Created
February 24, 2016 17:12
-
-
Save nsfmc/aebef4e7a4944819ff40 to your computer and use it in GitHub Desktop.
change .default-less require calls for certain modules to require().default
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* add .default to requires for 'stores/index' that don't already have them. | |
* | |
* this comes up because babel6 Does The Right Thing with es6 exports and | |
* commonjs requires now need to play by the rules of the es6 exported modules | |
* and specify the default argument. see more: | |
* https://medium.com/@kentcdodds/misunderstanding-es6-modules-upgrading-babel-tears-and-a-solution-ad2d5ab93ce0#.tjlvbfd4x | |
* | |
*/ | |
export default function transformer(file, api) { | |
const j = api.jscodeshift; | |
const {expression, statement, statements} = j.template; | |
return j(file.source) | |
.find(j.VariableDeclarator, {init: { type: 'CallExpression', callee: | |
{name: 'require'}, | |
arguments: [{value: 'stores/index'}]}}) | |
.replaceWith( | |
p => j.variableDeclarator( | |
p.node.id, | |
j.memberExpression( | |
p.node.init, | |
j.identifier('default') | |
)) | |
) | |
.toSource(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the effect is going from
to