GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support Babel's envName option in React Refresh plugin (#19009) · react/react@b7d18c4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/react-refresh/src
    • ReactFreshBabelPlugin.js
    • __tests__
      • ReactFreshBabelPlugin-test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/react-refresh/src/ReactFreshBabelPlugin.js‎

Copy file name to clipboardExpand all lines: packages/react-refresh/src/ReactFreshBabelPlugin.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
'use strict';
99

1010
export default function(babel, opts = {}) {
11-
if (typeof babel.getEnv === 'function') {
11+
if (typeof babel.env === '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. ' +
Collapse file

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

Copy file name to clipboardExpand all lines: packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js
+18-1Lines 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,
@@ -507,4 +509,19 @@ describe('ReactFreshBabelPlugin', () => {
507509
),
508510
).toMatchSnapshot();
509511
});
512+
513+
it("respects Babel's envName option", () => {
514+
const envName = 'random';
515+
expect(() =>
516+
transform(`export default function BabelEnv () { return null };`, {
517+
envName,
518+
skipEnvCheck: false,
519+
}),
520+
).toThrowError(
521+
'React Refresh Babel transform should only be enabled in development environment. ' +
522+
'Instead, the environment is: "' +
523+
envName +
524+
'". If you want to override this check, pass {skipEnvCheck: true} as plugin options.',
525+
);
526+
});
510527
});

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.