fix(core): store relative file name in hash details (#10166)
This commit is contained in:
parent
339b12977e
commit
5c9abff3c5
30
.husky/_/husky.sh
Normal file
30
.husky/_/husky.sh
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#!/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
|
||||||
@ -1,5 +1,6 @@
|
|||||||
// This must come before the Hasher import
|
// This must come before the Hasher import
|
||||||
import { DependencyType } from '../config/project-graph';
|
import { DependencyType } from '../config/project-graph';
|
||||||
|
import { defaultFileHasher } from '../hasher/file-hasher';
|
||||||
|
|
||||||
jest.doMock('../utils/workspace-root', () => {
|
jest.doMock('../utils/workspace-root', () => {
|
||||||
return {
|
return {
|
||||||
@ -56,6 +57,10 @@ describe('Hasher', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
|
jest
|
||||||
|
.spyOn(defaultFileHasher, 'hashFile')
|
||||||
|
.mockImplementation((p) => hashes[p]);
|
||||||
|
|
||||||
fs.readFileSync = (file) => {
|
fs.readFileSync = (file) => {
|
||||||
if (file === 'workspace.json') {
|
if (file === 'workspace.json') {
|
||||||
return JSON.stringify(workSpaceJson);
|
return JSON.stringify(workSpaceJson);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { resolveNewFormatWithInlineProjects } from '../config/workspaces';
|
|||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import * as minimatch from 'minimatch';
|
import * as minimatch from 'minimatch';
|
||||||
import { join } from 'path';
|
import { join, sep as pathSep } from 'path';
|
||||||
import { performance } from 'perf_hooks';
|
import { performance } from 'perf_hooks';
|
||||||
import { getRootTsConfigFileName } from '../utils/typescript';
|
import { getRootTsConfigFileName } from '../utils/typescript';
|
||||||
import { workspaceRoot } from '../utils/workspace-root';
|
import { workspaceRoot } from '../utils/workspace-root';
|
||||||
@ -13,6 +13,7 @@ import { NxJsonConfiguration } from '../config/nx-json';
|
|||||||
import { Task } from '../config/task-graph';
|
import { Task } from '../config/task-graph';
|
||||||
import { readJsonFile } from '../utils/fileutils';
|
import { readJsonFile } from '../utils/fileutils';
|
||||||
import { ProjectsConfigurations } from '../config/workspace-json-project-json';
|
import { ProjectsConfigurations } from '../config/workspace-json-project-json';
|
||||||
|
import { defaultFileHasher } from './file-hasher';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A data structure returned by the default hasher.
|
* A data structure returned by the default hasher.
|
||||||
@ -248,20 +249,10 @@ export class Hasher {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const fileHashes = [
|
const fileHashes = [
|
||||||
...fileNames
|
...fileNames.map((file) => ({
|
||||||
.map((maybeRelativePath) => {
|
file,
|
||||||
// Normalize the path to always be absolute and starting with workspaceRoot so we can check it exists
|
hash: defaultFileHasher.hashFile(file),
|
||||||
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(),
|
...this.hashNxJson(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user