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

Commit

Permalink
Switch to ConfigurationError
Browse files Browse the repository at this point in the history
  • Loading branch information
edmorley committed Oct 12, 2018
1 parent 984639a commit 00809b4
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
6 changes: 4 additions & 2 deletions packages/eslint/index.js
@@ -1,7 +1,7 @@
const deepmerge = require('deepmerge');
const clone = require('lodash.clonedeep');
const omit = require('lodash.omit');
const { DuplicateRuleError } = require('neutrino/errors');
const { ConfigurationError, DuplicateRuleError } = require('neutrino/errors');

const merge = (source, destination) => {
const sourceRules = (source && source.eslint && source.eslint.rules) || {};
Expand Down Expand Up @@ -78,7 +78,9 @@ const eslintrc = (neutrino) => {

module.exports = (neutrino, opts = {}) => {
if (neutrino.config.module.rules.has('compile')) {
throw new Error('Lint presets must be defined prior to any other presets in .neutrinorc.js.');
throw new ConfigurationError(
'Lint presets must be defined prior to any other presets in .neutrinorc.js.'
);
}

if (neutrino.config.module.rules.has('lint')) {
Expand Down
3 changes: 2 additions & 1 deletion packages/html-template/index.js
@@ -1,8 +1,9 @@
const { resolve } = require('path');
const { ConfigurationError } = require('neutrino/errors');

module.exports = (neutrino, { pluginId = 'html', ...options } = {}) => {
if ('links' in options && !('template' in options)) {
throw new Error(
throw new ConfigurationError(
'The default Neutrino HTML template no longer supports the "links" option. ' +
'To set a favicon use the "favicon" option instead. For stylesheets either ' +
'import the equivalent npm package from JS, or if using a CDN is preferred, ' +
Expand Down
9 changes: 7 additions & 2 deletions packages/library/index.js
Expand Up @@ -4,14 +4,19 @@ const clean = require('@neutrinojs/clean');
const loaderMerge = require('@neutrinojs/loader-merge');
const merge = require('deepmerge');
const nodeExternals = require('webpack-node-externals');
const { ConfigurationError } = require('neutrino/errors');

module.exports = (neutrino, opts = {}) => {
if (!opts.name) {
throw new Error('Missing required preset option "name". You must specify a library name when using this preset.');
throw new ConfigurationError(
'Missing required preset option "name". You must specify a library name when using this preset.'
);
}

if ('polyfills' in opts) {
throw new Error('The polyfills option has been removed, since polyfills are no longer included by default.');
throw new ConfigurationError(
'The polyfills option has been removed, since polyfills are no longer included by default.'
);
}

const options = merge({
Expand Down
9 changes: 7 additions & 2 deletions packages/neutrino/Neutrino.js
Expand Up @@ -3,6 +3,7 @@ const Config = require('webpack-chain');
const isPlainObject = require('is-plain-object');
const merge = require('deepmerge');
const { isAbsolute, join } = require('path');
const { ConfigurationError } = require('./errors');
const { source } = require('./extensions');

const getRoot = ({ root }) => root;
Expand Down Expand Up @@ -134,7 +135,9 @@ module.exports = class Neutrino {
});

if ('node_modules' in options) {
throw new Error('options.node_modules has been removed. Use `neutrino.config.resolve.modules` instead.');
throw new ConfigurationError(
'options.node_modules has been removed. Use `neutrino.config.resolve.modules` instead.'
);
}

return options;
Expand Down Expand Up @@ -217,7 +220,9 @@ module.exports = class Neutrino {
this.use(...middleware);
} else if (isPlainObject(middleware)) {
if ('env' in middleware) {
throw new Error('Using "env" in middleware has been removed. Apply middleware conditionally instead.');
throw new ConfigurationError(
'Using "env" in middleware has been removed. Apply middleware conditionally instead.'
);
}
// If middleware is an object, it could contain other middleware in
// its "use" property. Run every item in "use" prop back through .use(),
Expand Down
6 changes: 4 additions & 2 deletions packages/neutrino/handlers.js
@@ -1,6 +1,8 @@
const { ConfigurationError } = require('./errors');

const webpack = (neutrino) => {
if (neutrino.config.entryPoints.has('vendor')) {
throw new Error(
throw new ConfigurationError(
'Vendor chunks are now automatically generated. ' +
'Remove the manual `vendor` entrypoint.'
);
Expand All @@ -22,7 +24,7 @@ const webpack = (neutrino) => {
// disable source maps in terser-webpack-plugin, then they can unset `sourceMap` rather
// than setting it to `false`.
if (usingSourcemap && minimizer && (minimizer.get('args')[0] || {}).sourceMap === false) {
throw new Error(
throw new ConfigurationError(
`neutrino.config.devtool is set to '${devtool}', however terser-webpack-plugin ` +
'has not been correctly configured to allow source maps. ' +
'This can happen if the devtool is configured manually outside of the preset. ' +
Expand Down
5 changes: 4 additions & 1 deletion packages/node/index.js
Expand Up @@ -8,6 +8,7 @@ const {
} = require('path');
const merge = require('deepmerge');
const omit = require('lodash.omit');
const { ConfigurationError } = require('neutrino/errors');

const getOutputForEntry = entry => basename(
format(
Expand All @@ -20,7 +21,9 @@ const getOutputForEntry = entry => basename(

module.exports = (neutrino, opts = {}) => {
if ('polyfills' in opts) {
throw new Error('The polyfills option has been removed, since polyfills are no longer included by default.');
throw new ConfigurationError(
'The polyfills option has been removed, since polyfills are no longer included by default.'
);
}

const pkg = neutrino.options.packageJson;
Expand Down
29 changes: 19 additions & 10 deletions packages/web/index.js
Expand Up @@ -9,14 +9,15 @@ const loaderMerge = require('@neutrinojs/loader-merge');
const devServer = require('@neutrinojs/dev-server');
const { resolve } = require('url');
const merge = require('deepmerge');
const { ConfigurationError } = require('neutrino/errors');

module.exports = (neutrino, opts = {}) => {
if (neutrino.config.module.rules.has('compile')) {
throw new Error(
'@neutrinojs/web is being used when a `compile` rule already exists,\n' +
'which would cause the existing configuration to be overwritten.\n' +
'If you are including this preset manually to customise options configured\n' +
"by another preset, instead use that preset's own options to do so."
throw new ConfigurationError(
'@neutrinojs/web is being used when a `compile` rule already exists, ' +
'which would overwrite the existing configuration. If you are including ' +
'this preset manually to customise rules configured by another preset, ' +
"instead use that preset's own options to do so."
);
}

Expand Down Expand Up @@ -54,23 +55,31 @@ module.exports = (neutrino, opts = {}) => {
}, opts);

if ('babel' in options.minify) {
throw new Error('The minify.babel option has been removed. See the web preset docs for how to customise source minification.');
throw new ConfigurationError(
'The minify.babel option has been removed. See the web preset docs for how to customise source minification.'
);
}

if ('image' in options.minify) {
throw new Error('The minify.image option has been removed. See: https://github.com/neutrinojs/neutrino/issues/1104');
throw new ConfigurationError(
'The minify.image option has been removed. See: https://github.com/neutrinojs/neutrino/issues/1104'
);
}

if ('style' in options.minify) {
throw new Error('The minify.style option has been removed. To enable style minification use the @neutrinojs/style-minify preset.');
throw new ConfigurationError(
'The minify.style option has been removed. To enable style minification use the @neutrinojs/style-minify preset.'
);
}

if ('polyfills' in options) {
throw new Error('The polyfills option has been removed, since polyfills are no longer included by default.');
throw new ConfigurationError(
'The polyfills option has been removed, since polyfills are no longer included by default.'
);
}

if ('hotEntries' in options) {
throw new Error(
throw new ConfigurationError(
'The hotEntries option has been removed. See the "neutrino.options.mains" ' +
'docs for how to add custom hot entries to your bundle without importing.'
);
Expand Down
5 changes: 4 additions & 1 deletion packages/web/test/web_test.js
Expand Up @@ -246,7 +246,10 @@ test('supports multiple mains with custom html-webpack-plugin options', t => {
test('throws when used twice', t => {
const api = new Neutrino();
api.use(mw());
t.throws(() => api.use(mw()), /a `compile` rule already exists/);
t.throws(
() => api.use(mw()),
/@neutrinojs\/web is being used when a `compile` rule already exists/
);
});

test('throws when minify.babel defined', t => {
Expand Down

0 comments on commit 00809b4

Please sign in to comment.