@rsbuild/core 1.3.0-beta.0 → 1.3.0-beta.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/dist/index.cjs CHANGED
@@ -1166,7 +1166,7 @@ var __webpack_exports__ = {};
1166
1166
  rslog_index_js_namespaceObject.logger.debug(`failed to empty dir: ${dir}`), rslog_index_js_namespaceObject.logger.debug(err);
1167
1167
  }
1168
1168
  }
1169
- let hintNodePolyfill = (message)=>{
1169
+ let formatFileName = (fileName)=>/:\d+:\d+/.test(fileName) ? `File: ${index_js_default().cyan(fileName)}\n` : `File: ${index_js_default().cyan(fileName)}:1:1\n`, hintNodePolyfill = (message)=>{
1170
1170
  let getTips = (moduleName)=>{
1171
1171
  let tips = [
1172
1172
  `Tip: "${moduleName}" is a built-in Node.js module. It cannot be imported in client-side code.`,
@@ -1228,11 +1228,11 @@ var __webpack_exports__ = {};
1228
1228
  let matched = stats.moduleIdentifier.match(/(?:\!|^)([^!]+)$/);
1229
1229
  if (matched) {
1230
1230
  let fileName = matched.pop();
1231
- if (fileName) return `File: ${fileName}:1:1\n`;
1231
+ if (fileName) return formatFileName(fileName);
1232
1232
  }
1233
1233
  }
1234
1234
  let file = stats.file || stats.moduleName;
1235
- return file ? `File: ${file}\n` : '';
1235
+ return file ? formatFileName(file) : '';
1236
1236
  }(stats), mainMessage = stats.message, details = verbose && stats.details ? `\nDetails: ${stats.details}\n` : '', stack = verbose && stats.stack ? `\n${stats.stack}` : '', moduleTrace = function(stats) {
1237
1237
  let traceStr = '';
1238
1238
  if (stats.moduleTrace) for (let trace of stats.moduleTrace)trace.originName && (traceStr += `\n @ ${trace.originName}`);
@@ -1314,10 +1314,10 @@ var __webpack_exports__ = {};
1314
1314
  }, verbose);
1315
1315
  return {
1316
1316
  message: function(errors) {
1317
- let title = index_js_default().bold(index_js_default().red('Compile error: '));
1317
+ let title = index_js_default().bold(index_js_default().red('Build error: '));
1318
1318
  if (!errors.length) return `${title}\n${index_js_default().yellow("For more details, please setting 'stats.errors: true' ")}`;
1319
- let tip = index_js_default().yellow('Failed to compile, check the errors for troubleshooting.'), text = `${errors.join('\n\n')}\n`;
1320
- return `${title}\n${tip}\n${text}`;
1319
+ let text = `${errors.join('\n\n')}\n`;
1320
+ return `${title}\n${text}`;
1321
1321
  }(errors),
1322
1322
  level: 'error'
1323
1323
  };
@@ -1560,146 +1560,7 @@ var __webpack_exports__ = {};
1560
1560
  merged[key] = merge(x[key], y[key], childPath);
1561
1561
  }
1562
1562
  return merged;
