@rspack/plugin-react-refresh 1.0.0-beta.1 → 1.0.0-beta.3
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/dist/index.d.ts +1 -6
- package/dist/index.js +2 -7
- package/dist/sockets/WDSSocket.d.ts +7 -4
- package/dist/sockets/WDSSocket.js +9 -7
- package/dist/sockets/utils/getCurrentScriptSource.d.ts +1 -1
- package/dist/sockets/utils/getSocketUrlParts.js +3 -8
- package/dist/sockets/utils/getUrlFromParts.d.ts +4 -4
- package/dist/sockets/utils/getUrlFromParts.js +7 -10
- package/dist/sockets/utils/getWDSMetadata.d.ts +12 -1
- package/dist/utils/getAdditionalEntries.js +5 -10
- package/dist/utils/getSocketIntegration.d.ts +1 -1
- package/dist/utils/getSocketIntegration.js +2 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
import type { Compiler } from "@rspack/core";
|
2
|
-
import {
|
2
|
+
import type { NormalizedPluginOptions, PluginOptions } from "./options";
|
3
3
|
export type { PluginOptions };
|
4
|
-
/**
|
5
|
-
* @typedef {Object} Options
|
6
|
-
* @property {(string | RegExp | (string | RegExp)[] | null)=} include included resourcePath for loader
|
7
|
-
* @property {(string | RegExp | (string | RegExp)[] | null)=} exclude excluded resourcePath for loader
|
8
|
-
*/
|
9
4
|
declare class ReactRefreshRspackPlugin {
|
10
5
|
options: NormalizedPluginOptions;
|
11
6
|
static deprecated_runtimePaths: string[];
|
package/dist/index.js
CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
const node_path_1 = __importDefault(require("node:path"));
|
6
6
|
const options_1 = require("./options");
|
7
7
|
const getAdditionalEntries_1 = require("./utils/getAdditionalEntries");
|
8
|
-
const getSocketIntegration_1 =
|
8
|
+
const getSocketIntegration_1 = require("./utils/getSocketIntegration");
|
9
9
|
const reactRefreshPath = require.resolve("../client/reactRefresh.js");
|
10
10
|
const reactRefreshEntryPath = require.resolve("../client/reactRefreshEntry.js");
|
11
11
|
const refreshUtilsPath = require.resolve("../client/refreshUtils.js");
|
@@ -18,11 +18,6 @@ const runtimePaths = [
|
|
18
18
|
refreshUtilsPath,
|
19
19
|
refreshRuntimeDirPath
|
20
20
|
];
|
21
|
-
/**
|
22
|
-
* @typedef {Object} Options
|
23
|
-
* @property {(string | RegExp | (string | RegExp)[] | null)=} include included resourcePath for loader
|
24
|
-
* @property {(string | RegExp | (string | RegExp)[] | null)=} exclude excluded resourcePath for loader
|
25
|
-
*/
|
26
21
|
class ReactRefreshRspackPlugin {
|
27
22
|
constructor(options = {}) {
|
28
23
|
this.options = (0, options_1.normalizeOptions)(options);
|
@@ -81,7 +76,7 @@ class ReactRefreshRspackPlugin {
|
|
81
76
|
providedModules.__react_refresh_error_overlay__ = require.resolve(this.options.overlay.module);
|
82
77
|
}
|
83
78
|
if (this.options.overlay.sockIntegration) {
|
84
|
-
providedModules.__react_refresh_socket__ = (0, getSocketIntegration_1.
|
79
|
+
providedModules.__react_refresh_socket__ = (0, getSocketIntegration_1.getSocketIntegration)(this.options.overlay.sockIntegration);
|
85
80
|
}
|
86
81
|
}
|
87
82
|
new compiler.webpack.DefinePlugin(definedModules).apply(compiler);
|
@@ -1,10 +1,13 @@
|
|
1
|
+
import type { SocketClient } from "./utils/getWDSMetadata";
|
1
2
|
declare global {
|
2
|
-
var __webpack_dev_server_client__:
|
3
|
+
var __webpack_dev_server_client__: SocketClient | {
|
4
|
+
default: SocketClient;
|
5
|
+
};
|
3
6
|
}
|
4
7
|
/**
|
5
8
|
* Initializes a socket server for HMR for webpack-dev-server.
|
6
|
-
* @param
|
7
|
-
* @param
|
8
|
-
* @returns
|
9
|
+
* @param messageHandler A handler to consume Webpack compilation messages.
|
10
|
+
* @param resourceQuery Webpack's `__resourceQuery` string.
|
11
|
+
* @returns
|
9
12
|
*/
|
10
13
|
export declare function init(messageHandler: (...args: any[]) => void, resourceQuery: string): void;
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.init = void 0;
|
7
7
|
/**
|
8
8
|
* The following code is modified based on
|
9
|
-
* https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f1c8b9a44198449093ca95f85af5df97925e1cfc/sockets/
|
9
|
+
* https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f1c8b9a44198449093ca95f85af5df97925e1cfc/sockets/WDSSocket.js
|
10
10
|
*
|
11
11
|
* MIT Licensed
|
12
12
|
* Author Michael Mok
|
@@ -18,20 +18,22 @@ const getUrlFromParts_1 = __importDefault(require("./utils/getUrlFromParts"));
|
|
18
18
|
const getWDSMetadata_1 = __importDefault(require("./utils/getWDSMetadata"));
|
19
19
|
/**
|
20
20
|
* Initializes a socket server for HMR for webpack-dev-server.
|
21
|
-
* @param
|
22
|
-
* @param
|
23
|
-
* @returns
|
21
|
+
* @param messageHandler A handler to consume Webpack compilation messages.
|
22
|
+
* @param resourceQuery Webpack's `__resourceQuery` string.
|
23
|
+
* @returns
|
24
24
|
*/
|
25
25
|
function init(messageHandler, resourceQuery) {
|
26
26
|
if (typeof __webpack_dev_server_client__ !== "undefined") {
|
27
|
-
let SocketClient
|
28
|
-
if (
|
27
|
+
let SocketClient;
|
28
|
+
if ("default" in __webpack_dev_server_client__) {
|
29
29
|
SocketClient = __webpack_dev_server_client__.default;
|
30
30
|
}
|
31
|
+
else {
|
32
|
+
SocketClient = __webpack_dev_server_client__;
|
33
|
+
}
|
31
34
|
const wdsMeta = (0, getWDSMetadata_1.default)(SocketClient);
|
32
35
|
const urlParts = (0, getSocketUrlParts_1.default)(resourceQuery, wdsMeta);
|
33
36
|
const connection = new SocketClient((0, getUrlFromParts_1.default)(urlParts, wdsMeta));
|
34
|
-
// @ts-expect-error -- ignore
|
35
37
|
connection.onMessage(function onSocketMessage(data) {
|
36
38
|
const message = JSON.parse(data);
|
37
39
|
messageHandler(message);
|
@@ -1 +1 @@
|
|
1
|
-
export default function getCurrentScriptSource():
|
1
|
+
export default function getCurrentScriptSource(): string | null | undefined;
|
@@ -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;
|
@@ -24,7 +19,7 @@ function getSocketUrlParts(resourceQuery, metadata) {
|
|
24
19
|
urlParts.port = parsedQuery.sockPort;
|
25
20
|
// Make sure the protocol from resource query has a trailing colon
|
26
21
|
if (parsedQuery.sockProtocol) {
|
27
|
-
urlParts.protocol = parsedQuery.sockProtocol
|
22
|
+
urlParts.protocol = `${parsedQuery.sockProtocol}:`;
|
28
23
|
}
|
29
24
|
}
|
30
25
|
else {
|
@@ -47,7 +42,7 @@ function getSocketUrlParts(resourceQuery, metadata) {
|
|
47
42
|
// Result: <username> or <username>:<password>
|
48
43
|
urlParts.auth = url.username;
|
49
44
|
if (url.password) {
|
50
|
-
urlParts.auth +=
|
45
|
+
urlParts.auth += `:${url.password}`;
|
51
46
|
}
|
52
47
|
}
|
53
48
|
// `file://` URLs has `'null'` origin
|
@@ -2,8 +2,8 @@ import type { SocketUrlParts } from "./getSocketUrlParts";
|
|
2
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,14 +2,11 @@
|
|
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
|
-
if (typeof metadata === "undefined") {
|
11
|
-
metadata = {};
|
12
|
-
}
|
9
|
+
function urlFromParts(urlParts, metadata = {}) {
|
13
10
|
let fullProtocol = "http:";
|
14
11
|
if (urlParts.protocol) {
|
15
12
|
fullProtocol = urlParts.protocol;
|
@@ -17,14 +14,14 @@ function urlFromParts(urlParts, metadata) {
|
|
17
14
|
if (metadata.enforceWs) {
|
18
15
|
fullProtocol = fullProtocol.replace(/^(?:http|.+-extension|file)/i, "ws");
|
19
16
|
}
|
20
|
-
fullProtocol = fullProtocol
|
17
|
+
fullProtocol = `${fullProtocol}//`;
|
21
18
|
let fullHost = urlParts.hostname;
|
22
19
|
if (urlParts.auth) {
|
23
|
-
const fullAuth = urlParts.auth.split(":").map(encodeURIComponent).join(":")
|
20
|
+
const fullAuth = `${urlParts.auth.split(":").map(encodeURIComponent).join(":")}@`;
|
24
21
|
fullHost = fullAuth + fullHost;
|
25
22
|
}
|
26
23
|
if (urlParts.port) {
|
27
|
-
fullHost = fullHost
|
24
|
+
fullHost = `${fullHost}:${urlParts.port}`;
|
28
25
|
}
|
29
26
|
const url = new URL(urlParts.pathname, fullProtocol + fullHost);
|
30
27
|
return url.href;
|
@@ -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: any[]) => void): void;
|
9
|
+
onClose(f: (...args: any[]) => void): void;
|
10
|
+
onMessage(f: (...args: any[]) => void): void;
|
11
|
+
}
|
12
|
+
export interface SocketClient {
|
13
|
+
new (url: string): WebSocketClient;
|
14
|
+
}
|
15
|
+
export default function getWDSMetadata(SocketClient: SocketClient): WDSMetaObj;
|
16
|
+
export {};
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getAdditionalEntries = void 0;
|
7
7
|
const node_querystring_1 = __importDefault(require("node:querystring"));
|
8
8
|
function getAdditionalEntries({ devServer, options }) {
|
9
|
-
/** @type {Record<string, string | number>} */
|
10
9
|
const resourceQuery = {};
|
11
10
|
if (devServer) {
|
12
11
|
const { client, https, http2, sockHost, sockPath, sockPort } = devServer;
|
@@ -26,7 +25,7 @@ function getAdditionalEntries({ devServer, options }) {
|
|
26
25
|
if (parsedUrl.username) {
|
27
26
|
auth = parsedUrl.username;
|
28
27
|
if (parsedUrl.password) {
|
29
|
-
auth +=
|
28
|
+
auth += `:${parsedUrl.password}`;
|
30
29
|
}
|
31
30
|
}
|
32
31
|
if (parsedUrl.hostname != null) {
|
@@ -70,12 +69,8 @@ function getAdditionalEntries({ devServer, options }) {
|
|
70
69
|
}
|
71
70
|
// We don't need to URI encode the resourceQuery as it will be parsed by Webpack
|
72
71
|
const queryString = node_querystring_1.default.stringify(resourceQuery, undefined, undefined, {
|
73
|
-
|
74
|
-
|
75
|
-
* @returns {string}
|
76
|
-
*/
|
77
|
-
encodeURIComponent(string) {
|
78
|
-
return string;
|
72
|
+
encodeURIComponent(str) {
|
73
|
+
return str;
|
79
74
|
}
|
80
75
|
});
|
81
76
|
const prependEntries = [
|
@@ -84,8 +79,8 @@ function getAdditionalEntries({ devServer, options }) {
|
|
84
79
|
];
|
85
80
|
const overlayEntries = [
|
86
81
|
// Error overlay runtime
|
87
|
-
options.overlay &&
|
88
|
-
options.overlay
|
82
|
+
options.overlay !== false &&
|
83
|
+
options.overlay?.entry &&
|
89
84
|
`${require.resolve(options.overlay.entry)}${queryString ? `?${queryString}` : ""}`
|
90
85
|
].filter(Boolean);
|
91
86
|
return { prependEntries, overlayEntries };
|
@@ -1,2 +1,2 @@
|
|
1
1
|
export type IntegrationType = "wds";
|
2
|
-
export
|
2
|
+
export declare function getSocketIntegration(integrationType: IntegrationType): string;
|
@@ -1,5 +1,6 @@
|
|
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) {
|
@@ -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,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspack/plugin-react-refresh",
|
3
|
-
"version": "1.0.0-beta.
|
3
|
+
"version": "1.0.0-beta.3",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "React refresh plugin for rspack",
|
6
6
|
"main": "dist/index.js",
|
@@ -31,8 +31,8 @@
|
|
31
31
|
"devDependencies": {
|
32
32
|
"react-refresh": "^0.14.0",
|
33
33
|
"typescript": "5.0.2",
|
34
|
-
"@rspack/core": "1.0.0-beta.
|
35
|
-
"@rspack/plugin-react-refresh": "1.0.0-beta.
|
34
|
+
"@rspack/core": "1.0.0-beta.3",
|
35
|
+
"@rspack/plugin-react-refresh": "1.0.0-beta.3"
|
36
36
|
},
|
37
37
|
"dependencies": {
|
38
38
|
"error-stack-parser": "^2.0.6",
|