@patternslib/dev 4.6.0 → 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 CHANGED
@@ -1,5 +1,63 @@
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
+
35
+ ## [4.6.1](https://github.com/Patternslib/dev/compare/4.6.0...4.6.1) (2026-11-30)
36
+
37
+ ### Bug Fixes
38
+
39
+ - **jest:** Let the matchMedia mock emulate a desktop device. ([12e094e](https://github.com/Patternslib/dev/commit/12e094e49ebf0f2d3bf9ced0a6af6f4334cde882))
40
+
41
+ The mock returned matches: false for every query. TinyMCE 8.11 detects
42
+ touch devices with !matchMedia("(any-pointer:fine)") and therefore
43
+ treated jsDOM as a touch device, disabling the editor resize handle.
44
+
45
+ Fine pointer and hover queries now match, all other queries still don't.
46
+
47
+ Ref: ADR 0002
48
+
49
+ - **release-it:** Filter attribution trailers from changelogs. ([0d347c8](https://github.com/Patternslib/dev/commit/0d347c87e39d4d20e01a494fd20044b2283ad6fe))
50
+
51
+ Omit Assisted-by, Assisted by and Co-authored-by lines (case-insensitive)
52
+ from rendered commit bodies and footers. Add tests for the changelog commit
53
+ partial.
54
+
55
+ ### Maintenance
56
+
57
+ - **docs:** Add ADR 0002 about the matchMedia mock emulating a desktop device. ([f9d063a](https://github.com/Patternslib/dev/commit/f9d063a1c46a878367f3294e1519d641be307fc9))
58
+
59
+ Ref: ADR 0002
60
+
3
61
  ## [4.6.0](https://github.com/Patternslib/dev/compare/4.5.1...4.6.0) (2026-11-30)
4
62
 
5
63
  ### Features
@@ -16,16 +74,12 @@
16
74
 
17
75
  Ref: ADR 0001
18
76
 
19
- Assisted-by: Claude Opus 5.5
20
-
21
77
  ### Maintenance
22
78
 
23
79
  - **docs:** Add ADR 0001 about running upgrades from make update. ([7931180](https://github.com/Patternslib/dev/commit/7931180ac80e4195647b9aa0e82f776ba7943520))
24
80
 
25
81
  Ref: ADR 0001
26
82
 
27
- Assisted-by: Claude Opus 5.5
28
-
29
83
  - **docs:** Start with ADR records. ([c7add1e](https://github.com/Patternslib/dev/commit/c7add1e6e6923ed436b6d2853e5b00b4a49996b4))
30
84
 
31
85
  ## [4.5.1](https://github.com/Patternslib/dev/compare/4.5.0...4.5.1) (2026-11-30)
@@ -40,14 +94,10 @@
40
94
  .gitignore. Both commit their change and skip files with uncommitted
41
95
  changes, so that unrelated work is never committed.
42
96
 
43
- Assisted-by: Claude Opus 5.5
44
-
45
97
  ### Bug Fixes
46
98
 
47
99
  - **Makefile:** Fall back to webpack-cli config discovery for bundle analysis. ([fd4918d](https://github.com/Patternslib/dev/commit/fd4918de0dbce20be20aa1f8fc4a7b50ec9793f0))
48
100
 
49
- Assisted-by: Claude Opus 5.5
50
-
51
101
  ### Maintenance
52
102
 
53
103
  - **docs:** Update README with recent changes. ([92ad74b](https://github.com/Patternslib/dev/commit/92ad74ba9ad7192b14342b29a9c8d64c1ad8509e))
@@ -100,8 +150,6 @@
100
150
  in the actual release run. Also abort if the version cannot be
101
151
  determined.
102
152
 
103
- Assisted-by: Claude Opus 5.5
104
-
105
153
  - **Makefile:** Open sunburst stats.html directly in browser. ([fe885bf](https://github.com/Patternslib/dev/commit/fe885bfdf85b18e845f45ef67ba4e20f509dd540))
106
154
  - **webpack:** Fix test for loaders configured with resolved paths. ([5cf5071](https://github.com/Patternslib/dev/commit/5cf5071bfe5953004c1acd919149c196db62b1d1))
107
155
 
@@ -116,8 +164,6 @@
116
164
  style-loader. It now compares against the resolved path, and the
117
165
  resolveLoader workaround is no longer needed.
118
166
 
119
- Assisted-by: Claude Opus 5.5
120
-
121
167
  - **webpack:** Use imports relative to @patternslib/dev. ([b8032f1](https://github.com/Patternslib/dev/commit/b8032f1f108c30be1bdaadb5fba75ae2e3ab727f))
122
168
 
123
169
  Depending packages might not have all dependencies installed.
@@ -197,7 +243,7 @@
197
243
 
198
244
  ### Maintenance
199
245
 
200
- - Allow releases from alpha/* and beta/* branches, alongside to master, main and *.x. ([73c49fa](https://github.com/Patternslib/dev/commit/73c49fa2cb7d797626411da76f3b702f8e03a960))
246
+ - Allow releases from alpha/_and beta/_ branches, alongside to master, main and *.x. ([73c49fa](https://github.com/Patternslib/dev/commit/73c49fa2cb7d797626411da76f3b702f8e03a960))
201
247
  - Migrate handlebars changelog template to JavaScript render functions. ([a1685f9](https://github.com/Patternslib/dev/commit/a1685f9d84e7e36c6d2c1cc6426b454228ddf15d))
202
248
 
203
249
  Co-authored-by: Codex <noreply@openai.com>
@@ -260,10 +306,10 @@ projects do anyways, so this change is fine, IMO.
260
306
 
261
307
  The following problems are now fixed:
262
308
 
263
- * Whole history included in new changelog entries.
264
- * No dist/ published due to silent failures.
265
- * No GitHub release page updates.
266
- * No GutHub bundle zip upload.
309
+ - Whole history included in new changelog entries.
310
+ - No dist/ published due to silent failures.
311
+ - No GitHub release page updates.
312
+ - No GutHub bundle zip upload.
267
313
 
268
314
  ### Maintenance
269
315
 
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
- $(OPEN) stats.html || echo "Open stats.html in your browser."
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
- -rm $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip
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
- -git config --unset core.hooksPath
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,31 @@
1
+ # The `matchMedia` mock emulates a desktop device
2
+
3
+ Status: Accepted (2026-11-30)
4
+
5
+ ## Context
6
+
7
+ jsDOM does not implement `window.matchMedia`.
8
+ `jest/setup-tests.js` provides a mock for it, which until now returned `matches: false` for every media query.
9
+
10
+ TinyMCE 8.11 changed its touch device detection to `isTouch = isMobile || !matchMedia("(any-pointer:fine)")`.
11
+ With the mock, every query fails, so TinyMCE treats the jsDOM test environment as a touch device.
12
+ On touch devices TinyMCE disables the editor resize handle by default and adds the `tox-platform-touch` class.
13
+ This broke a TinyMCE test in Mockup which checks the translated label of the resize handle.
14
+
15
+ Other libraries use the same kind of check to switch between a touch and a desktop UI.
16
+ Our tests are written with a desktop browser in mind.
17
+
18
+ ## Decision
19
+
20
+ The `matchMedia` mock emulates a desktop device with a mouse.
21
+ The queries `(pointer:fine)`, `(any-pointer:fine)`, `(hover:hover)` and `(any-hover:hover)` match.
22
+ Whitespace in the query is ignored, so `(any-pointer: fine)` matches too.
23
+ All other queries still don't match.
24
+
25
+ ## Consequences
26
+
27
+ - Libraries which detect touch devices through pointer or hover media queries render their desktop UI in tests.
28
+ - Queries which don't match before, like `(prefers-reduced-motion: reduce)` or `(min-width: 768px)`, still don't match.
29
+ - Combined queries like `(pointer:fine) and (hover:hover)` don't match.
30
+ The mock does not parse media queries.
31
+ - Tests which relied on the touch UI in jsDOM need to override `window.matchMedia` themselves.
@@ -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.
@@ -102,11 +102,21 @@ Range.prototype.getBoundingClientRect = () => {
102
102
  return { x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0 };
103
103
  };
104
104
 
105
- // Originally from pat-tinymce.
105
+ // jsDOM does not implement ``matchMedia``. Originally from pat-tinymce.
106
+ // Emulate a desktop device with a mouse: pointer and hover queries for a fine
107
+ // pointer match, all other queries don't. Libraries like TinyMCE treat a device
108
+ // without a fine pointer as a touch device and change their UI accordingly.
109
+ // See: docs/adr/0002-match-media-mock-emulates-desktop.md
110
+ const desktop_media_features = [
111
+ "(pointer:fine)",
112
+ "(any-pointer:fine)",
113
+ "(hover:hover)",
114
+ "(any-hover:hover)",
115
+ ];
106
116
  Object.defineProperty(window, "matchMedia", {
107
117
  writable: true,
108
118
  value: jest.fn().mockImplementation((query) => ({
109
- matches: false,
119
+ matches: desktop_media_features.includes(query.replace(/\s+/g, "")),
110
120
  media: query,
111
121
  onchange: null,
112
122
  addListener: jest.fn(), // Deprecated
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternslib/dev",
3
- "version": "4.6.0",
3
+ "version": "4.7.0",
4
4
  "description": "Development base files for working with Patternslib and add-ons.",
5
5
  "license": "MIT",
6
6
  "packageManager": "pnpm@12.23.0",
@@ -1,3 +1,10 @@
1
+ function stripAttribution(text) {
2
+ return text
3
+ ?.replace(/^[ \t]*(?:Assisted[- ]by|Co-authored-by):[^\r\n]*(?:\r?\n|$)/gim, "")
4
+ .replace(/^(?:[ \t]*\r?\n)+/, "")
5
+ .trimEnd();
6
+ }
7
+
1
8
  // The preset adds the list marker and indents continuation lines.
2
9
  module.exports = function commitPartial(context, commit) {
3
10
  const repoUrl = context.repository
@@ -36,8 +43,8 @@ module.exports = function commitPartial(context, commit) {
36
43
 
37
44
  return [
38
45
  summary,
39
- commit.body,
40
- commit.footer,
46
+ stripAttribution(commit.body),
47
+ stripAttribution(commit.footer),
41
48
  references.length && `closes ${references.join(" ")}`,
42
49
  ]
43
50
  .filter(Boolean)
@@ -0,0 +1,129 @@
1
+ const commitPartial = require("../release-it/conventional-changelog-commit");
2
+
3
+ // Commit objects are shaped like the output of conventional-commits-parser
4
+ // with the conventionalcommits preset, which puts the first trailer-like line
5
+ // and everything after it into `footer`.
6
+ function render(commit, context = {}) {
7
+ return commitPartial(
8
+ { linkReferences: false, ...context },
9
+ { hash: "abc123", shortHash: "abc", subject: "Subject.", ...commit },
10
+ );
11
+ }
12
+
13
+ describe("conventional-changelog-commit", () => {
14
+ it("renders scope, subject and hash.", () => {
15
+ expect(render({ scope: "pat-x" })).toBe("**pat-x:** Subject. abc123");
16
+ });
17
+
18
+ it("renders body and footer as separate paragraphs.", () => {
19
+ expect(render({ body: "Body.", footer: "Ref: ADR 0003" })).toBe(
20
+ "Subject. abc123\n\nBody.\n\nRef: ADR 0003",
21
+ );
22
+ });
23
+
24
+ describe("attribution trailers", () => {
25
+ it("removes an Assisted-by footer.", () => {
26
+ expect(render({ body: "Body.", footer: "Assisted-by: GPT-6" })).toBe(
27
+ "Subject. abc123\n\nBody.",
28
+ );
29
+ });
30
+
31
+ it.each([
32
+ "Assisted-by",
33
+ "Assisted-By",
34
+ "ASSISTED-BY",
35
+ "Assisted by",
36
+ "assisted by",
37
+ ])("removes an '%s' line.", (key) => {
38
+ // The parser does not recognize "Assisted by:" as a footer
39
+ // token, so it ends up in the body.
40
+ expect(render({ body: `Body.\n\n${key}: X`, footer: null })).toBe(
41
+ "Subject. abc123\n\nBody.",
42
+ );
43
+ expect(render({ body: "Body.", footer: `${key}: X` })).toBe(
44
+ "Subject. abc123\n\nBody.",
45
+ );
46
+ });
47
+
48
+ it.each([
49
+ "Co-authored-by",
50
+ "Co-Authored-By",
51
+ "co-authored-by",
52
+ "CO-AUTHORED-BY",
53
+ ])("removes a '%s' line.", (key) => {
54
+ expect(
55
+ render({
56
+ body: "Body.",
57
+ footer: `${key}: Someone <someone@example.com>`,
58
+ }),
59
+ ).toBe("Subject. abc123\n\nBody.");
60
+ });
61
+
62
+ it("keeps lines which only mention attribution words.", () => {
63
+ expect(
64
+ render({ body: "Assisted by the new API.\nCo-authored-by convention." }),
65
+ ).toBe(
66
+ "Subject. abc123\n\nAssisted by the new API.\nCo-authored-by convention.",
67
+ );
68
+ });
69
+
70
+ it("leaves no empty paragraph if only trailers are present.", () => {
71
+ expect(render({ body: "", footer: "Assisted-by: GPT-6" })).toBe(
72
+ "Subject. abc123",
73
+ );
74
+ });
75
+
76
+ it("keeps other footer lines.", () => {
77
+ expect(
78
+ render({
79
+ body: "Body.",
80
+ footer: [
81
+ "Ref: ADR 0003",
82
+ "Signed-off-by: A <a@example.com>",
83
+ "Assisted-by: X",
84
+ "Co-authored-by: Y <y@example.com>",
85
+ ].join("\n"),
86
+ }),
87
+ ).toBe(
88
+ "Subject. abc123\n\nBody.\n\nRef: ADR 0003\nSigned-off-by: A <a@example.com>",
89
+ );
90
+ });
91
+
92
+ it("keeps a BREAKING CHANGE footer.", () => {
93
+ expect(
94
+ render({
95
+ body: "Body.",
96
+ footer: "BREAKING CHANGE: API removed.\n\nAssisted-by: X",
97
+ }),
98
+ ).toBe("Subject. abc123\n\nBody.\n\nBREAKING CHANGE: API removed.");
99
+ });
100
+
101
+ it("keeps paragraphs following a trailer.", () => {
102
+ expect(render({ body: "First.", footer: "Assisted-by: X\n\nSecond." })).toBe(
103
+ "Subject. abc123\n\nFirst.\n\nSecond.",
104
+ );
105
+ });
106
+
107
+ it("handles CRLF line endings.", () => {
108
+ expect(
109
+ render({ body: "Body.", footer: "Assisted-by: X\r\nRef: ADR 0003\r\n" }),
110
+ ).toBe("Subject. abc123\n\nBody.\n\nRef: ADR 0003");
111
+ });
112
+
113
+ it("removes trailers from the body.", () => {
114
+ expect(render({ body: "Body.\nAssisted-by: X", footer: null })).toBe(
115
+ "Subject. abc123\n\nBody.",
116
+ );
117
+ });
118
+ });
119
+
120
+ it("appends issue references.", () => {
121
+ expect(
122
+ render({
123
+ body: "Body.",
124
+ footer: "Assisted-by: X",
125
+ references: [{ issue: "12" }],
126
+ }),
127
+ ).toBe("Subject. abc123\n\nBody.\n\ncloses #12");
128
+ });
129
+ });
@@ -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: (stats.chunks || []).map((chunk) => ({
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
  `;