Skip to content

Only import types from declared dependencies - #16494

Merged
nicolo-ribaudo merged 13 commits into
babel:mainfrom
nicolo-ribaudo:no-missing-deps
May 30, 2024
Merged

nicolo-ribaudo merged 13 commits into
babel:mainfrom
nicolo-ribaudo:no-missing-deps

Conversation

@nicolo-ribaudo

@nicolo-ribaudo nicolo-ribaudo commented May 15, 2024 •

Copy link
Copy Markdown
Member
Q 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR makes sure that all our import types only reference packages that are listed in dependencies/peerDependencies. This is done mainly in two ways:

  1. plugins all peerDepend on @babel/core, so they can import NodePath/Visitor/Scope/types from there rather than from @babel/traverse/@babel/types
  2. helpers can depend on @babel/traverse/@babel/types: if a helper expects a NodePath as a parameter, you already have to have @babel/traverse/@babel/types in your dependencies so this is not causing extra deps.

To (2) there are some exceptions:

  • babel-helper-builder-react-jsx and babel-helper-plugin-utils only make sense when using with a full plugin (and not directly with parser+traverse), so I added @babel/core as a peer dependency (but only for Babel 8)
  • babel-helper-fixtures is also only needed when testing plugins, so I added @babel/core as a peer dep

This PR doesn't lint @babel/standalone and @babel/parser since those are bundled, but we should probably add @babel/types as a dependency of @babel/parser. I don't really like doing it since it's perfectly reasonable to use @babel/parser without also using @babel/types, but on the other hand if the dependency is only used in import type it won't actually affect anything at runtime (it won't be loaded) so adding it is not too bad.

There is one remaining lint error fixed by #16493.

@babel-bot

babel-bot commented May 15, 2024 •

Copy link
Copy Markdown
Collaborator

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

@nicolo-ribaudo
nicolo-ribaudo marked this pull request as draft May 15, 2024 16:57
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies -- TODO: Avoid cycle

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There are 4 packages whose types circularly depend on @babel/traverse. Lets just ignore those errors for now (@babel/traverse will be in the dependencies anyway), but I will think of a better solution before going stable.

@nicolo-ribaudo
nicolo-ribaudo marked this pull request as ready for review May 22, 2024 14:45
@nicolo-ribaudo nicolo-ribaudo added the PR: Internal (next major) 馃彔 A type of pull request used for our changelog categories for next major release label May 22, 2024
@nicolo-ribaudo
nicolo-ribaudo merged commit 90fdd7e into babel:main May 30, 2024
@nicolo-ribaudo
nicolo-ribaudo deleted the no-missing-deps branch May 30, 2024 07:47
@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 30, 2024
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Internal (next major) 馃彔 A type of pull request used for our changelog categories for next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants