diff --git a/frontend/package.json b/frontend/package.json index 952b52ccc6..5b7317589b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -5,7 +5,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", - "postinstall": "node scripts/untar_ui_builder.js", + "postinstall": "node scripts/untar_ui_builder.js && node scripts/patch_files.js", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --threshold warning", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .", diff --git a/frontend/scripts/patch_files.js b/frontend/scripts/patch_files.js new file mode 100644 index 0000000000..291468f913 --- /dev/null +++ b/frontend/scripts/patch_files.js @@ -0,0 +1,57 @@ +// patch-editor-worker.mjs +import { readFile, writeFile } from 'fs/promises' +import path from 'path' +import { fileURLToPath } from 'url' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) +const filePath = path.join( + __dirname, + '..', + 'node_modules', + '@codingame', + 'monaco-vscode-api', + 'workers', + 'editor.worker.js' +) + +const originalSnippet = `return requestHandler?.[propKey];` + +const patchedCode = ` +import '../vscode/src/vs/editor/common/services/editorWebWorkerMain.js'; +import { start } from '../vscode/src/vs/editor/editor.worker.start.js'; + +function initialize(createFn) { + let requestHandler; + const foreignModule = new Proxy({}, { + get(_target, propKey) { + if (propKey === '$initialize') { + return async (data) => { + if (!requestHandler) { + requestHandler = createFn(context, data); + } + }; + } + const value = requestHandler?.[propKey] + if (typeof value === 'function') { + return value.bind(requestHandler); + } + return value; + } + }); + const context = start(foreignModule); +} + +export { initialize }; +` + +try { + const current = await readFile(filePath, 'utf8') + if (current.includes(originalSnippet)) { + await writeFile(filePath, patchedCode, 'utf8') + console.log('✅ editor.worker.js patched successfully.') + } else { + console.log('â„šī¸ Patch already applied or file has changed.') + } +} catch (err) { + console.error('❌ Failed to patch editor.worker.js:', err) +} diff --git a/frontend/src/lib/components/SimpleEditor.svelte b/frontend/src/lib/components/SimpleEditor.svelte index 8edb013a1a..7cca3416ae 100644 --- a/frontend/src/lib/components/SimpleEditor.svelte +++ b/frontend/src/lib/components/SimpleEditor.svelte @@ -545,7 +545,6 @@ previousExtraLib = extraLib } languages.typescript.javascriptDefaults.setExtraLibs(libs) - setDiagnosticsOptions() } }