@rspack/dev-server 2.0.0-beta.1 → 2.0.0-beta.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/README.md +4 -3
- package/client/clients/WebSocketClient.d.ts +17 -0
- package/client/clients/WebSocketClient.js +28 -28
- package/client/index.d.ts +17 -0
- package/client/index.js +224 -363
- package/client/modules/logger/Logger.d.ts +40 -0
- package/client/modules/logger/Logger.js +123 -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 +18 -0
- package/client/modules/logger/index.js +20 -712
- package/client/modules/types.d.ts +45 -0
- package/client/modules/types.js +17 -0
- package/client/overlay.d.ts +44 -0
- package/client/overlay.js +241 -290
- package/client/progress.d.ts +11 -0
- package/client/progress.js +178 -111
- package/client/socket.d.ts +15 -0
- package/client/socket.js +19 -46
- package/client/utils/ansiHTML.d.ts +30 -0
- package/client/utils/ansiHTML.js +106 -153
- package/client/utils/log.d.ts +13 -0
- package/client/utils/log.js +7 -17
- package/client/utils/sendMessage.d.ts +11 -0
- package/client/utils/sendMessage.js +6 -15
- package/dist/0~launch-editor.js +618 -0
- package/dist/0~open.js +547 -0
- package/dist/0~p-retry.js +158 -0
- package/dist/131.js +1398 -0
- package/dist/getPort.d.ts +4 -1
- package/dist/index.js +1 -5
- package/dist/rslib-runtime.js +66 -0
- package/dist/server.d.ts +7 -7
- package/dist/servers/WebsocketServer.d.ts +8 -1
- package/dist/types.d.ts +7 -5
- package/package.json +55 -58
- package/dist/config.js +0 -2
- package/dist/getPort.js +0 -141
- package/dist/server.js +0 -1971
- package/dist/servers/BaseServer.js +0 -20
- package/dist/servers/WebsocketServer.js +0 -72
- package/dist/types.js +0 -5
|
@@ -0,0 +1,40 @@
|
|
|
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 WebpackLogger {
|
|
15
|
+
private [LOG_SYMBOL];
|
|
16
|
+
private [TIMERS_SYMBOL];
|
|
17
|
+
private [TIMERS_AGGREGATES_SYMBOL];
|
|
18
|
+
private getChildLogger;
|
|
19
|
+
constructor(log: (type: LogTypeEnum, args?: Args) => void, getChildLogger: (name: string | (() => string)) => WebpackLogger);
|
|
20
|
+
error(...args: Args): void;
|
|
21
|
+
warn(...args: Args): void;
|
|
22
|
+
info(...args: Args): void;
|
|
23
|
+
log(...args: Args): void;
|
|
24
|
+
debug(...args: Args): void;
|
|
25
|
+
assert(assertion: EXPECTED_ANY, ...args: Args): void;
|
|
26
|
+
trace(): void;
|
|
27
|
+
clear(): void;
|
|
28
|
+
status(...args: Args): void;
|
|
29
|
+
group(...args: Args): void;
|
|
30
|
+
groupCollapsed(...args: Args): void;
|
|
31
|
+
groupEnd(): void;
|
|
32
|
+
profile(label?: string): void;
|
|
33
|
+
profileEnd(label?: string): void;
|
|
34
|
+
time(label: string): void;
|
|
35
|
+
timeLog(label?: string): void;
|
|
36
|
+
timeEnd(label?: string): void;
|
|
37
|
+
timeAggregate(label?: string): void;
|
|
38
|
+
timeAggregateEnd(label?: string): void;
|
|
39
|
+
}
|
|
40
|
+
export { WebpackLogger as Logger };
|
|
@@ -0,0 +1,123 @@
|
|
|
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('webpack logger raw log method');
|
|
13
|
+
const TIMERS_SYMBOL = Symbol('webpack logger times');
|
|
14
|
+
const TIMERS_AGGREGATES_SYMBOL = Symbol('webpack logger aggregated times');
|
|
15
|
+
let _LOG_SYMBOL = LOG_SYMBOL, _TIMERS_SYMBOL = TIMERS_SYMBOL, _TIMERS_AGGREGATES_SYMBOL = TIMERS_AGGREGATES_SYMBOL;
|
|
16
|
+
class WebpackLogger {
|
|
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 WebpackLogger.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 WebpackLogger.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 WebpackLogger.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, getChildLogger){
|
|
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
|
+
_define_property(this, "getChildLogger", void 0);
|
|
119
|
+
this[LOG_SYMBOL] = log;
|
|
120
|
+
this.getChildLogger = getChildLogger;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export { WebpackLogger 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;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { LogType } from "../types.js";
|
|
2
|
+
const filterToFunction = (item)=>{
|
|
3
|
+
if ('string' == typeof item) {
|
|
4
|
+
const regExp = new RegExp(`[\\\\/]${item.replace(/[-[\]{}()*+?.\\^$|]/g, '\\$&')}([\\\\/]|$|!|\\?)`);
|
|
5
|
+
return (ident)=>regExp.test(ident);
|
|
6
|
+
}
|
|
7
|
+
if (item && 'object' == typeof item && 'function' == typeof item.test) return (ident)=>item.test(ident);
|
|
8
|
+
if ('function' == typeof item) return item;
|
|
9
|
+
if ('boolean' == typeof item) return ()=>item;
|
|
10
|
+
};
|
|
11
|
+
const LogLevel = {
|
|
12
|
+
none: 6,
|
|
13
|
+
false: 6,
|
|
14
|
+
error: 5,
|
|
15
|
+
warn: 4,
|
|
16
|
+
info: 3,
|
|
17
|
+
log: 2,
|
|
18
|
+
true: 2,
|
|
19
|
+
verbose: 1
|
|
20
|
+
};
|
|
21
|
+
const createConsoleLogger = ({ level = 'info', debug = false, console })=>{
|
|
22
|
+
const debugFilters = 'boolean' == typeof debug ? [
|
|
23
|
+
()=>debug
|
|
24
|
+
] : [
|
|
25
|
+
...Array.isArray(debug) ? debug : [
|
|
26
|
+
debug
|
|
27
|
+
]
|
|
28
|
+
].map(filterToFunction);
|
|
29
|
+
const loglevel = LogLevel[`${level}`] || 0;
|
|
30
|
+
const logger = (name, type, args)=>{
|
|
31
|
+
const labeledArgs = ()=>{
|
|
32
|
+
if (Array.isArray(args)) {
|
|
33
|
+
if (args.length > 0 && 'string' == typeof args[0]) return [
|
|
34
|
+
`[${name}] ${args[0]}`,
|
|
35
|
+
...args.slice(1)
|
|
36
|
+
];
|
|
37
|
+
return [
|
|
38
|
+
`[${name}]`,
|
|
39
|
+
...args
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
};
|
|
44
|
+
const debug = debugFilters.some((f)=>f(name));
|
|
45
|
+
switch(type){
|
|
46
|
+
case LogType.debug:
|
|
47
|
+
if (!debug) return;
|
|
48
|
+
if ('function' == typeof console.debug) console.debug(...labeledArgs());
|
|
49
|
+
else console.log(...labeledArgs());
|
|
50
|
+
break;
|
|
51
|
+
case LogType.log:
|
|
52
|
+
if (!debug && loglevel > LogLevel.log) return;
|
|
53
|
+
console.log(...labeledArgs());
|
|
54
|
+
break;
|
|
55
|
+
case LogType.info:
|
|
56
|
+
if (!debug && loglevel > LogLevel.info) return;
|
|
57
|
+
console.info(...labeledArgs());
|
|
58
|
+
break;
|
|
59
|
+
case LogType.warn:
|
|
60
|
+
if (!debug && loglevel > LogLevel.warn) return;
|
|
61
|
+
console.warn(...labeledArgs());
|
|
62
|
+
break;
|
|
63
|
+
case LogType.error:
|
|
64
|
+
if (!debug && loglevel > LogLevel.error) return;
|
|
65
|
+
console.error(...labeledArgs());
|
|
66
|
+
break;
|
|
67
|
+
case LogType.trace:
|
|
68
|
+
if (!debug) return;
|
|
69
|
+
console.trace();
|
|
70
|
+
break;
|
|
71
|
+
case LogType.groupCollapsed:
|
|
72
|
+
if (!debug && loglevel > LogLevel.log) return;
|
|
73
|
+
if (!debug && loglevel > LogLevel.verbose) {
|
|
74
|
+
if ('function' == typeof console.groupCollapsed) console.groupCollapsed(...labeledArgs());
|
|
75
|
+
else console.log(...labeledArgs());
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case LogType.group:
|
|
79
|
+
if (!debug && loglevel > LogLevel.log) return;
|
|
80
|
+
if ('function' == typeof console.group) console.group(...labeledArgs());
|
|
81
|
+
else console.log(...labeledArgs());
|
|
82
|
+
break;
|
|
83
|
+
case LogType.groupEnd:
|
|
84
|
+
if (!debug && loglevel > LogLevel.log) return;
|
|
85
|
+
if ('function' == typeof console.groupEnd) console.groupEnd();
|
|
86
|
+
break;
|
|
87
|
+
case LogType.time:
|
|
88
|
+
{
|
|
89
|
+
if (!debug && loglevel > LogLevel.log) return;
|
|
90
|
+
const [label, start, end] = args;
|
|
91
|
+
const ms = 1000 * start + end / 1000000;
|
|
92
|
+
const msg = `[${name}] ${label}: ${ms} ms`;
|
|
93
|
+
if ('function' == typeof console.logTime) console.logTime(msg);
|
|
94
|
+
else console.log(msg);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case LogType.profile:
|
|
98
|
+
if ('function' == typeof console.profile) console.profile(...labeledArgs());
|
|
99
|
+
break;
|
|
100
|
+
case LogType.profileEnd:
|
|
101
|
+
if ('function' == typeof console.profileEnd) console.profileEnd(...labeledArgs());
|
|
102
|
+
break;
|
|
103
|
+
case LogType.clear:
|
|
104
|
+
if (!debug && loglevel > LogLevel.log) return;
|
|
105
|
+
if ('function' == typeof console.clear) console.clear();
|
|
106
|
+
break;
|
|
107
|
+
case LogType.status:
|
|
108
|
+
if (!debug && loglevel > LogLevel.info) return;
|
|
109
|
+
if ('function' == typeof console.status) if (args && 0 !== args.length) console.status(...labeledArgs());
|
|
110
|
+
else console.status();
|
|
111
|
+
else if (args && 0 !== args.length) console.info(...labeledArgs());
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
throw new Error(`Unexpected LogType ${type}`);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return logger;
|
|
118
|
+
};
|
|
119
|
+
export { createConsoleLogger as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { Logger } from './Logger.js';
|
|
11
|
+
import type { LoggerOptions } from '../types.js';
|
|
12
|
+
export declare const logger: {
|
|
13
|
+
getLogger: (name: string) => Logger;
|
|
14
|
+
configureDefaultLogger: (options: LoggerOptions) => void;
|
|
15
|
+
hooks: {
|
|
16
|
+
log: any;
|
|
17
|
+
};
|
|
18
|
+
};
|