GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): open stable Zed when a prerelease Zed is first on PATH (… · Pipyakas/t3code@07f8283

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/process
    • externalLauncher.test.ts
  • packages/shared/src
    • editor.ts
    • shell.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/process/externalLauncher.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/process/externalLauncher.test.ts
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,56 @@ it.effect("keeps scanning after the caller is interrupted and shares that scan",
12341234
),
12351235
);
12361236
});
1237+
it.effect.each(["Zed Nightly", "Zed Preview"])(
1238+
"launches stable Zed on Windows when %s comes first on PATH",
1239+
(channel) =>
1240+
Effect.gen(function* () {
1241+
const fs = yield* FileSystem.FileSystem;
1242+
const path = yield* Path.Path;
1243+
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-zed-channels-" });
1244+
// A user folder naming Zed and a channel does not mark either install.
1245+
const programs = path.join(root, "Users", "zedpreview", "Programs");
1246+
const prereleaseBin = path.join(programs, channel, "bin");
1247+
const stableBin = path.join(programs, "Zed", "bin");
1248+
for (const dir of [prereleaseBin, stableBin]) {
1249+
yield* fs.makeDirectory(dir, { recursive: true });
1250+
yield* fs.writeFileString(path.join(dir, "zed.EXE"), "");
1251+
}
1252+
const env = { PATH: `${prereleaseBin};${stableBin}`, PATHEXT: ".COM;.EXE;.BAT;.CMD" };
1253+
1254+
const launchZed = Effect.gen(function* () {
1255+
let spawned: ChildProcess.StandardCommand | undefined;
1256+
yield* Effect.gen(function* () {
1257+
const launcher = yield* ExternalLauncher.ExternalLauncher;
1258+
yield* launcher.launchEditor({ editor: "zed", cwd: "C:\\workspace" });
1259+
}).pipe(
1260+
Effect.provide(
1261+
layerTest({
1262+
platform: "win32",
1263+
env,
1264+
onSpawn: (command) => {
1265+
spawned = command;
1266+
},
1267+
}),
1268+
),
1269+
);
1270+
assert.ok(spawned);
1271+
return spawned;
1272+
});
1273+
1274+
const stable = yield* launchZed;
1275+
assert.equal(stable.command, path.join(stableBin, "zed.EXE"));
1276+
assert.deepEqual(stable.args, ["C:\\workspace"]);
1277+
1278+
env.PATH = `${stableBin};${prereleaseBin}`;
1279+
assert.equal((yield* launchZed).command, "zed");
1280+
1281+
env.PATH = `${prereleaseBin};${stableBin}`;
1282+
// With only the prerelease install left, it still opens by name.
1283+
yield* fs.remove(path.join(stableBin, "zed.EXE"));
1284+
assert.equal((yield* launchZed).command, "zed");
1285+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
1286+
);
12371287

12381288
const launchWindowsShimEditor = (cwd: string) =>
12391289
Effect.gen(function* () {
Collapse file

‎packages/shared/src/editor.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/editor.ts
+26-2Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@ import * as Stream from "effect/Stream";
77
import { ChildProcess, ChildProcessSpawner } from "effect/process";
88

99
import * as HostProcess from "./HostProcess.ts";
10-
import { isCommandAvailable, resolveCommandPath } from "./shell.ts";
10+
import { isCommandAvailable, resolveCommandPath, resolveCommandPaths } from "./shell.ts";
1111

1212
type Editor = (typeof EDITORS)[number];
1313

14+
// The nearest Zed folder identifies the channel, even below a user named zedpreview.
15+
const isPrereleaseZedPath = (filePath: string) => {
16+
const install = filePath
17+
.split(/[\\/]/)
18+
.slice(0, -1)
19+
.findLast((folder) => folder.toLowerCase().includes("zed"))
20+
?.toLowerCase();
21+
return install !== undefined && (install.includes("nightly") || install.includes("preview"));
22+
};
23+
1424
const installNames: Partial<Record<Editor["id"], ReadonlyArray<string>>> = {
1525
vscode: ["Visual Studio Code"],
1626
"vscode-insiders": ["Visual Studio Code - Insiders"],
@@ -59,7 +69,21 @@ export const resolveEditorCommand = Effect.fn("editor.resolveEditorCommand")(fun
5969
// Prefer Zed's macOS bundle because OpenZFS also installs a zed executable.
6070
const preferBundle = platform === "darwin" && editor.id === "zed";
6171
const preferZeditor = platform === "linux" && editor.id === "zed";
62-
if (!preferBundle && !preferZeditor) {
72+
if (platform === "win32" && editor.id === "zed") {
73+
const isStable = (resolved: string) => !isPrereleaseZedPath(resolved);
74+
let firstCommand: string | undefined;
75+
for (const command of editor.commands) {
76+
const matches = yield* resolveCommandPaths(command, { env, until: isStable });
77+
const stable = matches.find(isStable);
78+
// Bypass PATH only when stable is behind a prerelease install.
79+
if (stable !== undefined) {
80+
const isFirst = firstCommand === undefined && stable === matches[0];
81+
return Option.some({ command: isFirst ? command : stable, baseArgs });
82+
}
83+
if (firstCommand === undefined && matches.length > 0) firstCommand = command;
84+
}
85+
if (firstCommand !== undefined) return Option.some({ command: firstCommand, baseArgs });
86+
} else if (!preferBundle && !preferZeditor) {
6387
for (const command of editor.commands) {
6488
if (yield* isCommandAvailable(command, { env })) return Option.some({ command, baseArgs });
6589
}
Collapse file

‎packages/shared/src/shell.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/shell.ts
+68-29Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,47 @@ const isExecutableFile = Effect.fnUntraced(function* (
640640
return canExecuteFile(filePath);
641641
});
642642

643+
// Called within the traced command resolvers.
644+
const findOnPath = Effect.fnUntraced(function* (
645+
pathValue: string,
646+
commandCandidates: ReadonlyArray<string>,
647+
platform: NodeJS.Platform,
648+
windowsPathExtensions: ReadonlyArray<string>,
649+
isLast: (match: string) => boolean,
650+
): Effect.fn.Return<ReadonlyArray<string>, never, FileSystem.FileSystem | Path.Path> {
651+
const path = yield* Path.Path;
652+
// Keep case variants: Windows can make PATH directories case-sensitive.
653+
const pathEntries: string[] = [];
654+
const seenPathEntries = new Set<string>();
655+
for (const entry of pathValue.split(pathDelimiterForPlatform(platform))) {
656+
const pathEntry = stripWrappingQuotes(entry.trim());
657+
if (pathEntry.length === 0 || seenPathEntries.has(pathEntry)) continue;
658+
659+
seenPathEntries.add(pathEntry);
660+
pathEntries.push(pathEntry);
661+
}
662+
663+
const listings = yield* PathDirectoryListings;
664+
const matches: string[] = [];
665+
for (const pathEntry of pathEntries) {
666+
let listing = listings && (yield* Cache.get(listings, pathEntry));
667+
if (listings && listing?.names && listing.modified !== (yield* directoryMtime(pathEntry))) {
668+
yield* Cache.invalidate(listings, pathEntry);
669+
listing = yield* Cache.get(listings, pathEntry);
670+
}
671+
for (const candidate of commandCandidates) {
672+
if (listing?.names && !listing.names.has(candidate.toLowerCase())) continue;
673+
const candidatePath = path.join(pathEntry, candidate);
674+
if (yield* isExecutableFile(candidatePath, platform, windowsPathExtensions)) {
675+
matches.push(candidatePath);
676+
if (isLast(candidatePath)) return matches;
677+
break;
678+
}
679+
}
680+
}
681+
return matches;
682+
});
683+
643684
const resolveCommandPathForPlatform = Effect.fn("shell.resolveCommandPathForPlatform")(function* (
644685
command: string,
645686
options: CommandAvailabilityOptions & { readonly platform: NodeJS.Platform },
@@ -679,35 +720,15 @@ const resolveCommandPathForPlatform = Effect.fn("shell.resolveCommandPathForPlat
679720
return cached.resolvedPath;
680721
}
681722

682-
// Keep case variants: Windows can make PATH directories case-sensitive.
683-
const pathEntries: string[] = [];
684-
const seenPathEntries = new Set<string>();
685-
for (const entry of pathValue.split(pathDelimiterForPlatform(platform))) {
686-
const pathEntry = stripWrappingQuotes(entry.trim());
687-
if (pathEntry.length === 0 || seenPathEntries.has(pathEntry)) continue;
688-
689-
seenPathEntries.add(pathEntry);
690-
pathEntries.push(pathEntry);
691-
}
692-
693-
const listings = yield* PathDirectoryListings;
694-
for (const pathEntry of pathEntries) {
695-
let listing = listings && (yield* Cache.get(listings, pathEntry));
696-
if (listings && listing?.names && listing.modified !== (yield* directoryMtime(pathEntry))) {
697-
yield* Cache.invalidate(listings, pathEntry);
698-
listing = yield* Cache.get(listings, pathEntry);
699-
}
700-
for (const candidate of commandCandidates) {
701-
if (listing?.names && !listing.names.has(candidate.toLowerCase())) continue;
702-
const candidatePath = path.join(pathEntry, candidate);
703-
if (yield* isExecutableFile(candidatePath, platform, windowsPathExtensions)) {
704-
cacheCommandResolution(cache, cacheKey, candidatePath, nowNanos);
705-
return candidatePath;
706-
}
707-
}
708-
}
709-
cacheCommandResolution(cache, cacheKey, null, nowNanos);
710-
return null;
723+
const [resolvedPath = null] = yield* findOnPath(
724+
pathValue,
725+
commandCandidates,
726+
platform,
727+
windowsPathExtensions,
728+
() => true,
729+
);
730+
cacheCommandResolution(cache, cacheKey, resolvedPath, nowNanos);
731+
return resolvedPath;
711732
});
712733

713734
export const resolveCommandPath = Effect.fn("shell.resolveCommandPath")(function* (
@@ -720,6 +741,24 @@ export const resolveCommandPath = Effect.fn("shell.resolveCommandPath")(function
720741
});
721742
});
722743

744+
// Matches for a bare command in PATH order, up to the first one `until` accepts; not cached.
745+
export const resolveCommandPaths = Effect.fn("shell.resolveCommandPaths")(function* (
746+
command: string,
747+
options: CommandAvailabilityOptions & { readonly until: (match: string) => boolean },
748+
) {
749+
const path = yield* Path.Path;
750+
const platform = yield* HostProcess.Platform;
751+
const env = options.env ?? (yield* HostProcess.Environment);
752+
const windowsPathExtensions = platform === "win32" ? resolveWindowsPathExtensions(env) : [];
753+
return yield* findOnPath(
754+
resolvePathEnvironmentVariable(env),
755+
resolveCommandCandidates(command, platform, windowsPathExtensions, path.extname),
756+
platform,
757+
windowsPathExtensions,
758+
options.until,
759+
);
760+
});
761+
723762
// Git 2.56 x64 uses ucrt64; ARM64 uses clangarm64; older x64/32-bit builds use mingw64/mingw32.
724763
const GIT_FOR_WINDOWS_BUILDS = ["ucrt64", "clangarm64", "mingw64", "mingw32"] as const;
725764

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.