Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core): warn when db cache is disabled #28929

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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