1563
- }, mergeRsbuildConfig = (...configs)=>2 === configs.length ? merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>merge(result, config), {}), commonOpts = {}, getEnvDir = (cwd, envDir)=>envDir ? external_node_path_default().isAbsolute(envDir) ? envDir : external_node_path_default().join(cwd, envDir) : cwd, init_loadConfig = async (root)=>{
1564
- var _config_server;
1565
- let { content: config, filePath } = await config_loadConfig({
1566
- cwd: root,
1567
- path: commonOpts.config,
1568
- envMode: commonOpts.envMode,
1569
- loader: commonOpts.configLoader
1570
- });
1571
- return config.dev ||= {}, config.source ||= {}, config.server ||= {}, commonOpts.base && (config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), !commonOpts.open || (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.open) || (config.server.open = commonOpts.open), commonOpts.host && (config.server.host = commonOpts.host), commonOpts.port && (config.server.port = commonOpts.port), void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), filePath && (config.dev.watchFiles = [
1572
- ...config.dev.watchFiles ? castArray(config.dev.watchFiles) : [],
1573
- {
1574
- paths: filePath,
1575
- type: 'reload-server'
1576
- }
1577
- ]), config;
1578
- };
1579
- async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
1580
- cliOptions && (commonOpts = cliOptions);
1581
- try {
1582
- let cwd = process.cwd(), root = commonOpts.root ? getAbsolutePath(cwd, commonOpts.root) : cwd, rsbuild = await createRsbuild({
1583
- cwd: root,
1584
- rsbuildConfig: ()=>init_loadConfig(root),
1585
- environment: commonOpts.environment,
1586
- loadEnv: {
1587
- cwd: getEnvDir(root, commonOpts.envDir),
1588
- mode: commonOpts.envMode
1589
- }
1590
- });
1591
- return rsbuild.onBeforeCreateCompiler(()=>{
1592
- let command = process.argv[2];
1593
- if ('dev' === command || isBuildWatch) {
1594
- var _config_dev;
1595
- let files = [], config = rsbuild.getNormalizedConfig();
1596
- if (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.watchFiles) for (let watchFilesConfig of castArray(config.dev.watchFiles)){
1597
- if ('reload-server' !== watchFilesConfig.type) continue;
1598
- let paths = castArray(watchFilesConfig.paths);
1599
- watchFilesConfig.options ? watchFilesForRestart(paths, root, isBuildWatch, watchFilesConfig.options) : files.push(...paths);
1600
- }
1601
- watchFilesForRestart(files, root, isBuildWatch);
1602
- }
1603
- }), rsbuild;
1604
- } catch (err) {
1605
- if (isRestart) rslog_index_js_namespaceObject.logger.error(err);
1606
- else throw err;
1607
- }
1608
- }
1609
- let cleaners = [], onBeforeRestartServer = (cleaner)=>{
1610
- cleaners.push(cleaner);
1611
- }, clearConsole = ()=>{
1612
- isTTY() && !process.env.DEBUG && process.stdout.write('\x1B[H\x1B[2J');
1613
- }, beforeRestart = async ({ filePath, clear = !0, id })=>{
1614
- if (clear && clearConsole(), filePath) {
1615
- let filename = external_node_path_default().basename(filePath);
1616
- rslog_index_js_namespaceObject.logger.info(`restarting ${id} because ${index_js_default().yellow(filename)} has changed\n`);
1617
- } else rslog_index_js_namespaceObject.logger.info(`restarting ${id}...\n`);
1618
- for (let cleaner of cleaners)await cleaner();
1619
- cleaners = [];
1620
- }, restartDevServer = async ({ filePath, clear = !0 } = {})=>{
1621
- await beforeRestart({
1622
- filePath,
1623
- clear,
1624
- id: 'server'
1625
- });
1626
- let rsbuild = await init({
1627
- isRestart: !0
1628
- });
1629
- rsbuild && await rsbuild.startDevServer();
1630
- }, restartBuild = async ({ filePath, clear = !0 } = {})=>{
1631
- await beforeRestart({
1632
- filePath,
1633
- clear,
1634
- id: 'build'
1635
- });
1636
- let rsbuild = await init({
1637
- isRestart: !0,
1638
- isBuildWatch: !0
1639
- });
1640
- rsbuild && onBeforeRestartServer((await rsbuild.build({
1641
- watch: !0
1642
- })).close);
1643
- };
1644
- async function setupWatchFiles(options) {
1645
- let { dev, server, root, compileMiddlewareAPI } = options, { hmr, liveReload } = dev;
1646
- if (!hmr && !liveReload || !compileMiddlewareAPI) return;
1647
- let closeDevFilesWatcher = await watchDevFiles(dev, compileMiddlewareAPI, root), serverFilesWatcher = await function(serverConfig, compileMiddlewareAPI, root) {
1648
- let publicDirs = normalizePublicDirs(serverConfig.publicDir);
1649
- if (!publicDirs.length) return;
1650
- let watchPaths = publicDirs.filter((item)=>item.watch).map((item)=>item.name);
1651
- if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths), compileMiddlewareAPI, root);
1652
- }(server, compileMiddlewareAPI, root);
1653
- return {
1654
- async close () {
1655
- await Promise.all([
1656
- null == closeDevFilesWatcher ? void 0 : closeDevFilesWatcher(),
1657
- null == serverFilesWatcher ? void 0 : serverFilesWatcher.close()
1658
- ]);
1659
- }
1660
- };
1661
- }
1662
- async function watchDevFiles(devConfig, compileMiddlewareAPI, root) {
1663
- let { watchFiles } = devConfig;
1664
- if (!watchFiles) return;
1665
- let watchers = [];
1666
- for (let { paths, options, type } of castArray(watchFiles)){
1667
- let watchOptions = prepareWatchOptions(paths, options, type), watcher = await startWatchFiles(watchOptions, compileMiddlewareAPI, root);
1668
- watcher && watchers.push(watcher);
1669
- }
1670
- return async ()=>{
1671
- for (let watcher of watchers)await watcher.close();
1672
- };
1673
- }
1674
- function prepareWatchOptions(paths, options = {}, type) {
1675
- return {
1676
- paths: 'string' == typeof paths ? [
1677
- paths
1678
- ] : paths,
1679
- options,
1680
- type
1681
- };
1682
- }
1683
- let GLOB_REGEX = /[*?{}[\]()!@+|]/, isGlob = (str)=>GLOB_REGEX.test(str);
1684
- async function createChokidar(pathOrGlobs, root, options) {
1685
- let chokidar = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/chokidar/index.js")), watchFiles = new Set(), globPatterns = pathOrGlobs.filter((pathOrGlob)=>!!isGlob(pathOrGlob) || (watchFiles.add(pathOrGlob), !1));
1686
- if (globPatterns.length) {
1687
- let tinyglobby = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/tinyglobby/index.js")), { glob } = tinyglobby.default || tinyglobby;
1688
- for (let file of (await glob(globPatterns, {
1689
- cwd: root,
1690
- absolute: !0
1691
- })))watchFiles.add(file);
1692
- }
1693
- return chokidar.watch(Array.from(watchFiles), options);
1694
- }
1695
- async function startWatchFiles({ paths, options, type = 'reload-page' }, compileMiddlewareAPI, root) {
1696
- if ('reload-page' !== type) return;
1697
- let watcher = await createChokidar(paths, root, options);
1698
- return watcher.on('change', ()=>{
1699
- compileMiddlewareAPI.sockWrite('static-changed');
1700
- }), watcher;
1701
- }
1702
- let config_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), getDefaultDevConfig = ()=>({
1563
+ }, mergeRsbuildConfig = (...configs)=>2 === configs.length ? merge(configs[0], configs[1]) : configs.length < 2 ? configs[0] : configs.reduce((result, config)=>merge(result, config), {}), config_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), getDefaultDevConfig = ()=>({
1703
1564
  hmr: !0,
1704
1565
  liveReload: !0,
1705
1566
  assetPrefix: DEFAULT_ASSET_PREFIX,
@@ -1868,27 +1729,6 @@ var __webpack_exports__ = {};
1868
1729
  }
1869
1730
  return null;
1870
1731
  };
