forked from kentcdodds/kcd-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from inthepocket/feature/pull-changes-from-base…
…-branch Feature/pull changes from base branch
- Loading branch information
Showing
5 changed files
with
100 additions
and
88 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,78 @@ | ||
const browserslist = require('browserslist'); | ||
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); | ||
const isRollup = parseEnv('BUILD_ROLLUP', false); | ||
const isUMD = process.env.BUILD_FORMAT === 'umd'; | ||
const isWebpack = parseEnv('BUILD_WEBPACK', false); | ||
const treeshake = parseEnv('BUILD_TREESHAKE', isRollup || isWebpack); | ||
const alias = parseEnv('BUILD_ALIAS', isPreact ? { react: 'preact' } : null); | ||
const isTest = (process.env.BABEL_ENV || process.env.NODE_ENV) === 'test' | ||
const isPreact = parseEnv('BUILD_PREACT', false) | ||
const isRollup = parseEnv('BUILD_ROLLUP', false) | ||
const isUMD = process.env.BUILD_FORMAT === 'umd' | ||
const isWebpack = parseEnv('BUILD_WEBPACK', false) | ||
const treeshake = parseEnv('BUILD_TREESHAKE', isRollup || isWebpack) | ||
const alias = parseEnv('BUILD_ALIAS', isPreact ? {react: 'preact'} : null) | ||
|
||
/** | ||
* use the strategy declared by browserslist to load browsers configuration. | ||
* fallback to the default if don't found custom configuration | ||
* @see https://github.com/browserslist/browserslist/blob/master/node.js#L139 | ||
*/ | ||
const browsersConfig = browserslist.loadConfig({ path: appDirectory }) || [ | ||
const browsersConfig = browserslist.loadConfig({path: appDirectory}) || [ | ||
'ie 10', | ||
'ios 7', | ||
]; | ||
] | ||
|
||
const envTargets = isTest | ||
? { node: 'current' } | ||
? {node: 'current'} | ||
: isWebpack || isRollup | ||
? { browsers: browsersConfig } | ||
: { node: '4.5' }; | ||
const envOptions = { modules: false, loose: true, targets: envTargets }; | ||
? {browsers: browsersConfig} | ||
: {node: getNodeVersion(pkg)} | ||
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' }, | ||
] | ||
require.resolve('babel-plugin-module-resolver'), | ||
{root: ['./src'], alias}, | ||
] | ||
: null, | ||
[ | ||
require.resolve('babel-plugin-transform-react-remove-prop-types'), | ||
isPreact ? { removeImport: true } : { mode: 'unsafe-wrap' }, | ||
isPreact ? {removeImport: true} : {mode: 'unsafe-wrap'}, | ||
], | ||
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), | ||
}; | ||
}) | ||
|
||
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 | ||
} |
10 changes: 5 additions & 5 deletions
10
src/scripts/__tests__/__snapshots__/travis-after-success.js.snap
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
const path = require('path'); | ||
const spawn = require('cross-spawn'); | ||
const rimraf = require('rimraf'); | ||
const { | ||
hasPkgProp, fromRoot, resolveBin, hasFile, | ||
} = require('../../utils'); | ||
const path = require('path') | ||
const spawn = require('cross-spawn') | ||
const rimraf = require('rimraf') | ||
const {hasPkgProp, fromRoot, resolveBin, hasFile} = require('../../utils') | ||
|
||
const args = process.argv.slice(2); | ||
const here = p => path.join(__dirname, p); | ||
const args = process.argv.slice(2) | ||
const here = p => path.join(__dirname, p) | ||
|
||
const useBuiltinConfig = !args.includes('--presets') && !hasFile('.babelrc') && !hasPkgProp('babel'); | ||
const useBuiltinConfig = | ||
!args.includes('--presets') && !hasFile('.babelrc') && !hasPkgProp('babel') | ||
const config = useBuiltinConfig | ||
? ['--presets', here('../../config/babelrc.js')] | ||
: []; | ||
: [] | ||
|
||
const ignore = args.includes('--ignore') | ||
? [] | ||
: ['--ignore', '__tests__,__mocks__']; | ||
: ['--ignore', '__tests__,__mocks__'] | ||
|
||
const copyFiles = args.includes('--no-copy-files') ? [] : ['--copy-files']; | ||
const copyFiles = args.includes('--no-copy-files') ? [] : ['--copy-files'] | ||
|
||
const useSpecifiedOutDir = args.includes('--out-dir'); | ||
const outDir = useSpecifiedOutDir ? [] : ['--out-dir', 'dist']; | ||
const useSpecifiedOutDir = args.includes('--out-dir') | ||
const outDir = useSpecifiedOutDir ? [] : ['--out-dir', 'dist'] | ||
|
||
if (!useSpecifiedOutDir && !args.includes('--no-clean')) { | ||
rimraf.sync(fromRoot('dist')); | ||
rimraf.sync(fromRoot('dist')) | ||
} | ||
|
||
const result = spawn.sync( | ||
resolveBin('babel-cli', { executable: 'babel' }), | ||
resolveBin('@babel/cli', {executable: 'babel'}), | ||
[...outDir, ...copyFiles, ...ignore, ...config, 'src'].concat(args), | ||
{ stdio: 'inherit' }, | ||
); | ||
{stdio: 'inherit'}, | ||
) | ||
|
||
process.exit(result.status); | ||
process.exit(result.status) |
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