Skip to content

Commit

Permalink
Merge pull request #328 from janicduplessis/webpack-modules
Browse files Browse the repository at this point in the history
Use chunk.forEachModules instead of deprecated chunk.modules
  • Loading branch information
HyperBrain authored Mar 1, 2018
2 parents 67b4da4 + 0c465e2 commit e6e544e
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 116 deletions.
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

0 comments on commit e6e544e

Please sign in to comment.