Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
.env
dist/
node_modules/
stats.html
stats.json
pat-*
86 changes: 67 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# This Makefile is meant to be exported by Patternslib or Mockup packages.

# Directory of this Makefile - the @patternslib/dev package directory.
# Must be set before any other include.
# Use the real path, as pnpm symlinks node_modules/@patternslib/dev into
# node_modules/.pnpm/, where its dependencies are located.
DEV_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))

# .evn include, mainly for a GITHUB_TOKEN.
-include .env
export
Expand All @@ -19,6 +25,12 @@ BUILDABLE := $(shell node -p "Boolean(require('./package.json').scripts?.build)"
PACKAGE_NAME := $(shell node -p "require('./package.json').name")
BUNDLE_NAME := $(subst @patternslib/,,$(subst @plone/,,$(PACKAGE_NAME)))

WEBPACK_CONFIG ?= webpack/webpack.config.js
# Resolve webpack-cli relative to @patternslib/dev. webpack is a dependency of
# @patternslib/dev and pnpm doesn't link binaries of indirect dependencies
# into the consuming project's node_modules/.bin.
WEBPACK_CLI = node $(shell node -p "require.resolve('webpack-cli/bin/cli.js', {paths: ['$(DEV_DIR)']})")

##
## User targets
#
Expand Down Expand Up @@ -50,49 +62,41 @@ update:
-git commit package.json -m"maint: Update dependencies."
-git commit pnpm-lock.yaml -m"pnpm-lock.yaml: Update." -n


.PHONY: clean-dist
clean-dist:
rm -Rf dist/


.PHONY: clean
clean: clean-dist
rm -Rf node_modules/

rm -Rf node_modules/ stats.json stats.html

.PHONY: lint eslint
lint: eslint
eslint: install
$(ESLINT) ./src


.PHONY: format prettier
format: prettier
prettier: install
$(PRETTIER) --write .


# NOTE: Needs a package.json script. Not implemented here.
.PHONY: test check
test: check
check: install eslint
$(PNPM) run test


# NOTE: Needs a package.json script. Not implemented here.
.PHONY: start serve
start: serve
serve: install
$(PNPM) run start


# NOTE: Needs a package.json script. Not implemented here.
.PHONY: watch
watch: install
$(PNPM) run watch


# Compile the bundle.
# NOTE: Needs a package.json script. Not implemented here.
# NOTE: When using the normal workflow - e.g. `make release-minor`, the
Expand All @@ -108,12 +112,10 @@ endif
release-major:
$(MAKE) LEVEL=major release


.PHONY: release-minor
release-minor:
$(MAKE) LEVEL=minor release


.PHONY: release-patch
release-patch:
$(MAKE) LEVEL=patch release
Expand All @@ -128,15 +130,67 @@ prerelease-beta:


##
## Helper targets
## Analyze
#

# Build stats.json. Rebuilt when pnpm-lock.yaml changes.
# Write to a temporary file first, so that a failed build doesn't leave a
# broken but up-to-date stats.json behind.
# With --json, webpack reports compilation errors only within the JSON output.
# On failure, print them before removing the temporary file.
stats.json: pnpm-lock.yaml
NODE_ENV=production $(WEBPACK_CLI) --config $(WEBPACK_CONFIG) --json > $@.tmp \
|| { \
node -e "try { for (const e of JSON.parse(require('fs').readFileSync('$@.tmp')).errors || []) console.error(e.message || e) } catch {}"; \
rm -f $@.tmp; \
exit 1; \
}
mv $@.tmp $@

# Use `pnpm dlx` instead of `npx`: npx might find a package in the dependency
# tree without a linked binary and then fail with "not found".

# https://github.com/d4rkr00t/whybundled
.PHONY: analyze-bundle-dependencies
analyze-bundle-dependencies: stats.json
$(PNPM) dlx whybundled stats.json

# https://github.com/webpack/webpack-bundle-analyzer
.PHONY: analyze-bundle-treemap
analyze-bundle-treemap: stats.json
$(PNPM) dlx webpack-bundle-analyzer stats.json

# https://github.com/jonamat/webpack-visualizer
# Maintained fork of https://github.com/chrisbateman/webpack-visualizer
# The webpack plugin isn't used. Only its prebuilt frontend is downloaded,
# which renders the existing stats.json as stats.html.
VISUALIZER_PACKAGE ?= webpack-visualizer-plugin2@2
VISUALIZER_DIR := node_modules/.cache/webpack-visualizer

$(VISUALIZER_DIR)/package/lib/main.js:
mkdir -p $(VISUALIZER_DIR)
cd $(VISUALIZER_DIR) && tar -xzf "$$(npm pack --silent $(VISUALIZER_PACKAGE))"

stats.html: stats.json $(VISUALIZER_DIR)/package/lib/main.js
node $(DEV_DIR)webpack/stats-sunburst.js $(VISUALIZER_DIR)/package stats.json $@

# Command to open a file in the default browser. Override with e.g.
# `make analyze-bundle-sunburst OPEN=firefox`.
OPEN ?= $(if $(filter Darwin,$(shell uname -s)),open,xdg-open)

.PHONY: analyze-bundle-sunburst
analyze-bundle-sunburst: stats.html
$(OPEN) stats.html || echo "Open stats.html in your browser."


##
## Helper targets
#

.git/hooks/commit-msg:
echo "npx commitlint --edit" > .git/hooks/commit-msg
chmod u+x .git/hooks/commit-msg


.PHONY: bundle-pre
bundle-pre::
@# Override this in your project to add some tasks before the bundle is built.
Expand All @@ -147,7 +201,6 @@ bundle-pre::
@# pnpm install
npx update-browserslist-db@latest


# Create a ZIP file from the bundle which is uploaded to the GitHub release tag.
# NOTE: When using the normal workflow - e.g. `make release-minor`, the
# relase-it config runs `make release-zip` after the version bump and `make bundle`.
Expand All @@ -162,7 +215,6 @@ ifeq ($(BUILDABLE),true)
rm -Rf $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
endif


# Prepare some necessary variables.
.PHONY: prepare-release
prepare-release:
Expand All @@ -179,7 +231,6 @@ else
$(eval RELEASE_IT_LEVEL := $(LEVEL))
endif


# Note release-zip is run via the `after:bump` hook from .release-it.js, so
# that the build contains the correct version bump.
.PHONY: release
Expand Down Expand Up @@ -212,14 +263,12 @@ endif
## Upgrades
#


upgrade:\
.git/hooks/commit-msg\
upgrade-remove-husky\
upgrade-eslint
@# Upgrade target, depends on other upgrades


upgrade-remove-husky:
test -d .husky\
&& rm -R .husky\
Expand All @@ -228,7 +277,6 @@ upgrade-remove-husky:
|| :
-git config --unset core.hooksPath


eslint.config.js upgrade-eslint:
test -f "eslint.config.js"\
|| (\
Expand Down
9 changes: 7 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// Resolve the preset from @patternslib/dev. Babel resolves preset names
// relative to the consuming project's config file, which might not have it
// installed - e.g. when @patternslib/dev is linked or not hoisted.
const preset_env = require.resolve("@babel/preset-env");

module.exports = (api) => {
let config = {
presets: [
[
"@babel/preset-env",
preset_env,
{
modules: "auto",
},
Expand All @@ -16,7 +21,7 @@ module.exports = (api) => {
config = {
presets: [
[
"@babel/preset-env",
preset_env,
{
debug: true,
modules: false,
Expand Down
28 changes: 13 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,34 @@
"version": "4.4.0",
"description": "Development base files for working with Patternslib and add-ons.",
"license": "MIT",
"packageManager": "pnpm@12.16.1",
"packageManager": "pnpm@12.23.0",
"dependencies": {
"@babel/core": "^8.1.0",
"@babel/preset-env": "^8.0.7",
"@commitlint/cli": "^21.2.4",
"@commitlint/config-conventional": "^21.2.4",
"@babel/core": "^8.1.4",
"@babel/preset-env": "^8.1.4",
"@commitlint/cli": "^21.3.0",
"@commitlint/config-conventional": "^21.3.0",
"@eslint/js": "^10.0.1",
"@release-it/conventional-changelog": "^12.0.2",
"babel-loader": "^10.1.1",
"css-loader": "^7.1.5",
"eslint": "^10.14.0",
"eslint-config-prettier": "^10.1.8",
"eslint": "^10.16.0",
"eslint-config-prettier": "^10.1.9",
"globals": "^17.14.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^30.5.2",
"jest-environment-jsdom": "^30.5.2",
"jest-watch-typeahead": "^3.0.1",
"prettier": "^3.9.10",
"prettier": "^3.10.1",
"regenerator-runtime": "^0.14.1",
"release-it": "^21.1.2",
"sass": "^1.107.1",
"sass-loader": "^17.1.0",
"release-it": "^21.1.3",
"sass": "^1.108.2",
"sass-loader": "^17.1.1",
"style-loader": "^4.0.0",
"terser-webpack-plugin": "^5.6.1",
"timezone-mock": "^1.4.3",
"webpack": "^5.112.2",
"webpack-bundle-analyzer": "^5.4.1",
"webpack": "^5.113.0",
"webpack-cli": "^7.3.1",
"webpack-dev-server": "^6.1.0",
"whybundled": "^2.0.0"
"webpack-dev-server": "^6.1.0"
},
"engines": {
"node": "^22.18.0 || >=24.11.0"
Expand Down
Loading