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
Avoid importing .json
files
#12759
Avoid importing .json
files
#12759
Conversation
@kaicataldo Do you know if there is an eslint rule to say something like "disallow |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 771d06d:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/39683/ |
That doesn't really prevent us from importing json files, it just ensures that we explicitly write the |
While not foolproof, can't we use it to at least disallow importing something with the json extension ( |
Actually, probably it's better to do the opposite: if we require the |
The new |
6af14d5
to
771d06d
Compare
} | ||
const field = path.node.property.name; | ||
|
||
// TODO: When dropping old Node.js versions, use require.resolve |
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.
Do we still need to support old versions since 1) we are building on latest node 2) it is a compile-time macro?
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.
"compile time" means also "on Node.js 6 inside babel-jest"
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.
Oh I thought we are replacing packageJson.field
on the build step.
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.
Yes, but we also run Babel in jest (that's the reason why we cannot use babel.config.mjs
)
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.
What do you think extract it to a dedicated plugin in yarn workspace. No need to publish now but maybe we can decide it later. Unlike the BABEL_8_BREAKING
flag remover, it falls to an optimizer plugin that will stay for a long time.
We would still need to run Babel inside the yarn plugin to modify the code (unless we want to hack it with regexps 😕) |
I'm starting to check what we need to do in order to migrate to native ES modules, and this is one of the problems I found: native ESM cannot import
.json
files by default.This PR replaces imports to
package.json
files with a compile-time macro, which is replaced with the correspondingpackage.json
entry.package.json
.@babel/standalone
size, since it doesn't need to include the fullpackage.json
contents.