@rspack/plugin-react-refresh 1.5.1 → 1.5.2

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 CHANGED
@@ -3,7 +3,10 @@ import type { NormalizedPluginOptions, PluginOptions } from './options';
3
3
  export type { PluginOptions };
4
4
  declare class ReactRefreshRspackPlugin {
5
5
  options: NormalizedPluginOptions;
6
- static deprecated_runtimePaths: string[];
6
+ /**
7
+ * @deprecated
8
+ */
9
+ static get deprecated_runtimePaths(): string[];
7
10
  static loader: string;
8
11
  constructor(options?: PluginOptions);
9
12
  apply(compiler: Compiler): void;
package/dist/index.js CHANGED
@@ -1,117 +1,255 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __webpack_require__ = {};
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 ('undefined' != 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);
41
+ const d = (object, property, defaultValue)=>{
42
+ if (void 0 === object[property] && void 0 !== defaultValue) object[property] = defaultValue;
43
+ return object[property];
4
44
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ReactRefreshRspackPlugin = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const options_1 = require("./options");
9
- const paths_1 = require("./paths");
10
- const getAdditionalEntries_1 = require("./utils/getAdditionalEntries");
11
- const getSocketIntegration_1 = require("./utils/getSocketIntegration");
12
- const getIntegrationEntry_1 = require("./utils/getIntegrationEntry");
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
+ function normalizeOptions(options) {
59
+ d(options, 'exclude', /node_modules/i);
60
+ d(options, 'include', /\.([cm]js|[jt]sx?|flow)$/i);
61
+ d(options, 'library');
62
+ d(options, 'forceEnable', false);
63
+ d(options, 'injectLoader', true);
64
+ d(options, 'injectEntry', true);
65
+ d(options, 'reloadOnRuntimeErrors', false);
66
+ options.overlay = normalizeOverlay(options.overlay);
67
+ return options;
68
+ }
69
+ const reactRefreshPath = external_node_path_default().join(__dirname, '../client/reactRefresh.js');
70
+ const reactRefreshEntryPath = external_node_path_default().join(__dirname, '../client/reactRefreshEntry.js');
71
+ const refreshUtilsPath = external_node_path_default().join(__dirname, '../client/refreshUtils.js');
72
+ let refreshRuntimeDirPath;
73
+ function getRefreshRuntimeDirPath() {
74
+ if (!refreshRuntimeDirPath) refreshRuntimeDirPath = external_node_path_default().dirname(require.resolve('react-refresh', {
75
+ paths: [
76
+ reactRefreshPath
77
+ ]
78
+ }));
79
+ return refreshRuntimeDirPath;
80
+ }
81
+ const getRefreshRuntimePaths = ()=>[
82
+ reactRefreshEntryPath,
83
+ reactRefreshPath,
84
+ refreshUtilsPath,
85
+ getRefreshRuntimeDirPath()
86
+ ];
87
+ const external_node_querystring_namespaceObject = require("node:querystring");
88
+ var external_node_querystring_default = /*#__PURE__*/ __webpack_require__.n(external_node_querystring_namespaceObject);
89
+ function getAdditionalEntries({ devServer, options }) {
90
+ const resourceQuery = {};
91
+ if (devServer) {
92
+ const { client, https, http2, sockHost, sockPath, sockPort } = devServer;
93
+ let { host, path, port } = devServer;
94
+ let protocol = https || http2 ? 'https' : 'http';
95
+ if (sockHost) host = sockHost;
96
+ if (sockPath) path = sockPath;
97
+ if (sockPort) port = sockPort;
98
+ if (client && null != client.webSocketURL) {
99
+ let parsedUrl = client.webSocketURL;
100
+ if ('string' == typeof parsedUrl) parsedUrl = new URL(parsedUrl);
101
+ let auth;
102
+ if (parsedUrl.username) {
103
+ auth = parsedUrl.username;
104
+ if (parsedUrl.password) auth += `:${parsedUrl.password}`;
105
+ }
106
+ if (null != parsedUrl.hostname) host = [
107
+ null != auth && auth,
108
+ parsedUrl.hostname
109
+ ].filter(Boolean).join('@');
110
+ if (null != parsedUrl.pathname) path = parsedUrl.pathname;
111
+ if (null != parsedUrl.port) port = [
112
+ '0',
113
+ 'auto'
114
+ ].includes(String(parsedUrl.port)) ? void 0 : parsedUrl.port;
115
+ if (null != parsedUrl.protocol) protocol = 'auto' !== parsedUrl.protocol ? parsedUrl.protocol.replace(':', '') : 'ws';
116
+ }
117
+ if (host) resourceQuery.sockHost = host;
118
+ if (path) resourceQuery.sockPath = path;
119
+ if (port) resourceQuery.sockPort = port;
120
+ resourceQuery.sockProtocol = protocol;
121
+ }
122
+ if (options.overlay) {
123
+ const { sockHost, sockPath, sockPort, sockProtocol } = options.overlay;
124
+ if (sockHost) resourceQuery.sockHost = sockHost;
125
+ if (sockPath) resourceQuery.sockPath = sockPath;
126
+ if (sockPort) resourceQuery.sockPort = sockPort;
127
+ if (sockProtocol) resourceQuery.sockProtocol = sockProtocol;
128
+ }
129
+ const queryString = external_node_querystring_default().stringify(resourceQuery, void 0, void 0, {
130
+ encodeURIComponent (str) {
131
+ return str;
132
+ }
133
+ });
134
+ const prependEntries = [
135
+ reactRefreshEntryPath
136
+ ];
137
+ const overlayEntries = [
138
+ false !== options.overlay && options.overlay?.entry && `${require.resolve(options.overlay.entry)}${queryString ? `?${queryString}` : ''}`
139
+ ].filter(Boolean);
140
+ return {
141
+ prependEntries,
142
+ overlayEntries
143
+ };
144
+ }
145
+ function getIntegrationEntry(integrationType) {
146
+ let resolvedEntry;
147
+ switch(integrationType){
148
+ case 'whm':
149
+ resolvedEntry = 'webpack-hot-middleware/client';
150
+ break;
151
+ }
152
+ return resolvedEntry;
153
+ }
154
+ function getSocketIntegration(integrationType) {
155
+ let resolvedSocketIntegration;
156
+ switch(integrationType){
157
+ case 'wds':
158
+ resolvedSocketIntegration = external_node_path_default().join(__dirname, './sockets/WDSSocket.js');
159
+ break;
160
+ case 'whm':
161
+ resolvedSocketIntegration = external_node_path_default().join(__dirname, './sockets/WHMEventSource.js');
162
+ break;
163
+ default:
164
+ resolvedSocketIntegration = require.resolve(integrationType);
165
+ break;
166
+ }
167
+ return resolvedSocketIntegration;
168
+ }
13
169
  function addEntry(entry, compiler) {
14
170
  new compiler.webpack.EntryPlugin(compiler.context, entry, {
15
- name: undefined,
171
+ name: void 0
16
172
  }).apply(compiler);
17
173
  }
18
174
  function addSocketEntry(sockIntegration, compiler) {
19
- const integrationEntry = (0, getIntegrationEntry_1.getIntegrationEntry)(sockIntegration);
20
- if (integrationEntry) {
21
- addEntry(integrationEntry, compiler);
22
- }
175
+ const integrationEntry = getIntegrationEntry(sockIntegration);
176
+ if (integrationEntry) addEntry(integrationEntry, compiler);
23
177
  }
24
178
  const PLUGIN_NAME = 'ReactRefreshRspackPlugin';
25
179
  class ReactRefreshRspackPlugin {
26
- constructor(options = {}) {
27
- this.options = (0, options_1.normalizeOptions)(options);
180
+ options;
181
+ static get deprecated_runtimePaths() {
182
+ return getRefreshRuntimePaths();
183
+ }
184
+ static loader = 'builtin:react-refresh-loader';
185
+ constructor(options = {}){
186
+ this.options = normalizeOptions(options);
28
187
  }
29
188
  apply(compiler) {
30
- 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
33
- (compiler.options.mode !== 'development' ||
34
- // We also check for production process.env.NODE_ENV,
35
- // in case it was set and mode is non-development (e.g. 'none')
36
- (process.env.NODE_ENV && process.env.NODE_ENV === 'production')) &&
37
- !this.options.forceEnable) {
38
- return;
39
- }
40
- const addEntries = (0, getAdditionalEntries_1.getAdditionalEntries)({
189
+ if (('development' !== compiler.options.mode || process.env.NODE_ENV && 'production' === process.env.NODE_ENV) && !this.options.forceEnable) return;
190
+ const addEntries = getAdditionalEntries({
41
191
  devServer: compiler.options.devServer,
42
- options: this.options,
192
+ options: this.options
43
193
  });
44
- if (this.options.injectEntry) {
45
- for (const entry of addEntries.prependEntries) {
46
- addEntry(entry, compiler);
47
- }
48
- }
49
- if (this.options.overlay !== false &&
50
- this.options.overlay.sockIntegration) {
51
- addSocketEntry(this.options.overlay.sockIntegration, compiler);
52
- }
53
- for (const entry of addEntries.overlayEntries) {
54
- addEntry(entry, compiler);
55
- }
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);
56
197
  new compiler.webpack.ProvidePlugin({
57
- $ReactRefreshRuntime$: paths_1.reactRefreshPath,
198
+ $ReactRefreshRuntime$: reactRefreshPath
58
199
  }).apply(compiler);
59
- if (this.options.injectLoader) {
60
- compiler.options.module.rules.unshift({
61
- test: this.options.test,
62
- // biome-ignore lint: exists
63
- include: this.options.include,
64
- exclude: {
65
- // biome-ignore lint: exists
66
- or: [this.options.exclude, [...paths_1.runtimePaths]].filter(Boolean),
67
- },
68
- resourceQuery: this.options.resourceQuery,
69
- dependency: {
70
- // `new URL("static/sdk.js", import.meta.url)` the sdk.js is an asset module
71
- // we shoudn't inject react refresh for asset module
72
- not: ['url'],
73
- },
74
- use: ReactRefreshRspackPlugin.loader,
75
- });
76
- }
200
+ if (this.options.injectLoader) compiler.options.module.rules.unshift({
201
+ test: this.options.test,
202
+ include: this.options.include,
203
+ exclude: {
204
+ or: [
205
+ this.options.exclude,
206
+ [
207
+ ...getRefreshRuntimePaths()
208
+ ]
209
+ ].filter(Boolean)
210
+ },
211
+ resourceQuery: this.options.resourceQuery,
212
+ dependency: {
213
+ not: [
214
+ 'url'
215
+ ]
216
+ },
217
+ use: ReactRefreshRspackPlugin.loader
218
+ });
77
219
  const definedModules = {
78
- // For Multiple Instance Mode
79
- __react_refresh_library__: JSON.stringify(compiler.webpack.Template.toIdentifier(this.options.library ||
80
- compiler.options.output.uniqueName ||
81
- compiler.options.output.library)),
82
- __reload_on_runtime_errors__: this.options.reloadOnRuntimeErrors,
220
+ __react_refresh_library__: JSON.stringify(compiler.webpack.Template.toIdentifier(this.options.library || compiler.options.output.uniqueName || compiler.options.output.library)),
221
+ __reload_on_runtime_errors__: this.options.reloadOnRuntimeErrors
83
222
  };
84
223
  const providedModules = {
85
- __react_refresh_utils__: paths_1.refreshUtilsPath,
224
+ __react_refresh_utils__: refreshUtilsPath
86
225
  };
87
- if (this.options.overlay === false) {
88
- // Stub errorOverlay module so their calls can be erased
226
+ if (false === this.options.overlay) {
89
227
  definedModules.__react_refresh_error_overlay__ = false;
90
228
  definedModules.__react_refresh_socket__ = false;
91
- }
92
- else {
93
- if (this.options.overlay.module) {
94
- providedModules.__react_refresh_error_overlay__ = require.resolve(this.options.overlay.module);
95
- }
96
- if (this.options.overlay.sockIntegration) {
97
- providedModules.__react_refresh_socket__ = (0, getSocketIntegration_1.getSocketIntegration)(this.options.overlay.sockIntegration);
98
- }
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);
99
232
  }
100
233
  new compiler.webpack.DefinePlugin(definedModules).apply(compiler);
101
234
  new compiler.webpack.ProvidePlugin(providedModules).apply(compiler);
102
- const refreshPath = node_path_1.default.dirname(require.resolve('react-refresh'));
103
235
  compiler.options.resolve.alias = {
104
- 'react-refresh': refreshPath,
105
- ...compiler.options.resolve.alias,
236
+ 'react-refresh': getRefreshRuntimeDirPath(),
237
+ ...compiler.options.resolve.alias
106
238
  };
107
- compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
108
- compilation.hooks.additionalTreeRuntimeRequirements.tap(PLUGIN_NAME, (_, runtimeRequirements) => {
239
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation)=>{
240
+ compilation.hooks.additionalTreeRuntimeRequirements.tap(PLUGIN_NAME, (_, runtimeRequirements)=>{
109
241
  runtimeRequirements.add(compiler.rspack.RuntimeGlobals.moduleCache);
110
242
  });
111
243
  });
112
244
  }
113
245
  }
114
- exports.ReactRefreshRspackPlugin = ReactRefreshRspackPlugin;
115
- ReactRefreshRspackPlugin.deprecated_runtimePaths = paths_1.runtimePaths;
116
- ReactRefreshRspackPlugin.loader = 'builtin:react-refresh-loader';
117
- exports.default = ReactRefreshRspackPlugin;
246
+ const src = ReactRefreshRspackPlugin;
247
+ exports.ReactRefreshRspackPlugin = __webpack_exports__.ReactRefreshRspackPlugin;
248
+ exports["default"] = __webpack_exports__["default"];
249
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
250
+ "ReactRefreshRspackPlugin",
251
+ "default"
252
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
253
+ Object.defineProperty(exports, '__esModule', {
254
+ value: true
255
+ });
package/dist/paths.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare const reactRefreshPath: string;
2
2
  export declare const reactRefreshEntryPath: string;
3
3
  export declare const refreshUtilsPath: string;
4
- export declare const refreshRuntimeDirPath: string;
5
- export declare const runtimePaths: string[];
4
+ export declare function getRefreshRuntimeDirPath(): string;
5
+ export declare const getRefreshRuntimePaths: () => string[];
@@ -1,42 +1,63 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.init = init;
7
- /**
8
- * The following code is modified based on
9
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f1c8b9a44198449093ca95f85af5df97925e1cfc/sockets/WDSSocket.js
10
- *
11
- * MIT Licensed
12
- * Author Michael Mok
13
- * Copyright (c) 2019 Michael Mok
14
- * https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/0b960573797bf38926937994c481e4fec9ed8aa6/LICENSE
15
- */
16
- const getSocketUrlParts_1 = __importDefault(require("./utils/getSocketUrlParts"));
17
- const getUrlFromParts_1 = __importDefault(require("./utils/getUrlFromParts"));
18
- const getWDSMetadata_1 = __importDefault(require("./utils/getWDSMetadata"));
19
- /**
20
- * Initializes a socket server for HMR for webpack-dev-server.
21
- * @param messageHandler A handler to consume Webpack compilation messages.
22
- * @param resourceQuery Webpack's `__resourceQuery` string.
23
- * @returns
24
- */
2
+ var __webpack_require__ = {};
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 ('undefined' != 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
+ init: ()=>init
37
+ });
38
+ const getSocketUrlParts_js_namespaceObject = require("./utils/getSocketUrlParts.js");
39
+ var getSocketUrlParts_js_default = /*#__PURE__*/ __webpack_require__.n(getSocketUrlParts_js_namespaceObject);
40
+ const getUrlFromParts_js_namespaceObject = require("./utils/getUrlFromParts.js");
41
+ var getUrlFromParts_js_default = /*#__PURE__*/ __webpack_require__.n(getUrlFromParts_js_namespaceObject);
42
+ const getWDSMetadata_js_namespaceObject = require("./utils/getWDSMetadata.js");
43
+ var getWDSMetadata_js_default = /*#__PURE__*/ __webpack_require__.n(getWDSMetadata_js_namespaceObject);
25
44
  function init(messageHandler, resourceQuery) {
26
- if (typeof __webpack_dev_server_client__ !== 'undefined') {
45
+ if ('undefined' != typeof __webpack_dev_server_client__) {
27
46
  let SocketClient;
28
- if ('default' in __webpack_dev_server_client__) {
29
- SocketClient = __webpack_dev_server_client__.default;
30
- }
31
- else {
32
- SocketClient = __webpack_dev_server_client__;
33
- }
34
- const wdsMeta = (0, getWDSMetadata_1.default)(SocketClient);
35
- const urlParts = (0, getSocketUrlParts_1.default)(resourceQuery, wdsMeta);
36
- const connection = new SocketClient((0, getUrlFromParts_1.default)(urlParts, wdsMeta));
37
- connection.onMessage(function onSocketMessage(data) {
47
+ SocketClient = 'default' in __webpack_dev_server_client__ ? __webpack_dev_server_client__.default : __webpack_dev_server_client__;
48
+ const wdsMeta = getWDSMetadata_js_default()(SocketClient);
49
+ const urlParts = getSocketUrlParts_js_default()(resourceQuery, wdsMeta);
50
+ const connection = new SocketClient(getUrlFromParts_js_default()(urlParts, wdsMeta));
51
+ connection.onMessage(function(data) {
38
52
  const message = JSON.parse(data);
39
53
  messageHandler(message);
40
54
  });
41
55
  }
42
56
  }
57
+ exports.init = __webpack_exports__.init;
58
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
59
+ "init"
60
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
61
+ Object.defineProperty(exports, '__esModule', {
62
+ value: true
63
+ });
@@ -1,34 +1,52 @@
1
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
- */
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ init: ()=>init
28
+ });
18
29
  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
30
  function init(messageHandler) {
25
31
  const client = window[singletonKey];
26
32
  client.useCustomOverlay({
27
- showProblems(type, data) {
28
- messageHandler({ type, data });
29
- },
30
- clear() {
31
- messageHandler({ type: 'ok' });
33
+ showProblems (type, data) {
34
+ messageHandler({
35
+ type,
36
+ data
37
+ });
32
38
  },
39
+ clear () {
40
+ messageHandler({
41
+ type: 'ok'
42
+ });
43
+ }
33
44
  });
34
45
  }
46
+ exports.init = __webpack_exports__.init;
47
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
48
+ "init"
49
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
50
+ Object.defineProperty(exports, '__esModule', {
51
+ value: true
52
+ });
@@ -1,22 +1,45 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = getCurrentScriptSource;
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ default: ()=>getCurrentScriptSource
28
+ });
4
29
  function getCurrentScriptSource() {
5
- // `document.currentScript` is the most accurate way to get the current running script,
6
- // but is not supported in all browsers (most notably, IE).
7
30
  if ('currentScript' in document) {
8
- // In some cases, `document.currentScript` would be `null` even if the browser supports it:
9
- // e.g. asynchronous chunks on Firefox.
10
- // We should not fallback to the list-approach as it would not be safe.
11
- if (document.currentScript == null)
12
- return;
31
+ if (null == document.currentScript) return;
13
32
  return document.currentScript.getAttribute('src');
14
33
  }
15
- // Fallback to getting all scripts running in the document,
16
- // and finding the last one injected.
17
- const scriptElementsWithSrc = Array.prototype.filter.call(document.scripts || [], (elem) => elem.getAttribute('src'));
18
- if (!scriptElementsWithSrc.length)
19
- return;
34
+ const scriptElementsWithSrc = Array.prototype.filter.call(document.scripts || [], (elem)=>elem.getAttribute('src'));
35
+ if (!scriptElementsWithSrc.length) return;
20
36
  const currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
21
37
  return currentScript.getAttribute('src');
22
38
  }
39
+ exports["default"] = __webpack_exports__["default"];
40
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
41
+ "default"
42
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
43
+ Object.defineProperty(exports, '__esModule', {
44
+ value: true
45
+ });
@@ -1,108 +1,87 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = getSocketUrlParts;
7
- const getCurrentScriptSource_1 = __importDefault(require("./getCurrentScriptSource"));
2
+ var __webpack_require__ = {};
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 ('undefined' != 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
+ default: ()=>getSocketUrlParts
37
+ });
38
+ const external_getCurrentScriptSource_js_namespaceObject = require("./getCurrentScriptSource.js");
39
+ var external_getCurrentScriptSource_js_default = /*#__PURE__*/ __webpack_require__.n(external_getCurrentScriptSource_js_namespaceObject);
8
40
  function getSocketUrlParts(resourceQuery, metadata = {}) {
9
41
  const urlParts = {};
10
- // If the resource query is available,
11
- // parse it and ignore everything we received from the script host.
12
42
  if (resourceQuery) {
13
43
  const parsedQuery = {};
14
44
  const searchParams = new URLSearchParams(resourceQuery.slice(1));
15
- searchParams.forEach((value, key) => {
45
+ searchParams.forEach((value, key)=>{
16
46
  parsedQuery[key] = value;
17
47
  });
18
48
  urlParts.hostname = parsedQuery.sockHost;
19
49
  urlParts.pathname = parsedQuery.sockPath;
20
50
  urlParts.port = parsedQuery.sockPort;
21
- // Make sure the protocol from resource query has a trailing colon
22
- if (parsedQuery.sockProtocol) {
23
- urlParts.protocol = `${parsedQuery.sockProtocol}:`;
24
- }
25
- }
26
- else {
27
- const scriptSource = (0, getCurrentScriptSource_1.default)();
51
+ if (parsedQuery.sockProtocol) urlParts.protocol = `${parsedQuery.sockProtocol}:`;
52
+ } else {
53
+ const scriptSource = external_getCurrentScriptSource_js_default()();
28
54
  let url = {};
29
55
  try {
30
- // The placeholder `baseURL` with `window.location.href`,
31
- // is to allow parsing of path-relative or protocol-relative URLs,
32
- // and will have no effect if `scriptSource` is a fully valid URL.
33
- // biome-ignore lint: reason
34
56
  url = new URL(scriptSource, window.location.href);
35
- }
36
- catch (e) {
37
- // URL parsing failed, do nothing.
38
- // We will still proceed to see if we can recover using `resourceQuery`
39
- }
40
- // Parse authentication credentials in case we need them
57
+ } catch (e) {}
41
58
  if (url.username) {
42
- // Since HTTP basic authentication does not allow empty username,
43
- // we only include password if the username is not empty.
44
- // Result: <username> or <username>:<password>
45
59
  urlParts.auth = url.username;
46
- if (url.password) {
47
- urlParts.auth += `:${url.password}`;
48
- }
49
- }
50
- // `file://` URLs has `'null'` origin
51
- if (url.origin !== 'null') {
52
- urlParts.hostname = url.hostname;
60
+ if (url.password) urlParts.auth += `:${url.password}`;
53
61
  }
62
+ if ('null' !== url.origin) urlParts.hostname = url.hostname;
54
63
  urlParts.protocol = url.protocol;
55
64
  urlParts.port = url.port;
56
65
  }
57
- if (!urlParts.pathname) {
58
- if (metadata.version === 4) {
59
- // This is hard-coded in WDS v4
60
- urlParts.pathname = '/ws';
61
- }
62
- else {
63
- // This is hard-coded in WDS v3
64
- urlParts.pathname = '/sockjs-node';
65
- }
66
- }
67
- // Check for IPv4 and IPv6 host addresses that correspond to any/empty.
68
- // This is important because `hostname` can be empty for some hosts,
69
- // such as 'about:blank' or 'file://' URLs.
70
- const isEmptyHostname = urlParts.hostname === '0.0.0.0' ||
71
- urlParts.hostname === '[::]' ||
72
- !urlParts.hostname;
73
- // We only re-assign the hostname if it is empty,
74
- // and if we are using HTTP/HTTPS protocols.
75
- if (isEmptyHostname &&
76
- window.location.hostname &&
77
- window.location.protocol.indexOf('http') === 0) {
78
- urlParts.hostname = window.location.hostname;
79
- }
80
- // We only re-assign `protocol` when `protocol` is unavailable,
81
- // or if `hostname` is available and is empty,
82
- // since otherwise we risk creating an invalid URL.
83
- // We also do this when 'https' is used as it mandates the use of secure sockets.
84
- if (!urlParts.protocol ||
85
- (urlParts.hostname &&
86
- (isEmptyHostname || window.location.protocol === 'https:'))) {
87
- urlParts.protocol = window.location.protocol;
88
- }
89
- // We only re-assign port when it is not available
90
- if (!urlParts.port) {
91
- urlParts.port = window.location.port;
92
- }
93
- if (!urlParts.hostname || !urlParts.pathname) {
94
- throw new Error([
95
- '[React Refresh] Failed to get an URL for the socket connection.',
96
- "This usually means that the current executed script doesn't have a `src` attribute set.",
97
- 'You should either specify the socket path parameters under the `devServer` key in your Rspack config, or use the `overlay` option.',
98
- 'https://www.rspack.dev/guide/tech/react#fast-refresh',
99
- ].join('\n'));
100
- }
66
+ if (!urlParts.pathname) if (4 === metadata.version) urlParts.pathname = '/ws';
67
+ else urlParts.pathname = '/sockjs-node';
68
+ const isEmptyHostname = '0.0.0.0' === urlParts.hostname || '[::]' === urlParts.hostname || !urlParts.hostname;
69
+ if (isEmptyHostname && window.location.hostname && 0 === window.location.protocol.indexOf('http')) urlParts.hostname = window.location.hostname;
70
+ if (!urlParts.protocol || urlParts.hostname && (isEmptyHostname || 'https:' === window.location.protocol)) urlParts.protocol = window.location.protocol;
71
+ if (!urlParts.port) urlParts.port = window.location.port;
72
+ if (!urlParts.hostname || !urlParts.pathname) throw new Error("[React Refresh] Failed to get an URL for the socket connection.\nThis usually means that the current executed script doesn't have a `src` attribute set.\nYou should either specify the socket path parameters under the `devServer` key in your Rspack config, or use the `overlay` option.\nhttps://www.rspack.dev/guide/tech/react#fast-refresh");
101
73
  return {
102
74
  auth: urlParts.auth,
103
75
  hostname: urlParts.hostname,
104
76
  pathname: urlParts.pathname,
105
77
  protocol: urlParts.protocol,
106
- port: urlParts.port || undefined,
78
+ port: urlParts.port || void 0
107
79
  };
108
80
  }
81
+ exports["default"] = __webpack_exports__["default"];
82
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
83
+ "default"
84
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
85
+ Object.defineProperty(exports, '__esModule', {
86
+ value: true
87
+ });
@@ -1,29 +1,49 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = urlFromParts;
4
- /**
5
- * Create a valid URL from parsed URL parts.
6
- * @param urlParts The parsed URL parts.
7
- * @param metadata The parsed WDS metadata object.
8
- * @returns The generated URL.
9
- */
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ default: ()=>urlFromParts
28
+ });
10
29
  function urlFromParts(urlParts, metadata = {}) {
11
30
  let fullProtocol = 'http:';
12
- if (urlParts.protocol) {
13
- fullProtocol = urlParts.protocol;
14
- }
15
- if (metadata.enforceWs) {
16
- fullProtocol = fullProtocol.replace(/^(?:http|.+-extension|file)/i, 'ws');
17
- }
31
+ if (urlParts.protocol) fullProtocol = urlParts.protocol;
32
+ if (metadata.enforceWs) fullProtocol = fullProtocol.replace(/^(?:http|.+-extension|file)/i, 'ws');
18
33
  fullProtocol = `${fullProtocol}//`;
19
34
  let fullHost = urlParts.hostname;
20
35
  if (urlParts.auth) {
21
36
  const fullAuth = `${urlParts.auth.split(':').map(encodeURIComponent).join(':')}@`;
22
37
  fullHost = fullAuth + fullHost;
23
38
  }
24
- if (urlParts.port) {
25
- fullHost = `${fullHost}:${urlParts.port}`;
26
- }
39
+ if (urlParts.port) fullHost = `${fullHost}:${urlParts.port}`;
27
40
  const url = new URL(urlParts.pathname, fullProtocol + fullHost);
28
41
  return url.href;
29
42
  }
43
+ exports["default"] = __webpack_exports__["default"];
44
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
45
+ "default"
46
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
47
+ Object.defineProperty(exports, '__esModule', {
48
+ value: true
49
+ });
@@ -1,30 +1,45 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = getWDSMetadata;
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ default: ()=>getWDSMetadata
28
+ });
4
29
  function getWDSMetadata(SocketClient) {
5
30
  let enforceWs = false;
6
- if (typeof SocketClient.name !== 'undefined' &&
7
- SocketClient.name !== null &&
8
- SocketClient.name.toLowerCase().includes('websocket')) {
9
- enforceWs = true;
10
- }
31
+ if (void 0 !== SocketClient.name && null !== SocketClient.name && SocketClient.name.toLowerCase().includes('websocket')) enforceWs = true;
11
32
  let version;
12
- // WDS versions <=3.5.0
13
- if (!('onMessage' in SocketClient.prototype)) {
14
- version = 3;
15
- }
16
- else {
17
- // WDS versions >=3.5.0 <4
18
- if ('getClientPath' in SocketClient ||
19
- Object.getPrototypeOf(SocketClient).name === 'BaseClient') {
20
- version = 3;
21
- }
22
- else {
23
- version = 4;
24
- }
25
- }
33
+ version = 'onMessage' in SocketClient.prototype ? 'getClientPath' in SocketClient || 'BaseClient' === Object.getPrototypeOf(SocketClient).name ? 3 : 4 : 3;
26
34
  return {
27
35
  enforceWs: enforceWs,
28
- version: version,
36
+ version: version
29
37
  };
30
38
  }
39
+ exports["default"] = __webpack_exports__["default"];
40
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
41
+ "default"
42
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
43
+ Object.defineProperty(exports, '__esModule', {
44
+ value: true
45
+ });
package/exports/index.mjs CHANGED
@@ -1,5 +1,9 @@
1
1
  // ES modules wrapper
2
- import { ReactRefreshRspackPlugin } from '../dist/index.js';
2
+ import { createRequire } from 'node:module';
3
+
4
+ const require = createRequire(import.meta.url);
5
+ const { ReactRefreshRspackPlugin } = require('../dist/index.js');
6
+
3
7
  // default export will be deprecated in next major version
4
8
  export default ReactRefreshRspackPlugin;
5
9
  export { ReactRefreshRspackPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/plugin-react-refresh",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "repository": "https://github.com/rspack-contrib/rspack-plugin-react-refresh",
5
5
  "license": "MIT",
6
6
  "description": "React refresh plugin for Rspack",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@biomejs/biome": "^1.9.4",
35
- "@rslib/core": "^0.11.0",
36
- "@rspack/core": "1.4.11",
35
+ "@rslib/core": "^0.15.1",
36
+ "@rspack/core": "^1.5.8",
37
37
  "@types/jest": "29.5.14",
38
38
  "@types/node": "^22.17.0",
39
39
  "bumpp": "^10.2.3",
@@ -70,8 +70,8 @@
70
70
  "registry": "https://registry.npmjs.org/"
71
71
  },
72
72
  "scripts": {
73
- "build": "tsc -b ./tsconfig.build.json",
74
- "dev": "tsc -b -w",
73
+ "build": "rslib build",
74
+ "dev": "rslib build -w",
75
75
  "lint": "biome check .",
76
76
  "lint:write": "biome check . --write",
77
77
  "test": "jest --colors",
package/dist/options.js DELETED
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeOptions = normalizeOptions;
4
- const d = (object, property, defaultValue) => {
5
- // TODO: should we also add default for null?
6
- if (typeof object[property] === 'undefined' &&
7
- typeof defaultValue !== 'undefined') {
8
- object[property] = defaultValue;
9
- }
10
- return object[property];
11
- };
12
- const normalizeOverlay = (options) => {
13
- const defaultOverlay = {
14
- entry: require.resolve('../client/errorOverlayEntry.js'),
15
- module: require.resolve('../client/overlay/index.js'),
16
- sockIntegration: 'wds',
17
- };
18
- if (!options) {
19
- return false;
20
- }
21
- if (typeof options === 'undefined' || options === true) {
22
- return defaultOverlay;
23
- }
24
- options.entry = options.entry ?? defaultOverlay.entry;
25
- options.module = options.module ?? defaultOverlay.module;
26
- options.sockIntegration =
27
- options.sockIntegration ?? defaultOverlay.sockIntegration;
28
- return options;
29
- };
30
- function normalizeOptions(options) {
31
- d(options, 'exclude', /node_modules/i);
32
- d(options, 'include', /\.([cm]js|[jt]sx?|flow)$/i);
33
- d(options, 'library');
34
- d(options, 'forceEnable', false);
35
- d(options, 'injectLoader', true);
36
- d(options, 'injectEntry', true);
37
- d(options, 'reloadOnRuntimeErrors', false);
38
- options.overlay = normalizeOverlay(options.overlay);
39
- return options;
40
- }
package/dist/paths.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.runtimePaths = exports.refreshRuntimeDirPath = exports.refreshUtilsPath = exports.reactRefreshEntryPath = exports.reactRefreshPath = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- exports.reactRefreshPath = require.resolve('../client/reactRefresh.js');
9
- exports.reactRefreshEntryPath = require.resolve('../client/reactRefreshEntry.js');
10
- exports.refreshUtilsPath = require.resolve('../client/refreshUtils.js');
11
- exports.refreshRuntimeDirPath = node_path_1.default.dirname(require.resolve('react-refresh', {
12
- paths: [exports.reactRefreshPath],
13
- }));
14
- exports.runtimePaths = [
15
- exports.reactRefreshEntryPath,
16
- exports.reactRefreshPath,
17
- exports.refreshUtilsPath,
18
- exports.refreshRuntimeDirPath,
19
- ];
@@ -1,88 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getAdditionalEntries = getAdditionalEntries;
7
- const node_querystring_1 = __importDefault(require("node:querystring"));
8
- const paths_1 = require("../paths");
9
- function getAdditionalEntries({ devServer, options, }) {
10
- const resourceQuery = {};
11
- if (devServer) {
12
- const { client, https, http2, sockHost, sockPath, sockPort } = devServer;
13
- let { host, path, port } = devServer;
14
- let protocol = https || http2 ? 'https' : 'http';
15
- if (sockHost)
16
- host = sockHost;
17
- if (sockPath)
18
- path = sockPath;
19
- if (sockPort)
20
- port = sockPort;
21
- if (client && client.webSocketURL != null) {
22
- let parsedUrl = client.webSocketURL;
23
- if (typeof parsedUrl === 'string')
24
- parsedUrl = new URL(parsedUrl);
25
- let auth;
26
- if (parsedUrl.username) {
27
- auth = parsedUrl.username;
28
- if (parsedUrl.password) {
29
- auth += `:${parsedUrl.password}`;
30
- }
31
- }
32
- if (parsedUrl.hostname != null) {
33
- host = [auth != null && auth, parsedUrl.hostname]
34
- .filter(Boolean)
35
- .join('@');
36
- }
37
- if (parsedUrl.pathname != null) {
38
- path = parsedUrl.pathname;
39
- }
40
- if (parsedUrl.port != null) {
41
- port = !['0', 'auto'].includes(String(parsedUrl.port))
42
- ? parsedUrl.port
43
- : undefined;
44
- }
45
- if (parsedUrl.protocol != null) {
46
- protocol =
47
- parsedUrl.protocol !== 'auto'
48
- ? parsedUrl.protocol.replace(':', '')
49
- : 'ws';
50
- }
51
- }
52
- if (host)
53
- resourceQuery.sockHost = host;
54
- if (path)
55
- resourceQuery.sockPath = path;
56
- if (port)
57
- resourceQuery.sockPort = port;
58
- resourceQuery.sockProtocol = protocol;
59
- }
60
- if (options.overlay) {
61
- const { sockHost, sockPath, sockPort, sockProtocol } = options.overlay;
62
- if (sockHost)
63
- resourceQuery.sockHost = sockHost;
64
- if (sockPath)
65
- resourceQuery.sockPath = sockPath;
66
- if (sockPort)
67
- resourceQuery.sockPort = sockPort;
68
- if (sockProtocol)
69
- resourceQuery.sockProtocol = sockProtocol;
70
- }
71
- // We don't need to URI encode the resourceQuery as it will be parsed by Webpack
72
- const queryString = node_querystring_1.default.stringify(resourceQuery, undefined, undefined, {
73
- encodeURIComponent(str) {
74
- return str;
75
- },
76
- });
77
- const prependEntries = [
78
- // React-refresh runtime
79
- paths_1.reactRefreshEntryPath,
80
- ];
81
- const overlayEntries = [
82
- // Error overlay runtime
83
- options.overlay !== false &&
84
- options.overlay?.entry &&
85
- `${require.resolve(options.overlay.entry)}${queryString ? `?${queryString}` : ''}`,
86
- ].filter(Boolean);
87
- return { prependEntries, overlayEntries };
88
- }
@@ -1,18 +0,0 @@
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,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSocketIntegration = getSocketIntegration;
4
- function getSocketIntegration(integrationType) {
5
- let resolvedSocketIntegration;
6
- switch (integrationType) {
7
- case 'wds': {
8
- resolvedSocketIntegration = require.resolve('../sockets/WDSSocket');
9
- break;
10
- }
11
- case 'whm': {
12
- resolvedSocketIntegration = require.resolve('../sockets/WHMEventSource');
13
- break;
14
- }
15
- default: {
16
- resolvedSocketIntegration = require.resolve(integrationType);
17
- break;
18
- }
19
- }
20
- return resolvedSocketIntegration;
21
- }