@rsbuild/webpack 1.6.0 → 1.6.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/index.js CHANGED
@@ -1,344 +1 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
2
- import MultiStats from "webpack/lib/MultiStats.js";
3
- import { reduceConfigsWithContext } from "reduce-configs";
4
- import node_fs from "node:fs";
5
- var installedChunks, installChunk, __webpack_modules__ = {
6
- "@rsbuild/core": function(module) {
7
- module.exports = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__;
8
- }
9
- }, __webpack_module_cache__ = {};
10
- function __webpack_require__(moduleId) {
11
- var cachedModule = __webpack_module_cache__[moduleId];
12
- if (void 0 !== cachedModule) return cachedModule.exports;
13
- var module = __webpack_module_cache__[moduleId] = {
14
- id: moduleId,
15
- loaded: !1,
16
- exports: {}
17
- };
18
- return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.loaded = !0, module.exports;
19
- }
20
- __webpack_require__.m = __webpack_modules__, __webpack_require__.n = (module)=>{
21
- var getter = module && module.__esModule ? ()=>module.default : ()=>module;
22
- return __webpack_require__.d(getter, {
23
- a: getter
24
- }), getter;
25
- }, __webpack_require__.d = (exports, definition)=>{
26
- for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key) && Object.defineProperty(exports, key, {
27
- enumerable: !0,
28
- get: definition[key]
29
- });
30
- }, __webpack_require__.f = {}, __webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>(__webpack_require__.f[key](chunkId, promises), promises), [])), __webpack_require__.u = (chunkId)=>"0~" + chunkId + ".js", __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.nmd = (module)=>(module.paths = [], module.children || (module.children = []), module), installedChunks = {
31
- 410: 0
32
- }, installChunk = (data)=>{
33
- var moduleId, chunkId, __webpack_ids__ = data.__webpack_ids__, __webpack_modules__ = data.__webpack_modules__, __webpack_runtime__ = data.__webpack_runtime__, i = 0;
34
- for(moduleId in __webpack_modules__)__webpack_require__.o(__webpack_modules__, moduleId) && (__webpack_require__.m[moduleId] = __webpack_modules__[moduleId]);
35
- for(__webpack_runtime__ && __webpack_runtime__(__webpack_require__); i < __webpack_ids__.length; i++)chunkId = __webpack_ids__[i], __webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId] && installedChunks[chunkId][0](), installedChunks[__webpack_ids__[i]] = 0;
36
- }, __webpack_require__.f.j = function(chunkId, promises) {
37
- var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
38
- if (0 !== installedChunkData) if (installedChunkData) promises.push(installedChunkData[1]);
39
- else {
40
- var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, (e)=>{
41
- throw 0 !== installedChunks[chunkId] && (installedChunks[chunkId] = void 0), e;
42
- }), promise = Promise.race([
43
- promise,
44
- new Promise((resolve)=>{
45
- installedChunkData = installedChunks[chunkId] = [
46
- resolve
47
- ];
48
- })
49
- ]);
50
- promises.push(installedChunkData[1] = promise);
51
- }
52
- };
53
- var core_ = __webpack_require__("@rsbuild/core");
54
- let castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
55
- arr
56
- ];
57
- async function modifyWebpackChain(context, utils, chain) {
58
- core_.logger.debug('modify webpack chain');
59
- let [modifiedChain] = await context.hooks.modifyWebpackChain.callChain({
60
- environment: utils.environment.name,
61
- args: [
62
- chain,
63
- utils
64
- ]
65
- });
66
- if (utils.environment.config.tools?.webpackChain) for (let item of castArray(utils.environment.config.tools.webpackChain))item(modifiedChain, utils);
67
- return core_.logger.debug('modify webpack chain done'), modifiedChain;
68
- }
69
- async function modifyWebpackConfig(context, webpackConfig, utils) {
70
- core_.logger.debug('modify webpack config');
71
- let [modifiedConfig] = await context.hooks.modifyWebpackConfig.callChain({
72
- environment: utils.environment.name,
73
- args: [
74
- webpackConfig,
75
- utils
76
- ]
77
- });
78
- return utils.environment.config.tools?.webpack && (modifiedConfig = reduceConfigsWithContext({
79
- initial: modifiedConfig,
80
- config: utils.environment.config.tools.webpack,
81
- ctx: utils,
82
- mergeFn: utils.mergeConfig
83
- })), core_.logger.debug('modify webpack config done'), modifiedConfig;
84
- }
85
- async function getChainUtils(target, environment, helpers) {
86
- let { default: webpack } = await import("webpack");
87
- return {
88
- ...helpers.getChainUtils(target, environment),
89
- name: ({
90
- web: 'client',
91
- node: 'server',
92
- 'web-worker': 'web-worker'
93
- })[target] || '',
94
- webpack,
95
- HtmlWebpackPlugin: helpers.getHTMLPlugin()
96
- };
97
- }
98
- async function generateWebpackConfig({ target, context, environment, helpers }) {
99
- let chainUtils = await getChainUtils(target, context.environments[environment], helpers), { default: webpack } = await import("webpack"), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, SourceMapDevToolPlugin, HotModuleReplacementPlugin } = webpack, bundlerChain = await helpers.modifyBundlerChain(context, {
100
- ...chainUtils,
101
- bundler: {
102
- BannerPlugin,
103
- DefinePlugin,
104
- IgnorePlugin,
105
- ProvidePlugin,
106
- SourceMapDevToolPlugin,
107
- HotModuleReplacementPlugin
108
- }
109
- }), webpackConfig = (await modifyWebpackChain(context, chainUtils, bundlerChain)).toConfig(), configUtils = helpers.getConfigUtils(()=>webpackConfig, chainUtils);
110
- return webpackConfig = await modifyWebpackConfig(context, webpackConfig, configUtils);
111
- }
112
- async function initConfigs({ context, pluginManager, rsbuildOptions, helpers }) {
113
- let normalizedConfig = await helpers.initRsbuildConfig({
114
- context,
115
- pluginManager
116
- }), webpackConfigs = await Promise.all(Object.entries(normalizedConfig.environments).map(([environment, config])=>generateWebpackConfig({
117
- target: config.output.target,
118
- context,
119
- environment,
120
- helpers
121
- })));
122
- if ('verbose' === core_.logger.level) {
123
- let inspect = async ()=>{
124
- await helpers.inspectConfig({
125
- context,
126
- bundler: 'webpack',
127
- pluginManager,
128
- inspectOptions: {
129
- verbose: !0,
130
- writeToDisk: !0
131
- },
132
- rsbuildOptions,
133
- bundlerConfigs: webpackConfigs
134
- });
135
- };
136
- context.hooks.onBeforeBuild.tap(async ({ isFirstCompile })=>{
137
- isFirstCompile && await inspect();
138
- }), context.hooks.onAfterStartDevServer.tap(inspect);
139
- }
140
- return {
141
- webpackConfigs
142
- };
143
- }
144
- async function createCompiler_createCompiler(options) {
145
- core_.logger.debug('creating compiler');
146
- let HOOK_NAME = 'rsbuild:compiler', { helpers, context } = options, { webpackConfigs } = await initConfigs(options);
147
- await context.hooks.onBeforeCreateCompiler.callBatch({
148
- bundlerConfigs: webpackConfigs,
149
- environments: context.environments
150
- });
151
- let { default: webpack } = await import("webpack"), compiler = webpack(1 === webpackConfigs.length ? webpackConfigs[0] : webpackConfigs);
152
- return compiler.hooks.run.tap(HOOK_NAME, ()=>{
153
- context.buildState.status = 'building';
154
- }), compiler.hooks.watchRun.tap(HOOK_NAME, ()=>{
155
- context.buildState.status = 'building';
156
- }), compiler.hooks.invalid.tap(HOOK_NAME, ()=>{
157
- context.buildState.stats = null, context.buildState.status = 'idle', context.buildState.hasErrors = !1;
158
- }), compiler.hooks.done.tap(HOOK_NAME, (statsInstance)=>{
159
- let stats = helpers.getRsbuildStats(statsInstance, compiler, context.action), hasErrors = statsInstance.hasErrors();
160
- context.buildState.stats = stats, context.buildState.status = 'done', context.buildState.hasErrors = hasErrors, context.socketServer?.onBuildDone();
161
- let { message, level } = helpers.formatStats(stats, hasErrors);
162
- 'error' === level ? core_.logger.error(message) : 'warning' === level && core_.logger.warn(message);
163
- }), 'dev' === context.action && helpers.registerDevHook({
164
- compiler,
165
- context,
166
- bundlerConfigs: webpackConfigs,
167
- MultiStatsCtor: MultiStats
168
- }), await context.hooks.onAfterCreateCompiler.callBatch({
169
- compiler,
170
- environments: context.environments
171
- }), core_.logger.debug('compiler created'), {
172
- compiler,
173
- webpackConfigs
174
- };
175
- }
176
- let build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
177
- let compiler, bundlerConfigs, { helpers, context } = initOptions;
178
- if (customCompiler) compiler = customCompiler;
179
- else {
180
- let result = await createCompiler_createCompiler(initOptions);
181
- compiler = result.compiler, bundlerConfigs = result.webpackConfigs;
182
- }
183
- if (helpers.registerBuildHook({
184
- context,
185
- bundlerConfigs: bundlerConfigs,
186
- compiler,
187
- isWatch: !!watch,
188
- MultiStatsCtor: MultiStats
189
- }), watch) return compiler.watch({}, (err)=>{
190
- err && core_.logger.error(err);
191
- }), {
192
- close: ()=>new Promise((resolve)=>{
193
- compiler.close(()=>{
194
- resolve();
195
- });
196
- })
197
- };
198
- let { stats } = await new Promise((resolve, reject)=>{
199
- compiler.run((err, stats)=>{
200
- err ? reject(err) : context.buildState.hasErrors ? reject(Error('webpack build failed.')) : compiler.close((closeErr)=>{
201
- closeErr && core_.logger.error(closeErr), resolve({
202
- stats
203
- });
204
- });
205
- });
206
- });
207
- return {
208
- stats,
209
- close: async ()=>{}
210
- };
211
- };
212
- async function applyTsConfigPathsPlugin({ chain, CHAIN_ID, mainFields, extensions, configFile }) {
213
- let { TsconfigPathsPlugin } = await import("tsconfig-paths-webpack-plugin");
214
- chain.resolve.plugin(CHAIN_ID.RESOLVE_PLUGIN.TS_CONFIG_PATHS).use(TsconfigPathsPlugin, [
215
- {
216
- configFile,
217
- extensions,
218
- mainFields: mainFields
219
- }
220
- ]);
221
- }
222
- let webpackProvider = async ({ context, pluginManager, rsbuildOptions, helpers })=>{
223
- let { default: cssExtractPlugin } = await import("mini-css-extract-plugin");
224
- if (helpers.setCssExtractPlugin(cssExtractPlugin), helpers.setHTMLPlugin) {
225
- let { default: htmlPlugin } = await import("html-webpack-plugin");
226
- helpers.setHTMLPlugin(htmlPlugin);
227
- }
228
- let createCompiler = async ()=>(await createCompiler_createCompiler({
229
- context,
230
- pluginManager,
231
- rsbuildOptions,
232
- helpers
233
- })).compiler;
234
- return pluginManager.addPlugins([
235
- {
236
- name: 'rsbuild-webpack:adaptor',
237
- setup (api) {
238
- api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, target })=>{
239
- let { config, tsconfigPath } = environment, aliasStrategy = config.source.aliasStrategy ?? config.resolve.aliasStrategy;
240
- tsconfigPath && 'prefer-tsconfig' === aliasStrategy && await applyTsConfigPathsPlugin({
241
- chain,
242
- CHAIN_ID,
243
- configFile: tsconfigPath,
244
- mainFields: ((chain, target)=>{
245
- let mainFields = chain.resolve.mainFields.values();
246
- return mainFields.length ? mainFields : castArray(target).includes('web') || target.includes('web-worker') ? [
247
- 'browser',
248
- 'module',
249
- 'main'
250
- ] : [
251
- 'module',
252
- 'main'
253
- ];
254
- })(chain, target),
255
- extensions: chain.resolve.extensions.values()
256
- });
257
- let { progressBar } = config.dev;
258
- if (progressBar) {
259
- let { ProgressPlugin } = await Promise.all([
260
- __webpack_require__.e("0"),
261
- __webpack_require__.e("502")
262
- ]).then(__webpack_require__.bind(__webpack_require__, "./src/progress/ProgressPlugin.ts"));
263
- chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin, [
264
- {
265
- id: environment.name,
266
- prettyTime: helpers.prettyTime,
267
- ...!0 === progressBar ? {} : progressBar
268
- }
269
- ]);
270
- }
271
- let { copy } = config.output;
272
- if (copy) {
273
- let { default: CopyPlugin } = await import("copy-webpack-plugin"), options = Array.isArray(copy) ? {
274
- patterns: copy
275
- } : copy;
276
- chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
277
- options
278
- ]);
279
- }
280
- }), api.modifyWebpackConfig(async (config)=>{
281
- let copyPlugin = config.plugins?.find((item)=>item?.constructor.name === 'CopyPlugin');
282
- copyPlugin && copyPlugin.patterns.every((pattern)=>'string' != typeof pattern && pattern.context && !node_fs.existsSync(pattern.context)) && (config.plugins = config.plugins?.filter((item)=>item?.constructor.name !== 'CopyPlugin'));
283
- });
284
- }
285
- }
286
- ]), {
287
- bundler: 'webpack',
288
- createCompiler,
289
- async initConfigs () {
290
- let { webpackConfigs } = await initConfigs({
291
- context,
292
- pluginManager,
293
- rsbuildOptions,
294
- helpers
295
- });
296
- return webpackConfigs;
297
- },
298
- async createDevServer (options) {
299
- let config = await helpers.initRsbuildConfig({
300
- context,
301
- pluginManager
302
- });
303
- return helpers.createDevServer({
304
- context,
305
- pluginManager,
306
- rsbuildOptions
307
- }, createCompiler, config, options);
308
- },
309
- async startDevServer (options) {
310
- let config = await helpers.initRsbuildConfig({
311
- context,
312
- pluginManager
313
- });
314
- return (await helpers.createDevServer({
315
- context,
316
- pluginManager,
317
- rsbuildOptions
318
- }, createCompiler, config, options)).listen();
319
- },
320
- build: async (options)=>build({
321
- context,
322
- pluginManager,
323
- rsbuildOptions,
324
- helpers
325
- }, options),
326
- async inspectConfig (inspectOptions) {
327
- let bundlerConfigs = (await initConfigs({
328
- context,
329
- pluginManager,
330
- rsbuildOptions,
331
- helpers
332
- })).webpackConfigs;
333
- return await helpers.inspectConfig({
334
- context,
335
- pluginManager,
336
- bundler: 'webpack',
337
- bundlerConfigs,
338
- rsbuildOptions,
339
- inspectOptions
340
- });
341
- }
342
- };
343
- };
344
- export { webpackProvider };
1
+ export { webpackProvider } from "./161.js";
@@ -0,0 +1,25 @@
1
+ var __webpack_modules__ = {}, __webpack_module_cache__ = {};
2
+ function __webpack_require__(moduleId) {
3
+ var cachedModule = __webpack_module_cache__[moduleId];
4
+ if (void 0 !== cachedModule) return cachedModule.exports;
5
+ var module = __webpack_module_cache__[moduleId] = {
6
+ id: moduleId,
7
+ loaded: !1,
8
+ exports: {}
9
+ };
10
+ return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.loaded = !0, module.exports;
11
+ }
12
+ __webpack_require__.m = __webpack_modules__, __webpack_require__.add = function registerModules(modules) {
13
+ Object.assign(__webpack_require__.m, modules);
14
+ }, __webpack_require__.n = (module)=>{
15
+ var getter = module && module.__esModule ? ()=>module.default : ()=>module;
16
+ return __webpack_require__.d(getter, {
17
+ a: getter
18
+ }), getter;
19
+ }, __webpack_require__.d = (exports, definition)=>{
20
+ for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key) && Object.defineProperty(exports, key, {
21
+ enumerable: !0,
22
+ get: definition[key]
23
+ });
24
+ }, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.nmd = (module)=>(module.paths = [], module.children || (module.children = []), module);
25
+ export { __webpack_require__ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/webpack",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "homepage": "https://rsbuild.rs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,21 +24,21 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "copy-webpack-plugin": "11.0.0",
27
- "html-webpack-plugin": "^5.6.4",
27
+ "html-webpack-plugin": "^5.6.5",
28
28
  "mini-css-extract-plugin": "2.9.4",
29
29
  "picocolors": "^1.1.1",
30
30
  "reduce-configs": "^1.1.1",
31
31
  "tsconfig-paths-webpack-plugin": "4.2.0",
32
- "webpack": "^5.102.1"
32
+ "webpack": "^5.103.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@rslib/core": "0.16.1",
36
- "@types/node": "^22.18.12",
35
+ "@rslib/core": "0.18.0",
36
+ "@types/node": "^24.10.1",
37
37
  "ansi-escapes": "4.3.2",
38
38
  "cli-truncate": "2.1.0",
39
39
  "patch-console": "1.0.0",
40
40
  "typescript": "^5.9.3",
41
- "@rsbuild/core": "1.6.0",
41
+ "@rsbuild/core": "1.6.8",
42
42
  "@scripts/test-helper": "1.0.1"
43
43
  },
