Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix esm strict #98

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading