Skip to content

Commit

Permalink
feat(core): allow partially resetting workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed May 29, 2024
1 parent 7ab246b commit 9b6e15b
Show file tree
Hide file tree
Showing 29 changed files with 497 additions and 78 deletions.
80 changes: 78 additions & 2 deletions docs/generated/cli/reset.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: 'reset - CLI command'
description: 'Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.'
description: 'Clears cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.'
---

# reset

Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.
Clears cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.

## Usage

Expand All @@ -14,3 +14,79 @@ nx reset
```

Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`.

### Examples

Clears the internal state of the daemon and metadata that Nx is tracking. Helpful if you are getting strange errors and want to start fresh:

```shell
nx reset
```

Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon:

```shell
nx reset --all
```

Clears the Nx Cache directory. This will remove all local cache entries for tasks, but will not affect the remote cache:

```shell
nx reset --cache
```

Stops the Nx Daemon to reset its internal state:

```shell
nx reset --daemon
```

Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. project graph construction, etc):

```shell
nx reset --workspace-data
```

## Options

### all

Type: `boolean`

Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.

### cache

Type: `boolean`

Default: `false`

Clears the Nx Cache directory. This will remove all local cache entries for tasks, but will not affect the remote cache.

### daemon

Type: `boolean`

Default: `true`

Stops the Nx Daemon to reset its internal state.

### help

Type: `boolean`

Show help

### version

Type: `boolean`

Show version number

### workspaceData

Type: `boolean`

Default: `true`

Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. project graph construction, etc)
80 changes: 78 additions & 2 deletions docs/generated/packages/nx/documents/reset.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: 'reset - CLI command'
description: 'Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.'
description: 'Clears cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.'
---

# reset

Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.
Clears cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.

## Usage

Expand All @@ -14,3 +14,79 @@ nx reset
```

Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`.

### Examples

Clears the internal state of the daemon and metadata that Nx is tracking. Helpful if you are getting strange errors and want to start fresh:

```shell
nx reset
```

Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon:

```shell
nx reset --all
```

Clears the Nx Cache directory. This will remove all local cache entries for tasks, but will not affect the remote cache:

```shell
nx reset --cache
```

Stops the Nx Daemon to reset its internal state:

```shell
nx reset --daemon
```

Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. project graph construction, etc):

```shell
nx reset --workspace-data
```

## Options

### all

Type: `boolean`

Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.

### cache

Type: `boolean`

Default: `false`

Clears the Nx Cache directory. This will remove all local cache entries for tasks, but will not affect the remote cache.

### daemon

Type: `boolean`

Default: `true`

Stops the Nx Daemon to reset its internal state.

### help

Type: `boolean`

Show help

### version

Type: `boolean`

Show version number

### workspaceData

Type: `boolean`

Default: `true`

Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. project graph construction, etc)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Schema } from '../schema';
import { type ExecutorContext, logger } from '@nx/devkit';
import type { StaticRemotesConfig } from './parse-static-remotes-config';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import { fork } from 'node:child_process';
import { join } from 'node:path';
import { createWriteStream } from 'node:fs';
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function buildStaticRemotes(
);
// File to debug build failures e.g. 2024-01-01T00_00_0_0Z-build.log'
const remoteBuildLogFile = join(
projectGraphCacheDirectory,
workspaceDataDirectory,
`${new Date().toISOString().replace(/[:\.]/g, '_')}-build.log`
);
const stdoutStream = createWriteStream(remoteBuildLogFile);
Expand Down
4 changes: 2 additions & 2 deletions packages/cypress/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
import { existsSync, readdirSync } from 'fs';
import { globWithWorkspaceContext } from 'nx/src/utils/workspace-context';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import { NX_PLUGIN_OPTIONS } from '../utils/constants';
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils';

Expand All @@ -30,7 +30,7 @@ export interface CypressPluginOptions {
componentTestingTargetName?: string;
}

const cachePath = join(projectGraphCacheDirectory, 'cypress.hash');
const cachePath = join(workspaceDataDirectory, 'cypress.hash');
const targetsCache = readTargetsCache();

function readTargetsCache(): Record<string, CypressTargets> {
Expand Down
4 changes: 2 additions & 2 deletions packages/detox/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { getLockFileName } from '@nx/js';
import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
import { existsSync, readdirSync } from 'fs';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';

export interface DetoxPluginOptions {
buildTargetName?: string;
startTargetName?: string;
testTargetName?: string;
}

const cachePath = join(projectGraphCacheDirectory, 'detox.hash');
const cachePath = join(workspaceDataDirectory, 'detox.hash');
const targetsCache = readTargetsCache();

function readTargetsCache(): Record<
Expand Down
4 changes: 2 additions & 2 deletions packages/expo/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getLockFileName } from '@nx/js';
import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
import { existsSync, readdirSync } from 'fs';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils';

