Skip to content

Commit 26f7e54

Browse files
authored
Dev-stamp the standalone CLI version in nightly builds (#3928)
## Related issues - Related to [STU-1772](https://linear.app/a8c/issue/STU-1772) — the standalone CLI update workflow depends on this. ## How AI was used in this PR Caught during real-world testing: installing a published nightly CLI showed `studio --version` → `1.11.0`, even though the Apps CDN publishes that same nightly as `1.12.0-dev103`. Traced it to `prepare-dev-build-version.mjs` dev-stamping only `apps/studio/package.json`. I reviewed the change myself. ## Proposed Changes `prepare-dev-build-version.mjs` rewrites the version to the `X.(Y+1).0-devN` dev form for nightly/dev builds — but only for the desktop app (`apps/studio/package.json`). The standalone CLI (`apps/cli/package.json`) was left at the static base version, so its baked `__STUDIO_CLI_VERSION__` (what `studio --version` reports) didn't match the version the bundle is actually published under on the CDN. This stamps `apps/cli/package.json` with the same dev version. After it: - `studio --version` on a nightly reports its real version (e.g. `1.12.0-dev103`) instead of a static, meaningless `1.11.0`. - It unblocks the standalone CLI update notifier (STU-1772): the CLI derives its update channel from its own version (`-devN` → nightly), so it needs the real dev version baked in to check the right channel. Without this, a nightly install looks like "production" to the update endpoint and never sees nightly updates. ## Testing Instructions ```sh GITHUB_SHA=$(git rev-parse HEAD) node ./scripts/prepare-dev-build-version.mjs grep '"version"' apps/studio/package.json apps/cli/package.json # → both show the same X.(Y+1).0-devN (e.g. 1.12.0-dev103), matching the CDN-published nightly git checkout -- apps/studio/package.json apps/cli/package.json # revert the local mutation ``` The CLI build (`cli:bundle`) runs after this script in the build pipelines, so the bundle bakes the stamped version. ## Pre-merge Checklist - [x] Have you checked for TypeScript, React or other console errors? — build script only; ran it and verified both files stamp to the same dev version.
1 parent 74ad042 commit 26f7e54

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

scripts/prepare-dev-build-version.mjs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,28 @@ if ( ! commitCount && commitCount !== 0 ) {
1717
throw new Error( 'Missing commit count' );
1818
}
1919

20-
// Use version from latestTag (strip leading 'v' if present)
21-
const tagVersion = latestTag.startsWith( 'v' ) ? latestTag.slice( 1 ) : latestTag;
22-
const parsedVersion = semver.parse( tagVersion );
23-
if ( ! parsedVersion ) {
24-
throw new Error( `Invalid version in latestTag: ${ latestTag }` );
20+
// Build a dev version targeting the next minor release (major.(minor+1).0-devN) from a base
21+
// version, so trunk builds sort above any stable or beta of that base. Strips a leading 'v'.
22+
function toDevVersion( baseVersion, source ) {
23+
const parsed = semver.parse(
24+
baseVersion.startsWith( 'v' ) ? baseVersion.slice( 1 ) : baseVersion
25+
);
26+
if ( ! parsed ) {
27+
throw new Error( `Invalid version in ${ source }: ${ baseVersion }` );
28+
}
29+
return `${ parsed.major }.${ parsed.minor + 1 }.0-dev${ commitCount }`;
2530
}
2631

27-
// Create dev version targeting the next minor release (major.minor+1.0-devN),
28-
// so trunk builds sort above any stable or beta of the last release.
29-
const devVersion = `${ parsedVersion.major }.${ parsedVersion.minor + 1 }.0-dev${ commitCount }`;
30-
31-
packageJson.version = devVersion;
32-
32+
// Desktop app: based on the latest release tag.
33+
packageJson.version = toDevVersion( latestTag, 'latestTag' );
3334
const packageJsonPath = path.resolve( 'apps', 'studio', 'package.json' );
3435
await fs.writeFile( packageJsonPath, JSON.stringify( packageJson, null, '\t' ) + '\n' );
36+
37+
// Standalone CLI: based on its OWN current version — the CLI and app aren't guaranteed to share a
38+
// version line. Its baked `__STUDIO_CLI_VERSION__` drives the update channel (a `-devN` version →
39+
// nightly); without this a nightly bundle reports the static base version, looks like production
40+
// to the update endpoint, and never sees nightly updates.
41+
const cliPackageJsonPath = path.resolve( 'apps', 'cli', 'package.json' );
42+
const cliPackageJson = JSON.parse( await fs.readFile( cliPackageJsonPath, 'utf8' ) );
43+
cliPackageJson.version = toDevVersion( cliPackageJson.version, 'apps/cli/package.json' );
44+
await fs.writeFile( cliPackageJsonPath, JSON.stringify( cliPackageJson, null, '\t' ) + '\n' );

0 commit comments

Comments
 (0)