@rsbuild/core 2.1.5 → 2.1.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/compiled/@rstackjs/load-config/index.d.ts +66 -0
- package/compiled/@rstackjs/load-config/license +21 -0
- package/compiled/@rstackjs/load-config/package.json +1 -0
- package/compiled/css-loader/index.js +2 -2
- package/compiled/html-rspack-plugin/index.d.ts +4 -4
- package/compiled/html-rspack-plugin/index.js +53 -48
- package/compiled/postcss/index.js +1 -1
- package/compiled/postcss/lib/postcss.d.ts +4 -1
- package/compiled/postcss/package.json +1 -1
- package/compiled/postcss-loader/index.js +6 -6
- package/compiled/rslog/index.d.ts +14 -14
- package/compiled/rslog/package.json +1 -1
- package/dist/711.js +392 -423
- package/dist/http-proxy-middleware.js +8 -8
- package/dist/manifest-plugin.js +37 -33
- package/dist/memfs.js +369 -201
- package/dist/ws.js +34 -38
- package/dist-types/cli/init.d.ts +1 -2
- package/dist-types/createContext.d.ts +2 -1
- package/dist-types/helpers/restartManager.d.ts +13 -0
- package/dist-types/hooks.d.ts +2 -1
- package/dist-types/index.d.ts +1 -1
- package/dist-types/loadConfig.d.ts +4 -39
- package/dist-types/plugins/minimize.d.ts +2 -2
- package/dist-types/restart.d.ts +10 -15
- package/dist-types/types/config.d.ts +12 -4
- package/dist-types/types/context.d.ts +4 -0
- package/dist-types/types/hooks.d.ts +11 -0
- package/dist-types/types/plugin.d.ts +4 -1
- package/dist-types/types/rsbuild.d.ts +12 -5
- package/package.json +9 -8
- /package/dist/{fresh-import.js → freshImport.js} +0 -0
package/dist/711.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/*! LICENSE: 711.js.LICENSE.txt */
|
|
2
|
-
let
|
|
2
|
+
let runtimeProcessArgs, runtimeInfo, swcHelpersPath, pluginHelper_htmlPlugin;
|
|
3
3
|
import { rspack as core_rspack } from "@rspack/core";
|
|
4
4
|
import node_util, { stripVTControlCharacters } from "node:util";
|
|
5
|
-
import node_process from "node:process";
|
|
6
|
-
import node_os, { constants as external_node_os_constants } from "node:os";
|
|
7
|
-
import node_tty from "node:tty";
|
|
8
5
|
import node_path, { dirname as external_node_path_dirname, isAbsolute as external_node_path_isAbsolute, join, posix, relative, resolve as external_node_path_resolve, sep, win32 } from "node:path";
|
|
9
6
|
import { builtinModules, createRequire, createRequire as __rspack_createRequire } from "node:module";
|
|
10
7
|
import node_fs, { existsSync } from "node:fs";
|
|
8
|
+
import node_os, { constants as external_node_os_constants } from "node:os";
|
|
9
|
+
import node_process from "node:process";
|
|
11
10
|
import { URL as external_node_url_URL, pathToFileURL, fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
12
11
|
import { isPromise, isRegExp } from "node:util/types";
|
|
13
12
|
import { readFile } from "node:fs/promises";
|
|
@@ -387,8 +386,8 @@ __webpack_require__.add({
|
|
|
387
386
|
return (asyncHooks.AsyncResource && (res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn')), res && res.runInAsyncScope) ? res.runInAsyncScope.bind(res, fn, null) : fn;
|
|
388
387
|
}
|
|
389
388
|
},
|
|
390
|
-
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
391
|
-
let yaml, { resolve } = __webpack_require__("node:path?435f"), config = __webpack_require__("../../node_modules/.pnpm/lilconfig@3.1.3/node_modules/lilconfig/src/index.js"), loadOptions = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
389
|
+
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.19/node_modules/postcss-load-config/src/index.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
390
|
+
let yaml, { resolve } = __webpack_require__("node:path?435f"), config = __webpack_require__("../../node_modules/.pnpm/lilconfig@3.1.3/node_modules/lilconfig/src/index.js"), loadOptions = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.19/node_modules/postcss-load-config/src/options.js"), loadPlugins = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.19/node_modules/postcss-load-config/src/plugins.js"), req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.19/node_modules/postcss-load-config/src/req.js");
|
|
392
391
|
async function processResult(ctx, result) {
|
|
393
392
|
let obj, file = result.filepath || '', projectConfig = ((obj = result.config) && obj.__esModule ? obj : {
|
|
394
393
|
default: obj
|
|
@@ -461,8 +460,8 @@ __webpack_require__.add({
|
|
|
461
460
|
});
|
|
462
461
|
};
|
|
463
462
|
},
|
|
464
|
-
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
465
|
-
let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
463
|
+
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.19/node_modules/postcss-load-config/src/options.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
464
|
+
let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.19/node_modules/postcss-load-config/src/req.js");
|
|
466
465
|
module.exports = async function options(config, file) {
|
|
467
466
|
if (config.parser && 'string' == typeof config.parser) try {
|
|
468
467
|
config.parser = await req(config.parser, file);
|
|
@@ -482,8 +481,8 @@ __webpack_require__.add({
|
|
|
482
481
|
return config;
|
|
483
482
|
};
|
|
484
483
|
},
|
|
485
|
-
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
486
|
-
let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
484
|
+
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.19/node_modules/postcss-load-config/src/plugins.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
485
|
+
let req = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.19/node_modules/postcss-load-config/src/req.js");
|
|
487
486
|
async function load(plugin, options, file) {
|
|
488
487
|
try {
|
|
489
488
|
if (null == options || 0 === Object.keys(options).length) return await req(plugin, file);
|
|
@@ -499,7 +498,7 @@ __webpack_require__.add({
|
|
|
499
498
|
}), list;
|
|
500
499
|
};
|
|
501
500
|
},
|
|
502
|
-
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
501
|
+
"../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.19/node_modules/postcss-load-config/src/req.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
503
502
|
let tsx, jiti, { createRequire } = __webpack_require__("node:module?1bcb"), { pathToFileURL } = __webpack_require__("node:url?b4ec"), TS_EXT_RE = /\.[mc]?ts$/, importError = [];
|
|
504
503
|
module.exports = async function req(name, rootFile = __rspack_import_meta_filename__) {
|
|
505
504
|
let url = createRequire(rootFile).resolve(name);
|
|
@@ -625,134 +624,35 @@ let createStyler = (style)=>(text)=>node_util.styleText(style, String(text)), co
|
|
|
625
624
|
magenta: createStyler('magenta'),
|
|
626
625
|
underline: createStyler('underline'),
|
|
627
626
|
strikethrough: createStyler('strikethrough')
|
|
628
|
-
}
|
|
629
|
-
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : node_process.argv) {
|
|
630
|
-
let prefix = flag.startsWith('-') ? '' : 1 === flag.length ? '-' : '--', position = argv.indexOf(prefix + flag), terminatorPosition = argv.indexOf('--');
|
|
631
|
-
return -1 !== position && (-1 === terminatorPosition || position < terminatorPosition);
|
|
632
|
-
}
|
|
633
|
-
let { env: dist_env } = node_process;
|
|
634
|
-
function envForceColor() {
|
|
635
|
-
if (!('FORCE_COLOR' in dist_env)) return;
|
|
636
|
-
if ('true' === dist_env.FORCE_COLOR) return 1;
|
|
637
|
-
if ('false' === dist_env.FORCE_COLOR) return 0;
|
|
638
|
-
if (0 === dist_env.FORCE_COLOR.length) return 1;
|
|
639
|
-
let level = Math.min(Number.parseInt(dist_env.FORCE_COLOR, 10), 3);
|
|
640
|
-
if ([
|
|
641
|
-
0,
|
|
642
|
-
1,
|
|
643
|
-
2,
|
|
644
|
-
3
|
|
645
|
-
].includes(level)) return level;
|
|
646
|
-
}
|
|
647
|
-
function translateLevel(level) {
|
|
648
|
-
return 0 !== level && {
|
|
649
|
-
level,
|
|
650
|
-
hasBasic: !0,
|
|
651
|
-
has256: level >= 2,
|
|
652
|
-
has16m: level >= 3
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = !0 } = {}) {
|
|
656
|
-
let noFlagForceColor = envForceColor();
|
|
657
|
-
void 0 !== noFlagForceColor && (flagForceColor = noFlagForceColor);
|
|
658
|
-
let forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
659
|
-
if (0 === forceColor) return 0;
|
|
660
|
-
if (sniffFlags) {
|
|
661
|
-
if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) return 3;
|
|
662
|
-
if (hasFlag('color=256')) return 2;
|
|
663
|
-
}
|
|
664
|
-
if ('TF_BUILD' in dist_env && 'AGENT_NAME' in dist_env) return 1;
|
|
665
|
-
if (haveStream && !streamIsTTY && void 0 === forceColor) return 0;
|
|
666
|
-
let min = forceColor || 0;
|
|
667
|
-
if ('dumb' === dist_env.TERM) return min;
|
|
668
|
-
if ('win32' === node_process.platform) {
|
|
669
|
-
let osRelease = node_os.release().split('.');
|
|
670
|
-
return Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586 ? Number(osRelease[2]) >= 14931 ? 3 : 2 : 1;
|
|
671
|
-
}
|
|
672
|
-
if ('CI' in dist_env) return [
|
|
673
|
-
'GITHUB_ACTIONS',
|
|
674
|
-
'GITEA_ACTIONS',
|
|
675
|
-
'CIRCLECI'
|
|
676
|
-
].some((key)=>key in dist_env) ? 3 : [
|
|
677
|
-
'TRAVIS',
|
|
678
|
-
'APPVEYOR',
|
|
679
|
-
'GITLAB_CI',
|
|
680
|
-
'BUILDKITE',
|
|
681
|
-
'DRONE'
|
|
682
|
-
].some((sign)=>sign in dist_env) || 'codeship' === dist_env.CI_NAME ? 1 : min;
|
|
683
|
-
if ('TEAMCITY_VERSION' in dist_env) return +!!/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(dist_env.TEAMCITY_VERSION);
|
|
684
|
-
if ('truecolor' === dist_env.COLORTERM || 'xterm-kitty' === dist_env.TERM || 'xterm-ghostty' === dist_env.TERM || 'wezterm' === dist_env.TERM) return 3;
|
|
685
|
-
if ('TERM_PROGRAM' in dist_env) {
|
|
686
|
-
let version = Number.parseInt((dist_env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
687
|
-
switch(dist_env.TERM_PROGRAM){
|
|
688
|
-
case 'iTerm.app':
|
|
689
|
-
return version >= 3 ? 3 : 2;
|
|
690
|
-
case 'Apple_Terminal':
|
|
691
|
-
return 2;
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
return /-256(color)?$/i.test(dist_env.TERM) ? 2 : /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(dist_env.TERM) || 'COLORTERM' in dist_env ? 1 : min;
|
|
695
|
-
}
|
|
696
|
-
function createSupportsColor(stream, options = {}) {
|
|
697
|
-
return translateLevel(_supportsColor(stream, {
|
|
698
|
-
streamIsTTY: stream && stream.isTTY,
|
|
699
|
-
...options
|
|
700
|
-
}));
|
|
701
|
-
}
|
|
702
|
-
hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never') ? flagForceColor = 0 : (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) && (flagForceColor = 1);
|
|
703
|
-
let supportsColor = {
|
|
704
|
-
stdout: createSupportsColor({
|
|
705
|
-
isTTY: node_tty.isatty(1)
|
|
706
|
-
}),
|
|
707
|
-
stderr: createSupportsColor({
|
|
708
|
-
isTTY: node_tty.isatty(2)
|
|
709
|
-
})
|
|
710
|
-
}, colorLevel = supportsColor.stdout ? supportsColor.stdout.level : 0, errorStackRegExp = /at [^\r\n]{0,200}:\d+:\d+[\s\)]*$/, anonymousErrorStackRegExp = /at [^\r\n]{0,200}\(<anonymous>\)$/, indexErrorStackRegExp = /at [^\r\n]{0,200}\(index\s\d+\)$/, isWord = (char)=>!/[\s\n]/.test(char), LOG_LEVEL = {
|
|
627
|
+
}, supportsTrueColor = !0 === process.stdout.isTTY && process.stdout.hasColors(16777216, process.env), LOG_LEVEL = {
|
|
711
628
|
silent: -1,
|
|
712
629
|
error: 0,
|
|
713
630
|
warn: 1,
|
|
714
631
|
info: 2,
|
|
715
632
|
log: 2,
|
|
716
633
|
verbose: 3
|
|
634
|
+
}, createLogType = (label, level, style)=>{
|
|
635
|
+
let formattedLabel;
|
|
636
|
+
return {
|
|
637
|
+
get label () {
|
|
638
|
+
return formattedLabel ??= color.bold(style(label.padEnd(7)));
|
|
639
|
+
},
|
|
640
|
+
level
|
|
641
|
+
};
|
|
717
642
|
}, LOG_TYPES = {
|
|
718
|
-
error:
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
label: 'warn',
|
|
725
|
-
level: 'warn',
|
|
726
|
-
color: color.yellow
|
|
727
|
-
},
|
|
728
|
-
info: {
|
|
729
|
-
label: 'info',
|
|
730
|
-
level: 'info',
|
|
731
|
-
color: color.cyan
|
|
732
|
-
},
|
|
733
|
-
start: {
|
|
734
|
-
label: 'start',
|
|
735
|
-
level: 'info',
|
|
736
|
-
color: color.cyan
|
|
737
|
-
},
|
|
738
|
-
ready: {
|
|
739
|
-
label: 'ready',
|
|
740
|
-
level: 'info',
|
|
741
|
-
color: color.green
|
|
742
|
-
},
|
|
743
|
-
success: {
|
|
744
|
-
label: 'success',
|
|
745
|
-
level: 'info',
|
|
746
|
-
color: color.green
|
|
747
|
-
},
|
|
643
|
+
error: createLogType('error', 'error', color.red),
|
|
644
|
+
warn: createLogType('warn', 'warn', color.yellow),
|
|
645
|
+
info: createLogType('info', 'info', color.cyan),
|
|
646
|
+
start: createLogType('start', 'info', color.cyan),
|
|
647
|
+
ready: createLogType('ready', 'info', color.green),
|
|
648
|
+
success: createLogType('success', 'info', color.green),
|
|
748
649
|
log: {
|
|
749
650
|
level: 'info'
|
|
750
651
|
},
|
|
751
|
-
debug:
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
}
|
|
652
|
+
debug: createLogType('debug', 'verbose', color.magenta)
|
|
653
|
+
}, ANSI_REGEXP = RegExp("\x1b\\[[0-9;]*m", 'g'), errorStackRegExp = /at [^\r\n]{0,200}(?::\d+:\d+[\s)]*|\(<anonymous>\)|\(index\s\d+\))$/, isErrorStackMessage = (message)=>{
|
|
654
|
+
let stripped = message.replace(ANSI_REGEXP, '');
|
|
655
|
+
return errorStackRegExp.test(stripped);
|
|
756
656
|
}, normalizeErrorMessage = (err)=>{
|
|
757
657
|
if (err.stack) {
|
|
758
658
|
let [rawName, ...rest] = err.stack.split('\n'), name = rawName.startsWith('Error: ') ? rawName.slice(7) : rawName;
|
|
@@ -760,26 +660,23 @@ let supportsColor = {
|
|
|
760
660
|
}
|
|
761
661
|
return err.message;
|
|
762
662
|
}, createLogger = (options = {})=>{
|
|
763
|
-
let { level = 'info', prefix, console: console1 = globalThis.console } = options, maxLevel = level, log = (type, message, ...args)=>{
|
|
663
|
+
let { level = 'info', prefix, console: console1 = globalThis.console, alignMultiline } = options, maxLevel = level, log = (type, message, ...args)=>{
|
|
764
664
|
let logType = LOG_TYPES[type], { level } = logType;
|
|
765
665
|
if (LOG_LEVEL[level] > LOG_LEVEL[maxLevel]) return;
|
|
766
666
|
if (null == message) return console1.log();
|
|
767
|
-
let label = '', text = '';
|
|
768
|
-
if (
|
|
667
|
+
let label = 'label' in logType ? logType.label : '', header = label ? prefix ? `${label} ${prefix}` : label : prefix, text = '', isErrorObject = message instanceof Error;
|
|
668
|
+
if (isErrorObject) {
|
|
769
669
|
text += normalizeErrorMessage(message);
|
|
770
670
|
let { cause } = message;
|
|
771
671
|
cause && (text += color.yellow('\n [cause]: '), text += cause instanceof Error ? normalizeErrorMessage(cause) : String(cause));
|
|
772
|
-
} else text = 'error' === level && 'string' == typeof message ? message.split('\n').map((line)=>
|
|
773
|
-
|
|
672
|
+
} else text = 'error' === level && 'string' == typeof message ? message.split('\n').map((line)=>isErrorStackMessage(line) ? color.gray(line) : line).join('\n') : `${message}`;
|
|
673
|
+
if (alignMultiline && header && !isErrorObject && text.includes('\n')) {
|
|
674
|
+
let indent = ' '.repeat(header.replace(ANSI_REGEXP, '').length + 1), skipStack = 'error' === level;
|
|
675
|
+
text = text.split('\n').map((line, i)=>0 === i || '' === line || skipStack && isErrorStackMessage(line) ? line : indent + line).join('\n');
|
|
676
|
+
}
|
|
677
|
+
console1['error' === level || 'warn' === level ? level : 'log'](header ? `${header} ${text}` : text, ...args);
|
|
774
678
|
}, logger = {
|
|
775
|
-
greet: (message)=>log('log', ((message)
|
|
776
|
-
if (colorLevel < 3) return 2 === colorLevel ? color.cyan(message) : message;
|
|
777
|
-
let chars = [
|
|
778
|
-
...message
|
|
779
|
-
], steps = chars.filter(isWord).length, r = 189, g = 255, b = 243, rStep = -115 / steps, gStep = -61 / steps, bStep = -89 / steps, output = '';
|
|
780
|
-
for (let char of chars)isWord(char) && (r += rStep, g += gStep, b += bStep), output += `\x1b[38;2;${Math.round(r)};${Math.round(g)};${Math.round(b)}m${char}\x1b[39m`;
|
|
781
|
-
return color.bold(output);
|
|
782
|
-
})(message))
|
|
679
|
+
greet: (message)=>log('log', supportsTrueColor ? `\x1b[1;38;2;132;225;199m${message}\x1b[39;22m` : color.bold(color.cyan(message)))
|
|
783
680
|
};
|
|
784
681
|
return Object.keys(LOG_TYPES).forEach((key)=>{
|
|
785
682
|
logger[key] = (...args)=>log(key, ...args);
|
|
@@ -2611,6 +2508,7 @@ function createAsyncHook() {
|
|
|
2611
2508
|
function initHooks() {
|
|
2612
2509
|
return {
|
|
2613
2510
|
onExit: createAsyncHook(),
|
|
2511
|
+
onRestart: createAsyncHook(),
|
|
2614
2512
|
onCloseBuild: createAsyncHook(),
|
|
2615
2513
|
onAfterBuild: createAsyncHook(),
|
|
2616
2514
|
onBeforeBuild: createAsyncHook(),
|
|
@@ -3379,6 +3277,7 @@ function initPluginAPI({ context, pluginManager }) {
|
|
|
3379
3277
|
getNormalizedConfig,
|
|
3380
3278
|
isPluginExists: pluginManager.isPluginExists,
|
|
3381
3279
|
onExit,
|
|
3280
|
+
onRestart: hooks.onRestart.tap,
|
|
3382
3281
|
onAfterBuild: hooks.onAfterBuild.tap,
|
|
3383
3282
|
onCloseBuild: hooks.onCloseBuild.tap,
|
|
3384
3283
|
onBeforeBuild: hooks.onBeforeBuild.tap,
|
|
@@ -3493,6 +3392,8 @@ function createPublicContext(context) {
|
|
|
3493
3392
|
'action',
|
|
3494
3393
|
'version',
|
|
3495
3394
|
'rootPath',
|
|
3395
|
+
'configFile',
|
|
3396
|
+
'configFileDependencies',
|
|
3496
3397
|
'distPath',
|
|
3497
3398
|
'devServer',
|
|
3498
3399
|
'cachePath',
|
|
@@ -3506,11 +3407,13 @@ function createPublicContext(context) {
|
|
|
3506
3407
|
set: (target, prop)=>(target.logger.error(`Context is readonly, you can not assign to the "context.${prop}" prop.`), !0)
|
|
3507
3408
|
});
|
|
3508
3409
|
}
|
|
3509
|
-
async function createContext(options, userConfig, logger) {
|
|
3510
|
-
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
|
|
3410
|
+
async function createContext(options, userConfig, logger, loadConfigResult) {
|
|
3411
|
+
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, hooks = initHooks();
|
|
3511
3412
|
return {
|
|
3512
|
-
version: "2.1.
|
|
3413
|
+
version: "2.1.7",
|
|
3513
3414
|
rootPath,
|
|
3415
|
+
configFile: loadConfigResult?.filePath ?? userConfig._privateMeta?.configFilePath,
|
|
3416
|
+
configFileDependencies: loadConfigResult?.dependencies ?? userConfig._privateMeta?.configFileDependencies ?? [],
|
|
3514
3417
|
distPath: '',
|
|
3515
3418
|
cachePath,
|
|
3516
3419
|
logger,
|
|
@@ -3519,7 +3422,38 @@ async function createContext(options, userConfig, logger) {
|
|
|
3519
3422
|
environments: {},
|
|
3520
3423
|
environmentList: [],
|
|
3521
3424
|
publicPathnames: [],
|
|
3522
|
-
hooks
|
|
3425
|
+
hooks,
|
|
3426
|
+
restartManager: (({ onRestart, restart })=>{
|
|
3427
|
+
let cleanups = new Set();
|
|
3428
|
+
return {
|
|
3429
|
+
canRestart: !!restart,
|
|
3430
|
+
registerCleanup: (cleanup)=>(cleanups.add(cleanup), ()=>{
|
|
3431
|
+
cleanups.delete(cleanup);
|
|
3432
|
+
}),
|
|
3433
|
+
async requestRestart (context) {
|
|
3434
|
+
let firstError;
|
|
3435
|
+
if (!restart) return await onRestart(context), !1;
|
|
3436
|
+
let currentCleanups = cleanups;
|
|
3437
|
+
cleanups = new Set();
|
|
3438
|
+
let hasError = !1;
|
|
3439
|
+
try {
|
|
3440
|
+
await onRestart(context);
|
|
3441
|
+
} catch (error) {
|
|
3442
|
+
hasError = !0, firstError = error;
|
|
3443
|
+
}
|
|
3444
|
+
for (let cleanup of currentCleanups)try {
|
|
3445
|
+
await cleanup();
|
|
3446
|
+
} catch (error) {
|
|
3447
|
+
hasError || (hasError = !0, firstError = error);
|
|
3448
|
+
}
|
|
3449
|
+
if (hasError) throw firstError;
|
|
3450
|
+
return restart(context);
|
|
3451
|
+
}
|
|
3452
|
+
};
|
|
3453
|
+
})({
|
|
3454
|
+
onRestart: hooks.onRestart.callBatch,
|
|
3455
|
+
restart: options.restart
|
|
3456
|
+
}),
|
|
3523
3457
|
config: {
|
|
3524
3458
|
...rsbuildConfig
|
|
3525
3459
|
},
|
|
@@ -4036,7 +3970,7 @@ async function initRsbuildConfig({ context, pluginManager }) {
|
|
|
4036
3970
|
}
|
|
4037
3971
|
return tsconfigPaths.size && 'prefer-tsconfig' === normalizedBaseConfig.resolve.aliasStrategy && normalizedBaseConfig.dev.watchFiles.push({
|
|
4038
3972
|
paths: Array.from(tsconfigPaths),
|
|
4039
|
-
type: '
|
|
3973
|
+
type: 'restart'
|
|
4040
3974
|
}), context.normalizedConfig = {
|
|
4041
3975
|
...normalizedBaseConfig,
|
|
4042
3976
|
environments
|
|
@@ -4253,8 +4187,132 @@ async function createCompiler_createCompiler(options) {
|
|
|
4253
4187
|
rspackConfigs
|
|
4254
4188
|
};
|
|
4255
4189
|
}
|
|
4190
|
+
async function setupWatchFiles(options) {
|
|
4191
|
+
let { config, root, buildManager } = options, { hmr, liveReload } = config.dev;
|
|
4192
|
+
if (!hmr && !liveReload || !buildManager) return;
|
|
4193
|
+
let closeDevFilesWatcher = await watchDevFiles(config.dev, buildManager, root), serverFilesWatcher = await watchServerFiles(config.server, buildManager, root);
|
|
4194
|
+
return {
|
|
4195
|
+
async close () {
|
|
4196
|
+
await Promise.all([
|
|
4197
|
+
closeDevFilesWatcher?.(),
|
|
4198
|
+
serverFilesWatcher?.close()
|
|
4199
|
+
]);
|
|
4200
|
+
}
|
|
4201
|
+
};
|
|
4202
|
+
}
|
|
4203
|
+
async function watchDevFiles(devConfig, buildManager, root) {
|
|
4204
|
+
let { watchFiles } = devConfig;
|
|
4205
|
+
if (!watchFiles) return;
|
|
4206
|
+
let watchers = [];
|
|
4207
|
+
for (let { paths, options, type } of helpers_castArray(watchFiles)){
|
|
4208
|
+
let watchOptions = prepareWatchOptions(paths, options, type), watcher = await startWatchFiles(watchOptions, buildManager, root);
|
|
4209
|
+
watcher && watchers.push(watcher);
|
|
4210
|
+
}
|
|
4211
|
+
return async ()=>{
|
|
4212
|
+
for (let watcher of watchers)await watcher.close();
|
|
4213
|
+
};
|
|
4214
|
+
}
|
|
4215
|
+
function watchServerFiles({ publicDir }, buildManager, root) {
|
|
4216
|
+
if (!publicDir.length) return;
|
|
4217
|
+
let watchPaths = publicDir.filter((item)=>item.watch).map((item)=>item.name);
|
|
4218
|
+
if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths), buildManager, root);
|
|
4219
|
+
}
|
|
4220
|
+
function prepareWatchOptions(paths, options = {}, type) {
|
|
4221
|
+
return {
|
|
4222
|
+
paths: 'string' == typeof paths ? [
|
|
4223
|
+
paths
|
|
4224
|
+
] : paths,
|
|
4225
|
+
options,
|
|
4226
|
+
type
|
|
4227
|
+
};
|
|
4228
|
+
}
|
|
4229
|
+
let GLOB_REGEX = /[*?{}[\]()!+|]/;
|
|
4230
|
+
async function createChokidar(pathOrGlobs, root, options) {
|
|
4231
|
+
let { default: chokidar } = await import("./chokidar.js"), watchFiles = new Set(), globPatterns = pathOrGlobs.filter((pathOrGlob)=>!!GLOB_REGEX.test(pathOrGlob) || (watchFiles.add(pathOrGlob), !1));
|
|
4232
|
+
if (globPatterns.length) {
|
|
4233
|
+
let { glob } = await import("./tinyglobby.js");
|
|
4234
|
+
for (let file of (await glob(globPatterns, {
|
|
4235
|
+
cwd: root,
|
|
4236
|
+
absolute: !0
|
|
4237
|
+
})))watchFiles.add(file);
|
|
4238
|
+
}
|
|
4239
|
+
return chokidar.watch(Array.from(watchFiles), options);
|
|
4240
|
+
}
|
|
4241
|
+
async function startWatchFiles({ paths, options, type = 'reload-page' }, buildManager, root) {
|
|
4242
|
+
if ('reload-page' !== type) return;
|
|
4243
|
+
let watcher = await createChokidar(paths, root, options);
|
|
4244
|
+
return watcher.on('change', ()=>{
|
|
4245
|
+
buildManager.socketServer.sendMessage({
|
|
4246
|
+
type: 'full-reload'
|
|
4247
|
+
});
|
|
4248
|
+
}), watcher;
|
|
4249
|
+
}
|
|
4250
|
+
let requestRestart = ({ filePath, clear = !0, action, logger, restartManager })=>{
|
|
4251
|
+
if (restartManager.canRestart) {
|
|
4252
|
+
clear && isTTY() && !process.env.DEBUG && process.stdout.write('\x1B[H\x1B[2J');
|
|
4253
|
+
let id = 'dev' === action ? 'server' : 'build';
|
|
4254
|
+
if (filePath) {
|
|
4255
|
+
let filename = node_path.basename(filePath);
|
|
4256
|
+
logger.info(`restarting ${id} as ${color.yellow(filename)} changed\n`);
|
|
4257
|
+
} else logger.info(`restarting ${id}...\n`);
|
|
4258
|
+
}
|
|
4259
|
+
return restartManager.requestRestart({
|
|
4260
|
+
action,
|
|
4261
|
+
filePath
|
|
4262
|
+
});
|
|
4263
|
+
};
|
|
4264
|
+
function watchFilesForRestart({ watchFiles, context, action }) {
|
|
4265
|
+
let closePromise, defaultFiles = context.configFile ? [
|
|
4266
|
+
context.configFile,
|
|
4267
|
+
...context.configFileDependencies
|
|
4268
|
+
] : [];
|
|
4269
|
+
if (!watchFiles.length && !defaultFiles.length) return;
|
|
4270
|
+
let watchGroups = [];
|
|
4271
|
+
for (let { paths, options, type } of watchFiles){
|
|
4272
|
+
if ('restart' !== type && 'reload-server' !== type) continue;
|
|
4273
|
+
let files = helpers_castArray(paths);
|
|
4274
|
+
files.length && (options ? watchGroups.push({
|
|
4275
|
+
files,
|
|
4276
|
+
options
|
|
4277
|
+
}) : defaultFiles.push(...files));
|
|
4278
|
+
}
|
|
4279
|
+
if (defaultFiles.length && watchGroups.push({
|
|
4280
|
+
files: defaultFiles
|
|
4281
|
+
}), !watchGroups.length) return;
|
|
4282
|
+
let { logger, restartManager, rootPath: root } = context, restarting = !1, onChange = async (filePath, cwd)=>{
|
|
4283
|
+
if (restarting || closePromise) return;
|
|
4284
|
+
restarting = !0;
|
|
4285
|
+
let absoluteFilePath = node_path.resolve(cwd, filePath);
|
|
4286
|
+
try {
|
|
4287
|
+
await requestRestart({
|
|
4288
|
+
action,
|
|
4289
|
+
filePath: absoluteFilePath,
|
|
4290
|
+
logger,
|
|
4291
|
+
restartManager
|
|
4292
|
+
}) ? await close() : restartManager.canRestart && logger.error('build' === action ? 'Restart build failed.' : 'Restart server failed.');
|
|
4293
|
+
} catch (error) {
|
|
4294
|
+
logger.error(error);
|
|
4295
|
+
} finally{
|
|
4296
|
+
restarting = !1;
|
|
4297
|
+
}
|
|
4298
|
+
}, watchersPromise = Promise.all(watchGroups.map(async ({ files, options })=>{
|
|
4299
|
+
try {
|
|
4300
|
+
let watcher = await createChokidar(files, root, {
|
|
4301
|
+
ignoreInitial: !0,
|
|
4302
|
+
ignorePermissionErrors: !0,
|
|
4303
|
+
...options
|
|
4304
|
+
}), cwd = options?.cwd || root, handleChange = (filePath)=>void onChange(filePath, cwd);
|
|
4305
|
+
return watcher.on('add', handleChange), watcher.on('change', handleChange), watcher.on('unlink', handleChange), watcher;
|
|
4306
|
+
} catch (error) {
|
|
4307
|
+
logger.error(error);
|
|
4308
|
+
}
|
|
4309
|
+
})), close = ()=>(closePromise || (closePromise = watchersPromise.then((watchers)=>Promise.all(watchers.map((watcher)=>watcher?.close()))).then(()=>{})), closePromise);
|
|
4310
|
+
return {
|
|
4311
|
+
close
|
|
4312
|
+
};
|
|
4313
|
+
}
|
|
4256
4314
|
let RSPACK_BUILD_ERROR = 'Rspack build failed.', build_build = async (initOptions, { watch } = {})=>{
|
|
4257
|
-
let { context } = initOptions, { logger } = context, { compiler, rspackConfigs } = await createCompiler_createCompiler(initOptions);
|
|
4315
|
+
let stats, closeCompiler, closingPromise, unregisterRestart, restartWatcher, { context } = initOptions, { logger } = context, { compiler, rspackConfigs } = await createCompiler_createCompiler(initOptions);
|
|
4258
4316
|
if ((({ context, isWatch, compiler, rspackConfigs, MultiStatsCtor })=>{
|
|
4259
4317
|
let isFirstCompile = !0, { environmentList } = context, onDone = async (stats)=>{
|
|
4260
4318
|
let promise = context.hooks.onAfterBuild.callBatch({
|
|
@@ -4316,28 +4374,32 @@ let RSPACK_BUILD_ERROR = 'Rspack build failed.', build_build = async (initOption
|
|
|
4316
4374
|
MultiStatsCtor: core_rspack.MultiStats
|
|
4317
4375
|
}), watch) {
|
|
4318
4376
|
let watchOptions = rspackConfigs.map((options)=>options.watchOptions || {});
|
|
4319
|
-
|
|
4377
|
+
compiler.watch(watchOptions.length > 1 ? watchOptions : watchOptions[0] || {}, (err)=>{
|
|
4320
4378
|
err && logger.error(err);
|
|
4321
|
-
}), {
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
};
|
|
4328
|
-
}
|
|
4329
|
-
let { stats } = await new Promise((resolve, reject)=>{
|
|
4379
|
+
}), closeCompiler = ()=>new Promise((resolve)=>{
|
|
4380
|
+
compiler.close(()=>{
|
|
4381
|
+
resolve();
|
|
4382
|
+
});
|
|
4383
|
+
});
|
|
4384
|
+
} else stats = await new Promise((resolve, reject)=>{
|
|
4330
4385
|
compiler.run((err, stats)=>{
|
|
4331
4386
|
compiler.close((closeErr)=>{
|
|
4332
|
-
closeErr && logger.error('Failed to close compiler: ', closeErr), err ? reject(err) : context.buildState.hasErrors ? reject(Error(RSPACK_BUILD_ERROR)) : resolve(
|
|
4333
|
-
stats
|
|
4334
|
-
});
|
|
4387
|
+
closeErr && logger.error('Failed to close compiler: ', closeErr), err ? reject(err) : context.buildState.hasErrors ? reject(Error(RSPACK_BUILD_ERROR)) : resolve(stats);
|
|
4335
4388
|
});
|
|
4336
4389
|
});
|
|
4337
4390
|
});
|
|
4338
|
-
|
|
4391
|
+
let closeBuild = ()=>closingPromise ||= (async ()=>{
|
|
4392
|
+
unregisterRestart?.(), unregisterRestart = void 0, await context.hooks.onCloseBuild.callBatch(), await closeCompiler?.();
|
|
4393
|
+
})();
|
|
4394
|
+
return watch && (unregisterRestart = context.restartManager.registerCleanup(closeBuild), restartWatcher = watchFilesForRestart({
|
|
4395
|
+
watchFiles: context.normalizedConfig.dev.watchFiles,
|
|
4396
|
+
context,
|
|
4397
|
+
action: 'build'
|
|
4398
|
+
})), {
|
|
4339
4399
|
stats,
|
|
4340
|
-
close: async ()=>{
|
|
4400
|
+
close: async ()=>{
|
|
4401
|
+
await restartWatcher?.close(), await closeBuild();
|
|
4402
|
+
}
|
|
4341
4403
|
};
|
|
4342
4404
|
}, main = __webpack_require__("../../node_modules/.pnpm/dotenv-expand@13.0.0_patch_hash=5ff37847fa487be2db4e4f14c2b21937f4e51cc7a43deea4506d4aaf3fa6149c/node_modules/dotenv-expand/lib/main.js"), DOTENV_LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
4343
4405
|
function loadEnv_parse(src) {
|
|
@@ -4856,7 +4918,7 @@ function getRegExpForExts(exts) {
|
|
|
4856
4918
|
function getCacheDirectory({ cacheDirectory }, context) {
|
|
4857
4919
|
return cacheDirectory ? external_node_path_isAbsolute(cacheDirectory) ? cacheDirectory : join(context.rootPath, cacheDirectory) : join(context.cachePath, 'rspack');
|
|
4858
4920
|
}
|
|
4859
|
-
async function getBuildDependencies(context,
|
|
4921
|
+
async function getBuildDependencies(context, environmentContext, additionalDependencies) {
|
|
4860
4922
|
let rootPackageJson = join(context.rootPath, 'package.json'), browserslistConfig = join(context.rootPath, '.browserslistrc'), buildDependencies = {};
|
|
4861
4923
|
await isFileExists(rootPackageJson) && (buildDependencies.packageJson = [
|
|
4862
4924
|
rootPackageJson
|
|
@@ -4864,8 +4926,9 @@ async function getBuildDependencies(context, config, environmentContext, additio
|
|
|
4864
4926
|
let { tsconfigPath } = environmentContext;
|
|
4865
4927
|
tsconfigPath && (buildDependencies.tsconfig = [
|
|
4866
4928
|
tsconfigPath
|
|
4867
|
-
]),
|
|
4868
|
-
|
|
4929
|
+
]), context.configFile && (buildDependencies.rsbuildConfig = [
|
|
4930
|
+
context.configFile,
|
|
4931
|
+
...context.configFileDependencies
|
|
4869
4932
|
]), await isFileExists(browserslistConfig) && (buildDependencies.browserslistrc = [
|
|
4870
4933
|
browserslistConfig
|
|
4871
4934
|
]);
|
|
@@ -4953,7 +5016,7 @@ function parseMinifyOptions(config) {
|
|
|
4953
5016
|
cssOptions: minify.cssOptions
|
|
4954
5017
|
};
|
|
4955
5018
|
}
|
|
4956
|
-
let postcss_load_config_src = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
5019
|
+
let postcss_load_config_src = __webpack_require__("../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.19/node_modules/postcss-load-config/src/index.js");
|
|
4957
5020
|
var postcss_load_config_src_default = __webpack_require__.n(postcss_load_config_src);
|
|
4958
5021
|
async function getLightningCSSLoaderOptions(config, targets, minify) {
|
|
4959
5022
|
let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
|
|
@@ -5205,7 +5268,7 @@ async function printFileSizes(options, stats, rootPath, distPath, environmentNam
|
|
|
5205
5268
|
if (!showTotal && !showDetail) return {
|
|
5206
5269
|
logs
|
|
5207
5270
|
};
|
|
5208
|
-
let relativeDistPath = node_path.relative(rootPath, distPath), snapshot = saveSnapshot ? {
|
|
5271
|
+
let relativeDistPath = node_path.relative(rootPath, distPath), rootFolderLabel = `${relativeDistPath || '.'}${node_path.sep}`, snapshot = saveSnapshot ? {
|
|
5209
5272
|
files: {},
|
|
5210
5273
|
totalSize: 0,
|
|
5211
5274
|
totalGzipSize: 0
|
|
@@ -5227,7 +5290,7 @@ async function printFileSizes(options, stats, rootPath, distPath, environmentNam
|
|
|
5227
5290
|
isSignificantDiff(gzipDiff) && (gzipSizeLabel += ` ${formatDiff(gzipDiff).label}`);
|
|
5228
5291
|
}
|
|
5229
5292
|
}
|
|
5230
|
-
let separatorIndex = filePath.lastIndexOf('/'), folderLabel =
|
|
5293
|
+
let separatorIndex = filePath.lastIndexOf('/'), folderLabel = -1 === separatorIndex ? rootFolderLabel : `${node_path.join(relativeDistPath, filePath.slice(0, separatorIndex))}${node_path.sep}`, filename = -1 === separatorIndex ? filePath : filePath.slice(separatorIndex + 1);
|
|
5231
5294
|
return {
|
|
5232
5295
|
filePath,
|
|
5233
5296
|
filenameLabel: color.dim(folderLabel) + (JS_REGEX.test(filename) ? color.cyan(filename) : filename.endsWith('.css') ? color.yellow(filename) : filename.endsWith('.html') ? color.green(filename) : color.magenta(filename)),
|
|
@@ -5916,6 +5979,8 @@ async function open_open({ port, routes, config, protocol, clearCache, logger })
|
|
|
5916
5979
|
for (let url of (targets.length ? urls.push(...targets.map((target)=>resolveUrl(replacePortPlaceholder(target, port), baseUrl))) : routes.length ? urls.push(`${baseUrl}${routes[0].pathname}`) : urls.push(baseUrl), before && await before(), urls))openedURLs.includes(url) || (openBrowser(url, logger), openedURLs.push(url));
|
|
5917
5980
|
}
|
|
5918
5981
|
let getServerUrlFromClientConfig = async (config, context)=>{
|
|
5982
|
+
let { assetPrefix } = config.dev;
|
|
5983
|
+
if (!(!0 === assetPrefix || 'string' == typeof assetPrefix && isURL(assetPrefix))) return;
|
|
5919
5984
|
let { devServer } = context;
|
|
5920
5985
|
if (!devServer) return;
|
|
5921
5986
|
let { client } = config.dev, hasClientHost = !!client.host, hasClientPort = void 0 !== client.port && '' !== client.port;
|
|
@@ -6727,7 +6792,7 @@ function createAssetsMiddleware(context, ready, outputFileSystem) {
|
|
|
6727
6792
|
}
|
|
6728
6793
|
async function setupOutputFileSystem(writeToDisk, compilers) {
|
|
6729
6794
|
if (!0 !== writeToDisk) {
|
|
6730
|
-
let { createFsFromVolume, Volume } = await import("./memfs.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/memfs@4.
|
|
6795
|
+
let { createFsFromVolume, Volume } = await import("./memfs.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/memfs@4.64.0/node_modules/memfs/lib/index.js", 23)), outputFileSystem = createFsFromVolume(new Volume());
|
|
6731
6796
|
for (let compiler of compilers)compiler.outputFileSystem = outputFileSystem;
|
|
6732
6797
|
}
|
|
6733
6798
|
let compiler = compilers.find((compiler)=>!!compiler.outputFileSystem);
|
|
@@ -8009,14 +8074,15 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
|
8009
8074
|
});
|
|
8010
8075
|
}, createCacheableFunction = (getter)=>{
|
|
8011
8076
|
let cache = new WeakMap();
|
|
8012
|
-
return
|
|
8077
|
+
return (stats, entryName, utils)=>{
|
|
8013
8078
|
let cachedEntries = cache.get(stats);
|
|
8014
|
-
|
|
8015
|
-
let
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
})
|
|
8079
|
+
cachedEntries || (cachedEntries = new Map(), cache.set(stats, cachedEntries));
|
|
8080
|
+
let cachedPromise = cachedEntries.get(entryName);
|
|
8081
|
+
if (cachedPromise) return cachedPromise;
|
|
8082
|
+
let promise = Promise.resolve().then(()=>getter(stats, entryName, utils)).catch((error)=>{
|
|
8083
|
+
throw cachedEntries.delete(entryName), error;
|
|
8084
|
+
});
|
|
8085
|
+
return cachedEntries.set(entryName, promise), promise;
|
|
8020
8086
|
};
|
|
8021
8087
|
}, cleanupCallbacks = new Set(), handleTermination = async (exitCode)=>{
|
|
8022
8088
|
try {
|
|
@@ -8062,69 +8128,9 @@ async function applyServerSetup(setup, context) {
|
|
|
8062
8128
|
}
|
|
8063
8129
|
return postCallbacks;
|
|
8064
8130
|
}
|
|
8065
|
-
async function setupWatchFiles(options) {
|
|
8066
|
-
let { config, root, buildManager } = options, { hmr, liveReload } = config.dev;
|
|
8067
|
-
if (!hmr && !liveReload || !buildManager) return;
|
|
8068
|
-
let closeDevFilesWatcher = await watchDevFiles(config.dev, buildManager, root), serverFilesWatcher = await watchServerFiles(config.server, buildManager, root);
|
|
8069
|
-
return {
|
|
8070
|
-
async close () {
|
|
8071
|
-
await Promise.all([
|
|
8072
|
-
closeDevFilesWatcher?.(),
|
|
8073
|
-
serverFilesWatcher?.close()
|
|
8074
|
-
]);
|
|
8075
|
-
}
|
|
8076
|
-
};
|
|
8077
|
-
}
|
|
8078
|
-
async function watchDevFiles(devConfig, buildManager, root) {
|
|
8079
|
-
let { watchFiles } = devConfig;
|
|
8080
|
-
if (!watchFiles) return;
|
|
8081
|
-
let watchers = [];
|
|
8082
|
-
for (let { paths, options, type } of helpers_castArray(watchFiles)){
|
|
8083
|
-
let watchOptions = prepareWatchOptions(paths, options, type), watcher = await startWatchFiles(watchOptions, buildManager, root);
|
|
8084
|
-
watcher && watchers.push(watcher);
|
|
8085
|
-
}
|
|
8086
|
-
return async ()=>{
|
|
8087
|
-
for (let watcher of watchers)await watcher.close();
|
|
8088
|
-
};
|
|
8089
|
-
}
|
|
8090
|
-
function watchServerFiles({ publicDir }, buildManager, root) {
|
|
8091
|
-
if (!publicDir.length) return;
|
|
8092
|
-
let watchPaths = publicDir.filter((item)=>item.watch).map((item)=>item.name);
|
|
8093
|
-
if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths), buildManager, root);
|
|
8094
|
-
}
|
|
8095
|
-
function prepareWatchOptions(paths, options = {}, type) {
|
|
8096
|
-
return {
|
|
8097
|
-
paths: 'string' == typeof paths ? [
|
|
8098
|
-
paths
|
|
8099
|
-
] : paths,
|
|
8100
|
-
options,
|
|
8101
|
-
type
|
|
8102
|
-
};
|
|
8103
|
-
}
|
|
8104
|
-
let GLOB_REGEX = /[*?{}[\]()!+|]/;
|
|
8105
|
-
async function createChokidar(pathOrGlobs, root, options) {
|
|
8106
|
-
let { default: chokidar } = await import("./chokidar.js"), watchFiles = new Set(), globPatterns = pathOrGlobs.filter((pathOrGlob)=>!!GLOB_REGEX.test(pathOrGlob) || (watchFiles.add(pathOrGlob), !1));
|
|
8107
|
-
if (globPatterns.length) {
|
|
8108
|
-
let { glob } = await import("./tinyglobby.js");
|
|
8109
|
-
for (let file of (await glob(globPatterns, {
|
|
8110
|
-
cwd: root,
|
|
8111
|
-
absolute: !0
|
|
8112
|
-
})))watchFiles.add(file);
|
|
8113
|
-
}
|
|
8114
|
-
return chokidar.watch(Array.from(watchFiles), options);
|
|
8115
|
-
}
|
|
8116
|
-
async function startWatchFiles({ paths, options, type = 'reload-page' }, buildManager, root) {
|
|
8117
|
-
if ('reload-page' !== type) return;
|
|
8118
|
-
let watcher = await createChokidar(paths, root, options);
|
|
8119
|
-
return watcher.on('change', ()=>{
|
|
8120
|
-
buildManager.socketServer.sendMessage({
|
|
8121
|
-
type: 'full-reload'
|
|
8122
|
-
});
|
|
8123
|
-
}), watcher;
|
|
8124
|
-
}
|
|
8125
8131
|
async function devServer_createDevServer(options, createCompiler, config, { getPortSilently, runCompile = !0 } = {}) {
|
|
8126
8132
|
var environmentCount;
|
|
8127
|
-
let stats, waiters, { context } = options, { logger } = context;
|
|
8133
|
+
let closingPromise, unregisterRestart, stats, waiters, { context } = options, { logger } = context;
|
|
8128
8134
|
logger.debug('create dev server');
|
|
8129
8135
|
let { port, portTip } = await resolvePort(config), { middlewareMode, host } = config.server, isHttps = !!config.server.https, routes = getRoutes(context), fallbackPathname = 0 === routes.length && context.environmentList.some((item)=>'web' === item.config.output.target) ? config.server.base : void 0;
|
|
8130
8136
|
context.devServer = {
|
|
@@ -8195,12 +8201,22 @@ async function devServer_createDevServer(options, createCompiler, config, { getP
|
|
|
8195
8201
|
protocol,
|
|
8196
8202
|
clearCache: !0,
|
|
8197
8203
|
logger
|
|
8198
|
-
}), state = {}, cleanupGracefulShutdown = middlewareMode ? null : setupGracefulShutdown(),
|
|
8204
|
+
}), state = {}, cleanupGracefulShutdown = middlewareMode ? null : setupGracefulShutdown(), closeServerResources = ()=>(closingPromise || (unregisterRestart?.(), unregisterRestart = void 0, closingPromise = (async ()=>{
|
|
8199
8205
|
removeCleanup(closeServer), cleanupGracefulShutdown?.(), await context.hooks.onCloseDevServer.callBatch(), await Promise.all([
|
|
8200
8206
|
state.devMiddlewares?.close(),
|
|
8201
8207
|
state.fileWatcher?.close()
|
|
8202
8208
|
]);
|
|
8203
|
-
})()), closingPromise)
|
|
8209
|
+
})()), closingPromise), closeServer = async ()=>{
|
|
8210
|
+
await state.restartWatcher?.close(), await closeServerResources();
|
|
8211
|
+
}, restartServer = async ()=>{
|
|
8212
|
+
let restarted = await requestRestart({
|
|
8213
|
+
action: 'dev',
|
|
8214
|
+
clear: !1,
|
|
8215
|
+
logger,
|
|
8216
|
+
restartManager: context.restartManager
|
|
8217
|
+
});
|
|
8218
|
+
return restarted && await state.restartWatcher?.close(), restarted;
|
|
8219
|
+
};
|
|
8204
8220
|
middlewareMode || registerCleanup(closeServer);
|
|
8205
8221
|
let beforeCreateCompiler = async ()=>{
|
|
8206
8222
|
if (printUrls(), cliShortcutsEnabled) {
|
|
@@ -8208,10 +8224,7 @@ async function devServer_createDevServer(options, createCompiler, config, { getP
|
|
|
8208
8224
|
openPage,
|
|
8209
8225
|
closeServer,
|
|
8210
8226
|
printUrls,
|
|
8211
|
-
restartServer:
|
|
8212
|
-
clear: !1,
|
|
8213
|
-
logger
|
|
8214
|
-
}),
|
|
8227
|
+
restartServer: context.restartManager.canRestart ? restartServer : void 0,
|
|
8215
8228
|
help: shortcutsOptions.help,
|
|
8216
8229
|
customShortcuts: shortcutsOptions.custom,
|
|
8217
8230
|
logger
|
|
@@ -8272,7 +8285,7 @@ async function devServer_createDevServer(options, createCompiler, config, { getP
|
|
|
8272
8285
|
port
|
|
8273
8286
|
}, async (err)=>{
|
|
8274
8287
|
if (err) throw err;
|
|
8275
|
-
middlewares.use(optionsFallbackMiddleware), middlewares.use(notFoundMiddleware), state.devMiddlewares && httpServer.on('upgrade', state.devMiddlewares.onUpgrade), logger.debug('listen dev server done'), await devServer.afterListen(),
|
|
8288
|
+
middlewares.use(optionsFallbackMiddleware), middlewares.use(notFoundMiddleware), state.devMiddlewares && httpServer.on('upgrade', state.devMiddlewares.onUpgrade), logger.debug('listen dev server done'), await devServer.afterListen(), resolve({
|
|
8276
8289
|
port,
|
|
8277
8290
|
urls: urls.map((item)=>item.url),
|
|
8278
8291
|
server: devServer
|
|
@@ -8314,7 +8327,11 @@ async function devServer_createDevServer(options, createCompiler, config, { getP
|
|
|
8314
8327
|
devServer,
|
|
8315
8328
|
context,
|
|
8316
8329
|
postCallbacks
|
|
8317
|
-
}), state.buildManager?.watch(),
|
|
8330
|
+
}), state.buildManager?.watch(), unregisterRestart = context.restartManager.registerCleanup(closeServerResources), state.restartWatcher = watchFilesForRestart({
|
|
8331
|
+
watchFiles: config.dev.watchFiles,
|
|
8332
|
+
context,
|
|
8333
|
+
action: 'dev'
|
|
8334
|
+
}), logger.debug('create dev server done'), devServer;
|
|
8318
8335
|
}
|
|
8319
8336
|
async function startPreviewServer(context, config, { getPortSilently } = {}) {
|
|
8320
8337
|
let environmentList, { logger } = context, { connect } = await import("./connect-next.js"), middlewares = connect(), { port, portTip } = await resolvePort(config), serverConfig = config.server, { host, headers, proxy, historyApiFallback, compress, base, cors } = serverConfig, assetPrefixes = context.environmentList.map((environment)=>environment.config.output.assetPrefix);
|
|
@@ -8546,7 +8563,7 @@ function applyDefaultPlugins(pluginManager, context) {
|
|
|
8546
8563
|
let { config } = environment, { buildCache = !1 } = config.performance;
|
|
8547
8564
|
if (!1 === buildCache) return;
|
|
8548
8565
|
cacheEnabled = !0;
|
|
8549
|
-
let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = getCacheDirectory(cacheConfig, context), buildDependencies = await getBuildDependencies(context,
|
|
8566
|
+
let { context } = api, cacheConfig = 'boolean' == typeof buildCache ? {} : buildCache, cacheDirectory = getCacheDirectory(cacheConfig, context), buildDependencies = await getBuildDependencies(context, environment, cacheConfig.buildDependencies), cacheVersion = Array.isArray(cacheConfig.cacheDigest) && cacheConfig.cacheDigest.length ? `${environment.name}-${env}-${await helpers_hash(JSON.stringify(cacheConfig.cacheDigest))}` : `${environment.name}-${env}`;
|
|
8550
8567
|
chain.cache({
|
|
8551
8568
|
type: 'persistent',
|
|
8552
8569
|
version: cacheVersion,
|
|
@@ -8671,7 +8688,7 @@ function applyDefaultPlugins(pluginManager, context) {
|
|
|
8671
8688
|
let showDiff = environments.some((environment)=>{
|
|
8672
8689
|
let { printFileSize } = environment.config.performance;
|
|
8673
8690
|
return 'object' == typeof printFileSize && !!printFileSize.diff;
|
|
8674
|
-
}), {
|
|
8691
|
+
}), { configFile } = api.context, snapshotHash = showDiff && configFile ? await helpers_hash(configFile) : '', snapshotPath = showDiff ? getSnapshotPath(api.context.cachePath, snapshotHash) : '', prevSnapshots = showDiff ? await loadPrevSnapshots(snapshotPath) : null, nextSnapshots = {}, logs = await Promise.all(environments.map(async ({ name, index, config, distPath })=>{
|
|
8675
8692
|
let statsItem = 'stats' in stats ? stats.stats[index] : stats, { logs: sizeLogs, snapshot } = await printFileSizes(((config)=>{
|
|
8676
8693
|
let { printFileSize } = config.performance, defaultConfig = {
|
|
8677
8694
|
total: !0,
|
|
@@ -9163,9 +9180,16 @@ try {
|
|
|
9163
9180
|
setup (api) {
|
|
9164
9181
|
api.modifyBundlerChain(async (chain, { environment, CHAIN_ID, rspack })=>{
|
|
9165
9182
|
let { config } = environment, { minifyJs, minifyCss, jsOptions, cssOptions } = parseMinifyOptions(config);
|
|
9166
|
-
if (chain.optimization.minimize(minifyJs || minifyCss), minifyJs
|
|
9167
|
-
|
|
9168
|
-
|
|
9183
|
+
if (chain.optimization.minimize(minifyJs || minifyCss), minifyJs) {
|
|
9184
|
+
let registerJsMinimizer = (jsOptionsItem, index = 0)=>{
|
|
9185
|
+
let minimizerId = 0 === index ? CHAIN_ID.MINIMIZER.JS : `${CHAIN_ID.MINIMIZER.JS}-${index}`;
|
|
9186
|
+
chain.optimization.minimizer(minimizerId).use(rspack.SwcJsMinimizerRspackPlugin, [
|
|
9187
|
+
getSwcMinimizerOptions(config, jsOptionsItem)
|
|
9188
|
+
]).end();
|
|
9189
|
+
}, jsOptionsList = helpers_castArray(jsOptions);
|
|
9190
|
+
jsOptionsList.length > 0 ? jsOptionsList.forEach(registerJsMinimizer) : registerJsMinimizer();
|
|
9191
|
+
}
|
|
9192
|
+
if (minifyCss) {
|
|
9169
9193
|
let loaderOptions = await getLightningCSSLoaderOptions(config, environment.browserslist, !0), defaultOptions = {
|
|
9170
9194
|
minimizerOptions: {
|
|
9171
9195
|
targets: isPlainObject(loaderOptions.targets) ? environment.browserslist : loaderOptions.targets,
|
|
@@ -9527,7 +9551,7 @@ try {
|
|
|
9527
9551
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev })=>{
|
|
9528
9552
|
let { output: { manifest }, dev: { writeToDisk } } = environment.config;
|
|
9529
9553
|
if (!1 === manifest) return;
|
|
9530
|
-
let manifestOptions = normalizeManifestObjectConfig(manifest), { RspackManifestPlugin } = await import("./manifest-plugin.js").then(__webpack_require__.bind(__webpack_require__, "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.
|
|
9554
|
+
let manifestOptions = normalizeManifestObjectConfig(manifest), { RspackManifestPlugin } = await import("./manifest-plugin.js").then(__webpack_require__.bind(__webpack_require__, "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.5/node_modules/rspack-manifest-plugin/dist/index.js")), { htmlPaths } = environment, filter = manifestOptions.filter ?? ((file)=>!file.name.endsWith('.LICENSE.txt'));
|
|
9531
9555
|
manifestFilenames.set(environment.name, manifestOptions.filename);
|
|
9532
9556
|
let pluginOptions = {
|
|
9533
9557
|
fileName: manifestOptions.filename,
|
|
@@ -9714,7 +9738,7 @@ function applyEnvsToConfig(config, envs) {
|
|
|
9714
9738
|
...config.dev.watchFiles ? helpers_castArray(config.dev.watchFiles) : [],
|
|
9715
9739
|
{
|
|
9716
9740
|
paths: envs.filePaths,
|
|
9717
|
-
type: '
|
|
9741
|
+
type: 'restart'
|
|
9718
9742
|
}
|
|
9719
9743
|
], config.performance?.buildCache))) {
|
|
9720
9744
|
let { buildCache } = config.performance;
|
|
@@ -9723,11 +9747,16 @@ function applyEnvsToConfig(config, envs) {
|
|
|
9723
9747
|
} : (buildCache.buildDependencies ||= [], buildCache.buildDependencies.push(...envs.filePaths));
|
|
9724
9748
|
}
|
|
9725
9749
|
}
|
|
9750
|
+
function isLoadConfigResult(result) {
|
|
9751
|
+
return 'object' == typeof result && null !== result && 'content' in result && 'filePath' in result && 'dependencies' in result;
|
|
9752
|
+
}
|
|
9726
9753
|
async function createRsbuild(options = {}) {
|
|
9727
|
-
let envs = options.loadEnv ? loadEnv({
|
|
9754
|
+
let loadConfigResult, envs = options.loadEnv ? loadEnv({
|
|
9728
9755
|
cwd: options.cwd,
|
|
9729
9756
|
...'boolean' == typeof options.loadEnv ? {} : options.loadEnv
|
|
9730
|
-
}) : null, configOrFactory = options.config ?? options.rsbuildConfig, config = isFunction(configOrFactory) ? await configOrFactory() : configOrFactory
|
|
9757
|
+
}) : null, configOrFactory = options.config ?? options.rsbuildConfig, config = isFunction(configOrFactory) ? await configOrFactory() : configOrFactory;
|
|
9758
|
+
isLoadConfigResult(config) && (loadConfigResult = config, config = config.content);
|
|
9759
|
+
let logger = (config ||= {}).customLogger ?? logger_createLogger({
|
|
9731
9760
|
...src_logger.options,
|
|
9732
9761
|
level: src_logger.level
|
|
9733
9762
|
});
|
|
@@ -9737,7 +9766,7 @@ async function createRsbuild(options = {}) {
|
|
|
9737
9766
|
callerName: 'rsbuild',
|
|
9738
9767
|
...options,
|
|
9739
9768
|
rsbuildConfig: config
|
|
9740
|
-
}, pluginManager = createPluginManager(logger), context = await createContext(resolvedOptions, config, logger), getPluginAPI = initPluginAPI({
|
|
9769
|
+
}, pluginManager = createPluginManager(logger), context = await createContext(resolvedOptions, config, logger, loadConfigResult), getPluginAPI = initPluginAPI({
|
|
9741
9770
|
context,
|
|
9742
9771
|
pluginManager
|
|
9743
9772
|
});
|
|
@@ -9759,20 +9788,11 @@ async function createRsbuild(options = {}) {
|
|
|
9759
9788
|
if (isEmptyDir(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} is empty, please build the project before previewing.`);
|
|
9760
9789
|
}
|
|
9761
9790
|
return startPreviewServer(context, config, options);
|
|
9762
|
-
}, build = async (options)=>{
|
|
9763
|
-
context.action = 'build', process.env.NODE_ENV || setNodeEnv('production');
|
|
9764
|
-
let buildInstance = await build_build({
|
|
9791
|
+
}, build = async (options)=>(context.action = 'build', process.env.NODE_ENV || setNodeEnv('production'), build_build({
|
|
9765
9792
|
context,
|
|
9766
9793
|
pluginManager,
|
|
9767
9794
|
rsbuildOptions: resolvedOptions
|
|
9768
|
-
}, options)
|
|
9769
|
-
return {
|
|
9770
|
-
...buildInstance,
|
|
9771
|
-
close: async ()=>{
|
|
9772
|
-
await context.hooks.onCloseBuild.callBatch(), await buildInstance.close();
|
|
9773
|
-
}
|
|
9774
|
-
};
|
|
9775
|
-
}, startDevServer = async (options)=>{
|
|
9795
|
+
}, options)), startDevServer = async (options)=>{
|
|
9776
9796
|
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
9777
9797
|
let config = await initRsbuildConfig({
|
|
9778
9798
|
context,
|
|
@@ -9859,7 +9879,8 @@ async function createRsbuild(options = {}) {
|
|
|
9859
9879
|
'onCloseBuild',
|
|
9860
9880
|
'onCloseDevServer',
|
|
9861
9881
|
'onDevCompileDone',
|
|
9862
|
-
'onExit'
|
|
9882
|
+
'onExit',
|
|
9883
|
+
'onRestart'
|
|
9863
9884
|
])
|
|
9864
9885
|
};
|
|
9865
9886
|
envs && (rsbuild.onCloseBuild(envs.cleanup), rsbuild.onCloseDevServer(envs.cleanup));
|
|
@@ -9881,61 +9902,59 @@ async function createRsbuild(options = {}) {
|
|
|
9881
9902
|
});
|
|
9882
9903
|
})), rsbuild;
|
|
9883
9904
|
}
|
|
9884
|
-
function
|
|
9885
|
-
return config;
|
|
9886
|
-
}
|
|
9887
|
-
let DEFAULT_CONFIG_FILE_NAMES = [
|
|
9888
|
-
'rsbuild.config.ts',
|
|
9889
|
-
'rsbuild.config.js',
|
|
9890
|
-
'rsbuild.config.mts',
|
|
9891
|
-
'rsbuild.config.mjs',
|
|
9892
|
-
'rsbuild.config.cts',
|
|
9893
|
-
'rsbuild.config.cjs'
|
|
9894
|
-
], canReadExport = (module)=>null !== module && ('object' == typeof module || 'function' == typeof module), getConfigExport = (configModule, exportName, configFilePath)=>{
|
|
9905
|
+
let canReadExport = (module)=>null !== module && ('object' == typeof module || 'function' == typeof module), getConfigExport = (configModule, exportName, configPath)=>{
|
|
9895
9906
|
if (!1 === exportName) return {};
|
|
9896
9907
|
if ('default' === exportName) return canReadExport(configModule) && 'default' in configModule ? configModule.default : configModule;
|
|
9897
9908
|
if (canReadExport(configModule) && Object.hasOwn(configModule, exportName)) return configModule[exportName];
|
|
9898
|
-
throw Error(`Cannot find export ${
|
|
9899
|
-
},
|
|
9909
|
+
throw Error(`Cannot find export ${exportName} in config file: ${configPath}`);
|
|
9910
|
+
}, loadWithJiti = async (configPath, exportName, fresh)=>{
|
|
9911
|
+
let createJiti;
|
|
9900
9912
|
try {
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
|
|
9913
|
+
({ createJiti } = await import("../compiled/jiti/lib/jiti.mjs"));
|
|
9914
|
+
} catch (error) {
|
|
9915
|
+
throw Error('The "jiti" package is required to load this config. Install it with your package manager.', {
|
|
9916
|
+
cause: error
|
|
9917
|
+
});
|
|
9905
9918
|
}
|
|
9906
|
-
|
|
9907
|
-
|
|
9908
|
-
return freshImportResult ? {
|
|
9909
|
-
configModule: freshImportResult.result,
|
|
9910
|
-
dependencies: freshImportResult.dependencies.sort()
|
|
9911
|
-
} : {
|
|
9912
|
-
configModule: await import(`${configFileURL}?t=${Date.now()}`),
|
|
9913
|
-
dependencies: []
|
|
9914
|
-
};
|
|
9915
|
-
}, loadConfigWithJiti = async (configFilePath, exportName)=>{
|
|
9916
|
-
let { createJiti } = await import("../compiled/jiti/lib/jiti.mjs"), jiti = createJiti(import.meta.filename, {
|
|
9917
|
-
moduleCache: !1,
|
|
9919
|
+
let jiti = createJiti(configPath, {
|
|
9920
|
+
moduleCache: !fresh,
|
|
9918
9921
|
interopDefault: !0,
|
|
9919
9922
|
nativeModules: [
|
|
9920
9923
|
"typescript"
|
|
9921
9924
|
]
|
|
9922
9925
|
});
|
|
9923
9926
|
return 'default' === exportName ? {
|
|
9924
|
-
configExport: await jiti.import(
|
|
9927
|
+
configExport: await jiti.import(configPath, {
|
|
9925
9928
|
default: !0
|
|
9926
9929
|
}),
|
|
9927
9930
|
dependencies: []
|
|
9928
9931
|
} : {
|
|
9929
|
-
configExport: getConfigExport(await jiti.import(
|
|
9932
|
+
configExport: getConfigExport(await jiti.import(configPath), exportName, configPath),
|
|
9933
|
+
dependencies: []
|
|
9934
|
+
};
|
|
9935
|
+
}, JS_CONFIG_REGEXP = /\.(?:js|mjs|cjs)$/, loadWithNative = async (configPath, fresh)=>{
|
|
9936
|
+
let configFileURL = pathToFileURL(configPath).href;
|
|
9937
|
+
if (!fresh) return {
|
|
9938
|
+
configModule: await import(configFileURL),
|
|
9939
|
+
dependencies: []
|
|
9940
|
+
};
|
|
9941
|
+
let { freshImport } = await import("./freshImport.js"), freshImportResult = await freshImport(configFileURL);
|
|
9942
|
+
return freshImportResult ? {
|
|
9943
|
+
configModule: freshImportResult.result,
|
|
9944
|
+
dependencies: freshImportResult.dependencies.sort()
|
|
9945
|
+
} : {
|
|
9946
|
+
configModule: await import(`${configFileURL}?t=${Date.now()}`),
|
|
9930
9947
|
dependencies: []
|
|
9931
9948
|
};
|
|
9932
9949
|
};
|
|
9933
|
-
async function
|
|
9934
|
-
let loadedConfig
|
|
9950
|
+
async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = [], loader = 'auto', exportName = 'default', configParams = [], fresh = !1 } = {}) {
|
|
9951
|
+
let loadedConfig;
|
|
9952
|
+
if (!path && 0 === configFileNames.length) throw Error('Either `path` or at least one `configFileNames` entry must be provided.');
|
|
9953
|
+
let configPath = ((root, customConfig, configFileNames = [])=>{
|
|
9935
9954
|
if (customConfig) {
|
|
9936
9955
|
let customConfigPath = external_node_path_isAbsolute(customConfig) ? customConfig : join(root, customConfig);
|
|
9937
9956
|
if (node_fs.existsSync(customConfigPath)) return customConfigPath;
|
|
9938
|
-
throw Error(`Cannot find config file: ${
|
|
9957
|
+
throw Error(`Cannot find config file: ${customConfigPath}`);
|
|
9939
9958
|
}
|
|
9940
9959
|
for (let file of configFileNames){
|
|
9941
9960
|
let configFile = join(root, file);
|
|
@@ -9943,67 +9962,87 @@ async function loadConfig_loadConfig({ cwd = process.cwd(), path, configFileName
|
|
|
9943
9962
|
}
|
|
9944
9963
|
return null;
|
|
9945
9964
|
})(cwd, path, configFileNames);
|
|
9946
|
-
if (!
|
|
9965
|
+
if (!configPath) return {
|
|
9947
9966
|
content: {},
|
|
9948
|
-
filePath:
|
|
9967
|
+
filePath: configPath,
|
|
9949
9968
|
dependencies: []
|
|
9950
9969
|
};
|
|
9951
|
-
|
|
9952
|
-
configFilePath
|
|
9953
|
-
}, config);
|
|
9954
|
-
if ('native' === loader || 'auto' === loader && (process.features.typescript || process.versions.bun || process.versions.deno) || /\.(?:js|mjs|cjs)$/.test(configFilePath)) {
|
|
9970
|
+
if ('native' === loader || 'auto' === loader && (process.features.typescript || process.versions.bun || process.versions.deno) || JS_CONFIG_REGEXP.test(configPath)) {
|
|
9955
9971
|
let result;
|
|
9956
9972
|
try {
|
|
9957
|
-
result = await
|
|
9973
|
+
result = await loadWithNative(configPath, fresh);
|
|
9958
9974
|
} catch (err) {
|
|
9959
|
-
|
|
9960
|
-
if ('native' === loader) throw src_logger.error(errorMessage), err;
|
|
9961
|
-
src_logger.debug(`${errorMessage}, fallback to jiti.`), src_logger.debug(err);
|
|
9975
|
+
if ('native' === loader) throw err;
|
|
9962
9976
|
}
|
|
9963
9977
|
result && (loadedConfig = {
|
|
9964
|
-
configExport: getConfigExport(result.configModule, exportName,
|
|
9978
|
+
configExport: getConfigExport(result.configModule, exportName, configPath),
|
|
9965
9979
|
dependencies: result.dependencies
|
|
9966
9980
|
});
|
|
9967
9981
|
}
|
|
9968
|
-
|
|
9969
|
-
loadedConfig = await loadConfigWithJiti(configFilePath, exportName);
|
|
9970
|
-
} catch (err) {
|
|
9971
|
-
throw src_logger.error(`Failed to load file with jiti: ${color.dim(configFilePath)}`), err;
|
|
9972
|
-
}
|
|
9982
|
+
loadedConfig || (loadedConfig = await loadWithJiti(configPath, exportName, fresh));
|
|
9973
9983
|
let { configExport, dependencies } = loadedConfig;
|
|
9974
9984
|
if ('function' == typeof configExport) {
|
|
9975
|
-
let
|
|
9976
|
-
env: nodeEnv,
|
|
9977
|
-
command: command ?? process.argv[2],
|
|
9978
|
-
envMode: envMode || nodeEnv,
|
|
9979
|
-
meta
|
|
9980
|
-
}, result = await configExport(configParams);
|
|
9985
|
+
let result = await configExport(...configParams);
|
|
9981
9986
|
if (void 0 === result) throw Error('The config function must return a config object.');
|
|
9982
9987
|
return {
|
|
9983
|
-
content:
|
|
9984
|
-
filePath:
|
|
9988
|
+
content: result,
|
|
9989
|
+
filePath: configPath,
|
|
9985
9990
|
dependencies
|
|
9986
9991
|
};
|
|
9987
9992
|
}
|
|
9988
|
-
|
|
9989
|
-
|
|
9990
|
-
|
|
9991
|
-
filePath: configFilePath,
|
|
9993
|
+
return {
|
|
9994
|
+
content: configExport,
|
|
9995
|
+
filePath: configPath,
|
|
9992
9996
|
dependencies
|
|
9993
9997
|
};
|
|
9994
9998
|
}
|
|
9999
|
+
function defineConfig(config) {
|
|
10000
|
+
return config;
|
|
10001
|
+
}
|
|
10002
|
+
let DEFAULT_CONFIG_FILE_NAMES = [
|
|
10003
|
+
'rsbuild.config.ts',
|
|
10004
|
+
'rsbuild.config.js',
|
|
10005
|
+
'rsbuild.config.mts',
|
|
10006
|
+
'rsbuild.config.mjs',
|
|
10007
|
+
'rsbuild.config.cts',
|
|
10008
|
+
'rsbuild.config.cjs'
|
|
10009
|
+
];
|
|
10010
|
+
async function loadConfig_loadConfig({ cwd = process.cwd(), path, configFileNames = DEFAULT_CONFIG_FILE_NAMES, envMode, meta, loader = 'auto', command, exportName = 'default' } = {}) {
|
|
10011
|
+
let nodeEnv = process.env.NODE_ENV || '', configParams = {
|
|
10012
|
+
env: nodeEnv,
|
|
10013
|
+
command: command ?? process.argv[2],
|
|
10014
|
+
envMode: envMode || nodeEnv,
|
|
10015
|
+
meta
|
|
10016
|
+
}, result = await dist_loadConfig({
|
|
10017
|
+
cwd,
|
|
10018
|
+
path,
|
|
10019
|
+
configFileNames,
|
|
10020
|
+
loader,
|
|
10021
|
+
exportName,
|
|
10022
|
+
configParams: [
|
|
10023
|
+
configParams
|
|
10024
|
+
],
|
|
10025
|
+
fresh: !0
|
|
10026
|
+
});
|
|
10027
|
+
if (!result.filePath) return src_logger.debug('no config file found.'), result;
|
|
10028
|
+
if (!isObject(result.content)) throw Error(`The config must be an object or a function that returns an object, get ${color.yellow(String(result.content))}`);
|
|
10029
|
+
return result.content._privateMeta = {
|
|
10030
|
+
configFilePath: result.filePath,
|
|
10031
|
+
configFileDependencies: result.dependencies
|
|
10032
|
+
}, src_logger.debug('configuration loaded from:', result.filePath), result;
|
|
10033
|
+
}
|
|
9995
10034
|
let cliState = {
|
|
9996
10035
|
options: {}
|
|
9997
10036
|
}, initCliAction = (command, options)=>{
|
|
9998
10037
|
process.env.NODE_ENV || (process.env.NODE_ENV = 'build' === command || 'preview' === command ? 'production' : 'development'), options.environment?.some((env)=>env.includes(',')) && (options.environment = options.environment.flatMap((env)=>env.split(','))), cliState.command = command, cliState.options = options;
|
|
9999
10038
|
}, init_loadConfig = async (root)=>{
|
|
10000
|
-
let { options, command } = cliState,
|
|
10039
|
+
let { options, command } = cliState, result = await loadConfig_loadConfig({
|
|
10001
10040
|
cwd: root,
|
|
10002
10041
|
path: options.config,
|
|
10003
10042
|
envMode: options.envMode,
|
|
10004
10043
|
loader: options.configLoader,
|
|
10005
10044
|
command
|
|
10006
|
-
});
|
|
10045
|
+
}), { content: config } = result;
|
|
10007
10046
|
if (config.dev ||= {}, config.source ||= {}, config.server ||= {}, options.base && (config.server.base = options.base), options.root && (config.root = root), options.mode && (config.mode = options.mode), options.logLevel && (config.logLevel = options.logLevel), options.open && !config.server?.open && (config.server.open = options.open), void 0 !== options.host && (config.server.host = options.host), options.port && (config.server.port = options.port), void 0 !== options.strictPort && (config.server.strictPort = options.strictPort), void 0 !== options.distPath) {
|
|
10008
10047
|
config.output ||= {};
|
|
10009
10048
|
let { distPath } = config.output;
|
|
@@ -10019,18 +10058,16 @@ let cliState = {
|
|
|
10019
10058
|
if ('boolean' != typeof sourceMap) throw Error('The "--source-map" option only accepts a boolean value.');
|
|
10020
10059
|
config.output ||= {}, config.output.sourceMap = sourceMap;
|
|
10021
10060
|
}
|
|
10022
|
-
return void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0),
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
|
|
10030
|
-
}
|
|
10031
|
-
]), config;
|
|
10061
|
+
return void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), result;
|
|
10062
|
+
}, init_restart = async ({ action })=>{
|
|
10063
|
+
let rsbuild = await init_init({
|
|
10064
|
+
isRestart: !0
|
|
10065
|
+
});
|
|
10066
|
+
return !!rsbuild && ('build' === action ? await rsbuild.build({
|
|
10067
|
+
watch: !0
|
|
10068
|
+
}) : await rsbuild.startDevServer(), !0);
|
|
10032
10069
|
};
|
|
10033
|
-
async function init_init({ isRestart
|
|
10070
|
+
async function init_init({ isRestart } = {}) {
|
|
10034
10071
|
let logger = src_logger, { options } = cliState;
|
|
10035
10072
|
try {
|
|
10036
10073
|
var envDir;
|
|
@@ -10041,90 +10078,21 @@ async function init_init({ isRestart, isBuildWatch = !1 } = {}) {
|
|
|
10041
10078
|
loadEnv: !1 !== options.env && {
|
|
10042
10079
|
cwd: (envDir = options.envDir) ? node_path.isAbsolute(envDir) ? envDir : node_path.join(root, envDir) : root,
|
|
10043
10080
|
mode: options.envMode
|
|
10044
|
-
}
|
|
10081
|
+
},
|
|
10082
|
+
restart: init_restart
|
|
10045
10083
|
});
|
|
10046
|
-
return logger = rsbuild.logger, rsbuild
|
|
10047
|
-
if ('dev' !== rsbuild.context.action && !isBuildWatch) return;
|
|
10048
|
-
let files = [], config = rsbuild.getNormalizedConfig();
|
|
10049
|
-
if (config.dev.watchFiles) for (let watchConfig of config.dev.watchFiles){
|
|
10050
|
-
if ('reload-server' !== watchConfig.type) continue;
|
|
10051
|
-
let paths = helpers_castArray(watchConfig.paths);
|
|
10052
|
-
watchConfig.options ? watchFilesForRestart({
|
|
10053
|
-
files: paths,
|
|
10054
|
-
rsbuild,
|
|
10055
|
-
isBuildWatch,
|
|
10056
|
-
watchOptions: watchConfig.options
|
|
10057
|
-
}) : files.push(...paths);
|
|
10058
|
-
}
|
|
10059
|
-
watchFilesForRestart({
|
|
10060
|
-
files,
|
|
10061
|
-
rsbuild,
|
|
10062
|
-
isBuildWatch
|
|
10063
|
-
});
|
|
10064
|
-
}), rsbuild;
|
|
10084
|
+
return logger = rsbuild.logger, rsbuild;
|
|
10065
10085
|
} catch (err) {
|
|
10066
10086
|
if (isRestart) logger.error(err);
|
|
10067
10087
|
else throw err;
|
|
10068
10088
|
}
|
|
10069
10089
|
}
|
|
10070
|
-
let cleaners = [], onBeforeRestartServer = (cleaner)=>{
|
|
10071
|
-
cleaners.push(cleaner);
|
|
10072
|
-
}, beforeRestart = async ({ filePath, clear = !0, id, logger })=>{
|
|
10073
|
-
if (clear && isTTY() && !process.env.DEBUG && process.stdout.write('\x1B[H\x1B[2J'), filePath) {
|
|
10074
|
-
let filename = node_path.basename(filePath);
|
|
10075
|
-
logger.info(`restarting ${id} as ${color.yellow(filename)} changed\n`);
|
|
10076
|
-
} else logger.info(`restarting ${id}...\n`);
|
|
10077
|
-
for (let cleaner of cleaners)await cleaner();
|
|
10078
|
-
cleaners = [];
|
|
10079
|
-
}, restartDevServer = async ({ filePath, clear = !0, logger })=>{
|
|
10080
|
-
await beforeRestart({
|
|
10081
|
-
filePath,
|
|
10082
|
-
clear,
|
|
10083
|
-
id: 'server',
|
|
10084
|
-
logger
|
|
10085
|
-
});
|
|
10086
|
-
let rsbuild = await init_init({
|
|
10087
|
-
isRestart: !0
|
|
10088
|
-
});
|
|
10089
|
-
return !!rsbuild && (await rsbuild.startDevServer(), !0);
|
|
10090
|
-
}, restartBuild = async ({ filePath, clear = !0, logger })=>{
|
|
10091
|
-
await beforeRestart({
|
|
10092
|
-
filePath,
|
|
10093
|
-
clear,
|
|
10094
|
-
id: 'build',
|
|
10095
|
-
logger
|
|
10096
|
-
});
|
|
10097
|
-
let rsbuild = await init_init({
|
|
10098
|
-
isRestart: !0,
|
|
10099
|
-
isBuildWatch: !0
|
|
10100
|
-
});
|
|
10101
|
-
return !!rsbuild && (onBeforeRestartServer((await rsbuild.build({
|
|
10102
|
-
watch: !0
|
|
10103
|
-
})).close), !0);
|
|
10104
|
-
};
|
|
10105
|
-
async function watchFilesForRestart({ files, rsbuild, isBuildWatch, watchOptions }) {
|
|
10106
|
-
if (!files.length) return;
|
|
10107
|
-
let root = rsbuild.context.rootPath, watcher = await createChokidar(files, root, {
|
|
10108
|
-
ignoreInitial: !0,
|
|
10109
|
-
ignorePermissionErrors: !0,
|
|
10110
|
-
...watchOptions
|
|
10111
|
-
}), restarting = !1, onChange = async (filePath)=>{
|
|
10112
|
-
restarting || (restarting = !0, (isBuildWatch ? await restartBuild({
|
|
10113
|
-
filePath,
|
|
10114
|
-
logger: rsbuild.logger
|
|
10115
|
-
}) : await restartDevServer({
|
|
10116
|
-
filePath,
|
|
10117
|
-
logger: rsbuild.logger
|
|
10118
|
-
})) ? await watcher.close() : rsbuild.logger.error(isBuildWatch ? 'Restart build failed.' : 'Restart server failed.'), restarting = !1);
|
|
10119
|
-
};
|
|
10120
|
-
watcher.on('add', onChange), watcher.on('change', onChange), watcher.on('unlink', onChange);
|
|
10121
|
-
}
|
|
10122
10090
|
let applyServerOptions = (command)=>{
|
|
10123
10091
|
command.option('-o, --open [url]', 'Open the page in browser on startup').option('--port <port>', 'Set the port number for the server').option('--strict-port', 'Exit if the specified port is already in use').option('--host [host]', 'Set the host that the server listens to');
|
|
10124
10092
|
};
|
|
10125
10093
|
function setupCommands(argv) {
|
|
10126
10094
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
10127
|
-
cli.version("2.1.
|
|
10095
|
+
cli.version("2.1.7"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
|
|
10128
10096
|
default: 'auto'
|
|
10129
10097
|
}).option('--dist-path <dir>', 'Set the root directory of output files').option('--source-map', 'Enable source map').option('--env-dir <dir>', 'Set the directory for loading `.env` files').option('--env-mode <mode>', 'Set the env mode to load the `.env.[mode]` file').option('--environment <name>', 'Set the environment name(s) to build', {
|
|
10130
10098
|
type: [
|
|
@@ -10148,15 +10116,13 @@ function setupCommands(argv) {
|
|
|
10148
10116
|
initCliAction('build', options);
|
|
10149
10117
|
try {
|
|
10150
10118
|
options.watch || (process.env.RSPACK_UNSAFE_FAST_DROP = 'true');
|
|
10151
|
-
let rsbuild = await init_init(
|
|
10152
|
-
isBuildWatch: options.watch
|
|
10153
|
-
});
|
|
10119
|
+
let rsbuild = await init_init();
|
|
10154
10120
|
if (!rsbuild) return;
|
|
10155
10121
|
logger = rsbuild.logger;
|
|
10156
10122
|
let buildResult = await rsbuild.build({
|
|
10157
10123
|
watch: options.watch
|
|
10158
10124
|
});
|
|
10159
|
-
|
|
10125
|
+
options.watch || await buildResult.close();
|
|
10160
10126
|
} catch (err) {
|
|
10161
10127
|
err instanceof Error && err.message === RSPACK_BUILD_ERROR || logger.error('Failed to build.'), logger.error(err), process.exit(1);
|
|
10162
10128
|
}
|
|
@@ -10183,12 +10149,15 @@ function setupCommands(argv) {
|
|
|
10183
10149
|
logger.error('Failed to inspect config.'), logger.error(err), process.exit(1);
|
|
10184
10150
|
}
|
|
10185
10151
|
}), cli.help((sections)=>{
|
|
10186
|
-
|
|
10152
|
+
sections.shift();
|
|
10153
|
+
let commandName = cli.matchedCommandName;
|
|
10154
|
+
for (let section of sections = sections.filter(({ title })=>!commandName || 'Commands' !== title && !title?.startsWith('For more info')))'Usage' === section.title && (section.body = ` ${color.yellow(`$ rsbuild ${commandName || '[command]'} [options]`)}`), 'Commands' === section.title && (section.body = section.body.replace(` ${devDescription}`, `dev ${devDescription}`)), section.title?.startsWith('For more info') ? (section.title = color.dim(' For details on a sub-command, run'), section.body = color.dim(' $ rsbuild <command> -h')) : section.title && (section.title = color.cyan(section.title));
|
|
10155
|
+
return sections;
|
|
10187
10156
|
}), cli.parse(argv);
|
|
10188
10157
|
}
|
|
10189
10158
|
function showGreeting() {
|
|
10190
10159
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
10191
|
-
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.1.
|
|
10160
|
+
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.1.7\n`);
|
|
10192
10161
|
}
|
|
10193
10162
|
function setupLogLevel(argv) {
|
|
10194
10163
|
if (argv.length <= 3) return;
|
|
@@ -10210,5 +10179,5 @@ function runCLI({ argv = process.argv } = {}) {
|
|
|
10210
10179
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
|
|
10211
10180
|
}
|
|
10212
10181
|
}
|
|
10213
|
-
let src_version = "2.1.
|
|
10182
|
+
let src_version = "2.1.7";
|
|
10214
10183
|
export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, core_rspack as rspack, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, loadConfig_loadConfig as loadConfig, loadEnv, logger_createLogger as createLogger, mergeRsbuildConfig, mrmime_lookup, runCLI, src_logger as logger, src_version as version };
|