Skip to content
PatternslibPublic

About

Development base files for working with Patternslib and add-ons.

Topics

Resources

Stars

0 stars

Watchers

10 watching

Forks

Repository files navigation

Development helpers and config for Patternslib and add-ons.

This repository includes base files which are extended in Patternslib, Mockup or other projects.

It includes a Makefile which helps in installing, testing, building and releasing packages. The Makefile uses pnpm as package manager.

Using the Makefile in your project

Include the shared Makefile from your project's Makefile and repeat the install target there. On a fresh checkout, @patternslib/dev and its Makefile are not installed yet, so your project needs its own install target to bootstrap:

PNPM ?= npx pnpm

-include node_modules/@patternslib/dev/Makefile

.PHONY: install
pnpm-lock.yaml install:
	$(PNPM) install

Then run make install.

Makefile targets

User targets

Target Description
make install Install the dependencies with pnpm and set up the commitlint commit-msg git hook.
make update Update pnpm and the project dependencies on a new dependencies-update branch. See Updating dependencies.
make clean-dist Remove the dist/ directory.
make clean Remove dist/, node_modules/ and the bundle analysis files stats.json and stats.html.
make lint, make eslint Lint the src/ directory with ESLint.
make format, make prettier Format all files with Prettier.
make check, make test Run ESLint, then the test script from package.json.
make serve, make start Run the start script from package.json, e.g. a webpack dev server.
make watch Run the watch script from package.json.
make bundle, make build Clean dist/ and run the build script from package.json, if there is one. Runs the bundle-pre target first.
make release-major Release a new major version.
make release-minor Release a new minor version.
make release-patch Release a new patch version.
make prerelease-alpha Release a new alpha pre-release.
make prerelease-beta Release a new beta pre-release.

The test, start, watch and build scripts are not provided by @patternslib/dev. Define them in your project's package.json.

Releasing

The release targets clean and reinstall the project, run make check and then use release-it to bump the version, generate the changelog, tag, publish to npm and create a GitHub release.

  • To create GitHub releases, add a GITHUB_TOKEN to a .env file in your project. The Makefile reads .env automatically. See release-it GitHub releases and GitHub tokens.
  • 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. Include dist/ in the files list of your package.json, so that the bundle is also published to npm.

To run tasks before the bundle is built, extend the bundle-pre target in your Makefile. Use double colons, so that the base bundle-pre target is also run:

bundle-pre::
	-pnpm unlink --recursive
	pnpm install

Bundle analysis targets

These targets build the bundle with webpack and analyze the resulting stats.json. They need a build script in your project's package.json.

Target Description
make analyze-bundle-dependencies Show why each package was included in the bundle, using whybundled.
make analyze-bundle-treemap Show the bundle as treemap, using webpack-bundle-analyzer.
make analyze-bundle-sunburst Render the bundle as sunburst chart into stats.html and open it in the browser, using webpack-visualizer.

stats.json is rebuilt when pnpm-lock.yaml changes. To rebuild it after source changes, run make clean or delete stats.json.

Configuration variables

Override these variables in your Makefile or on the command line, e.g. make analyze-bundle-sunburst OPEN=firefox.

Variable Default Description
PNPM npx pnpm Command to run pnpm.
ESLINT npx eslint Command to run ESLint.
PRETTIER npx prettier Command to run Prettier.
WEBPACK_CONFIG webpack/webpack.config.js, if it exists (*) Webpack config used by the bundle analysis targets.
OPEN xdg-open, open on macOS Command to open stats.html in the browser.

(*) Otherwise no --config is passed and webpack-cli finds the config itself, e.g. webpack.config.js in the project root.

Updating dependencies

Run make update to update the dependencies in this or your dependent project.

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. The dependencies are updated interactively with pnpm update --latest --interactive. package.json must not have uncommitted changes. Finally, make update runs make upgrade to apply the upgrade steps of a possibly updated @patternslib/dev.

Upgrading

make update runs the upgrade steps automatically. If you updated @patternslib/dev in another way, run make upgrade in your project.

Each upgrade step creates its own commit. Current upgrades:

  • Remove the .husky directory in favor of git hooks.
  • Create eslint.config.js and remove the old .eslintrc.js.
  • Remove the build:stats script from package.json, replaced by make stats.json.
  • Add stats.json and stats.html to .gitignore.

The last two steps skip files with uncommitted changes and run again on the next upgrade.

Migrating a consuming package from Yarn to pnpm

@patternslib/dev switched from Yarn to pnpm in version 4.3.0. The shared Makefile uses pnpm for installation and for running the build, test and start scripts. Projects which still use Yarn should migrate:

  1. Pin the pnpm version you intend to use in your project's package.json:

    "packageManager": "pnpm@12.3.4",
  2. Add a pnpm-workspace.yaml file at the project's workspace root:

    # No nested node_modules for Module Federation.
    shamefullyHoist: true

    You might also want to include the following to allow to build "@patternslib/dev" and to include releases of "@patternslib/dev" which are younger than the "minimumReleaseAge":

    allowBuilds:
        "@patternslib/dev": true
    
    minimumReleaseAgeExclude:
        - "@patternslib/dev"

    For more information, see the pnpm configuration reference.

  3. Change the yarn references in your Makefile to use pnpm, as shown in Using the Makefile in your project.

    If you use yarn link or yarn unlink in your Makefile, update it to fit the new pnpm syntax.

  4. You might need to include pnpm in the transformIgnorePatterns field of your Jest configuration to make the tests pass. See this project's jest.config.js for an example.

  5. Update the CI configuration to use pnpm and its cache - see this project's .github/workflows/test.yml.

  6. Run make install, add pnpm-lock.yaml to the git repository and remove yarn.lock.

Code style

The release process based on release-it includes automatic changelog generation via conventional-commit, commitlint and a git pre-commit hook. Please check the code style guide for the commit specification!

About

Development base files for working with Patternslib and add-ons.

Topics

Resources

Stars

0 stars

Watchers

10 watching

Forks

Releases

Packages

Used by

Contributors

Languages