Skip to content
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

Inline @babel/highlight in @babel/code-frame #16896

Merged
merged 6 commits into from
Oct 24, 2024

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Oct 9, 2024

Q                       A
Fixed Issues? Fixes #12442, fixes #11605
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link babel/website#2995
Any Dependency Changes?
License MIT

@babel/highlight is only used in one of our packages: @babel/code-frame. I thus checked on npm, and noticed that it also has very few dependents in the wider ecosystem: just 40 :) https://www.npmjs.com/browse/depended/@babel/highlight

I manually checked how it is used in packages that have been updated in the last year, and there are only two packages with usage of @babel/highlight that makes sense: one is https://github.com/facebook/flow/blob/2dc7cec37d7aa97f84640248d272ca38d982158e/packages/flow-upgrade/testUtils/codemodTestUtils.js#L15 (for which @babel/code-frame would also be ok, given that it's just to make test output more readable) and one is https://github.com/suchipi/at-js.
It's not enough usage for us to justify maintaining it as a standalone package. If anybody asks for it, we can export a highlight function from @babel/code-frame. We now export a highlight function from @babel/code-frame.

Merging @babel/highlight into @babel/code-frame means that we can fully remove the chalk dependency, which is unused (but exposed as-is in the @babel/highlight API through getChalk()) and alone makes 60% of @babel/code-frame's size. 🎉

I will add @babel/highlight to the archive once this PR is merged.

@nicolo-ribaudo nicolo-ribaudo added the PR: Internal 🏠 A type of pull request used for our changelog categories label Oct 9, 2024
@babel-bot
Copy link
Collaborator

babel-bot commented Oct 9, 2024

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58238

return colors;
}
import { getDefs, isColorSupported } from "./defs.ts";
import { highlight } from "./highlight.ts";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also export the highlight function? So that for @babel/highlight users, the can migrate to the highlight imported from @babel/code-frame when upgrading to Babel 8.

@nicolo-ribaudo nicolo-ribaudo added this to the v7.26.0 milestone Oct 22, 2024
@nicolo-ribaudo
Copy link
Member Author

Adding this to a minor milestone due to the new exported highlight function.

@@ -521,7 +521,7 @@ function buildRollup(packages, buildStandalone) {
// We have manually applied commonjs-esm interop to the source
// for library not in this monorepo
// https://github.com/babel/babel/pull/12795
if (!id.startsWith("@babel/")) return "compat";
if (!id.startsWith("@babel/")) return "default";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you briefly explain why archived syntax plugins are using compat while other dependencies are using default? Intuitively we should apply the same interop for everything not in the monorepo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs: https://rollupjs.org/configuration-options/#output-interop

default matches what Node.js does, so it's what we should use for external packages. For syntax plugins it doesn't really matter, because they all have .default and .__esModule so the compat and default work the same. But yeah, lets use default everywhere.

@nicolo-ribaudo nicolo-ribaudo removed the PR: Needs Review A pull request awaiting more approvals label Oct 24, 2024
@nicolo-ribaudo nicolo-ribaudo merged commit c369676 into babel:main Oct 24, 2024
54 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the inline-highlight branch October 24, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
4 participants