-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[babel 8] Use ESM-based chalk@5
#15792
Conversation
84703d8
to
8524e1c
Compare
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/55223/ |
8187ff5
to
2f30e87
Compare
176ffcb
to
330d883
Compare
f33c2f1
to
eba0252
Compare
eba0252
to
61dd3d3
Compare
61dd3d3
to
abeaafc
Compare
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.
To be honest, because of these special handling of chalk@5, I would rather stay with the old version unless there is a security problem.🤦♂️
export function setup() { | ||
// chalk, which we bundle in @babel/standalone, relies on `window.navigator` | ||
// for the browser build: | ||
// https://github.com/chalk/chalk/blob/f399cd0ff69841e88cca89d43a49f1cc9ba2efd5/source/vendor/supports-color/browser.js#L4 | ||
// We only bundle Chalk 5 in local dev and in Babel 8, so we avoid this | ||
// "polyfill" when releasing Babel 7 to make sure that we do not accidentally | ||
// bundle Chalk 5. | ||
|
||
if (process.env.BABEL_8_BREAKING) { | ||
globalThis.navigator = {}; | ||
} else if (!process.env.IS_PUBLISH) { | ||
global.navigator = {}; | ||
} | ||
} |
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.
Can we replace it with navigator || {}
in rollup?
I remember someone seems to be using @babel/standalone
in node, maybe it's not worth breaking them.
If you agree I can try to do this. :)
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 please!
The complexity is only there because we are using both chalk 2 and chalk 5 at the same time, if it was only chalk 5 it would be as complex as any other version. I would rather not have Babel 7 holding back Babel 8 😬 The main advantages of using Chalk 5 are that:
|
Amazing! Now i like it! :) |
Good :) Do you want to do #15792 (comment) here on in a separate PR? |
It didn't look complicated, so I pushed it directly in this PR. :) |
e7d7842
to
8fcb970
Compare
Unless you specify |
@liuxingbaoyu I pushed a commit to use a Babel plugin instead. Rollup's replace plugin had some problems, because:
|
Yes, I found this problem too. |
chalk/chalk#598 (comment) |
Well, Node.js will get the non-highlighted version but the result will still be ok. This is already the current behavior for Babel 7: search for |
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.
Sorry, I made a mistake. 😅
I thought code-frame
and highlight
would be affected too, now it looks fine.
Fixes #1, Fixes #2
I updated
yarn-plugin-conditions
to allow defining ESM dependencies, so that we can start updating other deps for Babel 8.Would this be ok for you other maintainers? It means that you can only run withBABEL_8_BREAKING=true
if you are developing in the monorepo in ESM mode (it's enough to runmake use-esm
once).The commits marked as[15816]
are from #15816, please review that PR first.