-
-
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
Conversation
🦋 Changeset detectedLatest commit: 6a50cd7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Closing due to old age |
Hey, it's actually a great change, too bad I didn't see it before today. I can sync with latest master, I think many tests have changed since this was created. But if you still wanna work on this, I'm happy to assist. Let me know what works best for you! |
@bashmish Synced and fixed tests |
@@ -1,14 +1,14 @@ | |||
const nameOne = 'one-name'; | |||
const imageOne = new URL(new URL('assets/one-deep-Bkie7h0E.svg', import.meta.url).href, import.meta.url).href; | |||
const imageOne = new URL(new URL('assets/one-deep-Bkie7h0E.svg', import.meta.url).href).href; |
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 type string
, not of type URL
. The expression does use URL
internally but it's an implementation detail (that changes depending on the output format), and the final result is still a string
. So to get a URL
as the new URL("./asset", import.meta.url)
expression suggests, we need to wrap it inside a new 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 the import.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
This removes the duplicated
import.meta.url
in the output, like this:Why
This way, it should work exactly the same (Rollup makes sure we have
import.meta.url
or something similar to base our URL on); but the secondimport.meta
gets eliminated, which reduces size, repetition, and most of all, doesn't trigger an error in Common JS modules.What I did
Updated the overwrite function
Updated tests