Skip to content

Commit b9665b6

Browse files
committed
fix(server): prioritize global installation ownership
1 parent 5dcf517 commit b9665b6

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

‎apps/server/src/cli/invocation.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ it.layer(NodeServices.layer)("manual server installation ownership", (it) => {
127127
Effect.gen(function* () {
128128
const fs = yield* FileSystem.FileSystem;
129129
const path = yield* Path.Path;
130-
const prefix = yield* fs.makeTempDirectoryScoped();
130+
const root = yield* fs.makeTempDirectoryScoped();
131+
const prefix = path.join(root, "bunx-tools");
131132
const packageRoot = path.join(prefix, "lib/node_modules/t3");
132133
const entry = path.join(packageRoot, "dist/bin.mjs");
133134
const globalBin = path.join(prefix, "bin/t3");
@@ -157,7 +158,8 @@ it.layer(NodeServices.layer)("manual server installation ownership", (it) => {
157158
Effect.gen(function* () {
158159
const fs = yield* FileSystem.FileSystem;
159160
const path = yield* Path.Path;
160-
const prefix = yield* fs.makeTempDirectoryScoped();
161+
const root = yield* fs.makeTempDirectoryScoped();
162+
const prefix = path.join(root, "bunx-tools");
161163
const packageRoot = path.join(prefix, "lib/node_modules/t3");
162164
const launcher = path.join(packageRoot, "bin/t3.js");
163165
const entry = path.join(packageRoot, "node_modules/@t3code/t3-linux-x64/t3");

‎apps/server/src/cli/invocation.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,19 @@ export const resolveServerInstallation = Effect.gen(function* () {
6262
const executablePath = yield* HostProcessExecutablePath;
6363
const platform = yield* HostProcessPlatform;
6464
const entry = yield* fs.realPath(executable ? executablePath : (args[1] ?? ""));
65-
const runner = detectCliRunner(entry);
66-
if (runner !== null) {
67-
return { kind: runner === "pnpm dlx" ? "pnpm-dlx" : runner } satisfies ServerInstallation;
68-
}
69-
// Windows shims and other package managers need their own ownership proof.
70-
if (platform === "win32") return null;
7165
const match =
7266
/^(.*)\/lib\/node_modules\/t3\/(?:dist\/bin\.mjs|bin\/t3\.js|node_modules\/@t3code\/t3-[^/]+\/t3)$/.exec(
7367
entry,
7468
);
75-
if (!match) return null;
69+
if (!match) {
70+
const runner = detectCliRunner(entry);
71+
return runner === null
72+
? null
73+
: ({ kind: runner === "pnpm dlx" ? "pnpm-dlx" : runner } satisfies ServerInstallation);
74+
}
75+
// A global prefix can contain runner-like names; prove its ownership first.
76+
// Windows shims and other package managers need their own ownership proof.
77+
if (platform === "win32") return null;
7678
const prefix = match[1] || "/";
7779
if (
7880
prefix.includes("/node_modules/") ||

0 commit comments

Comments
 (0)