1871
- async function watchFilesForRestart(files, root, isBuildWatch, watchOptions) {
1872
- var func;
1873
- let timeoutId;
1874
- if (!files.length) return;
1875
- let watcher = await createChokidar(files, root, {
1876
- ignoreInitial: !0,
1877
- ignorePermissionErrors: !0,
1878
- ...watchOptions
1879
- }), callback = (func = async (filePath)=>{
1880
- await watcher.close(), isBuildWatch ? await restartBuild({
1881
- filePath
1882
- }) : await restartDevServer({
1883
- filePath
1884
- });
1885
- }, timeoutId = null, (...args)=>{
1886
- null !== timeoutId && clearTimeout(timeoutId), timeoutId = setTimeout(()=>{
1887
- func(...args);
1888
- }, 300);
1889
- });
1890
- watcher.on('add', callback), watcher.on('change', callback), watcher.on('unlink', callback);
1891
- }
1892
1732
  async function config_loadConfig({ cwd = process.cwd(), path, envMode, meta, loader = 'jiti' } = {}) {
1893
1733
  let configExport;
1894
1734
  let configFilePath = resolveConfigPath(cwd, path);
@@ -2382,7 +2222,7 @@ var __webpack_exports__ = {};
2382
2222
  async function createContext(options, userConfig) {
2383
2223
  let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_namespaceObject.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
2384
2224
  return {
2385
- version: "1.3.0-beta.0",
2225
+ version: "1.3.0-beta.1",
2386
2226
  rootPath,
2387
2227
  distPath: '',
2388
2228
  cachePath,
@@ -2548,9 +2388,13 @@ var __webpack_exports__ = {};
2548
2388
  JS_DATA_URI: 'js-data-uri',
2549
2389
  TS: 'ts',
2550
2390
  CSS: 'css',
2391
+ CSS_RAW: 'css-raw',
2551
2392
  LESS: 'less',
2393
+ LESS_RAW: 'less-raw',
2552
2394
  SASS: 'sass',
2395
+ SASS_RAW: 'sass-raw',
2553
2396
  STYLUS: 'stylus',
2397
+ STYLUS_RAW: 'stylus-raw',
2554
2398
  SVG: 'svg',
2555
2399
  PUG: 'pug',
2556
2400
  VUE: 'vue',
@@ -2980,7 +2824,9 @@ var __webpack_exports__ = {};
2980
2824
  let rule = chain.module.rule(CHAIN_ID.RULE.CSS), { config } = environment;
2981
2825
  rule.test(CSS_REGEX).type("javascript/auto").dependency({
2982
2826
  not: 'url'
2983
- });
2827
+ }).resourceQuery({
2828
+ not: /raw/
2829
+ }), chain.module.rule(CHAIN_ID.RULE.CSS_RAW).test(CSS_REGEX).type('asset/source').resourceQuery(/raw/);
2984
2830
  let emitCss = config.output.emitCss ?? 'web' === target;
2985
2831
  if (emitCss) {
2986
2832
  if (config.output.injectStyles) {
@@ -3039,20 +2885,32 @@ var __webpack_exports__ = {};
3039
2885
  name: 'rsbuild:define',
3040
2886
  setup (api) {
3041
2887
  api.modifyBundlerChain((chain, { CHAIN_ID, bundler, environment })=>{
3042
- let { config } = environment, baseUrl = JSON.stringify(config.server.base), assetPrefix = JSON.stringify(getPublicPathFromChain(chain, !1)), builtinVars = {
2888
+ let { config } = environment, baseUrl = JSON.stringify(config.server.base), assetPrefix = JSON.stringify(getPublicPathFromChain(chain, !1)), mergedDefine = {
3043
2889
  'import.meta.env.MODE': JSON.stringify(config.mode),
3044
2890
  'import.meta.env.DEV': 'development' === config.mode,
3045
2891
  'import.meta.env.PROD': 'production' === config.mode,
3046
2892
  'import.meta.env.BASE_URL': baseUrl,
3047
2893
  'import.meta.env.ASSET_PREFIX': assetPrefix,
3048
2894
  'process.env.BASE_URL': baseUrl,
3049
- 'process.env.ASSET_PREFIX': assetPrefix
2895
+ 'process.env.ASSET_PREFIX': assetPrefix,
2896
+ ...config.source.define
3050
2897
  };
3051
- chain.plugin(CHAIN_ID.PLUGIN.DEFINE).use(bundler.DefinePlugin, [
3052
- {
3053
- ...builtinVars,
3054
- ...config.source.define
2898
+ !function(define) {
2899
+ let value = define['process.env'];
2900
+ if (!value) return;
2901
+ let check = (value)=>{
2902
+ let pathKey = Object.keys(value).find((key)=>'path' === key.toLowerCase() && value[key] === process.env[key]);
2903
+ pathKey && rslog_index_js_namespaceObject.logger.warn(index_js_default().yellow(`[rsbuild:config] The "source.define" option includes an object with the key ${JSON.stringify(pathKey)} under "process.env", indicating potential exposure of all environment variables. This can lead to security risks and should be avoided.`));
2904
+ };
2905
+ if ('object' == typeof value) {
2906
+ check(value);
2907
+ return;
3055
2908
  }
2909
+ if ('string' == typeof value) try {
2910
+ check(JSON.parse(value));
2911
+ } catch (error) {}
2912
+ }(mergedDefine), chain.plugin(CHAIN_ID.PLUGIN.DEFINE).use(bundler.DefinePlugin, [
2913
+ mergedDefine
3056
2914
  ]);
3057
2915
  });
3058
2916
  }
@@ -5092,6 +4950,167 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
5092
4950
  rspackConfigs
5093
4951
  };
5094
4952
  }
4953
+ let commonOpts = {}, getEnvDir = (cwd, envDir)=>envDir ? external_node_path_default().isAbsolute(envDir) ? envDir : external_node_path_default().join(cwd, envDir) : cwd, init_loadConfig = async (root)=>{
4954
+ var _config_server;
4955
+ let { content: config, filePath } = await config_loadConfig({
4956
+ cwd: root,
4957
+ path: commonOpts.config,
4958
+ envMode: commonOpts.envMode,
4959
+ loader: commonOpts.configLoader
4960
+ });
4961
+ return config.dev ||= {}, config.source ||= {}, config.server ||= {}, commonOpts.base && (config.server.base = commonOpts.base), commonOpts.root && (config.root = root), commonOpts.mode && (config.mode = commonOpts.mode), !commonOpts.open || (null === (_config_server = config.server) || void 0 === _config_server ? void 0 : _config_server.open) || (config.server.open = commonOpts.open), commonOpts.host && (config.server.host = commonOpts.host), commonOpts.port && (config.server.port = commonOpts.port), void 0 === config.dev.cliShortcuts && (config.dev.cliShortcuts = !0), filePath && (config.dev.watchFiles = [
4962
+ ...config.dev.watchFiles ? castArray(config.dev.watchFiles) : [],
4963
+ {
4964
+ paths: filePath,
4965
+ type: 'reload-server'
4966
+ }
4967
+ ]), config;
4968
+ };
4969
+ async function init({ cliOptions, isRestart, isBuildWatch = !1 }) {
4970
+ cliOptions && (commonOpts = cliOptions);
4971
+ try {
4972
+ let cwd = process.cwd(), root = commonOpts.root ? getAbsolutePath(cwd, commonOpts.root) : cwd, rsbuild = await createRsbuild({
4973
+ cwd: root,
4974
+ rsbuildConfig: ()=>init_loadConfig(root),
4975
+ environment: commonOpts.environment,
4976
+ loadEnv: {
4977
+ cwd: getEnvDir(root, commonOpts.envDir),
4978
+ mode: commonOpts.envMode
4979
+ }
4980
+ });
4981
+ return rsbuild.onBeforeCreateCompiler(()=>{
4982
+ var _config_dev;
4983
+ if ('dev' !== rsbuild.context.action && !isBuildWatch) return;
4984
+ let files = [], config = rsbuild.getNormalizedConfig();
4985
+ if (null === (_config_dev = config.dev) || void 0 === _config_dev ? void 0 : _config_dev.watchFiles) for (let watchFilesConfig of castArray(config.dev.watchFiles)){
4986
+ if ('reload-server' !== watchFilesConfig.type) continue;
4987
+ let paths = castArray(watchFilesConfig.paths);
4988
+ watchFilesConfig.options ? watchFilesForRestart({
4989
+ files: paths,
4990
+ rsbuild,
4991
+ isBuildWatch,
4992
+ watchOptions: watchFilesConfig.options
4993
+ }) : files.push(...paths);
4994
+ }
4995
+ watchFilesForRestart({
4996
+ files,
4997
+ rsbuild,
4998
+ isBuildWatch
4999
+ });
5000
+ }), rsbuild;
5001
+ } catch (err) {
5002
+ if (isRestart) rslog_index_js_namespaceObject.logger.error(err);
5003
+ else throw err;
5004
+ }
5005
+ }
5006
+ async function setupWatchFiles(options) {
5007
+ let { dev, server, root, compileMiddlewareAPI } = options, { hmr, liveReload } = dev;
5008
+ if (!hmr && !liveReload || !compileMiddlewareAPI) return;
5009
+ let closeDevFilesWatcher = await watchDevFiles(dev, compileMiddlewareAPI, root), serverFilesWatcher = await function(serverConfig, compileMiddlewareAPI, root) {
5010
+ let publicDirs = normalizePublicDirs(serverConfig.publicDir);
5011
+ if (!publicDirs.length) return;
5012
+ let watchPaths = publicDirs.filter((item)=>item.watch).map((item)=>item.name);
5013
+ if (watchPaths.length) return startWatchFiles(prepareWatchOptions(watchPaths), compileMiddlewareAPI, root);
5014
+ }(server, compileMiddlewareAPI, root);
5015
+ return {
5016
+ async close () {
5017
+ await Promise.all([
5018
+ null == closeDevFilesWatcher ? void 0 : closeDevFilesWatcher(),
5019
+ null == serverFilesWatcher ? void 0 : serverFilesWatcher.close()
5020
+ ]);
5021
+ }
5022
+ };
5023
+ }
5024
+ async function watchDevFiles(devConfig, compileMiddlewareAPI, root) {
5025
+ let { watchFiles } = devConfig;
5026
+ if (!watchFiles) return;
5027
+ let watchers = [];
5028
+ for (let { paths, options, type } of castArray(watchFiles)){
5029
+ let watchOptions = prepareWatchOptions(paths, options, type), watcher = await startWatchFiles(watchOptions, compileMiddlewareAPI, root);
5030
+ watcher && watchers.push(watcher);
5031
+ }
5032
+ return async ()=>{
5033
+ for (let watcher of watchers)await watcher.close();
5034
+ };
5035
+ }
5036
+ function prepareWatchOptions(paths, options = {}, type) {
5037
+ return {
5038
+ paths: 'string' == typeof paths ? [
5039
+ paths
5040
+ ] : paths,
5041
+ options,
5042
+ type
5043
+ };
5044
+ }
5045
+ let GLOB_REGEX = /[*?{}[\]()!@+|]/, isGlob = (str)=>GLOB_REGEX.test(str);
5046
+ async function createChokidar(pathOrGlobs, root, options) {
5047
+ let chokidar = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/chokidar/index.js")), watchFiles = new Set(), globPatterns = pathOrGlobs.filter((pathOrGlob)=>!!isGlob(pathOrGlob) || (watchFiles.add(pathOrGlob), !1));
5048
+ if (globPatterns.length) {
5049
+ let tinyglobby = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../../compiled/tinyglobby/index.js")), { glob } = tinyglobby.default || tinyglobby;
5050
+ for (let file of (await glob(globPatterns, {
5051
+ cwd: root,
5052
+ absolute: !0
5053
+ })))watchFiles.add(file);
5054
+ }
5055
+ return chokidar.watch(Array.from(watchFiles), options);
5056
+ }
5057
+ async function startWatchFiles({ paths, options, type = 'reload-page' }, compileMiddlewareAPI, root) {
5058
+ if ('reload-page' !== type) return;
5059
+ let watcher = await createChokidar(paths, root, options);
5060
+ return watcher.on('change', ()=>{
5061
+ compileMiddlewareAPI.sockWrite('static-changed');
5062
+ }), watcher;
5063
+ }
5064
+ let cleaners = [], onBeforeRestartServer = (cleaner)=>{
5065
+ cleaners.push(cleaner);
5066
+ }, clearConsole = ()=>{
5067
+ isTTY() && !process.env.DEBUG && process.stdout.write('\x1B[H\x1B[2J');
5068
+ }, beforeRestart = async ({ filePath, clear = !0, id })=>{
5069
+ if (clear && clearConsole(), filePath) {
5070
+ let filename = external_node_path_default().basename(filePath);
5071
+ rslog_index_js_namespaceObject.logger.info(`restarting ${id} as ${index_js_default().yellow(filename)} changed\n`);
5072
+ } else rslog_index_js_namespaceObject.logger.info(`restarting ${id}...\n`);
5073
+ for (let cleaner of cleaners)await cleaner();
5074
+ cleaners = [];
5075
+ }, restartDevServer = async ({ filePath, clear = !0 } = {})=>{
5076
+ await beforeRestart({
5077
+ filePath,
5078
+ clear,
5079
+ id: 'server'
5080
+ });
5081
+ let rsbuild = await init({
5082
+ isRestart: !0
5083
+ });
5084
+ return !!rsbuild && (await rsbuild.startDevServer(), !0);
5085
+ }, restartBuild = async ({ filePath, clear = !0 } = {})=>{
5086
+ await beforeRestart({
5087
+ filePath,
5088
+ clear,
5089
+ id: 'build'
5090
+ });
5091
+ let rsbuild = await init({
5092
+ isRestart: !0,
5093
+ isBuildWatch: !0
5094
+ });
5095
+ return !!rsbuild && (onBeforeRestartServer((await rsbuild.build({
5096
+ watch: !0
5097
+ })).close), !0);
5098
+ };
5099
+ async function watchFilesForRestart({ files, rsbuild, isBuildWatch, watchOptions }) {
5100
+ if (!files.length) return;
5101
+ let root = rsbuild.context.rootPath, watcher = await createChokidar(files, root, {
5102
+ ignoreInitial: !0,
5103
+ ignorePermissionErrors: !0,
5104
+ ...watchOptions
5105
+ }), restarting = !1, onChange = async (filePath)=>{
5106
+ !restarting && (restarting = !0, (isBuildWatch ? await restartBuild({
5107
+ filePath
5108
+ }) : await restartDevServer({
5109
+ filePath
5110
+ })) ? await watcher.close() : rslog_index_js_namespaceObject.logger.error(isBuildWatch ? 'Restart build failed.' : 'Restart server failed.'), restarting = !1);
5111
+ };
5112
+ watcher.on('add', onChange), watcher.on('change', onChange), watcher.on('unlink', onChange);
5113
+ }
5095
5114
  let external_node_readline_namespaceObject = require("node:readline");
5096
5115
  var external_node_readline_default = __webpack_require__.n(external_node_readline_namespaceObject);
5097
5116
  let isCliShortcutsEnabled = (devConfig)=>devConfig.cliShortcuts && isTTY('stdin');
@@ -6176,9 +6195,13 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6176
6195
  cleanupCallbacks.add(callback);
6177
6196
  }, removeCleanup = (callback)=>{
6178
6197
  cleanupCallbacks.delete(callback);
6179
- }, shutdownRefCount = 0, setupGracefulShutdown = ()=>(shutdownRefCount++, process.once('SIGTERM', handleTermination), 'true' !== process.env.CI && process.stdin.on('end', handleTermination), ()=>{
6180
- !(--shutdownRefCount > 0) && (process.removeListener('SIGTERM', handleTermination), 0 === process.stdin.listenerCount('end') && process.stdin.removeListener('end', handleTermination));
6181
- }), createHttpServer = async ({ serverConfig, middlewares })=>{
6198
+ }, shutdownRefCount = 0, setupGracefulShutdown = ()=>{
6199
+ shutdownRefCount++, process.once('SIGTERM', handleTermination);
6200
+ let isCI = 'true' === process.env.CI;
6201
+ return isCI || process.stdin.on('end', handleTermination), ()=>{
6202
+ !(--shutdownRefCount > 0) && (process.removeListener('SIGTERM', handleTermination), isCI || process.stdin.removeListener('end', handleTermination));
6203
+ };
6204
+ }, createHttpServer = async ({ serverConfig, middlewares })=>{
6182
6205
  if (serverConfig.https) {
6183
6206
  if (serverConfig.proxy) {
6184
6207
  let { createServer } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "node:https"));
@@ -6394,7 +6417,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6394
6417
  }
6395
6418
  rslog_index_js_namespaceObject.logger.start('build started...');
6396
6419
  }(compiler, context), isCompiling = !0;
6397
- }), 'build' === context.command && compiler.hooks.run.tap('rsbuild:run', logRspackVersion);
6420
+ }), 'build' === context.action && compiler.hooks.run.tap('rsbuild:run', logRspackVersion);
6398
6421
  let done = (stats)=>{
6399
6422
  let statsOptions = getStatsOptions(compiler), statsJson = stats.toJson({
6400
6423
  children: !0,
@@ -6419,7 +6442,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6419
6442
  };
6420
6443
  return compiler.hooks.done.tap('rsbuild:done', (stats)=>{
6421
6444
  done(stats);
6422
- }), 'dev' === context.command && registerDevHook({
6445
+ }), 'dev' === context.action && registerDevHook({
6423
6446
  context,
6424
6447
  compiler,
6425
6448
  bundlerConfigs: rspackConfigs,
@@ -6835,6 +6858,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6835
6858
  }), context = await createContext(resolvedOptions, config), getPluginAPI = function({ context, pluginManager }) {
6836
6859
  let { hooks } = context, publicContext = function(context) {
6837
6860
  let exposedKeys = [
6861
+ 'action',
6838
6862
  'version',
6839
6863
  'rootPath',
6840
6864
  'distPath',
@@ -7020,7 +7044,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
7020
7044
  helpers: provider_helpers_namespaceObject
7021
7045
  }), rsbuild = {
7022
7046
  build: async (...args)=>{
7023
- context.command = 'build', getNodeEnv() || setNodeEnv('production');
7047
+ context.action = 'build', getNodeEnv() || setNodeEnv('production');
7024
7048
  let buildInstance = await providerInstance.build(...args);
7025
7049
  return {
7026
7050
  ...buildInstance,
@@ -7030,7 +7054,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
7030
7054
  };
7031
7055
  },
7032
7056
  preview: async (options = {})=>{
7033
- context.command = 'preview', getNodeEnv() || setNodeEnv('production');
7057
+ context.action = 'preview', getNodeEnv() || setNodeEnv('production');
7034
7058
  let config = await initRsbuildConfig({
7035
7059
  context,
7036
7060
  pluginManager
@@ -7044,9 +7068,9 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
7044
7068
  }
7045
7069
  return startProdServer(context, config, options);
7046
7070
  },
7047
- startDevServer: (...args)=>(context.command = 'dev', getNodeEnv() || setNodeEnv('development'), providerInstance.startDevServer(...args)),
7048
- createCompiler: (...args)=>(context.command || (context.command = 'development' === getNodeEnv() ? 'dev' : 'build'), providerInstance.createCompiler(...args)),
7049
- createDevServer: (...args)=>(context.command = 'dev', getNodeEnv() || setNodeEnv('development'), providerInstance.createDevServer(...args)),
7071
+ startDevServer: (...args)=>(context.action = 'dev', getNodeEnv() || setNodeEnv('development'), providerInstance.startDevServer(...args)),
7072
+ createCompiler: (...args)=>(context.action || (context.action = 'development' === getNodeEnv() ? 'dev' : 'build'), providerInstance.createCompiler(...args)),
7073
+ createDevServer: (...args)=>(context.action = 'dev', getNodeEnv() || setNodeEnv('development'), providerInstance.createDevServer(...args)),
7050
7074
  ...pick(pluginManager, [
7051
7075
  'addPlugins',
7052
7076
  'getPlugins',
@@ -7412,22 +7436,20 @@ ${section.body}` : section.body).join("\n\n"));
7412
7436
  };
7413
7437
  async function runCLI() {
7414
7438
  !function() {
7415
- !function() {
7416
- if (!process.env.NODE_ENV) {
7417
- let command = process.argv[2];
7418
- process.env.NODE_ENV = [
7419
- 'build',
7420
- 'preview'
7421
- ].includes(command) ? 'production' : 'development';
7422
- }
7423
- }(), process.title = 'rsbuild-node';
7424
- let { npm_execpath } = process.env;
7425
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.3.0-beta.0\n`);
7426
- }();
7439
+ if (!process.env.NODE_ENV) {
7440
+ let command = process.argv[2];
7441
+ process.env.NODE_ENV = [
7442
+ 'build',
7443
+ 'preview'
7444
+ ].includes(command) ? 'production' : 'development';
7445
+ }
7446
+ }(), process.title = 'rsbuild-node';
7447
+ let { npm_execpath } = process.env;
7448
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.3.0-beta.1\n`);
7427
7449
  try {
7428
7450
  !function() {
7429
7451
  let cli = cac_dist('rsbuild');
7430
- cli.help(), cli.version("1.3.0-beta.0"), applyCommonOptions(cli);
7452
+ cli.help(), cli.version("1.3.0-beta.1"), applyCommonOptions(cli);
7431
7453
  let devCommand = cli.command('', 'starting the dev server').alias('dev'), 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');
7432
7454
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
7433
7455
  try {
@@ -7478,7 +7500,7 @@ ${section.body}` : section.body).join("\n\n"));
7478
7500
  rslog_index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), rslog_index_js_namespaceObject.logger.error(err);
7479
7501
  }
7480
7502
  }
7481
- let src_rslib_entry_version = "1.3.0-beta.0";
7503
+ let src_rslib_entry_version = "1.3.0-beta.1";
7482
7504
  })();
7483
7505
  var __webpack_export_target__ = exports;
7484
7506
  for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];