Skip to content

Commit 13f00fe

Browse files
committed
Merge branch 'master' into dave-custom-compression-support-aka-brotli
2 parents b71f9ae + 524dc41 commit 13f00fe

26 files changed

+6822
-8557
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
}]
88
],
99
"plugins": [
10-
["@babel/plugin-proposal-class-properties", {"loose": true}]
10+
["@babel/plugin-proposal-class-properties", {"loose": true}],
11+
["@babel/plugin-proposal-private-methods", {"loose": true}]
1112
]
1213
}

.github/workflows/main.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/checkout@v2
2020

2121
- name: Setup node
22-
uses: actions/setup-node@v1
22+
uses: actions/setup-node@v2
2323
with:
2424
node-version: ${{ matrix.node }}
2525

@@ -29,10 +29,8 @@ jobs:
2929
- name: Build sources
3030
run: npm run build
3131

32-
- name: Run tests with xvfb available
33-
uses: GabrielBB/xvfb-action@v1
34-
with:
35-
run: npm run test
32+
- name: Run tests
33+
run: npm run test
3634

3735
lint:
3836
runs-on: ubuntu-latest
@@ -41,7 +39,7 @@ jobs:
4139
uses: actions/checkout@v2
4240

4341
- name: Setup node
44-
uses: actions/setup-node@v1
42+
uses: actions/setup-node@v2
4543
with:
4644
node-version: '14.x'
4745

.npm-upgrade.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
"reason": "Current version of Webpack Dev Server doesn't work with v4"
1414
}
1515
}
16-
}
16+
}

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,33 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
1212

1313
## UNRELEASED
1414

15+
## 4.6.1
16+
17+
* **Bug Fix**
18+
* fix outputting different URL in cli mode ([#524](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/524) by [@southorange1228](https://github.com/southorange1228))
19+
20+
## 4.6.0
21+
22+
* **New Feature**
23+
* Support outputting different URL in server mode ([#520](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/520) by [@southorange1228](https://github.com/southorange1228))
24+
* Use deterministic chunk colors (#[501](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/501) by [@CreativeTechGuy](https://github.com/CreativeTechGuy))
25+
26+
## 4.5.0
27+
28+
* **Improvement**
29+
* Stop publishing src folder to npm ([#478](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/478) by [@wood1986](https://github.com/wood1986))
30+
31+
* **Internal**
32+
* Update some dependencies ([#448](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/448))
33+
* Replace nightmare with Puppeteer ([#469](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/469) by [@valscion](https://github.com/valscion))
34+
* Replace Mocha with Jest ([#470](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/470) by [@valscion](https://github.com/valscion))
35+
36+
## 4.4.2
37+
38+
* **Bug Fix**
39+
* Fix failure with `compiler.outputFileSystem.constructor` being `undefined` ([#447](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/447) by [@kedarv](https://github.com/kedarv) and [@alexander-akait](https://github.com/alexander-akait))
40+
* **NOTE:** This fix doesn't have added test coverage so the fix might break in future versions unless test coverage is added later.
41+
1542
## 4.4.1
1643

1744
* **Bug Fix**

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[![npm][npm]][npm-url]
22
[![node][node]][node-url]
3-
[![deps][deps]][deps-url]
43
[![tests][tests]][tests-url]
54
[![downloads][downloads]][downloads-url]
65

@@ -59,6 +58,7 @@ new BundleAnalyzerPlugin(options?: object)
5958
|**`analyzerMode`**|One of: `server`, `static`, `json`, `disabled`|Default: `server`. In `server` mode analyzer will start HTTP server to show bundle report. In `static` mode single HTML file with bundle report will be generated. In `json` mode single JSON file with bundle report will be generated. In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`. |
6059
|**`analyzerHost`**|`{String}`|Default: `127.0.0.1`. Host that will be used in `server` mode to start HTTP server.|
6160
|**`analyzerPort`**|`{Number}` or `auto`|Default: `8888`. Port that will be used in `server` mode to start HTTP server.|
61+
|**`analyzerUrl`**|`{Function}` called with `{ listenHost: string, listenHost: string, boundAddress: server.address}`. [server.address comes from Node.js](https://nodejs.org/api/net.html#serveraddress)| Default: `http://${listenHost}:${boundAddress.port}`. The URL printed to console with server mode.|
6262
|**`reportFilename`**|`{String}`|Default: `report.html`. Path to bundle report file that will be generated in `static` mode. It can be either an absolute path or a path relative to a bundle output directory (which is output.path in webpack config).|
6363
|**`reportTitle`**|`{String\|function}`|Default: function that returns pretty printed current date and time. Content of the HTML `title` element; or a function of the form `() => string` that provides the content.|
6464
|**`defaultSizes`**|One of: `stat`, `parsed`, `gzip`, `brotli`|Default: `parsed`. Module sizes to show in report by default. [Size definitions](#size-definitions) section describes what these values mean.|
@@ -180,8 +180,8 @@ The Chunk Context Menu can be opened by right-clicking or `Ctrl`-clicking on a s
180180

181181
It happens when `webpack-bundle-analyzer` analyzes files that don't actually exist in your file system, for example when you work with `webpack-dev-server` that keeps all the files in RAM. If you use `webpack-bundle-analyzer` as a plugin you won't get any errors, however if you run it via CLI you get the error message in terminal:
182182
```
183-
Couldn't parse bundle asset "your_bundle_name.bundle.js".
184-
Analyzer will use module sizes from stats file.
183+
Error parsing bundle asset "your_bundle_name.bundle.js": no such file
184+
No bundles were parsed. Analyzer will show only original module sizes from stats file.
185185
```
186186
To get more information about it you can read [issue #147](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/147).
187187

@@ -217,9 +217,6 @@ To get more information about it you can read [issue #147](https://github.com/we
217217
[node]: https://img.shields.io/node/v/webpack-bundle-analyzer.svg
218218
[node-url]: https://nodejs.org
219219

220-
[deps]: https://david-dm.org/webpack-contrib/webpack-bundle-analyzer.svg
221-
[deps-url]: https://david-dm.org/webpack-contrib/webpack-bundle-analyzer
222-
223220
[tests]: http://img.shields.io/travis/webpack-contrib/webpack-bundle-analyzer.svg
224221
[tests-url]: https://travis-ci.org/webpack-contrib/webpack-bundle-analyzer
225222

client/components/Treemap.jsx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default class Treemap extends Component {
77
super(props);
88
this.treemap = null;
99
this.zoomOutDisabled = false;
10+
this.findChunkNamePartIndex();
1011
}
1112

1213
componentDidMount() {
@@ -16,6 +17,7 @@ export default class Treemap extends Component {
1617

1718
componentWillReceiveProps(nextProps) {
1819
if (nextProps.data !== this.props.data) {
20+
this.findChunkNamePartIndex();
1921
this.treemap.set({
2022
dataObject: this.getTreemapDataObject(nextProps.data)
2123
});
@@ -76,6 +78,19 @@ export default class Treemap extends Component {
7678
vars.titleBarShown = false;
7779
},
7880
groupColorDecorator(options, properties, variables) {
81+
const root = component.getGroupRoot(properties.group);
82+
const chunkName = component.getChunkNamePart(root.label);
83+
const hash = /[^0-9]/u.test(chunkName)
84+
? hashCode(chunkName)
85+
: (parseInt(chunkName) / 1000) * 360;
86+
variables.groupColor = {
87+
model: 'hsla',
88+
h: Math.round(Math.abs(hash) % 360),
89+
s: 60,
90+
l: 50,
91+
a: 0.9
92+
};
93+
7994
const {highlightGroups} = component.props;
8095
const module = properties.group;
8196

@@ -136,6 +151,14 @@ export default class Treemap extends Component {
136151
});
137152
}
138153

154+
getGroupRoot(group) {
155+
let nextParent;
156+
while (!group.isAsset && (nextParent = this.treemap.get('hierarchy', group).parent)) {
157+
group = nextParent;
158+
}
159+
return group;
160+
}
161+
139162
zoomToGroup(group) {
140163
this.zoomOutDisabled = false;
141164

@@ -164,9 +187,62 @@ export default class Treemap extends Component {
164187
if (props.onResize) {
165188
props.onResize();
166189
}
190+
};
191+
192+
/**
193+
* Finds patterns across all chunk names to identify the unique "name" part.
194+
*/
195+
findChunkNamePartIndex() {
196+
const splitChunkNames = this.props.data.map((chunk) => chunk.label.split(/[^a-z0-9]/iu));
197+
const longestSplitName = Math.max(...splitChunkNames.map((parts) => parts.length));
198+
const namePart = {
199+
index: 0,
200+
votes: 0
201+
};
202+
for (let i = longestSplitName - 1; i >= 0; i--) {
203+
const identifierVotes = {
204+
name: 0,
205+
hash: 0,
206+
ext: 0
207+
};
208+
let lastChunkPart = '';
209+
for (const splitChunkName of splitChunkNames) {
210+
const part = splitChunkName[i];
211+
if (part === undefined || part === '') {
212+
continue;
213+
}
214+
if (part === lastChunkPart) {
215+
identifierVotes.ext++;
216+
} else if (/[a-z]/u.test(part) && /[0-9]/u.test(part) && part.length === lastChunkPart.length) {
217+
identifierVotes.hash++;
218+
} else if (/^[a-z]+$/iu.test(part) || /^[0-9]+$/u.test(part)) {
219+
identifierVotes.name++;
220+
}
221+
lastChunkPart = part;
222+
}
223+
if (identifierVotes.name >= namePart.votes) {
224+
namePart.index = i;
225+
namePart.votes = identifierVotes.name;
226+
}
227+
}
228+
this.chunkNamePartIndex = namePart.index;
229+
}
230+
231+
getChunkNamePart(chunkLabel) {
232+
return chunkLabel.split(/[^a-z0-9]/iu)[this.chunkNamePartIndex] || chunkLabel;
167233
}
168234
}
169235

170236
function preventDefault(event) {
171237
event.preventDefault();
172238
}
239+
240+
function hashCode(str) {
241+
let hash = 0;
242+
for (let i = 0; i < str.length; i++) {
243+
const code = str.charCodeAt(i);
244+
hash = (hash << 5) - hash + code;
245+
hash = hash & hash;
246+
}
247+
return hash;
248+
}

jest.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Jest configuration
2+
// Reference: https://jestjs.io/docs/configuration
3+
4+
module.exports = {
5+
testMatch: [
6+
'**/test/*.js'
7+
],
8+
testPathIgnorePatterns: [
9+
'<rootDir>/test/helpers.js'
10+
],
11+
setupFilesAfterEnv: [
12+
'<rootDir>/test/helpers.js'
13+
],
14+
watchPathIgnorePatterns: [
15+
// Ignore the output generated by plugin tests
16+
// when watching for changes to avoid the test
17+
// runner continuously re-running tests
18+
'<rootDir>/test/output'
19+
]
20+
};

0 commit comments

Comments
 (0)