@rsbuild/webpack 1.1.0 → 1.1.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/238.js CHANGED
@@ -3,28 +3,11 @@ export const ids = [
3
3
  ];
4
4
  export const modules = {
5
5
  "./src/progress/ProgressPlugin.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
6
- // EXPORTS
7
6
  __webpack_require__.d(__webpack_exports__, {
8
- ProgressPlugin: ()=>/* binding */ ProgressPlugin
7
+ ProgressPlugin: ()=>ProgressPlugin
9
8
  });
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 = {
9
+ var core_ = __webpack_require__("@rsbuild/core"), external_picocolors_ = __webpack_require__("picocolors"), external_webpack_ = __webpack_require__("webpack"), external_node_console_ = __webpack_require__("node:console"), cli_truncate = __webpack_require__("../../../node_modules/.pnpm/cli-truncate@2.1.0/node_modules/cli-truncate/index.js"), cli_truncate_default = __webpack_require__.n(cli_truncate), build = __webpack_require__("../../../node_modules/.pnpm/patch-console@1.0.0/node_modules/patch-console/build/index.js"), build_default = __webpack_require__.n(build);
10
+ let clamp = (x, min, max)=>Math.min(max, Math.max(min, x)), defaultOption = {
28
11
  total: 100,
29
12
  current: 0,
30
13
  color: 'green',
@@ -35,61 +18,39 @@ export const modules = {
35
18
  errorIcon: '✖',
36
19
  errorInfo: 'compile failed',
37
20
  message: '',
38
- done: false,
21
+ done: !1,
39
22
  spaceWidth: 1,
40
23
  messageWidth: 25,
41
24
  messageColor: 'gray',
42
25
  id: '',
43
26
  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;
27
+ hasErrors: !1
28
+ }, padding = (id, maxLen)=>{
29
+ let left = Math.floor((maxLen - id.length) / 2), right = maxLen - left - id.length;
49
30
  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 = {
31
+ }, renderBar = (option)=>{
32
+ let mergedOptions = {
55
33
  ...defaultOption,
56
34
  ...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;
35
+ }, { total, done, buildIcon, errorIcon, errorInfo, width, current, color, bgColor, char, message, messageWidth, spaceWidth, messageColor, maxIdLen, hasErrors } = mergedOptions, space = ' '.repeat(spaceWidth), percent = clamp(Math.floor(current / total * 100), 0, 100), barColor = external_picocolors_.default[color], backgroundColor = external_picocolors_.default[bgColor], doneColor = hasErrors ? external_picocolors_.default.red : barColor, idColor = done ? doneColor : barColor, id = mergedOptions.id ? idColor(padding(mergedOptions.id, maxIdLen)) : '', { columns: terminalWidth = 70 } = process.stdout;
69
36
  if (done) {
70
37
  if (hasErrors) {
71
- const message = external_picocolors_["default"].bold(doneColor(errorInfo));
72
- if (terminalWidth >= MIDDLE_WIDTH) return [
38
+ let message = external_picocolors_.default.bold(doneColor(errorInfo));
39
+ return terminalWidth >= 40 ? [
73
40
  idColor(errorIcon),
74
41
  id,
75
42
  doneColor(`${space}${message}`)
76
- ].join('');
77
- return [
43
+ ].join('') : [
78
44
  id,
79
45
  doneColor(`${message}`)
80
46
  ].join('');
81
47
  }
82
48
  return '';
83
49
  }
84
- // @ts-expect-error
85
- const msgStr = external_picocolors_["default"][messageColor](cli_truncate_default()(message, messageWidth, {
50
+ let msgStr = external_picocolors_.default[messageColor](cli_truncate_default()(message, messageWidth, {
86
51
  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 [
52
+ })), left = clamp(Math.floor(percent * width / 100), 0, width), right = clamp(width - left, 0, width), barStr = `${barColor(char.repeat(left))}${backgroundColor(char.repeat(right))}`, percentStr = `${percent.toString().padStart(3)}%`;
53
+ return terminalWidth >= 70 ? [
93
54
  idColor(buildIcon),
94
55
  id,
95
56
  space,
@@ -98,67 +59,49 @@ export const modules = {
98
59
  percentStr,
99
60
  space,
100
61
  msgStr
101
- ].join('');
102
- if (terminalWidth >= MIDDLE_WIDTH) return [
62
+ ].join('') : terminalWidth >= 40 ? [
103
63
  idColor(buildIcon),
104
64
  id,
105
65
  space,
106
66
  barStr,
107
67
  space,
108
68
  percentStr
109
- ].join('');
110
- return [
69
+ ].join('') : [
111
70
  idColor(buildIcon),
112
71
  id,
113
72
  space,
114
73
  percentStr
115
74
  ].join('');
116
75
  };
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;
76
+ var ansi_escapes = __webpack_require__("../../../node_modules/.pnpm/ansi-escapes@4.3.2/node_modules/ansi-escapes/index.js"), ansi_escapes_default = __webpack_require__.n(ansi_escapes);
77
+ let create = (stream)=>{
78
+ let previousLineCount = 0, previousOutput = '', render = (str)=>{
79
+ let output = `${str}\n`;
80
+ if (output !== previousOutput) previousOutput = output, stream.write(ansi_escapes_default().eraseLines(previousLineCount) + output), previousLineCount = output.split('\n').length;
129
81
  };
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;
82
+ return render.clear = ()=>{
83
+ stream.write(ansi_escapes_default().eraseLines(previousLineCount)), previousOutput = '', previousLineCount = 0;
84
+ }, render.done = ()=>{
85
+ previousOutput = '', previousLineCount = 0;
86
+ }, render;
140
87
  };
141
88
  function _define_property(obj, key, value) {
142
- if (key in obj) Object.defineProperty(obj, key, {
89
+ return key in obj ? Object.defineProperty(obj, key, {
143
90
  value: value,
144
- enumerable: true,
145
- configurable: true,
146
- writable: true
147
- });
148
- else obj[key] = value;
149
- return obj;
91
+ enumerable: !0,
92
+ configurable: !0,
93
+ writable: !0
94
+ }) : obj[key] = value, obj;
150
95
  }
151
- const colorList = [
96
+ let colorList = [
152
97
  'green',
153
98
  'cyan',
154
99
  'yellow',
155
100
  'blue',
156
101
  'magenta'
157
- ];
158
- const getProgressColor = (index)=>colorList[index % colorList.length];
159
- class Bus {
102
+ ], getProgressColor = (index)=>colorList[index % colorList.length], bus = new class Bus {
160
103
  update(state) {
161
- const index = this.states.findIndex((i)=>i.id === state.id);
104
+ let index = this.states.findIndex((i)=>i.id === state.id);
162
105
  if (-1 === index) {
163
106
  this.states.push(state);
164
107
  return;
@@ -166,157 +109,100 @@ export const modules = {
166
109
  this.states[index] = state;
167
110
  }
168
111
  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);
112
+ this.log.clear(), data && ('stdout' === type ? process.stdout.write(data) : 'stderr' === type && process.stderr.write(data)), this.log(this.prevOutput);
175
113
  }
176
114
  render() {
177
- const maxIdLen = Math.max(...this.states.map((i)=>{
115
+ let maxIdLen = Math.max(...this.states.map((i)=>{
178
116
  var _i_id;
179
117
  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;
118
+ })) + 2, { columns = 70 } = process.stdout;
182
119
  this.prevOutput = this.states.map((i, k)=>{
183
- const bar = renderBar({
120
+ let bar = renderBar({
184
121
  maxIdLen,
185
122
  color: i.color ?? getProgressColor(k),
186
123
  ...i
187
124
  });
188
- if (bar) return cli_truncate_default()(bar, columns, {
125
+ return bar ? cli_truncate_default()(bar, columns, {
189
126
  position: 'end'
190
- });
191
- return null;
192
- }).filter((item)=>null !== item).join('\n');
193
- this.writeToStd();
127
+ }) : null;
128
+ }).filter((item)=>null !== item).join('\n'), this.writeToStd();
194
129
  }
195
130
  destroy() {
196
- if (!this.destroyed) this.restore();
197
- this.destroyed = true;
131
+ !this.destroyed && this.restore(), this.destroyed = !0;
198
132
  }
199
133
  clear() {
200
- this.log.clear();
201
- this.log.done();
134
+ this.log.clear(), this.log.done();
202
135
  }
203
136
  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)=>{
137
+ _define_property(this, "states", []), _define_property(this, "log", void 0), _define_property(this, "restore", void 0), _define_property(this, "prevOutput", void 0), _define_property(this, "destroyed", !1), this.prevOutput = '', this.log = create(process.stdout), console.Console = external_node_console_.Console, this.restore = build_default()((type, data)=>{
213
138
  this.writeToStd(type, data);
214
139
  });
215
140
  }
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 = ()=>{
141
+ }(), createFriendlyPercentage = ()=>{
224
142
  let prevPercentage = 0;
225
143
  return (percentage)=>{
226
- if (0 === percentage || 1 === percentage) {
227
- prevPercentage = 0;
228
- return percentage;
229
- }
144
+ if (0 === percentage || 1 === percentage) return prevPercentage = 0, percentage;
230
145
  if (percentage <= prevPercentage) {
231
146
  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;
147
+ return prevPercentage < 0.3 ? step = 0.001 : prevPercentage < 0.6 ? step = 0.002 : prevPercentage < 0.8 ? step = 0.004 : prevPercentage < 0.99 && (step = 0.002), prevPercentage += step;
238
148
  }
239
- prevPercentage = percentage;
240
- return percentage;
149
+ return prevPercentage = percentage, percentage;
241
150
  };
242
151
  };
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
152
  function ProgressPlugin_define_property(obj, key, value) {
263
- if (key in obj) Object.defineProperty(obj, key, {
153
+ return key in obj ? Object.defineProperty(obj, key, {
264
154
  value: value,
265
- enumerable: true,
266
- configurable: true,
267
- writable: true
268
- });
269
- else obj[key] = value;
270
- return obj;
155
+ enumerable: !0,
156
+ configurable: !0,
157
+ writable: !0
158
+ }) : obj[key] = value, obj;
271
159
  }
272
- class ProgressPlugin extends external_webpack_["default"].ProgressPlugin {
160
+ class ProgressPlugin extends external_webpack_.default.ProgressPlugin {
273
161
  apply(compiler) {
274
162
  super.apply(compiler);
275
163
  let startTime = null;
276
164
  compiler.hooks.compile.tap(this.name, ()=>{
277
- this.compileTime = null;
278
- startTime = process.hrtime();
279
- });
280
- compiler.hooks.done.tap(this.name, (stat)=>{
165
+ this.compileTime = null, startTime = process.hrtime();
166
+ }), compiler.hooks.done.tap(this.name, (stat)=>{
281
167
  if (startTime) {
282
168
  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})`) : '';
169
+ let hrtime = process.hrtime(startTime), seconds = hrtime[0] + hrtime[1] / 1e9;
170
+ if (this.compileTime = this.prettyTime(seconds), startTime = null, !this.hasCompileErrors) {
171
+ let suffix = this.id ? external_picocolors_.default.gray(` (${this.id})`) : '';
289
172
  core_.logger.ready(`Built in ${this.compileTime} ${suffix}`);
290
173
  }
291
174
  }
292
175
  });
293
176
  }
294
177
  constructor(options){
295
- const { id = 'Rsbuild' } = options;
296
- const nonTTYLogger = createNonTTYLogger();
297
- const friendlyPercentage = createFriendlyPercentage();
178
+ let prevPercentage, { id = 'Rsbuild' } = options;
179
+ let nonTTYLogger = (prevPercentage = 0, {
180
+ log: ({ id, done, current, hasErrors, compileTime })=>{
181
+ let suffix = external_picocolors_.default.gray(`(${id})`);
182
+ if (done) {
183
+ if (100 === prevPercentage) return;
184
+ prevPercentage = 100, hasErrors ? core_.logger.error(`Built failed in ${compileTime} ${suffix}`) : core_.logger.ready(`Built in ${compileTime} ${suffix}`);
185
+ } else current - prevPercentage > 10 && (prevPercentage = current, core_.logger.info(`Build progress: ${current.toFixed(0)}% ${suffix}`));
186
+ }
187
+ }), friendlyPercentage = createFriendlyPercentage();
298
188
  super({
299
- activeModules: false,
300
- entries: true,
301
- modules: true,
189
+ activeModules: !1,
190
+ entries: !0,
191
+ modules: !0,
302
192
  modulesCount: 5000,
303
- profile: false,
304
- dependencies: true,
193
+ profile: !1,
194
+ dependencies: !0,
305
195
  dependenciesCount: 10000,
306
196
  percentBy: null,
307
197
  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({
198
+ let percentage = friendlyPercentage(originalPercentage), done = 1 === percentage;
199
+ process.stdout.isTTY ? (bus.update({
200
+ id,
201
+ current: 100 * percentage,
202
+ message,
203
+ done,
204
+ hasErrors: this.hasCompileErrors
205
+ }), bus.render()) : nonTTYLogger.log({
320
206
  id,
321
207
  done,
322
208
  current: 100 * percentage,
@@ -324,8 +210,7 @@ export const modules = {
324
210
  compileTime: this.compileTime
325
211
  });
326
212
  }
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;
213
+ }), ProgressPlugin_define_property(this, "name", 'ProgressPlugin'), ProgressPlugin_define_property(this, "id", void 0), ProgressPlugin_define_property(this, "hasCompileErrors", !1), ProgressPlugin_define_property(this, "compileTime", null), ProgressPlugin_define_property(this, "prettyTime", void 0), this.id = id, this.prettyTime = options.prettyTime;
329
214
  }
330
215
  }
331
216
  }