Skip to content

Commit b8a7a83

Browse files
authored
Merge pull request #1984 from cprecioso/update-url-import
fix(rollup-plugin-import-meta-assets): completely overwrite import.meta.url
2 parents 1d6402a + 6a50cd7 commit b8a7a83

File tree

11 files changed

+38
-33
lines changed

11 files changed

+38
-33
lines changed

.changeset/tall-oranges-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/rollup-plugin-import-meta-assets': minor
3+
---
4+
5+
Change output to avoid import.meta.url in non-ESM builds

packages/rollup-plugin-import-meta-assets/src/rollup-plugin-import-meta-assets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ ${` default: return new Promise(function(resolve, reject) {
180180
});
181181
magicString.overwrite(
182182
node.arguments[0].start,
183-
node.arguments[0].end,
183+
node.arguments[1].end,
184184
`import.meta.ROLLUP_FILE_URL_${ref}`,
185185
);
186186
modifiedCode = true;

packages/rollup-plugin-import-meta-assets/test/snapshots/different-asset-levels-bundle.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const nameOne = 'one-name';
2-
const imageOne = new URL(new URL('assets/one-deep-Bkie7h0E.svg', import.meta.url).href, import.meta.url).href;
2+
const imageOne = new URL(new URL('assets/one-deep-Bkie7h0E.svg', import.meta.url).href).href;
33

44
const nameTwo = 'two-name';
5-
const imageTwo = new URL(new URL('assets/two-deep-D7JyS-th.svg', import.meta.url).href, import.meta.url).href;
5+
const imageTwo = new URL(new URL('assets/two-deep-D7JyS-th.svg', import.meta.url).href).href;
66

77
const nameThree = 'three-name';
8-
const imageThree = new URL(new URL('assets/three-deep-IN2CmsMK.svg', import.meta.url).href, import.meta.url).href;
8+
const imageThree = new URL(new URL('assets/three-deep-IN2CmsMK.svg', import.meta.url).href).href;
99

1010
const nameFour = 'four-name';
11-
const imageFour = new URL(new URL('assets/four-deep-CUlW6cvD.svg', import.meta.url).href, import.meta.url).href;
11+
const imageFour = new URL(new URL('assets/four-deep-CUlW6cvD.svg', import.meta.url).href).href;
1212

1313
console.log({
1414
[nameOne]: imageOne,

packages/rollup-plugin-import-meta-assets/test/snapshots/directories-ignored.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const justUrlObject = new URL(new URL('assets/one-Bkie7h0E.svg', import.meta.url).href, import.meta.url);
2-
const href = new URL(new URL('assets/two-D7JyS-th.svg', import.meta.url).href, import.meta.url).href;
3-
const pathname = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href, import.meta.url).pathname;
4-
const searchParams = new URL(new URL('assets/four-CUlW6cvD.svg', import.meta.url).href, import.meta.url).searchParams;
1+
const justUrlObject = new URL(new URL('assets/one-Bkie7h0E.svg', import.meta.url).href);
2+
const href = new URL(new URL('assets/two-D7JyS-th.svg', import.meta.url).href).href;
3+
const pathname = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href).pathname;
4+
const searchParams = new URL(new URL('assets/four-CUlW6cvD.svg', import.meta.url).href).searchParams;
55

66
const directories = [
77
new URL('./', import.meta.url),

packages/rollup-plugin-import-meta-assets/test/snapshots/dynamic-vars.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function __variableDynamicURLRuntime0__(path) {
22
switch (path) {
3-
case './dynamic-assets/one.svg': return new URL(new URL('assets/one-Bkie7h0E.svg', import.meta.url).href, import.meta.url);
4-
case './dynamic-assets/three.svg': return new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href, import.meta.url);
5-
case './dynamic-assets/two.svg': return new URL(new URL('assets/two-D7JyS-th.svg', import.meta.url).href, import.meta.url);
3+
case './dynamic-assets/one.svg': return new URL(new URL('assets/one-Bkie7h0E.svg', import.meta.url).href);
4+
case './dynamic-assets/three.svg': return new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href);
5+
case './dynamic-assets/two.svg': return new URL(new URL('assets/two-D7JyS-th.svg', import.meta.url).href);
66
default: return new Promise(function(resolve, reject) {
77
(typeof queueMicrotask === 'function' ? queueMicrotask : setTimeout)(
88
reject.bind(null, new Error("Unknown variable dynamic new URL statement: " + path))
@@ -16,6 +16,6 @@ const names = ['one', 'two'];
1616
// Therefore, we expect both one.svg, two.svg and three.svg to be bundled, and this to turn into a switch statement
1717
// with 3 cases (for all 3 assets in the dynamic-assets folder)
1818
const dynamicImgs = names.map(n => __variableDynamicURLRuntime0__(`./dynamic-assets/${n}.svg`));
19-
const backticksImg = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href, import.meta.url);
19+
const backticksImg = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href);
2020

2121
console.log(dynamicImgs, backticksImg);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
const nameFour = 'four-name';
2-
const imageFour = new URL(new URL('assets/four-CUlW6cvD.svg', import.meta.url).href, import.meta.url).href;
2+
const imageFour = new URL(new URL('assets/four-CUlW6cvD.svg', import.meta.url).href).href;
33

44
export { imageFour, nameFour };

packages/rollup-plugin-import-meta-assets/test/snapshots/multi-level-bundle.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const nameOne = 'one-name';
2-
const imageOne = new URL(new URL('assets/one-Bkie7h0E.svg', import.meta.url).href, import.meta.url).href;
2+
const imageOne = new URL(new URL('assets/one-Bkie7h0E.svg', import.meta.url).href).href;
33

44
const nameTwo = 'two-name';
5-
const imageTwo = new URL(new URL('assets/two-D7JyS-th.svg', import.meta.url).href, import.meta.url).href;
5+
const imageTwo = new URL(new URL('assets/two-D7JyS-th.svg', import.meta.url).href).href;
66

77
const nameThree = 'three-name';
8-
const imageThree = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href, import.meta.url).href;
8+
const imageThree = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href).href;
99

1010
const nameFour = 'four-name';
11-
const imageFour = new URL(new URL('assets/four-CUlW6cvD.svg', import.meta.url).href, import.meta.url).href;
11+
const imageFour = new URL(new URL('assets/four-CUlW6cvD.svg', import.meta.url).href).href;
1212

1313
console.log({
1414
[nameOne]: imageOne,

packages/rollup-plugin-import-meta-assets/test/snapshots/simple-bundle.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const justUrlObject = new URL(new URL('assets/one-Bkie7h0E.svg', import.meta.url).href, import.meta.url);
2-
const href = new URL(new URL('assets/two-D7JyS-th.svg', import.meta.url).href, import.meta.url).href;
3-
const pathname = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href, import.meta.url).pathname;
4-
const searchParams = new URL(new URL('assets/four-CUlW6cvD.svg', import.meta.url).href, import.meta.url).searchParams;
5-
const noExtension = new URL(new URL('assets/five-Bnvj_R70', import.meta.url).href, import.meta.url);
1+
const justUrlObject = new URL(new URL('assets/one-Bkie7h0E.svg', import.meta.url).href);
2+
const href = new URL(new URL('assets/two-D7JyS-th.svg', import.meta.url).href).href;
3+
const pathname = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href).pathname;
4+
const searchParams = new URL(new URL('assets/four-CUlW6cvD.svg', import.meta.url).href).searchParams;
5+
const noExtension = new URL(new URL('assets/five-Bnvj_R70', import.meta.url).href);
66

77
console.log({
88
justUrlObject,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
const nameThree = 'three-name';
2-
const imageThree = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href, import.meta.url).href;
2+
const imageThree = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href).href;
33

44
export { imageThree, nameThree };

packages/rollup-plugin-import-meta-assets/test/snapshots/transform-bundle-ignored.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const justUrlObject = new URL(new URL('assets/one--RhQWA3U.svg', import.meta.url).href, import.meta.url);
2-
const href = new URL(new URL('assets/two-CZdxIUwi.svg', import.meta.url).href, import.meta.url).href;
3-
const pathname = new URL(new URL('assets/three-tFhyRH_R.svg', import.meta.url).href, import.meta.url).pathname;
4-
const searchParams = new URL(new URL('assets/four-Cs1OId-q.svg', import.meta.url).href, import.meta.url).searchParams;
1+
const justUrlObject = new URL(new URL('assets/one--RhQWA3U.svg', import.meta.url).href);
2+
const href = new URL(new URL('assets/two-CZdxIUwi.svg', import.meta.url).href).href;
3+
const pathname = new URL(new URL('assets/three-tFhyRH_R.svg', import.meta.url).href).pathname;
4+
const searchParams = new URL(new URL('assets/four-Cs1OId-q.svg', import.meta.url).href).searchParams;
55
const someJpg = new URL('./image.jpg', import.meta.url);
66

77
console.log({

0 commit comments

Comments
 (0)