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 #6 from inthepocket/feature/default-prettier-rules
feat(prettierrc): change to itp prettier rules
- Loading branch information
Showing
23 changed files
with
186 additions
and
278 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
{ | ||
"printWidth": 80, | ||
"printWidth": 100, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": false, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"bracketSpacing": false, | ||
"jsxBracketSameLine": false | ||
} | ||
} |
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
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
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,78 +1,63 @@ | ||
const browserslist = require('browserslist') | ||
const semver = require('semver') | ||
const browserslist = require('browserslist'); | ||
const semver = require('semver'); | ||
|
||
const {ifAnyDep, parseEnv, appDirectory, pkg} = 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}) || [ | ||
'ie 10', | ||
'ios 7', | ||
] | ||
const browsersConfig = browserslist.loadConfig({ path: appDirectory }) || ['ie 10', 'ios 7']; | ||
|
||
const envTargets = isTest | ||
? {node: 'current'} | ||
? { node: 'current' } | ||
: isWebpack || isRollup | ||
? {browsers: browsersConfig} | ||
: {node: getNodeVersion(pkg)} | ||
const envOptions = {modules: false, loose: true, targets: envTargets} | ||
? { browsers: browsersConfig } | ||
: { node: getNodeVersion(pkg) }; | ||
const envOptions = { modules: false, loose: true, targets: envTargets }; | ||
|
||
module.exports = () => ({ | ||
presets: [ | ||
[require.resolve('@babel/preset-env'), envOptions], | ||
ifAnyDep( | ||
['react', 'preact'], | ||
[ | ||
require.resolve('@babel/preset-react'), | ||
{pragma: isPreact ? 'React.h' : undefined}, | ||
], | ||
[require.resolve('@babel/preset-react'), { pragma: isPreact ? 'React.h' : undefined }], | ||
), | ||
].filter(Boolean), | ||
plugins: [ | ||
require.resolve('babel-plugin-macros'), | ||
alias | ||
? [ | ||
require.resolve('babel-plugin-module-resolver'), | ||
{root: ['./src'], alias}, | ||
] | ||
: null, | ||
alias ? [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, | ||
[require.resolve('@babel/plugin-proposal-class-properties'), {loose: true}], | ||
isUMD ? require.resolve('babel-plugin-transform-inline-environment-variables') : null, | ||
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: true }], | ||
require.resolve('babel-plugin-minify-dead-code-elimination'), | ||
treeshake | ||
? null | ||
: require.resolve('@babel/plugin-transform-modules-commonjs'), | ||
treeshake ? null : require.resolve('@babel/plugin-transform-modules-commonjs'), | ||
].filter(Boolean), | ||
}) | ||
}); | ||
|
||
function getNodeVersion({engines: {node: nodeVersion = '8'} = {}}) { | ||
function getNodeVersion({ engines: { node: nodeVersion = '8' } = {} }) { | ||
const oldestVersion = semver | ||
.validRange(nodeVersion) | ||
.replace(/[>=<|]/g, ' ') | ||
.split(' ') | ||
.filter(Boolean) | ||
.sort(semver.compare)[0] | ||
.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 | ||
return oldestVersion; | ||
} |
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
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
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
Oops, something went wrong.