@antone-io/render-picker 0.0.0-stage → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +324 -2
- package/dist/chunk-FM3HLV7V.js +105 -0
- package/dist/chunk-FM3HLV7V.js.map +1 -0
- package/dist/chunk-RT6TNNKG.js +6281 -0
- package/dist/chunk-RT6TNNKG.js.map +1 -0
- package/dist/chunk-XUPSSH7J.js +2676 -0
- package/dist/chunk-XUPSSH7J.js.map +1 -0
- package/dist/client.cjs +2498 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +165 -0
- package/dist/client.d.ts +165 -0
- package/dist/client.js +78 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +8885 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +261 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +19 -0
- package/dist/next.d.ts +19 -0
- package/dist/next.js +234 -0
- package/dist/next.js.map +1 -0
- package/dist/react.cjs +8103 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +94 -0
- package/dist/react.d.ts +94 -0
- package/dist/react.js +20 -0
- package/dist/react.js.map +1 -0
- package/dist/types-DrSxB-xa.d.cts +207 -0
- package/dist/types-DrSxB-xa.d.ts +207 -0
- package/package.json +114 -4
package/dist/next.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// src/next.ts
|
|
2
|
+
import { existsSync as existsSync2, readFileSync, statSync, writeFileSync } from "fs";
|
|
3
|
+
import { isAbsolute, join, relative, resolve } from "path";
|
|
4
|
+
|
|
5
|
+
// src/core/dev/editors.ts
|
|
6
|
+
var EDITORS = [
|
|
7
|
+
{ id: "vscode", label: "VS Code", scheme: "vscode", family: "vscode" },
|
|
8
|
+
{ id: "vscode-insiders", label: "VS Code Insiders", scheme: "vscode-insiders", family: "vscode" },
|
|
9
|
+
{ id: "cursor", label: "Cursor", scheme: "cursor", family: "vscode" },
|
|
10
|
+
{ id: "windsurf", label: "Windsurf", scheme: "windsurf", family: "vscode" },
|
|
11
|
+
{ id: "vscodium", label: "VSCodium", scheme: "vscodium", family: "vscode" },
|
|
12
|
+
{ id: "zed", label: "Zed", scheme: "zed", family: "zed" },
|
|
13
|
+
{ id: "webstorm", label: "WebStorm", scheme: "webstorm", family: "jetbrains" },
|
|
14
|
+
{ id: "phpstorm", label: "PhpStorm", scheme: "phpstorm", family: "jetbrains" },
|
|
15
|
+
{ id: "idea", label: "IntelliJ IDEA", scheme: "idea", family: "jetbrains" },
|
|
16
|
+
{ id: "pycharm", label: "PyCharm", scheme: "pycharm", family: "jetbrains" }
|
|
17
|
+
];
|
|
18
|
+
function isEditorId(value) {
|
|
19
|
+
return typeof value === "string" && EDITORS.some((e) => e.id === value);
|
|
20
|
+
}
|
|
21
|
+
function parseSource(source) {
|
|
22
|
+
const m = /^(.*?)(?::(\d+))?(?::(\d+))?$/.exec(source);
|
|
23
|
+
return { file: m?.[1] ?? source, line: m?.[2], col: m?.[3] };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/server/launch-editor.ts
|
|
27
|
+
import { execFile, spawn } from "child_process";
|
|
28
|
+
import { existsSync } from "fs";
|
|
29
|
+
var WIN_EXES = {
|
|
30
|
+
vscode: ["code.exe"],
|
|
31
|
+
"vscode-insiders": ["code - insiders.exe"],
|
|
32
|
+
cursor: ["cursor.exe"],
|
|
33
|
+
windsurf: ["windsurf.exe"],
|
|
34
|
+
vscodium: ["vscodium.exe"],
|
|
35
|
+
zed: ["zed.exe"],
|
|
36
|
+
webstorm: ["webstorm64.exe", "webstorm.exe"],
|
|
37
|
+
phpstorm: ["phpstorm64.exe", "phpstorm.exe"],
|
|
38
|
+
idea: ["idea64.exe", "idea.exe"],
|
|
39
|
+
pycharm: ["pycharm64.exe", "pycharm.exe"]
|
|
40
|
+
};
|
|
41
|
+
var MAC_APPS = {
|
|
42
|
+
webstorm: ["WebStorm"],
|
|
43
|
+
phpstorm: ["PhpStorm"],
|
|
44
|
+
idea: ["IntelliJ IDEA", "IntelliJ IDEA Ultimate", "IntelliJ IDEA CE"],
|
|
45
|
+
pycharm: ["PyCharm", "PyCharm Professional Edition", "PyCharm CE"]
|
|
46
|
+
};
|
|
47
|
+
var CLI_NAMES = {
|
|
48
|
+
vscode: ["code"],
|
|
49
|
+
"vscode-insiders": ["code-insiders"],
|
|
50
|
+
cursor: ["cursor"],
|
|
51
|
+
windsurf: ["windsurf"],
|
|
52
|
+
vscodium: ["codium", "vscodium"],
|
|
53
|
+
zed: ["zed", "zeditor"],
|
|
54
|
+
webstorm: ["webstorm"],
|
|
55
|
+
phpstorm: ["phpstorm"],
|
|
56
|
+
idea: ["idea"],
|
|
57
|
+
pycharm: ["pycharm"]
|
|
58
|
+
};
|
|
59
|
+
function editorArgs(editor, file, line, col) {
|
|
60
|
+
const family = EDITORS.find((e) => e.id === editor)?.family ?? "vscode";
|
|
61
|
+
const pos = line ? `${file}:${line}${col ? `:${col}` : ""}` : file;
|
|
62
|
+
switch (family) {
|
|
63
|
+
case "vscode":
|
|
64
|
+
return ["-r", "-g", pos];
|
|
65
|
+
case "zed":
|
|
66
|
+
return [pos];
|
|
67
|
+
case "jetbrains":
|
|
68
|
+
return [
|
|
69
|
+
...line ? ["--line", line] : [],
|
|
70
|
+
...line && col ? ["--column", col] : [],
|
|
71
|
+
file
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function findRunningEditor(editor, processPaths) {
|
|
76
|
+
const names = WIN_EXES[editor];
|
|
77
|
+
for (const p of processPaths) {
|
|
78
|
+
const base = p.replace(/\\/g, "/").split("/").pop()?.toLowerCase();
|
|
79
|
+
if (base && names.includes(base)) return p;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
var nodeDeps = {
|
|
84
|
+
platform: process.platform,
|
|
85
|
+
listProcesses: () => new Promise((resolve2) => {
|
|
86
|
+
execFile(
|
|
87
|
+
"powershell.exe",
|
|
88
|
+
[
|
|
89
|
+
"-NoProfile",
|
|
90
|
+
"-NonInteractive",
|
|
91
|
+
"-Command",
|
|
92
|
+
"Get-CimInstance Win32_Process | ForEach-Object { $_.ExecutablePath }"
|
|
93
|
+
],
|
|
94
|
+
{ windowsHide: true, maxBuffer: 8 * 1024 * 1024 },
|
|
95
|
+
(err, stdout) => {
|
|
96
|
+
if (err) return resolve2([]);
|
|
97
|
+
resolve2(
|
|
98
|
+
stdout.split(/\r?\n/).map((l) => l.trim()).filter(Boolean)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}),
|
|
103
|
+
start: (cmd, args) => new Promise((resolve2) => {
|
|
104
|
+
try {
|
|
105
|
+
const child = spawn(cmd, args, { detached: true, stdio: "ignore", windowsHide: true });
|
|
106
|
+
child.once("spawn", () => {
|
|
107
|
+
child.unref();
|
|
108
|
+
resolve2(true);
|
|
109
|
+
});
|
|
110
|
+
child.once("error", () => resolve2(false));
|
|
111
|
+
} catch {
|
|
112
|
+
resolve2(false);
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
run: (cmd, args) => new Promise((resolve2) => {
|
|
116
|
+
execFile(cmd, args, { windowsHide: true }, (err) => resolve2(!err));
|
|
117
|
+
}),
|
|
118
|
+
exists: existsSync
|
|
119
|
+
};
|
|
120
|
+
var exeCache = /* @__PURE__ */ new Map();
|
|
121
|
+
async function launchEditor(editor, file, line, col, deps = nodeDeps) {
|
|
122
|
+
const args = editorArgs(editor, file, line, col);
|
|
123
|
+
if (deps.platform === "win32") {
|
|
124
|
+
const cached = exeCache.get(editor);
|
|
125
|
+
if (cached && deps.exists(cached) && await deps.start(cached, args)) return true;
|
|
126
|
+
exeCache.delete(editor);
|
|
127
|
+
const exe = findRunningEditor(editor, await deps.listProcesses());
|
|
128
|
+
if (exe && await deps.start(exe, args)) {
|
|
129
|
+
exeCache.set(editor, exe);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (deps.platform === "darwin") {
|
|
134
|
+
for (const app of MAC_APPS[editor] ?? []) {
|
|
135
|
+
if (await deps.run("open", ["-na", `${app}.app`, "--args", ...args])) return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (const cli of CLI_NAMES[editor]) {
|
|
139
|
+
if (await deps.start(cli, args)) return true;
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/next.ts
|
|
145
|
+
function readConfigFile() {
|
|
146
|
+
try {
|
|
147
|
+
const raw = readFileSync(join(process.cwd(), "render-picker.config.json"), "utf8");
|
|
148
|
+
return JSON.stringify(JSON.parse(raw));
|
|
149
|
+
} catch {
|
|
150
|
+
return void 0;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function inject(config) {
|
|
154
|
+
if (process.env.NODE_ENV === "production") return config;
|
|
155
|
+
const configFile = readConfigFile();
|
|
156
|
+
return {
|
|
157
|
+
...config,
|
|
158
|
+
env: {
|
|
159
|
+
...config.env,
|
|
160
|
+
NEXT_PUBLIC_PROJECT_ROOT: process.cwd(),
|
|
161
|
+
...configFile ? { NEXT_PUBLIC_RENDER_PICKER_CONFIG: configFile } : {}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function withRenderPicker(config) {
|
|
166
|
+
if (typeof config === "function") {
|
|
167
|
+
return async (...args) => inject(await config(...args));
|
|
168
|
+
}
|
|
169
|
+
return inject(config);
|
|
170
|
+
}
|
|
171
|
+
var CONFIG_PATH = "render-picker.config.json";
|
|
172
|
+
var JSON_HEADERS = { "content-type": "application/json" };
|
|
173
|
+
function configFilePath() {
|
|
174
|
+
return join(process.cwd(), CONFIG_PATH);
|
|
175
|
+
}
|
|
176
|
+
function GET() {
|
|
177
|
+
if (process.env.NODE_ENV === "production") {
|
|
178
|
+
return new Response(null, { status: 404 });
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
const raw = readFileSync(configFilePath(), "utf8");
|
|
182
|
+
JSON.parse(raw);
|
|
183
|
+
return new Response(raw, { headers: JSON_HEADERS });
|
|
184
|
+
} catch {
|
|
185
|
+
return new Response("{}", { headers: JSON_HEADERS });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function json(body, status = 200) {
|
|
189
|
+
return new Response(JSON.stringify(body), { status, headers: JSON_HEADERS });
|
|
190
|
+
}
|
|
191
|
+
async function openInEditor(open) {
|
|
192
|
+
const { editor, source } = open ?? {};
|
|
193
|
+
if (!isEditorId(editor) || typeof source !== "string" || !source) {
|
|
194
|
+
return json({ error: "invalid" }, 400);
|
|
195
|
+
}
|
|
196
|
+
const root = process.cwd();
|
|
197
|
+
const { file, line, col } = parseSource(source.replace(/^\/+/, ""));
|
|
198
|
+
const abs = resolve(root, file);
|
|
199
|
+
const rel = relative(root, abs);
|
|
200
|
+
if (!rel || rel.startsWith("..") || isAbsolute(rel)) return json({ error: "forbidden" }, 403);
|
|
201
|
+
if (!existsSync2(abs) || !statSync(abs).isFile()) return json({ error: "not found" }, 404);
|
|
202
|
+
const ok = await launchEditor(editor, abs, line, col);
|
|
203
|
+
return ok ? json({ ok: true }) : json({ error: "editor not found" }, 500);
|
|
204
|
+
}
|
|
205
|
+
async function POST(req) {
|
|
206
|
+
if (process.env.NODE_ENV === "production") {
|
|
207
|
+
return new Response(null, { status: 404 });
|
|
208
|
+
}
|
|
209
|
+
let parsed;
|
|
210
|
+
try {
|
|
211
|
+
parsed = JSON.parse(await req.text());
|
|
212
|
+
} catch {
|
|
213
|
+
return json({ error: "invalid" }, 400);
|
|
214
|
+
}
|
|
215
|
+
if (parsed && typeof parsed === "object" && "open" in parsed) {
|
|
216
|
+
return openInEditor(parsed.open);
|
|
217
|
+
}
|
|
218
|
+
if (parsed == null || typeof parsed !== "object" || Object.keys(parsed).length === 0) {
|
|
219
|
+
return json({ ok: true, skipped: true });
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
writeFileSync(configFilePath(), `${JSON.stringify(parsed, null, 2)}
|
|
223
|
+
`);
|
|
224
|
+
return json({ ok: true });
|
|
225
|
+
} catch {
|
|
226
|
+
return json({ error: "invalid" }, 400);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
export {
|
|
230
|
+
GET,
|
|
231
|
+
POST,
|
|
232
|
+
withRenderPicker
|
|
233
|
+
};
|
|
234
|
+
//# sourceMappingURL=next.js.map
|
package/dist/next.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/next.ts","../src/core/dev/editors.ts","../src/server/launch-editor.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync, writeFileSync } from \"node:fs\";\nimport { isAbsolute, join, relative, resolve } from \"node:path\";\n\nimport { isEditorId, parseSource } from \"./core/dev/editors\";\nimport { launchEditor } from \"./server/launch-editor\";\n\n// Fichier Node uniquement (next.config + route dev). Jamais bundlé côté navigateur.\n\ntype NextConfigObject = { env?: Record<string, string | undefined> } & Record<\n string,\n unknown\n>;\ntype NextConfigFn<C> = (...args: never[]) => C | Promise<C>;\n\n/** Lit `render-picker.config.json` à la racine, ou `undefined` s'il est absent/invalide. */\nfunction readConfigFile(): string | undefined {\n try {\n const raw = readFileSync(join(process.cwd(), \"render-picker.config.json\"), \"utf8\");\n return JSON.stringify(JSON.parse(raw)); // normalise + valide le JSON\n } catch {\n return undefined;\n }\n}\n\nfunction inject<C extends NextConfigObject>(config: C): C {\n // Dev only — jamais en prod (pas de fuite de chemin local / config dans le bundle).\n if (process.env.NODE_ENV === \"production\") return config;\n const configFile = readConfigFile();\n return {\n ...config,\n env: {\n ...config.env,\n NEXT_PUBLIC_PROJECT_ROOT: process.cwd(),\n ...(configFile\n ? { NEXT_PUBLIC_RENDER_PICKER_CONFIG: configFile }\n : {}),\n },\n };\n}\n\n/**\n * Wrap `next.config` : expose `NEXT_PUBLIC_PROJECT_ROOT` au client hors production.\n * Accepte un objet ou une fonction `(phase, ctx) => config`.\n */\nexport function withRenderPicker<C extends NextConfigObject>(config: C): C;\nexport function withRenderPicker<C extends NextConfigObject, F extends NextConfigFn<C>>(\n config: F,\n): F;\nexport function withRenderPicker(\n config: NextConfigObject | NextConfigFn<NextConfigObject>,\n): unknown {\n if (typeof config === \"function\") {\n return async (...args: never[]) => inject(await config(...args));\n }\n return inject(config);\n}\n\n/* --- Route Handler dev : lit/écrit render-picker.config.json à la racine ---\n * Installer côté app : `app/api/render-picker/route.ts` →\n * export { GET, POST } from \"@antone-io/render-picker/next\";\n */\n\nconst CONFIG_PATH = \"render-picker.config.json\";\nconst JSON_HEADERS = { \"content-type\": \"application/json\" } as const;\n\nfunction configFilePath(): string {\n return join(process.cwd(), CONFIG_PATH);\n}\n\n/** Lit le fichier de config (`{}` si absent). Dev only. */\nexport function GET(): Response {\n if (process.env.NODE_ENV === \"production\") {\n return new Response(null, { status: 404 });\n }\n try {\n const raw = readFileSync(configFilePath(), \"utf8\");\n JSON.parse(raw); // valide\n return new Response(raw, { headers: JSON_HEADERS });\n } catch {\n return new Response(\"{}\", { headers: JSON_HEADERS });\n }\n}\n\nfunction json(body: unknown, status = 200): Response {\n return new Response(JSON.stringify(body), { status, headers: JSON_HEADERS });\n}\n\n/**\n * `{ open: { editor, source } }` → ouvre `source` (`src/…:ligne[:col]`, relatif à la\n * racine) dans l'IDE, côté serveur (aucune config système requise, voir\n * `server/launch-editor`). Refuse tout chemin hors du projet ou inexistant.\n */\nasync function openInEditor(open: unknown): Promise<Response> {\n const { editor, source } = (open ?? {}) as { editor?: unknown; source?: unknown };\n if (!isEditorId(editor) || typeof source !== \"string\" || !source) {\n return json({ error: \"invalid\" }, 400);\n }\n const root = process.cwd();\n const { file, line, col } = parseSource(source.replace(/^\\/+/, \"\"));\n const abs = resolve(root, file);\n const rel = relative(root, abs);\n if (!rel || rel.startsWith(\"..\") || isAbsolute(rel)) return json({ error: \"forbidden\" }, 403);\n if (!existsSync(abs) || !statSync(abs).isFile()) return json({ error: \"not found\" }, 404);\n\n const ok = await launchEditor(editor, abs, line, col);\n return ok ? json({ ok: true }) : json({ error: \"editor not found\" }, 500);\n}\n\n/**\n * Écrit le fichier de config depuis le body JSON — ou, si le body porte `open`,\n * ouvre le fichier dans l'IDE (Alt/Ctrl+clic). Dev only.\n */\nexport async function POST(req: Request): Promise<Response> {\n if (process.env.NODE_ENV === \"production\") {\n return new Response(null, { status: 404 });\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(await req.text());\n } catch {\n return json({ error: \"invalid\" }, 400);\n }\n if (parsed && typeof parsed === \"object\" && \"open\" in parsed) {\n return openInEditor((parsed as { open: unknown }).open);\n }\n // Delta vide (reset UI / réglages = défauts) : ne JAMAIS écraser le fichier de\n // config — il contient peut-être des réglages committés voulus.\n if (\n parsed == null ||\n typeof parsed !== \"object\" ||\n Object.keys(parsed as object).length === 0\n ) {\n return json({ ok: true, skipped: true });\n }\n try {\n writeFileSync(configFilePath(), `${JSON.stringify(parsed, null, 2)}\\n`);\n return json({ ok: true });\n } catch {\n return json({ error: \"invalid\" }, 400);\n }\n}\n","/**\n * Registre des éditeurs supportés par l'ouverture de source (Alt/Ctrl+clic) et\n * construction de leur URI. Pur, sans DOM — testable.\n *\n * Trois formats d'URL :\n * - famille VS Code : `<scheme>://file/<abs>:<ligne>[:<col>]` ;\n * - Zed : `zed://file/<abs>:<ligne>[:<col>]` ;\n * - JetBrains : `<scheme>://open?file=<abs>&line=<ligne>[&column=<col>]`\n * (schéma enregistré par l'IDE / JetBrains Toolbox).\n */\n\n/** Identifiant d'éditeur (valeur persistée dans `commands.editor`). */\nexport type EditorId =\n | \"vscode\"\n | \"vscode-insiders\"\n | \"cursor\"\n | \"windsurf\"\n | \"vscodium\"\n | \"zed\"\n | \"webstorm\"\n | \"phpstorm\"\n | \"idea\"\n | \"pycharm\";\n\ntype EditorFamily = \"vscode\" | \"zed\" | \"jetbrains\";\n\nexport interface EditorInfo {\n id: EditorId;\n /** Libellé affiché dans le dropdown. */\n label: string;\n /** Schéma d'URL enregistré par l'éditeur. */\n scheme: string;\n family: EditorFamily;\n}\n\n/** Éditeurs proposés, dans l'ordre du dropdown. */\nexport const EDITORS: readonly EditorInfo[] = [\n { id: \"vscode\", label: \"VS Code\", scheme: \"vscode\", family: \"vscode\" },\n { id: \"vscode-insiders\", label: \"VS Code Insiders\", scheme: \"vscode-insiders\", family: \"vscode\" },\n { id: \"cursor\", label: \"Cursor\", scheme: \"cursor\", family: \"vscode\" },\n { id: \"windsurf\", label: \"Windsurf\", scheme: \"windsurf\", family: \"vscode\" },\n { id: \"vscodium\", label: \"VSCodium\", scheme: \"vscodium\", family: \"vscode\" },\n { id: \"zed\", label: \"Zed\", scheme: \"zed\", family: \"zed\" },\n { id: \"webstorm\", label: \"WebStorm\", scheme: \"webstorm\", family: \"jetbrains\" },\n { id: \"phpstorm\", label: \"PhpStorm\", scheme: \"phpstorm\", family: \"jetbrains\" },\n { id: \"idea\", label: \"IntelliJ IDEA\", scheme: \"idea\", family: \"jetbrains\" },\n { id: \"pycharm\", label: \"PyCharm\", scheme: \"pycharm\", family: \"jetbrains\" },\n];\n\n/** Éditeur par défaut. */\nexport const DEFAULT_EDITOR: EditorId = \"vscode\";\n\n/** Vrai si `value` est un identifiant d'éditeur connu (config lue d'un JSON). */\nexport function isEditorId(value: unknown): value is EditorId {\n return typeof value === \"string\" && EDITORS.some((e) => e.id === value);\n}\n\n/** `src/a.tsx:42:7` → `{ file, line, col }` (ligne / colonne optionnelles). Pur. */\nexport function parseSource(source: string): { file: string; line?: string; col?: string } {\n const m = /^(.*?)(?::(\\d+))?(?::(\\d+))?$/.exec(source);\n return { file: m?.[1] ?? source, line: m?.[2], col: m?.[3] };\n}\n\n/**\n * Construit l'URI qui ouvre `source` (chemin relatif au projet, `src/…:ligne[:col]`)\n * dans l'éditeur donné. `root` = racine absolue du projet. `null` si l'un manque.\n */\nexport function buildEditorUri(\n editor: EditorId,\n root: string | undefined | null,\n source: string | null,\n): string | null {\n if (!root || !source) return null;\n const normalizedRoot = root.replace(/\\\\/g, \"/\").replace(/\\/+$/, \"\");\n if (!normalizedRoot) return null;\n const rel = source.replace(/^\\/+/, \"\");\n if (!rel) return null;\n\n const info = EDITORS.find((e) => e.id === editor) ?? EDITORS[0]!;\n switch (info.family) {\n case \"vscode\":\n // Format historique de `buildVscodeUri` (inchangé, y compris en posix).\n return `${info.scheme}://file/${normalizedRoot}/${rel}`;\n case \"zed\":\n // `zed://file` + chemin absolu : pas de double slash en posix.\n return `zed://file/${normalizedRoot.replace(/^\\/+/, \"\")}/${rel}`;\n case \"jetbrains\": {\n const { file, line, col } = parseSource(rel);\n let uri = `${info.scheme}://open?file=${encodeURIComponent(`${normalizedRoot}/${file}`)}`;\n if (line) uri += `&line=${line}`;\n if (line && col) uri += `&column=${col}`;\n return uri;\n }\n }\n}\n","import { execFile, spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\n\nimport { EDITORS, type EditorId } from \"../core/dev/editors\";\n\n// Node uniquement (route dev `next.ts`). Jamais bundlé côté navigateur.\n\n/**\n * Ouvre un fichier à une ligne dans l'IDE choisi, côté serveur dev, SANS rien\n * configurer sur la machine (pas de schéma d'URL à enregistrer, pas de Toolbox) :\n * 1. Windows : exécutable de l'IDE **déjà lancé**, lu dans la liste des process ;\n * 2. macOS (JetBrains) : `open -na \"<App>.app\" --args --line N <fichier>` ;\n * 3. partout : CLI de l'IDE si elle est dans le PATH.\n * Jamais de shell : l'exécutable et les arguments sont passés en tableau.\n */\n\n/** Noms d'exécutables Windows (minuscules) d'un IDE lancé. */\nconst WIN_EXES: Record<EditorId, string[]> = {\n vscode: [\"code.exe\"],\n \"vscode-insiders\": [\"code - insiders.exe\"],\n cursor: [\"cursor.exe\"],\n windsurf: [\"windsurf.exe\"],\n vscodium: [\"vscodium.exe\"],\n zed: [\"zed.exe\"],\n webstorm: [\"webstorm64.exe\", \"webstorm.exe\"],\n phpstorm: [\"phpstorm64.exe\", \"phpstorm.exe\"],\n idea: [\"idea64.exe\", \"idea.exe\"],\n pycharm: [\"pycharm64.exe\", \"pycharm.exe\"],\n};\n\n/** Bundles macOS des IDE JetBrains (`open -na <app>`), éditions incluses. */\nconst MAC_APPS: Partial<Record<EditorId, string[]>> = {\n webstorm: [\"WebStorm\"],\n phpstorm: [\"PhpStorm\"],\n idea: [\"IntelliJ IDEA\", \"IntelliJ IDEA Ultimate\", \"IntelliJ IDEA CE\"],\n pycharm: [\"PyCharm\", \"PyCharm Professional Edition\", \"PyCharm CE\"],\n};\n\n/** CLI de l'IDE (si dans le PATH). */\nconst CLI_NAMES: Record<EditorId, string[]> = {\n vscode: [\"code\"],\n \"vscode-insiders\": [\"code-insiders\"],\n cursor: [\"cursor\"],\n windsurf: [\"windsurf\"],\n vscodium: [\"codium\", \"vscodium\"],\n zed: [\"zed\", \"zeditor\"],\n webstorm: [\"webstorm\"],\n phpstorm: [\"phpstorm\"],\n idea: [\"idea\"],\n pycharm: [\"pycharm\"],\n};\n\n/** Arguments « ouvrir à la ligne » selon la famille de l'IDE. Pur. */\nexport function editorArgs(\n editor: EditorId,\n file: string,\n line?: string,\n col?: string,\n): string[] {\n const family = EDITORS.find((e) => e.id === editor)?.family ?? \"vscode\";\n const pos = line ? `${file}:${line}${col ? `:${col}` : \"\"}` : file;\n switch (family) {\n case \"vscode\":\n return [\"-r\", \"-g\", pos];\n case \"zed\":\n return [pos];\n case \"jetbrains\":\n return [\n ...(line ? [\"--line\", line] : []),\n ...(line && col ? [\"--column\", col] : []),\n file,\n ];\n }\n}\n\n/** Chemin de l'exécutable de l'IDE parmi les process lancés (Windows), ou `null`. Pur. */\nexport function findRunningEditor(editor: EditorId, processPaths: string[]): string | null {\n const names = WIN_EXES[editor];\n for (const p of processPaths) {\n const base = p.replace(/\\\\/g, \"/\").split(\"/\").pop()?.toLowerCase();\n if (base && names.includes(base)) return p;\n }\n return null;\n}\n\n/** Effets système, injectables pour les tests. */\nexport interface LaunchDeps {\n platform: NodeJS.Platform;\n /** Chemins des exécutables des process en cours (Windows). */\n listProcesses: () => Promise<string[]>;\n /** Lance détaché ; `true` si le process a démarré. */\n start: (cmd: string, args: string[]) => Promise<boolean>;\n /** Lance et attend la fin ; `true` si code de sortie 0 (`open -a` sur macOS). */\n run: (cmd: string, args: string[]) => Promise<boolean>;\n exists: (path: string) => boolean;\n}\n\nconst nodeDeps: LaunchDeps = {\n platform: process.platform,\n listProcesses: () =>\n new Promise((resolve) => {\n execFile(\n \"powershell.exe\",\n [\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-Command\",\n \"Get-CimInstance Win32_Process | ForEach-Object { $_.ExecutablePath }\",\n ],\n { windowsHide: true, maxBuffer: 8 * 1024 * 1024 },\n (err, stdout) => {\n if (err) return resolve([]);\n resolve(\n stdout\n .split(/\\r?\\n/)\n .map((l) => l.trim())\n .filter(Boolean),\n );\n },\n );\n }),\n start: (cmd, args) =>\n new Promise((resolve) => {\n try {\n const child = spawn(cmd, args, { detached: true, stdio: \"ignore\", windowsHide: true });\n child.once(\"spawn\", () => {\n child.unref();\n resolve(true);\n });\n child.once(\"error\", () => resolve(false));\n } catch {\n resolve(false);\n }\n }),\n run: (cmd, args) =>\n new Promise((resolve) => {\n execFile(cmd, args, { windowsHide: true }, (err) => resolve(!err));\n }),\n exists: existsSync,\n};\n\n/** Exécutable Windows déjà trouvé par IDE (la liste des process coûte ~0,5 s). */\nconst exeCache = new Map<EditorId, string>();\n\n/** Vide le cache des exécutables (tests). */\nexport function resetEditorCache(): void {\n exeCache.clear();\n}\n\n/**\n * Ouvre `file` (chemin absolu) à `line`/`col` dans `editor`. `true` si un\n * lancement a réussi ; `false` → l'appelant retombe sur le lien d'URL.\n */\nexport async function launchEditor(\n editor: EditorId,\n file: string,\n line?: string,\n col?: string,\n deps: LaunchDeps = nodeDeps,\n): Promise<boolean> {\n const args = editorArgs(editor, file, line, col);\n\n if (deps.platform === \"win32\") {\n const cached = exeCache.get(editor);\n if (cached && deps.exists(cached) && (await deps.start(cached, args))) return true;\n exeCache.delete(editor);\n\n const exe = findRunningEditor(editor, await deps.listProcesses());\n if (exe && (await deps.start(exe, args))) {\n exeCache.set(editor, exe);\n return true;\n }\n }\n\n if (deps.platform === \"darwin\") {\n for (const app of MAC_APPS[editor] ?? []) {\n if (await deps.run(\"open\", [\"-na\", `${app}.app`, \"--args\", ...args])) return true;\n }\n }\n\n for (const cli of CLI_NAMES[editor]) {\n if (await deps.start(cli, args)) return true;\n }\n return false;\n}\n"],"mappings":";AAAA,SAAS,cAAAA,aAAY,cAAc,UAAU,qBAAqB;AAClE,SAAS,YAAY,MAAM,UAAU,eAAe;;;ACmC7C,IAAM,UAAiC;AAAA,EAC5C,EAAE,IAAI,UAAU,OAAO,WAAW,QAAQ,UAAU,QAAQ,SAAS;AAAA,EACrE,EAAE,IAAI,mBAAmB,OAAO,oBAAoB,QAAQ,mBAAmB,QAAQ,SAAS;AAAA,EAChG,EAAE,IAAI,UAAU,OAAO,UAAU,QAAQ,UAAU,QAAQ,SAAS;AAAA,EACpE,EAAE,IAAI,YAAY,OAAO,YAAY,QAAQ,YAAY,QAAQ,SAAS;AAAA,EAC1E,EAAE,IAAI,YAAY,OAAO,YAAY,QAAQ,YAAY,QAAQ,SAAS;AAAA,EAC1E,EAAE,IAAI,OAAO,OAAO,OAAO,QAAQ,OAAO,QAAQ,MAAM;AAAA,EACxD,EAAE,IAAI,YAAY,OAAO,YAAY,QAAQ,YAAY,QAAQ,YAAY;AAAA,EAC7E,EAAE,IAAI,YAAY,OAAO,YAAY,QAAQ,YAAY,QAAQ,YAAY;AAAA,EAC7E,EAAE,IAAI,QAAQ,OAAO,iBAAiB,QAAQ,QAAQ,QAAQ,YAAY;AAAA,EAC1E,EAAE,IAAI,WAAW,OAAO,WAAW,QAAQ,WAAW,QAAQ,YAAY;AAC5E;AAMO,SAAS,WAAW,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