Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Use spread properties instead of Object.assign()/deepmerge #859

Merged
merged 3 commits into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/creating-presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ _Example:_

```js
module.exports = (neutrino, opts = {}) => {
const options = Object.assign({
const options = {
quiet: false,
logLevel: 'warn'
}, opts);
logLevel: 'warn',
...opts
};

// ...
};
Expand Down
3 changes: 2 additions & 1 deletion docs/packages/airbnb-base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ module.exports = {
(neutrino) => neutrino.config.module
.rule('lint')
.use('eslint')
.tap(options => Object.assign({}, options, {
.tap(options => ({
...options,
rules: {
semi: 'off'
}
Expand Down
3 changes: 2 additions & 1 deletion docs/packages/airbnb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ module.exports = {
(neutrino) => neutrino.config.module
.rule('lint')
.use('eslint')
.tap(options => Object.assign({}, options, {
.tap(options => ({
...options,
rules: {
semi: 'off'
}
Expand Down
3 changes: 2 additions & 1 deletion docs/packages/standardjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ module.exports = {
(neutrino) => neutrino.config.module
.rule('lint')
.use('eslint')
.tap(options => Object.assign({}, options, {
.tap(options => ({
...options,
rules: {
semi: 'error'
}
Expand Down
3 changes: 2 additions & 1 deletion packages/airbnb-base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ module.exports = {
(neutrino) => neutrino.config.module
.rule('lint')
.use('eslint')
.tap(options => Object.assign({}, options, {
.tap(options => ({
...options,
rules: {
semi: 'off'
}
Expand Down
3 changes: 2 additions & 1 deletion packages/airbnb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ module.exports = {
(neutrino) => neutrino.config.module
.rule('lint')
.use('eslint')
.tap(options => Object.assign({}, options, {
.tap(options => ({
...options,
rules: {
semi: 'off'
}
Expand Down
16 changes: 7 additions & 9 deletions packages/banner/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const { BannerPlugin } = require('webpack');
const merge = require('deepmerge');

module.exports = (neutrino, options = {}) => {
neutrino.config
.plugin(options.pluginId || 'banner')
.use(BannerPlugin, [
merge({
banner: 'require(\'source-map-support\').install();',
test: neutrino.regexFromExtensions(),
raw: true,
entryOnly: true
}, options)
]);
.use(BannerPlugin, [{
banner: 'require(\'source-map-support\').install();',
test: neutrino.regexFromExtensions(),
raw: true,
entryOnly: true,
...options
}]);
};
1 change: 0 additions & 1 deletion packages/banner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"yarn": ">=1.2.1"
},
"dependencies": {
"deepmerge": "^1.5.2",
"webpack": "^4.7.0"
},
"peerDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/clean/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const CleanPlugin = require('clean-webpack-plugin');
const merge = require('deepmerge');

module.exports = (neutrino, opts = {}) => {
const options = merge({
const options = {
pluginId: 'clean',
paths: [],
root: neutrino.options.root,
verbose: neutrino.options.debug
}, opts);
verbose: neutrino.options.debug,
...opts
};
const { paths, pluginId } = options;

delete options.paths;
Expand Down
3 changes: 1 addition & 2 deletions packages/clean/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"yarn": ">=1.2.1"
},
"dependencies": {
"clean-webpack-plugin": "^0.1.19",
"deepmerge": "^1.5.2"
"clean-webpack-plugin": "^0.1.19"
},
"peerDependencies": {
"neutrino": "^8.0.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/compile-loader/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const merge = require('deepmerge');
const babelMerge = require('babel-merge');

module.exports = (neutrino, options = {}) => neutrino.config.module
Expand All @@ -8,9 +7,10 @@ module.exports = (neutrino, options = {}) => neutrino.config.module
.when(options.exclude, rule => rule.exclude.merge(options.exclude))
.use(options.useId || 'babel')
.loader(require.resolve('babel-loader'))
.options(merge({
.options({
cacheDirectory: true,
babelrc: false
}, options.babel || {}));
babelrc: false,
...(options.babel || {})
});

module.exports.merge = babelMerge;
1 change: 0 additions & 1 deletion packages/compile-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@babel/core": "^7.0.0-beta.46",
"babel-loader": "^8.0.0-beta.2",
"babel-merge": "^1.1.1",
"deepmerge": "^1.5.2",
"webpack": "^4.7.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-project/commands/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module.exports = class Project extends Generator {

const jsonPath = join(this.options.directory, 'package.json');
const json = readJsonSync(jsonPath);
const packageJson = Object.assign(json, { scripts });
const packageJson = { ...json, scripts };

writeJsonSync(jsonPath, packageJson, { spaces: 2 });
this.log(` ${chalk.green('create')} ${join(basename(this.options.directory), 'package.json')}`);
Expand Down
18 changes: 8 additions & 10 deletions packages/jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ module.exports = (neutrino, opts = {}) => {
.argv;
const configFile = join(tmpdir(), 'config.json');
const options = normalizeJestOptions(opts, neutrino, usingBabel);
const cliOptions = Object.assign(
jestArgs,
{
// Jest is looking for Array of files in `argv._`. Providing them
_: jestArgs.files,
config: configFile,
coverage: args.coverage,
watch: args.watch
}
);
const cliOptions = {
...jestArgs,
// Jest is looking for Array of files in `argv._`. Providing them
_: jestArgs.files,
config: configFile,
coverage: args.coverage,
watch: args.watch
};

writeFileSync(configFile, `${JSON.stringify(options, null, 2)}\n`);

Expand Down
1 change: 0 additions & 1 deletion packages/mocha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@babel/register": "^7.0.0-beta.46",
"@neutrinojs/loader-merge": "^8.2.0",
"change-case": "^3.0.2",
"deepmerge": "^1.5.2",
"mocha": "^5.1.1",
"ramda": "^0.25.0"
},
Expand Down
13 changes: 7 additions & 6 deletions packages/mocha/src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const mocha = require('./mocha');
const merge = require('deepmerge');
const { omit } = require('ramda');
const loaderMerge = require('@neutrinojs/loader-merge');

module.exports = (neutrino, opts = {}) => {
neutrino.on('test', ({ files }) => {
const usingBabel = neutrino.config.module.rules.has('compile');
const options = merge.all([
{ reporter: 'spec', ui: 'tdd', bail: true },
opts,
files && files.length ? { recursive: true } : {}
]);
const options = {
reporter: 'spec',
ui: 'tdd',
bail: true,
...opts,
...(files && files.length ? { recursive: true } : {})
};

neutrino.config.when(usingBabel, () => {
neutrino.use(loaderMerge('compile', 'babel'), {
Expand Down
8 changes: 4 additions & 4 deletions packages/neutrino/bin/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const merge = require('deepmerge');
const ora = require('ora');
const { build } = require('../src');
const base = require('./base');
Expand Down Expand Up @@ -32,12 +31,13 @@ module.exports = (middleware, args, cli) => {
spinner.succeed('Building project completed');

if (stats) {
console.log(stats.toString(merge({
console.log(stats.toString({
modules: false,
colors: true,
chunks: false,
children: false
}, stats.compilation.compiler.options.stats || {})));
children: false,
...(stats.compilation.compiler.options.stats || {})
}));
}
}
});
Expand Down
12 changes: 4 additions & 8 deletions packages/preact/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ const compileLoader = require('@neutrinojs/compile-loader');
const loaderMerge = require('@neutrinojs/loader-merge');
const web = require('@neutrinojs/web');
const { join } = require('path');
const merge = require('deepmerge');

const MODULES = join(__dirname, 'node_modules');

module.exports = (neutrino, opts = {}) => {
const options = merge({
const options = {
hot: true,
babel: {}
}, opts);

Object.assign(options, {
...opts,
babel: compileLoader.merge({
plugins: [
[require.resolve('@babel/plugin-transform-react-jsx'), { pragma: 'h' }],
// Using loose for the reasons here:
// https://github.com/facebook/create-react-app/issues/4263
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: true }]
]
}, options.babel)
});
}, opts.babel || {})
};

neutrino.use(web, options);

Expand Down
1 change: 0 additions & 1 deletion packages/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@neutrinojs/compile-loader": "^8.2.0",
"@neutrinojs/loader-merge": "^8.2.0",
"@neutrinojs/web": "^8.2.0",
"deepmerge": "^1.5.2",
"eslint": "^4.19.1",
"eslint-plugin-react": "^7.7.0"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/standardjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ module.exports = {
(neutrino) => neutrino.config.module
.rule('lint')
.use('eslint')
.tap(options => Object.assign({}, options, {
.tap(options => ({
...options,
rules: {
semi: 'error'
}
Expand Down
11 changes: 4 additions & 7 deletions packages/style-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,10 @@ module.exports = (neutrino, opts = {}) => {
},
...options.loaders
]
.map((loader, index) => {
const obj = typeof loader === 'object' ? loader : { loader };

return Object.assign(obj, {
useId: obj.useId || `${options.cssUseId}-${index}`
});
});
.map((loader, index) => ({
useId: `${options.cssUseId}-${index}`,
...(typeof loader === 'object' ? loader : { loader })
}));

loaders.forEach(loader => {
styleRule
Expand Down
8 changes: 4 additions & 4 deletions packages/style-minify/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const merge = require('deepmerge');
const OptimizeCssPlugin = require('optimize-css-assets-webpack-plugin');

module.exports = ({ config }, opts = {}) => {
const options = merge({
const options = {
pluginId: 'optimize-css',
plugin: {}
}, opts);
plugin: {},
...opts
};

config
.plugin(options.pluginId)
Expand Down
1 change: 0 additions & 1 deletion packages/style-minify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"yarn": ">=1.2.1"
},
"dependencies": {
"deepmerge": "^1.5.2",
"optimize-css-assets-webpack-plugin": "^4.0.1",
"webpack": "^4.7.0"
},
Expand Down
7 changes: 4 additions & 3 deletions packages/stylelint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ const StylelintPlugin = require('stylelint-webpack-plugin');
const { lint, formatters } = require('stylelint');

module.exports = (neutrino, opts = {}) => {
const options = merge({
const options = {
pluginId: 'stylelint',
configBasedir: neutrino.options.root,
files: '**/*.+(css|scss|sass|less)',
context: neutrino.options.source,
formatter: formatters.string
}, opts);
formatter: formatters.string,
...opts
};

const getStylelintRcConfig = config => config
.plugin(options.pluginId)
Expand Down