Skip to content

Commit

Permalink
Merge pull request webpack-contrib#31 from zoehneto/scoped-packages
Browse files Browse the repository at this point in the history
Include package name for scoped packages
  • Loading branch information
robertknight authored Jan 9, 2017
2 parents dde058d + 1b395a7 commit 0726330
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/size_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ function bundleSizeTree(stats: webpack_stats.WebpackCompilation) {
let filename = '';
if (packages.length > 1) {
let lastSegment = packages.pop() as string;
let lastPackageName = lastSegment.slice(0, lastSegment.search(new RegExp('\\' + path.sep + '|$')));
let lastPackageName = '';
if(lastSegment[0] === ('@')){
// package is a scoped package
let offset = lastSegment.indexOf(path.sep) + 1;
lastPackageName = lastSegment.slice(0, offset + lastSegment.slice(offset).indexOf(path.sep));
} else {
lastPackageName = lastSegment.slice(0, lastSegment.indexOf(path.sep));
}
packages.push(lastPackageName);
filename = lastSegment.slice(lastPackageName.length + 1);
} else {
Expand Down
38 changes: 37 additions & 1 deletion tests/size_tree_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,40 @@ describe('dependencySizeTree()', () => {
const depsTree = size_tree.dependencySizeTree(statsJson);
expect(depsTree.length).to.equal(2);
});
});

it('should include the package name of scoped packages', () => {
let webpackOutput: webpack_stats.WebpackCompilation = {
version: '1.2.3',
hash: 'unused',
time: 100,
assetsByChunkName: {},
assets: [],
chunks: [],
modules: [{
id: 0,
identifier: path.join('/', 'path', 'to', 'project', 'node_modules', '@scope', 'package1', 'foo.js'),
size: 1234,
name: path.join('.', 'foo.js')
}, {
id: 0,
identifier: path.join('/', 'path', 'to', 'project', 'node_modules', '@scope', 'package2', 'bar.js'),
size: 1234,
name: path.join('.', 'bar.js')
}],
errors: [],
warnings: [],
};
const depsTree = size_tree.dependencySizeTree(webpackOutput);
expect(depsTree.length).to.equal(1);
expect(depsTree[0].children).to.deep.include({
packageName: '@scope/package1',
size: 1234,
children: []
});
expect(depsTree[0].children).to.deep.include({
packageName: '@scope/package2',
size: 1234,
children: []
});
});
});

0 comments on commit 0726330

Please sign in to comment.