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

Migrate CommonJS to ES2015 module notation (imports and exports) #11688

Closed
8 of 11 tasks
jsnmoon opened this issue Mar 1, 2017 · 5 comments
Closed
8 of 11 tasks

Migrate CommonJS to ES2015 module notation (imports and exports) #11688

jsnmoon opened this issue Mar 1, 2017 · 5 comments
Assignees
Labels
Framework OSS Citizen [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Type] Task

Comments

@jsnmoon
Copy link
Contributor

jsnmoon commented Mar 1, 2017

Context

Porting CommonJS modules to ES2015 modules will allow us to take advantage of Webpack 2's tree shaking optimization.

Status

Completed

  • Improve 5to6-codemod's import comment handling
  • Write a codemod to generate named exports from default object import (awaiting publication)
  • Improve CommonJS import codemod's comment handling
  • Improve CommonJS import codemod's called import handling
  • Write a codemod to hoist imports in blocks to the top
  • Test running codemods on client/
  • Enhance the named export generation codemod to transform functions to export functions
  • Provide easy executables for Calypso developers to ES2015-ify their modules (Add codemods: CommonJS -> ES2015 module #12520)

In review

Backburner

Logs and Notes

Initial impressions

We have many occurrences of conditional imports and imports inside blocks. Neither of these are allowed in ES modules, so we'll need to migrate these eventually.

  • Dynamic imports are possible, but probably not stable enough for us to jump on.
  • Hoisting imports from the blocks to the top might be straightforward solution. I would need to figure out how much of these imports have side effects before going forward with this, though. Most imports inside a block are from controller.js files.

Progress - 03/01/2017

  • Tested porting CommonJS imports via regex.
  • Tested porting CommonJS imports/exports via 5to6-codemod.

Progress - 03/24/2017

  • Contributed improvements to 5to6-codemod relating to both import and export transforms; currently awaiting merge & NPM publish for new version.
  • PR in progress to add 5to6-codemod as executable scripts inside this project.
  • PR in progress for enhancing our ESLint with eslint-plugin-import.

Progress - 04/04/2017

  • Made various improvements to 5to6-codemod, including CommonJS import hoisting and improved reliability.
  • All three codemods (import, export, and export name generation) run error-free for files inside client/.

Progress - 04/17/2017

  • Refactored run-codemods into a separate PR.
@jsnmoon jsnmoon added the [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Mar 1, 2017
@jsnmoon jsnmoon self-assigned this Mar 25, 2017
@jsnmoon
Copy link
Contributor Author

jsnmoon commented Apr 6, 2017

Update: named export generation codemod has been enhanced.

@jsnmoon
Copy link
Contributor Author

jsnmoon commented Apr 7, 2017

Update: bin/run-codemods has been created.

@jsnmoon jsnmoon changed the title Migrating imports and exports from CommonJS to ES2015 Migrate CommonJS to ES2015 module notation (imports and exports) Apr 12, 2017
@jsnmoon jsnmoon mentioned this issue Apr 12, 2017
8 tasks
@jsnmoon
Copy link
Contributor Author

jsnmoon commented Apr 18, 2017

Update: Added progress update for 04/17/2017 covering run-codemods PR. react-codemods PR and upstream PR for reactjs/react-codemod.

@jsnmoon
Copy link
Contributor Author

jsnmoon commented Apr 22, 2017

Update: Removed all mentions of react-codemods. Please refer to #13321 if you'd like to follow along the React migration project!

@jsnmoon
Copy link
Contributor Author

jsnmoon commented Jul 25, 2017

This issue is in a good place to close for now. If anyone has any interest in picking up the backburner items, please ping!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework OSS Citizen [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Type] Task
Projects
None yet
Development

No branches or pull requests

2 participants