plugins: [plugin-dynamic-import-vars] non-normalized paths no longer work

Expected Behavior

Imports passed non-normalized paths resolve the bundled file

Actual Behavior

Imports passed non-normalized paths produce a Unknown variable dynamic import error

Additional Information

#1780 breaks any code that doesn’t build normalized paths because tinyglobby always outputs normalized glob paths but the plugin doesn’t touch the original code.

Given this code:

import(`./../${myFile}.js`)

tinyglobby produces ../*.js -> ../myFile.js-> case '../myFile.js', which now doesn’t match ./../myFile.js.

I think the only reasonable options are:

  1. Revert
  2. Ask tinyglobby to make normalization optional (will take time and maybe isn’t even feasible/desired)
  3. Normalize the path inside __variableDynamicImportRuntime__ before the switch with path-normalize

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Making the decision to revert the changes. The only tangible benefit was a reduction of dependencies, but the juice isn’t worth the squeeze.

the crawler library generates a result that’s always the exact same no matter the patterns, and each possible result is generated is filtered by the (normalized) patterns

So then the issue is with the crawler then. I don’t think it’s actually an issue, though. Certainly not from its perspective. It might be best to just normalize the paths at runtime in the plugin.

that normalizes the pattern to match, not the way the results from the directory crawler are generated. the only case where the patterns can modify the result is if any of the patterns start with ../, but that’s just because the crawler can’t find any files outside the root without a workaround

the crawler library generates a result that’s always the exact same no matter the patterns, and each possible result that’s generated is filtered by the (normalized) patterns

if you have a directory that has a/a.txt for example, no matter what pattern you use, the crawler will see that file as a/a.txt when filtering and producing results