babel-upgrade
Advanced tools
Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "babel-upgrade", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Upgrade tool for Babel", | ||
@@ -14,6 +14,8 @@ "bin": "./bin/babel-upgrade", | ||
"dependencies": { | ||
"golden-fleece": "^1.0.3", | ||
"load-json-file": "^4.0.0", | ||
"json5": "^0.5.1", | ||
"pify": "^3.0.0", | ||
"read-pkg-up": "^3.0.0", | ||
"semver": "^5.5.0", | ||
"sort-keys": "^2.0.0", | ||
"write-json-file": "^2.3.0", | ||
"write-pkg": "^3.1.0" | ||
@@ -20,0 +22,0 @@ }, |
@@ -11,2 +11,3 @@ # babel-upgrade | ||
- [ ] auto run npm or yarn | ||
- [x] Update `package.json`: `dependencies` and `devDependencies` to the "latest supported" version. | ||
@@ -17,8 +18,16 @@ - This includes doing all package renames | ||
- [x] modify scripts for mocha + `@babel/register` | ||
- [ ] throw/warn if engines is < node 4 or current node is < 4? | ||
- [ ] log when replacing out preset-es2015,16,17,latest as FYI | ||
- [ ] if `babel-node` is used, import `@babel/node`? | ||
- [ ] Update the babel config file(s). | ||
- [x] `.babelrc` | ||
- [ ] `.babelrc.js` | ||
- [ ] `package.json babel key` | ||
- [x] `package.json babel key` | ||
- [x] handle `env` | ||
- [x] handle shorthand names: `babel-preset-env` and `env` | ||
- [ ] convert comma separated presets/plugins into an array | ||
- [ ] handle react + flow preset being split. Read if `.flowconfig` and add it? | ||
- [ ] convert only/ignore? | ||
- [ ] how do we want to handle spec/loose modes, especially when changing previous loose mode to spec (just warn?) | ||
- [ ] remove `typeof-symbol` if using `@babel/preset-env` | ||
- [ ] Update test files that use babel directly (`babel-types`, `babel-core`) | ||
@@ -28,2 +37,6 @@ - Update all requires/imports | ||
- [ ] Misc files as we go (`karma.conf.js`, `mocha.opts`) | ||
- [ ] Add to the upgrade guide which parts are autofixable and the command (if we care enough to make this individually runnable too infrastructure wise) | ||
- [ ] May need to add a warning on any 3rd party plugins since they might not be compatible | ||
- [ ] later: work on node 4 | ||
- [ ] Should certain parts be generic (replace the string `babel-register` with `@babel/register`)? Could be in a Makefile or somewhere else, but it's just find replace. | ||
@@ -30,0 +43,0 @@ ## Philosophy |
const path = require('path'); | ||
const readPkgUp = require('read-pkg-up'); | ||
const sortKeys = require('sort-keys'); | ||
const loadJsonFile = require('load-json-file'); | ||
const fs = require('fs'); | ||
const pify = require('pify'); | ||
const JSON5 = require('json5'); | ||
const writeJsonFile = require('write-json-file'); | ||
@@ -24,2 +26,3 @@ | ||
function updatePackageJSON(pkg) { | ||
console.log("Updating closest package.json dependencies"); | ||
if (pkg.devDependencies) { | ||
@@ -51,7 +54,17 @@ pkg.devDependencies = sortKeys(upgradeDeps( | ||
if (pkg.babel) { | ||
console.log("Updating package.json 'babel' config"); | ||
pkg.babel = upgradeConfig(pkg.babel); | ||
} | ||
await writeJsonFile(path, pkg, { detectIndent: true }); | ||
} | ||
function updateBabelRC(config) { | ||
return upgradeConfig(config); | ||
async function readBabelRC(configPath) { | ||
try { | ||
const rawFile = (await pify(fs.readFile)(configPath)).toString('utf8'); | ||
return JSON5.parse(rawFile); | ||
} catch (e) { | ||
throw new Error(`babel-upgrade: ${configPath} does not contain a valid .babelrc file. ${e.stack}`); | ||
} | ||
} | ||
@@ -63,10 +76,10 @@ | ||
try { | ||
json = await loadJsonFile(configPath); | ||
} catch (e) { | ||
throw new Error(`babel-upgrade: ${configPath} does not contain a .babelrc file`); | ||
json = await readBabelRC(configPath); | ||
} catch (e) {} | ||
if (json) { | ||
console.log("Updating ./.babelrc config"); | ||
json = upgradeConfig(json); | ||
await writeJsonFile(configPath, json, { detectIndent: true }); | ||
} | ||
json = updateBabelRC(json); | ||
await writeJsonFile(configPath, json, { detectIndent: true }); | ||
} | ||
@@ -77,4 +90,5 @@ | ||
writePackageJSON, | ||
readBabelRC, | ||
writeBabelRC, | ||
getLatestVersion | ||
}; |
@@ -211,2 +211,3 @@ const transformPlugins = { | ||
const misc = { | ||
'babel': null, | ||
'babel-cli': '@babel/cli', | ||
@@ -217,5 +218,2 @@ 'babel-code-frame': '@babel/code-frame', | ||
'babel-node': '@babel/node', | ||
'babel-plugin-check-es2015-constants': null, | ||
'babel-plugin-codemod-optional-catch-binding': '@babel/plugin-codemod-optional-catch-binding', | ||
'babel-plugin-external-helpers': '@babel/plugin-external-helpers', | ||
'babel-polyfill': '@babel/polyfill', | ||
@@ -232,3 +230,10 @@ 'babel-preset-env-standalone': '@babel/preset-env-standalone', | ||
const plugins = Object.assign({}, transformPlugins, syntaxPlugins, proposalPlugins); | ||
const plugins = Object.assign({ | ||
'babel-plugin-check-es2015-constants': null, | ||
'babel-plugin-external-helpers': '@babel/plugin-external-helpers', | ||
'babel-plugin-codemod-optional-catch-binding': '@babel/plugin-codemod-optional-catch-binding', | ||
}, | ||
transformPlugins, | ||
syntaxPlugins, | ||
proposalPlugins); | ||
@@ -243,3 +248,3 @@ const packages = Object.assign( | ||
const latestPackages = Array.from(new Set(Object.values(packages))); | ||
const latestPackages = new Set(Object.values(packages)); | ||
@@ -246,0 +251,0 @@ module.exports = { |
const { updatePackageJSON } = require('./'); | ||
const upgradeDeps = require('./upgradeDeps'); | ||
const depsFixture = require('./fixtures-deps'); | ||
const scriptsFixture = require('./fixtures-script'); | ||
const babelCoreFixture = require('./fixtures-babel-core'); | ||
const babelCoreFixture = require('../fixtures/babel-core'); | ||
const depsFixture = require('../fixtures/deps'); | ||
const depsFixtureEarlierBeta = require('../fixtures/deps-earlier-beta.json'); | ||
const scriptsFixture = require('../fixtures/script'); | ||
@@ -13,6 +14,10 @@ test('packages', () => { | ||
expect(updatePackageJSON(scriptsFixture)).toMatchSnapshot(); | ||
}) | ||
}); | ||
test('@babel/core peerDep', () => { | ||
expect(updatePackageJSON(babelCoreFixture)).toMatchSnapshot(); | ||
}) | ||
}); | ||
test('packages - earlier v7', () => { | ||
expect(upgradeDeps(depsFixtureEarlierBeta, "7.0.0-beta.39")).toMatchSnapshot(); | ||
}); |
@@ -56,3 +56,3 @@ const { presets: oldPresets, plugins: oldPlugins } = require('./packageData'); | ||
if (pluginsToReplace.includes(plugin)) { | ||
plugins[i] = oldPlugins[plugin]; | ||
plugins[i] = oldPlugins[plugin]; | ||
} | ||
@@ -59,0 +59,0 @@ } |
@@ -0,3 +1,6 @@ | ||
const path = require('path'); | ||
const upgradeConfig = require('./upgradeConfig'); | ||
const babelrcFixture = require('./babelrc'); | ||
const { readBabelRC } = require('./'); | ||
const JSON5_PATH = path.resolve(__dirname, 'babelrc.json5'); | ||
@@ -7,1 +10,6 @@ test('packages', () => { | ||
}); | ||
test('packages (json5)', async () => { | ||
const json5Data = await readBabelRC(JSON5_PATH); | ||
expect(upgradeConfig(json5Data)).toMatchSnapshot(); | ||
}); |
@@ -0,1 +1,2 @@ | ||
const semver = require('semver'); | ||
const { packages: oldPackages, latestPackages } = require('./packageData'); | ||
@@ -25,4 +26,8 @@ | ||
} | ||
// TODO: use semver check | ||
} else if (Object.keys(latestPackages).includes(pkg) && depVersion !== version) { | ||
} else if ( | ||
latestPackages.has(pkg) && | ||
semver.valid(depVersion) && | ||
semver.valid(version) && | ||
semver.lt(depVersion, version) | ||
) { | ||
dependencies[pkg] = version; | ||
@@ -36,9 +41,8 @@ // TODO: refactor out somewhere else | ||
// one-off on checking for `@babel/core` dep | ||
const deps = Object.keys(dependencies); | ||
if (deps.some(a => { | ||
return a.includes('@babel/plugin') || a.includes('@babel/preset'); | ||
})) { | ||
if (!deps.includes('@babel/core')) { | ||
dependencies['@babel/core'] = version; | ||
} | ||
if ( | ||
!dependencies['@babel/core'] && | ||
Object.keys(dependencies).some(a => | ||
a.startsWith('@babel/plugin') || a.startsWith('@babel/preset')) | ||
) { | ||
dependencies['@babel/core'] = version; | ||
} | ||
@@ -45,0 +49,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
47975
17
686
50
7
3
+ Addedjson5@^0.5.1
+ Addedpify@^3.0.0
+ Addedsemver@^5.5.0
+ Addedwrite-json-file@^2.3.0
+ Addedjson5@0.5.1(transitive)
- Removedgolden-fleece@^1.0.3
- Removedload-json-file@^4.0.0
- Removedgolden-fleece@1.0.9(transitive)