-
-
Save green3g/e92d71f26006deb871f908a36e93647c to your computer and use it in GitHub Desktop.
codemods
This file contains hidden or 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
// latest versions from canjs/canjs - make sure `npm install can` first | |
const canjs = require('can/package.json'); | |
function updateVersions(deps, canjs) { | |
const newDeps = {}; | |
Object.keys(deps).forEach((key) => { | |
// if dep exists in canjsDeps, set it to that version | |
// otherwise, keep existing version | |
newDeps[key] = canjs[key] || deps[key]; | |
}); | |
return newDeps; | |
} | |
module.exports = function transformer(file, api) { | |
let src = file.source; | |
try { | |
src = JSON.parse(src); | |
src.dependencies = updateVersions(src.dependencies, canjs.dependencies); | |
src.devDependencies = updateVersions(src.devDependencies, canjs.devDependencies); | |
// print result with 2-space indentation | |
src = JSON.stringify(src, null, 2) + '\n'; | |
} catch(e) { | |
console.error(e); | |
} | |
return src; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment