From b260bef398c4da465a41f6b95bc0cf64deafdfd7 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 6 Sep 2019 20:30:16 +0100 Subject: [PATCH] [Fresh] Add skipEnvCheck option to Babel plugin (#16688) --- packages/react-refresh/src/ReactFreshBabelPlugin.js | 6 +++--- .../src/__tests__/ReactFreshBabelPlugin-test.js | 2 +- .../src/__tests__/ReactFreshIntegration-test.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/react-refresh/src/ReactFreshBabelPlugin.js b/packages/react-refresh/src/ReactFreshBabelPlugin.js index b8474af1a0be6..ff41422ca8120 100644 --- a/packages/react-refresh/src/ReactFreshBabelPlugin.js +++ b/packages/react-refresh/src/ReactFreshBabelPlugin.js @@ -7,16 +7,16 @@ 'use strict'; -export default function(babel) { +export default function(babel, opts) { if (typeof babel.getEnv === 'function') { // Only available in Babel 7. const env = babel.getEnv(); - if (env !== 'development' && typeof expect !== 'function') { + if (env !== 'development' && !opts.skipEnvCheck) { throw new Error( 'React Refresh Babel transform should only be enabled in development environment. ' + 'Instead, the environment is: "' + env + - '".', + '". If you want to override this check, pass {skipEnvCheck: true} as plugin options.', ); } } diff --git a/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js b/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js index 2f47f1491b021..7544d4eea7a2b 100644 --- a/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js +++ b/packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js @@ -19,7 +19,7 @@ function transform(input, options = {}) { plugins: [ '@babel/syntax-jsx', '@babel/syntax-dynamic-import', - freshPlugin, + [freshPlugin, {skipEnvCheck: true}], ...(options.plugins || []), ], }).code, diff --git a/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js b/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js index 018c1d17955c9..4d1e5bf85c9be 100644 --- a/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js +++ b/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js @@ -60,7 +60,7 @@ describe('ReactFreshIntegration', () => { babelrc: false, presets: ['@babel/react'], plugins: [ - freshPlugin, + [freshPlugin, {skipEnvCheck: true}], '@babel/plugin-transform-modules-commonjs', compileDestructuring && '@babel/plugin-transform-destructuring', ].filter(Boolean),