ci(packages): add npm version lifecycle hooks to releasable packages - #132
Open
elycruz wants to merge 1 commit into
Open
ci(packages): add npm version lifecycle hooks to releasable packages#132elycruz wants to merge 1 commit into
elycruz wants to merge 1 commit into
Conversation
Adds `preversion`/`version`/`postversion` hooks to the three releasable packages (fjl, fjl-validator, fjl-inputfilter), plus `node_scripts/tasks/version.mjs` and `md/RELEASING.md`. The hooks are adapted to this repo rather than copied from npm's docs: jest and rollup are configured once at the repo root, so the hooks call back with `pnpm -w run <script>`; `**/dist` is gitignored, so the build runs as a gate rather than to stage anything. `npm version` (which pnpm 8.13.1 delegates to) only does git work when `.git` sits directly in its cwd - `@npmcli/git`'s `is()` never walks up - so inside `packages/<name>` it skips its clean-tree guard, the release commit, and the tag. `version.mjs` restores those two steps and tags package-qualified (`fjl@2.0.0-alpha.6`) to avoid sibling collisions. fjl-validator-recaptcha, fjl-filter, and fjl-labs are deliberately left alone; reasons are documented in md/RELEASING.md. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds npm's
preversion/version/postversionlifecycle hooks to the threereleasable packages so that a version bump is gated by tests and a build, and
produces a proper release commit + tag.
Closes #101
Work unit:
101-npm-version-scriptsChanges
packages/fjl/package.json,packages/fjl-validator/package.json,packages/fjl-inputfilter/package.json— added the three lifecycle hooks.node_scripts/tasks/version.mjs(new) —precheckandcommit-and-tagsubcommands used by the hooks.
md/RELEASING.md(new) — the release/versioning flow, and the reasoningbehind every deviation from the issue's example snippet.
README.md— a two-line pointer to the new doc.Root
package.jsonwas not touched; the hooks reuse thetest:*andbuildscripts that already exist there.The hooks, e.g. for
fjl:{ "preversion": "node ../../node_scripts/tasks/version.mjs precheck && pnpm -w run test:fjl", "version": "pnpm -w run build", "postversion": "node ../../node_scripts/tasks/version.mjs commit-and-tag" }Which packages, and which were skipped
fjl.github/workflows/publish.yml; built by rollup; tested by jest.fjl-validatorworkspaces, built, tested, published on npm.fjl-inputfilterworkspaces, built, tested, published on npm.fjl-validator-recaptchajest --selectProjects fjl-validator-recaptchaexits 1 with "no projects were found").fjl-filterworkspaces, not inrollup.config.mjsorjest.config.mjs, and itsmain/modulepoint at afjl-input.jsbundle nothing produces. Dormant.fjl-labspnpm-workspace.yamlbut has nopackage.jsonat all — sources only.Deviations from the issue's example snippet
The issue's snippet is
"preversion": "npm test","version": "npm run build && git add -A dist","postversion": "git push && git push --tags && rm -rf build/temp". Every line needed adapting:npm test/npm run builddo not exist per package. Jest is configuredonce at the root (
jest.config.mjs, a multi-project runner selected with--selectProjects) and rollup likewise (rollup.config.mjs, builds allpackages in one pass). The hooks therefore call back into the root with
pnpm -w run <script>.git add -A distwould stage nothing.**/distis in.gitignore;build output is never committed and CI rebuilds it on publish. The
versionhook still runs the build, but as a gate — the bump aborts if the package
stopped compiling.
rm -rf build/temphas no analogue. No such directory;rollup.config.mjsalready cleans eachpackages/*/dist/before writing.postversioncommits and tags instead of pushing. This is thenon-obvious one.
npm version(which pnpm 8.13.1 delegates to — it does notimplement
versionitself) only performs git work when a.gitentry sitsdirectly in its cwd:
@npmcli/git'sis()isstat(cwd + '/.git')and never walks up. The only.githere is at the reporoot, so
pnpm versioninsidepackages/<name>bumpspackage.jsonandruns all three hooks but silently skips its clean-tree guard, the release
commit, and the tag. Running it from the root does not help either:
npm version --workspace <pkg>hard-codes'git-tag-version': falseinlib/commands/version.js.node_scripts/tasks/version.mjsputs the twomissing steps back.
fjl@2.0.0-alpha.6) rather than npm's barev<version>, because siblings collide otherwise —fjl-inputfilterandfjl-validator-recaptchaare both at1.3.0today.publish.ymltriggers onrelease: [created],so a tag push alone publishes nothing and a manual GitHub Release is required
regardless; the repo's
pre-pushhook runs the fullpnpm test && pnpm build, making a push-per-package expensive; and coordinated multi-packagebumps are better pushed once.
commit-and-tagprints the exactgit push --follow-tagsto run next.How this was validated without cutting a release
No version was bumped, no tag was created, and nothing was published in this
repo.
git diff origin/maintouches onlyscriptsblocks; the three packageversions are still
2.0.0-alpha.5,0.8.0,1.3.0, and the tag count isunchanged at 139.
pnpm run preversionandpnpm run versionwere executed on their own — allexit 0 (
fjl125 suites / 920 tests,fjl-validator6 / 33,fjl-inputfilter2 / 113;pnpm -w run buildexits 0 from a package dir).precheckwas exercised in this repo (it is read-only): it correctlyfailed while the working tree was dirty and passed once the tree was clean.
mirrors this layout (root
pnpm-workspace.yaml+packages/fjl,packageManagerpinned topnpm@8.13.1), using a byte-for-byte copy ofversion.mjsand the realscriptsblock frompackages/fjl/package.json,with the root
test:fjl/buildstubbed toecho. Result: hooks ran inorder, and the commit
chore(release): fjl@2.0.0-alpha.6plus annotated tagfjl@2.0.0-alpha.6were created, touching onlypackages/fjl/package.json.Guard rails were verified too — re-running
commit-and-tagrefuses anexisting tag, and an unknown subcommand exits 1.
config:
echo "chore(release): fjl@2.0.0-alpha.6" | npx commitlintexits 0.from the installed
libnpmversion/lib/version.js,@npmcli/git/lib/is.js, andnpm/lib/commands/version.js.eslintandtsc-files --noEmitpass on the newversion.mjs.Hooks
No hook was bypassed.
commit-msg,pre-commit(lint-staged), andpre-push(
pnpm test && pnpm build) all ran and passed normally. The pre-existingpnpm lintfailures onmainand the pre-existing rollup.d.tswarnings forpackages/fjl/dist/esm/object/setTheory.d.tsare untouched by this change.🤖 Generated with Claude Code