Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

fix: some packages are treated as externals when they shouldn't #771

Merged
merged 5 commits into from
Feb 1, 2019

Conversation

rosen-vladimirov
Copy link
Contributor

In case externals are passed to webpack.config.js, they are converted to regular expression. The idea is to detect all imports for this module, for example if it is nativescript-vue, we would like to make externals imports like nativescript-vue/somesubdir/file1.
However, the regular expression we construct also matches packages like nativescript-vue-template.
Fix the regular expressions in all template webpack.config.js files and add unit tests for them.
Add devDependency to proxyquire as the webpack configs that are tested, require some packages that are not available in node_modules of nativescript-dev-webpack (including the nativescript-dev-webpack itself). This is expected for the webpack.config.js files, as they should be placed in the NativeScript applications, so mocking the requires shouldn't be a problem in this case.

PR Checklist

What is the current behavior?

Some packages may be treated as externals when they shouldn't (they are not passed in the env.externals array).

What is the new behavior?

Only packages passed as externals are treated as externals.

Fixes/Implements/Closes #[Issue Number].

In case `externals` are passed to webpack.config.js, they are converted to regular expression. The idea is to detect all imports for this module, for example if it is `nativescript-vue`, we would like to make externals imports like `nativescript-vue/somesubdir/file1`.
However, the regular expression we construct also matches packages like `nativescript-vue-template`.
Fix the regular expressions in all template webpack.config.js files and add unit tests for them.
Add devDependency to `proxyquire` as the webpack configs that are tested, require some packages that are not available in node_modules of `nativescript-dev-webpack` (including the `nativescript-dev-webpack` itself). This is expected for the `webpack.config.js` files, as they should be placed in the NativeScript applications, so mocking the requires shouldn't be a problem in this case.
@rosen-vladimirov
Copy link
Contributor Author

run ci

1 similar comment
@rosen-vladimirov
Copy link
Contributor Author

run ci

@rosen-vladimirov
Copy link
Contributor Author

test

Copy link
Contributor

@sis0k0 sis0k0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it might be better to construct the regular expressions from the externals strings directly in compiler.js and not in the webpack configs. What do you think?

@@ -48,7 +48,7 @@ module.exports = env => {
} = env;
env.externals = env.externals || [];
const externals = (env.externals).map((e) => { // --env.externals
return new RegExp(e + ".*");
return new RegExp(`^${e}((/.*)|$)`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment what the regex does, and why we need the externals array?

Move the conversion of regular expressions from `string[]` to `RegExp[]` to index.js file, so it can be reused in all webpack.config.js files.
Move most of the tests to the `index.spec.js` due to this change.
@rosen-vladimirov
Copy link
Contributor Author

Hey @sis0k0 , I'm unable to move the Regular Expression generation to compiler.js as it should be read by the webpack process which is spawned there. However, I've moved the logic to index.js file and now it is reused from there. This simplified the tests as well. Can you please take a look?

Copy link
Contributor

@sis0k0 sis0k0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I've only added a few GH suggestions, fixing grammar mistakes.

@rosen-vladimirov
Copy link
Contributor Author

@sis0k0 thanks a lot for the suggestions, I've commited all of them

@rosen-vladimirov rosen-vladimirov merged commit 3362cd6 into master Feb 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants