@rspack/cli 1.4.10 → 1.5.0-beta.0

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/cli.d.ts CHANGED
@@ -13,8 +13,12 @@ export declare class RspackCLI {
13
13
  getLogger(): RspackCLILogger;
14
14
  run(argv: string[]): Promise<void>;
15
15
  registerCommands(): Promise<void>;
16
- buildConfig(item: RspackOptions | MultiRspackOptions, options: RspackBuildCLIOptions, command: Command): Promise<RspackOptions | MultiRspackOptions>;
17
- loadConfig(options: RspackCLIOptions): Promise<RspackOptions | MultiRspackOptions>;
16
+ buildConfig(item: RspackOptions | MultiRspackOptions, pathMap: WeakMap<RspackOptions, string[]>, options: RspackBuildCLIOptions, command: Command): Promise<RspackOptions | MultiRspackOptions>;
17
+ loadConfig(options: RspackCLIOptions): Promise<{
18
+ config: RspackOptions | MultiRspackOptions;
19
+ pathMap: WeakMap<RspackOptions, string[]>;
20
+ }>;
21
+ private filterConfig;
18
22
  isMultipleCompiler(compiler: Compiler | MultiCompiler): compiler is MultiCompiler;
19
23
  isWatch(compiler: Compiler | MultiCompiler): boolean;
20
24
  }
package/dist/index.js CHANGED
@@ -266,7 +266,7 @@ var __webpack_exports__ = {};
266
266
  logger.error(error);
267
267
  process.exit(2);
268
268
  }
269
- if (null == stats ? void 0 : stats.hasErrors()) process.exitCode = 1;
269
+ if (stats?.hasErrors()) process.exitCode = 1;
270
270
  if (!compiler || !stats) return;
271
271
  const statsOptions = cli.isMultipleCompiler(compiler) ? {
272
272
  children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
@@ -346,7 +346,7 @@ var __webpack_exports__ = {};
346
346
  }
347
347
  };
348
348
  const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/dev-server"));
349
- let config = await cli.loadConfig(rspackOptions);
349
+ let { config } = await cli.loadConfig(rspackOptions);
350
350
  config = await getPreviewConfig(config, options);
351
351
  if (!Array.isArray(config)) config = [
352
352
  config
@@ -370,18 +370,17 @@ var __webpack_exports__ = {};
370
370
  }
371
371
  async function getPreviewConfig(item, options) {
372
372
  const internalPreviewConfig = async (item)=>{
373
- var _item_output, _item_devServer, _item_devServer1, _item_devServer2, _item_devServer3, _item_devServer4;
374
373
  item.devServer = {
375
374
  static: {
376
- directory: options.dir ? external_node_path_default().join(item.context ?? process.cwd(), options.dir) : (null == (_item_output = item.output) ? void 0 : _item_output.path) ?? external_node_path_default().join(item.context ?? process.cwd(), defaultRoot),
375
+ directory: options.dir ? external_node_path_default().join(item.context ?? process.cwd(), options.dir) : item.output?.path ?? external_node_path_default().join(item.context ?? process.cwd(), defaultRoot),
377
376
  publicPath: options.publicPath ?? "/"
378
377
  },
379
378
  port: options.port ?? 8080,
380
- proxy: null == (_item_devServer = item.devServer) ? void 0 : _item_devServer.proxy,
381
- host: options.host ?? (null == (_item_devServer1 = item.devServer) ? void 0 : _item_devServer1.host),
382
- open: options.open ?? (null == (_item_devServer2 = item.devServer) ? void 0 : _item_devServer2.open),
383
- server: options.server ?? (null == (_item_devServer3 = item.devServer) ? void 0 : _item_devServer3.server),
384
- historyApiFallback: null == (_item_devServer4 = item.devServer) ? void 0 : _item_devServer4.historyApiFallback
379
+ proxy: item.devServer?.proxy,
380
+ host: options.host ?? item.devServer?.host,
381
+ open: options.open ?? item.devServer?.open,
382
+ server: options.server ?? item.devServer?.server,
383
+ historyApiFallback: item.devServer?.historyApiFallback
385
384
  };
386
385
  return item;
387
386
  };
@@ -453,8 +452,8 @@ var __webpack_exports__ = {};
453
452
  let finalMiddlewares = middlewares;
454
453
  if (setupMiddlewares) finalMiddlewares = setupMiddlewares(finalMiddlewares, server);
455
454
  return [
456
- lazyCompileMiddleware,
457
- ...finalMiddlewares
455
+ ...finalMiddlewares,
456
+ lazyCompileMiddleware
458
457
  ];
459
458
  };
