@rsbuild/core 2.3.0-beta.0 → 2.3.0-rc.0
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/chokidar/index.d.ts +448 -161
- package/compiled/chokidar/package.json +1 -1
- package/compiled/css-loader/index.js +2 -2
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/http-proxy-middleware/index.d.ts +10 -10
- package/compiled/http-proxy-middleware/package.json +1 -1
- package/compiled/postcss/index.js +1 -1
- package/compiled/postcss/package.json +1 -1
- package/compiled/postcss-loader/index.js +6 -6
- package/dist/chokidar.js +1 -1
- package/dist/client/hmr.js +21 -7
- package/dist/client/overlay.js +4 -3
- package/dist/defaultConfig.d.ts +7 -2
- package/dist/helpers/compilation.d.ts +2 -0
- package/dist/http-proxy-middleware.js +4 -4
- package/dist/m.js +419 -315
- package/dist/manifest-plugin.js +1 -1
- package/dist/server/assets-middleware/index.d.ts +2 -1
- package/dist/server/assets-middleware/middleware.d.ts +4 -1
- package/dist/server/assets-middleware/setupMemoryFileSystemCleanup.d.ts +3 -0
- package/dist/server/devMiddlewares.d.ts +1 -1
- package/dist/server/helper.d.ts +1 -0
- package/dist/server/socketServer.d.ts +18 -2
- package/dist/types/config.d.ts +6 -1
- package/dist/types/plugin.d.ts +14 -3
- package/package.json +5 -5
package/dist/m.js
CHANGED
|
@@ -292,8 +292,8 @@ moduleFactories.add({
|
|
|
292
292
|
};
|
|
293
293
|
};
|
|
294
294
|
},
|
|
295
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
296
|
-
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/
|
|
295
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/5cec47ed0c72adfad7e947f8ff131ef2fb4291b37a63788557685a7ae51d3648/node_modules/postcss-load-config/src/index.js" (module) {
|
|
296
|
+
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/5cec47ed0c72adfad7e947f8ff131ef2fb4291b37a63788557685a7ae51d3648/node_modules/postcss-load-config/src/options.js"), loadPlugins = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/5cec47ed0c72adfad7e947f8ff131ef2fb4291b37a63788557685a7ae51d3648/node_modules/postcss-load-config/src/plugins.js"), req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/5cec47ed0c72adfad7e947f8ff131ef2fb4291b37a63788557685a7ae51d3648/node_modules/postcss-load-config/src/req.js");
|
|
297
297
|
async function processResult(ctx, result) {
|
|
298
298
|
let obj, file = result.filepath || '', projectConfig = ((obj = result.config) && obj.__esModule ? obj : {
|
|
299
299
|
default: obj
|
|
@@ -366,8 +366,8 @@ moduleFactories.add({
|
|
|
366
366
|
});
|
|
367
367
|
};
|
|
368
368
|
},
|
|
369
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
370
|
-
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
369
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/5cec47ed0c72adfad7e947f8ff131ef2fb4291b37a63788557685a7ae51d3648/node_modules/postcss-load-config/src/options.js" (module) {
|
|
370
|
+
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/5cec47ed0c72adfad7e947f8ff131ef2fb4291b37a63788557685a7ae51d3648/node_modules/postcss-load-config/src/req.js");
|
|
371
371
|
module.exports = async function options(config, file) {
|
|
372
372
|
if (config.parser && 'string' == typeof config.parser) try {
|
|
373
373
|
config.parser = await req(config.parser, file);
|
|
@@ -387,8 +387,8 @@ moduleFactories.add({
|
|
|
387
387
|
return config;
|
|
388
388
|
};
|
|
389
389
|
},
|
|
390
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
391
|
-
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
390
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/5cec47ed0c72adfad7e947f8ff131ef2fb4291b37a63788557685a7ae51d3648/node_modules/postcss-load-config/src/plugins.js" (module) {
|
|
391
|
+
let req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/5cec47ed0c72adfad7e947f8ff131ef2fb4291b37a63788557685a7ae51d3648/node_modules/postcss-load-config/src/req.js");
|
|
392
392
|
async function load(plugin, options, file) {
|
|
393
393
|
try {
|
|
394
394
|
if (null == options || 0 === Object.keys(options).length) return await req(plugin, file);
|
|
@@ -404,7 +404,7 @@ moduleFactories.add({
|
|
|
404
404
|
}), list;
|
|
405
405
|
};
|
|
406
406
|
},
|
|
407
|
-
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
407
|
+
"../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/5cec47ed0c72adfad7e947f8ff131ef2fb4291b37a63788557685a7ae51d3648/node_modules/postcss-load-config/src/req.js" (module) {
|
|
408
408
|
let tsx, jiti, { createRequire } = __rspack_createRequire_require("node:module"), { pathToFileURL } = __rspack_createRequire_require("node:url"), TS_EXT_RE = /\.[mc]?ts$/, importError = [];
|
|
409
409
|
module.exports = async function req(name, rootFile = __rspack_import_meta_filename__) {
|
|
410
410
|
let url = createRequire(rootFile).resolve(name);
|
|
@@ -2784,6 +2784,28 @@ let withDefaultConfig = async (rootPath, userConfig)=>{
|
|
|
2784
2784
|
await isFileExists(tsconfigPath) && (config.source.tsconfigPath = tsconfigPath);
|
|
2785
2785
|
}
|
|
2786
2786
|
return config;
|
|
2787
|
+
}, normalizePublicDirs = (rootPath, publicDir)=>{
|
|
2788
|
+
if (!1 === publicDir) return [];
|
|
2789
|
+
let defaultConfig = {
|
|
2790
|
+
name: join(rootPath, 'public'),
|
|
2791
|
+
copyOnBuild: 'auto',
|
|
2792
|
+
watch: !1,
|
|
2793
|
+
ignore: []
|
|
2794
|
+
};
|
|
2795
|
+
if (void 0 === publicDir) return [
|
|
2796
|
+
defaultConfig
|
|
2797
|
+
];
|
|
2798
|
+
let mergeWithDefault = (options)=>{
|
|
2799
|
+
if ('' === options.name) throw Error('[rsbuild:config] `publicDir.name` cannot be empty string.');
|
|
2800
|
+
let merged = {
|
|
2801
|
+
...defaultConfig,
|
|
2802
|
+
...options
|
|
2803
|
+
};
|
|
2804
|
+
return external_node_path_isAbsolute(merged.name) || (merged.name = join(rootPath, merged.name)), merged;
|
|
2805
|
+
};
|
|
2806
|
+
return Array.isArray(publicDir) ? publicDir.map((options)=>mergeWithDefault(options)) : [
|
|
2807
|
+
mergeWithDefault(publicDir)
|
|
2808
|
+
];
|
|
2787
2809
|
}, restartPorts = new WeakMap(), exitHook_callbacks = new Set(), isCalled = !1, isRegistered = !1;
|
|
2788
2810
|
function exit(exitCode, type) {
|
|
2789
2811
|
if (!isCalled) {
|
|
@@ -3051,11 +3073,11 @@ function initPluginAPI({ context, pluginManager }) {
|
|
|
3051
3073
|
if (descriptor.targets && !descriptor.targets.includes(target) || descriptor.environments && !descriptor.environments.includes(environmentContext.name)) return;
|
|
3052
3074
|
let rule = chain.module.rule(id);
|
|
3053
3075
|
descriptor.test && rule.test(descriptor.test), descriptor.resourceQuery && rule.resourceQuery(descriptor.resourceQuery), descriptor.layer && rule.layer(descriptor.layer), descriptor.issuerLayer && rule.issuerLayer(descriptor.issuerLayer), descriptor.issuer && rule.issuer(descriptor.issuer), descriptor.with && rule.with(descriptor.with), descriptor.mimetype && rule.mimetype(descriptor.mimetype), descriptor.order && 'default' !== descriptor.order ? rule.enforce(descriptor.order) : descriptor.enforce && rule.enforce(descriptor.enforce);
|
|
3054
|
-
let loaderPath = join(LOADER_PATH, descriptor.raw ? 'transformRawLoader.mjs' : 'transformLoader.mjs')
|
|
3055
|
-
rule.use(id).loader(loaderPath).options({
|
|
3076
|
+
let loaderPath = join(LOADER_PATH, descriptor.raw ? 'transformRawLoader.mjs' : 'transformLoader.mjs'), use = rule.use(id).loader(loaderPath).options({
|
|
3056
3077
|
id,
|
|
3057
3078
|
getEnvironment: ()=>environmentContext
|
|
3058
3079
|
});
|
|
3080
|
+
void 0 !== descriptor.codeFilter && use.set('codeFilter', descriptor.codeFilter);
|
|
3059
3081
|
}
|
|
3060
3082
|
});
|
|
3061
3083
|
},
|
|
@@ -3214,7 +3236,7 @@ function createPublicContext(context) {
|
|
|
3214
3236
|
async function createContext(options, userConfig, logger, loadConfigResult) {
|
|
3215
3237
|
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();
|
|
3216
3238
|
return {
|
|
3217
|
-
version: "2.3.0-
|
|
3239
|
+
version: "2.3.0-rc.0",
|
|
3218
3240
|
rootPath,
|
|
3219
3241
|
configFile: loadConfigResult?.filePath ?? userConfig._privateMeta?.configFilePath,
|
|
3220
3242
|
configFileDependencies: loadConfigResult?.dependencies ?? userConfig._privateMeta?.configFileDependencies ?? [],
|
|
@@ -3720,29 +3742,7 @@ async function initRsbuildConfig({ context, pluginManager }) {
|
|
|
3720
3742
|
context,
|
|
3721
3743
|
pluginManager
|
|
3722
3744
|
}), await modifyRsbuildConfig(context);
|
|
3723
|
-
let normalizedBaseConfig = (config = context.config, rootPath = context.rootPath, config.server ||= {}, config.server.host = 'string' == typeof (host = config.server.host) ? host : !0 === host ? ALL_INTERFACES_IPV4 : LOCALHOST, config.server.publicDir = (
|
|
3724
|
-
if (!1 === publicDir) return [];
|
|
3725
|
-
let defaultConfig = {
|
|
3726
|
-
name: join(rootPath, 'public'),
|
|
3727
|
-
copyOnBuild: 'auto',
|
|
3728
|
-
watch: !1,
|
|
3729
|
-
ignore: []
|
|
3730
|
-
};
|
|
3731
|
-
if (void 0 === publicDir) return [
|
|
3732
|
-
defaultConfig
|
|
3733
|
-
];
|
|
3734
|
-
let mergeWithDefault = (options)=>{
|
|
3735
|
-
if ('' === options.name) throw Error('[rsbuild:config] `publicDir.name` cannot be empty string.');
|
|
3736
|
-
let merged = {
|
|
3737
|
-
...defaultConfig,
|
|
3738
|
-
...options
|
|
3739
|
-
};
|
|
3740
|
-
return external_node_path_isAbsolute(merged.name) || (merged.name = join(rootPath, merged.name)), merged;
|
|
3741
|
-
};
|
|
3742
|
-
return Array.isArray(publicDir) ? publicDir.map((options)=>mergeWithDefault(options)) : [
|
|
3743
|
-
mergeWithDefault(publicDir)
|
|
3744
|
-
];
|
|
3745
|
-
})(rootPath, config.server.publicDir), (defaultConfig = createDefaultConfig()).mode = (()=>{
|
|
3745
|
+
let normalizedBaseConfig = (config = context.config, rootPath = context.rootPath, config.server ||= {}, config.server.host = 'string' == typeof (host = config.server.host) ? host : !0 === host ? ALL_INTERFACES_IPV4 : LOCALHOST, config.server.publicDir = normalizePublicDirs(rootPath, config.server.publicDir), (defaultConfig = createDefaultConfig()).mode = (()=>{
|
|
3746
3746
|
if (config.mode) return config.mode;
|
|
3747
3747
|
let nodeEnv = process.env.NODE_ENV || '';
|
|
3748
3748
|
return 'production' === nodeEnv || 'development' === nodeEnv ? nodeEnv : 'none';
|
|
@@ -3770,13 +3770,16 @@ async function initRsbuildConfig({ context, pluginManager }) {
|
|
|
3770
3770
|
};
|
|
3771
3771
|
})(normalizedBaseConfig, context.rootPath, context.specifiedEnvironments), tsconfigPaths = new Set();
|
|
3772
3772
|
for (let [name, config] of Object.entries(mergedEnvironments)){
|
|
3773
|
-
let environmentConfig = await modifyEnvironmentConfig(context, config, name), normalizedEnvironmentConfig = {
|
|
3773
|
+
let environmentConfig = await modifyEnvironmentConfig(context, config, name), publicDir = environmentConfig.server?.publicDir, normalizedEnvironmentConfig = {
|
|
3774
3774
|
...environmentConfig,
|
|
3775
3775
|
dev: {
|
|
3776
3776
|
...normalizedBaseConfig.dev,
|
|
3777
3777
|
...environmentConfig.dev
|
|
3778
3778
|
},
|
|
3779
|
-
server:
|
|
3779
|
+
server: {
|
|
3780
|
+
...normalizedBaseConfig.server,
|
|
3781
|
+
publicDir: void 0 === publicDir ? normalizedBaseConfig.server.publicDir : normalizePublicDirs(context.rootPath, publicDir)
|
|
3782
|
+
}
|
|
3780
3783
|
}, { tsconfigPath } = normalizedEnvironmentConfig.source;
|
|
3781
3784
|
if (tsconfigPath) {
|
|
3782
3785
|
let absoluteTsconfigPath = ensureAbsolutePath(context.rootPath, tsconfigPath);
|
|
@@ -3911,7 +3914,7 @@ async function createCompiler_createCompiler(options) {
|
|
|
3911
3914
|
}), compiler.hooks.watchRun.tap(HOOK_NAME, (compiler)=>{
|
|
3912
3915
|
startTime = Date.now(), context.buildState.status = 'building', logRspackVersion(), isCompiling || printBuildLog(compiler, context, lazyModules), lazyModules.size && lazyModules.clear(), isCompiling = !0;
|
|
3913
3916
|
}), compiler.hooks.invalid.tap(HOOK_NAME, ()=>{
|
|
3914
|
-
hasFatalError = !1, context.buildState.stats = null, context.buildState.status = 'idle', context.buildState.hasErrors = !1;
|
|
3917
|
+
hasFatalError = !1, context.buildState.stats = null, context.buildState.status = 'idle', context.buildState.hasErrors = !1, context.socketServer?.clearEnvironmentStats();
|
|
3915
3918
|
}), compilers))item.hooks.failed.tap(HOOK_NAME, ()=>{
|
|
3916
3919
|
hasFatalError = !0, context.buildState.hasErrors = !0, finishFatalBuild();
|
|
3917
3920
|
}), item.hooks.afterDone.tap(HOOK_NAME, finishFatalBuild), item.hooks.watchClose.tap(HOOK_NAME, finishFatalBuild);
|
|
@@ -4019,7 +4022,212 @@ async function createCompiler_createCompiler(options) {
|
|
|
4019
4022
|
rspackConfigs
|
|
4020
4023
|
};
|
|
4021
4024
|
}
|
|
4022
|
-
let
|
|
4025
|
+
let normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1'), formatPrefix = (input)=>{
|
|
4026
|
+
let prefix = input;
|
|
4027
|
+
if (prefix?.startsWith('./') && (prefix = prefix.replace('./', '')), !prefix) return '/';
|
|
4028
|
+
let hasLeadingSlash = prefix.startsWith('/'), hasTailSlash = prefix.endsWith('/');
|
|
4029
|
+
return `${hasLeadingSlash ? '' : '/'}${prefix}${hasTailSlash ? '' : '/'}`;
|
|
4030
|
+
}, joinUrlPath = (basePath, pathname)=>'' === basePath ? pathname : '' === pathname ? basePath : addTrailingSlash(basePath) + pathname.replace(/^\/+/, ''), getMoreEntriesMessage = (moreEntries, cliShortcutsEnabled)=>cliShortcutsEnabled ? ` ${color.dim(`... ${moreEntries} more entries, press `)}${color.bold('u + enter')}${color.dim(' to show all')}\n` : ` ${color.dim(`... ${moreEntries} more entries, set `)}${color.bold('server.printUrls.maxRoutes')}${color.dim(' to show more')}\n`, isUrlPathUnderBase = (pathname, base)=>{
|
|
4031
|
+
let basePath = removeTailingSlash(base);
|
|
4032
|
+
return '' === basePath || pathname === basePath || pathname.startsWith(`${basePath}/`);
|
|
4033
|
+
}, removeBasePath = (url, base)=>{
|
|
4034
|
+
let basePath = removeTailingSlash(base);
|
|
4035
|
+
if ('' === basePath || !url.startsWith(basePath)) return url;
|
|
4036
|
+
let nextChar = url[basePath.length];
|
|
4037
|
+
return void 0 === nextChar ? '/' : '/' === nextChar ? url.slice(basePath.length) : '?' === nextChar || '#' === nextChar ? `/${url.slice(basePath.length)}` : url;
|
|
4038
|
+
}, getRoutes = (context)=>{
|
|
4039
|
+
let environmentWithHtml = context.environmentList.filter((item)=>Object.keys(item.htmlPaths).length > 0);
|
|
4040
|
+
if (0 === environmentWithHtml.length) return [];
|
|
4041
|
+
let commonDistPath = getCommonParentPath(environmentWithHtml.map((item)=>item.distPath));
|
|
4042
|
+
return environmentWithHtml.reduce((prev, environmentContext)=>{
|
|
4043
|
+
let { distPath, config } = environmentContext, distPrefix = relative(commonDistPath, distPath).split(sep).join('/'), routes = formatRoutes(environmentContext.htmlPaths, context.normalizedConfig.server.base, posix.join(distPrefix, config.output.distPath.html), config.html.outputStructure);
|
|
4044
|
+
return prev.concat(...routes);
|
|
4045
|
+
}, []);
|
|
4046
|
+
}, formatRoutes = (entry, base, distPathPrefix, outputStructure)=>{
|
|
4047
|
+
let prefix = joinUrlPath(base, formatPrefix(distPathPrefix));
|
|
4048
|
+
return Object.keys(entry).map((entryName)=>({
|
|
4049
|
+
entryName,
|
|
4050
|
+
pathname: prefix + ('index' === entryName && 'nested' !== outputStructure ? '' : entryName)
|
|
4051
|
+
})).sort((a)=>'index' === a.entryName ? -1 : 1);
|
|
4052
|
+
}, formatName = (name)=>name ? `(${name.length > 20 ? `${name.slice(0, 19)}…` : name})` : name;
|
|
4053
|
+
function getURLMessages(urls, routes, { maxRoutes = 10, showAllRoutes, cliShortcutsEnabled }) {
|
|
4054
|
+
let prevName, routeLimit = showAllRoutes ? 1 / 0 : void 0 === maxRoutes ? 10 : 1 / 0 === maxRoutes ? maxRoutes : Math.max(0, Math.floor(maxRoutes)), printableRoutes = 0 === routeLimit ? [] : routes.slice(0, routeLimit), moreEntries = routeLimit > 0 ? routes.length - printableRoutes.length : 0, nameCount = 0;
|
|
4055
|
+
for (let { name } of urls)if (name && ++nameCount > 1) break;
|
|
4056
|
+
let showNames = nameCount > 1;
|
|
4057
|
+
if (routes.length <= 1 || 0 === printableRoutes.length) {
|
|
4058
|
+
let pathname = printableRoutes[0]?.pathname ?? '', items = urls.map(({ label, name, url })=>({
|
|
4059
|
+
label,
|
|
4060
|
+
name: showNames ? formatName(name) : void 0,
|
|
4061
|
+
url: normalizeUrl(`${url}${pathname}`)
|
|
4062
|
+
})), labelWidth = Math.max(10, ...items.map((item)=>item.label.trimEnd().length + 2)), urlWidth = Math.max(0, ...items.map((item)=>item.name ? item.url.length : 0)), message = items.map(({ label, name, url })=>{
|
|
4063
|
+
let prefix = `➜ ${color.dim(label.trimEnd().padEnd(labelWidth))}`, suffix = name ? `${' '.repeat(urlWidth - url.length + 2)}${color.dim(name)}` : '';
|
|
4064
|
+
return ` ${prefix}${color.cyan(url)}${suffix}\n`;
|
|
4065
|
+
}).join('');
|
|
4066
|
+
return moreEntries > 0 && (message += getMoreEntriesMessage(moreEntries, cliShortcutsEnabled)), message;
|
|
4067
|
+
}
|
|
4068
|
+
let message = '', prevLabel = '', entryWidth = Math.max(...printableRoutes.map((route)=>route.entryName.length));
|
|
4069
|
+
return urls.forEach(({ label, name, url }, index)=>{
|
|
4070
|
+
let shortName = showNames ? formatName(name) : void 0;
|
|
4071
|
+
if (prevLabel !== label || prevName !== shortName) {
|
|
4072
|
+
index > 0 && (message += '\n');
|
|
4073
|
+
let title = shortName ? `${label.trimEnd().slice(0, -1)} ${color.dim(shortName)}:` : label;
|
|
4074
|
+
message += ` ➜ ${title}\n`, prevLabel = label, prevName = shortName;
|
|
4075
|
+
}
|
|
4076
|
+
for (let { entryName, pathname } of printableRoutes)message += ` ${color.dim('-')} ${color.dim(entryName.padEnd(entryWidth + 4))}${color.cyan(normalizeUrl(`${url}${pathname}`))}\n`;
|
|
4077
|
+
}), moreEntries > 0 && (message += getMoreEntriesMessage(moreEntries, cliShortcutsEnabled)), message;
|
|
4078
|
+
}
|
|
4079
|
+
function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls, fallbackPathname, showAllRoutes, cliShortcutsEnabled, originalConfig, logger }) {
|
|
4080
|
+
if (!1 === printUrls) return null;
|
|
4081
|
+
let urls = originalUrls, useCustomUrl = isFunction(printUrls);
|
|
4082
|
+
if (useCustomUrl) {
|
|
4083
|
+
let newUrls = printUrls({
|
|
4084
|
+
urls: urls.map((item)=>item.url),
|
|
4085
|
+
port,
|
|
4086
|
+
routes,
|
|
4087
|
+
protocol
|
|
4088
|
+
});
|
|
4089
|
+
if (!newUrls) return null;
|
|
4090
|
+
if (!Array.isArray(newUrls)) throw Error(`${color.dim('[rsbuild:config]')} "server.printUrls" must return an array, but got ${typeof newUrls}.`);
|
|
4091
|
+
urls = newUrls.map((u)=>{
|
|
4092
|
+
let { url, label } = 'string' == typeof u ? {
|
|
4093
|
+
url: u
|
|
4094
|
+
} : u;
|
|
4095
|
+
return {
|
|
4096
|
+
url,
|
|
4097
|
+
label: label ?? getUrlLabel(url)
|
|
4098
|
+
};
|
|
4099
|
+
});
|
|
4100
|
+
}
|
|
4101
|
+
if (0 === urls.length) return null;
|
|
4102
|
+
let printableRoutes = 0 !== routes.length || useCustomUrl || void 0 === fallbackPathname ? routes : [
|
|
4103
|
+
{
|
|
4104
|
+
entryName: 'index',
|
|
4105
|
+
pathname: formatPrefix(fallbackPathname)
|
|
4106
|
+
}
|
|
4107
|
+
];
|
|
4108
|
+
if (0 === printableRoutes.length && !useCustomUrl) return null;
|
|
4109
|
+
let printUrlsOptions = printUrls && 'object' == typeof printUrls ? printUrls : {}, message = getURLMessages(urls, printableRoutes, {
|
|
4110
|
+
maxRoutes: useCustomUrl ? 1 / 0 : printUrlsOptions.maxRoutes,
|
|
4111
|
+
showAllRoutes,
|
|
4112
|
+
cliShortcutsEnabled
|
|
4113
|
+
});
|
|
4114
|
+
return originalConfig && originalConfig.server?.host === void 0 && (message += ` ➜ ${color.dim('Network:')} ${color.dim('use')} ${color.bold('--host')} ${color.dim('to expose')}\n`), !0 === cliShortcutsEnabled && message.endsWith('\n') && (message = message.slice(0, -1)), logger.log(message), message;
|
|
4115
|
+
}
|
|
4116
|
+
let getPort = async ({ host, port, strictPort, tryLimits = 20 })=>{
|
|
4117
|
+
'string' == typeof port && (port = Number.parseInt(port, 10)), strictPort && (tryLimits = 1);
|
|
4118
|
+
let { createServer } = await import("node:net"), original = port, found = !1, attempts = 0;
|
|
4119
|
+
for(; !found && attempts <= tryLimits;)try {
|
|
4120
|
+
await new Promise((resolve, reject)=>{
|
|
4121
|
+
let server = createServer();
|
|
4122
|
+
server.unref(), server.on('error', reject), server.listen({
|
|
4123
|
+
port,
|
|
4124
|
+
host
|
|
4125
|
+
}, ()=>{
|
|
4126
|
+
if (0 === port) {
|
|
4127
|
+
let address = server.address();
|
|
4128
|
+
address && 'string' != typeof address && (port = address.port);
|
|
4129
|
+
}
|
|
4130
|
+
found = !0, server.close(resolve);
|
|
4131
|
+
});
|
|
4132
|
+
});
|
|
4133
|
+
} catch (e) {
|
|
4134
|
+
if (!(e instanceof Error) || !('code' in e) || 'EADDRINUSE' !== e.code) throw e;
|
|
4135
|
+
port++, attempts++;
|
|
4136
|
+
}
|
|
4137
|
+
if (!found) throw Error(`${color.dim('[rsbuild:server]')} Failed to find an available port after ${tryLimits + 1} attempts, starting from ${color.yellow(original)}.`);
|
|
4138
|
+
if (0 !== original && port !== original && strictPort) throw Error(`${color.dim('[rsbuild:server]')} Port ${color.yellow(original)} is occupied, please choose another one.`);
|
|
4139
|
+
return port;
|
|
4140
|
+
}, resolvePort = async (config, lastPort)=>{
|
|
4141
|
+
let { host, port: originalPort, strictPort } = config.server, preferredPort = 0 === originalPort ? lastPort : void 0, port = await getPort({
|
|
4142
|
+
host,
|
|
4143
|
+
port: preferredPort ?? originalPort,
|
|
4144
|
+
strictPort: void 0 === preferredPort && strictPort
|
|
4145
|
+
}), portTip = 0 !== originalPort && port !== originalPort ? `port ${originalPort} is in use, ${color.yellow(`using port ${port}.`)}` : void 0;
|
|
4146
|
+
return {
|
|
4147
|
+
port,
|
|
4148
|
+
portTip
|
|
4149
|
+
};
|
|
4150
|
+
}, WILDCARD_HOSTS = new Set([
|
|
4151
|
+
ALL_INTERFACES_IPV4,
|
|
4152
|
+
'::',
|
|
4153
|
+
'0000:0000:0000:0000:0000:0000:0000:0000'
|
|
4154
|
+
]), LOOPBACK_HOSTS = new Set([
|
|
4155
|
+
LOCALHOST,
|
|
4156
|
+
'127.0.0.1',
|
|
4157
|
+
'::1',
|
|
4158
|
+
'0000:0000:0000:0000:0000:0000:0000:0001'
|
|
4159
|
+
]), isLoopbackHost = (host)=>LOOPBACK_HOSTS.has(host), getHostInUrl = async (host)=>{
|
|
4160
|
+
if (host === ALL_INTERFACES_IPV4 || host === LOCALHOST) return LOCALHOST;
|
|
4161
|
+
let { isIPv6 } = await import("node:net");
|
|
4162
|
+
return isIPv6(host) ? '::' === host ? '[::1]' : `[${host}]` : host;
|
|
4163
|
+
}, concatUrl = ({ host, port, protocol })=>`${protocol}://${host}:${port}`, LOCAL_LABEL = 'Local: ', NETWORK_LABEL = 'Network: ', getUrlLabel = (url)=>{
|
|
4164
|
+
try {
|
|
4165
|
+
let { hostname } = new URL(url);
|
|
4166
|
+
return isLoopbackHost(hostname) ? LOCAL_LABEL : NETWORK_LABEL;
|
|
4167
|
+
} catch {
|
|
4168
|
+
return NETWORK_LABEL;
|
|
4169
|
+
}
|
|
4170
|
+
}, getAddressUrls = async ({ protocol, port, host })=>{
|
|
4171
|
+
if (host && !WILDCARD_HOSTS.has(host)) {
|
|
4172
|
+
let url = concatUrl({
|
|
4173
|
+
port,
|
|
4174
|
+
host: await getHostInUrl(host),
|
|
4175
|
+
protocol
|
|
4176
|
+
});
|
|
4177
|
+
return [
|
|
4178
|
+
{
|
|
4179
|
+
label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL,
|
|
4180
|
+
url
|
|
4181
|
+
}
|
|
4182
|
+
];
|
|
4183
|
+
}
|
|
4184
|
+
let urls = [], seen = new Set(), hasLocal = !1;
|
|
4185
|
+
for (let [name, infos] of Object.entries(node_os.networkInterfaces()))for (let info of infos ?? []){
|
|
4186
|
+
let family = info.family;
|
|
4187
|
+
!('IPv4' !== family && 4 !== family || seen.has(info.address)) && (seen.add(info.address), isLoopbackHost(info.address) || info.internal ? hasLocal || (urls.push({
|
|
4188
|
+
label: LOCAL_LABEL,
|
|
4189
|
+
url: concatUrl({
|
|
4190
|
+
host: LOCALHOST,
|
|
4191
|
+
port,
|
|
4192
|
+
protocol
|
|
4193
|
+
})
|
|
4194
|
+
}), hasLocal = !0) : urls.push({
|
|
4195
|
+
label: NETWORK_LABEL,
|
|
4196
|
+
name,
|
|
4197
|
+
url: concatUrl({
|
|
4198
|
+
host: info.address,
|
|
4199
|
+
port,
|
|
4200
|
+
protocol
|
|
4201
|
+
})
|
|
4202
|
+
}));
|
|
4203
|
+
}
|
|
4204
|
+
return urls;
|
|
4205
|
+
};
|
|
4206
|
+
function getServerTerminator(server) {
|
|
4207
|
+
let listened = !1, pendingSockets = new Set(), onConnection = (socket)=>{
|
|
4208
|
+
pendingSockets.add(socket), socket.on('close', ()=>{
|
|
4209
|
+
pendingSockets.delete(socket);
|
|
4210
|
+
});
|
|
4211
|
+
};
|
|
4212
|
+
return server.on('connection', onConnection), server.on('secureConnection', onConnection), server.once('listening', ()=>{
|
|
4213
|
+
listened = !0;
|
|
4214
|
+
}), ()=>new Promise((resolve, reject)=>{
|
|
4215
|
+
for (let socket of pendingSockets)socket.destroy();
|
|
4216
|
+
listened ? server.close((err)=>{
|
|
4217
|
+
err ? reject(err) : resolve();
|
|
4218
|
+
}) : resolve();
|
|
4219
|
+
});
|
|
4220
|
+
}
|
|
4221
|
+
function escapeHtml(text) {
|
|
4222
|
+
return text ? text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''') : '';
|
|
4223
|
+
}
|
|
4224
|
+
let getPublicDirPaths = (config, watchOnly = !1)=>{
|
|
4225
|
+
let paths = new Set();
|
|
4226
|
+
for (let { server } of Object.values(config.environments))for (let { name, watch } of server.publicDir)(!watchOnly || watch) && paths.add(name);
|
|
4227
|
+
return [
|
|
4228
|
+
...paths
|
|
4229
|
+
];
|
|
4230
|
+
}, getChokidar = cachedImport_cachedImport(()=>import("./chokidar.js").then((m)=>m.chokidar_namespaceObject)), DEFAULT_WATCH_FILE_EVENTS = [
|
|
4023
4231
|
'add',
|
|
4024
4232
|
'change',
|
|
4025
4233
|
'unlink'
|
|
@@ -4027,7 +4235,7 @@ let getChokidar = cachedImport_cachedImport(()=>import("./chokidar.js").then((m)
|
|
|
4027
4235
|
async function setupWatchFiles(options) {
|
|
4028
4236
|
let { config, root, logger, buildManager } = options, { hmr, liveReload } = config.dev;
|
|
4029
4237
|
if (!hmr && !liveReload || !buildManager) return;
|
|
4030
|
-
let closeDevFilesWatcher = await watchDevFiles(config.dev, buildManager, root, logger), serverFilesWatcher = await watchServerFiles(config
|
|
4238
|
+
let closeDevFilesWatcher = await watchDevFiles(config.dev, buildManager, root, logger), serverFilesWatcher = await watchServerFiles(config, buildManager, root, logger);
|
|
4031
4239
|
return {
|
|
4032
4240
|
async close () {
|
|
4033
4241
|
await Promise.all([
|
|
@@ -4049,9 +4257,8 @@ async function watchDevFiles(devConfig, buildManager, root, logger) {
|
|
|
4049
4257
|
for (let watcher of watchers)await watcher.close();
|
|
4050
4258
|
};
|
|
4051
4259
|
}
|
|
4052
|
-
function watchServerFiles(
|
|
4053
|
-
|
|
4054
|
-
let watchPaths = publicDir.filter((item)=>item.watch).map((item)=>item.name);
|
|
4260
|
+
function watchServerFiles(config, buildManager, root, logger) {
|
|
4261
|
+
let watchPaths = getPublicDirPaths(config, !0);
|
|
4055
4262
|
if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths), buildManager, root, logger);
|
|
4056
4263
|
}
|
|
4057
4264
|
function prepareWatchOptions(paths, options = {}, type, events) {
|
|
@@ -4882,7 +5089,7 @@ function parseMinifyOptions(config) {
|
|
|
4882
5089
|
cssOptions: minify.cssOptions
|
|
4883
5090
|
};
|
|
4884
5091
|
}
|
|
4885
|
-
var postcss_load_config_src_default = compatGetDefaultExport(rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
5092
|
+
var postcss_load_config_src_default = compatGetDefaultExport(rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/5cec47ed0c72adfad7e947f8ff131ef2fb4291b37a63788557685a7ae51d3648/node_modules/postcss-load-config/src/index.js"));
|
|
4886
5093
|
async function getLightningCSSLoaderOptions(config, targets, minify) {
|
|
4887
5094
|
let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
|
|
4888
5095
|
targets,
|
|
@@ -5069,6 +5276,9 @@ function pluginExternals() {
|
|
|
5069
5276
|
}
|
|
5070
5277
|
};
|
|
5071
5278
|
}
|
|
5279
|
+
function getAssetNames(compilation) {
|
|
5280
|
+
return compilation.__internal__getAssetFilenames();
|
|
5281
|
+
}
|
|
5072
5282
|
function createAssetProcessor() {
|
|
5073
5283
|
let failure, active = 0, waiting = [];
|
|
5074
5284
|
return async (names, processAsset)=>{
|
|
@@ -5177,7 +5387,7 @@ let calcFileSize = (len)=>{
|
|
|
5177
5387
|
}, COMPRESSIBLE_REGEX = /\.(?:js|mjs|cjs|jsx|ts|tsx|mts|cts|css|html|json|svg|txt|xml|xhtml|wasm|manifest|md)$/i;
|
|
5178
5388
|
async function getFileSizes(options, compilation, processAssets) {
|
|
5179
5389
|
if ((!1 === options.detail || 0 === options.detail) && !1 === options.total) return [];
|
|
5180
|
-
let { exclude, include } = options, compression = getCompression(options.compressed), fileSizes = [], compilationAssets = compilation.assets, names =
|
|
5390
|
+
let { exclude, include } = options, compression = getCompression(options.compressed), fileSizes = [], compilationAssets = compilation.assets, names = getAssetNames(compilation);
|
|
5181
5391
|
return await processAssets(names, async (assetName, index)=>{
|
|
5182
5392
|
let queryIndex, filePath = -1 === (queryIndex = assetName.indexOf('?')) ? assetName : assetName.slice(0, queryIndex);
|
|
5183
5393
|
if (!exclude && EXCLUDE_ASSET_REGEX.test(filePath)) return;
|
|
@@ -5684,205 +5894,6 @@ function getInlineTests(config) {
|
|
|
5684
5894
|
styleTests
|
|
5685
5895
|
};
|
|
5686
5896
|
}
|
|
5687
|
-
let normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1'), formatPrefix = (input)=>{
|
|
5688
|
-
let prefix = input;
|
|
5689
|
-
if (prefix?.startsWith('./') && (prefix = prefix.replace('./', '')), !prefix) return '/';
|
|
5690
|
-
let hasLeadingSlash = prefix.startsWith('/'), hasTailSlash = prefix.endsWith('/');
|
|
5691
|
-
return `${hasLeadingSlash ? '' : '/'}${prefix}${hasTailSlash ? '' : '/'}`;
|
|
5692
|
-
}, joinUrlPath = (basePath, pathname)=>'' === basePath ? pathname : '' === pathname ? basePath : addTrailingSlash(basePath) + pathname.replace(/^\/+/, ''), getMoreEntriesMessage = (moreEntries, cliShortcutsEnabled)=>cliShortcutsEnabled ? ` ${color.dim(`... ${moreEntries} more entries, press `)}${color.bold('u + enter')}${color.dim(' to show all')}\n` : ` ${color.dim(`... ${moreEntries} more entries, set `)}${color.bold('server.printUrls.maxRoutes')}${color.dim(' to show more')}\n`, isUrlPathUnderBase = (pathname, base)=>{
|
|
5693
|
-
let basePath = removeTailingSlash(base);
|
|
5694
|
-
return '' === basePath || pathname === basePath || pathname.startsWith(`${basePath}/`);
|
|
5695
|
-
}, removeBasePath = (url, base)=>{
|
|
5696
|
-
let basePath = removeTailingSlash(base);
|
|
5697
|
-
if ('' === basePath || !url.startsWith(basePath)) return url;
|
|
5698
|
-
let nextChar = url[basePath.length];
|
|
5699
|
-
return void 0 === nextChar ? '/' : '/' === nextChar ? url.slice(basePath.length) : '?' === nextChar || '#' === nextChar ? `/${url.slice(basePath.length)}` : url;
|
|
5700
|
-
}, getRoutes = (context)=>{
|
|
5701
|
-
let environmentWithHtml = context.environmentList.filter((item)=>Object.keys(item.htmlPaths).length > 0);
|
|
5702
|
-
if (0 === environmentWithHtml.length) return [];
|
|
5703
|
-
let commonDistPath = getCommonParentPath(environmentWithHtml.map((item)=>item.distPath));
|
|
5704
|
-
return environmentWithHtml.reduce((prev, environmentContext)=>{
|
|
5705
|
-
let { distPath, config } = environmentContext, distPrefix = relative(commonDistPath, distPath).split(sep).join('/'), routes = formatRoutes(environmentContext.htmlPaths, context.normalizedConfig.server.base, posix.join(distPrefix, config.output.distPath.html), config.html.outputStructure);
|
|
5706
|
-
return prev.concat(...routes);
|
|
5707
|
-
}, []);
|
|
5708
|
-
}, formatRoutes = (entry, base, distPathPrefix, outputStructure)=>{
|
|
5709
|
-
let prefix = joinUrlPath(base, formatPrefix(distPathPrefix));
|
|
5710
|
-
return Object.keys(entry).map((entryName)=>({
|
|
5711
|
-
entryName,
|
|
5712
|
-
pathname: prefix + ('index' === entryName && 'nested' !== outputStructure ? '' : entryName)
|
|
5713
|
-
})).sort((a)=>'index' === a.entryName ? -1 : 1);
|
|
5714
|
-
}, formatName = (name)=>name ? `(${name.length > 20 ? `${name.slice(0, 19)}…` : name})` : name;
|
|
5715
|
-
function getURLMessages(urls, routes, { maxRoutes = 10, showAllRoutes, cliShortcutsEnabled }) {
|
|
5716
|
-
let prevName, routeLimit = showAllRoutes ? 1 / 0 : void 0 === maxRoutes ? 10 : 1 / 0 === maxRoutes ? maxRoutes : Math.max(0, Math.floor(maxRoutes)), printableRoutes = 0 === routeLimit ? [] : routes.slice(0, routeLimit), moreEntries = routeLimit > 0 ? routes.length - printableRoutes.length : 0, nameCount = 0;
|
|
5717
|
-
for (let { name } of urls)if (name && ++nameCount > 1) break;
|
|
5718
|
-
let showNames = nameCount > 1;
|
|
5719
|
-
if (routes.length <= 1 || 0 === printableRoutes.length) {
|
|
5720
|
-
let pathname = printableRoutes[0]?.pathname ?? '', items = urls.map(({ label, name, url })=>({
|
|
5721
|
-
label,
|
|
5722
|
-
name: showNames ? formatName(name) : void 0,
|
|
5723
|
-
url: normalizeUrl(`${url}${pathname}`)
|
|
5724
|
-
})), labelWidth = Math.max(10, ...items.map((item)=>item.label.trimEnd().length + 2)), urlWidth = Math.max(0, ...items.map((item)=>item.name ? item.url.length : 0)), message = items.map(({ label, name, url })=>{
|
|
5725
|
-
let prefix = `➜ ${color.dim(label.trimEnd().padEnd(labelWidth))}`, suffix = name ? `${' '.repeat(urlWidth - url.length + 2)}${color.dim(name)}` : '';
|
|
5726
|
-
return ` ${prefix}${color.cyan(url)}${suffix}\n`;
|
|
5727
|
-
}).join('');
|
|
5728
|
-
return moreEntries > 0 && (message += getMoreEntriesMessage(moreEntries, cliShortcutsEnabled)), message;
|
|
5729
|
-
}
|
|
5730
|
-
let message = '', prevLabel = '', entryWidth = Math.max(...printableRoutes.map((route)=>route.entryName.length));
|
|
5731
|
-
return urls.forEach(({ label, name, url }, index)=>{
|
|
5732
|
-
let shortName = showNames ? formatName(name) : void 0;
|
|
5733
|
-
if (prevLabel !== label || prevName !== shortName) {
|
|
5734
|
-
index > 0 && (message += '\n');
|
|
5735
|
-
let title = shortName ? `${label.trimEnd().slice(0, -1)} ${color.dim(shortName)}:` : label;
|
|
5736
|
-
message += ` ➜ ${title}\n`, prevLabel = label, prevName = shortName;
|
|
5737
|
-
}
|
|
5738
|
-
for (let { entryName, pathname } of printableRoutes)message += ` ${color.dim('-')} ${color.dim(entryName.padEnd(entryWidth + 4))}${color.cyan(normalizeUrl(`${url}${pathname}`))}\n`;
|
|
5739
|
-
}), moreEntries > 0 && (message += getMoreEntriesMessage(moreEntries, cliShortcutsEnabled)), message;
|
|
5740
|
-
}
|
|
5741
|
-
function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls, fallbackPathname, showAllRoutes, cliShortcutsEnabled, originalConfig, logger }) {
|
|
5742
|
-
if (!1 === printUrls) return null;
|
|
5743
|
-
let urls = originalUrls, useCustomUrl = isFunction(printUrls);
|
|
5744
|
-
if (useCustomUrl) {
|
|
5745
|
-
let newUrls = printUrls({
|
|
5746
|
-
urls: urls.map((item)=>item.url),
|
|
5747
|
-
port,
|
|
5748
|
-
routes,
|
|
5749
|
-
protocol
|
|
5750
|
-
});
|
|
5751
|
-
if (!newUrls) return null;
|
|
5752
|
-
if (!Array.isArray(newUrls)) throw Error(`${color.dim('[rsbuild:config]')} "server.printUrls" must return an array, but got ${typeof newUrls}.`);
|
|
5753
|
-
urls = newUrls.map((u)=>{
|
|
5754
|
-
let { url, label } = 'string' == typeof u ? {
|
|
5755
|
-
url: u
|
|
5756
|
-
} : u;
|
|
5757
|
-
return {
|
|
5758
|
-
url,
|
|
5759
|
-
label: label ?? getUrlLabel(url)
|
|
5760
|
-
};
|
|
5761
|
-
});
|
|
5762
|
-
}
|
|
5763
|
-
if (0 === urls.length) return null;
|
|
5764
|
-
let printableRoutes = 0 !== routes.length || useCustomUrl || void 0 === fallbackPathname ? routes : [
|
|
5765
|
-
{
|
|
5766
|
-
entryName: 'index',
|
|
5767
|
-
pathname: formatPrefix(fallbackPathname)
|
|
5768
|
-
}
|
|
5769
|
-
];
|
|
5770
|
-
if (0 === printableRoutes.length && !useCustomUrl) return null;
|
|
5771
|
-
let printUrlsOptions = printUrls && 'object' == typeof printUrls ? printUrls : {}, message = getURLMessages(urls, printableRoutes, {
|
|
5772
|
-
maxRoutes: useCustomUrl ? 1 / 0 : printUrlsOptions.maxRoutes,
|
|
5773
|
-
showAllRoutes,
|
|
5774
|
-
cliShortcutsEnabled
|
|
5775
|
-
});
|
|
5776
|
-
return originalConfig && originalConfig.server?.host === void 0 && (message += ` ➜ ${color.dim('Network:')} ${color.dim('use')} ${color.bold('--host')} ${color.dim('to expose')}\n`), !0 === cliShortcutsEnabled && message.endsWith('\n') && (message = message.slice(0, -1)), logger.log(message), message;
|
|
5777
|
-
}
|
|
5778
|
-
let getPort = async ({ host, port, strictPort, tryLimits = 20 })=>{
|
|
5779
|
-
'string' == typeof port && (port = Number.parseInt(port, 10)), strictPort && (tryLimits = 1);
|
|
5780
|
-
let { createServer } = await import("node:net"), original = port, found = !1, attempts = 0;
|
|
5781
|
-
for(; !found && attempts <= tryLimits;)try {
|
|
5782
|
-
await new Promise((resolve, reject)=>{
|
|
5783
|
-
let server = createServer();
|
|
5784
|
-
server.unref(), server.on('error', reject), server.listen({
|
|
5785
|
-
port,
|
|
5786
|
-
host
|
|
5787
|
-
}, ()=>{
|
|
5788
|
-
if (0 === port) {
|
|
5789
|
-
let address = server.address();
|
|
5790
|
-
address && 'string' != typeof address && (port = address.port);
|
|
5791
|
-
}
|
|
5792
|
-
found = !0, server.close(resolve);
|
|
5793
|
-
});
|
|
5794
|
-
});
|
|
5795
|
-
} catch (e) {
|
|
5796
|
-
if (!(e instanceof Error) || !('code' in e) || 'EADDRINUSE' !== e.code) throw e;
|
|
5797
|
-
port++, attempts++;
|
|
5798
|
-
}
|
|
5799
|
-
if (!found) throw Error(`${color.dim('[rsbuild:server]')} Failed to find an available port after ${tryLimits + 1} attempts, starting from ${color.yellow(original)}.`);
|
|
5800
|
-
if (0 !== original && port !== original && strictPort) throw Error(`${color.dim('[rsbuild:server]')} Port ${color.yellow(original)} is occupied, please choose another one.`);
|
|
5801
|
-
return port;
|
|
5802
|
-
}, resolvePort = async (config, lastPort)=>{
|
|
5803
|
-
let { host, port: originalPort, strictPort } = config.server, preferredPort = 0 === originalPort ? lastPort : void 0, port = await getPort({
|
|
5804
|
-
host,
|
|
5805
|
-
port: preferredPort ?? originalPort,
|
|
5806
|
-
strictPort: void 0 === preferredPort && strictPort
|
|
5807
|
-
}), portTip = 0 !== originalPort && port !== originalPort ? `port ${originalPort} is in use, ${color.yellow(`using port ${port}.`)}` : void 0;
|
|
5808
|
-
return {
|
|
5809
|
-
port,
|
|
5810
|
-
portTip
|
|
5811
|
-
};
|
|
5812
|
-
}, WILDCARD_HOSTS = new Set([
|
|
5813
|
-
ALL_INTERFACES_IPV4,
|
|
5814
|
-
'::',
|
|
5815
|
-
'0000:0000:0000:0000:0000:0000:0000:0000'
|
|
5816
|
-
]), LOOPBACK_HOSTS = new Set([
|
|
5817
|
-
LOCALHOST,
|
|
5818
|
-
'127.0.0.1',
|
|
5819
|
-
'::1',
|
|
5820
|
-
'0000:0000:0000:0000:0000:0000:0000:0001'
|
|
5821
|
-
]), isLoopbackHost = (host)=>LOOPBACK_HOSTS.has(host), getHostInUrl = async (host)=>{
|
|
5822
|
-
if (host === ALL_INTERFACES_IPV4 || host === LOCALHOST) return LOCALHOST;
|
|
5823
|
-
let { isIPv6 } = await import("node:net");
|
|
5824
|
-
return isIPv6(host) ? '::' === host ? '[::1]' : `[${host}]` : host;
|
|
5825
|
-
}, concatUrl = ({ host, port, protocol })=>`${protocol}://${host}:${port}`, LOCAL_LABEL = 'Local: ', NETWORK_LABEL = 'Network: ', getUrlLabel = (url)=>{
|
|
5826
|
-
try {
|
|
5827
|
-
let { hostname } = new URL(url);
|
|
5828
|
-
return isLoopbackHost(hostname) ? LOCAL_LABEL : NETWORK_LABEL;
|
|
5829
|
-
} catch {
|
|
5830
|
-
return NETWORK_LABEL;
|
|
5831
|
-
}
|
|
5832
|
-
}, getAddressUrls = async ({ protocol, port, host })=>{
|
|
5833
|
-
if (host && host !== ALL_INTERFACES_IPV4) {
|
|
5834
|
-
let url = concatUrl({
|
|
5835
|
-
port,
|
|
5836
|
-
host: await getHostInUrl(host),
|
|
5837
|
-
protocol
|
|
5838
|
-
});
|
|
5839
|
-
return [
|
|
5840
|
-
{
|
|
5841
|
-
label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL,
|
|
5842
|
-
url
|
|
5843
|
-
}
|
|
5844
|
-
];
|
|
5845
|
-
}
|
|
5846
|
-
let urls = [], seen = new Set(), hasLocal = !1;
|
|
5847
|
-
for (let [name, infos] of Object.entries(node_os.networkInterfaces()))for (let info of infos ?? []){
|
|
5848
|
-
let family = info.family;
|
|
5849
|
-
!('IPv4' !== family && 4 !== family || seen.has(info.address)) && (seen.add(info.address), isLoopbackHost(info.address) || info.internal ? hasLocal || (urls.push({
|
|
5850
|
-
label: LOCAL_LABEL,
|
|
5851
|
-
url: concatUrl({
|
|
5852
|
-
host: LOCALHOST,
|
|
5853
|
-
port,
|
|
5854
|
-
protocol
|
|
5855
|
-
})
|
|
5856
|
-
}), hasLocal = !0) : urls.push({
|
|
5857
|
-
label: NETWORK_LABEL,
|
|
5858
|
-
name,
|
|
5859
|
-
url: concatUrl({
|
|
5860
|
-
host: info.address,
|
|
5861
|
-
port,
|
|
5862
|
-
protocol
|
|
5863
|
-
})
|
|
5864
|
-
}));
|
|
5865
|
-
}
|
|
5866
|
-
return urls;
|
|
5867
|
-
};
|
|
5868
|
-
function getServerTerminator(server) {
|
|
5869
|
-
let listened = !1, pendingSockets = new Set(), onConnection = (socket)=>{
|
|
5870
|
-
pendingSockets.add(socket), socket.on('close', ()=>{
|
|
5871
|
-
pendingSockets.delete(socket);
|
|
5872
|
-
});
|
|
5873
|
-
};
|
|
5874
|
-
return server.on('connection', onConnection), server.on('secureConnection', onConnection), server.once('listening', ()=>{
|
|
5875
|
-
listened = !0;
|
|
5876
|
-
}), ()=>new Promise((resolve, reject)=>{
|
|
5877
|
-
for (let socket of pendingSockets)socket.destroy();
|
|
5878
|
-
listened ? server.close((err)=>{
|
|
5879
|
-
err ? reject(err) : resolve();
|
|
5880
|
-
}) : resolve();
|
|
5881
|
-
});
|
|
5882
|
-
}
|
|
5883
|
-
function escapeHtml(text) {
|
|
5884
|
-
return text ? text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''') : '';
|
|
5885
|
-
}
|
|
5886
5897
|
let supportedChromiumBrowsers = [
|
|
5887
5898
|
'Google Chrome Canary',
|
|
5888
5899
|
'Google Chrome Dev',
|
|
@@ -5993,7 +6004,7 @@ function doesChunkBelongToHtml({ chunk, htmlPluginData }) {
|
|
|
5993
6004
|
let { options } = htmlPluginData.plugin;
|
|
5994
6005
|
return recursiveChunkEntryNames(chunk).some((chunkName)=>isChunksFiltered(chunkName, options?.chunks, options?.excludeChunks));
|
|
5995
6006
|
}
|
|
5996
|
-
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/
|
|
6007
|
+
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/5d29cc83887df39016e8cad6b1c60b4fe006f49047c680407d40dcd6e311784e/node_modules/rspack-manifest-plugin/dist/index.js"))), isCSSPath = (filePath)=>filePath.endsWith('.css');
|
|
5997
6008
|
function normalizeManifestObjectConfig(manifest) {
|
|
5998
6009
|
let defaultOptions = {
|
|
5999
6010
|
prefix: !0,
|
|
@@ -6095,7 +6106,7 @@ function extractChunks(compilation, includeType) {
|
|
|
6095
6106
|
];
|
|
6096
6107
|
return void 0 === includeType || 'async-chunks' === includeType ? chunks.filter(isAsyncChunk) : 'initial' === includeType ? chunks.filter((chunk)=>!isAsyncChunk(chunk)) : 'all-chunks' === includeType ? chunks : 'all-assets' === includeType ? [
|
|
6097
6108
|
{
|
|
6098
|
-
files:
|
|
6109
|
+
files: getAssetNames(compilation).filter((file)=>!LICENSE_ASSET_REGEX.test(file))
|
|
6099
6110
|
}
|
|
6100
6111
|
] : chunks;
|
|
6101
6112
|
}
|
|
@@ -6236,6 +6247,38 @@ async function applyProfile(root, filterValue, traceLayer, traceOutput) {
|
|
|
6236
6247
|
let filter = resolveLayer(filterValue);
|
|
6237
6248
|
return isTerminalTraceOutput(traceOutput) || await ensureFileDir(traceOutput), await core_rspack.experiments.globalTrace.register(filter, traceLayer, traceOutput), traceOutput;
|
|
6238
6249
|
}
|
|
6250
|
+
let copyPublicDir = async (publicDir, distPaths, ignore)=>{
|
|
6251
|
+
let shouldCopy;
|
|
6252
|
+
if (ignore?.length) {
|
|
6253
|
+
let { globSync } = await getTinyglobby(), ignoredSet = new Set(globSync(ignore, {
|
|
6254
|
+
cwd: publicDir,
|
|
6255
|
+
absolute: !1,
|
|
6256
|
+
dot: !0,
|
|
6257
|
+
onlyFiles: !1
|
|
6258
|
+
}).map((item)=>item.replace(/\\/g, '/').replace(/\/$/, '')));
|
|
6259
|
+
shouldCopy = (source)=>{
|
|
6260
|
+
let relativePath = node_path.relative(publicDir, source);
|
|
6261
|
+
if (!relativePath) return !0;
|
|
6262
|
+
let normalizedPath = relativePath.replace(/\\/g, '/');
|
|
6263
|
+
return !ignoredSet.has(normalizedPath);
|
|
6264
|
+
};
|
|
6265
|
+
}
|
|
6266
|
+
try {
|
|
6267
|
+
await Promise.all(distPaths.map(async (distPath)=>{
|
|
6268
|
+
isDeno && node_fs.existsSync(distPath) && await node_fs.promises.rm(distPath, {
|
|
6269
|
+
recursive: !0,
|
|
6270
|
+
force: !0
|
|
6271
|
+
}), await node_fs.promises.cp(publicDir, distPath, {
|
|
6272
|
+
recursive: !0,
|
|
6273
|
+
dereference: !0,
|
|
6274
|
+
mode: node_fs.constants.COPYFILE_FICLONE,
|
|
6275
|
+
filter: shouldCopy
|
|
6276
|
+
});
|
|
6277
|
+
}));
|
|
6278
|
+
} catch (err) {
|
|
6279
|
+
throw err instanceof Error && (err.message = `Failed to copy public directory '${color.yellow(publicDir)}' to output directory. To disable public directory copying, set \`${color.cyan('server.publicDir: false')}\` in your config.\n${err.message}`), err;
|
|
6280
|
+
}
|
|
6281
|
+
};
|
|
6239
6282
|
function getForceSplittingGroups(forceSplitting, strategy) {
|
|
6240
6283
|
let cacheGroups = {};
|
|
6241
6284
|
for (let [key, regexp] of Array.isArray(forceSplitting) ? forceSplitting.map((regexp, index)=>[
|
|
@@ -6518,7 +6561,11 @@ async function getFileFromUrl(url, outputFileSystem, context) {
|
|
|
6518
6561
|
for (let [index, distPath] of distPaths.entries()){
|
|
6519
6562
|
let prefix = publicPathnames[index];
|
|
6520
6563
|
if (prefix && '/' !== prefix && isUrlPathUnderBase(pathname, prefix)) {
|
|
6521
|
-
let
|
|
6564
|
+
let relativePathname = pathname.slice(prefix.length);
|
|
6565
|
+
if (hasUpPath && UP_PATH_REGEXP.test(node_path.normalize(`./${relativePathname}`))) return {
|
|
6566
|
+
errorCode: 403
|
|
6567
|
+
};
|
|
6568
|
+
let candidatePath = node_path.join(distPath, relativePathname);
|
|
6522
6569
|
if (hasUpPath) {
|
|
6523
6570
|
let relativePath = node_path.relative(distPath, candidatePath);
|
|
6524
6571
|
if (UP_PATH_REGEXP.test(relativePath)) return {
|
|
@@ -6709,21 +6756,21 @@ function sendError(res, code) {
|
|
|
6709
6756
|
res.setHeader('Content-Length', byteLength), res.end(document);
|
|
6710
6757
|
}
|
|
6711
6758
|
let filterWebEnvironments = (environmentList)=>environmentList.filter((environment)=>isWebTarget(environment.config.output.target));
|
|
6712
|
-
function createAssetsMiddleware(context,
|
|
6759
|
+
function createAssetsMiddleware(context, { waitForAssets, waitForBuild }, outputFileSystem) {
|
|
6713
6760
|
let { logger } = context, webEnvironments = filterWebEnvironments(context.environmentList), assetContext = {
|
|
6714
6761
|
...context,
|
|
6715
6762
|
environmentList: webEnvironments,
|
|
6716
6763
|
publicPathnames: webEnvironments.map((environment)=>context.publicPathnames[environment.index])
|
|
6717
6764
|
};
|
|
6718
6765
|
return async function assetsMiddleware(req, res, next) {
|
|
6719
|
-
|
|
6766
|
+
function goNext() {
|
|
6720
6767
|
return new Promise((resolve)=>{
|
|
6721
|
-
|
|
6768
|
+
waitForBuild(()=>{
|
|
6722
6769
|
next(), resolve();
|
|
6723
6770
|
});
|
|
6724
6771
|
});
|
|
6725
6772
|
}
|
|
6726
|
-
req.method && 'GET' !== req.method && 'HEAD' !== req.method ? await goNext() :
|
|
6773
|
+
req.method && 'GET' !== req.method && 'HEAD' !== req.method ? await goNext() : waitForAssets(async function processRequest() {
|
|
6727
6774
|
let readStream;
|
|
6728
6775
|
if (!req.url) return void await goNext();
|
|
6729
6776
|
let resolved = await getFileFromUrl(req.url, outputFileSystem, assetContext);
|
|
@@ -6790,10 +6837,32 @@ function createAssetsMiddleware(context, ready, outputFileSystem) {
|
|
|
6790
6837
|
});
|
|
6791
6838
|
};
|
|
6792
6839
|
}
|
|
6840
|
+
function setupMemoryFileSystemCleanup(fileSystem, compilers) {
|
|
6841
|
+
if (compilers.some((compiler)=>compiler.options.output.clean)) return;
|
|
6842
|
+
let lastSeenByCompiler = compilers.map(()=>new Map());
|
|
6843
|
+
for (let [index, compiler] of compilers.entries()){
|
|
6844
|
+
let lastHash, lastSeen = lastSeenByCompiler[index], generation = 0;
|
|
6845
|
+
compiler.hooks.afterEmit.tap('rsbuild:clean-memory-filesystem', (compilation)=>{
|
|
6846
|
+
if (compilation.errors.length) return;
|
|
6847
|
+
compilation.hash !== lastHash && (generation++, lastHash = compilation.hash);
|
|
6848
|
+
let outputPath = compilation.getPath(compiler.outputPath);
|
|
6849
|
+
for (let name of getAssetNames(compilation)){
|
|
6850
|
+
let queryIndex = name.indexOf('?'), filePath = join(outputPath, -1 === queryIndex ? name : name.slice(0, queryIndex));
|
|
6851
|
+
lastSeen.set(filePath, generation);
|
|
6852
|
+
}
|
|
6853
|
+
for (let [filePath, seen] of lastSeen)if (!(seen >= generation - 1) && (lastSeen.delete(filePath), !lastSeenByCompiler.some((assets)=>assets.has(filePath)))) try {
|
|
6854
|
+
fileSystem.unlinkSync(filePath);
|
|
6855
|
+
} catch (error) {
|
|
6856
|
+
if ('ENOENT' !== error.code) throw error;
|
|
6857
|
+
}
|
|
6858
|
+
});
|
|
6859
|
+
}
|
|
6860
|
+
}
|
|
6793
6861
|
async function setupOutputFileSystem(writeAllToDisk, compilers) {
|
|
6794
6862
|
if (!writeAllToDisk) {
|
|
6795
6863
|
let { createMemoryFileSystem } = await import("./memfs.js"), outputFileSystem = createMemoryFileSystem();
|
|
6796
6864
|
for (let compiler of compilers)compiler.outputFileSystem = outputFileSystem;
|
|
6865
|
+
setupMemoryFileSystemCleanup(outputFileSystem, compilers);
|
|
6797
6866
|
}
|
|
6798
6867
|
let compiler = compilers.find((compiler)=>!!compiler.outputFileSystem);
|
|
6799
6868
|
return compiler?.outputFileSystem ?? node_fs;
|
|
@@ -6832,7 +6901,10 @@ let noop = ()=>{}, normalizeLiveReload = (liveReload)=>'boolean' == typeof liveR
|
|
|
6832
6901
|
} : {
|
|
6833
6902
|
enabled: !0,
|
|
6834
6903
|
html: !1 !== liveReload.html
|
|
6835
|
-
},
|
|
6904
|
+
}, isNodeCompiler = (compiler)=>{
|
|
6905
|
+
let { target } = compiler.options;
|
|
6906
|
+
return !!target && (Array.isArray(target) ? target.includes('node') : 'node' === target);
|
|
6907
|
+
}, isTsError = (error)=>'message' in error && error.stack?.includes('ts-checker-rspack-plugin');
|
|
6836
6908
|
function applyHMREntry({ config, compiler, token, resolvedHost, resolvedPort }) {
|
|
6837
6909
|
var overlay;
|
|
6838
6910
|
let overlay1;
|
|
@@ -6863,7 +6935,13 @@ init(
|
|
|
6863
6935
|
}).apply(compiler);
|
|
6864
6936
|
}
|
|
6865
6937
|
let assets_middleware_assetsMiddleware = async ({ config, compiler, context, socketServer, resolvedPort })=>{
|
|
6866
|
-
let watching, { logger } = context, resolvedHost = await resolveHostname(config.server.host), { environmentList } = context
|
|
6938
|
+
let watching, allCompilers, webCompilers, earlyWebUpdates, { logger } = context, resolvedHost = await resolveHostname(config.server.host), { environmentList } = context, { allCompilers: allCompilers1, webCompilers: webCompilers1, earlyWebUpdates: earlyWebUpdates1 } = (earlyWebUpdates = (webCompilers = (allCompilers = compiler_isMultiCompiler(compiler) ? compiler.compilers : [
|
|
6939
|
+
compiler
|
|
6940
|
+
]).filter((compiler)=>!isNodeCompiler(compiler))).length > 0 && webCompilers.length < allCompilers.length, {
|
|
6941
|
+
allCompilers,
|
|
6942
|
+
webCompilers,
|
|
6943
|
+
earlyWebUpdates
|
|
6944
|
+
});
|
|
6867
6945
|
applyToCompiler(compiler, (compiler, index)=>{
|
|
6868
6946
|
let environment = environmentList[index];
|
|
6869
6947
|
if (!environment) return;
|
|
@@ -6874,11 +6952,8 @@ let assets_middleware_assetsMiddleware = async ({ config, compiler, context, soc
|
|
|
6874
6952
|
compiler,
|
|
6875
6953
|
resolvedHost,
|
|
6876
6954
|
resolvedPort
|
|
6877
|
-
}), (({ context, compiler, token, socketServer, liveReload })=>{
|
|
6878
|
-
if ((
|
|
6879
|
-
let { target } = compiler.options;
|
|
6880
|
-
return !!target && (Array.isArray(target) ? target.includes('node') : 'node' === target);
|
|
6881
|
-
})(compiler)) return;
|
|
6955
|
+
}), (({ context, compiler, token, socketServer, liveReload, earlyWebUpdates })=>{
|
|
6956
|
+
if (isNodeCompiler(compiler)) return;
|
|
6882
6957
|
let errorsCount = null, warningsCount = null;
|
|
6883
6958
|
compiler.hooks.invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
6884
6959
|
errorsCount = null, warningsCount = null, 'string' == typeof fileName && fileName.endsWith('.html') && normalizeLiveReload(liveReload).html && socketServer.sendMessage({
|
|
@@ -6887,6 +6962,7 @@ let assets_middleware_assetsMiddleware = async ({ config, compiler, context, soc
|
|
|
6887
6962
|
}), compiler.hooks.done.tap('rsbuild-dev-server', (stats)=>{
|
|
6888
6963
|
let { errors, warnings } = stats.compilation;
|
|
6889
6964
|
if (errors.length === errorsCount && warnings.length === warningsCount) return;
|
|
6965
|
+
null === errorsCount && null === warningsCount && earlyWebUpdates && !stats.hasErrors() && socketServer.onEnvironmentDone(token, ()=>getRsbuildStats(stats, compiler, context.logger, context.action));
|
|
6890
6966
|
let isRecalled = null !== errorsCount || null !== warningsCount;
|
|
6891
6967
|
if (errorsCount = errors.length, warningsCount = warnings.length, isRecalled) {
|
|
6892
6968
|
let tsErrors = errors.filter(isTsError), tsWarnings = warnings.filter(isTsError);
|
|
@@ -6914,30 +6990,47 @@ let assets_middleware_assetsMiddleware = async ({ config, compiler, context, soc
|
|
|
6914
6990
|
compiler,
|
|
6915
6991
|
socketServer,
|
|
6916
6992
|
token,
|
|
6917
|
-
liveReload: environment.config.dev.liveReload
|
|
6993
|
+
liveReload: environment.config.dev.liveReload,
|
|
6994
|
+
earlyWebUpdates: earlyWebUpdates1
|
|
6918
6995
|
}));
|
|
6919
6996
|
});
|
|
6920
|
-
let
|
|
6921
|
-
compiler
|
|
6922
|
-
], callbacks = [], flushCallbacks = ()=>{
|
|
6997
|
+
let assetCallbacks = [], buildCallbacks = [], flushCallbacks = (callbacks)=>{
|
|
6923
6998
|
for (let callback of callbacks.splice(0))callback();
|
|
6999
|
+
}, flushAllCallbacks = ()=>{
|
|
7000
|
+
flushCallbacks(assetCallbacks), flushCallbacks(buildCallbacks);
|
|
6924
7001
|
};
|
|
6925
7002
|
compiler.hooks.done.tap('rsbuild-dev-middleware', ()=>{
|
|
6926
7003
|
process.nextTick(()=>{
|
|
6927
|
-
'done' === context.buildState.status &&
|
|
7004
|
+
'done' === context.buildState.status && flushAllCallbacks();
|
|
6928
7005
|
});
|
|
6929
7006
|
});
|
|
7007
|
+
let compiledWebCompilers = new Set(), isWebReady = ()=>earlyWebUpdates1 && compiledWebCompilers.size === webCompilers1.length;
|
|
7008
|
+
if (earlyWebUpdates1) for (let item of webCompilers1){
|
|
7009
|
+
let reset = ()=>{
|
|
7010
|
+
compiledWebCompilers.delete(item);
|
|
7011
|
+
};
|
|
7012
|
+
item.hooks.invalid.tap('rsbuild-dev-middleware', reset), item.hooks.watchRun.tap('rsbuild-dev-middleware', reset), item.hooks.done.tap('rsbuild-dev-middleware', (stats)=>{
|
|
7013
|
+
!stats.hasErrors() && (compiledWebCompilers.add(item), isWebReady() && process.nextTick(()=>{
|
|
7014
|
+
isWebReady() && flushCallbacks(assetCallbacks);
|
|
7015
|
+
}));
|
|
7016
|
+
});
|
|
7017
|
+
}
|
|
6930
7018
|
let writeToDiskList = environmentList.map((environment)=>environment.config.dev.writeToDisk);
|
|
6931
|
-
writeToDiskList.some(Boolean) && setupWriteToDisk(
|
|
6932
|
-
let instance = createAssetsMiddleware(context,
|
|
6933
|
-
|
|
6934
|
-
|
|
7019
|
+
writeToDiskList.some(Boolean) && setupWriteToDisk(allCompilers1, writeToDiskList, logger);
|
|
7020
|
+
let outputFileSystem = await setupOutputFileSystem(writeToDiskList.every((writeToDisk)=>!0 === writeToDisk), allCompilers1), isBuildReady = ()=>'done' === context.buildState.status || 'failed' === context.buildState.status, instance = createAssetsMiddleware(context, {
|
|
7021
|
+
waitForAssets: (callback)=>{
|
|
7022
|
+
isBuildReady() || isWebReady() ? callback() : assetCallbacks.push(callback);
|
|
7023
|
+
},
|
|
7024
|
+
waitForBuild: (callback)=>{
|
|
7025
|
+
isBuildReady() ? callback() : buildCallbacks.push(callback);
|
|
7026
|
+
}
|
|
7027
|
+
}, outputFileSystem);
|
|
6935
7028
|
return instance.watch = ()=>{
|
|
6936
7029
|
if (compiler.watching) watching = compiler.watching;
|
|
6937
7030
|
else {
|
|
6938
|
-
let watchOptions =
|
|
7031
|
+
let watchOptions = allCompilers1.length > 1 ? allCompilers1.map(({ options })=>options.watchOptions || {}) : allCompilers1[0].options.watchOptions || {};
|
|
6939
7032
|
watching = compiler.watch(watchOptions, (error)=>{
|
|
6940
|
-
error && (context.buildState.status = 'failed', context.buildState.hasErrors = !0, process.nextTick(
|
|
7033
|
+
error && (context.buildState.status = 'failed', context.buildState.hasErrors = !0, process.nextTick(flushAllCallbacks), error.message?.includes('× Error:') && (error.message = error.message.replace('× Error:', '').trim()), logger.error(error));
|
|
6941
7034
|
});
|
|
6942
7035
|
}
|
|
6943
7036
|
}, instance.close = (callback = noop)=>{
|
|
@@ -7184,6 +7277,7 @@ class SocketServer {
|
|
|
7184
7277
|
getOutputFileSystem;
|
|
7185
7278
|
reportedBrowserLogs = new Set();
|
|
7186
7279
|
currentHash = new Map();
|
|
7280
|
+
environmentStats = new Map();
|
|
7187
7281
|
onSocketConnect;
|
|
7188
7282
|
constructor(context, options, getOutputFileSystem, onSocketConnect){
|
|
7189
7283
|
this.context = context, this.options = options, this.getOutputFileSystem = getOutputFileSystem, this.onSocketConnect = onSocketConnect;
|
|
@@ -7215,8 +7309,16 @@ class SocketServer {
|
|
|
7215
7309
|
this.onConnect(socket, query.token);
|
|
7216
7310
|
});
|
|
7217
7311
|
}
|
|
7312
|
+
onEnvironmentDone(token, getStats) {
|
|
7313
|
+
'done' !== this.context.buildState.status && this.socketsMap.has(token) && (this.environmentStats.set(token, getStats()), this.sendStats({
|
|
7314
|
+
token
|
|
7315
|
+
}));
|
|
7316
|
+
}
|
|
7317
|
+
clearEnvironmentStats() {
|
|
7318
|
+
this.environmentStats.clear();
|
|
7319
|
+
}
|
|
7218
7320
|
onBuildDone() {
|
|
7219
|
-
if (this.reportedBrowserLogs.clear(), this.ensureInitialChunks(), this.socketsMap.size) for (let token of this.socketsMap.keys())this.sendStats({
|
|
7321
|
+
if (this.environmentStats.clear(), this.reportedBrowserLogs.clear(), this.ensureInitialChunks(), this.socketsMap.size) for (let token of this.socketsMap.keys())this.sendStats({
|
|
7220
7322
|
token
|
|
7221
7323
|
});
|
|
7222
7324
|
}
|
|
@@ -7334,6 +7436,12 @@ class SocketServer {
|
|
|
7334
7436
|
}
|
|
7335
7437
|
}
|
|
7336
7438
|
getStats(token) {
|
|
7439
|
+
let environmentStats = this.environmentStats.get(token);
|
|
7440
|
+
if (environmentStats) return {
|
|
7441
|
+
stats: environmentStats,
|
|
7442
|
+
errors: getStatsErrors(environmentStats),
|
|
7443
|
+
warnings: getStatsWarnings(environmentStats)
|
|
7444
|
+
};
|
|
7337
7445
|
let { stats } = this.context.buildState, environment = this.getEnvironmentByToken(token);
|
|
7338
7446
|
if (!stats || !environment) return;
|
|
7339
7447
|
let currentStats = stats;
|
|
@@ -7354,6 +7462,13 @@ class SocketServer {
|
|
|
7354
7462
|
if (this.initialChunksMap.set(token, newInitialChunks), shouldReload) return void this.sendMessage({
|
|
7355
7463
|
type: 'full-reload'
|
|
7356
7464
|
}, token);
|
|
7465
|
+
if (this.environmentStats.has(token)) {
|
|
7466
|
+
stats.hash && (this.currentHash.set(token, stats.hash), this.sendMessage({
|
|
7467
|
+
type: 'early-update',
|
|
7468
|
+
data: stats.hash
|
|
7469
|
+
}, token));
|
|
7470
|
+
return;
|
|
7471
|
+
}
|
|
7357
7472
|
if (stats.hash) {
|
|
7358
7473
|
let prevHash = this.currentHash.get(token);
|
|
7359
7474
|
if (this.currentHash.set(token, stats.hash), !force && 0 === errors.length && 0 === warnings.length && prevHash === stats.hash) return void this.sendMessage({
|
|
@@ -7740,7 +7855,7 @@ let applyDefaultMiddlewares = async ({ config, buildManager, context, devServer,
|
|
|
7740
7855
|
let { compiler } = buildManager;
|
|
7741
7856
|
(compiler_isMultiCompiler(compiler) ? compiler.compilers.some((childCompiler)=>childCompiler.options.lazyCompilation) : compiler.options.lazyCompilation) && middlewares.use(core_rspack.lazyCompilationMiddleware(compiler));
|
|
7742
7857
|
}
|
|
7743
|
-
|
|
7858
|
+
server.base && '/' !== server.base && middlewares.use(getBaseUrlMiddleware({
|
|
7744
7859
|
base: server.base
|
|
7745
7860
|
})), middlewares.use('/__open-in-editor', async (req, res, next)=>{
|
|
7746
7861
|
try {
|
|
@@ -7801,7 +7916,7 @@ let applyDefaultMiddlewares = async ({ config, buildManager, context, devServer,
|
|
|
7801
7916
|
try {
|
|
7802
7917
|
for(let key in environments){
|
|
7803
7918
|
res.write(`<h2>Environment: ${key}</h2>`);
|
|
7804
|
-
let list = [], environment = environments[key], stats = await environment.getStats(), assets =
|
|
7919
|
+
let list = [], environment = environments[key], stats = await environment.getStats(), assets = getAssetNames(stats.compilation);
|
|
7805
7920
|
for (let asset of (res.write('<ul>'), assets))list.push(`<li><a target="_blank" href="${asset}">${asset}</a></li>`);
|
|
7806
7921
|
res.write(list?.join('')), res.write('</ul>');
|
|
7807
7922
|
}
|
|
@@ -7823,9 +7938,11 @@ let applyDefaultMiddlewares = async ({ config, buildManager, context, devServer,
|
|
|
7823
7938
|
context.distPath
|
|
7824
7939
|
],
|
|
7825
7940
|
outputFileSystem: buildManager.outputFileSystem
|
|
7826
|
-
}))
|
|
7941
|
+
}));
|
|
7942
|
+
let publicDirPaths = getPublicDirPaths(config);
|
|
7943
|
+
if (publicDirPaths.length) {
|
|
7827
7944
|
let { default: sirv } = await import("./sirv.js");
|
|
7828
|
-
for (let
|
|
7945
|
+
for (let name of publicDirPaths){
|
|
7829
7946
|
let sirvMiddleware = sirv(name, {
|
|
7830
7947
|
etag: !0,
|
|
7831
7948
|
dev: !0
|
|
@@ -8512,7 +8629,10 @@ async function startPreviewServer(context, config, { getPortSilently } = {}) {
|
|
|
8512
8629
|
server: previewServer,
|
|
8513
8630
|
environments: context.environments
|
|
8514
8631
|
});
|
|
8515
|
-
let webEnvironments = filterWebEnvironments(context.environmentList), assetsMiddleware = createAssetsMiddleware(context,
|
|
8632
|
+
let webEnvironments = filterWebEnvironments(context.environmentList), assetsMiddleware = createAssetsMiddleware(context, {
|
|
8633
|
+
waitForAssets: (callback)=>callback(),
|
|
8634
|
+
waitForBuild: (callback)=>callback()
|
|
8635
|
+
}, node_fs), htmlMiddlewareOptions = {
|
|
8516
8636
|
assetsMiddleware,
|
|
8517
8637
|
distPaths: webEnvironments.map((environment)=>environment.distPath),
|
|
8518
8638
|
outputFileSystem: node_fs
|
|
@@ -8937,7 +9057,7 @@ function applyDefaultPlugins(pluginManager, context) {
|
|
|
8937
9057
|
{
|
|
8938
9058
|
name: 'rsbuild:html',
|
|
8939
9059
|
setup (api) {
|
|
8940
|
-
let
|
|
9060
|
+
let defaultFaviconCache = new Map();
|
|
8941
9061
|
api.modifyBundlerChain(async (chain, { HtmlPlugin, CHAIN_ID, environment })=>{
|
|
8942
9062
|
let { config, htmlPaths } = environment;
|
|
8943
9063
|
if (0 === Object.keys(htmlPaths).length) return;
|
|
@@ -8969,17 +9089,18 @@ function applyDefaultPlugins(pluginManager, context) {
|
|
|
8969
9089
|
};
|
|
8970
9090
|
})(environment.config);
|
|
8971
9091
|
tagConfig && (extraData.tagConfig = tagConfig), pluginOptions.title = await getTitle(entryName, config);
|
|
8972
|
-
let favicon = await getFavicon(entryName, config) || (()=>{
|
|
8973
|
-
|
|
8974
|
-
let { publicDir } = api.getNormalizedConfig().server, extensions = [
|
|
9092
|
+
let favicon = await getFavicon(entryName, config) || ((config)=>{
|
|
9093
|
+
let { publicDir } = config.server, extensions = [
|
|
8975
9094
|
'ico',
|
|
8976
9095
|
'png',
|
|
8977
9096
|
'svg'
|
|
8978
|
-
], publicDirs = Array.from(new Set(publicDir.map(({ name })=>name))),
|
|
9097
|
+
], publicDirs = Array.from(new Set(publicDir.map(({ name })=>name))), key = JSON.stringify(publicDirs), defaultFavicon = defaultFaviconCache.get(key);
|
|
9098
|
+
if (defaultFavicon) return defaultFavicon;
|
|
9099
|
+
let faviconPaths = [];
|
|
8979
9100
|
for (let publicDir of publicDirs)for (let ext of extensions)faviconPaths.push(node_path.join(publicDir, `favicon.${ext}`));
|
|
8980
9101
|
let faviconPath = findExists(faviconPaths);
|
|
8981
|
-
|
|
8982
|
-
})();
|
|
9102
|
+
if (faviconPath) return defaultFaviconCache.set(key, faviconPath), faviconPath;
|
|
9103
|
+
})(config);
|
|
8983
9104
|
favicon && (extraData.favicon = favicon);
|
|
8984
9105
|
let finalOptions = await reduceConfigsWithContext({
|
|
8985
9106
|
initial: pluginOptions,
|
|
@@ -9693,39 +9814,22 @@ try {
|
|
|
9693
9814
|
}
|
|
9694
9815
|
};
|
|
9695
9816
|
api.onAfterStartDevServer(onStartServer), api.onAfterStartPreviewServer(onStartServer), api.onBeforeBuild(async ({ isFirstCompile, environments })=>{
|
|
9696
|
-
if (isFirstCompile)
|
|
9697
|
-
|
|
9817
|
+
if (!isFirstCompile) return;
|
|
9818
|
+
let groups = new Map();
|
|
9819
|
+
for (let environment of Object.values(environments)){
|
|
9820
|
+
let key = JSON.stringify(environment.config.server.publicDir.map(({ name, copyOnBuild, ignore })=>[
|
|
9821
|
+
name,
|
|
9822
|
+
copyOnBuild,
|
|
9823
|
+
ignore
|
|
9824
|
+
])), group = groups.get(key);
|
|
9825
|
+
group ? group.push(environment) : groups.set(key, [
|
|
9826
|
+
environment
|
|
9827
|
+
]);
|
|
9828
|
+
}
|
|
9829
|
+
for (let group of groups.values())for (let { name: publicDir, copyOnBuild, ignore } of group[0].config.server.publicDir){
|
|
9698
9830
|
if (!1 === copyOnBuild || !node_fs.existsSync(publicDir)) continue;
|
|
9699
|
-
let distPaths = dedupeNestedPaths(
|
|
9700
|
-
|
|
9701
|
-
let { globSync } = await getTinyglobby(), ignoredSet = new Set(globSync(ignore, {
|
|
9702
|
-
cwd: publicDir,
|
|
9703
|
-
absolute: !1,
|
|
9704
|
-
dot: !0,
|
|
9705
|
-
onlyFiles: !1
|
|
9706
|
-
}).map((item)=>item.replace(/\\/g, '/').replace(/\/$/, '')));
|
|
9707
|
-
shouldCopy = (source)=>{
|
|
9708
|
-
let relativePath = node_path.relative(publicDir, source);
|
|
9709
|
-
if (!relativePath) return !0;
|
|
9710
|
-
let normalizedPath = relativePath.replace(/\\/g, '/');
|
|
9711
|
-
return !ignoredSet.has(normalizedPath);
|
|
9712
|
-
};
|
|
9713
|
-
}
|
|
9714
|
-
try {
|
|
9715
|
-
await Promise.all(distPaths.map(async (distPath)=>{
|
|
9716
|
-
isDeno && node_fs.existsSync(distPath) && await node_fs.promises.rm(distPath, {
|
|
9717
|
-
recursive: !0,
|
|
9718
|
-
force: !0
|
|
9719
|
-
}), await node_fs.promises.cp(publicDir, distPath, {
|
|
9720
|
-
recursive: !0,
|
|
9721
|
-
dereference: !0,
|
|
9722
|
-
mode: node_fs.constants.COPYFILE_FICLONE,
|
|
9723
|
-
filter: shouldCopy
|
|
9724
|
-
});
|
|
9725
|
-
}));
|
|
9726
|
-
} catch (err) {
|
|
9727
|
-
throw err instanceof Error && (err.message = `Failed to copy public directory '${color.yellow(publicDir)}' to output directory. To disable public directory copying, set \`${color.cyan('server.publicDir: false')}\` in your config.\n${err.message}`), err;
|
|
9728
|
-
}
|
|
9831
|
+
let distPaths = dedupeNestedPaths(group.filter(({ config })=>!0 === copyOnBuild || 'node' !== config.output.target).map(({ distPath })=>distPath));
|
|
9832
|
+
0 !== distPaths.length && await copyPublicDir(publicDir, distPaths, ignore);
|
|
9729
9833
|
}
|
|
9730
9834
|
});
|
|
9731
9835
|
}
|
|
@@ -10293,7 +10397,7 @@ let applyServerOptions = (command)=>{
|
|
|
10293
10397
|
};
|
|
10294
10398
|
function setupCommands(argv) {
|
|
10295
10399
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
10296
|
-
cli.version("2.3.0-
|
|
10400
|
+
cli.version("2.3.0-rc.0"), 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)', {
|
|
10297
10401
|
default: 'auto'
|
|
10298
10402
|
}).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', {
|
|
10299
10403
|
type: [
|
|
@@ -10358,7 +10462,7 @@ function setupCommands(argv) {
|
|
|
10358
10462
|
}
|
|
10359
10463
|
function showGreeting() {
|
|
10360
10464
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
10361
|
-
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.3.0-
|
|
10465
|
+
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.3.0-rc.0\n`);
|
|
10362
10466
|
}
|
|
10363
10467
|
function setupLogLevel(argv) {
|
|
10364
10468
|
if (argv.length <= 3) return;
|
|
@@ -10380,5 +10484,5 @@ function runCLI({ argv = process.argv } = {}) {
|
|
|
10380
10484
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
|
|
10381
10485
|
}
|
|
10382
10486
|
}
|
|
10383
|
-
let src_version = "2.3.0-
|
|
10487
|
+
let src_version = "2.3.0-rc.0";
|
|
10384
10488
|
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 };
|