@rsbuild/core 2.2.12 → 2.2.14
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 +10 -1
- package/compiled/@rstackjs/load-config/package.json +1 -1
- package/compiled/css-loader/index.js +2 -2
- package/compiled/html-rspack-plugin/index.d.ts +16 -2
- package/compiled/html-rspack-plugin/index.js +78 -28
- package/compiled/postcss/index.js +1 -1
- package/compiled/postcss/package.json +1 -1
- package/compiled/postcss-loader/index.js +9 -9
- package/dist/helpers/workspace.d.ts +1 -0
- package/dist/launch-editor-middleware.js +1 -1
- package/dist/m.js +272 -124
- package/dist/manifest-plugin.js +1 -1
- package/dist/plugins/fileSize.d.ts +11 -0
- package/dist/server/hostCheck.d.ts +7 -0
- package/dist/server/watchFiles.d.ts +3 -1
- package/dist/types/config.d.ts +8 -1
- package/package.json +12 -8
package/dist/m.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*! LICENSE: m.js.LICENSE.txt */
|
|
2
|
-
let
|
|
2
|
+
let runtimeInfo, swcHelpersPath, pluginHelper_htmlPlugin;
|
|
3
3
|
import { rspackRequire, moduleFactories, compatGetDefaultExport, createFakeNamespaceObject } from "./rslib-runtime.js";
|
|
4
4
|
import { rspack as core_rspack } from "@rspack/core";
|
|
5
5
|
import node_util, { format as external_node_util_format, promisify, stripVTControlCharacters } from "node:util";
|
|
6
6
|
import node_path, { dirname, isAbsolute as external_node_path_isAbsolute, join, posix, relative, resolve as external_node_path_resolve, sep } from "node:path";
|
|
7
7
|
import { builtinModules, createRequire, createRequire as __rspack_createRequire } from "node:module";
|
|
8
|
-
import node_fs, { existsSync } from "node:fs";
|
|
8
|
+
import node_fs, { existsSync, readFileSync } from "node:fs";
|
|
9
9
|
import node_os, { constants } from "node:os";
|
|
10
10
|
import node_process from "node:process";
|
|
11
11
|
import { URL as external_node_url_URL, pathToFileURL, fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
@@ -13,6 +13,7 @@ import { isPromise, isRegExp } from "node:util/types";
|
|
|
13
13
|
import { readFile } from "node:fs/promises";
|
|
14
14
|
import node_zlib, { constants as external_node_zlib_constants } from "node:zlib";
|
|
15
15
|
import { once as external_node_events_once } from "node:events";
|
|
16
|
+
import { isIP } from "node:net";
|
|
16
17
|
import { ALL_INTERFACES_IPV4, IMAGE_EXTENSIONS, ASSETS_DIST_DIR, FONT_DIST_DIR, AUDIO_EXTENSIONS, ensureAbsolutePath, NODE_MODULES_REGEX, FONT_EXTENSIONS, HMR_SOCKET_PATH, WASM_DIST_DIR, VIDEO_EXTENSIONS, BROWSER_LOG_PREFIX, toPosixPath, TRACK_EXTENSIONS, IMAGE_DIST_DIR, RSBUILD_OUTPUTS_PATH, DEFAULT_STACK_TRACE, LOADER_PATH, ASSET_EXTENSIONS, SVG_DIST_DIR, isWindows, COMPILED_PATH, WORKER_QUERY_REGEX, TS_CONFIG_FILE, dedupeNestedPaths, CSS_REGEX, relativeWithin, LAZY_COMPILATION_IDENTIFIER, DEFAULT_BROWSERSLIST, JS_REGEX, MEDIA_DIST_DIR, SCRIPT_REGEX, DEFAULT_WEB_BROWSERSLIST, getCompiledPath, normalizeRuleConditionPath, getPathnameFromUrl, toRelativePath, isDeno, CSS_DIST_DIR, INLINE_QUERY_REGEX, STATIC_PATH, RAW_QUERY_REGEX, PLUGIN_SWC_NAME, CLIENT_PATH, getCommonParentPath, LOCALHOST, JS_DIST_DIR, URL_QUERY_REGEX } from "./1.js";
|
|
17
18
|
import { cachedImport as cachedImport_cachedImport, getTinyglobby } from "./r.js";
|
|
18
19
|
var superClass, superClass1, __rspack_import_meta_filename__ = __rspack_fileURLToPath(import.meta.url);
|
|
@@ -389,8 +390,8 @@ moduleFactories.add({
|
|
|
389
390
|
return (asyncHooks.AsyncResource && (res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn')), res && res.runInAsyncScope) ? res.runInAsyncScope.bind(res, fn, null) : fn;
|
|
390
391
|
}
|
|
391
392
|
},
|
|
392
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
393
|
-
let yaml, { resolve } = __rspack_createRequire_require("node:path"), config = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/lilconfig/3.1.3/8e9a79516bf61f8427342cef50cdad2cdc2572f42288ba8053b88eadfdc0ebef/node_modules/lilconfig/src/index.js"), loadOptions = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
393
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/cbcc4ffbb08c543cea9a1ac750ccfc742d666712f0530b683d312c61ffd50060/node_modules/postcss-load-config/src/index.js" (module) {
|
|
394
|
+
let yaml, { resolve } = __rspack_createRequire_require("node:path"), config = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/lilconfig/3.1.3/8e9a79516bf61f8427342cef50cdad2cdc2572f42288ba8053b88eadfdc0ebef/node_modules/lilconfig/src/index.js"), loadOptions = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/cbcc4ffbb08c543cea9a1ac750ccfc742d666712f0530b683d312c61ffd50060/node_modules/postcss-load-config/src/options.js"), loadPlugins = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/cbcc4ffbb08c543cea9a1ac750ccfc742d666712f0530b683d312c61ffd50060/node_modules/postcss-load-config/src/plugins.js"), req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/cbcc4ffbb08c543cea9a1ac750ccfc742d666712f0530b683d312c61ffd50060/node_modules/postcss-load-config/src/req.js");
|
|
394
395
|
async function processResult(ctx, result) {
|
|
395
396
|
let obj, file = result.filepath || '', projectConfig = ((obj = result.config) && obj.__esModule ? obj : {
|
|
396
397
|
default: obj
|
|
@@ -463,8 +464,8 @@ moduleFactories.add({
|
|
|
463
464
|
});
|
|
464
465
|
};
|
|
465
466
|
},
|
|
466
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
467
|
-
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
467
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/cbcc4ffbb08c543cea9a1ac750ccfc742d666712f0530b683d312c61ffd50060/node_modules/postcss-load-config/src/options.js" (module) {
|
|
468
|
+
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/cbcc4ffbb08c543cea9a1ac750ccfc742d666712f0530b683d312c61ffd50060/node_modules/postcss-load-config/src/req.js");
|
|
468
469
|
module.exports = async function options(config, file) {
|
|
469
470
|
if (config.parser && 'string' == typeof config.parser) try {
|
|
470
471
|
config.parser = await req(config.parser, file);
|
|
@@ -484,8 +485,8 @@ moduleFactories.add({
|
|
|
484
485
|
return config;
|
|
485
486
|
};
|
|
486
487
|
},
|
|
487
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
488
|
-
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
488
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/cbcc4ffbb08c543cea9a1ac750ccfc742d666712f0530b683d312c61ffd50060/node_modules/postcss-load-config/src/plugins.js" (module) {
|
|
489
|
+
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/cbcc4ffbb08c543cea9a1ac750ccfc742d666712f0530b683d312c61ffd50060/node_modules/postcss-load-config/src/req.js");
|
|
489
490
|
async function load(plugin, options, file) {
|
|
490
491
|
try {
|
|
491
492
|
if (null == options || 0 === Object.keys(options).length) return await req(plugin, file);
|
|
@@ -501,7 +502,7 @@ moduleFactories.add({
|
|
|
501
502
|
}), list;
|
|
502
503
|
};
|
|
503
504
|
},
|
|
504
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
505
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/cbcc4ffbb08c543cea9a1ac750ccfc742d666712f0530b683d312c61ffd50060/node_modules/postcss-load-config/src/req.js" (module) {
|
|
505
506
|
let tsx, jiti, { createRequire } = __rspack_createRequire_require("node:module"), { pathToFileURL } = __rspack_createRequire_require("node:url"), TS_EXT_RE = /\.[mc]?ts$/, importError = [];
|
|
506
507
|
module.exports = async function req(name, rootFile = __rspack_import_meta_filename__) {
|
|
507
508
|
let url = createRequire(rootFile).resolve(name);
|
|
@@ -720,14 +721,14 @@ function findAllBrackets(v) {
|
|
|
720
721
|
}
|
|
721
722
|
function getMriOptions(options) {
|
|
722
723
|
let result = {
|
|
723
|
-
alias:
|
|
724
|
+
alias: Object.create(null),
|
|
724
725
|
boolean: []
|
|
725
726
|
};
|
|
726
727
|
for (let [index, option] of options.entries())option.names.length > 1 && (result.alias[option.names[0]] = option.names.slice(1)), option.isBoolean && (option.negated && options.some((o, i)=>i !== index && o.names.some((name)=>option.names.includes(name)) && "boolean" == typeof o.required) || result.boolean.push(option.names[0]));
|
|
727
728
|
return result;
|
|
728
729
|
}
|
|
729
730
|
function findLongest(arr) {
|
|
730
|
-
return arr.sort((a, b)=>
|
|
731
|
+
return arr.sort((a, b)=>b.length - a.length)[0];
|
|
731
732
|
}
|
|
732
733
|
function padRight(str, length) {
|
|
733
734
|
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
@@ -735,7 +736,13 @@ function padRight(str, length) {
|
|
|
735
736
|
function camelcase(input) {
|
|
736
737
|
return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
|
|
737
738
|
}
|
|
739
|
+
let UNSAFE_KEYS = new Set([
|
|
740
|
+
"__proto__",
|
|
741
|
+
"constructor",
|
|
742
|
+
"prototype"
|
|
743
|
+
]);
|
|
738
744
|
function setDotProp(obj, keys, val) {
|
|
745
|
+
if (keys.some((key)=>UNSAFE_KEYS.has(key))) return;
|
|
739
746
|
let current = obj;
|
|
740
747
|
for(let i = 0; i < keys.length; i++){
|
|
741
748
|
let key = keys[i];
|
|
@@ -751,12 +758,9 @@ function setDotProp(obj, keys, val) {
|
|
|
751
758
|
}
|
|
752
759
|
}
|
|
753
760
|
function setByType(obj, transforms) {
|
|
754
|
-
for (let key of Object.
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
obj[key]
|
|
758
|
-
].flat(), "function" == typeof transform.transformFunction && (obj[key] = obj[key].map(transform.transformFunction)));
|
|
759
|
-
}
|
|
761
|
+
for (let [key, transform] of Object.entries(transforms))transform.shouldTransform && key in obj && (obj[key] = [
|
|
762
|
+
obj[key]
|
|
763
|
+
].flat(), "function" == typeof transform.transformFunction && (obj[key] = obj[key].map(transform.transformFunction)));
|
|
760
764
|
}
|
|
761
765
|
function getFileName(input) {
|
|
762
766
|
let m = /([^\\/]+)$/.exec(input);
|
|
@@ -782,13 +786,16 @@ var CACError = class extends Error {
|
|
|
782
786
|
this.rawName = rawName, this.description = description, this.config = Object.assign({}, config), rawName = rawName.replaceAll(".*", ""), this.negated = !1, this.names = removeBrackets(rawName).split(",").map((v)=>{
|
|
783
787
|
let name = v.trim().replace(/^-{1,2}/, "");
|
|
784
788
|
return name.startsWith("no-") && (this.negated = !0, name = name.replace(/^no-/, "")), camelcaseOptionName(name);
|
|
785
|
-
}).sort((a, b)=>a.length
|
|
789
|
+
}).sort((a, b)=>a.length - b.length), this.name = this.names.at(-1), this.negated && null == this.config.default && (this.config.default = !0), rawName.includes("<") ? this.required = !0 : rawName.includes("[") ? this.required = !1 : this.isBoolean = !0;
|
|
786
790
|
}
|
|
787
791
|
};
|
|
788
792
|
if ("u" > typeof process) {
|
|
789
793
|
let runtimeName;
|
|
790
|
-
runtimeName = "u" > typeof Deno && "string" == typeof Deno.version?.deno ? "deno" : "u" > typeof Bun && "string" == typeof Bun.version ? "bun" : "node", runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}
|
|
794
|
+
runtimeName = "u" > typeof Deno && "string" == typeof Deno.version?.deno ? "deno" : "u" > typeof Bun && "string" == typeof Bun.version ? "bun" : "node", runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}`;
|
|
791
795
|
} else runtimeInfo = "u" < typeof navigator ? "unknown" : `${navigator.platform} ${navigator.userAgent}`;
|
|
796
|
+
function getRuntimeProcessArgs() {
|
|
797
|
+
return "u" < typeof process ? void 0 : process.argv;
|
|
798
|
+
}
|
|
792
799
|
var Command = class {
|
|
793
800
|
rawName;
|
|
794
801
|
description;
|
|
@@ -842,7 +849,7 @@ var Command = class {
|
|
|
842
849
|
return this instanceof GlobalCommand;
|
|
843
850
|
}
|
|
844
851
|
hasOption(name) {
|
|
845
|
-
return name = name.split(".")[0], this.options.find((option)=>option.names.includes(name));
|
|
852
|
+
return name = name.split(".", 1)[0], this.options.find((option)=>option.names.includes(name));
|
|
846
853
|
}
|
|
847
854
|
outputHelp() {
|
|
848
855
|
let { name, commands } = this.cli, { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand, sections = [
|
|
@@ -899,7 +906,7 @@ var Command = class {
|
|
|
899
906
|
...this.options
|
|
900
907
|
];
|
|
901
908
|
for (let option of options){
|
|
902
|
-
let value = parsedOptions[option.name.split(".")[0]];
|
|
909
|
+
let value = parsedOptions[option.name.split(".", 1)[0]];
|
|
903
910
|
if (option.required) {
|
|
904
911
|
let hasNegated = options.some((o)=>o.negated && o.names.includes(option.name));
|
|
905
912
|
if (!0 === value || !1 === value && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
@@ -961,6 +968,7 @@ var Command = class {
|
|
|
961
968
|
}
|
|
962
969
|
parse(argv, { run = !0 } = {}) {
|
|
963
970
|
if (!argv) {
|
|
971
|
+
let runtimeProcessArgs = getRuntimeProcessArgs();
|
|
964
972
|
if (!runtimeProcessArgs) throw Error("No argv provided and runtime process argv is not available.");
|
|
965
973
|
argv = runtimeProcessArgs;
|
|
966
974
|
}
|
|
@@ -1019,7 +1027,7 @@ var Command = class {
|
|
|
1019
1027
|
if (!ignoreDefault && void 0 !== cliOption.config.default) for (let name of cliOption.names)options[name] = cliOption.config.default;
|
|
1020
1028
|
Array.isArray(cliOption.config.type) && void 0 === transforms[cliOption.name] && (transforms[cliOption.name] = Object.create(null), transforms[cliOption.name].shouldTransform = !0, transforms[cliOption.name].transformFunction = cliOption.config.type[0]);
|
|
1021
1029
|
}
|
|
1022
|
-
for (let key of Object.
|
|
1030
|
+
for (let [key, value] of Object.entries(parsed))"_" !== key && (setDotProp(options, key.split("."), value), setByType(options, transforms));
|
|
1023
1031
|
return {
|
|
1024
1032
|
args,
|
|
1025
1033
|
options
|
|
@@ -2491,8 +2499,14 @@ class BrowserslistError extends Error {
|
|
|
2491
2499
|
let isFileCache = {};
|
|
2492
2500
|
function isFile(file) {
|
|
2493
2501
|
if (file in isFileCache) return isFileCache[file];
|
|
2494
|
-
|
|
2495
|
-
|
|
2502
|
+
try {
|
|
2503
|
+
let result = node_fs.existsSync(file) && node_fs.statSync(file).isFile();
|
|
2504
|
+
return isFileCache[file] = result, result;
|
|
2505
|
+
} catch (error) {
|
|
2506
|
+
let { code } = error;
|
|
2507
|
+
if ('ENOENT' === code || 'EACCES' === code || 'ERR_ACCESS_DENIED' === code) return !1;
|
|
2508
|
+
throw error;
|
|
2509
|
+
}
|
|
2496
2510
|
}
|
|
2497
2511
|
function dist_check(section) {
|
|
2498
2512
|
let FORMAT = 'Browserslist config should be a string or an array of strings with browser queries';
|
|
@@ -2506,7 +2520,7 @@ function parsePackage(file) {
|
|
|
2506
2520
|
let list = config.browserslist;
|
|
2507
2521
|
for(let i in Array.isArray(list) && (list = {
|
|
2508
2522
|
defaults: list
|
|
2509
|
-
}), 'string' == typeof list && (list = parseConfig(list)), list)dist_check(list[i]);
|
|
2523
|
+
}), 'string' == typeof list && (list = parseConfig(list)), list)dist_check(list[i]), 'string' == typeof list[i] && (list[i] = parseConfig(list[i]).defaults);
|
|
2510
2524
|
return list;
|
|
2511
2525
|
}
|
|
2512
2526
|
let IS_SECTION = /^\s*\[(.+)]\s*$/;
|
|
@@ -2730,6 +2744,7 @@ let OVERRIDE_PATHS = new Set([
|
|
|
2730
2744
|
server: {
|
|
2731
2745
|
port: 3000,
|
|
2732
2746
|
host: LOCALHOST,
|
|
2747
|
+
allowedHosts: !0,
|
|
2733
2748
|
open: !1,
|
|
2734
2749
|
base: '/',
|
|
2735
2750
|
htmlFallback: 'index',
|
|
@@ -3298,7 +3313,7 @@ function createPublicContext(context) {
|
|
|
3298
3313
|
async function createContext(options, userConfig, logger, loadConfigResult) {
|
|
3299
3314
|
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();
|
|
3300
3315
|
return {
|
|
3301
|
-
version: "2.2.
|
|
3316
|
+
version: "2.2.14",
|
|
3302
3317
|
rootPath,
|
|
3303
3318
|
configFile: loadConfigResult?.filePath ?? userConfig._privateMeta?.configFilePath,
|
|
3304
3319
|
configFileDependencies: loadConfigResult?.dependencies ?? userConfig._privateMeta?.configFileDependencies ?? [],
|
|
@@ -4109,9 +4124,9 @@ let getChokidar = cachedImport_cachedImport(()=>import("./chokidar.js").then((m)
|
|
|
4109
4124
|
'unlink'
|
|
4110
4125
|
];
|
|
4111
4126
|
async function setupWatchFiles(options) {
|
|
4112
|
-
let { config, root, buildManager } = options, { hmr, liveReload } = config.dev;
|
|
4127
|
+
let { config, root, logger, buildManager } = options, { hmr, liveReload } = config.dev;
|
|
4113
4128
|
if (!hmr && !liveReload || !buildManager) return;
|
|
4114
|
-
let closeDevFilesWatcher = await watchDevFiles(config.dev, buildManager, root), serverFilesWatcher = await watchServerFiles(config.server, buildManager, root);
|
|
4129
|
+
let closeDevFilesWatcher = await watchDevFiles(config.dev, buildManager, root, logger), serverFilesWatcher = await watchServerFiles(config.server, buildManager, root, logger);
|
|
4115
4130
|
return {
|
|
4116
4131
|
async close () {
|
|
4117
4132
|
await Promise.all([
|
|
@@ -4121,22 +4136,22 @@ async function setupWatchFiles(options) {
|
|
|
4121
4136
|
}
|
|
4122
4137
|
};
|
|
4123
4138
|
}
|
|
4124
|
-
async function watchDevFiles(devConfig, buildManager, root) {
|
|
4139
|
+
async function watchDevFiles(devConfig, buildManager, root, logger) {
|
|
4125
4140
|
let { watchFiles } = devConfig;
|
|
4126
4141
|
if (!watchFiles) return;
|
|
4127
4142
|
let watchers = [];
|
|
4128
4143
|
for (let { paths, events, options, type } of helpers_castArray(watchFiles)){
|
|
4129
|
-
let watchOptions = prepareWatchOptions(paths, options, type, events), watcher = await startWatchFiles(watchOptions, buildManager, root);
|
|
4144
|
+
let watchOptions = prepareWatchOptions(paths, options, type, events), watcher = await startWatchFiles(watchOptions, buildManager, root, logger);
|
|
4130
4145
|
watcher && watchers.push(watcher);
|
|
4131
4146
|
}
|
|
4132
4147
|
return async ()=>{
|
|
4133
4148
|
for (let watcher of watchers)await watcher.close();
|
|
4134
4149
|
};
|
|
4135
4150
|
}
|
|
4136
|
-
function watchServerFiles({ publicDir }, buildManager, root) {
|
|
4151
|
+
function watchServerFiles({ publicDir }, buildManager, root, logger) {
|
|
4137
4152
|
if (!publicDir.length) return;
|
|
4138
4153
|
let watchPaths = publicDir.filter((item)=>item.watch).map((item)=>item.name);
|
|
4139
|
-
if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths), buildManager, root);
|
|
4154
|
+
if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths), buildManager, root, logger);
|
|
4140
4155
|
}
|
|
4141
4156
|
function prepareWatchOptions(paths, options = {}, type, events) {
|
|
4142
4157
|
return {
|
|
@@ -4149,7 +4164,7 @@ function prepareWatchOptions(paths, options = {}, type, events) {
|
|
|
4149
4164
|
};
|
|
4150
4165
|
}
|
|
4151
4166
|
let GLOB_REGEX = /[*?{}[\]()!+|]/;
|
|
4152
|
-
async function createChokidar(pathOrGlobs, root, options) {
|
|
4167
|
+
async function createChokidar(pathOrGlobs, root, options, logger) {
|
|
4153
4168
|
let { default: chokidar } = await getChokidar(), watchFiles = new Set(), globPatterns = pathOrGlobs.filter((pathOrGlob)=>!!GLOB_REGEX.test(pathOrGlob) || (watchFiles.add(pathOrGlob), !1));
|
|
4154
4169
|
if (globPatterns.length) {
|
|
4155
4170
|
let { glob } = await getTinyglobby();
|
|
@@ -4158,14 +4173,17 @@ async function createChokidar(pathOrGlobs, root, options) {
|
|
|
4158
4173
|
absolute: !0
|
|
4159
4174
|
})))watchFiles.add(file);
|
|
4160
4175
|
}
|
|
4161
|
-
|
|
4176
|
+
let watcher = chokidar.watch(Array.from(watchFiles), options);
|
|
4177
|
+
return watcher.on('error', (error)=>{
|
|
4178
|
+
logger.error('File watcher error:', error);
|
|
4179
|
+
}), watcher;
|
|
4162
4180
|
}
|
|
4163
|
-
async function startWatchFiles({ paths, events, options, type = 'reload-page' }, buildManager, root) {
|
|
4181
|
+
async function startWatchFiles({ paths, events, options, type = 'reload-page' }, buildManager, root, logger) {
|
|
4164
4182
|
if ('reload-page' !== type || events?.length === 0) return;
|
|
4165
4183
|
let watcher = await createChokidar(paths, root, {
|
|
4166
4184
|
ignoreInitial: !0,
|
|
4167
4185
|
...options
|
|
4168
|
-
}), reloadPage = ()=>{
|
|
4186
|
+
}, logger), reloadPage = ()=>{
|
|
4169
4187
|
buildManager.socketServer.sendMessage({
|
|
4170
4188
|
type: 'full-reload'
|
|
4171
4189
|
});
|
|
@@ -4229,13 +4247,13 @@ function watchFilesForRestart({ watchFiles, context, restartContext }) {
|
|
|
4229
4247
|
ignoreInitial: !0,
|
|
4230
4248
|
ignorePermissionErrors: !0,
|
|
4231
4249
|
...options
|
|
4232
|
-
}), cwd = options?.cwd ?? root;
|
|
4250
|
+
}, logger), cwd = options?.cwd ?? root;
|
|
4233
4251
|
for (let event of events ? new Set(events) : DEFAULT_WATCH_FILE_EVENTS)watcher.on(event, (filePath)=>onWatchEvent(event, filePath, cwd));
|
|
4234
4252
|
return watcher;
|
|
4235
4253
|
} catch (error) {
|
|
4236
4254
|
logger.error(error);
|
|
4237
4255
|
}
|
|
4238
|
-
})), close = ()=>(closePromise || (closePromise = watchersPromise.then((watchers)=>Promise.all(watchers.map((watcher)=>watcher
|
|
4256
|
+
})), close = ()=>(closePromise || (closePromise = watchersPromise.then((watchers)=>Promise.all(watchers.filter((watcher)=>void 0 !== watcher).map((watcher)=>watcher.close()))).then(()=>{})), closePromise);
|
|
4239
4257
|
return {
|
|
4240
4258
|
close
|
|
4241
4259
|
};
|
|
@@ -4885,7 +4903,25 @@ let normalizeCleanDistPath = (userOptions)=>{
|
|
|
4885
4903
|
...defaultOptions,
|
|
4886
4904
|
...userOptions
|
|
4887
4905
|
};
|
|
4888
|
-
}
|
|
4906
|
+
};
|
|
4907
|
+
function findWorkspaceRoot(root) {
|
|
4908
|
+
let packageRoot, current = root;
|
|
4909
|
+
for(;;){
|
|
4910
|
+
if (isFileSync(join(current, 'pnpm-workspace.yaml')) || isFileSync(join(current, 'lerna.json'))) return current;
|
|
4911
|
+
let packageJson = join(current, 'package.json');
|
|
4912
|
+
if (isFileSync(packageJson)) {
|
|
4913
|
+
packageRoot ??= current;
|
|
4914
|
+
try {
|
|
4915
|
+
let pkg = JSON.parse(readFileSync(packageJson, 'utf8'));
|
|
4916
|
+
if (pkg?.workspaces) return current;
|
|
4917
|
+
} catch {}
|
|
4918
|
+
}
|
|
4919
|
+
let parent = dirname(current);
|
|
4920
|
+
if (parent === current) return packageRoot ?? root;
|
|
4921
|
+
current = parent;
|
|
4922
|
+
}
|
|
4923
|
+
}
|
|
4924
|
+
let getConsolePureFuncs = (methods)=>methods.map((method)=>`console.${method}`), ALL_CONSOLE_PURE_FUNCS = getConsolePureFuncs([
|
|
4889
4925
|
'assert',
|
|
4890
4926
|
'clear',
|
|
4891
4927
|
'count',
|
|
@@ -4945,7 +4981,7 @@ function parseMinifyOptions(config) {
|
|
|
4945
4981
|
cssOptions: minify.cssOptions
|
|
4946
4982
|
};
|
|
4947
4983
|
}
|
|
4948
|
-
var postcss_load_config_src_default = compatGetDefaultExport(rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
4984
|
+
var postcss_load_config_src_default = compatGetDefaultExport(rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/cbcc4ffbb08c543cea9a1ac750ccfc742d666712f0530b683d312c61ffd50060/node_modules/postcss-load-config/src/index.js"));
|
|
4949
4985
|
async function getLightningCSSLoaderOptions(config, targets, minify) {
|
|
4950
4986
|
let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
|
|
4951
4987
|
targets,
|
|
@@ -4968,7 +5004,9 @@ let clonePostCSSConfig = (config)=>({
|
|
|
4968
5004
|
async function loadUserPostcssrc(root, postcssrcCache) {
|
|
4969
5005
|
let cached = postcssrcCache.get(root);
|
|
4970
5006
|
if (cached) return clonePostCSSConfig(await cached);
|
|
4971
|
-
let promise = postcss_load_config_src_default()({}, root
|
|
5007
|
+
let promise = postcss_load_config_src_default()({}, root, {
|
|
5008
|
+
stopDir: findWorkspaceRoot(root)
|
|
5009
|
+
}).catch((err)=>{
|
|
4972
5010
|
if (err.message?.includes('No PostCSS Config found')) return {};
|
|
4973
5011
|
throw err;
|
|
4974
5012
|
});
|
|
@@ -5130,6 +5168,31 @@ function pluginExternals() {
|
|
|
5130
5168
|
}
|
|
5131
5169
|
};
|
|
5132
5170
|
}
|
|
5171
|
+
function createAssetProcessor() {
|
|
5172
|
+
let failure, active = 0, waiting = [];
|
|
5173
|
+
return async (names, processAsset)=>{
|
|
5174
|
+
let cursor = 0, consume = async ()=>{
|
|
5175
|
+
for(; cursor < names.length && !failure;){
|
|
5176
|
+
let index = cursor++;
|
|
5177
|
+
active >= 16 ? await new Promise((resolve)=>waiting.push(resolve)) : active++;
|
|
5178
|
+
try {
|
|
5179
|
+
if (failure) return;
|
|
5180
|
+
await processAsset(names[index], index);
|
|
5181
|
+
} catch (error) {
|
|
5182
|
+
failure ??= {
|
|
5183
|
+
error
|
|
5184
|
+
};
|
|
5185
|
+
} finally{
|
|
5186
|
+
let next = waiting.shift();
|
|
5187
|
+
next ? next() : active--;
|
|
5188
|
+
}
|
|
5189
|
+
}
|
|
5190
|
+
};
|
|
5191
|
+
if (await Promise.all(Array.from({
|
|
5192
|
+
length: Math.min(16, names.length)
|
|
5193
|
+
}, consume)), failure) throw failure.error;
|
|
5194
|
+
};
|
|
5195
|
+
}
|
|
5133
5196
|
function getCompression(compressed) {
|
|
5134
5197
|
let { type = 'gzip', level = 6 } = 'object' == typeof compressed ? compressed : {};
|
|
5135
5198
|
return 'brotli' === type ? {
|
|
@@ -5210,11 +5273,30 @@ function getHeader(maxFileLength, maxSizeLength, fileHeader, compressionHeader)
|
|
|
5210
5273
|
let calcFileSize = (len)=>{
|
|
5211
5274
|
let val = len / 1000;
|
|
5212
5275
|
return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
|
|
5213
|
-
}, COMPRESSIBLE_REGEX = /\.(?:js|mjs|cjs|jsx|ts|tsx|mts|cts|css|html|json|svg|txt|xml|xhtml|wasm|manifest|md)$/i
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
};
|
|
5217
|
-
|
|
5276
|
+
}, COMPRESSIBLE_REGEX = /\.(?:js|mjs|cjs|jsx|ts|tsx|mts|cts|css|html|json|svg|txt|xml|xhtml|wasm|manifest|md)$/i;
|
|
5277
|
+
async function getFileSizes(options, compilation, processAssets) {
|
|
5278
|
+
if (!1 === options.detail && !1 === options.total) return [];
|
|
5279
|
+
let { exclude, include } = options, compression = getCompression(options.compressed), fileSizes = [], compilationAssets = compilation.assets, names = Object.getOwnPropertyNames(compilationAssets);
|
|
5280
|
+
return await processAssets(names, async (assetName, index)=>{
|
|
5281
|
+
let queryIndex, filePath = -1 === (queryIndex = assetName.indexOf('?')) ? assetName : assetName.slice(0, queryIndex);
|
|
5282
|
+
if (!exclude && EXCLUDE_ASSET_REGEX.test(filePath)) return;
|
|
5283
|
+
let value = compilationAssets[assetName], content = options.compressed && COMPRESSIBLE_REGEX.test(filePath) ? value.buffer() : void 0, size = void 0 === content ? value.size() : content.length;
|
|
5284
|
+
if (exclude || include) {
|
|
5285
|
+
let publicAsset = {
|
|
5286
|
+
name: filePath,
|
|
5287
|
+
size
|
|
5288
|
+
};
|
|
5289
|
+
if (exclude?.(publicAsset) || include && !include(publicAsset)) return;
|
|
5290
|
+
}
|
|
5291
|
+
let compressedSize = void 0 === content ? null : await calcCompressedSize(content, compression.type, compression.level);
|
|
5292
|
+
fileSizes[index] = {
|
|
5293
|
+
filePath,
|
|
5294
|
+
size,
|
|
5295
|
+
compressedSize
|
|
5296
|
+
};
|
|
5297
|
+
}), fileSizes.filter(Boolean);
|
|
5298
|
+
}
|
|
5299
|
+
function printFileSizes(options, fileSizes, rootPath, distPath, environmentName, previousSizes, saveSnapshot) {
|
|
5218
5300
|
let logs = [], compression = getCompression(options.compressed), prev = previousSizes?.[environmentName], showDetail = !1 !== options.detail, showDiff = !1 !== options.diff && null !== previousSizes, prevType = prev?.compressionType ?? (!!prev?.totalGzipSize && 'gzip'), showCompressedDiff = showDiff && prevType === compression.type, showTotal = !1 !== options.total;
|
|
5219
5301
|
if (!showTotal && !showDetail) return {
|
|
5220
5302
|
logs
|
|
@@ -5224,52 +5306,45 @@ async function printFileSizes(options, stats, rootPath, distPath, environmentNam
|
|
|
5224
5306
|
totalSize: 0,
|
|
5225
5307
|
totalGzipSize: 0,
|
|
5226
5308
|
compressionType: !!options.compressed && compression.type
|
|
5227
|
-
} : null,
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
compressedSize,
|
|
5254
|
-
compressedSizeLabel
|
|
5255
|
-
};
|
|
5256
|
-
}, getAssets = async ()=>{
|
|
5257
|
-
let { exclude, include } = options, formattedAssets = [], compilationAssets = stats.compilation.assets;
|
|
5258
|
-
for (let assetName of Object.keys(compilationAssets)){
|
|
5259
|
-
let filePath = getFilePath(assetName);
|
|
5260
|
-
if (!exclude && EXCLUDE_ASSET_REGEX.test(filePath)) continue;
|
|
5261
|
-
let value = compilationAssets[assetName], content = options.compressed && isCompressible(filePath) ? value.source() : void 0, size = void 0 === content ? value.size() : Buffer.byteLength(content);
|
|
5262
|
-
if (exclude || include) {
|
|
5263
|
-
let publicAsset = {
|
|
5264
|
-
name: filePath,
|
|
5265
|
-
size
|
|
5266
|
-
};
|
|
5267
|
-
if (exclude?.(publicAsset) || include && !include(publicAsset)) continue;
|
|
5309
|
+
} : null, assets = fileSizes.map(({ filePath, size, compressedSize })=>((filePath, size, compressedSize)=>{
|
|
5310
|
+
let normalizedPath = '';
|
|
5311
|
+
if ((snapshot || showDetail && showDiff) && (normalizedPath = normalizeFilePath(filePath), snapshot && (snapshot.files[normalizedPath] = {
|
|
5312
|
+
size,
|
|
5313
|
+
[compression.sizeKey]: compressedSize ?? void 0
|
|
5314
|
+
})), !showDetail) return {
|
|
5315
|
+
filePath,
|
|
5316
|
+
filenameLabel: '',
|
|
5317
|
+
filenameLength: 0,
|
|
5318
|
+
size,
|
|
5319
|
+
sizeLabel: '',
|
|
5320
|
+
sizeLabelLength: 0,
|
|
5321
|
+
compressedSize,
|
|
5322
|
+
compressedSizeLabel: null
|
|
5323
|
+
};
|
|
5324
|
+
let sizeLabel = calcFileSize(size), sizeLabelLength = sizeLabel.length, compressedSizeLabel = compressedSize ? getAssetColor(compressedSize)(calcFileSize(compressedSize)) : null;
|
|
5325
|
+
if (showDiff) {
|
|
5326
|
+
let sizeData = prev?.files[normalizedPath], sizeDiff = size - (sizeData?.size ?? 0);
|
|
5327
|
+
if (isSignificantDiff(sizeDiff)) {
|
|
5328
|
+
let { label, length } = formatDiff(sizeDiff);
|
|
5329
|
+
sizeLabel += ` ${label}`, sizeLabelLength += length + 1;
|
|
5330
|
+
}
|
|
5331
|
+
if (null !== compressedSize && showCompressedDiff) {
|
|
5332
|
+
let compressedDiff = compressedSize - (sizeData?.[compression.sizeKey] ?? 0);
|
|
5333
|
+
isSignificantDiff(compressedDiff) && (compressedSizeLabel += ` ${formatDiff(compressedDiff).label}`);
|
|
5334
|
+
}
|
|
5268
5335
|
}
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5336
|
+
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);
|
|
5337
|
+
return {
|
|
5338
|
+
filePath,
|
|
5339
|
+
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)),
|
|
5340
|
+
filenameLength: folderLabel.length + filename.length,
|
|
5341
|
+
size,
|
|
5342
|
+
sizeLabel,
|
|
5343
|
+
sizeLabelLength,
|
|
5344
|
+
compressedSize,
|
|
5345
|
+
compressedSizeLabel
|
|
5346
|
+
};
|
|
5347
|
+
})(filePath, size, compressedSize)).sort((a, b)=>a.size - b.size);
|
|
5273
5348
|
if (0 === assets.length) return {
|
|
5274
5349
|
logs
|
|
5275
5350
|
};
|
|
@@ -5353,7 +5428,18 @@ async function printFileSizes(options, stats, rootPath, distPath, environmentNam
|
|
|
5353
5428
|
snapshot
|
|
5354
5429
|
};
|
|
5355
5430
|
}
|
|
5356
|
-
let
|
|
5431
|
+
let fileSize_normalizeConfig = (config)=>{
|
|
5432
|
+
let { printFileSize } = config.performance, defaultConfig = {
|
|
5433
|
+
total: !0,
|
|
5434
|
+
detail: !0,
|
|
5435
|
+
diff: !1,
|
|
5436
|
+
compressed: 'node' !== config.output.target
|
|
5437
|
+
};
|
|
5438
|
+
return !0 === printFileSize ? defaultConfig : {
|
|
5439
|
+
...defaultConfig,
|
|
5440
|
+
...printFileSize
|
|
5441
|
+
};
|
|
5442
|
+
}, isNonceTag = (tag)=>"script" === tag.tag || 'style' === tag.tag || 'link' === tag.tag && tag.attrs?.rel === 'preload' && tag.attrs?.as === "script", entryNameSymbol = Symbol('entryName'), VOID_TAGS = [
|
|
5357
5443
|
'area',
|
|
5358
5444
|
'base',
|
|
5359
5445
|
'br',
|
|
@@ -5638,7 +5724,7 @@ async function getMetaTags(entryName, config, templateContent) {
|
|
|
5638
5724
|
entryName
|
|
5639
5725
|
}
|
|
5640
5726
|
});
|
|
5641
|
-
return templateContent && metaTags.charset && /<meta[^>]
|
|
5727
|
+
return templateContent && metaTags.charset && /<meta\b(?:[^>"']|"[^"]*"|'[^']*')*?\scharset\s*=/i.test(templateContent) && delete metaTags.charset, metaTags;
|
|
5642
5728
|
}
|
|
5643
5729
|
function getTemplateParameters(entryName, config, assetPrefix) {
|
|
5644
5730
|
return async (compilation, assets, assetTags, pluginOptions)=>{
|
|
@@ -5805,7 +5891,7 @@ let getPort = async ({ host, port, strictPort, tryLimits = 20 })=>{
|
|
|
5805
5891
|
});
|
|
5806
5892
|
});
|
|
5807
5893
|
} catch (e) {
|
|
5808
|
-
if ('EADDRINUSE' !== e.code) throw e;
|
|
5894
|
+
if (!(e instanceof Error) || !('code' in e) || 'EADDRINUSE' !== e.code) throw e;
|
|
5809
5895
|
port++, attempts++;
|
|
5810
5896
|
}
|
|
5811
5897
|
if (!found) throw Error(`${color.dim('[rsbuild:server]')} Failed to find an available port after ${tryLimits + 1} attempts, starting from ${color.yellow(original)}.`);
|
|
@@ -6005,7 +6091,7 @@ function doesChunkBelongToHtml({ chunk, htmlPluginData }) {
|
|
|
6005
6091
|
let { options } = htmlPluginData.plugin;
|
|
6006
6092
|
return recursiveChunkEntryNames(chunk).some((chunkName)=>isChunksFiltered(chunkName, options?.chunks, options?.excludeChunks));
|
|
6007
6093
|
}
|
|
6008
|
-
let getManifestPlugin = cachedImport_cachedImport(()=>import("./manifest-plugin.js").then(rspackRequire.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/rspack-manifest-plugin/5.2.2/
|
|
6094
|
+
let getManifestPlugin = cachedImport_cachedImport(()=>import("./manifest-plugin.js").then(rspackRequire.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/rspack-manifest-plugin/5.2.2/cbeeb1bf16831c5d12121244c2e0e825d7a61324a587214ca9e44e464c6b1496/node_modules/rspack-manifest-plugin/dist/index.js"))), isCSSPath = (filePath)=>filePath.endsWith('.css');
|
|
6009
6095
|
function normalizeManifestObjectConfig(manifest) {
|
|
6010
6096
|
let defaultOptions = {
|
|
6011
6097
|
prefix: !0,
|
|
@@ -7718,7 +7804,10 @@ function formatProxyOptions(proxyOptions, logger) {
|
|
|
7718
7804
|
async function createProxyMiddleware(proxyOptions, logger) {
|
|
7719
7805
|
let formattedOptions = formatProxyOptions(proxyOptions, logger), proxyMiddlewares = [], middlewares = [], { createProxyMiddleware: baseMiddleware } = await import("./http-proxy-middleware.js");
|
|
7720
7806
|
for (let opts of formattedOptions){
|
|
7721
|
-
let proxyMiddleware = baseMiddleware(
|
|
7807
|
+
let proxyMiddleware = baseMiddleware({
|
|
7808
|
+
...opts,
|
|
7809
|
+
ws: !1
|
|
7810
|
+
}), middleware = async (req, res, next)=>{
|
|
7722
7811
|
let bypassUrl = 'function' == typeof opts.bypass ? await opts.bypass(req, res, opts) : null;
|
|
7723
7812
|
!1 === bypassUrl ? (res.statusCode = 404, next()) : 'string' == typeof bypassUrl ? (req.url = bypassUrl, next()) : !0 === bypassUrl ? next() : proxyMiddleware(req, res, next);
|
|
7724
7813
|
};
|
|
@@ -7755,7 +7844,7 @@ let applyDefaultMiddlewares = async ({ config, buildManager, context, devServer,
|
|
|
7755
7844
|
})), middlewares.use('/__open-in-editor', async (req, res, next)=>{
|
|
7756
7845
|
try {
|
|
7757
7846
|
(await (launchEditorHandlerPromise ??= (async ()=>{
|
|
7758
|
-
let { default: launchEditorMiddleware } = await import("./launch-editor-middleware.js").then(createFakeNamespaceObject.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/launch-editor-middleware/2.14.
|
|
7847
|
+
let { default: launchEditorMiddleware } = await import("./launch-editor-middleware.js").then(createFakeNamespaceObject.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/launch-editor-middleware/2.14.2/46c81dbb0ad4cd8f776539a7cfaa5ea6144007363b919f05970ca6624282dcce/node_modules/launch-editor-middleware/index.js", 23));
|
|
7759
7848
|
return launchEditorMiddleware();
|
|
7760
7849
|
})()))(req, res, next);
|
|
7761
7850
|
} catch (err) {
|
|
@@ -7841,7 +7930,7 @@ let applyDefaultMiddlewares = async ({ config, buildManager, context, devServer,
|
|
|
7841
7930
|
dev: !0
|
|
7842
7931
|
});
|
|
7843
7932
|
middlewares.use(function publicDirMiddleware(req, res, next) {
|
|
7844
|
-
sirvMiddleware(req, res, next);
|
|
7933
|
+
req.method && 'GET' !== req.method && 'HEAD' !== req.method ? next() : sirvMiddleware(req, res, next);
|
|
7845
7934
|
});
|
|
7846
7935
|
}
|
|
7847
7936
|
}
|
|
@@ -8170,7 +8259,44 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
|
8170
8259
|
}
|
|
8171
8260
|
let { createServer } = await import("node:http");
|
|
8172
8261
|
return createServer(middlewares);
|
|
8173
|
-
},
|
|
8262
|
+
}, HOST_CHECK_ERROR = 'Blocked request: disallowed or invalid Host header. To allow a trusted hostname, add it to server.allowedHosts.';
|
|
8263
|
+
function createHostCheckMiddleware(allowedHosts) {
|
|
8264
|
+
return (req, res, next)=>{
|
|
8265
|
+
isRequestHostAllowed(req.headers, allowedHosts) ? next() : (res.writeHead(403, {
|
|
8266
|
+
'Content-Type': 'text/plain; charset=utf-8'
|
|
8267
|
+
}), res.end(HOST_CHECK_ERROR));
|
|
8268
|
+
};
|
|
8269
|
+
}
|
|
8270
|
+
function withHostCheck(onUpgrade, allowedHosts) {
|
|
8271
|
+
return (req, socket, head)=>{
|
|
8272
|
+
if (!isRequestHostAllowed(req.headers, allowedHosts)) {
|
|
8273
|
+
socket.end(`HTTP/1.1 403 Forbidden\r\nConnection: close\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: ${Buffer.byteLength(HOST_CHECK_ERROR)}\r\n\r\n` + HOST_CHECK_ERROR), socket.destroySoon();
|
|
8274
|
+
return;
|
|
8275
|
+
}
|
|
8276
|
+
onUpgrade(req, socket, head);
|
|
8277
|
+
};
|
|
8278
|
+
}
|
|
8279
|
+
function isRequestHostAllowed(headers, allowedHosts) {
|
|
8280
|
+
let { host, ':authority': authority } = headers;
|
|
8281
|
+
if (void 0 !== authority && void 0 !== host && authority !== host) return !1;
|
|
8282
|
+
let hostHeader = authority ?? host;
|
|
8283
|
+
return 'string' == typeof hostHeader && isHostAllowed(hostHeader, allowedHosts);
|
|
8284
|
+
}
|
|
8285
|
+
let normalizeHostname = (hostname)=>hostname.toLowerCase().replace(/\.$/, '');
|
|
8286
|
+
function isHostAllowed(hostHeader, allowedHosts) {
|
|
8287
|
+
let hostname;
|
|
8288
|
+
if (!hostHeader || /[\s/@\\?#%]/.test(hostHeader)) return !1;
|
|
8289
|
+
try {
|
|
8290
|
+
hostname = normalizeHostname(new URL(`http://${hostHeader}`).hostname);
|
|
8291
|
+
} catch {
|
|
8292
|
+
return !1;
|
|
8293
|
+
}
|
|
8294
|
+
return !!(hostname.startsWith('[') || isIP(hostname) || 'localhost' === hostname || hostname.endsWith('.localhost')) || allowedHosts.some((allowedHost)=>{
|
|
8295
|
+
let normalized = normalizeHostname(allowedHost);
|
|
8296
|
+
return hostname === normalized || normalized.startsWith('.') && (hostname === normalized.slice(1) || hostname.endsWith(normalized));
|
|
8297
|
+
});
|
|
8298
|
+
}
|
|
8299
|
+
let getPublicPathname = (publicPath)=>'auto' === publicPath || '' === publicPath ? '' : getPathnameFromUrl(publicPath.endsWith('/') ? publicPath : `${publicPath}/`), getPublicPathnames = (publicPaths, base)=>publicPaths.map(getPublicPathname).map((prefix)=>base && '/' !== base ? removeBasePath(prefix, base) : prefix);
|
|
8174
8300
|
async function applyServerSetup(setup, context) {
|
|
8175
8301
|
let postCallbacks = [];
|
|
8176
8302
|
for (let handler of helpers_castArray(setup || [])){
|
|
@@ -8356,7 +8482,12 @@ async function devServer_createDevServer(options, createCompiler, config, devSer
|
|
|
8356
8482
|
}
|
|
8357
8483
|
};
|
|
8358
8484
|
});
|
|
8359
|
-
let { connect } = await import("./connect-next.js"), middlewares = connect(),
|
|
8485
|
+
let { connect } = await import("./connect-next.js"), middlewares = connect(), allowedHosts = !0 === config.server.allowedHosts ? void 0 : [
|
|
8486
|
+
...config.server.allowedHosts,
|
|
8487
|
+
host
|
|
8488
|
+
];
|
|
8489
|
+
allowedHosts && middlewares.use(createHostCheckMiddleware(allowedHosts));
|
|
8490
|
+
let httpServer = middlewareMode ? null : await createHttpServer({
|
|
8360
8491
|
serverConfig: config.server,
|
|
8361
8492
|
middlewares
|
|
8362
8493
|
}), devServer = {
|
|
@@ -8415,6 +8546,7 @@ async function devServer_createDevServer(options, createCompiler, config, devSer
|
|
|
8415
8546
|
];
|
|
8416
8547
|
return runCompile ? context.hooks.onBeforeCreateCompiler.tapOnce(beforeCreateCompiler) : await beforeCreateCompiler(), state.buildManager = runCompile ? await startCompile() : void 0, state.fileWatcher = await setupWatchFiles({
|
|
8417
8548
|
config,
|
|
8549
|
+
logger,
|
|
8418
8550
|
buildManager: state.buildManager,
|
|
8419
8551
|
root: context.rootPath
|
|
8420
8552
|
}), state.devMiddlewares = await getDevMiddlewares({
|
|
@@ -8423,14 +8555,19 @@ async function devServer_createDevServer(options, createCompiler, config, devSer
|
|
|
8423
8555
|
devServer,
|
|
8424
8556
|
context,
|
|
8425
8557
|
postCallbacks
|
|
8426
|
-
}), state.buildManager?.watch(), unregisterRestart = context.restartManager.registerCleanup(closeServerResources), state.restartWatcher = watchFilesForRestart({
|
|
8558
|
+
}), allowedHosts && (state.devMiddlewares.onUpgrade = withHostCheck(state.devMiddlewares.onUpgrade, allowedHosts)), state.buildManager?.watch(), unregisterRestart = context.restartManager.registerCleanup(closeServerResources), state.restartWatcher = watchFilesForRestart({
|
|
8427
8559
|
watchFiles: config.dev.watchFiles,
|
|
8428
8560
|
context,
|
|
8429
8561
|
restartContext
|
|
8430
8562
|
}), logger.debug('create dev server done'), devServer;
|
|
8431
8563
|
}
|
|
8432
8564
|
async function startPreviewServer(context, config, { getPortSilently } = {}) {
|
|
8433
|
-
let cleanupCliShortcuts, { 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,
|
|
8565
|
+
let cleanupCliShortcuts, { 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, allowedHosts = !0 === serverConfig.allowedHosts ? void 0 : [
|
|
8566
|
+
...serverConfig.allowedHosts,
|
|
8567
|
+
host
|
|
8568
|
+
];
|
|
8569
|
+
allowedHosts && middlewares.use(createHostCheckMiddleware(allowedHosts));
|
|
8570
|
+
let assetPrefixes = context.environmentList.map((environment)=>environment.config.output.assetPrefix);
|
|
8434
8571
|
context.publicPathnames = getPublicPathnames(assetPrefixes, base);
|
|
8435
8572
|
let protocol = serverConfig.https ? 'https' : 'http', routes = getRoutes(context), urls = await getAddressUrls({
|
|
8436
8573
|
protocol,
|
|
@@ -8489,7 +8626,7 @@ async function startPreviewServer(context, config, { getPortSilently } = {}) {
|
|
|
8489
8626
|
}), proxy) {
|
|
8490
8627
|
let { middlewares: proxyMiddlewares, upgrade } = await createProxyMiddleware(proxy, logger);
|
|
8491
8628
|
for (let middleware of proxyMiddlewares)middlewares.use(middleware);
|
|
8492
|
-
httpServer.on('upgrade', upgrade);
|
|
8629
|
+
httpServer.on('upgrade', allowedHosts ? withHostCheck(upgrade, allowedHosts) : upgrade);
|
|
8493
8630
|
}
|
|
8494
8631
|
for (let callback of (compress && middlewares.use(gzipMiddleware_gzipMiddleware({
|
|
8495
8632
|
level: external_node_zlib_constants.Z_DEFAULT_COMPRESSION,
|
|
@@ -8771,27 +8908,31 @@ function applyDefaultPlugins(pluginManager, context) {
|
|
|
8771
8908
|
{
|
|
8772
8909
|
name: 'rsbuild:file-size',
|
|
8773
8910
|
setup (api) {
|
|
8774
|
-
|
|
8911
|
+
let fileSizeResults, processAssets;
|
|
8912
|
+
api.onBeforeBuild(({ isFirstCompile })=>{
|
|
8913
|
+
fileSizeResults = isFirstCompile ? [] : void 0, processAssets = isFirstCompile ? createAssetProcessor() : void 0;
|
|
8914
|
+
}), api.onAfterCreateCompiler(({ compiler })=>{
|
|
8915
|
+
'build' === context.action && applyToCompiler(compiler, (compiler, index)=>{
|
|
8916
|
+
let { config } = context.environmentList[index];
|
|
8917
|
+
!1 !== config.performance.printFileSize && compiler.hooks.emit.tapPromise({
|
|
8918
|
+
name: 'rsbuild:file-size',
|
|
8919
|
+
stage: 1 / 0
|
|
8920
|
+
}, async (compilation)=>{
|
|
8921
|
+
fileSizeResults && processAssets && !compilation.errors.length && (fileSizeResults[index] = getFileSizes(fileSize_normalizeConfig(config), compilation, processAssets), await fileSizeResults[index].catch(()=>{}));
|
|
8922
|
+
});
|
|
8923
|
+
});
|
|
8924
|
+
}), api.onAfterBuild(async ({ stats, isFirstCompile })=>{
|
|
8925
|
+
let results = fileSizeResults;
|
|
8926
|
+
fileSizeResults = void 0, processAssets = void 0;
|
|
8775
8927
|
let { hasErrors } = context.buildState;
|
|
8776
|
-
if (!stats || hasErrors || !isFirstCompile) return;
|
|
8777
|
-
let environments = context.environmentList.filter(({
|
|
8928
|
+
if (!stats || hasErrors || !isFirstCompile || !results) return;
|
|
8929
|
+
let environments = context.environmentList.filter(({ index })=>void 0 !== results[index]);
|
|
8778
8930
|
if (!environments.length) return;
|
|
8779
8931
|
let showDiff = environments.some((environment)=>{
|
|
8780
8932
|
let { printFileSize } = environment.config.performance;
|
|
8781
8933
|
return 'object' == typeof printFileSize && !!printFileSize.diff;
|
|
8782
8934
|
}), { 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 })=>{
|
|
8783
|
-
let
|
|
8784
|
-
let { printFileSize } = config.performance, defaultConfig = {
|
|
8785
|
-
total: !0,
|
|
8786
|
-
detail: !0,
|
|
8787
|
-
diff: !1,
|
|
8788
|
-
compressed: 'node' !== config.output.target
|
|
8789
|
-
};
|
|
8790
|
-
return !0 === printFileSize ? defaultConfig : {
|
|
8791
|
-
...defaultConfig,
|
|
8792
|
-
...printFileSize
|
|
8793
|
-
};
|
|
8794
|
-
})(config), statsItem, api.context.rootPath, distPath, name, prevSnapshots, showDiff);
|
|
8935
|
+
let { logs: sizeLogs, snapshot } = printFileSizes(fileSize_normalizeConfig(config), await results[index], api.context.rootPath, distPath, name, prevSnapshots, showDiff);
|
|
8795
8936
|
return snapshot && (nextSnapshots[name] = snapshot), sizeLogs.join('\n');
|
|
8796
8937
|
})).catch((err)=>{
|
|
8797
8938
|
api.logger.warn('Failed to print file size.'), api.logger.warn(err);
|
|
@@ -9138,7 +9279,13 @@ try {
|
|
|
9138
9279
|
name: 'rsbuild:define',
|
|
9139
9280
|
setup (api) {
|
|
9140
9281
|
api.modifyBundlerChain((chain, { CHAIN_ID, rspack, environment })=>{
|
|
9141
|
-
let { config } = environment, baseUrl = JSON.stringify(config.server.base), assetPrefix = JSON.stringify(getPublicPathFromChain(chain, !1)),
|
|
9282
|
+
let { config } = environment, baseUrl = JSON.stringify(config.server.base), assetPrefix = JSON.stringify(getPublicPathFromChain(chain, !1)), envPrefix = 'import.meta.env.', userEnv = Object.create(null);
|
|
9283
|
+
for (let [key, value] of Object.entries(config.source.define)){
|
|
9284
|
+
if (!key.startsWith(envPrefix)) continue;
|
|
9285
|
+
let name = key.slice(envPrefix.length);
|
|
9286
|
+
'' === name || name.includes('.') || (userEnv[name] = value);
|
|
9287
|
+
}
|
|
9288
|
+
let mergedDefine = {
|
|
9142
9289
|
...{
|
|
9143
9290
|
'import.meta.env': {
|
|
9144
9291
|
MODE: JSON.stringify(config.mode),
|
|
@@ -9146,7 +9293,8 @@ try {
|
|
|
9146
9293
|
PROD: 'production' === config.mode,
|
|
9147
9294
|
SSR: 'node' === config.output.target,
|
|
9148
9295
|
BASE_URL: baseUrl,
|
|
9149
|
-
ASSET_PREFIX: assetPrefix
|
|
9296
|
+
ASSET_PREFIX: assetPrefix,
|
|
9297
|
+
...userEnv
|
|
9150
9298
|
},
|
|
9151
9299
|
'process.env.BASE_URL': baseUrl,
|
|
9152
9300
|
'process.env.ASSET_PREFIX': assetPrefix
|
|
@@ -9567,7 +9715,7 @@ try {
|
|
|
9567
9715
|
return;
|
|
9568
9716
|
}
|
|
9569
9717
|
}
|
|
9570
|
-
api.logger.warn(`\`process.env.RSDOCTOR\` enabled, please install ${color.bold(color.yellow('@rsdoctor/
|
|
9718
|
+
api.logger.warn(`\`process.env.RSDOCTOR\` enabled, please install ${color.bold(color.yellow('@rsdoctor/core@latest'))} package.`);
|
|
9571
9719
|
});
|
|
9572
9720
|
}
|
|
9573
9721
|
},
|
|
@@ -10243,7 +10391,7 @@ let applyServerOptions = (command)=>{
|
|
|
10243
10391
|
};
|
|
10244
10392
|
function setupCommands(argv) {
|
|
10245
10393
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
10246
|
-
cli.version("2.2.
|
|
10394
|
+
cli.version("2.2.14"), 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)', {
|
|
10247
10395
|
default: 'auto'
|
|
10248
10396
|
}).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', {
|
|
10249
10397
|
type: [
|
|
@@ -10308,7 +10456,7 @@ function setupCommands(argv) {
|
|
|
10308
10456
|
}
|
|
10309
10457
|
function showGreeting() {
|
|
10310
10458
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
10311
|
-
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.2.
|
|
10459
|
+
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.2.14\n`);
|
|
10312
10460
|
}
|
|
10313
10461
|
function setupLogLevel(argv) {
|
|
10314
10462
|
if (argv.length <= 3) return;
|
|
@@ -10330,5 +10478,5 @@ function runCLI({ argv = process.argv } = {}) {
|
|
|
10330
10478
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
|
|
10331
10479
|
}
|
|
10332
10480
|
}
|
|
10333
|
-
let src_version = "2.2.
|
|
10481
|
+
let src_version = "2.2.14";
|
|
10334
10482
|
export { 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 };
|