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 8cfbdd0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
19 changes: 15 additions & 4 deletions e2e/node/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,28 @@ 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']);
`
);

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

checkFilesExist(
`dist/apps/${nodeapp}/main.js`,
`dist/apps/${nodeapp}/additional-main.js`
);
const result = execSync(`node dist/apps/${nodeapp}/main.js`, {
cwd: tmpProjPath(),
}).toString();

const result = execSync(
`NODE_ENV=development && node dist/apps/${nodeapp}/main.js`,
{
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 8cfbdd0

Please sign in to comment.