diff --git a/size_tree.ts b/size_tree.ts
index eaeb62c9..30ee70c1 100644
--- a/size_tree.ts
+++ b/size_tree.ts
@@ -1,6 +1,7 @@
///
import filesize = require('filesize');
+import path = require('path');
import webpack_stats = require('./webpack_stats');
@@ -92,11 +93,11 @@ export function dependencySizeTree(stats: webpack_stats.WebpackJsonOutput) {
// root/node_modules/parent/node_modules/child/file/path.js =>
// ['root', 'parent', 'child', 'file/path.js'
- let packages = mod.path.split(/\/node_modules\//);
+ let packages = mod.path.split(new RegExp('\\' + path.sep + 'node_modules\\' + path.sep));
let filename = '';
if (packages.length > 1) {
let lastSegment = packages.pop();
- let lastPackageName = lastSegment.slice(0, lastSegment.search(/\/|$/));
+ let lastPackageName = lastSegment.slice(0, lastSegment.search(new RegExp('\\' + path.sep + '|$')));
packages.push(lastPackageName);
filename = lastSegment.slice(lastPackageName.length + 1);
} else {
diff --git a/tests/size_tree_test.ts b/tests/size_tree_test.ts
index c13f13d3..4536eccb 100644
--- a/tests/size_tree_test.ts
+++ b/tests/size_tree_test.ts
@@ -2,6 +2,7 @@
import {expect} from 'chai';
import fs = require('fs');
+import path = require('path');
import size_tree = require('../size_tree');
import webpack_stats = require('../webpack_stats');
@@ -10,8 +11,16 @@ describe('printDependencySizeTree()', () => {
it('should print the size tree', () => {
let output = '';
- const statsJsonStr = fs.readFileSync('tests/stats.json').toString();
+ const statsJsonStr = fs.readFileSync(path.join('tests', 'stats.json')).toString();
const statsJson = JSON.parse(statsJsonStr);
+
+ // convert paths in Json to WIN if necessary
+ if(path.sep !== '/') {
+ statsJson.modules.forEach(module => {
+ module.identifier = module.identifier.replace(/\//g, path.sep);
+ });
+ }
+
const depsTree = size_tree.dependencySizeTree(statsJson);
size_tree.printDependencySizeTree(depsTree, 0, line => output += '\n' + line);
@@ -39,9 +48,9 @@ describe('dependencySizeTree()', () => {
chunks: [],
modules: [{
id: 0,
- identifier: '/path/to/loader.js!/path/to/project/node_modules/dep/foo.js',
+ identifier: path.join('/', 'to', 'loader.js!', 'path', 'to', 'project', 'node_modules', 'dep', 'foo.js'),
size: 1234,
- name: './foo.js'
+ name: path.join('.', 'foo.js')
}]
};
const depsTree = size_tree.dependencySizeTree(webpackOutput);