Skip to content

Commit a102c13

Browse files
jrolfsclaude
andcommitted
feat(fork): add --snapshot to publish-fork for snapshot releases
--snapshot mints ephemeral 0.0.0-snapshot-<timestamp> versions via `changeset version --snapshot snapshot` (+ bun install so pack resolves the ranges), publishes them to the `snapshot` dist-tag instead of `latest`, and skips git tags / GitHub Releases. Only packages with a pending changeset get a snapshot version; the rest are skipped as already-published. Run after `bun changeset` + `bun run build` (or `bun snapshot`). It dirties the working tree (version bumps + consumed changesets) — discard with `git checkout .` afterward; CI is ephemeral. The normal changesets/action PR flow is unaffected (it calls ci:publish without --snapshot, which uses --tag latest). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9753ea6 commit a102c13

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"restart": "bun kill && bun clean:cache && bun dev",
1717
"changeset": "changeset",
1818
"ci:version": "changeset version && bun install",
19-
"ci:publish": "bun run scripts/publish-fork.ts"
19+
"ci:publish": "bun run scripts/publish-fork.ts",
20+
"snapshot": "bun run scripts/publish-fork.ts --snapshot"
2021
},
2122
"devDependencies": {
2223
"@biomejs/biome": "^2.4.16",

‎scripts/publish-fork.ts‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ import { extname, join } from "node:path";
2222
//
2323
// To target a different scope (e.g. @meterup) set PUBLISH_SCOPE — that is the
2424
// only thing that changes. Auth comes from .npmrc (NODE_AUTH_TOKEN).
25+
//
26+
// With --snapshot (run after `bun changeset` + `bun run build`): mints
27+
// 0.0.0-snapshot-<timestamp> versions via `changeset version --snapshot`,
28+
// publishes them to the `snapshot` dist-tag (leaving `latest` untouched), and
29+
// skips git tags / GitHub Releases. It dirties the working tree (version bumps +
30+
// consumed changesets) — discard with `git checkout .` afterward; CI is ephemeral.
2531

2632
const SOURCE_PREFIX = "@pascal-app/";
2733
const SCOPE = process.env.PUBLISH_SCOPE ?? "@meterup";
@@ -30,6 +36,11 @@ const TARGET_PREFIX = `${SCOPE}/${NAME_PREFIX}`; // e.g. "@meterup/pascal-"
3036
const REGISTRY = "https://npm.pkg.github.com";
3137
const DRY_RUN = process.argv.includes("--dry-run");
3238
const IN_CI = process.env.GITHUB_ACTIONS === "true";
39+
// --snapshot: mint ephemeral 0.0.0-snapshot-<timestamp> versions and publish them
40+
// to the `snapshot` dist-tag instead of `latest` (see changesets snapshot releases).
41+
const SNAPSHOT = process.argv.includes("--snapshot");
42+
const SNAPSHOT_TAG = "snapshot"; // both the changesets snapshot id and the dist-tag
43+
const DIST_TAG = SNAPSHOT ? SNAPSHOT_TAG : "latest";
3344
// "owner/repo" of the publishing fork in CI; used to link packages to this repo.
3445
const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY;
3546

@@ -70,6 +81,15 @@ const relinkRepository = (packageDir: string, repo: string, directory: string):
7081
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
7182
};
7283

84+
// Snapshot mode mints throwaway versions from the pending changesets. Only
85+
// packages with a changeset (+ their dependents) get a snapshot version; the
86+
// rest keep their released version and are skipped below as already-published.
87+
// `bun install` re-resolves the lockfile so `bun pm pack` emits snapshot ranges.
88+
if (SNAPSHOT && !DRY_RUN) {
89+
await $`bunx changeset version --snapshot ${SNAPSHOT_TAG}`;
90+
await $`bun install`;
91+
}
92+
7393
const newTags: string[] = [];
7494

7595
for (const dir of readdirSync("packages")) {
@@ -106,8 +126,8 @@ for (const dir of readdirSync("packages")) {
106126
continue;
107127
}
108128

109-
console.log(`→ Publishing ${tag}`);
110-
await $`npm publish ${packed} --ignore-scripts --registry ${REGISTRY}`;
129+
console.log(`→ Publishing ${tag} (dist-tag: ${DIST_TAG})`);
130+
await $`npm publish ${packed} --ignore-scripts --registry ${REGISTRY} --tag ${DIST_TAG}`;
111131
newTags.push(tag);
112132
} finally {
113133
rmSync(work, { recursive: true, force: true });
@@ -119,8 +139,9 @@ for (const dir of readdirSync("packages")) {
119139
// printed name against a workspace package, which never matches our rescoped
120140
// names (the source stays @pascal-app/*), so it errors. Instead we own the tag
121141
// + release here, named after what was actually published. Best-effort so a
122-
// re-run (tag/release already exists) doesn't fail the job.
123-
if (IN_CI && newTags.length > 0) {
142+
// re-run (tag/release already exists) doesn't fail the job. Skipped for
143+
// snapshots — they're ephemeral and shouldn't leave tags/releases behind.
144+
if (!SNAPSHOT && IN_CI && newTags.length > 0) {
124145
for (const tag of newTags) await $`git tag ${tag}`.nothrow();
125146
await $`git push origin ${newTags}`.nothrow();
126147
for (const tag of newTags) {

0 commit comments

Comments
 (0)