Skip to content

Commit 21c4067

Browse files
authored
Merge pull request #743 from CodinGame/lmn/fix-standalone-language-features-types
Fix standalone language features types
2 parents 84b142c + c4c6933 commit 21c4067

File tree

5 files changed

+116
-32
lines changed

5 files changed

+116
-32
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= <[email protected]>
3+
Date: Tue, 25 Nov 2025 14:07:33 +0100
4+
Subject: [PATCH] fix: preserve modules
5+
6+
---
7+
build/esm/rollup-types.config.mjs | 5 ++---
8+
build/releaseMetadata.ts | 9 ---------
9+
build/shared.mjs | 3 +++
10+
3 files changed, 5 insertions(+), 12 deletions(-)
11+
12+
diff --git a/build/esm/rollup-types.config.mjs b/build/esm/rollup-types.config.mjs
13+
index 5043188b..c20573b2 100644
14+
--- a/build/esm/rollup-types.config.mjs
15+
+++ b/build/esm/rollup-types.config.mjs
16+
@@ -15,13 +15,12 @@ const root = join(import.meta.dirname, '../../');
17+
18+
export default defineConfig({
19+
input: {
20+
- entry: join(root, './src/editor/editor.main.ts'),
21+
- editorApi: join(root, './src/editor/editor.api.ts'),
22+
+ entry: join(root, './src/editor/editor.main.ts')
23+
},
24+
output: {
25+
dir: join(root, './out/monaco-editor/esm'),
26+
format: 'es',
27+
- preserveModules: false,
28+
+ preserveModules: true,
29+
entryFileNames: function (chunkInfo) {
30+
const moduleId = chunkInfo.facadeModuleId;
31+
if (moduleId) {
32+
diff --git a/build/releaseMetadata.ts b/build/releaseMetadata.ts
33+
index d25ceb76..542aa232 100644
34+
--- a/build/releaseMetadata.ts
35+
+++ b/build/releaseMetadata.ts
36+
@@ -185,15 +185,6 @@ exports.languages = ${JSON.stringify(languages, null, ' ')};
37+
const jsDestination = path.join(REPO_ROOT, 'out/monaco-editor/esm/metadata.js');
38+
ensureDir(path.dirname(jsDestination));
39+
fs.writeFileSync(jsDestination, jsContents.replace(/\r\n/g, '\n'));
40+
-
41+
- for (const feature of [...features, ...languages]) {
42+
- const entries = [].concat(feature.entry);
43+
- for (const entry of entries) {
44+
- const dtsDestination = path.join(REPO_ROOT, 'out/monaco-editor/esm', entry) + '.d.ts';
45+
- ensureDir(path.dirname(dtsDestination));
46+
- fs.writeFileSync(dtsDestination, 'export {}\n');
47+
- }
48+
- }
49+
}
50+
);
51+
}
52+
diff --git a/build/shared.mjs b/build/shared.mjs
53+
index dc471455..24c43647 100644
54+
--- a/build/shared.mjs
55+
+++ b/build/shared.mjs
56+
@@ -14,6 +14,9 @@ import { readdirSync } from 'fs';
57+
* @param {string} newExt
58+
*/
59+
export function changeExt(filePath, newExt) {
60+
+ if (filePath.endsWith(newExt)) {
61+
+ return filePath
62+
+ }
63+
const idx = filePath.lastIndexOf('.');
64+
if (idx === -1) {
65+
return filePath + newExt;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= <[email protected]>
3+
Date: Tue, 25 Nov 2025 15:53:32 +0100
4+
Subject: [PATCH] fix: properly render relative paths
5+
6+
---
7+
build/esm/rollup-url-to-module-plugin/index.mjs | 7 +++++++
8+
1 file changed, 7 insertions(+)
9+
10+
diff --git a/build/esm/rollup-url-to-module-plugin/index.mjs b/build/esm/rollup-url-to-module-plugin/index.mjs
11+
index 8a0168bd..cb21f92a 100644
12+
--- a/build/esm/rollup-url-to-module-plugin/index.mjs
13+
+++ b/build/esm/rollup-url-to-module-plugin/index.mjs
14+
@@ -9,6 +9,13 @@
15+
export function urlToEsmPlugin() {
16+
return {
17+
name: 'import-meta-url',
18+
+ resolveFileUrl(options) {
19+
+ let relativePath = options.relativePath
20+
+ if (!relativePath.startsWith('.')) {
21+
+ relativePath = `./${options.relativePath}`
22+
+ }
23+
+ return `'${relativePath}'`
24+
+ },
25+
async transform(code, id) {
26+
if (this.environment?.mode === 'dev') {
27+
return;

rollup/rollup.monaco.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as fs from 'fs'
88
import { fileURLToPath } from 'url'
99
import { EDITOR_API_PACKAGE_NAME } from './tools/config'
1010
import { execSync } from 'child_process'
11-
import importMetaAssets from './plugins/import-meta-assets-plugin.js'
11+
import carryDtsPlugin from './plugins/rollup-carry-dts-plugin.js'
1212

1313
const pkg = JSON.parse(
1414
fs.readFileSync(new URL('../package.json', import.meta.url).pathname).toString()
@@ -112,17 +112,17 @@ export default rollup.defineConfig([
112112
const dirname = path.dirname(contributionFile)
113113
const language = path.basename(dirname)
114114
return <rollup.RollupOptions>{
115-
input: {
116-
index: contributionFile,
117-
worker: path.resolve(
115+
input: [
116+
contributionFile,
117+
path.resolve(
118118
dirname,
119119
(
120120
await glob('*.worker.js', {
121121
cwd: path.dirname(contributionFile)
122122
})
123123
)[0]!
124124
)
125-
},
125+
],
126126
treeshake: {
127127
preset: 'smallest'
128128
},
@@ -144,11 +144,21 @@ export default rollup.defineConfig([
144144
AMD: false,
145145
preventAssignment: true
146146
}),
147-
importMetaAssets(),
148147
resolver,
148+
carryDtsPlugin(),
149149
{
150150
name: 'loader',
151-
generateBundle() {
151+
generateBundle(options, bundle) {
152+
const allChunkIds = Object.keys(bundle)
153+
154+
const entryChunkIds: string[] = allChunkIds.filter((chunkId) => {
155+
const output = bundle[chunkId]!
156+
return output.type === 'chunk' && output.isEntry
157+
})
158+
159+
const main = entryChunkIds.find((m) => m.includes('monaco.contribution'))!
160+
const worker = entryChunkIds.find((m) => m.includes('worker'))!
161+
152162
const dependencies = Object.fromEntries(
153163
Array.from(this.getModuleIds())
154164
.map((id) => this.getModuleInfo(id)!)
@@ -178,10 +188,10 @@ export default rollup.defineConfig([
178188
description: `monaco-editor ${language} language features bundled to work with ${pkg.name}`,
179189
exports: {
180190
'.': {
181-
default: './index.js'
191+
default: './' + main
182192
},
183193
'./worker': {
184-
default: './worker.js'
194+
default: './' + worker
185195
}
186196
},
187197
main: 'index.js',
@@ -231,7 +241,6 @@ export default rollup.defineConfig([
231241
AMD: false,
232242
preventAssignment: true
233243
}),
234-
importMetaAssets(),
235244
resolver,
236245
{
237246
name: 'loader',

rollup/tools/configuredSubpackagePlugin.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import importMetaAssets from '../plugins/import-meta-assets-plugin.js'
88
import * as fs from 'node:fs'
99
import * as nodePath from 'node:path'
1010
import {
11-
BASE_DIR,
1211
EXTENSIONS,
1312
pkg,
1413
external,
@@ -279,27 +278,6 @@ ${code}`
279278
}
280279
rollupOptions.plugins = [
281280
rollupOptions.plugins,
282-
{
283-
name: 'replace-editor-types',
284-
async renderChunk(code, chunk) {
285-
if (chunk.fileName.endsWith('vscode/src/vs/editor/editor.api.d.ts')) {
286-
const monacoEditorTypes = (
287-
await fs.promises.readFile(
288-
nodePath.resolve(BASE_DIR, 'monaco-editor/editor.api.d.ts')
289-
)
290-
).toString()
291-
292-
const monacoWorkerTypes = Array.from(
293-
monacoEditorTypes.matchAll(/export namespace languages\..*?^}/gms)
294-
)
295-
.map((match) => match[0])
296-
.join('\n')
297-
298-
return `${code}\n${monacoWorkerTypes}`
299-
}
300-
return undefined
301-
}
302-
},
303281
{
304282
name: 'editor-api-expose-modules',
305283
async generateBundle() {

scripts/install-monaco-editor

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ monacoRef=$(cat package.json | jq -r '.config.monaco.ref')
66
package_json="`pwd`/package.json"
77
output_directory="`pwd`/monaco-editor"
88
version_info=$output_directory/version.info
9+
patch_directory="`pwd`/monaco-patches"
910

1011
if [[ -e $version_info && $(cat $version_info) == $monacoRef ]]; then
1112
echo "monaco-editor version $monacoRef is already installed. Aborting..."
@@ -23,6 +24,10 @@ monacoVersion=$(cat "$monaco_build_directory/package.json" | jq -r '.["version"]
2324
cat <<< "$(jq ".config.monaco.version = \"$monacoVersion\"" $package_json)" > $package_json
2425

2526
cd $monaco_build_directory
27+
28+
echo "Patching monaco-editor..."
29+
find "$patch_directory" -type f -name '*.patch' -print0 | sort -z | xargs -t -0 -n 1 patch -p1 -i
30+
2631
npm ci
2732

2833
# Copy editor types

0 commit comments

Comments
 (0)