Skip to content

Commit

Permalink
feat!: remove --define-process-env-node-env in favor of `--config-n…
Browse files Browse the repository at this point in the history
…ode-env` (#2923) (#4318)
  • Loading branch information
snitin315 authored Nov 6, 2024
1 parent 856f866 commit 6c5bec1
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 43 deletions.
14 changes: 7 additions & 7 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,20 +971,21 @@ 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",
},
],
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
Expand Down Expand Up @@ -2363,9 +2364,8 @@ class WebpackCLI implements IWebpackCLI {
options: Partial<WebpackDevServerOptions>,
callback?: Callback<[Error | undefined, WebpackCLIStats | undefined]>,
): Promise<WebpackCompiler> {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,25 @@

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();
expect(stdout).toContain("mode: 'development'");
});

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();
expect(stdout).toContain("mode: 'production'");
});

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();
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions test/build/config-node-env/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('--config-node-env test');
1 change: 0 additions & 1 deletion test/build/define-process-env-node-env/src/index.js

This file was deleted.

Loading

0 comments on commit 6c5bec1

Please sign in to comment.