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

feat(babel): migrate to babel@7 #790

Merged
merged 7 commits into from Sep 11, 2018
Merged

feat(babel): migrate to babel@7 #790

merged 7 commits into from Sep 11, 2018

Conversation

daern91
Copy link
Contributor

@daern91 daern91 commented Sep 10, 2018

Summary

PR migrates from babel@6 to @7.
Big thanks for the pointers and inspiration from @tdeekens's PR that did the same here: tdeekens/flopflip#465

Description

One thing to notice here is the solution on how to use the config file. Babel 7 removes support for .babelrc inside of monorepos (ref).

We will now use babel.config.js instead (ref). However, please see the following quote:

The primary downside of this project-wide config is that, because it relies on the working directory, it can be more painful to use in monorepos if the working directory is not the monorepo root. For example, if you have

babel.config.js
packages/
 mod1/
   package.json
   src/index.js
 mod2/
   package.json
   src/index.js

and the individual packages are responsible for running their builds (and their working directory for Babel is the individual packages), the babel.config.js file will not be automatically loaded, and users will be required to set the path to it manually.

So, PR also changes the build script across all packages. This might not be the ideal solution so I'd love to get any thoughts and input on it. Would be great if we could find another way.

resolves #768
resolves #773
resolves #763
resolves #766

affects: @commercetools/csv-parser-discount-code, @commercetools/csv-parser-orders,
@commercetools/csv-parser-price, @commercetools/csv-parser-state,
@commercetools/custom-objects-exporter, @commercetools/custom-objects-importer,
@commercetools/customer-groups-exporter, @commercetools/discount-code-exporter,
@commercetools/discount-code-generator, @commercetools/discount-code-importer,
@commercetools/get-credentials, @commercetools/inventories-exporter,
@commercetools/personal-data-erasure, @commercetools/price-exporter,
@commercetools/product-exporter, @commercetools/product-json-to-csv, @commercetools/state-importer
@codecov
Copy link

codecov bot commented Sep 10, 2018

Codecov Report

Merging #790 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #790   +/-   ##
=======================================
  Coverage   98.75%   98.75%           
=======================================
  Files         107      107           
  Lines        2737     2737           
  Branches      624      624           
=======================================
  Hits         2703     2703           
  Misses         30       30           
  Partials        4        4

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26f47d1...b1cdfa5. Read the comment docs.

Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

Looks legit on a first glance! 👌

package.json Outdated
"@commitlint/cli": "7.1.1",
"@commitlint/config-conventional": "7.1.1",
"babel-cli": "6.26.0",
"babel-core": "6.26.3",
"babel-core": "7.0.0-bridge.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is still needed for babel-jest below (ref).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup.

@@ -1,7 +1,8 @@
{
"lerna": "2.7.1",
"lerna": "2.11.0",
Copy link
Contributor Author

@daern91 daern91 Sep 10, 2018

Choose a reason for hiding this comment

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

We can not yet update to lerna 3.x because of cz-lerna-changelog not being updated.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, why are we still using that?

Copy link
Contributor Author

@daern91 daern91 Sep 10, 2018

Choose a reason for hiding this comment

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

It's used by commitizen when running the commit script.

"commit": "git-cz",

I'm not sure its very effective though, looking at the changelog it doesnt seem to be updated...
https://github.com/commercetools/nodejs/blob/master/CHANGELOG.md

Maybe we could get rid of it instead?

Copy link
Member

Choose a reason for hiding this comment

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

I would get rid of it. I think no one is using that command...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, will do. I'll keep commitizen itself tho as it's amazing for on-boarding students and introducing them to angular commit convention.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ask around in the team. I am not aware of anyone using it anymore. It was good introducing the style but should not be needed anymore. I would recommend removing it in amothrr PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

commitizen itself is so drilled into my spine that it is part of my muscle memory now.
However, if you feel that you want to keep this to ease "onboarding", or in some extent ensuring consistency in commit messages, then don't listen to us 👍

@@ -28,7 +28,7 @@
"lib"
],
"scripts": {
"build": "babel src --out-dir lib"
"build": "babel src --out-dir lib --config-file '../../babel.config.js'"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other ideas would be appreciated here. I do prefer this over having a config file inside of every package but it's definitely not ideal.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine like this

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes this is fine. To my knowledge the idea of a babel.config over an rc without being breaking is to be more explicit. Meaning you pass it, you import it etc.

Copy link
Contributor

@tdeekens tdeekens left a comment

Choose a reason for hiding this comment

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

💯👍🏼

babel.config.js Outdated
break
}
return {}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nicely done.

@@ -0,0 +1,3 @@
const babelConfig = require('./babel.config')

module.exports = require('babel-jest').createTransformer(babelConfig)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep. Have the same on mc-fe and flopflip. This js good and does he job.

@@ -1,7 +1,8 @@
{
"lerna": "2.7.1",
"lerna": "2.11.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Ask around in the team. I am not aware of anyone using it anymore. It was good introducing the style but should not be needed anymore. I would recommend removing it in amothrr PR.

package.json Outdated
"@commitlint/cli": "7.1.1",
"@commitlint/config-conventional": "7.1.1",
"babel-cli": "6.26.0",
"babel-core": "6.26.3",
"babel-core": "7.0.0-bridge.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Yup.

@@ -28,7 +28,7 @@
"lib"
],
"scripts": {
"build": "babel src --out-dir lib"
"build": "babel src --out-dir lib --config-file '../../babel.config.js'"
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes this is fine. To my knowledge the idea of a babel.config over an rc without being breaking is to be more explicit. Meaning you pass it, you import it etc.

@@ -4,7 +4,7 @@
"description": "Import states to the commercetools platform",
"main": "lib/main.js",
"scripts": {
"build": "babel src --out-dir lib"
"build": "babel src --out-dir lib --config-file '../../babel.config.js'"
Copy link
Contributor

Choose a reason for hiding this comment

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

You could maybe also pass it as an env var fro, the host project. BABEL_CONFIG=„blub“ and use it here via interpolation. I may have seen that somewhere. Not sure it serves a bug benefit however as it never moves etc.

}),
babel(
Object.assign(
{
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought you could spread here. Not sure what the nvmrc says in the repo these days 🎃

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that this file is not getting transpiled by babel and as we support node from version v6 we should not use any of new syntax here. Also, the spread operator based on ES6 works only with arrays.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, it doesn't.

I tried ES7 Object spread first but it failed on Node6 :(

Copy link
Contributor

@junajan junajan left a comment

Choose a reason for hiding this comment

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

Hi @daern91 .. you did really a good job here in this PR.. I added just two nitpicks

babel.config.js Outdated
default:
break
}
return {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a nitpick: this return {} can be in default branch instead of break.

Copy link
Contributor Author

@daern91 daern91 Sep 11, 2018

Choose a reason for hiding this comment

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

Ahh, good find, fixed here 4fbe7d3

}),
babel(
Object.assign(
{
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that this file is not getting transpiled by babel and as we support node from version v6 we should not use any of new syntax here. Also, the spread operator based on ES6 works only with arrays.

@daern91 daern91 merged commit bc6a3ee into master Sep 11, 2018
@daern91 daern91 deleted the migrate-to-babel-7 branch September 11, 2018 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants