diff --git a/monaco-patches/0001-fix-preserve-modules.patch b/monaco-patches/0001-fix-preserve-modules.patch new file mode 100644 index 00000000..99e4fd66 --- /dev/null +++ b/monaco-patches/0001-fix-preserve-modules.patch @@ -0,0 +1,65 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= +Date: Tue, 25 Nov 2025 14:07:33 +0100 +Subject: [PATCH] fix: preserve modules + +--- + build/esm/rollup-types.config.mjs | 5 ++--- + build/releaseMetadata.ts | 9 --------- + build/shared.mjs | 3 +++ + 3 files changed, 5 insertions(+), 12 deletions(-) + +diff --git a/build/esm/rollup-types.config.mjs b/build/esm/rollup-types.config.mjs +index 5043188b..c20573b2 100644 +--- a/build/esm/rollup-types.config.mjs ++++ b/build/esm/rollup-types.config.mjs +@@ -15,13 +15,12 @@ const root = join(import.meta.dirname, '../../'); + + export default defineConfig({ + input: { +- entry: join(root, './src/editor/editor.main.ts'), +- editorApi: join(root, './src/editor/editor.api.ts'), ++ entry: join(root, './src/editor/editor.main.ts') + }, + output: { + dir: join(root, './out/monaco-editor/esm'), + format: 'es', +- preserveModules: false, ++ preserveModules: true, + entryFileNames: function (chunkInfo) { + const moduleId = chunkInfo.facadeModuleId; + if (moduleId) { +diff --git a/build/releaseMetadata.ts b/build/releaseMetadata.ts +index d25ceb76..542aa232 100644 +--- a/build/releaseMetadata.ts ++++ b/build/releaseMetadata.ts +@@ -185,15 +185,6 @@ exports.languages = ${JSON.stringify(languages, null, ' ')}; + const jsDestination = path.join(REPO_ROOT, 'out/monaco-editor/esm/metadata.js'); + ensureDir(path.dirname(jsDestination)); + fs.writeFileSync(jsDestination, jsContents.replace(/\r\n/g, '\n')); +- +- for (const feature of [...features, ...languages]) { +- const entries = [].concat(feature.entry); +- for (const entry of entries) { +- const dtsDestination = path.join(REPO_ROOT, 'out/monaco-editor/esm', entry) + '.d.ts'; +- ensureDir(path.dirname(dtsDestination)); +- fs.writeFileSync(dtsDestination, 'export {}\n'); +- } +- } + } + ); + } +diff --git a/build/shared.mjs b/build/shared.mjs +index dc471455..24c43647 100644 +--- a/build/shared.mjs ++++ b/build/shared.mjs +@@ -14,6 +14,9 @@ import { readdirSync } from 'fs'; + * @param {string} newExt + */ + export function changeExt(filePath, newExt) { ++ if (filePath.endsWith(newExt)) { ++ return filePath ++ } + const idx = filePath.lastIndexOf('.'); + if (idx === -1) { + return filePath + newExt; diff --git a/monaco-patches/0002-fix-properly-render-relative-paths.patch b/monaco-patches/0002-fix-properly-render-relative-paths.patch new file mode 100644 index 00000000..5c9d823e --- /dev/null +++ b/monaco-patches/0002-fix-properly-render-relative-paths.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= +Date: Tue, 25 Nov 2025 15:53:32 +0100 +Subject: [PATCH] fix: properly render relative paths + +--- + build/esm/rollup-url-to-module-plugin/index.mjs | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/build/esm/rollup-url-to-module-plugin/index.mjs b/build/esm/rollup-url-to-module-plugin/index.mjs +index 8a0168bd..cb21f92a 100644 +--- a/build/esm/rollup-url-to-module-plugin/index.mjs ++++ b/build/esm/rollup-url-to-module-plugin/index.mjs +@@ -9,6 +9,13 @@ + export function urlToEsmPlugin() { + return { + name: 'import-meta-url', ++ resolveFileUrl(options) { ++ let relativePath = options.relativePath ++ if (!relativePath.startsWith('.')) { ++ relativePath = `./${options.relativePath}` ++ } ++ return `'${relativePath}'` ++ }, + async transform(code, id) { + if (this.environment?.mode === 'dev') { + return; diff --git a/rollup/rollup.monaco.ts b/rollup/rollup.monaco.ts index f1e002b7..da39643e 100644 --- a/rollup/rollup.monaco.ts +++ b/rollup/rollup.monaco.ts @@ -8,7 +8,7 @@ import * as fs from 'fs' import { fileURLToPath } from 'url' import { EDITOR_API_PACKAGE_NAME } from './tools/config' import { execSync } from 'child_process' -import importMetaAssets from './plugins/import-meta-assets-plugin.js' +import carryDtsPlugin from './plugins/rollup-carry-dts-plugin.js' const pkg = JSON.parse( fs.readFileSync(new URL('../package.json', import.meta.url).pathname).toString() @@ -112,9 +112,9 @@ export default rollup.defineConfig([ const dirname = path.dirname(contributionFile) const language = path.basename(dirname) return { - input: { - index: contributionFile, - worker: path.resolve( + input: [ + contributionFile, + path.resolve( dirname, ( await glob('*.worker.js', { @@ -122,7 +122,7 @@ export default rollup.defineConfig([ }) )[0]! ) - }, + ], treeshake: { preset: 'smallest' }, @@ -144,11 +144,21 @@ export default rollup.defineConfig([ AMD: false, preventAssignment: true }), - importMetaAssets(), resolver, + carryDtsPlugin(), { name: 'loader', - generateBundle() { + generateBundle(options, bundle) { + const allChunkIds = Object.keys(bundle) + + const entryChunkIds: string[] = allChunkIds.filter((chunkId) => { + const output = bundle[chunkId]! + return output.type === 'chunk' && output.isEntry + }) + + const main = entryChunkIds.find((m) => m.includes('monaco.contribution'))! + const worker = entryChunkIds.find((m) => m.includes('worker'))! + const dependencies = Object.fromEntries( Array.from(this.getModuleIds()) .map((id) => this.getModuleInfo(id)!) @@ -178,10 +188,10 @@ export default rollup.defineConfig([ description: `monaco-editor ${language} language features bundled to work with ${pkg.name}`, exports: { '.': { - default: './index.js' + default: './' + main }, './worker': { - default: './worker.js' + default: './' + worker } }, main: 'index.js', @@ -231,7 +241,6 @@ export default rollup.defineConfig([ AMD: false, preventAssignment: true }), - importMetaAssets(), resolver, { name: 'loader', diff --git a/rollup/tools/configuredSubpackagePlugin.ts b/rollup/tools/configuredSubpackagePlugin.ts index 2a8bb91e..e0343714 100644 --- a/rollup/tools/configuredSubpackagePlugin.ts +++ b/rollup/tools/configuredSubpackagePlugin.ts @@ -8,7 +8,6 @@ import importMetaAssets from '../plugins/import-meta-assets-plugin.js' import * as fs from 'node:fs' import * as nodePath from 'node:path' import { - BASE_DIR, EXTENSIONS, pkg, external, @@ -279,27 +278,6 @@ ${code}` } rollupOptions.plugins = [ rollupOptions.plugins, - { - name: 'replace-editor-types', - async renderChunk(code, chunk) { - if (chunk.fileName.endsWith('vscode/src/vs/editor/editor.api.d.ts')) { - const monacoEditorTypes = ( - await fs.promises.readFile( - nodePath.resolve(BASE_DIR, 'monaco-editor/editor.api.d.ts') - ) - ).toString() - - const monacoWorkerTypes = Array.from( - monacoEditorTypes.matchAll(/export namespace languages\..*?^}/gms) - ) - .map((match) => match[0]) - .join('\n') - - return `${code}\n${monacoWorkerTypes}` - } - return undefined - } - }, { name: 'editor-api-expose-modules', async generateBundle() { diff --git a/scripts/install-monaco-editor b/scripts/install-monaco-editor index 6b5cb81a..f1374f90 100755 --- a/scripts/install-monaco-editor +++ b/scripts/install-monaco-editor @@ -6,6 +6,7 @@ monacoRef=$(cat package.json | jq -r '.config.monaco.ref') package_json="`pwd`/package.json" output_directory="`pwd`/monaco-editor" version_info=$output_directory/version.info +patch_directory="`pwd`/monaco-patches" if [[ -e $version_info && $(cat $version_info) == $monacoRef ]]; then echo "monaco-editor version $monacoRef is already installed. Aborting..." @@ -23,6 +24,10 @@ monacoVersion=$(cat "$monaco_build_directory/package.json" | jq -r '.["version"] cat <<< "$(jq ".config.monaco.version = \"$monacoVersion\"" $package_json)" > $package_json cd $monaco_build_directory + +echo "Patching monaco-editor..." +find "$patch_directory" -type f -name '*.patch' -print0 | sort -z | xargs -t -0 -n 1 patch -p1 -i + npm ci # Copy editor types