@rspack/cli 1.7.2 → 2.0.0-canary-20260116

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/README.md CHANGED
@@ -6,6 +6,30 @@
6
6
 
7
7
  Command-line interface for rspack.
8
8
 
9
+ ## Installation
10
+
11
+ ```bash
12
+ pnpm add -D @rspack/cli
13
+ # or
14
+ npm install -D @rspack/cli
15
+ # or
16
+ yarn add -D @rspack/cli
17
+ ```
18
+
19
+ ## Required dependencies
20
+
21
+ The `rspack dev` and `rspack preview` commands require [@rspack/dev-server](https://www.npmjs.com/package/@rspack/dev-server) to be installed as a peer dependency:
22
+
23
+ ```bash
24
+ pnpm add -D @rspack/dev-server
25
+ # or
26
+ npm install -D @rspack/dev-server
27
+ # or
28
+ yarn add -D @rspack/dev-server
29
+ ```
30
+
31
+ If you try to use these commands without installing `@rspack/dev-server`, you will see a helpful error message with installation instructions.
32
+
9
33
  ## Wasm test
10
34
 
11
35
  See [@rspack/test-tools](../rspack-test-tools) for details.
package/bin/rspack.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const nodeModule = require('node:module');
2
+ import nodeModule from 'node:module';
3
3
 
4
4
  // enable on-disk code caching of all modules loaded by Node.js
5
5
  // requires Nodejs >= 22.8.0
@@ -15,7 +15,7 @@ if (enableCompileCache) {
15
15
  // make it easier to identify the process via activity monitor or other tools
16
16
  process.title = 'rspack-node';
17
17
 
18
- const { RspackCLI } = require('../dist/index');
18
+ import { RspackCLI } from '../dist/index.js';
19
19
 
20
20
  async function runCLI() {
21
21
  const cli = new RspackCLI();
@@ -1,8 +1,9 @@
1
1
  import * as __rspack_external_module from "module";
2
2
  import * as __rspack_external_path from "path";
3
- import { __webpack_require__ } from "./rslib-runtime.mjs";
3
+ import { __webpack_require__ } from "./rslib-runtime.js";
4
4
  import node_path from "node:path";
5
5
  import node_util from "node:util";
6
+ import { rspack } from "@rspack/core";
6
7
  import { EventEmitter } from "events";
7
8
  import node_fs from "node:fs";
8
9
  import { createRequire } from "node:module";
@@ -667,12 +668,12 @@ const normalizeCommonOptions = (options, action)=>{
667
668
  }
668
669
  if ('devtool' in options) options.devtool = normalizeDevtoolOption(options.devtool);
669
670
  };
670
- const commonOptionsForBuildAndServe = (command)=>command.option('--analyze', 'analyze').option('-d, --devtool <value>', 'specify a developer tool for debugging. Defaults to `cheap-module-source-map` in development and `source-map` in production.').option('--entry <entry>', 'entry file', {
671
+ const commonOptionsForBuildAndServe = (command)=>command.option('-d, --devtool <value>', 'specify a developer tool for debugging. Defaults to `cheap-module-source-map` in development and `source-map` in production.').option('--entry <entry>', 'entry file', {
671
672
  type: [
672
673
  String
673
674
  ],
674
675
  default: []
675
- }).option('-m, --mode <mode>', 'mode').option('-o, --output-path <dir>', 'output path dir').option('--profile', 'capture timing information for each module').option('-w, --watch', 'watch');
676
+ }).option('-m, --mode <mode>', 'mode').option('-o, --output-path <dir>', 'output path dir').option('-w, --watch', 'watch');
676
677
  function setBuiltinEnvArg(env, envNameSuffix, value) {
677
678
  const envName = `RSPACK_${envNameSuffix}`;
678
679
  if (!(envName in env)) env[envName] = value;
@@ -757,8 +758,6 @@ class BuildCommand {
757
758
  });
758
759
  }
759
760
  }
760
- const rspackCore_require = createRequire(import.meta.url);
761
- const rspack = rspackCore_require('@rspack/core');
762
761
  class PreviewCommand {
763
762
  async apply(cli) {
764
763
  const command = cli.program.command('preview [dir]', 'run the Rspack server for build output').alias('p');
@@ -766,7 +765,16 @@ class PreviewCommand {
766
765
  command.action(async (dir, options)=>{
767
766
  setDefaultNodeEnv(options, 'production');
768
767
  normalizeCommonOptions(options, 'preview');
769
- const { RspackDevServer } = await import("@rspack/dev-server");
768
+ let RspackDevServer;
769
+ try {
770
+ const devServerModule = await import("@rspack/dev-server");
771
+ RspackDevServer = devServerModule.RspackDevServer;
772
+ } catch (error) {
773
+ const logger = cli.getLogger();
774
+ if (error?.code === 'MODULE_NOT_FOUND' || error?.code === 'ERR_MODULE_NOT_FOUND') logger.error('The "@rspack/dev-server" package is required to use the preview command.\nPlease install it by running:\n pnpm add -D @rspack/dev-server\n or\n npm install -D @rspack/dev-server');
775
+ else logger.error('Failed to load "@rspack/dev-server":\n' + (error?.message || String(error)));
776
+ process.exit(1);
777
+ }
770
778
  let { config } = await cli.loadConfig(options);
771
779
  config = await getPreviewConfig(config, options, dir);
772
780
  if (!Array.isArray(config)) config = [
@@ -822,7 +830,16 @@ class ServeCommand {
822
830
  setDefaultNodeEnv(cliOptions, 'development');
823
831
  normalizeCommonOptions(cliOptions, 'serve');
824
832
  cliOptions.hot = normalizeHotOption(cliOptions.hot);
825
- const { RspackDevServer } = await import("@rspack/dev-server");
833
+ let RspackDevServer;
834
+ try {
835
+ const devServerModule = await import("@rspack/dev-server");
836
+ RspackDevServer = devServerModule.RspackDevServer;
837
+ } catch (error) {
838
+ const logger = cli.getLogger();
839
+ if (error?.code === 'MODULE_NOT_FOUND' || error?.code === 'ERR_MODULE_NOT_FOUND') logger.error('The "@rspack/dev-server" package is required to use the serve command.\nPlease install it by running:\n pnpm add -D @rspack/dev-server\n or\n npm install -D @rspack/dev-server');
840
+ else logger.error('Failed to load "@rspack/dev-server":\n' + (error?.message || String(error)));
841
+ process.exit(1);
842
+ }
826
843
  const userConfig = await cli.buildCompilerConfig(cliOptions, 'serve');
827
844
  const compiler = await cli.createCompiler(userConfig);
828
845
  if (!compiler) return;
@@ -922,13 +939,14 @@ const isEsmFile = (filePath)=>{
922
939
  const packageJson = utils_readPackageUp(node_path.dirname(filePath));
923
940
  return packageJson?.type === 'module';
924
941
  };
942
+ const crossImport_require = createRequire(import.meta.url);
925
943
  const crossImport = async (path)=>{
926
944
  if (isEsmFile(path)) {
927
945
  const url = pathToFileURL(path).href;
928
946
  const { default: config } = await import(url);
929
947
  return config;
930
948
  }
931
- let result = require(path);
949
+ let result = crossImport_require(path);
932
950
  if (result && 'object' == typeof result && 'default' in result) result = result.default || {};
933
951
  return result;
934
952
  };
@@ -953,6 +971,7 @@ const isTsFile = (configPath)=>{
953
971
  };
954
972
  const utils_isTsFile = isTsFile;
955
973
  const lib = __webpack_require__("../../node_modules/.pnpm/pirates@4.0.7/node_modules/pirates/lib/index.js");
974
+ const loadConfig_require = createRequire(import.meta.url);
956
975
  const injectInlineSourceMap = ({ code, map })=>{
957
976
  if (map) {
958
977
  const base64Map = Buffer.from(map, 'utf8').toString('base64');
@@ -1039,7 +1058,7 @@ async function loadExtendedConfig(config, configPath, cwd, options) {
1039
1058
  else throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
1040
1059
  }
1041
1060
  } else try {
1042
- resolvedPath = require.resolve(extendPath, {
1061
+ resolvedPath = loadConfig_require.resolve(extendPath, {
1043
1062
  paths: [
1044
1063
  baseDir,
1045
1064
  cwd
@@ -1094,7 +1113,7 @@ class RspackCLI {
1094
1113
  this.colors = this.createColors();
1095
1114
  this.program = program;
1096
1115
  program.help();
1097
- program.version("1.7.2");
1116
+ program.version("2.0.0-canary-20260116");
1098
1117
  }
1099
1118
  async buildCompilerConfig(options, rspackCommand) {
1100
1119
  let { config, pathMap } = await this.loadConfig(options);
@@ -1158,20 +1177,8 @@ class RspackCLI {
1158
1177
  };
1159
1178
  item.output = item.output || {};
1160
1179
  if (options.outputPath) item.output.path = node_path.resolve(process.cwd(), options.outputPath);
1161
- if (options.analyze) {
1162
- const { BundleAnalyzerPlugin } = await import("webpack-bundle-analyzer");
1163
- (item.plugins ??= []).push({
1164
- name: 'rspack-bundle-analyzer',
1165
- apply (compiler) {
1166
- new BundleAnalyzerPlugin({
1167
- generateStatsFile: true
1168
- }).apply(compiler);
1169
- }
1170
- });
1171
- }
1172
- if (options.profile) item.profile = true;
1173
1180
  if (process.env.RSPACK_PROFILE) {
1174
- const { applyProfile } = await import("./1~274.mjs").then((mod)=>({
1181
+ const { applyProfile } = await import("./274.js").then((mod)=>({
1175
1182
  applyProfile: mod.applyProfile
1176
1183
  }));
1177
1184
  await applyProfile(process.env.RSPACK_PROFILE, process.env.RSPACK_TRACE_LAYER, process.env.RSPACK_TRACE_OUTPUT);
@@ -1185,7 +1192,7 @@ class RspackCLI {
1185
1192
  const installed = (item.plugins ||= []).find((item)=>item instanceof rspack.ProgressPlugin);
1186
1193
  if (!installed) (item.plugins ??= []).push(new rspack.ProgressPlugin());
1187
1194
  }
1188
- const cacheOptions = item.experiments?.cache;
1195
+ const cacheOptions = item.cache;
1189
1196
  if ('object' == typeof cacheOptions && 'persistent' === cacheOptions.type) {
1190
1197
  const configPaths = pathMap.get(item);
1191
1198
  if (configPaths) cacheOptions.buildDependencies = [
@@ -1,4 +1,4 @@
1
- import { node_fs, node_path, rspack } from "./131.mjs";
1
+ import { node_fs, node_path, rspack } from "./131.js";
2
2
  const DEFAULT_RUST_TRACE_LAYER = 'perfetto';
3
3
  async function applyProfile(filterValue, traceLayer = DEFAULT_RUST_TRACE_LAYER, traceOutput) {
4
4
  const { asyncExitHook } = await import("exit-hook");