Skip to content

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

@timmorey

Description

@timmorey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions