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

Monorepo support #35

Closed
wants to merge 4 commits into from
Closed

Monorepo support #35

wants to merge 4 commits into from

Conversation

Raigen
Copy link
Contributor

@Raigen Raigen commented Feb 25, 2018

Find all existings of .babelrc and package.json not in node_modules
and update them.
Parameterize writePackageJSON with a relative package.json path
from globby.
Improve log output for babel config
Look for .flowconfig in each package.json directory only

I think this needs some more testing with different projects. I ran it on babel and react, which also gave me a hint to adjust the .flowconfig lookup which I am not happy with yet. But I have no time today to invest further and I also do not have experience with flow, so maybe someone else can try it out.

@Raigen
Copy link
Contributor Author

Raigen commented Feb 25, 2018

Babel output looks like this

$ babel-upgrade
??  Thanks for trying out https://github.com/babel/babel-upgrade!

Updating .babelrc config at packages/babel-cli/test/.babelrc
Updating .babelrc config at packages/babel-preset-es2015/test/.babelrc
Updating .babelrc config at packages/babel-core/test/.babelrc
Updating .babelrc config at packages/babel-core/test/fixtures/config/env/.babelrc
Updating .babelrc config at packages/babel-cli/test/fixtures/babel/filename babelrc no comments/.babelrc
Updating .babelrc config at packages/babel-core/test/fixtures/config/.babelrc
Updating .babelrc config at packages/babel-core/test/fixtures/config/dir2/.babelrc
Updating .babelrc config at packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/in-files/.babelrc
Updating package.json dependencies at package.json
Updating package.json dependencies at packages/babel-code-frame/package.json
Updating package.json dependencies at packages/babel-core/package.json
Updating package.json dependencies at packages/babel-cli/package.json
Updating package.json dependencies at packages/babel/package.json
Updating package.json dependencies at packages/babel-helper-bindify-decorators/package.json
Updating package.json dependencies at packages/babel-generator/package.json
Updating package.json dependencies at packages/babel-helper-builder-binary-assignment-operator-visitor/package.json
Updating package.json dependencies at packages/babel-helper-call-delegate/package.json
Updating package.json dependencies at packages/babel-helper-builder-conditional-assignment-operator-visitor/package.json
Updating package.json dependencies at packages/babel-helper-builder-react-jsx/package.json
Updating package.json dependencies at packages/babel-helper-explode-class/package.json
Updating package.json dependencies at packages/babel-helper-explode-assignable-expression/package.json
Updating package.json dependencies at packages/babel-helper-fixtures/package.json
Updating package.json dependencies at packages/babel-helper-define-map/package.json
Updating package.json dependencies at packages/babel-helper-function-name/package.json
Updating package.json dependencies at packages/babel-helper-get-function-arity/package.json
Updating package.json dependencies at packages/babel-helper-hoist-variables/package.json
Updating package.json dependencies at packages/babel-helper-plugin-test-runner/package.json
Updating package.json dependencies at packages/babel-helper-remap-async-to-generator/package.json
Updating package.json dependencies at packages/babel-helper-regex/package.json
Updating package.json dependencies at packages/babel-messages/package.json
Updating package.json dependencies at packages/babel-helper-optimise-call-expression/package.json
Updating package.json dependencies at packages/babel-helpers/package.json
Updating package.json dependencies at packages/babel-helper-transform-fixture-test-runner/package.json
Updating package.json dependencies at packages/babel-helper-replace-supers/package.json
Updating package.json dependencies at packages/babel-plugin-check-es2015-constants/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-async-generators/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-async-functions/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-class-constructor-call/package.json
Updating package.json dependencies at packages/babel-plugin-external-helpers/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-class-properties/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-dynamic-import/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-decorators/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-exponentiation-operator/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-function-bind/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-flow/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-export-extensions/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-function-sent/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-do-expressions/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-object-rest-spread/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-jsx/package.json
Updating package.json dependencies at packages/babel-plugin-transform-async-functions/package.json
Updating package.json dependencies at packages/babel-plugin-transform-async-generator-functions/package.json
Updating package.json dependencies at packages/babel-plugin-syntax-trailing-function-commas/package.json
Updating package.json dependencies at packages/babel-plugin-transform-async-to-generator/package.json
Updating package.json dependencies at packages/babel-plugin-transform-class-properties/package.json
Updating package.json dependencies at packages/babel-plugin-transform-class-constructor-call/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-arrow-functions/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-block-scoped-functions/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-classes/package.json
Updating package.json dependencies at packages/babel-plugin-transform-do-expressions/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-destructuring/package.json
Updating package.json dependencies at packages/babel-plugin-transform-decorators/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-computed-properties/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-for-of/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-block-scoping/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-literals/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-duplicate-keys/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-function-name/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-modules-umd/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-modules-systemjs/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-instanceof/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-modules-amd/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-object-super/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-modules-commonjs/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-shorthand-properties/package.json
Updating package.json dependencies at packages/babel-plugin-transform-async-to-module-method/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-parameters/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-template-literals/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-spread/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-unicode-regex/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-typeof-symbol/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es3-property-literals/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es3-member-expression-literals/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es5-property-mutators/package.json
Updating package.json dependencies at packages/babel-plugin-transform-es2015-sticky-regex/package.json
Updating package.json dependencies at packages/babel-plugin-transform-eval/package.json
Updating package.json dependencies at packages/babel-plugin-transform-export-extensions/package.json
Updating package.json dependencies at packages/babel-plugin-transform-exponentiation-operator/package.json
Updating package.json dependencies at packages/babel-plugin-transform-flow-strip-types/package.json
Updating package.json dependencies at packages/babel-plugin-transform-flow-comments/package.json
Updating package.json dependencies at packages/babel-plugin-transform-object-rest-spread/package.json
Updating package.json dependencies at packages/babel-plugin-transform-jscript/package.json
Updating package.json dependencies at packages/babel-plugin-transform-function-bind/package.json
Updating package.json dependencies at packages/babel-plugin-transform-object-assign/package.json
Updating package.json dependencies at packages/babel-plugin-transform-react-display-name/package.json
Updating package.json dependencies at packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json
Updating package.json dependencies at packages/babel-plugin-transform-proto-to-assign/package.json
Updating package.json dependencies at packages/babel-plugin-transform-react-constant-elements/package.json
Updating package.json dependencies at packages/babel-plugin-transform-react-jsx/package.json
Updating package.json dependencies at packages/babel-plugin-transform-react-jsx-self/package.json
Updating package.json dependencies at packages/babel-plugin-transform-react-inline-elements/package.json
Updating package.json dependencies at packages/babel-plugin-transform-react-jsx-compat/package.json
Updating package.json dependencies at packages/babel-plugin-transform-react-jsx-source/package.json
Updating package.json dependencies at packages/babel-plugin-transform-runtime/package.json
Updating package.json dependencies at packages/babel-plugin-transform-regenerator/package.json
Updating package.json dependencies at packages/babel-plugin-transform-strict-mode/package.json
Updating package.json dependencies at packages/babel-polyfill/package.json
Updating package.json dependencies at packages/babel-preset-es2015/package.json
Updating package.json dependencies at packages/babel-preset-es2016/package.json
Updating package.json dependencies at packages/babel-preset-es2017/package.json
Updating package.json dependencies at packages/babel-preset-latest/package.json
Updating package.json dependencies at packages/babel-preset-flow/package.json
Updating package.json dependencies at packages/babel-preset-stage-0/package.json
Updating package.json dependencies at packages/babel-register/package.json
Updating package.json dependencies at packages/babel-preset-stage-1/package.json
Updating package.json dependencies at packages/babel-preset-stage-3/package.json
Updating package.json dependencies at packages/babel-preset-react/package.json
Updating package.json dependencies at packages/babel-runtime/package.json
Updating package.json dependencies at packages/babel-types/package.json
Updating package.json dependencies at packages/babel-template/package.json
Updating package.json dependencies at packages/babel-traverse/package.json
Updating package.json dependencies at packages/babel-plugin-undeclared-variables-check/package.json
Updating package.json dependencies at packages/babel-preset-stage-2/package.json
Updating package.json dependencies at packages/babel-core/test/fixtures/config/pkg/package.json
Updating package.json 'babel' config at package.json
Updating package.json 'babel' config at packages/babel-core/test/fixtures/config/pkg/package.json

Diff lookes like this: https://pastebin.com/P0QSxFcP

@hiroppy
Copy link
Member

hiroppy commented Feb 25, 2018

Thanks!
You can check the checkbox(Monorepo support)! https://github.com/babel/babel-upgrade/blob/master/readme.md#todos

src/index.js Outdated
@@ -57,7 +57,11 @@ async function updatePackageJSON(pkg) {
}
}

const flowConfigs = await globby(['**/.flowconfig', '!**/node_modules/**']);
const flowConfigs = await globby(['.flowconfig', '!**/node_modules/**'], {
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to change from **/.flowconfig to .flowconfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the react repo it found the .flowconfig in the root from every package and added flow-type dependency in every package.json even though there is only one .flowconfig in the root.
But as I said I don't have experience with flow yet, maybe this is what should happen?

Choose a reason for hiding this comment

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

Flow takes the closest .flowconfig file it can process (by traversing up the tree) and usually this config is in the root of the project. Also, Flow doesn't traverse for configs down the tree (and thus doesn't merge existing configs). Provided that the command will be run from project's root, this change is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I am not sure anymore @thymikee

What does this line? It looks for a .flowconfig to figure out if this is a flow project. Then later on based on this check it adds the @babel/preset-flow to the package.json in https://github.com/babel/babel-upgrade/blob/master/src/upgradeDeps.js#L57-L61
This is executed for each package.json it finds, so for each package in a monorepo.
Before my change it will find a .flowconfig in the root and add the dependency to each package. With my change it will only add the dependency to the root package.json and each package that brings it own .flowconfig.

What I do not know: Do the packages in the monorepo need this dependency or is it enough to have this in the root package.json?

Choose a reason for hiding this comment

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

With my change it will only add the dependency to the root package.json and each package that brings it own .flowconfig.

That looks like a proper behavior to me. Usually (but maybe not always), projects in a monorepo use Flow from root and don't contain their own .flowconfig. If some of them do, that would imply that Flow should be run directly from these projects instead from the root.

I'd say – if you find .flowconfig in any package in the monorepo, that package should have its own @babel/preset-flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clarifying this! Now I feel more confident with my changes.

@Raigen
Copy link
Contributor Author

Raigen commented Feb 26, 2018

I still would like someone with flow experience to check if flow repos are handled correct.

@hzoo hzoo added the enhancement New feature or request label Feb 26, 2018
@existentialism
Copy link
Member

@Raigen mind rebasing? I moved the flowconfig detection up a level so that both upgradeDeps and upgradeConfig could handle adding flow-preset properly.

Raigen and others added 4 commits March 1, 2018 14:09
Find all existings of .babelrc and package.json not in node_modules
and update them.
Parameterize writePackageJSON with a relative package.json path
from globby.
@Raigen
Copy link
Contributor Author

Raigen commented Mar 1, 2018

I did the rebase and adjustments to my changes.

@hzoo
Copy link
Member

hzoo commented Mar 1, 2018

Ok cool; the thing we don't have are some fixture tests? I know you said you tested it in some repos but we need some tests to prevent regression

@hzoo
Copy link
Member

hzoo commented Mar 1, 2018

And based on your diff with Babel, maybe we need to add an option (doesn't have to be this PR) that can exclude folders or use a glob to ignore? --ignore */test/* kind of thing using minimatch or glob or something

Updating .babelrc config at packages/babel-cli/test/.babelrc
Updating .babelrc config at packages/babel-preset-es2015/test/.babelrc
Updating .babelrc config at packages/babel-core/test/.babelrc

@armujahid
Copy link

@Raigen is anything else pending in this PR except fixture tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants