@rsbuild/webpack 1.0.11 → 1.1.0-beta.0

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