@rslib/core 0.20.0 → 0.20.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/compiled/rslog/index.d.ts +18 -2
- package/compiled/rslog/package.json +1 -1
- package/dist/chokidar.js +1467 -0
- package/dist/chokidar.js.LICENSE.txt +1 -0
- package/dist/index.js +375 -80
- package/dist/rslib-runtime.js +18 -0
- package/dist/tinyglobby.js +2177 -0
- package/dist-types/config.d.ts +6 -1
- package/dist-types/css/cssConfig.d.ts +2 -2
- package/dist-types/utils/color.d.ts +1 -2
- package/dist-types/utils/helper.d.ts +1 -1
- package/package.json +13 -14
- package/compiled/chokidar/index.d.ts +0 -346
- package/compiled/chokidar/index.js +0 -1778
- package/compiled/chokidar/license +0 -21
- package/compiled/chokidar/package.json +0 -1
- package/compiled/picocolors/index.d.ts +0 -55
- package/compiled/picocolors/index.js +0 -132
- package/compiled/picocolors/license +0 -15
- package/compiled/picocolors/package.json +0 -1
- package/compiled/rslog/index.js +0 -300
- package/compiled/tinyglobby/index.d.ts +0 -46
- package/compiled/tinyglobby/index.js +0 -3061
- package/compiled/tinyglobby/license +0 -21
- package/compiled/tinyglobby/package.json +0 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,279 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import node_util from "node:util";
|
|
2
|
+
import node_process from "node:process";
|
|
3
|
+
import node_os from "node:os";
|
|
4
|
+
import node_tty from "node:tty";
|
|
3
5
|
import node_path, { basename as external_node_path_basename, dirname, extname, isAbsolute, join } from "node:path";
|
|
4
6
|
import node_fs, { promises as external_node_fs_promises } from "node:fs";
|
|
5
7
|
import promises from "node:fs/promises";
|
|
6
|
-
import node_util from "node:util";
|
|
7
8
|
import * as __rspack_external__rsbuild_core_1b356efc from "@rsbuild/core";
|
|
8
9
|
import { createRsbuild, defineConfig, loadConfig, loadEnv, mergeRsbuildConfig, rspack } from "@rsbuild/core";
|
|
9
|
-
import { glob } from "../compiled/tinyglobby/index.js";
|
|
10
10
|
import { createRequire } from "node:module";
|
|
11
11
|
import { createRequire as external_module_createRequire } from "module";
|
|
12
12
|
import { getUndoPath, ABSOLUTE_PUBLIC_PATH, isCssFile, DTS_EXTENSIONS_PATTERN, SWC_HELPERS, AUTO_PUBLIC_PATH, CSS_EXTENSIONS_PATTERN, JS_EXTENSIONS_PATTERN, isCssGlobalFile, SINGLE_DOT_PATH_SEGMENT, BASE_URI, isCssModulesFile } from "./108.js";
|
|
13
|
+
function checkNodeVersion() {
|
|
14
|
+
const { versions } = process;
|
|
15
|
+
if ("styleText" in node_util || !versions.node || versions.bun || versions.deno) return;
|
|
16
|
+
throw new Error(`Unsupported Node.js version: "${process.versions.node || 'unknown'}". Expected Node.js >= 20.`);
|
|
17
|
+
}
|
|
18
|
+
checkNodeVersion();
|
|
19
|
+
const createStyler = (style)=>(text)=>node_util.styleText(style, String(text));
|
|
20
|
+
const color = {
|
|
21
|
+
dim: createStyler('dim'),
|
|
22
|
+
red: createStyler('red'),
|
|
23
|
+
bold: createStyler('bold'),
|
|
24
|
+
blue: createStyler('blue'),
|
|
25
|
+
cyan: createStyler('cyan'),
|
|
26
|
+
gray: createStyler('gray'),
|
|
27
|
+
black: createStyler('black'),
|
|
28
|
+
green: createStyler('green'),
|
|
29
|
+
white: createStyler('white'),
|
|
30
|
+
reset: createStyler('reset'),
|
|
31
|
+
yellow: createStyler('yellow'),
|
|
32
|
+
magenta: createStyler('magenta'),
|
|
33
|
+
underline: createStyler('underline'),
|
|
34
|
+
strikethrough: createStyler('strikethrough')
|
|
35
|
+
};
|
|
36
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : node_process.argv) {
|
|
37
|
+
const prefix = flag.startsWith('-') ? '' : 1 === flag.length ? '-' : '--';
|
|
38
|
+
const position = argv.indexOf(prefix + flag);
|
|
39
|
+
const terminatorPosition = argv.indexOf('--');
|
|
40
|
+
return -1 !== position && (-1 === terminatorPosition || position < terminatorPosition);
|
|
41
|
+
}
|
|
42
|
+
const { env: dist_env } = node_process;
|
|
43
|
+
let flagForceColor;
|
|
44
|
+
if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) flagForceColor = 0;
|
|
45
|
+
else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) flagForceColor = 1;
|
|
46
|
+
function envForceColor() {
|
|
47
|
+
if (!('FORCE_COLOR' in dist_env)) return;
|
|
48
|
+
if ('true' === dist_env.FORCE_COLOR) return 1;
|
|
49
|
+
if ('false' === dist_env.FORCE_COLOR) return 0;
|
|
50
|
+
if (0 === dist_env.FORCE_COLOR.length) return 1;
|
|
51
|
+
const level = Math.min(Number.parseInt(dist_env.FORCE_COLOR, 10), 3);
|
|
52
|
+
if (![
|
|
53
|
+
0,
|
|
54
|
+
1,
|
|
55
|
+
2,
|
|
56
|
+
3
|
|
57
|
+
].includes(level)) return;
|
|
58
|
+
return level;
|
|
59
|
+
}
|
|
60
|
+
function translateLevel(level) {
|
|
61
|
+
if (0 === level) return false;
|
|
62
|
+
return {
|
|
63
|
+
level,
|
|
64
|
+
hasBasic: true,
|
|
65
|
+
has256: level >= 2,
|
|
66
|
+
has16m: level >= 3
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
70
|
+
const noFlagForceColor = envForceColor();
|
|
71
|
+
if (void 0 !== noFlagForceColor) flagForceColor = noFlagForceColor;
|
|
72
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
73
|
+
if (0 === forceColor) return 0;
|
|
74
|
+
if (sniffFlags) {
|
|
75
|
+
if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) return 3;
|
|
76
|
+
if (hasFlag('color=256')) return 2;
|
|
77
|
+
}
|
|
78
|
+
if ('TF_BUILD' in dist_env && 'AGENT_NAME' in dist_env) return 1;
|
|
79
|
+
if (haveStream && !streamIsTTY && void 0 === forceColor) return 0;
|
|
80
|
+
const min = forceColor || 0;
|
|
81
|
+
if ('dumb' === dist_env.TERM) return min;
|
|
82
|
+
if ('win32' === node_process.platform) {
|
|
83
|
+
const osRelease = node_os.release().split('.');
|
|
84
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
if ('CI' in dist_env) {
|
|
88
|
+
if ([
|
|
89
|
+
'GITHUB_ACTIONS',
|
|
90
|
+
'GITEA_ACTIONS',
|
|
91
|
+
'CIRCLECI'
|
|
92
|
+
].some((key)=>key in dist_env)) return 3;
|
|
93
|
+
if ([
|
|
94
|
+
'TRAVIS',
|
|
95
|
+
'APPVEYOR',
|
|
96
|
+
'GITLAB_CI',
|
|
97
|
+
'BUILDKITE',
|
|
98
|
+
'DRONE'
|
|
99
|
+
].some((sign)=>sign in dist_env) || 'codeship' === dist_env.CI_NAME) return 1;
|
|
100
|
+
return min;
|
|
101
|
+
}
|
|
102
|
+
if ('TEAMCITY_VERSION' in dist_env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(dist_env.TEAMCITY_VERSION) ? 1 : 0;
|
|
103
|
+
if ('truecolor' === dist_env.COLORTERM) return 3;
|
|
104
|
+
if ('xterm-kitty' === dist_env.TERM) return 3;
|
|
105
|
+
if ('xterm-ghostty' === dist_env.TERM) return 3;
|
|
106
|
+
if ('wezterm' === dist_env.TERM) return 3;
|
|
107
|
+
if ('TERM_PROGRAM' in dist_env) {
|
|
108
|
+
const version = Number.parseInt((dist_env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
109
|
+
switch(dist_env.TERM_PROGRAM){
|
|
110
|
+
case 'iTerm.app':
|
|
111
|
+
return version >= 3 ? 3 : 2;
|
|
112
|
+
case 'Apple_Terminal':
|
|
113
|
+
return 2;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (/-256(color)?$/i.test(dist_env.TERM)) return 2;
|
|
117
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(dist_env.TERM)) return 1;
|
|
118
|
+
if ('COLORTERM' in dist_env) return 1;
|
|
119
|
+
return min;
|
|
120
|
+
}
|
|
121
|
+
function createSupportsColor(stream, options = {}) {
|
|
122
|
+
const level = _supportsColor(stream, {
|
|
123
|
+
streamIsTTY: stream && stream.isTTY,
|
|
124
|
+
...options
|
|
125
|
+
});
|
|
126
|
+
return translateLevel(level);
|
|
127
|
+
}
|
|
128
|
+
const supportsColor = {
|
|
129
|
+
stdout: createSupportsColor({
|
|
130
|
+
isTTY: node_tty.isatty(1)
|
|
131
|
+
}),
|
|
132
|
+
stderr: createSupportsColor({
|
|
133
|
+
isTTY: node_tty.isatty(2)
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
const supports_color = supportsColor;
|
|
137
|
+
const colorLevel = supports_color.stdout ? supports_color.stdout.level : 0;
|
|
138
|
+
let errorStackRegExp = /at [^\r\n]{0,200}:\d+:\d+[\s\)]*$/;
|
|
139
|
+
let anonymousErrorStackRegExp = /at [^\r\n]{0,200}\(<anonymous>\)$/;
|
|
140
|
+
let indexErrorStackRegExp = /at [^\r\n]{0,200}\(index\s\d+\)$/;
|
|
141
|
+
let isErrorStackMessage = (message)=>errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message) || indexErrorStackRegExp.test(message);
|
|
142
|
+
let startColor = [
|
|
143
|
+
189,
|
|
144
|
+
255,
|
|
145
|
+
243
|
|
146
|
+
];
|
|
147
|
+
let endColor = [
|
|
148
|
+
74,
|
|
149
|
+
194,
|
|
150
|
+
154
|
|
151
|
+
];
|
|
152
|
+
let isWord = (char)=>!/[\s\n]/.test(char);
|
|
153
|
+
let gradient = (message)=>{
|
|
154
|
+
if (colorLevel < 3) return 2 === colorLevel ? color.cyan(message) : message;
|
|
155
|
+
let chars = [
|
|
156
|
+
...message
|
|
157
|
+
];
|
|
158
|
+
let steps = chars.filter(isWord).length;
|
|
159
|
+
let r = startColor[0];
|
|
160
|
+
let g = startColor[1];
|
|
161
|
+
let b = startColor[2];
|
|
162
|
+
let rStep = (endColor[0] - r) / steps;
|
|
163
|
+
let gStep = (endColor[1] - g) / steps;
|
|
164
|
+
let bStep = (endColor[2] - b) / steps;
|
|
165
|
+
let output = '';
|
|
166
|
+
for (let char of chars){
|
|
167
|
+
if (isWord(char)) {
|
|
168
|
+
r += rStep;
|
|
169
|
+
g += gStep;
|
|
170
|
+
b += bStep;
|
|
171
|
+
}
|
|
172
|
+
output += `\x1b[38;2;${Math.round(r)};${Math.round(g)};${Math.round(b)}m${char}\x1b[39m`;
|
|
173
|
+
}
|
|
174
|
+
return color.bold(output);
|
|
175
|
+
};
|
|
176
|
+
let LOG_LEVEL = {
|
|
177
|
+
silent: -1,
|
|
178
|
+
error: 0,
|
|
179
|
+
warn: 1,
|
|
180
|
+
info: 2,
|
|
181
|
+
log: 2,
|
|
182
|
+
verbose: 3
|
|
183
|
+
};
|
|
184
|
+
let LOG_TYPES = {
|
|
185
|
+
error: {
|
|
186
|
+
label: 'error',
|
|
187
|
+
level: 'error',
|
|
188
|
+
color: color.red
|
|
189
|
+
},
|
|
190
|
+
warn: {
|
|
191
|
+
label: 'warn',
|
|
192
|
+
level: 'warn',
|
|
193
|
+
color: color.yellow
|
|
194
|
+
},
|
|
195
|
+
info: {
|
|
196
|
+
label: 'info',
|
|
197
|
+
level: 'info',
|
|
198
|
+
color: color.cyan
|
|
199
|
+
},
|
|
200
|
+
start: {
|
|
201
|
+
label: 'start',
|
|
202
|
+
level: 'info',
|
|
203
|
+
color: color.cyan
|
|
204
|
+
},
|
|
205
|
+
ready: {
|
|
206
|
+
label: 'ready',
|
|
207
|
+
level: 'info',
|
|
208
|
+
color: color.green
|
|
209
|
+
},
|
|
210
|
+
success: {
|
|
211
|
+
label: 'success',
|
|
212
|
+
level: 'info',
|
|
213
|
+
color: color.green
|
|
214
|
+
},
|
|
215
|
+
log: {
|
|
216
|
+
level: 'info'
|
|
217
|
+
},
|
|
218
|
+
debug: {
|
|
219
|
+
label: 'debug',
|
|
220
|
+
level: 'verbose',
|
|
221
|
+
color: color.magenta
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const normalizeErrorMessage = (err)=>{
|
|
225
|
+
if (err.stack) {
|
|
226
|
+
let [name, ...rest] = err.stack.split('\n');
|
|
227
|
+
if (name.startsWith('Error: ')) name = name.slice(7);
|
|
228
|
+
return `${name}\n${color.gray(rest.join('\n'))}`;
|
|
229
|
+
}
|
|
230
|
+
return err.message;
|
|
231
|
+
};
|
|
232
|
+
let createLogger = (options = {})=>{
|
|
233
|
+
let maxLevel = options.level || 'info';
|
|
234
|
+
let log = (type, message, ...args)=>{
|
|
235
|
+
let logType = LOG_TYPES[type];
|
|
236
|
+
const { level } = logType;
|
|
237
|
+
if (LOG_LEVEL[level] > LOG_LEVEL[maxLevel]) return;
|
|
238
|
+
if (null == message) return console.log();
|
|
239
|
+
let label = '';
|
|
240
|
+
let text = '';
|
|
241
|
+
if ('label' in logType) {
|
|
242
|
+
label = (logType.label || '').padEnd(7);
|
|
243
|
+
label = color.bold(logType.color ? logType.color(label) : label);
|
|
244
|
+
}
|
|
245
|
+
if (message instanceof Error) {
|
|
246
|
+
text += normalizeErrorMessage(message);
|
|
247
|
+
const { cause } = message;
|
|
248
|
+
if (cause) {
|
|
249
|
+
text += color.yellow('\n [cause]: ');
|
|
250
|
+
text += cause instanceof Error ? normalizeErrorMessage(cause) : String(cause);
|
|
251
|
+
}
|
|
252
|
+
} else if ('error' === level && 'string' == typeof message) {
|
|
253
|
+
let lines = message.split('\n');
|
|
254
|
+
text = lines.map((line)=>isErrorStackMessage(line) ? color.gray(line) : line).join('\n');
|
|
255
|
+
} else text = `${message}`;
|
|
256
|
+
const method = 'error' === level || 'warn' === level ? level : 'log';
|
|
257
|
+
console[method](label.length ? `${label} ${text}` : text, ...args);
|
|
258
|
+
};
|
|
259
|
+
let logger = {
|
|
260
|
+
greet: (message)=>log('log', gradient(message))
|
|
261
|
+
};
|
|
262
|
+
Object.keys(LOG_TYPES).forEach((key)=>{
|
|
263
|
+
logger[key] = (...args)=>log(key, ...args);
|
|
264
|
+
});
|
|
265
|
+
Object.defineProperty(logger, 'level', {
|
|
266
|
+
get: ()=>maxLevel,
|
|
267
|
+
set (val) {
|
|
268
|
+
maxLevel = val;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
logger.override = (customLogger)=>{
|
|
272
|
+
Object.assign(logger, customLogger);
|
|
273
|
+
};
|
|
274
|
+
return logger;
|
|
275
|
+
};
|
|
276
|
+
let src_logger = createLogger();
|
|
13
277
|
const isDebugKey = (keys)=>{
|
|
14
278
|
if (!process.env.DEBUG) return false;
|
|
15
279
|
const values = process.env.DEBUG.toLocaleLowerCase().split(',');
|
|
@@ -22,7 +286,7 @@ const isDebug = ()=>isDebugKey([
|
|
|
22
286
|
'rstack',
|
|
23
287
|
'*'
|
|
24
288
|
]);
|
|
25
|
-
if (isDebug())
|
|
289
|
+
if (isDebug()) src_logger.level = 'verbose';
|
|
26
290
|
function getTime() {
|
|
27
291
|
const now = new Date();
|
|
28
292
|
const hours = String(now.getHours()).padStart(2, '0');
|
|
@@ -30,11 +294,11 @@ function getTime() {
|
|
|
30
294
|
const seconds = String(now.getSeconds()).padStart(2, '0');
|
|
31
295
|
return `${hours}:${minutes}:${seconds}`;
|
|
32
296
|
}
|
|
33
|
-
|
|
297
|
+
src_logger.override({
|
|
34
298
|
debug: (message, ...args)=>{
|
|
35
|
-
if ('verbose' !==
|
|
36
|
-
const time =
|
|
37
|
-
console.log(` ${
|
|
299
|
+
if ('verbose' !== src_logger.level) return;
|
|
300
|
+
const time = color.gray(getTime());
|
|
301
|
+
console.log(` ${color.green('rslib')} ${time} ${message}`, ...args);
|
|
38
302
|
}
|
|
39
303
|
});
|
|
40
304
|
function toArr(any) {
|
|
@@ -664,11 +928,11 @@ function ensureAbsolutePath(base, filepath) {
|
|
|
664
928
|
}
|
|
665
929
|
const readPackageJson = (rootPath)=>{
|
|
666
930
|
const pkgJsonPath = node_path.join(rootPath, './package.json');
|
|
667
|
-
if (!node_fs.existsSync(pkgJsonPath)) return void
|
|
931
|
+
if (!node_fs.existsSync(pkgJsonPath)) return void src_logger.warn(`The \`package.json\` file does not exist in the ${rootPath} directory`);
|
|
668
932
|
try {
|
|
669
933
|
return JSON.parse(node_fs.readFileSync(pkgJsonPath, 'utf8'));
|
|
670
934
|
} catch (_err) {
|
|
671
|
-
|
|
935
|
+
src_logger.warn(`Failed to parse ${pkgJsonPath}, it might not be valid JSON`);
|
|
672
936
|
return;
|
|
673
937
|
}
|
|
674
938
|
};
|
|
@@ -700,7 +964,7 @@ function checkMFPlugin(config, sharedPlugins) {
|
|
|
700
964
|
...config.plugins || []
|
|
701
965
|
]);
|
|
702
966
|
if (!added) {
|
|
703
|
-
|
|
967
|
+
src_logger.warn(`${color.green('format: "mf"')} should be used with ${color.blue('@module-federation/rsbuild-plugin')}", consider installing and adding it to plugins. Check the documentation (https://module-federation.io/guide/basic/rsbuild.html#rslib-module) to get started with "mf" output.`);
|
|
704
968
|
process.exit(1);
|
|
705
969
|
}
|
|
706
970
|
return added;
|
|
@@ -714,7 +978,9 @@ function debounce(func, wait) {
|
|
|
714
978
|
}, wait);
|
|
715
979
|
};
|
|
716
980
|
}
|
|
717
|
-
|
|
981
|
+
function isTTY(type = 'stdout') {
|
|
982
|
+
return ('stdin' === type ? process.stdin.isTTY : process.stdout.isTTY) && !process.env.CI;
|
|
983
|
+
}
|
|
718
984
|
const isIntermediateOutputFormat = (format)=>'cjs' === format || 'esm' === format;
|
|
719
985
|
const windowsSlashRegex = /\\/g;
|
|
720
986
|
function normalizeSlash(p) {
|
|
@@ -743,7 +1009,7 @@ function getWatchFilesForRestart(rslib) {
|
|
|
743
1009
|
}
|
|
744
1010
|
async function watchFilesForRestart(files, restart) {
|
|
745
1011
|
if (!files || !files.length) return;
|
|
746
|
-
const chokidar = await import("
|
|
1012
|
+
const { default: chokidar } = await import("./chokidar.js");
|
|
747
1013
|
const watcher = chokidar.watch(files, {
|
|
748
1014
|
ignoreInitial: true,
|
|
749
1015
|
ignorePermissionErrors: true
|
|
@@ -770,8 +1036,8 @@ const beforeRestart = async ({ filePath, clear = true } = {})=>{
|
|
|
770
1036
|
if (clear) clearConsole();
|
|
771
1037
|
if (filePath) {
|
|
772
1038
|
const filename = node_path.basename(filePath);
|
|
773
|
-
|
|
774
|
-
} else
|
|
1039
|
+
src_logger.info(`restarting as ${color.yellow(filename)} is changed\n`);
|
|
1040
|
+
} else src_logger.info('restarting...\n');
|
|
775
1041
|
for (const cleaner of cleaners)await cleaner();
|
|
776
1042
|
cleaners = [];
|
|
777
1043
|
};
|
|
@@ -927,7 +1193,7 @@ class LibCssExtractPlugin {
|
|
|
927
1193
|
apply(compiler) {
|
|
928
1194
|
compiler.hooks.make.tap(LibCssExtractPlugin_pluginName, (compilation)=>{
|
|
929
1195
|
compilation.hooks.processAssets.tap(LibCssExtractPlugin_pluginName, (assets)=>{
|
|
930
|
-
const chunkAsset = Object.keys(assets).filter((name)
|
|
1196
|
+
const chunkAsset = Object.keys(assets).filter((name)=>name.includes('.css'));
|
|
931
1197
|
for (const name of chunkAsset)compilation.updateAsset(name, (old)=>{
|
|
932
1198
|
const oldSource = old.source().toString();
|
|
933
1199
|
const replaceSource = new rspack.sources.ReplaceSource(old);
|
|
@@ -952,7 +1218,7 @@ class LibCssExtractPlugin {
|
|
|
952
1218
|
const cssConfig_require = createRequire(import.meta.url);
|
|
953
1219
|
const RSLIB_CSS_ENTRY_FLAG = '__rslib_css__';
|
|
954
1220
|
async function cssExternalHandler(request, callback, jsExtension, auto, styleRedirectPath, styleRedirectExtension, redirectedPath, issuer) {
|
|
955
|
-
if (/
|
|
1221
|
+
if (request.includes('compiled/css-loader/')) return void callback();
|
|
956
1222
|
let resolvedRequest = request;
|
|
957
1223
|
if (styleRedirectPath) {
|
|
958
1224
|
if (void 0 === redirectedPath) return false;
|
|
@@ -971,16 +1237,22 @@ async function cssExternalHandler(request, callback, jsExtension, auto, styleRed
|
|
|
971
1237
|
callback(void 0, resolvedRequest);
|
|
972
1238
|
}
|
|
973
1239
|
const cssConfig_PLUGIN_NAME = 'rsbuild:lib-css';
|
|
1240
|
+
const isPreprocessorRule = (preprocessRuleId, toMatchRuleId)=>{
|
|
1241
|
+
if (preprocessRuleId === toMatchRuleId) return true;
|
|
1242
|
+
if (new RegExp(`^${preprocessRuleId}-\\d+$`).test(toMatchRuleId)) return true;
|
|
1243
|
+
return false;
|
|
1244
|
+
};
|
|
974
1245
|
const pluginLibCss = (rootDir, auto, banner, footer)=>({
|
|
975
1246
|
name: cssConfig_PLUGIN_NAME,
|
|
976
1247
|
setup (api) {
|
|
977
1248
|
api.processAssets({
|
|
978
1249
|
stage: 'additional'
|
|
979
1250
|
}, ({ assets, compilation })=>{
|
|
980
|
-
for (const key of Object.keys(assets))if (
|
|
1251
|
+
for (const key of Object.keys(assets))if (RegExp(RSLIB_CSS_ENTRY_FLAG).exec(key)) compilation.deleteAsset(key);
|
|
981
1252
|
});
|
|
982
1253
|
api.modifyBundlerChain((config, { CHAIN_ID })=>{
|
|
983
1254
|
let isUsingCssExtract = false;
|
|
1255
|
+
const ruleIds = Object.keys(config.module.rules.entries());
|
|
984
1256
|
for (const [ruleId, oneOfId] of [
|
|
985
1257
|
[
|
|
986
1258
|
CHAIN_ID.RULE.CSS,
|
|
@@ -999,17 +1271,22 @@ const pluginLibCss = (rootDir, auto, banner, footer)=>({
|
|
|
999
1271
|
'stylus'
|
|
1000
1272
|
]
|
|
1001
1273
|
]){
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1274
|
+
const matchedRuleIds = ruleId === CHAIN_ID.RULE.CSS ? [
|
|
1275
|
+
ruleId
|
|
1276
|
+
] : ruleIds.filter((currentRuleId)=>isPreprocessorRule(ruleId, currentRuleId));
|
|
1277
|
+
for (const matchedRuleId of matchedRuleIds){
|
|
1278
|
+
if (!config.module.rules.has(matchedRuleId)) continue;
|
|
1279
|
+
const mainRule = config.module.rule(matchedRuleId).oneOfs.get(oneOfId);
|
|
1280
|
+
if (mainRule) {
|
|
1281
|
+
if (mainRule.uses.has(CHAIN_ID.USE.MINI_CSS_EXTRACT)) {
|
|
1282
|
+
isUsingCssExtract = true;
|
|
1283
|
+
mainRule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader(cssConfig_require.resolve('./libCssExtractLoader.js')).options({
|
|
1284
|
+
rootDir,
|
|
1285
|
+
auto,
|
|
1286
|
+
banner,
|
|
1287
|
+
footer
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1013
1290
|
}
|
|
1014
1291
|
}
|
|
1015
1292
|
}
|
|
@@ -1021,7 +1298,7 @@ const pluginLibCss = (rootDir, auto, banner, footer)=>({
|
|
|
1021
1298
|
});
|
|
1022
1299
|
}
|
|
1023
1300
|
});
|
|
1024
|
-
|
|
1301
|
+
function composeCssConfig(rootDir, auto, bundle = true, banner, footer) {
|
|
1025
1302
|
if (bundle || null === rootDir) return {};
|
|
1026
1303
|
return {
|
|
1027
1304
|
plugins: [
|
|
@@ -1033,7 +1310,7 @@ const composeCssConfig = (rootDir, auto, bundle = true, banner, footer)=>{
|
|
|
1033
1310
|
}
|
|
1034
1311
|
}
|
|
1035
1312
|
};
|
|
1036
|
-
}
|
|
1313
|
+
}
|
|
1037
1314
|
const EntryChunkPlugin_PLUGIN_NAME = 'rsbuild:lib-entry-chunk';
|
|
1038
1315
|
const IMPORT_META_URL_SHIM = `const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
1039
1316
|
return typeof document === 'undefined'
|
|
@@ -1139,7 +1416,7 @@ const getDefaultExtension = (options)=>{
|
|
|
1139
1416
|
dtsExtension
|
|
1140
1417
|
};
|
|
1141
1418
|
if (!pkgJson) {
|
|
1142
|
-
|
|
1419
|
+
src_logger.warn('The `autoExtension` configuration will not be applied due to read package.json failed');
|
|
1143
1420
|
return {
|
|
1144
1421
|
jsExtension,
|
|
1145
1422
|
dtsExtension
|
|
@@ -1876,7 +2153,7 @@ const composeExternalsWarnConfig = (format, ...externalsArray)=>{
|
|
|
1876
2153
|
};
|
|
1877
2154
|
if (contextInfo.issuer && 'commonjs' === dependencyType) {
|
|
1878
2155
|
matchUserExternals(externals, request, _callback);
|
|
1879
|
-
if (shouldWarn)
|
|
2156
|
+
if (shouldWarn) src_logger.warn(composeModuleImportWarn(request, contextInfo.issuer));
|
|
1880
2157
|
}
|
|
1881
2158
|
callback();
|
|
1882
2159
|
}
|
|
@@ -1891,7 +2168,7 @@ const composeAutoExternalConfig = (options)=>{
|
|
|
1891
2168
|
const autoExternal = getAutoExternalDefaultValue(format, options.autoExternal);
|
|
1892
2169
|
if (false === autoExternal) return {};
|
|
1893
2170
|
if (!pkgJson) {
|
|
1894
|
-
|
|
2171
|
+
src_logger.warn('The `autoExternal` configuration will not be applied due to read package.json failed');
|
|
1895
2172
|
return {};
|
|
1896
2173
|
}
|
|
1897
2174
|
const userExternalKeys = userExternals && isObject(userExternals) ? Object.keys(userExternals) : [];
|
|
@@ -2017,9 +2294,9 @@ function composePrintFileSizeConfig(bundle, target) {
|
|
|
2017
2294
|
performance: {
|
|
2018
2295
|
printFileSize: {
|
|
2019
2296
|
total: ({ environmentName, distPath, assets, totalSize, totalGzipSize })=>{
|
|
2020
|
-
let log = `${
|
|
2021
|
-
if ('web' === target) log += ` ${
|
|
2022
|
-
log += ` ${
|
|
2297
|
+
let log = `${color.yellow(assets.length)} files generated in ${color.cyan(distPath)}, ${color.magenta('total:')} ${(totalSize / 1000).toFixed(1)} kB`;
|
|
2298
|
+
if ('web' === target) log += ` ${color.green(`(${(totalGzipSize / 1000).toFixed(1)} kB gzipped)`)}`;
|
|
2299
|
+
log += ` ${color.dim(`(${environmentName})`)}`;
|
|
2023
2300
|
return log;
|
|
2024
2301
|
},
|
|
2025
2302
|
detail: false
|
|
@@ -2077,7 +2354,7 @@ async function createConstantRsbuildConfig() {
|
|
|
2077
2354
|
}
|
|
2078
2355
|
});
|
|
2079
2356
|
}
|
|
2080
|
-
const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledShims })=>{
|
|
2357
|
+
const composeFormatConfig = ({ format, target, bundle = true, umdName, pkgJson, enabledShims, multiCompilerIndex, sourceEntry })=>{
|
|
2081
2358
|
const jsParserOptions = {
|
|
2082
2359
|
cjs: {
|
|
2083
2360
|
requireResolve: false,
|
|
@@ -2098,7 +2375,8 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledS
|
|
|
2098
2375
|
const plugins = [
|
|
2099
2376
|
new rspack.experiments.RslibPlugin({
|
|
2100
2377
|
interceptApiPlugin: true,
|
|
2101
|
-
forceNodeShims: enabledShims.esm.__dirname || enabledShims.esm.__filename
|
|
2378
|
+
forceNodeShims: enabledShims.esm.__dirname || enabledShims.esm.__filename,
|
|
2379
|
+
externalEsmNodeBuiltin: 'esm' === format && 'node' === target
|
|
2102
2380
|
})
|
|
2103
2381
|
].filter(Boolean);
|
|
2104
2382
|
switch(format){
|
|
@@ -2121,9 +2399,11 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledS
|
|
|
2121
2399
|
optimization: {
|
|
2122
2400
|
concatenateModules: false,
|
|
2123
2401
|
sideEffects: true,
|
|
2124
|
-
runtimeChunk: {
|
|
2125
|
-
|
|
2126
|
-
|
|
2402
|
+
runtimeChunk: getRuntimeChunkConfig({
|
|
2403
|
+
bundle,
|
|
2404
|
+
multiCompilerIndex,
|
|
2405
|
+
sourceEntry
|
|
2406
|
+
}),
|
|
2127
2407
|
avoidEntryIife: true,
|
|
2128
2408
|
splitChunks: {
|
|
2129
2409
|
chunks: 'async'
|
|
@@ -2306,13 +2586,24 @@ const BundlePlugin = ()=>({
|
|
|
2306
2586
|
order: 'post',
|
|
2307
2587
|
handler: ({ bundlerConfig })=>{
|
|
2308
2588
|
if (bundlerConfig?.module?.parser?.javascript?.jsx === true) {
|
|
2309
|
-
|
|
2589
|
+
src_logger.error('Bundle mode does not support preserving JSX syntax. Set "bundle" to "false" or change the JSX runtime to `automatic` or `classic`. Check out ' + color.green('https://rslib.rs/guide/solution/react#jsx-transform') + ' for more details.');
|
|
2310
2590
|
process.exit(1);
|
|
2311
2591
|
}
|
|
2312
2592
|
}
|
|
2313
2593
|
});
|
|
2314
2594
|
}
|
|
2315
2595
|
});
|
|
2596
|
+
const RSLIB_RUNTIME_CHUNK_NAME = 'rslib-runtime';
|
|
2597
|
+
const getMultiCompilerRuntimeChunkName = (multiCompilerIndex)=>'number' == typeof multiCompilerIndex ? `${multiCompilerIndex}~${RSLIB_RUNTIME_CHUNK_NAME}` : RSLIB_RUNTIME_CHUNK_NAME;
|
|
2598
|
+
const getRuntimeChunkConfig = ({ bundle, multiCompilerIndex, sourceEntry })=>{
|
|
2599
|
+
if (!bundle) return {
|
|
2600
|
+
name: RSLIB_RUNTIME_CHUNK_NAME
|
|
2601
|
+
};
|
|
2602
|
+
if (!sourceEntry || Object.keys(sourceEntry).length <= 1) return;
|
|
2603
|
+
return {
|
|
2604
|
+
name: getMultiCompilerRuntimeChunkName(multiCompilerIndex)
|
|
2605
|
+
};
|
|
2606
|
+
};
|
|
2316
2607
|
const composeBundleConfig = (bundle)=>{
|
|
2317
2608
|
if (bundle) return {
|
|
2318
2609
|
rsbuildConfig: {
|
|
@@ -2395,7 +2686,7 @@ const composeShimsConfig = (format, shims)=>{
|
|
|
2395
2686
|
enabledShims
|
|
2396
2687
|
};
|
|
2397
2688
|
};
|
|
2398
|
-
const composeModuleImportWarn = (request, issuer)=>`The externalized commonjs request ${
|
|
2689
|
+
const composeModuleImportWarn = (request, issuer)=>`The externalized commonjs request ${color.green(`"${request}"`)} from ${color.green(issuer)} will use ${color.blue('"module"')} external type in ESM format. If you want to specify other external type, consider setting the request and type with ${color.blue('"output.externals"')}.`;
|
|
2399
2690
|
const composeExternalsConfig = (format, externals)=>{
|
|
2400
2691
|
const externalsTypeMap = {
|
|
2401
2692
|
esm: 'module-import',
|
|
@@ -2535,20 +2826,20 @@ const composeEntryConfig = async (rawEntry, bundle, root, cssModulesAuto, userOu
|
|
|
2535
2826
|
index: 'src/**'
|
|
2536
2827
|
};
|
|
2537
2828
|
}
|
|
2538
|
-
if ('object' != typeof entries) throw new Error(`The ${
|
|
2829
|
+
if ('object' != typeof entries) throw new Error(`The ${color.cyan('source.entry')} configuration should be an object, but received ${typeof entries}: ${color.cyan(entries)}. Checkout ${color.green('https://rslib.rs/config/rsbuild/source#sourceentry')} for more details.`);
|
|
2539
2830
|
if (false !== bundle) {
|
|
2540
2831
|
const entryErrorReasons = [];
|
|
2541
2832
|
traverseEntryQuery(entries, (entry)=>{
|
|
2542
2833
|
const entryAbsPath = node_path.isAbsolute(entry) ? entry : node_path.resolve(root, entry);
|
|
2543
2834
|
const isDirLike = '' === node_path.extname(entryAbsPath);
|
|
2544
|
-
const dirError = `Glob pattern ${
|
|
2835
|
+
const dirError = `Glob pattern ${color.cyan(`"${entry}"`)} is not supported when "bundle" is "true", considering "bundle" to "false" to use bundleless mode, or specify a file entry to bundle. See ${color.green('https://rslib.rs/guide/basic/output-structure')} for more details.`;
|
|
2545
2836
|
if (node_fs.existsSync(entryAbsPath)) {
|
|
2546
2837
|
const stats = node_fs.statSync(entryAbsPath);
|
|
2547
2838
|
if (!stats.isFile()) entryErrorReasons.push(dirError);
|
|
2548
2839
|
} else {
|
|
2549
2840
|
const isGlobLike = entry.startsWith('!') || /[*?[{\]}]/.test(entry);
|
|
2550
2841
|
if (isDirLike || isGlobLike) entryErrorReasons.push(dirError);
|
|
2551
|
-
else entryErrorReasons.push(`Can't resolve the entry ${
|
|
2842
|
+
else entryErrorReasons.push(`Can't resolve the entry ${color.cyan(`"${entry}"`)} at the location ${color.cyan(entryAbsPath)}. Please ensure that the file exists.`);
|
|
2552
2843
|
}
|
|
2553
2844
|
return entry;
|
|
2554
2845
|
});
|
|
@@ -2575,6 +2866,7 @@ const composeEntryConfig = async (rawEntry, bundle, root, cssModulesAuto, userOu
|
|
|
2575
2866
|
entry
|
|
2576
2867
|
] : null;
|
|
2577
2868
|
if (!entryFiles) throw new Error('Entry can only be a string or an array of strings for now');
|
|
2869
|
+
const { glob } = await import("./tinyglobby.js");
|
|
2578
2870
|
const globEntryFiles = await glob(entryFiles, {
|
|
2579
2871
|
cwd: root,
|
|
2580
2872
|
absolute: true,
|
|
@@ -2586,7 +2878,7 @@ const composeEntryConfig = async (rawEntry, bundle, root, cssModulesAuto, userOu
|
|
|
2586
2878
|
});
|
|
2587
2879
|
const resolvedEntryFiles = globEntryFiles.filter((i)=>!DTS_EXTENSIONS_PATTERN.test(i));
|
|
2588
2880
|
if (0 === resolvedEntryFiles.length) {
|
|
2589
|
-
const error = new Error(`No entry files matching ${entryFiles.map((file)=>
|
|
2881
|
+
const error = new Error(`No entry files matching ${entryFiles.map((file)=>color.cyan(file)).join(', ')}. Please ensure the entry pattern in ${color.cyan('source.entry')} is correct and points to valid source files.`);
|
|
2590
2882
|
error.stack = '';
|
|
2591
2883
|
throw error;
|
|
2592
2884
|
}
|
|
@@ -2599,7 +2891,7 @@ const composeEntryConfig = async (rawEntry, bundle, root, cssModulesAuto, userOu
|
|
|
2599
2891
|
}
|
|
2600
2892
|
for (const file of resolvedEntryFiles){
|
|
2601
2893
|
const entryName = getEntryName(file);
|
|
2602
|
-
if (resolvedEntries[entryName]) tryResolveOutBase &&
|
|
2894
|
+
if (resolvedEntries[entryName]) tryResolveOutBase && src_logger.warn(`Duplicate entry ${color.cyan(entryName)} from ${color.cyan(node_path.relative(root, file))} and ${color.cyan(node_path.relative(root, resolvedEntries[entryName]))}, which may lead to the incorrect output, please rename the file.`);
|
|
2603
2895
|
resolvedEntries[entryName] = file;
|
|
2604
2896
|
}
|
|
2605
2897
|
}
|
|
@@ -2675,7 +2967,7 @@ const composeBundlelessExternalConfig = (jsExtension, redirect, cssModulesAuto,
|
|
|
2675
2967
|
isResolved: true
|
|
2676
2968
|
};
|
|
2677
2969
|
} catch (_e) {
|
|
2678
|
-
|
|
2970
|
+
src_logger.debug(`Failed to resolve module ${color.green(`"${request}"`)} from ${color.green(issuer)}. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.`);
|
|
2679
2971
|
return {
|
|
2680
2972
|
path: request,
|
|
2681
2973
|
isResolved: false
|
|
@@ -2772,7 +3064,7 @@ const composeTargetConfig = (userTarget, format)=>{
|
|
|
2772
3064
|
}
|
|
2773
3065
|
},
|
|
2774
3066
|
target: 'node',
|
|
2775
|
-
externalsConfig: {
|
|
3067
|
+
externalsConfig: 'esm' === format ? {} : {
|
|
2776
3068
|
output: {
|
|
2777
3069
|
externals: nodeBuiltInModules
|
|
2778
3070
|
}
|
|
@@ -2798,7 +3090,7 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
|
|
|
2798
3090
|
...Object.keys(pkgJson?.devDependencies ?? [])
|
|
2799
3091
|
];
|
|
2800
3092
|
if (!deps.includes(SWC_HELPERS)) {
|
|
2801
|
-
|
|
3093
|
+
src_logger.error(`${color.green('externalHelpers')} is enabled, but the ${color.blue(SWC_HELPERS)} dependency declaration was not found in package.json.`);
|
|
2802
3094
|
process.exit(1);
|
|
2803
3095
|
}
|
|
2804
3096
|
defaultConfig = Object.assign(defaultConfig, {
|
|
@@ -2818,19 +3110,22 @@ async function composeLibRsbuildConfig(config, multiCompilerIndex, root = proces
|
|
|
2818
3110
|
const { format = 'esm', shims, bundle = true, banner = {}, footer = {}, autoExtension = true, autoExternal, externalHelpers = false, redirect = {}, umdName } = config;
|
|
2819
3111
|
const { rsbuildConfig: bundleConfig } = composeBundleConfig(bundle);
|
|
2820
3112
|
const { rsbuildConfig: shimsConfig, enabledShims } = composeShimsConfig(format, shims);
|
|
3113
|
+
const { config: targetConfig, externalsConfig: targetExternalsConfig, target } = composeTargetConfig(config.output?.target, format);
|
|
2821
3114
|
const formatConfig = composeFormatConfig({
|
|
2822
3115
|
format,
|
|
3116
|
+
target,
|
|
2823
3117
|
pkgJson: pkgJson,
|
|
2824
3118
|
bundle,
|
|
2825
3119
|
umdName,
|
|
2826
|
-
enabledShims
|
|
3120
|
+
enabledShims,
|
|
3121
|
+
multiCompilerIndex,
|
|
3122
|
+
sourceEntry: config.source?.entry
|
|
2827
3123
|
});
|
|
2828
3124
|
const externalHelpersConfig = composeExternalHelpersConfig(externalHelpers, pkgJson);
|
|
2829
3125
|
const userExternalsConfig = composeExternalsConfig(format, config.output?.externals);
|
|
2830
3126
|
const { config: outputFilenameConfig, jsExtension, dtsExtension } = composeOutputFilenameConfig(config, format, autoExtension, multiCompilerIndex, pkgJson);
|
|
2831
3127
|
const { entryConfig, outBase } = await composeEntryConfig(config.source?.entry, config.bundle, root, cssModulesAuto, config.outBase);
|
|
2832
3128
|
const { config: bundlelessExternalConfig } = composeBundlelessExternalConfig(jsExtension, redirect, cssModulesAuto, bundle, outBase);
|
|
2833
|
-
const { config: targetConfig, externalsConfig: targetExternalsConfig, target } = composeTargetConfig(config.output?.target, format);
|
|
2834
3129
|
const syntaxConfig = composeSyntaxConfig(target, config?.syntax);
|
|
2835
3130
|
const autoExternalConfig = composeAutoExternalConfig({
|
|
2836
3131
|
bundle,
|
|
@@ -2856,8 +3151,8 @@ async function composeLibRsbuildConfig(config, multiCompilerIndex, root = proces
|
|
|
2856
3151
|
async function composeCreateRsbuildConfig(rslibConfig) {
|
|
2857
3152
|
const constantRsbuildConfig = await createConstantRsbuildConfig();
|
|
2858
3153
|
const { lib: libConfigsArray, mode: _mode, root, plugins: sharedPlugins, dev: _dev, server: _server, logLevel, ...sharedRsbuildConfig } = rslibConfig;
|
|
2859
|
-
if (logLevel && !isDebug())
|
|
2860
|
-
if (!Array.isArray(libConfigsArray) || 0 === libConfigsArray.length) throw new Error(`Expect "lib" field to be a non-empty array, but got: ${
|
|
3154
|
+
if (logLevel && !isDebug()) src_logger.level = logLevel;
|
|
3155
|
+
if (!Array.isArray(libConfigsArray) || 0 === libConfigsArray.length) throw new Error(`Expect "lib" field to be a non-empty array, but got: ${color.cyan(JSON.stringify(libConfigsArray))}.`);
|
|
2861
3156
|
const libConfigPromises = libConfigsArray.map(async (libConfig, index)=>{
|
|
2862
3157
|
const userConfig = mergeRsbuildConfig(sharedRsbuildConfig, libConfig);
|
|
2863
3158
|
const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, libConfigsArray.length > 1 ? index : null, root, sharedPlugins);
|
|
@@ -2904,7 +3199,7 @@ async function composeRsbuildEnvironments(rslibConfig) {
|
|
|
2904
3199
|
const nextDefaultId = (format, index)=>`${format}${1 === formatCount[format] && 0 === index ? '' : index}`;
|
|
2905
3200
|
let index = 0;
|
|
2906
3201
|
let candidateId = nextDefaultId(format, index);
|
|
2907
|
-
while(
|
|
3202
|
+
while(usedIds.includes(candidateId))candidateId = nextDefaultId(format, ++index);
|
|
2908
3203
|
usedIds.push(candidateId);
|
|
2909
3204
|
return candidateId;
|
|
2910
3205
|
};
|
|
@@ -3013,7 +3308,7 @@ async function createRslib(options = {}) {
|
|
|
3013
3308
|
name: 'rslib:on-after-build',
|
|
3014
3309
|
setup (api) {
|
|
3015
3310
|
api.onAfterBuild(({ isFirstCompile, stats })=>{
|
|
3016
|
-
if (isFirstCompile) stats?.hasErrors() ?
|
|
3311
|
+
if (isFirstCompile) stats?.hasErrors() ? src_logger.error('build completed with errors, watching for changes...') : src_logger.success('build completed, watching for changes...');
|
|
3017
3312
|
});
|
|
3018
3313
|
}
|
|
3019
3314
|
});
|
|
@@ -3079,7 +3374,7 @@ const resolveConfigPath = (root, customConfig)=>{
|
|
|
3079
3374
|
if (customConfig) {
|
|
3080
3375
|
const customConfigPath = isAbsolute(customConfig) ? customConfig : join(root, customConfig);
|
|
3081
3376
|
if (node_fs.existsSync(customConfigPath)) return customConfigPath;
|
|
3082
|
-
const error = new Error(`${
|
|
3377
|
+
const error = new Error(`${color.dim('[rslib:loadConfig]')} Cannot find config file: ${color.dim(customConfigPath)}`);
|
|
3083
3378
|
error.stack = '';
|
|
3084
3379
|
throw error;
|
|
3085
3380
|
}
|
|
@@ -3100,7 +3395,7 @@ const resolveConfigPath = (root, customConfig)=>{
|
|
|
3100
3395
|
async function loadConfig_loadConfig({ cwd = process.cwd(), path, envMode, meta, loader }) {
|
|
3101
3396
|
const configFilePath = resolveConfigPath(cwd, path);
|
|
3102
3397
|
if (!configFilePath) {
|
|
3103
|
-
|
|
3398
|
+
src_logger.debug('no config file found.');
|
|
3104
3399
|
return {
|
|
3105
3400
|
content: {},
|
|
3106
3401
|
filePath: null
|
|
@@ -3203,7 +3498,7 @@ const init_loadConfig = async (options, root)=>{
|
|
|
3203
3498
|
config.lib = [
|
|
3204
3499
|
{}
|
|
3205
3500
|
];
|
|
3206
|
-
|
|
3501
|
+
src_logger.debug('Falling back to CLI options for the default library.');
|
|
3207
3502
|
}
|
|
3208
3503
|
applyCliOptions(config, options, root);
|
|
3209
3504
|
return config;
|
|
@@ -3234,9 +3529,9 @@ const applyCommonOptions = (cli)=>{
|
|
|
3234
3529
|
};
|
|
3235
3530
|
function setupCommands() {
|
|
3236
3531
|
const cli = cac('rslib');
|
|
3237
|
-
cli.version("0.20.
|
|
3532
|
+
cli.version("0.20.1");
|
|
3238
3533
|
applyCommonOptions(cli);
|
|
3239
|
-
const buildDescription = `build the library for production ${
|
|
3534
|
+
const buildDescription = `build the library for production ${color.dim('(default if no command is given)')}`;
|
|
3240
3535
|
const buildCommand = cli.command('', buildDescription).alias('build');
|
|
3241
3536
|
const inspectCommand = cli.command('inspect', 'inspect the Rsbuild / Rspack configs of Rslib projects');
|
|
3242
3537
|
const mfDevCommand = cli.command('mf-dev', 'start Rsbuild dev server of Module Federation format');
|
|
@@ -3264,9 +3559,9 @@ function setupCommands() {
|
|
|
3264
3559
|
await cliBuild();
|
|
3265
3560
|
} catch (err) {
|
|
3266
3561
|
const isRspackError = err instanceof Error && err.message === RSPACK_BUILD_ERROR;
|
|
3267
|
-
if (!isRspackError)
|
|
3268
|
-
if (err instanceof AggregateError) for (const error of err.errors)
|
|
3269
|
-
else
|
|
3562
|
+
if (!isRspackError) src_logger.error('Failed to build.');
|
|
3563
|
+
if (err instanceof AggregateError) for (const error of err.errors)src_logger.error(error);
|
|
3564
|
+
else src_logger.error(err);
|
|
3270
3565
|
process.exit(1);
|
|
3271
3566
|
}
|
|
3272
3567
|
});
|
|
@@ -3283,8 +3578,8 @@ function setupCommands() {
|
|
|
3283
3578
|
writeToDisk: true
|
|
3284
3579
|
});
|
|
3285
3580
|
} catch (err) {
|
|
3286
|
-
|
|
3287
|
-
|
|
3581
|
+
src_logger.error('Failed to inspect config.');
|
|
3582
|
+
src_logger.error(err);
|
|
3288
3583
|
process.exit(1);
|
|
3289
3584
|
}
|
|
3290
3585
|
});
|
|
@@ -3301,20 +3596,20 @@ function setupCommands() {
|
|
|
3301
3596
|
};
|
|
3302
3597
|
await cliMfDev();
|
|
3303
3598
|
} catch (err) {
|
|
3304
|
-
|
|
3305
|
-
|
|
3599
|
+
src_logger.error('Failed to start mf-dev.');
|
|
3600
|
+
src_logger.error(err);
|
|
3306
3601
|
process.exit(1);
|
|
3307
3602
|
}
|
|
3308
3603
|
});
|
|
3309
3604
|
cli.help((sections)=>{
|
|
3310
3605
|
sections.shift();
|
|
3311
3606
|
for (const section of sections){
|
|
3312
|
-
if ('Usage' === section.title) section.body = section.body.replace('$ rslib',
|
|
3607
|
+
if ('Usage' === section.title) section.body = section.body.replace('$ rslib', color.yellow('$ rslib [command] [options]'));
|
|
3313
3608
|
if ('Commands' === section.title) section.body = section.body.replace(` ${buildDescription}`, `build ${buildDescription}`);
|
|
3314
3609
|
if (section.title?.startsWith('For more info')) {
|
|
3315
|
-
section.title =
|
|
3316
|
-
section.body =
|
|
3317
|
-
} else section.title =
|
|
3610
|
+
section.title = color.dim(' For details on a sub-command, run');
|
|
3611
|
+
section.body = color.dim(' $ rslib <command> -h');
|
|
3612
|
+
} else if (section.title) section.title = color.cyan(section.title);
|
|
3318
3613
|
}
|
|
3319
3614
|
});
|
|
3320
3615
|
cli.parse();
|
|
@@ -3334,7 +3629,7 @@ function showGreeting() {
|
|
|
3334
3629
|
const isBun = npm_execpath?.includes('.bun');
|
|
3335
3630
|
const isNodeRun = Boolean(NODE_RUN_SCRIPT_NAME);
|
|
3336
3631
|
const prefix = isNpx || isBun || isNodeRun ? '\n' : '';
|
|
3337
|
-
|
|
3632
|
+
src_logger.greet(`${prefix}Rslib v0.20.1\n`);
|
|
3338
3633
|
}
|
|
3339
3634
|
function setupLogLevel() {
|
|
3340
3635
|
const logLevelIndex = process.argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
|
|
@@ -3344,7 +3639,7 @@ function setupLogLevel() {
|
|
|
3344
3639
|
'warn',
|
|
3345
3640
|
'error',
|
|
3346
3641
|
'silent'
|
|
3347
|
-
].includes(level) && !isDebug())
|
|
3642
|
+
].includes(level) && !isDebug()) src_logger.level = level;
|
|
3348
3643
|
}
|
|
3349
3644
|
}
|
|
3350
3645
|
function runCLI() {
|
|
@@ -3355,8 +3650,8 @@ function runCLI() {
|
|
|
3355
3650
|
try {
|
|
3356
3651
|
setupCommands();
|
|
3357
3652
|
} catch (err) {
|
|
3358
|
-
|
|
3359
|
-
|
|
3653
|
+
src_logger.error('Failed to start Rslib CLI.');
|
|
3654
|
+
src_logger.error(err);
|
|
3360
3655
|
process.exit(1);
|
|
3361
3656
|
}
|
|
3362
3657
|
}
|
|
@@ -3388,6 +3683,6 @@ function mergeRslibConfig(...originalConfigs) {
|
|
|
3388
3683
|
if (void 0 !== mergedLib) mergedConfig.lib = mergedLib;
|
|
3389
3684
|
return mergedConfig;
|
|
3390
3685
|
}
|
|
3391
|
-
const src_version = "0.20.
|
|
3686
|
+
const src_version = "0.20.1";
|
|
3392
3687
|
var rspack_0 = __rspack_external__rsbuild_core_1b356efc.rspack;
|
|
3393
3688
|
export { __rspack_external__rsbuild_core_1b356efc as rsbuild, createRslib, loadConfig_defineConfig as defineConfig, loadConfig_loadConfig as loadConfig, loadEnv, mergeRslibConfig, rspack_0 as rspack, runCLI, src_version as version };
|