Skip to content

Local Build env vars should NOT be set on the global process#10538

Draft
falahat wants to merge 4 commits into
fix_angularfrom
local_build_fix_envvars
Draft

Local Build env vars should NOT be set on the global process#10538
falahat wants to merge 4 commits into
fix_angularfrom
local_build_fix_envvars

Conversation

@falahat
Copy link
Copy Markdown
Contributor

@falahat falahat commented May 20, 2026

Description

Instead of modifying process.env, this sets env vars on the child process that runs universal maker.

Scenarios Tested

Performed a local build

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors environment variable handling during local builds by passing them explicitly through function arguments instead of mutating the global process.env. Feedback focuses on improving type safety by using NodeJS.ProcessEnv instead of generic records and replacing any types in test stubs with proper TypeScript definitions to align with the repository's style guide.

export async function runUniversalMaker(projectRoot: string): Promise<AppHostingBuildOutput> {
export async function runUniversalMaker(
projectRoot: string,
addedEnv: Record<string, string> = {},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using NodeJS.ProcessEnv is more idiomatic for environment variables in Node.js and aligns with the return type of toProcessEnv. This also helps avoid unnecessary type assertions at the call site.

Suggested change
addedEnv: Record<string, string> = {},
addedEnv: NodeJS.ProcessEnv = {},

function executeUniversalMakerBinary(
universalMakerBinary: string,
projectRoot: string,
addedEnv: Record<string, string> = {},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Update the type of addedEnv to NodeJS.ProcessEnv to maintain consistency with runUniversalMaker and the standard Node.js environment variable types.

Suggested change
addedEnv: Record<string, string> = {},
addedEnv: NodeJS.ProcessEnv = {},

}
const apphostingBuildOutput = await runUniversalMaker(
projectRoot,
addedEnv as Record<string, string>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

With the updated signature of runUniversalMaker to accept NodeJS.ProcessEnv, this type assertion is no longer necessary.

Suggested change
addedEnv as Record<string, string>,
addedEnv,

expect(process.env.MY_BUILD_SECRET).to.equal("secret-value");
expect(process.env.MY_RUNTIME_SECRET).to.be.undefined;
expect(process.env.MY_PLAIN_VAR).to.equal("plain-value");
sinon.stub(childProcess, "spawnSync").callsFake((command: any, args: any, options: any) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Avoid using any for function parameters. Use proper types to ensure type safety and adhere to the repository style guide.

Suggested change
sinon.stub(childProcess, "spawnSync").callsFake((command: any, args: any, options: any) => {
sinon.stub(childProcess, "spawnSync").callsFake((command: string, args: string[], options: childProcess.SpawnSyncOptions) => {
References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

sinon.stub(childProcess, "spawnSync").callsFake(() => {
expect(process.env.MY_PLAIN_VAR).to.equal("plain-value");
expect(process.env.ANOTHER_VAR).to.equal("another-value");
sinon.stub(childProcess, "spawnSync").callsFake((command: any, args: any, options: any) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Avoid using any for function parameters. Use proper types to ensure type safety and adhere to the repository style guide.

Suggested change
sinon.stub(childProcess, "spawnSync").callsFake((command: any, args: any, options: any) => {
sinon.stub(childProcess, "spawnSync").callsFake((command: string, args: string[], options: childProcess.SpawnSyncOptions) => {
References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants