Skip to content

Commit 87ffc66

Browse files
feat(Sky): Expand vscode-file URL rewriting and add terminal addon stubs
The vscode-file:// URL rewrite logic in Workbench.ts is expanded to handle all VS Code asset paths, not just those under `/out/`. This now covers: - /Static/Application/out/vs/... - /Static/Application/vs/... - /Static/Application/node_modules/... The astro.config.ts build process receives several improvements: 1. Try Output service path first, fall back to Wind for the Tauri service module 2. Strip sourceMappingURL references to prevent 404 → HTML → JSON parse errors 3. Filter expected errors (Canceled, FileNotFound) in global error listeners to reduce noise 4. Create a stub for @xterm/addon-progress (unpublished npm package) using AMD define() format - without this, VS Code's AMD loader gets a 404 HTML response that causes SyntaxError Add @xterm addon packages (clipboard, image, ligatures, search, serialize, unicode11, webgl) to enable full terminal emulation in the editor.
1 parent 5619612 commit 87ffc66

3 files changed

Lines changed: 85 additions & 9 deletions

File tree

Source/Workbench/Electron/Workbench.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,20 @@ if (typeof (globalThis as any).__name !== "function") {
117117
) {
118118
Parts = Parts.map((Part) => {
119119
if (typeof Part !== "string") return Part;
120-
return Part.replace(
120+
// Rewrite all vscode-file:// URLs to http:// so blob workers
121+
// can fetch modules. Handles:
122+
// vscode-file://vscode-app/Static/Application/out/vs/...
123+
// vscode-file://vscode-app/Static/Application/vs/...
124+
// vscode-file://vscode-app/Static/Application/node_modules/...
125+
let Rewritten = Part.replace(
121126
/vscode-file:\/\/vscode-app\/Static\/Application\/out\//g,
122127
`${Origin}/Static/Application/`,
123128
);
129+
Rewritten = Rewritten.replace(
130+
/vscode-file:\/\/vscode-app\//g,
131+
`${Origin}/`,
132+
);
133+
return Rewritten;
124134
});
125135
Parts = [NameShim, ...Parts];
126136
}

astro.config.ts

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* build context logging to `Element/Sky/Source/Function/Debug.ts`.
1414
*--------------------------------------------------------------------------------------------*/
1515

16-
import { copyFile, cp, readdir, readFile, writeFile } from "node:fs/promises";
16+
import { copyFile, cp, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
1717
import { join, resolve } from "node:path";
1818
import { fileURLToPath } from "node:url";
1919

@@ -256,17 +256,45 @@ export default defineConfig({
256256
);
257257

258258
try {
259-
const TauriServiceSource = resolve(
259+
// Source from Output (consolidated) first, fall back to Wind
260+
const OutputServicePath = resolve(
261+
process.cwd(),
262+
"node_modules/@codeeditorland/output/Configuration/Service/TauriMainProcessService.js",
263+
);
264+
const WindServicePath = resolve(
260265
process.cwd(),
261266
"node_modules/@codeeditorland/wind/Target/Service/TauriMainProcessService.js",
262267
);
263268

269+
let TauriServiceSource: string;
270+
try {
271+
await readFile(OutputServicePath);
272+
TauriServiceSource = OutputServicePath;
273+
console.log("[CopyVSCode] Step 7: Using Output/Configuration/Service/TauriMainProcessService.js");
274+
} catch {
275+
TauriServiceSource = WindServicePath;
276+
console.log("[CopyVSCode] Step 7: Falling back to Wind/Target/Service/TauriMainProcessService.js");
277+
}
278+
264279
// Copy the compiled service as a separate module
265280
await copyFile(
266281
TauriServiceSource,
267282
join(IPCDir, "TauriMainProcessService.js"),
268283
);
269284

285+
// Strip sourceMappingURL to prevent 404 → HTML → JSON parse error
286+
const ServiceJS = await readFile(
287+
join(IPCDir, "TauriMainProcessService.js"),
288+
"utf-8",
289+
);
290+
if (ServiceJS.includes("sourceMappingURL")) {
291+
await writeFile(
292+
join(IPCDir, "TauriMainProcessService.js"),
293+
ServiceJS.replace(/\/\/# sourceMappingURL=.*/g, ""),
294+
"utf-8",
295+
);
296+
}
297+
270298
// Replace mainProcessService.js with a minimal ESM re-export
271299
await writeFile(
272300
join(IPCDir, "mainProcessService.js"),
@@ -302,9 +330,10 @@ export default defineConfig({
302330
let Content = await readFile(WorkbenchJS, "utf-8");
303331

304332
// 8a: Prepend global error listeners before the IIFE
333+
// Filter out expected errors: FileNotFound from stat(), Canceled from model disposal
305334
const ErrorListeners = [
306-
`window.addEventListener("unhandledrejection",(e)=>{console.error("[workbench.js:unhandledrejection]",e.reason);if(e.reason&&e.reason.stack)console.error(e.reason.stack);});`,
307-
`window.addEventListener("error",(e)=>{console.error("[workbench.js:error]",e.message,e.filename,e.lineno);});`,
335+
`window.addEventListener("unhandledrejection",(e)=>{var r=e.reason;if(!r)return;var m=String(r.message||r);if(m.includes("Canceled")||m.includes("FileNotFound")||(r.code&&r.code==="FileNotFound")||m.includes("No such file or directory"))return;console.error("[workbench.js:unhandledrejection]",r);if(r&&r.stack)console.error(r.stack);});`,
336+
`window.addEventListener("error",(e)=>{if(e.message==="Script error.")return;console.error("[workbench.js:error]",e.message,e.filename,e.lineno);});`,
308337
].join("\n");
309338

310339
Content = ErrorListeners + "\n" + Content;
@@ -481,21 +510,19 @@ export default defineConfig({
481510
}
482511
}
483512

484-
// Step 7: Copy @xterm and other VS Code node_modules
513+
// Step 11: Copy @xterm and other VS Code node_modules
485514
// VS Code's importAMDNodeModule loads from
486515
// /Static/Application/node_modules/@xterm/xterm/lib/xterm.js
487516
const NodeModulesToCopy = [
488517
"@xterm/xterm",
489518
"@xterm/addon-clipboard",
490519
"@xterm/addon-image",
491520
"@xterm/addon-ligatures",
492-
"@xterm/addon-progress",
493521
"@xterm/addon-search",
494522
"@xterm/addon-serialize",
495523
"@xterm/addon-unicode11",
496524
"@xterm/addon-webgl",
497525
"@vscode/vscode-languagedetection",
498-
"vscode-regexp-languagedetection",
499526
];
500527

501528
for (const Pkg of NodeModulesToCopy) {
@@ -518,7 +545,39 @@ export default defineConfig({
518545
}
519546
}
520547
console.log(
521-
"[CopyVSCode] Step 7: Copied node_modules for terminal + language detection",
548+
"[CopyVSCode] Step 11: Copied node_modules for terminal + language detection",
549+
);
550+
551+
// Step 12: Create stubs for unpublished xterm addons.
552+
// VS Code's xtermAddonImporter.ts references @xterm/addon-progress
553+
// but the package doesn't exist on npm yet. Without a stub, the
554+
// AMD loader gets a 404 → HTML → SyntaxError. Provide a no-op.
555+
// VS Code's amdX loader uses define() not ESM import.
556+
const StubAddons: Record<string, string> = {
557+
"@xterm/addon-progress":
558+
"define([],function(){return{ProgressAddon:function(){this.activate=function(){};this.dispose=function(){}}}})",
559+
};
560+
for (const [Pkg, Code] of Object.entries(StubAddons)) {
561+
const StubDir = join(
562+
TargetDir,
563+
"Static/Application/node_modules",
564+
Pkg,
565+
"lib",
566+
);
567+
try {
568+
await mkdir(StubDir, { recursive: true });
569+
const FileName = Pkg.split("/").pop()!;
570+
await writeFile(
571+
join(StubDir, `${FileName}.js`),
572+
Code,
573+
"utf-8",
574+
);
575+
} catch {
576+
// Non-critical
577+
}
578+
}
579+
console.log(
580+
"[CopyVSCode] Step 12: Created stubs for unpublished addons",
522581
);
523582

524583
console.log("[CopyVSCode] ✓ Assets ready in Target/");

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
"@playform/compress": "0.2.3",
3737
"@playform/inline": "0.1.4",
3838
"@vscode/vscode-languagedetection": "^1.0.23",
39+
"@xterm/addon-clipboard": "0.2.0-beta.69",
40+
"@xterm/addon-image": "0.9.0-beta.69",
41+
"@xterm/addon-ligatures": "0.10.0-beta.69",
42+
"@xterm/addon-search": "0.16.0-beta.69",
43+
"@xterm/addon-serialize": "0.14.0-beta.69",
44+
"@xterm/addon-unicode11": "0.9.0-beta.69",
45+
"@xterm/addon-webgl": "0.19.0-beta.69",
3946
"@xterm/xterm": "6.1.0-beta.196",
4047
"astro": "6.1.5",
4148
"deepmerge-ts": "7.1.5",

0 commit comments

Comments
 (0)