Skip to content

Commit

Permalink
fix(core): disable the db by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Nov 1, 2024
1 parent 9adb9e0 commit 0c5424c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/nx/src/hasher/hash-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { ProjectGraph } from '../config/project-graph';
import { NxJsonConfiguration } from '../config/nx-json';
import { readNxJson } from '../config/nx-json';
import { HashedTask, IS_WASM, TaskDetails } from '../native';
import { getDbConnection } from '../utils/db-connection';
import { databaseSupportEnabled, getDbConnection } from '../utils/database';

let taskDetails: TaskDetails;

export function getTaskDetails(): TaskDetails | null {
// TODO: Remove when wasm supports sqlite
if (process.env.NX_DISABLE_DB === 'true' || IS_WASM) {
if (!databaseSupportEnabled() || IS_WASM) {
return null;
}
if (!taskDetails) {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/native/tests/cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TaskDetails, NxCache } from '../index';
import { join } from 'path';
import { TempFs } from '../../internal-testing-utils/temp-fs';
import { rmSync } from 'fs';
import { getDbConnection } from '../../utils/db-connection';
import { getDbConnection } from '../../utils/database';
import { randomBytes } from 'crypto';

describe('Cache', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/native/tests/task_history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TaskDetails, NxTaskHistory } from '../index';
import { join } from 'path';
import { TempFs } from '../../internal-testing-utils/temp-fs';
import { rmSync } from 'fs';
import { getDbConnection } from '../../utils/db-connection';
import { getDbConnection } from '../../utils/database';
import { randomBytes } from 'crypto';

const dbOutputFolder = 'temp-db-task';
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/tasks-runner/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { cacheDir } from '../utils/cache-directory';
import { Task } from '../config/task-graph';
import { machineId } from 'node-machine-id';
import { NxCache, CachedResult as NativeCacheResult, IS_WASM } from '../native';
import { getDbConnection } from '../utils/db-connection';
import { databaseSupportEnabled, getDbConnection } from '../utils/database';
import { isNxCloudUsed } from '../utils/nx-cloud-utils';
import { NxJsonConfiguration, readNxJson } from '../config/nx-json';
import { verifyOrUpdateNxCloudClient } from '../nx-cloud/update-manager';
Expand All @@ -32,7 +32,7 @@ export type TaskWithCachedResult = { task: Task; cachedResult: CachedResult };
export function dbCacheEnabled(nxJson: NxJsonConfiguration = readNxJson()) {
return (
!IS_WASM &&
process.env.NX_DISABLE_DB !== 'true' &&
databaseSupportEnabled() &&
nxJson.useLegacyCache !== true &&
process.env.NX_DB_CACHE !== 'false'
);
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/tasks-runner/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { shouldStreamOutput } from './utils';
import chalk = require('chalk');
import type { Observable } from 'rxjs';
import { printPowerpackLicense } from '../utils/powerpack';
import { databaseSupportEnabled } from '../utils/database';

async function getTerminalOutputLifeCycle(
initiatingProject: string,
Expand Down Expand Up @@ -711,7 +712,7 @@ function constructLifeCycles(lifeCycle: LifeCycle): LifeCycle[] {
}
if (!isNxCloudUsed(readNxJson())) {
lifeCycles.push(
process.env.NX_DISABLE_DB !== 'true' && !IS_WASM
databaseSupportEnabled() && !IS_WASM
? new TaskHistoryLifeCycle()
: new LegacyTaskHistoryLifeCycle()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ function getEntryOrSet<TKey, TVal>(
map.set(key, val);
return val;
}

// database is disabled by default
export function databaseSupportEnabled() {
return process.env.NX_DISABLE_DB === 'false';
}
4 changes: 2 additions & 2 deletions packages/nx/src/utils/task-history.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { daemonClient } from '../daemon/client/client';
import { isOnDaemon } from '../daemon/is-on-daemon';
import { IS_WASM, NxTaskHistory, TaskRun, TaskTarget } from '../native';
import { getDbConnection } from './db-connection';
import { databaseSupportEnabled, getDbConnection } from './database';

export class TaskHistory {
taskHistory = new NxTaskHistory(getDbConnection());
Expand Down Expand Up @@ -42,7 +42,7 @@ let taskHistory: TaskHistory;
* @returns singleton instance of TaskHistory, null if database is disabled or WASM is enabled
*/
export function getTaskHistory(): TaskHistory | null {
if (process.env.NX_DISABLE_DB === 'true' || IS_WASM) {
if (!databaseSupportEnabled() || IS_WASM) {
return null;
}

Expand Down

0 comments on commit 0c5424c

Please sign in to comment.