@rspack/plugin-react-refresh 1.0.1 → 1.0.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/README.md +2 -0
- package/dist/index.js +18 -6
- package/dist/options.d.ts +1 -1
- package/dist/sockets/WHMEventSource.d.ts +36 -0
- package/dist/sockets/WHMEventSource.js +34 -0
- package/dist/utils/getIntegrationEntry.d.ts +7 -0
- package/dist/utils/getIntegrationEntry.js +18 -0
- package/dist/utils/getSocketIntegration.d.ts +1 -1
- package/dist/utils/getSocketIntegration.js +4 -0
- package/package.json +9 -6
package/README.md
CHANGED
@@ -146,6 +146,8 @@ It is most useful when multiple instances of React Refresh is running together s
|
|
146
146
|
|
147
147
|
Modify the behavior of the error overlay.
|
148
148
|
|
149
|
+
Checkout [OverlayOptions](https://github.com/rspack-contrib/rspack-plugin-react-refresh/blob/main/src/options.ts#L4) type signature for more details.
|
150
|
+
|
149
151
|
- Enable the error overlay:
|
150
152
|
|
151
153
|
```js
|
package/dist/index.js
CHANGED
@@ -7,6 +7,18 @@ const options_1 = require("./options");
|
|
7
7
|
const paths_1 = require("./paths");
|
8
8
|
const getAdditionalEntries_1 = require("./utils/getAdditionalEntries");
|
9
9
|
const getSocketIntegration_1 = require("./utils/getSocketIntegration");
|
10
|
+
const getIntegrationEntry_1 = require("./utils/getIntegrationEntry");
|
11
|
+
function addEntry(entry, compiler) {
|
12
|
+
new compiler.webpack.EntryPlugin(compiler.context, entry, {
|
13
|
+
name: undefined,
|
14
|
+
}).apply(compiler);
|
15
|
+
}
|
16
|
+
function addSocketEntry(sockIntegration, compiler) {
|
17
|
+
const integrationEntry = (0, getIntegrationEntry_1.getIntegrationEntry)(sockIntegration);
|
18
|
+
if (integrationEntry) {
|
19
|
+
addEntry(integrationEntry, compiler);
|
20
|
+
}
|
21
|
+
}
|
10
22
|
class ReactRefreshRspackPlugin {
|
11
23
|
constructor(options = {}) {
|
12
24
|
this.options = (0, options_1.normalizeOptions)(options);
|
@@ -27,14 +39,14 @@ class ReactRefreshRspackPlugin {
|
|
27
39
|
options: this.options,
|
28
40
|
});
|
29
41
|
for (const entry of addEntries.prependEntries) {
|
30
|
-
|
31
|
-
|
32
|
-
|
42
|
+
addEntry(entry, compiler);
|
43
|
+
}
|
44
|
+
if (this.options.overlay !== false &&
|
45
|
+
this.options.overlay.sockIntegration) {
|
46
|
+
addSocketEntry(this.options.overlay.sockIntegration, compiler);
|
33
47
|
}
|
34
48
|
for (const entry of addEntries.overlayEntries) {
|
35
|
-
|
36
|
-
name: undefined,
|
37
|
-
}).apply(compiler);
|
49
|
+
addEntry(entry, compiler);
|
38
50
|
}
|
39
51
|
new compiler.webpack.ProvidePlugin({
|
40
52
|
$ReactRefreshRuntime$: paths_1.reactRefreshPath,
|
package/dist/options.d.ts
CHANGED
@@ -3,7 +3,7 @@ import type { IntegrationType } from './utils/getSocketIntegration';
|
|
3
3
|
interface OverlayOptions {
|
4
4
|
entry: string;
|
5
5
|
module: string;
|
6
|
-
sockIntegration: IntegrationType;
|
6
|
+
sockIntegration: IntegrationType | false;
|
7
7
|
sockHost?: string;
|
8
8
|
sockPath?: string;
|
9
9
|
sockPort?: string;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/**
|
2
|
+
* The following code is modified based on
|
3
|
+
* https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f770d3962c388da01eeda7079bff5f40c93992d2/sockets/WHMEventSource.js
|
4
|
+
*
|
5
|
+
* MIT Licensed
|
6
|
+
* Author Michael Mok
|
7
|
+
* Copyright (c) 2019 Michael Mok
|
8
|
+
* https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f770d3962c388da01eeda7079bff5f40c93992d2/LICENSE
|
9
|
+
*/
|
10
|
+
/**
|
11
|
+
* The hard-coded singleton key for webpack-hot-middleware's client instance.
|
12
|
+
*
|
13
|
+
* [Ref](https://github.com/webpack-contrib/webpack-hot-middleware/blob/cb29abb9dde435a1ac8e9b19f82d7d36b1093198/client.js#L152)
|
14
|
+
*/
|
15
|
+
declare const singletonKey = "__webpack_hot_middleware_reporter__";
|
16
|
+
interface WHMClient {
|
17
|
+
cleanProblemsCache: () => void;
|
18
|
+
problems: () => boolean;
|
19
|
+
success: () => void;
|
20
|
+
useCustomOverlay: (customOverlay: {
|
21
|
+
showProblems: (type: string, data: string[]) => void;
|
22
|
+
clear: () => void;
|
23
|
+
}) => void;
|
24
|
+
}
|
25
|
+
declare global {
|
26
|
+
interface Window {
|
27
|
+
[singletonKey]: WHMClient;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
/**
|
31
|
+
* Initializes a socket server for HMR for webpack-hot-middleware.
|
32
|
+
* @param {function(*): void} messageHandler A handler to consume Webpack compilation messages.
|
33
|
+
* @returns {void}
|
34
|
+
*/
|
35
|
+
export declare function init(messageHandler: (...args: unknown[]) => void): void;
|
36
|
+
export {};
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* The following code is modified based on
|
4
|
+
* https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f770d3962c388da01eeda7079bff5f40c93992d2/sockets/WHMEventSource.js
|
5
|
+
*
|
6
|
+
* MIT Licensed
|
7
|
+
* Author Michael Mok
|
8
|
+
* Copyright (c) 2019 Michael Mok
|
9
|
+
* https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f770d3962c388da01eeda7079bff5f40c93992d2/LICENSE
|
10
|
+
*/
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.init = init;
|
13
|
+
/**
|
14
|
+
* The hard-coded singleton key for webpack-hot-middleware's client instance.
|
15
|
+
*
|
16
|
+
* [Ref](https://github.com/webpack-contrib/webpack-hot-middleware/blob/cb29abb9dde435a1ac8e9b19f82d7d36b1093198/client.js#L152)
|
17
|
+
*/
|
18
|
+
const singletonKey = '__webpack_hot_middleware_reporter__';
|
19
|
+
/**
|
20
|
+
* Initializes a socket server for HMR for webpack-hot-middleware.
|
21
|
+
* @param {function(*): void} messageHandler A handler to consume Webpack compilation messages.
|
22
|
+
* @returns {void}
|
23
|
+
*/
|
24
|
+
function init(messageHandler) {
|
25
|
+
const client = window[singletonKey];
|
26
|
+
client.useCustomOverlay({
|
27
|
+
showProblems(type, data) {
|
28
|
+
messageHandler({ type, data });
|
29
|
+
},
|
30
|
+
clear() {
|
31
|
+
messageHandler({ type: 'ok' });
|
32
|
+
},
|
33
|
+
});
|
34
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { IntegrationType } from './getSocketIntegration';
|
2
|
+
/**
|
3
|
+
* Gets entry point of a supported socket integration.
|
4
|
+
* @param integrationType A valid socket integration type or a path to a module.
|
5
|
+
* @returns Path to the resolved integration entry point.
|
6
|
+
*/
|
7
|
+
export declare function getIntegrationEntry(integrationType: IntegrationType): string | undefined;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getIntegrationEntry = getIntegrationEntry;
|
4
|
+
/**
|
5
|
+
* Gets entry point of a supported socket integration.
|
6
|
+
* @param integrationType A valid socket integration type or a path to a module.
|
7
|
+
* @returns Path to the resolved integration entry point.
|
8
|
+
*/
|
9
|
+
function getIntegrationEntry(integrationType) {
|
10
|
+
let resolvedEntry;
|
11
|
+
switch (integrationType) {
|
12
|
+
case 'whm': {
|
13
|
+
resolvedEntry = 'webpack-hot-middleware/client';
|
14
|
+
break;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
return resolvedEntry;
|
18
|
+
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export type IntegrationType = 'wds';
|
1
|
+
export type IntegrationType = 'wds' | 'whm' | (string & {});
|
2
2
|
export declare function getSocketIntegration(integrationType: IntegrationType): string;
|
@@ -8,6 +8,10 @@ function getSocketIntegration(integrationType) {
|
|
8
8
|
resolvedSocketIntegration = require.resolve('../sockets/WDSSocket');
|
9
9
|
break;
|
10
10
|
}
|
11
|
+
case 'whm': {
|
12
|
+
resolvedSocketIntegration = require.resolve('../sockets/WHMEventSource');
|
13
|
+
break;
|
14
|
+
}
|
11
15
|
default: {
|
12
16
|
resolvedSocketIntegration = require.resolve(integrationType);
|
13
17
|
break;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspack/plugin-react-refresh",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
4
4
|
"repository": "https://github.com/rspack-contrib/rspack-plugin-react-refresh",
|
5
5
|
"license": "MIT",
|
6
6
|
"description": "React refresh plugin for rspack",
|
@@ -30,9 +30,8 @@
|
|
30
30
|
"devDependencies": {
|
31
31
|
"@biomejs/biome": "^1.9.4",
|
32
32
|
"@rspack/core": "1.1.4",
|
33
|
-
"@types/node": "^22.10.1",
|
34
33
|
"@types/jest": "29.5.14",
|
35
|
-
"
|
34
|
+
"@types/node": "^22.10.1",
|
36
35
|
"cross-env": "^7.0.3",
|
37
36
|
"execa": "9.5.1",
|
38
37
|
"fs-extra": "11.2.0",
|
@@ -40,20 +39,24 @@
|
|
40
39
|
"jest-cli": "29.7.0",
|
41
40
|
"jest-environment-node": "29.7.0",
|
42
41
|
"nano-staged": "^0.8.0",
|
42
|
+
"react-refresh": "^0.14.2",
|
43
43
|
"semver": "7.6.3",
|
44
44
|
"simple-git-hooks": "^2.11.1",
|
45
45
|
"ts-jest": "29.2.5",
|
46
|
-
"
|
46
|
+
"ts-node": "^10.9.2",
|
47
|
+
"typescript": "5.7.2",
|
48
|
+
"@continuous-auth/client": "2.3.2"
|
47
49
|
},
|
48
50
|
"dependencies": {
|
49
51
|
"error-stack-parser": "^2.1.4",
|
50
52
|
"html-entities": "^2.5.2"
|
51
53
|
},
|
52
54
|
"peerDependencies": {
|
53
|
-
"react-refresh": ">=0.10.0 <1.0.0"
|
55
|
+
"react-refresh": ">=0.10.0 <1.0.0",
|
56
|
+
"webpack-hot-middleware": "2.x"
|
54
57
|
},
|
55
58
|
"peerDependenciesMeta": {
|
56
|
-
"
|
59
|
+
"webpack-hot-middleware": {
|
57
60
|
"optional": true
|
58
61
|
}
|
59
62
|
},
|