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 (#17375)
  • Loading branch information
ndcunningham committed Jun 2, 2023
1 parent a0b41eb commit 8f771e0
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

1 comment on commit 8f771e0

@vercel
Copy link

@vercel vercel bot commented on 8f771e0 Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.