460
459
  result.hot = options.hot ?? result.hot ?? true;
@@ -512,7 +511,7 @@ var __webpack_exports__ = {};
512
511
  if (/\.(mjs|mts)$/.test(ext)) return true;
513
512
  if (/\.(cjs|cts)/.test(ext)) return false;
514
513
  const packageJson = utils_readPackageUp(external_node_path_default().dirname(filePath));
515
- return (null == packageJson ? void 0 : packageJson.type) === "module";
514
+ return packageJson?.type === "module";
516
515
  };
517
516
  const utils_isEsmFile = isEsmFile;
518
517
  const crossImport = async (path, cwd = process.cwd())=>{
@@ -551,7 +550,7 @@ var __webpack_exports__ = {};
551
550
  const { default: rechoir } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "rechoir"));
552
551
  rechoir.prepare(extensions, configPath);
553
552
  } catch (error) {
554
- const failures = null == error ? void 0 : error.failures;
553
+ const failures = error?.failures;
555
554
  if (failures) {
556
555
  const messages = failures.map((failure)=>failure.error.message);
557
556
  throw new Error(`${messages.join("\n")}`);
@@ -562,17 +561,35 @@ var __webpack_exports__ = {};
562
561
  const checkIsMultiRspackOptions = (config)=>Array.isArray(config);
563
562
  async function loadExtendedConfig(config, configPath, cwd, options) {
564
563
  if (checkIsMultiRspackOptions(config)) {
565
- const extendedConfigs = await Promise.all(config.map((item)=>loadExtendedConfig(item, configPath, cwd, options)));
564
+ const resultPathMap = new WeakMap();
565
+ const extendedConfigs = await Promise.all(config.map(async (item)=>{
566
+ const { config, pathMap } = await loadExtendedConfig(item, configPath, cwd, options);
567
+ resultPathMap.set(config, pathMap.get(config));
568
+ return config;
569
+ }));
566
570
  extendedConfigs.parallelism = config.parallelism;
567
- return extendedConfigs;
571
+ return {
572
+ config: extendedConfigs,
573
+ pathMap: resultPathMap
574
+ };
568
575
  }
569
- if (!("extends" in config) || !config.extends) return config;
576
+ const pathMap = new WeakMap();
577
+ pathMap.set(config, [
578
+ configPath
579
+ ]);
580
+ if (!("extends" in config) || !config.extends) return {
581
+ config,
582
+ pathMap
583
+ };
570
584
  const extendsList = Array.isArray(config.extends) ? config.extends : [
571
585
  config.extends
572
586
  ];
573
587
  const { extends: _, ...configWithoutExtends } = config;
574
588
  const baseDir = external_node_path_default().dirname(configPath);
575
589
  let resultConfig = configWithoutExtends;
590
+ pathMap.set(resultConfig, [
591
+ configPath
592
+ ]);
576
593
  for (const extendPath of extendsList){
577
594
  let resolvedPath;
578
595
  if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
@@ -594,50 +611,52 @@ var __webpack_exports__ = {};
594
611
  }
595
612
  if (!external_node_fs_default().existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
596
613
  if (isTsFile(resolvedPath) && "register" === options.configLoader) await registerLoader(resolvedPath);
597
- let extendedConfig = await crossImport(resolvedPath, cwd);
598
- if ("function" == typeof extendedConfig) {
599
- var _options_argv;
600
- extendedConfig = extendedConfig(null == (_options_argv = options.argv) ? void 0 : _options_argv.env, options.argv);
601
- if ("function" == typeof extendedConfig.then) extendedConfig = await extendedConfig;
614
+ let loadedConfig = await crossImport(resolvedPath, cwd);
615
+ if ("function" == typeof loadedConfig) {
616
+ loadedConfig = loadedConfig(options.argv?.env, options.argv);
617
+ if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
602
618
  }
603
- extendedConfig = await loadExtendedConfig(extendedConfig, resolvedPath, cwd, options);
619
+ const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(loadedConfig, resolvedPath, cwd, options);
620
+ const configPaths = [
621
+ ...pathMap.get(resultConfig) || [],
622
+ ...extendedPathMap.get(extendedConfig) || []
623
+ ];
604
624
  resultConfig = core_.util.cleverMerge(extendedConfig, resultConfig);
625
+ pathMap.set(resultConfig, configPaths);
605
626
  }
606
- return resultConfig;
627
+ return {
628
+ config: resultConfig,
629
+ pathMap
630
+ };
607
631
  }
608
632
  async function loadRspackConfig(options, cwd = process.cwd()) {
609
- let configPath;
610
- let loadedConfig;
633
+ let configPath = "";
611
634
  if (options.config) {
612
635
  configPath = external_node_path_default().resolve(cwd, options.config);
613
636
  if (!external_node_fs_default().existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
614
- if (isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
615
- loadedConfig = await crossImport(configPath, cwd);
616
637
  } else {
617
638
  const defaultConfig = utils_findConfig(external_node_path_default().resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
618
- if (!defaultConfig) return {};
639
+ if (!defaultConfig) return null;
619
640
  configPath = defaultConfig;
620
- if (isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
621
- loadedConfig = await crossImport(defaultConfig, cwd);
622
641
  }
623
- if ("function" != typeof loadedConfig && configPath) loadedConfig = await loadExtendedConfig(loadedConfig, configPath, cwd, options);
624
- return loadedConfig;
625
- }
626
- function _define_property(obj, key, value) {
627
- if (key in obj) Object.defineProperty(obj, key, {
628
- value: value,
629
- enumerable: true,
630
- configurable: true,
631
- writable: true
632
- });
633
- else obj[key] = value;
634
- return obj;
642
+ if (isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
643
+ const loadedConfig = await crossImport(configPath, cwd);
644
+ return {
645
+ loadedConfig,
646
+ configPath
647
+ };
635
648
  }
636
649
  class RspackCLI {
650
+ colors;
651
+ program;
652
+ constructor(){
653
+ this.colors = this.createColors();
654
+ this.program = external_yargs_default()();
655
+ }
637
656
  async createCompiler(options, rspackCommand, callback) {
638
657
  process.env.RSPACK_CONFIG_VALIDATE ??= "loose";
639
- let config = await this.loadConfig(options);
640
- config = await this.buildConfig(config, options, rspackCommand);
658
+ let { config, pathMap } = await this.loadConfig(options);
659
+ config = await this.buildConfig(config, pathMap, options, rspackCommand);
641
660
  const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
642
661
  let compiler;
643
662
  try {
@@ -691,7 +710,7 @@ var __webpack_exports__ = {};
691
710
  ];
692
711
  for (const command of builtinCommands)command.apply(this);
693
712
  }
694
- async buildConfig(item, options, command) {
713
+ async buildConfig(item, pathMap, options, command) {
695
714
  const isBuild = "build" === command;
696
715
  const isServe = "serve" === command;
697
716
  const internalBuildConfig = async (item)=>{
@@ -725,6 +744,14 @@ var __webpack_exports__ = {};
725
744
  const installed = (item.plugins ||= []).find((item)=>item instanceof core_.ProgressPlugin);
726
745
  if (!installed) (item.plugins ??= []).push(new core_.ProgressPlugin());
727
746
  }
747
+ const cacheOptions = item.experiments?.cache;
748
+ if ("object" == typeof cacheOptions && "persistent" === cacheOptions.type) {
749
+ const configPaths = pathMap.get(item);
750
+ if (configPaths) cacheOptions.buildDependencies = [
751
+ ...configPaths,
752
+ ...cacheOptions.buildDependencies || []
753
+ ];
754
+ }
728
755
  if (void 0 === item.stats) item.stats = {
729
756
  preset: "errors-warnings",
730
757
  timings: true
@@ -744,22 +771,29 @@ var __webpack_exports__ = {};
744
771
  return internalBuildConfig(item);
745
772
  }
746
773
  async loadConfig(options) {
747
- let loadedConfig = await loadRspackConfig(options);
774
+ const config = await loadRspackConfig(options);
775
+ if (!config) return {
776
+ config: this.filterConfig(options, {}),
777
+ pathMap: new WeakMap()
778
+ };
779
+ let { loadedConfig, configPath } = config;
748
780
  if ("function" == typeof loadedConfig) {
749
- var _options_argv;
750
- let functionResult = loadedConfig(null == (_options_argv = options.argv) ? void 0 : _options_argv.env, options.argv);
781
+ let functionResult = loadedConfig(options.argv?.env, options.argv);
751
782
  if ("function" == typeof functionResult.then) functionResult = await functionResult;
752
783
  loadedConfig = functionResult;
753
- if ("extends" in loadedConfig && loadedConfig.extends) {
754
- const tempConfigPath = external_node_path_default().resolve(process.cwd(), "rspack.config.js");
755
- loadedConfig = await loadExtendedConfig(loadedConfig, tempConfigPath, process.cwd(), options);
756
- }
757
784
  }
785
+ const { config: extendedConfig, pathMap } = await loadExtendedConfig(loadedConfig, configPath, process.cwd(), options);
786
+ return {
787
+ config: this.filterConfig(options, extendedConfig),
788
+ pathMap
789
+ };
790
+ }
791
+ filterConfig(options, config) {
758
792
  if (options.configName) {
759
793
  const notFoundConfigNames = [];
760
- loadedConfig = options.configName.map((configName)=>{
794
+ config = options.configName.map((configName)=>{
761
795
  let found;
762
- found = Array.isArray(loadedConfig) ? loadedConfig.find((options)=>options.name === configName) : loadedConfig.name === configName ? loadedConfig : void 0;
796
+ found = Array.isArray(config) ? config.find((options)=>options.name === configName) : config.name === configName ? config : void 0;
763
797
  if (!found) notFoundConfigNames.push(configName);
764
798
  return found;
765
799
  });
@@ -768,7 +802,7 @@ var __webpack_exports__ = {};
768
802
  process.exit(2);
769
803
  }
770
804
  }
771
- return loadedConfig;
805
+ return config;
772
806
  }
773
807
  isMultipleCompiler(compiler) {
774
808
  return Boolean(compiler.compilers);
@@ -776,12 +810,6 @@ var __webpack_exports__ = {};
776
810
  isWatch(compiler) {
777
811
  return Boolean(this.isMultipleCompiler(compiler) ? compiler.compilers.some((compiler)=>compiler.options.watch) : compiler.options.watch);
778
812
  }
779
- constructor(){
780
- _define_property(this, "colors", void 0);
781
- _define_property(this, "program", void 0);
782
- this.colors = this.createColors();
783
- this.program = external_yargs_default()();
784
- }
785
813
  }
786
814
  function defineConfig(config) {
787
815
  return config;
package/dist/index.mjs CHANGED
@@ -231,7 +231,7 @@ class BuildCommand {
231
231
  logger.error(error);
232
232
  process.exit(2);
233
233
  }
234
- if (null == stats ? void 0 : stats.hasErrors()) process.exitCode = 1;
234
+ if (stats?.hasErrors()) process.exitCode = 1;
235
235
  if (!compiler || !stats) return;
236
236
  const statsOptions = cli.isMultipleCompiler(compiler) ? {
237
237
  children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
@@ -311,7 +311,7 @@ class PreviewCommand {
311
311
  }
312
312
  };
313
313
  const { RspackDevServer } = await import("@rspack/dev-server");
314
- let config = await cli.loadConfig(rspackOptions);
314
+ let { config } = await cli.loadConfig(rspackOptions);
315
315
  config = await getPreviewConfig(config, options);
316
316
  if (!Array.isArray(config)) config = [
317
317
  config
@@ -335,18 +335,17 @@ class PreviewCommand {
335
335
  }
336
336
  async function getPreviewConfig(item, options) {
337
337
  const internalPreviewConfig = async (item)=>{
338
- var _item_output, _item_devServer, _item_devServer1, _item_devServer2, _item_devServer3, _item_devServer4;
339
338
  item.devServer = {
340
339
  static: {
341
- directory: options.dir ? external_node_path_["default"].join(item.context ?? process.cwd(), options.dir) : (null == (_item_output = item.output) ? void 0 : _item_output.path) ?? external_node_path_["default"].join(item.context ?? process.cwd(), defaultRoot),
340
+ directory: options.dir ? external_node_path_["default"].join(item.context ?? process.cwd(), options.dir) : item.output?.path ?? external_node_path_["default"].join(item.context ?? process.cwd(), defaultRoot),
342
341
  publicPath: options.publicPath ?? "/"
343
342
  },
344
343
  port: options.port ?? 8080,
345
- proxy: null == (_item_devServer = item.devServer) ? void 0 : _item_devServer.proxy,
346
- host: options.host ?? (null == (_item_devServer1 = item.devServer) ? void 0 : _item_devServer1.host),
347
- open: options.open ?? (null == (_item_devServer2 = item.devServer) ? void 0 : _item_devServer2.open),
348
- server: options.server ?? (null == (_item_devServer3 = item.devServer) ? void 0 : _item_devServer3.server),
349
- historyApiFallback: null == (_item_devServer4 = item.devServer) ? void 0 : _item_devServer4.historyApiFallback
344
+ proxy: item.devServer?.proxy,
345
+ host: options.host ?? item.devServer?.host,
346
+ open: options.open ?? item.devServer?.open,
347
+ server: options.server ?? item.devServer?.server,
348
+ historyApiFallback: item.devServer?.historyApiFallback
350
349
  };
351
350
  return item;
352
351
  };
@@ -418,8 +417,8 @@ class ServeCommand {
418
417
  let finalMiddlewares = middlewares;
419
418
  if (setupMiddlewares) finalMiddlewares = setupMiddlewares(finalMiddlewares, server);
420
419
  return [
421
- lazyCompileMiddleware,
422
- ...finalMiddlewares
420
+ ...finalMiddlewares,
421
+ lazyCompileMiddleware
423
422
  ];
424
423
  };
425
424
  result.hot = options.hot ?? result.hot ?? true;
@@ -476,7 +475,7 @@ const isEsmFile = (filePath, cwd = process.cwd())=>{
476
475
  if (/\.(mjs|mts)$/.test(ext)) return true;
477
476
  if (/\.(cjs|cts)/.test(ext)) return false;
478
477
  const packageJson = utils_readPackageUp(external_node_path_["default"].dirname(filePath));
479
- return (null == packageJson ? void 0 : packageJson.type) === "module";
478
+ return packageJson?.type === "module";
480
479
  };
481
480
  const utils_isEsmFile = isEsmFile;
482
481
  const crossImport = async (path, cwd = process.cwd())=>{
@@ -515,7 +514,7 @@ const registerLoader = async (configPath)=>{
515
514
  const { default: rechoir } = await import("rechoir");
516
515
  rechoir.prepare(extensions, configPath);
517
516
  } catch (error) {
518
- const failures = null == error ? void 0 : error.failures;
517
+ const failures = error?.failures;
519
518
  if (failures) {
520
519
  const messages = failures.map((failure)=>failure.error.message);
521
520
  throw new Error(`${messages.join("\n")}`);
@@ -526,17 +525,35 @@ const registerLoader = async (configPath)=>{
526
525
  const checkIsMultiRspackOptions = (config)=>Array.isArray(config);
527
526
  async function loadExtendedConfig(config, configPath, cwd, options) {
528
527
  if (checkIsMultiRspackOptions(config)) {
529
- const extendedConfigs = await Promise.all(config.map((item)=>loadExtendedConfig(item, configPath, cwd, options)));
528
+ const resultPathMap = new WeakMap();
529
+ const extendedConfigs = await Promise.all(config.map(async (item)=>{
530
+ const { config, pathMap } = await loadExtendedConfig(item, configPath, cwd, options);
531
+ resultPathMap.set(config, pathMap.get(config));
532
+ return config;
533
+ }));
530
534
  extendedConfigs.parallelism = config.parallelism;
531
- return extendedConfigs;
535
+ return {
536
+ config: extendedConfigs,
537
+ pathMap: resultPathMap
538
+ };
532
539
  }
533
- if (!("extends" in config) || !config.extends) return config;
540
+ const pathMap = new WeakMap();
541
+ pathMap.set(config, [
542
+ configPath
543
+ ]);
544
+ if (!("extends" in config) || !config.extends) return {
545
+ config,
546
+ pathMap
547
+ };
534
548
  const extendsList = Array.isArray(config.extends) ? config.extends : [
535
549
  config.extends
536
550
  ];
537
551
  const { extends: _, ...configWithoutExtends } = config;
538
552
  const baseDir = external_node_path_["default"].dirname(configPath);
539
553
  let resultConfig = configWithoutExtends;
554
+ pathMap.set(resultConfig, [
555
+ configPath
556
+ ]);
540
557
  for (const extendPath of extendsList){
541
558
  let resolvedPath;
542
559
  if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
@@ -558,50 +575,52 @@ async function loadExtendedConfig(config, configPath, cwd, options) {
558
575
  }
559
576
  if (!external_node_fs_["default"].existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
560
577
  if (isTsFile(resolvedPath) && "register" === options.configLoader) await registerLoader(resolvedPath);
561
- let extendedConfig = await crossImport(resolvedPath, cwd);
562
- if ("function" == typeof extendedConfig) {
563
- var _options_argv;
564
- extendedConfig = extendedConfig(null == (_options_argv = options.argv) ? void 0 : _options_argv.env, options.argv);
565
- if ("function" == typeof extendedConfig.then) extendedConfig = await extendedConfig;
578
+ let loadedConfig = await crossImport(resolvedPath, cwd);
579
+ if ("function" == typeof loadedConfig) {
580
+ loadedConfig = loadedConfig(options.argv?.env, options.argv);
581
+ if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
566
582
  }
567
- extendedConfig = await loadExtendedConfig(extendedConfig, resolvedPath, cwd, options);
583
+ const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(loadedConfig, resolvedPath, cwd, options);
584
+ const configPaths = [
585
+ ...pathMap.get(resultConfig) || [],
586
+ ...extendedPathMap.get(extendedConfig) || []
587
+ ];
568
588
  resultConfig = core_.util.cleverMerge(extendedConfig, resultConfig);
589
+ pathMap.set(resultConfig, configPaths);
569
590
  }
570
- return resultConfig;
591
+ return {
592
+ config: resultConfig,
593
+ pathMap
594
+ };
571
595
  }
572
596
  async function loadRspackConfig(options, cwd = process.cwd()) {
573
- let configPath;
574
- let loadedConfig;
597
+ let configPath = "";
575
598
  if (options.config) {
576
599
  configPath = external_node_path_["default"].resolve(cwd, options.config);
577
600
  if (!external_node_fs_["default"].existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
578
- if (isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
579
- loadedConfig = await crossImport(configPath, cwd);
580
601
  } else {
581
602
  const defaultConfig = utils_findConfig(external_node_path_["default"].resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
582
- if (!defaultConfig) return {};
603
+ if (!defaultConfig) return null;
583
604
  configPath = defaultConfig;
584
- if (isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
585
- loadedConfig = await crossImport(defaultConfig, cwd);
586
605
  }
587
- if ("function" != typeof loadedConfig && configPath) loadedConfig = await loadExtendedConfig(loadedConfig, configPath, cwd, options);
588
- return loadedConfig;
589
- }
590
- function _define_property(obj, key, value) {
591
- if (key in obj) Object.defineProperty(obj, key, {
592
- value: value,
593
- enumerable: true,
594
- configurable: true,
595
- writable: true
596
- });
597
- else obj[key] = value;
598
- return obj;
606
+ if (isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
607
+ const loadedConfig = await crossImport(configPath, cwd);
608
+ return {
609
+ loadedConfig,
610
+ configPath
611
+ };
599
612
  }
600
613
  class RspackCLI {
614
+ colors;
615
+ program;
616
+ constructor(){
617
+ this.colors = this.createColors();
618
+ this.program = yargs_0();
619
+ }
601
620
  async createCompiler(options, rspackCommand, callback) {
602
621
  process.env.RSPACK_CONFIG_VALIDATE ??= "loose";
603
- let config = await this.loadConfig(options);
604
- config = await this.buildConfig(config, options, rspackCommand);
622
+ let { config, pathMap } = await this.loadConfig(options);
623
+ config = await this.buildConfig(config, pathMap, options, rspackCommand);
605
624
  const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
606
625
  let compiler;
607
626
  try {
@@ -655,7 +674,7 @@ class RspackCLI {
655
674
  ];
656
675
  for (const command of builtinCommands)command.apply(this);
657
676
  }
658
- async buildConfig(item, options, command) {
677
+ async buildConfig(item, pathMap, options, command) {
659
678
  const isBuild = "build" === command;
660
679
  const isServe = "serve" === command;
661
680
  const internalBuildConfig = async (item)=>{
@@ -689,6 +708,14 @@ class RspackCLI {
689
708
  const installed = (item.plugins ||= []).find((item)=>item instanceof core_.ProgressPlugin);
690
709
  if (!installed) (item.plugins ??= []).push(new core_.ProgressPlugin());
691
710
  }
711
+ const cacheOptions = item.experiments?.cache;
712
+ if ("object" == typeof cacheOptions && "persistent" === cacheOptions.type) {
713
+ const configPaths = pathMap.get(item);
714
+ if (configPaths) cacheOptions.buildDependencies = [
715
+ ...configPaths,
716
+ ...cacheOptions.buildDependencies || []
717
+ ];
718
+ }
692
719
  if (void 0 === item.stats) item.stats = {
693
720
  preset: "errors-warnings",
694
721
  timings: true
@@ -708,22 +735,29 @@ class RspackCLI {
708
735
  return internalBuildConfig(item);
709
736
  }
710
737
  async loadConfig(options) {
711
- let loadedConfig = await loadRspackConfig(options);
738
+ const config = await loadRspackConfig(options);
739
+ if (!config) return {
740
+ config: this.filterConfig(options, {}),
741
+ pathMap: new WeakMap()
742
+ };
743
+ let { loadedConfig, configPath } = config;
712
744
  if ("function" == typeof loadedConfig) {
713
- var _options_argv;
714
- let functionResult = loadedConfig(null == (_options_argv = options.argv) ? void 0 : _options_argv.env, options.argv);
745
+ let functionResult = loadedConfig(options.argv?.env, options.argv);
715
746
  if ("function" == typeof functionResult.then) functionResult = await functionResult;
716
747
  loadedConfig = functionResult;
717
- if ("extends" in loadedConfig && loadedConfig.extends) {
718
- const tempConfigPath = external_node_path_["default"].resolve(process.cwd(), "rspack.config.js");
719
- loadedConfig = await loadExtendedConfig(loadedConfig, tempConfigPath, process.cwd(), options);
720
- }
721
748
  }
749
+ const { config: extendedConfig, pathMap } = await loadExtendedConfig(loadedConfig, configPath, process.cwd(), options);
750
+ return {
751
+ config: this.filterConfig(options, extendedConfig),
752
+ pathMap
753
+ };
754
+ }
755
+ filterConfig(options, config) {
722
756
  if (options.configName) {
723
757
  const notFoundConfigNames = [];
724
- loadedConfig = options.configName.map((configName)=>{
758
+ config = options.configName.map((configName)=>{
725
759
  let found;
726
- found = Array.isArray(loadedConfig) ? loadedConfig.find((options)=>options.name === configName) : loadedConfig.name === configName ? loadedConfig : void 0;
760
+ found = Array.isArray(config) ? config.find((options)=>options.name === configName) : config.name === configName ? config : void 0;
727
761
  if (!found) notFoundConfigNames.push(configName);
728
762
  return found;
729
763
  });
@@ -732,7 +766,7 @@ class RspackCLI {
732
766
  process.exit(2);
733
767
  }
734
768
  }
735
- return loadedConfig;
769
+ return config;
736
770
  }
737
771
  isMultipleCompiler(compiler) {
738
772
  return Boolean(compiler.compilers);
@@ -740,12 +774,6 @@ class RspackCLI {
740
774
  isWatch(compiler) {
741
775
  return Boolean(this.isMultipleCompiler(compiler) ? compiler.compilers.some((compiler)=>compiler.options.watch) : compiler.options.watch);
742
776
  }
743
- constructor(){
744
- _define_property(this, "colors", void 0);
745
- _define_property(this, "program", void 0);
746
- this.colors = this.createColors();
747
- this.program = yargs_0();
748
- }
749
777
  }
750
778
  function defineConfig(config) {
751
779
  return config;
@@ -9,5 +9,19 @@ export type LoadedRspackConfig = undefined | RspackOptions | MultiRspackOptions
9
9
  * @param options CLI options
10
10
  * @returns The merged configuration
11
11
  */
12
- export declare function loadExtendedConfig(config: RspackOptions | MultiRspackOptions, configPath: string, cwd: string, options: RspackCLIOptions): Promise<RspackOptions | MultiRspackOptions>;
13
- export declare function loadRspackConfig(options: RspackCLIOptions, cwd?: string): Promise<LoadedRspackConfig>;
12
+ export declare function loadExtendedConfig(config: RspackOptions, configPath: string, cwd: string, options: RspackCLIOptions): Promise<{
13
+ config: RspackOptions;
14
+ pathMap: WeakMap<RspackOptions, string[]>;
15
+ }>;
16
+ export declare function loadExtendedConfig(config: MultiRspackOptions, configPath: string, cwd: string, options: RspackCLIOptions): Promise<{
17
+ config: MultiRspackOptions;
18
+ pathMap: WeakMap<RspackOptions, string[]>;
19
+ }>;
20
+ export declare function loadExtendedConfig(config: RspackOptions | MultiRspackOptions, configPath: string, cwd: string, options: RspackCLIOptions): Promise<{
21
+ config: RspackOptions | MultiRspackOptions;
22
+ pathMap: WeakMap<RspackOptions, string[]>;
23
+ }>;
24
+ export declare function loadRspackConfig(options: RspackCLIOptions, cwd?: string): Promise<{
25
+ loadedConfig: LoadedRspackConfig;
26
+ configPath: string;
27
+ } | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/cli",
3
- "version": "1.4.10",
3
+ "version": "1.5.0-beta.0",
4
4
  "description": "CLI for rspack",
5
5
  "homepage": "https://rspack.rs",
6
6
  "bugs": "https://github.com/web-infra-dev/rspack/issues",
@@ -38,7 +38,7 @@
38
38
  "yargs": "17.7.2"
39
39
  },
40
40
  "devDependencies": {
41
- "@rslib/core": "0.10.5",
41
+ "@rslib/core": "0.11.0",
42
42
  "@types/interpret": "^1.1.3",
43
43
  "@types/rechoir": "^0.6.4",
44
44
  "@types/webpack-bundle-analyzer": "^4.7.0",
@@ -47,8 +47,8 @@
47
47
  "cross-env": "^7.0.3",
48
48
  "execa": "^5.1.1",
49
49
  "ts-node": "^10.9.2",
50
- "typescript": "^5.8.3",
51
- "@rspack/core": "1.4.10"
50
+ "typescript": "^5.9.2",
51
+ "@rspack/core": "1.5.0-beta.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@rspack/core": "^1.0.0-alpha || ^1.x"