Skip to content

Commit

Permalink
fix: fix import-meta-asset-plugin resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Oct 7, 2024
1 parent 0751bc9 commit e865de3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
25 changes: 25 additions & 0 deletions patches/@web+rollup-plugin-import-meta-assets+2.2.1.patch
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 3 additions & 7 deletions rollup/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,7 @@ export default (args: Record<string, string>): 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/**/*'
Expand Down Expand Up @@ -621,9 +619,8 @@ export default (args: Record<string, string>): 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) {
Expand Down Expand Up @@ -1068,9 +1065,8 @@ export default (args: Record<string, string>): 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
Expand Down

0 comments on commit e865de3

Please sign in to comment.