diff --git a/docs/generated/devkit/README.md b/docs/generated/devkit/README.md index f0c7e6bd6a250..74d1d5d836a1e 100644 --- a/docs/generated/devkit/README.md +++ b/docs/generated/devkit/README.md @@ -20,6 +20,7 @@ It only uses language primitives and immutable objects ### Classes - [AggregateCreateNodesError](../../devkit/documents/AggregateCreateNodesError) +- [StaleProjectGraphCacheError](../../devkit/documents/StaleProjectGraphCacheError) ### Interfaces diff --git a/docs/generated/devkit/StaleProjectGraphCacheError.md b/docs/generated/devkit/StaleProjectGraphCacheError.md new file mode 100644 index 0000000000000..6fa253253d569 --- /dev/null +++ b/docs/generated/devkit/StaleProjectGraphCacheError.md @@ -0,0 +1,144 @@ +# Class: StaleProjectGraphCacheError + +## Hierarchy + +- `Error` + + ↳ **`StaleProjectGraphCacheError`** + +## Table of contents + +### Constructors + +- [constructor](../../devkit/documents/StaleProjectGraphCacheError#constructor) + +### Properties + +- [cause](../../devkit/documents/StaleProjectGraphCacheError#cause): unknown +- [message](../../devkit/documents/StaleProjectGraphCacheError#message): string +- [name](../../devkit/documents/StaleProjectGraphCacheError#name): string +- [stack](../../devkit/documents/StaleProjectGraphCacheError#stack): string +- [prepareStackTrace](../../devkit/documents/StaleProjectGraphCacheError#preparestacktrace): Function +- [stackTraceLimit](../../devkit/documents/StaleProjectGraphCacheError#stacktracelimit): number + +### Methods + +- [captureStackTrace](../../devkit/documents/StaleProjectGraphCacheError#capturestacktrace) + +## Constructors + +### constructor + +• **new StaleProjectGraphCacheError**(): [`StaleProjectGraphCacheError`](../../devkit/documents/StaleProjectGraphCacheError) + +#### Returns + +[`StaleProjectGraphCacheError`](../../devkit/documents/StaleProjectGraphCacheError) + +#### Overrides + +Error.constructor + +## Properties + +### cause + +• `Optional` **cause**: `unknown` + +#### Inherited from + +Error.cause + +--- + +### message + +• **message**: `string` + +#### Inherited from + +Error.message + +--- + +### name + +• **name**: `string` + +#### Inherited from + +Error.name + +--- + +### stack + +• `Optional` **stack**: `string` + +#### Inherited from + +Error.stack + +--- + +### prepareStackTrace + +▪ `Static` `Optional` **prepareStackTrace**: (`err`: `Error`, `stackTraces`: `CallSite`[]) => `any` + +Optional override for formatting stack traces + +**`See`** + +https://v8.dev/docs/stack-trace-api#customizing-stack-traces + +#### Type declaration + +▸ (`err`, `stackTraces`): `any` + +##### Parameters + +| Name | Type | +| :------------ | :----------- | +| `err` | `Error` | +| `stackTraces` | `CallSite`[] | + +##### Returns + +`any` + +#### Inherited from + +Error.prepareStackTrace + +--- + +### stackTraceLimit + +▪ `Static` **stackTraceLimit**: `number` + +#### Inherited from + +Error.stackTraceLimit + +## Methods + +### captureStackTrace + +▸ **captureStackTrace**(`targetObject`, `constructorOpt?`): `void` + +Create .stack property on a target object + +#### Parameters + +| Name | Type | +| :---------------- | :--------- | +| `targetObject` | `object` | +| `constructorOpt?` | `Function` | + +#### Returns + +`void` + +#### Inherited from + +Error.captureStackTrace diff --git a/docs/generated/devkit/readCachedProjectGraph.md b/docs/generated/devkit/readCachedProjectGraph.md index 32b36db5f2505..3ce681d8f6402 100644 --- a/docs/generated/devkit/readCachedProjectGraph.md +++ b/docs/generated/devkit/readCachedProjectGraph.md @@ -1,12 +1,18 @@ # Function: readCachedProjectGraph -▸ **readCachedProjectGraph**(): [`ProjectGraph`](../../devkit/documents/ProjectGraph) & \{ `computedAt`: `number` ; `errors`: `ProjectGraphErrorTypes`[] } +▸ **readCachedProjectGraph**(`minimumComputedAt?`): [`ProjectGraph`](../../devkit/documents/ProjectGraph) Synchronously reads the latest cached copy of the workspace's ProjectGraph. +#### Parameters + +| Name | Type | Description | +| :------------------- | :------- | :----------------------------------------------------------------------------- | +| `minimumComputedAt?` | `number` | The minimum timestamp that the cached ProjectGraph must have been computed at. | + #### Returns -[`ProjectGraph`](../../devkit/documents/ProjectGraph) & \{ `computedAt`: `number` ; `errors`: `ProjectGraphErrorTypes`[] } +[`ProjectGraph`](../../devkit/documents/ProjectGraph) **`Throws`** diff --git a/docs/generated/packages/devkit/documents/nx_devkit.md b/docs/generated/packages/devkit/documents/nx_devkit.md index f0c7e6bd6a250..74d1d5d836a1e 100644 --- a/docs/generated/packages/devkit/documents/nx_devkit.md +++ b/docs/generated/packages/devkit/documents/nx_devkit.md @@ -20,6 +20,7 @@ It only uses language primitives and immutable objects ### Classes - [AggregateCreateNodesError](../../devkit/documents/AggregateCreateNodesError) +- [StaleProjectGraphCacheError](../../devkit/documents/StaleProjectGraphCacheError) ### Interfaces diff --git a/packages/js/src/utils/buildable-libs-utils.ts b/packages/js/src/utils/buildable-libs-utils.ts index 454b0c3813357..2ee4b484fcbcd 100644 --- a/packages/js/src/utils/buildable-libs-utils.ts +++ b/packages/js/src/utils/buildable-libs-utils.ts @@ -19,6 +19,7 @@ import { output } from 'nx/src/utils/output'; import { dirname, join, relative, extname, resolve } from 'path'; import type * as ts from 'typescript'; import { readTsConfigPaths } from './typescript/ts-config'; +import { registerCleanupFn } from 'nx/src/utils/cleanup'; function isBuildable(target: string, node: ProjectGraphProjectNode): boolean { return ( @@ -454,7 +455,7 @@ export function createTmpTsConfig( dependencies, workspaceRoot ); - process.on('exit', () => cleanupTmpTsConfigFile(tmpTsConfigPath)); + registerCleanupFn(() => cleanupTmpTsConfigFile(tmpTsConfigPath)); if (useWorkspaceAsBaseUrl) { parsedTSConfig.compilerOptions ??= {}; diff --git a/packages/nx/src/executors/run-commands/run-commands.impl.ts b/packages/nx/src/executors/run-commands/run-commands.impl.ts index 699e734ac3ac5..2416ad6cd89e0 100644 --- a/packages/nx/src/executors/run-commands/run-commands.impl.ts +++ b/packages/nx/src/executors/run-commands/run-commands.impl.ts @@ -643,7 +643,11 @@ function registerProcessListener() { registerCleanupFn((signal) => { childProcesses.forEach((p) => { if ('connected' in p ? p.connected : p.isAlive) { - p.kill(signal); + if (signal) { + p.kill(signal); + } else { + p.kill(); + } } }); }); diff --git a/packages/nx/src/native/db/initialize.rs b/packages/nx/src/native/db/initialize.rs index ada1ebb349630..b45f8f64bd463 100644 --- a/packages/nx/src/native/db/initialize.rs +++ b/packages/nx/src/native/db/initialize.rs @@ -1,5 +1,4 @@ use crate::native::db::connection::NxDbConnection; -use fs4::fs_std::FileExt; use rusqlite::{Connection, OpenFlags}; use std::fs::{remove_file, File}; use std::path::{Path, PathBuf}; @@ -12,9 +11,7 @@ pub(super) struct LockFile { pub(super) fn unlock_file(lock_file: &LockFile) { if lock_file.path.exists() { - lock_file - .file - .unlock() + fs4::fs_std::FileExt::unlock(&lock_file.file) .and_then(|_| remove_file(&lock_file.path)) .ok(); } @@ -26,8 +23,7 @@ pub(super) fn create_lock_file(db_path: &Path) -> anyhow::Result { .map_err(|e| anyhow::anyhow!("Unable to create db lock file: {:?}", e))?; trace!("Getting lock on db lock file"); - lock_file - .lock_exclusive() + fs4::fs_std::FileExt::lock_exclusive(&lock_file) .inspect(|_| trace!("Got lock on db lock file")) .map_err(|e| anyhow::anyhow!("Unable to lock the db lock file: {:?}", e))?; Ok(LockFile { @@ -77,7 +73,10 @@ pub(super) fn initialize_db(nx_version: String, db_path: &Path) -> anyhow::Resul Ok(c) } Err(reason) => { - trace!("Unable to connect to existing database because: {:?}", reason); + trace!( + "Unable to connect to existing database because: {:?}", + reason + ); trace!("Removing existing incompatible database"); remove_file(db_path)?; diff --git a/packages/nx/src/native/utils/file_lock.rs b/packages/nx/src/native/utils/file_lock.rs index 2487bb6237fb8..064340aed3d7a 100644 --- a/packages/nx/src/native/utils/file_lock.rs +++ b/packages/nx/src/native/utils/file_lock.rs @@ -49,7 +49,7 @@ impl FileLock { if file_lock.is_ok() { // Checking if the file is locked, locks it, so unlock it. - file.unlock()?; + fs4::fs_std::FileExt::unlock(&file)?; } Ok(Self { @@ -60,9 +60,10 @@ impl FileLock { } #[napi] - pub fn unlock(&mut self) { - let _ = self.file.unlock(); + pub fn unlock(&mut self) -> Result<()> { + fs4::fs_std::FileExt::unlock(&self.file)?; self.locked = false; + Ok(()) } #[napi] @@ -72,7 +73,7 @@ impl FileLock { if file_lock.is_ok() { // Checking if the file is locked, locks it, so unlock it. - self.file.unlock()?; + fs4::fs_std::FileExt::unlock(&self.file)?; } self.locked = file_lock.is_err(); @@ -90,8 +91,8 @@ impl FileLock { .write(true) .create(true) .open(&lock_file_path)?; - file.lock_shared()?; - file.unlock()?; + fs4::fs_std::FileExt::lock_shared(&file)?; + fs4::fs_std::FileExt::unlock(&file)?; Ok(()) }) } else { diff --git a/packages/nx/src/tasks-runner/forked-process-task-runner.ts b/packages/nx/src/tasks-runner/forked-process-task-runner.ts index 477954a1595b2..304cc96013e9f 100644 --- a/packages/nx/src/tasks-runner/forked-process-task-runner.ts +++ b/packages/nx/src/tasks-runner/forked-process-task-runner.ts @@ -502,7 +502,11 @@ export class ForkedProcessTaskRunner { registerCleanupFn((signal) => { this.processes.forEach((p) => { if ('connected' in p ? p.connected : p.isAlive) { - p.kill(signal); + if (signal) { + p.kill(signal); + } else { + p.kill(); + } } }); });