You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The glob resolver (@parcel/resolver-glob) only supports a file path as a specifier, and will not do node style resolution if a package is specified.
If the import references a path within a package, should the glob resolver "resolve" the package to a path first? Or should it at least warn or error if the file list the glob resolves to is empty?
🔦 Context
I have a component I'm trying to bundle that currently uses Webpack's dynamic expressions, something like: import(`@scope/pkg/dist/i18n/${locale}`).
As part of migrating to Parcel, I tried replacing this with import('@scope/pkg/dist/i18n/*.js')[locale] however this did not work correctly, as it is assumed the specifier is a path -
In the example above, this doesn't work because the resolver tries to find files in /path/to/my/repo/src/path/@scope/pkg/dist/i18n/*.js (assuming a source path of /path/to/my/repo/src/path/)
Changing the import to a relative path obviously makes it work (i.e. import('../../../node_modules/@scope/pkg/dist/i18n/*.js')) but is potentially fragile if things get moved around, and similar to the case above would fail to find any files silently.
Should the glob resolver resolve any packages to paths first? I could see the argument for either the current behaviour or resolving, so it's not cut and dry in my mind - hence the RFC.
Another potential option, if package resolution is determined to not be appropriate here, would be to at least warn (or error?) if the list of files is empty? Because I didn't realise what the problem was until I debugged the build and stepped through the glob resolver. i.e. after the line below, warn if files.length === 0:
💬 RFC
The glob resolver (
@parcel/resolver-glob
) only supports a file path as a specifier, and will not do node style resolution if a package is specified.If the import references a path within a package, should the glob resolver "resolve" the package to a path first? Or should it at least warn or error if the file list the glob resolves to is empty?
🔦 Context
I have a component I'm trying to bundle that currently uses Webpack's dynamic expressions, something like:
import(`@scope/pkg/dist/i18n/${locale}`)
.As part of migrating to Parcel, I tried replacing this with
import('@scope/pkg/dist/i18n/*.js')[locale]
however this did not work correctly, as it is assumed the specifier is a path -parcel/packages/resolvers/glob/src/GlobResolver.js
Line 55 in 8daaed8
In the example above, this doesn't work because the resolver tries to find files in
/path/to/my/repo/src/path/@scope/pkg/dist/i18n/*.js
(assuming a source path of/path/to/my/repo/src/path/
)Changing the import to a relative path obviously makes it work (i.e.
import('../../../node_modules/@scope/pkg/dist/i18n/*.js')
) but is potentially fragile if things get moved around, and similar to the case above would fail to find any files silently.Should the glob resolver resolve any packages to paths first? I could see the argument for either the current behaviour or resolving, so it's not cut and dry in my mind - hence the RFC.
Another potential option, if package resolution is determined to not be appropriate here, would be to at least warn (or error?) if the list of files is empty? Because I didn't realise what the problem was until I debugged the build and stepped through the glob resolver. i.e. after the line below, warn if
files.length === 0
:parcel/packages/resolvers/glob/src/GlobResolver.js
Line 57 in 8daaed8
The text was updated successfully, but these errors were encountered: