@rslib/core 0.0.5 → 0.0.7
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/README.md +2 -2
- package/compiled/rslog/index.d.ts +66 -0
- package/compiled/rslog/index.js +334 -0
- package/compiled/rslog/license +21 -0
- package/compiled/rslog/package.json +1 -0
- package/dist/index.js +949 -392
- package/dist-types/config.d.ts +1 -0
- package/dist-types/constant.d.ts +6 -1
- package/dist-types/plugins/cjsShim.d.ts +2 -0
- package/dist-types/types/config/index.d.ts +4 -1
- package/dist-types/utils/syntax.d.ts +11 -2
- package/dist-types/utils/tsconfig.d.ts +3 -0
- package/package.json +8 -7
package/dist/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE_os__ from "os";
|
|
3
|
-
import * as __WEBPACK_EXTERNAL_MODULE_tty__ from "tty";
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__ from "../compiled/rslog/index.js";
|
|
4
2
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
|
|
5
3
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises__ from "node:fs/promises";
|
|
6
4
|
import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
|
|
@@ -8,281 +6,7 @@ import * as __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__ from "../c
|
|
|
8
6
|
import * as __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__ from "../compiled/commander/index.js";
|
|
9
7
|
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
|
|
10
8
|
import * as __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js__ from "../compiled/fast-glob/index.js";
|
|
11
|
-
|
|
12
|
-
"rsbuild-plugin-dts": function(module) {
|
|
13
|
-
module.exports = import("rsbuild-plugin-dts");
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
/************************************************************************/ // The module cache
|
|
17
|
-
var __webpack_module_cache__ = {};
|
|
18
|
-
// The require function
|
|
19
|
-
function __webpack_require__(moduleId) {
|
|
20
|
-
// Check if module is in cache
|
|
21
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
22
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
23
|
-
// Create a new module (and put it into the cache)
|
|
24
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
25
|
-
exports: {}
|
|
26
|
-
};
|
|
27
|
-
// Execute the module function
|
|
28
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
29
|
-
// Return the exports of the module
|
|
30
|
-
return module.exports;
|
|
31
|
-
} /************************************************************************/
|
|
32
|
-
var external_process_namespaceObject = __WEBPACK_EXTERNAL_MODULE_process__;
|
|
33
|
-
var external_os_namespaceObject = __WEBPACK_EXTERNAL_MODULE_os__;
|
|
34
|
-
var external_tty_namespaceObject = __WEBPACK_EXTERNAL_MODULE_tty__;
|
|
35
|
-
// node_modules/.pnpm/supports-color@9.4.0/node_modules/supports-color/index.js
|
|
36
|
-
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : external_process_namespaceObject["default"].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
|
-
var { env } = external_process_namespaceObject["default"];
|
|
43
|
-
var 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 env) {
|
|
48
|
-
if ("true" === env.FORCE_COLOR) return 1;
|
|
49
|
-
if ("false" === env.FORCE_COLOR) return 0;
|
|
50
|
-
return 0 === env.FORCE_COLOR.length ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function translateLevel(level) {
|
|
54
|
-
if (0 === level) return false;
|
|
55
|
-
return {
|
|
56
|
-
level,
|
|
57
|
-
hasBasic: true,
|
|
58
|
-
has256: level >= 2,
|
|
59
|
-
has16m: level >= 3
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
63
|
-
const noFlagForceColor = envForceColor();
|
|
64
|
-
if (void 0 !== noFlagForceColor) flagForceColor = noFlagForceColor;
|
|
65
|
-
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
66
|
-
if (0 === forceColor) return 0;
|
|
67
|
-
if (sniffFlags) {
|
|
68
|
-
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) return 3;
|
|
69
|
-
if (hasFlag("color=256")) return 2;
|
|
70
|
-
}
|
|
71
|
-
if ("TF_BUILD" in env && "AGENT_NAME" in env) return 1;
|
|
72
|
-
if (haveStream && !streamIsTTY && void 0 === forceColor) return 0;
|
|
73
|
-
const min = forceColor || 0;
|
|
74
|
-
if ("dumb" === env.TERM) return min;
|
|
75
|
-
if ("win32" === external_process_namespaceObject["default"].platform) {
|
|
76
|
-
const osRelease = external_os_namespaceObject["default"].release().split(".");
|
|
77
|
-
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
78
|
-
return 1;
|
|
79
|
-
}
|
|
80
|
-
if ("CI" in env) {
|
|
81
|
-
if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) return 3;
|
|
82
|
-
if ([
|
|
83
|
-
"TRAVIS",
|
|
84
|
-
"CIRCLECI",
|
|
85
|
-
"APPVEYOR",
|
|
86
|
-
"GITLAB_CI",
|
|
87
|
-
"BUILDKITE",
|
|
88
|
-
"DRONE"
|
|
89
|
-
].some((sign)=>sign in env) || "codeship" === env.CI_NAME) return 1;
|
|
90
|
-
return min;
|
|
91
|
-
}
|
|
92
|
-
if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
93
|
-
if ("truecolor" === env.COLORTERM) return 3;
|
|
94
|
-
if ("xterm-kitty" === env.TERM) return 3;
|
|
95
|
-
if ("TERM_PROGRAM" in env) {
|
|
96
|
-
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
97
|
-
switch(env.TERM_PROGRAM){
|
|
98
|
-
case "iTerm.app":
|
|
99
|
-
return version >= 3 ? 3 : 2;
|
|
100
|
-
case "Apple_Terminal":
|
|
101
|
-
return 2;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (/-256(color)?$/i.test(env.TERM)) return 2;
|
|
105
|
-
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) return 1;
|
|
106
|
-
if ("COLORTERM" in env) return 1;
|
|
107
|
-
return min;
|
|
108
|
-
}
|
|
109
|
-
function createSupportsColor(stream, options = {}) {
|
|
110
|
-
const level = _supportsColor(stream, {
|
|
111
|
-
streamIsTTY: stream && stream.isTTY,
|
|
112
|
-
...options
|
|
113
|
-
});
|
|
114
|
-
return translateLevel(level);
|
|
115
|
-
}
|
|
116
|
-
var supportsColor = {
|
|
117
|
-
stdout: createSupportsColor({
|
|
118
|
-
isTTY: external_tty_namespaceObject["default"].isatty(1)
|
|
119
|
-
}),
|
|
120
|
-
stderr: createSupportsColor({
|
|
121
|
-
isTTY: external_tty_namespaceObject["default"].isatty(2)
|
|
122
|
-
})
|
|
123
|
-
};
|
|
124
|
-
var supports_color_default = supportsColor;
|
|
125
|
-
// src/utils.ts
|
|
126
|
-
var colorLevel = supports_color_default.stdout ? supports_color_default.stdout.level : 0;
|
|
127
|
-
var errorStackRegExp = /at\s.*:\d+:\d+[\s\)]*$/;
|
|
128
|
-
var anonymousErrorStackRegExp = /at\s.*\(<anonymous>\)$/;
|
|
129
|
-
var isErrorStackMessage = (message)=>errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
|
|
130
|
-
// src/color.ts
|
|
131
|
-
var formatter = (open, close, replace = open)=>colorLevel >= 2 ? (input)=>{
|
|
132
|
-
let string = "" + input;
|
|
133
|
-
let index = string.indexOf(close, open.length);
|
|
134
|
-
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
135
|
-
} : String;
|
|
136
|
-
var replaceClose = (string, close, replace, index)=>{
|
|
137
|
-
let start = string.substring(0, index) + replace;
|
|
138
|
-
let end = string.substring(index + close.length);
|
|
139
|
-
let nextIndex = end.indexOf(close);
|
|
140
|
-
return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
|
|
141
|
-
};
|
|
142
|
-
var bold = formatter("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m");
|
|
143
|
-
var red = formatter("\x1B[31m", "\x1B[39m");
|
|
144
|
-
var green = formatter("\x1B[32m", "\x1B[39m");
|
|
145
|
-
var yellow = formatter("\x1B[33m", "\x1B[39m");
|
|
146
|
-
var magenta = formatter("\x1B[35m", "\x1B[39m");
|
|
147
|
-
var cyan = formatter("\x1B[36m", "\x1B[39m");
|
|
148
|
-
var gray = formatter("\x1B[90m", "\x1B[39m");
|
|
149
|
-
// src/gradient.ts
|
|
150
|
-
var startColor = [
|
|
151
|
-
189,
|
|
152
|
-
255,
|
|
153
|
-
243
|
|
154
|
-
];
|
|
155
|
-
var endColor = [
|
|
156
|
-
74,
|
|
157
|
-
194,
|
|
158
|
-
154
|
|
159
|
-
];
|
|
160
|
-
var isWord = (char)=>!/[\s\n]/.test(char);
|
|
161
|
-
var gradient = (message)=>{
|
|
162
|
-
if (colorLevel < 3) return 2 === colorLevel ? bold(cyan(message)) : message;
|
|
163
|
-
let chars = [
|
|
164
|
-
...message
|
|
165
|
-
];
|
|
166
|
-
let steps = chars.filter(isWord).length;
|
|
167
|
-
let r = startColor[0];
|
|
168
|
-
let g = startColor[1];
|
|
169
|
-
let b = startColor[2];
|
|
170
|
-
let rStep = (endColor[0] - r) / steps;
|
|
171
|
-
let gStep = (endColor[1] - g) / steps;
|
|
172
|
-
let bStep = (endColor[2] - b) / steps;
|
|
173
|
-
let output = "";
|
|
174
|
-
for (let char of chars){
|
|
175
|
-
if (isWord(char)) {
|
|
176
|
-
r += rStep;
|
|
177
|
-
g += gStep;
|
|
178
|
-
b += bStep;
|
|
179
|
-
}
|
|
180
|
-
output += `\x1B[38;2;${Math.round(r)};${Math.round(g)};${Math.round(b)}m${char}\x1B[39m`;
|
|
181
|
-
}
|
|
182
|
-
return bold(output);
|
|
183
|
-
};
|
|
184
|
-
// src/constants.ts
|
|
185
|
-
var LOG_LEVEL = {
|
|
186
|
-
error: 0,
|
|
187
|
-
warn: 1,
|
|
188
|
-
info: 2,
|
|
189
|
-
log: 3,
|
|
190
|
-
verbose: 4
|
|
191
|
-
};
|
|
192
|
-
var LOG_TYPES = {
|
|
193
|
-
// Level error
|
|
194
|
-
error: {
|
|
195
|
-
label: "error",
|
|
196
|
-
level: "error",
|
|
197
|
-
color: red
|
|
198
|
-
},
|
|
199
|
-
// Level warn
|
|
200
|
-
warn: {
|
|
201
|
-
label: "warn",
|
|
202
|
-
level: "warn",
|
|
203
|
-
color: yellow
|
|
204
|
-
},
|
|
205
|
-
// Level info
|
|
206
|
-
info: {
|
|
207
|
-
label: "info",
|
|
208
|
-
level: "info",
|
|
209
|
-
color: cyan
|
|
210
|
-
},
|
|
211
|
-
start: {
|
|
212
|
-
label: "start",
|
|
213
|
-
level: "info",
|
|
214
|
-
color: cyan
|
|
215
|
-
},
|
|
216
|
-
ready: {
|
|
217
|
-
label: "ready",
|
|
218
|
-
level: "info",
|
|
219
|
-
color: green
|
|
220
|
-
},
|
|
221
|
-
success: {
|
|
222
|
-
label: "success",
|
|
223
|
-
level: "info",
|
|
224
|
-
color: green
|
|
225
|
-
},
|
|
226
|
-
// Level log
|
|
227
|
-
log: {
|
|
228
|
-
level: "log"
|
|
229
|
-
},
|
|
230
|
-
// Level debug
|
|
231
|
-
debug: {
|
|
232
|
-
label: "debug",
|
|
233
|
-
level: "verbose",
|
|
234
|
-
color: magenta
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
// src/createLogger.ts
|
|
238
|
-
var createLogger = (options = {})=>{
|
|
239
|
-
let maxLevel = options.level || "log";
|
|
240
|
-
let log = (type, message, ...args)=>{
|
|
241
|
-
if (LOG_LEVEL[LOG_TYPES[type].level] > LOG_LEVEL[maxLevel]) return;
|
|
242
|
-
if (null == message) return console.log();
|
|
243
|
-
let logType = LOG_TYPES[type];
|
|
244
|
-
let label = "";
|
|
245
|
-
let text = "";
|
|
246
|
-
if ("label" in logType) {
|
|
247
|
-
label = (logType.label || "").padEnd(7);
|
|
248
|
-
label = bold(logType.color ? logType.color(label) : label);
|
|
249
|
-
}
|
|
250
|
-
if (message instanceof Error) {
|
|
251
|
-
if (message.stack) {
|
|
252
|
-
let [name, ...rest] = message.stack.split("\n");
|
|
253
|
-
if (name.startsWith("Error: ")) name = name.slice(7);
|
|
254
|
-
text = `${name}
|
|
255
|
-
${gray(rest.join("\n"))}`;
|
|
256
|
-
} else text = message.message;
|
|
257
|
-
} else if ("error" === logType.level && "string" == typeof message) {
|
|
258
|
-
let lines = message.split("\n");
|
|
259
|
-
text = lines.map((line)=>isErrorStackMessage(line) ? gray(line) : line).join("\n");
|
|
260
|
-
} else text = `${message}`;
|
|
261
|
-
console.log(label.length ? `${label} ${text}` : text, ...args);
|
|
262
|
-
};
|
|
263
|
-
let logger2 = {
|
|
264
|
-
greet: (message)=>log("log", gradient(message))
|
|
265
|
-
};
|
|
266
|
-
Object.keys(LOG_TYPES).forEach((key)=>{
|
|
267
|
-
logger2[key] = (...args)=>log(key, ...args);
|
|
268
|
-
});
|
|
269
|
-
Object.defineProperty(logger2, "level", {
|
|
270
|
-
get: ()=>maxLevel,
|
|
271
|
-
set (val) {
|
|
272
|
-
maxLevel = val;
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
logger2.override = (customLogger)=>{
|
|
276
|
-
Object.assign(logger2, customLogger);
|
|
277
|
-
};
|
|
278
|
-
return logger2;
|
|
279
|
-
};
|
|
280
|
-
// src/index.ts
|
|
281
|
-
var dist_logger = createLogger();
|
|
282
|
-
var external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_fs__;
|
|
283
|
-
var promises_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_fs_promises__;
|
|
284
|
-
var external_node_path_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_path__;
|
|
285
|
-
var index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__;
|
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE_module__ from "module";
|
|
286
10
|
/**
|
|
287
11
|
* Node.js built-in modules.
|
|
288
12
|
* Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
|
|
@@ -351,7 +75,7 @@ async function calcLongestCommonPath(absPaths) {
|
|
|
351
75
|
// we support two cases
|
|
352
76
|
// 1. /packages-a/src/index.ts
|
|
353
77
|
// 2. D:/packages-a/src/index.ts
|
|
354
|
-
const sep =
|
|
78
|
+
const sep = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep;
|
|
355
79
|
const splitPaths = absPaths.map((p)=>p.split(sep));
|
|
356
80
|
let lcaFragments = splitPaths[0];
|
|
357
81
|
for(let i = 1; i < splitPaths.length; i++){
|
|
@@ -362,20 +86,20 @@ async function calcLongestCommonPath(absPaths) {
|
|
|
362
86
|
lcaFragments = lcaFragments.slice(0, j);
|
|
363
87
|
}
|
|
364
88
|
let lca = lcaFragments.length > 0 ? lcaFragments.join(sep) : sep;
|
|
365
|
-
const stats = await
|
|
366
|
-
if (stats?.isFile()) lca =
|
|
89
|
+
const stats = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises__["default"].stat(lca);
|
|
90
|
+
if (stats?.isFile()) lca = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(lca);
|
|
367
91
|
return lca;
|
|
368
92
|
}
|
|
369
93
|
const readPackageJson = (rootPath)=>{
|
|
370
|
-
const pkgJsonPath =
|
|
371
|
-
if (!
|
|
372
|
-
|
|
94
|
+
const pkgJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(rootPath, './package.json');
|
|
95
|
+
if (!__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(pkgJsonPath)) {
|
|
96
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`package.json does not exist in the ${rootPath} directory`);
|
|
373
97
|
return;
|
|
374
98
|
}
|
|
375
99
|
try {
|
|
376
|
-
return JSON.parse(
|
|
100
|
+
return JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(pkgJsonPath, 'utf8'));
|
|
377
101
|
} catch (err) {
|
|
378
|
-
|
|
102
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`Failed to parse ${pkgJsonPath}, it might not be valid JSON`);
|
|
379
103
|
return;
|
|
380
104
|
}
|
|
381
105
|
};
|
|
@@ -394,21 +118,25 @@ function omit(obj, keys) {
|
|
|
394
118
|
}, {});
|
|
395
119
|
}
|
|
396
120
|
// setup the logger level
|
|
397
|
-
if (process.env.DEBUG)
|
|
398
|
-
function initNodeEnv() {
|
|
121
|
+
if (process.env.DEBUG) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.level = 'verbose';
|
|
122
|
+
function initNodeEnv() {
|
|
123
|
+
if (!process.env.NODE_ENV) {
|
|
124
|
+
const command = process.argv[2] ?? '';
|
|
125
|
+
process.env.NODE_ENV = [
|
|
126
|
+
'build'
|
|
127
|
+
].includes(command) ? 'production' : 'development';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
399
130
|
function prepareCli() {
|
|
400
131
|
initNodeEnv();
|
|
401
132
|
// Print a blank line to keep the greet log nice.
|
|
402
133
|
// Some package managers automatically output a blank line, some do not.
|
|
403
134
|
const { npm_execpath } = process.env;
|
|
404
135
|
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
|
|
405
|
-
|
|
136
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.0.7\n`);
|
|
406
137
|
}
|
|
407
|
-
var commander_index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__;
|
|
408
|
-
var core_namespaceObject = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__;
|
|
409
|
-
var fast_glob_index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js__;
|
|
410
138
|
const DEFAULT_CONFIG_NAME = 'rslib.config';
|
|
411
|
-
const
|
|
139
|
+
const DEFAULT_CONFIG_EXTENSIONS = [
|
|
412
140
|
'.js',
|
|
413
141
|
'.ts',
|
|
414
142
|
'.mjs',
|
|
@@ -417,6 +145,66 @@ const DEFAULT_EXTENSIONS = [
|
|
|
417
145
|
'.cts'
|
|
418
146
|
];
|
|
419
147
|
const SWC_HELPERS = '@swc/helpers';
|
|
148
|
+
const JS_EXTENSIONS = [
|
|
149
|
+
'js',
|
|
150
|
+
'mjs',
|
|
151
|
+
'jsx',
|
|
152
|
+
'ts',
|
|
153
|
+
'mts',
|
|
154
|
+
'tsx',
|
|
155
|
+
'cjs',
|
|
156
|
+
'cjsx',
|
|
157
|
+
'mjsx',
|
|
158
|
+
'mtsx',
|
|
159
|
+
'cts',
|
|
160
|
+
'ctsx'
|
|
161
|
+
];
|
|
162
|
+
const CSS_EXTENSIONS = [
|
|
163
|
+
'css',
|
|
164
|
+
'sass',
|
|
165
|
+
'scss',
|
|
166
|
+
'less'
|
|
167
|
+
];
|
|
168
|
+
const ENTRY_EXTENSIONS = [
|
|
169
|
+
...JS_EXTENSIONS,
|
|
170
|
+
...CSS_EXTENSIONS
|
|
171
|
+
];
|
|
172
|
+
const JS_EXTENSIONS_PATTERN = new RegExp(`\\.(${JS_EXTENSIONS.join('|')})$`);
|
|
173
|
+
const ENTRY_EXTENSIONS_PATTERN = new RegExp(`\\.(${ENTRY_EXTENSIONS.join('|')})$`);
|
|
174
|
+
const importMetaUrlShim = `var __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
175
|
+
return typeof document === 'undefined'
|
|
176
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
177
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
178
|
+
new URL('main.js', document.baseURI).href;
|
|
179
|
+
})();
|
|
180
|
+
`;
|
|
181
|
+
// This Rsbuild plugin will shim `import.meta.url` for CommonJS modules.
|
|
182
|
+
// - Replace `import.meta.url` with `importMetaUrl`.
|
|
183
|
+
// - Inject `importMetaUrl` to the end of the module (can't inject at the beginning because of `"use strict";`).
|
|
184
|
+
// This is a short-term solution, and we hope to provide built-in polyfills like `node.__filename` on Rspack side.
|
|
185
|
+
const pluginCjsShim = ()=>({
|
|
186
|
+
name: 'rsbuild-plugin-cjs-shim',
|
|
187
|
+
setup (api) {
|
|
188
|
+
api.modifyRsbuildConfig((config)=>{
|
|
189
|
+
config.source ||= {};
|
|
190
|
+
config.source.define = {
|
|
191
|
+
...config.source.define,
|
|
192
|
+
'import.meta.url': '__rslib_import_meta_url__'
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
api.modifyRspackConfig((config)=>{
|
|
196
|
+
config.plugins ??= [];
|
|
197
|
+
config.plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
198
|
+
banner: importMetaUrlShim,
|
|
199
|
+
// Just before minify stage, to perform tree shaking.
|
|
200
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
|
|
201
|
+
raw: true,
|
|
202
|
+
footer: true,
|
|
203
|
+
include: /\.(js|cjs)$/
|
|
204
|
+
}));
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
420
208
|
const getDefaultExtension = (options)=>{
|
|
421
209
|
const { format, pkgJson, autoExtension } = options;
|
|
422
210
|
let jsExtension = '.js';
|
|
@@ -426,7 +214,7 @@ const getDefaultExtension = (options)=>{
|
|
|
426
214
|
dtsExtension
|
|
427
215
|
};
|
|
428
216
|
if (!pkgJson) {
|
|
429
|
-
|
|
217
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn('autoExtension configuration will not be applied due to read package.json failed');
|
|
430
218
|
return {
|
|
431
219
|
jsExtension,
|
|
432
220
|
dtsExtension
|
|
@@ -447,6 +235,30 @@ const getDefaultExtension = (options)=>{
|
|
|
447
235
|
isModule
|
|
448
236
|
};
|
|
449
237
|
};
|
|
238
|
+
const LATEST_TARGET_VERSIONS = {
|
|
239
|
+
node: [
|
|
240
|
+
'last 1 node versions'
|
|
241
|
+
],
|
|
242
|
+
web: [
|
|
243
|
+
'last 1 Chrome versions',
|
|
244
|
+
'last 1 Firefox versions',
|
|
245
|
+
'last 1 Edge versions',
|
|
246
|
+
'last 1 Safari versions',
|
|
247
|
+
'last 1 ios_saf versions',
|
|
248
|
+
'not dead'
|
|
249
|
+
],
|
|
250
|
+
get 'web-worker' () {
|
|
251
|
+
return LATEST_TARGET_VERSIONS.web;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
const calcEsnextBrowserslistByTarget = (target)=>{
|
|
255
|
+
if (!target) return [
|
|
256
|
+
...LATEST_TARGET_VERSIONS.node,
|
|
257
|
+
...LATEST_TARGET_VERSIONS.web
|
|
258
|
+
];
|
|
259
|
+
if ('node' === target) return LATEST_TARGET_VERSIONS.node;
|
|
260
|
+
return LATEST_TARGET_VERSIONS.web;
|
|
261
|
+
};
|
|
450
262
|
/**
|
|
451
263
|
* The esX to browserslist mapping is transformed from esbuild:
|
|
452
264
|
* https://github.com/evanw/esbuild/blob/main/internal/compat/js_table.go
|
|
@@ -551,8 +363,8 @@ const getDefaultExtension = (options)=>{
|
|
|
551
363
|
Opera: '62.0.0',
|
|
552
364
|
Safari: '13.1.0'
|
|
553
365
|
},
|
|
554
|
-
es2024:
|
|
555
|
-
esnext:
|
|
366
|
+
es2024: calcEsnextBrowserslistByTarget,
|
|
367
|
+
esnext: calcEsnextBrowserslistByTarget,
|
|
556
368
|
es5: {
|
|
557
369
|
Chrome: '5.0.0',
|
|
558
370
|
Edge: '12.0.0',
|
|
@@ -564,13 +376,18 @@ const getDefaultExtension = (options)=>{
|
|
|
564
376
|
Safari: '3.1.0'
|
|
565
377
|
}
|
|
566
378
|
};
|
|
567
|
-
|
|
379
|
+
function transformSyntaxToBrowserslist(syntax, target) {
|
|
568
380
|
const handleSyntaxItem = (syntaxItem)=>{
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
381
|
+
const normalizedSyntaxItem = syntaxItem.toLowerCase();
|
|
382
|
+
if (normalizedSyntaxItem.startsWith('es')) {
|
|
383
|
+
if (normalizedSyntaxItem in ESX_TO_BROWSERSLIST) {
|
|
384
|
+
const browserslistItem = ESX_TO_BROWSERSLIST[normalizedSyntaxItem];
|
|
385
|
+
if ('function' == typeof browserslistItem) return browserslistItem(target);
|
|
386
|
+
return Object.entries(browserslistItem).flatMap(([engine, version])=>{
|
|
387
|
+
if (Array.isArray(version)) return version;
|
|
388
|
+
return `${engine} >= ${version}`;
|
|
389
|
+
});
|
|
390
|
+
}
|
|
574
391
|
throw new Error(`Unsupported ES version: ${syntaxItem}`);
|
|
575
392
|
}
|
|
576
393
|
return [
|
|
@@ -579,28 +396,741 @@ const transformSyntaxToBrowserslist = (syntax)=>{
|
|
|
579
396
|
};
|
|
580
397
|
if (Array.isArray(syntax)) return syntax.flatMap(handleSyntaxItem);
|
|
581
398
|
return handleSyntaxItem(syntax);
|
|
399
|
+
}
|
|
400
|
+
const POSIX_SEP_RE = new RegExp('\\' + __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep, 'g');
|
|
401
|
+
const NATIVE_SEP_RE = new RegExp('\\' + __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep, 'g');
|
|
402
|
+
/** @type {Map<string,RegExp>}*/ const PATTERN_REGEX_CACHE = new Map();
|
|
403
|
+
const GLOB_ALL_PATTERN = "**/*";
|
|
404
|
+
const TS_EXTENSIONS = [
|
|
405
|
+
'.ts',
|
|
406
|
+
'.tsx',
|
|
407
|
+
'.mts',
|
|
408
|
+
'.cts'
|
|
409
|
+
];
|
|
410
|
+
const util_JS_EXTENSIONS = [
|
|
411
|
+
'.js',
|
|
412
|
+
'.jsx',
|
|
413
|
+
'.mjs',
|
|
414
|
+
'.cjs'
|
|
415
|
+
];
|
|
416
|
+
const TSJS_EXTENSIONS = TS_EXTENSIONS.concat(util_JS_EXTENSIONS);
|
|
417
|
+
const TS_EXTENSIONS_RE_GROUP = `\\.(?:${TS_EXTENSIONS.map((ext)=>ext.substring(1)).join('|')})`;
|
|
418
|
+
const TSJS_EXTENSIONS_RE_GROUP = `\\.(?:${TSJS_EXTENSIONS.map((ext)=>ext.substring(1)).join('|')})`;
|
|
419
|
+
const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep === __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep;
|
|
420
|
+
/**
|
|
421
|
+
* @template T
|
|
422
|
+
* @returns {{resolve:(result:T)=>void, reject:(error:any)=>void, promise: Promise<T>}}
|
|
423
|
+
*/ function util_makePromise() {
|
|
424
|
+
let resolve, reject;
|
|
425
|
+
const promise = new Promise((res, rej)=>{
|
|
426
|
+
resolve = res;
|
|
427
|
+
reject = rej;
|
|
428
|
+
});
|
|
429
|
+
return {
|
|
430
|
+
promise,
|
|
431
|
+
resolve,
|
|
432
|
+
reject
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* @param {string} filename
|
|
437
|
+
* @param {import('./cache.js').TSConfckCache} [cache]
|
|
438
|
+
* @returns {Promise<string|void>}
|
|
439
|
+
*/ async function util_resolveTSConfigJson(filename, cache) {
|
|
440
|
+
if ('.json' !== __WEBPACK_EXTERNAL_MODULE_node_path__["default"].extname(filename)) return; // ignore files that are not json
|
|
441
|
+
const tsconfig = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename);
|
|
442
|
+
if (cache && (cache.hasParseResult(tsconfig) || cache.hasParseResult(filename))) return tsconfig;
|
|
443
|
+
return __WEBPACK_EXTERNAL_MODULE_node_fs__.promises.stat(tsconfig).then((stat)=>{
|
|
444
|
+
if (stat.isFile() || stat.isFIFO()) return tsconfig;
|
|
445
|
+
throw new Error(`${filename} exists but is not a regular file.`);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
*
|
|
450
|
+
* @param {string} dir an absolute directory path
|
|
451
|
+
* @returns {boolean} if dir path includes a node_modules segment
|
|
452
|
+
*/ const util_isInNodeModules = IS_POSIX ? (dir)=>dir.includes('/node_modules/') : (dir)=>dir.match(/[/\\]node_modules[/\\]/);
|
|
453
|
+
/**
|
|
454
|
+
* convert posix separator to native separator
|
|
455
|
+
*
|
|
456
|
+
* eg.
|
|
457
|
+
* windows: C:/foo/bar -> c:\foo\bar
|
|
458
|
+
* linux: /foo/bar -> /foo/bar
|
|
459
|
+
*
|
|
460
|
+
* @param {string} filename with posix separators
|
|
461
|
+
* @returns {string} filename with native separators
|
|
462
|
+
*/ const posix2native = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(POSIX_SEP_RE, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep);
|
|
463
|
+
/**
|
|
464
|
+
* convert native separator to posix separator
|
|
465
|
+
*
|
|
466
|
+
* eg.
|
|
467
|
+
* windows: C:\foo\bar -> c:/foo/bar
|
|
468
|
+
* linux: /foo/bar -> /foo/bar
|
|
469
|
+
*
|
|
470
|
+
* @param {string} filename - filename with native separators
|
|
471
|
+
* @returns {string} filename with posix separators
|
|
472
|
+
*/ const util_native2posix = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(NATIVE_SEP_RE, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep);
|
|
473
|
+
/**
|
|
474
|
+
* converts params to native separator, resolves path and converts native back to posix
|
|
475
|
+
*
|
|
476
|
+
* needed on windows to handle posix paths in tsconfig
|
|
477
|
+
*
|
|
478
|
+
* @param dir {string|null} directory to resolve from
|
|
479
|
+
* @param filename {string} filename or pattern to resolve
|
|
480
|
+
* @returns string
|
|
481
|
+
*/ const resolve2posix = IS_POSIX ? (dir, filename)=>dir ? __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(dir, filename) : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename) : (dir, filename)=>util_native2posix(dir ? __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(posix2native(dir), posix2native(filename)) : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(posix2native(filename)));
|
|
482
|
+
/**
|
|
483
|
+
*
|
|
484
|
+
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
485
|
+
* @param {import('./public.d.ts').TSConfckParseOptions} [options]
|
|
486
|
+
* @returns {string[]}
|
|
487
|
+
*/ function util_resolveReferencedTSConfigFiles(result, options) {
|
|
488
|
+
const dir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(result.tsconfigFile);
|
|
489
|
+
return result.tsconfig.references.map((ref)=>{
|
|
490
|
+
const refPath = ref.path.endsWith('.json') ? ref.path : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(ref.path, options?.configName ?? 'tsconfig.json');
|
|
491
|
+
return resolve2posix(dir, refPath);
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* @param {string} filename
|
|
496
|
+
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
497
|
+
* @returns {import('./public.d.ts').TSConfckParseResult}
|
|
498
|
+
*/ function util_resolveSolutionTSConfig(filename, result) {
|
|
499
|
+
const allowJs = result.tsconfig.compilerOptions?.allowJs;
|
|
500
|
+
const extensions = allowJs ? TSJS_EXTENSIONS : TS_EXTENSIONS;
|
|
501
|
+
if (result.referenced && extensions.some((ext)=>filename.endsWith(ext)) && !util_isIncluded(filename, result)) {
|
|
502
|
+
const solutionTSConfig = result.referenced.find((referenced)=>util_isIncluded(filename, referenced));
|
|
503
|
+
if (solutionTSConfig) return solutionTSConfig;
|
|
504
|
+
}
|
|
505
|
+
return result;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
*
|
|
509
|
+
* @param {string} filename
|
|
510
|
+
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
511
|
+
* @returns {boolean}
|
|
512
|
+
*/ function util_isIncluded(filename, result) {
|
|
513
|
+
const dir = util_native2posix(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(result.tsconfigFile));
|
|
514
|
+
const files = (result.tsconfig.files || []).map((file)=>resolve2posix(dir, file));
|
|
515
|
+
const absoluteFilename = resolve2posix(null, filename);
|
|
516
|
+
if (files.includes(filename)) return true;
|
|
517
|
+
const allowJs = result.tsconfig.compilerOptions?.allowJs;
|
|
518
|
+
const isIncluded = isGlobMatch(absoluteFilename, dir, result.tsconfig.include || (result.tsconfig.files ? [] : [
|
|
519
|
+
GLOB_ALL_PATTERN
|
|
520
|
+
]), allowJs);
|
|
521
|
+
if (isIncluded) {
|
|
522
|
+
const isExcluded = isGlobMatch(absoluteFilename, dir, result.tsconfig.exclude || [], allowJs);
|
|
523
|
+
return !isExcluded;
|
|
524
|
+
}
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* test filenames agains glob patterns in tsconfig
|
|
529
|
+
*
|
|
530
|
+
* @param filename {string} posix style abolute path to filename to test
|
|
531
|
+
* @param dir {string} posix style absolute path to directory of tsconfig containing patterns
|
|
532
|
+
* @param patterns {string[]} glob patterns to match against
|
|
533
|
+
* @param allowJs {boolean} allowJs setting in tsconfig to include js extensions in checks
|
|
534
|
+
* @returns {boolean} true when at least one pattern matches filename
|
|
535
|
+
*/ function isGlobMatch(filename, dir, patterns, allowJs) {
|
|
536
|
+
const extensions = allowJs ? TSJS_EXTENSIONS : TS_EXTENSIONS;
|
|
537
|
+
return patterns.some((pattern)=>{
|
|
538
|
+
// filename must end with part of pattern that comes after last wildcard
|
|
539
|
+
let lastWildcardIndex = pattern.length;
|
|
540
|
+
let hasWildcard = false;
|
|
541
|
+
for(let i = pattern.length - 1; i > -1; i--)if ('*' === pattern[i] || '?' === pattern[i]) {
|
|
542
|
+
lastWildcardIndex = i;
|
|
543
|
+
hasWildcard = true;
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
546
|
+
// if pattern does not end with wildcard, filename must end with pattern after last wildcard
|
|
547
|
+
if (lastWildcardIndex < pattern.length - 1 && !filename.endsWith(pattern.slice(lastWildcardIndex + 1))) return false;
|
|
548
|
+
// if pattern ends with *, filename must end with a default extension
|
|
549
|
+
if (pattern.endsWith('*') && !extensions.some((ext)=>filename.endsWith(ext))) return false;
|
|
550
|
+
// for **/* , filename must start with the dir
|
|
551
|
+
if (pattern === GLOB_ALL_PATTERN) return filename.startsWith(`${dir}/`);
|
|
552
|
+
const resolvedPattern = resolve2posix(dir, pattern);
|
|
553
|
+
// filename must start with part of pattern that comes before first wildcard
|
|
554
|
+
let firstWildcardIndex = -1;
|
|
555
|
+
for(let i = 0; i < resolvedPattern.length; i++)if ('*' === resolvedPattern[i] || '?' === resolvedPattern[i]) {
|
|
556
|
+
firstWildcardIndex = i;
|
|
557
|
+
hasWildcard = true;
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
if (firstWildcardIndex > 1 && !filename.startsWith(resolvedPattern.slice(0, firstWildcardIndex - 1))) return false;
|
|
561
|
+
// if no wildcard in pattern, filename must be equal to resolved pattern
|
|
562
|
+
if (!hasWildcard) return filename === resolvedPattern;
|
|
563
|
+
// complex pattern, use regex to check it
|
|
564
|
+
if (PATTERN_REGEX_CACHE.has(resolvedPattern)) return PATTERN_REGEX_CACHE.get(resolvedPattern).test(filename);
|
|
565
|
+
const regex = pattern2regex(resolvedPattern, allowJs);
|
|
566
|
+
PATTERN_REGEX_CACHE.set(resolvedPattern, regex);
|
|
567
|
+
return regex.test(filename);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* @param {string} resolvedPattern
|
|
572
|
+
* @param {boolean} allowJs
|
|
573
|
+
* @returns {RegExp}
|
|
574
|
+
*/ function pattern2regex(resolvedPattern, allowJs) {
|
|
575
|
+
let regexStr = '^';
|
|
576
|
+
for(let i = 0; i < resolvedPattern.length; i++){
|
|
577
|
+
const char = resolvedPattern[i];
|
|
578
|
+
if ('?' === char) {
|
|
579
|
+
regexStr += '[^\\/]';
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
if ('*' === char) {
|
|
583
|
+
if ('*' === resolvedPattern[i + 1] && '/' === resolvedPattern[i + 2]) {
|
|
584
|
+
i += 2;
|
|
585
|
+
regexStr += '(?:[^\\/]*\\/)*'; // zero or more path segments
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
regexStr += '[^\\/]*';
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
if ('/.+^${}()|[]\\'.includes(char)) regexStr += "\\";
|
|
592
|
+
regexStr += char;
|
|
593
|
+
}
|
|
594
|
+
// add known file endings if pattern ends on *
|
|
595
|
+
if (resolvedPattern.endsWith('*')) regexStr += allowJs ? TSJS_EXTENSIONS_RE_GROUP : TS_EXTENSIONS_RE_GROUP;
|
|
596
|
+
regexStr += '$';
|
|
597
|
+
return new RegExp(regexStr);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* replace tokens like ${configDir}
|
|
601
|
+
* @param {any} tsconfig
|
|
602
|
+
* @param {string} configDir
|
|
603
|
+
* @returns {any}
|
|
604
|
+
*/ function util_replaceTokens(tsconfig, configDir) {
|
|
605
|
+
return JSON.parse(JSON.stringify(tsconfig)// replace ${configDir}
|
|
606
|
+
.replaceAll(/"\${configDir}/g, `"${util_native2posix(configDir)}`));
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* find the closest tsconfig.json file
|
|
610
|
+
*
|
|
611
|
+
* @param {string} filename - path to file to find tsconfig for (absolute or relative to cwd)
|
|
612
|
+
* @param {import('./public.d.ts').TSConfckFindOptions} [options] - options
|
|
613
|
+
* @returns {Promise<string|null>} absolute path to closest tsconfig.json or null if not found
|
|
614
|
+
*/ async function find(filename, options) {
|
|
615
|
+
let dir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename));
|
|
616
|
+
if (options?.ignoreNodeModules && util_isInNodeModules(dir)) return null;
|
|
617
|
+
const cache = options?.cache;
|
|
618
|
+
const configName = options?.configName ?? 'tsconfig.json';
|
|
619
|
+
if (cache?.hasConfigPath(dir, configName)) return cache.getConfigPath(dir, configName);
|
|
620
|
+
const { promise, resolve, reject } = util_makePromise();
|
|
621
|
+
if (options?.root && !__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(options.root)) options.root = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(options.root);
|
|
622
|
+
findUp(dir, {
|
|
623
|
+
promise,
|
|
624
|
+
resolve,
|
|
625
|
+
reject
|
|
626
|
+
}, options);
|
|
627
|
+
return promise;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
*
|
|
631
|
+
* @param {string} dir
|
|
632
|
+
* @param {{promise:Promise<string|null>,resolve:(result:string|null)=>void,reject:(err:any)=>void}} madePromise
|
|
633
|
+
* @param {import('./public.d.ts').TSConfckFindOptions} [options] - options
|
|
634
|
+
*/ function findUp(dir, { resolve, reject, promise }, options) {
|
|
635
|
+
const { cache, root, configName } = options ?? {};
|
|
636
|
+
if (cache) {
|
|
637
|
+
if (cache.hasConfigPath(dir, configName)) {
|
|
638
|
+
let cached;
|
|
639
|
+
try {
|
|
640
|
+
cached = cache.getConfigPath(dir, configName);
|
|
641
|
+
} catch (e) {
|
|
642
|
+
reject(e);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
if (cached?.then) cached.then(resolve).catch(reject);
|
|
646
|
+
else resolve(cached);
|
|
647
|
+
} else cache.setConfigPath(dir, promise, configName);
|
|
648
|
+
}
|
|
649
|
+
const tsconfig = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(dir, options?.configName ?? 'tsconfig.json');
|
|
650
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].stat(tsconfig, (err, stats)=>{
|
|
651
|
+
if (stats && (stats.isFile() || stats.isFIFO())) resolve(tsconfig);
|
|
652
|
+
else if (err?.code !== 'ENOENT') reject(err);
|
|
653
|
+
else {
|
|
654
|
+
let parent;
|
|
655
|
+
if (root === dir || (parent = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(dir)) === dir) resolve(null);
|
|
656
|
+
else findUp(parent, {
|
|
657
|
+
promise,
|
|
658
|
+
resolve,
|
|
659
|
+
reject
|
|
660
|
+
}, options);
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* @typedef WalkState
|
|
666
|
+
* @interface
|
|
667
|
+
* @property {string[]} files - files
|
|
668
|
+
* @property {number} calls - number of ongoing calls
|
|
669
|
+
* @property {(dir: string)=>boolean} skip - function to skip dirs
|
|
670
|
+
* @property {boolean} err - error flag
|
|
671
|
+
* @property {string[]} configNames - config file names
|
|
672
|
+
*/ __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep;
|
|
673
|
+
/*
|
|
674
|
+
this file contains code from strip-bom and strip-json-comments by Sindre Sorhus
|
|
675
|
+
https://github.com/sindresorhus/strip-json-comments/blob/v4.0.0/index.js
|
|
676
|
+
https://github.com/sindresorhus/strip-bom/blob/v5.0.0/index.js
|
|
677
|
+
licensed under MIT, see ../LICENSE
|
|
678
|
+
*/ /**
|
|
679
|
+
* convert content of tsconfig.json to regular json
|
|
680
|
+
*
|
|
681
|
+
* @param {string} tsconfigJson - content of tsconfig.json
|
|
682
|
+
* @returns {string} content as regular json, comments and dangling commas have been replaced with whitespace
|
|
683
|
+
*/ function toJson(tsconfigJson) {
|
|
684
|
+
const stripped = stripDanglingComma(stripJsonComments(stripBom(tsconfigJson)));
|
|
685
|
+
if ('' === stripped.trim()) // only whitespace left after stripping, return empty object so that JSON.parse still works
|
|
686
|
+
return '{}';
|
|
687
|
+
return stripped;
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* replace dangling commas from pseudo-json string with single space
|
|
691
|
+
* implementation heavily inspired by strip-json-comments
|
|
692
|
+
*
|
|
693
|
+
* @param {string} pseudoJson
|
|
694
|
+
* @returns {string}
|
|
695
|
+
*/ function stripDanglingComma(pseudoJson) {
|
|
696
|
+
let insideString = false;
|
|
697
|
+
let offset = 0;
|
|
698
|
+
let result = '';
|
|
699
|
+
let danglingCommaPos = null;
|
|
700
|
+
for(let i = 0; i < pseudoJson.length; i++){
|
|
701
|
+
const currentCharacter = pseudoJson[i];
|
|
702
|
+
if ('"' === currentCharacter) {
|
|
703
|
+
const escaped = isEscaped(pseudoJson, i);
|
|
704
|
+
if (!escaped) insideString = !insideString;
|
|
705
|
+
}
|
|
706
|
+
if (insideString) {
|
|
707
|
+
danglingCommaPos = null;
|
|
708
|
+
continue;
|
|
709
|
+
}
|
|
710
|
+
if (',' === currentCharacter) {
|
|
711
|
+
danglingCommaPos = i;
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
if (danglingCommaPos) {
|
|
715
|
+
if ('}' === currentCharacter || ']' === currentCharacter) {
|
|
716
|
+
result += pseudoJson.slice(offset, danglingCommaPos) + ' ';
|
|
717
|
+
offset = danglingCommaPos + 1;
|
|
718
|
+
danglingCommaPos = null;
|
|
719
|
+
} else if (!currentCharacter.match(/\s/)) danglingCommaPos = null;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return result + pseudoJson.substring(offset);
|
|
723
|
+
}
|
|
724
|
+
// start strip-json-comments
|
|
725
|
+
/**
|
|
726
|
+
*
|
|
727
|
+
* @param {string} jsonString
|
|
728
|
+
* @param {number} quotePosition
|
|
729
|
+
* @returns {boolean}
|
|
730
|
+
*/ function isEscaped(jsonString, quotePosition) {
|
|
731
|
+
let index = quotePosition - 1;
|
|
732
|
+
let backslashCount = 0;
|
|
733
|
+
while('\\' === jsonString[index]){
|
|
734
|
+
index -= 1;
|
|
735
|
+
backslashCount += 1;
|
|
736
|
+
}
|
|
737
|
+
return Boolean(backslashCount % 2);
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
*
|
|
741
|
+
* @param {string} string
|
|
742
|
+
* @param {number?} start
|
|
743
|
+
* @param {number?} end
|
|
744
|
+
*/ function strip(string, start, end) {
|
|
745
|
+
return string.slice(start, end).replace(/\S/g, ' ');
|
|
746
|
+
}
|
|
747
|
+
const singleComment = Symbol('singleComment');
|
|
748
|
+
const multiComment = Symbol('multiComment');
|
|
749
|
+
/**
|
|
750
|
+
* @param {string} jsonString
|
|
751
|
+
* @returns {string}
|
|
752
|
+
*/ function stripJsonComments(jsonString) {
|
|
753
|
+
let isInsideString = false;
|
|
754
|
+
/** @type {false | symbol} */ let isInsideComment = false;
|
|
755
|
+
let offset = 0;
|
|
756
|
+
let result = '';
|
|
757
|
+
for(let index = 0; index < jsonString.length; index++){
|
|
758
|
+
const currentCharacter = jsonString[index];
|
|
759
|
+
const nextCharacter = jsonString[index + 1];
|
|
760
|
+
if (!isInsideComment && '"' === currentCharacter) {
|
|
761
|
+
const escaped = isEscaped(jsonString, index);
|
|
762
|
+
if (!escaped) isInsideString = !isInsideString;
|
|
763
|
+
}
|
|
764
|
+
if (!isInsideString) if (isInsideComment || currentCharacter + nextCharacter !== '//') {
|
|
765
|
+
if (isInsideComment === singleComment && currentCharacter + nextCharacter === '\r\n') {
|
|
766
|
+
index++;
|
|
767
|
+
isInsideComment = false;
|
|
768
|
+
result += strip(jsonString, offset, index);
|
|
769
|
+
offset = index;
|
|
770
|
+
} else if (isInsideComment === singleComment && '\n' === currentCharacter) {
|
|
771
|
+
isInsideComment = false;
|
|
772
|
+
result += strip(jsonString, offset, index);
|
|
773
|
+
offset = index;
|
|
774
|
+
} else if (isInsideComment || currentCharacter + nextCharacter !== '/*') {
|
|
775
|
+
if (isInsideComment === multiComment && currentCharacter + nextCharacter === '*/') {
|
|
776
|
+
index++;
|
|
777
|
+
isInsideComment = false;
|
|
778
|
+
result += strip(jsonString, offset, index + 1);
|
|
779
|
+
offset = index + 1;
|
|
780
|
+
}
|
|
781
|
+
} else {
|
|
782
|
+
result += jsonString.slice(offset, index);
|
|
783
|
+
offset = index;
|
|
784
|
+
isInsideComment = multiComment;
|
|
785
|
+
index++;
|
|
786
|
+
}
|
|
787
|
+
} else {
|
|
788
|
+
result += jsonString.slice(offset, index);
|
|
789
|
+
offset = index;
|
|
790
|
+
isInsideComment = singleComment;
|
|
791
|
+
index++;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return result + (isInsideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
|
|
795
|
+
}
|
|
796
|
+
// end strip-json-comments
|
|
797
|
+
// start strip-bom
|
|
798
|
+
/**
|
|
799
|
+
* @param {string} string
|
|
800
|
+
* @returns {string}
|
|
801
|
+
*/ function stripBom(string) {
|
|
802
|
+
// Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
|
|
803
|
+
// conversion translates it to FEFF (UTF-16 BOM).
|
|
804
|
+
if (0xfeff === string.charCodeAt(0)) return string.slice(1);
|
|
805
|
+
return string;
|
|
806
|
+
}
|
|
807
|
+
const not_found_result = {
|
|
808
|
+
tsconfigFile: null,
|
|
809
|
+
tsconfig: {}
|
|
810
|
+
};
|
|
811
|
+
/**
|
|
812
|
+
* parse the closest tsconfig.json file
|
|
813
|
+
*
|
|
814
|
+
* @param {string} filename - path to a tsconfig .json or a source file or directory (absolute or relative to cwd)
|
|
815
|
+
* @param {import('./public.d.ts').TSConfckParseOptions} [options] - options
|
|
816
|
+
* @returns {Promise<import('./public.d.ts').TSConfckParseResult>}
|
|
817
|
+
* @throws {TSConfckParseError}
|
|
818
|
+
*/ async function parse(filename, options) {
|
|
819
|
+
/** @type {import('./cache.js').TSConfckCache} */ const cache = options?.cache;
|
|
820
|
+
if (cache?.hasParseResult(filename)) return getParsedDeep(filename, cache, options);
|
|
821
|
+
const { resolve, reject, /** @type {Promise<import('./public.d.ts').TSConfckParseResult>}*/ promise } = util_makePromise();
|
|
822
|
+
cache?.setParseResult(filename, promise, true);
|
|
823
|
+
try {
|
|
824
|
+
let tsconfigFile = await util_resolveTSConfigJson(filename, cache) || await find(filename, options);
|
|
825
|
+
if (!tsconfigFile) {
|
|
826
|
+
resolve(not_found_result);
|
|
827
|
+
return promise;
|
|
828
|
+
}
|
|
829
|
+
let result;
|
|
830
|
+
if (filename !== tsconfigFile && cache?.hasParseResult(tsconfigFile)) result = await getParsedDeep(tsconfigFile, cache, options);
|
|
831
|
+
else {
|
|
832
|
+
result = await parseFile(tsconfigFile, cache, filename === tsconfigFile);
|
|
833
|
+
await Promise.all([
|
|
834
|
+
parseExtends(result, cache),
|
|
835
|
+
parseReferences(result, options)
|
|
836
|
+
]);
|
|
837
|
+
}
|
|
838
|
+
result.tsconfig = util_replaceTokens(result.tsconfig, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(tsconfigFile));
|
|
839
|
+
resolve(util_resolveSolutionTSConfig(filename, result));
|
|
840
|
+
} catch (e) {
|
|
841
|
+
reject(e);
|
|
842
|
+
}
|
|
843
|
+
return promise;
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* ensure extends and references are parsed
|
|
847
|
+
*
|
|
848
|
+
* @param {string} filename - cached file
|
|
849
|
+
* @param {import('./cache.js').TSConfckCache} cache - cache
|
|
850
|
+
* @param {import('./public.d.ts').TSConfckParseOptions} options - options
|
|
851
|
+
*/ async function getParsedDeep(filename, cache, options) {
|
|
852
|
+
const result = await cache.getParseResult(filename);
|
|
853
|
+
if (result.tsconfig.extends && !result.extended || result.tsconfig.references && !result.referenced) {
|
|
854
|
+
const promise = Promise.all([
|
|
855
|
+
parseExtends(result, cache),
|
|
856
|
+
parseReferences(result, options)
|
|
857
|
+
]).then(()=>result);
|
|
858
|
+
cache.setParseResult(filename, promise, true);
|
|
859
|
+
return promise;
|
|
860
|
+
}
|
|
861
|
+
return result;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
*
|
|
865
|
+
* @param {string} tsconfigFile - path to tsconfig file
|
|
866
|
+
* @param {import('./cache.js').TSConfckCache} [cache] - cache
|
|
867
|
+
* @param {boolean} [skipCache] - skip cache
|
|
868
|
+
* @returns {Promise<import('./public.d.ts').TSConfckParseResult>}
|
|
869
|
+
*/ async function parseFile(tsconfigFile, cache, skipCache) {
|
|
870
|
+
if (!skipCache && cache?.hasParseResult(tsconfigFile) && !cache.getParseResult(tsconfigFile)._isRootFile_) return cache.getParseResult(tsconfigFile);
|
|
871
|
+
const promise = __WEBPACK_EXTERNAL_MODULE_node_fs__.promises.readFile(tsconfigFile, 'utf-8').then(toJson).then((json)=>{
|
|
872
|
+
const parsed = JSON.parse(json);
|
|
873
|
+
applyDefaults(parsed, tsconfigFile);
|
|
874
|
+
return {
|
|
875
|
+
tsconfigFile,
|
|
876
|
+
tsconfig: normalizeTSConfig(parsed, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(tsconfigFile))
|
|
877
|
+
};
|
|
878
|
+
}).catch((e)=>{
|
|
879
|
+
throw new TSConfckParseError(`parsing ${tsconfigFile} failed: ${e}`, 'PARSE_FILE', tsconfigFile, e);
|
|
880
|
+
});
|
|
881
|
+
if (!skipCache && (!cache?.hasParseResult(tsconfigFile) || !cache.getParseResult(tsconfigFile)._isRootFile_)) cache?.setParseResult(tsconfigFile, promise);
|
|
882
|
+
return promise;
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* normalize to match the output of ts.parseJsonConfigFileContent
|
|
886
|
+
*
|
|
887
|
+
* @param {any} tsconfig - typescript tsconfig output
|
|
888
|
+
* @param {string} dir - directory
|
|
889
|
+
*/ function normalizeTSConfig(tsconfig, dir) {
|
|
890
|
+
// set baseUrl to absolute path
|
|
891
|
+
const baseUrl = tsconfig.compilerOptions?.baseUrl;
|
|
892
|
+
if (baseUrl && !baseUrl.startsWith('${') && !__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(baseUrl)) tsconfig.compilerOptions.baseUrl = resolve2posix(dir, baseUrl);
|
|
893
|
+
return tsconfig;
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
*
|
|
897
|
+
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
898
|
+
* @param {import('./public.d.ts').TSConfckParseOptions} [options]
|
|
899
|
+
* @returns {Promise<void>}
|
|
900
|
+
*/ async function parseReferences(result, options) {
|
|
901
|
+
if (!result.tsconfig.references) return;
|
|
902
|
+
const referencedFiles = util_resolveReferencedTSConfigFiles(result, options);
|
|
903
|
+
const referenced = await Promise.all(referencedFiles.map((file)=>parseFile(file, options?.cache)));
|
|
904
|
+
await Promise.all(referenced.map((ref)=>parseExtends(ref, options?.cache)));
|
|
905
|
+
referenced.forEach((ref)=>{
|
|
906
|
+
ref.solution = result;
|
|
907
|
+
});
|
|
908
|
+
result.referenced = referenced;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
912
|
+
* @param {import('./cache.js').TSConfckCache}[cache]
|
|
913
|
+
* @returns {Promise<void>}
|
|
914
|
+
*/ async function parseExtends(result, cache) {
|
|
915
|
+
if (!result.tsconfig.extends) return;
|
|
916
|
+
// use result as first element in extended
|
|
917
|
+
// but dereference tsconfig so that mergeExtended can modify the original without affecting extended[0]
|
|
918
|
+
/** @type {import('./public.d.ts').TSConfckParseResult[]} */ const extended = [
|
|
919
|
+
{
|
|
920
|
+
tsconfigFile: result.tsconfigFile,
|
|
921
|
+
tsconfig: JSON.parse(JSON.stringify(result.tsconfig))
|
|
922
|
+
}
|
|
923
|
+
];
|
|
924
|
+
// flatten extends graph into extended
|
|
925
|
+
let pos = 0;
|
|
926
|
+
/** @type {string[]} */ const extendsPath = [];
|
|
927
|
+
let currentBranchDepth = 0;
|
|
928
|
+
while(pos < extended.length){
|
|
929
|
+
const extending = extended[pos];
|
|
930
|
+
extendsPath.push(extending.tsconfigFile);
|
|
931
|
+
if (extending.tsconfig.extends) {
|
|
932
|
+
// keep following this branch
|
|
933
|
+
currentBranchDepth += 1;
|
|
934
|
+
/** @type {string[]} */ let resolvedExtends;
|
|
935
|
+
// reverse because typescript 5.0 treats ['a','b','c'] as c extends b extends a
|
|
936
|
+
resolvedExtends = Array.isArray(extending.tsconfig.extends) ? extending.tsconfig.extends.reverse().map((ex)=>resolveExtends(ex, extending.tsconfigFile)) : [
|
|
937
|
+
resolveExtends(extending.tsconfig.extends, extending.tsconfigFile)
|
|
938
|
+
];
|
|
939
|
+
const circularExtends = resolvedExtends.find((tsconfigFile)=>extendsPath.includes(tsconfigFile));
|
|
940
|
+
if (circularExtends) {
|
|
941
|
+
const circle = extendsPath.concat([
|
|
942
|
+
circularExtends
|
|
943
|
+
]).join(' -> ');
|
|
944
|
+
throw new TSConfckParseError(`Circular dependency in "extends": ${circle}`, 'EXTENDS_CIRCULAR', result.tsconfigFile);
|
|
945
|
+
}
|
|
946
|
+
// add new extends to the list directly after current
|
|
947
|
+
extended.splice(pos + 1, 0, ...await Promise.all(resolvedExtends.map((file)=>parseFile(file, cache))));
|
|
948
|
+
} else {
|
|
949
|
+
// reached a leaf, backtrack to the last branching point and continue
|
|
950
|
+
extendsPath.splice(-currentBranchDepth);
|
|
951
|
+
currentBranchDepth = 0;
|
|
952
|
+
}
|
|
953
|
+
pos += 1;
|
|
954
|
+
}
|
|
955
|
+
result.extended = extended;
|
|
956
|
+
// skip first as it is the original config
|
|
957
|
+
for (const ext of result.extended.slice(1))extendTSConfig(result, ext);
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
*
|
|
961
|
+
* @param {string} extended
|
|
962
|
+
* @param {string} from
|
|
963
|
+
* @returns {string}
|
|
964
|
+
*/ function resolveExtends(extended, from) {
|
|
965
|
+
if ('..' === extended) // see #149
|
|
966
|
+
extended = '../tsconfig.json';
|
|
967
|
+
const req = (0, __WEBPACK_EXTERNAL_MODULE_module__.createRequire)(from);
|
|
968
|
+
let error;
|
|
969
|
+
try {
|
|
970
|
+
return req.resolve(extended);
|
|
971
|
+
} catch (e) {
|
|
972
|
+
error = e;
|
|
973
|
+
}
|
|
974
|
+
if ('.' !== extended[0] && !__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(extended)) try {
|
|
975
|
+
return req.resolve(`${extended}/tsconfig.json`);
|
|
976
|
+
} catch (e) {
|
|
977
|
+
error = e;
|
|
978
|
+
}
|
|
979
|
+
throw new TSConfckParseError(`failed to resolve "extends":"${extended}" in ${from}`, 'EXTENDS_RESOLVE', from, error);
|
|
980
|
+
}
|
|
981
|
+
// references, extends and custom keys are not carried over
|
|
982
|
+
const EXTENDABLE_KEYS = [
|
|
983
|
+
'compilerOptions',
|
|
984
|
+
'files',
|
|
985
|
+
'include',
|
|
986
|
+
'exclude',
|
|
987
|
+
'watchOptions',
|
|
988
|
+
'compileOnSave',
|
|
989
|
+
'typeAcquisition',
|
|
990
|
+
'buildOptions'
|
|
991
|
+
];
|
|
992
|
+
/**
|
|
993
|
+
*
|
|
994
|
+
* @param {import('./public.d.ts').TSConfckParseResult} extending
|
|
995
|
+
* @param {import('./public.d.ts').TSConfckParseResult} extended
|
|
996
|
+
* @returns void
|
|
997
|
+
*/ function extendTSConfig(extending, extended) {
|
|
998
|
+
const extendingConfig = extending.tsconfig;
|
|
999
|
+
const extendedConfig = extended.tsconfig;
|
|
1000
|
+
const relativePath = util_native2posix(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].relative(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(extending.tsconfigFile), __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(extended.tsconfigFile)));
|
|
1001
|
+
for (const key of Object.keys(extendedConfig).filter((key)=>EXTENDABLE_KEYS.includes(key)))if ('compilerOptions' === key) {
|
|
1002
|
+
if (!extendingConfig.compilerOptions) extendingConfig.compilerOptions = {};
|
|
1003
|
+
for (const option of Object.keys(extendedConfig.compilerOptions)){
|
|
1004
|
+
if (!Object.prototype.hasOwnProperty.call(extendingConfig.compilerOptions, option)) extendingConfig.compilerOptions[option] = rebaseRelative(option, extendedConfig.compilerOptions[option], relativePath);
|
|
1005
|
+
}
|
|
1006
|
+
} else if (void 0 === extendingConfig[key]) {
|
|
1007
|
+
if ('watchOptions' === key) {
|
|
1008
|
+
extendingConfig.watchOptions = {};
|
|
1009
|
+
for (const option of Object.keys(extendedConfig.watchOptions))extendingConfig.watchOptions[option] = rebaseRelative(option, extendedConfig.watchOptions[option], relativePath);
|
|
1010
|
+
} else extendingConfig[key] = rebaseRelative(key, extendedConfig[key], relativePath);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
const REBASE_KEYS = [
|
|
1014
|
+
// root
|
|
1015
|
+
'files',
|
|
1016
|
+
'include',
|
|
1017
|
+
'exclude',
|
|
1018
|
+
// compilerOptions
|
|
1019
|
+
'baseUrl',
|
|
1020
|
+
'rootDir',
|
|
1021
|
+
'rootDirs',
|
|
1022
|
+
'typeRoots',
|
|
1023
|
+
'outDir',
|
|
1024
|
+
'outFile',
|
|
1025
|
+
'declarationDir',
|
|
1026
|
+
// watchOptions
|
|
1027
|
+
'excludeDirectories',
|
|
1028
|
+
'excludeFiles'
|
|
1029
|
+
];
|
|
1030
|
+
/** @typedef {string | string[]} PathValue */ /**
|
|
1031
|
+
*
|
|
1032
|
+
* @param {string} key
|
|
1033
|
+
* @param {PathValue} value
|
|
1034
|
+
* @param {string} prependPath
|
|
1035
|
+
* @returns {PathValue}
|
|
1036
|
+
*/ function rebaseRelative(key, value, prependPath) {
|
|
1037
|
+
if (!REBASE_KEYS.includes(key)) return value;
|
|
1038
|
+
if (Array.isArray(value)) return value.map((x)=>rebasePath(x, prependPath));
|
|
1039
|
+
return rebasePath(value, prependPath);
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
*
|
|
1043
|
+
* @param {string} value
|
|
1044
|
+
* @param {string} prependPath
|
|
1045
|
+
* @returns {string}
|
|
1046
|
+
*/ function rebasePath(value, prependPath) {
|
|
1047
|
+
if (__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(value) || value.startsWith('${configDir}')) return value;
|
|
1048
|
+
// relative paths use posix syntax in tsconfig
|
|
1049
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.normalize(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.join(prependPath, value));
|
|
1050
|
+
}
|
|
1051
|
+
class TSConfckParseError extends Error {
|
|
1052
|
+
/**
|
|
1053
|
+
* error code
|
|
1054
|
+
* @type {string}
|
|
1055
|
+
*/ code;
|
|
1056
|
+
/**
|
|
1057
|
+
* error cause
|
|
1058
|
+
* @type { Error | undefined}
|
|
1059
|
+
*/ cause;
|
|
1060
|
+
/**
|
|
1061
|
+
* absolute path of tsconfig file where the error happened
|
|
1062
|
+
* @type {string}
|
|
1063
|
+
*/ tsconfigFile;
|
|
1064
|
+
/**
|
|
1065
|
+
*
|
|
1066
|
+
* @param {string} message - error message
|
|
1067
|
+
* @param {string} code - error code
|
|
1068
|
+
* @param {string} tsconfigFile - path to tsconfig file
|
|
1069
|
+
* @param {Error?} cause - cause of this error
|
|
1070
|
+
*/ constructor(message, code, tsconfigFile, cause){
|
|
1071
|
+
super(message);
|
|
1072
|
+
// Set the prototype explicitly.
|
|
1073
|
+
Object.setPrototypeOf(this, TSConfckParseError.prototype);
|
|
1074
|
+
this.name = TSConfckParseError.name;
|
|
1075
|
+
this.code = code;
|
|
1076
|
+
this.cause = cause;
|
|
1077
|
+
this.tsconfigFile = tsconfigFile;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
*
|
|
1082
|
+
* @param {any} tsconfig
|
|
1083
|
+
* @param {string} tsconfigFile
|
|
1084
|
+
*/ function applyDefaults(tsconfig, tsconfigFile) {
|
|
1085
|
+
if (isJSConfig(tsconfigFile)) tsconfig.compilerOptions = {
|
|
1086
|
+
...DEFAULT_JSCONFIG_COMPILER_OPTIONS,
|
|
1087
|
+
...tsconfig.compilerOptions
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
const DEFAULT_JSCONFIG_COMPILER_OPTIONS = {
|
|
1091
|
+
allowJs: true,
|
|
1092
|
+
maxNodeModuleJsDepth: 2,
|
|
1093
|
+
allowSyntheticDefaultImports: true,
|
|
1094
|
+
skipLibCheck: true,
|
|
1095
|
+
noEmit: true
|
|
582
1096
|
};
|
|
1097
|
+
/**
|
|
1098
|
+
* @param {string} configFileName
|
|
1099
|
+
*/ function isJSConfig(configFileName) {
|
|
1100
|
+
return 'jsconfig.json' === __WEBPACK_EXTERNAL_MODULE_node_path__["default"].basename(configFileName);
|
|
1101
|
+
}
|
|
1102
|
+
async function loadTsconfig(root, tsconfigPath = 'tsconfig.json') {
|
|
1103
|
+
const tsconfigFileName = await find((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(root, tsconfigPath), {
|
|
1104
|
+
root,
|
|
1105
|
+
configName: (0, __WEBPACK_EXTERNAL_MODULE_node_path__.basename)(tsconfigPath)
|
|
1106
|
+
});
|
|
1107
|
+
if (tsconfigFileName) {
|
|
1108
|
+
const { tsconfig } = await parse(tsconfigFileName);
|
|
1109
|
+
return tsconfig;
|
|
1110
|
+
}
|
|
1111
|
+
return {};
|
|
1112
|
+
}
|
|
583
1113
|
/**
|
|
584
1114
|
* This function helps you to autocomplete configuration types.
|
|
585
1115
|
* It accepts a Rslib config object, or a function that returns a config.
|
|
586
1116
|
*/ function defineConfig(config) {
|
|
587
1117
|
return config;
|
|
588
1118
|
}
|
|
589
|
-
const findConfig = (basePath)=>
|
|
1119
|
+
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync);
|
|
590
1120
|
const resolveConfigPath = (root, customConfig)=>{
|
|
591
1121
|
if (customConfig) {
|
|
592
|
-
const customConfigPath = (0,
|
|
593
|
-
if (
|
|
594
|
-
|
|
1122
|
+
const customConfigPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.isAbsolute)(customConfig) ? customConfig : (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(root, customConfig);
|
|
1123
|
+
if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(customConfigPath)) return customConfigPath;
|
|
1124
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`Cannot find config file: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].dim(customConfigPath)}\n`);
|
|
595
1125
|
}
|
|
596
|
-
const configFilePath = findConfig((0,
|
|
1126
|
+
const configFilePath = findConfig((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(root, DEFAULT_CONFIG_NAME));
|
|
597
1127
|
if (configFilePath) return configFilePath;
|
|
598
1128
|
throw new Error(`${DEFAULT_CONFIG_NAME} not found in ${root}`);
|
|
599
1129
|
};
|
|
600
1130
|
async function loadConfig({ cwd = process.cwd(), path, envMode }) {
|
|
601
1131
|
const configFilePath = resolveConfigPath(cwd, path);
|
|
602
|
-
const { content } = await (0,
|
|
603
|
-
cwd: (0,
|
|
1132
|
+
const { content } = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.loadConfig)({
|
|
1133
|
+
cwd: (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configFilePath),
|
|
604
1134
|
path: configFilePath,
|
|
605
1135
|
envMode
|
|
606
1136
|
});
|
|
@@ -666,7 +1196,7 @@ const composeExternalsWarnConfig = (format, ...externalsArray)=>{
|
|
|
666
1196
|
};
|
|
667
1197
|
if (contextInfo.issuer && 'commonjs' === dependencyType) {
|
|
668
1198
|
matchUserExternals(externals, request, _callback);
|
|
669
|
-
if (externalized)
|
|
1199
|
+
if (externalized) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(composeModuleImportWarn(request));
|
|
670
1200
|
}
|
|
671
1201
|
callback();
|
|
672
1202
|
}
|
|
@@ -678,7 +1208,7 @@ const composeAutoExternalConfig = (options)=>{
|
|
|
678
1208
|
const { autoExternal, pkgJson, userExternals } = options;
|
|
679
1209
|
if (!autoExternal) return {};
|
|
680
1210
|
if (!pkgJson) {
|
|
681
|
-
|
|
1211
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn('autoExternal configuration will not be applied due to read package.json failed');
|
|
682
1212
|
return {};
|
|
683
1213
|
}
|
|
684
1214
|
const externalOptions = {
|
|
@@ -751,30 +1281,30 @@ function composeBannerFooterConfig(banner, footer) {
|
|
|
751
1281
|
if (isEmptyObject(bannerConfig) && isEmptyObject(footerConfig)) return {};
|
|
752
1282
|
const plugins = [];
|
|
753
1283
|
if (!isEmptyObject(bannerConfig)) {
|
|
754
|
-
if (bannerConfig.js) plugins.push(new
|
|
1284
|
+
if (bannerConfig.js) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
755
1285
|
banner: bannerConfig.js,
|
|
756
|
-
stage:
|
|
1286
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
757
1287
|
raw: true,
|
|
758
1288
|
include: /\.(js|mjs|cjs)$/
|
|
759
1289
|
}));
|
|
760
|
-
if (bannerConfig.css) plugins.push(new
|
|
1290
|
+
if (bannerConfig.css) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
761
1291
|
banner: bannerConfig.css,
|
|
762
|
-
stage:
|
|
1292
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
763
1293
|
raw: true,
|
|
764
1294
|
include: /\.(css)$/
|
|
765
1295
|
}));
|
|
766
1296
|
}
|
|
767
1297
|
if (!isEmptyObject(footerConfig)) {
|
|
768
|
-
if (footerConfig.js) plugins.push(new
|
|
1298
|
+
if (footerConfig.js) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
769
1299
|
banner: footerConfig.js,
|
|
770
|
-
stage:
|
|
1300
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
771
1301
|
raw: true,
|
|
772
1302
|
footer: true,
|
|
773
1303
|
include: /\.(js|mjs|cjs)$/
|
|
774
1304
|
}));
|
|
775
|
-
if (footerConfig.css) plugins.push(new
|
|
1305
|
+
if (footerConfig.css) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
776
1306
|
banner: footerConfig.css,
|
|
777
|
-
stage:
|
|
1307
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
778
1308
|
raw: true,
|
|
779
1309
|
footer: true,
|
|
780
1310
|
include: /\.(css)$/
|
|
@@ -788,8 +1318,18 @@ function composeBannerFooterConfig(banner, footer) {
|
|
|
788
1318
|
}
|
|
789
1319
|
};
|
|
790
1320
|
}
|
|
1321
|
+
function composeDecoratorsConfig(compilerOptions, version) {
|
|
1322
|
+
if (version || !compilerOptions?.experimentalDecorators) return {};
|
|
1323
|
+
return {
|
|
1324
|
+
source: {
|
|
1325
|
+
decorators: {
|
|
1326
|
+
version: 'legacy'
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
791
1331
|
async function createConstantRsbuildConfig() {
|
|
792
|
-
return (0,
|
|
1332
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.defineConfig)({
|
|
793
1333
|
mode: 'production',
|
|
794
1334
|
dev: {
|
|
795
1335
|
progressBar: false
|
|
@@ -873,8 +1413,18 @@ const composeFormatConfig = (format)=>{
|
|
|
873
1413
|
};
|
|
874
1414
|
case 'cjs':
|
|
875
1415
|
return {
|
|
1416
|
+
plugins: [
|
|
1417
|
+
pluginCjsShim()
|
|
1418
|
+
],
|
|
876
1419
|
tools: {
|
|
877
1420
|
rspack: {
|
|
1421
|
+
module: {
|
|
1422
|
+
parser: {
|
|
1423
|
+
javascript: {
|
|
1424
|
+
importMeta: false
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
},
|
|
878
1428
|
output: {
|
|
879
1429
|
iife: false,
|
|
880
1430
|
chunkFormat: 'commonjs',
|
|
@@ -889,6 +1439,13 @@ const composeFormatConfig = (format)=>{
|
|
|
889
1439
|
return {
|
|
890
1440
|
tools: {
|
|
891
1441
|
rspack: {
|
|
1442
|
+
module: {
|
|
1443
|
+
parser: {
|
|
1444
|
+
javascript: {
|
|
1445
|
+
importMeta: false
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
892
1449
|
output: {
|
|
893
1450
|
library: {
|
|
894
1451
|
type: 'umd'
|
|
@@ -901,7 +1458,7 @@ const composeFormatConfig = (format)=>{
|
|
|
901
1458
|
throw new Error(`Unsupported format: ${format}`);
|
|
902
1459
|
}
|
|
903
1460
|
};
|
|
904
|
-
const composeModuleImportWarn = (request)=>`The externalized commonjs request ${
|
|
1461
|
+
const composeModuleImportWarn = (request)=>`The externalized commonjs request ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].green(`"${request}"`)} will use ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('"module"')} external type in ESM format. If you want to specify other external type, considering set the request and type with ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('"output.externals"')}.`;
|
|
905
1462
|
const composeExternalsConfig = (format, externals)=>{
|
|
906
1463
|
// TODO: Define the internal externals config in Rsbuild's externals instead
|
|
907
1464
|
// Rspack's externals as they will not be merged from different fields. All externals
|
|
@@ -950,36 +1507,19 @@ const composeAutoExtensionConfig = (config, autoExtension, pkgJson)=>{
|
|
|
950
1507
|
};
|
|
951
1508
|
const composeSyntaxConfig = (syntax, target)=>{
|
|
952
1509
|
// Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported.
|
|
953
|
-
if (syntax)
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1510
|
+
if (syntax) {
|
|
1511
|
+
const resolvedBrowserslist = transformSyntaxToBrowserslist(syntax, target);
|
|
1512
|
+
return {
|
|
1513
|
+
tools: {
|
|
1514
|
+
rspack: (config)=>{
|
|
1515
|
+
config.target = resolvedBrowserslist.map((item)=>`browserslist:${item}`);
|
|
1516
|
+
}
|
|
1517
|
+
},
|
|
1518
|
+
output: {
|
|
1519
|
+
overrideBrowserslist: resolvedBrowserslist
|
|
963
1520
|
}
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
overrideBrowserslist: transformSyntaxToBrowserslist(syntax)
|
|
967
|
-
}
|
|
968
|
-
};
|
|
969
|
-
// If `syntax` is not defined, Rslib will try to determine by the `target`, with the last version of the target.
|
|
970
|
-
const lastTargetVersions = {
|
|
971
|
-
node: [
|
|
972
|
-
'last 1 node versions'
|
|
973
|
-
],
|
|
974
|
-
web: [
|
|
975
|
-
'last 1 Chrome versions',
|
|
976
|
-
'last 1 Firefox versions',
|
|
977
|
-
'last 1 Edge versions',
|
|
978
|
-
'last 1 Safari versions',
|
|
979
|
-
'last 1 ios_saf versions',
|
|
980
|
-
'not dead'
|
|
981
|
-
]
|
|
982
|
-
};
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
983
1523
|
return {
|
|
984
1524
|
tools: {
|
|
985
1525
|
rspack: (config)=>{
|
|
@@ -990,10 +1530,8 @@ const composeSyntaxConfig = (syntax, target)=>{
|
|
|
990
1530
|
}
|
|
991
1531
|
},
|
|
992
1532
|
output: {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
...lastTargetVersions.web
|
|
996
|
-
]
|
|
1533
|
+
// If `syntax` is not defined, Rslib will try to determine by the `target`, with the last version of the target.
|
|
1534
|
+
overrideBrowserslist: ESX_TO_BROWSERSLIST.esnext(target)
|
|
997
1535
|
}
|
|
998
1536
|
};
|
|
999
1537
|
};
|
|
@@ -1017,18 +1555,20 @@ const composeEntryConfig = async (entries, bundle, root)=>{
|
|
|
1017
1555
|
] : null;
|
|
1018
1556
|
if (!entryFiles) throw new Error('Entry can only be a string or an array of strings for now');
|
|
1019
1557
|
// Turn entries in array into each separate entry.
|
|
1020
|
-
const
|
|
1558
|
+
const globEntryFiles = await (0, __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js__["default"])(entryFiles, {
|
|
1021
1559
|
cwd: root
|
|
1022
1560
|
});
|
|
1561
|
+
// Filter the glob resolved entry files based on the allowed extensions
|
|
1562
|
+
const resolvedEntryFiles = globEntryFiles.filter((file)=>ENTRY_EXTENSIONS_PATTERN.test(file));
|
|
1023
1563
|
if (0 === resolvedEntryFiles.length) throw new Error(`Cannot find ${resolvedEntryFiles}`);
|
|
1024
1564
|
// Similar to `rootDir` in tsconfig and `outbase` in esbuild.
|
|
1025
1565
|
const lcp = await calcLongestCommonPath(resolvedEntryFiles);
|
|
1026
1566
|
// Using the longest common path of all non-declaration input files by default.
|
|
1027
1567
|
const outBase = null === lcp ? root : lcp;
|
|
1028
1568
|
for (const file of resolvedEntryFiles){
|
|
1029
|
-
const { dir, name } =
|
|
1569
|
+
const { dir, name } = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].parse(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].relative(outBase, file));
|
|
1030
1570
|
// Entry filename contains nested path to preserve source directory structure.
|
|
1031
|
-
const entryFileName =
|
|
1571
|
+
const entryFileName = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(dir, name);
|
|
1032
1572
|
resolvedEntries[entryFileName] = file;
|
|
1033
1573
|
}
|
|
1034
1574
|
}
|
|
@@ -1054,7 +1594,13 @@ const composeBundleConfig = (jsExtension, bundle = true)=>{
|
|
|
1054
1594
|
// This may result in a change in semantics,
|
|
1055
1595
|
// user should use copy to keep origin file or use another separate entry to deal this
|
|
1056
1596
|
let request = data.request;
|
|
1057
|
-
if ('.' === request[0])
|
|
1597
|
+
if ('.' === request[0]) {
|
|
1598
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_node_path__.extname)(request)) {
|
|
1599
|
+
if (!JS_EXTENSIONS_PATTERN.test(request)) // If it does not match jsExtensionsPattern, we should do nothing, eg: ./foo.png
|
|
1600
|
+
return callback();
|
|
1601
|
+
request = request.replace(/\.[^.]+$/, jsExtension);
|
|
1602
|
+
} else request = `${request}${jsExtension}`;
|
|
1603
|
+
}
|
|
1058
1604
|
return callback(null, request);
|
|
1059
1605
|
}
|
|
1060
1606
|
callback();
|
|
@@ -1066,7 +1612,7 @@ const composeBundleConfig = (jsExtension, bundle = true)=>{
|
|
|
1066
1612
|
const composeDtsConfig = async (libConfig, dtsExtension)=>{
|
|
1067
1613
|
const { dts, bundle, output, autoExternal, banner, footer } = libConfig;
|
|
1068
1614
|
if (false === dts || void 0 === dts) return {};
|
|
1069
|
-
const { pluginDts } = await
|
|
1615
|
+
const { pluginDts } = await import("rsbuild-plugin-dts");
|
|
1070
1616
|
return {
|
|
1071
1617
|
plugins: [
|
|
1072
1618
|
pluginDts({
|
|
@@ -1089,7 +1635,12 @@ const composeTargetConfig = (target = 'web')=>{
|
|
|
1089
1635
|
rspack: {
|
|
1090
1636
|
target: [
|
|
1091
1637
|
'web'
|
|
1092
|
-
]
|
|
1638
|
+
],
|
|
1639
|
+
output: {
|
|
1640
|
+
chunkLoading: 'import',
|
|
1641
|
+
workerChunkLoading: 'import',
|
|
1642
|
+
wasmLoading: 'fetch'
|
|
1643
|
+
}
|
|
1093
1644
|
}
|
|
1094
1645
|
}
|
|
1095
1646
|
};
|
|
@@ -1099,12 +1650,17 @@ const composeTargetConfig = (target = 'web')=>{
|
|
|
1099
1650
|
rspack: {
|
|
1100
1651
|
target: [
|
|
1101
1652
|
'node'
|
|
1102
|
-
]
|
|
1653
|
+
],
|
|
1654
|
+
// "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`,
|
|
1655
|
+
// and leave them as-is in the rest of the cases.
|
|
1656
|
+
// { node: { __dirname: ..., __filename: ... } }
|
|
1657
|
+
output: {
|
|
1658
|
+
chunkLoading: 'require',
|
|
1659
|
+
workerChunkLoading: 'async-node',
|
|
1660
|
+
wasmLoading: 'async-node'
|
|
1661
|
+
}
|
|
1103
1662
|
}
|
|
1104
1663
|
},
|
|
1105
|
-
// "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`,
|
|
1106
|
-
// and leave them as-is in the rest of the cases.
|
|
1107
|
-
// { node: { __dirname: ..., __filename: ... } }
|
|
1108
1664
|
output: {
|
|
1109
1665
|
// When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`.
|
|
1110
1666
|
// Simply override the built-in modules to make them external.
|
|
@@ -1113,17 +1669,15 @@ const composeTargetConfig = (target = 'web')=>{
|
|
|
1113
1669
|
target: 'node'
|
|
1114
1670
|
}
|
|
1115
1671
|
};
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
}
|
|
1126
|
-
};
|
|
1672
|
+
// TODO: Support `neutral` target, however Rsbuild don't list it as an option in the target field.
|
|
1673
|
+
// case 'neutral':
|
|
1674
|
+
// return {
|
|
1675
|
+
// tools: {
|
|
1676
|
+
// rspack: {
|
|
1677
|
+
// target: ['web', 'node'],
|
|
1678
|
+
// },
|
|
1679
|
+
// },
|
|
1680
|
+
// };
|
|
1127
1681
|
default:
|
|
1128
1682
|
throw new Error(`Unsupported platform: ${target}`);
|
|
1129
1683
|
}
|
|
@@ -1144,7 +1698,7 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
|
|
|
1144
1698
|
...Object.keys(pkgJson?.devDependencies ?? [])
|
|
1145
1699
|
];
|
|
1146
1700
|
if (!deps.includes(SWC_HELPERS)) {
|
|
1147
|
-
|
|
1701
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(`${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].green('externalHelpers')} is enabled, but the ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue(SWC_HELPERS)} dependency declaration was not found in package.json.`);
|
|
1148
1702
|
process.exit(1);
|
|
1149
1703
|
}
|
|
1150
1704
|
defaultConfig = Object.assign(defaultConfig, {
|
|
@@ -1157,8 +1711,9 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
|
|
|
1157
1711
|
return defaultConfig;
|
|
1158
1712
|
};
|
|
1159
1713
|
async function composeLibRsbuildConfig(config, configPath) {
|
|
1160
|
-
const rootPath = (0,
|
|
1714
|
+
const rootPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configPath);
|
|
1161
1715
|
const pkgJson = readPackageJson(rootPath);
|
|
1716
|
+
const { compilerOptions } = await loadTsconfig(rootPath, config.source?.tsconfigPath);
|
|
1162
1717
|
const { format, banner = {}, footer = {}, autoExtension = true, autoExternal = true, externalHelpers = false } = config;
|
|
1163
1718
|
const formatConfig = composeFormatConfig(format);
|
|
1164
1719
|
const externalHelpersConfig = composeExternalHelpersConfig(externalHelpers, pkgJson);
|
|
@@ -1172,12 +1727,13 @@ async function composeLibRsbuildConfig(config, configPath) {
|
|
|
1172
1727
|
pkgJson,
|
|
1173
1728
|
userExternals: config.output?.externals
|
|
1174
1729
|
});
|
|
1175
|
-
const entryConfig = await composeEntryConfig(config.source?.entry, config.bundle, (0,
|
|
1730
|
+
const entryConfig = await composeEntryConfig(config.source?.entry, config.bundle, (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configPath));
|
|
1176
1731
|
const dtsConfig = await composeDtsConfig(config, dtsExtension);
|
|
1177
1732
|
const externalsWarnConfig = composeExternalsWarnConfig(format, autoExternalConfig?.output?.externals, externalsConfig?.output?.externals);
|
|
1178
1733
|
const minifyConfig = composeMinifyConfig(config.output?.minify);
|
|
1179
1734
|
const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
|
|
1180
|
-
|
|
1735
|
+
const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
|
|
1736
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(formatConfig, externalHelpersConfig, externalsWarnConfig, externalsConfig, autoExternalConfig, autoExtensionConfig, syntaxConfig, bundleConfig, targetConfig, entryConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig);
|
|
1181
1737
|
}
|
|
1182
1738
|
async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
1183
1739
|
const constantRsbuildConfig = await createConstantRsbuildConfig();
|
|
@@ -1185,7 +1741,7 @@ async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
|
1185
1741
|
const { lib: libConfigsArray, ...sharedRsbuildConfig } = rslibConfig;
|
|
1186
1742
|
if (!libConfigsArray) throw new Error(`Expect lib field to be an array, but got ${libConfigsArray}.`);
|
|
1187
1743
|
const libConfigPromises = libConfigsArray.map(async (libConfig)=>{
|
|
1188
|
-
const userConfig = (0,
|
|
1744
|
+
const userConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(sharedRsbuildConfig, libConfig);
|
|
1189
1745
|
// Merge the configuration of each environment based on the shared Rsbuild
|
|
1190
1746
|
// configuration and Lib configuration in the settings.
|
|
1191
1747
|
const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, configPath);
|
|
@@ -1207,7 +1763,7 @@ async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
|
1207
1763
|
// We should state in the document that the built-in configuration should not be changed optionally
|
|
1208
1764
|
// In compose process of 2, we may read some config from 1, and reassemble the related config,
|
|
1209
1765
|
// so before final mergeRsbuildConfig, we reset some specified fields
|
|
1210
|
-
config: (0,
|
|
1766
|
+
config: (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(constantRsbuildConfig, libRsbuildConfig, omit(userConfig, [
|
|
1211
1767
|
'bundle',
|
|
1212
1768
|
'format',
|
|
1213
1769
|
'autoExtension',
|
|
@@ -1240,7 +1796,7 @@ async function initRsbuild(rslibConfig) {
|
|
|
1240
1796
|
const currentFormatIndex = formatIndex[format]++;
|
|
1241
1797
|
environments[1 === currentFormatCount ? format : `${format}${currentFormatIndex}`] = config;
|
|
1242
1798
|
}
|
|
1243
|
-
return (0,
|
|
1799
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.createRsbuild)({
|
|
1244
1800
|
rsbuildConfig: {
|
|
1245
1801
|
environments
|
|
1246
1802
|
}
|
|
@@ -1257,9 +1813,9 @@ const applyCommonOptions = (command)=>{
|
|
|
1257
1813
|
command.option('-c --config <config>', 'specify the configuration file, can be a relative or absolute path').option('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file');
|
|
1258
1814
|
};
|
|
1259
1815
|
function runCli() {
|
|
1260
|
-
|
|
1261
|
-
const buildCommand =
|
|
1262
|
-
const inspectCommand =
|
|
1816
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.7");
|
|
1817
|
+
const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
|
|
1818
|
+
const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
|
|
1263
1819
|
[
|
|
1264
1820
|
buildCommand,
|
|
1265
1821
|
inspectCommand
|
|
@@ -1272,8 +1828,8 @@ function runCli() {
|
|
|
1272
1828
|
});
|
|
1273
1829
|
await build(rslibConfig, options);
|
|
1274
1830
|
} catch (err) {
|
|
1275
|
-
|
|
1276
|
-
|
|
1831
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error('Failed to build.');
|
|
1832
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(err);
|
|
1277
1833
|
process.exit(1);
|
|
1278
1834
|
}
|
|
1279
1835
|
});
|
|
@@ -1292,12 +1848,13 @@ function runCli() {
|
|
|
1292
1848
|
writeToDisk: true
|
|
1293
1849
|
});
|
|
1294
1850
|
} catch (err) {
|
|
1295
|
-
|
|
1296
|
-
|
|
1851
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error('Failed to inspect config.');
|
|
1852
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(err);
|
|
1297
1853
|
process.exit(1);
|
|
1298
1854
|
}
|
|
1299
1855
|
});
|
|
1300
|
-
|
|
1856
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
|
|
1301
1857
|
}
|
|
1302
|
-
const src_version = "0.0.
|
|
1303
|
-
|
|
1858
|
+
const src_version = "0.0.7";
|
|
1859
|
+
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
|
|
1860
|
+
export { build, defineConfig, loadConfig, prepareCli, runCli, src_version as version, __webpack_exports__logger as logger };
|