From e865de30c17db17961ffadff0ead86470a7a24df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Mon, 7 Oct 2024 15:58:19 +0200 Subject: [PATCH] fix: fix import-meta-asset-plugin resolution see https://github.com/modernweb-dev/web/pull/2819 --- ...llup-plugin-import-meta-assets+2.2.1.patch | 25 +++++++++++++++++++ rollup/rollup.config.ts | 10 +++----- 2 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 patches/@web+rollup-plugin-import-meta-assets+2.2.1.patch diff --git a/patches/@web+rollup-plugin-import-meta-assets+2.2.1.patch b/patches/@web+rollup-plugin-import-meta-assets+2.2.1.patch new file mode 100644 index 00000000..51e98093 --- /dev/null +++ b/patches/@web+rollup-plugin-import-meta-assets+2.2.1.patch @@ -0,0 +1,25 @@ +diff --git a/node_modules/@web/rollup-plugin-import-meta-assets/src/rollup-plugin-import-meta-assets.js b/node_modules/@web/rollup-plugin-import-meta-assets/src/rollup-plugin-import-meta-assets.js +index 245ec98..fa2e485 100644 +--- a/node_modules/@web/rollup-plugin-import-meta-assets/src/rollup-plugin-import-meta-assets.js ++++ b/node_modules/@web/rollup-plugin-import-meta-assets/src/rollup-plugin-import-meta-assets.js +@@ -161,11 +161,20 @@ ${` default: return new Promise(function(resolve, reject) { + if (importMetaUrlType === 'static') { + const absoluteScriptDir = path.dirname(id); + const relativeAssetPath = getRelativeAssetPath(node); ++ const resolved = await this.resolve(relativeAssetPath, id) ++ if (resolved == null) { ++ this.error(`Unable to resolve "${relativeAssetPath}" from "${id}"`) ++ return ++ } ++ if (resolved.external) { ++ return ++ } + const absoluteAssetPath = path.resolve(absoluteScriptDir, relativeAssetPath); + const assetName = path.basename(absoluteAssetPath); + + try { +- const assetContents = await fs.promises.readFile(absoluteAssetPath); ++ const assetContents = await fs.promises.readFile(resolved.id); + const transformedAssetContents = + transform != null + ? await transform(assetContents, absoluteAssetPath) diff --git a/rollup/rollup.config.ts b/rollup/rollup.config.ts index 82f44d97..7ef15dca 100644 --- a/rollup/rollup.config.ts +++ b/rollup/rollup.config.ts @@ -436,9 +436,7 @@ export default (args: Record): rollup.RollupOptions[] => { input, plugins: [ importMetaAssets({ - include: ['**/*.ts', '**/*.js'], - // assets are externals and this plugin is not able to ignore external assets - exclude: ['**/service-override/textmate.ts', '**/service-override/languageDetectionWorker.ts'] + include: ['**/*.ts', '**/*.js'] }), commonjs({ include: '**/vscode-semver/**/*' @@ -621,9 +619,8 @@ export default (args: Record): rollup.RollupOptions[] => { hoistTransitiveImports: false }], plugins: [importMetaAssets({ - include: ['**/*.ts', '**/*.js'], + include: ['**/*.ts', '**/*.js'] // assets are externals and this plugin is not able to ignore external assets - exclude: ['**/service-override/textmate.js', '**/service-override/languageDetectionWorker.js'] }), { name: 'resolve-asset-url', resolveFileUrl (options) { @@ -1068,9 +1065,8 @@ export default (args: Record): rollup.RollupOptions[] => { treeshake: false, plugins: [ importMetaAssets({ - include: ['**/*.ts', '**/*.js'], + include: ['**/*.ts', '**/*.js'] // assets are externals and this plugin is not able to ignore external assets - exclude: ['**/service-override/textmate.js', '**/service-override/languageDetectionWorker.js'] }), nodeResolve({ extensions: EXTENSIONS