@rsbuild/core 2.3.0 → 2.3.1
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/css-loader/index.js +2 -2
- package/compiled/html-rspack-plugin/index.js +14 -14
- 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/overlay.js +2 -2
- package/dist/http-proxy-middleware.js +1 -1
- package/dist/m.js +849 -847
- package/dist/manifest-plugin.js +1 -1
- package/dist/memfs.js +1 -1
- package/dist/open.js +2 -2
- package/dist/server/assets-middleware/getFileFromUrl.d.ts +3 -1
- package/dist/transformLoader.mjs +10 -10
- package/dist/workerLoader.mjs +3 -3
- package/dist/ws.js +2 -2
- 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/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/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/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/options.js"), loadPlugins = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/plugins.js"), req = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/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/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/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/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/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/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/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/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/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/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/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);
|
|
@@ -2608,14 +2608,22 @@ let OVERRIDE_PATHS = new Set([
|
|
|
2608
2608
|
y
|
|
2609
2609
|
];
|
|
2610
2610
|
if (!isPlainObject(x) || !isPlainObject(y)) return y;
|
|
2611
|
-
let merged = {};
|
|
2612
|
-
for (let key of
|
|
2613
|
-
...Object.keys(x),
|
|
2614
|
-
...Object.keys(y)
|
|
2615
|
-
])){
|
|
2611
|
+
let merged = {}, xKeys = Object.keys(x), yKeys = Object.keys(y), xKeySet = xKeys.length > 8 && yKeys.length > 8 ? new Set(xKeys) : void 0;
|
|
2612
|
+
for (let key of xKeys){
|
|
2616
2613
|
let childPath = path ? `${path}.${key}` : key;
|
|
2617
2614
|
merged[key] = merge(x[key], y[key], childPath);
|
|
2618
2615
|
}
|
|
2616
|
+
for (let key of yKeys)if (!(xKeySet ? xKeySet.has(key) : xKeys.includes(key))) {
|
|
2617
|
+
let childPath = path ? `${path}.${key}` : key;
|
|
2618
|
+
merged[key] = merge(x[key], y[key], childPath);
|
|
2619
|
+
}
|
|
2620
|
+
for (let source of [
|
|
2621
|
+
x,
|
|
2622
|
+
y
|
|
2623
|
+
])for (let key of Object.getOwnPropertySymbols(source))if (Object.prototype.propertyIsEnumerable.call(source, key)) {
|
|
2624
|
+
let value = source[key];
|
|
2625
|
+
void 0 !== value && (merged[key] = value);
|
|
2626
|
+
}
|
|
2619
2627
|
return merged;
|
|
2620
2628
|
}, normalizeConfigStructure = (config)=>{
|
|
2621
2629
|
let { dev, output } = config, normalizedConfig = {
|
|
@@ -2788,17 +2796,7 @@ function getDefaultEntry(root) {
|
|
|
2788
2796
|
index: entryFile
|
|
2789
2797
|
} : {};
|
|
2790
2798
|
}
|
|
2791
|
-
let
|
|
2792
|
-
let config = mergeRsbuildConfig(createDefaultConfig(), userConfig);
|
|
2793
|
-
if (config.root ||= rootPath, config.source ||= {}, config.server?.base && (userConfig.dev?.assetPrefix === void 0 && (config.dev ||= {}, config.dev.assetPrefix = config.server.base), userConfig.output?.assetPrefix === void 0 && (config.output ||= {}, config.output.assetPrefix = config.server.base)), userConfig.dev?.client?.logLevel === void 0 && (config.dev ||= {}, config.dev.client ||= {}, config.dev.client.logLevel = config.logLevel), config.dev?.lazyCompilation === void 0 && (config.dev ||= {}, config.dev.lazyCompilation = {
|
|
2794
|
-
imports: !0,
|
|
2795
|
-
entries: !1
|
|
2796
|
-
}), !config.source.tsconfigPath) {
|
|
2797
|
-
let tsconfigPath = join(rootPath, TS_CONFIG_FILE);
|
|
2798
|
-
await isFileExists(tsconfigPath) && (config.source.tsconfigPath = tsconfigPath);
|
|
2799
|
-
}
|
|
2800
|
-
return config;
|
|
2801
|
-
}, normalizePublicDirs = (rootPath, publicDir)=>{
|
|
2799
|
+
let normalizePublicDirs = (rootPath, publicDir)=>{
|
|
2802
2800
|
if (!1 === publicDir) return [];
|
|
2803
2801
|
let defaultConfig = {
|
|
2804
2802
|
name: join(rootPath, 'public'),
|
|
@@ -3248,9 +3246,19 @@ function createPublicContext(context) {
|
|
|
3248
3246
|
});
|
|
3249
3247
|
}
|
|
3250
3248
|
async function createContext(options, userConfig, logger, loadConfigResult) {
|
|
3251
|
-
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await
|
|
3249
|
+
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await (async (rootPath, userConfig)=>{
|
|
3250
|
+
let config = mergeRsbuildConfig(createDefaultConfig(), userConfig);
|
|
3251
|
+
if (config.root ||= rootPath, config.source ||= {}, config.server?.base && (userConfig.dev?.assetPrefix === void 0 && (config.dev ||= {}, config.dev.assetPrefix = config.server.base), userConfig.output?.assetPrefix === void 0 && (config.output ||= {}, config.output.assetPrefix = config.server.base)), userConfig.dev?.client?.logLevel === void 0 && (config.dev ||= {}, config.dev.client ||= {}, config.dev.client.logLevel = config.logLevel), config.dev?.lazyCompilation === void 0 && (config.dev ||= {}, config.dev.lazyCompilation = {
|
|
3252
|
+
imports: !0,
|
|
3253
|
+
entries: !1
|
|
3254
|
+
}), !config.source.tsconfigPath) {
|
|
3255
|
+
let tsconfigPath = join(rootPath, TS_CONFIG_FILE);
|
|
3256
|
+
await isFileExists(tsconfigPath) && (config.source.tsconfigPath = tsconfigPath);
|
|
3257
|
+
}
|
|
3258
|
+
return config;
|
|
3259
|
+
})(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, hooks = initHooks();
|
|
3252
3260
|
return {
|
|
3253
|
-
version: "2.3.
|
|
3261
|
+
version: "2.3.1",
|
|
3254
3262
|
rootPath,
|
|
3255
3263
|
configFile: loadConfigResult?.filePath ?? userConfig._privateMeta?.configFilePath,
|
|
3256
3264
|
configFileDependencies: loadConfigResult?.dependencies ?? userConfig._privateMeta?.configFileDependencies ?? [],
|
|
@@ -3972,28 +3980,7 @@ async function createCompiler_createCompiler(options) {
|
|
|
3972
3980
|
let { message, level } = formatStats(stats, hasErrors, options.context.rootPath, logger);
|
|
3973
3981
|
'error' === level && logger.error(message), 'warning' === level && logger.warn(message), isMultiCompiler || printTime(0, hasErrors), isCompiling = !1;
|
|
3974
3982
|
}), 'dev' === context.action && (({ context, compiler, bundlerConfigs, MultiStatsCtor })=>{
|
|
3975
|
-
let isFirstCompile = !0, { environmentList } = context
|
|
3976
|
-
let promise = context.hooks.onAfterDevCompile.callBatch({
|
|
3977
|
-
isFirstCompile,
|
|
3978
|
-
stats,
|
|
3979
|
-
environments: context.environments
|
|
3980
|
-
});
|
|
3981
|
-
isFirstCompile = !1, await promise;
|
|
3982
|
-
}, onEnvironmentDone = async (index, stats)=>{
|
|
3983
|
-
let environment = environmentList[index], time = context.buildState.time[environment.name] ?? 0;
|
|
3984
|
-
await context.hooks.onAfterEnvironmentCompile.callBatch({
|
|
3985
|
-
environment: environment.name,
|
|
3986
|
-
args: [
|
|
3987
|
-
{
|
|
3988
|
-
isFirstCompile,
|
|
3989
|
-
stats,
|
|
3990
|
-
environment,
|
|
3991
|
-
isWatch: !0,
|
|
3992
|
-
time
|
|
3993
|
-
}
|
|
3994
|
-
]
|
|
3995
|
-
});
|
|
3996
|
-
};
|
|
3983
|
+
let isFirstCompile = !0, { environmentList } = context;
|
|
3997
3984
|
onBeforeCompile({
|
|
3998
3985
|
compiler,
|
|
3999
3986
|
beforeEnvironmentCompile: async (buildIndex)=>{
|
|
@@ -4019,8 +4006,29 @@ async function createCompiler_createCompiler(options) {
|
|
|
4019
4006
|
isWatch: !0
|
|
4020
4007
|
}), onCompileDone({
|
|
4021
4008
|
compiler,
|
|
4022
|
-
onDone
|
|
4023
|
-
|
|
4009
|
+
onDone: async (stats)=>{
|
|
4010
|
+
let promise = context.hooks.onAfterDevCompile.callBatch({
|
|
4011
|
+
isFirstCompile,
|
|
4012
|
+
stats,
|
|
4013
|
+
environments: context.environments
|
|
4014
|
+
});
|
|
4015
|
+
isFirstCompile = !1, await promise;
|
|
4016
|
+
},
|
|
4017
|
+
onEnvironmentDone: async (index, stats)=>{
|
|
4018
|
+
let environment = environmentList[index], time = context.buildState.time[environment.name] ?? 0;
|
|
4019
|
+
await context.hooks.onAfterEnvironmentCompile.callBatch({
|
|
4020
|
+
environment: environment.name,
|
|
4021
|
+
args: [
|
|
4022
|
+
{
|
|
4023
|
+
isFirstCompile,
|
|
4024
|
+
stats,
|
|
4025
|
+
environment,
|
|
4026
|
+
isWatch: !0,
|
|
4027
|
+
time
|
|
4028
|
+
}
|
|
4029
|
+
]
|
|
4030
|
+
});
|
|
4031
|
+
},
|
|
4024
4032
|
MultiStatsCtor
|
|
4025
4033
|
});
|
|
4026
4034
|
})({
|
|
@@ -4127,32 +4135,32 @@ function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls
|
|
|
4127
4135
|
});
|
|
4128
4136
|
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;
|
|
4129
4137
|
}
|
|
4130
|
-
let
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4138
|
+
let resolvePort = async (config, lastPort)=>{
|
|
4139
|
+
let { host, port: originalPort, strictPort } = config.server, preferredPort = 0 === originalPort ? lastPort : void 0, port = await (async ({ host, port, strictPort, tryLimits = 20 })=>{
|
|
4140
|
+
'string' == typeof port && (port = Number.parseInt(port, 10)), strictPort && (tryLimits = 1);
|
|
4141
|
+
let { createServer } = await import("node:net"), original = port, found = !1, attempts = 0;
|
|
4142
|
+
for(; !found && attempts <= tryLimits;)try {
|
|
4143
|
+
await new Promise((resolve, reject)=>{
|
|
4144
|
+
let server = createServer();
|
|
4145
|
+
server.unref(), server.on('error', reject), server.listen({
|
|
4146
|
+
port,
|
|
4147
|
+
host
|
|
4148
|
+
}, ()=>{
|
|
4149
|
+
if (0 === port) {
|
|
4150
|
+
let address = server.address();
|
|
4151
|
+
address && 'string' != typeof address && (port = address.port);
|
|
4152
|
+
}
|
|
4153
|
+
found = !0, server.close(resolve);
|
|
4154
|
+
});
|
|
4145
4155
|
});
|
|
4146
|
-
})
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
}, resolvePort = async (config, lastPort)=>{
|
|
4155
|
-
let { host, port: originalPort, strictPort } = config.server, preferredPort = 0 === originalPort ? lastPort : void 0, port = await getPort({
|
|
4156
|
+
} catch (e) {
|
|
4157
|
+
if (!(e instanceof Error) || !('code' in e) || 'EADDRINUSE' !== e.code) throw e;
|
|
4158
|
+
port++, attempts++;
|
|
4159
|
+
}
|
|
4160
|
+
if (!found) throw Error(`${color.dim('[rsbuild:server]')} Failed to find an available port after ${tryLimits + 1} attempts, starting from ${color.yellow(original)}.`);
|
|
4161
|
+
if (0 !== original && port !== original && strictPort) throw Error(`${color.dim('[rsbuild:server]')} Port ${color.yellow(original)} is occupied, please choose another one.`);
|
|
4162
|
+
return port;
|
|
4163
|
+
})({
|
|
4156
4164
|
host,
|
|
4157
4165
|
port: preferredPort ?? originalPort,
|
|
4158
4166
|
strictPort: void 0 === preferredPort && strictPort
|
|
@@ -4380,100 +4388,7 @@ function watchFilesForRestart({ watchFiles, context, restartContext }) {
|
|
|
4380
4388
|
close
|
|
4381
4389
|
};
|
|
4382
4390
|
}
|
|
4383
|
-
let RSPACK_BUILD_ERROR = 'Rspack build failed.',
|
|
4384
|
-
let stats, closeCompiler, closingPromise, unregisterRestart, restartWatcher, { watch } = buildOptions, { context } = initOptions, { logger } = context, { compiler, rspackConfigs } = await createCompiler_createCompiler(initOptions);
|
|
4385
|
-
if ((({ context, isWatch, compiler, rspackConfigs, MultiStatsCtor })=>{
|
|
4386
|
-
let isFirstCompile = !0, { environmentList } = context, onDone = async (stats)=>{
|
|
4387
|
-
let shouldLogWatching = isWatch && isFirstCompile, promise = context.hooks.onAfterBuild.callBatch({
|
|
4388
|
-
isFirstCompile,
|
|
4389
|
-
stats,
|
|
4390
|
-
environments: context.environments,
|
|
4391
|
-
isWatch
|
|
4392
|
-
});
|
|
4393
|
-
isFirstCompile = !1, await promise, shouldLogWatching && context.logger.info('watching for changes...');
|
|
4394
|
-
}, onEnvironmentDone = async (index, stats)=>{
|
|
4395
|
-
let environment = environmentList[index], time = context.buildState.time[environment.name] ?? 0;
|
|
4396
|
-
await context.hooks.onAfterEnvironmentCompile.callBatch({
|
|
4397
|
-
environment: environment.name,
|
|
4398
|
-
args: [
|
|
4399
|
-
{
|
|
4400
|
-
isFirstCompile,
|
|
4401
|
-
stats,
|
|
4402
|
-
environment,
|
|
4403
|
-
isWatch,
|
|
4404
|
-
time
|
|
4405
|
-
}
|
|
4406
|
-
]
|
|
4407
|
-
});
|
|
4408
|
-
};
|
|
4409
|
-
onBeforeCompile({
|
|
4410
|
-
compiler,
|
|
4411
|
-
beforeCompile: async ()=>context.hooks.onBeforeBuild.callBatch({
|
|
4412
|
-
bundlerConfigs: rspackConfigs,
|
|
4413
|
-
environments: context.environments,
|
|
4414
|
-
isWatch,
|
|
4415
|
-
isFirstCompile
|
|
4416
|
-
}),
|
|
4417
|
-
beforeEnvironmentCompile: async (buildIndex)=>{
|
|
4418
|
-
let environment = environmentList[buildIndex];
|
|
4419
|
-
return context.hooks.onBeforeEnvironmentCompile.callBatch({
|
|
4420
|
-
environment: environment.name,
|
|
4421
|
-
args: [
|
|
4422
|
-
{
|
|
4423
|
-
bundlerConfig: rspackConfigs[buildIndex],
|
|
4424
|
-
environment,
|
|
4425
|
-
isWatch,
|
|
4426
|
-
isFirstCompile
|
|
4427
|
-
}
|
|
4428
|
-
]
|
|
4429
|
-
});
|
|
4430
|
-
},
|
|
4431
|
-
isWatch
|
|
4432
|
-
}), onCompileDone({
|
|
4433
|
-
compiler,
|
|
4434
|
-
onDone,
|
|
4435
|
-
onEnvironmentDone,
|
|
4436
|
-
MultiStatsCtor
|
|
4437
|
-
});
|
|
4438
|
-
})({
|
|
4439
|
-
context,
|
|
4440
|
-
rspackConfigs,
|
|
4441
|
-
compiler,
|
|
4442
|
-
isWatch: !!watch,
|
|
4443
|
-
MultiStatsCtor: core_rspack.MultiStats
|
|
4444
|
-
}), watch) {
|
|
4445
|
-
let watchOptions = rspackConfigs.map((options)=>options.watchOptions || {});
|
|
4446
|
-
compiler.watch(watchOptions.length > 1 ? watchOptions : watchOptions[0] || {}, (err)=>{
|
|
4447
|
-
err && logger.error(err);
|
|
4448
|
-
}), closeCompiler = ()=>new Promise((resolve)=>{
|
|
4449
|
-
compiler.close(()=>{
|
|
4450
|
-
resolve();
|
|
4451
|
-
});
|
|
4452
|
-
});
|
|
4453
|
-
} else stats = await new Promise((resolve, reject)=>{
|
|
4454
|
-
compiler.run((err, stats)=>{
|
|
4455
|
-
compiler.close((closeErr)=>{
|
|
4456
|
-
closeErr && logger.error('Failed to close compiler: ', closeErr), err ? reject(err) : context.buildState.hasErrors ? reject(Error(RSPACK_BUILD_ERROR)) : resolve(stats);
|
|
4457
|
-
});
|
|
4458
|
-
});
|
|
4459
|
-
});
|
|
4460
|
-
let closeBuild = ()=>closingPromise ||= (async ()=>{
|
|
4461
|
-
unregisterRestart?.(), unregisterRestart = void 0, await context.hooks.onCloseBuild.callBatch(), await closeCompiler?.();
|
|
4462
|
-
})();
|
|
4463
|
-
return watch && (unregisterRestart = context.restartManager.registerCleanup(closeBuild), restartWatcher = watchFilesForRestart({
|
|
4464
|
-
watchFiles: context.normalizedConfig.dev.watchFiles,
|
|
4465
|
-
context,
|
|
4466
|
-
restartContext: {
|
|
4467
|
-
action: 'build',
|
|
4468
|
-
options: buildOptions
|
|
4469
|
-
}
|
|
4470
|
-
})), {
|
|
4471
|
-
stats,
|
|
4472
|
-
close: async ()=>{
|
|
4473
|
-
await restartWatcher?.close(), await closeBuild();
|
|
4474
|
-
}
|
|
4475
|
-
};
|
|
4476
|
-
}, main = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/dotenv-expand/13.0.0/1d3d360f4c41ed89366b79ec2c361d16e6aee7ab6c47163ea4f3718f7f78cc4c/node_modules/dotenv-expand/lib/main.js"), DOTENV_LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
4391
|
+
let RSPACK_BUILD_ERROR = 'Rspack build failed.', main = rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/dotenv-expand/13.0.0/1d3d360f4c41ed89366b79ec2c361d16e6aee7ab6c47163ea4f3718f7f78cc4c/node_modules/dotenv-expand/lib/main.js"), DOTENV_LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
4477
4392
|
function loadEnv_parse(src) {
|
|
4478
4393
|
let match, obj = {}, lines = src.toString();
|
|
4479
4394
|
for(lines = lines.replace(/\r\n?/gm, '\n'); null != (match = DOTENV_LINE.exec(lines));){
|
|
@@ -5103,7 +5018,7 @@ function parseMinifyOptions(config) {
|
|
|
5103
5018
|
cssOptions: minify.cssOptions
|
|
5104
5019
|
};
|
|
5105
5020
|
}
|
|
5106
|
-
var postcss_load_config_src_default = compatGetDefaultExport(rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/
|
|
5021
|
+
var postcss_load_config_src_default = compatGetDefaultExport(rspackRequire("../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/postcss-load-config/6.0.1/3982c00e478b1022695fb90618a4bf86beec38a06e2b0c0a97aeacbed78f1172/node_modules/postcss-load-config/src/index.js"));
|
|
5107
5022
|
async function getLightningCSSLoaderOptions(config, targets, minify) {
|
|
5108
5023
|
let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
|
|
5109
5024
|
targets,
|
|
@@ -5134,75 +5049,6 @@ async function loadUserPostcssrc(root, postcssrcCache) {
|
|
|
5134
5049
|
});
|
|
5135
5050
|
return postcssrcCache.set(root, promise), promise.then((config)=>(postcssrcCache.set(root, config), clonePostCSSConfig(config)));
|
|
5136
5051
|
}
|
|
5137
|
-
let getPostcssLoaderOptions = async ({ config, root, postcssrcCache })=>{
|
|
5138
|
-
let extraPlugins = [], userOptions = await loadUserPostcssrc(root, postcssrcCache);
|
|
5139
|
-
userOptions.plugins ||= [];
|
|
5140
|
-
let defaultOptions = {
|
|
5141
|
-
implementation: getCompiledPath('postcss'),
|
|
5142
|
-
postcssOptions: userOptions,
|
|
5143
|
-
sourceMap: getCSSSourceMap(config)
|
|
5144
|
-
}, finalOptions = await reduceConfigsWithContext({
|
|
5145
|
-
initial: defaultOptions,
|
|
5146
|
-
config: config.tools.postcss,
|
|
5147
|
-
ctx: {
|
|
5148
|
-
addPlugins (plugins, options = {}) {
|
|
5149
|
-
let { order = 'post' } = options, list = helpers_castArray(plugins);
|
|
5150
|
-
'pre' === order ? extraPlugins.unshift(...list) : extraPlugins.push(...list);
|
|
5151
|
-
}
|
|
5152
|
-
}
|
|
5153
|
-
});
|
|
5154
|
-
finalOptions.postcssOptions ||= {};
|
|
5155
|
-
let updatePostcssOptions = (options)=>(options.plugins ||= [], extraPlugins.length && options.plugins.push(...extraPlugins), options.plugins = options.plugins.map((plugin)=>'function' == typeof plugin && 'postcss' in plugin && plugin.postcss ? plugin() : plugin), options.config = !1, options), { postcssOptions } = finalOptions;
|
|
5156
|
-
if ('function' == typeof postcssOptions) {
|
|
5157
|
-
let postcssOptionsWrapper = (loaderContext)=>{
|
|
5158
|
-
let options = postcssOptions(loaderContext);
|
|
5159
|
-
if ('object' != typeof options || null === options) throw Error(`${color.dim('[rsbuild:css]')} \`postcssOptions\` function must return a PostCSSOptions object, got ${color.yellow(typeof options)}.`);
|
|
5160
|
-
return updatePostcssOptions({
|
|
5161
|
-
...userOptions,
|
|
5162
|
-
...options,
|
|
5163
|
-
plugins: [
|
|
5164
|
-
...userOptions.plugins || [],
|
|
5165
|
-
...options.plugins || []
|
|
5166
|
-
]
|
|
5167
|
-
});
|
|
5168
|
-
};
|
|
5169
|
-
return postcssOptionsWrapper.config = !1, {
|
|
5170
|
-
...finalOptions,
|
|
5171
|
-
postcssOptions: postcssOptionsWrapper
|
|
5172
|
-
};
|
|
5173
|
-
}
|
|
5174
|
-
return finalOptions.postcssOptions = updatePostcssOptions(postcssOptions), finalOptions;
|
|
5175
|
-
}, getCSSLoaderOptions = async ({ config, localIdentName, emitCss })=>{
|
|
5176
|
-
let { cssModules } = config.output, defaultOptions = {
|
|
5177
|
-
modules: {
|
|
5178
|
-
...cssModules,
|
|
5179
|
-
localIdentName
|
|
5180
|
-
},
|
|
5181
|
-
sourceMap: getCSSSourceMap(config)
|
|
5182
|
-
};
|
|
5183
|
-
return ((options, exportOnlyLocals)=>{
|
|
5184
|
-
if (options.modules && exportOnlyLocals) {
|
|
5185
|
-
let { modules } = options;
|
|
5186
|
-
return modules = !0 === modules ? {
|
|
5187
|
-
exportOnlyLocals: !0
|
|
5188
|
-
} : 'string' == typeof modules ? {
|
|
5189
|
-
mode: modules,
|
|
5190
|
-
exportOnlyLocals: !0
|
|
5191
|
-
} : {
|
|
5192
|
-
...modules,
|
|
5193
|
-
exportOnlyLocals: !0
|
|
5194
|
-
}, {
|
|
5195
|
-
...options,
|
|
5196
|
-
modules
|
|
5197
|
-
};
|
|
5198
|
-
}
|
|
5199
|
-
return options;
|
|
5200
|
-
})(await reduceConfigs({
|
|
5201
|
-
initial: defaultOptions,
|
|
5202
|
-
config: config.tools.cssLoader,
|
|
5203
|
-
mergeFn: cjs_0_default()
|
|
5204
|
-
}), !emitCss);
|
|
5205
|
-
};
|
|
5206
5052
|
function checkProcessEnvSecurity(define, logger) {
|
|
5207
5053
|
let value = define['process.env'];
|
|
5208
5054
|
if (!value) return;
|
|
@@ -5215,13 +5061,7 @@ function checkProcessEnvSecurity(define, logger) {
|
|
|
5215
5061
|
check(JSON.parse(value));
|
|
5216
5062
|
} catch {}
|
|
5217
5063
|
}
|
|
5218
|
-
let
|
|
5219
|
-
if (await isFileExists(pkgJsonPath)) try {
|
|
5220
|
-
return JSON.parse(await readFile(pkgJsonPath, 'utf8'));
|
|
5221
|
-
} catch {
|
|
5222
|
-
return;
|
|
5223
|
-
}
|
|
5224
|
-
}, dependencyTypes = [
|
|
5064
|
+
let dependencyTypes = [
|
|
5225
5065
|
'dependencies',
|
|
5226
5066
|
'peerDependencies',
|
|
5227
5067
|
'devDependencies',
|
|
@@ -5238,18 +5078,6 @@ let readPackageJsonByPath = async (pkgJsonPath)=>{
|
|
|
5238
5078
|
...!0 === autoExternal ? {} : autoExternal
|
|
5239
5079
|
};
|
|
5240
5080
|
return dependencyTypes.some((type)=>externalOptions[type]) ? externalOptions : void 0;
|
|
5241
|
-
}, readPackageJsonList = async (paths, cache)=>{
|
|
5242
|
-
var packageJsonList = (await Promise.all(paths.map(async (path)=>(cache.has(path) || cache.set(path, await readPackageJsonByPath(path)), cache.get(path))))).filter((pkgJson)=>!!pkgJson);
|
|
5243
|
-
return packageJsonList.length ? dependencyTypes.reduce((merged, type)=>{
|
|
5244
|
-
for (let pkgJson of packageJsonList){
|
|
5245
|
-
let deps = pkgJson[type];
|
|
5246
|
-
isPlainObject(deps) && (merged[type] = {
|
|
5247
|
-
...merged[type],
|
|
5248
|
-
...deps
|
|
5249
|
-
});
|
|
5250
|
-
}
|
|
5251
|
-
return merged;
|
|
5252
|
-
}, {}) : void 0;
|
|
5253
5081
|
};
|
|
5254
5082
|
function pluginExternals() {
|
|
5255
5083
|
return {
|
|
@@ -5260,7 +5088,25 @@ function pluginExternals() {
|
|
|
5260
5088
|
let pkgJson, { autoExternal, externals } = environment.config.output, externalOptions = resolveAutoExternalOptions(autoExternal);
|
|
5261
5089
|
if (externalOptions) {
|
|
5262
5090
|
let rootPath, packageJsonPaths = (rootPath = api.context.rootPath, helpers_castArray(externalOptions.packageJson ?? 'package.json').map((path)=>external_node_path_resolve(rootPath, path)));
|
|
5263
|
-
pkgJson = await
|
|
5091
|
+
pkgJson = await (async (paths, cache)=>{
|
|
5092
|
+
var packageJsonList = (await Promise.all(paths.map(async (path)=>(cache.has(path) || cache.set(path, await (async (pkgJsonPath)=>{
|
|
5093
|
+
if (await isFileExists(pkgJsonPath)) try {
|
|
5094
|
+
return JSON.parse(await readFile(pkgJsonPath, 'utf8'));
|
|
5095
|
+
} catch {
|
|
5096
|
+
return;
|
|
5097
|
+
}
|
|
5098
|
+
})(path)), cache.get(path))))).filter((pkgJson)=>!!pkgJson);
|
|
5099
|
+
return packageJsonList.length ? dependencyTypes.reduce((merged, type)=>{
|
|
5100
|
+
for (let pkgJson of packageJsonList){
|
|
5101
|
+
let deps = pkgJson[type];
|
|
5102
|
+
isPlainObject(deps) && (merged[type] = {
|
|
5103
|
+
...merged[type],
|
|
5104
|
+
...deps
|
|
5105
|
+
});
|
|
5106
|
+
}
|
|
5107
|
+
return merged;
|
|
5108
|
+
}, {}) : void 0;
|
|
5109
|
+
})(packageJsonPaths, packageJsonCache);
|
|
5264
5110
|
}
|
|
5265
5111
|
!externalOptions || pkgJson || hasWarnedReadPackageJsonFailed || (api.logger.warn('The `output.autoExternal` configuration will not be applied because reading package.json failed.'), hasWarnedReadPackageJsonFailed = !0);
|
|
5266
5112
|
let autoExternalRules = ((options)=>{
|
|
@@ -5296,7 +5142,10 @@ function getAssetNames(compilation) {
|
|
|
5296
5142
|
function createAssetProcessor() {
|
|
5297
5143
|
let failure, active = 0, waiting = [];
|
|
5298
5144
|
return async (names, processAsset)=>{
|
|
5299
|
-
let cursor = 0
|
|
5145
|
+
let cursor = 0;
|
|
5146
|
+
if (await Promise.all(Array.from({
|
|
5147
|
+
length: Math.min(16, names.length)
|
|
5148
|
+
}, async ()=>{
|
|
5300
5149
|
for(; cursor < names.length && !failure;){
|
|
5301
5150
|
let index = cursor++;
|
|
5302
5151
|
active >= 16 ? await new Promise((resolve)=>waiting.push(resolve)) : active++;
|
|
@@ -5312,10 +5161,7 @@ function createAssetProcessor() {
|
|
|
5312
5161
|
next ? next() : active--;
|
|
5313
5162
|
}
|
|
5314
5163
|
}
|
|
5315
|
-
};
|
|
5316
|
-
if (await Promise.all(Array.from({
|
|
5317
|
-
length: Math.min(16, names.length)
|
|
5318
|
-
}, consume)), failure) throw failure.error;
|
|
5164
|
+
})), failure) throw failure.error;
|
|
5319
5165
|
};
|
|
5320
5166
|
}
|
|
5321
5167
|
function getCompression(compressed) {
|
|
@@ -5639,42 +5485,7 @@ class RsbuildHtmlPlugin {
|
|
|
5639
5485
|
this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData, this.getHTMLPlugin = getHTMLPlugin;
|
|
5640
5486
|
}
|
|
5641
5487
|
apply(compiler) {
|
|
5642
|
-
let
|
|
5643
|
-
let fileContent, name = node_path.basename(favicon), outputFilename = node_path.posix.join(faviconDistPath, name);
|
|
5644
|
-
if (outputFilename in compilation.assets) return outputFilename;
|
|
5645
|
-
let inputFs = compilation.inputFileSystem;
|
|
5646
|
-
if (!inputFs) return addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file as ${color.yellow('compilation.inputFileSystem')} is not available.`), null;
|
|
5647
|
-
let inputFilename = node_path.isAbsolute(favicon) ? favicon : node_path.join(compilation.compiler.context, favicon);
|
|
5648
|
-
try {
|
|
5649
|
-
fileContent = await readFileAsync(inputFs, inputFilename);
|
|
5650
|
-
} catch (error) {
|
|
5651
|
-
return logger.debug('read favicon error:', error), addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file at ${color.yellow(inputFilename)}.`), null;
|
|
5652
|
-
}
|
|
5653
|
-
let source = new core_rspack.sources.RawSource(fileContent, !1);
|
|
5654
|
-
return compilation.emitAsset(outputFilename, source), outputFilename;
|
|
5655
|
-
}, addFavicon = async ({ headTags, favicon, faviconDistPath, compilation, publicPath, logger })=>{
|
|
5656
|
-
let href = favicon;
|
|
5657
|
-
if (!isURL(favicon)) {
|
|
5658
|
-
let name = await emitFavicon({
|
|
5659
|
-
compilation,
|
|
5660
|
-
favicon,
|
|
5661
|
-
faviconDistPath,
|
|
5662
|
-
logger
|
|
5663
|
-
});
|
|
5664
|
-
if (null === name) return;
|
|
5665
|
-
href = ensureAssetPrefix(name, publicPath);
|
|
5666
|
-
}
|
|
5667
|
-
let tag = {
|
|
5668
|
-
tagName: 'link',
|
|
5669
|
-
voidTag: !0,
|
|
5670
|
-
attributes: {
|
|
5671
|
-
rel: 'icon',
|
|
5672
|
-
href
|
|
5673
|
-
},
|
|
5674
|
-
meta: {}
|
|
5675
|
-
};
|
|
5676
|
-
href.endsWith('.svg') && (tag.attributes.type = 'image/svg+xml'), headTags.unshift(tag);
|
|
5677
|
-
}, getExtraDataByPlugin = (plugin)=>{
|
|
5488
|
+
let getExtraDataByPlugin = (plugin)=>{
|
|
5678
5489
|
if (!plugin.options) return;
|
|
5679
5490
|
let entryName = plugin.options[entryNameSymbol];
|
|
5680
5491
|
if (entryName) return this.getExtraData(entryName);
|
|
@@ -5693,7 +5504,42 @@ class RsbuildHtmlPlugin {
|
|
|
5693
5504
|
voidTag: !1,
|
|
5694
5505
|
meta: {}
|
|
5695
5506
|
});
|
|
5696
|
-
})(headTags, data.plugin.options?.title), favicon && await
|
|
5507
|
+
})(headTags, data.plugin.options?.title), favicon && await (async ({ headTags, favicon, faviconDistPath, compilation, publicPath, logger })=>{
|
|
5508
|
+
let href = favicon;
|
|
5509
|
+
if (!isURL(favicon)) {
|
|
5510
|
+
let name = await (async ({ compilation, favicon, faviconDistPath, logger })=>{
|
|
5511
|
+
let fileContent, name = node_path.basename(favicon), outputFilename = node_path.posix.join(faviconDistPath, name);
|
|
5512
|
+
if (outputFilename in compilation.assets) return outputFilename;
|
|
5513
|
+
let inputFs = compilation.inputFileSystem;
|
|
5514
|
+
if (!inputFs) return addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file as ${color.yellow('compilation.inputFileSystem')} is not available.`), null;
|
|
5515
|
+
let inputFilename = node_path.isAbsolute(favicon) ? favicon : node_path.join(compilation.compiler.context, favicon);
|
|
5516
|
+
try {
|
|
5517
|
+
fileContent = await readFileAsync(inputFs, inputFilename);
|
|
5518
|
+
} catch (error) {
|
|
5519
|
+
return logger.debug('read favicon error:', error), addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file at ${color.yellow(inputFilename)}.`), null;
|
|
5520
|
+
}
|
|
5521
|
+
let source = new core_rspack.sources.RawSource(fileContent, !1);
|
|
5522
|
+
return compilation.emitAsset(outputFilename, source), outputFilename;
|
|
5523
|
+
})({
|
|
5524
|
+
compilation,
|
|
5525
|
+
favicon,
|
|
5526
|
+
faviconDistPath,
|
|
5527
|
+
logger
|
|
5528
|
+
});
|
|
5529
|
+
if (null === name) return;
|
|
5530
|
+
href = ensureAssetPrefix(name, publicPath);
|
|
5531
|
+
}
|
|
5532
|
+
let tag = {
|
|
5533
|
+
tagName: 'link',
|
|
5534
|
+
voidTag: !0,
|
|
5535
|
+
attributes: {
|
|
5536
|
+
rel: 'icon',
|
|
5537
|
+
href
|
|
5538
|
+
},
|
|
5539
|
+
meta: {}
|
|
5540
|
+
};
|
|
5541
|
+
href.endsWith('.svg') && (tag.attributes.type = 'image/svg+xml'), headTags.unshift(tag);
|
|
5542
|
+
})({
|
|
5697
5543
|
headTags,
|
|
5698
5544
|
favicon,
|
|
5699
5545
|
faviconDistPath,
|
|
@@ -5922,14 +5768,14 @@ let supportedChromiumBrowsers = [
|
|
|
5922
5768
|
async function openBrowser(url, logger) {
|
|
5923
5769
|
let browser = process.env.BROWSER, browserArgs = process.env.BROWSER_ARGS;
|
|
5924
5770
|
if ('darwin' === process.platform && (!browser || !browserArgs) && (!browser || supportedChromiumBrowsers.includes(mapChromiumBrowserName(browser)))) {
|
|
5925
|
-
let { execFile } = await import("node:child_process"), execFileAsync = promisify(execFile)
|
|
5926
|
-
let { stdout: ps } = await execFileAsync('ps', [
|
|
5927
|
-
'cax'
|
|
5928
|
-
]);
|
|
5929
|
-
return supportedChromiumBrowsers.find((b)=>ps.includes(b));
|
|
5930
|
-
};
|
|
5771
|
+
let { execFile } = await import("node:child_process"), execFileAsync = promisify(execFile);
|
|
5931
5772
|
try {
|
|
5932
|
-
let chromiumBrowser = browser ? mapChromiumBrowserName(browser) : await
|
|
5773
|
+
let chromiumBrowser = browser ? mapChromiumBrowserName(browser) : await (async ()=>{
|
|
5774
|
+
let { stdout: ps } = await execFileAsync('ps', [
|
|
5775
|
+
'cax'
|
|
5776
|
+
]);
|
|
5777
|
+
return supportedChromiumBrowsers.find((b)=>ps.includes(b));
|
|
5778
|
+
})();
|
|
5933
5779
|
if (chromiumBrowser) return await execFileAsync("osascript", [
|
|
5934
5780
|
"openChrome.applescript",
|
|
5935
5781
|
encodeURI(url),
|
|
@@ -6018,7 +5864,7 @@ function doesChunkBelongToHtml({ chunk, htmlPluginData }) {
|
|
|
6018
5864
|
let { options } = htmlPluginData.plugin;
|
|
6019
5865
|
return recursiveChunkEntryNames(chunk).some((chunkName)=>isChunksFiltered(chunkName, options?.chunks, options?.excludeChunks));
|
|
6020
5866
|
}
|
|
6021
|
-
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/
|
|
5867
|
+
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/962a610493ec402e318fb90e15abdb8e0c048f9453227ea9c1af410588c46571/node_modules/rspack-manifest-plugin/dist/index.js"))), isCSSPath = (filePath)=>filePath.endsWith('.css');
|
|
6022
5868
|
function normalizeManifestObjectConfig(manifest) {
|
|
6023
5869
|
let defaultOptions = {
|
|
6024
5870
|
prefix: !0,
|
|
@@ -6739,12 +6585,7 @@ function destroyStream(stream, suppress) {
|
|
|
6739
6585
|
'number' == typeof fd && this.close();
|
|
6740
6586
|
}), 'function' == typeof stream.addListener && suppress && (stream.removeAllListeners('error'), stream.addListener('error', ()=>{}));
|
|
6741
6587
|
}
|
|
6742
|
-
let getRangeParser = cachedImport_cachedImport(()=>import("./range-parser.js").then(createFakeNamespaceObject.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/range-parser/1.3.0/d49e5dcb9d0e39475844e240fad8cd1db6a58f4144f7ede43d9755e2fce5babc/node_modules/range-parser/index.js", 23)))
|
|
6743
|
-
let { default: rangeParser } = await getRangeParser(), [len, rangeHeader] = value.split('|');
|
|
6744
|
-
return rangeParser(Number(len), rangeHeader, {
|
|
6745
|
-
combine: !0
|
|
6746
|
-
});
|
|
6747
|
-
};
|
|
6588
|
+
let getRangeParser = cachedImport_cachedImport(()=>import("./range-parser.js").then(createFakeNamespaceObject.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/range-parser/1.3.0/d49e5dcb9d0e39475844e240fad8cd1db6a58f4144f7ede43d9755e2fce5babc/node_modules/range-parser/index.js", 23)));
|
|
6748
6589
|
function sendError(res, code) {
|
|
6749
6590
|
let content = {
|
|
6750
6591
|
400: 'Bad Request',
|
|
@@ -6815,7 +6656,12 @@ function createAssetsMiddleware(context, { waitForAssets, waitForBuild }, output
|
|
|
6815
6656
|
}
|
|
6816
6657
|
}
|
|
6817
6658
|
if (rangeHeader) {
|
|
6818
|
-
let parsedRanges = await
|
|
6659
|
+
let parsedRanges = await (async (value)=>{
|
|
6660
|
+
let { default: rangeParser } = await getRangeParser(), [len, rangeHeader] = value.split('|');
|
|
6661
|
+
return rangeParser(Number(len), rangeHeader, {
|
|
6662
|
+
combine: !0
|
|
6663
|
+
});
|
|
6664
|
+
})(`${size}|${rangeHeader}`);
|
|
6819
6665
|
if (isRangeFresh(req.headers, res) || (parsedRanges = []), -1 === parsedRanges) {
|
|
6820
6666
|
logger.error("[rsbuild:middleware] Unsatisfiable range for 'Range' header."), res.setHeader('Content-Range', getValueContentRangeHeader('bytes', size)), sendError(res, 416);
|
|
6821
6667
|
return;
|
|
@@ -6915,10 +6761,7 @@ let noop = ()=>{}, normalizeLiveReload = (liveReload)=>'boolean' == typeof liveR
|
|
|
6915
6761
|
} : {
|
|
6916
6762
|
enabled: !0,
|
|
6917
6763
|
html: !1 !== liveReload.html
|
|
6918
|
-
},
|
|
6919
|
-
let { target } = compiler.options;
|
|
6920
|
-
return !!target && (Array.isArray(target) ? target.includes('node') : 'node' === target);
|
|
6921
|
-
}, isTsError = (error)=>'message' in error && error.stack?.includes('ts-checker-rspack-plugin');
|
|
6764
|
+
}, isTsError = (error)=>'message' in error && error.stack?.includes('ts-checker-rspack-plugin');
|
|
6922
6765
|
function applyHMREntry({ config, compiler, token, resolvedHost, resolvedPort }) {
|
|
6923
6766
|
var overlay;
|
|
6924
6767
|
let overlay1;
|
|
@@ -6948,111 +6791,6 @@ init(
|
|
|
6948
6791
|
name: void 0
|
|
6949
6792
|
}).apply(compiler);
|
|
6950
6793
|
}
|
|
6951
|
-
let assets_middleware_assetsMiddleware = async ({ config, compiler, context, socketServer, resolvedPort })=>{
|
|
6952
|
-
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 : [
|
|
6953
|
-
compiler
|
|
6954
|
-
]).filter((compiler)=>!isNodeCompiler(compiler))).length > 0 && webCompilers.length < allCompilers.length, {
|
|
6955
|
-
allCompilers,
|
|
6956
|
-
webCompilers,
|
|
6957
|
-
earlyWebUpdates
|
|
6958
|
-
});
|
|
6959
|
-
applyToCompiler(compiler, (compiler, index)=>{
|
|
6960
|
-
let environment = environmentList[index];
|
|
6961
|
-
if (!environment) return;
|
|
6962
|
-
let token = environment.webSocketToken;
|
|
6963
|
-
token && (applyHMREntry({
|
|
6964
|
-
token,
|
|
6965
|
-
config: environment.config,
|
|
6966
|
-
compiler,
|
|
6967
|
-
resolvedHost,
|
|
6968
|
-
resolvedPort
|
|
6969
|
-
}), (({ context, compiler, token, socketServer, liveReload, earlyWebUpdates })=>{
|
|
6970
|
-
if (isNodeCompiler(compiler)) return;
|
|
6971
|
-
let errorsCount = null, warningsCount = null, reset = ()=>{
|
|
6972
|
-
errorsCount = null, warningsCount = null, socketServer.clearEnvironmentStats(token);
|
|
6973
|
-
};
|
|
6974
|
-
compiler.hooks.watchRun.tap('rsbuild-dev-server', reset), compiler.hooks.invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
6975
|
-
reset(), 'string' == typeof fileName && fileName.endsWith('.html') && normalizeLiveReload(liveReload).html && socketServer.sendMessage({
|
|
6976
|
-
type: 'full-reload'
|
|
6977
|
-
}, token);
|
|
6978
|
-
}), compiler.hooks.done.tap('rsbuild-dev-server', (stats)=>{
|
|
6979
|
-
let { errors, warnings } = stats.compilation;
|
|
6980
|
-
if (errors.length === errorsCount && warnings.length === warningsCount) return;
|
|
6981
|
-
null === errorsCount && null === warningsCount && earlyWebUpdates && !stats.hasErrors() && socketServer.onEnvironmentDone(token, ()=>getEarlyStats(stats));
|
|
6982
|
-
let isRecalled = null !== errorsCount || null !== warningsCount;
|
|
6983
|
-
if (errorsCount = errors.length, warningsCount = warnings.length, isRecalled) {
|
|
6984
|
-
let tsErrors = errors.filter(isTsError), tsWarnings = warnings.filter(isTsError);
|
|
6985
|
-
if (!tsErrors.length && !tsWarnings.length) return;
|
|
6986
|
-
let { stats: statsJson } = context.buildState, handleTsIssues = (issues, type, sendFn)=>{
|
|
6987
|
-
let statsIssues = issues.map((item)=>pick(item, [
|
|
6988
|
-
'message',
|
|
6989
|
-
'file'
|
|
6990
|
-
]));
|
|
6991
|
-
statsJson && (statsJson[type] = statsJson[type] ? [
|
|
6992
|
-
...statsJson[type],
|
|
6993
|
-
...statsIssues
|
|
6994
|
-
] : statsIssues), sendFn(statsIssues, token);
|
|
6995
|
-
};
|
|
6996
|
-
if (tsErrors.length > 0) return void handleTsIssues(tsErrors, 'errors', (issues, token)=>{
|
|
6997
|
-
socketServer.sendError(issues, token);
|
|
6998
|
-
});
|
|
6999
|
-
if (tsWarnings.length > 0) return void handleTsIssues(tsWarnings, 'warnings', (issues, token)=>{
|
|
7000
|
-
socketServer.sendWarning(issues, token);
|
|
7001
|
-
});
|
|
7002
|
-
}
|
|
7003
|
-
});
|
|
7004
|
-
})({
|
|
7005
|
-
context,
|
|
7006
|
-
compiler,
|
|
7007
|
-
socketServer,
|
|
7008
|
-
token,
|
|
7009
|
-
liveReload: environment.config.dev.liveReload,
|
|
7010
|
-
earlyWebUpdates: earlyWebUpdates1
|
|
7011
|
-
}));
|
|
7012
|
-
});
|
|
7013
|
-
let assetCallbacks = [], buildCallbacks = [], flushCallbacks = (callbacks)=>{
|
|
7014
|
-
for (let callback of callbacks.splice(0))callback();
|
|
7015
|
-
}, flushAllCallbacks = ()=>{
|
|
7016
|
-
flushCallbacks(assetCallbacks), flushCallbacks(buildCallbacks);
|
|
7017
|
-
};
|
|
7018
|
-
compiler.hooks.done.tap('rsbuild-dev-middleware', ()=>{
|
|
7019
|
-
process.nextTick(()=>{
|
|
7020
|
-
'done' === context.buildState.status && flushAllCallbacks();
|
|
7021
|
-
});
|
|
7022
|
-
});
|
|
7023
|
-
let compiledWebCompilers = new Set(), isWebReady = ()=>earlyWebUpdates1 && compiledWebCompilers.size === webCompilers1.length;
|
|
7024
|
-
if (earlyWebUpdates1) for (let item of webCompilers1){
|
|
7025
|
-
let reset = ()=>{
|
|
7026
|
-
compiledWebCompilers.delete(item);
|
|
7027
|
-
};
|
|
7028
|
-
item.hooks.invalid.tap('rsbuild-dev-middleware', reset), item.hooks.watchRun.tap('rsbuild-dev-middleware', reset), item.hooks.done.tap('rsbuild-dev-middleware', (stats)=>{
|
|
7029
|
-
!stats.hasErrors() && (compiledWebCompilers.add(item), isWebReady() && process.nextTick(()=>{
|
|
7030
|
-
isWebReady() && flushCallbacks(assetCallbacks);
|
|
7031
|
-
}));
|
|
7032
|
-
});
|
|
7033
|
-
}
|
|
7034
|
-
let writeToDiskList = environmentList.map((environment)=>environment.config.dev.writeToDisk);
|
|
7035
|
-
writeToDiskList.some(Boolean) && setupWriteToDisk(allCompilers1, writeToDiskList, logger);
|
|
7036
|
-
let outputFileSystem = await setupOutputFileSystem(writeToDiskList.every((writeToDisk)=>!0 === writeToDisk), allCompilers1), isBuildReady = ()=>'done' === context.buildState.status || 'failed' === context.buildState.status, instance = createAssetsMiddleware(context, {
|
|
7037
|
-
waitForAssets: (callback)=>{
|
|
7038
|
-
isBuildReady() || isWebReady() ? callback() : assetCallbacks.push(callback);
|
|
7039
|
-
},
|
|
7040
|
-
waitForBuild: (callback)=>{
|
|
7041
|
-
isBuildReady() ? callback() : buildCallbacks.push(callback);
|
|
7042
|
-
}
|
|
7043
|
-
}, outputFileSystem);
|
|
7044
|
-
return instance.watch = ()=>{
|
|
7045
|
-
if (compiler.watching) watching = compiler.watching;
|
|
7046
|
-
else {
|
|
7047
|
-
let watchOptions = allCompilers1.length > 1 ? allCompilers1.map(({ options })=>options.watchOptions || {}) : allCompilers1[0].options.watchOptions || {};
|
|
7048
|
-
watching = compiler.watch(watchOptions, (error)=>{
|
|
7049
|
-
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));
|
|
7050
|
-
});
|
|
7051
|
-
}
|
|
7052
|
-
}, instance.close = (callback = noop)=>{
|
|
7053
|
-
watching?.close(callback);
|
|
7054
|
-
}, instance;
|
|
7055
|
-
};
|
|
7056
6794
|
var UNKNOWN_FUNCTION = '<unknown>';
|
|
7057
6795
|
function stack_trace_parser_esm_parse(stackString) {
|
|
7058
6796
|
return stackString.split('\n').reduce(function(stack, line) {
|
|
@@ -7144,16 +6882,6 @@ let getTraceMapping = cachedImport_cachedImport(()=>import("./trace-mapping.js")
|
|
|
7144
6882
|
} catch (error) {
|
|
7145
6883
|
error instanceof Error && context.logger.debug('failed to map source map position:', error);
|
|
7146
6884
|
}
|
|
7147
|
-
}, resolveOriginalLocation = async (stackFrames, fs, context, cache)=>{
|
|
7148
|
-
let frame = stackFrames.find((frame)=>null !== frame.file && null !== frame.column && null !== frame.lineNumber && SCRIPT_REGEX.test(frame.file));
|
|
7149
|
-
if (!frame) return;
|
|
7150
|
-
let parsedFrame = await parseFrame(frame, fs, context, cache);
|
|
7151
|
-
if (!parsedFrame) return;
|
|
7152
|
-
let { sourceMapPath, originalPosition } = parsedFrame;
|
|
7153
|
-
return {
|
|
7154
|
-
frame,
|
|
7155
|
-
location: formatOriginalLocation(sourceMapPath, originalPosition, context)
|
|
7156
|
-
};
|
|
7157
6885
|
}, formatOriginalLocation = (sourceMapPath, originalMapping, context)=>{
|
|
7158
6886
|
let { source, line, column } = originalMapping;
|
|
7159
6887
|
if (!source) return;
|
|
@@ -7166,39 +6894,23 @@ let getTraceMapping = cachedImport_cachedImport(()=>import("./trace-mapping.js")
|
|
|
7166
6894
|
}, formatFrameLocation = (frame)=>{
|
|
7167
6895
|
let { file, lineNumber, column } = frame;
|
|
7168
6896
|
if (file) return null !== lineNumber ? null !== column ? `${file}:${lineNumber}:${column}` : `${file}:${lineNumber}` : file;
|
|
7169
|
-
}, formatFullStack = async (stackFrames, context, fs, cache)=>{
|
|
7170
|
-
let formattedFrames = [];
|
|
7171
|
-
for (let frame of stackFrames){
|
|
7172
|
-
let location, parsedFrame = await parseFrame(frame, fs, context, cache), { methodName } = frame, parts = [];
|
|
7173
|
-
isValidMethodName(methodName) && parts.push(methodName);
|
|
7174
|
-
let parsed = !1;
|
|
7175
|
-
if (parsedFrame) {
|
|
7176
|
-
let { sourceMapPath, originalPosition } = parsedFrame, originalLocation = formatOriginalLocation(sourceMapPath, originalPosition, context);
|
|
7177
|
-
originalLocation && (location = originalLocation, parts.push(originalLocation), parsed = !0);
|
|
7178
|
-
}
|
|
7179
|
-
if (!parsed && isVerbose(context.logger)) {
|
|
7180
|
-
let frameString = formatFrameLocation(frame);
|
|
7181
|
-
frameString && (location = frameString, parts.push(frameString));
|
|
7182
|
-
}
|
|
7183
|
-
let [first, second] = parts;
|
|
7184
|
-
if (first) {
|
|
7185
|
-
let isRspackRuntime = isRspackRuntimeStack(methodName) || isRspackRuntimeStack(location);
|
|
7186
|
-
formattedFrames.push({
|
|
7187
|
-
text: second ? `\n at ${first} (${second})` : `\n at ${first}`,
|
|
7188
|
-
isRspackRuntime,
|
|
7189
|
-
hasLocation: void 0 !== location
|
|
7190
|
-
});
|
|
7191
|
-
}
|
|
7192
|
-
}
|
|
7193
|
-
let shouldFilterRspackRuntime = formattedFrames.some((frame)=>!frame.isRspackRuntime && frame.hasLocation);
|
|
7194
|
-
return formattedFrames.filter((frame)=>!(shouldFilterRspackRuntime && frame.isRspackRuntime)).map((frame)=>frame.text).join('');
|
|
7195
6897
|
}, formatBrowserErrorLog = async (message, context, fs, stackTrace, stackFrames, cache)=>{
|
|
7196
6898
|
var log;
|
|
7197
6899
|
let log1 = color.red(message);
|
|
7198
6900
|
if (stackFrames?.length) switch(stackTrace){
|
|
7199
6901
|
case 'summary':
|
|
7200
6902
|
{
|
|
7201
|
-
let resolved = await
|
|
6903
|
+
let resolved = await (async (stackFrames, fs, context, cache)=>{
|
|
6904
|
+
let frame = stackFrames.find((frame)=>null !== frame.file && null !== frame.column && null !== frame.lineNumber && SCRIPT_REGEX.test(frame.file));
|
|
6905
|
+
if (!frame) return;
|
|
6906
|
+
let parsedFrame = await parseFrame(frame, fs, context, cache);
|
|
6907
|
+
if (!parsedFrame) return;
|
|
6908
|
+
let { sourceMapPath, originalPosition } = parsedFrame;
|
|
6909
|
+
return {
|
|
6910
|
+
frame,
|
|
6911
|
+
location: formatOriginalLocation(sourceMapPath, originalPosition, context)
|
|
6912
|
+
};
|
|
6913
|
+
})(stackFrames, fs, context, cache);
|
|
7202
6914
|
if (!resolved) break;
|
|
7203
6915
|
let { frame, location } = resolved, { methodName } = frame, suffix = '';
|
|
7204
6916
|
isValidMethodName(methodName) && (suffix += ` at ${methodName}`), location && (suffix += ` (${location})`), log1 += suffix ? color.dim(suffix) : '';
|
|
@@ -7206,7 +6918,33 @@ let getTraceMapping = cachedImport_cachedImport(()=>import("./trace-mapping.js")
|
|
|
7206
6918
|
}
|
|
7207
6919
|
case 'full':
|
|
7208
6920
|
{
|
|
7209
|
-
let fullStack = await
|
|
6921
|
+
let fullStack = await (async (stackFrames, context, fs, cache)=>{
|
|
6922
|
+
let formattedFrames = [];
|
|
6923
|
+
for (let frame of stackFrames){
|
|
6924
|
+
let location, parsedFrame = await parseFrame(frame, fs, context, cache), { methodName } = frame, parts = [];
|
|
6925
|
+
isValidMethodName(methodName) && parts.push(methodName);
|
|
6926
|
+
let parsed = !1;
|
|
6927
|
+
if (parsedFrame) {
|
|
6928
|
+
let { sourceMapPath, originalPosition } = parsedFrame, originalLocation = formatOriginalLocation(sourceMapPath, originalPosition, context);
|
|
6929
|
+
originalLocation && (location = originalLocation, parts.push(originalLocation), parsed = !0);
|
|
6930
|
+
}
|
|
6931
|
+
if (!parsed && isVerbose(context.logger)) {
|
|
6932
|
+
let frameString = formatFrameLocation(frame);
|
|
6933
|
+
frameString && (location = frameString, parts.push(frameString));
|
|
6934
|
+
}
|
|
6935
|
+
let [first, second] = parts;
|
|
6936
|
+
if (first) {
|
|
6937
|
+
let isRspackRuntime = isRspackRuntimeStack(methodName) || isRspackRuntimeStack(location);
|
|
6938
|
+
formattedFrames.push({
|
|
6939
|
+
text: second ? `\n at ${first} (${second})` : `\n at ${first}`,
|
|
6940
|
+
isRspackRuntime,
|
|
6941
|
+
hasLocation: void 0 !== location
|
|
6942
|
+
});
|
|
6943
|
+
}
|
|
6944
|
+
}
|
|
6945
|
+
let shouldFilterRspackRuntime = formattedFrames.some((frame)=>!frame.isRspackRuntime && frame.hasLocation);
|
|
6946
|
+
return formattedFrames.filter((frame)=>!(shouldFilterRspackRuntime && frame.isRspackRuntime)).map((frame)=>frame.text).join('');
|
|
6947
|
+
})(stackFrames, context, fs, cache);
|
|
7210
6948
|
fullStack && (log1 += fullStack);
|
|
7211
6949
|
}
|
|
7212
6950
|
}
|
|
@@ -7539,7 +7277,110 @@ class BuildManager {
|
|
|
7539
7277
|
}
|
|
7540
7278
|
readFileSync = (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : node_fs.readFileSync(fileName, 'utf-8');
|
|
7541
7279
|
async setupCompilationMiddleware() {
|
|
7542
|
-
let { config, context } = this, middleware = await
|
|
7280
|
+
let { config, context } = this, middleware = await (async ({ config, compiler, context, socketServer, resolvedPort })=>{
|
|
7281
|
+
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 : [
|
|
7282
|
+
compiler
|
|
7283
|
+
]).filter((_, index)=>isWebTarget(environmentList[index].config.output.target))).length > 0 && webCompilers.length < allCompilers.length, {
|
|
7284
|
+
allCompilers,
|
|
7285
|
+
webCompilers,
|
|
7286
|
+
earlyWebUpdates
|
|
7287
|
+
});
|
|
7288
|
+
applyToCompiler(compiler, (compiler, index)=>{
|
|
7289
|
+
let environment = environmentList[index];
|
|
7290
|
+
if (!environment) return;
|
|
7291
|
+
let token = environment.webSocketToken;
|
|
7292
|
+
!token || (applyHMREntry({
|
|
7293
|
+
token,
|
|
7294
|
+
config: environment.config,
|
|
7295
|
+
compiler,
|
|
7296
|
+
resolvedHost,
|
|
7297
|
+
resolvedPort
|
|
7298
|
+
}), isWebTarget(environment.config.output.target) && (({ context, compiler, token, socketServer, liveReload, earlyWebUpdates })=>{
|
|
7299
|
+
let errorsCount = null, warningsCount = null, reset = ()=>{
|
|
7300
|
+
errorsCount = null, warningsCount = null, socketServer.clearEnvironmentStats(token);
|
|
7301
|
+
};
|
|
7302
|
+
compiler.hooks.watchRun.tap('rsbuild-dev-server', reset), compiler.hooks.invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
7303
|
+
reset(), 'string' == typeof fileName && fileName.endsWith('.html') && normalizeLiveReload(liveReload).html && socketServer.sendMessage({
|
|
7304
|
+
type: 'full-reload'
|
|
7305
|
+
}, token);
|
|
7306
|
+
}), compiler.hooks.done.tap('rsbuild-dev-server', (stats)=>{
|
|
7307
|
+
let { errors, warnings } = stats.compilation;
|
|
7308
|
+
if (errors.length === errorsCount && warnings.length === warningsCount) return;
|
|
7309
|
+
null === errorsCount && null === warningsCount && earlyWebUpdates && !stats.hasErrors() && socketServer.onEnvironmentDone(token, ()=>getEarlyStats(stats));
|
|
7310
|
+
let isRecalled = null !== errorsCount || null !== warningsCount;
|
|
7311
|
+
if (errorsCount = errors.length, warningsCount = warnings.length, isRecalled) {
|
|
7312
|
+
let tsErrors = errors.filter(isTsError), tsWarnings = warnings.filter(isTsError);
|
|
7313
|
+
if (!tsErrors.length && !tsWarnings.length) return;
|
|
7314
|
+
let { stats: statsJson } = context.buildState, handleTsIssues = (issues, type, sendFn)=>{
|
|
7315
|
+
let statsIssues = issues.map((item)=>pick(item, [
|
|
7316
|
+
'message',
|
|
7317
|
+
'file'
|
|
7318
|
+
]));
|
|
7319
|
+
statsJson && (statsJson[type] = statsJson[type] ? [
|
|
7320
|
+
...statsJson[type],
|
|
7321
|
+
...statsIssues
|
|
7322
|
+
] : statsIssues), sendFn(statsIssues, token);
|
|
7323
|
+
};
|
|
7324
|
+
if (tsErrors.length > 0) return void handleTsIssues(tsErrors, 'errors', (issues, token)=>{
|
|
7325
|
+
socketServer.sendError(issues, token);
|
|
7326
|
+
});
|
|
7327
|
+
if (tsWarnings.length > 0) return void handleTsIssues(tsWarnings, 'warnings', (issues, token)=>{
|
|
7328
|
+
socketServer.sendWarning(issues, token);
|
|
7329
|
+
});
|
|
7330
|
+
}
|
|
7331
|
+
});
|
|
7332
|
+
})({
|
|
7333
|
+
context,
|
|
7334
|
+
compiler,
|
|
7335
|
+
socketServer,
|
|
7336
|
+
token,
|
|
7337
|
+
liveReload: environment.config.dev.liveReload,
|
|
7338
|
+
earlyWebUpdates: earlyWebUpdates1
|
|
7339
|
+
}));
|
|
7340
|
+
});
|
|
7341
|
+
let assetCallbacks = [], buildCallbacks = [], flushCallbacks = (callbacks)=>{
|
|
7342
|
+
for (let callback of callbacks.splice(0))callback();
|
|
7343
|
+
}, flushAllCallbacks = ()=>{
|
|
7344
|
+
flushCallbacks(assetCallbacks), flushCallbacks(buildCallbacks);
|
|
7345
|
+
};
|
|
7346
|
+
compiler.hooks.done.tap('rsbuild-dev-middleware', ()=>{
|
|
7347
|
+
process.nextTick(()=>{
|
|
7348
|
+
'done' === context.buildState.status && flushAllCallbacks();
|
|
7349
|
+
});
|
|
7350
|
+
});
|
|
7351
|
+
let compiledWebCompilers = new Set(), isWebReady = ()=>earlyWebUpdates1 && compiledWebCompilers.size === webCompilers1.length;
|
|
7352
|
+
if (earlyWebUpdates1) for (let item of webCompilers1){
|
|
7353
|
+
let reset = ()=>{
|
|
7354
|
+
compiledWebCompilers.delete(item);
|
|
7355
|
+
};
|
|
7356
|
+
item.hooks.invalid.tap('rsbuild-dev-middleware', reset), item.hooks.watchRun.tap('rsbuild-dev-middleware', reset), item.hooks.done.tap('rsbuild-dev-middleware', (stats)=>{
|
|
7357
|
+
!stats.hasErrors() && (compiledWebCompilers.add(item), isWebReady() && process.nextTick(()=>{
|
|
7358
|
+
isWebReady() && flushCallbacks(assetCallbacks);
|
|
7359
|
+
}));
|
|
7360
|
+
});
|
|
7361
|
+
}
|
|
7362
|
+
let writeToDiskList = environmentList.map((environment)=>environment.config.dev.writeToDisk);
|
|
7363
|
+
writeToDiskList.some(Boolean) && setupWriteToDisk(allCompilers1, writeToDiskList, logger);
|
|
7364
|
+
let outputFileSystem = await setupOutputFileSystem(writeToDiskList.every((writeToDisk)=>!0 === writeToDisk), allCompilers1), isBuildReady = ()=>'done' === context.buildState.status || 'failed' === context.buildState.status, instance = createAssetsMiddleware(context, {
|
|
7365
|
+
waitForAssets: (callback)=>{
|
|
7366
|
+
isBuildReady() || isWebReady() ? callback() : assetCallbacks.push(callback);
|
|
7367
|
+
},
|
|
7368
|
+
waitForBuild: (callback)=>{
|
|
7369
|
+
isBuildReady() ? callback() : buildCallbacks.push(callback);
|
|
7370
|
+
}
|
|
7371
|
+
}, outputFileSystem);
|
|
7372
|
+
return instance.watch = ()=>{
|
|
7373
|
+
if (compiler.watching) watching = compiler.watching;
|
|
7374
|
+
else {
|
|
7375
|
+
let watchOptions = allCompilers1.length > 1 ? allCompilers1.map(({ options })=>options.watchOptions || {}) : allCompilers1[0].options.watchOptions || {};
|
|
7376
|
+
watching = compiler.watch(watchOptions, (error)=>{
|
|
7377
|
+
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));
|
|
7378
|
+
});
|
|
7379
|
+
}
|
|
7380
|
+
}, instance.close = (callback = noop)=>{
|
|
7381
|
+
watching?.close(callback);
|
|
7382
|
+
}, instance;
|
|
7383
|
+
})({
|
|
7543
7384
|
config,
|
|
7544
7385
|
context,
|
|
7545
7386
|
compiler: this.compiler,
|
|
@@ -7856,193 +7697,33 @@ async function createProxyMiddleware(proxyOptions, logger) {
|
|
|
7856
7697
|
}
|
|
7857
7698
|
};
|
|
7858
7699
|
}
|
|
7859
|
-
let
|
|
7860
|
-
let
|
|
7861
|
-
if (
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
}
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
let
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
}
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
} catch (err) {
|
|
7887
|
-
next(err);
|
|
7888
|
-
}
|
|
7889
|
-
}), middlewares.use((({ environments, logger })=>async function viewingServedFilesMiddleware(req, res, next) {
|
|
7890
|
-
if ('/rsbuild-dev-server' !== req.url.replace(postfixRE, '')) return void next();
|
|
7891
|
-
res.writeHead(200, {
|
|
7892
|
-
'Content-Type': 'text/html; charset=utf-8'
|
|
7893
|
-
}), res.write(`<!DOCTYPE html>
|
|
7894
|
-
<html>
|
|
7895
|
-
<head>
|
|
7896
|
-
<meta charset="utf-8"/>
|
|
7897
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7898
|
-
<style>
|
|
7899
|
-
body {
|
|
7900
|
-
margin: 0;
|
|
7901
|
-
color: #f6f7f9;
|
|
7902
|
-
padding: 32px 40px;
|
|
7903
|
-
line-height: 1.8;
|
|
7904
|
-
min-height: 100vh;
|
|
7905
|
-
background-image: linear-gradient(#020917, #101725);
|
|
7906
|
-
font-family: ui-sans-serif,system-ui,sans-serif;
|
|
7907
|
-
}
|
|
7908
|
-
h1, h2 {
|
|
7909
|
-
font-weight: 500;
|
|
7910
|
-
}
|
|
7911
|
-
h1 {
|
|
7912
|
-
margin: 0;
|
|
7913
|
-
font-size: 36px;
|
|
7914
|
-
}
|
|
7915
|
-
h2 {
|
|
7916
|
-
font-size: 20px;
|
|
7917
|
-
margin: 24px 0 16px;
|
|
7918
|
-
}
|
|
7919
|
-
ul {
|
|
7920
|
-
margin: 0;
|
|
7921
|
-
padding-left: 16px;
|
|
7922
|
-
}
|
|
7923
|
-
a {
|
|
7924
|
-
color: #58c4dc;
|
|
7925
|
-
text-decoration: none;
|
|
7926
|
-
}
|
|
7927
|
-
a:hover {
|
|
7928
|
-
text-decoration: underline;
|
|
7929
|
-
}
|
|
7930
|
-
</style>
|
|
7931
|
-
</head>
|
|
7932
|
-
<body>
|
|
7933
|
-
<h1>Assets Report</h1>
|
|
7934
|
-
</body>
|
|
7935
|
-
</html>`);
|
|
7936
|
-
try {
|
|
7937
|
-
for(let key in environments){
|
|
7938
|
-
res.write(`<h2>Environment: ${key}</h2>`);
|
|
7939
|
-
let list = [], environment = environments[key], stats = await environment.getStats(), assets = getAssetNames(stats.compilation);
|
|
7940
|
-
for (let asset of (res.write('<ul>'), assets))list.push(`<li><a target="_blank" href="${asset}">${asset}</a></li>`);
|
|
7941
|
-
res.write(list?.join('')), res.write('</ul>');
|
|
7942
|
-
}
|
|
7943
|
-
res.end('</body></html>');
|
|
7944
|
-
} catch (err) {
|
|
7945
|
-
logger.error(err), res.writeHead(500), res.end('Failed to list the files');
|
|
7946
|
-
}
|
|
7947
|
-
})({
|
|
7948
|
-
environments: devServer.environments,
|
|
7949
|
-
logger
|
|
7950
|
-
})), buildManager && (middlewares.use(buildManager.assetsMiddleware), upgradeEvents.push(buildManager.socketServer.upgrade), middlewares.use(function hotUpdateJsonFallbackMiddleware(req, res, next) {
|
|
7951
|
-
let url = req.url;
|
|
7952
|
-
if (!url || 'OPTIONS' === req.method) return void next();
|
|
7953
|
-
let queryIndex = url.indexOf('?'), end = -1 === queryIndex ? url.length : queryIndex;
|
|
7954
|
-
url.endsWith('.hot-update.json', end) || url.endsWith('.hot-update.json.mjs', end) ? notFoundMiddleware(req, res, next) : next();
|
|
7955
|
-
})), buildManager && middlewares.use(getHtmlCompletionMiddleware({
|
|
7956
|
-
assetsMiddleware: buildManager.assetsMiddleware,
|
|
7957
|
-
distPaths: [
|
|
7958
|
-
context.distPath
|
|
7959
|
-
],
|
|
7960
|
-
outputFileSystem: buildManager.outputFileSystem
|
|
7961
|
-
}));
|
|
7962
|
-
let publicDirPaths = getPublicDirPaths(config);
|
|
7963
|
-
if (publicDirPaths.length) {
|
|
7964
|
-
let { default: sirv } = await import("./sirv.js");
|
|
7965
|
-
for (let name of publicDirPaths){
|
|
7966
|
-
let sirvMiddleware = sirv(name, {
|
|
7967
|
-
etag: !0,
|
|
7968
|
-
dev: !0
|
|
7969
|
-
});
|
|
7970
|
-
middlewares.use(function publicDirMiddleware(req, res, next) {
|
|
7971
|
-
req.method && 'GET' !== req.method && 'HEAD' !== req.method ? next() : sirvMiddleware(req, res, next);
|
|
7972
|
-
});
|
|
7973
|
-
}
|
|
7974
|
-
}
|
|
7975
|
-
for (let callback of postCallbacks)await callback();
|
|
7976
|
-
return server.historyApiFallback && (middlewares.use(historyApiFallback_historyApiFallbackMiddleware(logger, !0 === server.historyApiFallback ? {} : server.historyApiFallback)), buildManager?.assetsMiddleware && middlewares.use(buildManager.assetsMiddleware)), buildManager && server.htmlFallback && middlewares.use(getHtmlFallbackMiddleware({
|
|
7977
|
-
assetsMiddleware: buildManager.assetsMiddleware,
|
|
7978
|
-
distPaths: [
|
|
7979
|
-
context.distPath
|
|
7980
|
-
],
|
|
7981
|
-
logger,
|
|
7982
|
-
outputFileSystem: buildManager.outputFileSystem
|
|
7983
|
-
})), middlewares.use(faviconFallbackMiddleware), {
|
|
7984
|
-
onUpgrade: (...args)=>{
|
|
7985
|
-
for (let cb of upgradeEvents)cb(...args);
|
|
7986
|
-
}
|
|
7987
|
-
};
|
|
7988
|
-
}, getDevMiddlewares = async (options)=>{
|
|
7989
|
-
let { buildManager, context, devServer } = options, { middlewares } = devServer, { logger } = context;
|
|
7990
|
-
isVerbose(logger) && middlewares.use(getRequestLoggerMiddleware(logger));
|
|
7991
|
-
let { before, after } = ((config, devServer, logger)=>{
|
|
7992
|
-
let setupMiddlewares = config.dev.setupMiddlewares ? helpers_castArray(config.dev.setupMiddlewares) : [];
|
|
7993
|
-
setupMiddlewares.length && logger.warn('[rsbuild] `dev.setupMiddlewares` is deprecated, use `server.setup` instead');
|
|
7994
|
-
let serverOptions = pick(devServer, [
|
|
7995
|
-
'sockWrite',
|
|
7996
|
-
'environments'
|
|
7997
|
-
]), before = [], after = [];
|
|
7998
|
-
for (let handler of setupMiddlewares)handler({
|
|
7999
|
-
unshift: (...handlers)=>before.unshift(...handlers),
|
|
8000
|
-
push: (...handlers)=>after.push(...handlers)
|
|
8001
|
-
}, serverOptions);
|
|
8002
|
-
return {
|
|
8003
|
-
before,
|
|
8004
|
-
after
|
|
8005
|
-
};
|
|
8006
|
-
})(options.config, options.devServer, logger);
|
|
8007
|
-
for (let middleware of before)middlewares.use(middleware);
|
|
8008
|
-
let { onUpgrade } = await applyDefaultMiddlewares({
|
|
8009
|
-
...options,
|
|
8010
|
-
middlewares
|
|
8011
|
-
});
|
|
8012
|
-
for (let middleware of after)middlewares.use(middleware);
|
|
8013
|
-
return {
|
|
8014
|
-
close: async ()=>{
|
|
8015
|
-
await buildManager?.close();
|
|
8016
|
-
},
|
|
8017
|
-
onUpgrade
|
|
8018
|
-
};
|
|
8019
|
-
}, isModuleNamespaceObject = (moduleExports)=>'[object Module]' === Object.prototype.toString.call(moduleExports), asModule = async (vm, moduleExports, context, unlinked)=>{
|
|
8020
|
-
let { Module, SyntheticModule } = vm;
|
|
8021
|
-
if (moduleExports instanceof Module) return moduleExports;
|
|
8022
|
-
let normalizedModuleExports = null !== moduleExports && ('object' == typeof moduleExports || 'function' == typeof moduleExports) ? moduleExports : {
|
|
8023
|
-
default: moduleExports
|
|
8024
|
-
}, exports = [
|
|
8025
|
-
...new Set([
|
|
8026
|
-
'default',
|
|
8027
|
-
...Object.keys(normalizedModuleExports)
|
|
8028
|
-
])
|
|
8029
|
-
], syntheticModule = new SyntheticModule(exports, ()=>{
|
|
8030
|
-
for (let name of exports)if ('default' === name) {
|
|
8031
|
-
let defaultExport = isModuleNamespaceObject(normalizedModuleExports) && 'default' in normalizedModuleExports ? normalizedModuleExports.default : moduleExports;
|
|
8032
|
-
syntheticModule.setExport(name, defaultExport);
|
|
8033
|
-
} else syntheticModule.setExport(name, normalizedModuleExports[name]);
|
|
8034
|
-
}, {
|
|
8035
|
-
context
|
|
8036
|
-
});
|
|
8037
|
-
return unlinked || (await syntheticModule.link(()=>{}), await syntheticModule.evaluate()), syntheticModule;
|
|
8038
|
-
};
|
|
8039
|
-
class BasicRunner {
|
|
8040
|
-
options;
|
|
8041
|
-
globalContext = null;
|
|
8042
|
-
baseModuleScope = null;
|
|
8043
|
-
requirers = new Map();
|
|
8044
|
-
constructor(options){
|
|
8045
|
-
this.options = options;
|
|
7700
|
+
let isModuleNamespaceObject = (moduleExports)=>'[object Module]' === Object.prototype.toString.call(moduleExports), asModule = async (vm, moduleExports, context, unlinked)=>{
|
|
7701
|
+
let { Module, SyntheticModule } = vm;
|
|
7702
|
+
if (moduleExports instanceof Module) return moduleExports;
|
|
7703
|
+
let normalizedModuleExports = null !== moduleExports && ('object' == typeof moduleExports || 'function' == typeof moduleExports) ? moduleExports : {
|
|
7704
|
+
default: moduleExports
|
|
7705
|
+
}, exports = [
|
|
7706
|
+
...new Set([
|
|
7707
|
+
'default',
|
|
7708
|
+
...Object.keys(normalizedModuleExports)
|
|
7709
|
+
])
|
|
7710
|
+
], syntheticModule = new SyntheticModule(exports, ()=>{
|
|
7711
|
+
for (let name of exports)if ('default' === name) {
|
|
7712
|
+
let defaultExport = isModuleNamespaceObject(normalizedModuleExports) && 'default' in normalizedModuleExports ? normalizedModuleExports.default : moduleExports;
|
|
7713
|
+
syntheticModule.setExport(name, defaultExport);
|
|
7714
|
+
} else syntheticModule.setExport(name, normalizedModuleExports[name]);
|
|
7715
|
+
}, {
|
|
7716
|
+
context
|
|
7717
|
+
});
|
|
7718
|
+
return unlinked || (await syntheticModule.link(()=>{}), await syntheticModule.evaluate()), syntheticModule;
|
|
7719
|
+
};
|
|
7720
|
+
class BasicRunner {
|
|
7721
|
+
options;
|
|
7722
|
+
globalContext = null;
|
|
7723
|
+
baseModuleScope = null;
|
|
7724
|
+
requirers = new Map();
|
|
7725
|
+
constructor(options){
|
|
7726
|
+
this.options = options;
|
|
8046
7727
|
}
|
|
8047
7728
|
run(file) {
|
|
8048
7729
|
this.globalContext || (this.globalContext = this.createGlobalContext()), this.baseModuleScope = this.createBaseModuleScope(), this.createRunner();
|
|
@@ -8218,10 +7899,7 @@ class BasicRunnerFactory {
|
|
|
8218
7899
|
return new EsmRunner(runnerOptions);
|
|
8219
7900
|
}
|
|
8220
7901
|
}
|
|
8221
|
-
let
|
|
8222
|
-
let runner = new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions);
|
|
8223
|
-
return await runner.run(bundlePath);
|
|
8224
|
-
}, loadBundleStatsCache = new WeakMap(), loadBundle = async (stats, entryName, utils)=>{
|
|
7902
|
+
let loadBundleStatsCache = new WeakMap(), loadBundle = async (stats, entryName, utils)=>{
|
|
8225
7903
|
let loadBundleStats = loadBundleStatsCache.get(stats);
|
|
8226
7904
|
loadBundleStats || (loadBundleStats = {
|
|
8227
7905
|
...stats.toJson({
|
|
@@ -8245,7 +7923,10 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
|
8245
7923
|
for (let chunk of (outputFilePaths = new Set(), chunks || []))for (let file of chunk.files)outputFilePaths.add(join(outputPath, file));
|
|
8246
7924
|
loadBundleStats.outputFilePaths = outputFilePaths;
|
|
8247
7925
|
}
|
|
8248
|
-
return await
|
|
7926
|
+
return await (async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
7927
|
+
let runner = new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions);
|
|
7928
|
+
return await runner.run(bundlePath);
|
|
7929
|
+
})({
|
|
8249
7930
|
bundlePath: files[0],
|
|
8250
7931
|
dist: outputPath,
|
|
8251
7932
|
compilerOptions: stats.compilation.options,
|
|
@@ -8373,51 +8054,7 @@ async function devServer_createDevServer(options, createCompiler, config, devSer
|
|
|
8373
8054
|
let currentStats = stats[index];
|
|
8374
8055
|
return currentStats || waiters[index].promise;
|
|
8375
8056
|
}
|
|
8376
|
-
}), hotConnectCallbacks = new Map(),
|
|
8377
|
-
let compiler = await createCompiler();
|
|
8378
|
-
if (!compiler) throw Error(`${color.dim('[rsbuild:server]')} Failed to get compiler instance.`);
|
|
8379
|
-
context.publicPathnames = getPublicPathnames(compiler_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
|
|
8380
|
-
getPublicPathFromCompiler(compiler)
|
|
8381
|
-
], config.server.base);
|
|
8382
|
-
let hookOptions = {
|
|
8383
|
-
name: 'rsbuild:environment-api',
|
|
8384
|
-
stage: -10000
|
|
8385
|
-
};
|
|
8386
|
-
compiler_isMultiCompiler(compiler) ? compiler.compilers.forEach((compiler, index)=>{
|
|
8387
|
-
compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8388
|
-
compileState.reset(index);
|
|
8389
|
-
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8390
|
-
compileState.done(index, stats);
|
|
8391
|
-
});
|
|
8392
|
-
}) : (compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8393
|
-
compileState.reset(0);
|
|
8394
|
-
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8395
|
-
compileState.done(0, stats);
|
|
8396
|
-
}));
|
|
8397
|
-
let buildManager = new BuildManager({
|
|
8398
|
-
context,
|
|
8399
|
-
config,
|
|
8400
|
-
compiler,
|
|
8401
|
-
resolvedPort: port,
|
|
8402
|
-
onSocketConnect: (socket, token)=>{
|
|
8403
|
-
let callbacks = hotConnectCallbacks?.get(token);
|
|
8404
|
-
if (!callbacks?.size) return;
|
|
8405
|
-
let client = {
|
|
8406
|
-
send: createHotSend(socket)
|
|
8407
|
-
};
|
|
8408
|
-
for (let callback of [
|
|
8409
|
-
...callbacks
|
|
8410
|
-
])try {
|
|
8411
|
-
Promise.resolve(callback(client)).catch((error)=>{
|
|
8412
|
-
logger.error(error);
|
|
8413
|
-
});
|
|
8414
|
-
} catch (error) {
|
|
8415
|
-
logger.error(error);
|
|
8416
|
-
}
|
|
8417
|
-
}
|
|
8418
|
-
});
|
|
8419
|
-
return await buildManager.init(), buildManager;
|
|
8420
|
-
}, protocol = isHttps ? 'https' : 'http', urls = await getAddressUrls({
|
|
8057
|
+
}), hotConnectCallbacks = new Map(), protocol = isHttps ? 'https' : 'http', urls = await getAddressUrls({
|
|
8421
8058
|
protocol,
|
|
8422
8059
|
port,
|
|
8423
8060
|
host
|
|
@@ -8582,12 +8219,216 @@ async function devServer_createDevServer(options, createCompiler, config, devSer
|
|
|
8582
8219
|
})).filter((item)=>'function' == typeof item),
|
|
8583
8220
|
...setupPostCallbacks
|
|
8584
8221
|
];
|
|
8585
|
-
return runCompile ? context.hooks.onBeforeCreateCompiler.tapOnce(beforeCreateCompiler) : await beforeCreateCompiler(), state.buildManager = runCompile ? await
|
|
8222
|
+
return runCompile ? context.hooks.onBeforeCreateCompiler.tapOnce(beforeCreateCompiler) : await beforeCreateCompiler(), state.buildManager = runCompile ? await (async ()=>{
|
|
8223
|
+
let compiler = await createCompiler();
|
|
8224
|
+
if (!compiler) throw Error(`${color.dim('[rsbuild:server]')} Failed to get compiler instance.`);
|
|
8225
|
+
context.publicPathnames = getPublicPathnames(compiler_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
|
|
8226
|
+
getPublicPathFromCompiler(compiler)
|
|
8227
|
+
], config.server.base);
|
|
8228
|
+
let hookOptions = {
|
|
8229
|
+
name: 'rsbuild:environment-api',
|
|
8230
|
+
stage: -10000
|
|
8231
|
+
};
|
|
8232
|
+
compiler_isMultiCompiler(compiler) ? compiler.compilers.forEach((compiler, index)=>{
|
|
8233
|
+
compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8234
|
+
compileState.reset(index);
|
|
8235
|
+
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8236
|
+
compileState.done(index, stats);
|
|
8237
|
+
});
|
|
8238
|
+
}) : (compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8239
|
+
compileState.reset(0);
|
|
8240
|
+
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8241
|
+
compileState.done(0, stats);
|
|
8242
|
+
}));
|
|
8243
|
+
let buildManager = new BuildManager({
|
|
8244
|
+
context,
|
|
8245
|
+
config,
|
|
8246
|
+
compiler,
|
|
8247
|
+
resolvedPort: port,
|
|
8248
|
+
onSocketConnect: (socket, token)=>{
|
|
8249
|
+
let callbacks = hotConnectCallbacks?.get(token);
|
|
8250
|
+
if (!callbacks?.size) return;
|
|
8251
|
+
let client = {
|
|
8252
|
+
send: createHotSend(socket)
|
|
8253
|
+
};
|
|
8254
|
+
for (let callback of [
|
|
8255
|
+
...callbacks
|
|
8256
|
+
])try {
|
|
8257
|
+
Promise.resolve(callback(client)).catch((error)=>{
|
|
8258
|
+
logger.error(error);
|
|
8259
|
+
});
|
|
8260
|
+
} catch (error) {
|
|
8261
|
+
logger.error(error);
|
|
8262
|
+
}
|
|
8263
|
+
}
|
|
8264
|
+
});
|
|
8265
|
+
return await buildManager.init(), buildManager;
|
|
8266
|
+
})() : void 0, state.fileWatcher = await setupWatchFiles({
|
|
8586
8267
|
config,
|
|
8587
8268
|
logger,
|
|
8588
8269
|
buildManager: state.buildManager,
|
|
8589
8270
|
root: context.rootPath
|
|
8590
|
-
}), state.devMiddlewares = await
|
|
8271
|
+
}), state.devMiddlewares = await (async (options)=>{
|
|
8272
|
+
let { buildManager, context, devServer } = options, { middlewares } = devServer, { logger } = context;
|
|
8273
|
+
isVerbose(logger) && middlewares.use(getRequestLoggerMiddleware(logger));
|
|
8274
|
+
let { before, after } = ((config, devServer, logger)=>{
|
|
8275
|
+
let setupMiddlewares = config.dev.setupMiddlewares ? helpers_castArray(config.dev.setupMiddlewares) : [];
|
|
8276
|
+
setupMiddlewares.length && logger.warn('[rsbuild] `dev.setupMiddlewares` is deprecated, use `server.setup` instead');
|
|
8277
|
+
let serverOptions = pick(devServer, [
|
|
8278
|
+
'sockWrite',
|
|
8279
|
+
'environments'
|
|
8280
|
+
]), before = [], after = [];
|
|
8281
|
+
for (let handler of setupMiddlewares)handler({
|
|
8282
|
+
unshift: (...handlers)=>before.unshift(...handlers),
|
|
8283
|
+
push: (...handlers)=>after.push(...handlers)
|
|
8284
|
+
}, serverOptions);
|
|
8285
|
+
return {
|
|
8286
|
+
before,
|
|
8287
|
+
after
|
|
8288
|
+
};
|
|
8289
|
+
})(options.config, options.devServer, logger);
|
|
8290
|
+
for (let middleware of before)middlewares.use(middleware);
|
|
8291
|
+
let { onUpgrade } = await (async ({ config, buildManager, context, devServer, middlewares, postCallbacks })=>{
|
|
8292
|
+
let launchEditorHandlerPromise, upgradeEvents = [], { server } = config, { logger } = context;
|
|
8293
|
+
if (server.cors) {
|
|
8294
|
+
let { default: corsMiddleware } = await import("./cors.js").then(createFakeNamespaceObject.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/cors/2.8.6/abeeebb4dd5e2293f01aa9f4c01ff28ab19103cfa7a845442d515e16cf051f35/node_modules/cors/lib/index.js", 23));
|
|
8295
|
+
middlewares.use(corsMiddleware('boolean' == typeof server.cors ? {} : server.cors));
|
|
8296
|
+
}
|
|
8297
|
+
let { headers } = server;
|
|
8298
|
+
if (headers && middlewares.use((_req, res, next)=>{
|
|
8299
|
+
for (let [key, value] of Object.entries(headers))res.setHeader(key, value);
|
|
8300
|
+
next();
|
|
8301
|
+
}), server.proxy) {
|
|
8302
|
+
let { middlewares: proxyMiddlewares, upgrade } = await createProxyMiddleware(server.proxy, logger);
|
|
8303
|
+
for (let middleware of (upgradeEvents.push(upgrade), proxyMiddlewares))middlewares.use(middleware);
|
|
8304
|
+
}
|
|
8305
|
+
let { compress } = server;
|
|
8306
|
+
if (compress && middlewares.use(gzipMiddleware_gzipMiddleware('object' == typeof compress ? compress : void 0)), 'dev' === context.action && buildManager) {
|
|
8307
|
+
let { compiler } = buildManager;
|
|
8308
|
+
(compiler_isMultiCompiler(compiler) ? compiler.compilers.some((childCompiler)=>childCompiler.options.lazyCompilation) : compiler.options.lazyCompilation) && middlewares.use(core_rspack.lazyCompilationMiddleware(compiler));
|
|
8309
|
+
}
|
|
8310
|
+
server.base && '/' !== server.base && middlewares.use(getBaseUrlMiddleware({
|
|
8311
|
+
base: server.base
|
|
8312
|
+
})), middlewares.use('/__open-in-editor', async (req, res, next)=>{
|
|
8313
|
+
try {
|
|
8314
|
+
(await (launchEditorHandlerPromise ??= (async ()=>{
|
|
8315
|
+
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));
|
|
8316
|
+
return launchEditorMiddleware();
|
|
8317
|
+
})()))(req, res, next);
|
|
8318
|
+
} catch (err) {
|
|
8319
|
+
next(err);
|
|
8320
|
+
}
|
|
8321
|
+
}), middlewares.use((({ environments, logger })=>async function viewingServedFilesMiddleware(req, res, next) {
|
|
8322
|
+
if ('/rsbuild-dev-server' !== req.url.replace(postfixRE, '')) return void next();
|
|
8323
|
+
res.writeHead(200, {
|
|
8324
|
+
'Content-Type': 'text/html; charset=utf-8'
|
|
8325
|
+
}), res.write(`<!DOCTYPE html>
|
|
8326
|
+
<html>
|
|
8327
|
+
<head>
|
|
8328
|
+
<meta charset="utf-8"/>
|
|
8329
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8330
|
+
<style>
|
|
8331
|
+
body {
|
|
8332
|
+
margin: 0;
|
|
8333
|
+
color: #f6f7f9;
|
|
8334
|
+
padding: 32px 40px;
|
|
8335
|
+
line-height: 1.8;
|
|
8336
|
+
min-height: 100vh;
|
|
8337
|
+
background-image: linear-gradient(#020917, #101725);
|
|
8338
|
+
font-family: ui-sans-serif,system-ui,sans-serif;
|
|
8339
|
+
}
|
|
8340
|
+
h1, h2 {
|
|
8341
|
+
font-weight: 500;
|
|
8342
|
+
}
|
|
8343
|
+
h1 {
|
|
8344
|
+
margin: 0;
|
|
8345
|
+
font-size: 36px;
|
|
8346
|
+
}
|
|
8347
|
+
h2 {
|
|
8348
|
+
font-size: 20px;
|
|
8349
|
+
margin: 24px 0 16px;
|
|
8350
|
+
}
|
|
8351
|
+
ul {
|
|
8352
|
+
margin: 0;
|
|
8353
|
+
padding-left: 16px;
|
|
8354
|
+
}
|
|
8355
|
+
a {
|
|
8356
|
+
color: #58c4dc;
|
|
8357
|
+
text-decoration: none;
|
|
8358
|
+
}
|
|
8359
|
+
a:hover {
|
|
8360
|
+
text-decoration: underline;
|
|
8361
|
+
}
|
|
8362
|
+
</style>
|
|
8363
|
+
</head>
|
|
8364
|
+
<body>
|
|
8365
|
+
<h1>Assets Report</h1>
|
|
8366
|
+
</body>
|
|
8367
|
+
</html>`);
|
|
8368
|
+
try {
|
|
8369
|
+
for(let key in environments){
|
|
8370
|
+
res.write(`<h2>Environment: ${key}</h2>`);
|
|
8371
|
+
let list = [], environment = environments[key], stats = await environment.getStats(), assets = getAssetNames(stats.compilation);
|
|
8372
|
+
for (let asset of (res.write('<ul>'), assets))list.push(`<li><a target="_blank" href="${asset}">${asset}</a></li>`);
|
|
8373
|
+
res.write(list?.join('')), res.write('</ul>');
|
|
8374
|
+
}
|
|
8375
|
+
res.end('</body></html>');
|
|
8376
|
+
} catch (err) {
|
|
8377
|
+
logger.error(err), res.writeHead(500), res.end('Failed to list the files');
|
|
8378
|
+
}
|
|
8379
|
+
})({
|
|
8380
|
+
environments: devServer.environments,
|
|
8381
|
+
logger
|
|
8382
|
+
})), buildManager && (middlewares.use(buildManager.assetsMiddleware), upgradeEvents.push(buildManager.socketServer.upgrade), middlewares.use(function hotUpdateJsonFallbackMiddleware(req, res, next) {
|
|
8383
|
+
let url = req.url;
|
|
8384
|
+
if (!url || 'OPTIONS' === req.method) return void next();
|
|
8385
|
+
let queryIndex = url.indexOf('?'), end = -1 === queryIndex ? url.length : queryIndex;
|
|
8386
|
+
url.endsWith('.hot-update.json', end) || url.endsWith('.hot-update.json.mjs', end) ? notFoundMiddleware(req, res, next) : next();
|
|
8387
|
+
})), buildManager && middlewares.use(getHtmlCompletionMiddleware({
|
|
8388
|
+
assetsMiddleware: buildManager.assetsMiddleware,
|
|
8389
|
+
distPaths: [
|
|
8390
|
+
context.distPath
|
|
8391
|
+
],
|
|
8392
|
+
outputFileSystem: buildManager.outputFileSystem
|
|
8393
|
+
}));
|
|
8394
|
+
let publicDirPaths = getPublicDirPaths(config);
|
|
8395
|
+
if (publicDirPaths.length) {
|
|
8396
|
+
let { default: sirv } = await import("./sirv.js");
|
|
8397
|
+
for (let name of publicDirPaths){
|
|
8398
|
+
let sirvMiddleware = sirv(name, {
|
|
8399
|
+
etag: !0,
|
|
8400
|
+
dev: !0
|
|
8401
|
+
});
|
|
8402
|
+
middlewares.use(function publicDirMiddleware(req, res, next) {
|
|
8403
|
+
req.method && 'GET' !== req.method && 'HEAD' !== req.method ? next() : sirvMiddleware(req, res, next);
|
|
8404
|
+
});
|
|
8405
|
+
}
|
|
8406
|
+
}
|
|
8407
|
+
for (let callback of postCallbacks)await callback();
|
|
8408
|
+
return server.historyApiFallback && (middlewares.use(historyApiFallback_historyApiFallbackMiddleware(logger, !0 === server.historyApiFallback ? {} : server.historyApiFallback)), buildManager?.assetsMiddleware && middlewares.use(buildManager.assetsMiddleware)), buildManager && server.htmlFallback && middlewares.use(getHtmlFallbackMiddleware({
|
|
8409
|
+
assetsMiddleware: buildManager.assetsMiddleware,
|
|
8410
|
+
distPaths: [
|
|
8411
|
+
context.distPath
|
|
8412
|
+
],
|
|
8413
|
+
logger,
|
|
8414
|
+
outputFileSystem: buildManager.outputFileSystem
|
|
8415
|
+
})), middlewares.use(faviconFallbackMiddleware), {
|
|
8416
|
+
onUpgrade: (...args)=>{
|
|
8417
|
+
for (let cb of upgradeEvents)cb(...args);
|
|
8418
|
+
}
|
|
8419
|
+
};
|
|
8420
|
+
})({
|
|
8421
|
+
...options,
|
|
8422
|
+
middlewares
|
|
8423
|
+
});
|
|
8424
|
+
for (let middleware of after)middlewares.use(middleware);
|
|
8425
|
+
return {
|
|
8426
|
+
close: async ()=>{
|
|
8427
|
+
await buildManager?.close();
|
|
8428
|
+
},
|
|
8429
|
+
onUpgrade
|
|
8430
|
+
};
|
|
8431
|
+
})({
|
|
8591
8432
|
buildManager: state.buildManager,
|
|
8592
8433
|
config,
|
|
8593
8434
|
devServer,
|
|
@@ -9416,7 +9257,45 @@ try {
|
|
|
9416
9257
|
skipMain: !emitCss
|
|
9417
9258
|
});
|
|
9418
9259
|
}
|
|
9419
|
-
let postcssLoaderOptions = await
|
|
9260
|
+
let postcssLoaderOptions = await (async ({ config, root, postcssrcCache })=>{
|
|
9261
|
+
let extraPlugins = [], userOptions = await loadUserPostcssrc(root, postcssrcCache);
|
|
9262
|
+
userOptions.plugins ||= [];
|
|
9263
|
+
let defaultOptions = {
|
|
9264
|
+
implementation: getCompiledPath('postcss'),
|
|
9265
|
+
postcssOptions: userOptions,
|
|
9266
|
+
sourceMap: getCSSSourceMap(config)
|
|
9267
|
+
}, finalOptions = await reduceConfigsWithContext({
|
|
9268
|
+
initial: defaultOptions,
|
|
9269
|
+
config: config.tools.postcss,
|
|
9270
|
+
ctx: {
|
|
9271
|
+
addPlugins (plugins, options = {}) {
|
|
9272
|
+
let { order = 'post' } = options, list = helpers_castArray(plugins);
|
|
9273
|
+
'pre' === order ? extraPlugins.unshift(...list) : extraPlugins.push(...list);
|
|
9274
|
+
}
|
|
9275
|
+
}
|
|
9276
|
+
});
|
|
9277
|
+
finalOptions.postcssOptions ||= {};
|
|
9278
|
+
let updatePostcssOptions = (options)=>(options.plugins ||= [], extraPlugins.length && options.plugins.push(...extraPlugins), options.plugins = options.plugins.map((plugin)=>'function' == typeof plugin && 'postcss' in plugin && plugin.postcss ? plugin() : plugin), options.config = !1, options), { postcssOptions } = finalOptions;
|
|
9279
|
+
if ('function' == typeof postcssOptions) {
|
|
9280
|
+
let postcssOptionsWrapper = (loaderContext)=>{
|
|
9281
|
+
let options = postcssOptions(loaderContext);
|
|
9282
|
+
if ('object' != typeof options || null === options) throw Error(`${color.dim('[rsbuild:css]')} \`postcssOptions\` function must return a PostCSSOptions object, got ${color.yellow(typeof options)}.`);
|
|
9283
|
+
return updatePostcssOptions({
|
|
9284
|
+
...userOptions,
|
|
9285
|
+
...options,
|
|
9286
|
+
plugins: [
|
|
9287
|
+
...userOptions.plugins || [],
|
|
9288
|
+
...options.plugins || []
|
|
9289
|
+
]
|
|
9290
|
+
});
|
|
9291
|
+
};
|
|
9292
|
+
return postcssOptionsWrapper.config = !1, {
|
|
9293
|
+
...finalOptions,
|
|
9294
|
+
postcssOptions: postcssOptionsWrapper
|
|
9295
|
+
};
|
|
9296
|
+
}
|
|
9297
|
+
return finalOptions.postcssOptions = updatePostcssOptions(postcssOptions), finalOptions;
|
|
9298
|
+
})({
|
|
9420
9299
|
config,
|
|
9421
9300
|
root: api.context.rootPath,
|
|
9422
9301
|
postcssrcCache
|
|
@@ -9430,7 +9309,37 @@ try {
|
|
|
9430
9309
|
skipMain: !emitCss
|
|
9431
9310
|
});
|
|
9432
9311
|
}
|
|
9433
|
-
let localIdentName = config.output.cssModules.localIdentName || (isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'), cssLoaderOptions = await
|
|
9312
|
+
let localIdentName = config.output.cssModules.localIdentName || (isProd ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'), cssLoaderOptions = await (async ({ config, localIdentName, emitCss })=>{
|
|
9313
|
+
let { cssModules } = config.output, defaultOptions = {
|
|
9314
|
+
modules: {
|
|
9315
|
+
...cssModules,
|
|
9316
|
+
localIdentName
|
|
9317
|
+
},
|
|
9318
|
+
sourceMap: getCSSSourceMap(config)
|
|
9319
|
+
};
|
|
9320
|
+
return ((options, exportOnlyLocals)=>{
|
|
9321
|
+
if (options.modules && exportOnlyLocals) {
|
|
9322
|
+
let { modules } = options;
|
|
9323
|
+
return modules = !0 === modules ? {
|
|
9324
|
+
exportOnlyLocals: !0
|
|
9325
|
+
} : 'string' == typeof modules ? {
|
|
9326
|
+
mode: modules,
|
|
9327
|
+
exportOnlyLocals: !0
|
|
9328
|
+
} : {
|
|
9329
|
+
...modules,
|
|
9330
|
+
exportOnlyLocals: !0
|
|
9331
|
+
}, {
|
|
9332
|
+
...options,
|
|
9333
|
+
modules
|
|
9334
|
+
};
|
|
9335
|
+
}
|
|
9336
|
+
return options;
|
|
9337
|
+
})(await reduceConfigs({
|
|
9338
|
+
initial: defaultOptions,
|
|
9339
|
+
config: config.tools.cssLoader,
|
|
9340
|
+
mergeFn: cjs_0_default()
|
|
9341
|
+
}), !emitCss);
|
|
9342
|
+
})({
|
|
9434
9343
|
config,
|
|
9435
9344
|
localIdentName,
|
|
9436
9345
|
emitCss
|
|
@@ -10089,82 +9998,175 @@ async function createRsbuild(options = {}) {
|
|
|
10089
9998
|
context,
|
|
10090
9999
|
pluginManager,
|
|
10091
10000
|
rsbuildOptions: resolvedOptions
|
|
10092
|
-
})).compiler),
|
|
10093
|
-
context.action = 'preview', process.env.NODE_ENV || setNodeEnv('production');
|
|
10094
|
-
let config = await initRsbuildConfig({
|
|
10095
|
-
context,
|
|
10096
|
-
pluginManager
|
|
10097
|
-
}), { distPath } = context, { checkDistDir = !0 } = options;
|
|
10098
|
-
if (checkDistDir) {
|
|
10099
|
-
if (!existsSync(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} does not exist, please build the project before previewing.`);
|
|
10100
|
-
if (isEmptyDir(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} is empty, please build the project before previewing.`);
|
|
10101
|
-
}
|
|
10102
|
-
return startPreviewServer(context, config, options);
|
|
10103
|
-
}, build = async (options = {})=>(context.action = 'build', process.env.NODE_ENV || setNodeEnv('production'), build_build({
|
|
10104
|
-
context,
|
|
10105
|
-
pluginManager,
|
|
10106
|
-
rsbuildOptions: resolvedOptions
|
|
10107
|
-
}, {
|
|
10108
|
-
...options
|
|
10109
|
-
})), startDevServer = async (options = {})=>{
|
|
10110
|
-
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
10111
|
-
let config = await initRsbuildConfig({
|
|
10112
|
-
context,
|
|
10113
|
-
pluginManager
|
|
10114
|
-
});
|
|
10115
|
-
return (await devServer_createDevServer({
|
|
10116
|
-
context,
|
|
10117
|
-
pluginManager,
|
|
10118
|
-
rsbuildOptions: resolvedOptions
|
|
10119
|
-
}, createCompiler, config, options)).listen();
|
|
10120
|
-
}, createDevServer = async (options)=>{
|
|
10121
|
-
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
10122
|
-
let config = await initRsbuildConfig({
|
|
10123
|
-
context,
|
|
10124
|
-
pluginManager
|
|
10125
|
-
});
|
|
10126
|
-
return devServer_createDevServer({
|
|
10127
|
-
context,
|
|
10128
|
-
pluginManager,
|
|
10129
|
-
rsbuildOptions: resolvedOptions
|
|
10130
|
-
}, createCompiler, config, options);
|
|
10131
|
-
}, initAction = (mode = config.mode)=>{
|
|
10001
|
+
})).compiler), initAction = (mode = config.mode)=>{
|
|
10132
10002
|
context.action || (context.action = 'development' === mode ? 'dev' : 'build');
|
|
10133
|
-
}, inspectConfig = async (inspectOptions = {})=>{
|
|
10134
|
-
inspectOptions.mode ? setNodeEnv(inspectOptions.mode) : process.env.NODE_ENV || setNodeEnv('development'), initAction(config.mode ?? (process.env.NODE_ENV || ''));
|
|
10135
|
-
let { rspackConfigs } = await initConfigs_initConfigs({
|
|
10136
|
-
context,
|
|
10137
|
-
pluginManager,
|
|
10138
|
-
rsbuildOptions: resolvedOptions
|
|
10139
|
-
});
|
|
10140
|
-
return inspectConfig_inspectConfig({
|
|
10141
|
-
context,
|
|
10142
|
-
pluginManager,
|
|
10143
|
-
rsbuildOptions: resolvedOptions,
|
|
10144
|
-
inspectOptions,
|
|
10145
|
-
bundlerConfigs: rspackConfigs
|
|
10146
|
-
});
|
|
10147
|
-
}, initConfigs = async (options)=>{
|
|
10148
|
-
if (context.action && options?.action && context.action !== options.action) throw Error(`\
|
|
10149
|
-
[rsbuild] initConfigs() can only be called with the same action type.
|
|
10150
|
-
- Expected: ${context.action}
|
|
10151
|
-
- Actual: ${options?.action}`);
|
|
10152
|
-
options?.action && (context.action = options.action);
|
|
10153
|
-
let { rspackConfigs } = await initConfigs_initConfigs({
|
|
10154
|
-
context,
|
|
10155
|
-
pluginManager,
|
|
10156
|
-
rsbuildOptions: resolvedOptions
|
|
10157
|
-
});
|
|
10158
|
-
return rspackConfigs;
|
|
10159
10003
|
}, rsbuild = {
|
|
10160
10004
|
logger: context.logger,
|
|
10161
|
-
build,
|
|
10162
|
-
|
|
10163
|
-
|
|
10005
|
+
build: async (options = {})=>(context.action = 'build', process.env.NODE_ENV || setNodeEnv('production'), (async (initOptions, buildOptions = {})=>{
|
|
10006
|
+
let stats, closeCompiler, closingPromise, unregisterRestart, restartWatcher, { watch } = buildOptions, { context } = initOptions, { logger } = context, { compiler, rspackConfigs } = await createCompiler_createCompiler(initOptions);
|
|
10007
|
+
if ((({ context, isWatch, compiler, rspackConfigs, MultiStatsCtor })=>{
|
|
10008
|
+
let isFirstCompile = !0, { environmentList } = context;
|
|
10009
|
+
onBeforeCompile({
|
|
10010
|
+
compiler,
|
|
10011
|
+
beforeCompile: async ()=>context.hooks.onBeforeBuild.callBatch({
|
|
10012
|
+
bundlerConfigs: rspackConfigs,
|
|
10013
|
+
environments: context.environments,
|
|
10014
|
+
isWatch,
|
|
10015
|
+
isFirstCompile
|
|
10016
|
+
}),
|
|
10017
|
+
beforeEnvironmentCompile: async (buildIndex)=>{
|
|
10018
|
+
let environment = environmentList[buildIndex];
|
|
10019
|
+
return context.hooks.onBeforeEnvironmentCompile.callBatch({
|
|
10020
|
+
environment: environment.name,
|
|
10021
|
+
args: [
|
|
10022
|
+
{
|
|
10023
|
+
bundlerConfig: rspackConfigs[buildIndex],
|
|
10024
|
+
environment,
|
|
10025
|
+
isWatch,
|
|
10026
|
+
isFirstCompile
|
|
10027
|
+
}
|
|
10028
|
+
]
|
|
10029
|
+
});
|
|
10030
|
+
},
|
|
10031
|
+
isWatch
|
|
10032
|
+
}), onCompileDone({
|
|
10033
|
+
compiler,
|
|
10034
|
+
onDone: async (stats)=>{
|
|
10035
|
+
let shouldLogWatching = isWatch && isFirstCompile, promise = context.hooks.onAfterBuild.callBatch({
|
|
10036
|
+
isFirstCompile,
|
|
10037
|
+
stats,
|
|
10038
|
+
environments: context.environments,
|
|
10039
|
+
isWatch
|
|
10040
|
+
});
|
|
10041
|
+
isFirstCompile = !1, await promise, shouldLogWatching && context.logger.info('watching for changes...');
|
|
10042
|
+
},
|
|
10043
|
+
onEnvironmentDone: async (index, stats)=>{
|
|
10044
|
+
let environment = environmentList[index], time = context.buildState.time[environment.name] ?? 0;
|
|
10045
|
+
await context.hooks.onAfterEnvironmentCompile.callBatch({
|
|
10046
|
+
environment: environment.name,
|
|
10047
|
+
args: [
|
|
10048
|
+
{
|
|
10049
|
+
isFirstCompile,
|
|
10050
|
+
stats,
|
|
10051
|
+
environment,
|
|
10052
|
+
isWatch,
|
|
10053
|
+
time
|
|
10054
|
+
}
|
|
10055
|
+
]
|
|
10056
|
+
});
|
|
10057
|
+
},
|
|
10058
|
+
MultiStatsCtor
|
|
10059
|
+
});
|
|
10060
|
+
})({
|
|
10061
|
+
context,
|
|
10062
|
+
rspackConfigs,
|
|
10063
|
+
compiler,
|
|
10064
|
+
isWatch: !!watch,
|
|
10065
|
+
MultiStatsCtor: core_rspack.MultiStats
|
|
10066
|
+
}), watch) {
|
|
10067
|
+
let watchOptions = rspackConfigs.map((options)=>options.watchOptions || {});
|
|
10068
|
+
compiler.watch(watchOptions.length > 1 ? watchOptions : watchOptions[0] || {}, (err)=>{
|
|
10069
|
+
err && logger.error(err);
|
|
10070
|
+
}), closeCompiler = ()=>new Promise((resolve)=>{
|
|
10071
|
+
compiler.close(()=>{
|
|
10072
|
+
resolve();
|
|
10073
|
+
});
|
|
10074
|
+
});
|
|
10075
|
+
} else stats = await new Promise((resolve, reject)=>{
|
|
10076
|
+
compiler.run((err, stats)=>{
|
|
10077
|
+
compiler.close((closeErr)=>{
|
|
10078
|
+
closeErr && logger.error('Failed to close compiler: ', closeErr), err ? reject(err) : context.buildState.hasErrors ? reject(Error(RSPACK_BUILD_ERROR)) : resolve(stats);
|
|
10079
|
+
});
|
|
10080
|
+
});
|
|
10081
|
+
});
|
|
10082
|
+
let closeBuild = ()=>closingPromise ||= (async ()=>{
|
|
10083
|
+
unregisterRestart?.(), unregisterRestart = void 0, await context.hooks.onCloseBuild.callBatch(), await closeCompiler?.();
|
|
10084
|
+
})();
|
|
10085
|
+
return watch && (unregisterRestart = context.restartManager.registerCleanup(closeBuild), restartWatcher = watchFilesForRestart({
|
|
10086
|
+
watchFiles: context.normalizedConfig.dev.watchFiles,
|
|
10087
|
+
context,
|
|
10088
|
+
restartContext: {
|
|
10089
|
+
action: 'build',
|
|
10090
|
+
options: buildOptions
|
|
10091
|
+
}
|
|
10092
|
+
})), {
|
|
10093
|
+
stats,
|
|
10094
|
+
close: async ()=>{
|
|
10095
|
+
await restartWatcher?.close(), await closeBuild();
|
|
10096
|
+
}
|
|
10097
|
+
};
|
|
10098
|
+
})({
|
|
10099
|
+
context,
|
|
10100
|
+
pluginManager,
|
|
10101
|
+
rsbuildOptions: resolvedOptions
|
|
10102
|
+
}, {
|
|
10103
|
+
...options
|
|
10104
|
+
})),
|
|
10105
|
+
preview: async (options = {})=>{
|
|
10106
|
+
context.action = 'preview', process.env.NODE_ENV || setNodeEnv('production');
|
|
10107
|
+
let config = await initRsbuildConfig({
|
|
10108
|
+
context,
|
|
10109
|
+
pluginManager
|
|
10110
|
+
}), { distPath } = context, { checkDistDir = !0 } = options;
|
|
10111
|
+
if (checkDistDir) {
|
|
10112
|
+
if (!existsSync(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} does not exist, please build the project before previewing.`);
|
|
10113
|
+
if (isEmptyDir(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} is empty, please build the project before previewing.`);
|
|
10114
|
+
}
|
|
10115
|
+
return startPreviewServer(context, config, options);
|
|
10116
|
+
},
|
|
10117
|
+
startDevServer: async (options = {})=>{
|
|
10118
|
+
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
10119
|
+
let config = await initRsbuildConfig({
|
|
10120
|
+
context,
|
|
10121
|
+
pluginManager
|
|
10122
|
+
});
|
|
10123
|
+
return (await devServer_createDevServer({
|
|
10124
|
+
context,
|
|
10125
|
+
pluginManager,
|
|
10126
|
+
rsbuildOptions: resolvedOptions
|
|
10127
|
+
}, createCompiler, config, options)).listen();
|
|
10128
|
+
},
|
|
10164
10129
|
createCompiler,
|
|
10165
|
-
createDevServer
|
|
10166
|
-
|
|
10167
|
-
|
|
10130
|
+
createDevServer: async (options)=>{
|
|
10131
|
+
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
10132
|
+
let config = await initRsbuildConfig({
|
|
10133
|
+
context,
|
|
10134
|
+
pluginManager
|
|
10135
|
+
});
|
|
10136
|
+
return devServer_createDevServer({
|
|
10137
|
+
context,
|
|
10138
|
+
pluginManager,
|
|
10139
|
+
rsbuildOptions: resolvedOptions
|
|
10140
|
+
}, createCompiler, config, options);
|
|
10141
|
+
},
|
|
10142
|
+
inspectConfig: async (inspectOptions = {})=>{
|
|
10143
|
+
inspectOptions.mode ? setNodeEnv(inspectOptions.mode) : process.env.NODE_ENV || setNodeEnv('development'), initAction(config.mode ?? (process.env.NODE_ENV || ''));
|
|
10144
|
+
let { rspackConfigs } = await initConfigs_initConfigs({
|
|
10145
|
+
context,
|
|
10146
|
+
pluginManager,
|
|
10147
|
+
rsbuildOptions: resolvedOptions
|
|
10148
|
+
});
|
|
10149
|
+
return inspectConfig_inspectConfig({
|
|
10150
|
+
context,
|
|
10151
|
+
pluginManager,
|
|
10152
|
+
rsbuildOptions: resolvedOptions,
|
|
10153
|
+
inspectOptions,
|
|
10154
|
+
bundlerConfigs: rspackConfigs
|
|
10155
|
+
});
|
|
10156
|
+
},
|
|
10157
|
+
initConfigs: async (options)=>{
|
|
10158
|
+
if (context.action && options?.action && context.action !== options.action) throw Error(`\
|
|
10159
|
+
[rsbuild] initConfigs() can only be called with the same action type.
|
|
10160
|
+
- Expected: ${context.action}
|
|
10161
|
+
- Actual: ${options?.action}`);
|
|
10162
|
+
options?.action && (context.action = options.action);
|
|
10163
|
+
let { rspackConfigs } = await initConfigs_initConfigs({
|
|
10164
|
+
context,
|
|
10165
|
+
pluginManager,
|
|
10166
|
+
rsbuildOptions: resolvedOptions
|
|
10167
|
+
});
|
|
10168
|
+
return rspackConfigs;
|
|
10169
|
+
},
|
|
10168
10170
|
...pick(pluginManager, [
|
|
10169
10171
|
'addPlugins',
|
|
10170
10172
|
'getPlugins',
|
|
@@ -10227,50 +10229,11 @@ let canReadExport = (module)=>null !== module && ('object' == typeof module || '
|
|
|
10227
10229
|
return ()=>promise ??= importer().catch((error)=>{
|
|
10228
10230
|
throw promise = void 0, error;
|
|
10229
10231
|
});
|
|
10230
|
-
}, getJiti = cachedImport(()=>import("../compiled/jiti/lib/jiti.mjs")),
|
|
10231
|
-
let createJiti;
|
|
10232
|
-
try {
|
|
10233
|
-
({ createJiti } = await getJiti());
|
|
10234
|
-
} catch (error) {
|
|
10235
|
-
throw Error('The "jiti" package is required to load this config. Install it with your package manager.', {
|
|
10236
|
-
cause: error
|
|
10237
|
-
});
|
|
10238
|
-
}
|
|
10239
|
-
let jiti = createJiti(configPath, {
|
|
10240
|
-
moduleCache: !fresh,
|
|
10241
|
-
interopDefault: !0,
|
|
10242
|
-
nativeModules: [
|
|
10243
|
-
"typescript"
|
|
10244
|
-
]
|
|
10245
|
-
});
|
|
10246
|
-
return 'default' === exportName ? {
|
|
10247
|
-
configExport: await jiti.import(configPath, {
|
|
10248
|
-
default: !0
|
|
10249
|
-
}),
|
|
10250
|
-
dependencies: []
|
|
10251
|
-
} : {
|
|
10252
|
-
configExport: getConfigExport(await jiti.import(configPath), exportName, configPath),
|
|
10253
|
-
dependencies: []
|
|
10254
|
-
};
|
|
10255
|
-
}, CONFIG_META = Symbol.for('@rstackjs/load-config/meta');
|
|
10232
|
+
}, getJiti = cachedImport(()=>import("../compiled/jiti/lib/jiti.mjs")), CONFIG_META = Symbol.for('@rstackjs/load-config/meta');
|
|
10256
10233
|
function getConfigMeta(config) {
|
|
10257
10234
|
if (null !== config && 'object' == typeof config && Object.hasOwn(config, CONFIG_META)) return config[CONFIG_META];
|
|
10258
10235
|
}
|
|
10259
|
-
let getFreshImport = cachedImport(()=>import("./freshImport.js")), JS_CONFIG_REGEXP = /\.(?:js|mjs|cjs)
|
|
10260
|
-
let configFileURL = pathToFileURL(configPath).href;
|
|
10261
|
-
if (!fresh) return {
|
|
10262
|
-
configModule: await import(configFileURL),
|
|
10263
|
-
dependencies: []
|
|
10264
|
-
};
|
|
10265
|
-
let { freshImport } = await getFreshImport(), freshImportResult = await freshImport(configFileURL);
|
|
10266
|
-
return freshImportResult ? {
|
|
10267
|
-
configModule: freshImportResult.result,
|
|
10268
|
-
dependencies: freshImportResult.dependencies.sort()
|
|
10269
|
-
} : {
|
|
10270
|
-
configModule: await import(`${configFileURL}?t=${Date.now()}`),
|
|
10271
|
-
dependencies: []
|
|
10272
|
-
};
|
|
10273
|
-
};
|
|
10236
|
+
let getFreshImport = cachedImport(()=>import("./freshImport.js")), JS_CONFIG_REGEXP = /\.(?:js|mjs|cjs)$/;
|
|
10274
10237
|
async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = [], loader = 'auto', exportName = 'default', configParams = [], fresh = !1 } = {}) {
|
|
10275
10238
|
let loadedConfig, content;
|
|
10276
10239
|
if (!path && 0 === configFileNames.length) throw Error('Either `path` or at least one `configFileNames` entry must be provided.');
|
|
@@ -10294,7 +10257,21 @@ async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = []
|
|
|
10294
10257
|
if ('native' === loader || 'auto' === loader && (process.features.typescript || process.versions.bun || process.versions.deno) || JS_CONFIG_REGEXP.test(configPath)) {
|
|
10295
10258
|
let result;
|
|
10296
10259
|
try {
|
|
10297
|
-
result = await
|
|
10260
|
+
result = await (async (configPath, fresh)=>{
|
|
10261
|
+
let configFileURL = pathToFileURL(configPath).href;
|
|
10262
|
+
if (!fresh) return {
|
|
10263
|
+
configModule: await import(configFileURL),
|
|
10264
|
+
dependencies: []
|
|
10265
|
+
};
|
|
10266
|
+
let { freshImport } = await getFreshImport(), freshImportResult = await freshImport(configFileURL);
|
|
10267
|
+
return freshImportResult ? {
|
|
10268
|
+
configModule: freshImportResult.result,
|
|
10269
|
+
dependencies: freshImportResult.dependencies.sort()
|
|
10270
|
+
} : {
|
|
10271
|
+
configModule: await import(`${configFileURL}?t=${Date.now()}`),
|
|
10272
|
+
dependencies: []
|
|
10273
|
+
};
|
|
10274
|
+
})(configPath, fresh);
|
|
10298
10275
|
} catch (err) {
|
|
10299
10276
|
if ('native' === loader) throw err;
|
|
10300
10277
|
}
|
|
@@ -10303,7 +10280,32 @@ async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = []
|
|
|
10303
10280
|
dependencies: result.dependencies
|
|
10304
10281
|
});
|
|
10305
10282
|
}
|
|
10306
|
-
loadedConfig || (loadedConfig = await
|
|
10283
|
+
loadedConfig || (loadedConfig = await (async (configPath, exportName, fresh)=>{
|
|
10284
|
+
let createJiti;
|
|
10285
|
+
try {
|
|
10286
|
+
({ createJiti } = await getJiti());
|
|
10287
|
+
} catch (error) {
|
|
10288
|
+
throw Error('The "jiti" package is required to load this config. Install it with your package manager.', {
|
|
10289
|
+
cause: error
|
|
10290
|
+
});
|
|
10291
|
+
}
|
|
10292
|
+
let jiti = createJiti(configPath, {
|
|
10293
|
+
moduleCache: !fresh,
|
|
10294
|
+
interopDefault: !0,
|
|
10295
|
+
nativeModules: [
|
|
10296
|
+
"typescript"
|
|
10297
|
+
]
|
|
10298
|
+
});
|
|
10299
|
+
return 'default' === exportName ? {
|
|
10300
|
+
configExport: await jiti.import(configPath, {
|
|
10301
|
+
default: !0
|
|
10302
|
+
}),
|
|
10303
|
+
dependencies: []
|
|
10304
|
+
} : {
|
|
10305
|
+
configExport: getConfigExport(await jiti.import(configPath), exportName, configPath),
|
|
10306
|
+
dependencies: []
|
|
10307
|
+
};
|
|
10308
|
+
})(configPath, exportName, fresh));
|
|
10307
10309
|
let { configExport, dependencies } = loadedConfig;
|
|
10308
10310
|
if ('function' == typeof configExport) {
|
|
10309
10311
|
let result = await configExport(...configParams);
|
|
@@ -10362,30 +10364,6 @@ let cliState = {
|
|
|
10362
10364
|
options: {}
|
|
10363
10365
|
}, initCliAction = (command, options)=>{
|
|
10364
10366
|
process.env.NODE_ENV || (process.env.NODE_ENV = 'build' === command || 'preview' === command ? 'production' : 'development'), options.environment?.some((env)=>env.includes(',')) && (options.environment = options.environment.flatMap((env)=>env.split(','))), cliState.command = command, cliState.options = options;
|
|
10365
|
-
}, init_loadConfig = async (root)=>{
|
|
10366
|
-
let { options, command } = cliState, result = await loadConfig_loadConfig({
|
|
10367
|
-
cwd: root,
|
|
10368
|
-
path: options.config,
|
|
10369
|
-
envMode: options.envMode,
|
|
10370
|
-
loader: options.configLoader,
|
|
10371
|
-
command
|
|
10372
|
-
}), { content: config } = result;
|
|
10373
|
-
if (config.dev ||= {}, config.source ||= {}, config.server ||= {}, options.base && (config.server.base = options.base), options.root && (config.root = root), options.mode && (config.mode = options.mode), options.logLevel && (config.logLevel = options.logLevel), options.open && !config.server?.open && (config.server.open = options.open), void 0 !== options.host && (config.server.host = options.host), void 0 !== options.port && (config.server.port = options.port), void 0 !== options.strictPort && (config.server.strictPort = options.strictPort), void 0 !== options.distPath) {
|
|
10374
|
-
config.output ||= {};
|
|
10375
|
-
let { distPath } = config.output;
|
|
10376
|
-
config.output.distPath = distPath && 'object' == typeof distPath ? {
|
|
10377
|
-
...distPath,
|
|
10378
|
-
root: options.distPath
|
|
10379
|
-
} : {
|
|
10380
|
-
root: options.distPath
|
|
10381
|
-
};
|
|
10382
|
-
}
|
|
10383
|
-
if (void 0 !== options.sourceMap) {
|
|
10384
|
-
let sourceMap = options.sourceMap;
|
|
10385
|
-
if ('boolean' != typeof sourceMap) throw Error('The "--source-map" option only accepts a boolean value.');
|
|
10386
|
-
config.output ||= {}, config.output.sourceMap = sourceMap;
|
|
10387
|
-
}
|
|
10388
|
-
return void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), result;
|
|
10389
10367
|
}, init_restart = async (context)=>{
|
|
10390
10368
|
let rsbuild = await init_init({
|
|
10391
10369
|
isRestart: !0
|
|
@@ -10398,7 +10376,31 @@ async function init_init({ isRestart } = {}) {
|
|
|
10398
10376
|
var envDir;
|
|
10399
10377
|
let cwd = process.cwd(), root = options.root ? ensureAbsolutePath(cwd, options.root) : cwd, rsbuild = await createRsbuild({
|
|
10400
10378
|
cwd: root,
|
|
10401
|
-
config: ()=>
|
|
10379
|
+
config: ()=>(async (root)=>{
|
|
10380
|
+
let { options, command } = cliState, result = await loadConfig_loadConfig({
|
|
10381
|
+
cwd: root,
|
|
10382
|
+
path: options.config,
|
|
10383
|
+
envMode: options.envMode,
|
|
10384
|
+
loader: options.configLoader,
|
|
10385
|
+
command
|
|
10386
|
+
}), { content: config } = result;
|
|
10387
|
+
if (config.dev ||= {}, config.source ||= {}, config.server ||= {}, options.base && (config.server.base = options.base), options.root && (config.root = root), options.mode && (config.mode = options.mode), options.logLevel && (config.logLevel = options.logLevel), options.open && !config.server?.open && (config.server.open = options.open), void 0 !== options.host && (config.server.host = options.host), void 0 !== options.port && (config.server.port = options.port), void 0 !== options.strictPort && (config.server.strictPort = options.strictPort), void 0 !== options.distPath) {
|
|
10388
|
+
config.output ||= {};
|
|
10389
|
+
let { distPath } = config.output;
|
|
10390
|
+
config.output.distPath = distPath && 'object' == typeof distPath ? {
|
|
10391
|
+
...distPath,
|
|
10392
|
+
root: options.distPath
|
|
10393
|
+
} : {
|
|
10394
|
+
root: options.distPath
|
|
10395
|
+
};
|
|
10396
|
+
}
|
|
10397
|
+
if (void 0 !== options.sourceMap) {
|
|
10398
|
+
let sourceMap = options.sourceMap;
|
|
10399
|
+
if ('boolean' != typeof sourceMap) throw Error('The "--source-map" option only accepts a boolean value.');
|
|
10400
|
+
config.output ||= {}, config.output.sourceMap = sourceMap;
|
|
10401
|
+
}
|
|
10402
|
+
return void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), result;
|
|
10403
|
+
})(root),
|
|
10402
10404
|
environment: options.environment,
|
|
10403
10405
|
loadEnv: !1 !== options.env && {
|
|
10404
10406
|
cwd: (envDir = options.envDir) ? node_path.isAbsolute(envDir) ? envDir : node_path.join(root, envDir) : root,
|
|
@@ -10417,7 +10419,7 @@ let applyServerOptions = (command)=>{
|
|
|
10417
10419
|
};
|
|
10418
10420
|
function setupCommands(argv) {
|
|
10419
10421
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
10420
|
-
cli.version("2.3.
|
|
10422
|
+
cli.version("2.3.1"), 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)', {
|
|
10421
10423
|
default: 'auto'
|
|
10422
10424
|
}).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', {
|
|
10423
10425
|
type: [
|
|
@@ -10482,7 +10484,7 @@ function setupCommands(argv) {
|
|
|
10482
10484
|
}
|
|
10483
10485
|
function showGreeting() {
|
|
10484
10486
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
10485
|
-
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.3.
|
|
10487
|
+
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.3.1\n`);
|
|
10486
10488
|
}
|
|
10487
10489
|
function setupLogLevel(argv) {
|
|
10488
10490
|
if (argv.length <= 3) return;
|
|
@@ -10504,5 +10506,5 @@ function runCLI({ argv = process.argv } = {}) {
|
|
|
10504
10506
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
|
|
10505
10507
|
}
|
|
10506
10508
|
}
|
|
10507
|
-
let src_version = "2.3.
|
|
10509
|
+
let src_version = "2.3.1";
|
|
10508
10510
|
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 };
|