export interface ExpoPluginOptions {
Expand All @@ -29,7 +29,7 @@ export interface ExpoPluginOptions {
submitTargetName?: string;
}

const cachePath = join(projectGraphCacheDirectory, 'expo.hash');
const cachePath = join(workspaceDataDirectory, 'expo.hash');
const targetsCache = readTargetsCache();

function readTargetsCache(): Record<
Expand Down
4 changes: 2 additions & 2 deletions packages/gradle/src/plugin/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';

import { getGradleExecFile } from '../utils/exec-gradle';
import { getGradleReport } from '../utils/get-gradle-report';
Expand All @@ -33,7 +33,7 @@ export interface GradlePluginOptions {
[taskTargetName: string]: string | undefined;
}

const cachePath = join(projectGraphCacheDirectory, 'gradle.hash');
const cachePath = join(workspaceDataDirectory, 'gradle.hash');
const targetsCache = readTargetsCache();
type GradleTargets = Record<
string,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { dirname, join, normalize, relative, resolve } from 'path';
import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
import { existsSync, readdirSync, readFileSync } from 'fs';
import { readConfig } from 'jest-config';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { clearRequireCache } from '@nx/devkit/src/utils/config-utils';
import { getGlobPatternsFromPackageManagerWorkspaces } from 'nx/src/plugins/package-json-workspaces';
Expand All @@ -27,7 +27,7 @@ export interface JestPluginOptions {
ciTargetName?: string;
}

const cachePath = join(projectGraphCacheDirectory, 'jest.hash');
const cachePath = join(workspaceDataDirectory, 'jest.hash');
const targetsCache = readTargetsCache();

type JestTargets = Awaited<ReturnType<typeof buildJestTargets>>;
Expand Down
4 changes: 2 additions & 2 deletions packages/js/src/plugins/typescript/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { basename, dirname, join, relative } from 'node:path';
import { minimatch } from 'minimatch';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { getLockFileName } from 'nx/src/plugins/js/lock-file/lock-file';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import type { ParsedCommandLine } from 'typescript';
import { readTsConfig } from '../../utils/typescript/ts-config';

Expand Down Expand Up @@ -49,7 +49,7 @@ interface NormalizedPluginOptions {
};
}

const cachePath = join(projectGraphCacheDirectory, 'tsc.hash');
const cachePath = join(workspaceDataDirectory, 'tsc.hash');
const targetsCache = readTargetsCache();

function readTargetsCache(): Record<
Expand Down
6 changes: 3 additions & 3 deletions packages/next/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
TargetConfiguration,
writeJsonFile,
} from '@nx/devkit';
import { dirname, extname, join } from 'path';
import { dirname, join } from 'path';

import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
import { existsSync, readdirSync } from 'fs';

import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { getLockFileName } from '@nx/js';
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils';
Expand All @@ -25,7 +25,7 @@ export interface NextPluginOptions {
serveStaticTargetName?: string;
}

const cachePath = join(projectGraphCacheDirectory, 'next.hash');
const cachePath = join(workspaceDataDirectory, 'next.hash');
const targetsCache = readTargetsCache();

function readTargetsCache(): Record<
Expand Down
7 changes: 3 additions & 4 deletions packages/nuxt/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ import {
CreateNodes,
CreateNodesContext,
detectPackageManager,
joinPathFragments,
readJsonFile,
TargetConfiguration,
workspaceRoot,
writeJsonFile,
} from '@nx/devkit';
import { basename, dirname, isAbsolute, join, relative } from 'path';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { dirname, isAbsolute, join, relative } from 'path';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
import { existsSync, readdirSync } from 'fs';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { getLockFileName } from '@nx/js';
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils';

const cachePath = join(projectGraphCacheDirectory, 'nuxt.hash');
const cachePath = join(workspaceDataDirectory, 'nuxt.hash');
const targetsCache = readTargetsCache();

function readTargetsCache(): Record<
Expand Down
6 changes: 6 additions & 0 deletions packages/nx/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
"version": "18.1.0-beta.3",
"description": "Moves affected.defaultBase to defaultBase in `nx.json`",
"implementation": "./src/migrations/update-17-2-0/move-default-base"
},
"19-1-0-move-graph-cache-directory": {
"cli": "nx",
"version": "19.1.0-beta.0",
"description": "Updates the default graph cache directory to .nx/workspace-data",
"implementation": "./src/migrations/update-19-1-0/move-graph-cache-directory"
}
}
}
Loading

0 comments on commit 9b6e15b

Please sign in to comment.