44
44
  "peerDependencies": {
package/dist/0~502.js DELETED
@@ -1,204 +0,0 @@
1
- import picocolors from "picocolors";
2
- import webpack from "webpack";
3
- import { Console } from "node:console";
4
- import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
5
- export const __webpack_id__ = "502";
6
- export const __webpack_ids__ = [
7
- "502"
8
- ];
9
- export const __webpack_modules__ = {
10
- "./src/progress/ProgressPlugin.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
11
- __webpack_require__.d(__webpack_exports__, {
12
- ProgressPlugin: ()=>ProgressPlugin
13
- });
14
- var core_ = __webpack_require__("@rsbuild/core"), 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);
15
- let clamp = (x, min, max)=>Math.min(max, Math.max(min, x)), defaultOption = {
16
- total: 100,
17
- current: 0,
18
- color: 'green',
19
- bgColor: 'gray',
20
- char: '━',
21
- width: 25,
22
- buildIcon: '◯',
23
- errorIcon: '✖',
24
- errorInfo: 'compile failed',
25
- message: '',
26
- done: !1,
27
- spaceWidth: 1,
28
- messageWidth: 25,
29
- messageColor: 'gray',
30
- id: '',
31
- maxIdLen: 16,
32
- hasErrors: !1
33
- };
34
- var build = __webpack_require__("../../../node_modules/.pnpm/patch-console@1.0.0/node_modules/patch-console/build/index.js"), build_default = __webpack_require__.n(build), 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);
35
- let colorList = [
36
- 'green',
37
- 'cyan',
38
- 'yellow',
39
- 'blue',
40
- 'magenta'
41
- ], bus = new class {
42
- states = [];
43
- log;
44
- restore;
45
- prevOutput;
46
- destroyed = !1;
47
- constructor(){
48
- var stream;
49
- let previousLineCount, previousOutput, render;
50
- this.prevOutput = '', this.log = (stream = process.stdout, previousLineCount = 0, previousOutput = '', (render = (str)=>{
51
- let output = `${str}\n`;
52
- output !== previousOutput && (previousOutput = output, stream.write(ansi_escapes_default().eraseLines(previousLineCount) + output), previousLineCount = output.split('\n').length);
53
- }).clear = ()=>{
54
- stream.write(ansi_escapes_default().eraseLines(previousLineCount)), previousOutput = '', previousLineCount = 0;
55
- }, render.done = ()=>{
56
- previousOutput = '', previousLineCount = 0;
57
- }, render), console.Console = Console, this.restore = build_default()((type, data)=>{
58
- this.writeToStd(type, data);
59
- });
60
- }
61
- update(state) {
62
- let index = this.states.findIndex((i)=>i.id === state.id);
63
- -1 === index ? this.states.push(state) : this.states[index] = state;
64
- }
65
- writeToStd(type = 'stdout', data) {
66
- this.log.clear(), data && ('stdout' === type ? process.stdout.write(data) : 'stderr' === type && process.stderr.write(data)), this.log(this.prevOutput);
67
- }
68
- render() {
69
- let maxIdLen = Math.max(...this.states.map((i)=>i.id?.length ?? 0)) + 2, { columns = 70 } = process.stdout;
70
- this.prevOutput = this.states.map((i, k)=>{
71
- let bar = ((option)=>{
72
- var id;
73
- let left, right, mergedOptions = {
74
- ...defaultOption,
75
- ...option
76
- }, { 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 = picocolors[color], backgroundColor = picocolors[bgColor], doneColor = hasErrors ? picocolors.red : barColor, idColor = done ? doneColor : barColor, id1 = mergedOptions.id ? idColor((left = Math.floor((maxIdLen - (id = mergedOptions.id).length) / 2), right = maxIdLen - left - id.length, ' '.repeat(left) + id + ' '.repeat(right))) : '', { columns: terminalWidth = 70 } = process.stdout;
77
- if (done) {
78
- if (hasErrors) {
79
- let message = picocolors.bold(doneColor(errorInfo));
80
- return terminalWidth >= 40 ? [
81
- idColor(errorIcon),
82
- id1,
83
- doneColor(`${space}${message}`)
84
- ].join('') : [
85
- id1,
86
- doneColor(`${message}`)
87
- ].join('');
88
- }
89
- return '';
90
- }
91
- let msgStr = picocolors[messageColor](cli_truncate_default()(message, messageWidth, {
92
- position: 'start'
93
- })), left1 = clamp(Math.floor(percent * width / 100), 0, width), right1 = clamp(width - left1, 0, width), barStr = `${barColor(char.repeat(left1))}${backgroundColor(char.repeat(right1))}`, percentStr = `${percent.toString().padStart(3)}%`;
94
- return terminalWidth >= 70 ? [
95
- idColor(buildIcon),
96
- id1,
97
- space,
98
- barStr,
99
- space,
100
- percentStr,
101
- space,
102
- msgStr
103
- ].join('') : terminalWidth >= 40 ? [
104
- idColor(buildIcon),
105
- id1,
106
- space,
107
- barStr,
108
- space,
109
- percentStr
110
- ].join('') : [
111
- idColor(buildIcon),
112
- id1,
113
- space,
114
- percentStr
115
- ].join('');
116
- })({
117
- maxIdLen,
118
- color: i.color ?? colorList[k % colorList.length],
119
- ...i
120
- });
121
- return bar ? cli_truncate_default()(bar, columns, {
122
- position: 'end'
123
- }) : null;
124
- }).filter((item)=>null !== item).join('\n'), this.writeToStd();
125
- }
126
- destroy() {
127
- this.destroyed || this.restore(), this.destroyed = !0;
128
- }
129
- clear() {
130
- this.log.clear(), this.log.done();
131
- }
132
- }();
133
- class ProgressPlugin extends webpack.ProgressPlugin {
134
- name = 'ProgressPlugin';
135
- id;
136
- hasCompileErrors = !1;
137
- compileTime = null;
138
- prettyTime;
139
- constructor(options){
140
- let prevPercentage, prevPercentage1, { id = 'Rsbuild' } = options, nonTTYLogger = (prevPercentage = 0, {
141
- log: ({ id, done, current, hasErrors, compileTime })=>{
142
- let suffix = picocolors.gray(`(${id})`);
143
- if (done) {
144
- if (100 === prevPercentage) return;
145
- prevPercentage = 100, hasErrors ? core_.logger.error(`built failed in ${compileTime} ${suffix}`) : core_.logger.ready(`built in ${compileTime} ${suffix}`);
146
- } else current - prevPercentage > 10 && (prevPercentage = current, core_.logger.info(`build progress: ${current.toFixed(0)}% ${suffix}`));
147
- }
148
- }), friendlyPercentage = (prevPercentage1 = 0, (percentage)=>{
149
- if (0 === percentage || 1 === percentage) return prevPercentage1 = 0, percentage;
150
- if (percentage <= prevPercentage1) {
151
- let step = 0;
152
- return prevPercentage1 < 0.3 ? step = 0.001 : prevPercentage1 < 0.6 ? step = 0.002 : prevPercentage1 < 0.8 ? step = 0.004 : prevPercentage1 < 0.99 && (step = 0.002), prevPercentage1 += step;
153
- }
154
- return prevPercentage1 = percentage, percentage;
155
- });
156
- super({
157
- activeModules: !1,
158
- entries: !0,
159
- modules: !0,
160
- modulesCount: 5000,
161
- profile: !1,
162
- dependencies: !0,
163
- dependenciesCount: 10000,
164
- percentBy: null,
165
- handler: (originalPercentage, message)=>{
166
- let percentage = friendlyPercentage(originalPercentage), done = 1 === percentage;
167
- process.stdout.isTTY ? (bus.update({
168
- id,
169
- current: 100 * percentage,
170
- message,
171
- done,
172
- hasErrors: this.hasCompileErrors
173
- }), bus.render()) : nonTTYLogger.log({
174
- id,
175
- done,
176
- current: 100 * percentage,
177
- hasErrors: this.hasCompileErrors,
178
- compileTime: this.compileTime
179
- });
180
- }
181
- }), this.id = id, this.prettyTime = options.prettyTime;
182
- }
183
- apply(compiler) {
184
- super.apply(compiler);
185
- let startTime = null;
186
- compiler.hooks.compile.tap(this.name, ()=>{
187
- this.compileTime = null, startTime = process.hrtime();
188
- }), compiler.hooks.done.tap(this.name, (stat)=>{
189
- if (startTime) {
190
- this.hasCompileErrors = stat.hasErrors();
191
- let hrtime = process.hrtime(startTime), seconds = hrtime[0] + hrtime[1] / 1e9;
192
- if (this.compileTime = this.prettyTime(seconds), startTime = null, !this.hasCompileErrors) {
193
- let suffix = this.id ? picocolors.gray(` (${this.id})`) : '';
194
- core_.logger.ready(`built in ${this.compileTime} ${suffix}`);
195
- }
196
- }
197
- });
198
- }
199
- }
200
- },
201
- stream: function(module) {
202
- module.exports = __WEBPACK_EXTERNAL_MODULE_stream__;
203
- }
204
- };