Skip to content

Commit c95a14e

Browse files
committed
chore: update
1 parent d8b6571 commit c95a14e

5 files changed

Lines changed: 11 additions & 19 deletions

File tree

loader/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
getModuleSystem,
1313
getRefreshModuleRuntime,
1414
normalizeOptions,
15-
RefreshGlobals,
15+
webpackGlobal,
1616
} = require('./utils');
1717
const schema = require('./options.json');
1818

@@ -46,11 +46,11 @@ function ReactRefreshLoader(source, inputSourceMap, meta) {
4646

4747
const RefreshSetupRuntimes = {
4848
cjs: Template.asString(
49-
`${RefreshGlobals}.$Refresh$.runtime = require('${RefreshRuntimePath}');`
49+
`${webpackGlobal}.$Refresh$.runtime = require('${RefreshRuntimePath}');`
5050
),
5151
esm: Template.asString([
5252
`import * as __react_refresh_runtime__ from '${RefreshRuntimePath}';`,
53-
`${RefreshGlobals}.$Refresh$.runtime = __react_refresh_runtime__;`,
53+
`${webpackGlobal}.$Refresh$.runtime = __react_refresh_runtime__;`,
5454
]),
5555
};
5656

@@ -68,7 +68,6 @@ function ReactRefreshLoader(source, inputSourceMap, meta) {
6868
const RefreshModuleRuntime = getRefreshModuleRuntime(Template, {
6969
const: options.const,
7070
moduleSystem,
71-
refreshGlobals: RefreshGlobals,
7271
});
7372

7473
if (this.sourceMap) {

loader/utils/getRefreshModuleRuntime.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
const webpackGlobal = require('./webpackGlobal');
2+
13
/**
24
* @typedef ModuleRuntimeOptions {Object}
35
* @property {boolean} const Use ES6 `const` and `let` in generated runtime code.
46
* @property {'cjs' | 'esm'} moduleSystem The module system to be used.
5-
* @property {string} refreshGlobals The global runtime function where React Refresh runtime is injected.
67
*/
78

89
/**
@@ -21,9 +22,8 @@ function getRefreshModuleRuntime(Template, options) {
2122
const constDeclaration = options.const ? 'const' : 'var';
2223
const letDeclaration = options.const ? 'let' : 'var';
2324
const webpackHot = options.moduleSystem === 'esm' ? 'import.meta.webpackHot' : 'module.hot';
24-
const refreshGlobals = options.refreshGlobals;
2525
return Template.asString([
26-
`${constDeclaration} $ReactRefreshModuleId$ = ${refreshGlobals}.$Refresh$.moduleId;`,
26+
`${constDeclaration} $ReactRefreshModuleId$ = ${webpackGlobal}.$Refresh$.moduleId;`,
2727
`${constDeclaration} $ReactRefreshCurrentExports$ = __react_refresh_utils__.getModuleExports(`,
2828
Template.indent('$ReactRefreshModuleId$'),
2929
');',

loader/utils/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ const getIdentitySourceMap = require('./getIdentitySourceMap');
22
const getModuleSystem = require('./getModuleSystem');
33
const getRefreshModuleRuntime = require('./getRefreshModuleRuntime');
44
const normalizeOptions = require('./normalizeOptions');
5-
const RefreshGlobals = require('./RefreshGlobals');
5+
const webpackGlobal = require('./webpackGlobal');
66

77
module.exports = {
88
getIdentitySourceMap,
99
getModuleSystem,
1010
getRefreshModuleRuntime,
1111
normalizeOptions,
12-
RefreshGlobals,
12+
webpackGlobal,
1313
};
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// When available, use `__webpack_global__` which is a stable runtime function to use `__webpack_require__` in this compilation
22
// See: https://github.com/webpack/webpack/issues/20139
3-
const RefreshGlobals = `(typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__)`;
3+
const webpackGlobal = `(typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__)`;
44

5-
module.exports = RefreshGlobals;
5+
module.exports = webpackGlobal;

test/loader/unit/getRefreshModuleRuntime.test.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
const { Template } = require('webpack');
2-
const {
3-
getRefreshModuleRuntime,
4-
RefreshGlobals: refreshGlobals,
5-
} = require('../../../loader/utils');
2+
const { getRefreshModuleRuntime } = require('../../../loader/utils');
63

74
describe('getRefreshModuleRuntime', () => {
85
it('should return working refresh module runtime without const using CommonJS', () => {
96
const refreshModuleRuntime = getRefreshModuleRuntime(Template, {
107
const: false,
118
moduleSystem: 'cjs',
12-
refreshGlobals,
139
});
1410

1511
expect(refreshModuleRuntime.indexOf('var')).not.toBe(-1);
@@ -55,7 +51,6 @@ describe('getRefreshModuleRuntime', () => {
5551
const refreshModuleRuntime = getRefreshModuleRuntime(Template, {
5652
const: true,
5753
moduleSystem: 'cjs',
58-
refreshGlobals,
5954
});
6055

6156
expect(refreshModuleRuntime.indexOf('var')).toBe(-1);
@@ -101,7 +96,6 @@ describe('getRefreshModuleRuntime', () => {
10196
const refreshModuleRuntime = getRefreshModuleRuntime(Template, {
10297
const: false,
10398
moduleSystem: 'esm',
104-
refreshGlobals,
10599
});
106100

107101
expect(refreshModuleRuntime.indexOf('var')).not.toBe(-1);
@@ -147,7 +141,6 @@ describe('getRefreshModuleRuntime', () => {
147141
const refreshModuleRuntime = getRefreshModuleRuntime(Template, {
148142
const: true,
149143
moduleSystem: 'esm',
150-
refreshGlobals,
151144
});
152145

153146
expect(refreshModuleRuntime.indexOf('var')).toBe(-1);

0 commit comments

Comments
 (0)