diff --git a/rollup.config.ts b/rollup.config.ts index 1b89db3..ff64d8f 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -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) @@ -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', @@ -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) {