Execute scripts/patch/patch-jscodeshift.js
.
It will monkey-patch node_modules/jscodeshift/parser/babel5compat.js
by prepending 'decorators-legacy'
to the plugins array.
Created
June 27, 2018 08:51
-
-
Save loopmode/b737ea697f0628e2b6164e93d1fd6e74 to your computer and use it in GitHub Desktop.
monkey-patching jscodeshift for decorators support
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
// file: scripts/patch/patches/jscodeshift-addDecoratorsPlugin.js | |
const before = `plugins: [ | |
'estree',`; | |
const after = `plugins: [ | |
'decorators-legacy', | |
'estree',`; | |
module.exports = { | |
files: 'node_modules/jscodeshift/parser/babel5compat.js', | |
from: before, | |
to: after | |
}; |
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
#!/usr/bin/env node | |
// file: scripts/patch/patch-jscodeshift.js | |
const replace = require('replace-in-file'); | |
const patches = [ | |
'./patches/jscodeshift-addDecoratorsPlugin' | |
]; | |
patches.forEach(function applyPatch(patchfile) { | |
const patch = require(patchfile); | |
if (Array.isArray(patch)) { | |
patch.forEach(applyPatch); | |
return; | |
} | |
try { | |
const changes = replace.sync(patch); | |
console.log(`[patches] ${patchfile}`, changes && changes.length ? { changes } : '(unchanged)'); | |
} catch (error) { | |
console.log('┎──────────────────────────────────────────────────────────────────'); | |
console.log('┃'); | |
console.log(`┃ Failed to patch ${patch.files}`); | |
console.log('┃'); | |
console.log('┖──────────────────────────────────────────────────────────────────'); | |
console.log(error); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment