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

Use chunk.forEachModules instead of deprecated chunk.modules #328

Merged
merged 1 commit into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/packExternalModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function getExternalModules(stats) {

_.forEach(stats.compilation.chunks, chunk => {
// Explore each module within the chunk (built inputs):
_.forEach(chunk.modules, module => {
chunk.forEachModule(module => {
if (isExternalModule(module)) {
externals.add({
origin: _.get(findExternalOrigin(module.issuer), 'rawRequest'),
Expand Down Expand Up @@ -285,7 +285,7 @@ module.exports = {
/**
* We should not be modifying 'package-lock.json'
* because this file should be treat as internal to npm.
*
*
* Rebase package-lock is a temporary workaround and must be
* removed as soon as https://github.com/npm/npm/issues/19183 gets fixed.
*/
Expand Down
37 changes: 0 additions & 37 deletions tests/data/stats-peerdeps.js

This file was deleted.

190 changes: 113 additions & 77 deletions tests/packExternalModules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ chai.use(require('sinon-chai'));

const expect = chai.expect;

class ChunkMock {
constructor(modules) {
this._modules = modules;
}

forEachModule(fn) {
_.forEach(this._modules, fn);
}
}

describe('packExternalModules', () => {
let sandbox;
let baseModule;
Expand Down Expand Up @@ -90,34 +100,32 @@ describe('packExternalModules', () => {
{
compilation: {
chunks: [
{
modules: [
{
identifier: _.constant('"crypto"')
},
{
identifier: _.constant('"uuid/v4"')
},
{
identifier: _.constant('external "eslint"')
},
{
identifier: _.constant('"mockery"')
},
{
identifier: _.constant('"@scoped/vendor/module1"')
},
{
identifier: _.constant('external "@scoped/vendor/module2"')
},
{
identifier: _.constant('external "uuid/v4"')
},
{
identifier: _.constant('external "bluebird"')
},
]
}
new ChunkMock([
{
identifier: _.constant('"crypto"')
},
{
identifier: _.constant('"uuid/v4"')
},
{
identifier: _.constant('external "eslint"')
},
{
identifier: _.constant('"mockery"')
},
{
identifier: _.constant('"@scoped/vendor/module1"')
},
{
identifier: _.constant('external "@scoped/vendor/module2"')
},
{
identifier: _.constant('external "uuid/v4"')
},
{
identifier: _.constant('external "bluebird"')
},
])
],
compiler: {
outputPath: '/my/Service/Path/.webpack/service'
Expand All @@ -131,22 +139,20 @@ describe('packExternalModules', () => {
{
compilation: {
chunks: [
{
modules: [
{
identifier: _.constant('"crypto"')
},
{
identifier: _.constant('"uuid/v4"')
},
{
identifier: _.constant('"mockery"')
},
{
identifier: _.constant('"@scoped/vendor/module1"')
},
]
}
new ChunkMock([
{
identifier: _.constant('"crypto"')
},
{
identifier: _.constant('"uuid/v4"')
},
{
identifier: _.constant('"mockery"')
},
{
identifier: _.constant('"@scoped/vendor/module1"')
},
])
],
compiler: {
outputPath: '/my/Service/Path/.webpack/service'
Expand All @@ -160,37 +166,35 @@ describe('packExternalModules', () => {
{
compilation: {
chunks: [
{
modules: [
{
identifier: _.constant('"crypto"')
},
{
identifier: _.constant('"uuid/v4"')
},
{
identifier: _.constant('external "eslint"')
},
{
identifier: _.constant('"mockery"')
},
{
identifier: _.constant('"@scoped/vendor/module1"')
},
{
identifier: _.constant('external "@scoped/vendor/module2"')
},
{
identifier: _.constant('external "uuid/v4"')
},
{
identifier: _.constant('external "localmodule"')
},
{
identifier: _.constant('external "bluebird"')
},
]
}
new ChunkMock([
{
identifier: _.constant('"crypto"')
},
{
identifier: _.constant('"uuid/v4"')
},
{
identifier: _.constant('external "eslint"')
},
{
identifier: _.constant('"mockery"')
},
{
identifier: _.constant('"@scoped/vendor/module1"')
},
{
identifier: _.constant('external "@scoped/vendor/module2"')
},
{
identifier: _.constant('external "uuid/v4"')
},
{
identifier: _.constant('external "localmodule"')
},
{
identifier: _.constant('external "bluebird"')
},
])
],
compiler: {
outputPath: '/my/Service/Path/.webpack/service'
Expand Down Expand Up @@ -332,7 +336,7 @@ describe('packExternalModules', () => {

sandbox.stub(process, 'cwd').returns(path.join('/my/Service/Path'));
mockery.registerMock(path.join(process.cwd(), 'locals', 'package.json'), packageLocalRefMock);

return expect(module.packExternalModules()).to.be.fulfilled
.then(() => BbPromise.all([
// The module package JSON and the composite one should have been stored
Expand Down Expand Up @@ -859,7 +863,39 @@ describe('packExternalModules', () => {
};

const dependencyGraph = require('./data/npm-ls-peerdeps.json');
const peerDepStats = require('./data/stats-peerdeps.js');
const peerDepStats = {
stats: [
{
compilation: {
chunks: [
new ChunkMock([
{
identifier: _.constant('"crypto"')
},
{
identifier: _.constant('"uuid/v4"')
},
{
identifier: _.constant('"mockery"')
},
{
identifier: _.constant('"@scoped/vendor/module1"')
},
{
identifier: _.constant('external "bluebird"')
},
{
identifier: _.constant('external "request-promise"')
}
])
],
compiler: {
outputPath: '/my/Service/Path/.webpack/service'
}
}
}
]
};

module.webpackOutputPath = 'outputPath';
fsExtraMock.pathExists.yields(null, false);
Expand Down