Skip to content
TypeScript

chore(server): keep the legacy service entry point to the npm package only (#11770)

Julius Marmingef328db30da06
diff --git a/apps/server/src/cloud/pinnedRuntime.test.ts b/apps/server/src/cloud/pinnedRuntime.test.ts
index ca090bc2870..e4b16b8f719 100644
--- a/apps/server/src/cloud/pinnedRuntime.test.ts
+++ b/apps/server/src/cloud/pinnedRuntime.test.ts
@@ -1,4 +1,3 @@
-import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, it } from "@effect/vitest";
import * as Deferred from "effect/Deferred";
@@ -95,19 +94,6 @@ it.layer(NodeServices.layer)("ensurePinnedRuntimeInstalled", (it) => {
assert.deepEqual(commands, ["tar"]);
assert.equal(yield* fs.readFileString(paths.sentinelPath), `${version}\n`);
assert.isFalse(yield* fs.exists(path.join(paths.versionDir, "t3-runtime-archive")));
- if ((yield* HostProcessPlatform) !== "win32") {
- // The old launcher must still be able to start this archive after the
- // first npm-to-executable update, including from the final directory.
- yield* fs.writeFileString(paths.entryPath, '#!/bin/sh\nprintf "%s\\n" "$@"\n');
- yield* fs.chmod(paths.entryPath, 0o755);
- const runner = yield* ProcessRunner.make();
- const legacyStart = yield* runner.run({
- command: process.execPath,
- args: [path.join(paths.versionDir, "node_modules/t3/dist/bin.mjs"), "serve"],
- });
- assert.equal(Number(legacyStart.code), 0, legacyStart.stderr);
- assert.equal(legacyStart.stdout.trim(), "serve");
- }
}),
);
@@ -223,40 +209,6 @@ it.layer(NodeServices.layer)("ensurePinnedRuntimeInstalled", (it) => {
}),
);
- it.effect("backfills a cached archive without downloading or replacing it", () =>
- Effect.gen(function* () {
- const fs = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-pinned-legacy-cache-" });
- const cached = pinnedRuntimePaths(path, baseDir, version, "linux");
- const legacyEntry = path.join(cached.versionDir, "node_modules/t3/dist/bin.mjs");
- yield* fs.makeDirectory(cached.versionDir, { recursive: true });
- yield* fs.writeFileString(cached.entryPath, "cached executable\n");
- yield* fs.writeFileString(cached.sentinelPath, `${version}\n`);
- const requests: string[] = [];
- const commands: string[] = [];
- yield* ensurePinnedRuntimeInstalled({
- baseDir,
- version,
- fs,
- path,
- platform: "linux",
- arch: "x64",
- httpClient: releaseHttpClient(yield* validChecksums, requests),
- runner: extractingRunner(fs, path, commands),
- validate: () =>
- fs.exists(legacyEntry).pipe(
- Effect.flatMap((exists) => (exists ? Effect.void : Effect.die("missing legacy entry"))),
- Effect.orDie,
- ),
- });
- assert.deepEqual(requests, []);
- assert.deepEqual(commands, []);
- assert.equal(yield* fs.readFileString(cached.entryPath), "cached executable\n");
- assert.equal(yield* fs.readFileString(cached.sentinelPath), `${version}\n`);
- }),
- );
-
it.effect("preserves a completed runtime when validation fails", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
diff --git a/apps/server/src/cloud/pinnedRuntime.ts b/apps/server/src/cloud/pinnedRuntime.ts
index ef929ebb823..680d80e46cd 100644
--- a/apps/server/src/cloud/pinnedRuntime.ts
+++ b/apps/server/src/cloud/pinnedRuntime.ts
@@ -8,7 +8,6 @@ import * as Option from "effect/Option";
import * as Semaphore from "effect/Semaphore";
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
-import { legacyCliLauncherScript } from "@t3tools/shared/legacyCliLauncher";
import {
CLI_RELEASE_CHECKSUMS_FILE,
cliArchiveFileName,
@@ -230,24 +229,6 @@ const installPinnedRuntime = Effect.fn("cloud.pinned_runtime.ensure_installed")(
input: PinnedRuntimeInstallInput,
) {
const { fs } = input;
- // Old service launchers still use the npm entry point, including when an
- // archive was cached before this compatibility wrapper existed.
- const ensureLegacyEntry = Effect.fn("cloud.pinned_runtime.ensure_legacy_entry")(
- function* (versionDir: string) {
- const legacyDir = input.path.join(versionDir, "node_modules", "t3", "dist");
- const entryPath = input.path.join(legacyDir, "bin.mjs");
- if (yield* fs.exists(entryPath)) return;
- yield* fs.makeDirectory(legacyDir, { recursive: true });
- yield* fs.writeFileString(entryPath, legacyCliLauncherScript("archive"));
- },
- Effect.mapError(
- (cause) =>
- new PinnedRuntimeInstallError({
- step: "writing the legacy service entry point",
- cause,
- }),
- ),
- );
const paths = pinnedRuntimePaths(input.path, input.baseDir, input.version, input.platform);
const [versionDirExists, entryExists, sentinel] = yield* Effect.all([
fs.exists(paths.versionDir),
@@ -261,7 +242,6 @@ const installPinnedRuntime = Effect.fn("cloud.pinned_runtime.ensure_installed")(
const alreadyPinned =
entryExists && Option.isSome(sentinel) && sentinel.value.trim() === input.version;
if (alreadyPinned) {
- yield* ensureLegacyEntry(paths.versionDir);
yield* input.validate(paths);
return paths;
}
@@ -310,8 +290,6 @@ const installPinnedRuntime = Effect.fn("cloud.pinned_runtime.ensure_installed")(
return yield* Effect.gen(function* () {
yield* installFromArchive(input, stagingDir);
- yield* ensureLegacyEntry(stagingDir);
-
yield* input.validate(stagingPaths);
yield* fs
.writeFileString(stagingPaths.sentinelPath, `${input.version}\n`)
@@ -350,10 +328,7 @@ const installPinnedRuntime = Effect.fn("cloud.pinned_runtime.ensure_installed")(
),
),
);
- if (!published) {
- yield* ensureLegacyEntry(paths.versionDir);
- yield* input.validate(paths);
- }
+ if (!published) yield* input.validate(paths);
return paths;
}).pipe(
Effect.ensuring(fs.remove(stagingDir, { recursive: true, force: true }).pipe(Effect.ignore)),
diff --git a/packages/shared/src/legacyCliLauncher.test.ts b/packages/shared/src/legacyCliLauncher.test.ts
index 0a0f3feabb7..b6630f468a8 100644
--- a/packages/shared/src/legacyCliLauncher.test.ts
+++ b/packages/shared/src/legacyCliLauncher.test.ts
@@ -14,22 +14,22 @@ const hostPlatform = NodeOS.platform();
const hostArch = NodeOS.arch();
// The fixture executable uses a POSIX shebang. The wrapper itself also runs on Windows.
-it.skipIf(hostPlatform === "win32").each(["npm", "archive"] as const)(
- "keeps %s service IPC, arguments, and termination connected",
- async (distribution) => {
+it.skipIf(hostPlatform === "win32")(
+ "keeps service IPC, arguments, and termination connected",
+ async () => {
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-legacy-launcher-"));
const entry = NodePath.join(root, "node_modules/t3/dist/bin.mjs");
- const executable =
- distribution === "archive"
- ? NodePath.join(root, "t3")
- : NodePath.join(root, `node_modules/@t3code/t3-${hostPlatform}-${hostArch}/t3`);
+ const executable = NodePath.join(
+ root,
+ `node_modules/@t3code/t3-${hostPlatform}-${hostArch}/t3`,
+ );
await NodeFSP.mkdir(NodePath.dirname(entry), { recursive: true });
await NodeFSP.mkdir(NodePath.dirname(executable), { recursive: true });
await NodeFSP.writeFile(
NodePath.join(NodePath.dirname(executable), "package.json"),
'{"type":"commonjs"}',
);
- await NodeFSP.writeFile(entry, legacyCliLauncherScript(distribution));
+ await NodeFSP.writeFile(entry, legacyCliLauncherScript());
await NodeFSP.writeFile(
executable,
`#!${process.execPath}
diff --git a/packages/shared/src/legacyCliLauncher.ts b/packages/shared/src/legacyCliLauncher.ts
index f159c41d3e0..b852e2310db 100644
--- a/packages/shared/src/legacyCliLauncher.ts
+++ b/packages/shared/src/legacyCliLauncher.ts
@@ -1,17 +1,23 @@
-/** Node entry point for service launchers installed before executable releases. */
-export function legacyCliLauncherScript(distribution: "npm" | "archive"): string {
- const executable =
- distribution === "npm"
- ? 'join(dirname(require.resolve("@t3code/t3-" + process.platform + "-" + process.arch + "/package.json")), executableName)'
- : 'resolve(dirname(fileURLToPath(import.meta.url)), "../../..", executableName)';
+/**
+ * `dist/bin.mjs` of the `t3` npm package: the entry point boot-service
+ * launchers installed before 0.0.41 run with Node to start a new version they
+ * just npm-installed. It forwards everything (arguments, stdio, the IPC
+ * channel the launcher talks over, signals, exit status) to the platform
+ * executable in the sibling `@t3code/t3-<platform>-<arch>` package.
+ *
+ * The first server started this way rewrites the service unit to run the
+ * executable directly, so nothing depends on this file after one update.
+ * Remove it once no supported release predates the executable (after the
+ * first stable release that ships it).
+ */
+export function legacyCliLauncherScript(): string {
return `import { spawn } from "node:child_process";
import { constants } from "node:os";
-import { dirname, join, resolve } from "node:path";
-import { fileURLToPath } from "node:url";
+import { dirname, join } from "node:path";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const executableName = process.platform === "win32" ? "t3.exe" : "t3";
-const executable = ${executable};
+const executable = join(dirname(require.resolve("@t3code/t3-" + process.platform + "-" + process.arch + "/package.json")), executableName);
const ipc = process.send !== undefined;
const child = spawn(executable, process.argv.slice(2), {
stdio: ipc ? ["inherit", "inherit", "inherit", "ipc"] : "inherit",
diff --git a/scripts/build-npm-platform-packages.ts b/scripts/build-npm-platform-packages.ts
index fd8c4999a17..d823fc61df4 100644
--- a/scripts/build-npm-platform-packages.ts
+++ b/scripts/build-npm-platform-packages.ts
@@ -389,7 +389,7 @@ const stageLauncherPackage = Effect.fn("stageLauncherPackage")(function* (input:
// Older service updaters and launchers run this exact path with Node.
// Keep it in the package so they can preflight and start the new executable.
yield* fs.makeDirectory(path.join(stageDir, "dist"));
- yield* fs.writeFileString(path.join(stageDir, "dist/bin.mjs"), legacyCliLauncherScript("npm"));
+ yield* fs.writeFileString(path.join(stageDir, "dist/bin.mjs"), legacyCliLauncherScript());
const readme = yield* path.fromFileUrl(new URL("../apps/server/README.md", import.meta.url));
if (yield* fs.exists(readme)) {
yield* fs.copyFile(readme, path.join(stageDir, "README.md"));