From 9e916795b82f2be3355edfd9e87160918b1b12b0 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Wed, 6 Nov 2024 20:44:45 +0530 Subject: [PATCH] feat!: remove `--define-process-env-node-env` in favor of `--config-node-env` (#2923) (#4318) --- packages/webpack-cli/src/webpack-cli.ts | 14 ++--- .../auto-mode.config.js | 0 .../config-node-env.test.js} | 23 +++----- test/build/config-node-env/src/index.js | 1 + .../webpack.config.js | 0 .../define-process-env-node-env/src/index.js | 1 - .../help.test.js.snap.devServer5.webpack5 | 57 ++++++++++++------- 7 files changed, 53 insertions(+), 43 deletions(-) rename test/build/{define-process-env-node-env => config-node-env}/auto-mode.config.js (100%) rename test/build/{define-process-env-node-env/define-process-env-node-env.test.js => config-node-env/config-node-env.test.js} (75%) create mode 100644 test/build/config-node-env/src/index.js rename test/build/{define-process-env-node-env => config-node-env}/webpack.config.js (100%) delete mode 100644 test/build/define-process-env-node-env/src/index.js diff --git a/packages/webpack-cli/src/webpack-cli.ts b/packages/webpack-cli/src/webpack-cli.ts index 8c5bc9746b7..23b17b36045 100644 --- a/packages/webpack-cli/src/webpack-cli.ts +++ b/packages/webpack-cli/src/webpack-cli.ts @@ -972,11 +972,12 @@ class WebpackCLI implements IWebpackCLI { }, ], multiple: false, - description: "Sets process.env.NODE_ENV to the specified value.", + description: + "Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead)", helpLevel: "minimum", }, { - name: "define-process-env-node-env", + name: "config-node-env", configs: [ { type: "string", @@ -984,8 +985,8 @@ class WebpackCLI implements IWebpackCLI { ], multiple: false, description: - "Sets process.env.NODE_ENV to the specified value. (Currently an alias for `--node-env`).", - helpLevel: "verbose", + "Sets process.env.NODE_ENV to the specified value for access within the configuration.", + helpLevel: "minimum", }, // Adding more plugins @@ -2364,9 +2365,8 @@ class WebpackCLI implements IWebpackCLI { options: Partial, callback?: Callback<[Error | undefined, WebpackCLIStats | undefined]>, ): Promise { - if (typeof options.defineProcessEnvNodeEnv === "string") { - // TODO: This should only set NODE_ENV for the runtime not for the config too. Change this during next breaking change. - process.env.NODE_ENV = options.defineProcessEnvNodeEnv; + if (typeof options.configNodeEnv === "string") { + process.env.NODE_ENV = options.configNodeEnv; } else if (typeof options.nodeEnv === "string") { process.env.NODE_ENV = options.nodeEnv; } diff --git a/test/build/define-process-env-node-env/auto-mode.config.js b/test/build/config-node-env/auto-mode.config.js similarity index 100% rename from test/build/define-process-env-node-env/auto-mode.config.js rename to test/build/config-node-env/auto-mode.config.js diff --git a/test/build/define-process-env-node-env/define-process-env-node-env.test.js b/test/build/config-node-env/config-node-env.test.js similarity index 75% rename from test/build/define-process-env-node-env/define-process-env-node-env.test.js rename to test/build/config-node-env/config-node-env.test.js index 814adf19991..669799d723b 100644 --- a/test/build/define-process-env-node-env/define-process-env-node-env.test.js +++ b/test/build/config-node-env/config-node-env.test.js @@ -2,12 +2,9 @@ const { run } = require("../../utils/test-utils"); -describe("--define-process-env-node-env flag", () => { +describe("--config-node-env flag", () => { it('should set "process.env.NODE_ENV" to "development"', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - "--define-process-env-node-env", - "development", - ]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--config-node-env", "development"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -15,10 +12,7 @@ describe("--define-process-env-node-env flag", () => { }); it('should set "process.env.NODE_ENV" to "production"', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - "--define-process-env-node-env", - "production", - ]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--config-node-env", "production"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -26,10 +20,7 @@ describe("--define-process-env-node-env flag", () => { }); it('should set "process.env.NODE_ENV" to "none"', async () => { - const { exitCode, stderr, stdout } = await run(__dirname, [ - "--define-process-env-node-env", - "none", - ]); + const { exitCode, stderr, stdout } = await run(__dirname, ["--config-node-env", "none"]); expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); @@ -38,7 +29,7 @@ describe("--define-process-env-node-env flag", () => { it('should set "process.env.NODE_ENV" and the "mode" option to "development"', async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - "--define-process-env-node-env", + "--config-node-env", "development", "--config", "./auto-mode.config.js", @@ -51,7 +42,7 @@ describe("--define-process-env-node-env flag", () => { it('should set "process.env.NODE_ENV" and the "mode" option to "production"', async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - "--define-process-env-node-env", + "--config-node-env", "production", "--config", "./auto-mode.config.js", @@ -64,7 +55,7 @@ describe("--define-process-env-node-env flag", () => { it('should set "process.env.NODE_ENV" and the "mode" option to "none"', async () => { const { exitCode, stderr, stdout } = await run(__dirname, [ - "--define-process-env-node-env", + "--config-node-env", "none", "--config", "./auto-mode.config.js", diff --git a/test/build/config-node-env/src/index.js b/test/build/config-node-env/src/index.js new file mode 100644 index 00000000000..c14261d870d --- /dev/null +++ b/test/build/config-node-env/src/index.js @@ -0,0 +1 @@ +console.log('--config-node-env test'); \ No newline at end of file diff --git a/test/build/define-process-env-node-env/webpack.config.js b/test/build/config-node-env/webpack.config.js similarity index 100% rename from test/build/define-process-env-node-env/webpack.config.js rename to test/build/config-node-env/webpack.config.js diff --git a/test/build/define-process-env-node-env/src/index.js b/test/build/define-process-env-node-env/src/index.js deleted file mode 100644 index 59e782152a2..00000000000 --- a/test/build/define-process-env-node-env/src/index.js +++ /dev/null @@ -1 +0,0 @@ -console.log('--define-process-env-node-env test'); \ No newline at end of file diff --git a/test/help/__snapshots__/help.test.js.snap.devServer5.webpack5 b/test/help/__snapshots__/help.test.js.snap.devServer5.webpack5 index c1ae9165b41..c07bceeecb6 100644 --- a/test/help/__snapshots__/help.test.js.snap.devServer5.webpack5 +++ b/test/help/__snapshots__/help.test.js.snap.devServer5.webpack5 @@ -99,7 +99,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -156,7 +157,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -213,7 +215,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -269,7 +272,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -316,7 +320,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -363,7 +368,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -410,7 +416,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -457,7 +464,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -504,7 +512,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -831,7 +840,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -876,7 +886,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -921,7 +932,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -966,7 +978,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -1011,7 +1024,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -1056,7 +1070,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -1102,7 +1117,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -1159,7 +1175,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -1420,7 +1437,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file. @@ -1475,7 +1493,8 @@ Options: -m, --merge Merge two or more configurations using 'webpack-merge'. --disable-interpret Disable interpret for loading the config file. --env Environment variables passed to the configuration when it is a function, e.g. "myvar" or "myvar=myval". - --node-env Sets process.env.NODE_ENV to the specified value. + --node-env Sets process.env.NODE_ENV to the specified value for access within the configuration.(Deprecated: Use '--config-node-env' instead) + --config-node-env Sets process.env.NODE_ENV to the specified value for access within the configuration. --analyze It invokes webpack-bundle-analyzer plugin to get bundle information. --progress [value] Print compilation progress during build. -j, --json [pathToJsonFile] Prints result as JSON or store it in a file.