@rsbuild/core 2.0.12 → 2.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/756.js +81 -30
- package/dist-types/server/compileState.d.ts +5 -0
- package/package.json +1 -1
- package/types.d.ts +1 -1
package/dist/756.js
CHANGED
|
@@ -3483,7 +3483,7 @@ function createPublicContext(context) {
|
|
|
3483
3483
|
async function createContext(options, userConfig, logger) {
|
|
3484
3484
|
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = join(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
|
|
3485
3485
|
return {
|
|
3486
|
-
version: "2.0.
|
|
3486
|
+
version: "2.0.14",
|
|
3487
3487
|
rootPath,
|
|
3488
3488
|
distPath: '',
|
|
3489
3489
|
cachePath,
|
|
@@ -5868,6 +5868,14 @@ async function open_open({ port, routes, config, protocol, clearCache, logger })
|
|
|
5868
5868
|
let urls = [], host = await getHostInUrl(config.server.host), baseUrl = `${protocol}://${host}:${port}`;
|
|
5869
5869
|
for (let url of (targets.length ? urls.push(...targets.map((target)=>resolveUrl(replacePortPlaceholder(target, port), baseUrl))) : routes.length ? urls.push(`${baseUrl}${routes[0].pathname}`) : urls.push(baseUrl), before && await before(), urls))openedURLs.includes(url) || (openBrowser(url, logger), openedURLs.push(url));
|
|
5870
5870
|
}
|
|
5871
|
+
let getServerUrlFromClientConfig = async (config, context)=>{
|
|
5872
|
+
let { devServer } = context;
|
|
5873
|
+
if (!devServer) return;
|
|
5874
|
+
let { client } = config.dev, hasClientHost = !!client.host, hasClientPort = void 0 !== client.port && '' !== client.port;
|
|
5875
|
+
if (!hasClientHost && !hasClientPort) return;
|
|
5876
|
+
let protocol = client.protocol ? `${'wss' === client.protocol ? 'https' : 'http'}:` : '', hostname = await getHostInUrl(client.host || devServer.hostname), port = client.port && '<port>' !== client.port ? client.port : devServer.port;
|
|
5877
|
+
return `${protocol}//${hostname}:${port}`;
|
|
5878
|
+
};
|
|
5871
5879
|
function recursiveChunkGroup(chunkGroup, visited = new Set()) {
|
|
5872
5880
|
if (visited.has(chunkGroup)) return [];
|
|
5873
5881
|
visited.add(chunkGroup);
|
|
@@ -7335,7 +7343,12 @@ async function setupCliShortcuts({ help = !0, openPage, closeServer, printUrls,
|
|
|
7335
7343
|
rl.close();
|
|
7336
7344
|
};
|
|
7337
7345
|
}
|
|
7338
|
-
let
|
|
7346
|
+
let createDeferred = ()=>{
|
|
7347
|
+
let deferred = {};
|
|
7348
|
+
return deferred.promise = new Promise((resolve)=>{
|
|
7349
|
+
deferred.resolve = resolve;
|
|
7350
|
+
}), deferred;
|
|
7351
|
+
}, ENCODING_REGEX = /\bgzip\b/, CONTENT_TYPE_REGEX = /text|javascript|\/json|xml/i;
|
|
7339
7352
|
function gzipMiddleware_gzipMiddleware({ filter, level = node_zlib.constants.Z_BEST_SPEED } = {}) {
|
|
7340
7353
|
return function gzipMiddleware(req, res, next) {
|
|
7341
7354
|
let gzip, writeHeadStatus, writeHeadMessage;
|
|
@@ -8057,7 +8070,8 @@ async function startWatchFiles({ paths, options, type = 'reload-page' }, buildMa
|
|
|
8057
8070
|
}), watcher;
|
|
8058
8071
|
}
|
|
8059
8072
|
async function devServer_createDevServer(options, createCompiler, config, { getPortSilently, runCompile = !0 } = {}) {
|
|
8060
|
-
|
|
8073
|
+
var environmentCount;
|
|
8074
|
+
let stats, waiters, { context } = options, { logger } = context;
|
|
8061
8075
|
logger.debug('create dev server');
|
|
8062
8076
|
let { port, portTip } = await resolvePort(config), { middlewareMode, host } = config.server, isHttps = !!config.server.https, routes = getRoutes(context), fallbackPathname = 0 === routes.length && context.environmentList.some((item)=>'web' === item.config.output.target) ? config.server.base : void 0;
|
|
8063
8077
|
context.devServer = {
|
|
@@ -8065,24 +8079,40 @@ async function devServer_createDevServer(options, createCompiler, config, { getP
|
|
|
8065
8079
|
port,
|
|
8066
8080
|
https: isHttps
|
|
8067
8081
|
};
|
|
8068
|
-
let
|
|
8069
|
-
|
|
8070
|
-
})
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8082
|
+
let compileState = (stats = Array(environmentCount = context.environmentList.length), waiters = Array.from({
|
|
8083
|
+
length: environmentCount
|
|
8084
|
+
}, createDeferred), {
|
|
8085
|
+
reset (index) {
|
|
8086
|
+
stats[index] && (stats[index] = void 0, waiters[index] = createDeferred());
|
|
8087
|
+
},
|
|
8088
|
+
done (index, nextStats) {
|
|
8089
|
+
stats[index] = nextStats, waiters[index].resolve(nextStats);
|
|
8090
|
+
},
|
|
8091
|
+
async wait (index) {
|
|
8092
|
+
let currentStats = stats[index];
|
|
8093
|
+
return currentStats || waiters[index].promise;
|
|
8094
|
+
}
|
|
8095
|
+
}), startCompile = async ()=>{
|
|
8077
8096
|
let compiler = await createCompiler();
|
|
8078
8097
|
if (!compiler) throw Error(`${color.dim('[rsbuild:server]')} Failed to get compiler instance.`);
|
|
8079
8098
|
context.publicPathnames = getPublicPathnames(compiler_isMultiCompiler(compiler) ? compiler.compilers.map(getPublicPathFromCompiler) : [
|
|
8080
8099
|
getPublicPathFromCompiler(compiler)
|
|
8081
|
-
], config.server.base)
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
}
|
|
8100
|
+
], config.server.base);
|
|
8101
|
+
let hookOptions = {
|
|
8102
|
+
name: 'rsbuild:environment-api',
|
|
8103
|
+
stage: -10000
|
|
8104
|
+
};
|
|
8105
|
+
compiler_isMultiCompiler(compiler) ? compiler.compilers.forEach((compiler, index)=>{
|
|
8106
|
+
compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8107
|
+
compileState.reset(index);
|
|
8108
|
+
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8109
|
+
compileState.done(index, stats);
|
|
8110
|
+
});
|
|
8111
|
+
}) : (compiler.hooks.watchRun.tap(hookOptions, ()=>{
|
|
8112
|
+
compileState.reset(0);
|
|
8113
|
+
}), compiler.hooks.done.tap(hookOptions, (stats)=>{
|
|
8114
|
+
compileState.done(0, stats);
|
|
8115
|
+
}));
|
|
8086
8116
|
let buildManager = new BuildManager({
|
|
8087
8117
|
context,
|
|
8088
8118
|
config,
|
|
@@ -8152,18 +8182,18 @@ async function devServer_createDevServer(options, createCompiler, config, { getP
|
|
|
8152
8182
|
},
|
|
8153
8183
|
getStats: async ()=>{
|
|
8154
8184
|
if (!state.buildManager) throw Error(getErrorMsg('getStats'));
|
|
8155
|
-
return
|
|
8185
|
+
return compileState.wait(index);
|
|
8156
8186
|
},
|
|
8157
8187
|
loadBundle: async (entryName)=>{
|
|
8158
8188
|
if (!state.buildManager) throw Error(getErrorMsg('loadBundle'));
|
|
8159
|
-
return await
|
|
8189
|
+
return cacheableLoadBundle(await compileState.wait(index), entryName, {
|
|
8160
8190
|
readFileSync: state.buildManager.readFileSync,
|
|
8161
8191
|
environment
|
|
8162
8192
|
});
|
|
8163
8193
|
},
|
|
8164
8194
|
getTransformedHtml: async (entryName)=>{
|
|
8165
8195
|
if (!state.buildManager) throw Error(getErrorMsg('getTransformedHtml'));
|
|
8166
|
-
return await
|
|
8196
|
+
return cacheableTransformedHtml(await compileState.wait(index), entryName, {
|
|
8167
8197
|
readFileSync: state.buildManager.readFileSync,
|
|
8168
8198
|
environment
|
|
8169
8199
|
});
|
|
@@ -9454,7 +9484,7 @@ try {
|
|
|
9454
9484
|
for (let file of chunkFiles){
|
|
9455
9485
|
file.isInitial || (isCSSPath(file.path) ? asyncCSS.push(file.path) : asyncJS.push(file.path));
|
|
9456
9486
|
let relatedLICENSE = licenseMap.get(file.path);
|
|
9457
|
-
if (relatedLICENSE && assets.add(relatedLICENSE), file.chunk) for (let auxiliaryFile of file.chunk.auxiliaryFiles)assets.add(auxiliaryFile);
|
|
9487
|
+
if (relatedLICENSE && assets.add(relatedLICENSE), file.chunk) for (let auxiliaryFile of file.chunk.auxiliaryFiles)assets.add(manifestOptions.prefix ? ensureAssetPrefix(auxiliaryFile, publicPath) : auxiliaryFile);
|
|
9458
9488
|
}
|
|
9459
9489
|
let entryManifest = {};
|
|
9460
9490
|
assets.size && (entryManifest.assets = Array.from(assets));
|
|
@@ -9519,18 +9549,39 @@ try {
|
|
|
9519
9549
|
name: 'rsbuild:lazy-compilation',
|
|
9520
9550
|
apply: 'serve',
|
|
9521
9551
|
setup (api) {
|
|
9522
|
-
api.modifyBundlerChain((chain, { environment, target })=>{
|
|
9552
|
+
api.modifyBundlerChain(async (chain, { environment, target })=>{
|
|
9523
9553
|
if ('web' !== target) return;
|
|
9524
|
-
let { config } = environment
|
|
9554
|
+
let { config } = environment;
|
|
9555
|
+
if (!config.dev.hmr && !config.dev.liveReload) return;
|
|
9556
|
+
let options = config.dev?.lazyCompilation;
|
|
9525
9557
|
if (options) {
|
|
9526
|
-
if (!0 === options
|
|
9527
|
-
entries
|
|
9528
|
-
|
|
9529
|
-
|
|
9558
|
+
if (!0 === options) {
|
|
9559
|
+
let entries = chain.entryPoints.entries() || {}, serverUrl = await getServerUrlFromClientConfig(config, api.context);
|
|
9560
|
+
if (Object.keys(entries).length <= 1) return void chain.lazyCompilation({
|
|
9561
|
+
entries: !1,
|
|
9562
|
+
imports: !0,
|
|
9563
|
+
...serverUrl ? {
|
|
9564
|
+
serverUrl
|
|
9565
|
+
} : {}
|
|
9566
|
+
});
|
|
9567
|
+
if (serverUrl) return void chain.lazyCompilation({
|
|
9568
|
+
entries: !0,
|
|
9569
|
+
imports: !0,
|
|
9570
|
+
serverUrl
|
|
9571
|
+
});
|
|
9572
|
+
}
|
|
9530
9573
|
if ('object' == typeof options && 'string' == typeof options.serverUrl && api.context.devServer) return void chain.lazyCompilation({
|
|
9531
9574
|
...options,
|
|
9532
9575
|
serverUrl: replacePortPlaceholder(options.serverUrl, api.context.devServer.port)
|
|
9533
9576
|
});
|
|
9577
|
+
if ('object' == typeof options) {
|
|
9578
|
+
let serverUrl = await getServerUrlFromClientConfig(config, api.context);
|
|
9579
|
+
chain.lazyCompilation(serverUrl ? {
|
|
9580
|
+
...options,
|
|
9581
|
+
serverUrl
|
|
9582
|
+
} : options);
|
|
9583
|
+
return;
|
|
9584
|
+
}
|
|
9534
9585
|
chain.lazyCompilation(options);
|
|
9535
9586
|
}
|
|
9536
9587
|
});
|
|
@@ -9941,7 +9992,7 @@ let applyServerOptions = (command)=>{
|
|
|
9941
9992
|
};
|
|
9942
9993
|
function setupCommands() {
|
|
9943
9994
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
9944
|
-
cli.version("2.0.
|
|
9995
|
+
cli.version("2.0.14"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
|
|
9945
9996
|
default: 'auto'
|
|
9946
9997
|
}).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', {
|
|
9947
9998
|
type: [
|
|
@@ -10012,7 +10063,7 @@ function initNodeEnv(command) {
|
|
|
10012
10063
|
}
|
|
10013
10064
|
function showGreeting() {
|
|
10014
10065
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
10015
|
-
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.0.
|
|
10066
|
+
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v2.0.14\n`);
|
|
10016
10067
|
}
|
|
10017
10068
|
function setupLogLevel() {
|
|
10018
10069
|
if (cli_argv.length <= 3) return;
|
|
@@ -10034,5 +10085,5 @@ function runCLI() {
|
|
|
10034
10085
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err), process.exit(1);
|
|
10035
10086
|
}
|
|
10036
10087
|
}
|
|
10037
|
-
let src_version = "2.0.
|
|
10088
|
+
let src_version = "2.0.14";
|
|
10038
10089
|
export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, core_rspack as rspack, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, loadConfig_loadConfig as loadConfig, loadEnv, logger_createLogger as createLogger, mergeRsbuildConfig, mrmime_lookup, runCLI, src_logger as logger, src_version as version };
|
package/package.json
CHANGED