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
fix: use custom Rollup plugin for import.meta.url
#77
Conversation
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 change looks ok to me, but wondering:
- wouldn’t it be better to file an issue with Rollup?
- Will this break usage in browsers? (Linter references this package)
rollup.config.js
Outdated
name: "custom-import-meta-url", | ||
resolveImportMeta(property) { | ||
if (property === "url") { | ||
return "require('url').pathToFileURL(__filename)"; |
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.
Just a note: pathToFileURL
returns a URL object, while import.meta.url
is a string. This is not a problem as long as import.meta.url
is only used for createRequire
as it is here the case. But if we accept that, then we could also just return "__filename"
, because createRequire
is perfectly fine with a path as argument.
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.
You're right, import.meta.url
should be transformed to a URL string. I have applied @aladdin-add's suggestion to fix this by using URL#toString()
. Thanks!
I've also noticed the issue when moving eslint to esm. there is a babel plugin doing the same thing - babel-plugin-transform-import-meta. wondering if we want to use that? |
Co-authored-by: 唯然 <weiran.zsd@outlook.com>
It's probably more robust than this text transformation, but I'm not sure if it warrants adding babel to the build? If there's a case where the babel plugin handles code better than this, I'd guess it would have to be a very edge case. |
@nzakas AFAICT |
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.
LGTM
I've filed rollup/rollup#4461 now, waiting for response.
I believe not, as this particular module that uses |
Thanks @fasttime for all of your help on this. @mdjermanovic up to you to either merge this or wait for a Rollup response. |
All checks in eslint repo (eslint/eslint#15795) are passing with this branch. Since there is still no response on rollup/rollup#4461, I'm going to merge this now. If and when Rollup fixes this issue, we can revert this change. |
Refs eslint/eslint#15766, this should fix the issue.
dist/eslintrc.cjs
diff (line 2383):The new version does not include code for browsers (
typeof document ...
), I'm not sure why Rollup's default transformation includes it when the output format is set to"cjs"
.Without this change, the added test case fails with the same error as in eslint/eslint#15766.