@rsbuild/webpack 1.0.11 → 1.1.0-beta.1
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/15.cjs +368 -0
- package/dist/238.js +332 -0
- package/dist/997.cjs +2349 -0
- package/dist/997.js +2334 -0
- package/{dist-types → dist}/build.d.ts +1 -1
- package/{dist-types → dist}/createCompiler.d.ts +1 -1
- package/dist/index.cjs +1043 -2531
- package/dist/index.d.ts +2 -0
- package/dist/index.js +563 -2579
- package/{dist-types → dist}/initConfigs.d.ts +2 -2
- package/{dist-types → dist}/inspectConfig.d.ts +2 -2
- package/{dist-types → dist}/progress/ProgressPlugin.d.ts +1 -1
- package/{dist-types → dist}/progress/helpers/bar.d.ts +1 -1
- package/{dist-types → dist}/progress/helpers/bus.d.ts +2 -2
- package/dist/progress/helpers/index.d.ts +4 -0
- package/{dist-types → dist}/webpackConfig.d.ts +2 -2
- package/package.json +8 -9
- package/dist-types/index.d.ts +0 -2
- package/dist-types/package.json +0 -1
- package/dist-types/progress/helpers/index.d.ts +0 -4
- /package/{dist-types → dist}/plugin.d.ts +0 -0
- /package/{dist-types → dist}/progress/helpers/log.d.ts +0 -0
- /package/{dist-types → dist}/progress/helpers/nonTty.d.ts +0 -0
- /package/{dist-types → dist}/progress/helpers/percentage.d.ts +0 -0
- /package/{dist-types → dist}/progress/helpers/types.d.ts +0 -0
- /package/{dist-types → dist}/progress/helpers/utils.d.ts +0 -0
- /package/{dist-types → dist}/provider.d.ts +0 -0
- /package/{dist-types → dist}/shared.d.ts +0 -0
- /package/{dist-types → dist}/types.d.ts +0 -0
package/dist/238.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
export const ids = [
|
|
2
|
+
'238'
|
|
3
|
+
];
|
|
4
|
+
export const modules = {
|
|
5
|
+
"./src/progress/ProgressPlugin.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
6
|
+
// EXPORTS
|
|
7
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
8
|
+
ProgressPlugin: ()=>/* binding */ ProgressPlugin
|
|
9
|
+
});
|
|
10
|
+
// EXTERNAL MODULE: external "@rsbuild/core"
|
|
11
|
+
var core_ = __webpack_require__("@rsbuild/core");
|
|
12
|
+
// EXTERNAL MODULE: external "picocolors"
|
|
13
|
+
var external_picocolors_ = __webpack_require__("picocolors");
|
|
14
|
+
// EXTERNAL MODULE: external "webpack"
|
|
15
|
+
var external_webpack_ = __webpack_require__("webpack");
|
|
16
|
+
// EXTERNAL MODULE: ./src/shared.ts
|
|
17
|
+
var shared = __webpack_require__("./src/shared.ts");
|
|
18
|
+
// EXTERNAL MODULE: external "node:console"
|
|
19
|
+
var external_node_console_ = __webpack_require__("node:console");
|
|
20
|
+
// EXTERNAL MODULE: ../../../node_modules/.pnpm/cli-truncate@2.1.0/node_modules/cli-truncate/index.js
|
|
21
|
+
var cli_truncate = __webpack_require__("../../../node_modules/.pnpm/cli-truncate@2.1.0/node_modules/cli-truncate/index.js");
|
|
22
|
+
var cli_truncate_default = /*#__PURE__*/ __webpack_require__.n(cli_truncate);
|
|
23
|
+
// EXTERNAL MODULE: ../../../node_modules/.pnpm/patch-console@1.0.0/node_modules/patch-console/build/index.js
|
|
24
|
+
var build = __webpack_require__("../../../node_modules/.pnpm/patch-console@1.0.0/node_modules/patch-console/build/index.js");
|
|
25
|
+
var build_default = /*#__PURE__*/ __webpack_require__.n(build);
|
|
26
|
+
const clamp = (x, min, max)=>Math.min(max, Math.max(min, x));
|
|
27
|
+
const defaultOption = {
|
|
28
|
+
total: 100,
|
|
29
|
+
current: 0,
|
|
30
|
+
color: 'green',
|
|
31
|
+
bgColor: 'gray',
|
|
32
|
+
char: '━',
|
|
33
|
+
width: 25,
|
|
34
|
+
buildIcon: '◯',
|
|
35
|
+
errorIcon: '✖',
|
|
36
|
+
errorInfo: 'compile failed',
|
|
37
|
+
message: '',
|
|
38
|
+
done: false,
|
|
39
|
+
spaceWidth: 1,
|
|
40
|
+
messageWidth: 25,
|
|
41
|
+
messageColor: 'gray',
|
|
42
|
+
id: '',
|
|
43
|
+
maxIdLen: 16,
|
|
44
|
+
hasErrors: false
|
|
45
|
+
};
|
|
46
|
+
const padding = (id, maxLen)=>{
|
|
47
|
+
const left = Math.floor((maxLen - id.length) / 2);
|
|
48
|
+
const right = maxLen - left - id.length;
|
|
49
|
+
return ' '.repeat(left) + id + ' '.repeat(right);
|
|
50
|
+
};
|
|
51
|
+
const FULL_WIDTH = 70; // display all info
|
|
52
|
+
const MIDDLE_WIDTH = 40; // remove message info
|
|
53
|
+
const renderBar = (option)=>{
|
|
54
|
+
const mergedOptions = {
|
|
55
|
+
...defaultOption,
|
|
56
|
+
...option
|
|
57
|
+
};
|
|
58
|
+
const { total, done, buildIcon, errorIcon, errorInfo, width, current, color, bgColor, char, message, messageWidth, spaceWidth, messageColor, maxIdLen, hasErrors } = mergedOptions;
|
|
59
|
+
const space = ' '.repeat(spaceWidth);
|
|
60
|
+
const percent = clamp(Math.floor(current / total * 100), 0, 100);
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
const barColor = external_picocolors_["default"][color];
|
|
63
|
+
// @ts-expect-error
|
|
64
|
+
const backgroundColor = external_picocolors_["default"][bgColor];
|
|
65
|
+
const doneColor = hasErrors ? external_picocolors_["default"].red : barColor;
|
|
66
|
+
const idColor = done ? doneColor : barColor;
|
|
67
|
+
const id = mergedOptions.id ? idColor(padding(mergedOptions.id, maxIdLen)) : '';
|
|
68
|
+
const { columns: terminalWidth = FULL_WIDTH } = process.stdout;
|
|
69
|
+
if (done) {
|
|
70
|
+
if (hasErrors) {
|
|
71
|
+
const message = external_picocolors_["default"].bold(doneColor(errorInfo));
|
|
72
|
+
if (terminalWidth >= MIDDLE_WIDTH) return [
|
|
73
|
+
idColor(errorIcon),
|
|
74
|
+
id,
|
|
75
|
+
doneColor(`${space}${message}`)
|
|
76
|
+
].join('');
|
|
77
|
+
return [
|
|
78
|
+
id,
|
|
79
|
+
doneColor(`${message}`)
|
|
80
|
+
].join('');
|
|
81
|
+
}
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
// @ts-expect-error
|
|
85
|
+
const msgStr = external_picocolors_["default"][messageColor](cli_truncate_default()(message, messageWidth, {
|
|
86
|
+
position: 'start'
|
|
87
|
+
}));
|
|
88
|
+
const left = clamp(Math.floor(percent * width / 100), 0, width);
|
|
89
|
+
const right = clamp(width - left, 0, width);
|
|
90
|
+
const barStr = `${barColor(char.repeat(left))}${backgroundColor(char.repeat(right))}`;
|
|
91
|
+
const percentStr = `${percent.toString().padStart(3)}%`;
|
|
92
|
+
if (terminalWidth >= FULL_WIDTH) return [
|
|
93
|
+
idColor(buildIcon),
|
|
94
|
+
id,
|
|
95
|
+
space,
|
|
96
|
+
barStr,
|
|
97
|
+
space,
|
|
98
|
+
percentStr,
|
|
99
|
+
space,
|
|
100
|
+
msgStr
|
|
101
|
+
].join('');
|
|
102
|
+
if (terminalWidth >= MIDDLE_WIDTH) return [
|
|
103
|
+
idColor(buildIcon),
|
|
104
|
+
id,
|
|
105
|
+
space,
|
|
106
|
+
barStr,
|
|
107
|
+
space,
|
|
108
|
+
percentStr
|
|
109
|
+
].join('');
|
|
110
|
+
return [
|
|
111
|
+
idColor(buildIcon),
|
|
112
|
+
id,
|
|
113
|
+
space,
|
|
114
|
+
percentStr
|
|
115
|
+
].join('');
|
|
116
|
+
};
|
|
117
|
+
// EXTERNAL MODULE: ../../../node_modules/.pnpm/ansi-escapes@4.3.2/node_modules/ansi-escapes/index.js
|
|
118
|
+
var ansi_escapes = __webpack_require__("../../../node_modules/.pnpm/ansi-escapes@4.3.2/node_modules/ansi-escapes/index.js");
|
|
119
|
+
var ansi_escapes_default = /*#__PURE__*/ __webpack_require__.n(ansi_escapes);
|
|
120
|
+
const create = (stream)=>{
|
|
121
|
+
let previousLineCount = 0;
|
|
122
|
+
let previousOutput = '';
|
|
123
|
+
const render = (str)=>{
|
|
124
|
+
const output = `${str}\n`;
|
|
125
|
+
if (output === previousOutput) return;
|
|
126
|
+
previousOutput = output;
|
|
127
|
+
stream.write(ansi_escapes_default().eraseLines(previousLineCount) + output);
|
|
128
|
+
previousLineCount = output.split('\n').length;
|
|
129
|
+
};
|
|
130
|
+
render.clear = ()=>{
|
|
131
|
+
stream.write(ansi_escapes_default().eraseLines(previousLineCount));
|
|
132
|
+
previousOutput = '';
|
|
133
|
+
previousLineCount = 0;
|
|
134
|
+
};
|
|
135
|
+
render.done = ()=>{
|
|
136
|
+
previousOutput = '';
|
|
137
|
+
previousLineCount = 0;
|
|
138
|
+
};
|
|
139
|
+
return render;
|
|
140
|
+
};
|
|
141
|
+
function _define_property(obj, key, value) {
|
|
142
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
143
|
+
value: value,
|
|
144
|
+
enumerable: true,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true
|
|
147
|
+
});
|
|
148
|
+
else obj[key] = value;
|
|
149
|
+
return obj;
|
|
150
|
+
}
|
|
151
|
+
const colorList = [
|
|
152
|
+
'green',
|
|
153
|
+
'cyan',
|
|
154
|
+
'yellow',
|
|
155
|
+
'blue',
|
|
156
|
+
'magenta'
|
|
157
|
+
];
|
|
158
|
+
const getProgressColor = (index)=>colorList[index % colorList.length];
|
|
159
|
+
class Bus {
|
|
160
|
+
update(state) {
|
|
161
|
+
const index = this.states.findIndex((i)=>i.id === state.id);
|
|
162
|
+
if (-1 === index) {
|
|
163
|
+
this.states.push(state);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
this.states[index] = state;
|
|
167
|
+
}
|
|
168
|
+
writeToStd(type = 'stdout', data) {
|
|
169
|
+
this.log.clear();
|
|
170
|
+
if (data) {
|
|
171
|
+
if ('stdout' === type) process.stdout.write(data);
|
|
172
|
+
else if ('stderr' === type) process.stderr.write(data);
|
|
173
|
+
}
|
|
174
|
+
this.log(this.prevOutput);
|
|
175
|
+
}
|
|
176
|
+
render() {
|
|
177
|
+
const maxIdLen = Math.max(...this.states.map((i)=>{
|
|
178
|
+
var _i_id;
|
|
179
|
+
return (null === (_i_id = i.id) || void 0 === _i_id ? void 0 : _i_id.length) ?? 0;
|
|
180
|
+
})) + 2;
|
|
181
|
+
const { columns = FULL_WIDTH } = process.stdout;
|
|
182
|
+
this.prevOutput = this.states.map((i, k)=>{
|
|
183
|
+
const bar = renderBar({
|
|
184
|
+
maxIdLen,
|
|
185
|
+
color: i.color ?? getProgressColor(k),
|
|
186
|
+
...i
|
|
187
|
+
});
|
|
188
|
+
if (bar) return cli_truncate_default()(bar, columns, {
|
|
189
|
+
position: 'end'
|
|
190
|
+
});
|
|
191
|
+
return null;
|
|
192
|
+
}).filter((item)=>null !== item).join('\n');
|
|
193
|
+
this.writeToStd();
|
|
194
|
+
}
|
|
195
|
+
destroy() {
|
|
196
|
+
if (!this.destroyed) this.restore();
|
|
197
|
+
this.destroyed = true;
|
|
198
|
+
}
|
|
199
|
+
clear() {
|
|
200
|
+
this.log.clear();
|
|
201
|
+
this.log.done();
|
|
202
|
+
}
|
|
203
|
+
constructor(){
|
|
204
|
+
_define_property(this, "states", []);
|
|
205
|
+
_define_property(this, "log", void 0);
|
|
206
|
+
_define_property(this, "restore", void 0);
|
|
207
|
+
_define_property(this, "prevOutput", void 0);
|
|
208
|
+
_define_property(this, "destroyed", false);
|
|
209
|
+
this.prevOutput = '';
|
|
210
|
+
this.log = create(process.stdout);
|
|
211
|
+
console.Console = external_node_console_.Console;
|
|
212
|
+
this.restore = build_default()((type, data)=>{
|
|
213
|
+
this.writeToStd(type, data);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const bus = new Bus();
|
|
218
|
+
/**
|
|
219
|
+
* Make the progress percentage more user friendly.
|
|
220
|
+
* The original percentage may pause at certain number for a long time,
|
|
221
|
+
* or decrease in some cases, which will confuse the user.
|
|
222
|
+
* So we format the percentage number and display a more smooth percentage.
|
|
223
|
+
*/ const createFriendlyPercentage = ()=>{
|
|
224
|
+
let prevPercentage = 0;
|
|
225
|
+
return (percentage)=>{
|
|
226
|
+
if (0 === percentage || 1 === percentage) {
|
|
227
|
+
prevPercentage = 0;
|
|
228
|
+
return percentage;
|
|
229
|
+
}
|
|
230
|
+
if (percentage <= prevPercentage) {
|
|
231
|
+
let step = 0;
|
|
232
|
+
if (prevPercentage < 0.3) step = 0.001;
|
|
233
|
+
else if (prevPercentage < 0.6) step = 0.002;
|
|
234
|
+
else if (prevPercentage < 0.8) step = 0.004;
|
|
235
|
+
else if (prevPercentage < 0.99) step = 0.002;
|
|
236
|
+
prevPercentage += step;
|
|
237
|
+
return prevPercentage;
|
|
238
|
+
}
|
|
239
|
+
prevPercentage = percentage;
|
|
240
|
+
return percentage;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
function createNonTTYLogger() {
|
|
244
|
+
let prevPercentage = 0;
|
|
245
|
+
const log = ({ id, done, current, hasErrors, compileTime })=>{
|
|
246
|
+
const suffix = external_picocolors_["default"].gray(`(${id})`);
|
|
247
|
+
if (done) {
|
|
248
|
+
// avoid printing done twice
|
|
249
|
+
if (100 === prevPercentage) return;
|
|
250
|
+
prevPercentage = 100;
|
|
251
|
+
if (hasErrors) core_.logger.error(`Built failed in ${compileTime} ${suffix}`);
|
|
252
|
+
else core_.logger.ready(`Built in ${compileTime} ${suffix}`);
|
|
253
|
+
} else if (current - prevPercentage > 10) {
|
|
254
|
+
prevPercentage = current;
|
|
255
|
+
core_.logger.info(`Build progress: ${current.toFixed(0)}% ${suffix}`);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
return {
|
|
259
|
+
log
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function ProgressPlugin_define_property(obj, key, value) {
|
|
263
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
264
|
+
value: value,
|
|
265
|
+
enumerable: true,
|
|
266
|
+
configurable: true,
|
|
267
|
+
writable: true
|
|
268
|
+
});
|
|
269
|
+
else obj[key] = value;
|
|
270
|
+
return obj;
|
|
271
|
+
}
|
|
272
|
+
class ProgressPlugin extends external_webpack_["default"].ProgressPlugin {
|
|
273
|
+
apply(compiler) {
|
|
274
|
+
super.apply(compiler);
|
|
275
|
+
let startTime = null;
|
|
276
|
+
compiler.hooks.compile.tap(this.name, ()=>{
|
|
277
|
+
this.compileTime = null;
|
|
278
|
+
startTime = process.hrtime();
|
|
279
|
+
});
|
|
280
|
+
compiler.hooks.done.tap(this.name, (stat)=>{
|
|
281
|
+
if (startTime) {
|
|
282
|
+
this.hasCompileErrors = stat.hasErrors();
|
|
283
|
+
const hrtime = process.hrtime(startTime);
|
|
284
|
+
const seconds = hrtime[0] + hrtime[1] / 1e9;
|
|
285
|
+
this.compileTime = (0, shared /* prettyTime */ .AS)(seconds);
|
|
286
|
+
startTime = null;
|
|
287
|
+
if (!this.hasCompileErrors) {
|
|
288
|
+
const suffix = this.id ? external_picocolors_["default"].gray(` (${this.id})`) : '';
|
|
289
|
+
core_.logger.ready(`Built in ${this.compileTime} ${suffix}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
constructor(options){
|
|
295
|
+
const { id = 'Rsbuild' } = options;
|
|
296
|
+
const nonTTYLogger = createNonTTYLogger();
|
|
297
|
+
const friendlyPercentage = createFriendlyPercentage();
|
|
298
|
+
super({
|
|
299
|
+
activeModules: false,
|
|
300
|
+
entries: true,
|
|
301
|
+
modules: true,
|
|
302
|
+
modulesCount: 5000,
|
|
303
|
+
profile: false,
|
|
304
|
+
dependencies: true,
|
|
305
|
+
dependenciesCount: 10000,
|
|
306
|
+
percentBy: null,
|
|
307
|
+
handler: (originalPercentage, message)=>{
|
|
308
|
+
const percentage = friendlyPercentage(originalPercentage);
|
|
309
|
+
const done = 1 === percentage;
|
|
310
|
+
if (process.stdout.isTTY) {
|
|
311
|
+
bus.update({
|
|
312
|
+
id,
|
|
313
|
+
current: 100 * percentage,
|
|
314
|
+
message,
|
|
315
|
+
done,
|
|
316
|
+
hasErrors: this.hasCompileErrors
|
|
317
|
+
});
|
|
318
|
+
bus.render();
|
|
319
|
+
} else nonTTYLogger.log({
|
|
320
|
+
id,
|
|
321
|
+
done,
|
|
322
|
+
current: 100 * percentage,
|
|
323
|
+
hasErrors: this.hasCompileErrors,
|
|
324
|
+
compileTime: this.compileTime
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}), ProgressPlugin_define_property(this, "name", 'ProgressPlugin'), ProgressPlugin_define_property(this, "id", void 0), ProgressPlugin_define_property(this, "hasCompileErrors", false), ProgressPlugin_define_property(this, "compileTime", null);
|
|
328
|
+
this.id = id;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|