@rsbuild/core 2.3.0-rc.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/helpers/stats.d.ts +1 -0
- package/dist/http-proxy-middleware.js +1 -1
- package/dist/m.js +876 -854
- 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/server/socketServer.d.ts +1 -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);
|
|
@@ -2214,6 +2214,20 @@ function getRsbuildStats(statsInstance, compiler, logger, action) {
|
|
|
2214
2214
|
let statsOptions = getStatsOptions(compiler, logger, action);
|
|
2215
2215
|
return statsInstance.toJson(statsOptions);
|
|
2216
2216
|
}
|
|
2217
|
+
function getEarlyStats(stats) {
|
|
2218
|
+
let entrypoints = Object.create(null);
|
|
2219
|
+
for (let [name, entrypoint] of stats.compilation.entrypoints){
|
|
2220
|
+
let chunks = [];
|
|
2221
|
+
for (let { id } of entrypoint.chunks)null != id && chunks.push(id);
|
|
2222
|
+
entrypoints[name] = {
|
|
2223
|
+
chunks
|
|
2224
|
+
};
|
|
2225
|
+
}
|
|
2226
|
+
return {
|
|
2227
|
+
hash: stats.hash ?? void 0,
|
|
2228
|
+
entrypoints
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2217
2231
|
function formatStats(stats, hasErrors, root, logger) {
|
|
2218
2232
|
if (hasErrors) return {
|
|
2219
2233
|
message: formatErrorMessage(getStatsErrors(stats).map((item)=>formatStatsError(item, root, 'error', logger))),
|
|
@@ -2594,14 +2608,22 @@ let OVERRIDE_PATHS = new Set([
|
|
|
2594
2608
|
y
|
|
2595
2609
|
];
|
|
2596
2610
|
if (!isPlainObject(x) || !isPlainObject(y)) return y;
|
|
2597
|
-
let merged = {};
|
|
2598
|
-
for (let key of
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
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){
|
|
2613
|
+
let childPath = path ? `${path}.${key}` : key;
|
|
2614
|
+
merged[key] = merge(x[key], y[key], childPath);
|
|
2615
|
+
}
|
|
2616
|
+
for (let key of yKeys)if (!(xKeySet ? xKeySet.has(key) : xKeys.includes(key))) {
|
|
2602
2617
|
let childPath = path ? `${path}.${key}` : key;
|
|
2603
2618
|
merged[key] = merge(x[key], y[key], childPath);
|
|
2604
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
|
+
}
|
|
2605
2627
|
return merged;
|
|
2606
2628
|
}, normalizeConfigStructure = (config)=>{
|
|
2607
2629
|
let { dev, output } = config, normalizedConfig = {
|
|
@@ -2774,17 +2796,7 @@ function getDefaultEntry(root) {
|
|
|
2774
2796
|
index: entryFile
|
|
2775
2797
|
} : {};
|
|
2776
2798
|
}
|
|
2777
|
-
let
|
|
2778
|
-
let config = mergeRsbuildConfig(createDefaultConfig(), userConfig);
|
|
2779
|
-
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 = {
|
|
2780
|
-
imports: !0,
|
|
2781
|
-
entries: !1
|
|
2782
|
-
}), !config.source.tsconfigPath) {
|
|
2783
|
-
let tsconfigPath = join(rootPath, TS_CONFIG_FILE);
|
|
2784
|
-
await isFileExists(tsconfigPath) && (config.source.tsconfigPath = tsconfigPath);
|
|
2785
|
-
}
|
|
2786
|
-
return config;
|
|
2787
|
-
}, normalizePublicDirs = (rootPath, publicDir)=>{
|
|
2799
|
+
let normalizePublicDirs = (rootPath, publicDir)=>{
|
|
2788
2800
|
if (!1 === publicDir) return [];
|
|
2789
2801
|
let defaultConfig = {
|
|
2790
2802
|
name: join(rootPath, 'public'),
|
|
@@ -3234,9 +3246,19 @@ function createPublicContext(context) {
|
|
|
3234
3246
|
});
|
|
3235
3247
|
}
|
|
3236
3248
|
async function createContext(options, userConfig, logger, loadConfigResult) {
|
|
3237
|
-
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();
|
|
3238
3260
|
return {
|
|
3239
|
-
version: "2.3.
|
|
3261
|
+
version: "2.3.1",
|
|
3240
3262
|
rootPath,
|
|
3241
3263
|
configFile: loadConfigResult?.filePath ?? userConfig._privateMeta?.configFilePath,
|
|
3242
3264
|
configFileDependencies: loadConfigResult?.dependencies ?? userConfig._privateMeta?.configFileDependencies ?? [],
|
|
@@ -3914,7 +3936,7 @@ async function createCompiler_createCompiler(options) {
|
|
|
3914
3936
|
}), compiler.hooks.watchRun.tap(HOOK_NAME, (compiler)=>{
|
|
3915
3937
|
startTime = Date.now(), context.buildState.status = 'building', logRspackVersion(), isCompiling || printBuildLog(compiler, context, lazyModules), lazyModules.size && lazyModules.clear(), isCompiling = !0;
|
|
3916
3938
|
}), compiler.hooks.invalid.tap(HOOK_NAME, ()=>{
|
|
3917
|
-
hasFatalError = !1, context.buildState.stats = null, context.buildState.status = 'idle', context.buildState.hasErrors = !1
|
|
3939
|
+
hasFatalError = !1, context.buildState.stats = null, context.buildState.status = 'idle', context.buildState.hasErrors = !1;
|
|
3918
3940
|
}), compilers))item.hooks.failed.tap(HOOK_NAME, ()=>{
|
|
3919
3941
|
hasFatalError = !0, context.buildState.hasErrors = !0, finishFatalBuild();
|
|
3920
3942
|
}), item.hooks.afterDone.tap(HOOK_NAME, finishFatalBuild), item.hooks.watchClose.tap(HOOK_NAME, finishFatalBuild);
|
|
@@ -3958,28 +3980,7 @@ async function createCompiler_createCompiler(options) {
|
|
|
3958
3980
|
let { message, level } = formatStats(stats, hasErrors, options.context.rootPath, logger);
|
|
3959
3981
|
'error' === level && logger.error(message), 'warning' === level && logger.warn(message), isMultiCompiler || printTime(0, hasErrors), isCompiling = !1;
|
|
3960
3982
|
}), 'dev' === context.action && (({ context, compiler, bundlerConfigs, MultiStatsCtor })=>{
|
|
3961
|
-
let isFirstCompile = !0, { environmentList } = context
|
|
3962
|
-
let promise = context.hooks.onAfterDevCompile.callBatch({
|
|
3963
|
-
isFirstCompile,
|
|
3964
|
-
stats,
|
|
3965
|
-
environments: context.environments
|
|
3966
|
-
});
|
|
3967
|
-
isFirstCompile = !1, await promise;
|
|
3968
|
-
}, onEnvironmentDone = async (index, stats)=>{
|
|
3969
|
-
let environment = environmentList[index], time = context.buildState.time[environment.name] ?? 0;
|
|
3970
|
-
await context.hooks.onAfterEnvironmentCompile.callBatch({
|
|
3971
|
-
environment: environment.name,
|
|
3972
|
-
args: [
|
|
3973
|
-
{
|
|
3974
|
-
isFirstCompile,
|
|
3975
|
-
stats,
|
|
3976
|
-
environment,
|
|
3977
|
-
isWatch: !0,
|
|
3978
|
-
time
|
|
3979
|
-
}
|
|
3980
|
-
]
|
|
3981
|
-
});
|
|
3982
|
-
};
|
|
3983
|
+
let isFirstCompile = !0, { environmentList } = context;
|
|
3983
3984
|
onBeforeCompile({
|
|
3984
3985
|
compiler,
|
|
3985
3986
|
beforeEnvironmentCompile: async (buildIndex)=>{
|
|
@@ -4005,8 +4006,29 @@ async function createCompiler_createCompiler(options) {
|
|
|
4005
4006
|
isWatch: !0
|
|
4006
4007
|
}), onCompileDone({
|
|
4007
4008
|
compiler,
|
|
4008
|
-
onDone
|
|
4009
|
-
|
|
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
|
+
},
|
|
4010
4032
|
MultiStatsCtor
|
|
4011
4033
|
});
|
|
4012
4034
|
})({
|
|
@@ -4113,32 +4135,32 @@ function printServerURLs({ urls: originalUrls, port, routes, protocol, printUrls
|
|
|
4113
4135
|
});
|
|
4114
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;
|
|
4115
4137
|
}
|
|
4116
|
-
let
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
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
|
+
});
|
|
4131
4155
|
});
|
|
4132
|
-
})
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
}, resolvePort = async (config, lastPort)=>{
|
|
4141
|
-
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
|
+
})({
|
|
4142
4164
|
host,
|
|
4143
4165
|
port: preferredPort ?? originalPort,
|
|
4144
4166
|
strictPort: void 0 === preferredPort && strictPort
|
|
@@ -4366,100 +4388,7 @@ function watchFilesForRestart({ watchFiles, context, restartContext }) {
|
|
|
4366
4388
|
close
|
|
4367
4389
|
};
|
|
4368
4390
|
}
|
|
4369
|
-
let RSPACK_BUILD_ERROR = 'Rspack build failed.',
|
|
4370
|
-
let stats, closeCompiler, closingPromise, unregisterRestart, restartWatcher, { watch } = buildOptions, { context } = initOptions, { logger } = context, { compiler, rspackConfigs } = await createCompiler_createCompiler(initOptions);
|
|
4371
|
-
if ((({ context, isWatch, compiler, rspackConfigs, MultiStatsCtor })=>{
|
|
4372
|
-
let isFirstCompile = !0, { environmentList } = context, onDone = async (stats)=>{
|
|
4373
|
-
let shouldLogWatching = isWatch && isFirstCompile, promise = context.hooks.onAfterBuild.callBatch({
|
|
4374
|
-
isFirstCompile,
|
|
4375
|
-
stats,
|
|
4376
|
-
environments: context.environments,
|
|
4377
|
-
isWatch
|
|
4378
|
-
});
|
|
4379
|
-
isFirstCompile = !1, await promise, shouldLogWatching && context.logger.info('watching for changes...');
|
|
4380
|
-
}, onEnvironmentDone = async (index, stats)=>{
|
|
4381
|
-
let environment = environmentList[index], time = context.buildState.time[environment.name] ?? 0;
|
|
4382
|
-
await context.hooks.onAfterEnvironmentCompile.callBatch({
|
|
4383
|
-
environment: environment.name,
|
|
4384
|
-
args: [
|
|
4385
|
-
{
|
|
4386
|
-
isFirstCompile,
|
|
4387
|
-
stats,
|
|
4388
|
-
environment,
|
|
4389
|
-
isWatch,
|
|
4390
|
-
time
|
|
4391
|
-
}
|
|
4392
|
-
]
|
|
4393
|
-
});
|
|
4394
|
-
};
|
|
4395
|
-
onBeforeCompile({
|
|
4396
|
-
compiler,
|
|
4397
|
-
beforeCompile: async ()=>context.hooks.onBeforeBuild.callBatch({
|
|
4398
|
-
bundlerConfigs: rspackConfigs,
|
|
4399
|
-
environments: context.environments,
|
|
4400
|
-
isWatch,
|
|
4401
|
-
isFirstCompile
|
|
4402
|
-
}),
|
|
4403
|
-
beforeEnvironmentCompile: async (buildIndex)=>{
|
|
4404
|
-
let environment = environmentList[buildIndex];
|
|
4405
|
-
return context.hooks.onBeforeEnvironmentCompile.callBatch({
|
|
4406
|
-
environment: environment.name,
|
|
4407
|
-
args: [
|
|
4408
|
-
{
|
|
4409
|
-
bundlerConfig: rspackConfigs[buildIndex],
|
|
4410
|
-
environment,
|
|
4411
|
-
isWatch,
|
|
4412
|
-
isFirstCompile
|
|
4413
|
-
}
|
|
4414
|
-
]
|
|
4415
|
-
});
|
|
4416
|
-
},
|
|
4417
|
-
isWatch
|
|
4418
|
-
}), onCompileDone({
|
|
4419
|
-
compiler,
|
|
4420
|
-
onDone,
|
|
4421
|
-
onEnvironmentDone,
|
|
4422
|
-
MultiStatsCtor
|
|
4423
|
-
});
|
|
4424
|
-
})({
|
|
4425
|
-
context,
|
|
4426
|
-
rspackConfigs,
|
|
4427
|
-
compiler,
|
|
4428
|
-
isWatch: !!watch,
|
|
4429
|
-
MultiStatsCtor: core_rspack.MultiStats
|
|
4430
|
-
}), watch) {
|
|
4431
|
-
let watchOptions = rspackConfigs.map((options)=>options.watchOptions || {});
|
|
4432
|
-
compiler.watch(watchOptions.length > 1 ? watchOptions : watchOptions[0] || {}, (err)=>{
|
|
4433
|
-
err && logger.error(err);
|
|
4434
|
-
}), closeCompiler = ()=>new Promise((resolve)=>{
|
|
4435
|
-
compiler.close(()=>{
|
|
4436
|
-
resolve();
|
|
4437
|
-
});
|
|
4438
|
-
});
|
|
4439
|
-
} else stats = await new Promise((resolve, reject)=>{
|
|
4440
|
-
compiler.run((err, stats)=>{
|
|
4441
|
-
compiler.close((closeErr)=>{
|
|
4442
|
-
closeErr && logger.error('Failed to close compiler: ', closeErr), err ? reject(err) : context.buildState.hasErrors ? reject(Error(RSPACK_BUILD_ERROR)) : resolve(stats);
|
|
4443
|
-
});
|
|
4444
|
-
});
|
|
4445
|
-
});
|
|
4446
|
-
let closeBuild = ()=>closingPromise ||= (async ()=>{
|
|
4447
|
-
unregisterRestart?.(), unregisterRestart = void 0, await context.hooks.onCloseBuild.callBatch(), await closeCompiler?.();
|
|
4448
|
-
})();
|
|
4449
|
-
return watch && (unregisterRestart = context.restartManager.registerCleanup(closeBuild), restartWatcher = watchFilesForRestart({
|
|
4450
|
-
watchFiles: context.normalizedConfig.dev.watchFiles,
|
|
4451
|
-
context,
|
|
4452
|
-
restartContext: {
|
|
4453
|
-
action: 'build',
|
|
4454
|
-
options: buildOptions
|
|
4455
|
-
}
|
|
4456
|
-
})), {
|
|
4457
|
-
stats,
|
|
4458
|
-
close: async ()=>{
|
|
4459
|
-
await restartWatcher?.close(), await closeBuild();
|
|
4460
|
-
}
|
|
4461
|
-
};
|
|
4462
|
-
}, 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;
|
|
4463
4392
|
function loadEnv_parse(src) {
|
|
4464
4393
|
let match, obj = {}, lines = src.toString();
|
|
4465
4394
|
for(lines = lines.replace(/\r\n?/gm, '\n'); null != (match = DOTENV_LINE.exec(lines));){
|
|
@@ -5089,7 +5018,7 @@ function parseMinifyOptions(config) {
|
|
|
5089
5018
|
cssOptions: minify.cssOptions
|
|
5090
5019
|
};
|
|
5091
5020
|
}
|
|
5092
|
-
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"));
|
|
5093
5022
|
async function getLightningCSSLoaderOptions(config, targets, minify) {
|
|
5094
5023
|
let userOptions = 'object' == typeof config.tools.lightningcssLoader ? config.tools.lightningcssLoader : {}, initialOptions = {
|
|
5095
5024
|
targets,
|
|
@@ -5120,75 +5049,6 @@ async function loadUserPostcssrc(root, postcssrcCache) {
|
|
|
5120
5049
|
});
|
|
5121
5050
|
return postcssrcCache.set(root, promise), promise.then((config)=>(postcssrcCache.set(root, config), clonePostCSSConfig(config)));
|
|
5122
5051
|
}
|
|
5123
|
-
let getPostcssLoaderOptions = async ({ config, root, postcssrcCache })=>{
|
|
5124
|
-
let extraPlugins = [], userOptions = await loadUserPostcssrc(root, postcssrcCache);
|
|
5125
|
-
userOptions.plugins ||= [];
|
|
5126
|
-
let defaultOptions = {
|
|
5127
|
-
implementation: getCompiledPath('postcss'),
|
|
5128
|
-
postcssOptions: userOptions,
|
|
5129
|
-
sourceMap: getCSSSourceMap(config)
|
|
5130
|
-
}, finalOptions = await reduceConfigsWithContext({
|
|
5131
|
-
initial: defaultOptions,
|
|
5132
|
-
config: config.tools.postcss,
|
|
5133
|
-
ctx: {
|
|
5134
|
-
addPlugins (plugins, options = {}) {
|
|
5135
|
-
let { order = 'post' } = options, list = helpers_castArray(plugins);
|
|
5136
|
-
'pre' === order ? extraPlugins.unshift(...list) : extraPlugins.push(...list);
|
|
5137
|
-
}
|
|
5138
|
-
}
|
|
5139
|
-
});
|
|
5140
|
-
finalOptions.postcssOptions ||= {};
|
|
5141
|
-
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;
|
|
5142
|
-
if ('function' == typeof postcssOptions) {
|
|
5143
|
-
let postcssOptionsWrapper = (loaderContext)=>{
|
|
5144
|
-
let options = postcssOptions(loaderContext);
|
|
5145
|
-
if ('object' != typeof options || null === options) throw Error(`${color.dim('[rsbuild:css]')} \`postcssOptions\` function must return a PostCSSOptions object, got ${color.yellow(typeof options)}.`);
|
|
5146
|
-
return updatePostcssOptions({
|
|
5147
|
-
...userOptions,
|
|
5148
|
-
...options,
|
|
5149
|
-
plugins: [
|
|
5150
|
-
...userOptions.plugins || [],
|
|
5151
|
-
...options.plugins || []
|
|
5152
|
-
]
|
|
5153
|
-
});
|
|
5154
|
-
};
|
|
5155
|
-
return postcssOptionsWrapper.config = !1, {
|
|
5156
|
-
...finalOptions,
|
|
5157
|
-
postcssOptions: postcssOptionsWrapper
|
|
5158
|
-
};
|
|
5159
|
-
}
|
|
5160
|
-
return finalOptions.postcssOptions = updatePostcssOptions(postcssOptions), finalOptions;
|
|
5161
|
-
}, getCSSLoaderOptions = async ({ config, localIdentName, emitCss })=>{
|
|
5162
|
-
let { cssModules } = config.output, defaultOptions = {
|
|
5163
|
-
modules: {
|
|
5164
|
-
...cssModules,
|
|
5165
|
-
localIdentName
|
|
5166
|
-
},
|
|
5167
|
-
sourceMap: getCSSSourceMap(config)
|
|
5168
|
-
};
|
|
5169
|
-
return ((options, exportOnlyLocals)=>{
|
|
5170
|
-
if (options.modules && exportOnlyLocals) {
|
|
5171
|
-
let { modules } = options;
|
|
5172
|
-
return modules = !0 === modules ? {
|
|
5173
|
-
exportOnlyLocals: !0
|
|
5174
|
-
} : 'string' == typeof modules ? {
|
|
5175
|
-
mode: modules,
|
|
5176
|
-
exportOnlyLocals: !0
|
|
5177
|
-
} : {
|
|
5178
|
-
...modules,
|
|
5179
|
-
exportOnlyLocals: !0
|
|
5180
|
-
}, {
|
|
5181
|
-
...options,
|
|
5182
|
-
modules
|
|
5183
|
-
};
|
|
5184
|
-
}
|
|
5185
|
-
return options;
|
|
5186
|
-
})(await reduceConfigs({
|
|
5187
|
-
initial: defaultOptions,
|
|
5188
|
-
config: config.tools.cssLoader,
|
|
5189
|
-
mergeFn: cjs_0_default()
|
|
5190
|
-
}), !emitCss);
|
|
5191
|
-
};
|
|
5192
5052
|
function checkProcessEnvSecurity(define, logger) {
|
|
5193
5053
|
let value = define['process.env'];
|
|
5194
5054
|
if (!value) return;
|
|
@@ -5201,13 +5061,7 @@ function checkProcessEnvSecurity(define, logger) {
|
|
|
5201
5061
|
check(JSON.parse(value));
|
|
5202
5062
|
} catch {}
|
|
5203
5063
|
}
|
|
5204
|
-
let
|
|
5205
|
-
if (await isFileExists(pkgJsonPath)) try {
|
|
5206
|
-
return JSON.parse(await readFile(pkgJsonPath, 'utf8'));
|
|
5207
|
-
} catch {
|
|
5208
|
-
return;
|
|
5209
|
-
}
|
|
5210
|
-
}, dependencyTypes = [
|
|
5064
|
+
let dependencyTypes = [
|
|
5211
5065
|
'dependencies',
|
|
5212
5066
|
'peerDependencies',
|
|
5213
5067
|
'devDependencies',
|
|
@@ -5224,18 +5078,6 @@ let readPackageJsonByPath = async (pkgJsonPath)=>{
|
|
|
5224
5078
|
...!0 === autoExternal ? {} : autoExternal
|
|
5225
5079
|
};
|
|
5226
5080
|
return dependencyTypes.some((type)=>externalOptions[type]) ? externalOptions : void 0;
|
|
5227
|
-
}, readPackageJsonList = async (paths, cache)=>{
|
|
5228
|
-
var packageJsonList = (await Promise.all(paths.map(async (path)=>(cache.has(path) || cache.set(path, await readPackageJsonByPath(path)), cache.get(path))))).filter((pkgJson)=>!!pkgJson);
|
|
5229
|
-
return packageJsonList.length ? dependencyTypes.reduce((merged, type)=>{
|
|
5230
|
-
for (let pkgJson of packageJsonList){
|
|
5231
|
-
let deps = pkgJson[type];
|
|
5232
|
-
isPlainObject(deps) && (merged[type] = {
|
|
5233
|
-
...merged[type],
|
|
5234
|
-
...deps
|
|
5235
|
-
});
|
|
5236
|
-
}
|
|
5237
|
-
return merged;
|
|
5238
|
-
}, {}) : void 0;
|
|
5239
5081
|
};
|
|
5240
5082
|
function pluginExternals() {
|
|
5241
5083
|
return {
|
|
@@ -5246,7 +5088,25 @@ function pluginExternals() {
|
|
|
5246
5088
|
let pkgJson, { autoExternal, externals } = environment.config.output, externalOptions = resolveAutoExternalOptions(autoExternal);
|
|
5247
5089
|
if (externalOptions) {
|
|
5248
5090
|
let rootPath, packageJsonPaths = (rootPath = api.context.rootPath, helpers_castArray(externalOptions.packageJson ?? 'package.json').map((path)=>external_node_path_resolve(rootPath, path)));
|
|
5249
|
-
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);
|
|
5250
5110
|
}
|
|
5251
5111
|
!externalOptions || pkgJson || hasWarnedReadPackageJsonFailed || (api.logger.warn('The `output.autoExternal` configuration will not be applied because reading package.json failed.'), hasWarnedReadPackageJsonFailed = !0);
|
|
5252
5112
|
let autoExternalRules = ((options)=>{
|
|
@@ -5282,7 +5142,10 @@ function getAssetNames(compilation) {
|
|
|
5282
5142
|
function createAssetProcessor() {
|
|
5283
5143
|
let failure, active = 0, waiting = [];
|
|
5284
5144
|
return async (names, processAsset)=>{
|
|
5285
|
-
let cursor = 0
|
|
5145
|
+
let cursor = 0;
|
|
5146
|
+
if (await Promise.all(Array.from({
|
|
5147
|
+
length: Math.min(16, names.length)
|
|
5148
|
+
}, async ()=>{
|
|
5286
5149
|
for(; cursor < names.length && !failure;){
|
|
5287
5150
|
let index = cursor++;
|
|
5288
5151
|
active >= 16 ? await new Promise((resolve)=>waiting.push(resolve)) : active++;
|
|
@@ -5298,10 +5161,7 @@ function createAssetProcessor() {
|
|
|
5298
5161
|
next ? next() : active--;
|
|
5299
5162
|
}
|
|
5300
5163
|
}
|
|
5301
|
-
};
|
|
5302
|
-
if (await Promise.all(Array.from({
|
|
5303
|
-
length: Math.min(16, names.length)
|
|
5304
|
-
}, consume)), failure) throw failure.error;
|
|
5164
|
+
})), failure) throw failure.error;
|
|
5305
5165
|
};
|
|
5306
5166
|
}
|
|
5307
5167
|
function getCompression(compressed) {
|
|
@@ -5625,42 +5485,7 @@ class RsbuildHtmlPlugin {
|
|
|
5625
5485
|
this.name = 'RsbuildHtmlPlugin', this.getExtraData = getExtraData, this.getHTMLPlugin = getHTMLPlugin;
|
|
5626
5486
|
}
|
|
5627
5487
|
apply(compiler) {
|
|
5628
|
-
let
|
|
5629
|
-
let fileContent, name = node_path.basename(favicon), outputFilename = node_path.posix.join(faviconDistPath, name);
|
|
5630
|
-
if (outputFilename in compilation.assets) return outputFilename;
|
|
5631
|
-
let inputFs = compilation.inputFileSystem;
|
|
5632
|
-
if (!inputFs) return addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file as ${color.yellow('compilation.inputFileSystem')} is not available.`), null;
|
|
5633
|
-
let inputFilename = node_path.isAbsolute(favicon) ? favicon : node_path.join(compilation.compiler.context, favicon);
|
|
5634
|
-
try {
|
|
5635
|
-
fileContent = await readFileAsync(inputFs, inputFilename);
|
|
5636
|
-
} catch (error) {
|
|
5637
|
-
return logger.debug('read favicon error:', error), addCompilationError(compilation, `${color.dim('[rsbuild:html]')} Failed to read the favicon file at ${color.yellow(inputFilename)}.`), null;
|
|
5638
|
-
}
|
|
5639
|
-
let source = new core_rspack.sources.RawSource(fileContent, !1);
|
|
5640
|
-
return compilation.emitAsset(outputFilename, source), outputFilename;
|
|
5641
|
-
}, addFavicon = async ({ headTags, favicon, faviconDistPath, compilation, publicPath, logger })=>{
|
|
5642
|
-
let href = favicon;
|
|
5643
|
-
if (!isURL(favicon)) {
|
|
5644
|
-
let name = await emitFavicon({
|
|
5645
|
-
compilation,
|
|
5646
|
-
favicon,
|
|
5647
|
-
faviconDistPath,
|
|
5648
|
-
logger
|
|
5649
|
-
});
|
|
5650
|
-
if (null === name) return;
|
|
5651
|
-
href = ensureAssetPrefix(name, publicPath);
|
|
5652
|
-
}
|
|
5653
|
-
let tag = {
|
|
5654
|
-
tagName: 'link',
|
|
5655
|
-
voidTag: !0,
|
|
5656
|
-
attributes: {
|
|
5657
|
-
rel: 'icon',
|
|
5658
|
-
href
|
|
5659
|
-
},
|
|
5660
|
-
meta: {}
|
|
5661
|
-
};
|
|
5662
|
-
href.endsWith('.svg') && (tag.attributes.type = 'image/svg+xml'), headTags.unshift(tag);
|
|
5663
|
-
}, getExtraDataByPlugin = (plugin)=>{
|
|
5488
|
+
let getExtraDataByPlugin = (plugin)=>{
|
|
5664
5489
|
if (!plugin.options) return;
|
|
5665
5490
|
let entryName = plugin.options[entryNameSymbol];
|
|
5666
5491
|
if (entryName) return this.getExtraData(entryName);
|
|
@@ -5679,7 +5504,42 @@ class RsbuildHtmlPlugin {
|
|
|
5679
5504
|
voidTag: !1,
|
|
5680
5505
|
meta: {}
|
|
5681
5506
|
});
|
|
5682
|
-
})(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
|
+
})({
|
|
5683
5543
|
headTags,
|
|
5684
5544
|
favicon,
|
|
5685
5545
|
faviconDistPath,
|
|
@@ -5908,14 +5768,14 @@ let supportedChromiumBrowsers = [
|
|
|
5908
5768
|
async function openBrowser(url, logger) {
|
|
5909
5769
|
let browser = process.env.BROWSER, browserArgs = process.env.BROWSER_ARGS;
|
|
5910
5770
|
if ('darwin' === process.platform && (!browser || !browserArgs) && (!browser || supportedChromiumBrowsers.includes(mapChromiumBrowserName(browser)))) {
|
|
5911
|
-
let { execFile } = await import("node:child_process"), execFileAsync = promisify(execFile)
|
|
5912
|
-
let { stdout: ps } = await execFileAsync('ps', [
|
|
5913
|
-
'cax'
|
|
5914
|
-
]);
|
|
5915
|
-
return supportedChromiumBrowsers.find((b)=>ps.includes(b));
|
|
5916
|
-
};
|
|
5771
|
+
let { execFile } = await import("node:child_process"), execFileAsync = promisify(execFile);
|
|
5917
5772
|
try {
|
|
5918
|
-
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
|
+
})();
|
|
5919
5779
|
if (chromiumBrowser) return await execFileAsync("osascript", [
|
|
5920
5780
|
"openChrome.applescript",
|
|
5921
5781
|
encodeURI(url),
|
|
@@ -6004,7 +5864,7 @@ function doesChunkBelongToHtml({ chunk, htmlPluginData }) {
|
|
|
6004
5864
|
let { options } = htmlPluginData.plugin;
|
|
6005
5865
|
return recursiveChunkEntryNames(chunk).some((chunkName)=>isChunksFiltered(chunkName, options?.chunks, options?.excludeChunks));
|
|
6006
5866
|
}
|
|
6007
|
-
let getManifestPlugin = cachedImport_cachedImport(()=>import("./manifest-plugin.js").then(rspackRequire.bind(rspackRequire, "../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/rspack-manifest-plugin/5.2.2/
|
|
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');
|
|
6008
5868
|
function normalizeManifestObjectConfig(manifest) {
|
|
6009
5869
|
let defaultOptions = {
|
|
6010
5870
|
prefix: !0,
|
|
@@ -6725,12 +6585,7 @@ function destroyStream(stream, suppress) {
|
|
|
6725
6585
|
'number' == typeof fd && this.close();
|
|
6726
6586
|
}), 'function' == typeof stream.addListener && suppress && (stream.removeAllListeners('error'), stream.addListener('error', ()=>{}));
|
|
6727
6587
|
}
|
|
6728
|
-
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)))
|
|
6729
|
-
let { default: rangeParser } = await getRangeParser(), [len, rangeHeader] = value.split('|');
|
|
6730
|
-
return rangeParser(Number(len), rangeHeader, {
|
|
6731
|
-
combine: !0
|
|
6732
|
-
});
|
|
6733
|
-
};
|
|
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)));
|
|
6734
6589
|
function sendError(res, code) {
|
|
6735
6590
|
let content = {
|
|
6736
6591
|
400: 'Bad Request',
|
|
@@ -6801,7 +6656,12 @@ function createAssetsMiddleware(context, { waitForAssets, waitForBuild }, output
|
|
|
6801
6656
|
}
|
|
6802
6657
|
}
|
|
6803
6658
|
if (rangeHeader) {
|
|
6804
|
-
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}`);
|
|
6805
6665
|
if (isRangeFresh(req.headers, res) || (parsedRanges = []), -1 === parsedRanges) {
|
|
6806
6666
|
logger.error("[rsbuild:middleware] Unsatisfiable range for 'Range' header."), res.setHeader('Content-Range', getValueContentRangeHeader('bytes', size)), sendError(res, 416);
|
|
6807
6667
|
return;
|
|
@@ -6901,10 +6761,7 @@ let noop = ()=>{}, normalizeLiveReload = (liveReload)=>'boolean' == typeof liveR
|
|
|
6901
6761
|
} : {
|
|
6902
6762
|
enabled: !0,
|
|
6903
6763
|
html: !1 !== liveReload.html
|
|
6904
|
-
},
|
|
6905
|
-
let { target } = compiler.options;
|
|
6906
|
-
return !!target && (Array.isArray(target) ? target.includes('node') : 'node' === target);
|
|
6907
|
-
}, isTsError = (error)=>'message' in error && error.stack?.includes('ts-checker-rspack-plugin');
|
|
6764
|
+
}, isTsError = (error)=>'message' in error && error.stack?.includes('ts-checker-rspack-plugin');
|
|
6908
6765
|
function applyHMREntry({ config, compiler, token, resolvedHost, resolvedPort }) {
|
|
6909
6766
|
var overlay;
|
|
6910
6767
|
let overlay1;
|
|
@@ -6934,109 +6791,6 @@ init(
|
|
|
6934
6791
|
name: void 0
|
|
6935
6792
|
}).apply(compiler);
|
|
6936
6793
|
}
|
|
6937
|
-
let assets_middleware_assetsMiddleware = async ({ config, compiler, context, socketServer, resolvedPort })=>{
|
|
6938
|
-
let watching, allCompilers, webCompilers, earlyWebUpdates, { logger } = context, resolvedHost = await resolveHostname(config.server.host), { environmentList } = context, { allCompilers: allCompilers1, webCompilers: webCompilers1, earlyWebUpdates: earlyWebUpdates1 } = (earlyWebUpdates = (webCompilers = (allCompilers = compiler_isMultiCompiler(compiler) ? compiler.compilers : [
|
|
6939
|
-
compiler
|
|
6940
|
-
]).filter((compiler)=>!isNodeCompiler(compiler))).length > 0 && webCompilers.length < allCompilers.length, {
|
|
6941
|
-
allCompilers,
|
|
6942
|
-
webCompilers,
|
|
6943
|
-
earlyWebUpdates
|
|
6944
|
-
});
|
|
6945
|
-
applyToCompiler(compiler, (compiler, index)=>{
|
|
6946
|
-
let environment = environmentList[index];
|
|
6947
|
-
if (!environment) return;
|
|
6948
|
-
let token = environment.webSocketToken;
|
|
6949
|
-
token && (applyHMREntry({
|
|
6950
|
-
token,
|
|
6951
|
-
config: environment.config,
|
|
6952
|
-
compiler,
|
|
6953
|
-
resolvedHost,
|
|
6954
|
-
resolvedPort
|
|
6955
|
-
}), (({ context, compiler, token, socketServer, liveReload, earlyWebUpdates })=>{
|
|
6956
|
-
if (isNodeCompiler(compiler)) return;
|
|
6957
|
-
let errorsCount = null, warningsCount = null;
|
|
6958
|
-
compiler.hooks.invalid.tap('rsbuild-dev-server', (fileName)=>{
|
|
6959
|
-
errorsCount = null, warningsCount = null, 'string' == typeof fileName && fileName.endsWith('.html') && normalizeLiveReload(liveReload).html && socketServer.sendMessage({
|
|
6960
|
-
type: 'full-reload'
|
|
6961
|
-
}, token);
|
|
6962
|
-
}), compiler.hooks.done.tap('rsbuild-dev-server', (stats)=>{
|
|
6963
|
-
let { errors, warnings } = stats.compilation;
|
|
6964
|
-
if (errors.length === errorsCount && warnings.length === warningsCount) return;
|
|
6965
|
-
null === errorsCount && null === warningsCount && earlyWebUpdates && !stats.hasErrors() && socketServer.onEnvironmentDone(token, ()=>getRsbuildStats(stats, compiler, context.logger, context.action));
|
|
6966
|
-
let isRecalled = null !== errorsCount || null !== warningsCount;
|
|
6967
|
-
if (errorsCount = errors.length, warningsCount = warnings.length, isRecalled) {
|
|
6968
|
-
let tsErrors = errors.filter(isTsError), tsWarnings = warnings.filter(isTsError);
|
|
6969
|
-
if (!tsErrors.length && !tsWarnings.length) return;
|
|
6970
|
-
let { stats: statsJson } = context.buildState, handleTsIssues = (issues, type, sendFn)=>{
|
|
6971
|
-
let statsIssues = issues.map((item)=>pick(item, [
|
|
6972
|
-
'message',
|
|
6973
|
-
'file'
|
|
6974
|
-
]));
|
|
6975
|
-
statsJson && (statsJson[type] = statsJson[type] ? [
|
|
6976
|
-
...statsJson[type],
|
|
6977
|
-
...statsIssues
|
|
6978
|
-
] : statsIssues), sendFn(statsIssues, token);
|
|
6979
|
-
};
|
|
6980
|
-
if (tsErrors.length > 0) return void handleTsIssues(tsErrors, 'errors', (issues, token)=>{
|
|
6981
|
-
socketServer.sendError(issues, token);
|
|
6982
|
-
});
|
|
6983
|
-
if (tsWarnings.length > 0) return void handleTsIssues(tsWarnings, 'warnings', (issues, token)=>{
|
|
6984
|
-
socketServer.sendWarning(issues, token);
|
|
6985
|
-
});
|
|
6986
|
-
}
|
|
6987
|
-
});
|
|
6988
|
-
})({
|
|
6989
|
-
context,
|
|
6990
|
-
compiler,
|
|
6991
|
-
socketServer,
|
|
6992
|
-
token,
|
|
6993
|
-
liveReload: environment.config.dev.liveReload,
|
|
6994
|
-
earlyWebUpdates: earlyWebUpdates1
|
|
6995
|
-
}));
|
|
6996
|
-
});
|
|
6997
|
-
let assetCallbacks = [], buildCallbacks = [], flushCallbacks = (callbacks)=>{
|
|
6998
|
-
for (let callback of callbacks.splice(0))callback();
|
|
6999
|
-
}, flushAllCallbacks = ()=>{
|
|
7000
|
-
flushCallbacks(assetCallbacks), flushCallbacks(buildCallbacks);
|
|
7001
|
-
};
|
|
7002
|
-
compiler.hooks.done.tap('rsbuild-dev-middleware', ()=>{
|
|
7003
|
-
process.nextTick(()=>{
|
|
7004
|
-
'done' === context.buildState.status && flushAllCallbacks();
|
|
7005
|
-
});
|
|
7006
|
-
});
|
|
7007
|
-
let compiledWebCompilers = new Set(), isWebReady = ()=>earlyWebUpdates1 && compiledWebCompilers.size === webCompilers1.length;
|
|
7008
|
-
if (earlyWebUpdates1) for (let item of webCompilers1){
|
|
7009
|
-
let reset = ()=>{
|
|
7010
|
-
compiledWebCompilers.delete(item);
|
|
7011
|
-
};
|
|
7012
|
-
item.hooks.invalid.tap('rsbuild-dev-middleware', reset), item.hooks.watchRun.tap('rsbuild-dev-middleware', reset), item.hooks.done.tap('rsbuild-dev-middleware', (stats)=>{
|
|
7013
|
-
!stats.hasErrors() && (compiledWebCompilers.add(item), isWebReady() && process.nextTick(()=>{
|
|
7014
|
-
isWebReady() && flushCallbacks(assetCallbacks);
|
|
7015
|
-
}));
|
|
7016
|
-
});
|
|
7017
|
-
}
|
|
7018
|
-
let writeToDiskList = environmentList.map((environment)=>environment.config.dev.writeToDisk);
|
|
7019
|
-
writeToDiskList.some(Boolean) && setupWriteToDisk(allCompilers1, writeToDiskList, logger);
|
|
7020
|
-
let outputFileSystem = await setupOutputFileSystem(writeToDiskList.every((writeToDisk)=>!0 === writeToDisk), allCompilers1), isBuildReady = ()=>'done' === context.buildState.status || 'failed' === context.buildState.status, instance = createAssetsMiddleware(context, {
|
|
7021
|
-
waitForAssets: (callback)=>{
|
|
7022
|
-
isBuildReady() || isWebReady() ? callback() : assetCallbacks.push(callback);
|
|
7023
|
-
},
|
|
7024
|
-
waitForBuild: (callback)=>{
|
|
7025
|
-
isBuildReady() ? callback() : buildCallbacks.push(callback);
|
|
7026
|
-
}
|
|
7027
|
-
}, outputFileSystem);
|
|
7028
|
-
return instance.watch = ()=>{
|
|
7029
|
-
if (compiler.watching) watching = compiler.watching;
|
|
7030
|
-
else {
|
|
7031
|
-
let watchOptions = allCompilers1.length > 1 ? allCompilers1.map(({ options })=>options.watchOptions || {}) : allCompilers1[0].options.watchOptions || {};
|
|
7032
|
-
watching = compiler.watch(watchOptions, (error)=>{
|
|
7033
|
-
error && (context.buildState.status = 'failed', context.buildState.hasErrors = !0, process.nextTick(flushAllCallbacks), error.message?.includes('× Error:') && (error.message = error.message.replace('× Error:', '').trim()), logger.error(error));
|
|
7034
|
-
});
|
|
7035
|
-
}
|
|
7036
|
-
}, instance.close = (callback = noop)=>{
|
|
7037
|
-
watching?.close(callback);
|
|
7038
|
-
}, instance;
|
|
7039
|
-
};
|
|
7040
6794
|
var UNKNOWN_FUNCTION = '<unknown>';
|
|
7041
6795
|
function stack_trace_parser_esm_parse(stackString) {
|
|
7042
6796
|
return stackString.split('\n').reduce(function(stack, line) {
|
|
@@ -7128,16 +6882,6 @@ let getTraceMapping = cachedImport_cachedImport(()=>import("./trace-mapping.js")
|
|
|
7128
6882
|
} catch (error) {
|
|
7129
6883
|
error instanceof Error && context.logger.debug('failed to map source map position:', error);
|
|
7130
6884
|
}
|
|
7131
|
-
}, resolveOriginalLocation = async (stackFrames, fs, context, cache)=>{
|
|
7132
|
-
let frame = stackFrames.find((frame)=>null !== frame.file && null !== frame.column && null !== frame.lineNumber && SCRIPT_REGEX.test(frame.file));
|
|
7133
|
-
if (!frame) return;
|
|
7134
|
-
let parsedFrame = await parseFrame(frame, fs, context, cache);
|
|
7135
|
-
if (!parsedFrame) return;
|
|
7136
|
-
let { sourceMapPath, originalPosition } = parsedFrame;
|
|
7137
|
-
return {
|
|
7138
|
-
frame,
|
|
7139
|
-
location: formatOriginalLocation(sourceMapPath, originalPosition, context)
|
|
7140
|
-
};
|
|
7141
6885
|
}, formatOriginalLocation = (sourceMapPath, originalMapping, context)=>{
|
|
7142
6886
|
let { source, line, column } = originalMapping;
|
|
7143
6887
|
if (!source) return;
|
|
@@ -7150,39 +6894,23 @@ let getTraceMapping = cachedImport_cachedImport(()=>import("./trace-mapping.js")
|
|
|
7150
6894
|
}, formatFrameLocation = (frame)=>{
|
|
7151
6895
|
let { file, lineNumber, column } = frame;
|
|
7152
6896
|
if (file) return null !== lineNumber ? null !== column ? `${file}:${lineNumber}:${column}` : `${file}:${lineNumber}` : file;
|
|
7153
|
-
}, formatFullStack = async (stackFrames, context, fs, cache)=>{
|
|
7154
|
-
let formattedFrames = [];
|
|
7155
|
-
for (let frame of stackFrames){
|
|
7156
|
-
let location, parsedFrame = await parseFrame(frame, fs, context, cache), { methodName } = frame, parts = [];
|
|
7157
|
-
isValidMethodName(methodName) && parts.push(methodName);
|
|
7158
|
-
let parsed = !1;
|
|
7159
|
-
if (parsedFrame) {
|
|
7160
|
-
let { sourceMapPath, originalPosition } = parsedFrame, originalLocation = formatOriginalLocation(sourceMapPath, originalPosition, context);
|
|
7161
|
-
originalLocation && (location = originalLocation, parts.push(originalLocation), parsed = !0);
|
|
7162
|
-
}
|
|
7163
|
-
if (!parsed && isVerbose(context.logger)) {
|
|
7164
|
-
let frameString = formatFrameLocation(frame);
|
|
7165
|
-
frameString && (location = frameString, parts.push(frameString));
|
|
7166
|
-
}
|
|
7167
|
-
let [first, second] = parts;
|
|
7168
|
-
if (first) {
|
|
7169
|
-
let isRspackRuntime = isRspackRuntimeStack(methodName) || isRspackRuntimeStack(location);
|
|
7170
|
-
formattedFrames.push({
|
|
7171
|
-
text: second ? `\n at ${first} (${second})` : `\n at ${first}`,
|
|
7172
|
-
isRspackRuntime,
|
|
7173
|
-
hasLocation: void 0 !== location
|
|
7174
|
-
});
|
|
7175
|
-
}
|
|
7176
|
-
}
|
|
7177
|
-
let shouldFilterRspackRuntime = formattedFrames.some((frame)=>!frame.isRspackRuntime && frame.hasLocation);
|
|
7178
|
-
return formattedFrames.filter((frame)=>!(shouldFilterRspackRuntime && frame.isRspackRuntime)).map((frame)=>frame.text).join('');
|
|
7179
6897
|
}, formatBrowserErrorLog = async (message, context, fs, stackTrace, stackFrames, cache)=>{
|
|
7180
6898
|
var log;
|
|
7181
6899
|
let log1 = color.red(message);
|
|
7182
6900
|
if (stackFrames?.length) switch(stackTrace){
|
|
7183
6901
|
case 'summary':
|
|
7184
6902
|
{
|
|
7185
|
-
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);
|
|
7186
6914
|
if (!resolved) break;
|
|
7187
6915
|
let { frame, location } = resolved, { methodName } = frame, suffix = '';
|
|
7188
6916
|
isValidMethodName(methodName) && (suffix += ` at ${methodName}`), location && (suffix += ` (${location})`), log1 += suffix ? color.dim(suffix) : '';
|
|
@@ -7190,7 +6918,33 @@ let getTraceMapping = cachedImport_cachedImport(()=>import("./trace-mapping.js")
|
|
|
7190
6918
|
}
|
|
7191
6919
|
case 'full':
|
|
7192
6920
|
{
|
|
7193
|
-
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);
|
|
7194
6948
|
fullStack && (log1 += fullStack);
|
|
7195
6949
|
}
|
|
7196
6950
|
}
|
|
@@ -7314,8 +7068,8 @@ class SocketServer {
|
|
|
7314
7068
|
token
|
|
7315
7069
|
}));
|
|
7316
7070
|
}
|
|
7317
|
-
clearEnvironmentStats() {
|
|
7318
|
-
this.environmentStats.
|
|
7071
|
+
clearEnvironmentStats(token) {
|
|
7072
|
+
this.environmentStats.delete(token);
|
|
7319
7073
|
}
|
|
7320
7074
|
onBuildDone() {
|
|
7321
7075
|
if (this.environmentStats.clear(), this.reportedBrowserLogs.clear(), this.ensureInitialChunks(), this.socketsMap.size) for (let token of this.socketsMap.keys())this.sendStats({
|
|
@@ -7362,7 +7116,7 @@ class SocketServer {
|
|
|
7362
7116
|
for (let sockets of this.socketsMap.values())sockets.forEach((socket)=>{
|
|
7363
7117
|
socket.close();
|
|
7364
7118
|
});
|
|
7365
|
-
return this.socketsMap.clear(), this.initialChunksMap.clear(), this.reportedBrowserLogs.clear(), new Promise((resolve, reject)=>{
|
|
7119
|
+
return this.socketsMap.clear(), this.initialChunksMap.clear(), this.environmentStats.clear(), this.currentHash.clear(), this.reportedBrowserLogs.clear(), new Promise((resolve, reject)=>{
|
|
7366
7120
|
this.wsServer.close((err)=>{
|
|
7367
7121
|
err ? reject(err) : resolve();
|
|
7368
7122
|
});
|
|
@@ -7417,11 +7171,12 @@ class SocketServer {
|
|
|
7417
7171
|
}
|
|
7418
7172
|
getInitialChunks(stats) {
|
|
7419
7173
|
let initialChunks = new Set(), { entrypoints } = stats;
|
|
7420
|
-
if (!entrypoints) return
|
|
7174
|
+
if (!entrypoints) return;
|
|
7421
7175
|
let entryNames = Object.keys(entrypoints);
|
|
7422
7176
|
for(let entryIndex = 0; entryIndex < entryNames.length; entryIndex++){
|
|
7423
7177
|
let chunks = entrypoints[entryNames[entryIndex]]?.chunks;
|
|
7424
|
-
if (Array.isArray(chunks))
|
|
7178
|
+
if (!Array.isArray(chunks)) return;
|
|
7179
|
+
for(let index = 0; index < chunks.length; index++){
|
|
7425
7180
|
let chunkName = chunks[index];
|
|
7426
7181
|
void 0 !== chunkName && initialChunks.add('string' == typeof chunkName ? chunkName : String(chunkName));
|
|
7427
7182
|
}
|
|
@@ -7432,7 +7187,10 @@ class SocketServer {
|
|
|
7432
7187
|
for (let { webSocketToken } of this.context.environmentList){
|
|
7433
7188
|
if (this.initialChunksMap.has(webSocketToken)) continue;
|
|
7434
7189
|
let result = this.getStats(webSocketToken);
|
|
7435
|
-
|
|
7190
|
+
if (result) {
|
|
7191
|
+
let initialChunks = this.getInitialChunks(result.stats);
|
|
7192
|
+
initialChunks && this.initialChunksMap.set(webSocketToken, initialChunks);
|
|
7193
|
+
}
|
|
7436
7194
|
}
|
|
7437
7195
|
}
|
|
7438
7196
|
getStats(token) {
|
|
@@ -7458,8 +7216,8 @@ class SocketServer {
|
|
|
7458
7216
|
sendStats({ force = !1, token }) {
|
|
7459
7217
|
let result = this.getStats(token);
|
|
7460
7218
|
if (!result) return null;
|
|
7461
|
-
let { stats, errors, warnings } = result, newInitialChunks = this.getInitialChunks(stats), initialChunks = this.initialChunksMap.get(token), shouldReload =
|
|
7462
|
-
if (this.initialChunksMap.set(token, newInitialChunks), shouldReload) return void this.sendMessage({
|
|
7219
|
+
let { stats, errors, warnings } = result, newInitialChunks = this.getInitialChunks(stats), initialChunks = this.initialChunksMap.get(token), shouldReload = newInitialChunks && initialChunks && !isEqualSet(initialChunks, newInitialChunks);
|
|
7220
|
+
if (newInitialChunks && this.initialChunksMap.set(token, newInitialChunks), shouldReload) return void this.sendMessage({
|
|
7463
7221
|
type: 'full-reload'
|
|
7464
7222
|
}, token);
|
|
7465
7223
|
if (this.environmentStats.has(token)) {
|
|
@@ -7519,7 +7277,110 @@ class BuildManager {
|
|
|
7519
7277
|
}
|
|
7520
7278
|
readFileSync = (fileName)=>'readFileSync' in this.outputFileSystem ? this.outputFileSystem.readFileSync(fileName, 'utf-8') : node_fs.readFileSync(fileName, 'utf-8');
|
|
7521
7279
|
async setupCompilationMiddleware() {
|
|
7522
|
-
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
|
+
})({
|
|
7523
7384
|
config,
|
|
7524
7385
|
context,
|
|
7525
7386
|
compiler: this.compiler,
|
|
@@ -7836,193 +7697,33 @@ async function createProxyMiddleware(proxyOptions, logger) {
|
|
|
7836
7697
|
}
|
|
7837
7698
|
};
|
|
7838
7699
|
}
|
|
7839
|
-
let
|
|
7840
|
-
let
|
|
7841
|
-
if (
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
}
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
let
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
}
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
} catch (err) {
|
|
7867
|
-
next(err);
|
|
7868
|
-
}
|
|
7869
|
-
}), middlewares.use((({ environments, logger })=>async function viewingServedFilesMiddleware(req, res, next) {
|
|
7870
|
-
if ('/rsbuild-dev-server' !== req.url.replace(postfixRE, '')) return void next();
|
|
7871
|
-
res.writeHead(200, {
|
|
7872
|
-
'Content-Type': 'text/html; charset=utf-8'
|
|
7873
|
-
}), res.write(`<!DOCTYPE html>
|
|
7874
|
-
<html>
|
|
7875
|
-
<head>
|
|
7876
|
-
<meta charset="utf-8"/>
|
|
7877
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7878
|
-
<style>
|
|
7879
|
-
body {
|
|
7880
|
-
margin: 0;
|
|
7881
|
-
color: #f6f7f9;
|
|
7882
|
-
padding: 32px 40px;
|
|
7883
|
-
line-height: 1.8;
|
|
7884
|
-
min-height: 100vh;
|
|
7885
|
-
background-image: linear-gradient(#020917, #101725);
|
|
7886
|
-
font-family: ui-sans-serif,system-ui,sans-serif;
|
|
7887
|
-
}
|
|
7888
|
-
h1, h2 {
|
|
7889
|
-
font-weight: 500;
|
|
7890
|
-
}
|
|
7891
|
-
h1 {
|
|
7892
|
-
margin: 0;
|
|
7893
|
-
font-size: 36px;
|
|
7894
|
-
}
|
|
7895
|
-
h2 {
|
|
7896
|
-
font-size: 20px;
|
|
7897
|
-
margin: 24px 0 16px;
|
|
7898
|
-
}
|
|
7899
|
-
ul {
|
|
7900
|
-
margin: 0;
|
|
7901
|
-
padding-left: 16px;
|
|
7902
|
-
}
|
|
7903
|
-
a {
|
|
7904
|
-
color: #58c4dc;
|
|
7905
|
-
text-decoration: none;
|
|
7906
|
-
}
|
|
7907
|
-
a:hover {
|
|
7908
|
-
text-decoration: underline;
|
|
7909
|
-
}
|
|
7910
|
-
</style>
|
|
7911
|
-
</head>
|
|
7912
|
-
<body>
|
|
7913
|
-
<h1>Assets Report</h1>
|
|
7914
|
-
</body>
|
|
7915
|
-
</html>`);
|
|
7916
|
-
try {
|
|
7917
|
-
for(let key in environments){
|
|
7918
|
-
res.write(`<h2>Environment: ${key}</h2>`);
|
|
7919
|
-
let list = [], environment = environments[key], stats = await environment.getStats(), assets = getAssetNames(stats.compilation);
|
|
7920
|
-
for (let asset of (res.write('<ul>'), assets))list.push(`<li><a target="_blank" href="${asset}">${asset}</a></li>`);
|
|
7921
|
-
res.write(list?.join('')), res.write('</ul>');
|
|
7922
|
-
}
|
|
7923
|
-
res.end('</body></html>');
|
|
7924
|
-
} catch (err) {
|
|
7925
|
-
logger.error(err), res.writeHead(500), res.end('Failed to list the files');
|
|
7926
|
-
}
|
|
7927
|
-
})({
|
|
7928
|
-
environments: devServer.environments,
|
|
7929
|
-
logger
|
|
7930
|
-
})), buildManager && (middlewares.use(buildManager.assetsMiddleware), upgradeEvents.push(buildManager.socketServer.upgrade), middlewares.use(function hotUpdateJsonFallbackMiddleware(req, res, next) {
|
|
7931
|
-
let url = req.url;
|
|
7932
|
-
if (!url || 'OPTIONS' === req.method) return void next();
|
|
7933
|
-
let queryIndex = url.indexOf('?'), end = -1 === queryIndex ? url.length : queryIndex;
|
|
7934
|
-
url.endsWith('.hot-update.json', end) || url.endsWith('.hot-update.json.mjs', end) ? notFoundMiddleware(req, res, next) : next();
|
|
7935
|
-
})), buildManager && middlewares.use(getHtmlCompletionMiddleware({
|
|
7936
|
-
assetsMiddleware: buildManager.assetsMiddleware,
|
|
7937
|
-
distPaths: [
|
|
7938
|
-
context.distPath
|
|
7939
|
-
],
|
|
7940
|
-
outputFileSystem: buildManager.outputFileSystem
|
|
7941
|
-
}));
|
|
7942
|
-
let publicDirPaths = getPublicDirPaths(config);
|
|
7943
|
-
if (publicDirPaths.length) {
|
|
7944
|
-
let { default: sirv } = await import("./sirv.js");
|
|
7945
|
-
for (let name of publicDirPaths){
|
|
7946
|
-
let sirvMiddleware = sirv(name, {
|
|
7947
|
-
etag: !0,
|
|
7948
|
-
dev: !0
|
|
7949
|
-
});
|
|
7950
|
-
middlewares.use(function publicDirMiddleware(req, res, next) {
|
|
7951
|
-
req.method && 'GET' !== req.method && 'HEAD' !== req.method ? next() : sirvMiddleware(req, res, next);
|
|
7952
|
-
});
|
|
7953
|
-
}
|
|
7954
|
-
}
|
|
7955
|
-
for (let callback of postCallbacks)await callback();
|
|
7956
|
-
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({
|
|
7957
|
-
assetsMiddleware: buildManager.assetsMiddleware,
|
|
7958
|
-
distPaths: [
|
|
7959
|
-
context.distPath
|
|
7960
|
-
],
|
|
7961
|
-
logger,
|
|
7962
|
-
outputFileSystem: buildManager.outputFileSystem
|
|
7963
|
-
})), middlewares.use(faviconFallbackMiddleware), {
|
|
7964
|
-
onUpgrade: (...args)=>{
|
|
7965
|
-
for (let cb of upgradeEvents)cb(...args);
|
|
7966
|
-
}
|
|
7967
|
-
};
|
|
7968
|
-
}, getDevMiddlewares = async (options)=>{
|
|
7969
|
-
let { buildManager, context, devServer } = options, { middlewares } = devServer, { logger } = context;
|
|
7970
|
-
isVerbose(logger) && middlewares.use(getRequestLoggerMiddleware(logger));
|
|
7971
|
-
let { before, after } = ((config, devServer, logger)=>{
|
|
7972
|
-
let setupMiddlewares = config.dev.setupMiddlewares ? helpers_castArray(config.dev.setupMiddlewares) : [];
|
|
7973
|
-
setupMiddlewares.length && logger.warn('[rsbuild] `dev.setupMiddlewares` is deprecated, use `server.setup` instead');
|
|
7974
|
-
let serverOptions = pick(devServer, [
|
|
7975
|
-
'sockWrite',
|
|
7976
|
-
'environments'
|
|
7977
|
-
]), before = [], after = [];
|
|
7978
|
-
for (let handler of setupMiddlewares)handler({
|
|
7979
|
-
unshift: (...handlers)=>before.unshift(...handlers),
|
|
7980
|
-
push: (...handlers)=>after.push(...handlers)
|
|
7981
|
-
}, serverOptions);
|
|
7982
|
-
return {
|
|
7983
|
-
before,
|
|
7984
|
-
after
|
|
7985
|
-
};
|
|
7986
|
-
})(options.config, options.devServer, logger);
|
|
7987
|
-
for (let middleware of before)middlewares.use(middleware);
|
|
7988
|
-
let { onUpgrade } = await applyDefaultMiddlewares({
|
|
7989
|
-
...options,
|
|
7990
|
-
middlewares
|
|
7991
|
-
});
|
|
7992
|
-
for (let middleware of after)middlewares.use(middleware);
|
|
7993
|
-
return {
|
|
7994
|
-
close: async ()=>{
|
|
7995
|
-
await buildManager?.close();
|
|
7996
|
-
},
|
|
7997
|
-
onUpgrade
|
|
7998
|
-
};
|
|
7999
|
-
}, isModuleNamespaceObject = (moduleExports)=>'[object Module]' === Object.prototype.toString.call(moduleExports), asModule = async (vm, moduleExports, context, unlinked)=>{
|
|
8000
|
-
let { Module, SyntheticModule } = vm;
|
|
8001
|
-
if (moduleExports instanceof Module) return moduleExports;
|
|
8002
|
-
let normalizedModuleExports = null !== moduleExports && ('object' == typeof moduleExports || 'function' == typeof moduleExports) ? moduleExports : {
|
|
8003
|
-
default: moduleExports
|
|
8004
|
-
}, exports = [
|
|
8005
|
-
...new Set([
|
|
8006
|
-
'default',
|
|
8007
|
-
...Object.keys(normalizedModuleExports)
|
|
8008
|
-
])
|
|
8009
|
-
], syntheticModule = new SyntheticModule(exports, ()=>{
|
|
8010
|
-
for (let name of exports)if ('default' === name) {
|
|
8011
|
-
let defaultExport = isModuleNamespaceObject(normalizedModuleExports) && 'default' in normalizedModuleExports ? normalizedModuleExports.default : moduleExports;
|
|
8012
|
-
syntheticModule.setExport(name, defaultExport);
|
|
8013
|
-
} else syntheticModule.setExport(name, normalizedModuleExports[name]);
|
|
8014
|
-
}, {
|
|
8015
|
-
context
|
|
8016
|
-
});
|
|
8017
|
-
return unlinked || (await syntheticModule.link(()=>{}), await syntheticModule.evaluate()), syntheticModule;
|
|
8018
|
-
};
|
|
8019
|
-
class BasicRunner {
|
|
8020
|
-
options;
|
|
8021
|
-
globalContext = null;
|
|
8022
|
-
baseModuleScope = null;
|
|
8023
|
-
requirers = new Map();
|
|
8024
|
-
constructor(options){
|
|
8025
|
-
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;
|
|
8026
7727
|
}
|
|
8027
7728
|
run(file) {
|
|
8028
7729
|
this.globalContext || (this.globalContext = this.createGlobalContext()), this.baseModuleScope = this.createBaseModuleScope(), this.createRunner();
|
|
@@ -8198,10 +7899,7 @@ class BasicRunnerFactory {
|
|
|
8198
7899
|
return new EsmRunner(runnerOptions);
|
|
8199
7900
|
}
|
|
8200
7901
|
}
|
|
8201
|
-
let
|
|
8202
|
-
let runner = new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions);
|
|
8203
|
-
return await runner.run(bundlePath);
|
|
8204
|
-
}, loadBundleStatsCache = new WeakMap(), loadBundle = async (stats, entryName, utils)=>{
|
|
7902
|
+
let loadBundleStatsCache = new WeakMap(), loadBundle = async (stats, entryName, utils)=>{
|
|
8205
7903
|
let loadBundleStats = loadBundleStatsCache.get(stats);
|
|
8206
7904
|
loadBundleStats || (loadBundleStats = {
|
|
8207
7905
|
...stats.toJson({
|
|
@@ -8225,7 +7923,10 @@ let runner_run = async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
|
8225
7923
|
for (let chunk of (outputFilePaths = new Set(), chunks || []))for (let file of chunk.files)outputFilePaths.add(join(outputPath, file));
|
|
8226
7924
|
loadBundleStats.outputFilePaths = outputFilePaths;
|
|
8227
7925
|
}
|
|
8228
|
-
return await
|
|
7926
|
+
return await (async ({ bundlePath, ...runnerFactoryOptions })=>{
|
|
7927
|
+
let runner = new BasicRunnerFactory(bundlePath).create(runnerFactoryOptions);
|
|
7928
|
+
return await runner.run(bundlePath);
|
|
7929
|
+
})({
|
|
8229
7930
|
bundlePath: files[0],
|
|
8230
7931
|
dist: outputPath,
|
|
8231
7932
|
compilerOptions: stats.compilation.options,
|
|
@@ -8353,51 +8054,7 @@ async function devServer_createDevServer(options, createCompiler, config, devSer
|
|
|
8353
8054
|
let currentStats = stats[index];
|
|
8354
8055
|
return currentStats || waiters[index].promise;
|
|
8355
8056
|
}
|
|
8356
|
-
}), hotConnectCallbacks = new Map(),
|
|
8357
|
-
let compiler = await createCompiler();
|
|
8358
|
-
if (!compiler) throw Error(`${color.dim('[rsbuild:server]')} Failed to get compiler instance.`);
|
|
8359
|
-
context.publicPathnames = getPublicPathnames(compiler_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
|
|
8360
|
-
getPublicPathFromCompiler(compiler)
|
|
8361
|
-
], config.server.base);
|
|
8362
|
-
let hookOptions = {
|
|
8363
|
-
name: 'rsbuild:environment-api',
|
|
8364
|
-
stage: -10000
|
|
8365
|
-
};
|
|
8366
|
-
compiler_isMultiCompiler(compiler) ? compiler.compilers.forEach((compiler, index)=>{
|
|
8367
|
-
compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8368
|
-
compileState.reset(index);
|
|
8369
|
-
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8370
|
-
compileState.done(index, stats);
|
|
8371
|
-
});
|
|
8372
|
-
}) : (compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8373
|
-
compileState.reset(0);
|
|
8374
|
-
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8375
|
-
compileState.done(0, stats);
|
|
8376
|
-
}));
|
|
8377
|
-
let buildManager = new BuildManager({
|
|
8378
|
-
context,
|
|
8379
|
-
config,
|
|
8380
|
-
compiler,
|
|
8381
|
-
resolvedPort: port,
|
|
8382
|
-
onSocketConnect: (socket, token)=>{
|
|
8383
|
-
let callbacks = hotConnectCallbacks?.get(token);
|
|
8384
|
-
if (!callbacks?.size) return;
|
|
8385
|
-
let client = {
|
|
8386
|
-
send: createHotSend(socket)
|
|
8387
|
-
};
|
|
8388
|
-
for (let callback of [
|
|
8389
|
-
...callbacks
|
|
8390
|
-
])try {
|
|
8391
|
-
Promise.resolve(callback(client)).catch((error)=>{
|
|
8392
|
-
logger.error(error);
|
|
8393
|
-
});
|
|
8394
|
-
} catch (error) {
|
|
8395
|
-
logger.error(error);
|
|
8396
|
-
}
|
|
8397
|
-
}
|
|
8398
|
-
});
|
|
8399
|
-
return await buildManager.init(), buildManager;
|
|
8400
|
-
}, protocol = isHttps ? 'https' : 'http', urls = await getAddressUrls({
|
|
8057
|
+
}), hotConnectCallbacks = new Map(), protocol = isHttps ? 'https' : 'http', urls = await getAddressUrls({
|
|
8401
8058
|
protocol,
|
|
8402
8059
|
port,
|
|
8403
8060
|
host
|
|
@@ -8562,12 +8219,216 @@ async function devServer_createDevServer(options, createCompiler, config, devSer
|
|
|
8562
8219
|
})).filter((item)=>'function' == typeof item),
|
|
8563
8220
|
...setupPostCallbacks
|
|
8564
8221
|
];
|
|
8565
|
-
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({
|
|
8566
8267
|
config,
|
|
8567
8268
|
logger,
|
|
8568
8269
|
buildManager: state.buildManager,
|
|
8569
8270
|
root: context.rootPath
|
|
8570
|
-
}), 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
|
+
})({
|
|
8571
8432
|
buildManager: state.buildManager,
|
|
8572
8433
|
config,
|
|
8573
8434
|
devServer,
|
|
@@ -9396,7 +9257,45 @@ try {
|
|
|
9396
9257
|
skipMain: !emitCss
|
|
9397
9258
|
});
|
|
9398
9259
|
}
|
|
9399
|
-
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
|
+
})({
|
|
9400
9299
|
config,
|
|
9401
9300
|
root: api.context.rootPath,
|
|
9402
9301
|
postcssrcCache
|
|
@@ -9410,7 +9309,37 @@ try {
|
|
|
9410
9309
|
skipMain: !emitCss
|
|
9411
9310
|
});
|
|
9412
9311
|
}
|
|
9413
|
-
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
|
+
})({
|
|
9414
9343
|
config,
|
|
9415
9344
|
localIdentName,
|
|
9416
9345
|
emitCss
|
|
@@ -10069,82 +9998,175 @@ async function createRsbuild(options = {}) {
|
|
|
10069
9998
|
context,
|
|
10070
9999
|
pluginManager,
|
|
10071
10000
|
rsbuildOptions: resolvedOptions
|
|
10072
|
-
})).compiler),
|
|
10073
|
-
context.action = 'preview', process.env.NODE_ENV || setNodeEnv('production');
|
|
10074
|
-
let config = await initRsbuildConfig({
|
|
10075
|
-
context,
|
|
10076
|
-
pluginManager
|
|
10077
|
-
}), { distPath } = context, { checkDistDir = !0 } = options;
|
|
10078
|
-
if (checkDistDir) {
|
|
10079
|
-
if (!existsSync(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} does not exist, please build the project before previewing.`);
|
|
10080
|
-
if (isEmptyDir(distPath)) throw Error(`${color.dim('[rsbuild:preview]')} The output directory ${color.yellow(distPath)} is empty, please build the project before previewing.`);
|
|
10081
|
-
}
|
|
10082
|
-
return startPreviewServer(context, config, options);
|
|
10083
|
-
}, build = async (options = {})=>(context.action = 'build', process.env.NODE_ENV || setNodeEnv('production'), build_build({
|
|
10084
|
-
context,
|
|
10085
|
-
pluginManager,
|
|
10086
|
-
rsbuildOptions: resolvedOptions
|
|
10087
|
-
}, {
|
|
10088
|
-
...options
|
|
10089
|
-
})), startDevServer = async (options = {})=>{
|
|
10090
|
-
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
10091
|
-
let config = await initRsbuildConfig({
|
|
10092
|
-
context,
|
|
10093
|
-
pluginManager
|
|
10094
|
-
});
|
|
10095
|
-
return (await devServer_createDevServer({
|
|
10096
|
-
context,
|
|
10097
|
-
pluginManager,
|
|
10098
|
-
rsbuildOptions: resolvedOptions
|
|
10099
|
-
}, createCompiler, config, options)).listen();
|
|
10100
|
-
}, createDevServer = async (options)=>{
|
|
10101
|
-
context.action = 'dev', process.env.NODE_ENV || setNodeEnv('development');
|
|
10102
|
-
let config = await initRsbuildConfig({
|
|
10103
|
-
context,
|
|
10104
|
-
pluginManager
|
|
10105
|
-
});
|
|
10106
|
-
return devServer_createDevServer({
|
|
10107
|
-
context,
|
|
10108
|
-
pluginManager,
|
|
10109
|
-
rsbuildOptions: resolvedOptions
|
|
10110
|
-
}, createCompiler, config, options);
|
|
10111
|
-
}, initAction = (mode = config.mode)=>{
|
|
10001
|
+
})).compiler), initAction = (mode = config.mode)=>{
|
|
10112
10002
|
context.action || (context.action = 'development' === mode ? 'dev' : 'build');
|
|
10113
|
-
}, inspectConfig = async (inspectOptions = {})=>{
|
|
10114
|
-
inspectOptions.mode ? setNodeEnv(inspectOptions.mode) : process.env.NODE_ENV || setNodeEnv('development'), initAction(config.mode ?? (process.env.NODE_ENV || ''));
|
|
10115
|
-
let { rspackConfigs } = await initConfigs_initConfigs({
|
|
10116
|
-
context,
|
|
10117
|
-
pluginManager,
|
|
10118
|
-
rsbuildOptions: resolvedOptions
|
|
10119
|
-
});
|
|
10120
|
-
return inspectConfig_inspectConfig({
|
|
10121
|
-
context,
|
|
10122
|
-
pluginManager,
|
|
10123
|
-
rsbuildOptions: resolvedOptions,
|
|
10124
|
-
inspectOptions,
|
|
10125
|
-
bundlerConfigs: rspackConfigs
|
|
10126
|
-
});
|
|
10127
|
-
}, initConfigs = async (options)=>{
|
|
10128
|
-
if (context.action && options?.action && context.action !== options.action) throw Error(`\
|
|
10129
|
-
[rsbuild] initConfigs() can only be called with the same action type.
|
|
10130
|
-
- Expected: ${context.action}
|
|
10131
|
-
- Actual: ${options?.action}`);
|
|
10132
|
-
options?.action && (context.action = options.action);
|
|
10133
|
-
let { rspackConfigs } = await initConfigs_initConfigs({
|
|
10134
|
-
context,
|
|
10135
|
-
pluginManager,
|
|
10136
|
-
rsbuildOptions: resolvedOptions
|
|
10137
|
-
});
|
|
10138
|
-
return rspackConfigs;
|
|
10139
10003
|
}, rsbuild = {
|
|
10140
10004
|
logger: context.logger,
|
|
10141
|
-
build,
|
|
10142
|
-
|
|
10143
|
-
|
|
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
|
+
},
|
|
10144
10129
|
createCompiler,
|
|
10145
|
-
createDevServer
|
|
10146
|
-
|
|
10147
|
-
|
|
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
|
+
},
|
|
10148
10170
|
...pick(pluginManager, [
|
|
10149
10171
|
'addPlugins',
|
|
10150
10172
|
'getPlugins',
|
|
@@ -10207,50 +10229,11 @@ let canReadExport = (module)=>null !== module && ('object' == typeof module || '
|
|
|
10207
10229
|
return ()=>promise ??= importer().catch((error)=>{
|
|
10208
10230
|
throw promise = void 0, error;
|
|
10209
10231
|
});
|
|
10210
|
-
}, getJiti = cachedImport(()=>import("../compiled/jiti/lib/jiti.mjs")),
|
|
10211
|
-
let createJiti;
|
|
10212
|
-
try {
|
|
10213
|
-
({ createJiti } = await getJiti());
|
|
10214
|
-
} catch (error) {
|
|
10215
|
-
throw Error('The "jiti" package is required to load this config. Install it with your package manager.', {
|
|
10216
|
-
cause: error
|
|
10217
|
-
});
|
|
10218
|
-
}
|
|
10219
|
-
let jiti = createJiti(configPath, {
|
|
10220
|
-
moduleCache: !fresh,
|
|
10221
|
-
interopDefault: !0,
|
|
10222
|
-
nativeModules: [
|
|
10223
|
-
"typescript"
|
|
10224
|
-
]
|
|
10225
|
-
});
|
|
10226
|
-
return 'default' === exportName ? {
|
|
10227
|
-
configExport: await jiti.import(configPath, {
|
|
10228
|
-
default: !0
|
|
10229
|
-
}),
|
|
10230
|
-
dependencies: []
|
|
10231
|
-
} : {
|
|
10232
|
-
configExport: getConfigExport(await jiti.import(configPath), exportName, configPath),
|
|
10233
|
-
dependencies: []
|
|
10234
|
-
};
|
|
10235
|
-
}, 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');
|
|
10236
10233
|
function getConfigMeta(config) {
|
|
10237
10234
|
if (null !== config && 'object' == typeof config && Object.hasOwn(config, CONFIG_META)) return config[CONFIG_META];
|
|
10238
10235
|
}
|
|
10239
|
-
let getFreshImport = cachedImport(()=>import("./freshImport.js")), JS_CONFIG_REGEXP = /\.(?:js|mjs|cjs)
|
|
10240
|
-
let configFileURL = pathToFileURL(configPath).href;
|
|
10241
|
-
if (!fresh) return {
|
|
10242
|
-
configModule: await import(configFileURL),
|
|
10243
|
-
dependencies: []
|
|
10244
|
-
};
|
|
10245
|
-
let { freshImport } = await getFreshImport(), freshImportResult = await freshImport(configFileURL);
|
|
10246
|
-
return freshImportResult ? {
|
|
10247
|
-
configModule: freshImportResult.result,
|
|
10248
|
-
dependencies: freshImportResult.dependencies.sort()
|
|
10249
|
-
} : {
|
|
10250
|
-
configModule: await import(`${configFileURL}?t=${Date.now()}`),
|
|
10251
|
-
dependencies: []
|
|
10252
|
-
};
|
|
10253
|
-
};
|
|
10236
|
+
let getFreshImport = cachedImport(()=>import("./freshImport.js")), JS_CONFIG_REGEXP = /\.(?:js|mjs|cjs)$/;
|
|
10254
10237
|
async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = [], loader = 'auto', exportName = 'default', configParams = [], fresh = !1 } = {}) {
|
|
10255
10238
|
let loadedConfig, content;
|
|
10256
10239
|
if (!path && 0 === configFileNames.length) throw Error('Either `path` or at least one `configFileNames` entry must be provided.');
|
|
@@ -10274,7 +10257,21 @@ async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = []
|
|
|
10274
10257
|
if ('native' === loader || 'auto' === loader && (process.features.typescript || process.versions.bun || process.versions.deno) || JS_CONFIG_REGEXP.test(configPath)) {
|
|
10275
10258
|
let result;
|
|
10276
10259
|
try {
|
|
10277
|
-
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);
|
|
10278
10275
|
} catch (err) {
|
|
10279
10276
|
if ('native' === loader) throw err;
|
|
10280
10277
|
}
|
|
@@ -10283,7 +10280,32 @@ async function dist_loadConfig({ cwd = process.cwd(), path, configFileNames = []
|
|
|
10283
10280
|
dependencies: result.dependencies
|
|
10284
10281
|
});
|
|
10285
10282
|
}
|
|
10286
|
-
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));
|
|
10287
10309
|
let { configExport, dependencies } = loadedConfig;
|
|
10288
10310
|
if ('function' == typeof configExport) {
|
|
10289
10311
|
let result = await configExport(...configParams);
|
|
@@ -10342,30 +10364,6 @@ let cliState = {
|
|
|
10342
10364
|
options: {}
|
|
10343
10365
|
}, initCliAction = (command, options)=>{
|
|
10344
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;
|
|
10345
|
-
}, init_loadConfig = async (root)=>{
|
|
10346
|
-
let { options, command } = cliState, result = await loadConfig_loadConfig({
|
|
10347
|
-
cwd: root,
|
|
10348
|
-
path: options.config,
|
|
10349
|
-
envMode: options.envMode,
|
|
10350
|
-
loader: options.configLoader,
|
|
10351
|
-
command
|
|
10352
|
-
}), { content: config } = result;
|
|
10353
|
-
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) {
|
|
10354
|
-
config.output ||= {};
|
|
10355
|
-
let { distPath } = config.output;
|
|
10356
|
-
config.output.distPath = distPath && 'object' == typeof distPath ? {
|
|
10357
|
-
...distPath,
|
|
10358
|
-
root: options.distPath
|
|
10359
|
-
} : {
|
|
10360
|
-
root: options.distPath
|
|
10361
|
-
};
|
|
10362
|
-
}
|
|
10363
|
-
if (void 0 !== options.sourceMap) {
|
|
10364
|
-
let sourceMap = options.sourceMap;
|
|
10365
|
-
if ('boolean' != typeof sourceMap) throw Error('The "--source-map" option only accepts a boolean value.');
|
|
10366
|
-
config.output ||= {}, config.output.sourceMap = sourceMap;
|
|
10367
|
-
}
|
|
10368
|
-
return void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), result;
|
|
10369
10367
|
}, init_restart = async (context)=>{
|
|
10370
10368
|
let rsbuild = await init_init({
|
|
10371
10369
|
isRestart: !0
|
|
@@ -10378,7 +10376,31 @@ async function init_init({ isRestart } = {}) {
|
|
|
10378
10376
|
var envDir;
|
|
10379
10377
|
let cwd = process.cwd(), root = options.root ? ensureAbsolutePath(cwd, options.root) : cwd, rsbuild = await createRsbuild({
|
|
10380
10378
|
cwd: root,
|
|
10381
|
-
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),
|
|
10382
10404
|
environment: options.environment,
|
|
10383
10405
|
loadEnv: !1 !== options.env && {
|
|
10384
10406
|
cwd: (envDir = options.envDir) ? node_path.isAbsolute(envDir) ? envDir : node_path.join(root, envDir) : root,
|
|
@@ -10397,7 +10419,7 @@ let applyServerOptions = (command)=>{
|
|
|
10397
10419
|
};
|
|
10398
10420
|
function setupCommands(argv) {
|
|
10399
10421
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
10400
|
-
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)', {
|
|
10401
10423
|
default: 'auto'
|
|
10402
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', {
|
|
10403
10425
|
type: [
|
|
@@ -10462,7 +10484,7 @@ function setupCommands(argv) {
|
|
|
10462
10484
|
}
|
|
10463
10485
|
function showGreeting() {
|
|
10464
10486
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
10465
|
-
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`);
|
|
10466
10488
|
}
|
|
10467
10489
|
function setupLogLevel(argv) {
|
|
10468
10490
|
if (argv.length <= 3) return;
|
|
@@ -10484,5 +10506,5 @@ function runCLI({ argv = process.argv } = {}) {
|
|
|
10484
10506
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
|
|
10485
10507
|
}
|
|
10486
10508
|
}
|
|
10487
|
-
let src_version = "2.3.
|
|
10509
|
+
let src_version = "2.3.1";
|
|
10488
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 };
|