fix(core): ensure daemon enabled check is unchanged (#30228)
This commit is contained in:
parent
2986a02dc9
commit
5382c8af65
@ -1,12 +1,6 @@
|
||||
# Function: isDaemonEnabled
|
||||
|
||||
▸ **isDaemonEnabled**(`nxJson?`): `boolean`
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------- | :----------------------------------------------------------------------------------------- |
|
||||
| `nxJson` | [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)\<`string`[] \| `"*"`\> |
|
||||
▸ **isDaemonEnabled**(): `boolean`
|
||||
|
||||
#### Returns
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ import { getFullOsSocketPath, killSocketOrPath } from '../socket-utils';
|
||||
import {
|
||||
DAEMON_DIR_FOR_CURRENT_WORKSPACE,
|
||||
DAEMON_OUTPUT_LOG_FILE,
|
||||
isDaemonDisabled,
|
||||
removeSocketDir,
|
||||
} from '../tmp-dir';
|
||||
import { FileData, ProjectGraph } from '../../config/project-graph';
|
||||
@ -95,7 +96,6 @@ import {
|
||||
POST_TASKS_EXECUTION,
|
||||
PRE_TASKS_EXECUTION,
|
||||
} from '../message-types/run-tasks-execution-hooks';
|
||||
import { isDaemonEnabled } from './enabled';
|
||||
|
||||
const DAEMON_ENV_SETTINGS = {
|
||||
NX_PROJECT_GLOB_CACHE: 'false',
|
||||
@ -141,7 +141,48 @@ export class DaemonClient {
|
||||
private _err: FileHandle = null;
|
||||
|
||||
enabled() {
|
||||
return isDaemonEnabled(this.nxJson);
|
||||
if (this._enabled === undefined) {
|
||||
const useDaemonProcessOption = this.nxJson?.useDaemonProcess;
|
||||
const env = process.env.NX_DAEMON;
|
||||
|
||||
// env takes precedence
|
||||
// option=true,env=false => no daemon
|
||||
// option=false,env=undefined => no daemon
|
||||
// option=false,env=false => no daemon
|
||||
|
||||
// option=undefined,env=undefined => daemon
|
||||
// option=true,env=true => daemon
|
||||
// option=false,env=true => daemon
|
||||
|
||||
// CI=true,env=undefined => no daemon
|
||||
// CI=true,env=false => no daemon
|
||||
// CI=true,env=true => daemon
|
||||
|
||||
// docker=true,env=undefined => no daemon
|
||||
// docker=true,env=false => no daemon
|
||||
// docker=true,env=true => daemon
|
||||
// WASM => no daemon because file watching does not work
|
||||
if (
|
||||
((isCI() || isDocker()) && env !== 'true') ||
|
||||
isDaemonDisabled() ||
|
||||
nxJsonIsNotPresent() ||
|
||||
(useDaemonProcessOption === undefined && env === 'false') ||
|
||||
(useDaemonProcessOption === true && env === 'false') ||
|
||||
(useDaemonProcessOption === false && env === undefined) ||
|
||||
(useDaemonProcessOption === false && env === 'false')
|
||||
) {
|
||||
this._enabled = false;
|
||||
} else if (IS_WASM) {
|
||||
output.warn({
|
||||
title:
|
||||
'The Nx Daemon is unsupported in WebAssembly environments. Some things may be slower than or not function as expected.',
|
||||
});
|
||||
this._enabled = false;
|
||||
} else {
|
||||
this._enabled = true;
|
||||
}
|
||||
}
|
||||
return this._enabled;
|
||||
}
|
||||
|
||||
reset() {
|
||||
@ -677,6 +718,27 @@ export class DaemonClient {
|
||||
|
||||
export const daemonClient = new DaemonClient();
|
||||
|
||||
export function isDaemonEnabled() {
|
||||
return daemonClient.enabled();
|
||||
}
|
||||
|
||||
function isDocker() {
|
||||
try {
|
||||
statSync('/.dockerenv');
|
||||
return true;
|
||||
} catch {
|
||||
try {
|
||||
return readFileSync('/proc/self/cgroup', 'utf8')?.includes('docker');
|
||||
} catch {}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function nxJsonIsNotPresent() {
|
||||
return !hasNxJson(workspaceRoot);
|
||||
}
|
||||
|
||||
function daemonProcessException(message: string) {
|
||||
try {
|
||||
let log = readFileSync(DAEMON_OUTPUT_LOG_FILE).toString().split('\n');
|
||||
|
||||
@ -1,79 +0,0 @@
|
||||
import {
|
||||
hasNxJson,
|
||||
readNxJson,
|
||||
type NxJsonConfiguration,
|
||||
} from '../../config/nx-json';
|
||||
|
||||
import { readFileSync, statSync } from 'node:fs';
|
||||
|
||||
import { isCI } from '../../utils/is-ci';
|
||||
import { workspaceRoot } from '../../utils/workspace-root';
|
||||
import { isDaemonDisabled } from '../tmp-dir';
|
||||
|
||||
let _enabled: boolean | undefined;
|
||||
|
||||
export function isDaemonEnabled(nxJson: NxJsonConfiguration = readNxJson()) {
|
||||
if (_enabled === undefined) {
|
||||
const useDaemonProcessOption = nxJson?.useDaemonProcess;
|
||||
const env = process.env.NX_DAEMON;
|
||||
|
||||
// env takes precedence
|
||||
// option=true,env=false => no daemon
|
||||
// option=false,env=undefined => no daemon
|
||||
// option=false,env=false => no daemon
|
||||
|
||||
// option=undefined,env=undefined => daemon
|
||||
// option=true,env=true => daemon
|
||||
// option=false,env=true => daemon
|
||||
|
||||
// CI=true,env=undefined => no daemon
|
||||
// CI=true,env=false => no daemon
|
||||
// CI=true,env=true => daemon
|
||||
|
||||
// docker=true,env=undefined => no daemon
|
||||
// docker=true,env=false => no daemon
|
||||
// docker=true,env=true => daemon
|
||||
// WASM => no daemon because file watching does not work
|
||||
if (
|
||||
((isCI() || isDocker()) && env !== 'true') ||
|
||||
isDaemonDisabled() ||
|
||||
nxJsonIsNotPresent() ||
|
||||
(useDaemonProcessOption === undefined && env === 'false') ||
|
||||
(useDaemonProcessOption === true && env === 'false') ||
|
||||
(useDaemonProcessOption === false && env === undefined) ||
|
||||
(useDaemonProcessOption === false && env === 'false')
|
||||
) {
|
||||
_enabled = false;
|
||||
} else if (
|
||||
(require('../../native') as typeof import('../../native')).IS_WASM
|
||||
) {
|
||||
(
|
||||
require('../../utils/output') as typeof import('../../utils/output')
|
||||
).output.warn({
|
||||
title:
|
||||
'The Nx Daemon is unsupported in WebAssembly environments. Some things may be slower than or not function as expected.',
|
||||
});
|
||||
_enabled = false;
|
||||
} else {
|
||||
_enabled = true;
|
||||
}
|
||||
}
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
function isDocker() {
|
||||
try {
|
||||
statSync('/.dockerenv');
|
||||
return true;
|
||||
} catch {
|
||||
try {
|
||||
return readFileSync('/proc/self/cgroup', 'utf8')?.includes('docker');
|
||||
} catch {}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function nxJsonIsNotPresent() {
|
||||
return !hasNxJson(workspaceRoot);
|
||||
}
|
||||
@ -260,4 +260,4 @@ export { cacheDir } from './utils/cache-directory';
|
||||
*/
|
||||
export { createProjectFileMapUsingProjectGraph } from './project-graph/file-map-utils';
|
||||
|
||||
export { isDaemonEnabled } from './daemon/client/enabled';
|
||||
export { isDaemonEnabled } from './daemon/client/client';
|
||||
|
||||
@ -17,7 +17,7 @@ import type {
|
||||
} from './public-api';
|
||||
import { createNodesFromFiles } from './utils';
|
||||
import { isIsolationEnabled } from './isolation/enabled';
|
||||
import { isDaemonEnabled } from '../../daemon/client/enabled';
|
||||
import { isDaemonEnabled } from '../../daemon/client/client';
|
||||
|
||||
export class LoadedNxPlugin {
|
||||
index?: number;
|
||||
@ -123,10 +123,7 @@ export class LoadedNxPlugin {
|
||||
this.preTasksExecution = async (context: PreTasksExecutionContext) => {
|
||||
const updates = {};
|
||||
let originalEnv = process.env;
|
||||
if (
|
||||
isIsolationEnabled() ||
|
||||
isDaemonEnabled(context.nxJsonConfiguration)
|
||||
) {
|
||||
if (isIsolationEnabled() || isDaemonEnabled()) {
|
||||
process.env = new Proxy<NodeJS.ProcessEnv>(originalEnv, {
|
||||
set: (target, key: string, value) => {
|
||||
target[key] = value;
|
||||
|
||||
@ -4,13 +4,12 @@ import type {
|
||||
} from './public-api';
|
||||
import { getPlugins } from './get-plugins';
|
||||
import { isOnDaemon } from '../../daemon/is-on-daemon';
|
||||
import { daemonClient } from '../../daemon/client/client';
|
||||
import { isDaemonEnabled } from '../../daemon/client/enabled';
|
||||
import { daemonClient, isDaemonEnabled } from '../../daemon/client/client';
|
||||
|
||||
export async function runPreTasksExecution(
|
||||
pluginContext: PreTasksExecutionContext
|
||||
) {
|
||||
if (isOnDaemon() || !isDaemonEnabled(pluginContext.nxJsonConfiguration)) {
|
||||
if (isOnDaemon() || !isDaemonEnabled()) {
|
||||
performance.mark(`preTasksExecution:start`);
|
||||
const plugins = await getPlugins(pluginContext.workspaceRoot);
|
||||
const envs = await Promise.all(
|
||||
@ -31,7 +30,7 @@ export async function runPreTasksExecution(
|
||||
})
|
||||
);
|
||||
|
||||
if (!isDaemonEnabled(pluginContext.nxJsonConfiguration)) {
|
||||
if (!isDaemonEnabled()) {
|
||||
applyProcessEnvs(envs);
|
||||
}
|
||||
performance.mark(`preTasksExecution:end`);
|
||||
@ -58,7 +57,7 @@ function applyProcessEnvs(envs: NodeJS.ProcessEnv[]) {
|
||||
export async function runPostTasksExecution(
|
||||
context: PostTasksExecutionContext
|
||||
) {
|
||||
if (isOnDaemon() || !isDaemonEnabled(context.nxJsonConfiguration)) {
|
||||
if (isOnDaemon() || !isDaemonEnabled()) {
|
||||
performance.mark(`postTasksExecution:start`);
|
||||
const plugins = await getPlugins();
|
||||
await Promise.all(
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { exec } from 'child_process';
|
||||
import type { Compiler } from '@rspack/core';
|
||||
import { daemonClient } from 'nx/src/daemon/client/client';
|
||||
import { isDaemonEnabled } from 'nx/src/daemon/client/enabled';
|
||||
import { daemonClient, isDaemonEnabled } from 'nx/src/daemon/client/client';
|
||||
import { BatchFunctionRunner } from 'nx/src/command-line/watch/watch';
|
||||
import { output } from 'nx/src/utils/output';
|
||||
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import { exec } from 'child_process';
|
||||
import type { Compiler } from 'webpack';
|
||||
import { daemonClient } from 'nx/src/daemon/client/client';
|
||||
import { daemonClient, isDaemonEnabled } from 'nx/src/daemon/client/client';
|
||||
import { BatchFunctionRunner } from 'nx/src/command-line/watch/watch';
|
||||
import { output } from 'nx/src/utils/output';
|
||||
import { isDaemonEnabled } from 'nx/src/daemon/client/enabled';
|
||||
|
||||
type PluginOptions = {
|
||||
skipInitialBuild?: boolean;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user