feat(core): add prune lock file hashing based on the input (#13167)
This commit is contained in:
parent
af0a18ff4e
commit
b924f1a620
@ -1,6 +1,11 @@
|
||||
import { satisfies } from 'semver';
|
||||
import { LockFileData, PackageDependency } from './lock-file-type';
|
||||
import { sortObject, hashString, TransitiveLookupFunctionInput } from './utils';
|
||||
import {
|
||||
sortObject,
|
||||
hashString,
|
||||
TransitiveLookupFunctionInput,
|
||||
generatePrunnedHash,
|
||||
} from './utils';
|
||||
|
||||
type PackageMeta = {
|
||||
path: string;
|
||||
@ -460,7 +465,11 @@ Returning entire lock file.`
|
||||
...pruneRootPackage(lockFileData, packages, projectName),
|
||||
};
|
||||
let prunedLockFileData: LockFileData;
|
||||
prunedLockFileData = { dependencies, lockFileMetadata, hash: '' };
|
||||
prunedLockFileData = {
|
||||
dependencies,
|
||||
lockFileMetadata,
|
||||
hash: generatePrunnedHash(lockFileData.hash, packages, projectName),
|
||||
};
|
||||
return prunedLockFileData;
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import {
|
||||
hashString,
|
||||
isRootVersion,
|
||||
TransitiveLookupFunctionInput,
|
||||
generatePrunnedHash,
|
||||
} from './utils';
|
||||
import { satisfies } from 'semver';
|
||||
|
||||
@ -345,7 +346,7 @@ export function prunePnpmLockFile(
|
||||
const prunedLockFileData = {
|
||||
lockFileMetadata: lockFileData.lockFileMetadata,
|
||||
dependencies,
|
||||
hash: '',
|
||||
hash: generatePrunnedHash(lockFileData.hash, packages, projectName),
|
||||
};
|
||||
return prunedLockFileData;
|
||||
}
|
||||
|
||||
@ -245,3 +245,22 @@ function traverseExternalNodesDependencies(
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate new hash based on the original hash and pruning input parameters - packages and project name
|
||||
* @param originalHash
|
||||
* @param packages
|
||||
* @param projectName
|
||||
* @returns
|
||||
*/
|
||||
export function generatePrunnedHash(
|
||||
originalHash: string,
|
||||
packages: string[],
|
||||
projectName?: string
|
||||
) {
|
||||
const hashingInput = [originalHash, ...packages];
|
||||
if (projectName) {
|
||||
hashingInput.push(projectName);
|
||||
}
|
||||
return defaultHashing.hashArray(hashingInput);
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import {
|
||||
hashString,
|
||||
isRootVersion,
|
||||
TransitiveLookupFunctionInput,
|
||||
generatePrunnedHash,
|
||||
} from './utils';
|
||||
|
||||
type LockFileDependencies = Record<
|
||||
@ -204,10 +205,13 @@ export function pruneYarnLockFile(
|
||||
),
|
||||
},
|
||||
dependencies: prunedDependencies,
|
||||
hash: '',
|
||||
hash: generatePrunnedHash(lockFileData.hash, packages, projectName),
|
||||
};
|
||||
} else {
|
||||
prunedLockFileData = { dependencies: prunedDependencies, hash: '' };
|
||||
prunedLockFileData = {
|
||||
dependencies: prunedDependencies,
|
||||
hash: generatePrunnedHash(lockFileData.hash, packages, projectName),
|
||||
};
|
||||
}
|
||||
|
||||
prunedLockFileData.hash = hashString(JSON.stringify(prunedLockFileData));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user