Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loose regex can cause require/define to be replaced in unexpected places #128

Open
timmorey opened this issue Sep 30, 2024 · 0 comments
Open

Comments

@timmorey
Copy link
Collaborator

timmorey commented Sep 30, 2024

The regular expressions defined in

new RegExp(path.parse(outputPaths.app.js).name + '(.*js)'),
new RegExp(path.parse(outputPaths.vendor.js).name + '(.*js)'),
new RegExp(path.parse(outputPaths.tests.js).name + '(.*js)'),

are very loose, and will result in renaming require/define in any js asset with a filename that contains the words "tests", "vendor", or the ember app's configured modulePrefix.

When ember-auto-import@2 is used in a non-trivial app, it will output a large number of js assets, and by default many of these will contain "vendor" somewhere in the filename. These files will have usages of "require" and "define" rewritten by this addon, and this can cause cause runtime errors or subtly incorrect behaviors that.

To add to the complexity, there are a couple files output by ember-auto-import@2 that do need to be processed by this addon: the primary app and tests entrypoints do need to be rewritten so they can capture the renamed require/define functions the app is using.

I'm logging this issue mostly to share information. We have worked around this issue in our apps, and we are also working to drop this addon entirely in the future. We could tighten up these regexes, though it would take some experimentation to figure out exactly how to do that. If anyone else runs into something like this, I may be able to advise on a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant