@rspack/dev-server 2.0.2 → 2.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/client/clients/WebSocketClient.d.ts +17 -0
- package/client/clients/WebSocketClient.js +32 -0
- package/client/index.d.ts +17 -0
- package/client/index.js +356 -0
- package/client/modules/logger/Logger.d.ts +39 -0
- package/client/modules/logger/Logger.js +121 -0
- package/client/modules/logger/createConsoleLogger.d.ts +12 -0
- package/client/modules/logger/createConsoleLogger.js +119 -0
- package/client/modules/logger/index.d.ts +26 -0
- package/client/modules/logger/index.js +32 -0
- package/client/modules/types.d.ts +45 -0
- package/client/modules/types.js +17 -0
- package/client/overlay.d.ts +47 -0
- package/client/overlay.js +454 -0
- package/client/progress.d.ts +11 -0
- package/client/progress.js +197 -0
- package/client/socket.d.ts +15 -0
- package/client/socket.js +34 -0
- package/client/type.d.ts +15 -0
- package/client/type.js +1 -0
- package/client/utils/ansiHTML.d.ts +30 -0
- package/client/utils/ansiHTML.js +195 -0
- package/client/utils/log.d.ts +13 -0
- package/client/utils/log.js +11 -0
- package/client/utils/sendMessage.d.ts +11 -0
- package/client/utils/sendMessage.js +8 -0
- package/dist/0~chokidar.js +1477 -0
- package/dist/0~chokidar.js.LICENSE.txt +1 -0
- package/dist/0~connect-history-api-fallback.js +76 -0
- package/dist/0~connect-next.js +1245 -0
- package/dist/0~connect-next.js.LICENSE.txt +57 -0
- package/dist/0~debug.js +621 -0
- package/dist/0~http-proxy-middleware.js +3817 -0
- package/dist/0~http-proxy-middleware.js.LICENSE.txt +34 -0
- package/dist/0~launch-editor.js +601 -0
- package/dist/0~open.js +555 -0
- package/dist/0~p-retry.js +161 -0
- package/dist/0~serve-static.js +1595 -0
- package/dist/0~serve-static.js.LICENSE.txt +108 -0
- package/dist/465.js +5192 -0
- package/dist/index.d.ts +1008 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/webpack/webpack-dev-server
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Tobias Koppers @sokra
|
|
7
|
+
* Copyright (c) JS Foundation and other contributors
|
|
8
|
+
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
import { CommunicationClient } from '../type.js';
|
|
11
|
+
export default class WebSocketClient implements CommunicationClient {
|
|
12
|
+
private client;
|
|
13
|
+
constructor(url: string);
|
|
14
|
+
onOpen(fn: (...args: unknown[]) => void): void;
|
|
15
|
+
onClose(fn: (...args: unknown[]) => void): void;
|
|
16
|
+
onMessage(fn: (...args: unknown[]) => void): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { log } from "../utils/log.js";
|
|
2
|
+
function _define_property(obj, key, value) {
|
|
3
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
else obj[key] = value;
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
class WebSocketClient {
|
|
13
|
+
onOpen(fn) {
|
|
14
|
+
this.client.onopen = fn;
|
|
15
|
+
}
|
|
16
|
+
onClose(fn) {
|
|
17
|
+
this.client.onclose = fn;
|
|
18
|
+
}
|
|
19
|
+
onMessage(fn) {
|
|
20
|
+
this.client.onmessage = (event)=>{
|
|
21
|
+
fn(event.data);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
constructor(url){
|
|
25
|
+
_define_property(this, "client", void 0);
|
|
26
|
+
this.client = new WebSocket(url);
|
|
27
|
+
this.client.onerror = (error)=>{
|
|
28
|
+
log.error(error);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export default WebSocketClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/webpack/webpack-dev-server
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Tobias Koppers @sokra
|
|
7
|
+
* Copyright (c) JS Foundation and other contributors
|
|
8
|
+
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
declare const parseURL: (resourceQuery: string) => {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
};
|
|
13
|
+
declare const getCurrentScriptSource: () => string;
|
|
14
|
+
declare const createSocketURL: (parsedURL: URL & {
|
|
15
|
+
fromCurrentScript?: boolean;
|
|
16
|
+
}) => string;
|
|
17
|
+
export { getCurrentScriptSource, parseURL, createSocketURL };
|
package/client/index.js
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { emitter } from "@rspack/core/hot/emitter.js";
|
|
2
|
+
import { log } from "@rspack/core/hot/log.js";
|
|
3
|
+
import { createOverlay, formatProblem } from "./overlay.js";
|
|
4
|
+
import socket from "./socket.js";
|
|
5
|
+
import { defineProgressElement, isProgressSupported } from "./progress.js";
|
|
6
|
+
import { log as log_js_log, setLogLevel } from "./utils/log.js";
|
|
7
|
+
import sendMessage from "./utils/sendMessage.js";
|
|
8
|
+
function _define_property(obj, key, value) {
|
|
9
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
10
|
+
value: value,
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true
|
|
14
|
+
});
|
|
15
|
+
else obj[key] = value;
|
|
16
|
+
return obj;
|
|
17
|
+
}
|
|
18
|
+
function _object_spread(target) {
|
|
19
|
+
for(var i = 1; i < arguments.length; i++){
|
|
20
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
21
|
+
var ownKeys = Object.keys(source);
|
|
22
|
+
if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
23
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
24
|
+
}));
|
|
25
|
+
ownKeys.forEach(function(key) {
|
|
26
|
+
_define_property(target, key, source[key]);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return target;
|
|
30
|
+
}
|
|
31
|
+
const decodeOverlayOptions = (overlayOptions)=>{
|
|
32
|
+
if ('object' == typeof overlayOptions) [
|
|
33
|
+
'warnings',
|
|
34
|
+
'errors',
|
|
35
|
+
'runtimeErrors'
|
|
36
|
+
].forEach((property)=>{
|
|
37
|
+
if ('string' == typeof overlayOptions[property]) {
|
|
38
|
+
const overlayFilterFunctionString = decodeURIComponent(overlayOptions[property]);
|
|
39
|
+
overlayOptions[property] = new Function('message', `var callback = ${overlayFilterFunctionString}
|
|
40
|
+
return callback(message)`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const parseURL = (resourceQuery)=>{
|
|
45
|
+
let result = {};
|
|
46
|
+
if ('string' == typeof resourceQuery && '' !== resourceQuery) {
|
|
47
|
+
const searchParams = resourceQuery.slice(1).split('&');
|
|
48
|
+
for(let i = 0; i < searchParams.length; i++){
|
|
49
|
+
const pair = searchParams[i].split('=');
|
|
50
|
+
result[pair[0]] = decodeURIComponent(pair[1]);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
const scriptSource = getCurrentScriptSource();
|
|
54
|
+
let scriptSourceURL;
|
|
55
|
+
try {
|
|
56
|
+
scriptSourceURL = new URL(scriptSource, self.location.href);
|
|
57
|
+
} catch (error) {}
|
|
58
|
+
if (scriptSourceURL) {
|
|
59
|
+
result = scriptSourceURL;
|
|
60
|
+
result['fromCurrentScript'] = 'true';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
};
|
|
65
|
+
const client_src_status = {
|
|
66
|
+
isUnloading: false,
|
|
67
|
+
currentHash: __webpack_hash__
|
|
68
|
+
};
|
|
69
|
+
const getCurrentScriptSource = ()=>{
|
|
70
|
+
if (document.currentScript) return document.currentScript.getAttribute('src');
|
|
71
|
+
const scriptElements = document.scripts || [];
|
|
72
|
+
const scriptElementsWithSrc = Array.prototype.filter.call(scriptElements, (element)=>element.getAttribute('src'));
|
|
73
|
+
if (scriptElementsWithSrc.length > 0) {
|
|
74
|
+
const currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
|
|
75
|
+
return currentScript.getAttribute('src');
|
|
76
|
+
}
|
|
77
|
+
throw new Error("[rspack-dev-server] Failed to get current script source.");
|
|
78
|
+
};
|
|
79
|
+
const parsedResourceQuery = parseURL(__resourceQuery);
|
|
80
|
+
const enabledFeatures = {
|
|
81
|
+
'Hot Module Replacement': false,
|
|
82
|
+
'Live Reloading': false,
|
|
83
|
+
Progress: false,
|
|
84
|
+
Overlay: false
|
|
85
|
+
};
|
|
86
|
+
const options = {
|
|
87
|
+
hot: false,
|
|
88
|
+
liveReload: false,
|
|
89
|
+
progress: false,
|
|
90
|
+
overlay: false
|
|
91
|
+
};
|
|
92
|
+
if ('true' === parsedResourceQuery.hot) {
|
|
93
|
+
options.hot = true;
|
|
94
|
+
enabledFeatures['Hot Module Replacement'] = true;
|
|
95
|
+
}
|
|
96
|
+
if ('true' === parsedResourceQuery['live-reload']) {
|
|
97
|
+
options.liveReload = true;
|
|
98
|
+
enabledFeatures['Live Reloading'] = true;
|
|
99
|
+
}
|
|
100
|
+
if ('true' === parsedResourceQuery.progress) {
|
|
101
|
+
options.progress = true;
|
|
102
|
+
enabledFeatures.Progress = true;
|
|
103
|
+
}
|
|
104
|
+
if (parsedResourceQuery.overlay) {
|
|
105
|
+
try {
|
|
106
|
+
options.overlay = JSON.parse(parsedResourceQuery.overlay);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
log_js_log.error('Error parsing overlay options from resource query:', e);
|
|
109
|
+
}
|
|
110
|
+
if ('object' == typeof options.overlay) {
|
|
111
|
+
options.overlay = _object_spread({
|
|
112
|
+
errors: true,
|
|
113
|
+
warnings: true,
|
|
114
|
+
runtimeErrors: true
|
|
115
|
+
}, options.overlay);
|
|
116
|
+
decodeOverlayOptions(options.overlay);
|
|
117
|
+
}
|
|
118
|
+
enabledFeatures.Overlay = false !== options.overlay;
|
|
119
|
+
}
|
|
120
|
+
if (parsedResourceQuery.logging) options.logging = parsedResourceQuery.logging;
|
|
121
|
+
if (void 0 !== parsedResourceQuery.reconnect) options.reconnect = Number(parsedResourceQuery.reconnect);
|
|
122
|
+
const setAllLogLevel = (level)=>{
|
|
123
|
+
log.setLogLevel('verbose' === level || 'log' === level ? 'info' : level);
|
|
124
|
+
setLogLevel(level);
|
|
125
|
+
};
|
|
126
|
+
if (options.logging) setAllLogLevel(options.logging);
|
|
127
|
+
const logEnabledFeatures = (features)=>{
|
|
128
|
+
const listEnabledFeatures = Object.keys(features);
|
|
129
|
+
if (!features || 0 === listEnabledFeatures.length) return;
|
|
130
|
+
let logString = 'Server started:';
|
|
131
|
+
for(let i = 0; i < listEnabledFeatures.length; i++){
|
|
132
|
+
const key = listEnabledFeatures[i];
|
|
133
|
+
logString += ` ${key} ${features[key] ? 'enabled' : 'disabled'},`;
|
|
134
|
+
}
|
|
135
|
+
logString = logString.slice(0, -1).concat('.');
|
|
136
|
+
log_js_log.info(logString);
|
|
137
|
+
};
|
|
138
|
+
logEnabledFeatures(enabledFeatures);
|
|
139
|
+
self.addEventListener('beforeunload', ()=>{
|
|
140
|
+
client_src_status.isUnloading = true;
|
|
141
|
+
});
|
|
142
|
+
const overlay = "u" > typeof window ? createOverlay('object' == typeof options.overlay ? {
|
|
143
|
+
trustedTypesPolicyName: options.overlay.trustedTypesPolicyName,
|
|
144
|
+
catchRuntimeError: options.overlay.runtimeErrors
|
|
145
|
+
} : {
|
|
146
|
+
trustedTypesPolicyName: false,
|
|
147
|
+
catchRuntimeError: options.overlay
|
|
148
|
+
}) : {
|
|
149
|
+
send: ()=>{}
|
|
150
|
+
};
|
|
151
|
+
const reloadApp = ({ hot, liveReload }, currentStatus)=>{
|
|
152
|
+
if (currentStatus.isUnloading) return;
|
|
153
|
+
const { currentHash, previousHash } = currentStatus;
|
|
154
|
+
const isInitial = currentHash.indexOf(previousHash) >= 0;
|
|
155
|
+
if (isInitial) return;
|
|
156
|
+
function applyReload(rootWindow, intervalId) {
|
|
157
|
+
clearInterval(intervalId);
|
|
158
|
+
log_js_log.info('App updated. Reloading...');
|
|
159
|
+
rootWindow.location.reload();
|
|
160
|
+
}
|
|
161
|
+
const search = self.location.search.toLowerCase();
|
|
162
|
+
const allowToHot = -1 === search.indexOf('rspack-dev-server-hot=false');
|
|
163
|
+
const allowToLiveReload = -1 === search.indexOf('rspack-dev-server-live-reload=false');
|
|
164
|
+
if (hot && allowToHot) {
|
|
165
|
+
log_js_log.info('App hot update...');
|
|
166
|
+
emitter.emit('webpackHotUpdate', currentStatus.currentHash);
|
|
167
|
+
if ("u" > typeof self && self.window) self.postMessage(`webpackHotUpdate${currentStatus.currentHash}`, '*');
|
|
168
|
+
} else if (liveReload && allowToLiveReload) {
|
|
169
|
+
let rootWindow = self;
|
|
170
|
+
const intervalId = self.setInterval(()=>{
|
|
171
|
+
if ('about:' !== rootWindow.location.protocol) applyReload(rootWindow, intervalId);
|
|
172
|
+
else {
|
|
173
|
+
rootWindow = rootWindow.parent;
|
|
174
|
+
if (rootWindow.parent === rootWindow) applyReload(rootWindow, intervalId);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const ansiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))", 'g');
|
|
180
|
+
const stripAnsi = (string)=>{
|
|
181
|
+
if ('string' != typeof string) throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
182
|
+
return string.replace(ansiRegex, '');
|
|
183
|
+
};
|
|
184
|
+
const onSocketMessage = {
|
|
185
|
+
hot () {
|
|
186
|
+
if ('false' === parsedResourceQuery.hot) return;
|
|
187
|
+
options.hot = true;
|
|
188
|
+
},
|
|
189
|
+
liveReload () {
|
|
190
|
+
if ('false' === parsedResourceQuery['live-reload']) return;
|
|
191
|
+
options.liveReload = true;
|
|
192
|
+
},
|
|
193
|
+
invalid () {
|
|
194
|
+
log_js_log.info('App updated. Recompiling...');
|
|
195
|
+
if (options.overlay) overlay.send({
|
|
196
|
+
type: 'DISMISS'
|
|
197
|
+
});
|
|
198
|
+
sendMessage('Invalid');
|
|
199
|
+
},
|
|
200
|
+
hash: function(_hash) {
|
|
201
|
+
if (!_hash) return;
|
|
202
|
+
client_src_status.previousHash = client_src_status.currentHash;
|
|
203
|
+
client_src_status.currentHash = _hash;
|
|
204
|
+
},
|
|
205
|
+
logging: setAllLogLevel,
|
|
206
|
+
overlay (value) {
|
|
207
|
+
if ("u" < typeof document) return;
|
|
208
|
+
options.overlay = value;
|
|
209
|
+
decodeOverlayOptions(options.overlay);
|
|
210
|
+
},
|
|
211
|
+
reconnect (value) {
|
|
212
|
+
if ('false' === parsedResourceQuery.reconnect) return;
|
|
213
|
+
options.reconnect = value;
|
|
214
|
+
},
|
|
215
|
+
progress (value) {
|
|
216
|
+
options.progress = value;
|
|
217
|
+
},
|
|
218
|
+
'progress-update': function(data) {
|
|
219
|
+
if (options.progress) log_js_log.info(`${data.percent}% - ${data.msg}.`);
|
|
220
|
+
if (isProgressSupported()) {
|
|
221
|
+
if ('string' == typeof options.progress) {
|
|
222
|
+
let progress = document.querySelector('wds-progress');
|
|
223
|
+
if (!progress) {
|
|
224
|
+
defineProgressElement();
|
|
225
|
+
progress = document.createElement('wds-progress');
|
|
226
|
+
document.body.appendChild(progress);
|
|
227
|
+
}
|
|
228
|
+
progress.setAttribute('progress', data.percent.toString());
|
|
229
|
+
progress.setAttribute('type', options.progress);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
sendMessage('Progress', data);
|
|
233
|
+
},
|
|
234
|
+
'still-ok': function() {
|
|
235
|
+
log_js_log.info('Nothing changed.');
|
|
236
|
+
if (options.overlay) overlay.send({
|
|
237
|
+
type: 'DISMISS'
|
|
238
|
+
});
|
|
239
|
+
sendMessage('StillOk');
|
|
240
|
+
},
|
|
241
|
+
ok () {
|
|
242
|
+
sendMessage('Ok');
|
|
243
|
+
if (options.overlay) overlay.send({
|
|
244
|
+
type: 'DISMISS'
|
|
245
|
+
});
|
|
246
|
+
reloadApp(options, client_src_status);
|
|
247
|
+
},
|
|
248
|
+
'static-changed': function(file) {
|
|
249
|
+
log_js_log.info(`${file ? `"${file}"` : 'Content'} from static directory was changed. Reloading...`);
|
|
250
|
+
self.location.reload();
|
|
251
|
+
},
|
|
252
|
+
warnings (warnings, params) {
|
|
253
|
+
log_js_log.warn('Warnings while compiling.');
|
|
254
|
+
const printableWarnings = warnings.map((error)=>{
|
|
255
|
+
const { header, body } = formatProblem('warning', error);
|
|
256
|
+
return `${header}\n${stripAnsi(body)}`;
|
|
257
|
+
});
|
|
258
|
+
sendMessage('Warnings', printableWarnings);
|
|
259
|
+
for(let i = 0; i < printableWarnings.length; i++)log_js_log.warn(printableWarnings[i]);
|
|
260
|
+
const overlayWarningsSetting = 'boolean' == typeof options.overlay ? options.overlay : options.overlay && options.overlay.warnings;
|
|
261
|
+
if (overlayWarningsSetting) {
|
|
262
|
+
const warningsToDisplay = 'function' == typeof overlayWarningsSetting ? warnings.filter(overlayWarningsSetting) : warnings;
|
|
263
|
+
if (warningsToDisplay.length) overlay.send({
|
|
264
|
+
type: 'BUILD_ERROR',
|
|
265
|
+
level: 'warning',
|
|
266
|
+
messages: warnings
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
if (params && params.preventReloading) return;
|
|
270
|
+
reloadApp(options, client_src_status);
|
|
271
|
+
},
|
|
272
|
+
errors (errors) {
|
|
273
|
+
log_js_log.error('Errors while compiling. Reload prevented.');
|
|
274
|
+
const printableErrors = errors.map((error)=>{
|
|
275
|
+
const { header, body } = formatProblem('error', error);
|
|
276
|
+
return `${header}\n${stripAnsi(body)}`;
|
|
277
|
+
});
|
|
278
|
+
sendMessage('Errors', printableErrors);
|
|
279
|
+
for(let i = 0; i < printableErrors.length; i++)log_js_log.error(printableErrors[i]);
|
|
280
|
+
const overlayErrorsSettings = 'boolean' == typeof options.overlay ? options.overlay : options.overlay && options.overlay.errors;
|
|
281
|
+
if (overlayErrorsSettings) {
|
|
282
|
+
const errorsToDisplay = 'function' == typeof overlayErrorsSettings ? errors.filter(overlayErrorsSettings) : errors;
|
|
283
|
+
if (errorsToDisplay.length) overlay.send({
|
|
284
|
+
type: 'BUILD_ERROR',
|
|
285
|
+
level: 'error',
|
|
286
|
+
messages: errors
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
error (error) {
|
|
291
|
+
log_js_log.error(error);
|
|
292
|
+
},
|
|
293
|
+
close () {
|
|
294
|
+
log_js_log.info('Disconnected!');
|
|
295
|
+
if (options.overlay) overlay.send({
|
|
296
|
+
type: 'DISMISS'
|
|
297
|
+
});
|
|
298
|
+
sendMessage('Close');
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
const formatURL = (objURL)=>{
|
|
302
|
+
let protocol = objURL.protocol || '';
|
|
303
|
+
if (protocol && ':' !== protocol.substr(-1)) protocol += ':';
|
|
304
|
+
let auth = objURL.auth || '';
|
|
305
|
+
if (auth) {
|
|
306
|
+
auth = encodeURIComponent(auth);
|
|
307
|
+
auth = auth.replace(/%3A/i, ':');
|
|
308
|
+
auth += '@';
|
|
309
|
+
}
|
|
310
|
+
let host = '';
|
|
311
|
+
if (objURL.hostname) {
|
|
312
|
+
host = auth + (-1 === objURL.hostname.indexOf(':') ? objURL.hostname : `[${objURL.hostname}]`);
|
|
313
|
+
if (objURL.port) host += `:${objURL.port}`;
|
|
314
|
+
}
|
|
315
|
+
let pathname = objURL.pathname || '';
|
|
316
|
+
if (objURL.slashes) {
|
|
317
|
+
host = `//${host || ''}`;
|
|
318
|
+
if (pathname && '/' !== pathname.charAt(0)) pathname = `/${pathname}`;
|
|
319
|
+
} else if (!host) host = '';
|
|
320
|
+
let search = objURL.search || '';
|
|
321
|
+
if (search && '?' !== search.charAt(0)) search = `?${search}`;
|
|
322
|
+
let hash = objURL.hash || '';
|
|
323
|
+
if (hash && '#' !== hash.charAt(0)) hash = `#${hash}`;
|
|
324
|
+
pathname = pathname.replace(/[?#]/g, (match)=>encodeURIComponent(match));
|
|
325
|
+
search = search.replace('#', '%23');
|
|
326
|
+
return `${protocol}${host}${pathname}${search}${hash}`;
|
|
327
|
+
};
|
|
328
|
+
const createSocketURL = (parsedURL)=>{
|
|
329
|
+
let { hostname } = parsedURL;
|
|
330
|
+
const isInAddrAny = '0.0.0.0' === hostname || '::' === hostname || '[::]' === hostname;
|
|
331
|
+
if (isInAddrAny && self.location.hostname && 0 === self.location.protocol.indexOf('http')) hostname = self.location.hostname;
|
|
332
|
+
let socketURLProtocol = parsedURL.protocol || self.location.protocol;
|
|
333
|
+
if ('auto:' === socketURLProtocol || hostname && isInAddrAny && 'https:' === self.location.protocol) socketURLProtocol = self.location.protocol;
|
|
334
|
+
socketURLProtocol = socketURLProtocol.replace(/^(?:http|.+-extension|file)/i, 'ws');
|
|
335
|
+
let socketURLAuth = '';
|
|
336
|
+
if (parsedURL.username) {
|
|
337
|
+
socketURLAuth = parsedURL.username;
|
|
338
|
+
if (parsedURL.password) socketURLAuth = socketURLAuth.concat(':', parsedURL.password);
|
|
339
|
+
}
|
|
340
|
+
const socketURLHostname = (hostname || self.location.hostname || 'localhost').replace(/^\[(.*)\]$/, '$1');
|
|
341
|
+
let socketURLPort = parsedURL.port;
|
|
342
|
+
if (!socketURLPort || '0' === socketURLPort) socketURLPort = self.location.port;
|
|
343
|
+
let socketURLPathname = '/ws';
|
|
344
|
+
if (parsedURL.pathname && !parsedURL.fromCurrentScript) socketURLPathname = parsedURL.pathname;
|
|
345
|
+
return formatURL({
|
|
346
|
+
protocol: socketURLProtocol,
|
|
347
|
+
auth: socketURLAuth,
|
|
348
|
+
hostname: socketURLHostname,
|
|
349
|
+
port: socketURLPort,
|
|
350
|
+
pathname: socketURLPathname,
|
|
351
|
+
slashes: true
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
const socketURL = createSocketURL(parsedResourceQuery);
|
|
355
|
+
socket(socketURL, onSocketMessage, options.reconnect);
|
|
356
|
+
export { createSocketURL, getCurrentScriptSource, parseURL };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/webpack/webpack-dev-server
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Tobias Koppers @sokra
|
|
7
|
+
* Copyright (c) JS Foundation and other contributors
|
|
8
|
+
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
import { type Args, type EXPECTED_ANY, type LogTypeEnum } from '../types.js';
|
|
11
|
+
declare const LOG_SYMBOL: unique symbol;
|
|
12
|
+
declare const TIMERS_SYMBOL: unique symbol;
|
|
13
|
+
declare const TIMERS_AGGREGATES_SYMBOL: unique symbol;
|
|
14
|
+
declare class RspackLogger {
|
|
15
|
+
private [LOG_SYMBOL];
|
|
16
|
+
private [TIMERS_SYMBOL];
|
|
17
|
+
private [TIMERS_AGGREGATES_SYMBOL];
|
|
18
|
+
constructor(log: (type: LogTypeEnum, args?: Args) => void);
|
|
19
|
+
error(...args: Args): void;
|
|
20
|
+
warn(...args: Args): void;
|
|
21
|
+
info(...args: Args): void;
|
|
22
|
+
log(...args: Args): void;
|
|
23
|
+
debug(...args: Args): void;
|
|
24
|
+
assert(assertion: EXPECTED_ANY, ...args: Args): void;
|
|
25
|
+
trace(): void;
|
|
26
|
+
clear(): void;
|
|
27
|
+
status(...args: Args): void;
|
|
28
|
+
group(...args: Args): void;
|
|
29
|
+
groupCollapsed(...args: Args): void;
|
|
30
|
+
groupEnd(): void;
|
|
31
|
+
profile(label?: string): void;
|
|
32
|
+
profileEnd(label?: string): void;
|
|
33
|
+
time(label: string): void;
|
|
34
|
+
timeLog(label?: string): void;
|
|
35
|
+
timeEnd(label?: string): void;
|
|
36
|
+
timeAggregate(label?: string): void;
|
|
37
|
+
timeAggregateEnd(label?: string): void;
|
|
38
|
+
}
|
|
39
|
+
export { RspackLogger as Logger };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { LogType } from "../types.js";
|
|
2
|
+
function _define_property(obj, key, value) {
|
|
3
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
else obj[key] = value;
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
const LOG_SYMBOL = Symbol('rspack logger raw log method');
|
|
13
|
+
const TIMERS_SYMBOL = Symbol('rspack logger times');
|
|
14
|
+
const TIMERS_AGGREGATES_SYMBOL = Symbol('rspack logger aggregated times');
|
|
15
|
+
let _LOG_SYMBOL = LOG_SYMBOL, _TIMERS_SYMBOL = TIMERS_SYMBOL, _TIMERS_AGGREGATES_SYMBOL = TIMERS_AGGREGATES_SYMBOL;
|
|
16
|
+
class RspackLogger {
|
|
17
|
+
error(...args) {
|
|
18
|
+
this[LOG_SYMBOL](LogType.error, args);
|
|
19
|
+
}
|
|
20
|
+
warn(...args) {
|
|
21
|
+
this[LOG_SYMBOL](LogType.warn, args);
|
|
22
|
+
}
|
|
23
|
+
info(...args) {
|
|
24
|
+
this[LOG_SYMBOL](LogType.info, args);
|
|
25
|
+
}
|
|
26
|
+
log(...args) {
|
|
27
|
+
this[LOG_SYMBOL](LogType.log, args);
|
|
28
|
+
}
|
|
29
|
+
debug(...args) {
|
|
30
|
+
this[LOG_SYMBOL](LogType.debug, args);
|
|
31
|
+
}
|
|
32
|
+
assert(assertion, ...args) {
|
|
33
|
+
if (!assertion) this[LOG_SYMBOL](LogType.error, args);
|
|
34
|
+
}
|
|
35
|
+
trace() {
|
|
36
|
+
this[LOG_SYMBOL](LogType.trace, [
|
|
37
|
+
'Trace'
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
clear() {
|
|
41
|
+
this[LOG_SYMBOL](LogType.clear);
|
|
42
|
+
}
|
|
43
|
+
status(...args) {
|
|
44
|
+
this[LOG_SYMBOL](LogType.status, args);
|
|
45
|
+
}
|
|
46
|
+
group(...args) {
|
|
47
|
+
this[LOG_SYMBOL](LogType.group, args);
|
|
48
|
+
}
|
|
49
|
+
groupCollapsed(...args) {
|
|
50
|
+
this[LOG_SYMBOL](LogType.groupCollapsed, args);
|
|
51
|
+
}
|
|
52
|
+
groupEnd() {
|
|
53
|
+
this[LOG_SYMBOL](LogType.groupEnd);
|
|
54
|
+
}
|
|
55
|
+
profile(label) {
|
|
56
|
+
this[LOG_SYMBOL](LogType.profile, [
|
|
57
|
+
label
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
profileEnd(label) {
|
|
61
|
+
this[LOG_SYMBOL](LogType.profileEnd, [
|
|
62
|
+
label
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
time(label) {
|
|
66
|
+
this[TIMERS_SYMBOL] = this[TIMERS_SYMBOL] || new Map();
|
|
67
|
+
this[TIMERS_SYMBOL].set(label, process.hrtime());
|
|
68
|
+
}
|
|
69
|
+
timeLog(label) {
|
|
70
|
+
const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
|
|
71
|
+
if (!prev) throw new Error(`No such label '${label}' for RspackLogger.timeLog()`);
|
|
72
|
+
const time = process.hrtime(prev);
|
|
73
|
+
this[LOG_SYMBOL](LogType.time, [
|
|
74
|
+
label,
|
|
75
|
+
...time
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
timeEnd(label) {
|
|
79
|
+
const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
|
|
80
|
+
if (!prev) throw new Error(`No such label '${label}' for RspackLogger.timeEnd()`);
|
|
81
|
+
const time = process.hrtime(prev);
|
|
82
|
+
this[TIMERS_SYMBOL].delete(label);
|
|
83
|
+
this[LOG_SYMBOL](LogType.time, [
|
|
84
|
+
label,
|
|
85
|
+
...time
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
timeAggregate(label) {
|
|
89
|
+
const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
|
|
90
|
+
if (!prev) throw new Error(`No such label '${label}' for RspackLogger.timeAggregate()`);
|
|
91
|
+
const time = process.hrtime(prev);
|
|
92
|
+
this[TIMERS_SYMBOL].delete(label);
|
|
93
|
+
this[TIMERS_AGGREGATES_SYMBOL] = this[TIMERS_AGGREGATES_SYMBOL] || new Map();
|
|
94
|
+
const current = this[TIMERS_AGGREGATES_SYMBOL].get(label);
|
|
95
|
+
if (void 0 !== current) if (time[1] + current[1] > 1e9) {
|
|
96
|
+
time[0] += current[0] + 1;
|
|
97
|
+
time[1] = time[1] - 1e9 + current[1];
|
|
98
|
+
} else {
|
|
99
|
+
time[0] += current[0];
|
|
100
|
+
time[1] += current[1];
|
|
101
|
+
}
|
|
102
|
+
this[TIMERS_AGGREGATES_SYMBOL].set(label, time);
|
|
103
|
+
}
|
|
104
|
+
timeAggregateEnd(label) {
|
|
105
|
+
if (void 0 === this[TIMERS_AGGREGATES_SYMBOL]) return;
|
|
106
|
+
const time = this[TIMERS_AGGREGATES_SYMBOL].get(label);
|
|
107
|
+
if (void 0 === time) return;
|
|
108
|
+
this[TIMERS_AGGREGATES_SYMBOL].delete(label);
|
|
109
|
+
this[LOG_SYMBOL](LogType.time, [
|
|
110
|
+
label,
|
|
111
|
+
...time
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
constructor(log){
|
|
115
|
+
_define_property(this, _LOG_SYMBOL, void 0);
|
|
116
|
+
_define_property(this, _TIMERS_SYMBOL, new Map());
|
|
117
|
+
_define_property(this, _TIMERS_AGGREGATES_SYMBOL, new Map());
|
|
118
|
+
this[LOG_SYMBOL] = log;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export { RspackLogger as Logger };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/webpack/webpack-dev-server
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Tobias Koppers @sokra
|
|
7
|
+
* Copyright (c) JS Foundation and other contributors
|
|
8
|
+
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
import { type LoggerOptions, type LoggingFunction } from '../types.js';
|
|
11
|
+
declare const _default: ({ level, debug, console, }: LoggerOptions) => LoggingFunction;
|
|
12
|
+
export default _default;
|