From 6c3ce13b589d8e4702ab4928bd545db0e821802c Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Tue, 7 Jun 2022 08:34:23 -0400 Subject: [PATCH] Revert "fix(core): store relative file name in hash details (#10166)" This reverts commit 5c9abff3c5c6e3c2654e2b2dc1120bc143b2922b. --- .husky/_/husky.sh | 30 --------------------------- packages/nx/src/hasher/hasher.spec.ts | 5 ----- packages/nx/src/hasher/hasher.ts | 21 +++++++++++++------ 3 files changed, 15 insertions(+), 41 deletions(-) delete mode 100644 .husky/_/husky.sh diff --git a/.husky/_/husky.sh b/.husky/_/husky.sh deleted file mode 100644 index ca2720e08aad5..0000000000000 --- a/.husky/_/husky.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -if [ -z "$husky_skip_init" ]; then - debug () { - [ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1" - } - - readonly hook_name="$(basename "$0")" - debug "starting $hook_name..." - - if [ "$HUSKY" = "0" ]; then - debug "HUSKY env variable is set to 0, skipping hook" - exit 0 - fi - - if [ -f ~/.huskyrc ]; then - debug "sourcing ~/.huskyrc" - . ~/.huskyrc - fi - - export readonly husky_skip_init=1 - sh -e "$0" "$@" - exitCode="$?" - - if [ $exitCode != 0 ]; then - echo "husky - $hook_name hook exited with code $exitCode (error)" - exit $exitCode - fi - - exit 0 -fi diff --git a/packages/nx/src/hasher/hasher.spec.ts b/packages/nx/src/hasher/hasher.spec.ts index 5725c9d09e41a..a449adc85c1e0 100644 --- a/packages/nx/src/hasher/hasher.spec.ts +++ b/packages/nx/src/hasher/hasher.spec.ts @@ -1,6 +1,5 @@ // This must come before the Hasher import import { DependencyType } from '../config/project-graph'; -import { defaultFileHasher } from '../hasher/file-hasher'; jest.doMock('../utils/workspace-root', () => { return { @@ -57,10 +56,6 @@ describe('Hasher', () => { } beforeAll(() => { - jest - .spyOn(defaultFileHasher, 'hashFile') - .mockImplementation((p) => hashes[p]); - fs.readFileSync = (file) => { if (file === 'workspace.json') { return JSON.stringify(workSpaceJson); diff --git a/packages/nx/src/hasher/hasher.ts b/packages/nx/src/hasher/hasher.ts index a54423c3dcff8..b3496cde2a816 100644 --- a/packages/nx/src/hasher/hasher.ts +++ b/packages/nx/src/hasher/hasher.ts @@ -2,7 +2,7 @@ import { resolveNewFormatWithInlineProjects } from '../config/workspaces'; import { exec } from 'child_process'; import { existsSync } from 'fs'; import * as minimatch from 'minimatch'; -import { join, sep as pathSep } from 'path'; +import { join } from 'path'; import { performance } from 'perf_hooks'; import { getRootTsConfigFileName } from '../utils/typescript'; import { workspaceRoot } from '../utils/workspace-root'; @@ -13,7 +13,6 @@ import { NxJsonConfiguration } from '../config/nx-json'; import { Task } from '../config/task-graph'; import { readJsonFile } from '../utils/fileutils'; import { ProjectsConfigurations } from '../config/workspace-json-project-json'; -import { defaultFileHasher } from './file-hasher'; /** * A data structure returned by the default hasher. @@ -249,10 +248,20 @@ export class Hasher { ]; const fileHashes = [ - ...fileNames.map((file) => ({ - file, - hash: defaultFileHasher.hashFile(file), - })), + ...fileNames + .map((maybeRelativePath) => { + // Normalize the path to always be absolute and starting with workspaceRoot so we can check it exists + if (!maybeRelativePath.startsWith(workspaceRoot)) { + return join(workspaceRoot, maybeRelativePath); + } + return maybeRelativePath; + }) + .filter((file) => existsSync(file)) + .map((file) => { + // we should use default file hasher here + const hash = this.hashing.hashFile(file); + return { file, hash }; + }), ...this.hashNxJson(), ];