@rspack/plugin-react-refresh 1.6.2 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -57
- package/client/reactRefresh.js +16 -28
- package/client/reactRefreshEntry.js +11 -12
- package/client/refreshUtils.js +116 -133
- package/dist/index.d.ts +1 -6
- package/dist/index.js +10 -176
- package/dist/options.d.ts +3 -20
- package/package.json +24 -40
- package/client/errorOverlayEntry.js +0 -101
- package/client/overlay/components/CompileErrorTrace.js +0 -68
- package/client/overlay/components/PageHeader.js +0 -60
- package/client/overlay/components/RuntimeErrorFooter.js +0 -93
- package/client/overlay/components/RuntimeErrorHeader.js +0 -38
- package/client/overlay/components/RuntimeErrorStack.js +0 -80
- package/client/overlay/components/Spacer.js +0 -19
- package/client/overlay/containers/CompileErrorContainer.js +0 -25
- package/client/overlay/containers/RuntimeErrorContainer.js +0 -29
- package/client/overlay/index.js +0 -351
- package/client/overlay/theme.js +0 -39
- package/client/overlay/utils.js +0 -74
- package/client/utils/ansi-html.js +0 -300
- package/client/utils/errorEventHandlers.js +0 -102
- package/client/utils/formatWebpackErrors.js +0 -106
- package/client/utils/retry.js +0 -23
- package/dist/sockets/WDSSocket.d.ts +0 -13
- package/dist/sockets/WDSSocket.js +0 -63
- package/dist/sockets/WHMEventSource.d.ts +0 -26
- package/dist/sockets/WHMEventSource.js +0 -52
- package/dist/sockets/utils/getCurrentScriptSource.d.ts +0 -1
- package/dist/sockets/utils/getCurrentScriptSource.js +0 -45
- package/dist/sockets/utils/getSocketUrlParts.d.ts +0 -9
- package/dist/sockets/utils/getSocketUrlParts.js +0 -87
- package/dist/sockets/utils/getUrlFromParts.d.ts +0 -9
- package/dist/sockets/utils/getUrlFromParts.js +0 -49
- package/dist/sockets/utils/getWDSMetadata.d.ts +0 -16
- package/dist/sockets/utils/getWDSMetadata.js +0 -45
- package/dist/utils/getAdditionalEntries.d.ts +0 -9
- package/dist/utils/getIntegrationEntry.d.ts +0 -7
- package/dist/utils/getSocketIntegration.d.ts +0 -2
- package/exports/index.cjs +0 -7
- package/exports/index.d.cts +0 -3
- package/exports/index.d.mts +0 -5
- package/exports/index.mjs +0 -11
package/dist/index.js
CHANGED
|
@@ -1,82 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: definition[key]
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
})();
|
|
20
|
-
(()=>{
|
|
21
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
-
})();
|
|
23
|
-
(()=>{
|
|
24
|
-
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
-
value: 'Module'
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
-
value: true
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __webpack_exports__ = {};
|
|
34
|
-
__webpack_require__.r(__webpack_exports__);
|
|
35
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
ReactRefreshRspackPlugin: ()=>ReactRefreshRspackPlugin,
|
|
37
|
-
default: ()=>src
|
|
38
|
-
});
|
|
39
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
40
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
41
3
|
const d = (object, property, defaultValue)=>{
|
|
42
4
|
if (void 0 === object[property] && void 0 !== defaultValue) object[property] = defaultValue;
|
|
43
5
|
return object[property];
|
|
44
6
|
};
|
|
45
|
-
const normalizeOverlay = (options)=>{
|
|
46
|
-
const defaultOverlay = {
|
|
47
|
-
entry: external_node_path_default().join(__dirname, '../client/errorOverlayEntry.js'),
|
|
48
|
-
module: external_node_path_default().join(__dirname, '../client/overlay/index.js'),
|
|
49
|
-
sockIntegration: 'wds'
|
|
50
|
-
};
|
|
51
|
-
if (!options) return false;
|
|
52
|
-
if (void 0 === options || true === options) return defaultOverlay;
|
|
53
|
-
options.entry = options.entry ?? defaultOverlay.entry;
|
|
54
|
-
options.module = options.module ?? defaultOverlay.module;
|
|
55
|
-
options.sockIntegration = options.sockIntegration ?? defaultOverlay.sockIntegration;
|
|
56
|
-
return options;
|
|
57
|
-
};
|
|
58
7
|
function normalizeOptions(options) {
|
|
8
|
+
d(options, 'test', /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/);
|
|
59
9
|
d(options, 'exclude', /node_modules/i);
|
|
60
|
-
d(options, 'include', /\.([cm]js|[jt]sx?|flow)$/i);
|
|
61
10
|
d(options, 'library');
|
|
62
11
|
d(options, 'forceEnable', false);
|
|
63
12
|
d(options, 'injectLoader', true);
|
|
64
13
|
d(options, 'injectEntry', true);
|
|
65
14
|
d(options, 'reloadOnRuntimeErrors', false);
|
|
66
15
|
d(options, 'reactRefreshLoader', 'builtin:react-refresh-loader');
|
|
67
|
-
options.overlay = normalizeOverlay(options.overlay);
|
|
68
16
|
return options;
|
|
69
17
|
}
|
|
70
|
-
const reactRefreshPath =
|
|
71
|
-
const reactRefreshEntryPath =
|
|
72
|
-
const refreshUtilsPath =
|
|
18
|
+
const reactRefreshPath = node_path.join(import.meta.dirname, '../client/reactRefresh.js');
|
|
19
|
+
const reactRefreshEntryPath = node_path.join(import.meta.dirname, '../client/reactRefreshEntry.js');
|
|
20
|
+
const refreshUtilsPath = node_path.join(import.meta.dirname, '../client/refreshUtils.js');
|
|
21
|
+
const paths_require = createRequire(import.meta.url);
|
|
73
22
|
let refreshRuntimeDirPath;
|
|
74
23
|
function getRefreshRuntimeDirPath() {
|
|
75
|
-
if (!refreshRuntimeDirPath) refreshRuntimeDirPath =
|
|
76
|
-
paths: [
|
|
77
|
-
reactRefreshPath
|
|
78
|
-
]
|
|
79
|
-
}));
|
|
24
|
+
if (!refreshRuntimeDirPath) refreshRuntimeDirPath = node_path.dirname(paths_require.resolve('react-refresh/runtime'));
|
|
80
25
|
return refreshRuntimeDirPath;
|
|
81
26
|
}
|
|
82
27
|
const getRefreshRuntimePaths = ()=>[
|
|
@@ -85,115 +30,20 @@ const getRefreshRuntimePaths = ()=>[
|
|
|
85
30
|
refreshUtilsPath,
|
|
86
31
|
getRefreshRuntimeDirPath()
|
|
87
32
|
];
|
|
88
|
-
const external_node_querystring_namespaceObject = require("node:querystring");
|
|
89
|
-
var external_node_querystring_default = /*#__PURE__*/ __webpack_require__.n(external_node_querystring_namespaceObject);
|
|
90
|
-
function getAdditionalEntries({ devServer, options }) {
|
|
91
|
-
const resourceQuery = {};
|
|
92
|
-
if (devServer) {
|
|
93
|
-
const { client, https, http2, sockHost, sockPath, sockPort } = devServer;
|
|
94
|
-
let { host, path, port } = devServer;
|
|
95
|
-
let protocol = https || http2 ? 'https' : 'http';
|
|
96
|
-
if (sockHost) host = sockHost;
|
|
97
|
-
if (sockPath) path = sockPath;
|
|
98
|
-
if (sockPort) port = sockPort;
|
|
99
|
-
if (client && null != client.webSocketURL) {
|
|
100
|
-
let parsedUrl = client.webSocketURL;
|
|
101
|
-
if ('string' == typeof parsedUrl) parsedUrl = new URL(parsedUrl);
|
|
102
|
-
let auth;
|
|
103
|
-
if (parsedUrl.username) {
|
|
104
|
-
auth = parsedUrl.username;
|
|
105
|
-
if (parsedUrl.password) auth += `:${parsedUrl.password}`;
|
|
106
|
-
}
|
|
107
|
-
if (null != parsedUrl.hostname) host = [
|
|
108
|
-
null != auth && auth,
|
|
109
|
-
parsedUrl.hostname
|
|
110
|
-
].filter(Boolean).join('@');
|
|
111
|
-
if (null != parsedUrl.pathname) path = parsedUrl.pathname;
|
|
112
|
-
if (null != parsedUrl.port) port = [
|
|
113
|
-
'0',
|
|
114
|
-
'auto'
|
|
115
|
-
].includes(String(parsedUrl.port)) ? void 0 : parsedUrl.port;
|
|
116
|
-
if (null != parsedUrl.protocol) protocol = 'auto' !== parsedUrl.protocol ? parsedUrl.protocol.replace(':', '') : 'ws';
|
|
117
|
-
}
|
|
118
|
-
if (host) resourceQuery.sockHost = host;
|
|
119
|
-
if (path) resourceQuery.sockPath = path;
|
|
120
|
-
if (port) resourceQuery.sockPort = port;
|
|
121
|
-
resourceQuery.sockProtocol = protocol;
|
|
122
|
-
}
|
|
123
|
-
if (options.overlay) {
|
|
124
|
-
const { sockHost, sockPath, sockPort, sockProtocol } = options.overlay;
|
|
125
|
-
if (sockHost) resourceQuery.sockHost = sockHost;
|
|
126
|
-
if (sockPath) resourceQuery.sockPath = sockPath;
|
|
127
|
-
if (sockPort) resourceQuery.sockPort = sockPort;
|
|
128
|
-
if (sockProtocol) resourceQuery.sockProtocol = sockProtocol;
|
|
129
|
-
}
|
|
130
|
-
const queryString = external_node_querystring_default().stringify(resourceQuery, void 0, void 0, {
|
|
131
|
-
encodeURIComponent (str) {
|
|
132
|
-
return str;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
const prependEntries = [
|
|
136
|
-
reactRefreshEntryPath
|
|
137
|
-
];
|
|
138
|
-
const overlayEntries = [
|
|
139
|
-
false !== options.overlay && options.overlay?.entry && `${require.resolve(options.overlay.entry)}${queryString ? `?${queryString}` : ''}`
|
|
140
|
-
].filter(Boolean);
|
|
141
|
-
return {
|
|
142
|
-
prependEntries,
|
|
143
|
-
overlayEntries
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function getIntegrationEntry(integrationType) {
|
|
147
|
-
let resolvedEntry;
|
|
148
|
-
switch(integrationType){
|
|
149
|
-
case 'whm':
|
|
150
|
-
resolvedEntry = 'webpack-hot-middleware/client';
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
return resolvedEntry;
|
|
154
|
-
}
|
|
155
|
-
function getSocketIntegration(integrationType) {
|
|
156
|
-
let resolvedSocketIntegration;
|
|
157
|
-
switch(integrationType){
|
|
158
|
-
case 'wds':
|
|
159
|
-
resolvedSocketIntegration = external_node_path_default().join(__dirname, './sockets/WDSSocket.js');
|
|
160
|
-
break;
|
|
161
|
-
case 'whm':
|
|
162
|
-
resolvedSocketIntegration = external_node_path_default().join(__dirname, './sockets/WHMEventSource.js');
|
|
163
|
-
break;
|
|
164
|
-
default:
|
|
165
|
-
resolvedSocketIntegration = require.resolve(integrationType);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
return resolvedSocketIntegration;
|
|
169
|
-
}
|
|
170
33
|
function addEntry(entry, compiler) {
|
|
171
34
|
new compiler.rspack.EntryPlugin(compiler.context, entry, {
|
|
172
35
|
name: void 0
|
|
173
36
|
}).apply(compiler);
|
|
174
37
|
}
|
|
175
|
-
function addSocketEntry(sockIntegration, compiler) {
|
|
176
|
-
const integrationEntry = getIntegrationEntry(sockIntegration);
|
|
177
|
-
if (integrationEntry) addEntry(integrationEntry, compiler);
|
|
178
|
-
}
|
|
179
38
|
const PLUGIN_NAME = 'ReactRefreshRspackPlugin';
|
|
180
39
|
class ReactRefreshRspackPlugin {
|
|
181
40
|
options;
|
|
182
|
-
static get deprecated_runtimePaths() {
|
|
183
|
-
return getRefreshRuntimePaths();
|
|
184
|
-
}
|
|
185
41
|
constructor(options = {}){
|
|
186
42
|
this.options = normalizeOptions(options);
|
|
187
43
|
}
|
|
188
44
|
apply(compiler) {
|
|
189
45
|
if (('development' !== compiler.options.mode || process.env.NODE_ENV && 'production' === process.env.NODE_ENV) && !this.options.forceEnable) return;
|
|
190
|
-
|
|
191
|
-
devServer: compiler.options.devServer,
|
|
192
|
-
options: this.options
|
|
193
|
-
});
|
|
194
|
-
if (this.options.injectEntry) for (const entry of addEntries.prependEntries)addEntry(entry, compiler);
|
|
195
|
-
if (false !== this.options.overlay && this.options.overlay.sockIntegration) addSocketEntry(this.options.overlay.sockIntegration, compiler);
|
|
196
|
-
for (const entry of addEntries.overlayEntries)addEntry(entry, compiler);
|
|
46
|
+
if (this.options.injectEntry) addEntry(reactRefreshEntryPath, compiler);
|
|
197
47
|
new compiler.rspack.ProvidePlugin({
|
|
198
48
|
$ReactRefreshRuntime$: reactRefreshPath
|
|
199
49
|
}).apply(compiler);
|
|
@@ -223,13 +73,6 @@ class ReactRefreshRspackPlugin {
|
|
|
223
73
|
const providedModules = {
|
|
224
74
|
__react_refresh_utils__: refreshUtilsPath
|
|
225
75
|
};
|
|
226
|
-
if (false === this.options.overlay) {
|
|
227
|
-
definedModules.__react_refresh_error_overlay__ = false;
|
|
228
|
-
definedModules.__react_refresh_socket__ = false;
|
|
229
|
-
} else {
|
|
230
|
-
if (this.options.overlay.module) providedModules.__react_refresh_error_overlay__ = require.resolve(this.options.overlay.module);
|
|
231
|
-
if (this.options.overlay.sockIntegration) providedModules.__react_refresh_socket__ = getSocketIntegration(this.options.overlay.sockIntegration);
|
|
232
|
-
}
|
|
233
76
|
new compiler.rspack.DefinePlugin(definedModules).apply(compiler);
|
|
234
77
|
new compiler.rspack.ProvidePlugin(providedModules).apply(compiler);
|
|
235
78
|
compiler.options.resolve.alias = {
|
|
@@ -243,13 +86,4 @@ class ReactRefreshRspackPlugin {
|
|
|
243
86
|
});
|
|
244
87
|
}
|
|
245
88
|
}
|
|
246
|
-
|
|
247
|
-
exports.ReactRefreshRspackPlugin = __webpack_exports__.ReactRefreshRspackPlugin;
|
|
248
|
-
exports["default"] = __webpack_exports__["default"];
|
|
249
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
250
|
-
"ReactRefreshRspackPlugin",
|
|
251
|
-
"default"
|
|
252
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
253
|
-
Object.defineProperty(exports, '__esModule', {
|
|
254
|
-
value: true
|
|
255
|
-
});
|
|
89
|
+
export { ReactRefreshRspackPlugin };
|
package/dist/options.d.ts
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import type { RuleSetCondition } from '@rspack/core';
|
|
2
|
-
import type { IntegrationType } from './utils/getSocketIntegration';
|
|
3
|
-
interface OverlayOptions {
|
|
4
|
-
entry: string;
|
|
5
|
-
module: string;
|
|
6
|
-
sockIntegration: IntegrationType | false;
|
|
7
|
-
sockHost?: string;
|
|
8
|
-
sockPath?: string;
|
|
9
|
-
sockPort?: string;
|
|
10
|
-
sockProtocol?: string;
|
|
11
|
-
}
|
|
12
2
|
export type PluginOptions = {
|
|
13
3
|
/**
|
|
14
4
|
* Specifies which files should be processed by the React Refresh loader.
|
|
15
5
|
* This option is passed to the `builtin:react-refresh-loader` as the `rule.test` condition.
|
|
16
6
|
* Works identically to Rspack's `rule.test` option.
|
|
7
|
+
* @default /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/
|
|
17
8
|
* @see https://rspack.rs/config/module-rules#rulestest
|
|
18
9
|
*/
|
|
19
10
|
test?: RuleSetCondition;
|
|
@@ -22,7 +13,7 @@ export type PluginOptions = {
|
|
|
22
13
|
* This option is passed to the `builtin:react-refresh-loader` as the `rule.include` condition.
|
|
23
14
|
* Use this to limit processing to specific directories or file patterns.
|
|
24
15
|
* Works identically to Rspack's `rule.include` option.
|
|
25
|
-
* @default
|
|
16
|
+
* @default undefined
|
|
26
17
|
* @see https://rspack.rs/config/module-rules#rulesinclude
|
|
27
18
|
*/
|
|
28
19
|
include?: RuleSetCondition | null;
|
|
@@ -60,11 +51,6 @@ export type PluginOptions = {
|
|
|
60
51
|
* @default false
|
|
61
52
|
*/
|
|
62
53
|
forceEnable?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Modify the behavior of the error overlay.
|
|
65
|
-
* @default false
|
|
66
|
-
*/
|
|
67
|
-
overlay?: boolean | Partial<OverlayOptions>;
|
|
68
54
|
/**
|
|
69
55
|
* Whether to inject the builtin:react-refresh-loader
|
|
70
56
|
* @default true
|
|
@@ -86,8 +72,5 @@ export type PluginOptions = {
|
|
|
86
72
|
*/
|
|
87
73
|
reactRefreshLoader?: string;
|
|
88
74
|
};
|
|
89
|
-
export
|
|
90
|
-
overlay: false | OverlayOptions;
|
|
91
|
-
}
|
|
75
|
+
export type NormalizedPluginOptions = Required<PluginOptions>;
|
|
92
76
|
export declare function normalizeOptions(options: PluginOptions): NormalizedPluginOptions;
|
|
93
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,76 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/plugin-react-refresh",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"repository": "https://github.com/rstackjs/rspack-plugin-react-refresh",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "React refresh plugin for Rspack",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"types": "exports/index.d.cts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
10
9
|
"exports": {
|
|
11
10
|
".": {
|
|
12
|
-
"
|
|
13
|
-
"default": "./
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
14
13
|
},
|
|
15
14
|
"./react-refresh": "./client/reactRefresh.js",
|
|
16
15
|
"./react-refresh-entry": "./client/reactRefreshEntry.js",
|
|
17
|
-
"./overlay": "./client/overlay/index.js",
|
|
18
16
|
"./package.json": "./package.json"
|
|
19
17
|
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "rslib",
|
|
20
|
+
"dev": "rslib -w",
|
|
21
|
+
"lint": "rslint && prettier -c .",
|
|
22
|
+
"lint:write": "rslint --fix && prettier -w .",
|
|
23
|
+
"prepare": "simple-git-hooks && npm run build",
|
|
24
|
+
"test": "rstest",
|
|
25
|
+
"release": "node ./scripts/release.js",
|
|
26
|
+
"bump": "npx bumpp --no-push --no-tag --no-commit"
|
|
27
|
+
},
|
|
20
28
|
"files": [
|
|
21
29
|
"client",
|
|
22
|
-
"dist"
|
|
23
|
-
"exports"
|
|
30
|
+
"dist"
|
|
24
31
|
],
|
|
25
32
|
"simple-git-hooks": {
|
|
26
|
-
"pre-commit": "
|
|
27
|
-
},
|
|
28
|
-
"nano-staged": {
|
|
29
|
-
"*.{js,jsx,ts,tsx,mjs,cjs}": [
|
|
30
|
-
"biome check --write --no-errors-on-unmatched"
|
|
31
|
-
]
|
|
33
|
+
"pre-commit": "pnpm run lint:write"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
|
-
"@biomejs/biome": "^1.9.4",
|
|
35
36
|
"@rslib/core": "^0.20.3",
|
|
37
|
+
"@rslint/core": "^0.3.4",
|
|
36
38
|
"@rspack/core": "2.0.0-rc.0",
|
|
37
39
|
"@rstest/core": "^0.9.6",
|
|
38
40
|
"@types/node": "^24.12.2",
|
|
39
|
-
"
|
|
40
|
-
"cac": "^7.0.0",
|
|
41
|
-
"cross-env": "^10.1.0",
|
|
42
|
-
"execa": "9.6.1",
|
|
43
|
-
"fs-extra": "11.3.4",
|
|
44
|
-
"nano-staged": "^0.9.0",
|
|
41
|
+
"prettier": "^3.8.1",
|
|
45
42
|
"react-refresh": "^0.18.0",
|
|
46
|
-
"semver": "7.7.4",
|
|
47
43
|
"simple-git-hooks": "^2.13.1",
|
|
48
|
-
"ts-node": "^10.9.2",
|
|
49
44
|
"typescript": "^6.0.2"
|
|
50
45
|
},
|
|
51
|
-
"dependencies": {
|
|
52
|
-
"error-stack-parser": "^2.1.4"
|
|
53
|
-
},
|
|
54
46
|
"peerDependencies": {
|
|
55
|
-
"
|
|
56
|
-
"
|
|
47
|
+
"@rspack/core": "^2.0.0-0",
|
|
48
|
+
"react-refresh": ">=0.10.0 <1.0.0"
|
|
57
49
|
},
|
|
58
50
|
"peerDependenciesMeta": {
|
|
59
|
-
"
|
|
51
|
+
"@rspack/core": {
|
|
60
52
|
"optional": true
|
|
61
53
|
}
|
|
62
54
|
},
|
|
55
|
+
"packageManager": "pnpm@10.33.0",
|
|
63
56
|
"publishConfig": {
|
|
64
57
|
"access": "public",
|
|
65
58
|
"registry": "https://registry.npmjs.org/"
|
|
66
|
-
},
|
|
67
|
-
"scripts": {
|
|
68
|
-
"build": "rslib",
|
|
69
|
-
"dev": "rslib -w",
|
|
70
|
-
"lint": "biome check .",
|
|
71
|
-
"lint:write": "biome check . --write",
|
|
72
|
-
"test": "rstest",
|
|
73
|
-
"release": "node ./scripts/release.mjs",
|
|
74
|
-
"bump": "npx bumpp --no-push --no-tag --no-commit"
|
|
75
59
|
}
|
|
76
|
-
}
|
|
60
|
+
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/* global __react_refresh_error_overlay__, __react_refresh_socket__, __resourceQuery */
|
|
2
|
-
const events = require('./utils/errorEventHandlers.js');
|
|
3
|
-
const formatWebpackErrors = require('./utils/formatWebpackErrors.js');
|
|
4
|
-
const runWithRetry = require('./utils/retry.js');
|
|
5
|
-
|
|
6
|
-
// Setup error states
|
|
7
|
-
let isHotReload = false;
|
|
8
|
-
let hasRuntimeErrors = false;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Try dismissing the compile error overlay.
|
|
12
|
-
* This will also reset runtime error records (if any),
|
|
13
|
-
* because we have new source to evaluate.
|
|
14
|
-
* @returns {void}
|
|
15
|
-
*/
|
|
16
|
-
function tryDismissErrorOverlay() {
|
|
17
|
-
__react_refresh_error_overlay__.clearCompileError();
|
|
18
|
-
__react_refresh_error_overlay__.clearRuntimeErrors(!hasRuntimeErrors);
|
|
19
|
-
hasRuntimeErrors = false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A function called after a compile success signal is received from Webpack.
|
|
24
|
-
* @returns {void}
|
|
25
|
-
*/
|
|
26
|
-
function handleCompileSuccess() {
|
|
27
|
-
isHotReload = true;
|
|
28
|
-
|
|
29
|
-
if (isHotReload) {
|
|
30
|
-
tryDismissErrorOverlay();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* A function called after a compile errored signal is received from Webpack.
|
|
36
|
-
* @param {string[]} errors
|
|
37
|
-
* @returns {void}
|
|
38
|
-
*/
|
|
39
|
-
function handleCompileErrors(errors) {
|
|
40
|
-
isHotReload = true;
|
|
41
|
-
|
|
42
|
-
const formattedErrors = formatWebpackErrors(errors);
|
|
43
|
-
|
|
44
|
-
// Only show the first error
|
|
45
|
-
__react_refresh_error_overlay__.showCompileError(formattedErrors[0]);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Handles compilation messages from Webpack.
|
|
50
|
-
* Integrates with a compile error overlay.
|
|
51
|
-
* @param {*} message A Webpack HMR message sent via WebSockets.
|
|
52
|
-
* @returns {void}
|
|
53
|
-
*/
|
|
54
|
-
function compileMessageHandler(message) {
|
|
55
|
-
switch (message.type) {
|
|
56
|
-
case 'ok':
|
|
57
|
-
case 'still-ok':
|
|
58
|
-
case 'warnings': {
|
|
59
|
-
// TODO: Implement handling for warnings
|
|
60
|
-
handleCompileSuccess();
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
case 'errors': {
|
|
64
|
-
handleCompileErrors(message.data);
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
default: {
|
|
68
|
-
// Do nothing.
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
74
|
-
if (typeof window !== 'undefined') {
|
|
75
|
-
function setupOverlay() {
|
|
76
|
-
// Only register if no other overlay have been registered
|
|
77
|
-
if (!window.__reactRefreshOverlayInjected && __react_refresh_socket__) {
|
|
78
|
-
// Registers handlers for compile errors with retry -
|
|
79
|
-
// This is to prevent mismatching injection order causing errors to be thrown
|
|
80
|
-
runWithRetry(function initSocket() {
|
|
81
|
-
__react_refresh_socket__.init(compileMessageHandler, __resourceQuery);
|
|
82
|
-
}, 3);
|
|
83
|
-
// Registers handlers for runtime errors
|
|
84
|
-
events.handleError(function handleError(error) {
|
|
85
|
-
hasRuntimeErrors = true;
|
|
86
|
-
__react_refresh_error_overlay__.handleRuntimeError(error);
|
|
87
|
-
});
|
|
88
|
-
events.handleUnhandledRejection(
|
|
89
|
-
function handleUnhandledPromiseRejection(error) {
|
|
90
|
-
hasRuntimeErrors = true;
|
|
91
|
-
__react_refresh_error_overlay__.handleRuntimeError(error);
|
|
92
|
-
},
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
// Mark overlay as injected to prevent double-injection
|
|
96
|
-
window.__reactRefreshOverlayInjected = true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
setupOverlay();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const ansiHTML = require('../../utils/ansi-html.js');
|
|
2
|
-
const theme = require('../theme.js');
|
|
3
|
-
const utils = require('../utils.js');
|
|
4
|
-
|
|
5
|
-
ansiHTML.setColors(theme);
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Escape text before passing it to `ansiHTML`, which injects HTML markup.
|
|
9
|
-
* @param {string} value
|
|
10
|
-
* @returns {string}
|
|
11
|
-
*/
|
|
12
|
-
function escapeHtml(value) {
|
|
13
|
-
return value
|
|
14
|
-
.replace(/&/g, '&')
|
|
15
|
-
.replace(/</g, '<')
|
|
16
|
-
.replace(/>/g, '>')
|
|
17
|
-
.replace(/"/g, '"')
|
|
18
|
-
.replace(/'/g, ''');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @typedef {Object} CompileErrorTraceProps
|
|
23
|
-
* @property {string} errorMessage
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A formatter that turns Webpack compile error messages into highlighted HTML source traces.
|
|
28
|
-
* @param {Document} document
|
|
29
|
-
* @param {HTMLElement} root
|
|
30
|
-
* @param {CompileErrorTraceProps} props
|
|
31
|
-
* @returns {void}
|
|
32
|
-
*/
|
|
33
|
-
function CompileErrorTrace(document, root, props) {
|
|
34
|
-
const errorParts = props.errorMessage.split('\n');
|
|
35
|
-
if (errorParts.length) {
|
|
36
|
-
if (errorParts[0]) {
|
|
37
|
-
errorParts[0] = utils.formatFilename(errorParts[0]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const errorMessage = errorParts.splice(1, 1)[0];
|
|
41
|
-
if (errorMessage) {
|
|
42
|
-
// Strip filename from the error message
|
|
43
|
-
errorParts.unshift(errorMessage.replace(/^(.*:)\s.*:(\s.*)$/, '$1$2'));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const stackContainer = document.createElement('pre');
|
|
48
|
-
stackContainer.innerHTML = ansiHTML(escapeHtml(errorParts.join('\n')));
|
|
49
|
-
stackContainer.style.fontFamily = [
|
|
50
|
-
'"Operator Mono SSm"',
|
|
51
|
-
'"Operator Mono"',
|
|
52
|
-
'"Fira Code Retina"',
|
|
53
|
-
'"Fira Code"',
|
|
54
|
-
'"FiraCode-Retina"',
|
|
55
|
-
'"Andale Mono"',
|
|
56
|
-
'"Lucida Console"',
|
|
57
|
-
'Menlo',
|
|
58
|
-
'Consolas',
|
|
59
|
-
'Monaco',
|
|
60
|
-
'monospace',
|
|
61
|
-
].join(', ');
|
|
62
|
-
stackContainer.style.margin = '0';
|
|
63
|
-
stackContainer.style.whiteSpace = 'pre-wrap';
|
|
64
|
-
|
|
65
|
-
root.appendChild(stackContainer);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
module.exports = CompileErrorTrace;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const Spacer = require('./Spacer.js');
|
|
2
|
-
const theme = require('../theme.js');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {Object} PageHeaderProps
|
|
6
|
-
* @property {string} [message]
|
|
7
|
-
* @property {string} title
|
|
8
|
-
* @property {string} [topOffset]
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The header of the overlay.
|
|
13
|
-
* @param {Document} document
|
|
14
|
-
* @param {HTMLElement} root
|
|
15
|
-
* @param {PageHeaderProps} props
|
|
16
|
-
* @returns {void}
|
|
17
|
-
*/
|
|
18
|
-
function PageHeader(document, root, props) {
|
|
19
|
-
const pageHeaderContainer = document.createElement('div');
|
|
20
|
-
pageHeaderContainer.style.background = '#' + theme.dimgrey;
|
|
21
|
-
pageHeaderContainer.style.boxShadow = '0 1px 4px rgba(0, 0, 0, 0.3)';
|
|
22
|
-
pageHeaderContainer.style.color = '#' + theme.white;
|
|
23
|
-
pageHeaderContainer.style.left = '0';
|
|
24
|
-
pageHeaderContainer.style.right = '0';
|
|
25
|
-
pageHeaderContainer.style.padding = '1rem 1.5rem';
|
|
26
|
-
pageHeaderContainer.style.paddingLeft =
|
|
27
|
-
'max(1.5rem, env(safe-area-inset-left))';
|
|
28
|
-
pageHeaderContainer.style.paddingRight =
|
|
29
|
-
'max(1.5rem, env(safe-area-inset-right))';
|
|
30
|
-
pageHeaderContainer.style.position = 'fixed';
|
|
31
|
-
pageHeaderContainer.style.top = props.topOffset || '0';
|
|
32
|
-
|
|
33
|
-
const title = document.createElement('h3');
|
|
34
|
-
title.innerText = props.title;
|
|
35
|
-
title.style.color = '#' + theme.red;
|
|
36
|
-
title.style.fontSize = '1.125rem';
|
|
37
|
-
title.style.lineHeight = '1.3';
|
|
38
|
-
title.style.margin = '0';
|
|
39
|
-
pageHeaderContainer.appendChild(title);
|
|
40
|
-
|
|
41
|
-
if (props.message) {
|
|
42
|
-
title.style.margin = '0 0 0.5rem';
|
|
43
|
-
|
|
44
|
-
const message = document.createElement('span');
|
|
45
|
-
message.innerText = props.message;
|
|
46
|
-
message.style.color = '#' + theme.white;
|
|
47
|
-
message.style.wordBreak = 'break-word';
|
|
48
|
-
pageHeaderContainer.appendChild(message);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
root.appendChild(pageHeaderContainer);
|
|
52
|
-
|
|
53
|
-
// This has to run after appending elements to root
|
|
54
|
-
// because we need to actual mounted height.
|
|
55
|
-
Spacer(document, root, {
|
|
56
|
-
space: pageHeaderContainer.offsetHeight.toString(10),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
module.exports = PageHeader;
|