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

Throw when specifying env property in middleware #1038

Merged
merged 1 commit into from
Aug 23, 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
3 changes: 3 additions & 0 deletions packages/neutrino/Neutrino.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ module.exports = class Neutrino {
// middleware type and options
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.');
}
// If middleware is an object, it could contain other middleware in
// its "use" property. Run every item in "use" prop back through .use(),
// plus set any options.
Expand Down
18 changes: 18 additions & 0 deletions packages/neutrino/test/api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ test('throws when legacy options.node_modules is set', t => {
t.throws(() => api.use({ options }), /options\.node_modules has been removed/);
});

test('throws when middleware "env" is set', t => {
const api = new Neutrino();
const middleware = {
env: {
NODE_ENV: {
production: neutrino => {
neutrino.config.devtool('alpha');
}
}
}
};

api.config.devtool('beta');

t.throws(() => api.use(middleware), /"env" in middleware has been removed/);
t.is(api.config.get('devtool'), 'beta');
});

test('options.mains', t => {
const api = new Neutrino();

Expand Down