Skip to content

Commit c157584

Browse files
authored
Merge pull request #98 from CodinGame/fix-esm-strict
Fix esm strict
2 parents af8a927 + 7a74b27 commit c157584

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

rollup.config.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import vsixPlugin from '@codingame/monaco-vscode-rollup-vsix-plugin'
99
import glob from 'fast-glob'
1010
import path from 'path'
1111
import pkg from './package.json' assert { type: 'json' }
12+
import { addExtension } from '@rollup/pluginutils'
1213

1314
const externals = Object.keys(pkg.dependencies)
1415

@@ -26,15 +27,6 @@ export default rollup.defineConfig({
2627
'features/notifications': 'src/features/notifications.ts',
2728
'features/extensionGallery': 'src/features/extensionGallery.ts'
2829
},
29-
external: function isExternal (source, importer, isResolved) {
30-
if (isResolved) {
31-
return false
32-
}
33-
if (/\.wasm$/.test(source)) {
34-
return true
35-
}
36-
return externals.some(external => source === external || source.startsWith(`${external}/`))
37-
},
3830
output: [{
3931
dir: 'dist',
4032
format: 'esm',
@@ -49,6 +41,32 @@ export default rollup.defineConfig({
4941
}],
5042
plugins: [
5143
builtins(),
44+
{
45+
name: 'external-resolver',
46+
resolveId (id) {
47+
// monaco-editor can safely be imported with monaco-vscode-api
48+
if (id === 'monaco-editor/esm/vs/editor/editor.api') {
49+
return {
50+
id: 'monaco-editor',
51+
external: 'absolute'
52+
}
53+
}
54+
// Add missing .js extension to respect ESM strict mode
55+
if (id.startsWith('monaco-editor/esm')) {
56+
return {
57+
id: addExtension(id, '.js'),
58+
external: 'absolute'
59+
}
60+
}
61+
if (/\.wasm$/.test(id) || externals.some(external => id === external || id.startsWith(`${external}/`))) {
62+
return {
63+
id,
64+
external: true
65+
}
66+
}
67+
return undefined
68+
}
69+
},
5270
{
5371
name: 'glob-vsix-import',
5472
async resolveId (source, importer) {

0 commit comments

Comments
 (0)