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

update tsconfig generation to reference dependencies used in source code #12941

Merged
merged 5 commits into from Mar 15, 2021

Conversation

zxbodya
Copy link
Contributor

@zxbodya zxbodya commented Mar 2, 2021

Q                       A
Any Dependency Changes? dev dependency on globby
License MIT

In some cases there are devDependecnies used for type-checking(like on @babel/traverse to get NodePath type).

This changes how tsconfig.json files are generated to include references, to babel packages imported from package source code.

@babel-bot
Copy link
Collaborator

babel-bot commented Mar 2, 2021

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 2, 2021

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 0b4e16e:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@@ -2,6 +2,10 @@ import path from "path";
import fs from "fs";
import { createRequire } from "module";
import { fileURLToPath } from "url";
import globby from "globby";
import * as babel from "@babel/core";
import traverseModule from "@babel/traverse";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

when running it locally instead of default export - whole module is imported here

Copy link
Member

Choose a reason for hiding this comment

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

It's expected, because @babel/traverse is not a native module but it's compiled to CJS.

Comment on lines 53 to 55
const ast = babel.parseSync(source, {
ast: true,
filename,
});

traverse(ast, {
ImportDeclaration(path) {
const importSource = path.node.source.value;
if (importSource.startsWith("@babel/")) {
result.add(importSource);
}
},
});
}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could speed this up with

for (const [importSource] of source.matchAll(/(?<=from\s*")@babel\/[^"/]+/g)) {
  result.add(importSource);
}

this doesn't work for generic JS, but it should be ok for our own source files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that actually not only faster - it also covers additional cases when when having export {} from "" statement

updated the PR

@nicolo-ribaudo
Copy link
Member

I have no idea why CI is failing, I'll investigate.

@nicolo-ribaudo
Copy link
Member

I cannot reproduce the failure locally, and GH doesn't let me clean the actions cache. Could you try rebasing this on main, to re-run CI with a clean cache?

in some cases there are devDependecnies used for type-checking, this change adds references to them when generationg tsconfig
@zxbodya zxbodya force-pushed the update-tsconfig-generation branch from 0480e16 to afd5c7a Compare March 2, 2021 15:45
@zxbodya
Copy link
Contributor Author

zxbodya commented Mar 2, 2021

rebased it

@nicolo-ribaudo
Copy link
Member

If CI passes you can revert 5648962

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Approving, pending the revert of 5648962.

Note for other reviewers: the reason this is needed is that relying on devDependencies introduces many circular dependencies between packages, and TS doesn't handle them well. What this PR matches is a subset of actual deps/devDeps, because many devDeps are only used in tests.

@JLHwung JLHwung self-requested a review March 15, 2021 16:08
@JLHwung JLHwung merged commit 6e1e003 into babel:main Mar 15, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the update-tsconfig-generation branch March 15, 2021 16:40
@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 Jun 15, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2021
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants