Skip to content

Commit 6815c62

Browse files
authored
chore: update references from webpack to Rspack (#97)
1 parent c22c6f3 commit 6815c62

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

client/reactRefresh.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import {
44
} from 'react-refresh/runtime';
55
import { executeRuntime, getModuleExports } from './refreshUtils.js';
66

7-
function refresh(moduleId, webpackHot) {
7+
function refresh(moduleId, hot) {
88
const currentExports = getModuleExports(moduleId);
99
const fn = (exports) => {
1010
var testMode;
1111
if (typeof __react_refresh_test__ !== 'undefined') {
1212
testMode = __react_refresh_test__;
1313
}
14-
executeRuntime(exports, moduleId, webpackHot, testMode);
14+
executeRuntime(exports, moduleId, hot, testMode);
1515
};
1616
if (typeof Promise !== 'undefined' && currentExports instanceof Promise) {
1717
currentExports.then(fn);

client/refreshUtils.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
} from 'react-refresh/runtime';
88

99
/**
10-
* Extracts exports from a webpack module object.
11-
* @param {string} moduleId A Webpack module ID.
10+
* Extracts exports from a Rspack module object.
11+
* @param {string} moduleId An Rspack module ID.
1212
* @returns {*} An exports object from the module.
1313
*/
1414
function getModuleExports(moduleId) {
@@ -45,7 +45,7 @@ function getModuleExports(moduleId) {
4545
* If this signature changes, it's unsafe to accept the boundary.
4646
*
4747
* This implementation is based on the one in [Metro](https://github.com/facebook/metro/blob/907d6af22ac6ebe58572be418e9253a90665ecbd/packages/metro/src/lib/polyfills/require.js#L795-L816).
48-
* @param {*} moduleExports A Webpack module exports object.
48+
* @param {*} moduleExports An Rspack module exports object.
4949
* @returns {string[]} A React refresh boundary signature array.
5050
*/
5151
function getReactRefreshBoundarySignature(moduleExports) {
@@ -104,7 +104,7 @@ function createDebounceUpdate() {
104104
* Checks if all exports are likely a React component.
105105
*
106106
* This implementation is based on the one in [Metro](https://github.com/facebook/metro/blob/febdba2383113c88296c61e28e4ef6a7f4939fda/packages/metro/src/lib/polyfills/require.js#L748-L774).
107-
* @param {*} moduleExports A Webpack module exports object.
107+
* @param {*} moduleExports An Rspack module exports object.
108108
* @returns {boolean} Whether the exports are React component like.
109109
*/
110110
function isReactRefreshBoundary(moduleExports) {
@@ -131,7 +131,7 @@ function isReactRefreshBoundary(moduleExports) {
131131
}
132132

133133
// We can (and have to) safely execute getters here,
134-
// as Webpack manually assigns harmony exports to getters,
134+
// as Rspack/webpack manually assigns ESM exports to getters,
135135
// without any side-effects attached.
136136
// Ref: https://github.com/webpack/webpack/blob/b93048643fe74de2a6931755911da1212df55897/lib/MainTemplate.js#L281
137137
var exportValue = moduleExports[key];
@@ -147,8 +147,8 @@ function isReactRefreshBoundary(moduleExports) {
147147
* Checks if exports are likely a React component and registers them.
148148
*
149149
* This implementation is based on the one in [Metro](https://github.com/facebook/metro/blob/febdba2383113c88296c61e28e4ef6a7f4939fda/packages/metro/src/lib/polyfills/require.js#L818-L835).
150-
* @param {*} moduleExports A Webpack module exports object.
151-
* @param {string} moduleId A Webpack module ID.
150+
* @param {*} moduleExports An Rspack module exports object.
151+
* @param {string} moduleId An Rspack module ID.
152152
* @returns {void}
153153
*/
154154
function registerExportsForReactRefresh(moduleExports, moduleId) {
@@ -184,8 +184,8 @@ function registerExportsForReactRefresh(moduleExports, moduleId) {
184184
* Compares previous and next module objects to check for mutated boundaries.
185185
*
186186
* This implementation is based on the one in [Metro](https://github.com/facebook/metro/blob/907d6af22ac6ebe58572be418e9253a90665ecbd/packages/metro/src/lib/polyfills/require.js#L776-L792).
187-
* @param {*} prevExports The current Webpack module exports object.
188-
* @param {*} nextExports The next Webpack module exports object.
187+
* @param {*} prevExports The current Rspack module exports object.
188+
* @param {*} nextExports The next Rspack module exports object.
189189
* @returns {boolean} Whether the React refresh boundary should be invalidated.
190190
*/
191191
function shouldInvalidateReactRefreshBoundary(prevExports, nextExports) {
@@ -207,30 +207,30 @@ function shouldInvalidateReactRefreshBoundary(prevExports, nextExports) {
207207

208208
var enqueueUpdate = createDebounceUpdate();
209209

210-
function executeRuntime(moduleExports, moduleId, webpackHot, isTest) {
210+
function executeRuntime(moduleExports, moduleId, hot, isTest) {
211211
registerExportsForReactRefresh(moduleExports, moduleId);
212212

213-
if (webpackHot) {
214-
var isHotUpdate = !!webpackHot.data;
213+
if (hot) {
214+
var isHotUpdate = !!hot.data;
215215
var prevExports;
216216
if (isHotUpdate) {
217-
prevExports = webpackHot.data.prevExports;
217+
prevExports = hot.data.prevExports;
218218
}
219219

220220
if (isReactRefreshBoundary(moduleExports)) {
221-
webpackHot.dispose(
221+
hot.dispose(
222222
/**
223223
* A callback to performs a full refresh if React has unrecoverable errors,
224224
* and also caches the to-be-disposed module.
225-
* @param {*} data A hot module data object from Webpack HMR.
225+
* @param {*} data A hot module data object from Rspack HMR.
226226
* @returns {void}
227227
*/
228228
function hotDisposeCallback(data) {
229229
// We have to mutate the data object to get data registered and cached
230230
data.prevExports = moduleExports;
231231
},
232232
);
233-
webpackHot.accept(
233+
hot.accept(
234234
/**
235235
* An error handler to allow self-recovering behaviours.
236236
* @param {Error} error An error occurred during evaluation of a module.
@@ -261,14 +261,14 @@ function executeRuntime(moduleExports, moduleId, webpackHot, isTest) {
261261
isReactRefreshBoundary(prevExports) &&
262262
shouldInvalidateReactRefreshBoundary(prevExports, moduleExports)
263263
) {
264-
webpackHot.invalidate();
264+
hot.invalidate();
265265
} else {
266266
enqueueUpdate();
267267
}
268268
}
269269
} else {
270270
if (isHotUpdate && typeof prevExports !== 'undefined') {
271-
webpackHot.invalidate();
271+
hot.invalidate();
272272
}
273273
}
274274
}

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class ReactRefreshRspackPlugin {
2828

2929
apply(compiler: Compiler) {
3030
if (
31-
// Webpack do not set process.env.NODE_ENV, so we need to check for mode.
32-
// Ref: https://github.com/webpack/webpack/issues/7074
3331
(compiler.options.mode !== 'development' ||
3432
// We also check for production process.env.NODE_ENV,
3533
// in case it was set and mode is non-development (e.g. 'none')

test/test.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const compileWithReactRefresh = (
6565
splitChunks: {
6666
cacheGroups: {
6767
reactRefresh: {
68-
test: /[\\/](react-refresh|rspack-plugin-react-refresh\/client|react-refresh-webpack-plugin)[\\/]/,
68+
test: /[\\/](react-refresh|rspack-plugin-react-refresh\/client)[\\/]/,
6969
name: 'react-refresh',
7070
chunks: 'all',
7171
priority: -1000,

0 commit comments

Comments
 (0)