@rspack/plugin-react-refresh 1.0.0-beta.2 → 1.0.0-beta.4
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/LICENSE +0 -1
- package/README.md +67 -3
- package/client/errorOverlayEntry.js +9 -7
- package/client/overlay/components/CompileErrorTrace.js +7 -2
- package/client/overlay/components/PageHeader.js +4 -2
- package/client/overlay/components/RuntimeErrorHeader.js +2 -1
- package/client/overlay/components/RuntimeErrorStack.js +2 -1
- package/client/overlay/index.js +10 -3
- package/client/overlay/utils.js +1 -1
- package/client/reactRefresh.js +15 -15
- package/client/reactRefreshEntry.js +41 -41
- package/client/refreshUtils.js +213 -213
- package/client/utils/ansi-html.js +80 -78
- package/client/utils/errorEventHandlers.js +2 -2
- package/client/utils/formatWebpackErrors.js +15 -5
- package/client/utils/retry.js +2 -2
- package/dist/index.d.ts +2 -7
- package/dist/index.js +23 -26
- package/dist/options.d.ts +1 -1
- package/dist/options.js +10 -10
- package/dist/sockets/WDSSocket.d.ts +8 -5
- package/dist/sockets/WDSSocket.js +10 -8
- package/dist/sockets/utils/getCurrentScriptSource.d.ts +1 -1
- package/dist/sockets/utils/getCurrentScriptSource.js +4 -4
- package/dist/sockets/utils/getSocketUrlParts.d.ts +1 -1
- package/dist/sockets/utils/getSocketUrlParts.js +14 -18
- package/dist/sockets/utils/getUrlFromParts.d.ts +6 -6
- package/dist/sockets/utils/getUrlFromParts.js +7 -10
- package/dist/sockets/utils/getWDSMetadata.d.ts +12 -1
- package/dist/sockets/utils/getWDSMetadata.js +6 -6
- package/dist/utils/getAdditionalEntries.d.ts +2 -2
- package/dist/utils/getAdditionalEntries.js +11 -11
- package/dist/utils/getSocketIntegration.d.ts +2 -2
- package/dist/utils/getSocketIntegration.js +4 -3
- package/package.json +31 -21
@@ -3,20 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
function getCurrentScriptSource() {
|
4
4
|
// `document.currentScript` is the most accurate way to get the current running script,
|
5
5
|
// but is not supported in all browsers (most notably, IE).
|
6
|
-
if (
|
6
|
+
if ('currentScript' in document) {
|
7
7
|
// In some cases, `document.currentScript` would be `null` even if the browser supports it:
|
8
8
|
// e.g. asynchronous chunks on Firefox.
|
9
9
|
// We should not fallback to the list-approach as it would not be safe.
|
10
10
|
if (document.currentScript == null)
|
11
11
|
return;
|
12
|
-
return document.currentScript.getAttribute(
|
12
|
+
return document.currentScript.getAttribute('src');
|
13
13
|
}
|
14
14
|
// Fallback to getting all scripts running in the document,
|
15
15
|
// and finding the last one injected.
|
16
|
-
const scriptElementsWithSrc = Array.prototype.filter.call(document.scripts || [], elem => elem.getAttribute(
|
16
|
+
const scriptElementsWithSrc = Array.prototype.filter.call(document.scripts || [], (elem) => elem.getAttribute('src'));
|
17
17
|
if (!scriptElementsWithSrc.length)
|
18
18
|
return;
|
19
19
|
const currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
|
20
|
-
return currentScript.getAttribute(
|
20
|
+
return currentScript.getAttribute('src');
|
21
21
|
}
|
22
22
|
exports.default = getCurrentScriptSource;
|
@@ -4,11 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const getCurrentScriptSource_1 = __importDefault(require("./getCurrentScriptSource"));
|
7
|
-
function getSocketUrlParts(resourceQuery, metadata) {
|
8
|
-
if (typeof metadata === "undefined") {
|
9
|
-
metadata = {};
|
10
|
-
}
|
11
|
-
/** @type {SocketUrlParts} */
|
7
|
+
function getSocketUrlParts(resourceQuery, metadata = {}) {
|
12
8
|
const urlParts = {};
|
13
9
|
// If the resource query is available,
|
14
10
|
// parse it and ignore everything we received from the script host.
|
@@ -16,7 +12,6 @@ function getSocketUrlParts(resourceQuery, metadata) {
|
|
16
12
|
const parsedQuery = {};
|
17
13
|
const searchParams = new URLSearchParams(resourceQuery.slice(1));
|
18
14
|
searchParams.forEach((value, key) => {
|
19
|
-
// @ts-expect-error -- ignore
|
20
15
|
parsedQuery[key] = value;
|
21
16
|
});
|
22
17
|
urlParts.hostname = parsedQuery.sockHost;
|
@@ -34,6 +29,7 @@ function getSocketUrlParts(resourceQuery, metadata) {
|
|
34
29
|
// The placeholder `baseURL` with `window.location.href`,
|
35
30
|
// is to allow parsing of path-relative or protocol-relative URLs,
|
36
31
|
// and will have no effect if `scriptSource` is a fully valid URL.
|
32
|
+
// biome-ignore lint: reason
|
37
33
|
url = new URL(scriptSource, window.location.href);
|
38
34
|
}
|
39
35
|
catch (e) {
|
@@ -51,7 +47,7 @@ function getSocketUrlParts(resourceQuery, metadata) {
|
|
51
47
|
}
|
52
48
|
}
|
53
49
|
// `file://` URLs has `'null'` origin
|
54
|
-
if (url.origin !==
|
50
|
+
if (url.origin !== 'null') {
|
55
51
|
urlParts.hostname = url.hostname;
|
56
52
|
}
|
57
53
|
urlParts.protocol = url.protocol;
|
@@ -60,24 +56,24 @@ function getSocketUrlParts(resourceQuery, metadata) {
|
|
60
56
|
if (!urlParts.pathname) {
|
61
57
|
if (metadata.version === 4) {
|
62
58
|
// This is hard-coded in WDS v4
|
63
|
-
urlParts.pathname =
|
59
|
+
urlParts.pathname = '/ws';
|
64
60
|
}
|
65
61
|
else {
|
66
62
|
// This is hard-coded in WDS v3
|
67
|
-
urlParts.pathname =
|
63
|
+
urlParts.pathname = '/sockjs-node';
|
68
64
|
}
|
69
65
|
}
|
70
66
|
// Check for IPv4 and IPv6 host addresses that correspond to any/empty.
|
71
67
|
// This is important because `hostname` can be empty for some hosts,
|
72
68
|
// such as 'about:blank' or 'file://' URLs.
|
73
|
-
const isEmptyHostname = urlParts.hostname ===
|
74
|
-
urlParts.hostname ===
|
69
|
+
const isEmptyHostname = urlParts.hostname === '0.0.0.0' ||
|
70
|
+
urlParts.hostname === '[::]' ||
|
75
71
|
!urlParts.hostname;
|
76
72
|
// We only re-assign the hostname if it is empty,
|
77
73
|
// and if we are using HTTP/HTTPS protocols.
|
78
74
|
if (isEmptyHostname &&
|
79
75
|
window.location.hostname &&
|
80
|
-
window.location.protocol.indexOf(
|
76
|
+
window.location.protocol.indexOf('http') === 0) {
|
81
77
|
urlParts.hostname = window.location.hostname;
|
82
78
|
}
|
83
79
|
// We only re-assign `protocol` when `protocol` is unavailable,
|
@@ -86,7 +82,7 @@ function getSocketUrlParts(resourceQuery, metadata) {
|
|
86
82
|
// We also do this when 'https' is used as it mandates the use of secure sockets.
|
87
83
|
if (!urlParts.protocol ||
|
88
84
|
(urlParts.hostname &&
|
89
|
-
(isEmptyHostname || window.location.protocol ===
|
85
|
+
(isEmptyHostname || window.location.protocol === 'https:'))) {
|
90
86
|
urlParts.protocol = window.location.protocol;
|
91
87
|
}
|
92
88
|
// We only re-assign port when it is not available
|
@@ -95,18 +91,18 @@ function getSocketUrlParts(resourceQuery, metadata) {
|
|
95
91
|
}
|
96
92
|
if (!urlParts.hostname || !urlParts.pathname) {
|
97
93
|
throw new Error([
|
98
|
-
|
94
|
+
'[React Refresh] Failed to get an URL for the socket connection.',
|
99
95
|
"This usually means that the current executed script doesn't have a `src` attribute set.",
|
100
|
-
|
101
|
-
|
102
|
-
].join(
|
96
|
+
'You should either specify the socket path parameters under the `devServer` key in your Rspack config, or use the `overlay` option.',
|
97
|
+
'https://www.rspack.dev/guide/tech/react#fast-refresh',
|
98
|
+
].join('\n'));
|
103
99
|
}
|
104
100
|
return {
|
105
101
|
auth: urlParts.auth,
|
106
102
|
hostname: urlParts.hostname,
|
107
103
|
pathname: urlParts.pathname,
|
108
104
|
protocol: urlParts.protocol,
|
109
|
-
port: urlParts.port || undefined
|
105
|
+
port: urlParts.port || undefined,
|
110
106
|
};
|
111
107
|
}
|
112
108
|
exports.default = getSocketUrlParts;
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import type { SocketUrlParts } from
|
2
|
-
import type { WDSMetaObj } from
|
1
|
+
import type { SocketUrlParts } from './getSocketUrlParts';
|
2
|
+
import type { WDSMetaObj } from './getWDSMetadata';
|
3
3
|
/**
|
4
4
|
* Create a valid URL from parsed URL parts.
|
5
|
-
* @param
|
6
|
-
* @param
|
7
|
-
* @returns
|
5
|
+
* @param urlParts The parsed URL parts.
|
6
|
+
* @param metadata The parsed WDS metadata object.
|
7
|
+
* @returns The generated URL.
|
8
8
|
*/
|
9
|
-
export default function urlFromParts(urlParts: SocketUrlParts, metadata
|
9
|
+
export default function urlFromParts(urlParts: SocketUrlParts, metadata?: WDSMetaObj): string;
|
@@ -2,25 +2,22 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
/**
|
4
4
|
* Create a valid URL from parsed URL parts.
|
5
|
-
* @param
|
6
|
-
* @param
|
7
|
-
* @returns
|
5
|
+
* @param urlParts The parsed URL parts.
|
6
|
+
* @param metadata The parsed WDS metadata object.
|
7
|
+
* @returns The generated URL.
|
8
8
|
*/
|
9
|
-
function urlFromParts(urlParts, metadata) {
|
10
|
-
|
11
|
-
metadata = {};
|
12
|
-
}
|
13
|
-
let fullProtocol = "http:";
|
9
|
+
function urlFromParts(urlParts, metadata = {}) {
|
10
|
+
let fullProtocol = 'http:';
|
14
11
|
if (urlParts.protocol) {
|
15
12
|
fullProtocol = urlParts.protocol;
|
16
13
|
}
|
17
14
|
if (metadata.enforceWs) {
|
18
|
-
fullProtocol = fullProtocol.replace(/^(?:http|.+-extension|file)/i,
|
15
|
+
fullProtocol = fullProtocol.replace(/^(?:http|.+-extension|file)/i, 'ws');
|
19
16
|
}
|
20
17
|
fullProtocol = `${fullProtocol}//`;
|
21
18
|
let fullHost = urlParts.hostname;
|
22
19
|
if (urlParts.auth) {
|
23
|
-
const fullAuth = `${urlParts.auth.split(
|
20
|
+
const fullAuth = `${urlParts.auth.split(':').map(encodeURIComponent).join(':')}@`;
|
24
21
|
fullHost = fullAuth + fullHost;
|
25
22
|
}
|
26
23
|
if (urlParts.port) {
|
@@ -2,4 +2,15 @@ export interface WDSMetaObj {
|
|
2
2
|
enforceWs?: boolean;
|
3
3
|
version?: number;
|
4
4
|
}
|
5
|
-
|
5
|
+
declare class WebSocketClient {
|
6
|
+
client: WebSocket;
|
7
|
+
constructor(url: string);
|
8
|
+
onOpen(f: (...args: unknown[]) => void): void;
|
9
|
+
onClose(f: (...args: unknown[]) => void): void;
|
10
|
+
onMessage(f: (...args: unknown[]) => void): void;
|
11
|
+
}
|
12
|
+
export interface SocketClient {
|
13
|
+
new (url: string): WebSocketClient;
|
14
|
+
}
|
15
|
+
export default function getWDSMetadata(SocketClient: SocketClient): WDSMetaObj;
|
16
|
+
export {};
|
@@ -2,20 +2,20 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
function getWDSMetadata(SocketClient) {
|
4
4
|
let enforceWs = false;
|
5
|
-
if (typeof SocketClient.name !==
|
5
|
+
if (typeof SocketClient.name !== 'undefined' &&
|
6
6
|
SocketClient.name !== null &&
|
7
|
-
SocketClient.name.toLowerCase().includes(
|
7
|
+
SocketClient.name.toLowerCase().includes('websocket')) {
|
8
8
|
enforceWs = true;
|
9
9
|
}
|
10
10
|
let version;
|
11
11
|
// WDS versions <=3.5.0
|
12
|
-
if (!(
|
12
|
+
if (!('onMessage' in SocketClient.prototype)) {
|
13
13
|
version = 3;
|
14
14
|
}
|
15
15
|
else {
|
16
16
|
// WDS versions >=3.5.0 <4
|
17
|
-
if (
|
18
|
-
Object.getPrototypeOf(SocketClient).name ===
|
17
|
+
if ('getClientPath' in SocketClient ||
|
18
|
+
Object.getPrototypeOf(SocketClient).name === 'BaseClient') {
|
19
19
|
version = 3;
|
20
20
|
}
|
21
21
|
else {
|
@@ -24,7 +24,7 @@ function getWDSMetadata(SocketClient) {
|
|
24
24
|
}
|
25
25
|
return {
|
26
26
|
enforceWs: enforceWs,
|
27
|
-
version: version
|
27
|
+
version: version,
|
28
28
|
};
|
29
29
|
}
|
30
30
|
exports.default = getWDSMetadata;
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import type { NormalizedPluginOptions } from
|
1
|
+
import type { NormalizedPluginOptions } from '../options';
|
2
2
|
export interface AdditionalEntries {
|
3
3
|
prependEntries: string[];
|
4
4
|
overlayEntries: string[];
|
5
5
|
}
|
6
|
-
export declare function getAdditionalEntries({ devServer, options }: {
|
6
|
+
export declare function getAdditionalEntries({ devServer, options, }: {
|
7
7
|
devServer: any;
|
8
8
|
options: NormalizedPluginOptions;
|
9
9
|
}): AdditionalEntries;
|
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.getAdditionalEntries = void 0;
|
7
7
|
const node_querystring_1 = __importDefault(require("node:querystring"));
|
8
|
-
function getAdditionalEntries({ devServer, options }) {
|
8
|
+
function getAdditionalEntries({ devServer, options, }) {
|
9
9
|
const resourceQuery = {};
|
10
10
|
if (devServer) {
|
11
11
|
const { client, https, http2, sockHost, sockPath, sockPort } = devServer;
|
12
12
|
let { host, path, port } = devServer;
|
13
|
-
let protocol = https || http2 ?
|
13
|
+
let protocol = https || http2 ? 'https' : 'http';
|
14
14
|
if (sockHost)
|
15
15
|
host = sockHost;
|
16
16
|
if (sockPath)
|
@@ -19,7 +19,7 @@ function getAdditionalEntries({ devServer, options }) {
|
|
19
19
|
port = sockPort;
|
20
20
|
if (client && client.webSocketURL != null) {
|
21
21
|
let parsedUrl = client.webSocketURL;
|
22
|
-
if (typeof parsedUrl ===
|
22
|
+
if (typeof parsedUrl === 'string')
|
23
23
|
parsedUrl = new URL(parsedUrl);
|
24
24
|
let auth;
|
25
25
|
if (parsedUrl.username) {
|
@@ -31,21 +31,21 @@ function getAdditionalEntries({ devServer, options }) {
|
|
31
31
|
if (parsedUrl.hostname != null) {
|
32
32
|
host = [auth != null && auth, parsedUrl.hostname]
|
33
33
|
.filter(Boolean)
|
34
|
-
.join(
|
34
|
+
.join('@');
|
35
35
|
}
|
36
36
|
if (parsedUrl.pathname != null) {
|
37
37
|
path = parsedUrl.pathname;
|
38
38
|
}
|
39
39
|
if (parsedUrl.port != null) {
|
40
|
-
port = ![
|
40
|
+
port = !['0', 'auto'].includes(String(parsedUrl.port))
|
41
41
|
? parsedUrl.port
|
42
42
|
: undefined;
|
43
43
|
}
|
44
44
|
if (parsedUrl.protocol != null) {
|
45
45
|
protocol =
|
46
|
-
parsedUrl.protocol !==
|
47
|
-
? parsedUrl.protocol.replace(
|
48
|
-
:
|
46
|
+
parsedUrl.protocol !== 'auto'
|
47
|
+
? parsedUrl.protocol.replace(':', '')
|
48
|
+
: 'ws';
|
49
49
|
}
|
50
50
|
}
|
51
51
|
if (host)
|
@@ -71,17 +71,17 @@ function getAdditionalEntries({ devServer, options }) {
|
|
71
71
|
const queryString = node_querystring_1.default.stringify(resourceQuery, undefined, undefined, {
|
72
72
|
encodeURIComponent(str) {
|
73
73
|
return str;
|
74
|
-
}
|
74
|
+
},
|
75
75
|
});
|
76
76
|
const prependEntries = [
|
77
77
|
// React-refresh runtime
|
78
|
-
require.resolve(
|
78
|
+
require.resolve('../../client/reactRefreshEntry'),
|
79
79
|
];
|
80
80
|
const overlayEntries = [
|
81
81
|
// Error overlay runtime
|
82
82
|
options.overlay !== false &&
|
83
83
|
options.overlay?.entry &&
|
84
|
-
`${require.resolve(options.overlay.entry)}${queryString ? `?${queryString}` :
|
84
|
+
`${require.resolve(options.overlay.entry)}${queryString ? `?${queryString}` : ''}`,
|
85
85
|
].filter(Boolean);
|
86
86
|
return { prependEntries, overlayEntries };
|
87
87
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export type IntegrationType =
|
2
|
-
export
|
1
|
+
export type IntegrationType = 'wds';
|
2
|
+
export declare function getSocketIntegration(integrationType: IntegrationType): string;
|
@@ -1,10 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getSocketIntegration = void 0;
|
3
4
|
function getSocketIntegration(integrationType) {
|
4
5
|
let resolvedSocketIntegration;
|
5
6
|
switch (integrationType) {
|
6
|
-
case
|
7
|
-
resolvedSocketIntegration = require.resolve(
|
7
|
+
case 'wds': {
|
8
|
+
resolvedSocketIntegration = require.resolve('../sockets/WDSSocket');
|
8
9
|
break;
|
9
10
|
}
|
10
11
|
default: {
|
@@ -14,4 +15,4 @@ function getSocketIntegration(integrationType) {
|
|
14
15
|
}
|
15
16
|
return resolvedSocketIntegration;
|
16
17
|
}
|
17
|
-
exports.
|
18
|
+
exports.getSocketIntegration = getSocketIntegration;
|
package/package.json
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspack/plugin-react-refresh",
|
3
|
-
"version": "1.0.0-beta.
|
3
|
+
"version": "1.0.0-beta.4",
|
4
|
+
"repository": "https://github.com/rspack-contrib/rspack-plugin-react-refresh",
|
4
5
|
"license": "MIT",
|
5
6
|
"description": "React refresh plugin for rspack",
|
6
7
|
"main": "dist/index.js",
|
@@ -17,22 +18,33 @@
|
|
17
18
|
"client",
|
18
19
|
"dist"
|
19
20
|
],
|
20
|
-
"
|
21
|
-
"
|
22
|
-
"provenance": true
|
21
|
+
"simple-git-hooks": {
|
22
|
+
"pre-commit": "npx nano-staged"
|
23
23
|
},
|
24
|
-
"
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
"url": "https://github.com/web-infra-dev/rspack",
|
29
|
-
"directory": "packages/rspack-plugin-react-refresh"
|
24
|
+
"nano-staged": {
|
25
|
+
"*.{js,jsx,ts,tsx,mjs,cjs}": [
|
26
|
+
"biome check --write --no-errors-on-unmatched"
|
27
|
+
]
|
30
28
|
},
|
31
29
|
"devDependencies": {
|
30
|
+
"@biomejs/biome": "^1.8.3",
|
31
|
+
"@rspack/core": "1.0.0-beta.3",
|
32
|
+
"@rspack/test-tools": "1.0.0-beta.3",
|
33
|
+
"@rspack/dev-server": "1.0.0-beta.3",
|
34
|
+
"@types/node": "^20.14.13",
|
35
|
+
"@types/jest": "29.5.12",
|
32
36
|
"react-refresh": "^0.14.0",
|
33
|
-
"
|
34
|
-
"
|
35
|
-
"
|
37
|
+
"cross-env": "^7.0.3",
|
38
|
+
"execa": "9.3.0",
|
39
|
+
"fs-extra": "11.2.0",
|
40
|
+
"jest": "29.7.0",
|
41
|
+
"jest-cli": "29.7.0",
|
42
|
+
"jest-environment-node": "29.7.0",
|
43
|
+
"nano-staged": "^0.8.0",
|
44
|
+
"semver": "7.6.3",
|
45
|
+
"simple-git-hooks": "^2.11.1",
|
46
|
+
"ts-jest": "29.1.2",
|
47
|
+
"typescript": "5.0.2"
|
36
48
|
},
|
37
49
|
"dependencies": {
|
38
50
|
"error-stack-parser": "^2.0.6",
|
@@ -46,18 +58,16 @@
|
|
46
58
|
"optional": true
|
47
59
|
}
|
48
60
|
},
|
49
|
-
"
|
50
|
-
"
|
51
|
-
|
52
|
-
"<rootDir>/tests/dist"
|
53
|
-
],
|
54
|
-
"testEnvironment": "../../scripts/test/patch-node-env.cjs"
|
61
|
+
"publishConfig": {
|
62
|
+
"access": "public",
|
63
|
+
"registry": "https://registry.npmjs.org/"
|
55
64
|
},
|
56
65
|
"scripts": {
|
57
66
|
"build": "tsc -b ./tsconfig.build.json",
|
58
67
|
"dev": "tsc -b -w",
|
68
|
+
"lint": "biome check .",
|
69
|
+
"lint:write": "biome check . --write",
|
59
70
|
"test": "jest --colors",
|
60
|
-
"
|
61
|
-
"api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
|
71
|
+
"release": "node ./scripts/release.mjs"
|
62
72
|
}
|
63
73
|
}
|