-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed
Description
Description
When using glob import I'm usually trying to do some manipulation of the path. This is the pattern which appears a lot of the time
const globbedArray = Object.entries(import.meta.glob('./routes/*.js'))
const routes = globbedArray.map(([name, item]) => {
path = name.split('/').at(-1).split('.')[0]
return [path, item]
})which works great but the compiled output will contain those paths which aren't needed.
Suggested solution
const routes = import.meta.glob('./routes/*.js', {
array: true,
key: (path) => path.split('/').at(-1).split('.')[0],
})where array: true just uses the Object.entries of the existing output, and key transforms the key used in the object (duplicate handling shouldn't be too much of a concern as it is up to the dev to write it appropriately).
looking at the current importMetaGlob.ts plugin it looks possible to do. if this proposal is accepted I am willing to submit a pr
Additional context
Apologies if I had missed any earlier discussion that is similar to this, most of the import glob issues that I see have been resolved by the current implementation
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Reactions are currently unavailable