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 Jun 4, 2024
1 parent c002b54 commit fac07fd
Show file tree
Hide file tree
Showing 32 changed files with 519 additions and 114 deletions.
68 changes: 66 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 onlyDaemon.'
---

# 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 onlyDaemon.

## Usage

Expand All @@ -14,3 +14,67 @@ 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
```

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

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

Stops the Nx Daemon to reset its internal state:

```shell
nx reset --only-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 --only-workspace-data
```

## Options

### help

Type: `boolean`

Show help

### onlyCache

Type: `boolean`

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

### onlyDaemon

Type: `boolean`

Stops the Nx Daemon to reset its internal state.

### onlyWorkspaceData

Type: `boolean`

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

### version

Type: `boolean`

Show version number
68 changes: 66 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 onlyDaemon.'
---

# 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 onlyDaemon.

## Usage

Expand All @@ -14,3 +14,67 @@ 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
```

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

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

Stops the Nx Daemon to reset its internal state:

```shell
nx reset --only-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 --only-workspace-data
```

## Options

### help

Type: `boolean`

Show help

### onlyCache

Type: `boolean`

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

### onlyDaemon

Type: `boolean`

Stops the Nx Daemon to reset its internal state.

### onlyWorkspaceData

Type: `boolean`

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

### version

Type: `boolean`

Show version number
58 changes: 29 additions & 29 deletions docs/shared/reference/environment-variables.md

Large diffs are not rendered by default.

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 @@ -21,7 +21,7 @@ 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 { NX_PLUGIN_OPTIONS } from '../utils/constants';
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils';
import { hashObject } from 'nx/src/devkit-internals';
Expand Down Expand Up @@ -49,7 +49,7 @@ export const createNodesV2: CreateNodesV2<CypressPluginOptions> = [
async (configFiles, options, context) => {
const optionsHash = hashObject(options);
const cachePath = join(
projectGraphCacheDirectory,
workspaceDataDirectory,
`cypress-${optionsHash}.hash`
);
const targetsCache = readTargetsCache(cachePath);
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
5 changes: 2 additions & 3 deletions packages/gradle/src/plugin/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import {
createNodesFromFiles,
readJsonFile,
writeJsonFile,
CreateNodesResultV2,
CreateNodesFunction,
logger,
} from '@nx/devkit';
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 {
Expand Down Expand Up @@ -67,7 +66,7 @@ export const createNodesV2: CreateNodesV2<GradlePluginOptions> = [
async (configFiles, options, context) => {
const optionsHash = hashObject(options);
const cachePath = join(
projectGraphCacheDirectory,
workspaceDataDirectory,
`gradle-${optionsHash}.hash`
);
const targetsCache = readTargetsCache(cachePath);
Expand Down
7 changes: 2 additions & 5 deletions packages/jest/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { dirname, join, 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 Down Expand Up @@ -49,10 +49,7 @@ export const createNodesV2: CreateNodesV2<JestPluginOptions> = [
jestConfigGlob,
async (configFiles, options, context) => {
const optionsHash = hashObject(options);
const cachePath = join(
projectGraphCacheDirectory,
`jest-${optionsHash}.hash`
);
const cachePath = join(workspaceDataDirectory, `jest-${optionsHash}.hash`);
const targetsCache = readTargetsCache(cachePath);
try {
return await createNodesFromFiles(
Expand Down
1 change: 1 addition & 0 deletions packages/js/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export async function initGenerator(
/dist
/coverage
/.nx/cache
/.nx/workspace-data
`
);
}
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-2-0-move-graph-cache-directory": {
"cli": "nx",
"version": "19.2.0-beta.2",
"description": "Updates the default graph cache directory to .nx/workspace-data",
"implementation": "./src/migrations/update-19-2-0/move-graph-cache-directory"
}
}
}
Loading

0 comments on commit fac07fd

Please sign in to comment.