@patternslib/dev 4.4.0 → 4.5.1
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/AGENTS.md +75 -0
- package/CHANGES.md +100 -0
- package/Makefile +178 -56
- package/README.md +114 -20
- package/babel.config.js +7 -2
- package/package.json +14 -16
- package/src/webpack-assets.test.js +4 -4
- package/webpack/stats-sunburst.js +83 -0
- package/webpack/webpack.config.js +7 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @patternslib/dev
|
|
2
|
+
|
|
3
|
+
## About this project
|
|
4
|
+
|
|
5
|
+
This is the common development configuration files for Patternslib and related
|
|
6
|
+
projects like Pattern addons or Mockup.
|
|
7
|
+
|
|
8
|
+
## Architecture Decision Records
|
|
9
|
+
|
|
10
|
+
Record significant decisions made during agentic sessions as Architecture
|
|
11
|
+
Decision Records (ADRs) in `./docs/adr/`.
|
|
12
|
+
|
|
13
|
+
- Write an ADR when a session makes a non-trivial design, architecture or
|
|
14
|
+
styling decision, or a change whose reasoning is not obvious from the
|
|
15
|
+
code. Q&A, reviews and trivial fixes need none. If unsure, ask.
|
|
16
|
+
- Start with a draft ADR, so that it can be referenced from source commits.
|
|
17
|
+
- Multiple commits can reference one ADR.
|
|
18
|
+
- One ADR per decision, not per session. Write it when the decision is
|
|
19
|
+
implemented, before committing.
|
|
20
|
+
- File name: `NNNN-short-kebab-title.md`, numbered consecutively.
|
|
21
|
+
- Sections: title, `Status: <Proposed|Accepted|Superseded by NNNN> (YYYY-MM-DD)`,
|
|
22
|
+
Context, Decision, Consequences. See `0001-*.md` as an example.
|
|
23
|
+
- Unpushed ADRs may be rewritten freely. Once pushed, an accepted ADR is
|
|
24
|
+
only changed for typos and clarifications; to revise the decision, write
|
|
25
|
+
a new ADR and mark the old one `Superseded by NNNN`.
|
|
26
|
+
- If a source commit implements a decision documented in an ADR, reference that ADR in the commit message as:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
ORIGINAL COMMIT MESSAGE
|
|
30
|
+
|
|
31
|
+
Ref: ADR NNNN
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Commit messages
|
|
35
|
+
|
|
36
|
+
- We use a commitlint pre-commit hook. The message format is:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
<TYPE>(<COMPONENT>): <TITLE>
|
|
40
|
+
|
|
41
|
+
<MESSAGE>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- `<TYPE>`: One of: "breaking" (for breaking changes), "feat" (for features), fix (for bug fixes), tech (technical changes), maint (for maintenance work).
|
|
45
|
+
- `<COMPONENT>`: `pat-<PATTERNNAME>` for Pattern fixes, `core <MODULE_NAME>` for fixes in core.
|
|
46
|
+
|
|
47
|
+
- If a source commit implements a decision documented in an ADR, reference that ADR in the commit message as:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
ORIGINAL COMMIT MESSAGE
|
|
51
|
+
|
|
52
|
+
Ref: ADR NNNN
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- If a commit was done with significant help from someone else, append this to the commit message:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
ORIGINAL COMMIT MESSAGE
|
|
59
|
+
|
|
60
|
+
Co-Authored-By: NAME <EMAIL>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- If a commit was done with significant help from an AI, append this to the commit message:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
ORIGINAL COMMIT MESSAGE
|
|
67
|
+
|
|
68
|
+
Assisted-by: NAME
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Don't use `Co-Authored-By` for AI contributions, as for Plone and other projects we need a contributor agreement for commits and an AI cannot sign it.
|
|
72
|
+
|
|
73
|
+
`<NAME>` should be the Model name and version, e.g. `Claude Opus 5.5`. Don't include the email, it's not useful.
|
|
74
|
+
|
|
75
|
+
- Use these rules in order as they are defined here - first ADR, then scrum, then co-authored, then assisted references.
|
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,105 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.5.1](https://github.com/Patternslib/dev/compare/4.5.0...4.5.1) (2026-11-30)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- **Makefile:** Upgrade targets to remove build:stats and ignore stats files. ([a5f63f8](https://github.com/Patternslib/dev/commit/a5f63f8766b4cebaf82a6b27ce592a73627d22f2))
|
|
8
|
+
|
|
9
|
+
Add upgrade-remove-build-stats, which removes the obsolete build:stats
|
|
10
|
+
script from package.json in favor of make stats.json, and
|
|
11
|
+
upgrade-gitignore-stats, which adds stats.json and stats.html to
|
|
12
|
+
.gitignore. Both commit their change and skip files with uncommitted
|
|
13
|
+
changes, so that unrelated work is never committed.
|
|
14
|
+
|
|
15
|
+
Assisted-by: Claude Opus 5.5
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
- **Makefile:** Fall back to webpack-cli config discovery for bundle analysis. ([fd4918d](https://github.com/Patternslib/dev/commit/fd4918de0dbce20be20aa1f8fc4a7b50ec9793f0))
|
|
20
|
+
|
|
21
|
+
Assisted-by: Claude Opus 5.5
|
|
22
|
+
|
|
23
|
+
### Maintenance
|
|
24
|
+
|
|
25
|
+
- **docs:** Update README with recent changes. ([92ad74b](https://github.com/Patternslib/dev/commit/92ad74ba9ad7192b14342b29a9c8d64c1ad8509e))
|
|
26
|
+
- **Makefile:** Add a guard to stats.json to not analyze dev directly. ([c3a451d](https://github.com/Patternslib/dev/commit/c3a451d20f481113b5266134c70468c9d38a8b61))
|
|
27
|
+
|
|
28
|
+
@patternslib/dev has no build script, so it cannot be analyzed directly.
|
|
29
|
+
Print a informational message if the stats.json targed is called from
|
|
30
|
+
within @patternslib/dev.
|
|
31
|
+
|
|
32
|
+
## [4.5.0](https://github.com/Patternslib/dev/compare/4.4.0...4.5.0) (2026-11-30)
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
- **Makefile:** Add analyze-bundle-sunburst. ([920a460](https://github.com/Patternslib/dev/commit/920a460895fa7192a7b54d6f74025caca83cfa9b))
|
|
37
|
+
|
|
38
|
+
The dependency tree is displayed in a sunburst map, which gives a good
|
|
39
|
+
overview of which packages add the biggest weight.
|
|
40
|
+
|
|
41
|
+
- **Makefile:** Add new target name aliases. ([151324b](https://github.com/Patternslib/dev/commit/151324bca0ff1aa6a480214c6c51bfd49ed89f9d))
|
|
42
|
+
|
|
43
|
+
- start (alias for: serve)
|
|
44
|
+
- build (alias for: bundle)
|
|
45
|
+
- test (alias for: check)
|
|
46
|
+
- lint (alias for: eslint)
|
|
47
|
+
- format (alias for: prettier)
|
|
48
|
+
|
|
49
|
+
- **Makefile:** Add watch target - needs to be implemented in package.json. ([366cf3a](https://github.com/Patternslib/dev/commit/366cf3af46cb15e6fbde1ce3cfca7341505f3d2a))
|
|
50
|
+
- **Makefile:** New targets for bundle analyzing. ([5c57519](https://github.com/Patternslib/dev/commit/5c57519ae6ec09374aab2326c486d69afe821f9c))
|
|
51
|
+
|
|
52
|
+
This package's dependencies on whybundled and webpack-bundle-analyzer
|
|
53
|
+
have been removed. Instead, there are two new makefile targets:
|
|
54
|
+
|
|
55
|
+
- analyze-bundle-dependencies (whybundled)
|
|
56
|
+
- analyze-bundle-treemap (webpack-bundle-analyzer)
|
|
57
|
+
|
|
58
|
+
### Bug Fixes
|
|
59
|
+
|
|
60
|
+
- **Babel:** Use imports relative to @patternslib/dev. ([e591850](https://github.com/Patternslib/dev/commit/e591850a7205934c5a90a367d6292b8044ec98b3))
|
|
61
|
+
|
|
62
|
+
Depending packages might not have all dependencies installed.
|
|
63
|
+
|
|
64
|
+
- **Makefile:** Fix missing version in release bundle name when not logged in to npm. ([b90dc10](https://github.com/Patternslib/dev/commit/b90dc102adde0e3c35dbe97f781e34c4aae4a0de))
|
|
65
|
+
|
|
66
|
+
`release-it --release-version` runs in CI mode, where the npm plugin
|
|
67
|
+
cannot do the interactive login. When not logged in to npm it failed
|
|
68
|
+
silently, leaving PACKAGE_VERSION empty. The GitHub release asset was
|
|
69
|
+
then looked up as `<name>-bundle-.zip` and not uploaded.
|
|
70
|
+
|
|
71
|
+
Skip the npm checks when determining the version - they are still run
|
|
72
|
+
in the actual release run. Also abort if the version cannot be
|
|
73
|
+
determined.
|
|
74
|
+
|
|
75
|
+
Assisted-by: Claude Opus 5.5
|
|
76
|
+
|
|
77
|
+
- **Makefile:** Open sunburst stats.html directly in browser. ([fe885bf](https://github.com/Patternslib/dev/commit/fe885bfdf85b18e845f45ef67ba4e20f509dd540))
|
|
78
|
+
- **webpack:** Fix test for loaders configured with resolved paths. ([5cf5071](https://github.com/Patternslib/dev/commit/5cf5071bfe5953004c1acd919149c196db62b1d1))
|
|
79
|
+
|
|
80
|
+
The webpack and Babel configs now name their loaders and presets by the
|
|
81
|
+
resolved path from @patternslib/dev instead of a bare package name.
|
|
82
|
+
Webpack and Babel look up bare names from the consuming project, so a
|
|
83
|
+
build only worked if the project happened to have them, e.g. through
|
|
84
|
+
shamefully-hoist.
|
|
85
|
+
Resolved paths also work when @patternslib/dev is linked or not hoisted.
|
|
86
|
+
|
|
87
|
+
The test compared the loader by name, so it no longer removed the
|
|
88
|
+
style-loader. It now compares against the resolved path, and the
|
|
89
|
+
resolveLoader workaround is no longer needed.
|
|
90
|
+
|
|
91
|
+
Assisted-by: Claude Opus 5.5
|
|
92
|
+
|
|
93
|
+
- **webpack:** Use imports relative to @patternslib/dev. ([b8032f1](https://github.com/Patternslib/dev/commit/b8032f1f108c30be1bdaadb5fba75ae2e3ab727f))
|
|
94
|
+
|
|
95
|
+
Depending packages might not have all dependencies installed.
|
|
96
|
+
|
|
97
|
+
### Maintenance
|
|
98
|
+
|
|
99
|
+
- **Makefile:** Restructure and move all user-targeted targets on top. ([51cd1c2](https://github.com/Patternslib/dev/commit/51cd1c223b2020aee720d3fcfaed93f611977689))
|
|
100
|
+
- Update dependencies. ([8959b4f](https://github.com/Patternslib/dev/commit/8959b4ff9eeb7358b7d5571e7c65695d47701f85))
|
|
101
|
+
- Update pnpm. ([fda4f62](https://github.com/Patternslib/dev/commit/fda4f62a0f30cdc2c2991b5179bf6bc22cdd5c4d))
|
|
102
|
+
|
|
3
103
|
## [4.4.0](https://github.com/Patternslib/dev/compare/4.3.0...4.4.0) (2026-11-05)
|
|
4
104
|
|
|
5
105
|
### Features
|
package/Makefile
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# This Makefile is meant to be exported by Patternslib or Mockup packages.
|
|
2
2
|
|
|
3
|
+
# Directory of this Makefile - the @patternslib/dev package directory.
|
|
4
|
+
# Must be set before any other include.
|
|
5
|
+
# Use the real path, as pnpm symlinks node_modules/@patternslib/dev into
|
|
6
|
+
# node_modules/.pnpm/, where its dependencies are located.
|
|
7
|
+
DEV_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
|
8
|
+
|
|
3
9
|
# .evn include, mainly for a GITHUB_TOKEN.
|
|
4
10
|
-include .env
|
|
5
11
|
export
|
|
@@ -19,6 +25,20 @@ BUILDABLE := $(shell node -p "Boolean(require('./package.json').scripts?.build)"
|
|
|
19
25
|
PACKAGE_NAME := $(shell node -p "require('./package.json').name")
|
|
20
26
|
BUNDLE_NAME := $(subst @patternslib/,,$(subst @plone/,,$(PACKAGE_NAME)))
|
|
21
27
|
|
|
28
|
+
# Webpack config for the bundle analysis targets.
|
|
29
|
+
# Patternslib keeps it in webpack/webpack.config.js, most add-ons in the
|
|
30
|
+
# project root. If webpack/webpack.config.js doesn't exist, this is empty and
|
|
31
|
+
# no --config is passed. webpack-cli then uses its own discovery, which finds
|
|
32
|
+
# webpack.config.{js,mjs,cjs,ts,...} in the root or in .webpack/.
|
|
33
|
+
WEBPACK_CONFIG ?= $(wildcard webpack/webpack.config.js)
|
|
34
|
+
# Resolve webpack-cli relative to @patternslib/dev. webpack is a dependency of
|
|
35
|
+
# @patternslib/dev and pnpm doesn't link binaries of indirect dependencies
|
|
36
|
+
# into the consuming project's node_modules/.bin.
|
|
37
|
+
WEBPACK_CLI = node $(shell node -p "require.resolve('webpack-cli/bin/cli.js', {paths: ['$(DEV_DIR)']})")
|
|
38
|
+
|
|
39
|
+
##
|
|
40
|
+
## User targets
|
|
41
|
+
#
|
|
22
42
|
|
|
23
43
|
# Repeat this install target in consuming packages' Makefiles: on a fresh
|
|
24
44
|
# checkout, @patternslib/dev and this shared Makefile are not installed yet.
|
|
@@ -47,56 +67,151 @@ update:
|
|
|
47
67
|
-git commit package.json -m"maint: Update dependencies."
|
|
48
68
|
-git commit pnpm-lock.yaml -m"pnpm-lock.yaml: Update." -n
|
|
49
69
|
|
|
50
|
-
.git/hooks/commit-msg:
|
|
51
|
-
echo "npx commitlint --edit" > .git/hooks/commit-msg
|
|
52
|
-
chmod u+x .git/hooks/commit-msg
|
|
53
|
-
|
|
54
|
-
|
|
55
70
|
.PHONY: clean-dist
|
|
56
71
|
clean-dist:
|
|
57
72
|
rm -Rf dist/
|
|
58
73
|
|
|
59
|
-
|
|
60
74
|
.PHONY: clean
|
|
61
75
|
clean: clean-dist
|
|
62
|
-
rm -Rf node_modules/
|
|
63
|
-
|
|
76
|
+
rm -Rf node_modules/ stats.json stats.html
|
|
64
77
|
|
|
65
|
-
.PHONY: eslint
|
|
78
|
+
.PHONY: lint eslint
|
|
79
|
+
lint: eslint
|
|
66
80
|
eslint: install
|
|
67
81
|
$(ESLINT) ./src
|
|
68
82
|
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
.PHONY: format prettier
|
|
84
|
+
format: prettier
|
|
71
85
|
prettier: install
|
|
72
86
|
$(PRETTIER) --write .
|
|
73
87
|
|
|
74
|
-
|
|
75
|
-
.PHONY: check
|
|
88
|
+
# NOTE: Needs a package.json script. Not implemented here.
|
|
89
|
+
.PHONY: test check
|
|
90
|
+
test: check
|
|
76
91
|
check: install eslint
|
|
77
92
|
$(PNPM) run test
|
|
78
93
|
|
|
94
|
+
# NOTE: Needs a package.json script. Not implemented here.
|
|
95
|
+
.PHONY: start serve
|
|
96
|
+
start: serve
|
|
97
|
+
serve: install
|
|
98
|
+
$(PNPM) run start
|
|
79
99
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
@# Example: Unlink any linked dependencies.
|
|
85
|
-
@# bundle-pre::
|
|
86
|
-
@# -pnpm unlink --recursive
|
|
87
|
-
@# pnpm install
|
|
88
|
-
npx update-browserslist-db@latest
|
|
89
|
-
|
|
100
|
+
# NOTE: Needs a package.json script. Not implemented here.
|
|
101
|
+
.PHONY: watch
|
|
102
|
+
watch: install
|
|
103
|
+
$(PNPM) run watch
|
|
90
104
|
|
|
91
105
|
# Compile the bundle.
|
|
106
|
+
# NOTE: Needs a package.json script. Not implemented here.
|
|
92
107
|
# NOTE: When using the normal workflow - e.g. `make release-minor`, the
|
|
93
108
|
# relase-it config runs `make bundle` after the version bump.
|
|
94
|
-
.PHONY: bundle
|
|
109
|
+
.PHONY: build bundle
|
|
110
|
+
build: bundle
|
|
95
111
|
bundle: clean-dist bundle-pre install
|
|
96
112
|
ifeq ($(BUILDABLE),true)
|
|
97
113
|
$(PNPM) run build
|
|
98
114
|
endif
|
|
99
115
|
|
|
116
|
+
.PHONY: release-major
|
|
117
|
+
release-major:
|
|
118
|
+
$(MAKE) LEVEL=major release
|
|
119
|
+
|
|
120
|
+
.PHONY: release-minor
|
|
121
|
+
release-minor:
|
|
122
|
+
$(MAKE) LEVEL=minor release
|
|
123
|
+
|
|
124
|
+
.PHONY: release-patch
|
|
125
|
+
release-patch:
|
|
126
|
+
$(MAKE) LEVEL=patch release
|
|
127
|
+
|
|
128
|
+
.PHONY: prerelease-alpha
|
|
129
|
+
prerelease-alpha:
|
|
130
|
+
$(MAKE) LEVEL=alpha release
|
|
131
|
+
|
|
132
|
+
.PHONY: prerelease-beta
|
|
133
|
+
prerelease-beta:
|
|
134
|
+
$(MAKE) LEVEL=beta release
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
##
|
|
138
|
+
## Analyze
|
|
139
|
+
#
|
|
140
|
+
|
|
141
|
+
# Build stats.json. Rebuilt when pnpm-lock.yaml changes.
|
|
142
|
+
# Write to a temporary file first, so that a failed build doesn't leave a
|
|
143
|
+
# broken but up-to-date stats.json behind.
|
|
144
|
+
# With --json, webpack reports compilation errors only within the JSON output.
|
|
145
|
+
# On failure, print them before removing the temporary file.
|
|
146
|
+
# Packages without a build script (like @patternslib/dev itself) have no
|
|
147
|
+
# bundle to analyze. Stop early with a clear message instead of failing
|
|
148
|
+
# with a webpack configuration error.
|
|
149
|
+
stats.json: pnpm-lock.yaml
|
|
150
|
+
ifneq ($(BUILDABLE),true)
|
|
151
|
+
@echo "$(PACKAGE_NAME) has no build script in package.json - nothing to analyze." >&2
|
|
152
|
+
@exit 1
|
|
153
|
+
endif
|
|
154
|
+
NODE_ENV=production $(WEBPACK_CLI) $(if $(WEBPACK_CONFIG),--config $(WEBPACK_CONFIG)) --json > $@.tmp \
|
|
155
|
+
|| { \
|
|
156
|
+
node -e "try { for (const e of JSON.parse(require('fs').readFileSync('$@.tmp')).errors || []) console.error(e.message || e) } catch {}"; \
|
|
157
|
+
rm -f $@.tmp; \
|
|
158
|
+
exit 1; \
|
|
159
|
+
}
|
|
160
|
+
mv $@.tmp $@
|
|
161
|
+
|
|
162
|
+
# Use `pnpm dlx` instead of `npx`: npx might find a package in the dependency
|
|
163
|
+
# tree without a linked binary and then fail with "not found".
|
|
164
|
+
|
|
165
|
+
# https://github.com/d4rkr00t/whybundled
|
|
166
|
+
.PHONY: analyze-bundle-dependencies
|
|
167
|
+
analyze-bundle-dependencies: stats.json
|
|
168
|
+
$(PNPM) dlx whybundled stats.json
|
|
169
|
+
|
|
170
|
+
# https://github.com/webpack/webpack-bundle-analyzer
|
|
171
|
+
.PHONY: analyze-bundle-treemap
|
|
172
|
+
analyze-bundle-treemap: stats.json
|
|
173
|
+
$(PNPM) dlx webpack-bundle-analyzer stats.json
|
|
174
|
+
|
|
175
|
+
# https://github.com/jonamat/webpack-visualizer
|
|
176
|
+
# Maintained fork of https://github.com/chrisbateman/webpack-visualizer
|
|
177
|
+
# The webpack plugin isn't used. Only its prebuilt frontend is downloaded,
|
|
178
|
+
# which renders the existing stats.json as stats.html.
|
|
179
|
+
VISUALIZER_PACKAGE ?= webpack-visualizer-plugin2@2
|
|
180
|
+
VISUALIZER_DIR := node_modules/.cache/webpack-visualizer
|
|
181
|
+
|
|
182
|
+
$(VISUALIZER_DIR)/package/lib/main.js:
|
|
183
|
+
mkdir -p $(VISUALIZER_DIR)
|
|
184
|
+
cd $(VISUALIZER_DIR) && tar -xzf "$$(npm pack --silent $(VISUALIZER_PACKAGE))"
|
|
185
|
+
|
|
186
|
+
stats.html: stats.json $(VISUALIZER_DIR)/package/lib/main.js
|
|
187
|
+
node $(DEV_DIR)webpack/stats-sunburst.js $(VISUALIZER_DIR)/package stats.json $@
|
|
188
|
+
|
|
189
|
+
# Command to open a file in the default browser. Override with e.g.
|
|
190
|
+
# `make analyze-bundle-sunburst OPEN=firefox`.
|
|
191
|
+
OPEN ?= $(if $(filter Darwin,$(shell uname -s)),open,xdg-open)
|
|
192
|
+
|
|
193
|
+
.PHONY: analyze-bundle-sunburst
|
|
194
|
+
analyze-bundle-sunburst: stats.html
|
|
195
|
+
$(OPEN) stats.html || echo "Open stats.html in your browser."
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
##
|
|
199
|
+
## Helper targets
|
|
200
|
+
#
|
|
201
|
+
|
|
202
|
+
.git/hooks/commit-msg:
|
|
203
|
+
echo "npx commitlint --edit" > .git/hooks/commit-msg
|
|
204
|
+
chmod u+x .git/hooks/commit-msg
|
|
205
|
+
|
|
206
|
+
.PHONY: bundle-pre
|
|
207
|
+
bundle-pre::
|
|
208
|
+
@# Override this in your project to add some tasks before the bundle is built.
|
|
209
|
+
@# Please use double-colons `::` so that the base bundle-pre is also run.
|
|
210
|
+
@# Example: Unlink any linked dependencies.
|
|
211
|
+
@# bundle-pre::
|
|
212
|
+
@# -pnpm unlink --recursive
|
|
213
|
+
@# pnpm install
|
|
214
|
+
npx update-browserslist-db@latest
|
|
100
215
|
|
|
101
216
|
# Create a ZIP file from the bundle which is uploaded to the GitHub release tag.
|
|
102
217
|
# NOTE: When using the normal workflow - e.g. `make release-minor`, the
|
|
@@ -112,7 +227,6 @@ ifeq ($(BUILDABLE),true)
|
|
|
112
227
|
rm -Rf $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
|
|
113
228
|
endif
|
|
114
229
|
|
|
115
|
-
|
|
116
230
|
# Prepare some necessary variables.
|
|
117
231
|
.PHONY: prepare-release
|
|
118
232
|
prepare-release:
|
|
@@ -129,14 +243,18 @@ else
|
|
|
129
243
|
$(eval RELEASE_IT_LEVEL := $(LEVEL))
|
|
130
244
|
endif
|
|
131
245
|
|
|
132
|
-
|
|
133
246
|
# Note release-zip is run via the `after:bump` hook from .release-it.js, so
|
|
134
247
|
# that the build contains the correct version bump.
|
|
135
248
|
.PHONY: release
|
|
136
249
|
release: clean install check prepare-release
|
|
137
250
|
@# Note: The consuming package must include dist/ in its package.json files list.
|
|
138
251
|
|
|
139
|
-
|
|
252
|
+
@# Get the version to be released.
|
|
253
|
+
@# `--release-version` implies CI mode, where release-it cannot do the
|
|
254
|
+
@# interactive npm login and would fail with no output if not logged in.
|
|
255
|
+
@# Skip the npm checks here - they are done in the real release run below.
|
|
256
|
+
$(eval PACKAGE_VERSION := $(shell npx release-it $(RELEASE_IT_LEVEL) --release-version --npm.skipChecks))
|
|
257
|
+
$(if $(PACKAGE_VERSION),,$(error Could not determine the release version via release-it))
|
|
140
258
|
ifeq ($(BUILDABLE),true)
|
|
141
259
|
$(eval RELEASE_IT_GITHUB_OPTIONS += --github.assets=$(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip)
|
|
142
260
|
endif
|
|
@@ -153,40 +271,45 @@ endif
|
|
|
153
271
|
-rm $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip
|
|
154
272
|
|
|
155
273
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
.PHONY: release-minor
|
|
162
|
-
release-minor:
|
|
163
|
-
$(MAKE) LEVEL=minor release
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
.PHONY: release-patch
|
|
167
|
-
release-patch:
|
|
168
|
-
$(MAKE) LEVEL=patch release
|
|
169
|
-
|
|
170
|
-
.PHONY: prerelease-alpha
|
|
171
|
-
prerelease-alpha:
|
|
172
|
-
$(MAKE) LEVEL=alpha release
|
|
173
|
-
|
|
174
|
-
.PHONY: prerelease-beta
|
|
175
|
-
prerelease-beta:
|
|
176
|
-
$(MAKE) LEVEL=beta release
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
.PHONY: serve
|
|
180
|
-
serve: install
|
|
181
|
-
$(PNPM) run start
|
|
182
|
-
|
|
274
|
+
##
|
|
275
|
+
## Upgrades
|
|
276
|
+
#
|
|
183
277
|
|
|
184
278
|
upgrade:\
|
|
185
279
|
.git/hooks/commit-msg\
|
|
186
280
|
upgrade-remove-husky\
|
|
187
|
-
upgrade-eslint
|
|
281
|
+
upgrade-eslint\
|
|
282
|
+
upgrade-remove-build-stats\
|
|
283
|
+
upgrade-gitignore-stats
|
|
188
284
|
@# Upgrade target, depends on other upgrades
|
|
189
285
|
|
|
286
|
+
# The following upgrades only touch files without uncommitted changes, so
|
|
287
|
+
# that they never commit unrelated work. They run again on the next upgrade.
|
|
288
|
+
|
|
289
|
+
# The build:stats script is replaced by the stats.json target.
|
|
290
|
+
upgrade-remove-build-stats:
|
|
291
|
+
@if node -e "process.exit(require('./package.json').scripts?.['build:stats'] ? 0 : 1)"; then \
|
|
292
|
+
if git diff --quiet HEAD -- package.json 2>/dev/null; then \
|
|
293
|
+
npm pkg delete "scripts.build:stats" \
|
|
294
|
+
&& git commit package.json -m"maint: @patternslib/dev upgrade - remove build:stats script in favor of make stats.json."; \
|
|
295
|
+
else \
|
|
296
|
+
echo "Skipping removal of the build:stats script: package.json has uncommitted changes." >&2; \
|
|
297
|
+
fi; \
|
|
298
|
+
fi
|
|
299
|
+
|
|
300
|
+
# Ignore the generated bundle analysis files.
|
|
301
|
+
upgrade-gitignore-stats:
|
|
302
|
+
@if [ -f .gitignore ] && ! { grep -qxF stats.json .gitignore && grep -qxF stats.html .gitignore; }; then \
|
|
303
|
+
if git diff --quiet HEAD -- .gitignore 2>/dev/null; then \
|
|
304
|
+
[ -z "$$(tail -c1 .gitignore)" ] || echo >> .gitignore; \
|
|
305
|
+
for f in stats.json stats.html; do \
|
|
306
|
+
grep -qxF $$f .gitignore || echo $$f >> .gitignore; \
|
|
307
|
+
done \
|
|
308
|
+
&& git commit .gitignore -m"maint: @patternslib/dev upgrade - ignore stats.json and stats.html."; \
|
|
309
|
+
else \
|
|
310
|
+
echo "Skipping the stats.json/stats.html .gitignore update: .gitignore has uncommitted changes." >&2; \
|
|
311
|
+
fi; \
|
|
312
|
+
fi
|
|
190
313
|
|
|
191
314
|
upgrade-remove-husky:
|
|
192
315
|
test -d .husky\
|
|
@@ -196,7 +319,6 @@ upgrade-remove-husky:
|
|
|
196
319
|
|| :
|
|
197
320
|
-git config --unset core.hooksPath
|
|
198
321
|
|
|
199
|
-
|
|
200
322
|
eslint.config.js upgrade-eslint:
|
|
201
323
|
test -f "eslint.config.js"\
|
|
202
324
|
|| (\
|
package/README.md
CHANGED
|
@@ -2,25 +2,128 @@
|
|
|
2
2
|
|
|
3
3
|
This repository includes base files which are extended in Patternslib, Mockup or other projects.
|
|
4
4
|
|
|
5
|
-
It includes a Makefile which helps in installing and releasing packages.
|
|
5
|
+
It includes a Makefile which helps in installing, testing, building and releasing packages.
|
|
6
|
+
The Makefile uses [pnpm](https://pnpm.io/) as package manager.
|
|
7
|
+
|
|
8
|
+
## Using the Makefile in your project
|
|
9
|
+
|
|
10
|
+
Include the shared Makefile from your project's `Makefile` and repeat the `install` target there.
|
|
11
|
+
On a fresh checkout, `@patternslib/dev` and its Makefile are not installed yet, so your project needs its own `install` target to bootstrap:
|
|
12
|
+
|
|
13
|
+
```makefile
|
|
14
|
+
PNPM ?= npx pnpm
|
|
15
|
+
|
|
16
|
+
-include node_modules/@patternslib/dev/Makefile
|
|
17
|
+
|
|
18
|
+
.PHONY: install
|
|
19
|
+
pnpm-lock.yaml install:
|
|
20
|
+
$(PNPM) install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Then run `make install`.
|
|
24
|
+
|
|
25
|
+
## Makefile targets
|
|
26
|
+
|
|
27
|
+
### User targets
|
|
28
|
+
|
|
29
|
+
| Target | Description |
|
|
30
|
+
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
31
|
+
| `make install` | Install the dependencies with pnpm and set up the commitlint `commit-msg` git hook. |
|
|
32
|
+
| `make update` | Update pnpm and the project dependencies on a new `dependencies-update` branch. See [Updating dependencies](#updating-dependencies). |
|
|
33
|
+
| `make clean-dist` | Remove the `dist/` directory. |
|
|
34
|
+
| `make clean` | Remove `dist/`, `node_modules/` and the bundle analysis files `stats.json` and `stats.html`. |
|
|
35
|
+
| `make lint`, `make eslint` | Lint the `src/` directory with ESLint. |
|
|
36
|
+
| `make format`, `make prettier` | Format all files with Prettier. |
|
|
37
|
+
| `make check`, `make test` | Run ESLint, then the `test` script from `package.json`. |
|
|
38
|
+
| `make serve`, `make start` | Run the `start` script from `package.json`, e.g. a webpack dev server. |
|
|
39
|
+
| `make watch` | Run the `watch` script from `package.json`. |
|
|
40
|
+
| `make bundle`, `make build` | Clean `dist/` and run the `build` script from `package.json`, if there is one. Runs the `bundle-pre` target first. |
|
|
41
|
+
| `make release-major` | Release a new major version. |
|
|
42
|
+
| `make release-minor` | Release a new minor version. |
|
|
43
|
+
| `make release-patch` | Release a new patch version. |
|
|
44
|
+
| `make prerelease-alpha` | Release a new alpha pre-release. |
|
|
45
|
+
| `make prerelease-beta` | Release a new beta pre-release. |
|
|
46
|
+
|
|
47
|
+
The `test`, `start`, `watch` and `build` scripts are not provided by `@patternslib/dev`.
|
|
48
|
+
Define them in your project's `package.json`.
|
|
49
|
+
|
|
50
|
+
#### Releasing
|
|
51
|
+
|
|
52
|
+
The release targets clean and reinstall the project, run `make check` and then use [release-it](https://github.com/release-it/release-it) to bump the version, generate the changelog, tag, publish to npm and create a GitHub release.
|
|
53
|
+
|
|
54
|
+
- To create GitHub releases, add a `GITHUB_TOKEN` to a `.env` file in your project.
|
|
55
|
+
The Makefile reads `.env` automatically.
|
|
56
|
+
See [release-it GitHub releases](https://github.com/release-it/release-it/blob/master/docs/github-releases.md#automated) and [GitHub tokens](https://github.com/settings/tokens).
|
|
57
|
+
- If your project has a `build` script, the bundle is built after the version bump and attached to the GitHub release as `BUNDLENAME-bundle-VERSION.zip`.
|
|
58
|
+
Include `dist/` in the `files` list of your `package.json`, so that the bundle is also published to npm.
|
|
59
|
+
|
|
60
|
+
To run tasks before the bundle is built, extend the `bundle-pre` target in your Makefile.
|
|
61
|
+
Use double colons, so that the base `bundle-pre` target is also run:
|
|
62
|
+
|
|
63
|
+
```makefile
|
|
64
|
+
bundle-pre::
|
|
65
|
+
-pnpm unlink --recursive
|
|
66
|
+
pnpm install
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Bundle analysis targets
|
|
70
|
+
|
|
71
|
+
These targets build the bundle with webpack and analyze the resulting `stats.json`.
|
|
72
|
+
They need a `build` script in your project's `package.json`.
|
|
73
|
+
|
|
74
|
+
| Target | Description |
|
|
75
|
+
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
76
|
+
| `make analyze-bundle-dependencies` | Show why each package was included in the bundle, using [whybundled](https://github.com/d4rkr00t/whybundled). |
|
|
77
|
+
| `make analyze-bundle-treemap` | Show the bundle as treemap, using [webpack-bundle-analyzer](https://github.com/webpack/webpack-bundle-analyzer). |
|
|
78
|
+
| `make analyze-bundle-sunburst` | Render the bundle as sunburst chart into `stats.html` and open it in the browser, using [webpack-visualizer](https://github.com/jonamat/webpack-visualizer). |
|
|
79
|
+
|
|
80
|
+
`stats.json` is rebuilt when `pnpm-lock.yaml` changes.
|
|
81
|
+
To rebuild it after source changes, run `make clean` or delete `stats.json`.
|
|
82
|
+
|
|
83
|
+
### Configuration variables
|
|
84
|
+
|
|
85
|
+
Override these variables in your Makefile or on the command line, e.g. `make analyze-bundle-sunburst OPEN=firefox`.
|
|
86
|
+
|
|
87
|
+
| Variable | Default | Description |
|
|
88
|
+
| ---------------- | ---------------------------------------------- | --------------------------------------------------- |
|
|
89
|
+
| `PNPM` | `npx pnpm` | Command to run pnpm. |
|
|
90
|
+
| `ESLINT` | `npx eslint` | Command to run ESLint. |
|
|
91
|
+
| `PRETTIER` | `npx prettier` | Command to run Prettier. |
|
|
92
|
+
| `WEBPACK_CONFIG` | `webpack/webpack.config.js`, if it exists (\*) | Webpack config used by the bundle analysis targets. |
|
|
93
|
+
| `OPEN` | `xdg-open`, `open` on macOS | Command to open `stats.html` in the browser. |
|
|
94
|
+
|
|
95
|
+
(\*) Otherwise no `--config` is passed and webpack-cli finds the config itself, e.g. `webpack.config.js` in the project root.
|
|
6
96
|
|
|
7
97
|
## Updating dependencies
|
|
8
98
|
|
|
9
99
|
Run `make update` to update the dependencies in this or your dependent project.
|
|
10
100
|
|
|
101
|
+
It creates a `dependencies-update` branch and makes up to three separate commits: one for the pnpm update, one for the updated dependencies in `package.json`, and one for `pnpm-lock.yaml`.
|
|
102
|
+
The dependencies are updated interactively with `pnpm update --latest --interactive`.
|
|
103
|
+
`package.json` must not have uncommitted changes.
|
|
104
|
+
|
|
11
105
|
## Upgrading
|
|
12
106
|
|
|
13
107
|
Run `make upgrade` in your project.
|
|
14
108
|
|
|
15
109
|
Alternatively, if there is a new `@patternslib/dev` version installed, the `postinstall` package.json script will automatically run `make upgrade` in the directory where package installer was invoked, that is your project directory which depends on `@patternslib/dev`.
|
|
16
110
|
|
|
17
|
-
|
|
111
|
+
Each upgrade step creates its own commit. Current upgrades:
|
|
112
|
+
|
|
113
|
+
- Remove the `.husky` directory in favor of git hooks.
|
|
114
|
+
- Create `eslint.config.js` and remove the old `.eslintrc.js`.
|
|
115
|
+
- Remove the `build:stats` script from `package.json`, replaced by `make stats.json`.
|
|
116
|
+
- Add `stats.json` and `stats.html` to `.gitignore`.
|
|
117
|
+
|
|
118
|
+
The last two steps skip files with uncommitted changes and run again on the next upgrade.
|
|
18
119
|
|
|
19
|
-
|
|
20
|
-
If you choose to migrate, update the consuming project's configuration and workflows explicitly.
|
|
21
|
-
The shared Makefile uses pnpm for installation and for running build, test, and start scripts.
|
|
120
|
+
## Migrating a consuming package from Yarn to pnpm
|
|
22
121
|
|
|
23
|
-
|
|
122
|
+
`@patternslib/dev` switched from Yarn to pnpm in version 4.3.0.
|
|
123
|
+
The shared Makefile uses pnpm for installation and for running the build, test and start scripts.
|
|
124
|
+
Projects which still use Yarn should migrate:
|
|
125
|
+
|
|
126
|
+
1. Pin the pnpm version you intend to use in your project's `package.json`:
|
|
24
127
|
|
|
25
128
|
```json
|
|
26
129
|
"packageManager": "pnpm@12.3.4",
|
|
@@ -45,23 +148,14 @@ The shared Makefile uses pnpm for installation and for running build, test, and
|
|
|
45
148
|
|
|
46
149
|
For more information, see the [pnpm configuration reference](https://pnpm.io/settings).
|
|
47
150
|
|
|
48
|
-
3. Change the `yarn` references in
|
|
49
|
-
|
|
50
|
-
```makefile
|
|
51
|
-
PNPM ?= npx pnpm
|
|
52
|
-
|
|
53
|
-
-include node_modules/@patternslib/dev/Makefile
|
|
54
|
-
|
|
55
|
-
.PHONY: install
|
|
56
|
-
pnpm-lock.yaml install:
|
|
57
|
-
$(PNPM) install
|
|
58
|
-
```
|
|
151
|
+
3. Change the `yarn` references in your Makefile to use `pnpm`, as shown in [Using the Makefile in your project](#using-the-makefile-in-your-project).
|
|
59
152
|
|
|
60
|
-
If you use `yarn link` or `yarn unlink` in your Makefile, update it to fit the new [pnpm syntax](https://pnpm.io/cli/link).
|
|
153
|
+
If you use `yarn link` or `yarn unlink` in your Makefile, update it to fit the new [pnpm syntax](https://pnpm.io/cli/link).
|
|
61
154
|
|
|
62
|
-
4. You might need to include pnpm
|
|
155
|
+
4. You might need to include pnpm in the `transformIgnorePatterns` field of your Jest configuration to make the tests pass.
|
|
156
|
+
See this project's `jest.config.js` for an example.
|
|
63
157
|
|
|
64
|
-
5. Update the CI configuration to use
|
|
158
|
+
5. Update the CI configuration to use pnpm and its cache - see this project's `.github/workflows/test.yml`.
|
|
65
159
|
|
|
66
160
|
6. Run `make install`, add `pnpm-lock.yaml` to the git repository and remove `yarn.lock`.
|
|
67
161
|
|
package/babel.config.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
// Resolve the preset from @patternslib/dev. Babel resolves preset names
|
|
2
|
+
// relative to the consuming project's config file, which might not have it
|
|
3
|
+
// installed - e.g. when @patternslib/dev is linked or not hoisted.
|
|
4
|
+
const preset_env = require.resolve("@babel/preset-env");
|
|
5
|
+
|
|
1
6
|
module.exports = (api) => {
|
|
2
7
|
let config = {
|
|
3
8
|
presets: [
|
|
4
9
|
[
|
|
5
|
-
|
|
10
|
+
preset_env,
|
|
6
11
|
{
|
|
7
12
|
modules: "auto",
|
|
8
13
|
},
|
|
@@ -16,7 +21,7 @@ module.exports = (api) => {
|
|
|
16
21
|
config = {
|
|
17
22
|
presets: [
|
|
18
23
|
[
|
|
19
|
-
|
|
24
|
+
preset_env,
|
|
20
25
|
{
|
|
21
26
|
debug: true,
|
|
22
27
|
modules: false,
|
package/package.json
CHANGED
|
@@ -1,38 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternslib/dev",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"description": "Development base files for working with Patternslib and add-ons.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"packageManager": "pnpm@12.
|
|
6
|
+
"packageManager": "pnpm@12.23.0",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@babel/core": "^8.1.
|
|
9
|
-
"@babel/preset-env": "^8.
|
|
10
|
-
"@commitlint/cli": "^21.
|
|
11
|
-
"@commitlint/config-conventional": "^21.
|
|
8
|
+
"@babel/core": "^8.1.4",
|
|
9
|
+
"@babel/preset-env": "^8.1.4",
|
|
10
|
+
"@commitlint/cli": "^21.3.0",
|
|
11
|
+
"@commitlint/config-conventional": "^21.3.0",
|
|
12
12
|
"@eslint/js": "^10.0.1",
|
|
13
13
|
"@release-it/conventional-changelog": "^12.0.2",
|
|
14
14
|
"babel-loader": "^10.1.1",
|
|
15
15
|
"css-loader": "^7.1.5",
|
|
16
|
-
"eslint": "^10.
|
|
17
|
-
"eslint-config-prettier": "^10.1.
|
|
16
|
+
"eslint": "^10.16.0",
|
|
17
|
+
"eslint-config-prettier": "^10.1.9",
|
|
18
18
|
"globals": "^17.14.0",
|
|
19
19
|
"identity-obj-proxy": "^3.0.0",
|
|
20
20
|
"jest": "^30.5.2",
|
|
21
21
|
"jest-environment-jsdom": "^30.5.2",
|
|
22
22
|
"jest-watch-typeahead": "^3.0.1",
|
|
23
|
-
"prettier": "^3.
|
|
23
|
+
"prettier": "^3.10.1",
|
|
24
24
|
"regenerator-runtime": "^0.14.1",
|
|
25
|
-
"release-it": "^21.1.
|
|
26
|
-
"sass": "^1.
|
|
27
|
-
"sass-loader": "^17.1.
|
|
25
|
+
"release-it": "^21.1.3",
|
|
26
|
+
"sass": "^1.108.2",
|
|
27
|
+
"sass-loader": "^17.1.1",
|
|
28
28
|
"style-loader": "^4.0.0",
|
|
29
29
|
"terser-webpack-plugin": "^5.6.1",
|
|
30
30
|
"timezone-mock": "^1.4.3",
|
|
31
|
-
"webpack": "^5.
|
|
32
|
-
"webpack-bundle-analyzer": "^5.4.1",
|
|
31
|
+
"webpack": "^5.113.0",
|
|
33
32
|
"webpack-cli": "^7.3.1",
|
|
34
|
-
"webpack-dev-server": "^6.1.0"
|
|
35
|
-
"whybundled": "^2.0.0"
|
|
33
|
+
"webpack-dev-server": "^6.1.0"
|
|
36
34
|
},
|
|
37
35
|
"engines": {
|
|
38
36
|
"node": "^22.18.0 || >=24.11.0"
|
|
@@ -50,12 +50,12 @@ it("builds SVG URL dependencies as files while preserving raw SVG imports", () =
|
|
|
50
50
|
publicPath: "https://example.test/assets/",
|
|
51
51
|
library: { type: "commonjs2" },
|
|
52
52
|
};
|
|
53
|
-
config.resolveLoader = {
|
|
54
|
-
modules: [path.resolve("node_modules")],
|
|
55
|
-
};
|
|
56
53
|
// Export the CSS string instead of injecting a style tag.
|
|
54
|
+
// Loaders are configured with their resolved paths.
|
|
57
55
|
const cssRule = config.module.rules.find(rule => rule.test.test("style.css"));
|
|
58
|
-
cssRule.use = cssRule.use.filter(
|
|
56
|
+
cssRule.use = cssRule.use.filter(
|
|
57
|
+
item => item.loader !== require.resolve("style-loader"),
|
|
58
|
+
);
|
|
59
59
|
const compiler = webpack(config);
|
|
60
60
|
compiler.run((error, stats) => {
|
|
61
61
|
compiler.close(closeError => {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Render a webpack stats.json file as a sunburst chart.
|
|
2
|
+
//
|
|
3
|
+
// Uses the prebuilt, self-contained frontend of webpack-visualizer-plugin2
|
|
4
|
+
// (https://github.com/jonamat/webpack-visualizer, a maintained fork of
|
|
5
|
+
// https://github.com/chrisbateman/webpack-visualizer) without having to add
|
|
6
|
+
// the plugin to the webpack configuration or to install its dependencies.
|
|
7
|
+
//
|
|
8
|
+
// Usage:
|
|
9
|
+
// node stats-sunburst.js VISUALIZER_PACKAGE_DIR STATS_JSON OUTPUT_HTML
|
|
10
|
+
//
|
|
11
|
+
// The stats are reduced to the data which is needed by the chart. A full
|
|
12
|
+
// stats.json can easily be a few hundred megabytes, which is too much to be
|
|
13
|
+
// embedded in a HTML page.
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const path = require("path");
|
|
16
|
+
|
|
17
|
+
const [visualizer_dir, stats_file, output_file] = process.argv.slice(2);
|
|
18
|
+
if (!visualizer_dir || !stats_file || !output_file) {
|
|
19
|
+
console.error(
|
|
20
|
+
"Usage: node stats-sunburst.js VISUALIZER_PACKAGE_DIR STATS_JSON OUTPUT_HTML",
|
|
21
|
+
);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const stats = JSON.parse(fs.readFileSync(stats_file, "utf8"));
|
|
26
|
+
|
|
27
|
+
// Return the modules with the fields used by the chart.
|
|
28
|
+
// Concatenated modules (e.g. "./src/index.js + 2 modules") are replaced by
|
|
29
|
+
// their individual modules, so that they show up at their real location.
|
|
30
|
+
const reduce_modules = (modules = []) =>
|
|
31
|
+
modules.flatMap((module) =>
|
|
32
|
+
module.modules
|
|
33
|
+
? reduce_modules(module.modules)
|
|
34
|
+
: [
|
|
35
|
+
{
|
|
36
|
+
id: module.id,
|
|
37
|
+
identifier: module.identifier,
|
|
38
|
+
issuer: module.issuer,
|
|
39
|
+
index: module.index,
|
|
40
|
+
name: module.name,
|
|
41
|
+
size: module.size,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const reduced_stats = {
|
|
47
|
+
assets: (stats.assets || []).map((asset) => ({
|
|
48
|
+
name: asset.name,
|
|
49
|
+
chunks: asset.chunks,
|
|
50
|
+
})),
|
|
51
|
+
chunks: (stats.chunks || []).map((chunk) => ({
|
|
52
|
+
id: chunk.id,
|
|
53
|
+
modules: reduce_modules(chunk.modules),
|
|
54
|
+
})),
|
|
55
|
+
modules: reduce_modules(stats.modules),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const read = (file) => fs.readFileSync(path.join(visualizer_dir, "lib", file), "utf8");
|
|
59
|
+
|
|
60
|
+
// Escape "<" and ">" like the original plugin, so that the stats cannot
|
|
61
|
+
// close the script tag.
|
|
62
|
+
const stats_string = JSON.stringify(reduced_stats)
|
|
63
|
+
.replace(/</g, "<")
|
|
64
|
+
.replace(/>/g, ">");
|
|
65
|
+
|
|
66
|
+
const html = `<!DOCTYPE html>
|
|
67
|
+
<html lang="en">
|
|
68
|
+
<head>
|
|
69
|
+
<meta charset="UTF-8">
|
|
70
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
71
|
+
<title>Webpack Visualizer - ${path.basename(path.resolve(stats_file, "../"))}</title>
|
|
72
|
+
<style>${read("style.css")}</style>
|
|
73
|
+
</head>
|
|
74
|
+
<body>
|
|
75
|
+
<div id="App"></div>
|
|
76
|
+
<script>window.stats = ${stats_string};</script>
|
|
77
|
+
<script>${read("main.js")}</script>
|
|
78
|
+
</body>
|
|
79
|
+
</html>
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
fs.writeFileSync(output_file, html);
|
|
83
|
+
console.log(`Sunburst chart written to: ${path.resolve(output_file)}`);
|
|
@@ -48,32 +48,35 @@ const config_factory = (env, argv, config, babel_include = [], package_json) =>
|
|
|
48
48
|
},
|
|
49
49
|
optimization: {},
|
|
50
50
|
module: {
|
|
51
|
+
// Loaders are resolved from @patternslib/dev and not from the
|
|
52
|
+
// consuming project, which might not have them installed - e.g.
|
|
53
|
+
// when @patternslib/dev is linked or not hoisted.
|
|
51
54
|
rules: [
|
|
52
55
|
{
|
|
53
56
|
test: /\.js$/,
|
|
54
57
|
// Exclude node modules except patternslib, pat-* and mockup packgages.
|
|
55
58
|
// Allows for extending this file without needing to override for a successful webpack build.
|
|
56
59
|
exclude: new RegExp(babel_exclude),
|
|
57
|
-
loader: "babel-loader",
|
|
60
|
+
loader: require.resolve("babel-loader"),
|
|
58
61
|
},
|
|
59
62
|
{
|
|
60
63
|
test: /\.(?:sass|scss|css)$/i,
|
|
61
64
|
use: [
|
|
62
65
|
{
|
|
63
|
-
loader: "style-loader",
|
|
66
|
+
loader: require.resolve("style-loader"),
|
|
64
67
|
options: {
|
|
65
68
|
insert: require.resolve("./style-inserter"),
|
|
66
69
|
},
|
|
67
70
|
},
|
|
68
71
|
{
|
|
69
|
-
loader: "css-loader",
|
|
72
|
+
loader: require.resolve("css-loader"),
|
|
70
73
|
options: {
|
|
71
74
|
// production: false, others: loader defaults
|
|
72
75
|
sourceMap: is_production ? false : undefined,
|
|
73
76
|
},
|
|
74
77
|
},
|
|
75
78
|
{
|
|
76
|
-
loader: "sass-loader",
|
|
79
|
+
loader: require.resolve("sass-loader"),
|
|
77
80
|
options: {
|
|
78
81
|
// production: false, others: loader defaults
|
|
79
82
|
sourceMap: is_production ? false : undefined,
|