-
-
Notifications
You must be signed in to change notification settings - Fork 40
fix: some packages are treated as externals when they shouldn't #771
Conversation
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.
run ci |
1 similar comment
run ci |
test |
There was a problem hiding this 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?
templates/webpack.angular.js
Outdated
@@ -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}((/.*)|$)`); |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this 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.
@sis0k0 thanks a lot for the suggestions, I've commited all of them |
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 isnativescript-vue
, we would like to make externals imports likenativescript-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 ofnativescript-dev-webpack
(including thenativescript-dev-webpack
itself). This is expected for thewebpack.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].