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 14, 2024
1 parent 1393679 commit 2453d62
Show file tree
Hide file tree
Showing 29 changed files with 526 additions and 74 deletions.
82 changes: 80 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,81 @@ nx reset
```

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

### Examples

Open interactive prompt to choose what to reset. This is the default behavior when no flags are provided and in an interactive environment.:

```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`

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

### daemon

Type: `boolean`

Stops the Nx Daemon to reset its internal state.

### help

Type: `boolean`

Show help

### interactive

Type: `boolean`

Default: `true`

Shows multiselect prompt to choose what to reset

### version

Type: `boolean`

Show version number

### workspaceData

Type: `boolean`

Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. project graph construction, etc)
82 changes: 80 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,81 @@ nx reset
```

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

### Examples

Open interactive prompt to choose what to reset. This is the default behavior when no flags are provided and in an interactive environment.:

```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`

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

### daemon

Type: `boolean`

Stops the Nx Daemon to reset its internal state.

### help

Type: `boolean`

Show help

### interactive

Type: `boolean`

Default: `true`

Shows multiselect prompt to choose what to reset

### version

Type: `boolean`

Show version number

### workspaceData

Type: `boolean`

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 = existsSync(cachePath) ? readTargetsCache() : {};

const calculatedTargets: 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 = existsSync(cachePath) ? readTargetsCache() : {};

const calculatedTargets: 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 = existsSync(cachePath) ? readTargetsCache() : {};

const calculatedTargets: 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 = existsSync(cachePath) ? readTargetsCache() : {};

export const calculatedTargets: Record<
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 = existsSync(cachePath) ? 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 = existsSync(cachePath) ? readTargetsCache() : {};

const calculatedTargets: Record<
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { dirname, extname, 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 = existsSync(cachePath) ? readTargetsCache() : {};

const calculatedTargets: Record<
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
writeJsonFile,
} from '@nx/devkit';
import { basename, dirname, isAbsolute, join, relative } from 'path';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
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 = existsSync(cachePath) ? readTargetsCache() : {};

const calculatedTargets: 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"
}
}
}
26 changes: 26 additions & 0 deletions packages/nx/src/command-line/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,32 @@ export const examples: Record<string, Example[]> = {
'Create a dedicated commit for each successfully completed migration. You can customize the prefix used for each commit by additionally setting --commit-prefix="PREFIX_HERE "',
},
],
reset: [
{
command: 'reset',
description:
'Open interactive prompt to choose what to reset. This is the default behavior when no flags are provided and in an interactive environment.',
},
{
command: 'reset --all',
description:
'Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon',
},
{
command: 'reset --cache',
description:
'Clears the Nx Cache directory. This will remove all local cache entries for tasks, but will not affect the remote cache',
},
{
command: 'reset --daemon',
description: 'Stops the Nx Daemon to reset its internal state',
},
{
command: 'reset --workspace-data',
description:
'Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. project graph construction, etc)',
},
],
show: [
{
command: 'show projects',
Expand Down
Loading

0 comments on commit 2453d62

Please sign in to comment.