@rsbuild/core 1.2.11 → 1.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/chokidar/index.d.ts +61 -23
- package/compiled/chokidar/index.js +71 -56
- package/compiled/css-loader/index.js +309 -195
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/http-proxy-middleware/index.d.ts +1 -1
- package/compiled/launch-editor-middleware/index.js +9 -6
- package/compiled/mrmime/index.js +4 -0
- package/compiled/mrmime/package.json +1 -1
- package/compiled/postcss/index.js +194 -194
- package/compiled/postcss/package.json +1 -1
- package/compiled/postcss-load-config/index.js +11 -11
- package/compiled/postcss-loader/index.js +9 -9
- package/compiled/rsbuild-dev-middleware/index.js +25 -25
- package/compiled/rspack-manifest-plugin/index.js +4 -4
- package/compiled/sirv/index.js +8 -4
- package/compiled/sirv/package.json +1 -1
- package/compiled/style-loader/index.js +10 -10
- package/compiled/tinyglobby/index.d.ts +1 -0
- package/compiled/tinyglobby/index.js +266 -142
- package/compiled/tinyglobby/package.json +1 -1
- package/compiled/webpack-bundle-analyzer/index.js +6 -2
- package/compiled/ws/index.js +50 -49
- package/compiled/ws/package.json +1 -1
- package/dist/client/hmr.js +2 -2
- package/dist/index.cjs +86 -53
- package/dist/index.js +82 -49
- package/dist-types/helpers/index.d.ts +3 -3
- package/dist-types/index.d.ts +1 -1
- package/dist-types/loadEnv.d.ts +16 -4
- package/dist-types/logger.d.ts +14 -0
- package/dist-types/server/devServer.d.ts +2 -1
- package/dist-types/server/socketServer.d.ts +4 -2
- package/dist-types/types/config.d.ts +79 -43
- package/dist-types/types/rspack.d.ts +1 -1
- package/package.json +11 -11
- package/compiled/jiti/index.d.ts +0 -1
- package/compiled/jiti/index.js +0 -416
- package/compiled/jiti/license +0 -21
- package/compiled/jiti/package.json +0 -1
package/dist/index.js
CHANGED
|
@@ -438,7 +438,7 @@ async function emptyDir(dir, keep = [], checkExists = !0) {
|
|
|
438
438
|
!keep.some((reg)=>reg.test(toPosixPath(fullPath))) && (entry.isDirectory() ? (await emptyDir(fullPath, keep, !1), keep.length || await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.rmdir(fullPath)) : await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.unlink(fullPath));
|
|
439
439
|
}));
|
|
440
440
|
} catch (err) {
|
|
441
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`
|
|
441
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`failed to empty dir: ${dir}`), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(err);
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
444
|
let hintNodePolyfill = (message)=>{
|
|
@@ -688,7 +688,7 @@ let camelCase = (input)=>input.replace(/[-_](\w)/g, (_, c)=>c.toUpperCase()), pr
|
|
|
688
688
|
}, isTTY = (type = 'stdout')=>('stdin' === type ? process.stdin.isTTY : process.stdout.isTTY) && !process.env.CI;
|
|
689
689
|
function loadEnv({ cwd = process.cwd(), mode = getNodeEnv(), prefixes = [
|
|
690
690
|
'PUBLIC_'
|
|
691
|
-
] } = {}) {
|
|
691
|
+
], processEnv = process.env } = {}) {
|
|
692
692
|
if ('local' === mode) throw Error("[rsbuild:loadEnv] 'local' cannot be used as a value for env mode, because \".env.local\" represents a temporary local file. Please use another value.");
|
|
693
693
|
let filePaths = [
|
|
694
694
|
'.env',
|
|
@@ -696,13 +696,14 @@ function loadEnv({ cwd = process.cwd(), mode = getNodeEnv(), prefixes = [
|
|
|
696
696
|
`.env.${mode}`,
|
|
697
697
|
`.env.${mode}.local`
|
|
698
698
|
].map((filename)=>(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, filename)).filter(isFileSync), parsed = {};
|
|
699
|
-
for (let envPath of filePaths)Object.assign(parsed, (0, main.parse)(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.readFileSync(envPath)));
|
|
700
|
-
parsed.NODE_ENV && (
|
|
701
|
-
parsed
|
|
699
|
+
for (let envPath of filePaths)Object.assign(parsed, (0, main.parse)(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.readFileSync(envPath))), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('loaded env file:', envPath);
|
|
700
|
+
parsed.NODE_ENV && (processEnv.NODE_ENV = parsed.NODE_ENV), (0, lib_main.expand)({
|
|
701
|
+
parsed,
|
|
702
|
+
processEnv
|
|
702
703
|
});
|
|
703
704
|
let publicVars = {}, rawPublicVars = {};
|
|
704
|
-
for (let key of Object.keys(
|
|
705
|
-
let val =
|
|
705
|
+
for (let key of Object.keys(processEnv))if (prefixes.some((prefix)=>key.startsWith(prefix))) {
|
|
706
|
+
let val = processEnv[key];
|
|
706
707
|
publicVars[`import.meta.env.${key}`] = JSON.stringify(val), publicVars[`process.env.${key}`] = JSON.stringify(val), rawPublicVars[key] = val;
|
|
707
708
|
}
|
|
708
709
|
let cleaned = !1;
|
|
@@ -710,7 +711,7 @@ function loadEnv({ cwd = process.cwd(), mode = getNodeEnv(), prefixes = [
|
|
|
710
711
|
parsed,
|
|
711
712
|
cleanup: ()=>{
|
|
712
713
|
if (!cleaned) {
|
|
713
|
-
for (let key of Object.keys(parsed))'NODE_ENV' !== key &&
|
|
714
|
+
for (let key of Object.keys(parsed))'NODE_ENV' !== key && processEnv[key] === parsed[key] && delete processEnv[key];
|
|
714
715
|
cleaned = !0;
|
|
715
716
|
}
|
|
716
717
|
},
|
|
@@ -881,8 +882,8 @@ let cleaners = [], onBeforeRestartServer = (cleaner)=>{
|
|
|
881
882
|
}, beforeRestart = async ({ filePath, clear = !0, id })=>{
|
|
882
883
|
if (clear && clearConsole(), filePath) {
|
|
883
884
|
let filename = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.basename(filePath);
|
|
884
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(`
|
|
885
|
-
} else __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(`
|
|
885
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(`restarting ${id} because ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow(filename)} has changed\n`);
|
|
886
|
+
} else __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(`restarting ${id}...\n`);
|
|
886
887
|
for (let cleaner of cleaners)await cleaner();
|
|
887
888
|
cleaners = [];
|
|
888
889
|
}, restartDevServer = async ({ filePath, clear = !0 } = {})=>{
|
|
@@ -989,7 +990,8 @@ let config_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.create
|
|
|
989
990
|
compress: !0,
|
|
990
991
|
printUrls: !0,
|
|
991
992
|
strictPort: !1,
|
|
992
|
-
cors: !1
|
|
993
|
+
cors: !1,
|
|
994
|
+
middlewareMode: !1
|
|
993
995
|
}), getDefaultSourceConfig = ()=>({
|
|
994
996
|
alias: {},
|
|
995
997
|
define: {},
|
|
@@ -1159,7 +1161,7 @@ async function watchFilesForRestart(files, root, isBuildWatch, watchOptions) {
|
|
|
1159
1161
|
async function config_loadConfig({ cwd = process.cwd(), path, envMode, meta, loader = 'jiti' } = {}) {
|
|
1160
1162
|
let configExport;
|
|
1161
1163
|
let configFilePath = resolveConfigPath(cwd, path);
|
|
1162
|
-
if (!configFilePath) return {
|
|
1164
|
+
if (!configFilePath) return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('no config file found.'), {
|
|
1163
1165
|
content: {},
|
|
1164
1166
|
filePath: configFilePath
|
|
1165
1167
|
};
|
|
@@ -1171,16 +1173,17 @@ async function config_loadConfig({ cwd = process.cwd(), path, envMode, meta, loa
|
|
|
1171
1173
|
configExport = exportModule.default ? exportModule.default : exportModule;
|
|
1172
1174
|
} catch (err) {
|
|
1173
1175
|
if ('native' === loader) throw __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(`Failed to load file with native loader: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(configFilePath)}`), err;
|
|
1174
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`
|
|
1176
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`failed to load file with dynamic import: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(configFilePath)}`);
|
|
1175
1177
|
}
|
|
1176
1178
|
try {
|
|
1177
1179
|
if (void 0 === configExport) {
|
|
1178
|
-
let {
|
|
1179
|
-
|
|
1180
|
-
esmResolve: !0,
|
|
1181
|
-
requireCache: !1,
|
|
1180
|
+
let { createJiti } = await import("jiti"), jiti = createJiti(constants_filename, {
|
|
1181
|
+
moduleCache: !1,
|
|
1182
1182
|
interopDefault: !0
|
|
1183
|
-
})
|
|
1183
|
+
});
|
|
1184
|
+
configExport = await jiti.import(configFilePath, {
|
|
1185
|
+
default: !0
|
|
1186
|
+
});
|
|
1184
1187
|
}
|
|
1185
1188
|
} catch (err) {
|
|
1186
1189
|
throw __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(`Failed to load file with jiti: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(configFilePath)}`), err;
|
|
@@ -1199,7 +1202,7 @@ async function config_loadConfig({ cwd = process.cwd(), path, envMode, meta, loa
|
|
|
1199
1202
|
};
|
|
1200
1203
|
}
|
|
1201
1204
|
if (!isObject(configExport)) throw Error(`[rsbuild:loadConfig] The config must be an object or a function that returns an object, get ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow(configExport)}`);
|
|
1202
|
-
return {
|
|
1205
|
+
return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('loaded config file:', configFilePath), {
|
|
1203
1206
|
content: applyMetaInfo(configExport),
|
|
1204
1207
|
filePath: configFilePath
|
|
1205
1208
|
};
|
|
@@ -1239,13 +1242,13 @@ async function outputInspectConfigFiles({ rawBundlerConfigs, rawEnvironmentConfi
|
|
|
1239
1242
|
...rawEnvironmentConfigs.map(({ name, content })=>{
|
|
1240
1243
|
if (1 === rawEnvironmentConfigs.length) return {
|
|
1241
1244
|
path: (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'rsbuild.config.mjs'),
|
|
1242
|
-
label: 'Rsbuild
|
|
1245
|
+
label: 'Rsbuild config',
|
|
1243
1246
|
content
|
|
1244
1247
|
};
|
|
1245
1248
|
let outputFile = `rsbuild.config.${name}.mjs`;
|
|
1246
1249
|
return {
|
|
1247
1250
|
path: (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, outputFile),
|
|
1248
|
-
label: `Rsbuild
|
|
1251
|
+
label: `Rsbuild config (${name})`,
|
|
1249
1252
|
content
|
|
1250
1253
|
};
|
|
1251
1254
|
}),
|
|
@@ -1262,7 +1265,7 @@ async function outputInspectConfigFiles({ rawBundlerConfigs, rawEnvironmentConfi
|
|
|
1262
1265
|
recursive: !0
|
|
1263
1266
|
}), await Promise.all(files.map(async (item)=>__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.writeFile(item.path, `export default ${item.content}`)));
|
|
1264
1267
|
let fileInfos = files.map((item)=>` - ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.bold(__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow(item.label))}: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.underline(item.path)}`).join('\n');
|
|
1265
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.success(`
|
|
1268
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.success(`config inspection completed, generated files: \n\n${fileInfos}\n`);
|
|
1266
1269
|
}
|
|
1267
1270
|
function stringifyConfig(config, verbose) {
|
|
1268
1271
|
return (0, __WEBPACK_EXTERNAL_MODULE__compiled_rspack_chain_index_js_b67fefbd__.default.toString)(config, {
|
|
@@ -1648,7 +1651,7 @@ async function updateEnvironmentContext(context, configs) {
|
|
|
1648
1651
|
async function createContext(options, userConfig, bundlerType) {
|
|
1649
1652
|
let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
|
|
1650
1653
|
return {
|
|
1651
|
-
version: "1.2.
|
|
1654
|
+
version: "1.2.12",
|
|
1652
1655
|
rootPath,
|
|
1653
1656
|
distPath: '',
|
|
1654
1657
|
cachePath,
|
|
@@ -1879,7 +1882,10 @@ let configChain_CHAIN_ID = {
|
|
|
1879
1882
|
api.modifyBundlerChain((chain, { isProd, environment })=>{
|
|
1880
1883
|
let { config } = environment, getMergedFilename = (assetType)=>{
|
|
1881
1884
|
let distDir = config.output.distPath[assetType], filename = getFilename(config, assetType, isProd);
|
|
1882
|
-
return
|
|
1885
|
+
return 'function' == typeof filename ? (...args)=>{
|
|
1886
|
+
let name = filename(...args);
|
|
1887
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.posix.join(distDir, name);
|
|
1888
|
+
} : __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.posix.join(distDir, filename);
|
|
1883
1889
|
}, createAssetRule = (assetType, exts, emit)=>{
|
|
1884
1890
|
let regExp = function(exts) {
|
|
1885
1891
|
let matcher = exts.map((ext)=>ext.trim()).map((ext)=>ext.startsWith('.') ? ext.slice(1) : ext).join('|');
|
|
@@ -1963,7 +1969,7 @@ async function validateWebpackCache(cacheDirectory, buildDependencies) {
|
|
|
1963
1969
|
try {
|
|
1964
1970
|
prevBuildDependencies = JSON.parse(rawConfigFile);
|
|
1965
1971
|
} catch (e) {
|
|
1966
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('
|
|
1972
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('failed to parse the previous buildDependencies.json', e);
|
|
1967
1973
|
}
|
|
1968
1974
|
if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) return;
|
|
1969
1975
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.rm(cacheDirectory, {
|
|
@@ -3166,7 +3172,7 @@ let getPort = async ({ host, port, strictPort, tryLimits = 20 })=>{
|
|
|
3166
3172
|
host,
|
|
3167
3173
|
port: originalPort,
|
|
3168
3174
|
strictPort: config.server.strictPort || !1
|
|
3169
|
-
}), https = !!config.server.https, portTip = port !== originalPort ? `
|
|
3175
|
+
}), https = !!config.server.https, portTip = port !== originalPort ? `port ${originalPort} is in use, ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow(`using port ${port}.`)}` : void 0;
|
|
3170
3176
|
return {
|
|
3171
3177
|
port,
|
|
3172
3178
|
host,
|
|
@@ -3267,9 +3273,9 @@ async function openBrowser(url) {
|
|
|
3267
3273
|
if (targetBrowser) return await execAsync(`osascript openChrome.applescript "${encodeURI(url)}" "${targetBrowser}"`, {
|
|
3268
3274
|
cwd: STATIC_PATH
|
|
3269
3275
|
}), !0;
|
|
3270
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('
|
|
3276
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('failed to find the target browser.');
|
|
3271
3277
|
} catch (err) {
|
|
3272
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug("
|
|
3278
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug("failed to open start URL with apple script."), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(err);
|
|
3273
3279
|
}
|
|
3274
3280
|
try {
|
|
3275
3281
|
let { default: open } = await import("../compiled/open/index.js");
|
|
@@ -3554,7 +3560,7 @@ class HtmlPreloadOrPrefetchPlugin {
|
|
|
3554
3560
|
}({
|
|
3555
3561
|
href,
|
|
3556
3562
|
file
|
|
3557
|
-
}), 'font' === attributes.as && (attributes.crossorigin = ''), ("script" === attributes.as || 'style' === attributes.as) && crossOriginLoading &&
|
|
3563
|
+
}), 'font' === attributes.as && (attributes.crossorigin = ''), ("script" === attributes.as || 'style' === attributes.as) && crossOriginLoading && ('use-credentials' === crossOriginLoading || '/' !== publicPath) && (attributes.crossorigin = 'anonymous' === crossOriginLoading ? '' : crossOriginLoading)), links.push({
|
|
3558
3564
|
tagName: 'link',
|
|
3559
3565
|
attributes,
|
|
3560
3566
|
voidTag: !0,
|
|
@@ -3698,7 +3704,7 @@ let resourceHints_generateLinks = (options, rel)=>options.map((option)=>({
|
|
|
3698
3704
|
}), api.onExit(()=>{
|
|
3699
3705
|
enableProfileTrace && __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.default.experiments.globalTrace.cleanup();
|
|
3700
3706
|
let profileDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(api.context.distPath, profileDirName);
|
|
3701
|
-
stopProfiler(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(profileDir, 'jscpuprofile.json'), profileSession), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(`
|
|
3707
|
+
stopProfiler(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(profileDir, 'jscpuprofile.json'), profileSession), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(`saved Rspack profile file to ${profileDir}`);
|
|
3702
3708
|
});
|
|
3703
3709
|
}
|
|
3704
3710
|
}), pluginServer = ()=>({
|
|
@@ -4517,17 +4523,19 @@ class SocketServer {
|
|
|
4517
4523
|
this.wsServer.emit('connection', connection, req);
|
|
4518
4524
|
});
|
|
4519
4525
|
}
|
|
4526
|
+
clearHeartbeatTimer() {
|
|
4527
|
+
this.heartbeatTimer && (clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
|
|
4528
|
+
}
|
|
4520
4529
|
async prepare() {
|
|
4521
4530
|
var _this_options_client;
|
|
4531
|
+
this.clearHeartbeatTimer();
|
|
4522
4532
|
let { default: ws } = await import("../compiled/ws/index.js");
|
|
4523
4533
|
this.wsServer = new ws.Server({
|
|
4524
4534
|
noServer: !0,
|
|
4525
4535
|
path: null === (_this_options_client = this.options.client) || void 0 === _this_options_client ? void 0 : _this_options_client.path
|
|
4526
4536
|
}), this.wsServer.on('error', (err)=>{
|
|
4527
4537
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(err);
|
|
4528
|
-
}), this.
|
|
4529
|
-
for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
|
|
4530
|
-
}, 30000), this.wsServer.on('connection', (socket, req)=>{
|
|
4538
|
+
}), this.heartbeatTimer = setTimeout(this.checkSockets, 30000), this.wsServer.on('connection', (socket, req)=>{
|
|
4531
4539
|
let queryStr = req.url ? req.url.split('?')[1] : '';
|
|
4532
4540
|
this.onConnect(socket, queryStr ? (0, __WEBPACK_EXTERNAL_MODULE_node_querystring_aeb3c0b4__.parse)(queryStr) : {});
|
|
4533
4541
|
});
|
|
@@ -4552,23 +4560,28 @@ class SocketServer {
|
|
|
4552
4560
|
compilationId
|
|
4553
4561
|
}));
|
|
4554
4562
|
}
|
|
4555
|
-
close() {
|
|
4563
|
+
async close() {
|
|
4564
|
+
for (let socket of (this.clearHeartbeatTimer(), this.wsServer.removeAllListeners(), this.wsServer.clients))socket.terminate();
|
|
4556
4565
|
for (let socket of this.sockets)socket.close();
|
|
4557
|
-
this.
|
|
4566
|
+
return this.stats = {}, this.initialChunks = {}, this.sockets.length = 0, new Promise((resolve, reject)=>{
|
|
4567
|
+
this.wsServer.close((err)=>{
|
|
4568
|
+
err ? reject(err) : resolve();
|
|
4569
|
+
});
|
|
4570
|
+
});
|
|
4558
4571
|
}
|
|
4559
4572
|
onConnect(socket, params) {
|
|
4560
4573
|
socket.isAlive = !0, socket.on('pong', ()=>{
|
|
4561
4574
|
socket.isAlive = !0;
|
|
4562
|
-
}),
|
|
4563
|
-
let
|
|
4564
|
-
|
|
4575
|
+
}), this.sockets.push(socket), socket.on('close', ()=>{
|
|
4576
|
+
let index = this.sockets.indexOf(socket);
|
|
4577
|
+
index >= 0 && this.sockets.splice(index, 1);
|
|
4565
4578
|
}), (this.options.hmr || this.options.liveReload) && this.singleWrite(socket, {
|
|
4566
4579
|
type: 'hot',
|
|
4567
4580
|
compilationId: params.compilationId
|
|
4568
4581
|
}), this.stats && this.sendStats({
|
|
4569
4582
|
force: !0,
|
|
4570
4583
|
compilationId: params.compilationId
|
|
4571
|
-
})
|
|
4584
|
+
});
|
|
4572
4585
|
}
|
|
4573
4586
|
getStats(name) {
|
|
4574
4587
|
let curStats = this.stats[name];
|
|
@@ -4773,7 +4786,10 @@ class SocketServer {
|
|
|
4773
4786
|
1 === connection.readyState && connection.send(message);
|
|
4774
4787
|
}
|
|
4775
4788
|
constructor(options){
|
|
4776
|
-
socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", []), socketServer_define_property(this, "options", void 0), socketServer_define_property(this, "stats", void 0), socketServer_define_property(this, "initialChunks", void 0), socketServer_define_property(this, "
|
|
4789
|
+
socketServer_define_property(this, "wsServer", void 0), socketServer_define_property(this, "sockets", []), socketServer_define_property(this, "options", void 0), socketServer_define_property(this, "stats", void 0), socketServer_define_property(this, "initialChunks", void 0), socketServer_define_property(this, "heartbeatTimer", null), socketServer_define_property(this, "checkSockets", ()=>{
|
|
4790
|
+
for (let socket of this.wsServer.clients)socket.isAlive ? (socket.isAlive = !1, socket.ping(()=>{})) : socket.terminate();
|
|
4791
|
+
null !== this.heartbeatTimer && (this.heartbeatTimer = setTimeout(this.checkSockets, 30000));
|
|
4792
|
+
}), this.options = options, this.stats = {}, this.initialChunks = {};
|
|
4777
4793
|
}
|
|
4778
4794
|
}
|
|
4779
4795
|
function compilerDevMiddleware_define_property(obj, key, value) {
|
|
@@ -4806,7 +4822,7 @@ class CompilerDevMiddleware {
|
|
|
4806
4822
|
this.socketServer.upgrade(req, sock, head);
|
|
4807
4823
|
}
|
|
4808
4824
|
async close() {
|
|
4809
|
-
this.socketServer.close(), this.middleware && await new Promise((resolve)=>{
|
|
4825
|
+
await this.socketServer.close(), this.middleware && await new Promise((resolve)=>{
|
|
4810
4826
|
this.middleware.close(()=>{
|
|
4811
4827
|
resolve();
|
|
4812
4828
|
});
|
|
@@ -5496,7 +5512,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
5496
5512
|
environment
|
|
5497
5513
|
}))
|
|
5498
5514
|
}
|
|
5499
|
-
])), { default: connect } = await import("../compiled/connect/index.js"), middlewares = connect(), httpServer = await createHttpServer({
|
|
5515
|
+
])), { default: connect } = await import("../compiled/connect/index.js"), middlewares = connect(), httpServer = config.server.middlewareMode ? null : await createHttpServer({
|
|
5500
5516
|
serverConfig: config.server,
|
|
5501
5517
|
middlewares
|
|
5502
5518
|
}), devServerAPI = {
|
|
@@ -5505,6 +5521,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
5505
5521
|
environments: environmentAPI,
|
|
5506
5522
|
httpServer,
|
|
5507
5523
|
listen: async ()=>{
|
|
5524
|
+
if (!httpServer) throw Error('[rsbuild:server] Can not listen dev server as `server.middlewareMode` is enabled.');
|
|
5508
5525
|
let serverTerminator = getServerTerminator(httpServer);
|
|
5509
5526
|
return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('listen dev server'), options.context.hooks.onCloseDevServer.tap(serverTerminator), new Promise((resolve)=>{
|
|
5510
5527
|
httpServer.listen({
|
|
@@ -5560,6 +5577,12 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
5560
5577
|
})).middlewares))Array.isArray(item) ? middlewares.use(...item) : middlewares.use(item);
|
|
5561
5578
|
return __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('create dev server done'), devServerAPI;
|
|
5562
5579
|
}
|
|
5580
|
+
function cutPath(filePath, root) {
|
|
5581
|
+
let prefix = root.endsWith(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep) ? root : root + __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep;
|
|
5582
|
+
if (filePath.startsWith(prefix)) return filePath.slice(prefix.length);
|
|
5583
|
+
let parts = filePath.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep).filter(Boolean);
|
|
5584
|
+
return parts.length > 3 ? parts.slice(-3).join(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep) : parts.join(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep);
|
|
5585
|
+
}
|
|
5563
5586
|
async function createCompiler_createCompiler(options) {
|
|
5564
5587
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug('create compiler');
|
|
5565
5588
|
let { context } = options, { rspackConfigs } = await initConfigs(options);
|
|
@@ -5568,10 +5591,20 @@ async function createCompiler_createCompiler(options) {
|
|
|
5568
5591
|
environments: context.environments
|
|
5569
5592
|
}), !await isSatisfyRspackVersion(__WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack.rspackVersion)) throw Error(`[rsbuild] The current Rspack version does not meet the requirements, the minimum supported version of Rspack is ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.green(rspackMinVersion)}`);
|
|
5570
5593
|
let compiler = 1 === rspackConfigs.length ? (0, __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack)(rspackConfigs[0]) : (0, __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack)(rspackConfigs), isVersionLogged = !1, isCompiling = !1, logRspackVersion = ()=>{
|
|
5571
|
-
isVersionLogged || (__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`
|
|
5594
|
+
isVersionLogged || (__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`use Rspack v${__WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack.rspackVersion}`), isVersionLogged = !0);
|
|
5572
5595
|
};
|
|
5573
|
-
compiler.hooks.watchRun.tap('rsbuild:compiling', ()=>{
|
|
5574
|
-
logRspackVersion(), isCompiling
|
|
5596
|
+
compiler.hooks.watchRun.tap('rsbuild:compiling', (compiler)=>{
|
|
5597
|
+
if (logRspackVersion(), !isCompiling) {
|
|
5598
|
+
let changedFiles = compiler.modifiedFiles ? Array.from(compiler.modifiedFiles) : [], removedFiles = compiler.removedFiles ? Array.from(compiler.removedFiles) : [];
|
|
5599
|
+
if (changedFiles.length) {
|
|
5600
|
+
let fileInfo = __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(changedFiles.map((file)=>cutPath(file, context.rootPath)).join(', '));
|
|
5601
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.start(`building ${fileInfo}`);
|
|
5602
|
+
} else if (removedFiles.length) {
|
|
5603
|
+
let fileInfo = removedFiles.map((file)=>cutPath(file, context.rootPath)).join(', ');
|
|
5604
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.start(`building ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(`removed ${fileInfo}`)}`);
|
|
5605
|
+
} else __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.start('build started...');
|
|
5606
|
+
}
|
|
5607
|
+
isCompiling = !0;
|
|
5575
5608
|
}), 'build' === context.command && compiler.hooks.run.tap('rsbuild:run', logRspackVersion);
|
|
5576
5609
|
let done = (stats)=>{
|
|
5577
5610
|
let statsOptions = getStatsOptions(compiler), statsJson = stats.toJson({
|
|
@@ -5583,7 +5616,7 @@ async function createCompiler_createCompiler(options) {
|
|
|
5583
5616
|
}), printTime = (c, index)=>{
|
|
5584
5617
|
if (c.time) {
|
|
5585
5618
|
let time = prettyTime(c.time / 1000), { name } = rspackConfigs[index], suffix = name ? __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.gray(` (${name})`) : '';
|
|
5586
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.ready(`
|
|
5619
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.ready(`built in ${time}${suffix}`);
|
|
5587
5620
|
}
|
|
5588
5621
|
}, hasErrors = stats.hasErrors();
|
|
5589
5622
|
if (!hasErrors) {
|
|
@@ -6578,12 +6611,12 @@ async function runCLI() {
|
|
|
6578
6611
|
}
|
|
6579
6612
|
}(), process.title = 'rsbuild-node';
|
|
6580
6613
|
let { npm_execpath } = process.env;
|
|
6581
|
-
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.2.
|
|
6614
|
+
(!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.2.12\n`);
|
|
6582
6615
|
}();
|
|
6583
6616
|
try {
|
|
6584
6617
|
!function() {
|
|
6585
6618
|
let cli = dist('rsbuild');
|
|
6586
|
-
cli.help(), cli.version("1.2.
|
|
6619
|
+
cli.help(), cli.version("1.2.12"), applyCommonOptions(cli);
|
|
6587
6620
|
let devCommand = cli.command('dev', 'starting the dev server'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
|
|
6588
6621
|
applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
|
|
6589
6622
|
try {
|
|
@@ -6634,6 +6667,6 @@ async function runCLI() {
|
|
|
6634
6667
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error('Failed to start Rsbuild CLI.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(err);
|
|
6635
6668
|
}
|
|
6636
6669
|
}
|
|
6637
|
-
let src_version = "1.2.
|
|
6670
|
+
let src_version = "1.2.12";
|
|
6638
6671
|
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack;
|
|
6639
6672
|
export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, createRsbuild, defineConfig, ensureAssetPrefix, config_loadConfig as loadConfig, loadEnv, mergeRsbuildConfig, runCLI, src_version as version, __webpack_exports__logger as logger, __webpack_exports__rspack as rspack };
|
|
@@ -27,9 +27,9 @@ export declare const urlJoin: (base: string, path: string) => string;
|
|
|
27
27
|
export declare const canParse: (url: string) => boolean;
|
|
28
28
|
export declare const parseUrl: (url: string) => URL | null;
|
|
29
29
|
export declare const ensureAssetPrefix: (url: string, assetPrefix?: Rspack.PublicPath) => string;
|
|
30
|
-
export declare function getFilename(config: NormalizedConfig | NormalizedEnvironmentConfig, type: 'js', isProd: boolean, isServer?: boolean):
|
|
31
|
-
export declare function getFilename(config: NormalizedConfig | NormalizedEnvironmentConfig, type: 'css', isProd: boolean):
|
|
32
|
-
export declare function getFilename(config: NormalizedConfig | NormalizedEnvironmentConfig, type: Exclude<keyof FilenameConfig, 'js' | 'css'>, isProd: boolean, isServer?: boolean):
|
|
30
|
+
export declare function getFilename(config: NormalizedConfig | NormalizedEnvironmentConfig, type: 'js', isProd: boolean, isServer?: boolean): Rspack.Filename;
|
|
31
|
+
export declare function getFilename(config: NormalizedConfig | NormalizedEnvironmentConfig, type: 'css', isProd: boolean): Rspack.CssFilename;
|
|
32
|
+
export declare function getFilename(config: NormalizedConfig | NormalizedEnvironmentConfig, type: Exclude<keyof FilenameConfig, 'js' | 'css'>, isProd: boolean, isServer?: boolean): Rspack.AssetModuleFilename;
|
|
33
33
|
export declare function partition<T>(array: T[], predicate: (value: T) => boolean): [T[], T[]];
|
|
34
34
|
export declare const applyToCompiler: (compiler: Rspack.Compiler | Rspack.MultiCompiler, apply: (c: Rspack.Compiler, index: number) => void) => void;
|
|
35
35
|
export declare const upperFirst: (str: string) => string;
|
package/dist-types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { rspack } from '@rspack/core';
|
|
|
6
6
|
import type * as Rspack from '@rspack/core';
|
|
7
7
|
export { loadEnv } from './loadEnv';
|
|
8
8
|
export { createRsbuild } from './createRsbuild';
|
|
9
|
-
export { loadConfig, defineConfig, type LoadConfigOptions, type LoadConfigResult, } from './config';
|
|
9
|
+
export { loadConfig, defineConfig, type ConfigParams, type LoadConfigOptions, type LoadConfigResult, } from './config';
|
|
10
10
|
export { runCLI } from './cli';
|
|
11
11
|
export declare const version: string;
|
|
12
12
|
export { rspack };
|
package/dist-types/loadEnv.d.ts
CHANGED
|
@@ -14,11 +14,21 @@ export type LoadEnvOptions = {
|
|
|
14
14
|
* @default ['PUBLIC_']
|
|
15
15
|
*/
|
|
16
16
|
prefixes?: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Specify a target object to store environment variables.
|
|
19
|
+
* If not provided, variables will be written to `process.env`.
|
|
20
|
+
* @default process.env
|
|
21
|
+
*/
|
|
22
|
+
processEnv?: Record<string, string>;
|
|
17
23
|
};
|
|
18
|
-
export declare function loadEnv({ cwd, mode, prefixes, }?: LoadEnvOptions): {
|
|
19
|
-
/**
|
|
24
|
+
export declare function loadEnv({ cwd, mode, prefixes, processEnv, }?: LoadEnvOptions): {
|
|
25
|
+
/**
|
|
26
|
+
* All env variables in the .env file
|
|
27
|
+
*/
|
|
20
28
|
parsed: Record<string, string>;
|
|
21
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* The absolute paths to all env files
|
|
31
|
+
*/
|
|
22
32
|
filePaths: string[];
|
|
23
33
|
/**
|
|
24
34
|
* Env variables that start with prefixes.
|
|
@@ -45,6 +55,8 @@ export declare function loadEnv({ cwd, mode, prefixes, }?: LoadEnvOptions): {
|
|
|
45
55
|
* ```
|
|
46
56
|
**/
|
|
47
57
|
publicVars: Record<string, string>;
|
|
48
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Clear the env variables mounted on `process.env`
|
|
60
|
+
*/
|
|
49
61
|
cleanup: () => void;
|
|
50
62
|
};
|
package/dist-types/logger.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging message case convention:
|
|
3
|
+
*
|
|
4
|
+
* Info, ready, success and debug messages:
|
|
5
|
+
* - Start with lowercase
|
|
6
|
+
* - Example: "info build started..."
|
|
7
|
+
*
|
|
8
|
+
* Errors and warnings:
|
|
9
|
+
* - Start with uppercase
|
|
10
|
+
* - Example: "error Failed to build"
|
|
11
|
+
*
|
|
12
|
+
* This convention helps distinguish between normal operations
|
|
13
|
+
* and important alerts that require attention.
|
|
14
|
+
*/
|
|
1
15
|
import { type Logger, logger } from '../compiled/rslog/index.js';
|
|
2
16
|
export declare const isDebug: () => boolean;
|
|
3
17
|
export { logger };
|
|
@@ -11,7 +11,8 @@ export type RsbuildDevServer = {
|
|
|
11
11
|
middlewares: Connect.Server;
|
|
12
12
|
/**
|
|
13
13
|
* The Node.js HTTP server instance.
|
|
14
|
-
* Will be `Http2SecureServer` if `server.https` config is used.
|
|
14
|
+
* - Will be `Http2SecureServer` if `server.https` config is used.
|
|
15
|
+
* - Will be `null` if `server.middlewareMode` is enabled.
|
|
15
16
|
*/
|
|
16
17
|
httpServer: import('node:http').Server | import('node:http2').Http2SecureServer | null;
|
|
17
18
|
/**
|
|
@@ -12,14 +12,16 @@ export declare class SocketServer {
|
|
|
12
12
|
private readonly options;
|
|
13
13
|
private stats;
|
|
14
14
|
private initialChunks;
|
|
15
|
-
private
|
|
15
|
+
private heartbeatTimer;
|
|
16
16
|
constructor(options: DevConfig);
|
|
17
17
|
upgrade(req: IncomingMessage, sock: Socket, head: any): void;
|
|
18
|
+
private checkSockets;
|
|
19
|
+
private clearHeartbeatTimer;
|
|
18
20
|
prepare(): Promise<void>;
|
|
19
21
|
updateStats(stats: Rspack.Stats): void;
|
|
20
22
|
sockWrite({ type, compilationId, data }: SocketMessage): void;
|
|
21
23
|
private singleWrite;
|
|
22
|
-
close(): void
|
|
24
|
+
close(): Promise<void>;
|
|
23
25
|
private onConnect;
|
|
24
26
|
private getStats;
|
|
25
27
|
private sendStats;
|