@rspack/cli 0.5.1 → 0.5.2-canary-e13c103-20240123120827

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.
@@ -38,6 +38,14 @@ class BuildCommand {
38
38
  describe: "emit stats json"
39
39
  }
40
40
  }), async (options) => {
41
+ const env = (0, options_1.ensureEnvObject)(options);
42
+ if (options.watch) {
43
+ (0, options_1.setBuiltinEnvArg)(env, "WATCH", true);
44
+ }
45
+ else {
46
+ (0, options_1.setBuiltinEnvArg)(env, "BUNDLE", true);
47
+ (0, options_1.setBuiltinEnvArg)(env, "BUILD", true);
48
+ }
41
49
  const logger = cli.getLogger();
42
50
  let createJsonStringifyStream;
43
51
  if (options.json) {
@@ -8,6 +8,7 @@ class ServeCommand {
8
8
  cli.program.command(["serve", "server", "s", "dev"], "run the rspack dev server.", options_1.commonOptions, async (options) => {
9
9
  var _a, _b, _c, _d;
10
10
  var _e, _f;
11
+ (0, options_1.setBuiltinEnvArg)((0, options_1.ensureEnvObject)(options), "SERVE", true);
11
12
  const rspackOptions = {
12
13
  ...options,
13
14
  argv: {
@@ -82,3 +82,15 @@ export declare const previewOptions: (yargs: yargs.Argv<{}>) => yargs.Argv<yargs
82
82
  };
83
83
  }>>;
84
84
  export declare function normalizeEnv(argv: yargs.Arguments): void;
85
+ /**
86
+ * set builtin env from cli - like `WEBPACK_BUNDLE=true`. also for `RSPACK_` prefixed.
87
+ * @param env the `argv.env` object
88
+ * @param envNameSuffix the added env will be `WEBPACK_${envNameSuffix}` and `RSPACK_${envNameSuffix}`
89
+ * @param value
90
+ */
91
+ export declare function setBuiltinEnvArg(env: Record<string, any>, envNameSuffix: string, value: any): void;
92
+ /**
93
+ * infer `argv.env` as an object for it was transformed from array to object after `normalizeEnv` middleware
94
+ * @returns the reference of `argv.env` object
95
+ */
96
+ export declare function ensureEnvObject<T extends Record<string, unknown>>(options: yargs.Arguments): T;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeEnv = exports.previewOptions = exports.commonOptions = void 0;
3
+ exports.ensureEnvObject = exports.setBuiltinEnvArg = exports.normalizeEnv = exports.previewOptions = exports.commonOptions = void 0;
4
4
  const commonOptions = (yargs) => {
5
5
  return yargs
6
6
  .options({
@@ -127,3 +127,36 @@ function normalizeEnv(argv) {
127
127
  argv.env = envObj;
128
128
  }
129
129
  exports.normalizeEnv = normalizeEnv;
130
+ /**
131
+ * set builtin env from cli - like `WEBPACK_BUNDLE=true`. also for `RSPACK_` prefixed.
132
+ * @param env the `argv.env` object
133
+ * @param envNameSuffix the added env will be `WEBPACK_${envNameSuffix}` and `RSPACK_${envNameSuffix}`
134
+ * @param value
135
+ */
136
+ function setBuiltinEnvArg(env, envNameSuffix, value) {
137
+ const envNames = [
138
+ // TODO: breaking change
139
+ // `WEBPACK_${envNameSuffix}`,
140
+ `RSPACK_${envNameSuffix}`
141
+ ];
142
+ for (const envName of envNames) {
143
+ if (envName in env) {
144
+ continue;
145
+ }
146
+ env[envName] = value;
147
+ }
148
+ }
149
+ exports.setBuiltinEnvArg = setBuiltinEnvArg;
150
+ /**
151
+ * infer `argv.env` as an object for it was transformed from array to object after `normalizeEnv` middleware
152
+ * @returns the reference of `argv.env` object
153
+ */
154
+ function ensureEnvObject(options) {
155
+ if (Array.isArray(options.env)) {
156
+ // in case that cli haven't got `normalizeEnv` middleware applied
157
+ normalizeEnv(options);
158
+ }
159
+ options.env = options.env || {};
160
+ return options.env;
161
+ }
162
+ exports.ensureEnvObject = ensureEnvObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/cli",
3
- "version": "0.5.1",
3
+ "version": "0.5.2-canary-e13c103-20240123120827",
4
4
  "license": "MIT",
5
5
  "description": "CLI for rspack",
6
6
  "bin": {
@@ -32,7 +32,7 @@
32
32
  "internal-ip": "6.2.0",
33
33
  "source-map-support": "^0.5.19",
34
34
  "ts-node": "10.9.1",
35
- "@rspack/core": "0.5.1"
35
+ "@rspack/core": "0.5.2-canary-e13c103-20240123120827"
36
36
  },
37
37
  "dependencies": {
38
38
  "@discoveryjs/json-ext": "^0.5.7",
@@ -43,11 +43,11 @@
43
43
  "semver": "6.3.1",
44
44
  "webpack-bundle-analyzer": "4.6.1",
45
45
  "yargs": "17.6.2",
46
- "@rspack/dev-server": "0.5.1"
46
+ "@rspack/dev-server": "0.5.2-canary-e13c103-20240123120827"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsc -b ./tsconfig.build.json",
50
50
  "dev": "tsc -b -w",
51
- "test": "cross-env RSPACK_DEP_WARNINGS=false jest --runInBand"
51
+ "test": "cross-env jest --runInBand"
52
52
  }
53
53
  }