-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Refactor open service onto Effect-backed process spawning #1603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2ade037
d7257df
d358a66
7fa5304
439e8bc
935e7c6
0cdb35e
c547247
9b3394c
72c3478
1218eff
8d257e2
b909b94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| started | ||
| started | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| import { spawn } from "node:child_process"; | ||
| import { accessSync, constants, statSync } from "node:fs"; | ||
| import { extname, join } from "node:path"; | ||
| import { pathToFileURL } from "node:url"; | ||
|
|
||
| import { EDITORS, OpenError, type EditorId } from "@t3tools/contracts"; | ||
| import { Context, Effect, Layer } from "effect"; | ||
|
|
@@ -35,6 +36,11 @@ interface CommandAvailabilityOptions { | |
| } | ||
|
|
||
| const TARGET_WITH_POSITION_PATTERN = /^(.*?):(\d+)(?::(\d+))?$/; | ||
| const WINDOWS_EDITOR_URI_SCHEMES: Partial<Record<EditorId, string>> = { | ||
| vscode: "vscode", | ||
| "vscode-insiders": "vscode-insiders", | ||
| vscodium: "vscodium", | ||
| }; | ||
|
|
||
| function parseTargetPathAndPosition(target: string): { | ||
| path: string; | ||
|
|
@@ -53,6 +59,36 @@ function parseTargetPathAndPosition(target: string): { | |
| }; | ||
| } | ||
|
|
||
| function splitTargetPathAndSuffix(target: string): { | ||
| path: string; | ||
| suffix: string; | ||
| } { | ||
| const parsedTarget = parseTargetPathAndPosition(target); | ||
| if (!parsedTarget) { | ||
| return { path: target, suffix: "" }; | ||
| } | ||
|
|
||
| return { | ||
| path: parsedTarget.path, | ||
| suffix: parsedTarget.column | ||
| ? `:${parsedTarget.line}:${parsedTarget.column}` | ||
| : `:${parsedTarget.line}`, | ||
| }; | ||
| } | ||
|
|
||
| function makeWindowsEditorProtocolTarget(editor: EditorId, target: string): string | undefined { | ||
| const scheme = WINDOWS_EDITOR_URI_SCHEMES[editor]; | ||
| if (!scheme) return undefined; | ||
|
|
||
| const { path, suffix } = splitTargetPathAndSuffix(target); | ||
| const fileUrl = pathToFileURL(path).href; | ||
| const fileTarget = fileUrl.startsWith("file:///") | ||
| ? fileUrl.slice("file:///".length) | ||
| : fileUrl.replace(/^file:\/\//, ""); | ||
|
|
||
| return `${scheme}://file/${fileTarget}${suffix}`; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate
|
||
|
|
||
| function resolveCommandEditorArgs( | ||
| editor: (typeof EDITORS)[number], | ||
| target: string, | ||
|
|
@@ -268,6 +304,16 @@ export const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* ( | |
| return yield* new OpenError({ message: `Unknown editor: ${input.editor}` }); | ||
| } | ||
|
|
||
| if (platform === "win32") { | ||
| const protocolTarget = makeWindowsEditorProtocolTarget(input.editor, input.cwd); | ||
| if (protocolTarget) { | ||
| return { | ||
| command: fileManagerCommandForPlatform(platform), | ||
| args: [protocolTarget], | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| if (editorDef.commands) { | ||
| const command = | ||
| resolveAvailableCommand(editorDef.commands, { platform, env }) ?? editorDef.commands[0]; | ||
|
|
@@ -296,7 +342,12 @@ export const launchDetached = (launch: EditorLaunch) => | |
| child = spawn(launch.command, [...launch.args], { | ||
| detached: true, | ||
| stdio: "ignore", | ||
| shell: process.platform === "win32", | ||
| shell: | ||
| process.platform === "win32" && | ||
| launch.command.toLowerCase() !== "explorer" && | ||
| !launch.command.toLowerCase().endsWith("\\explorer.exe") && | ||
| !launch.command.toLowerCase().endsWith("/explorer.exe"), | ||
| ...(process.platform === "win32" ? { windowsHide: true } : {}), | ||
| }); | ||
| } catch (error) { | ||
| return resume( | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug test files accidentally committed to repository
Medium Severity
apps/server/spawned2.txt(containing "started" output) andapps/server/tmp-test.cmd(a batch file that appends tospawned2.txt) are debug/test artifacts that were accidentally included in the commit. These files are not referenced by any production or test code and appear to be leftovers from manual testing of process spawning.Additional Locations (1)
apps/server/tmp-test.cmd#L1-L3Reviewed by Cursor Bugbot for commit 8d257e2. Configure here.