Skip to content

Commit

Permalink
chore(core): warn when db cache is disabled (#28929)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
AgentEnder authored Nov 26, 2024
1 parent beded4e commit 30d722b
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions packages/nx/src/tasks-runner/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { verifyOrUpdateNxCloudClient } from '../nx-cloud/update-manager';
import { getCloudOptions } from '../nx-cloud/utilities/get-cloud-options';
import { isCI } from '../utils/is-ci';
import { output } from '../utils/output';
import { logger } from '../utils/logger';

export type CachedResult = {
terminalOutput: string;
Expand All @@ -29,13 +30,50 @@ export type CachedResult = {
};
export type TaskWithCachedResult = { task: Task; cachedResult: CachedResult };

// This function is called once during tasks runner initialization. It checks if the db cache is enabled and logs a warning if it is not.
export function dbCacheEnabled(nxJson: NxJsonConfiguration = readNxJson()) {
return (
!IS_WASM &&
process.env.NX_DISABLE_DB !== 'true' &&
nxJson.useLegacyCache !== true &&
process.env.NX_DB_CACHE !== 'false'
);
// If the user has explicitly disabled the db cache, we can warn...
if (
nxJson.useLegacyCache ||
process.env.NX_DISABLE_DB === 'true' ||
process.env.NX_DB_CACHE === 'false'
) {
let readMoreLink = 'https://nx.dev/deprecated/legacy-cache';
if (
nxJson.tasksRunnerOptions?.default?.runner &&
!['nx-cloud', 'nx/tasks-runners/default', '@nrwl/nx-cloud'].includes(
nxJson.tasksRunnerOptions.default.runner
)
) {
readMoreLink += '#tasksrunneroptions';
} else if (
process.env.NX_REJECT_UNKNOWN_LOCAL_CACHE === '0' ||
process.env.NX_REJECT_UNKNOWN_LOCAL_CACHE === 'false'
) {
readMoreLink += '#nxrejectunknownlocalcache';
}
logger.warn(
`Nx is configured to use the legacy cache. This cache will be removed in Nx 21. Read more at ${readMoreLink}.`
);
return false;
}
// ...but if on wasm and the the db cache isnt supported we shouldn't warn
if (IS_WASM) {
return false;
}
// Below this point we are using the db cache.
if (
// The NX_REJECT_UNKNOWN_LOCAL_CACHE env var is not supported with the db cache.
// If the user has tried to use it, we can point them to powerpack as it
// provides a similar featureset.
process.env.NX_REJECT_UNKNOWN_LOCAL_CACHE === '0' ||
process.env.NX_REJECT_UNKNOWN_LOCAL_CACHE === 'false'
) {
logger.warn(
'NX_REJECT_UNKNOWN_LOCAL_CACHE=0 is not supported with the new database cache. Read more at https://nx.dev/deprecated/legacy-cache#nxrejectunknownlocalcache.'
);
}
return true;
}

// Do not change the order of these arguments as this function is used by nx cloud
Expand Down

0 comments on commit 30d722b

Please sign in to comment.