feat(release): publish npx t3 as a launcher over per-platform executable packages #11607
Mergedjuliusmarmingemerged 7 commits into
sea/release-graph fromrefs/pull/11607/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -0,0 +337,21 @@337+}) {338+ const fs = yield* FileSystem.FileSystem;339+ const path = yield* Path.Path;340+341+ const present = yield* fs.readDirectory(input.archivesDir);342+ const archives = CLI_ARCHIVE_PLATFORM_KEYS.flatMap((key) => {343+ const fileName = cliArchiveFileName(input.version, key);344+ return present.includes(fileName)345+ ? [{ key, archive: path.join(input.archivesDir, fileName) }]346+ : [];347+ });348+ const missing = CLI_ARCHIVE_PLATFORM_KEYS.filter(349+ (key) => !archives.some((entry) => entry.key === key),350+ );351+ if (missing.length > 0 && (!input.allowMissing || archives.length === 0)) {352+ return yield* new NpmPackagesArchivesMissingError({ archivesDir: input.archivesDir, missing });353+ }354+355+ yield* fs.makeDirectory(path.join(input.outputDir, NPM_PLATFORM_PACKAGE_SCOPE), {356+ recursive: true,357+ });@@ -294,6 +295,11 @@294295295296 ## 0) npm OIDC trusted publishing setup (CLI)296297297-The workflow invokes `node apps/server/scripts/cli.ts publish` after aligning package versions. That298-script temporarily prepares the `t3` package, then runs `vp pm publish --filter t3 ...` from the299-repository root so workspace publish configuration is applied correctly.298+The workflow runs `node scripts/build-npm-platform-packages.ts` on the downloaded CLI archives, then299+`node apps/server/scripts/cli.ts publish --packages-dir npm-packages`, which runs `npm publish` on300+each `@t3code/t3-<platform>-<arch>.tgz` and finally on `t3.tgz`, the launcher. The script publishes301+tarballs it built itself rather than directories: `npm publish <dir>` strips `node_modules/` from the302+tarball no matter what `files` says, and the executable loads its native addons from there. Seven303+packages are published per release: `t3`, `@t3code/t3-darwin-arm64`, `@t3code/t3-darwin-x64`,304+`@t3code/t3-linux-arm64`, `@t3code/t3-linux-x64`, `@t3code/t3-win32-arm64`,305+`@t3code/t3-win32-x64`.@@ -516,5 +542,11 @@516542 "tar (zip)",517543 );518544 } else {545+ // On Linux, pnpm hard-links identical files out of its store and node-gyp546+ // hard-links build outputs, and GNU tar records those as link entries.547+ // The npm registry rejects a tarball containing any, and the npm platform548+ // packages are re-packed from this archive's contents, so store every549+ // file as a file. macOS's bsdtar has no such flag; pnpm clones there.519550 yield* runCommand(520- ChildProcess.make("tar", ["-czf", archivePath, "-C", stageRoot, stem]),551+ ChildProcess.make("tar", [552+ ...(input.platform === "linux" ? ["--hard-dereference"] : []),
- @@ -286,6 +191,15 @@286- // Assert build assets exist287- for (const relPath of ["dist/bin.mjs", "dist/client/index.html"]) {288- const abs = path.join(serverDir, relPath);289- if (!(yield* fs.exists(abs))) {290- return yield* new ServerCliBuildAssetMissingError({ assetPath: abs });291- }191+ // npm runs with cwd set to the packages dir below, so tarball paths are192+ // resolved once here rather than joined twice.193+ const packagesDir = path.resolve(config.packagesDir);194+ const scopeDir = path.join(packagesDir, "@t3code");195+ const launcherTarball = path.join(packagesDir, "t3.tgz");196+ const platformTarballs = (yield* fs197+ .readDirectory(scopeDir)198+ .pipe(Effect.orElseSucceed((): ReadonlyArray<string> => [])))199+ .filter((entry) => entry.startsWith("t3-") && entry.endsWith(".tgz"))200+ .sort()201+ .map((entry) => path.join(scopeDir, entry));202+ if (platformTarballs.length === 0) {203+ return yield* new ServerCliBuildAssetMissingError({204+ assetPath: path.join(scopeDir, "t3-<platform>.tgz"),205+ });@@ -349,11 +215,11 @@215+ for (const tarball of [...platformTarballs, launcherTarball]) {216+ const spawnCommand = yield* resolveSpawnCommand("npm", [...args, tarball]);217+ yield* Effect.log(`[cli] npm ${args.join(" ")} ${path.basename(tarball)}`);218+ yield* runCommand(219+ ChildProcess.make(spawnCommand.command, spawnCommand.args, {220+ cwd: packagesDir,221+ stdout: config.verbose ? "inherit" : "ignore",222+ stderr: "inherit",223+ shell: spawnCommand.shell,349224 }),350- // Release: restore every file even if applying overrides or publishing fails.351- (resource) =>352- Effect.gen(function* () {353- yield* fs.writeFile(packageJsonPath, resource.originalPackageJson);354- for (const icon of resource.icons) {355- yield* fs.writeFile(icon.targetPath, icon.original);356- }357- if (config.verbose) yield* Effect.log("[cli] Restored original publish assets");358- }),359- );225+ );@@ -294,6 +295,11 @@294295295296 ## 0) npm OIDC trusted publishing setup (CLI)296297297-The workflow invokes `node apps/server/scripts/cli.ts publish` after aligning package versions. That298-script temporarily prepares the `t3` package, then runs `vp pm publish --filter t3 ...` from the299-repository root so workspace publish configuration is applied correctly.298+The workflow runs `node scripts/build-npm-platform-packages.ts` on the downloaded CLI archives, then299+`node apps/server/scripts/cli.ts publish --packages-dir npm-packages`, which runs `npm publish` on300+each `@t3code/t3-<platform>-<arch>.tgz` and finally on `t3.tgz`, the launcher. The script publishes301+tarballs it built itself rather than directories: `npm publish <dir>` strips `node_modules/` from the302+tarball no matter what `files` says, and the executable loads its native addons from there. Seven303+packages are published per release: `t3`, `@t3code/t3-darwin-arm64`, `@t3code/t3-darwin-x64`,304+`@t3code/t3-linux-arm64`, `@t3code/t3-linux-x64`, `@t3code/t3-win32-arm64`,305+`@t3code/t3-win32-x64`.@@ -0,0 +166,21 @@166+ ["-tzvf", path.join(fixture.outputDir, "@t3code/t3-linux-x64.tgz")],167+ { cwd: fixture.outputDir },168+ );169+ assert.equal(listing.exitCode, 0, listing.stderr);170+ const lines = listing.stdout.split("\n");171+ assert.isTrue(lines.some((line) => line.endsWith(" package/node_modules/node-pty/")));172+ assert.isTrue(lines.some((line) => line.endsWith(" package/package.json")));173+ assert.isTrue(174+ lines.some((line) => /^-rwxr-xr-x .* package\/t3$/.test(line)),175+ listing.stdout,176+ );177+178+ // NODE_PATH stands in for node_modules: require.resolve finds the179+ // platform package there exactly as it would after `npm install`.180+ const env = { ...process.env, NODE_PATH: fixture.outputDir } as Record<string, string>;181+ const passthrough = yield* run(process.execPath, ["bin/t3.js", "serve", "--port", "1234"], {182+ cwd: launcherDir,183+ env,184+ });185+ assert.equal(passthrough.stdout.trim(), "stub linux-x64 serve --port 1234");186+ assert.equal(passthrough.exitCode, 7);@@ -0,0 +173,21 @@173+ stdout: "inherit",174+ stderr: "inherit",175+ }),176+ );177+ const exitCode = Number(yield* child.exitCode);178+ if (exitCode !== 0) {179+ return yield* new NpmPackagesCommandFailedError({ command: label, exitCode });180+ }181+});182+183+/**184+ * Extracts an archive and returns its single top-level directory. `.tar.gz`185+ * goes through tar everywhere; `.zip` through the bsdtar Windows ships or,186+ * elsewhere, `unzip`, since GNU tar cannot read zip.187+ */188+const extractArchive = Effect.fn("extractArchive")(function* (archive: string, into: string) {189+ const fs = yield* FileSystem.FileSystem;190+ const path = yield* Path.Path;191+ const platform = yield* HostProcessPlatform;192+ if (!archive.endsWith(".zip")) {193+ yield* runCommand(ChildProcess.make("tar", ["-xf", archive, "-C", into]), "tar -xf");
- @@ -20,3 +22,7 @@2022 This starts the server and opens the local web app. Run2123 `npx t3@latest --help` for command-line options.222425+The executable is built for Apple Silicon Macs, Linux, and Windows. There is26+no Intel Mac build of it, because Node cannot produce a single executable for27+that platform; the Intel desktop app is unaffected. To run a standalone server28+on an Intel Mac, build it from source. You need Node.js 24 and `vp` (see
- @@ -20,3 +22,6 @@2022 This starts the server and opens the local web app. Run2123 `npx t3@latest --help` for command-line options.222425+The executable is built for Apple Silicon Macs, Linux, and Windows. There is26+no Intel Mac build of it, because Node cannot produce a single executable for27+that platform; the Intel desktop app is unaffected. To run a standalone server
juliusmarminge merged this91cd91c
juliusmarminge closed this
Sign in to join this conversation.
Bugbot is paused — on-demand spend limit reached
Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.
A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.