@rslib/core 0.19.6 → 0.20.0-canary-202603101
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/{800.js → 108.js} +6 -6
- package/dist/index.js +237 -185
- package/dist/libCssExtractLoader.js +5 -4
- package/dist-types/css/const.d.ts +3 -4
- package/dist-types/index.d.ts +1 -1
- package/dist-types/plugins/EntryChunkPlugin.d.ts +1 -2
- package/dist-types/types/config.d.ts +1 -0
- package/dist-types/types/rslib.d.ts +3 -3
- package/package.json +8 -8
- package/dist/entryModuleLoader.js +0 -5
- package/dist-types/plugins/entryModuleLoader.d.ts +0 -3
package/dist/{800.js → 108.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import node_path
|
|
1
|
+
import node_path from "node:path";
|
|
2
2
|
const SWC_HELPERS = '@swc/helpers';
|
|
3
3
|
const DTS_EXTENSIONS = [
|
|
4
4
|
'd.ts',
|
|
@@ -75,8 +75,8 @@ function isCssGlobalFile(filepath, auto) {
|
|
|
75
75
|
const isCssModules = isCssModulesFile(filepath, auto);
|
|
76
76
|
return !isCssModules;
|
|
77
77
|
}
|
|
78
|
-
const BASE_URI = '
|
|
79
|
-
const AUTO_PUBLIC_PATH = '
|
|
80
|
-
const ABSOLUTE_PUBLIC_PATH = `${BASE_URI}/
|
|
81
|
-
const SINGLE_DOT_PATH_SEGMENT = '
|
|
82
|
-
export { ABSOLUTE_PUBLIC_PATH, AUTO_PUBLIC_PATH, BASE_URI, CSS_EXTENSIONS_PATTERN, DTS_EXTENSIONS_PATTERN, JS_EXTENSIONS_PATTERN, SINGLE_DOT_PATH_SEGMENT, SWC_HELPERS,
|
|
78
|
+
const BASE_URI = 'rspack-css-extract://';
|
|
79
|
+
const AUTO_PUBLIC_PATH = '__css_extract_public_path_auto__';
|
|
80
|
+
const ABSOLUTE_PUBLIC_PATH = `${BASE_URI}/css-extract-plugin/`;
|
|
81
|
+
const SINGLE_DOT_PATH_SEGMENT = '__css_extract_single_dot_path_segment__';
|
|
82
|
+
export { ABSOLUTE_PUBLIC_PATH, AUTO_PUBLIC_PATH, BASE_URI, CSS_EXTENSIONS_PATTERN, DTS_EXTENSIONS_PATTERN, JS_EXTENSIONS_PATTERN, SINGLE_DOT_PATH_SEGMENT, SWC_HELPERS, getUndoPath, isCssFile, isCssGlobalFile, isCssModulesFile };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import * as __rspack_external__rsbuild_core_1b356efc from "@rsbuild/core";
|
|
2
1
|
import { logger } from "../compiled/rslog/index.js";
|
|
3
2
|
import picocolors from "../compiled/picocolors/index.js";
|
|
4
|
-
import {
|
|
5
|
-
import node_fs, { promises } from "node:fs";
|
|
6
|
-
import
|
|
3
|
+
import node_path, { basename as external_node_path_basename, dirname, extname, isAbsolute, join } from "node:path";
|
|
4
|
+
import node_fs, { promises as external_node_fs_promises } from "node:fs";
|
|
5
|
+
import promises from "node:fs/promises";
|
|
7
6
|
import node_util from "node:util";
|
|
7
|
+
import * as __rspack_external__rsbuild_core_1b356efc from "@rsbuild/core";
|
|
8
|
+
import { createRsbuild, defineConfig, loadConfig, loadEnv, mergeRsbuildConfig, rspack } from "@rsbuild/core";
|
|
8
9
|
import { glob } from "../compiled/tinyglobby/index.js";
|
|
9
10
|
import { createRequire } from "node:module";
|
|
10
11
|
import { createRequire as external_module_createRequire } from "module";
|
|
11
|
-
import {
|
|
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";
|
|
12
13
|
const isDebugKey = (keys)=>{
|
|
13
14
|
if (!process.env.DEBUG) return false;
|
|
14
15
|
const values = process.env.DEBUG.toLocaleLowerCase().split(',');
|
|
@@ -42,13 +43,13 @@ function toArr(any) {
|
|
|
42
43
|
];
|
|
43
44
|
}
|
|
44
45
|
function toVal(out, key, val, opts) {
|
|
45
|
-
var x, old = out[key], nxt = ~opts.string.indexOf(key) ? null == val || true === val ?
|
|
46
|
+
var x, old = out[key], nxt = ~opts.string.indexOf(key) ? null == val || true === val ? "" : String(val) : "boolean" == typeof val ? val : ~opts.boolean.indexOf(key) ? "false" === val ? false : "true" === val || (out._.push((x = +val, 0 * x === 0) ? x : val), !!val) : (x = +val, 0 * x === 0) ? x : val;
|
|
46
47
|
out[key] = null == old ? nxt : Array.isArray(old) ? old.concat(nxt) : [
|
|
47
48
|
old,
|
|
48
49
|
nxt
|
|
49
50
|
];
|
|
50
51
|
}
|
|
51
|
-
function
|
|
52
|
+
function lib_default(args, opts) {
|
|
52
53
|
args = args || [];
|
|
53
54
|
opts = opts || {};
|
|
54
55
|
var k, arr, arg, name, val, out = {
|
|
@@ -84,26 +85,26 @@ function mri2(args, opts) {
|
|
|
84
85
|
const keys = strict ? Object.keys(opts.alias) : [];
|
|
85
86
|
for(i = 0; i < len; i++){
|
|
86
87
|
arg = args[i];
|
|
87
|
-
if (
|
|
88
|
+
if ("--" === arg) {
|
|
88
89
|
out._ = out._.concat(args.slice(++i));
|
|
89
90
|
break;
|
|
90
91
|
}
|
|
91
92
|
for(j = 0; j < arg.length && 45 === arg.charCodeAt(j); j++);
|
|
92
93
|
if (0 === j) out._.push(arg);
|
|
93
|
-
else if (
|
|
94
|
+
else if ("no-" === arg.substring(j, j + 3)) {
|
|
94
95
|
name = arg.substring(j + 3);
|
|
95
96
|
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
96
97
|
out[name] = false;
|
|
97
98
|
} else {
|
|
98
99
|
for(idx = j + 1; idx < arg.length && 61 !== arg.charCodeAt(idx); idx++);
|
|
99
100
|
name = arg.substring(j, idx);
|
|
100
|
-
val = arg.substring(++idx) || i + 1 === len || 45 === (
|
|
101
|
+
val = arg.substring(++idx) || i + 1 === len || 45 === ("" + args[i + 1]).charCodeAt(0) || args[++i];
|
|
101
102
|
arr = 2 === j ? [
|
|
102
103
|
name
|
|
103
104
|
] : name;
|
|
104
105
|
for(idx = 0; idx < arr.length; idx++){
|
|
105
106
|
name = arr[idx];
|
|
106
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown(
|
|
107
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
107
108
|
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
@@ -117,8 +118,10 @@ function mri2(args, opts) {
|
|
|
117
118
|
}
|
|
118
119
|
return out;
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
function removeBrackets(v) {
|
|
122
|
+
return v.replace(/[<[].+/, "").trim();
|
|
123
|
+
}
|
|
124
|
+
function findAllBrackets(v) {
|
|
122
125
|
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
123
126
|
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
124
127
|
const res = [];
|
|
@@ -140,8 +143,8 @@ const findAllBrackets = (v)=>{
|
|
|
140
143
|
let squareMatch;
|
|
141
144
|
while(squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v))res.push(parse(squareMatch));
|
|
142
145
|
return res;
|
|
143
|
-
}
|
|
144
|
-
|
|
146
|
+
}
|
|
147
|
+
function getMriOptions(options) {
|
|
145
148
|
const result = {
|
|
146
149
|
alias: {},
|
|
147
150
|
boolean: []
|
|
@@ -149,53 +152,74 @@ const getMriOptions = (options)=>{
|
|
|
149
152
|
for (const [index, option] of options.entries()){
|
|
150
153
|
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
|
151
154
|
if (option.isBoolean) if (option.negated) {
|
|
152
|
-
|
|
153
|
-
if (!hasStringTypeOption) result.boolean.push(option.names[0]);
|
|
155
|
+
if (!options.some((o, i)=>i !== index && o.names.some((name)=>option.names.includes(name)) && "boolean" == typeof o.required)) result.boolean.push(option.names[0]);
|
|
154
156
|
} else result.boolean.push(option.names[0]);
|
|
155
157
|
}
|
|
156
158
|
return result;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
159
|
+
}
|
|
160
|
+
function findLongest(arr) {
|
|
161
|
+
return arr.sort((a, b)=>a.length > b.length ? -1 : 1)[0];
|
|
162
|
+
}
|
|
163
|
+
function padRight(str, length) {
|
|
164
|
+
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
165
|
+
}
|
|
166
|
+
function camelcase(input) {
|
|
167
|
+
return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
|
|
168
|
+
}
|
|
169
|
+
function setDotProp(obj, keys, val) {
|
|
170
|
+
let current = obj;
|
|
171
|
+
for(let i = 0; i < keys.length; i++){
|
|
172
|
+
const key = keys[i];
|
|
173
|
+
if (i === keys.length - 1) {
|
|
174
|
+
current[key] = val;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (null == current[key]) {
|
|
178
|
+
const nextKeyIsArrayIndex = +keys[i + 1] > -1;
|
|
179
|
+
current[key] = nextKeyIsArrayIndex ? [] : {};
|
|
180
|
+
}
|
|
181
|
+
current = current[key];
|
|
169
182
|
}
|
|
170
|
-
}
|
|
171
|
-
|
|
183
|
+
}
|
|
184
|
+
function setByType(obj, transforms) {
|
|
172
185
|
for (const key of Object.keys(transforms)){
|
|
173
186
|
const transform = transforms[key];
|
|
174
187
|
if (transform.shouldTransform) {
|
|
175
|
-
obj[key] =
|
|
188
|
+
obj[key] = [
|
|
189
|
+
obj[key]
|
|
190
|
+
].flat();
|
|
176
191
|
if ("function" == typeof transform.transformFunction) obj[key] = obj[key].map(transform.transformFunction);
|
|
177
192
|
}
|
|
178
193
|
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const m = /([
|
|
194
|
+
}
|
|
195
|
+
function getFileName(input) {
|
|
196
|
+
const m = /([^\\/]+)$/.exec(input);
|
|
182
197
|
return m ? m[1] : "";
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
198
|
+
}
|
|
199
|
+
function camelcaseOptionName(name) {
|
|
200
|
+
return name.split(".").map((v, i)=>0 === i ? camelcase(v) : v).join(".");
|
|
201
|
+
}
|
|
202
|
+
var CACError = class extends Error {
|
|
186
203
|
constructor(message){
|
|
187
204
|
super(message);
|
|
188
|
-
this.name =
|
|
189
|
-
if ("function"
|
|
190
|
-
else this.stack = new Error(message).stack;
|
|
205
|
+
this.name = "CACError";
|
|
206
|
+
if ("function" != typeof Error.captureStackTrace) this.stack = new Error(message).stack;
|
|
191
207
|
}
|
|
192
|
-
}
|
|
193
|
-
|
|
208
|
+
};
|
|
209
|
+
var Option = class {
|
|
210
|
+
rawName;
|
|
211
|
+
description;
|
|
212
|
+
name;
|
|
213
|
+
names;
|
|
214
|
+
isBoolean;
|
|
215
|
+
required;
|
|
216
|
+
config;
|
|
217
|
+
negated;
|
|
194
218
|
constructor(rawName, description, config){
|
|
195
219
|
this.rawName = rawName;
|
|
196
220
|
this.description = description;
|
|
197
221
|
this.config = Object.assign({}, config);
|
|
198
|
-
rawName = rawName.
|
|
222
|
+
rawName = rawName.replaceAll(".*", "");
|
|
199
223
|
this.negated = false;
|
|
200
224
|
this.names = removeBrackets(rawName).split(",").map((v)=>{
|
|
201
225
|
let name = v.trim().replace(/^-{1,2}/, "");
|
|
@@ -205,16 +229,36 @@ class Option {
|
|
|
205
229
|
}
|
|
206
230
|
return camelcaseOptionName(name);
|
|
207
231
|
}).sort((a, b)=>a.length > b.length ? 1 : -1);
|
|
208
|
-
this.name = this.names
|
|
232
|
+
this.name = this.names.at(-1);
|
|
209
233
|
if (this.negated && null == this.config.default) this.config.default = true;
|
|
210
234
|
if (rawName.includes("<")) this.required = true;
|
|
211
235
|
else if (rawName.includes("[")) this.required = false;
|
|
212
236
|
else this.isBoolean = true;
|
|
213
237
|
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
238
|
+
};
|
|
239
|
+
let runtimeProcessArgs;
|
|
240
|
+
let runtimeInfo;
|
|
241
|
+
if ("u" > typeof process) {
|
|
242
|
+
let runtimeName;
|
|
243
|
+
runtimeName = "u" > typeof Deno && "string" == typeof Deno.version?.deno ? "deno" : "u" > typeof Bun && "string" == typeof Bun.version ? "bun" : "node";
|
|
244
|
+
runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}`;
|
|
245
|
+
runtimeProcessArgs = process.argv;
|
|
246
|
+
} else runtimeInfo = "u" < typeof navigator ? "unknown" : `${navigator.platform} ${navigator.userAgent}`;
|
|
247
|
+
var Command = class {
|
|
248
|
+
rawName;
|
|
249
|
+
description;
|
|
250
|
+
config;
|
|
251
|
+
cli;
|
|
252
|
+
options;
|
|
253
|
+
aliasNames;
|
|
254
|
+
name;
|
|
255
|
+
args;
|
|
256
|
+
commandAction;
|
|
257
|
+
usageText;
|
|
258
|
+
versionNumber;
|
|
259
|
+
examples;
|
|
260
|
+
helpCallback;
|
|
261
|
+
globalCommand;
|
|
218
262
|
constructor(rawName, description, config = {}, cli){
|
|
219
263
|
this.rawName = rawName;
|
|
220
264
|
this.description = description;
|
|
@@ -285,14 +329,12 @@ class Command {
|
|
|
285
329
|
title: "Usage",
|
|
286
330
|
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
287
331
|
});
|
|
288
|
-
|
|
289
|
-
if (showCommands) {
|
|
332
|
+
if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
|
|
290
333
|
const longestCommandName = findLongest(commands.map((command)=>command.rawName));
|
|
291
334
|
sections.push({
|
|
292
335
|
title: "Commands",
|
|
293
336
|
body: commands.map((command)=>` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`).join("\n")
|
|
294
|
-
}
|
|
295
|
-
sections.push({
|
|
337
|
+
}, {
|
|
296
338
|
title: "For more info, run any command with the `--help` flag",
|
|
297
339
|
body: commands.map((command)=>` $ ${name}${"" === command.name ? "" : ` ${command.name}`} --help`).join("\n")
|
|
298
340
|
});
|
|
@@ -317,13 +359,12 @@ class Command {
|
|
|
317
359
|
}).join("\n")
|
|
318
360
|
});
|
|
319
361
|
if (helpCallback) sections = helpCallback(sections) || sections;
|
|
320
|
-
console.
|
|
321
|
-
${section.body}` : section.body).join("\n\n"));
|
|
362
|
+
console.info(sections.map((section)=>section.title ? `${section.title}:\n${section.body}` : section.body).join("\n\n"));
|
|
322
363
|
}
|
|
323
364
|
outputVersion() {
|
|
324
365
|
const { name } = this.cli;
|
|
325
366
|
const { versionNumber } = this.cli.globalCommand;
|
|
326
|
-
if (versionNumber) console.
|
|
367
|
+
if (versionNumber) console.info(`${name}/${versionNumber} ${runtimeInfo}`);
|
|
327
368
|
}
|
|
328
369
|
checkRequiredArgs() {
|
|
329
370
|
const minimalArgsCount = this.args.filter((arg)=>arg.required).length;
|
|
@@ -349,14 +390,27 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
349
390
|
}
|
|
350
391
|
}
|
|
351
392
|
}
|
|
352
|
-
|
|
353
|
-
|
|
393
|
+
checkUnusedArgs() {
|
|
394
|
+
const maximumArgsCount = this.args.some((arg)=>arg.variadic) ? 1 / 0 : this.args.length;
|
|
395
|
+
if (maximumArgsCount < this.cli.args.length) throw new CACError(`Unused args: ${this.cli.args.slice(maximumArgsCount).map((arg)=>`\`${arg}\``).join(", ")}`);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
var GlobalCommand = class extends Command {
|
|
354
399
|
constructor(cli){
|
|
355
400
|
super("@@global@@", "", {}, cli);
|
|
356
401
|
}
|
|
357
|
-
}
|
|
358
|
-
var
|
|
359
|
-
|
|
402
|
+
};
|
|
403
|
+
var CAC = class extends EventTarget {
|
|
404
|
+
name;
|
|
405
|
+
commands;
|
|
406
|
+
globalCommand;
|
|
407
|
+
matchedCommand;
|
|
408
|
+
matchedCommandName;
|
|
409
|
+
rawArgs;
|
|
410
|
+
args;
|
|
411
|
+
options;
|
|
412
|
+
showHelpOnExit;
|
|
413
|
+
showVersionOnExit;
|
|
360
414
|
constructor(name = ""){
|
|
361
415
|
super();
|
|
362
416
|
this.name = name;
|
|
@@ -414,7 +468,11 @@ class CAC extends EventEmitter {
|
|
|
414
468
|
this.matchedCommand = void 0;
|
|
415
469
|
this.matchedCommandName = void 0;
|
|
416
470
|
}
|
|
417
|
-
parse(argv
|
|
471
|
+
parse(argv, { run = true } = {}) {
|
|
472
|
+
if (!argv) {
|
|
473
|
+
if (!runtimeProcessArgs) throw new Error("No argv provided and runtime process argv is not available.");
|
|
474
|
+
argv = runtimeProcessArgs;
|
|
475
|
+
}
|
|
418
476
|
this.rawArgs = argv;
|
|
419
477
|
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
420
478
|
let shouldParse = true;
|
|
@@ -423,19 +481,24 @@ class CAC extends EventEmitter {
|
|
|
423
481
|
const commandName = parsed.args[0];
|
|
424
482
|
if (command.isMatched(commandName)) {
|
|
425
483
|
shouldParse = false;
|
|
426
|
-
const parsedInfo =
|
|
484
|
+
const parsedInfo = {
|
|
485
|
+
...parsed,
|
|
427
486
|
args: parsed.args.slice(1)
|
|
428
|
-
}
|
|
487
|
+
};
|
|
429
488
|
this.setParsedInfo(parsedInfo, command, commandName);
|
|
430
|
-
this.
|
|
489
|
+
this.dispatchEvent(new CustomEvent(`command:${commandName}`, {
|
|
490
|
+
detail: command
|
|
491
|
+
}));
|
|
431
492
|
}
|
|
432
493
|
}
|
|
433
494
|
if (shouldParse) {
|
|
434
|
-
for (const command of this.commands)if (
|
|
495
|
+
for (const command of this.commands)if (command.isDefaultCommand) {
|
|
435
496
|
shouldParse = false;
|
|
436
497
|
const parsed = this.mri(argv.slice(2), command);
|
|
437
498
|
this.setParsedInfo(parsed, command);
|
|
438
|
-
this.
|
|
499
|
+
this.dispatchEvent(new CustomEvent("command:!", {
|
|
500
|
+
detail: command
|
|
501
|
+
}));
|
|
439
502
|
}
|
|
440
503
|
}
|
|
441
504
|
if (shouldParse) {
|
|
@@ -457,7 +520,9 @@ class CAC extends EventEmitter {
|
|
|
457
520
|
options: this.options
|
|
458
521
|
};
|
|
459
522
|
if (run) this.runMatchedCommand();
|
|
460
|
-
if (!this.matchedCommand && this.args[0]) this.
|
|
523
|
+
if (!this.matchedCommand && this.args[0]) this.dispatchEvent(new CustomEvent("command:*", {
|
|
524
|
+
detail: this.args[0]
|
|
525
|
+
}));
|
|
461
526
|
return parsedArgv;
|
|
462
527
|
}
|
|
463
528
|
mri(argv, command) {
|
|
@@ -468,12 +533,13 @@ class CAC extends EventEmitter {
|
|
|
468
533
|
const mriOptions = getMriOptions(cliOptions);
|
|
469
534
|
let argsAfterDoubleDashes = [];
|
|
470
535
|
const doubleDashesIndex = argv.indexOf("--");
|
|
471
|
-
if (
|
|
536
|
+
if (-1 !== doubleDashesIndex) {
|
|
472
537
|
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
473
538
|
argv = argv.slice(0, doubleDashesIndex);
|
|
474
539
|
}
|
|
475
|
-
let parsed =
|
|
476
|
-
parsed = Object.keys(parsed).reduce((res, name)=>
|
|
540
|
+
let parsed = lib_default(argv, mriOptions);
|
|
541
|
+
parsed = Object.keys(parsed).reduce((res, name)=>({
|
|
542
|
+
...res,
|
|
477
543
|
[camelcaseOptionName(name)]: parsed[name]
|
|
478
544
|
}), {
|
|
479
545
|
_: []
|
|
@@ -483,20 +549,17 @@ class CAC extends EventEmitter {
|
|
|
483
549
|
"--": argsAfterDoubleDashes
|
|
484
550
|
};
|
|
485
551
|
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
486
|
-
|
|
552
|
+
const transforms = Object.create(null);
|
|
487
553
|
for (const cliOption of cliOptions){
|
|
488
554
|
if (!ignoreDefault && void 0 !== cliOption.config.default) for (const name of cliOption.names)options[name] = cliOption.config.default;
|
|
489
|
-
if (Array.isArray(cliOption.config.type)) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
|
494
|
-
}
|
|
555
|
+
if (Array.isArray(cliOption.config.type) && void 0 === transforms[cliOption.name]) {
|
|
556
|
+
transforms[cliOption.name] = Object.create(null);
|
|
557
|
+
transforms[cliOption.name].shouldTransform = true;
|
|
558
|
+
transforms[cliOption.name].transformFunction = cliOption.config.type[0];
|
|
495
559
|
}
|
|
496
560
|
}
|
|
497
561
|
for (const key of Object.keys(parsed))if ("_" !== key) {
|
|
498
|
-
|
|
499
|
-
setDotProp(options, keys, parsed[key]);
|
|
562
|
+
setDotProp(options, key.split("."), parsed[key]);
|
|
500
563
|
setByType(options, transforms);
|
|
501
564
|
}
|
|
502
565
|
return {
|
|
@@ -510,6 +573,7 @@ class CAC extends EventEmitter {
|
|
|
510
573
|
command.checkUnknownOptions();
|
|
511
574
|
command.checkOptionValue();
|
|
512
575
|
command.checkRequiredArgs();
|
|
576
|
+
command.checkUnusedArgs();
|
|
513
577
|
const actionArgs = [];
|
|
514
578
|
command.args.forEach((arg, index)=>{
|
|
515
579
|
if (arg.variadic) actionArgs.push(args.slice(index));
|
|
@@ -518,9 +582,8 @@ class CAC extends EventEmitter {
|
|
|
518
582
|
actionArgs.push(options);
|
|
519
583
|
return command.commandAction.apply(this, actionArgs);
|
|
520
584
|
}
|
|
521
|
-
}
|
|
585
|
+
};
|
|
522
586
|
const cac = (name = "")=>new CAC(name);
|
|
523
|
-
const dist = cac;
|
|
524
587
|
const nodeBuiltInModules = [
|
|
525
588
|
'assert',
|
|
526
589
|
'assert/strict',
|
|
@@ -592,7 +655,7 @@ async function calcLongestCommonPath(absPaths) {
|
|
|
592
655
|
lcaFragments = lcaFragments.slice(0, j);
|
|
593
656
|
}
|
|
594
657
|
let lca = lcaFragments.length > 0 ? lcaFragments.join(sep) : sep;
|
|
595
|
-
const stats = await
|
|
658
|
+
const stats = await promises.stat(lca);
|
|
596
659
|
if (stats?.isFile()) lca = node_path.dirname(lca);
|
|
597
660
|
return lca;
|
|
598
661
|
}
|
|
@@ -659,7 +722,7 @@ function normalizeSlash(p) {
|
|
|
659
722
|
}
|
|
660
723
|
async function isDirectory(filePath) {
|
|
661
724
|
try {
|
|
662
|
-
const stat = await
|
|
725
|
+
const stat = await promises.stat(filePath);
|
|
663
726
|
return stat.isDirectory();
|
|
664
727
|
} catch {
|
|
665
728
|
return false;
|
|
@@ -723,7 +786,7 @@ class LibSvgrPatchPlugin {
|
|
|
723
786
|
const chunkAsset = Object.keys(assets).filter((name)=>name.endsWith('js'));
|
|
724
787
|
for (const name of chunkAsset)compilation.updateAsset(name, (old)=>{
|
|
725
788
|
const oldSource = old.source().toString();
|
|
726
|
-
const newSource = new
|
|
789
|
+
const newSource = new rspack.sources.ReplaceSource(old);
|
|
727
790
|
const pattern = new RegExp(`\\(?['"]${PUBLIC_PATH_PLACEHOLDER}(.*)['"]\\)?`, 'g');
|
|
728
791
|
const matches = [
|
|
729
792
|
...oldSource.matchAll(pattern)
|
|
@@ -867,7 +930,7 @@ class LibCssExtractPlugin {
|
|
|
867
930
|
const chunkAsset = Object.keys(assets).filter((name)=>/\.css/.test(name));
|
|
868
931
|
for (const name of chunkAsset)compilation.updateAsset(name, (old)=>{
|
|
869
932
|
const oldSource = old.source().toString();
|
|
870
|
-
const replaceSource = new
|
|
933
|
+
const replaceSource = new rspack.sources.ReplaceSource(old);
|
|
871
934
|
function replace(searchValue, replaceValue) {
|
|
872
935
|
let start = oldSource.indexOf(searchValue);
|
|
873
936
|
while(-1 !== start){
|
|
@@ -918,22 +981,36 @@ const pluginLibCss = (rootDir, auto, banner, footer)=>({
|
|
|
918
981
|
});
|
|
919
982
|
api.modifyBundlerChain((config, { CHAIN_ID })=>{
|
|
920
983
|
let isUsingCssExtract = false;
|
|
921
|
-
for (const ruleId of [
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
984
|
+
for (const [ruleId, oneOfId] of [
|
|
985
|
+
[
|
|
986
|
+
CHAIN_ID.RULE.CSS,
|
|
987
|
+
CHAIN_ID.ONE_OF.CSS_MAIN
|
|
988
|
+
],
|
|
989
|
+
[
|
|
990
|
+
CHAIN_ID.RULE.SASS,
|
|
991
|
+
'sass'
|
|
992
|
+
],
|
|
993
|
+
[
|
|
994
|
+
CHAIN_ID.RULE.LESS,
|
|
995
|
+
'less'
|
|
996
|
+
],
|
|
997
|
+
[
|
|
998
|
+
CHAIN_ID.RULE.STYLUS,
|
|
999
|
+
'stylus'
|
|
1000
|
+
]
|
|
926
1001
|
]){
|
|
927
1002
|
if (!config.module.rules.has(ruleId)) continue;
|
|
928
|
-
const
|
|
929
|
-
if (
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
1003
|
+
const mainRule = config.module.rule(ruleId).oneOfs.get(oneOfId);
|
|
1004
|
+
if (mainRule) {
|
|
1005
|
+
if (mainRule.uses.has(CHAIN_ID.USE.MINI_CSS_EXTRACT)) {
|
|
1006
|
+
isUsingCssExtract = true;
|
|
1007
|
+
mainRule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader(cssConfig_require.resolve('./libCssExtractLoader.js')).options({
|
|
1008
|
+
rootDir,
|
|
1009
|
+
auto,
|
|
1010
|
+
banner,
|
|
1011
|
+
footer
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
937
1014
|
}
|
|
938
1015
|
}
|
|
939
1016
|
if (isUsingCssExtract) {
|
|
@@ -957,9 +1034,7 @@ const composeCssConfig = (rootDir, auto, bundle = true, banner, footer)=>{
|
|
|
957
1034
|
}
|
|
958
1035
|
};
|
|
959
1036
|
};
|
|
960
|
-
const EntryChunkPlugin_require = createRequire(import.meta.url);
|
|
961
1037
|
const EntryChunkPlugin_PLUGIN_NAME = 'rsbuild:lib-entry-chunk';
|
|
962
|
-
const LOADER_NAME = 'rsbuild:lib-entry-module';
|
|
963
1038
|
const IMPORT_META_URL_SHIM = `const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
964
1039
|
return typeof document === 'undefined'
|
|
965
1040
|
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
@@ -994,7 +1069,7 @@ class EntryChunkPlugin {
|
|
|
994
1069
|
const chunkAsset = Object.keys(assets).filter((name)=>JS_EXTENSIONS_PATTERN.test(name) && this.shimsInjectedAssets.has(name));
|
|
995
1070
|
for (const name of chunkAsset)compilation.updateAsset(name, (old)=>{
|
|
996
1071
|
const oldSource = old.source().toString();
|
|
997
|
-
const replaceSource = new
|
|
1072
|
+
const replaceSource = new rspack.sources.ReplaceSource(old);
|
|
998
1073
|
if (oldSource.startsWith('#!')) {
|
|
999
1074
|
const firstLineEnd = oldSource.indexOf('\n');
|
|
1000
1075
|
replaceSource.insert(firstLineEnd + 1, IMPORT_META_URL_SHIM);
|
|
@@ -1006,18 +1081,7 @@ class EntryChunkPlugin {
|
|
|
1006
1081
|
});
|
|
1007
1082
|
}
|
|
1008
1083
|
}
|
|
1009
|
-
const
|
|
1010
|
-
name: EntryChunkPlugin_PLUGIN_NAME,
|
|
1011
|
-
setup (api) {
|
|
1012
|
-
api.modifyBundlerChain((config, { CHAIN_ID })=>{
|
|
1013
|
-
config.module.rule(`Rslib:${CHAIN_ID.RULE.JS}-entry-loader`).test(config.module.rule(CHAIN_ID.RULE.JS).get('test')).issuer(/^$/).use(LOADER_NAME).loader(EntryChunkPlugin_require.resolve('./entryModuleLoader.js'));
|
|
1014
|
-
});
|
|
1015
|
-
}
|
|
1016
|
-
});
|
|
1017
|
-
const composeEntryChunkConfig = ({ enabledImportMetaUrlShim, useLoader, contextToWatch = null })=>({
|
|
1018
|
-
plugins: useLoader ? [
|
|
1019
|
-
entryModuleLoaderRsbuildPlugin()
|
|
1020
|
-
] : [],
|
|
1084
|
+
const composeEntryChunkConfig = ({ enabledImportMetaUrlShim, contextToWatch = null })=>({
|
|
1021
1085
|
tools: {
|
|
1022
1086
|
rspack: {
|
|
1023
1087
|
plugins: [
|
|
@@ -1057,9 +1121,9 @@ const pluginEsmRequireShim = ()=>({
|
|
|
1057
1121
|
setup (api) {
|
|
1058
1122
|
api.modifyRspackConfig((config)=>{
|
|
1059
1123
|
config.plugins ??= [];
|
|
1060
|
-
config.plugins.push(new
|
|
1124
|
+
config.plugins.push(new rspack.BannerPlugin({
|
|
1061
1125
|
banner: requireShim,
|
|
1062
|
-
stage:
|
|
1126
|
+
stage: rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
|
|
1063
1127
|
raw: true,
|
|
1064
1128
|
include: /\.(js|mjs)$/
|
|
1065
1129
|
}));
|
|
@@ -1278,7 +1342,7 @@ async function util_resolveTSConfigJson(filename, cache) {
|
|
|
1278
1342
|
if ('.json' !== node_path.extname(filename)) return;
|
|
1279
1343
|
const tsconfig = node_path.resolve(filename);
|
|
1280
1344
|
if (cache && (cache.hasParseResult(tsconfig) || cache.hasParseResult(filename))) return tsconfig;
|
|
1281
|
-
return
|
|
1345
|
+
return external_node_fs_promises.stat(tsconfig).then((stat)=>{
|
|
1282
1346
|
if (stat.isFile() || stat.isFIFO()) return tsconfig;
|
|
1283
1347
|
throw new Error(`${filename} exists but is not a regular file.`);
|
|
1284
1348
|
});
|
|
@@ -1578,7 +1642,7 @@ async function getParsedDeep(filename, cache, options) {
|
|
|
1578
1642
|
}
|
|
1579
1643
|
async function parseFile(tsconfigFile, cache, skipCache) {
|
|
1580
1644
|
if (!skipCache && cache?.hasParseResult(tsconfigFile) && !cache.getParseResult(tsconfigFile)._isRootFile_) return cache.getParseResult(tsconfigFile);
|
|
1581
|
-
const promise =
|
|
1645
|
+
const promise = external_node_fs_promises.readFile(tsconfigFile, 'utf-8').then(toJson).then((json)=>{
|
|
1582
1646
|
const parsed = JSON.parse(json);
|
|
1583
1647
|
applyDefaults(parsed, tsconfigFile);
|
|
1584
1648
|
return {
|
|
@@ -1900,30 +1964,30 @@ function composeBannerFooterConfig(banner, footer) {
|
|
|
1900
1964
|
if (isEmptyObject(bannerConfig) && isEmptyObject(footerConfig)) return {};
|
|
1901
1965
|
const plugins = [];
|
|
1902
1966
|
if (!isEmptyObject(bannerConfig)) {
|
|
1903
|
-
if (bannerConfig.js) plugins.push(new
|
|
1967
|
+
if (bannerConfig.js) plugins.push(new rspack.BannerPlugin({
|
|
1904
1968
|
banner: bannerConfig.js,
|
|
1905
|
-
stage:
|
|
1969
|
+
stage: rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
1906
1970
|
raw: true,
|
|
1907
1971
|
include: /\.(js|mjs|cjs)$/
|
|
1908
1972
|
}));
|
|
1909
|
-
if (bannerConfig.css) plugins.push(new
|
|
1973
|
+
if (bannerConfig.css) plugins.push(new rspack.BannerPlugin({
|
|
1910
1974
|
banner: bannerConfig.css,
|
|
1911
|
-
stage:
|
|
1975
|
+
stage: rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
1912
1976
|
raw: true,
|
|
1913
1977
|
include: /\.(css)$/
|
|
1914
1978
|
}));
|
|
1915
1979
|
}
|
|
1916
1980
|
if (!isEmptyObject(footerConfig)) {
|
|
1917
|
-
if (footerConfig.js) plugins.push(new
|
|
1981
|
+
if (footerConfig.js) plugins.push(new rspack.BannerPlugin({
|
|
1918
1982
|
banner: footerConfig.js,
|
|
1919
|
-
stage:
|
|
1983
|
+
stage: rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
1920
1984
|
raw: true,
|
|
1921
1985
|
footer: true,
|
|
1922
1986
|
include: /\.(js|mjs|cjs)$/
|
|
1923
1987
|
}));
|
|
1924
|
-
if (footerConfig.css) plugins.push(new
|
|
1988
|
+
if (footerConfig.css) plugins.push(new rspack.BannerPlugin({
|
|
1925
1989
|
banner: footerConfig.css,
|
|
1926
|
-
stage:
|
|
1990
|
+
stage: rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
1927
1991
|
raw: true,
|
|
1928
1992
|
footer: true,
|
|
1929
1993
|
include: /\.(css)$/
|
|
@@ -1964,7 +2028,7 @@ function composePrintFileSizeConfig(bundle, target) {
|
|
|
1964
2028
|
};
|
|
1965
2029
|
}
|
|
1966
2030
|
async function createConstantRsbuildConfig() {
|
|
1967
|
-
return
|
|
2031
|
+
return defineConfig({
|
|
1968
2032
|
performance: {
|
|
1969
2033
|
chunkSplit: {
|
|
1970
2034
|
strategy: 'custom'
|
|
@@ -1978,13 +2042,6 @@ async function createConstantRsbuildConfig() {
|
|
|
1978
2042
|
moduleIds: 'named',
|
|
1979
2043
|
nodeEnv: false
|
|
1980
2044
|
},
|
|
1981
|
-
experiments: {
|
|
1982
|
-
rspackFuture: {
|
|
1983
|
-
bundlerInfo: {
|
|
1984
|
-
force: false
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
},
|
|
1988
2045
|
resolve: {
|
|
1989
2046
|
extensionAlias: {
|
|
1990
2047
|
'.js': [
|
|
@@ -2020,7 +2077,7 @@ async function createConstantRsbuildConfig() {
|
|
|
2020
2077
|
}
|
|
2021
2078
|
});
|
|
2022
2079
|
}
|
|
2023
|
-
const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledShims
|
|
2080
|
+
const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledShims })=>{
|
|
2024
2081
|
const jsParserOptions = {
|
|
2025
2082
|
cjs: {
|
|
2026
2083
|
requireResolve: false,
|
|
@@ -2038,13 +2095,11 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledS
|
|
|
2038
2095
|
worker: false
|
|
2039
2096
|
}
|
|
2040
2097
|
};
|
|
2041
|
-
const experimentalEsmOutput = bundle && 'esm' === format && advancedEsm;
|
|
2042
2098
|
const plugins = [
|
|
2043
|
-
new
|
|
2099
|
+
new rspack.experiments.RslibPlugin({
|
|
2044
2100
|
interceptApiPlugin: true,
|
|
2045
2101
|
forceNodeShims: enabledShims.esm.__dirname || enabledShims.esm.__filename
|
|
2046
|
-
})
|
|
2047
|
-
experimentalEsmOutput && new __rspack_external__rsbuild_core_1b356efc.rspack.experiments.EsmLibraryPlugin()
|
|
2102
|
+
})
|
|
2048
2103
|
].filter(Boolean);
|
|
2049
2104
|
switch(format){
|
|
2050
2105
|
case 'esm':
|
|
@@ -2064,11 +2119,11 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledS
|
|
|
2064
2119
|
}
|
|
2065
2120
|
},
|
|
2066
2121
|
optimization: {
|
|
2067
|
-
concatenateModules:
|
|
2068
|
-
sideEffects:
|
|
2069
|
-
runtimeChunk:
|
|
2122
|
+
concatenateModules: false,
|
|
2123
|
+
sideEffects: true,
|
|
2124
|
+
runtimeChunk: {
|
|
2070
2125
|
name: 'rslib-runtime'
|
|
2071
|
-
}
|
|
2126
|
+
},
|
|
2072
2127
|
avoidEntryIife: true,
|
|
2073
2128
|
splitChunks: {
|
|
2074
2129
|
chunks: 'async'
|
|
@@ -2076,16 +2131,13 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledS
|
|
|
2076
2131
|
},
|
|
2077
2132
|
output: {
|
|
2078
2133
|
module: true,
|
|
2079
|
-
chunkFormat:
|
|
2134
|
+
chunkFormat: false,
|
|
2080
2135
|
library: {
|
|
2081
2136
|
type: 'modern-module'
|
|
2082
2137
|
},
|
|
2083
2138
|
chunkLoading: 'import',
|
|
2084
2139
|
workerChunkLoading: 'import'
|
|
2085
2140
|
},
|
|
2086
|
-
experiments: {
|
|
2087
|
-
outputModule: true
|
|
2088
|
-
},
|
|
2089
2141
|
plugins
|
|
2090
2142
|
}
|
|
2091
2143
|
}
|
|
@@ -2093,6 +2145,7 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledS
|
|
|
2093
2145
|
case 'cjs':
|
|
2094
2146
|
return {
|
|
2095
2147
|
output: {
|
|
2148
|
+
module: false,
|
|
2096
2149
|
filenameHash: false
|
|
2097
2150
|
},
|
|
2098
2151
|
tools: {
|
|
@@ -2129,6 +2182,7 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledS
|
|
|
2129
2182
|
if (!bundle) throw new Error('When using "umd" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.');
|
|
2130
2183
|
const config = {
|
|
2131
2184
|
output: {
|
|
2185
|
+
module: false,
|
|
2132
2186
|
filenameHash: false
|
|
2133
2187
|
},
|
|
2134
2188
|
tools: {
|
|
@@ -2164,6 +2218,7 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledS
|
|
|
2164
2218
|
if (!bundle) throw new Error('When using "iife" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.');
|
|
2165
2219
|
const config = {
|
|
2166
2220
|
output: {
|
|
2221
|
+
module: false,
|
|
2167
2222
|
filenameHash: false,
|
|
2168
2223
|
minify: {
|
|
2169
2224
|
jsOptions: {
|
|
@@ -2186,7 +2241,7 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson, enabledS
|
|
|
2186
2241
|
iife: true,
|
|
2187
2242
|
asyncChunks: false,
|
|
2188
2243
|
library: {
|
|
2189
|
-
type: '
|
|
2244
|
+
type: 'module'
|
|
2190
2245
|
}
|
|
2191
2246
|
},
|
|
2192
2247
|
optimization: {
|
|
@@ -2230,7 +2285,7 @@ const disableUrlParseRsbuildPlugin = ()=>({
|
|
|
2230
2285
|
name: 'rsbuild:disable-url-parse',
|
|
2231
2286
|
setup (api) {
|
|
2232
2287
|
api.modifyBundlerChain((config, { CHAIN_ID })=>{
|
|
2233
|
-
config.module.rule(CHAIN_ID.RULE.JS).parser({
|
|
2288
|
+
config.module.rule(CHAIN_ID.RULE.JS).oneOf(CHAIN_ID.ONE_OF.JS_MAIN).parser({
|
|
2234
2289
|
url: false
|
|
2235
2290
|
});
|
|
2236
2291
|
});
|
|
@@ -2240,21 +2295,19 @@ const fixJsModuleTypePlugin = ()=>({
|
|
|
2240
2295
|
name: 'rsbuild:fix-js-module-type',
|
|
2241
2296
|
setup (api) {
|
|
2242
2297
|
api.modifyBundlerChain((config, { CHAIN_ID })=>{
|
|
2243
|
-
config.module.rule(CHAIN_ID.RULE.JS).delete('type');
|
|
2298
|
+
config.module.rule(CHAIN_ID.RULE.JS).oneOf(CHAIN_ID.ONE_OF.JS_MAIN).delete('type');
|
|
2244
2299
|
});
|
|
2245
2300
|
}
|
|
2246
2301
|
});
|
|
2247
2302
|
const BundlePlugin = ()=>({
|
|
2248
2303
|
name: 'rslib:bundle',
|
|
2249
2304
|
setup (api) {
|
|
2250
|
-
api.
|
|
2305
|
+
api.onBeforeEnvironmentCompile({
|
|
2251
2306
|
order: 'post',
|
|
2252
|
-
handler: ({
|
|
2253
|
-
if (
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
process.exit(1);
|
|
2257
|
-
}
|
|
2307
|
+
handler: ({ bundlerConfig })=>{
|
|
2308
|
+
if (bundlerConfig?.module?.parser?.javascript?.jsx === true) {
|
|
2309
|
+
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 ' + picocolors.green('https://rslib.rs/guide/solution/react#jsx-transform') + ' for more details.');
|
|
2310
|
+
process.exit(1);
|
|
2258
2311
|
}
|
|
2259
2312
|
}
|
|
2260
2313
|
});
|
|
@@ -2393,7 +2446,7 @@ const composeOutputFilenameConfig = (config, format, autoExtension, multiCompile
|
|
|
2393
2446
|
const filenameHash = config.output?.filenameHash ?? false;
|
|
2394
2447
|
const getHash = ()=>{
|
|
2395
2448
|
if ('string' == typeof filenameHash) return filenameHash ? `.[${filenameHash}]` : '';
|
|
2396
|
-
return filenameHash ? '.[contenthash:
|
|
2449
|
+
return filenameHash ? '.[contenthash:10]' : '';
|
|
2397
2450
|
};
|
|
2398
2451
|
const inferChunkFilename = (filename)=>{
|
|
2399
2452
|
if ('function' != typeof filename) {
|
|
@@ -2420,7 +2473,7 @@ const composeOutputFilenameConfig = (config, format, autoExtension, multiCompile
|
|
|
2420
2473
|
}
|
|
2421
2474
|
}
|
|
2422
2475
|
};
|
|
2423
|
-
const finalConfig = userJsFilename ? chunkFilename :
|
|
2476
|
+
const finalConfig = userJsFilename ? chunkFilename : mergeRsbuildConfig(chunkFilename, {
|
|
2424
2477
|
output: {
|
|
2425
2478
|
filename: {
|
|
2426
2479
|
js: defaultJsFilename
|
|
@@ -2492,8 +2545,11 @@ const composeEntryConfig = async (rawEntry, bundle, root, cssModulesAuto, userOu
|
|
|
2492
2545
|
if (node_fs.existsSync(entryAbsPath)) {
|
|
2493
2546
|
const stats = node_fs.statSync(entryAbsPath);
|
|
2494
2547
|
if (!stats.isFile()) entryErrorReasons.push(dirError);
|
|
2495
|
-
} else
|
|
2496
|
-
|
|
2548
|
+
} else {
|
|
2549
|
+
const isGlobLike = entry.startsWith('!') || /[*?[{\]}]/.test(entry);
|
|
2550
|
+
if (isDirLike || isGlobLike) entryErrorReasons.push(dirError);
|
|
2551
|
+
else entryErrorReasons.push(`Can't resolve the entry ${picocolors.cyan(`"${entry}"`)} at the location ${picocolors.cyan(entryAbsPath)}. Please ensure that the file exists.`);
|
|
2552
|
+
}
|
|
2497
2553
|
return entry;
|
|
2498
2554
|
});
|
|
2499
2555
|
if (entryErrorReasons.length) throw new AggregateError(entryErrorReasons.map((reason)=>new Error(reason)));
|
|
@@ -2759,8 +2815,7 @@ async function composeLibRsbuildConfig(config, multiCompilerIndex, root = proces
|
|
|
2759
2815
|
const pkgJson = readPackageJson(root);
|
|
2760
2816
|
const { compilerOptions } = await loadTsconfig(root, config.source?.tsconfigPath);
|
|
2761
2817
|
const cssModulesAuto = config.output?.cssModules?.auto ?? true;
|
|
2762
|
-
const { format = 'esm', shims, bundle = true, banner = {}, footer = {}, autoExtension = true, autoExternal, externalHelpers = false, redirect = {}, umdName
|
|
2763
|
-
const advancedEsm = experiments?.advancedEsm ?? true;
|
|
2818
|
+
const { format = 'esm', shims, bundle = true, banner = {}, footer = {}, autoExtension = true, autoExternal, externalHelpers = false, redirect = {}, umdName } = config;
|
|
2764
2819
|
const { rsbuildConfig: bundleConfig } = composeBundleConfig(bundle);
|
|
2765
2820
|
const { rsbuildConfig: shimsConfig, enabledShims } = composeShimsConfig(format, shims);
|
|
2766
2821
|
const formatConfig = composeFormatConfig({
|
|
@@ -2768,8 +2823,7 @@ async function composeLibRsbuildConfig(config, multiCompilerIndex, root = proces
|
|
|
2768
2823
|
pkgJson: pkgJson,
|
|
2769
2824
|
bundle,
|
|
2770
2825
|
umdName,
|
|
2771
|
-
enabledShims
|
|
2772
|
-
advancedEsm
|
|
2826
|
+
enabledShims
|
|
2773
2827
|
});
|
|
2774
2828
|
const externalHelpersConfig = composeExternalHelpersConfig(externalHelpers, pkgJson);
|
|
2775
2829
|
const userExternalsConfig = composeExternalsConfig(format, config.output?.externals);
|
|
@@ -2788,7 +2842,6 @@ async function composeLibRsbuildConfig(config, multiCompilerIndex, root = proces
|
|
|
2788
2842
|
const cssConfig = composeCssConfig(outBase, cssModulesAuto, config.bundle, banner?.css, footer?.css);
|
|
2789
2843
|
const assetConfig = composeAssetConfig(bundle, format);
|
|
2790
2844
|
const entryChunkConfig = composeEntryChunkConfig({
|
|
2791
|
-
useLoader: 'iife' === format || 'esm' === format && !advancedEsm,
|
|
2792
2845
|
enabledImportMetaUrlShim: enabledShims.cjs['import.meta.url'],
|
|
2793
2846
|
contextToWatch: outBase
|
|
2794
2847
|
});
|
|
@@ -2798,7 +2851,7 @@ async function composeLibRsbuildConfig(config, multiCompilerIndex, root = proces
|
|
|
2798
2851
|
const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
|
|
2799
2852
|
const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
|
|
2800
2853
|
const printFileSizeConfig = composePrintFileSizeConfig(bundle, target);
|
|
2801
|
-
return
|
|
2854
|
+
return mergeRsbuildConfig(bundleConfig, formatConfig, shimsConfig, syntaxConfig, externalHelpersConfig, outputFilenameConfig, targetConfig, externalsWarnConfig, userExternalsConfig, autoExternalConfig, targetExternalsConfig, bundlelessExternalConfig, entryConfig, cssConfig, assetConfig, entryChunkConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig, printFileSizeConfig);
|
|
2802
2855
|
}
|
|
2803
2856
|
async function composeCreateRsbuildConfig(rslibConfig) {
|
|
2804
2857
|
const constantRsbuildConfig = await createConstantRsbuildConfig();
|
|
@@ -2806,7 +2859,7 @@ async function composeCreateRsbuildConfig(rslibConfig) {
|
|
|
2806
2859
|
if (logLevel && !isDebug()) logger.level = logLevel;
|
|
2807
2860
|
if (!Array.isArray(libConfigsArray) || 0 === libConfigsArray.length) throw new Error(`Expect "lib" field to be a non-empty array, but got: ${picocolors.cyan(JSON.stringify(libConfigsArray))}.`);
|
|
2808
2861
|
const libConfigPromises = libConfigsArray.map(async (libConfig, index)=>{
|
|
2809
|
-
const userConfig =
|
|
2862
|
+
const userConfig = mergeRsbuildConfig(sharedRsbuildConfig, libConfig);
|
|
2810
2863
|
const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, libConfigsArray.length > 1 ? index : null, root, sharedPlugins);
|
|
2811
2864
|
userConfig.source ??= {};
|
|
2812
2865
|
userConfig.source.entry = {};
|
|
@@ -2814,7 +2867,7 @@ async function composeCreateRsbuildConfig(rslibConfig) {
|
|
|
2814
2867
|
delete userConfig.output.externals;
|
|
2815
2868
|
const config = {
|
|
2816
2869
|
format: libConfig.format ?? 'esm',
|
|
2817
|
-
config:
|
|
2870
|
+
config: mergeRsbuildConfig(constantRsbuildConfig, libRsbuildConfig, omit(userConfig, {
|
|
2818
2871
|
id: true,
|
|
2819
2872
|
bundle: true,
|
|
2820
2873
|
format: true,
|
|
@@ -2908,7 +2961,7 @@ const applyDebugInspectConfigPlugin = (rsbuildInstance, config)=>{
|
|
|
2908
2961
|
});
|
|
2909
2962
|
};
|
|
2910
2963
|
async function createRslib(options = {}) {
|
|
2911
|
-
const envs = options.loadEnv ?
|
|
2964
|
+
const envs = options.loadEnv ? loadEnv({
|
|
2912
2965
|
cwd: options.cwd,
|
|
2913
2966
|
...'boolean' == typeof options.loadEnv ? {} : options.loadEnv
|
|
2914
2967
|
}) : null;
|
|
@@ -2929,7 +2982,7 @@ async function createRslib(options = {}) {
|
|
|
2929
2982
|
onAfterCreateRsbuildCallbacks.push(callback);
|
|
2930
2983
|
};
|
|
2931
2984
|
const createRsbuildInstance = async (options, mode, environments)=>{
|
|
2932
|
-
const rsbuildInstance = await
|
|
2985
|
+
const rsbuildInstance = await createRsbuild({
|
|
2933
2986
|
cwd: options.cwd,
|
|
2934
2987
|
callerName: 'rslib',
|
|
2935
2988
|
config: {
|
|
@@ -3019,7 +3072,7 @@ async function createRslib(options = {}) {
|
|
|
3019
3072
|
};
|
|
3020
3073
|
return rslib;
|
|
3021
3074
|
}
|
|
3022
|
-
function
|
|
3075
|
+
function loadConfig_defineConfig(config) {
|
|
3023
3076
|
return config;
|
|
3024
3077
|
}
|
|
3025
3078
|
const resolveConfigPath = (root, customConfig)=>{
|
|
@@ -3044,7 +3097,7 @@ const resolveConfigPath = (root, customConfig)=>{
|
|
|
3044
3097
|
}
|
|
3045
3098
|
return null;
|
|
3046
3099
|
};
|
|
3047
|
-
async function
|
|
3100
|
+
async function loadConfig_loadConfig({ cwd = process.cwd(), path, envMode, meta, loader }) {
|
|
3048
3101
|
const configFilePath = resolveConfigPath(cwd, path);
|
|
3049
3102
|
if (!configFilePath) {
|
|
3050
3103
|
logger.debug('no config file found.');
|
|
@@ -3053,7 +3106,7 @@ async function loadConfig({ cwd = process.cwd(), path, envMode, meta, loader })
|
|
|
3053
3106
|
filePath: null
|
|
3054
3107
|
};
|
|
3055
3108
|
}
|
|
3056
|
-
const { content } = await
|
|
3109
|
+
const { content } = await loadConfig({
|
|
3057
3110
|
cwd: dirname(configFilePath),
|
|
3058
3111
|
path: configFilePath,
|
|
3059
3112
|
envMode,
|
|
@@ -3140,7 +3193,7 @@ const applyCliOptions = (config, options, root)=>{
|
|
|
3140
3193
|
}
|
|
3141
3194
|
};
|
|
3142
3195
|
const init_loadConfig = async (options, root)=>{
|
|
3143
|
-
const { content: config, filePath: configFilePath } = await
|
|
3196
|
+
const { content: config, filePath: configFilePath } = await loadConfig_loadConfig({
|
|
3144
3197
|
cwd: root,
|
|
3145
3198
|
path: options.config,
|
|
3146
3199
|
envMode: options.envMode,
|
|
@@ -3180,8 +3233,8 @@ const applyCommonOptions = (cli)=>{
|
|
|
3180
3233
|
}).option('--no-env', 'Disable loading of `.env` files');
|
|
3181
3234
|
};
|
|
3182
3235
|
function setupCommands() {
|
|
3183
|
-
const cli =
|
|
3184
|
-
cli.version("0.
|
|
3236
|
+
const cli = cac('rslib');
|
|
3237
|
+
cli.version("0.20.0-canary-202603101");
|
|
3185
3238
|
applyCommonOptions(cli);
|
|
3186
3239
|
const buildDescription = `build the library for production ${picocolors.dim('(default if no command is given)')}`;
|
|
3187
3240
|
const buildCommand = cli.command('', buildDescription).alias('build');
|
|
@@ -3281,7 +3334,7 @@ function showGreeting() {
|
|
|
3281
3334
|
const isBun = npm_execpath?.includes('.bun');
|
|
3282
3335
|
const isNodeRun = Boolean(NODE_RUN_SCRIPT_NAME);
|
|
3283
3336
|
const prefix = isNpx || isBun || isNodeRun ? '\n' : '';
|
|
3284
|
-
logger.greet(`${prefix}Rslib v0.
|
|
3337
|
+
logger.greet(`${prefix}Rslib v0.20.0-canary-202603101\n`);
|
|
3285
3338
|
}
|
|
3286
3339
|
function setupLogLevel() {
|
|
3287
3340
|
const logLevelIndex = process.argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
|
|
@@ -3314,7 +3367,7 @@ function mergeLibConfigs(...libArrays) {
|
|
|
3314
3367
|
const itemsWithoutId = [];
|
|
3315
3368
|
for (const libArray of definedLibArrays)for (const libConfig of libArray)if (void 0 !== libConfig.id) {
|
|
3316
3369
|
const existing = mergedById.get(libConfig.id);
|
|
3317
|
-
if (existing) mergedById.set(libConfig.id,
|
|
3370
|
+
if (existing) mergedById.set(libConfig.id, mergeRsbuildConfig(existing, libConfig));
|
|
3318
3371
|
else mergedById.set(libConfig.id, libConfig);
|
|
3319
3372
|
} else itemsWithoutId.push(libConfig);
|
|
3320
3373
|
return [
|
|
@@ -3330,12 +3383,11 @@ function mergeRslibConfig(...originalConfigs) {
|
|
|
3330
3383
|
const { lib: _, ...rest } = config;
|
|
3331
3384
|
return rest;
|
|
3332
3385
|
});
|
|
3333
|
-
const mergedConfig =
|
|
3386
|
+
const mergedConfig = mergeRsbuildConfig(...configsWithoutLib);
|
|
3334
3387
|
const mergedLib = mergeLibConfigs(...libArrays);
|
|
3335
3388
|
if (void 0 !== mergedLib) mergedConfig.lib = mergedLib;
|
|
3336
3389
|
return mergedConfig;
|
|
3337
3390
|
}
|
|
3338
|
-
const src_version = "0.
|
|
3339
|
-
var
|
|
3340
|
-
|
|
3341
|
-
export { __rspack_external__rsbuild_core_1b356efc as rsbuild, createRslib, defineConfig, loadConfig, loadEnv, mergeRslibConfig, rspack, runCLI, src_version as version };
|
|
3391
|
+
const src_version = "0.20.0-canary-202603101";
|
|
3392
|
+
var rspack_0 = __rspack_external__rsbuild_core_1b356efc.rspack;
|
|
3393
|
+
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 };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import node_path, { extname } from "node:path";
|
|
2
|
+
import { isCssModulesFile, ABSOLUTE_PUBLIC_PATH, SINGLE_DOT_PATH_SEGMENT, BASE_URI, AUTO_PUBLIC_PATH } from "./108.js";
|
|
2
3
|
const LOADER_NAME = 'LIB_CSS_EXTRACT_LOADER';
|
|
3
4
|
function stringifyLocal(value) {
|
|
4
5
|
return 'function' == typeof value ? value.toString() : JSON.stringify(value);
|
|
5
6
|
}
|
|
6
7
|
const libCssExtractLoader_loader = function(content) {
|
|
7
|
-
if (this.
|
|
8
|
+
if (this._module && ('css' === this._module.type || 'css/auto' === this._module.type || 'css/global' === this._module.type || 'css/module' === this._module.type)) return content;
|
|
8
9
|
};
|
|
9
10
|
const pitch = function(request, _, _data) {
|
|
10
|
-
if (this.
|
|
11
|
-
const e = new Error("use type 'css' and `CssExtractRspackPlugin` together, please set `
|
|
11
|
+
if (this._module && ('css' === this._module.type || 'css/auto' === this._module.type || 'css/global' === this._module.type || 'css/module' === this._module.type)) {
|
|
12
|
+
const e = new Error("use type 'css' and `CssExtractRspackPlugin` together, please set `{ type: \"javascript/auto\" }` for rules with `CssExtractRspackPlugin` in your rspack config (now `CssExtractRspackPlugin` does nothing).");
|
|
12
13
|
e.stack = void 0;
|
|
13
14
|
this.emitWarning(e);
|
|
14
15
|
return;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export declare const BASE_URI = "
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const AUTO_PUBLIC_PATH = "__mini_css_extract_plugin_public_path_auto__";
|
|
1
|
+
export declare const BASE_URI = "rspack-css-extract://";
|
|
2
|
+
export declare const AUTO_PUBLIC_PATH = "__css_extract_public_path_auto__";
|
|
4
3
|
export declare const ABSOLUTE_PUBLIC_PATH: string;
|
|
5
|
-
export declare const SINGLE_DOT_PATH_SEGMENT = "
|
|
4
|
+
export declare const SINGLE_DOT_PATH_SEGMENT = "__css_extract_single_dot_path_segment__";
|
package/dist-types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { runCLI } from './cli';
|
|
|
6
6
|
export { createRslib } from './createRslib';
|
|
7
7
|
export { type ConfigParams, defineConfig, type LoadConfigOptions, type LoadConfigResult, type LoadEnvOptions, type LoadEnvResult, loadConfig, loadEnv, } from './loadConfig';
|
|
8
8
|
export { mergeRslibConfig } from './mergeConfig';
|
|
9
|
-
export type { AutoExternal, BannerAndFooter, BuildOptions, BuildResult, CreateRslibOptions, Dts, Format, InspectConfigOptions, InspectConfigResult, LibConfig, LibExperiments, OnAfterCreateRsbuildFn, Redirect, RslibConfig, RslibInstance, Shims, StartMFDevServerOptions,
|
|
9
|
+
export type { AutoExternal, BannerAndFooter, BuildOptions, BuildResult, CreateRslibOptions, Dts, Format, InspectConfigOptions, InspectConfigResult, LibConfig, LibExperiments, OnAfterCreateRsbuildFn, Redirect, RslibConfig, RslibInstance, Shims, StartMFDevServerOptions, StartDevServerResult, Syntax, } from './types';
|
|
10
10
|
export declare const version: string;
|
|
11
11
|
export type * as Rsbuild from '@rsbuild/core';
|
|
12
12
|
export * as rsbuild from '@rsbuild/core';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type EnvironmentConfig } from '@rsbuild/core';
|
|
2
|
-
export declare const composeEntryChunkConfig: ({ enabledImportMetaUrlShim,
|
|
3
|
-
useLoader: boolean;
|
|
2
|
+
export declare const composeEntryChunkConfig: ({ enabledImportMetaUrlShim, contextToWatch, }: {
|
|
4
3
|
enabledImportMetaUrlShim: boolean;
|
|
5
4
|
contextToWatch: string | null;
|
|
6
5
|
}) => EnvironmentConfig;
|
|
@@ -208,6 +208,7 @@ export type Redirect = {
|
|
|
208
208
|
export type LibExperiments = {
|
|
209
209
|
/**
|
|
210
210
|
* Whether to enable Rspack advanced ESM output.
|
|
211
|
+
* @deprecated The advanced ESM output is now the default output for ESM format and this option has no effect. It will be removed in a future major version.
|
|
211
212
|
* @defaultValue `true`
|
|
212
213
|
* @see {@link https://rslib.rs/config/lib/experiments#experimentsadvancedesm}
|
|
213
214
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BuildResult, LoadEnvOptions, InspectConfigResult as RsbuildInspectConfigResult, RsbuildInstance, RsbuildMode,
|
|
1
|
+
import type { BuildResult, LoadEnvOptions, InspectConfigResult as RsbuildInspectConfigResult, RsbuildInstance, RsbuildMode, StartDevServerResult } from '@rsbuild/core';
|
|
2
2
|
import type { RslibConfig } from './config';
|
|
3
3
|
export type CommonOptions = {
|
|
4
4
|
/**
|
|
@@ -38,7 +38,7 @@ export type InspectConfigOptions = CommonOptions & {
|
|
|
38
38
|
writeToDisk?: boolean;
|
|
39
39
|
};
|
|
40
40
|
export type StartMFDevServerOptions = CommonOptions;
|
|
41
|
-
export type { BuildResult,
|
|
41
|
+
export type { BuildResult, StartDevServerResult };
|
|
42
42
|
export type InspectConfigResult = {
|
|
43
43
|
rslibConfig: string;
|
|
44
44
|
} & RsbuildInspectConfigResult;
|
|
@@ -74,7 +74,7 @@ export type RslibInstance = {
|
|
|
74
74
|
* 1. Start a development server that serves your mf format module.
|
|
75
75
|
* 2. Watch for file changes and trigger recompilation.
|
|
76
76
|
*/
|
|
77
|
-
startMFDevServer(options?: StartMFDevServerOptions): Promise<
|
|
77
|
+
startMFDevServer(options?: StartMFDevServerOptions): Promise<StartDevServerResult>;
|
|
78
78
|
};
|
|
79
79
|
export type OnAfterCreateRsbuildFn = (params: {
|
|
80
80
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rslib/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0-canary-202603101",
|
|
4
4
|
"description": "The Rsbuild-based library development tool.",
|
|
5
5
|
"homepage": "https://rslib.rs",
|
|
6
6
|
"bugs": {
|
|
@@ -36,21 +36,21 @@
|
|
|
36
36
|
"types.d.ts"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@rsbuild/core": "
|
|
40
|
-
"rsbuild-plugin-dts": "0.
|
|
39
|
+
"@rsbuild/core": "2.0.0-canary-20260309140114",
|
|
40
|
+
"rsbuild-plugin-dts": "0.20.0-canary-202603101"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@module-federation/rsbuild-plugin": "^0.24.1",
|
|
44
44
|
"@types/fs-extra": "^11.0.4",
|
|
45
|
-
"cac": "^
|
|
45
|
+
"cac": "^7.0.0",
|
|
46
46
|
"chokidar": "^4.0.3",
|
|
47
|
-
"fs-extra": "^11.3.
|
|
48
|
-
"memfs": "^4.56.
|
|
47
|
+
"fs-extra": "^11.3.4",
|
|
48
|
+
"memfs": "^4.56.11",
|
|
49
49
|
"path-serializer": "0.5.1",
|
|
50
50
|
"picocolors": "1.1.1",
|
|
51
51
|
"prebundle": "1.6.2",
|
|
52
52
|
"rsbuild-plugin-publint": "^0.3.4",
|
|
53
|
-
"rslib": "npm:@rslib/core@0.
|
|
53
|
+
"rslib": "npm:@rslib/core@0.20.0-canary-202603091",
|
|
54
54
|
"rslog": "^1.3.2",
|
|
55
55
|
"tinyglobby": "0.2.14",
|
|
56
56
|
"tsconfck": "3.1.6",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"engines": {
|
|
73
|
-
"node": ">=
|
|
73
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
74
74
|
},
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public",
|