diff --git a/docs/generated/cli/reset.md b/docs/generated/cli/reset.md index 7f036bb07d82d..ad1bf3e90755e 100644 --- a/docs/generated/cli/reset.md +++ b/docs/generated/cli/reset.md @@ -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 @@ -14,3 +14,61 @@ 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 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, it will be restarted fresh when the next Nx command is run.: + +```shell + nx reset --only-daemon +``` + +Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. partial results, incremental data, etc): + +```shell + nx reset --only-workspace-data +``` + +## Options + +### help + +Type: `boolean` + +Show help + +### onlyCache + +Type: `boolean` + +Clears the Nx cache directory. This will remove all local cache entries for tasks, but will not affect the remote cache. + +### onlyDaemon + +Type: `boolean` + +Stops the Nx Daemon, it will be restarted fresh when the next Nx command is run. + +### onlyWorkspaceData + +Type: `boolean` + +Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. partial results, incremental data, etc) + +### version + +Type: `boolean` + +Show version number diff --git a/docs/generated/packages/nx/documents/reset.md b/docs/generated/packages/nx/documents/reset.md index 7f036bb07d82d..ad1bf3e90755e 100644 --- a/docs/generated/packages/nx/documents/reset.md +++ b/docs/generated/packages/nx/documents/reset.md @@ -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 @@ -14,3 +14,61 @@ 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 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, it will be restarted fresh when the next Nx command is run.: + +```shell + nx reset --only-daemon +``` + +Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. partial results, incremental data, etc): + +```shell + nx reset --only-workspace-data +``` + +## Options + +### help + +Type: `boolean` + +Show help + +### onlyCache + +Type: `boolean` + +Clears the Nx cache directory. This will remove all local cache entries for tasks, but will not affect the remote cache. + +### onlyDaemon + +Type: `boolean` + +Stops the Nx Daemon, it will be restarted fresh when the next Nx command is run. + +### onlyWorkspaceData + +Type: `boolean` + +Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. partial results, incremental data, etc) + +### version + +Type: `boolean` + +Show version number diff --git a/docs/shared/reference/environment-variables.md b/docs/shared/reference/environment-variables.md index 6c17f2a10b486..5971752b0ff16 100644 --- a/docs/shared/reference/environment-variables.md +++ b/docs/shared/reference/environment-variables.md @@ -2,35 +2,35 @@ The following environment variables are ones that you can set to change the behavior of Nx in different environments. -| Property | Type | Description | -| -------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| NX_ADD_PLUGINS | boolean | If set to `false`, Nx will not add plugins to infer tasks. This is `true` by default. Workspaces created before Nx 18 will have this disabled via a migration for backwards compatibility | -| NX_BASE | string | The default base branch to use when calculating the affected projects. Can be overridden on the command line with `--base`. | -| NX_CACHE_DIRECTORY | string | The cache for task outputs is stored in `.nx/cache` by default. Set this variable to use a different directory. | -| NX_CACHE_PROJECT_GRAPH | boolean | If set to `false`, disables the project graph cache. Most useful when developing a plugin that modifies the project graph. | -| NX_DAEMON | boolean | If set to `false`, disables the Nx daemon process. Disable the daemon to print `console.log` statements in plugin code you are developing. | -| NX_DEFAULT_PROJECT | string | The default project used for commands which require a project. e.g. `nx build`, `nx g component`, etc. | -| NX_HEAD | string | The default head branch to use when calculating the affected projects. Can be overridden on the command line with `--head`. | -| NX_PERF_LOGGING | boolean | If set to `true`, will print debug information useful for for profiling executors and Nx itself | -| NX_PROFILE | string | Prepend `NX_PROFILE=profile.json` before running targets with Nx to generate a file that be [loaded in Chrome dev tools](/troubleshooting/performance-profiling) to visualize the performance of Nx across multiple processes. | -| NX_PROJECT_GRAPH_CACHE_DIRECTORY | string | The project graph cache is stored in `.nx/cache` by default. Set this variable to use a different directory. | -| NX_PROJECT_GRAPH_MAX_WORKERS | number | The number of workers to use when calculating the project graph. | -| NX_PARALLEL | number | The number of tasks Nx should run in parallel. Overrides any configured value inside nx.json | -| NX_RUNNER | string | The name of task runner from the config to use. Can be overridden on the command line with `--runner`. Not read if `NX_TASKS_RUNNER` is set. | -| NX_SKIP_NX_CACHE | boolean | Rerun the tasks even when the results are available in the cache | -| NX_TASKS_RUNNER | string | The name of task runner from the config to use. Can be overridden on the command line with `--runner`. Preferred over `NX_RUNNER`. | -| NX_TASKS_RUNNER_DYNAMIC_OUTPUT | boolean | If set to `false`, will use non-dynamic terminal output strategy (what you see in CI), even when you terminal can support the dynamic version | -| NX_VERBOSE_LOGGING | boolean | If set to `true`, will print debug information useful for troubleshooting | -| NX_DRY_RUN | boolean | If set to `true`, will perform a dry run of the generator. No files will be created and no packages will be installed. | -| NX_INTERACTIVE | boolean | If set to `true`, will allow Nx to prompt you in the terminal to answer some further questions when running generators. | -| NX_GENERATE_QUIET | boolean | If set to `true`, will prevent Nx logging file operations during generate | -| NX_PREFER_TS_NODE | boolean | If set to `true`, Nx will use `ts-node` for local execution of plugins even if `@swc-node/register` is installed. | -| NX_IGNORE_CYCLES | boolean | If set to `true`, Nx will ignore errors created by a task graph circular dependency. Can be overriden on the command line with `--nxIgnoreCycles` | -| NX_BATCH_MODE | boolean | If set to `true`, Nx will run task(s) in batches for executors which support batches. | -| NX_SKIP_LOG_GROUPING | boolean | If set to `true`, Nx will not group command's logs on CI. | -| NX_MIGRATE_CLI_VERSION | string | The version of Nx to use for running the `nx migrate` command. If not set, it defaults to `latest`. | -| NX_LOAD_DOT_ENV_FILES | boolean | If set to 'false', Nx will not load any environment files (e.g. `.local.env`, `.env.local`) | -| NX_NATIVE_FILE_CACHE_DIRECTORY | string | The cache for native `.node` files is stored under a global temp directory by default. Set this variable to use a different directory. This is interpreted as an absolute path. | +| Property | Type | Description | +| --------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| NX_ADD_PLUGINS | boolean | If set to `false`, Nx will not add plugins to infer tasks. This is `true` by default. Workspaces created before Nx 18 will have this disabled via a migration for backwards compatibility | +| NX_BASE | string | The default base branch to use when calculating the affected projects. Can be overridden on the command line with `--base`. | +| NX_CACHE_DIRECTORY | string | The cache for task outputs is stored in `.nx/cache` by default. Set this variable to use a different directory. | +| NX_CACHE_PROJECT_GRAPH | boolean | If set to `false`, disables the project graph cache. Most useful when developing a plugin that modifies the project graph. | +| NX_DAEMON | boolean | If set to `false`, disables the Nx daemon process. Disable the daemon to print `console.log` statements in plugin code you are developing. | +| NX_DEFAULT_PROJECT | string | The default project used for commands which require a project. e.g. `nx build`, `nx g component`, etc. | +| NX_HEAD | string | The default head branch to use when calculating the affected projects. Can be overridden on the command line with `--head`. | +| NX_PERF_LOGGING | boolean | If set to `true`, will print debug information useful for for profiling executors and Nx itself | +| NX_PROFILE | string | Prepend `NX_PROFILE=profile.json` before running targets with Nx to generate a file that be [loaded in Chrome dev tools](/troubleshooting/performance-profiling) to visualize the performance of Nx across multiple processes. | +| NX_WORKSPACE_DATA_CACHE_DIRECTORY | string | The project graph cache and some other internal nx caches are stored in `.nx/workspace-data` by default. Set this variable to use a different directory. | +| NX_PROJECT_GRAPH_MAX_WORKERS | number | The number of workers to use when calculating the project graph. | +| NX_PARALLEL | number | The number of tasks Nx should run in parallel. Overrides any configured value inside nx.json | +| NX_RUNNER | string | The name of task runner from the config to use. Can be overridden on the command line with `--runner`. Not read if `NX_TASKS_RUNNER` is set. | +| NX_SKIP_NX_CACHE | boolean | Rerun the tasks even when the results are available in the cache | +| NX_TASKS_RUNNER | string | The name of task runner from the config to use. Can be overridden on the command line with `--runner`. Preferred over `NX_RUNNER`. | +| NX_TASKS_RUNNER_DYNAMIC_OUTPUT | boolean | If set to `false`, will use non-dynamic terminal output strategy (what you see in CI), even when you terminal can support the dynamic version | +| NX_VERBOSE_LOGGING | boolean | If set to `true`, will print debug information useful for troubleshooting | +| NX_DRY_RUN | boolean | If set to `true`, will perform a dry run of the generator. No files will be created and no packages will be installed. | +| NX_INTERACTIVE | boolean | If set to `true`, will allow Nx to prompt you in the terminal to answer some further questions when running generators. | +| NX_GENERATE_QUIET | boolean | If set to `true`, will prevent Nx logging file operations during generate | +| NX_PREFER_TS_NODE | boolean | If set to `true`, Nx will use `ts-node` for local execution of plugins even if `@swc-node/register` is installed. | +| NX_IGNORE_CYCLES | boolean | If set to `true`, Nx will ignore errors created by a task graph circular dependency. Can be overriden on the command line with `--nxIgnoreCycles` | +| NX_BATCH_MODE | boolean | If set to `true`, Nx will run task(s) in batches for executors which support batches. | +| NX_SKIP_LOG_GROUPING | boolean | If set to `true`, Nx will not group command's logs on CI. | +| NX_MIGRATE_CLI_VERSION | string | The version of Nx to use for running the `nx migrate` command. If not set, it defaults to `latest`. | +| NX_LOAD_DOT_ENV_FILES | boolean | If set to 'false', Nx will not load any environment files (e.g. `.local.env`, `.env.local`) | +| NX_NATIVE_FILE_CACHE_DIRECTORY | string | The cache for native `.node` files is stored under a global temp directory by default. Set this variable to use a different directory. This is interpreted as an absolute path. | Nx will set the following environment variables so they can be accessible within the process even outside of executors and generators. diff --git a/packages/angular/src/executors/module-federation-dev-server/lib/build-static-remotes.ts b/packages/angular/src/executors/module-federation-dev-server/lib/build-static-remotes.ts index 6b30f84ef8fc0..feb82ad16ef27 100644 --- a/packages/angular/src/executors/module-federation-dev-server/lib/build-static-remotes.ts +++ b/packages/angular/src/executors/module-federation-dev-server/lib/build-static-remotes.ts @@ -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'; @@ -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); diff --git a/packages/cypress/src/plugins/plugin.ts b/packages/cypress/src/plugins/plugin.ts index a7a466eaccc97..45c0582fa6d94 100644 --- a/packages/cypress/src/plugins/plugin.ts +++ b/packages/cypress/src/plugins/plugin.ts @@ -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'; @@ -49,7 +49,7 @@ export const createNodesV2: CreateNodesV2 = [ async (configFiles, options, context) => { const optionsHash = hashObject(options); const cachePath = join( - projectGraphCacheDirectory, + workspaceDataDirectory, `cypress-${optionsHash}.hash` ); const targetsCache = readTargetsCache(cachePath); diff --git a/packages/detox/src/plugins/plugin.ts b/packages/detox/src/plugins/plugin.ts index cfe03e75a826a..dd1e3c745fef6 100644 --- a/packages/detox/src/plugins/plugin.ts +++ b/packages/detox/src/plugins/plugin.ts @@ -13,7 +13,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'; export interface DetoxPluginOptions { buildTargetName?: string; @@ -21,7 +21,7 @@ export interface DetoxPluginOptions { testTargetName?: string; } -const cachePath = join(projectGraphCacheDirectory, 'detox.hash'); +const cachePath = join(workspaceDataDirectory, 'detox.hash'); const targetsCache = readTargetsCache(); function readTargetsCache(): Record< diff --git a/packages/eslint/src/plugins/plugin.spec.ts b/packages/eslint/src/plugins/plugin.spec.ts index 753c32b12a950..fd04f0899eef5 100644 --- a/packages/eslint/src/plugins/plugin.spec.ts +++ b/packages/eslint/src/plugins/plugin.spec.ts @@ -6,7 +6,7 @@ import { mkdirSync, rmdirSync } from 'fs'; jest.mock('nx/src/utils/cache-directory', () => ({ ...jest.requireActual('nx/src/utils/cache-directory'), - projectGraphCacheDirectory: 'tmp/project-graph-cache', + workspaceDataDirectory: 'tmp/project-graph-cache', })); describe('@nx/eslint/plugin', () => { diff --git a/packages/eslint/src/plugins/plugin.ts b/packages/eslint/src/plugins/plugin.ts index 80fd776f4d2bf..14c2d65411ae5 100644 --- a/packages/eslint/src/plugins/plugin.ts +++ b/packages/eslint/src/plugins/plugin.ts @@ -24,7 +24,7 @@ import { } from '../utils/config-file'; import { resolveESLintClass } from '../utils/resolve-eslint-class'; import { gte } from 'semver'; -import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory'; +import { workspaceDataDirectory } from 'nx/src/utils/cache-directory'; import { hashObject } from 'nx/src/hasher/file-hasher'; import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes'; @@ -163,7 +163,7 @@ export const createNodesV2: CreateNodesV2 = [ async (configFiles, options, context) => { const optionsHash = hashObject(options); const cachePath = join( - projectGraphCacheDirectory, + workspaceDataDirectory, `eslint-${optionsHash}.hash` ); const targetsCache = readTargetsCache(cachePath); diff --git a/packages/expo/plugins/plugin.ts b/packages/expo/plugins/plugin.ts index 7f7c7f70c7be3..95939d5c1e71c 100644 --- a/packages/expo/plugins/plugin.ts +++ b/packages/expo/plugins/plugin.ts @@ -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 { @@ -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< diff --git a/packages/gradle/src/plugin/nodes.ts b/packages/gradle/src/plugin/nodes.ts index 3f312e71e4d49..222d9f5ed8ed5 100644 --- a/packages/gradle/src/plugin/nodes.ts +++ b/packages/gradle/src/plugin/nodes.ts @@ -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 { @@ -67,7 +66,7 @@ export const createNodesV2: CreateNodesV2 = [ async (configFiles, options, context) => { const optionsHash = hashObject(options); const cachePath = join( - projectGraphCacheDirectory, + workspaceDataDirectory, `gradle-${optionsHash}.hash` ); const targetsCache = readTargetsCache(cachePath); diff --git a/packages/jest/src/plugins/plugin.ts b/packages/jest/src/plugins/plugin.ts index fb23032dfe94f..5c25a1fb30da5 100644 --- a/packages/jest/src/plugins/plugin.ts +++ b/packages/jest/src/plugins/plugin.ts @@ -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'; @@ -49,10 +49,7 @@ export const createNodesV2: CreateNodesV2 = [ 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( diff --git a/packages/js/src/generators/init/init.ts b/packages/js/src/generators/init/init.ts index 051b2c8137a72..4a3136f248389 100644 --- a/packages/js/src/generators/init/init.ts +++ b/packages/js/src/generators/init/init.ts @@ -124,6 +124,7 @@ export async function initGenerator( /dist /coverage /.nx/cache + /.nx/workspace-data ` ); } diff --git a/packages/js/src/plugins/typescript/plugin.ts b/packages/js/src/plugins/typescript/plugin.ts index 1473c672351eb..10b6e087c25b8 100644 --- a/packages/js/src/plugins/typescript/plugin.ts +++ b/packages/js/src/plugins/typescript/plugin.ts @@ -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'; @@ -49,7 +49,7 @@ interface NormalizedPluginOptions { }; } -const cachePath = join(projectGraphCacheDirectory, 'tsc.hash'); +const cachePath = join(workspaceDataDirectory, 'tsc.hash'); const targetsCache = readTargetsCache(); function readTargetsCache(): Record< diff --git a/packages/next/src/plugins/plugin.ts b/packages/next/src/plugins/plugin.ts index 87de5aa084783..396b24b15d0c6 100644 --- a/packages/next/src/plugins/plugin.ts +++ b/packages/next/src/plugins/plugin.ts @@ -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'; @@ -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< diff --git a/packages/nuxt/src/plugins/plugin.ts b/packages/nuxt/src/plugins/plugin.ts index c1614e50456d4..0f2d465f53799 100644 --- a/packages/nuxt/src/plugins/plugin.ts +++ b/packages/nuxt/src/plugins/plugin.ts @@ -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< diff --git a/packages/nx/migrations.json b/packages/nx/migrations.json index b0971f8ac4bac..007c3b4dab0a0 100644 --- a/packages/nx/migrations.json +++ b/packages/nx/migrations.json @@ -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 workspace data directory to .nx/workspace-data", + "implementation": "./src/migrations/update-19-2-0/move-workspace-data-directory" } } } diff --git a/packages/nx/src/command-line/examples.ts b/packages/nx/src/command-line/examples.ts index 1d6cdeee0e5b4..5a2192f733fd4 100644 --- a/packages/nx/src/command-line/examples.ts +++ b/packages/nx/src/command-line/examples.ts @@ -336,6 +336,28 @@ export const examples: Record = { '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: + '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', + }, + { + command: 'reset --only-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 --only-daemon', + description: + 'Stops the Nx Daemon, it will be restarted fresh when the next Nx command is run.', + }, + { + command: 'reset --only-workspace-data', + description: + 'Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. partial results, incremental data, etc)', + }, + ], show: [ { command: 'show projects', diff --git a/packages/nx/src/command-line/reset/command-object.ts b/packages/nx/src/command-line/reset/command-object.ts index 2502ff6b34bc9..17decc00dd4d0 100644 --- a/packages/nx/src/command-line/reset/command-object.ts +++ b/packages/nx/src/command-line/reset/command-object.ts @@ -1,9 +1,35 @@ import { CommandModule } from 'yargs'; -export const yargsResetCommand: CommandModule = { +export type ResetCommandOptions = { + onlyCache?: boolean; + onlyDaemon?: boolean; + onlyWorkspaceData?: boolean; +}; + +export const yargsResetCommand: CommandModule< + Record, + ResetCommandOptions +> = { command: 'reset', describe: - '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.', aliases: ['clear-cache'], - handler: async () => (await import('./reset')).resetHandler(), + builder: (yargs) => + yargs + .option('onlyCache', { + description: + 'Clears the Nx cache directory. This will remove all local cache entries for tasks, but will not affect the remote cache.', + type: 'boolean', + }) + .option('onlyDaemon', { + description: + 'Stops the Nx Daemon, it will be restarted fresh when the next Nx command is run.', + type: 'boolean', + }) + .option('onlyWorkspaceData', { + description: + 'Clears the workspace data directory. Used by Nx to store cached data about the current workspace (e.g. partial results, incremental data, etc)', + type: 'boolean', + }), + handler: async (argv) => (await import('./reset')).resetHandler(argv), }; diff --git a/packages/nx/src/command-line/reset/reset.ts b/packages/nx/src/command-line/reset/reset.ts index 12271c2ca80e6..2f2d23a67956b 100644 --- a/packages/nx/src/command-line/reset/reset.ts +++ b/packages/nx/src/command-line/reset/reset.ts @@ -1,29 +1,131 @@ import { rmSync } from 'fs-extra'; import { daemonClient } from '../../daemon/client/client'; -import { - cacheDir, - projectGraphCacheDirectory, -} from '../../utils/cache-directory'; +import { cacheDir, workspaceDataDirectory } from '../../utils/cache-directory'; import { output } from '../../utils/output'; import { getNativeFileCacheLocation } from '../../native/native-file-cache-location'; +import { ResetCommandOptions } from './command-object'; -export async function resetHandler() { - output.note({ - title: 'Resetting the Nx workspace cache and stopping the Nx Daemon.', - bodyLines: [`This might take a few minutes.`], - }); - await daemonClient.stop(); - output.log({ title: 'Daemon Server - Stopped' }); +// Wait at max 5 seconds before giving up on a failing operation. +const INCREMENTAL_BACKOFF_MAX_DURATION = 5000; + +// If an operation fails, wait 100ms before first retry. +const INCREMENTAL_BACKOFF_FIRST_DELAY = 100; + +export async function resetHandler(args: ResetCommandOptions) { + let errors = []; + + const all = + args.onlyDaemon === undefined && + args.onlyCache === undefined && + args.onlyWorkspaceData === undefined; + + const startupMessage = all + ? 'Resetting the Nx cache and stopping the daemon.' + : 'Resetting:'; + const bodyLines = []; + if (!all) { + if (args.onlyDaemon) { + bodyLines.push('- Nx Daemon'); + } + if (args.onlyCache) { + bodyLines.push('- Cache directory'); + } + if (args.onlyWorkspaceData) { + bodyLines.push('- Workspace data directory'); + } + } + output.note({ title: startupMessage, bodyLines }); + + if (all || args.onlyDaemon) { + try { + await killDaemon(); + } catch { + errors.push('Failed to stop the Nx Daemon.'); + } + } + if (all || args.onlyCache) { + try { + await cleanupCacheEntries(); + } catch { + errors.push('Failed to clean up the cache directory.'); + } + } + if (all || args.onlyWorkspaceData) { + try { + await cleanupNativeFileCache(); + } catch { + errors.push('Failed to clean up the native file cache.'); + } + try { + await cleanupWorkspaceData(); + } catch { + errors.push('Failed to clean up the workspace data directory.'); + } + } + if (errors.length > 0) { + output.error({ + title: 'Failed to reset the Nx workspace.', + bodyLines: errors, + }); + process.exit(1); + } else { + output.success({ + title: 'Successfully reset the Nx workspace.', + }); + } +} + +function killDaemon() { + return daemonClient.stop(); +} + +function cleanupCacheEntries() { + return incrementalBackoff( + INCREMENTAL_BACKOFF_FIRST_DELAY, + INCREMENTAL_BACKOFF_MAX_DURATION, + () => { + rmSync(cacheDir, { recursive: true, force: true }); + } + ); +} + +function cleanupNativeFileCache() { + return incrementalBackoff( + INCREMENTAL_BACKOFF_FIRST_DELAY, + INCREMENTAL_BACKOFF_MAX_DURATION, + () => { + rmSync(getNativeFileCacheLocation(), { recursive: true, force: true }); + } + ); +} + +function cleanupWorkspaceData() { + return incrementalBackoff( + INCREMENTAL_BACKOFF_FIRST_DELAY, + INCREMENTAL_BACKOFF_MAX_DURATION, + () => { + rmSync(workspaceDataDirectory, { recursive: true, force: true }); + } + ); +} + +async function incrementalBackoff( + ms: number, + maxDuration: number, + callback: () => void +) { try { - rmSync(getNativeFileCacheLocation(), { recursive: true, force: true }); + callback(); } catch (e) { - // ignore, deleting the native file cache is not critical and can fail if another process is locking the file - } - rmSync(cacheDir, { recursive: true, force: true }); - if (projectGraphCacheDirectory !== cacheDir) { - rmSync(projectGraphCacheDirectory, { recursive: true, force: true }); + if (ms < maxDuration) { + await sleep(ms); + await incrementalBackoff(ms * 2, maxDuration, callback); + } else { + throw e; + } } - output.success({ - title: 'Successfully reset the Nx workspace.', - }); +} + +function sleep(ms: number) { + return new Promise((resolve) => setTimeout(resolve, ms)); } diff --git a/packages/nx/src/daemon/tmp-dir.ts b/packages/nx/src/daemon/tmp-dir.ts index 2507b4ed87ab0..a865439486193 100644 --- a/packages/nx/src/daemon/tmp-dir.ts +++ b/packages/nx/src/daemon/tmp-dir.ts @@ -6,13 +6,13 @@ import { statSync, writeFileSync } from 'fs'; import { ensureDirSync, rmSync } from 'fs-extra'; import { join } from 'path'; -import { projectGraphCacheDirectory } from '../utils/cache-directory'; +import { workspaceDataDirectory } from '../utils/cache-directory'; import { createHash } from 'crypto'; import { tmpdir } from 'tmp'; import { workspaceRoot } from '../utils/workspace-root'; export const DAEMON_DIR_FOR_CURRENT_WORKSPACE = join( - projectGraphCacheDirectory, + workspaceDataDirectory, 'd' ); diff --git a/packages/nx/src/migrations/update-19-2-0/move-workspace-data-directory.spec.ts b/packages/nx/src/migrations/update-19-2-0/move-workspace-data-directory.spec.ts new file mode 100644 index 0000000000000..0c1ed963eb5b3 --- /dev/null +++ b/packages/nx/src/migrations/update-19-2-0/move-workspace-data-directory.spec.ts @@ -0,0 +1,32 @@ +import { createTree } from '../../generators/testing-utils/create-tree'; +import moveWorkspaceDataDirectory from './move-workspace-data-directory'; + +describe('moveWorkspaceDataDirectory', () => { + it("should not throw if .gitignore does't exist", () => { + const tree = createTree(); + expect(() => moveWorkspaceDataDirectory(tree)).not.toThrow(); + }); + + it("shouldn't change anything if gitignore doesn't include .nx/cache", () => { + const tree = createTree(); + tree.write('.gitignore', 'dist'); + moveWorkspaceDataDirectory(tree); + expect(tree.read('.gitignore', 'utf-8')).toBe('dist'); + }); + + it('should add .nx/workspace-data to .gitignore if it includes .nx/cache', () => { + const tree = createTree(); + tree.write( + '.gitignore', + ['# temporary files from Nx', '.nx/cache', '', 'dist'].join('\n') + ); + moveWorkspaceDataDirectory(tree); + expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(` + "# temporary files from Nx + .nx/cache + .nx/workspace-data + + dist" + `); + }); +}); diff --git a/packages/nx/src/migrations/update-19-2-0/move-workspace-data-directory.ts b/packages/nx/src/migrations/update-19-2-0/move-workspace-data-directory.ts new file mode 100644 index 0000000000000..06fba2e49ec63 --- /dev/null +++ b/packages/nx/src/migrations/update-19-2-0/move-workspace-data-directory.ts @@ -0,0 +1,41 @@ +import { Tree } from '../../generators/tree'; + +export default async function moveGraphCacheDirectory(tree: Tree) { + updateGitIgnore(tree); + updatePrettierIgnore(tree); +} + +export function updatePrettierIgnore(tree: Tree) { + if (tree.exists('.prettierignore')) { + const ignored = tree.read('.prettierignore', 'utf-8'); + if (!ignored?.includes('.nx/workspace-data')) { + tree.write( + '.prettierignore', + [ignored, '/.nx/workspace-data'].join('\n') + ); + } + } +} + +export function updateGitIgnore(tree: Tree) { + const gitignore = tree.read('.gitignore', 'utf-8'); + if (!gitignore) { + return; + } + + const includesNxWorkspaceData = gitignore.includes('.nx/workspace-data'); + if (includesNxWorkspaceData) { + return; + } + + const includesNxCache = gitignore.includes('.nx/cache'); + if (!includesNxCache) { + return; + } + + const updatedGitignore = gitignore.replace( + '.nx/cache', + ['.nx/cache', '.nx/workspace-data'].join('\n') + ); + tree.write('.gitignore', updatedGitignore); +} diff --git a/packages/nx/src/native/walker.rs b/packages/nx/src/native/walker.rs index 8b50a96d86fa6..5c310ff7004f5 100644 --- a/packages/nx/src/native/walker.rs +++ b/packages/nx/src/native/walker.rs @@ -35,6 +35,7 @@ where "**/node_modules".into(), "**/.git".into(), "**/.nx/cache".into(), + "**/.nx/workspace-data".into(), "**/.yarn/cache".into(), ]; @@ -65,8 +66,14 @@ where { let directory = directory.as_ref(); - let ignore_glob_set = build_glob_set(&["**/node_modules", "**/.git", "**/.nx/cache"]) - .expect("These static ignores always build"); + let ignore_glob_set = build_glob_set(&[ + "**/node_modules", + "**/.git", + "**/.nx/cache", + "**/.nx/workspace-data", + "**/.yarn/cache", + ]) + .expect("These static ignores always build"); let mut walker = WalkBuilder::new(directory); walker.hidden(false); diff --git a/packages/nx/src/plugins/js/index.ts b/packages/nx/src/plugins/js/index.ts index 609c4866a4e34..2f4f565a839e7 100644 --- a/packages/nx/src/plugins/js/index.ts +++ b/packages/nx/src/plugins/js/index.ts @@ -3,7 +3,7 @@ import { ensureDirSync } from 'fs-extra'; import { dirname, join } from 'path'; import { performance } from 'perf_hooks'; import { ProjectGraph } from '../../config/project-graph'; -import { projectGraphCacheDirectory } from '../../utils/cache-directory'; +import { workspaceDataDirectory } from '../../utils/cache-directory'; import { combineGlobPatterns } from '../../utils/globs'; import { CreateDependencies, @@ -160,8 +160,8 @@ function readCachedParsedLockFile(): ParsedLockFile { return JSON.parse(readFileSync(cachedParsedLockFile).toString()); } -const lockFileHashFile = join(projectGraphCacheDirectory, 'lockfile.hash'); +const lockFileHashFile = join(workspaceDataDirectory, 'lockfile.hash'); const cachedParsedLockFile = join( - projectGraphCacheDirectory, + workspaceDataDirectory, 'parsed-lock-file.json' ); diff --git a/packages/nx/src/project-graph/nx-deps-cache.ts b/packages/nx/src/project-graph/nx-deps-cache.ts index f9fb5801a3667..ab7cfd4d0ecb5 100644 --- a/packages/nx/src/project-graph/nx-deps-cache.ts +++ b/packages/nx/src/project-graph/nx-deps-cache.ts @@ -10,7 +10,7 @@ import { ProjectGraph, } from '../config/project-graph'; import { ProjectConfiguration } from '../config/workspace-json-project-json'; -import { projectGraphCacheDirectory } from '../utils/cache-directory'; +import { workspaceDataDirectory } from '../utils/cache-directory'; import { directoryExists, fileExists, @@ -31,15 +31,15 @@ export interface FileMapCache { } export const nxProjectGraph = join( - projectGraphCacheDirectory, + workspaceDataDirectory, 'project-graph.json' ); -export const nxFileMap = join(projectGraphCacheDirectory, 'file-map.json'); +export const nxFileMap = join(workspaceDataDirectory, 'file-map.json'); export function ensureCacheDirectory(): void { try { - if (!existsSync(projectGraphCacheDirectory)) { - ensureDirSync(projectGraphCacheDirectory); + if (!existsSync(workspaceDataDirectory)) { + ensureDirSync(workspaceDataDirectory); } } catch (e) { /* @@ -52,10 +52,8 @@ export function ensureCacheDirectory(): void { * In this case, we're creating the directory. If the operation failed, we ensure that the directory * exists before continuing (or raise an exception). */ - if (!directoryExists(projectGraphCacheDirectory)) { - throw new Error( - `Failed to create directory: ${projectGraphCacheDirectory}` - ); + if (!directoryExists(workspaceDataDirectory)) { + throw new Error(`Failed to create directory: ${workspaceDataDirectory}`); } } } diff --git a/packages/nx/src/utils/cache-directory.ts b/packages/nx/src/utils/cache-directory.ts index 63883fd08cdbc..2a8d735006126 100644 --- a/packages/nx/src/utils/cache-directory.ts +++ b/packages/nx/src/utils/cache-directory.ts @@ -36,7 +36,11 @@ function cacheDirectory(root: string, cacheDirectory: string) { } } -function defaultCacheDirectory(root: string) { +function pickCacheDirectory( + root: string, + nonNxCacheDirectory: string, + nxCacheDirectory: string +) { // If nx.json doesn't exist the repo can't utilize // caching, so .nx/cache is less relevant. Lerna users // that don't want to fully opt in to Nx at this time @@ -47,9 +51,17 @@ function defaultCacheDirectory(root: string) { existsSync(join(root, 'lerna.json')) && !existsSync(join(root, 'nx.json')) ) { - return join(root, 'node_modules', '.cache', 'nx'); + return join(root, 'node_modules', '.cache', nonNxCacheDirectory); } - return join(root, '.nx', 'cache'); + return join(root, '.nx', nxCacheDirectory); +} + +function defaultCacheDirectory(root: string) { + return pickCacheDirectory(root, 'nx', 'cache'); +} + +function defaultWorkspaceDataDirectory(root: string) { + return pickCacheDirectory(root, 'nx-workspace-data', 'workspace-data'); } /** @@ -67,8 +79,9 @@ export function cacheDirectoryForWorkspace(workspaceRoot: string) { ); } -export const projectGraphCacheDirectory = absolutePath( +export const workspaceDataDirectory = absolutePath( workspaceRoot, - process.env.NX_PROJECT_GRAPH_CACHE_DIRECTORY ?? - defaultCacheDirectory(workspaceRoot) + process.env.NX_WORKSPACE_DATA_DIRECTORY ?? + process.env.NX_PROJECT_GRAPH_CACHE_DIRECTORY ?? + defaultWorkspaceDataDirectory(workspaceRoot) ); diff --git a/packages/playwright/src/plugins/plugin.ts b/packages/playwright/src/plugins/plugin.ts index 2384d669e53e2..ef311667e4af5 100644 --- a/packages/playwright/src/plugins/plugin.ts +++ b/packages/playwright/src/plugins/plugin.ts @@ -21,7 +21,7 @@ import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash import type { PlaywrightTestConfig } from '@playwright/test'; import { getFilesInDirectoryUsingContext } from 'nx/src/utils/workspace-context'; import { minimatch } from 'minimatch'; -import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory'; +import { workspaceDataDirectory } from 'nx/src/utils/cache-directory'; import { getLockFileName } from '@nx/js'; import { loadConfigFile } from '@nx/devkit/src/utils/config-utils'; import { hashObject } from 'nx/src/hasher/file-hasher'; @@ -57,7 +57,7 @@ export const createNodesV2: CreateNodesV2 = [ async (configFilePaths, options, context) => { const optionsHash = hashObject(options); const cachePath = join( - projectGraphCacheDirectory, + workspaceDataDirectory, `playwright-${optionsHash}.hash` ); const targetsCache = readTargetsCache(cachePath); diff --git a/packages/react-native/plugins/plugin.ts b/packages/react-native/plugins/plugin.ts index d56a08be9dc8d..a1c027461da80 100644 --- a/packages/react-native/plugins/plugin.ts +++ b/packages/react-native/plugins/plugin.ts @@ -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 ReactNativePluginOptions { @@ -29,7 +29,7 @@ export interface ReactNativePluginOptions { upgradeTargetname?: string; } -const cachePath = join(projectGraphCacheDirectory, 'react-native.hash'); +const cachePath = join(workspaceDataDirectory, 'react-native.hash'); const targetsCache = readTargetsCache(); function readTargetsCache(): Record< string, diff --git a/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts b/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts index 3e2cbe0a19c65..c152e50b3dfe7 100644 --- a/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts +++ b/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts @@ -18,7 +18,7 @@ import { createAsyncIterable, } from '@nx/devkit/src/utils/async-iterable'; import { waitForPortOpen } from '@nx/web/src/utils/wait-for-port-open'; -import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory'; +import { workspaceDataDirectory } from 'nx/src/utils/cache-directory'; import { fork } from 'node:child_process'; import { basename, dirname, join } from 'node:path'; import { createWriteStream, cpSync } from 'node:fs'; @@ -205,7 +205,7 @@ 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); diff --git a/packages/remix/src/plugins/plugin.ts b/packages/remix/src/plugins/plugin.ts index faf019af2bb2d..d48bc6eadd4c8 100644 --- a/packages/remix/src/plugins/plugin.ts +++ b/packages/remix/src/plugins/plugin.ts @@ -1,4 +1,4 @@ -import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory'; +import { workspaceDataDirectory } from 'nx/src/utils/cache-directory'; import { type CreateDependencies, type CreateNodes, @@ -17,7 +17,7 @@ import { dirname, join } from 'path'; import { existsSync, readdirSync } from 'fs'; import { loadConfigFile } from '@nx/devkit/src/utils/config-utils'; -const cachePath = join(projectGraphCacheDirectory, 'remix.hash'); +const cachePath = join(workspaceDataDirectory, 'remix.hash'); const targetsCache = readTargetsCache(); function readTargetsCache(): Record< diff --git a/packages/rollup/src/plugins/plugin.ts b/packages/rollup/src/plugins/plugin.ts index c48a2a51d4d00..a76f4644d944e 100644 --- a/packages/rollup/src/plugins/plugin.ts +++ b/packages/rollup/src/plugins/plugin.ts @@ -1,4 +1,4 @@ -import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory'; +import { workspaceDataDirectory } from 'nx/src/utils/cache-directory'; import { basename, dirname, join } from 'path'; import { existsSync, readdirSync } from 'fs'; import { @@ -20,7 +20,7 @@ import { type RollupOptions } from 'rollup'; // @ts-ignore import { loadConfigFile } from 'rollup/loadConfigFile'; -const cachePath = join(projectGraphCacheDirectory, 'rollup.hash'); +const cachePath = join(workspaceDataDirectory, 'rollup.hash'); const targetsCache = readTargetsCache(); function readTargetsCache(): Record< diff --git a/packages/storybook/src/plugins/plugin.ts b/packages/storybook/src/plugins/plugin.ts index 597ac6a00f0eb..abb1352a2e425 100644 --- a/packages/storybook/src/plugins/plugin.ts +++ b/packages/storybook/src/plugins/plugin.ts @@ -13,7 +13,7 @@ import { dirname, join } from 'path'; import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs'; import { existsSync, readFileSync, 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 { getLockFileName } from '@nx/js'; import { loadConfigFile } from '@nx/devkit/src/utils/config-utils'; import type { StorybookConfig } from '@storybook/types'; @@ -25,7 +25,7 @@ export interface StorybookPluginOptions { testStorybookTargetName?: string; } -const cachePath = join(projectGraphCacheDirectory, 'storybook.hash'); +const cachePath = join(workspaceDataDirectory, 'storybook.hash'); const targetsCache = readTargetsCache(); function readTargetsCache(): Record< diff --git a/packages/vite/src/plugins/plugin.ts b/packages/vite/src/plugins/plugin.ts index ca05415845cf9..6b91eadac280c 100644 --- a/packages/vite/src/plugins/plugin.ts +++ b/packages/vite/src/plugins/plugin.ts @@ -12,7 +12,7 @@ import { dirname, isAbsolute, join, relative } from 'path'; 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 { getLockFileName } from '@nx/js'; import { loadViteDynamicImport } from '../utils/executor-utils'; @@ -24,7 +24,7 @@ export interface VitePluginOptions { serveStaticTargetName?: string; } -const cachePath = join(projectGraphCacheDirectory, 'vite.hash'); +const cachePath = join(workspaceDataDirectory, 'vite.hash'); const targetsCache = readTargetsCache(); function readTargetsCache(): Record< diff --git a/packages/webpack/src/plugins/plugin.ts b/packages/webpack/src/plugins/plugin.ts index e9a2f59ca5ab5..cb4a375e4cec9 100644 --- a/packages/webpack/src/plugins/plugin.ts +++ b/packages/webpack/src/plugins/plugin.ts @@ -16,7 +16,7 @@ import { existsSync, readdirSync } from 'fs'; import { readWebpackOptions } from '../utils/webpack/read-webpack-options'; import { resolveUserDefinedWebpackConfig } from '../utils/webpack/resolve-user-defined-webpack-config'; import { getLockFileName, getRootTsConfigPath } from '@nx/js'; -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'; export interface WebpackPluginOptions { @@ -26,7 +26,7 @@ export interface WebpackPluginOptions { previewTargetName?: string; } -const cachePath = join(projectGraphCacheDirectory, 'webpack.hash'); +const cachePath = join(workspaceDataDirectory, 'webpack.hash'); const targetsCache = readTargetsCache(); function readTargetsCache(): Record<