diff --git a/packages/nx/bin/nx.ts b/packages/nx/bin/nx.ts index a1b2cfa1fbcf8..263100b56755c 100644 --- a/packages/nx/bin/nx.ts +++ b/packages/nx/bin/nx.ts @@ -26,7 +26,8 @@ function main() { if ( process.argv[2] !== 'report' && process.argv[2] !== '--version' && - process.argv[2] !== '--help' + process.argv[2] !== '--help' && + process.argv[2] !== 'reset' ) { assertSupportedPlatform(); } diff --git a/packages/nx/src/daemon/cache.ts b/packages/nx/src/daemon/cache.ts index fff36b3bdc0a1..9a4e06a948d08 100644 --- a/packages/nx/src/daemon/cache.ts +++ b/packages/nx/src/daemon/cache.ts @@ -43,6 +43,23 @@ export async function safelyCleanUpExistingProcess(): Promise { if (daemonProcessJson && daemonProcessJson.processId) { try { process.kill(daemonProcessJson.processId); + await new Promise((resolve, reject) => { + let count = 0; + const interval = setInterval(() => { + try { + process.kill(daemonProcessJson.processId, 0); + } catch (e) { + clearInterval(interval); + resolve(); + } + if ((count += 1) > 200) { + clearInterval(interval); + reject( + `Daemon process ${daemonProcessJson.processId} didn't exit after 2 seconds.` + ); + } + }, 10); + }); } catch {} } deleteDaemonJsonProcessCache(); diff --git a/packages/nx/src/daemon/client/client.ts b/packages/nx/src/daemon/client/client.ts index a2c6771853009..d68d776b0bd34 100644 --- a/packages/nx/src/daemon/client/client.ts +++ b/packages/nx/src/daemon/client/client.ts @@ -26,7 +26,7 @@ import { Hash } from '../../hasher/task-hasher'; import { Task, TaskGraph } from '../../config/task-graph'; import { ConfigurationSourceMaps } from '../../project-graph/utils/project-configuration-utils'; import { DaemonProjectGraphError } from '../daemon-project-graph-error'; -import { ProjectGraphError } from '../../project-graph/project-graph'; +import { ProjectGraphError } from '../../project-graph/project-graph-error'; const DAEMON_ENV_SETTINGS = { NX_PROJECT_GLOB_CACHE: 'false', diff --git a/packages/nx/src/native/index.js b/packages/nx/src/native/index.js index 4e8f4f6ac49cb..7c94757f70bbf 100644 --- a/packages/nx/src/native/index.js +++ b/packages/nx/src/native/index.js @@ -1,8 +1,8 @@ const { join, basename } = require('path'); const { copyFileSync, existsSync, mkdirSync } = require('fs'); const Module = require('module'); -const { cacheDir } = require("../utils/cache-directory.js") -const { nxVersion } = require('../utils/versions.js'); +const { nxVersion} = require("../utils/versions") +const { cacheDir} = require("../utils/cache-directory") const nxPackages = [ '@nx/nx-android-arm64', @@ -48,7 +48,6 @@ Module._load = function (request, parent, isMain) { ) { const nativeLocation = require.resolve(modulePath); const fileName = basename(nativeLocation) - const tmpFile = join(cacheDir, nxVersion + '-' + fileName); if (existsSync(tmpFile)) { return originalLoad.apply(this, [tmpFile, parent, isMain]); diff --git a/packages/nx/src/project-graph/project-graph-error.ts b/packages/nx/src/project-graph/project-graph-error.ts new file mode 100644 index 0000000000000..d403a3dbe026a --- /dev/null +++ b/packages/nx/src/project-graph/project-graph-error.ts @@ -0,0 +1,74 @@ +import { DaemonProjectGraphError } from '../daemon/daemon-project-graph-error'; +import { ProjectGraph } from '../devkit-exports'; +import { + ProcessDependenciesError, + ProcessProjectGraphError, +} from './build-project-graph'; +import { + CreateNodesError, + MergeNodesError, + ProjectsWithConflictingNamesError, + ProjectsWithNoNameError, +} from './error-types'; +import { ConfigurationSourceMaps } from './utils/project-configuration-utils'; + +export class ProjectGraphError extends Error { + readonly #errors: Array< + | CreateNodesError + | MergeNodesError + | ProjectsWithNoNameError + | ProjectsWithConflictingNamesError + | ProcessDependenciesError + | ProcessProjectGraphError + >; + readonly #partialProjectGraph: ProjectGraph; + readonly #partialSourceMaps: ConfigurationSourceMaps; + + constructor( + errors: Array< + | CreateNodesError + | MergeNodesError + | ProjectsWithNoNameError + | ProjectsWithConflictingNamesError + | ProcessDependenciesError + | ProcessProjectGraphError + >, + partialProjectGraph: ProjectGraph, + partialSourceMaps: ConfigurationSourceMaps + ) { + super(`Failed to process project graph.`); + this.name = this.constructor.name; + this.#errors = errors; + this.#partialProjectGraph = partialProjectGraph; + this.#partialSourceMaps = partialSourceMaps; + this.stack = `${this.message}\n ${errors + .map((error) => error.stack.split('\n').join('\n ')) + .join('\n')}`; + } + + /** + * The daemon cannot throw errors which contain methods as they are not serializable. + * + * This method creates a new {@link ProjectGraphError} from a {@link DaemonProjectGraphError} with the methods based on the same serialized data. + */ + static fromDaemonProjectGraphError(e: DaemonProjectGraphError) { + return new ProjectGraphError(e.errors, e.projectGraph, e.sourceMaps); + } + + /** + * This gets the partial project graph despite the errors which occured. + * This partial project graph may be missing nodes, properties of nodes, or dependencies. + * This is useful mostly for visualization/debugging. It should not be used for running tasks. + */ + getPartialProjectGraph() { + return this.#partialProjectGraph; + } + + getPartialSourcemaps() { + return this.#partialSourceMaps; + } + + getErrors() { + return this.#errors; + } +} diff --git a/packages/nx/src/project-graph/project-graph.ts b/packages/nx/src/project-graph/project-graph.ts index 5fa8035661aed..f3c4577c914a2 100644 --- a/packages/nx/src/project-graph/project-graph.ts +++ b/packages/nx/src/project-graph/project-graph.ts @@ -1,31 +1,32 @@ -import { - readFileMapCache, - readProjectGraphCache, - writeCache, -} from './nx-deps-cache'; -import { - CreateDependenciesError, - ProcessDependenciesError, - ProcessProjectGraphError, - buildProjectGraphUsingProjectFileMap, -} from './build-project-graph'; -import { output } from '../utils/output'; -import { markDaemonAsDisabled, writeDaemonLogs } from '../daemon/tmp-dir'; +import { performance } from 'perf_hooks'; +import { readNxJson } from '../config/nx-json'; import { ProjectGraph } from '../config/project-graph'; -import { stripIndents } from '../utils/strip-indents'; import { ProjectConfiguration, ProjectsConfigurations, } from '../config/workspace-json-project-json'; import { daemonClient } from '../daemon/client/client'; +import { markDaemonAsDisabled, writeDaemonLogs } from '../daemon/tmp-dir'; import { fileExists } from '../utils/fileutils'; +import { output } from '../utils/output'; +import { stripIndents } from '../utils/strip-indents'; import { workspaceRoot } from '../utils/workspace-root'; -import { performance } from 'perf_hooks'; +import { + CreateDependenciesError, + ProcessDependenciesError, + ProcessProjectGraphError, + buildProjectGraphUsingProjectFileMap, +} from './build-project-graph'; +import { + readFileMapCache, + readProjectGraphCache, + writeCache, +} from './nx-deps-cache'; + import { retrieveProjectConfigurations, retrieveWorkspaceFiles, } from './utils/retrieve-workspace-files'; -import { readNxJson } from '../config/nx-json'; import { ConfigurationResult, ConfigurationSourceMaps, @@ -39,6 +40,7 @@ import { } from './error-types'; import { DaemonProjectGraphError } from '../daemon/daemon-project-graph-error'; import { loadNxPlugins, LoadedNxPlugin } from './plugins/internal-api'; +import { ProjectGraphError } from './project-graph-error'; /** * Synchronously reads the latest cached copy of the workspace's ProjectGraph. @@ -179,67 +181,6 @@ export async function buildProjectGraphAndSourceMapsWithoutDaemon() { } } -export class ProjectGraphError extends Error { - readonly #errors: Array< - | CreateNodesError - | MergeNodesError - | ProjectsWithNoNameError - | ProjectsWithConflictingNamesError - | ProcessDependenciesError - | ProcessProjectGraphError - >; - readonly #partialProjectGraph: ProjectGraph; - readonly #partialSourceMaps: ConfigurationSourceMaps; - - constructor( - errors: Array< - | CreateNodesError - | MergeNodesError - | ProjectsWithNoNameError - | ProjectsWithConflictingNamesError - | ProcessDependenciesError - | ProcessProjectGraphError - >, - partialProjectGraph: ProjectGraph, - partialSourceMaps: ConfigurationSourceMaps - ) { - super(`Failed to process project graph.`); - this.name = this.constructor.name; - this.#errors = errors; - this.#partialProjectGraph = partialProjectGraph; - this.#partialSourceMaps = partialSourceMaps; - this.stack = `${this.message}\n ${errors - .map((error) => error.stack.split('\n').join('\n ')) - .join('\n')}`; - } - - /** - * The daemon cannot throw errors which contain methods as they are not serializable. - * - * This method creates a new {@link ProjectGraphError} from a {@link DaemonProjectGraphError} with the methods based on the same serialized data. - */ - static fromDaemonProjectGraphError(e: DaemonProjectGraphError) { - return new ProjectGraphError(e.errors, e.projectGraph, e.sourceMaps); - } - - /** - * This gets the partial project graph despite the errors which occured. - * This partial project graph may be missing nodes, properties of nodes, or dependencies. - * This is useful mostly for visualization/debugging. It should not be used for running tasks. - */ - getPartialProjectGraph() { - return this.#partialProjectGraph; - } - - getPartialSourcemaps() { - return this.#partialSourceMaps; - } - - getErrors() { - return this.#errors; - } -} - function handleProjectGraphError(opts: { exitOnError: boolean }, e) { if (opts.exitOnError) { const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true'; diff --git a/packages/nx/src/utils/params.ts b/packages/nx/src/utils/params.ts index e83699d5571f3..af96304ff824e 100644 --- a/packages/nx/src/utils/params.ts +++ b/packages/nx/src/utils/params.ts @@ -5,7 +5,7 @@ import type { ProjectsConfigurations, } from '../config/workspace-json-project-json'; import { output } from './output'; -import type { ProjectGraphError } from '../project-graph/project-graph'; +import type { ProjectGraphError } from '../project-graph/project-graph-error'; const LIST_CHOICE_DISPLAY_LIMIT = 10;