-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add codemods: CommonJS -> ES2015 module #12520
Conversation
a08dab1
to
0ae0654
Compare
0ae0654
to
cef3540
Compare
package.json
Outdated
@@ -154,6 +154,7 @@ | |||
"css-lint": "stylelint 'client/**/*.scss' --syntax scss" | |||
}, | |||
"devDependencies": { | |||
"5to6-codemod": "^1.5.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should pin these versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Nice work. Pleased to see this coming together! |
I've just ran Like so: diff --git a/client/my-sites/pages/page-list.jsx b/client/my-sites/pages/page-list.jsx
index 81b1424..59ae927 100644
--- a/client/my-sites/pages/page-list.jsx
+++ b/client/my-sites/pages/page-list.jsx
@@ -1,22 +1,24 @@
+import React from 'react';
+import PureRenderMixin from 'react-pure-render/mixin';
+
/**
* External dependencies
*/
-var React = require( 'react' ),
- PureRenderMixin = require( 'react-pure-render/mixin' ),
- omit = require( 'lodash/omit' );
+import omit from 'lodash/omit';
+
+import PostListFetcher from 'components/post-list-fetcher';
+import Page from './page';
+import infiniteScroll from 'lib/mixins/infinite-scroll';
+import observe from 'lib/mixins/data-observe';
+import EmptyContent from 'components/empty-content';
+import NoResults from 'my-sites/no-results';
+import actions from 'lib/posts/actions';
+import Placeholder from './placeholder';
/**
* Internal dependencies
*/
-var PostListFetcher = require( 'components/post-list-fetcher' ),
- Page = require( './page' ),
- infiniteScroll = require( 'lib/mixins/infinite-scroll' ),
- observe = require( 'lib/mixins/data-observe' ),
- EmptyContent = require( 'components/empty-content' ),
- NoResults = require( 'my-sites/no-results' ),
- actions = require( 'lib/posts/actions' ),
- Placeholder = require( './placeholder' ),
- mapStatus = require( 'lib/route' ).mapPostStatus;
+import { mapPostStatus as mapStatus } from 'lib/route'; |
cef3540
to
65be0b6
Compare
Hi @ockham, I updated this branch to use my forked 5to6-codemods which includes the most up-to-date fixes for the import transformation. Let me know if the fixes are to your liking! |
dff635c
to
5bdaf2b
Compare
That's a lot better, they're below the corresponding comment block now. There's still a funny newline after the first import of each block (is that related to the diff --git a/client/my-sites/pages/page-list.jsx b/client/my-sites/pages/page-list.jsx
index 81b1424..93a46ac 100644
--- a/client/my-sites/pages/page-list.jsx
+++ b/client/my-sites/pages/page-list.jsx
@@ -1,22 +1,24 @@
/**
* External dependencies
*/
-var React = require( 'react' ),
- PureRenderMixin = require( 'react-pure-render/mixin' ),
- omit = require( 'lodash/omit' );
+import React from 'react';
+
+import PureRenderMixin from 'react-pure-render/mixin';
+import omit from 'lodash/omit';
/**
* Internal dependencies
*/
-var PostListFetcher = require( 'components/post-list-fetcher' ),
- Page = require( './page' ),
- infiniteScroll = require( 'lib/mixins/infinite-scroll' ),
- observe = require( 'lib/mixins/data-observe' ),
- EmptyContent = require( 'components/empty-content' ),
- NoResults = require( 'my-sites/no-results' ),
- actions = require( 'lib/posts/actions' ),
- Placeholder = require( './placeholder' ),
- mapStatus = require( 'lib/route' ).mapPostStatus;
+import PostListFetcher from 'components/post-list-fetcher';
+
+import Page from './page';
+import infiniteScroll from 'lib/mixins/infinite-scroll';
+import observe from 'lib/mixins/data-observe';
+import EmptyContent from 'components/empty-content';
+import NoResults from 'my-sites/no-results';
+import actions from 'lib/posts/actions';
+import Placeholder from './placeholder';
+import { mapPostStatus as mapStatus } from 'lib/route';
import BlogPostsPage from './blog-posts-page'; |
Yup, that's definitely the same bug :) |
Using jscodeshift's `useTabs` and `arrayBracketSpacing` option flags will generate code more in line with our style guide.
Cool, could we split this up into a separate PR, and at least have the |
1137323
to
040d869
Compare
Great! Thanks. I'll merge this, and we'll test them out :) |
Part of #11688.
This change adds executable codemod scripts to
bin/
andbin/codemods
. The intent is to have these executables be available for Calypso contributors who are working on migrating CJS modules to ES modules. Each script inbin/codemods/
are individually executable.Todo:
Await merge & publish of Transform called CommonJS imports 5to6/5to6-codemod#40 (1).useTabs
andarrayBracketSpacing
Recast option flags*.js
and*.jsx
files inclient/
Caveats: