From 8e01bf36e897bf2cd6e7e83c8fd9644fa9352fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Tue, 13 Feb 2024 15:43:22 +0100 Subject: [PATCH 1/2] refactor: resolve externals using resolveId function --- rollup.config.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/rollup.config.ts b/rollup.config.ts index 1b89db3..8d010f9 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -26,15 +26,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 +40,18 @@ export default rollup.defineConfig({ }], plugins: [ builtins(), + { + name: 'external-resolver', + resolveId (id) { + 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) { From 7a74b2770e7024e53fbcf5ca8f470629e5839ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Tue, 13 Feb 2024 15:43:47 +0100 Subject: [PATCH 2/2] fix: transform monaco import from monaco-emacs/vim to be esm strict compliant --- rollup.config.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rollup.config.ts b/rollup.config.ts index 8d010f9..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) @@ -43,6 +44,20 @@ export default rollup.defineConfig({ { 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,