Skip to content

Commit

Permalink
fix(node): When serving using js:node executor NODE_ENV should not be…
Browse files Browse the repository at this point in the history
… undefined

closes: nrwl#16960
  • Loading branch information
ndcunningham committed Jun 1, 2023
1 parent f5e52db commit 7ea09f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion e2e/node/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,16 @@ describe('Node Applications', () => {
`apps/${nodeapp}/src/additional-main.ts`,
`console.log('Hello Additional World!');`
);
updateFile(`apps/${nodeapp}/src/main.ts`, `console.log('Hello World!');`);
updateFile(
`apps/${nodeapp}/src/main.ts`,
`console.log('Hello World!');
console.log('env: ' + process.env['NODE_ENV']);
`
);
// deleting `NODE_ENV` value, so that it's `undefined`, and not `"test"`
// this simulates a real behaviour of running node outside on this e2e test
delete process.env.NODE_ENV;

await runCLIAsync(`build ${nodeapp}`);

checkFilesExist(
Expand All @@ -119,6 +128,7 @@ describe('Node Applications', () => {
cwd: tmpProjPath(),
}).toString();
expect(result).toContain('Hello World!');
expect(result).toContain('env: development');

const additionalResult = execSync(
`node dist/apps/${nodeapp}/additional-main.js`,
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild/src/executors/esbuild/esbuild.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function* esbuildExecutor(
_options: EsBuildExecutorOptions,
context: ExecutorContext
) {
process.env.NODE_ENV ??= context.configurationName;
process.env.NODE_ENV ??= context.configurationName ?? 'production';

const options = normalizeOptions(_options, context);
if (options.deleteOutputPath) removeSync(options.outputPath);
Expand Down
1 change: 1 addition & 0 deletions packages/js/src/executors/node/node.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export async function* nodeExecutor(
options: NodeExecutorOptions,
context: ExecutorContext
) {
process.env.NODE_ENV ??= context?.configurationName ?? 'development';
const project = context.projectGraph.nodes[context.projectName];
const buildTarget = parseTargetString(
options.buildTarget,
Expand Down

0 comments on commit 7ea09f5

Please sign in to comment.