Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: rename --define-process-env-node-env to --config-node-env #4318

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading