@rsbuild/webpack 0.0.0-next-20231103091827

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.
Files changed (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/compiled/ansi-escapes/index.d.ts +248 -0
  4. package/compiled/ansi-escapes/index.js +1 -0
  5. package/compiled/ansi-escapes/license +9 -0
  6. package/compiled/ansi-escapes/package.json +1 -0
  7. package/compiled/ansi-escapes/type-fest/index.d.ts +2 -0
  8. package/compiled/babel-plugin-lodash/index.d.ts +1 -0
  9. package/compiled/babel-plugin-lodash/index.js +1 -0
  10. package/compiled/babel-plugin-lodash/license +44 -0
  11. package/compiled/babel-plugin-lodash/package.json +1 -0
  12. package/compiled/babel-plugin-transform-react-remove-prop-types/index.d.ts +1 -0
  13. package/compiled/babel-plugin-transform-react-remove-prop-types/index.js +1 -0
  14. package/compiled/babel-plugin-transform-react-remove-prop-types/license +22 -0
  15. package/compiled/babel-plugin-transform-react-remove-prop-types/package.json +1 -0
  16. package/compiled/cli-truncate/index.d.ts +96 -0
  17. package/compiled/cli-truncate/index.js +1 -0
  18. package/compiled/cli-truncate/license +9 -0
  19. package/compiled/cli-truncate/package.json +1 -0
  20. package/compiled/copy-webpack-plugin/index.d.ts +1 -0
  21. package/compiled/copy-webpack-plugin/index.js +22 -0
  22. package/compiled/copy-webpack-plugin/license +20 -0
  23. package/compiled/copy-webpack-plugin/package.json +1 -0
  24. package/compiled/patch-console/build/index.d.ts +4 -0
  25. package/compiled/patch-console/index.js +1 -0
  26. package/compiled/patch-console/package.json +1 -0
  27. package/compiled/schema-utils3/index.d.ts +1 -0
  28. package/compiled/schema-utils3/index.js +3 -0
  29. package/compiled/schema-utils3/license +20 -0
  30. package/compiled/schema-utils3/package.json +1 -0
  31. package/compiled/tapable/index.js +1 -0
  32. package/compiled/tapable/license +21 -0
  33. package/compiled/tapable/package.json +1 -0
  34. package/compiled/tapable/tapable.d.ts +116 -0
  35. package/compiled/webpack-manifest-plugin/index.js +1 -0
  36. package/compiled/webpack-manifest-plugin/license +21 -0
  37. package/compiled/webpack-manifest-plugin/package.json +1 -0
  38. package/compiled/webpack-manifest-plugin/types/helpers.d.ts +23 -0
  39. package/compiled/webpack-manifest-plugin/types/hooks.d.ts +24 -0
  40. package/compiled/webpack-manifest-plugin/types/index.d.ts +30 -0
  41. package/compiled/webpack-sources/index.d.ts +1 -0
  42. package/compiled/webpack-sources/index.js +1 -0
  43. package/compiled/webpack-sources/license +21 -0
  44. package/compiled/webpack-sources/package.json +1 -0
  45. package/dist/config/defaults.d.ts +3 -0
  46. package/dist/config/defaults.js +52 -0
  47. package/dist/config/normalize.d.ts +7 -0
  48. package/dist/config/normalize.js +33 -0
  49. package/dist/core/build.d.ts +20 -0
  50. package/dist/core/build.js +80 -0
  51. package/dist/core/createCompiler.d.ts +8 -0
  52. package/dist/core/createCompiler.js +68 -0
  53. package/dist/core/createContext.d.ts +13 -0
  54. package/dist/core/createContext.js +56 -0
  55. package/dist/core/devMiddleware.d.ts +5 -0
  56. package/dist/core/devMiddleware.js +73 -0
  57. package/dist/core/initConfigs.d.ts +14 -0
  58. package/dist/core/initConfigs.js +76 -0
  59. package/dist/core/initHooks.d.ts +19 -0
  60. package/dist/core/initHooks.js +44 -0
  61. package/dist/core/initPlugins.d.ts +9 -0
  62. package/dist/core/initPlugins.js +83 -0
  63. package/dist/core/inspectConfig.d.ts +20 -0
  64. package/dist/core/inspectConfig.js +81 -0
  65. package/dist/core/startDevServer.d.ts +5 -0
  66. package/dist/core/startDevServer.js +75 -0
  67. package/dist/core/webpackConfig.d.ts +9 -0
  68. package/dist/core/webpackConfig.js +164 -0
  69. package/dist/exports/webpack.d.ts +2 -0
  70. package/dist/exports/webpack.js +35 -0
  71. package/dist/index.d.ts +6 -0
  72. package/dist/index.js +34 -0
  73. package/dist/plugins/babel.d.ts +3 -0
  74. package/dist/plugins/babel.js +171 -0
  75. package/dist/plugins/basic.d.ts +5 -0
  76. package/dist/plugins/basic.js +60 -0
  77. package/dist/plugins/copy.d.ts +2 -0
  78. package/dist/plugins/copy.js +69 -0
  79. package/dist/plugins/css.d.ts +23 -0
  80. package/dist/plugins/css.js +123 -0
  81. package/dist/plugins/fallback.d.ts +2 -0
  82. package/dist/plugins/fallback.js +51 -0
  83. package/dist/plugins/hmr.d.ts +2 -0
  84. package/dist/plugins/hmr.js +41 -0
  85. package/dist/plugins/lazyCompilation.d.ts +2 -0
  86. package/dist/plugins/lazyCompilation.js +43 -0
  87. package/dist/plugins/less.d.ts +6 -0
  88. package/dist/plugins/less.js +65 -0
  89. package/dist/plugins/manifest.d.ts +2 -0
  90. package/dist/plugins/manifest.js +58 -0
  91. package/dist/plugins/minimize.d.ts +2 -0
  92. package/dist/plugins/minimize.js +64 -0
  93. package/dist/plugins/moduleScopes.d.ts +5 -0
  94. package/dist/plugins/moduleScopes.js +85 -0
  95. package/dist/plugins/output.d.ts +2 -0
  96. package/dist/plugins/output.js +66 -0
  97. package/dist/plugins/progress.d.ts +2 -0
  98. package/dist/plugins/progress.js +57 -0
  99. package/dist/plugins/react.d.ts +2 -0
  100. package/dist/plugins/react.js +96 -0
  101. package/dist/plugins/resolve.d.ts +2 -0
  102. package/dist/plugins/resolve.js +88 -0
  103. package/dist/plugins/sass.d.ts +2 -0
  104. package/dist/plugins/sass.js +76 -0
  105. package/dist/plugins/sri.d.ts +2 -0
  106. package/dist/plugins/sri.js +43 -0
  107. package/dist/plugins/tsLoader.d.ts +2 -0
  108. package/dist/plugins/tsLoader.js +103 -0
  109. package/dist/provider.d.ts +9 -0
  110. package/dist/provider.js +104 -0
  111. package/dist/shared/fs.d.ts +1 -0
  112. package/dist/shared/fs.js +38 -0
  113. package/dist/shared/index.d.ts +1 -0
  114. package/dist/shared/index.js +22 -0
  115. package/dist/shared/plugin.d.ts +5 -0
  116. package/dist/shared/plugin.js +111 -0
  117. package/dist/types/config/index.d.ts +30 -0
  118. package/dist/types/config/index.js +26 -0
  119. package/dist/types/config/security.d.ts +9 -0
  120. package/dist/types/config/security.js +16 -0
  121. package/dist/types/config/source.d.ts +26 -0
  122. package/dist/types/config/source.js +16 -0
  123. package/dist/types/config/tools.d.ts +52 -0
  124. package/dist/types/config/tools.js +16 -0
  125. package/dist/types/context.d.ts +17 -0
  126. package/dist/types/context.js +16 -0
  127. package/dist/types/hooks.d.ts +24 -0
  128. package/dist/types/hooks.js +16 -0
  129. package/dist/types/index.d.ts +5 -0
  130. package/dist/types/index.js +30 -0
  131. package/dist/types/plugin.d.ts +10 -0
  132. package/dist/types/plugin.js +16 -0
  133. package/dist/types/thirdParty/css.d.ts +7 -0
  134. package/dist/types/thirdParty/css.js +16 -0
  135. package/dist/types/thirdParty/index.d.ts +9 -0
  136. package/dist/types/thirdParty/index.js +16 -0
  137. package/dist/webpackPlugins/ModuleScopePlugin.d.ts +16 -0
  138. package/dist/webpackPlugins/ModuleScopePlugin.js +111 -0
  139. package/dist/webpackPlugins/ProgressPlugin/ProgressPlugin.d.ts +13 -0
  140. package/dist/webpackPlugins/ProgressPlugin/ProgressPlugin.js +102 -0
  141. package/dist/webpackPlugins/ProgressPlugin/helpers/bar.d.ts +5 -0
  142. package/dist/webpackPlugins/ProgressPlugin/helpers/bar.js +143 -0
  143. package/dist/webpackPlugins/ProgressPlugin/helpers/bus.d.ts +17 -0
  144. package/dist/webpackPlugins/ProgressPlugin/helpers/bus.js +105 -0
  145. package/dist/webpackPlugins/ProgressPlugin/helpers/index.d.ts +4 -0
  146. package/dist/webpackPlugins/ProgressPlugin/helpers/index.js +28 -0
  147. package/dist/webpackPlugins/ProgressPlugin/helpers/log.d.ts +8 -0
  148. package/dist/webpackPlugins/ProgressPlugin/helpers/log.js +62 -0
  149. package/dist/webpackPlugins/ProgressPlugin/helpers/nonTty.d.ts +15 -0
  150. package/dist/webpackPlugins/ProgressPlugin/helpers/nonTty.js +56 -0
  151. package/dist/webpackPlugins/ProgressPlugin/helpers/percentage.d.ts +7 -0
  152. package/dist/webpackPlugins/ProgressPlugin/helpers/percentage.js +52 -0
  153. package/dist/webpackPlugins/ProgressPlugin/helpers/type.d.ts +25 -0
  154. package/dist/webpackPlugins/ProgressPlugin/helpers/type.js +16 -0
  155. package/dist/webpackPlugins/ProgressPlugin/helpers/utils.d.ts +1 -0
  156. package/dist/webpackPlugins/ProgressPlugin/helpers/utils.js +30 -0
  157. package/package.json +88 -0
  158. package/static/ModuleFilenameHelpers.js +2 -0
@@ -0,0 +1,13 @@
1
+ import webpack from 'webpack';
2
+ import type { Props } from './helpers/type';
3
+ export interface ProgressOptions extends Omit<Partial<Props>, 'message' | 'total' | 'current' | 'done'> {
4
+ id?: string;
5
+ }
6
+ export declare class ProgressPlugin extends webpack.ProgressPlugin {
7
+ readonly name: string;
8
+ id: string;
9
+ hasCompileErrors: boolean;
10
+ compileTime: string | null;
11
+ constructor(options: ProgressOptions);
12
+ apply(compiler: webpack.Compiler): void;
13
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var ProgressPlugin_exports = {};
30
+ __export(ProgressPlugin_exports, {
31
+ ProgressPlugin: () => ProgressPlugin
32
+ });
33
+ module.exports = __toCommonJS(ProgressPlugin_exports);
34
+ var import_webpack = __toESM(require("webpack"));
35
+ var import_shared = require("@rsbuild/shared");
36
+ var import_helpers = require("./helpers");
37
+ var import_nonTty = require("./helpers/nonTty");
38
+ class ProgressPlugin extends import_webpack.default.ProgressPlugin {
39
+ constructor(options) {
40
+ const { id = "Rsbuild" } = options;
41
+ const nonTTYLogger = (0, import_nonTty.createNonTTYLogger)();
42
+ const friendlyPercentage = (0, import_helpers.createFriendlyPercentage)();
43
+ super({
44
+ activeModules: false,
45
+ entries: true,
46
+ modules: true,
47
+ modulesCount: 5e3,
48
+ profile: false,
49
+ dependencies: true,
50
+ dependenciesCount: 1e4,
51
+ percentBy: null,
52
+ handler: (percentage, message) => {
53
+ percentage = friendlyPercentage(percentage);
54
+ const done = percentage === 1;
55
+ if (process.stdout.isTTY) {
56
+ import_helpers.bus.update({
57
+ id,
58
+ current: percentage * 100,
59
+ message,
60
+ done,
61
+ hasErrors: this.hasCompileErrors
62
+ });
63
+ import_helpers.bus.render();
64
+ } else {
65
+ nonTTYLogger.log({
66
+ id,
67
+ done,
68
+ current: percentage * 100,
69
+ hasErrors: this.hasCompileErrors,
70
+ compileTime: this.compileTime
71
+ });
72
+ }
73
+ }
74
+ });
75
+ this.name = "ProgressPlugin";
76
+ this.hasCompileErrors = false;
77
+ this.compileTime = null;
78
+ this.id = id;
79
+ }
80
+ apply(compiler) {
81
+ super.apply(compiler);
82
+ let startTime = null;
83
+ compiler.hooks.compile.tap(this.name, () => {
84
+ this.compileTime = null;
85
+ startTime = process.hrtime();
86
+ });
87
+ compiler.hooks.done.tap(this.name, (stat) => {
88
+ if (startTime) {
89
+ this.hasCompileErrors = stat.hasErrors();
90
+ this.compileTime = (0, import_shared.prettyTime)(process.hrtime(startTime));
91
+ startTime = null;
92
+ if (!this.hasCompileErrors) {
93
+ import_shared.logger.ready(`${this.id} compiled in ${this.compileTime}`);
94
+ }
95
+ }
96
+ });
97
+ }
98
+ }
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ ProgressPlugin
102
+ });
@@ -0,0 +1,5 @@
1
+ import type { Props } from './type';
2
+ export declare const FULL_WIDTH = 70;
3
+ export declare const MIDDLE_WIDTH = 40;
4
+ export declare const SMALL_WIDTH = 15;
5
+ export declare const renderBar: (option: Partial<Props>) => string;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var bar_exports = {};
30
+ __export(bar_exports, {
31
+ FULL_WIDTH: () => FULL_WIDTH,
32
+ MIDDLE_WIDTH: () => MIDDLE_WIDTH,
33
+ SMALL_WIDTH: () => SMALL_WIDTH,
34
+ renderBar: () => renderBar
35
+ });
36
+ module.exports = __toCommonJS(bar_exports);
37
+ var import_cli_truncate = __toESM(require("../../../../compiled/cli-truncate"));
38
+ var import_utils = require("./utils");
39
+ var import_chalk = require("@rsbuild/shared/chalk");
40
+ const defaultOption = {
41
+ total: 100,
42
+ current: 0,
43
+ color: "green",
44
+ bgColor: "gray",
45
+ char: "━",
46
+ width: 25,
47
+ buildIcon: "◯",
48
+ errorIcon: "✖",
49
+ errorInfo: "compile failed",
50
+ message: "",
51
+ done: false,
52
+ spaceWidth: 1,
53
+ messageWidth: 25,
54
+ messageColor: "grey",
55
+ id: "",
56
+ maxIdLen: 16,
57
+ hasErrors: false
58
+ };
59
+ const padding = (id, maxLen) => {
60
+ const left = Math.floor((maxLen - id.length) / 2);
61
+ const right = maxLen - left - id.length;
62
+ return " ".repeat(left) + id + " ".repeat(right);
63
+ };
64
+ const FULL_WIDTH = 70;
65
+ const MIDDLE_WIDTH = 40;
66
+ const SMALL_WIDTH = 15;
67
+ const renderBar = (option) => {
68
+ const mergedOptions = {
69
+ ...defaultOption,
70
+ ...option
71
+ };
72
+ const {
73
+ total,
74
+ done,
75
+ buildIcon,
76
+ errorIcon,
77
+ errorInfo,
78
+ width,
79
+ current,
80
+ color,
81
+ bgColor,
82
+ char,
83
+ message,
84
+ messageWidth,
85
+ spaceWidth,
86
+ messageColor,
87
+ maxIdLen,
88
+ hasErrors
89
+ } = mergedOptions;
90
+ const space = " ".repeat(spaceWidth);
91
+ const percent = (0, import_utils.clamp)(Math.floor(current / total * 100), 0, 100);
92
+ const barColor = Reflect.get(import_chalk.chalk, color);
93
+ const backgroundColor = Reflect.get(import_chalk.chalk, bgColor);
94
+ const doneColor = hasErrors ? import_chalk.chalk.bold.red : Reflect.get(import_chalk.chalk, color);
95
+ const idColor = done ? doneColor : barColor;
96
+ const id = mergedOptions.id ? idColor(padding(mergedOptions.id, maxIdLen)) : "";
97
+ const { columns: terminalWidth = FULL_WIDTH } = process.stdout;
98
+ if (done) {
99
+ if (hasErrors) {
100
+ const message2 = doneColor(errorInfo);
101
+ if (terminalWidth >= MIDDLE_WIDTH) {
102
+ return [idColor(errorIcon), id, doneColor(`${space}${message2}`)].join(
103
+ ""
104
+ );
105
+ }
106
+ return [id, doneColor(`${message2}`)].join("");
107
+ }
108
+ return "";
109
+ }
110
+ const msgStr = Reflect.get(
111
+ import_chalk.chalk,
112
+ messageColor
113
+ )((0, import_cli_truncate.default)(message, messageWidth, { position: "start" }));
114
+ const left = (0, import_utils.clamp)(Math.floor(percent * width / 100), 0, width);
115
+ const right = (0, import_utils.clamp)(width - left, 0, width);
116
+ const barStr = `${barColor(char.repeat(left))}${backgroundColor(
117
+ char.repeat(right)
118
+ )}`;
119
+ const percentStr = `${percent.toString().padStart(3)}%`;
120
+ if (terminalWidth >= FULL_WIDTH) {
121
+ return [
122
+ idColor(buildIcon),
123
+ id,
124
+ space,
125
+ barStr,
126
+ space,
127
+ percentStr,
128
+ space,
129
+ msgStr
130
+ ].join("");
131
+ }
132
+ if (terminalWidth >= MIDDLE_WIDTH) {
133
+ return [idColor(buildIcon), id, space, barStr, space, percentStr].join("");
134
+ }
135
+ return [idColor(buildIcon), id, space, percentStr].join("");
136
+ };
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ FULL_WIDTH,
140
+ MIDDLE_WIDTH,
141
+ SMALL_WIDTH,
142
+ renderBar
143
+ });
@@ -0,0 +1,17 @@
1
+ import type { Props } from './type';
2
+ import type { LogUpdate } from './log';
3
+ declare class Bus {
4
+ states: Partial<Props>[];
5
+ log: LogUpdate;
6
+ restore: () => void;
7
+ prevOutput: string;
8
+ destroyed: boolean;
9
+ constructor();
10
+ update(state: Partial<Props>): void;
11
+ writeToStd(type?: 'stdout' | 'stderr', data?: string): void;
12
+ render(): void;
13
+ destroy(): void;
14
+ clear(): void;
15
+ }
16
+ declare const bus: Bus;
17
+ export { bus };
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var bus_exports = {};
30
+ __export(bus_exports, {
31
+ bus: () => bus
32
+ });
33
+ module.exports = __toCommonJS(bus_exports);
34
+ var import_console = require("console");
35
+ var import_patch_console = __toESM(require("../../../../compiled/patch-console"));
36
+ var import_cli_truncate = __toESM(require("../../../../compiled/cli-truncate"));
37
+ var import_bar = require("./bar");
38
+ var import_log = require("./log");
39
+ var import_shared = require("@rsbuild/shared");
40
+ class Bus {
41
+ constructor() {
42
+ this.states = [];
43
+ this.destroyed = false;
44
+ this.prevOutput = "";
45
+ this.log = (0, import_log.create)(process.stdout);
46
+ console.Console = import_console.Console;
47
+ this.restore = (0, import_patch_console.default)((type, data) => {
48
+ this.writeToStd(type, data);
49
+ });
50
+ }
51
+ update(state) {
52
+ const index = this.states.findIndex((i) => i.id === state.id);
53
+ if (index === -1) {
54
+ this.states.push(state);
55
+ return;
56
+ }
57
+ this.states[index] = state;
58
+ }
59
+ writeToStd(type = "stdout", data) {
60
+ this.log.clear();
61
+ if (data) {
62
+ if (type === "stdout") {
63
+ process.stdout.write(data);
64
+ } else if (type === "stderr") {
65
+ process.stderr.write(data);
66
+ }
67
+ }
68
+ this.log(this.prevOutput);
69
+ }
70
+ render() {
71
+ const maxIdLen = Math.max(...this.states.map((i) => {
72
+ var _a, _b;
73
+ return (_b = (_a = i.id) == null ? void 0 : _a.length) != null ? _b : 0;
74
+ })) + 2;
75
+ const { columns = import_bar.FULL_WIDTH } = process.stdout;
76
+ this.prevOutput = this.states.map((i, k) => {
77
+ var _a;
78
+ const bar = (0, import_bar.renderBar)({
79
+ maxIdLen,
80
+ color: (_a = i.color) != null ? _a : (0, import_shared.getProgressColor)(k),
81
+ ...i
82
+ });
83
+ if (bar) {
84
+ return (0, import_cli_truncate.default)(bar, columns, { position: "end" });
85
+ }
86
+ return null;
87
+ }).filter((item) => item !== null).join("\n");
88
+ this.writeToStd();
89
+ }
90
+ destroy() {
91
+ if (!this.destroyed) {
92
+ this.restore();
93
+ }
94
+ this.destroyed = true;
95
+ }
96
+ clear() {
97
+ this.log.clear();
98
+ this.log.done();
99
+ }
100
+ }
101
+ const bus = new Bus();
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ bus
105
+ });
@@ -0,0 +1,4 @@
1
+ export * from './bus';
2
+ export * from './bar';
3
+ export * from './type';
4
+ export * from './percentage';
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var helpers_exports = {};
17
+ module.exports = __toCommonJS(helpers_exports);
18
+ __reExport(helpers_exports, require("./bus"), module.exports);
19
+ __reExport(helpers_exports, require("./bar"), module.exports);
20
+ __reExport(helpers_exports, require("./type"), module.exports);
21
+ __reExport(helpers_exports, require("./percentage"), module.exports);
22
+ // Annotate the CommonJS export names for ESM import in node:
23
+ 0 && (module.exports = {
24
+ ...require("./bus"),
25
+ ...require("./bar"),
26
+ ...require("./type"),
27
+ ...require("./percentage")
28
+ });
@@ -0,0 +1,8 @@
1
+ import { Writable } from 'stream';
2
+ export interface LogUpdate {
3
+ clear: () => void;
4
+ done: () => void;
5
+ (str: string): void;
6
+ }
7
+ declare const create: (stream: Writable) => LogUpdate;
8
+ export { create };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var log_exports = {};
30
+ __export(log_exports, {
31
+ create: () => create
32
+ });
33
+ module.exports = __toCommonJS(log_exports);
34
+ var import_ansi_escapes = __toESM(require("../../../../compiled/ansi-escapes"));
35
+ const create = (stream) => {
36
+ let previousLineCount = 0;
37
+ let previousOutput = "";
38
+ const render = (str) => {
39
+ const output = `${str}
40
+ `;
41
+ if (output === previousOutput) {
42
+ return;
43
+ }
44
+ previousOutput = output;
45
+ stream.write(import_ansi_escapes.default.eraseLines(previousLineCount) + output);
46
+ previousLineCount = output.split("\n").length;
47
+ };
48
+ render.clear = () => {
49
+ stream.write(import_ansi_escapes.default.eraseLines(previousLineCount));
50
+ previousOutput = "";
51
+ previousLineCount = 0;
52
+ };
53
+ render.done = () => {
54
+ previousOutput = "";
55
+ previousLineCount = 0;
56
+ };
57
+ return render;
58
+ };
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ create
62
+ });
@@ -0,0 +1,15 @@
1
+ export declare function createNonTTYLogger(): {
2
+ log: ({
3
+ id,
4
+ done,
5
+ current,
6
+ hasErrors,
7
+ compileTime
8
+ }: {
9
+ id: string;
10
+ done: boolean;
11
+ current: number;
12
+ hasErrors: boolean;
13
+ compileTime: string | null;
14
+ }) => void;
15
+ };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var nonTty_exports = {};
20
+ __export(nonTty_exports, {
21
+ createNonTTYLogger: () => createNonTTYLogger
22
+ });
23
+ module.exports = __toCommonJS(nonTty_exports);
24
+ var import_shared = require("@rsbuild/shared");
25
+ function createNonTTYLogger() {
26
+ let prevPercentage = 0;
27
+ const log = ({
28
+ id,
29
+ done,
30
+ current,
31
+ hasErrors,
32
+ compileTime
33
+ }) => {
34
+ if (done) {
35
+ if (prevPercentage === 100) {
36
+ return;
37
+ }
38
+ prevPercentage = 100;
39
+ if (hasErrors) {
40
+ import_shared.logger.error(`${id} compile failed in ${compileTime}`);
41
+ } else {
42
+ import_shared.logger.ready(`${id} compiled in ${compileTime}`);
43
+ }
44
+ } else if (current - prevPercentage > 10) {
45
+ prevPercentage = current;
46
+ import_shared.logger.info(`${id} compile progress: ${current.toFixed(0)}%`);
47
+ }
48
+ };
49
+ return {
50
+ log
51
+ };
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ createNonTTYLogger
56
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Make the progress percentage more user friendly.
3
+ * The original percentage may pause at certain number for a long time,
4
+ * or decrease in some cases, which will confuse the user.
5
+ * So we format the percentage number and display a more smooth percentage.
6
+ */
7
+ export declare const createFriendlyPercentage: () => (percentage: number) => number;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var percentage_exports = {};
20
+ __export(percentage_exports, {
21
+ createFriendlyPercentage: () => createFriendlyPercentage
22
+ });
23
+ module.exports = __toCommonJS(percentage_exports);
24
+ const createFriendlyPercentage = () => {
25
+ let prevPercentage = 0;
26
+ return (percentage) => {
27
+ if (percentage === 0 || percentage === 1) {
28
+ prevPercentage = 0;
29
+ return percentage;
30
+ }
31
+ if (percentage <= prevPercentage) {
32
+ let step = 0;
33
+ if (prevPercentage < 0.3) {
34
+ step = 1e-3;
35
+ } else if (prevPercentage < 0.6) {
36
+ step = 2e-3;
37
+ } else if (prevPercentage < 0.8) {
38
+ step = 4e-3;
39
+ } else if (prevPercentage < 0.99) {
40
+ step = 2e-3;
41
+ }
42
+ prevPercentage += step;
43
+ return prevPercentage;
44
+ }
45
+ prevPercentage = percentage;
46
+ return percentage;
47
+ };
48
+ };
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ createFriendlyPercentage
52
+ });
@@ -0,0 +1,25 @@
1
+ import type { chalk } from '@rsbuild/shared/chalk';
2
+ type Color = (typeof chalk)['ForegroundColor'];
3
+ export type Props = {
4
+ total: number;
5
+ current: number;
6
+ color: Color;
7
+ bgColor: Color;
8
+ char: string;
9
+ width: number;
10
+ buildIcon: string;
11
+ errorIcon: string;
12
+ errorInfo: string;
13
+ message: string;
14
+ done: boolean;
15
+ messageWidth: number;
16
+ spaceWidth: number;
17
+ messageColor: Color;
18
+ id: string;
19
+ maxIdLen: number;
20
+ hasErrors: boolean;
21
+ };
22
+ export type BusOption = {
23
+ state: Props[];
24
+ };
25
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var type_exports = {};
16
+ module.exports = __toCommonJS(type_exports);
@@ -0,0 +1 @@
1
+ export declare const clamp: (x: number, min: number, max: number) => number;