@rspack/cli 1.2.8 → 1.3.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  exports.ids = [
3
- '390'
3
+ '957'
4
4
  ];
5
5
  exports.modules = {
6
6
  "./src/utils/profile.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
@@ -1,5 +1,5 @@
1
1
  export const __webpack_ids__ = [
2
- '390'
2
+ '957'
3
3
  ];
4
4
  export const __webpack_modules__ = {
5
5
  "./src/utils/profile.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
package/dist/index.js CHANGED
@@ -542,19 +542,63 @@ var __webpack_exports__ = {};
542
542
  throw error;
543
543
  }
544
544
  };
545
+ async function loadExtendedConfig(config, configPath, cwd, options) {
546
+ if (!("extends" in config) || !config.extends) return config;
547
+ const extendsList = Array.isArray(config.extends) ? config.extends : [
548
+ config.extends
549
+ ];
550
+ const { extends: _, ...configWithoutExtends } = config;
551
+ const baseDir = external_node_path_default().dirname(configPath);
552
+ let resultConfig = configWithoutExtends;
553
+ for (const extendPath of extendsList){
554
+ let resolvedPath;
555
+ if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
556
+ resolvedPath = external_node_path_default().resolve(baseDir, extendPath);
557
+ if (!external_node_path_default().extname(resolvedPath)) {
558
+ const foundConfig = utils_findConfig(resolvedPath);
559
+ if (foundConfig) resolvedPath = foundConfig;
560
+ else throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
561
+ }
562
+ } else try {
563
+ resolvedPath = require.resolve(extendPath, {
564
+ paths: [
565
+ baseDir,
566
+ cwd
567
+ ]
568
+ });
569
+ } catch (error) {
570
+ throw new Error(`Cannot find module '${extendPath}' to extend from.`);
571
+ }
572
+ if (!external_node_fs_default().existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
573
+ if (utils_isTsFile(resolvedPath) && "register" === options.configLoader) await registerLoader(resolvedPath);
574
+ let extendedConfig = await crossImport(resolvedPath, cwd);
575
+ if ("function" == typeof extendedConfig) {
576
+ var _options_argv;
577
+ extendedConfig = extendedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
578
+ if ("function" == typeof extendedConfig.then) extendedConfig = await extendedConfig;
579
+ }
580
+ extendedConfig = await loadExtendedConfig(extendedConfig, resolvedPath, cwd, options);
581
+ resultConfig = core_.util.cleverMerge(extendedConfig, resultConfig);
582
+ }
583
+ return resultConfig;
584
+ }
545
585
  async function loadRspackConfig(options, cwd = process.cwd()) {
586
+ let configPath;
587
+ let loadedConfig;
546
588
  if (options.config) {
547
- const configPath = external_node_path_default().resolve(cwd, options.config);
589
+ configPath = external_node_path_default().resolve(cwd, options.config);
548
590
  if (!external_node_fs_default().existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
549
591
  if (utils_isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
550
- return crossImport(configPath, cwd);
551
- }
552
- const defaultConfig = utils_findConfig(external_node_path_default().resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
553
- if (defaultConfig) {
592
+ loadedConfig = await crossImport(configPath, cwd);
593
+ } else {
594
+ const defaultConfig = utils_findConfig(external_node_path_default().resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
595
+ if (!defaultConfig) return {};
596
+ configPath = defaultConfig;
554
597
  if (utils_isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
555
- return crossImport(defaultConfig, cwd);
598
+ loadedConfig = await crossImport(defaultConfig, cwd);
556
599
  }
557
- return {};
600
+ if ("function" != typeof loadedConfig && configPath) loadedConfig = await loadExtendedConfig(loadedConfig, configPath, cwd, options);
601
+ return loadedConfig;
558
602
  }
559
603
  function _define_property(obj, key, value) {
560
604
  if (key in obj) Object.defineProperty(obj, key, {
@@ -647,7 +691,7 @@ var __webpack_exports__ = {};
647
691
  }
648
692
  if (options.profile) item.profile = true;
649
693
  if (process.env.RSPACK_PROFILE) {
650
- const { applyProfile } = await __webpack_require__.e("390").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
694
+ const { applyProfile } = await __webpack_require__.e("957").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
651
695
  await applyProfile(process.env.RSPACK_PROFILE, item);
652
696
  }
653
697
  if (options.watch) item.watch = options.watch;
@@ -680,8 +724,13 @@ var __webpack_exports__ = {};
680
724
  let loadedConfig = await loadRspackConfig(options);
681
725
  if ("function" == typeof loadedConfig) {
682
726
  var _options_argv;
683
- loadedConfig = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
684
- if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
727
+ let functionResult = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
728
+ if ("function" == typeof functionResult.then) functionResult = await functionResult;
729
+ loadedConfig = functionResult;
730
+ if ("extends" in loadedConfig && loadedConfig.extends) {
731
+ const tempConfigPath = external_node_path_default().resolve(process.cwd(), "rspack.config.js");
732
+ loadedConfig = await loadExtendedConfig(loadedConfig, tempConfigPath, process.cwd(), options);
733
+ }
685
734
  }
686
735
  if (options.configName) {
687
736
  const notFoundConfigNames = [];
package/dist/index.mjs CHANGED
@@ -522,19 +522,63 @@ const registerLoader = async (configPath)=>{
522
522
  throw error;
523
523
  }
524
524
  };
525
+ async function loadExtendedConfig(config, configPath, cwd, options) {
526
+ if (!("extends" in config) || !config.extends) return config;
527
+ const extendsList = Array.isArray(config.extends) ? config.extends : [
528
+ config.extends
529
+ ];
530
+ const { extends: _, ...configWithoutExtends } = config;
531
+ const baseDir = external_node_path_["default"].dirname(configPath);
532
+ let resultConfig = configWithoutExtends;
533
+ for (const extendPath of extendsList){
534
+ let resolvedPath;
535
+ if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
536
+ resolvedPath = external_node_path_["default"].resolve(baseDir, extendPath);
537
+ if (!external_node_path_["default"].extname(resolvedPath)) {
538
+ const foundConfig = utils_findConfig(resolvedPath);
539
+ if (foundConfig) resolvedPath = foundConfig;
540
+ else throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
541
+ }
542
+ } else try {
543
+ resolvedPath = require.resolve(extendPath, {
544
+ paths: [
545
+ baseDir,
546
+ cwd
547
+ ]
548
+ });
549
+ } catch (error) {
550
+ throw new Error(`Cannot find module '${extendPath}' to extend from.`);
551
+ }
552
+ if (!external_node_fs_["default"].existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
553
+ if (utils_isTsFile(resolvedPath) && "register" === options.configLoader) await registerLoader(resolvedPath);
554
+ let extendedConfig = await crossImport(resolvedPath, cwd);
555
+ if ("function" == typeof extendedConfig) {
556
+ var _options_argv;
557
+ extendedConfig = extendedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
558
+ if ("function" == typeof extendedConfig.then) extendedConfig = await extendedConfig;
559
+ }
560
+ extendedConfig = await loadExtendedConfig(extendedConfig, resolvedPath, cwd, options);
561
+ resultConfig = core_.util.cleverMerge(extendedConfig, resultConfig);
562
+ }
563
+ return resultConfig;
564
+ }
525
565
  async function loadRspackConfig(options, cwd = process.cwd()) {
566
+ let configPath;
567
+ let loadedConfig;
526
568
  if (options.config) {
527
- const configPath = external_node_path_["default"].resolve(cwd, options.config);
569
+ configPath = external_node_path_["default"].resolve(cwd, options.config);
528
570
  if (!external_node_fs_["default"].existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
529
571
  if (utils_isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
530
- return crossImport(configPath, cwd);
531
- }
532
- const defaultConfig = utils_findConfig(external_node_path_["default"].resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
533
- if (defaultConfig) {
572
+ loadedConfig = await crossImport(configPath, cwd);
573
+ } else {
574
+ const defaultConfig = utils_findConfig(external_node_path_["default"].resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
575
+ if (!defaultConfig) return {};
576
+ configPath = defaultConfig;
534
577
  if (utils_isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
535
- return crossImport(defaultConfig, cwd);
578
+ loadedConfig = await crossImport(defaultConfig, cwd);
536
579
  }
537
- return {};
580
+ if ("function" != typeof loadedConfig && configPath) loadedConfig = await loadExtendedConfig(loadedConfig, configPath, cwd, options);
581
+ return loadedConfig;
538
582
  }
539
583
  function _define_property(obj, key, value) {
540
584
  if (key in obj) Object.defineProperty(obj, key, {
@@ -627,7 +671,7 @@ class RspackCLI {
627
671
  }
628
672
  if (options.profile) item.profile = true;
629
673
  if (process.env.RSPACK_PROFILE) {
630
- const { applyProfile } = await __webpack_require__.e("390").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
674
+ const { applyProfile } = await __webpack_require__.e("957").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
631
675
  await applyProfile(process.env.RSPACK_PROFILE, item);
632
676
  }
633
677
  if (options.watch) item.watch = options.watch;
@@ -660,8 +704,13 @@ class RspackCLI {
660
704
  let loadedConfig = await loadRspackConfig(options);
661
705
  if ("function" == typeof loadedConfig) {
662
706
  var _options_argv;
663
- loadedConfig = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
664
- if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
707
+ let functionResult = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
708
+ if ("function" == typeof functionResult.then) functionResult = await functionResult;
709
+ loadedConfig = functionResult;
710
+ if ("extends" in loadedConfig && loadedConfig.extends) {
711
+ const tempConfigPath = external_node_path_["default"].resolve(process.cwd(), "rspack.config.js");
712
+ loadedConfig = await loadExtendedConfig(loadedConfig, tempConfigPath, process.cwd(), options);
713
+ }
665
714
  }
666
715
  if (options.configName) {
667
716
  const notFoundConfigNames = [];
@@ -1,4 +1,13 @@
1
- import type { MultiRspackOptions, RspackOptions } from "@rspack/core";
1
+ import { type MultiRspackOptions, type RspackOptions } from "@rspack/core";
2
2
  import type { RspackCLIOptions } from "../types";
3
3
  export type LoadedRspackConfig = undefined | RspackOptions | MultiRspackOptions | ((env: Record<string, any>, argv?: Record<string, any>) => RspackOptions | MultiRspackOptions);
4
+ /**
5
+ * Loads and merges configurations from the 'extends' property
6
+ * @param config The configuration object that may contain an 'extends' property
7
+ * @param configPath The path to the configuration file
8
+ * @param cwd The current working directory
9
+ * @param options CLI options
10
+ * @returns The merged configuration
11
+ */
12
+ export declare function loadExtendedConfig(config: RspackOptions | MultiRspackOptions, configPath: string, cwd: string, options: RspackCLIOptions): Promise<RspackOptions | MultiRspackOptions>;
4
13
  export declare function loadRspackConfig(options: RspackCLIOptions, cwd?: string): Promise<LoadedRspackConfig>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/cli",
3
- "version": "1.2.8",
3
+ "version": "1.3.0-beta.0",
4
4
  "description": "CLI for rspack",
5
5
  "homepage": "https://rspack.dev",
6
6
  "bugs": "https://github.com/web-infra-dev/rspack/issues",
@@ -29,16 +29,16 @@
29
29
  ],
30
30
  "dependencies": {
31
31
  "@discoveryjs/json-ext": "^0.5.7",
32
- "@rspack/dev-server": "1.0.10",
32
+ "@rspack/dev-server": "1.1.0",
33
33
  "colorette": "2.0.20",
34
34
  "exit-hook": "^4.0.0",
35
35
  "interpret": "^3.1.1",
36
36
  "rechoir": "^0.8.0",
37
- "webpack-bundle-analyzer": "4.6.1",
37
+ "webpack-bundle-analyzer": "4.10.2",
38
38
  "yargs": "17.7.2"
39
39
  },
40
40
  "devDependencies": {
41
- "@rslib/core": "0.5.3",
41
+ "@rslib/core": "0.5.4",
42
42
  "@types/interpret": "^1.1.3",
43
43
  "@types/rechoir": "^0.6.4",
44
44
  "@types/webpack-bundle-analyzer": "^4.7.0",
@@ -48,8 +48,8 @@
48
48
  "execa": "^5.1.1",
49
49
  "ts-node": "^10.9.2",
50
50
  "typescript": "^5.7.3",
51
- "@rspack/core": "1.2.8",
52
- "@rspack/tracing": "1.2.8"
51
+ "@rspack/core": "1.3.0-beta.0",
52
+ "@rspack/tracing": "1.3.0-beta.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@rspack/core": "^1.0.0-alpha || ^1.x",