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

Signup: Migrate imports and exports from CommonJS to ES2015 #11719

Merged
merged 2 commits into from
Mar 17, 2017

Conversation

jsnmoon
Copy link
Contributor

@jsnmoon jsnmoon commented Mar 2, 2017

Part of #11688.

This change will allow us to leverage Webpack 2's tree shaking optimization for ES6 modules in the future. Please share your suggestions and comments!

@jsnmoon jsnmoon added [Status] In Progress [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it labels Mar 2, 2017
@matticbot matticbot added OSS Citizen [Size] L Large sized issue labels Mar 2, 2017
@jsnmoon jsnmoon added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Mar 2, 2017
@jsnmoon jsnmoon requested review from blowery and drewblaisdell March 2, 2017 20:22
Copy link
Contributor

@drewblaisdell drewblaisdell left a comment

Choose a reason for hiding this comment

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

The changes here look good to me. I had a comment but it isn't something that needs to change. I tested with the main flow (/start) logged in and logged out and the behavior was unchanged.

I'm AFK tomorrow so I will merge this on Monday if no one beats me to it.

var React = require( 'react' ),
debug = require( 'debug' )( 'calypso:signup:wpcom-login' );
import React from 'react';
const debug = require( 'debug' )( 'calypso:signup:wpcom-login' );
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we usually use a different syntax for this:

import debugFactory from 'debug'; // sometimes named debugModule
const debug = debugFactory( 'calypso:whatever' );

Per:

wp-calypso (master) ☯ spot client/ const debug | grep debug | grep require | wc -l
      15
wp-calypso (master) ☯ spot client/ const debug | grep debug | grep Module | wc -l
      41
wp-calypso (master) ☯ spot client/ const debug | grep debug | grep Factory | wc -l
      68

I don't see a reason to not use the shorter syntax you have here, but I thought it was worth mentioning.

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's good to know. (Since this is part of a bulk change, I was wary of introducing an intermediary variable in case of collisions.)

I think using the shorter syntax has two potential downsides - you've already mentioned the first (it deviates from an established pattern in the codebase). The second is that Webpack 2 won't be able to tree shake this import due to the CommonJS notation. However, I highly doubt we'd reach a situation where we'd need to shake debug off during a build.

@drewblaisdell drewblaisdell added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Mar 3, 2017
Copy link
Contributor

@spen spen left a comment

Choose a reason for hiding this comment

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

Looks good! There are a few cases where lodash imports could be updated but those could be tackled in the future I'm sure :)

assign = require( 'lodash/assign' );
import i18n from 'i18n-calypso';
import React from 'react';
import assign from 'lodash/assign';
Copy link
Contributor

Choose a reason for hiding this comment

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

We use a babel plugin that allows tree-shaking of lodash utils already, so this could be converted to:

import { assign } from 'lodash';

FFTI if you feel this is out of this PR's scope though :)

map = require( 'lodash/map' ),
debug = require( 'debug' )( 'calypso:steps:site' ); // eslint-disable-line no-unused-vars
import React from 'react';
import isEmpty from 'lodash/isEmpty';
Copy link
Contributor

Choose a reason for hiding this comment

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

And here, in this case we would see more benefit as we could truncate the 3 imports :D
Actually, this might be a good thing to tackle on another pass, regexing or code-modding for lodash/xx specifically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed!

@jsnmoon jsnmoon force-pushed the try/cjs-import-export-signup branch from 75c4925 to 31a802e Compare March 3, 2017 23:10
@matticbot matticbot added the [Size] L Large sized issue label Mar 3, 2017
@jsnmoon jsnmoon force-pushed the try/cjs-import-export-signup branch from 31a802e to 988a918 Compare March 17, 2017 04:04
@drewblaisdell drewblaisdell force-pushed the try/cjs-import-export-signup branch from 988a918 to 9403f8d Compare March 17, 2017 19:07
@drewblaisdell drewblaisdell merged commit a1d3501 into master Mar 17, 2017
@drewblaisdell drewblaisdell deleted the try/cjs-import-export-signup branch March 17, 2017 19:44
@matticbot matticbot added the [Size] L Large sized issue label Mar 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OSS Citizen [Size] L Large sized issue [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants