Skip to content

Commit

Permalink
feat(core): add native extension implementation
Browse files Browse the repository at this point in the history
This reverts commit b30c9fd.
  • Loading branch information
Cammisuli authored and FrozenPandaz committed Jan 30, 2023
1 parent c7c5bc3 commit 4e7bdda
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/nx/src/hasher/file-hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import { FileHasherBase } from './file-hasher-base';
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { join } from 'path';
import { NativeFileHasher } from './native-file-hasher';

function createFileHasher(): FileHasherBase {
// special case for unit tests
if (workspaceRoot === '/root') {
return new NodeBasedFileHasher();
}
try {
if (process.env.NX_NATIVE_HASHER) {
return new NativeFileHasher();
}

execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
// we don't use git based hasher when the repo uses git submodules
if (!existsSync(join(workspaceRoot, '.git', 'modules'))) {
Expand Down
34 changes: 34 additions & 0 deletions packages/nx/src/hasher/native-file-hasher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FileHasherBase } from './file-hasher-base';
import { performance } from 'perf_hooks';
import { hashFile, hashFiles } from '@nrwl/native-extensions';
import { workspaceRoot } from '../utils/app-root';

export class NativeFileHasher extends FileHasherBase {
async init(): Promise<void> {
performance.mark('init hashing:start');
this.clear();
const filesObject = hashFiles(workspaceRoot);
this.fileHashes = new Map(Object.entries(filesObject));

performance.mark('init hashing:end');
performance.measure(
'init hashing',
'init hashing:start',
'init hashing:end'
);
}

async hashFiles(files: string[]): Promise<Map<string, string>> {
const r = new Map<string, string>();

for (let f of files) {
r.set(f, this.hashFile(f));
}

return r;
}

hashFile(path: string): string {
return hashFile(path).hash;
}
}

0 comments on commit 4e7bdda

Please sign in to comment.