Skip to content

Commit

Permalink
Merge pull request #98 from CodinGame/fix-esm-strict
Browse files Browse the repository at this point in the history
Fix esm strict
  • Loading branch information
CGNonofr authored Feb 13, 2024
2 parents af8a927 + 7a74b27 commit c157584
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import vsixPlugin from '@codingame/monaco-vscode-rollup-vsix-plugin'
import glob from 'fast-glob'
import path from 'path'
import pkg from './package.json' assert { type: 'json' }
import { addExtension } from '@rollup/pluginutils'

const externals = Object.keys(pkg.dependencies)

Expand All @@ -26,15 +27,6 @@ export default rollup.defineConfig({
'features/notifications': 'src/features/notifications.ts',
'features/extensionGallery': 'src/features/extensionGallery.ts'
},
external: function isExternal (source, importer, isResolved) {
if (isResolved) {
return false
}
if (/\.wasm$/.test(source)) {
return true
}
return externals.some(external => source === external || source.startsWith(`${external}/`))
},
output: [{
dir: 'dist',
format: 'esm',
Expand All @@ -49,6 +41,32 @@ export default rollup.defineConfig({
}],
plugins: [
builtins(),
{
name: 'external-resolver',
resolveId (id) {
// monaco-editor can safely be imported with monaco-vscode-api
if (id === 'monaco-editor/esm/vs/editor/editor.api') {
return {
id: 'monaco-editor',
external: 'absolute'
}
}
// Add missing .js extension to respect ESM strict mode
if (id.startsWith('monaco-editor/esm')) {
return {
id: addExtension(id, '.js'),
external: 'absolute'
}
}
if (/\.wasm$/.test(id) || externals.some(external => id === external || id.startsWith(`${external}/`))) {
return {
id,
external: true
}
}
return undefined
}
},
{
name: 'glob-vsix-import',
async resolveId (source, importer) {
Expand Down

0 comments on commit c157584

Please sign in to comment.