-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Unexpected properties in config are now flagged up as errors - Added basic type validation for all config properties - Config report now indicates if CLI config overrides were used - Added missing documentation for webpack.copy config - Added babel.config() - Deprecated webpack.compat.sinon - Simplified configuration of locales in webpack.compat config - Split user and plugin config code out into modules under src/config/
- Loading branch information
Showing
31 changed files
with
1,498 additions
and
780 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import util from 'util' | ||
|
||
import chalk from 'chalk' | ||
import figures from 'figures' | ||
|
||
import {pluralise as s} from '../utils' | ||
|
||
export default class UserConfigReport { | ||
constructor({configFileExists, configPath} = {}) { | ||
this.configFileExists = configFileExists | ||
this.configPath = configPath | ||
this.deprecations = [] | ||
this.errors = [] | ||
this.hints = [] | ||
this.hasArgumentOverrides = false | ||
} | ||
|
||
deprecated(path, ...messages) { | ||
this.deprecations.push({path, messages}) | ||
} | ||
|
||
error(path, value, message) { | ||
this.errors.push({path, value, message}) | ||
} | ||
|
||
hasErrors() { | ||
return this.errors.length > 0 | ||
} | ||
|
||
hasSomethingToReport() { | ||
return this.errors.length + this.deprecations.length + this.hints.length > 0 | ||
} | ||
|
||
hint(path, ...messages) { | ||
this.hints.push({path, messages}) | ||
} | ||
|
||
getConfigSource() { | ||
if (this.configFileExists) { | ||
let description = this.configPath | ||
if (this.hasArgumentOverrides) { | ||
description += ' (with CLI argument overrides)' | ||
} | ||
return description | ||
} | ||
else if (this.hasArgumentOverrides) { | ||
return 'config via CLI arguments' | ||
} | ||
return 'funsies' | ||
} | ||
|
||
getReport() { | ||
let report = [] | ||
|
||
report.push(chalk.underline(`nwb config report for ${this.getConfigSource()}`)) | ||
report.push('') | ||
|
||
if (!this.hasSomethingToReport()) { | ||
report.push(chalk.green(`${figures.tick} Nothing to report!`)) | ||
return report.join('\n') | ||
} | ||
|
||
if (this.errors.length) { | ||
let count = this.errors.length > 1 ? `${this.errors.length} ` : '' | ||
report.push(chalk.red.underline(`${count}Error${s(this.errors.length)}`)) | ||
report.push('') | ||
} | ||
this.errors.forEach(({path, value, message}) => { | ||
report.push(`${chalk.red(`${figures.cross} ${path}`)} ${chalk.cyan('=')} ${util.inspect(value)}`) | ||
report.push(` ${message}`) | ||
report.push('') | ||
}) | ||
|
||
if (this.deprecations.length) { | ||
let count = this.deprecations.length > 1 ? `${this.deprecations.length} ` : '' | ||
report.push(chalk.yellow.underline(`${count}Deprecation Warning${s(this.deprecations.length)}`)) | ||
report.push('') | ||
} | ||
this.deprecations.forEach(({path, messages}) => { | ||
report.push(chalk.yellow(`${figures.warning} ${path}`)) | ||
messages.forEach(message => { | ||
report.push(` ${message}`) | ||
}) | ||
report.push('') | ||
}) | ||
|
||
if (this.hints.length) { | ||
let count = this.hints.length > 1 ? `${this.hints.length} ` : '' | ||
report.push(chalk.cyan.underline(`${count}Hint${s(this.hints.length)}`)) | ||
report.push('') | ||
} | ||
this.hints.forEach(({path, messages}) => { | ||
report.push(chalk.cyan(`${figures.info} ${path}`)) | ||
messages.forEach(message => { | ||
report.push(` ${message}`) | ||
}) | ||
report.push('') | ||
}) | ||
|
||
return report.join('\n') | ||
} | ||
|
||
log() { | ||
console.log(this.getReport()) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import chalk from 'chalk' | ||
|
||
import {pluralise as s, typeOf} from '../utils' | ||
|
||
const BABEL_RUNTIME_OPTIONS = new Set(['helpers', 'polyfill']) | ||
|
||
export function processBabelConfig({report, userConfig}) { | ||
let { | ||
cherryPick, | ||
env, | ||
loose, | ||
plugins, | ||
presets, | ||
removePropTypes, | ||
reactConstantElements, | ||
runtime, | ||
stage, | ||
config, | ||
...unexpectedConfig | ||
} = userConfig.babel | ||
|
||
let unexpectedProps = Object.keys(unexpectedConfig) | ||
if (unexpectedProps.length > 0) { | ||
report.error( | ||
'babel', | ||
unexpectedProps.join(', '), | ||
`Unexpected prop${s(unexpectedProps.length)} in ${chalk.cyan('babel')} config - ` + | ||
'see https://github.com/insin/nwb/blob/master/docs/Configuration.md#babel-configuration for supported config' | ||
) | ||
} | ||
|
||
// cherryPick | ||
if ('cherryPick' in userConfig.babel) { | ||
if (typeOf(cherryPick) !== 'string' && typeOf(cherryPick) !== 'array') { | ||
report.error( | ||
'babel.cherryPick', | ||
cherryPick, | ||
`Must be a ${chalk.cyan('String')} or an ${chalk.cyan('Array')}` | ||
) | ||
} | ||
} | ||
|
||
// env | ||
if ('env' in userConfig.babel) { | ||
if (typeOf(env) !== 'Object') { | ||
report.error( | ||
'babel.env', | ||
env, | ||
`Must be an ${chalk.cyan('Object')}` | ||
) | ||
} | ||
} | ||
|
||
// loose | ||
if ('loose' in userConfig.babel) { | ||
if (typeOf(loose) !== 'boolean') { | ||
report.error( | ||
'babel.loose', | ||
loose, | ||
`Must be ${chalk.cyan('Boolean')}` | ||
) | ||
} | ||
} | ||
|
||
// plugins | ||
if ('plugins' in userConfig.babel) { | ||
if (typeOf(plugins) === 'string') { | ||
userConfig.babel.plugins = [plugins] | ||
} | ||
else if (typeOf(userConfig.babel.plugins) !== 'array') { | ||
report.error( | ||
'babel.plugins', | ||
plugins, | ||
`Must be a ${chalk.cyan('String')} or an ${chalk.cyan('Array')}` | ||
) | ||
} | ||
} | ||
|
||
// presets | ||
if ('presets' in userConfig.babel) { | ||
if (typeOf(presets) === 'string') { | ||
userConfig.babel.presets = [presets] | ||
} | ||
else if (typeOf(presets) !== 'array') { | ||
report.error( | ||
'babel.presets', | ||
presets, | ||
`Must be a ${chalk.cyan('String')} or an ${chalk.cyan('Array')}` | ||
) | ||
} | ||
} | ||
|
||
// removePropTypes | ||
if ('removePropTypes' in userConfig.babel) { | ||
if (removePropTypes !== false && typeOf(removePropTypes) !== 'object') { | ||
report.error( | ||
`babel.removePropTypes`, | ||
removePropTypes, | ||
`Must be ${chalk.cyan('false')} (to disable removal of PropTypes) ` + | ||
`or an ${chalk.cyan('Object')} (to configure react-remove-prop-types)` | ||
) | ||
} | ||
} | ||
|
||
// reactConstantElements | ||
if ('reactConstantElements' in userConfig.babel) { | ||
if (typeOf(reactConstantElements) !== 'boolean') { | ||
report.error( | ||
'babel.reactConstantElements', | ||
reactConstantElements, | ||
`Must be ${chalk.cyan('Boolean')}` | ||
) | ||
} | ||
} | ||
|
||
// runtime | ||
if ('runtime' in userConfig.babel && | ||
typeOf(runtime) !== 'boolean' && | ||
!BABEL_RUNTIME_OPTIONS.has(runtime)) { | ||
report.error( | ||
'babel.runtime', | ||
runtime, | ||
`Must be ${chalk.cyan('Boolean')}, ${chalk.cyan("'helpers'")} or ${chalk.cyan("'polyfill'")}` | ||
) | ||
} | ||
|
||
// stage | ||
if ('stage' in userConfig.babel) { | ||
if (typeOf(stage) === 'number') { | ||
if (stage < 0 || stage > 3) { | ||
report.error( | ||
'babel.stage', | ||
stage, | ||
`Must be between ${chalk.cyan(0)} and ${chalk.cyan(3)}` | ||
) | ||
} | ||
} | ||
else if (stage !== false) { | ||
report.error( | ||
'babel.stage', | ||
stage, | ||
`Must be a ${chalk.cyan('Number')} between ${chalk.cyan('0')} and ${chalk.cyan('3')} (to choose a stage preset), ` + | ||
`or ${chalk.cyan('false')} (to disable use of a stage preset)` | ||
) | ||
} | ||
} | ||
|
||
// config | ||
if ('config' in userConfig.babel && typeOf(config) !== 'function') { | ||
report.error( | ||
`babel.config`, | ||
`type: ${typeOf(config)}`, | ||
`Must be a ${chalk.cyan('Function')}` | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export {getPluginConfig} from './plugin' | ||
export {getProjectType, getUserConfig} from './user' | ||
export {default as UserConfigReport} from './UserConfigReport' |
Oops, something went wrong.