Skip to content

Commit

Permalink
fix(core): only use native hasher if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Apr 10, 2023
1 parent 9690c0b commit dc2e4c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/nx/src/hasher/file-hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { NativeFileHasher } from './native-file-hasher';
function createFileHasher(): FileHasherBase {
try {
if (
!process.env.NX_NON_NATIVE_HASHER ||
process.env.NX_NON_NATIVE_HASHER != 'true'
(!process.env.NX_NON_NATIVE_HASHER ||
process.env.NX_NON_NATIVE_HASHER != 'true') &&
NativeFileHasher.available()
) {
return new NativeFileHasher();
}
Expand Down
9 changes: 9 additions & 0 deletions packages/nx/src/hasher/native-file-hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { performance } from 'perf_hooks';
import { workspaceRoot } from '../utils/app-root';

export class NativeFileHasher extends FileHasherBase {
static available() {
try {
require('../native');
return true;
} catch {
return false;
}
}

async init(): Promise<void> {
performance.mark('init hashing:start');
// Import as needed. There is also an issue running unit tests in Nx repo if this is a top-level import.
Expand Down

0 comments on commit dc2e4c7

Please sign in to comment.