fix(core): apply NX_variables on top of env variables (#7205)
This commit is contained in:
parent
a57ca80a19
commit
6df11a2a18
@ -28,11 +28,6 @@ export class ForkedProcessTaskRunner {
|
|||||||
public forkProcessForBatch({ executorName, taskGraph }: Batch) {
|
public forkProcessForBatch({ executorName, taskGraph }: Batch) {
|
||||||
return new Promise<BatchResults>((res, rej) => {
|
return new Promise<BatchResults>((res, rej) => {
|
||||||
try {
|
try {
|
||||||
const env = this.envForForkedProcess(
|
|
||||||
process.env.FORCE_COLOR === undefined
|
|
||||||
? 'true'
|
|
||||||
: process.env.FORCE_COLOR
|
|
||||||
);
|
|
||||||
const count = Object.keys(taskGraph.tasks).length;
|
const count = Object.keys(taskGraph.tasks).length;
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
output.logSingleLine(
|
output.logSingleLine(
|
||||||
@ -49,10 +44,7 @@ export class ForkedProcessTaskRunner {
|
|||||||
|
|
||||||
const p = fork(workerPath, {
|
const p = fork(workerPath, {
|
||||||
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
||||||
env: {
|
env: this.getEnvVariablesForProcess(),
|
||||||
...env,
|
|
||||||
...process.env,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
this.processes.add(p);
|
this.processes.add(p);
|
||||||
|
|
||||||
@ -99,14 +91,6 @@ export class ForkedProcessTaskRunner {
|
|||||||
) {
|
) {
|
||||||
return new Promise<{ code: number; terminalOutput: string }>((res, rej) => {
|
return new Promise<{ code: number; terminalOutput: string }>((res, rej) => {
|
||||||
try {
|
try {
|
||||||
const env = this.envForForkedProcessForTask(
|
|
||||||
task,
|
|
||||||
process.env.FORCE_COLOR === undefined
|
|
||||||
? 'true'
|
|
||||||
: process.env.FORCE_COLOR,
|
|
||||||
undefined,
|
|
||||||
forwardOutput
|
|
||||||
);
|
|
||||||
const args = getCommandArgsForTask(task);
|
const args = getCommandArgsForTask(task);
|
||||||
const commandLine = `nx ${args.join(' ')}`;
|
const commandLine = `nx ${args.join(' ')}`;
|
||||||
|
|
||||||
@ -115,10 +99,14 @@ export class ForkedProcessTaskRunner {
|
|||||||
}
|
}
|
||||||
const p = fork(this.cliPath, args, {
|
const p = fork(this.cliPath, args, {
|
||||||
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
|
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
|
||||||
env: {
|
env: this.getEnvVariablesForTask(
|
||||||
...env,
|
task,
|
||||||
...process.env,
|
process.env.FORCE_COLOR === undefined
|
||||||
},
|
? 'true'
|
||||||
|
: process.env.FORCE_COLOR,
|
||||||
|
undefined,
|
||||||
|
forwardOutput
|
||||||
|
),
|
||||||
});
|
});
|
||||||
this.processes.add(p);
|
this.processes.add(p);
|
||||||
let out = [];
|
let out = [];
|
||||||
@ -164,12 +152,6 @@ export class ForkedProcessTaskRunner {
|
|||||||
) {
|
) {
|
||||||
return new Promise<{ code: number; terminalOutput: string }>((res, rej) => {
|
return new Promise<{ code: number; terminalOutput: string }>((res, rej) => {
|
||||||
try {
|
try {
|
||||||
const env = this.envForForkedProcessForTask(
|
|
||||||
task,
|
|
||||||
undefined,
|
|
||||||
temporaryOutputPath,
|
|
||||||
forwardOutput
|
|
||||||
);
|
|
||||||
const args = getCommandArgsForTask(task);
|
const args = getCommandArgsForTask(task);
|
||||||
const commandLine = `nx ${args.join(' ')}`;
|
const commandLine = `nx ${args.join(' ')}`;
|
||||||
|
|
||||||
@ -178,10 +160,12 @@ export class ForkedProcessTaskRunner {
|
|||||||
}
|
}
|
||||||
const p = fork(this.cliPath, args, {
|
const p = fork(this.cliPath, args, {
|
||||||
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
||||||
env: {
|
env: this.getEnvVariablesForTask(
|
||||||
...env,
|
task,
|
||||||
...process.env,
|
undefined,
|
||||||
},
|
temporaryOutputPath,
|
||||||
|
forwardOutput
|
||||||
|
),
|
||||||
});
|
});
|
||||||
this.processes.add(p);
|
this.processes.add(p);
|
||||||
p.on('exit', (code, signal) => {
|
p.on('exit', (code, signal) => {
|
||||||
@ -219,18 +203,47 @@ export class ForkedProcessTaskRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private envForForkedProcess(
|
// region Environment Variables
|
||||||
|
private getEnvVariablesForProcess() {
|
||||||
|
return {
|
||||||
|
// Start With Dotenv Variables
|
||||||
|
...this.getDotenvVariablesForForkedProcess(),
|
||||||
|
// User Process Env Variables override Dotenv Variables
|
||||||
|
...process.env,
|
||||||
|
// Nx Env Variables overrides everything
|
||||||
|
...this.getNxEnvVariablesForForkedProcess(
|
||||||
|
process.env.FORCE_COLOR === undefined ? 'true' : process.env.FORCE_COLOR
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private getEnvVariablesForTask(
|
||||||
|
task: Task,
|
||||||
|
forceColor: string,
|
||||||
|
outputPath: string,
|
||||||
|
forwardOutput: boolean
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
// Start With Dotenv Variables
|
||||||
|
...this.getDotenvVariablesForTask(task),
|
||||||
|
// User Process Env Variables override Dotenv Variables
|
||||||
|
...process.env,
|
||||||
|
// Nx Env Variables overrides everything
|
||||||
|
...this.getNxEnvVariablesForTask(
|
||||||
|
task,
|
||||||
|
forceColor,
|
||||||
|
outputPath,
|
||||||
|
forwardOutput
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private getNxEnvVariablesForForkedProcess(
|
||||||
forceColor: string,
|
forceColor: string,
|
||||||
outputPath?: string,
|
outputPath?: string,
|
||||||
forwardOutput?: boolean
|
forwardOutput?: boolean
|
||||||
) {
|
) {
|
||||||
const envsFromFiles = {
|
|
||||||
...parseEnv('.env'),
|
|
||||||
...parseEnv('.local.env'),
|
|
||||||
...parseEnv('.env.local'),
|
|
||||||
};
|
|
||||||
const env: NodeJS.ProcessEnv = {
|
const env: NodeJS.ProcessEnv = {
|
||||||
...envsFromFiles,
|
|
||||||
FORCE_COLOR: forceColor,
|
FORCE_COLOR: forceColor,
|
||||||
NX_INVOKED_BY_RUNNER: 'true',
|
NX_INVOKED_BY_RUNNER: 'true',
|
||||||
NX_WORKSPACE_ROOT: this.workspaceRoot,
|
NX_WORKSPACE_ROOT: this.workspaceRoot,
|
||||||
@ -245,29 +258,16 @@ export class ForkedProcessTaskRunner {
|
|||||||
env.NX_FORWARD_OUTPUT = 'true';
|
env.NX_FORWARD_OUTPUT = 'true';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
private envForForkedProcessForTask(
|
private getNxEnvVariablesForTask(
|
||||||
task: Task,
|
task: Task,
|
||||||
forceColor: string,
|
forceColor: string,
|
||||||
outputPath: string,
|
outputPath: string,
|
||||||
forwardOutput: boolean
|
forwardOutput: boolean
|
||||||
) {
|
) {
|
||||||
const envsFromFiles = {
|
|
||||||
...parseEnv(`.${task.target.target}.env`),
|
|
||||||
...parseEnv(`.env.${task.target.target}`),
|
|
||||||
...parseEnv(`${task.projectRoot}/.env`),
|
|
||||||
...parseEnv(`${task.projectRoot}/.local.env`),
|
|
||||||
...parseEnv(`${task.projectRoot}/.env.local`),
|
|
||||||
...parseEnv(`${task.projectRoot}/.${task.target.target}.env`),
|
|
||||||
...parseEnv(`${task.projectRoot}/.env.${task.target.target}`),
|
|
||||||
};
|
|
||||||
|
|
||||||
const env: NodeJS.ProcessEnv = {
|
const env: NodeJS.ProcessEnv = {
|
||||||
...this.envForForkedProcess(forceColor, outputPath, forwardOutput),
|
|
||||||
...envsFromFiles,
|
|
||||||
NX_TASK_TARGET_PROJECT: task.target.project,
|
NX_TASK_TARGET_PROJECT: task.target.project,
|
||||||
NX_TASK_HASH: task.hash,
|
NX_TASK_HASH: task.hash,
|
||||||
};
|
};
|
||||||
@ -276,9 +276,39 @@ export class ForkedProcessTaskRunner {
|
|||||||
if (task.target.target === 'test') {
|
if (task.target.target === 'test') {
|
||||||
env.NX_TERMINAL_CAPTURE_STDERR = 'true';
|
env.NX_TERMINAL_CAPTURE_STDERR = 'true';
|
||||||
}
|
}
|
||||||
return env;
|
|
||||||
|
return {
|
||||||
|
...this.getNxEnvVariablesForForkedProcess(
|
||||||
|
forceColor,
|
||||||
|
outputPath,
|
||||||
|
forwardOutput
|
||||||
|
),
|
||||||
|
...env,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getDotenvVariablesForForkedProcess() {
|
||||||
|
return {
|
||||||
|
...parseEnv('.env'),
|
||||||
|
...parseEnv('.local.env'),
|
||||||
|
...parseEnv('.env.local'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private getDotenvVariablesForTask(task: Task) {
|
||||||
|
return {
|
||||||
|
...this.getDotenvVariablesForForkedProcess(),
|
||||||
|
...parseEnv(`.${task.target.target}.env`),
|
||||||
|
...parseEnv(`.env.${task.target.target}`),
|
||||||
|
...parseEnv(`${task.projectRoot}/.env`),
|
||||||
|
...parseEnv(`${task.projectRoot}/.local.env`),
|
||||||
|
...parseEnv(`${task.projectRoot}/.env.local`),
|
||||||
|
...parseEnv(`${task.projectRoot}/.${task.target.target}.env`),
|
||||||
|
...parseEnv(`${task.projectRoot}/.env.${task.target.target}`),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// endregion Environment Variables
|
||||||
|
|
||||||
private signalToCode(signal: string) {
|
private signalToCode(signal: string) {
|
||||||
if (signal === 'SIGHUP') return 128 + 1;
|
if (signal === 'SIGHUP') return 128 + 1;
|
||||||
if (signal === 'SIGINT') return 128 + 2;
|
if (signal === 'SIGINT') return 128 + 2;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user