-
-
Notifications
You must be signed in to change notification settings - Fork 318
fix(rollup-plugin-import-meta-assets): completely overwrite import.meta.url #1984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@web/rollup-plugin-import-meta-assets': minor | ||
--- | ||
|
||
Change output to avoid import.meta.url in non-ESM builds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
packages/rollup-plugin-import-meta-assets/test/snapshots/different-asset-levels-bundle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
packages/rollup-plugin-import-meta-assets/test/snapshots/directories-ignored.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/rollup-plugin-import-meta-assets/test/snapshots/four-bundle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const nameFour = 'four-name'; | ||
const imageFour = new URL(new URL('assets/four-CUlW6cvD.svg', import.meta.url).href, import.meta.url).href; | ||
const imageFour = new URL(new URL('assets/four-CUlW6cvD.svg', import.meta.url).href).href; | ||
|
||
export { imageFour, nameFour }; |
8 changes: 4 additions & 4 deletions
8
packages/rollup-plugin-import-meta-assets/test/snapshots/multi-level-bundle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
packages/rollup-plugin-import-meta-assets/test/snapshots/simple-bundle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/rollup-plugin-import-meta-assets/test/snapshots/three-bundle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const nameThree = 'three-name'; | ||
const imageThree = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href, import.meta.url).href; | ||
const imageThree = new URL(new URL('assets/three-IN2CmsMK.svg', import.meta.url).href).href; | ||
|
||
export { imageThree, nameThree }; |
8 changes: 4 additions & 4 deletions
8
packages/rollup-plugin-import-meta-assets/test/snapshots/transform-bundle-ignored.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
packages/rollup-plugin-import-meta-assets/test/snapshots/transform-bundle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I mislooked first time, but I was under impression that the whole outer URL wrapper will be gone with you change, not only the
import.meta.url
do you think it's a more complex change or is the outer one still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The outer one is still needed for the most general case.
When using the
import.meta.ROLLUP_FILE_URL_referenceId
notation, Rollup will generate an expression of typestring
, not of typeURL
. The expression does useURL
internally but it's an implementation detail (that changes depending on the output format), and the final result is still astring
. So to get aURL
as thenew URL("./asset", import.meta.url)
expression suggests, we need to wrap it inside anew URL()
call anyway. You can see example output for both ESM and CJS in the first code example in the PR description.The main problem I was trying to solve with this PR is not removing URL constructors, but the fact that keeping the outermost
import.meta.url
was tripping up CJS support.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an optimization that you can do if the input is
new URL("./asset", import.meta.url).href
, as you could replace that whole-sale with theimport.meta.ROLLUP_FILE_URL_referenceId
expression and be correct, but only for the case where we're calling.href
or.toString()
. I do not have the bandwidth to implement that currently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok got it! thanks for the explainer, helps with the decision making a lot and historical reference