From ef73d1473994057c1cb10b1cf28bf27206201fc3 Mon Sep 17 00:00:00 2001 From: Alexander Nanberg Date: Tue, 28 Aug 2018 19:30:07 +0200 Subject: [PATCH 1/3] feat: upgrade to babel 7 (#62) --- package.json | 23 +++++++++++------------ src/config/babelrc.js | 29 ++++++++++++----------------- src/scripts/build/babel.js | 2 +- 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 35059340..cd48060d 100644 --- a/package.json +++ b/package.json @@ -31,22 +31,21 @@ "author": "Kent C. Dodds (http://kentcdodds.com/)", "license": "MIT", "dependencies": { + "@babel/cli": "^7.0.0", + "@babel/core": "^7.0.0", + "@babel/plugin-proposal-class-properties": "^7.0.0", + "@babel/plugin-transform-modules-commonjs": "^7.0.0", + "@babel/preset-env": "^7.0.0", + "@babel/preset-react": "^7.0.0", "all-contributors-cli": "^5.0.0", "arrify": "^1.0.1", - "babel-cli": "^6.26.0", - "babel-core": "^6.26.3", + "babel-core": "^7.0.0-0", "babel-jest": "^23.4.2", - "babel-plugin-external-helpers": "^6.22.0", "babel-plugin-macros": "^2.3.0", - "babel-plugin-minify-dead-code-elimination": "^0.3.0", + "babel-plugin-minify-dead-code-elimination": "^0.4.0", "babel-plugin-module-resolver": "^3.1.1", - "babel-plugin-transform-class-properties": "^6.24.1", - "babel-plugin-transform-inline-environment-variables": "^0.3.0", - "babel-plugin-transform-object-rest-spread": "^6.26.0", - "babel-plugin-transform-react-jsx": "^6.24.1", + "babel-plugin-transform-inline-environment-variables": "^0.4.0", "babel-plugin-transform-react-remove-prop-types": "^0.4.13", - "babel-preset-env": "^1.6.1", - "babel-preset-react": "^6.24.1", "browserslist": "^4.0.0", "concurrently": "^3.5.1", "cross-env": "^5.1.4", @@ -68,8 +67,8 @@ "read-pkg-up": "^4.0.0", "resolve": "^1.6.0", "rimraf": "^2.6.2", - "rollup": "^0.63.0", - "rollup-plugin-babel": "^3.0.3", + "rollup": "^0.65.0", + "rollup-plugin-babel": "^4.0.0", "rollup-plugin-commonjs": "^9.1.0", "rollup-plugin-json": "^3.0.0", "rollup-plugin-node-builtins": "^2.1.2", diff --git a/src/config/babelrc.js b/src/config/babelrc.js index acf45e07..dc03a40b 100644 --- a/src/config/babelrc.js +++ b/src/config/babelrc.js @@ -27,28 +27,25 @@ const envTargets = isTest : {node: '4.5'} const envOptions = {modules: false, loose: true, targets: envTargets} -module.exports = { +module.exports = () => ({ presets: [ - [require.resolve('babel-preset-env'), envOptions], - ifAnyDep(['react', 'preact'], require.resolve('babel-preset-react')), + [require.resolve('@babel/preset-env'), envOptions], + ifAnyDep( + ['react', 'preact'], + [ + require.resolve('@babel/preset-react'), + {pragma: isPreact ? 'React.h' : undefined}, + ], + ), ].filter(Boolean), plugins: [ require.resolve('babel-plugin-macros'), - isRollup ? require.resolve('babel-plugin-external-helpers') : null, - // we're actually not using JSX at all, but I'm leaving this - // in here just in case we ever do (this would be easy to miss). alias ? [ require.resolve('babel-plugin-module-resolver'), {root: ['./src'], alias}, ] : null, - isPreact - ? [ - require.resolve('babel-plugin-transform-react-jsx'), - {pragma: 'React.h'}, - ] - : null, [ require.resolve('babel-plugin-transform-react-remove-prop-types'), isPreact ? {removeImport: true} : {mode: 'unsafe-wrap'}, @@ -56,12 +53,10 @@ module.exports = { isUMD ? require.resolve('babel-plugin-transform-inline-environment-variables') : null, - // TODO: use loose mode when upgrading to babel@7 - require.resolve('babel-plugin-transform-class-properties'), - require.resolve('babel-plugin-transform-object-rest-spread'), + [require.resolve('@babel/plugin-proposal-class-properties'), {loose: true}], require.resolve('babel-plugin-minify-dead-code-elimination'), treeshake ? null - : require.resolve('babel-plugin-transform-es2015-modules-commonjs'), + : require.resolve('@babel/plugin-transform-modules-commonjs'), ].filter(Boolean), -} +}) diff --git a/src/scripts/build/babel.js b/src/scripts/build/babel.js index d4486b63..92a3783a 100644 --- a/src/scripts/build/babel.js +++ b/src/scripts/build/babel.js @@ -26,7 +26,7 @@ if (!useSpecifiedOutDir && !args.includes('--no-clean')) { } const result = spawn.sync( - resolveBin('babel-cli', {executable: 'babel'}), + resolveBin('@babel/cli', {executable: 'babel'}), [...outDir, ...copyFiles, ...ignore, ...config, 'src'].concat(args), {stdio: 'inherit'}, ) From 3f916e8b75ca69cabec798343fdb7a9f5a094322 Mon Sep 17 00:00:00 2001 From: Alexander Nanberg Date: Fri, 31 Aug 2018 15:17:20 +0200 Subject: [PATCH 2/3] chore: upgrade travis-deploy-once dependency (#63) --- .../__snapshots__/travis-after-success.js.snap | 10 +++++----- src/scripts/travis-after-success.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/scripts/__tests__/__snapshots__/travis-after-success.js.snap b/src/scripts/__tests__/__snapshots__/travis-after-success.js.snap index ebfa9024..45c0eb21 100644 --- a/src/scripts/__tests__/__snapshots__/travis-after-success.js.snap +++ b/src/scripts/__tests__/__snapshots__/travis-after-success.js.snap @@ -1,22 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`travis-after-success calls concurrently with both scripts when on travis 1`] = `npx travis-deploy-once@4`; +exports[`travis-after-success calls concurrently with both scripts when on travis 1`] = `npx travis-deploy-once@5`; exports[`travis-after-success calls concurrently with both scripts when on travis 2`] = `concurrently --prefix [{name}] --names codecov,release --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'" "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`; -exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 1`] = `npx travis-deploy-once@4`; +exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 1`] = `npx travis-deploy-once@5`; exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 2`] = `concurrently --prefix [{name}] --names codecov --prefix-colors bgBlue.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'"`; -exports[`travis-after-success does not do the autorelease script when the version is different 1`] = `npx travis-deploy-once@4`; +exports[`travis-after-success does not do the autorelease script when the version is different 1`] = `npx travis-deploy-once@5`; exports[`travis-after-success does not do the autorelease script when the version is different 2`] = `concurrently --prefix [{name}] --names codecov --prefix-colors bgBlue.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'"`; -exports[`travis-after-success does not do the codecov script when opted out 1`] = `npx travis-deploy-once@4`; +exports[`travis-after-success does not do the codecov script when opted out 1`] = `npx travis-deploy-once@5`; exports[`travis-after-success does not do the codecov script when opted out 2`] = `concurrently --prefix [{name}] --names release --prefix-colors bgBlue.bold.reset "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`; -exports[`travis-after-success does not do the codecov script when there is no coverage directory 1`] = `npx travis-deploy-once@4`; +exports[`travis-after-success does not do the codecov script when there is no coverage directory 1`] = `npx travis-deploy-once@5`; exports[`travis-after-success does not do the codecov script when there is no coverage directory 2`] = `concurrently --prefix [{name}] --names release --prefix-colors bgBlue.bold.reset "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`; diff --git a/src/scripts/travis-after-success.js b/src/scripts/travis-after-success.js index a5707500..37b11845 100644 --- a/src/scripts/travis-after-success.js +++ b/src/scripts/travis-after-success.js @@ -8,7 +8,7 @@ const { } = require('../utils') console.log('installing and running travis-deploy-once') -const deployOnceResults = spawn.sync('npx', ['travis-deploy-once@4']) +const deployOnceResults = spawn.sync('npx', ['travis-deploy-once@5']) if (deployOnceResults.status === 0) { runAfterSuccessScripts() } else { From 31783586202f86f57e7c90a8320a4ab116491872 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Tue, 4 Sep 2018 10:48:09 -0600 Subject: [PATCH 3/3] feat: support custom node version based on engines (#66) --- package.json | 1 + src/config/babelrc.js | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index cd48060d..9e7789cd 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "rollup-plugin-replace": "^2.0.0", "rollup-plugin-size-snapshot": "^0.6.1", "rollup-plugin-terser": "^1.0.1", + "semver": "^5.5.1", "which": "^1.3.0", "yargs-parser": "^10.0.0" }, diff --git a/src/config/babelrc.js b/src/config/babelrc.js index dc03a40b..46a8011e 100644 --- a/src/config/babelrc.js +++ b/src/config/babelrc.js @@ -1,6 +1,7 @@ const browserslist = require('browserslist') +const semver = require('semver') -const {ifAnyDep, parseEnv, appDirectory} = require('../utils') +const {ifAnyDep, parseEnv, appDirectory, pkg} = require('../utils') const isTest = (process.env.BABEL_ENV || process.env.NODE_ENV) === 'test' const isPreact = parseEnv('BUILD_PREACT', false) @@ -24,7 +25,7 @@ const envTargets = isTest ? {node: 'current'} : isWebpack || isRollup ? {browsers: browsersConfig} - : {node: '4.5'} + : {node: getNodeVersion(pkg)} const envOptions = {modules: false, loose: true, targets: envTargets} module.exports = () => ({ @@ -60,3 +61,18 @@ module.exports = () => ({ : require.resolve('@babel/plugin-transform-modules-commonjs'), ].filter(Boolean), }) + +function getNodeVersion({engines: {node: nodeVersion = '8'} = {}}) { + const oldestVersion = semver + .validRange(nodeVersion) + .replace(/[>=<|]/g, ' ') + .split(' ') + .filter(Boolean) + .sort(semver.compare)[0] + if (!oldestVersion) { + throw new Error( + `Unable to determine the oldest version in the range in your package.json at engines.node: "${nodeVersion}". Please attempt to make it less ambiguous.`, + ) + } + return oldestVersion +}