From 99dd9755f65752401d3d7b30bd5d4e9ce60ef0e0 Mon Sep 17 00:00:00 2001 From: Eli Perelman <eli@eliperelman.com> Date: Wed, 22 Aug 2018 20:54:05 -0500 Subject: [PATCH] Throw when specifying env property in middleware --- packages/neutrino/Neutrino.js | 3 +++ packages/neutrino/test/api_test.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/neutrino/Neutrino.js b/packages/neutrino/Neutrino.js index c975a9244..7b3cbd28e 100644 --- a/packages/neutrino/Neutrino.js +++ b/packages/neutrino/Neutrino.js @@ -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. diff --git a/packages/neutrino/test/api_test.js b/packages/neutrino/test/api_test.js index 1bf225aea..17af60214 100644 --- a/packages/neutrino/test/api_test.js +++ b/packages/neutrino/test/api_test.js @@ -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();