@patternslib/dev 4.6.1 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +32 -0
- package/Makefile +29 -17
- package/README.md +1 -0
- package/docs/adr/0003-link-sunburst-segments-to-chunks.md +30 -0
- package/jest.config.js +1 -0
- package/package.json +1 -1
- package/webpack/stats-sunburst-navigation.js +119 -0
- package/webpack/stats-sunburst.js +19 -2
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.7.0](https://github.com/Patternslib/dev/compare/4.6.1...4.7.0) (2026-12-01)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- **Makefile:** Add audit target to check the dependencies for security vulnerabilities. ([8b8ec3f](https://github.com/Patternslib/dev/commit/8b8ec3fe7e3864fa09c98c96a17ac0ed28056be9))
|
|
8
|
+
- **webpack:** Link sunburst segments to matching assets. ([8155249](https://github.com/Patternslib/dev/commit/81552491d10f5b84942212054d22fba75bbe6160))
|
|
9
|
+
|
|
10
|
+
Let users select a module or directory in the bundle report and jump to an asset that contains it. Rebuild the report when either sunburst script changes.
|
|
11
|
+
|
|
12
|
+
Ref: ADR 0003
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- **Makefile:** Omit per-chunk module lists from analysis stats. ([6c08593](https://github.com/Patternslib/dev/commit/6c08593b5271dc2f8824a731de5d7b52d4dd010f))
|
|
17
|
+
|
|
18
|
+
Apply the webpack-cli flag only when generating stats.json. Keep top-level module reasons for whybundled and preserve stats settings for regular builds.
|
|
19
|
+
|
|
20
|
+
- **webpack:** Restore sunburst asset breakdown for compact stats. ([366137b](https://github.com/Patternslib/dev/commit/366137b437402a75b61497b886936ccf356e1e97))
|
|
21
|
+
|
|
22
|
+
Reconstruct missing per-chunk module lists from top-level module membership before flattening concatenated modules.
|
|
23
|
+
|
|
24
|
+
- **webpack:** Reuse the sunburst chunk dropdown. ([4552e9e](https://github.com/Patternslib/dev/commit/4552e9e862a9b771b7e73195e2cd407074d6f1df))
|
|
25
|
+
|
|
26
|
+
Filter the existing chunk options when a segment is activated. Restore the full list when users select a chunk or clear the filter.
|
|
27
|
+
|
|
28
|
+
Ref: ADR 0003
|
|
29
|
+
|
|
30
|
+
### Maintenance
|
|
31
|
+
|
|
32
|
+
- Be quiter when running tests and supress console messages. ([a013e37](https://github.com/Patternslib/dev/commit/a013e37d1e1835b1977a3597d3af7624a4affb5e))
|
|
33
|
+
- **Makefile:** Be quiter when running Makefile targets. ([a58ccf5](https://github.com/Patternslib/dev/commit/a58ccf5acf96f5a73303114623e508973d0bff73))
|
|
34
|
+
|
|
3
35
|
## [4.6.1](https://github.com/Patternslib/dev/compare/4.6.0...4.6.1) (2026-11-30)
|
|
4
36
|
|
|
5
37
|
### Bug Fixes
|
package/Makefile
CHANGED
|
@@ -142,11 +142,19 @@ prerelease-beta:
|
|
|
142
142
|
## Analyze
|
|
143
143
|
#
|
|
144
144
|
|
|
145
|
+
.PHONY: audit
|
|
146
|
+
audit:
|
|
147
|
+
$(PNPM) audit
|
|
148
|
+
|
|
145
149
|
# Build stats.json. Rebuilt when pnpm-lock.yaml changes.
|
|
146
150
|
# Write to a temporary file first, so that a failed build doesn't leave a
|
|
147
151
|
# broken but up-to-date stats.json behind.
|
|
148
152
|
# With --json, webpack reports compilation errors only within the JSON output.
|
|
149
153
|
# On failure, print them before removing the temporary file.
|
|
154
|
+
#
|
|
155
|
+
# Omit per-chunk module lists, which repeat module reasons across chunks.
|
|
156
|
+
# Keep the top-level module list and reasons for whybundled.
|
|
157
|
+
#
|
|
150
158
|
# Packages without a build script (like @patternslib/dev itself) have no
|
|
151
159
|
# bundle to analyze. Stop early with a clear message instead of failing
|
|
152
160
|
# with a webpack configuration error.
|
|
@@ -155,7 +163,7 @@ ifneq ($(BUILDABLE),true)
|
|
|
155
163
|
@echo "$(PACKAGE_NAME) has no build script in package.json - nothing to analyze." >&2
|
|
156
164
|
@exit 1
|
|
157
165
|
endif
|
|
158
|
-
NODE_ENV=production $(WEBPACK_CLI) $(if $(WEBPACK_CONFIG),--config $(WEBPACK_CONFIG)) --json > $@.tmp \
|
|
166
|
+
@NODE_ENV=production $(WEBPACK_CLI) $(if $(WEBPACK_CONFIG),--config $(WEBPACK_CONFIG)) --no-stats-chunk-modules --json > $@.tmp \
|
|
159
167
|
|| { \
|
|
160
168
|
node -e "try { for (const e of JSON.parse(require('fs').readFileSync('$@.tmp')).errors || []) console.error(e.message || e) } catch {}"; \
|
|
161
169
|
rm -f $@.tmp; \
|
|
@@ -184,11 +192,11 @@ VISUALIZER_PACKAGE ?= webpack-visualizer-plugin2@2
|
|
|
184
192
|
VISUALIZER_DIR := node_modules/.cache/webpack-visualizer
|
|
185
193
|
|
|
186
194
|
$(VISUALIZER_DIR)/package/lib/main.js:
|
|
187
|
-
mkdir -p $(VISUALIZER_DIR)
|
|
188
|
-
cd $(VISUALIZER_DIR) && tar -xzf "$$(npm pack --silent $(VISUALIZER_PACKAGE))"
|
|
195
|
+
@mkdir -p $(VISUALIZER_DIR)
|
|
196
|
+
@cd $(VISUALIZER_DIR) && tar -xzf "$$(npm pack --silent $(VISUALIZER_PACKAGE))"
|
|
189
197
|
|
|
190
|
-
stats.html: stats.json $(VISUALIZER_DIR)/package/lib/main.js
|
|
191
|
-
node $(DEV_DIR)webpack/stats-sunburst.js $(VISUALIZER_DIR)/package stats.json $@
|
|
198
|
+
stats.html: stats.json $(VISUALIZER_DIR)/package/lib/main.js $(DEV_DIR)webpack/stats-sunburst.js $(DEV_DIR)webpack/stats-sunburst-navigation.js
|
|
199
|
+
@node $(DEV_DIR)webpack/stats-sunburst.js $(VISUALIZER_DIR)/package stats.json $@
|
|
192
200
|
|
|
193
201
|
# Command to open a file in the default browser. Override with e.g.
|
|
194
202
|
# `make analyze-bundle-sunburst OPEN=firefox`.
|
|
@@ -196,7 +204,7 @@ OPEN ?= $(if $(filter Darwin,$(shell uname -s)),open,xdg-open)
|
|
|
196
204
|
|
|
197
205
|
.PHONY: analyze-bundle-sunburst
|
|
198
206
|
analyze-bundle-sunburst: stats.html
|
|
199
|
-
|
|
207
|
+
@$(OPEN) stats.html || echo "Open stats.html in your browser."
|
|
200
208
|
|
|
201
209
|
|
|
202
210
|
##
|
|
@@ -204,8 +212,8 @@ analyze-bundle-sunburst: stats.html
|
|
|
204
212
|
#
|
|
205
213
|
|
|
206
214
|
.git/hooks/commit-msg:
|
|
207
|
-
echo "npx commitlint --edit" > .git/hooks/commit-msg
|
|
208
|
-
chmod u+x .git/hooks/commit-msg
|
|
215
|
+
@echo "npx commitlint --edit" > .git/hooks/commit-msg
|
|
216
|
+
@chmod u+x .git/hooks/commit-msg
|
|
209
217
|
|
|
210
218
|
.PHONY: bundle-pre
|
|
211
219
|
bundle-pre::
|
|
@@ -225,10 +233,10 @@ release-zip:
|
|
|
225
233
|
ifeq ($(BUILDABLE),true)
|
|
226
234
|
$(eval PACKAGE_VERSION := $(shell node -p "require('./package.json').version"))
|
|
227
235
|
@echo Creating $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip
|
|
228
|
-
mkdir -p $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
|
|
229
|
-
cp -R dist/. $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
|
|
236
|
+
@mkdir -p $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
|
|
237
|
+
@cp -R dist/. $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
|
|
230
238
|
zip -r $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)/
|
|
231
|
-
rm -Rf $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
|
|
239
|
+
@rm -Rf $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
|
|
232
240
|
endif
|
|
233
241
|
|
|
234
242
|
# Prepare some necessary variables.
|
|
@@ -263,7 +271,7 @@ ifeq ($(BUILDABLE),true)
|
|
|
263
271
|
$(eval RELEASE_IT_GITHUB_OPTIONS += --github.assets=$(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip)
|
|
264
272
|
endif
|
|
265
273
|
|
|
266
|
-
npx release-it \
|
|
274
|
+
@npx release-it \
|
|
267
275
|
$(RELEASE_IT_LEVEL) \
|
|
268
276
|
--github.release \
|
|
269
277
|
--no-github.update \
|
|
@@ -272,7 +280,7 @@ endif
|
|
|
272
280
|
|
|
273
281
|
@# Remove the bundle from release-zip again.
|
|
274
282
|
@# But don't break if it doesn't exist.
|
|
275
|
-
|
|
283
|
+
@-rm $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip
|
|
276
284
|
|
|
277
285
|
|
|
278
286
|
##
|
|
@@ -316,22 +324,26 @@ upgrade-gitignore-stats:
|
|
|
316
324
|
fi
|
|
317
325
|
|
|
318
326
|
upgrade-remove-husky:
|
|
319
|
-
test -d .husky\
|
|
327
|
+
@test -d .husky\
|
|
320
328
|
&& rm -R .husky\
|
|
321
329
|
&& git add .husky\
|
|
322
330
|
&& git commit .husky -m"maint: @patternslib/dev upgrade - remove .husky directory in favor of git hooks."\
|
|
323
331
|
|| :
|
|
324
|
-
|
|
332
|
+
@# supress output, even in error case:
|
|
333
|
+
@git config --unset core.hooksPath || :
|
|
334
|
+
echo "Upgraded husky configuration"\
|
|
325
335
|
|
|
326
336
|
eslint.config.js upgrade-eslint:
|
|
327
|
-
test -f "eslint.config.js"\
|
|
337
|
+
@test -f "eslint.config.js"\
|
|
328
338
|
|| (\
|
|
329
339
|
echo 'module.exports = require("@patternslib/dev/eslint.config.js");' > eslint.config.js\
|
|
330
340
|
&& git add eslint.config.js\
|
|
331
341
|
&& git commit eslint.config.js -m"maint: @patternslib/dev upgrade - create eslint.config.js."\
|
|
342
|
+
&& echo "Upgraded eslint configuration pt1."
|
|
332
343
|
)
|
|
333
|
-
test -f ".eslintrc.js"\
|
|
344
|
+
@test -f ".eslintrc.js"\
|
|
334
345
|
&& rm .eslintrc.js\
|
|
335
346
|
&& git add .eslintrc.js\
|
|
336
347
|
&& git commit .eslintrc.js -m"maint: @patternslib/dev upgrade - remove old .eslintrc.js."\
|
|
348
|
+
&& echo "Upgraded eslint configuration pt2."
|
|
337
349
|
|| :
|
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ Then run `make install`.
|
|
|
35
35
|
| `make lint`, `make eslint` | Lint the `src/` directory with ESLint. |
|
|
36
36
|
| `make format`, `make prettier` | Format all files with Prettier. |
|
|
37
37
|
| `make check`, `make test` | Run ESLint, then the `test` script from `package.json`. |
|
|
38
|
+
| `make audit` | Run `pnpm audit` to check project dependencies for known security vulnerabilities. |
|
|
38
39
|
| `make serve`, `make start` | Run the `start` script from `package.json`, e.g. a webpack dev server. |
|
|
39
40
|
| `make watch` | Run the `watch` script from `package.json`. |
|
|
40
41
|
| `make bundle`, `make build` | Clean `dist/` and run the `build` script from `package.json`, if there is one. Runs the `bundle-pre` target first. |
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Link sunburst segments to the existing asset filter
|
|
2
|
+
|
|
3
|
+
Status: Proposed (2026-12-01)
|
|
4
|
+
|
|
5
|
+
## Context
|
|
6
|
+
|
|
7
|
+
The sunburst's overview groups modules by path. Its filter lists emitted
|
|
8
|
+
JavaScript assets by filename, so finding the assets that contain a given
|
|
9
|
+
module or directory requires trying options individually.
|
|
10
|
+
|
|
11
|
+
## Decision
|
|
12
|
+
|
|
13
|
+
Add a small script to the generated report. Use the modules in each asset's
|
|
14
|
+
chart to find matching filter options for a selected arc. For a directory
|
|
15
|
+
arc, include assets that contain any of its visible subtree's modules.
|
|
16
|
+
Apply the selected asset through the visualizer's existing filter.
|
|
17
|
+
|
|
18
|
+
When a segment is activated, hide and disable nonmatching asset options in
|
|
19
|
+
the existing dropdown. Preserve the option nodes and values so the visualizer's
|
|
20
|
+
React component can handle selection. Keep the current selection and All Chunks
|
|
21
|
+
available. Restore the full list when users make a selection or clear the filter.
|
|
22
|
+
|
|
23
|
+
## Consequences
|
|
24
|
+
|
|
25
|
+
- The report remains a single HTML file and uses the existing chart renderer.
|
|
26
|
+
- A module can point to several assets when it is present in multiple chunks.
|
|
27
|
+
- Clearing the filter leaves the current chart selection in place.
|
|
28
|
+
- The script relies on the visualizer's SVG structure, the hierarchy nodes
|
|
29
|
+
bound by D3, and its asset selector. Check chart navigation when upgrading
|
|
30
|
+
the visualizer.
|
package/jest.config.js
CHANGED
|
@@ -15,6 +15,7 @@ module.exports = {
|
|
|
15
15
|
moduleNameMapper: {
|
|
16
16
|
"\\.(css|less|sass|scss)$": "identity-obj-proxy",
|
|
17
17
|
},
|
|
18
|
+
silent: true, // Don't emit console messages during a test run.
|
|
18
19
|
testEnvironment: "jsdom",
|
|
19
20
|
transformIgnorePatterns: [
|
|
20
21
|
"/node_modules/(?!(?:\\.pnpm/|@patternslib/|@plone/|preact/|screenfull/)).+\\.[tj]sx?$",
|
package/package.json
CHANGED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// This script runs after webpack-visualizer-plugin2 renders into #App.
|
|
2
|
+
(() => {
|
|
3
|
+
const app = document.querySelector("#App");
|
|
4
|
+
const asset_filter = app.querySelector("select");
|
|
5
|
+
if (!asset_filter) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const chunks_by_id = new Map(window.stats.chunks.map((chunk) => [chunk.id, chunk]));
|
|
10
|
+
const assets_by_name = new Map(
|
|
11
|
+
window.stats.assets.map((asset) => [asset.name, asset]),
|
|
12
|
+
);
|
|
13
|
+
const assets_by_module = new Map();
|
|
14
|
+
const module_key = (name, id) => JSON.stringify([name, id]);
|
|
15
|
+
const asset_options = Array.from(asset_filter.options).slice(1);
|
|
16
|
+
|
|
17
|
+
for (const option of asset_options) {
|
|
18
|
+
const asset = assets_by_name.get(option.text);
|
|
19
|
+
// The visualizer renders the first chunk assigned to a JavaScript asset.
|
|
20
|
+
const chunk = chunks_by_id.get(asset?.chunks?.[0]);
|
|
21
|
+
for (const module of chunk?.modules || []) {
|
|
22
|
+
const key = module_key(module.name, module.id);
|
|
23
|
+
if (!assets_by_module.has(key)) {
|
|
24
|
+
assets_by_module.set(key, new Set());
|
|
25
|
+
}
|
|
26
|
+
assets_by_module.get(key).add(option);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const filter_status = document.createElement("div");
|
|
31
|
+
filter_status.setAttribute("role", "status");
|
|
32
|
+
const reset_filter = document.createElement("button");
|
|
33
|
+
reset_filter.type = "button";
|
|
34
|
+
reset_filter.textContent = "Clear chunk filter";
|
|
35
|
+
reset_filter.hidden = true;
|
|
36
|
+
asset_filter.after(reset_filter, filter_status);
|
|
37
|
+
|
|
38
|
+
function clear_filter() {
|
|
39
|
+
for (const option of asset_options) {
|
|
40
|
+
option.hidden = false;
|
|
41
|
+
option.disabled = false;
|
|
42
|
+
}
|
|
43
|
+
filter_status.textContent = "";
|
|
44
|
+
reset_filter.hidden = true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function show_assets(segment) {
|
|
48
|
+
const assets = new Set();
|
|
49
|
+
const pending = [segment];
|
|
50
|
+
while (pending.length) {
|
|
51
|
+
const node = pending.pop();
|
|
52
|
+
if (node.children) {
|
|
53
|
+
for (const child of node.children) {
|
|
54
|
+
pending.push(child);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
for (const option of assets_by_module.get(
|
|
58
|
+
module_key(node.fullName, node.id),
|
|
59
|
+
) || []) {
|
|
60
|
+
assets.add(option);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Keep React's option nodes and selected value in place. Disable hidden
|
|
66
|
+
// options so they are also skipped during keyboard navigation.
|
|
67
|
+
for (const option of asset_options) {
|
|
68
|
+
const excluded = !option.selected && !assets.has(option);
|
|
69
|
+
option.hidden = excluded;
|
|
70
|
+
option.disabled = excluded;
|
|
71
|
+
}
|
|
72
|
+
const segment_name = segment.fullName || segment.name;
|
|
73
|
+
filter_status.textContent = assets.size
|
|
74
|
+
? `Showing chunks containing ${segment_name}.`
|
|
75
|
+
: `No chunks found containing ${segment_name}.`;
|
|
76
|
+
reset_filter.hidden = false;
|
|
77
|
+
asset_filter.focus();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
reset_filter.addEventListener("click", () => {
|
|
81
|
+
clear_filter();
|
|
82
|
+
asset_filter.focus();
|
|
83
|
+
});
|
|
84
|
+
asset_filter.addEventListener("change", clear_filter);
|
|
85
|
+
|
|
86
|
+
// D3 attaches the current hierarchy node to each arc and replaces the
|
|
87
|
+
// arcs on filter changes. Keep the keyboard controls on the new arcs.
|
|
88
|
+
function configure_segments() {
|
|
89
|
+
for (const arc of app.querySelectorAll(
|
|
90
|
+
'#svgWrapper path:not([display="none"])',
|
|
91
|
+
)) {
|
|
92
|
+
arc.setAttribute("tabindex", "0");
|
|
93
|
+
arc.setAttribute("role", "button");
|
|
94
|
+
const { fullName, name } = arc.__data__;
|
|
95
|
+
arc.setAttribute("aria-label", `Find chunks containing ${fullName || name}`);
|
|
96
|
+
arc.style.cursor = "pointer";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function activate_segment(event) {
|
|
101
|
+
const arc = event.target.closest('#svgWrapper path:not([display="none"])');
|
|
102
|
+
if (arc?.__data__) {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
show_assets(arc.__data__);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
app.addEventListener("click", activate_segment);
|
|
109
|
+
app.addEventListener("keydown", (event) => {
|
|
110
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
111
|
+
activate_segment(event);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
new MutationObserver(configure_segments).observe(app.querySelector(".chart"), {
|
|
115
|
+
childList: true,
|
|
116
|
+
subtree: true,
|
|
117
|
+
});
|
|
118
|
+
configure_segments();
|
|
119
|
+
})();
|
|
@@ -43,14 +43,30 @@ const reduce_modules = (modules = []) =>
|
|
|
43
43
|
],
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
+
const chunks = stats.chunks || [];
|
|
47
|
+
const modules_by_chunk = new Map(
|
|
48
|
+
chunks.filter((chunk) => chunk.modules == null).map((chunk) => [chunk.id, []]),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// Compact stats record chunk membership on the top-level modules. Index
|
|
52
|
+
// those modules before flattening, since concatenated children may lack IDs
|
|
53
|
+
// for the chunks they belong to.
|
|
54
|
+
if (modules_by_chunk.size) {
|
|
55
|
+
for (const module of stats.modules || []) {
|
|
56
|
+
for (const chunk_id of module.chunks || []) {
|
|
57
|
+
modules_by_chunk.get(chunk_id)?.push(module);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
const reduced_stats = {
|
|
47
63
|
assets: (stats.assets || []).map((asset) => ({
|
|
48
64
|
name: asset.name,
|
|
49
65
|
chunks: asset.chunks,
|
|
50
66
|
})),
|
|
51
|
-
chunks:
|
|
67
|
+
chunks: chunks.map((chunk) => ({
|
|
52
68
|
id: chunk.id,
|
|
53
|
-
modules: reduce_modules(chunk.modules),
|
|
69
|
+
modules: reduce_modules(chunk.modules ?? modules_by_chunk.get(chunk.id)),
|
|
54
70
|
})),
|
|
55
71
|
modules: reduce_modules(stats.modules),
|
|
56
72
|
};
|
|
@@ -75,6 +91,7 @@ const html = `<!DOCTYPE html>
|
|
|
75
91
|
<div id="App"></div>
|
|
76
92
|
<script>window.stats = ${stats_string};</script>
|
|
77
93
|
<script>${read("main.js")}</script>
|
|
94
|
+
<script>${fs.readFileSync(path.join(__dirname, "stats-sunburst-navigation.js"), "utf8")}</script>
|
|
78
95
|
</body>
|
|
79
96
|
</html>
|
|
80
97
|
`;
|