mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-06 00:14:54 +00:00
* feat(desktop): open files in more installed editors Detect bundled app commands as well as PATH launchers and preserve file positions through editor-specific launches. * fix(desktop): preserve editor target compatibility Keep existing file-manager preference ids, retain project context for file launches, and recognize Windows 64-bit IDE commands.
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import type { SpawnOptions } from "node:child_process";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { createEditorTargetRuntime } from "./runtime.js";
|
|
|
|
interface SpawnRecord {
|
|
command: string;
|
|
args: string[];
|
|
options: SpawnOptions;
|
|
unrefed: boolean;
|
|
}
|
|
|
|
describe("editor target runtime", () => {
|
|
it("resolves command aliases and safely launches Windows command scripts", async () => {
|
|
const records: SpawnRecord[] = [];
|
|
const runtime = createEditorTargetRuntime({
|
|
platform: "win32",
|
|
env: {
|
|
PATH: "C:/Program Files/Editors & Tools/bin",
|
|
ELECTRON_RUN_AS_NODE: "1",
|
|
},
|
|
pathExists: (targetPath) => targetPath === "C:/Program Files/Editors & Tools/bin/code.cmd",
|
|
spawn: (command, args, options) => {
|
|
const record = { command, args, options, unrefed: false };
|
|
records.push(record);
|
|
const child = {
|
|
once(event: "error" | "spawn", handler: (error?: Error) => void) {
|
|
if (event === "spawn") queueMicrotask(() => handler());
|
|
return child;
|
|
},
|
|
unref() {
|
|
record.unrefed = true;
|
|
},
|
|
};
|
|
return child;
|
|
},
|
|
});
|
|
|
|
const command = runtime.resolveCommand(["missing", "code"]);
|
|
if (!command) throw new Error("Expected the editor command to resolve");
|
|
await runtime.spawnDetached({
|
|
command,
|
|
args: ["C:/repo & workspace", "C:/repo/src/file & calculator.ts"],
|
|
});
|
|
|
|
expect(records).toEqual([
|
|
{
|
|
command: '"C:/Program Files/Editors & Tools/bin/code.cmd"',
|
|
args: ['"C:/repo & workspace"', '"C:/repo/src/file & calculator.ts"'],
|
|
options: {
|
|
detached: true,
|
|
env: { PATH: "C:/Program Files/Editors & Tools/bin" },
|
|
shell: true,
|
|
stdio: "ignore",
|
|
},
|
|
unrefed: true,
|
|
},
|
|
]);
|
|
});
|
|
});
|