From df22777f4ebbd5834f6135f459746a31bdff40a8 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 31 Dec 2024 10:09:01 +0100 Subject: [PATCH] remove the default behavior of env replacement on node env --- README.md | 2 +- src/env.ts | 3 --- test/integration/dev-prod-convention/index.test.ts | 6 +++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3426dc16..ca80c2c1 100644 --- a/README.md +++ b/README.md @@ -358,7 +358,7 @@ This convention keeps shared modules private while enabling efficient bundling a - External (`--external `): Specifying extra external dependencies, by default it is the list of `dependencies` and `peerDependencies` from `package.json`. Values are separate by comma. - Target (`--target `): Set ECMAScript target (default: `'es2015'`). - Runtime (`--runtime `): Set build runtime (default: `'browser'`). -- Environment (`--env `): Define environment variables. (default: `NODE_ENV`, separate by comma) +- Environment (`--env `): Define environment variables. (default: `[]`, separate by comma) - Working Directory (`--cwd `): Set current working directory where containing `package.json`. - Minify (`-m`): Compress output. - Watch (`-w`): Watch for source file changes. diff --git a/src/env.ts b/src/env.ts index 5ae7f682..aa3ac44d 100644 --- a/src/env.ts +++ b/src/env.ts @@ -7,9 +7,6 @@ export function getDefinedInlineVariables( envs: string[], parsedExportCondition: ParsedExportCondition, ): Record { - if (!envs.includes('NODE_ENV')) { - envs.push('NODE_ENV') - } const envVars = envs.reduce((acc: Record, key) => { const value = process.env[key] if (typeof value !== 'undefined') { diff --git a/test/integration/dev-prod-convention/index.test.ts b/test/integration/dev-prod-convention/index.test.ts index e74c5457..acd48cef 100644 --- a/test/integration/dev-prod-convention/index.test.ts +++ b/test/integration/dev-prod-convention/index.test.ts @@ -12,9 +12,9 @@ describe('integration dev-prod-convention', () => { 'index.development.mjs': /= "development"/, 'index.production.js': /= "production"/, 'index.production.mjs': /= "production"/, - // In jest the NODE_ENV is set to test - 'index.js': /= "test"/, - 'index.mjs': /= "test"/, + // Do not replace NODE_ENV by default + 'index.js': /= process.env.NODE_ENV/, + 'index.mjs': /= process.env.NODE_ENV/, }) }, )