Skip to content

Commit 771be1f

Browse files
committed
feat: release workspace packages through npm publish hooks
1 parent afdee8b commit 771be1f

4 files changed

Lines changed: 62 additions & 23 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,27 @@ npm version patch
9898
The version hook synchronizes all public workspace manifests and MCP metadata, stages them, and
9999
includes them in npm's version commit and `v<version>` tag. Do not bump plugin versions separately.
100100

101-
Publish the full release with one command:
101+
Publish and push using the normal npm workflow:
102102

103103
```bash
104-
pnpm release:publish
104+
npm publish && git push && git push --tags
105105
```
106106

107-
It rejects version drift before building, prepares and validates the core package, builds and
108-
packs the public workspace packages, then uses `pnpm --recursive publish` to publish every
109-
unpublished package version. pnpm excludes private packages and skips versions already published,
110-
so the same command can finish a partially completed release. Publish lifecycle scripts are skipped
111-
only after preparation succeeds. The command then marks all public manifests and MCP metadata with
112-
the next `-dev` version; commit and push that development marker. Push the single release tag and
113-
write one GitHub release covering the core and plugins.
107+
The publish hooks prepare and validate every public package before uploading the core, then
108+
publish the remaining workspace packages at the same version. Private packages stay unpublished.
109+
After every package succeeds, the hook commits all public manifests and MCP metadata at the next
110+
`-dev` version. Your `git push` includes that commit; the version bump created the single release
111+
tag. Write one GitHub release covering the core and plugins.
114112

115-
For a local packaging preview, run `pnpm release:prepare`, then
116-
`pnpm --recursive --include-workspace-root publish --dry-run --ignore-scripts --access public --no-git-checks`.
117-
Publishing requires npm registry access for `agent-device` and the `@agent-device` scope.
113+
After setting the version, preview the full release with `npm publish --dry-run`. It builds and checks the packages without
114+
uploading them, changing versions, or creating commits. Publishing requires npm registry access for
115+
`agent-device` and the `@agent-device` scope.
116+
117+
If core publication succeeds but a later package fails, run `pnpm release:publish` to finish the
118+
release. It skips versions already published and commits the development marker once every package
119+
succeeds. Plain `npm publish` cannot retry an already-published core version.
120+
If every upload succeeds but Git refuses the development-marker commit, fix the Git error and
121+
commit the changed public manifests and `server.json` before pushing. No package needs republishing.
118122

119123
A public package owns its `files`, published `exports`, license, repository metadata, README,
120124
and `prepack` build (including any prerequisites). Use `publishConfig.exports` for source-only
@@ -129,9 +133,9 @@ Run its packed-install smoke before releasing.
129133

130134
### The version on main never equals a published version
131135

132-
`release:publish` runs `release:mark-dev` after publishing, moving all public package manifests
136+
`postpublish` runs `release:mark-dev` after all packages publish, moving all public manifests
133137
and synchronized `server.json` to the next patch with a `-dev` prerelease marker (for example
134-
`0.20.11-dev`). Commit that bump as part of the release. The invariant it protects: MCP registry
138+
`0.20.11-dev`) and committing that bump as part of the release. The invariant it protects: MCP registry
135139
scanners diff the repository's tool surface per version string, so a released number left on `main`
136140
while `main` keeps changing is indistinguishable from a republished ("rug-pull") version.
137141
`release:prepare` enforces the inverse direction and refuses to publish while the `-dev` marker is

‎package.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"build:package": "pnpm build && pnpm build:xcuitest:ios && pnpm build:xcuitest:macos && pnpm build:xcuitest:tvos && pnpm build:xcuitest:visionos && pnpm build:macos-helper:clean && pnpm prepare:publish-assets",
118118
"package:npm": "pnpm build:package && pnpm check:package",
119119
"release:prepare": "node scripts/release-mark-dev.mjs --check-release-version && rm -rf .tmp/release && pnpm check:mcp-metadata && pnpm build:package && pnpm check:package -- --pack-destination .tmp/release && node scripts/release-workspace.mjs pack",
120-
"release:publish": "pnpm release:prepare && pnpm --recursive --include-workspace-root publish --access public --no-git-checks --ignore-scripts && pnpm release:mark-dev",
120+
"release:publish": "pnpm release:prepare && node scripts/release-workspace.mjs publish",
121121
"release:mark-dev": "node scripts/release-mark-dev.mjs",
122122
"ad": "node bin/agent-device.mjs",
123123
"bench:help-conformance": "node scripts/help-conformance-bench.mjs",
@@ -174,7 +174,7 @@
174174
"check:tooling": "pnpm format:check && pnpm lint && pnpm typecheck && pnpm check:layering && pnpm depgraph:test && pnpm check:gate-manifest:test && pnpm check:gate-manifest && pnpm check:production-exports && pnpm check:tmpdir-leaks:test && pnpm check:xctest-selection && pnpm check:packaged-runner-swift && pnpm check:mcp-metadata && pnpm build && pnpm check:bundle-owner-files && pnpm check:package",
175175
"check:unit": "pnpm test:unit && pnpm check:tmpdir-leaks && pnpm test:smoke",
176176
"check": "pnpm check:tooling && pnpm check:fallow && pnpm check:unit",
177-
"prepack": "pnpm check:mcp-metadata && pnpm package:npm",
177+
"prepack": "npm_config_dry_run=false pnpm release:prepare",
178178
"typecheck": "tsc -b packages/xml packages/kernel packages/contracts packages/device-selection packages/host-kit packages/capture-kit packages/managed-allocation packages/provision-kit packages/platform-apple packages/platform-android packages/platform-harmonyos packages/platform-vega packages/platform-linux packages/platform-web packages/ad-script packages/selectors packages/command-registry packages/session-journal packages/ad-replay packages/maestro packages/replay-port packages/replay-test packages/provider-webdriver packages/provider-limrun && tsc -p tsconfig.json && tsc -p examples/sdk/tsconfig.json",
179179
"test-app:install": "pnpm install --dir examples/test-app",
180180
"test-app:start": "pnpm --dir examples/test-app start",
@@ -210,7 +210,8 @@
210210
"test:replay:android": "node --experimental-strip-types src/bin.ts test test/integration/replays/android/emulator",
211211
"test:replay:macos": "node --experimental-strip-types src/bin.ts test test/integration/replays/macos",
212212
"test:replay:linux": "node --experimental-strip-types src/bin.ts test test/integration/replays/linux",
213-
"test:linux:command-evidence": "node --experimental-strip-types test/integration/linux-e2e/live-runner.ts"
213+
"test:linux:command-evidence": "node --experimental-strip-types test/integration/linux-e2e/live-runner.ts",
214+
"postpublish": "node scripts/release-workspace.mjs publish"
214215
},
215216
"files": [
216217
"bin",

‎scripts/release-mark-dev.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import process from 'node:process';
66
// The version on main must never equal a published version: registry scanners
77
// diff the repository's tool surface per version string, so a released number
88
// left in place while main keeps moving reads as a rug-pull republish
9-
// (AS-012). `release:publish` runs this after publishing to move
9+
// (AS-012). `postpublish` runs this after all packages publish to move
1010
// main to the next patch with a `-dev` prerelease marker; `--check-release-version`
1111
// is the inverse guard in `release:prepare`, refusing to publish a `-dev`
1212
// version because the maintainer has not set the release version yet.

‎scripts/release-workspace.mjs‎

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import path from 'node:path';
55
const root = process.cwd();
66
const [command, ...options] = process.argv.slice(2);
77
if (
8-
!['sync', 'check', 'pack'].includes(command) ||
8+
!['sync', 'check', 'pack', 'publish'].includes(command) ||
99
options.some((option) => option !== '--stage')
1010
) {
11-
throw new Error('Usage: node scripts/release-workspace.mjs <sync|check|pack> [--stage]');
11+
throw new Error('Usage: node scripts/release-workspace.mjs <sync|check|pack|publish> [--stage]');
1212
}
1313
const packages = JSON.parse(
1414
execFileSync('pnpm', ['list', '--recursive', '--depth', '-1', '--json'], {
@@ -39,6 +39,7 @@ if (command === 'sync') {
3939
}
4040
}
4141
if (command === 'pack') packWorkspacePackages();
42+
if (command === 'publish') publishWorkspacePackages();
4243
}
4344

4445
function syncVersions() {
@@ -63,9 +64,9 @@ function packWorkspacePackages() {
6364
destination,
6465
`${pkg.manifest.name.replace('@', '').replace('/', '-')}-${version}.tgz`,
6566
);
66-
const args = ['pack', '--out', tarball];
67-
if (pkg.directory === root) args.push('--config.ignore-scripts=true');
68-
execFileSync('pnpm', args, { cwd: pkg.directory, stdio: 'inherit' });
67+
if (pkg.directory !== root) {
68+
execFileSync('pnpm', ['pack', '--out', tarball], { cwd: pkg.directory, stdio: 'inherit' });
69+
}
6970
const packed = JSON.parse(
7071
execFileSync('tar', ['-xOf', tarball, 'package/package.json'], { encoding: 'utf8' }),
7172
);
@@ -100,3 +101,36 @@ function checkPackedIdentity(packed, name) {
100101
throw new Error('Packed package identity differs from the synchronized public package.');
101102
}
102103
}
104+
105+
function publishWorkspacePackages() {
106+
const dryRun = process.env.npm_config_dry_run === 'true';
107+
const args = [
108+
'--recursive',
109+
'--include-workspace-root',
110+
'publish',
111+
'--access',
112+
'public',
113+
'--no-git-checks',
114+
'--ignore-scripts',
115+
];
116+
if (process.env.npm_lifecycle_event === 'postpublish') {
117+
args.push('--filter', `!${rootPackage.manifest.name}`);
118+
}
119+
if (dryRun) args.push('--dry-run');
120+
execFileSync('pnpm', args, { cwd: root, stdio: 'inherit' });
121+
if (dryRun) return;
122+
execFileSync(process.execPath, ['scripts/release-mark-dev.mjs'], { cwd: root, stdio: 'inherit' });
123+
execFileSync(
124+
'git',
125+
[
126+
'commit',
127+
'--only',
128+
'-m',
129+
`chore: mark ${version} as released`,
130+
'--',
131+
...publicPackages.map((pkg) => pkg.manifestPath),
132+
path.join(root, 'server.json'),
133+
],
134+
{ cwd: root, stdio: 'inherit' },
135+
);
136+
}

0 commit comments

Comments
 (0)