Skip to content

Commit c4ae573

Browse files
committed
Fix envName bug
1 parent 9273e65 commit c4ae573

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/react-refresh/src/ReactFreshBabelPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
export default function(babel, opts = {}) {
1111
if (typeof babel.getEnv === 'function') {
1212
// Only available in Babel 7.
13-
const env = babel.getEnv();
13+
const env = babel.env();
1414
if (env !== 'development' && !opts.skipEnvCheck) {
1515
throw new Error(
1616
'React Refresh Babel transform should only be enabled in development environment. ' +

packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ function transform(input, options = {}) {
1616
babel.transform(input, {
1717
babelrc: false,
1818
configFile: false,
19+
envName: options.envName,
1920
plugins: [
2021
'@babel/syntax-jsx',
2122
'@babel/syntax-dynamic-import',
2223
[
2324
freshPlugin,
2425
{
25-
skipEnvCheck: true,
26+
skipEnvCheck:
27+
options.skipEnvCheck === undefined ? true : options.skipEnvCheck,
2628
// To simplify debugging tests:
2729
emitFullSignatures: true,
2830
...options.freshOptions,
@@ -498,4 +500,19 @@ describe('ReactFreshBabelPlugin', () => {
498500
),
499501
).toMatchSnapshot();
500502
});
503+
504+
it("respects Babel's envName option", () => {
505+
const envName = 'random';
506+
expect(() =>
507+
transform(`export default function BabelEnv () { return null };`, {
508+
envName,
509+
skipEnvCheck: false,
510+
}),
511+
).toThrowError(
512+
'React Refresh Babel transform should only be enabled in development environment. ' +
513+
'Instead, the environment is: "' +
514+
envName +
515+
'". If you want to override this check, pass {skipEnvCheck: true} as plugin options.',
516+
);
517+
});
501518
});

0 commit comments

Comments
 (0)