From c1b49b18e255dc6734c240f48458017dc0ef723e Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:46:20 -0800 Subject: [PATCH 1/2] Drop redundant links contribution import monaco-editor-core's editor.main already registers the links contribution through editor.all. Importing the contribution from monaco-editor pulls in that package's separate copy of the editor core, so the registration lands in an editor instance the playground never uses while adding hundreds of duplicate modules to the bundle. --- packages/playground-v2/src/global.d.ts | 1 - packages/playground-v2/src/main.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/playground-v2/src/global.d.ts b/packages/playground-v2/src/global.d.ts index e4fb1ae047a1..530394c3c503 100644 --- a/packages/playground-v2/src/global.d.ts +++ b/packages/playground-v2/src/global.d.ts @@ -3,7 +3,6 @@ declare module "*.json" { const value: any export default value } -declare module "monaco-editor/editor/contrib/links/browser/links.js" declare module "monaco-editor-core/esm/vs/base/browser/touch.js" { export const EventType: { Change: string; Tap: string } diff --git a/packages/playground-v2/src/main.ts b/packages/playground-v2/src/main.ts index f7b31df12421..2069c85371a4 100644 --- a/packages/playground-v2/src/main.ts +++ b/packages/playground-v2/src/main.ts @@ -15,7 +15,6 @@ import { loadLegacyCompilerVersions, publishedNativeCompilerSelection, } from "./compiler-versions" -import "monaco-editor/editor/contrib/links/browser/links.js" import LZString from "lz-string" import "reflect-metadata" import { From 3439dd6f7c62bfa495d73592f7bb815df9b1379f Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:46:20 -0800 Subject: [PATCH 2/2] Resolve monaco-editor core imports to monaco-editor-core The Monarch language definitions and the editor worker entry come from monaco-editor, which ships its own build of the editor core under esm/vs. Bundling them as-is includes a second copy of Monaco with its own service registries, which inflates the playground bundle and misses the patch applied to monaco-editor-core. Both packages are built from the same VS Code commit, so the relative imports from monaco-editor into vs/ can resolve to the equivalent monaco-editor-core modules. The build also fails if any monaco-editor module with a monaco-editor-core counterpart ends up in the output, so a future mismatch between the two packages is caught early. --- packages/playground-v2/scripts/build.mjs | 34 +++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/playground-v2/scripts/build.mjs b/packages/playground-v2/scripts/build.mjs index 33dae9adbcc5..9d689e585724 100644 --- a/packages/playground-v2/scripts/build.mjs +++ b/packages/playground-v2/scripts/build.mjs @@ -1,6 +1,7 @@ import { context } from "esbuild" +import { existsSync } from "node:fs" import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises" -import { dirname, resolve } from "node:path" +import { dirname, relative, resolve, sep } from "node:path" import { fileURLToPath } from "node:url" import { compatibilityHtml, compatibilityPaths, playgroundPath } from "./routes.mjs" @@ -16,6 +17,11 @@ const serve = process.argv.includes("--serve") const playgroundBase = serve ? "/" : process.env.PLAYGROUND_BASE ?? playgroundPath const editorWorker = fileURLToPath(import.meta.resolve("monaco-editor/editor/editor.worker")) +const monacoEditorVs = resolve(fileURLToPath(import.meta.resolve("monaco-editor/editor/editor.api.js")), "../..") +const monacoEditorCoreVs = resolve( + fileURLToPath(import.meta.resolve("monaco-editor-core/esm/vs/editor/editor.api.js")), + "../.." +) const coiServiceWorker = fileURLToPath(import.meta.resolve("coi-serviceworker/coi-serviceworker.min.js")) const indexHtml = (await readFile(resolve(packageDirectory, "src/index.html"), "utf8")).replaceAll( @@ -30,6 +36,25 @@ await Promise.all([ cp(coiServiceWorker, resolve(outputDirectory, "coi-serviceworker.min.js")), ]) +// monaco-editor ships its own copy of the editor core. Its relative imports into +// vs/ resolve to the matching monaco-editor-core files so the language +// definitions and editor worker share the patched core used by the app. +const monacoEditorCorePath = path => { + if (!path.startsWith(monacoEditorVs + sep)) return + const corePath = resolve(monacoEditorCoreVs, relative(monacoEditorVs, path)) + return existsSync(corePath) ? corePath : undefined +} +const monacoEditorCorePlugin = { + name: "monaco-editor-core", + setup(build) { + build.onResolve({ filter: /^\./ }, args => { + if (!args.importer.startsWith(monacoEditorVs + sep)) return + const corePath = monacoEditorCorePath(resolve(args.resolveDir, args.path)) + if (corePath) return { path: corePath } + }) + }, +} + const buildContext = await context({ absWorkingDir: packageDirectory, bundle: true, @@ -51,6 +76,7 @@ const buildContext = await context({ outdir: outputDirectory, metafile: true, platform: "browser", + plugins: [monacoEditorCorePlugin], sourcemap: true, target: ["es2022"], }) @@ -69,6 +95,12 @@ if (serve) { /node_modules\/(?:@typescript\/)?typescript(?:-wasip1-wasm)?\//.test(path) ) if (compilerInputs.length) throw new Error(`Compiler implementation was bundled: ${compilerInputs.join(", ")}`) + const duplicateMonacoInputs = Object.keys(result.metafile.inputs).filter(path => + monacoEditorCorePath(resolve(packageDirectory, path)) + ) + if (duplicateMonacoInputs.length) { + throw new Error(`monaco-editor core was bundled alongside monaco-editor-core: ${duplicateMonacoInputs.join(", ")}`) + } await buildContext.dispose() await rm(websitePlayDirectory, { force: true, recursive: true }) await cp(outputDirectory, websiteStaticDirectory, { recursive: true })