fix(js): set external nodes when lockfile is not reprocessed (#18944)

This commit is contained in:
Jason Jean 2023-08-31 17:11:01 -04:00 committed by GitHub
parent f6ad6998d4
commit 7f76c2bec3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,7 @@ import { ProjectGraphDependencyWithFile } from '../../project-graph/project-grap
import { hashArray } from '../../hasher/file-hasher'; import { hashArray } from '../../hasher/file-hasher';
import { detectPackageManager } from '../../utils/package-manager'; import { detectPackageManager } from '../../utils/package-manager';
import { workspaceRoot } from '../../utils/workspace-root'; import { workspaceRoot } from '../../utils/workspace-root';
import { nxVersion } from '../../utils/versions';
export const name = 'nx-js-graph-plugin'; export const name = 'nx-js-graph-plugin';
@ -50,11 +51,13 @@ export const createNodes: CreateNodes = [
const lockFilePath = join(workspaceRoot, lockFile); const lockFilePath = join(workspaceRoot, lockFile);
const lockFileContents = readFileSync(lockFilePath).toString(); const lockFileContents = readFileSync(lockFilePath).toString();
const lockFileHash = hashArray([lockFileContents]); const lockFileHash = getLockFileHash(lockFileContents);
if (!lockFileNeedsReprocessing(lockFileHash)) { if (!lockFileNeedsReprocessing(lockFileHash)) {
const nodes = readCachedParsedLockFile().externalNodes;
parsedLockFile.externalNodes = nodes;
return { return {
externalNodes: readCachedParsedLockFile().externalNodes, externalNodes: nodes,
}; };
} }
@ -86,7 +89,7 @@ export const createDependencies: CreateDependencies = (
) { ) {
const lockFilePath = join(workspaceRoot, getLockFileName(packageManager)); const lockFilePath = join(workspaceRoot, getLockFileName(packageManager));
const lockFileContents = readFileSync(lockFilePath).toString(); const lockFileContents = readFileSync(lockFilePath).toString();
const lockFileHash = hashArray([lockFileContents]); const lockFileHash = getLockFileHash(lockFileContents);
if (!lockFileNeedsReprocessing(lockFileHash)) { if (!lockFileNeedsReprocessing(lockFileHash)) {
lockfileDependencies = readCachedParsedLockFile().dependencies ?? []; lockfileDependencies = readCachedParsedLockFile().dependencies ?? [];
@ -118,6 +121,10 @@ export const createDependencies: CreateDependencies = (
return lockfileDependencies.concat(explicitProjectDependencies); return lockfileDependencies.concat(explicitProjectDependencies);
}; };
function getLockFileHash(lockFileContents: string) {
return hashArray([nxVersion, lockFileContents]);
}
function lockFileNeedsReprocessing(lockHash: string) { function lockFileNeedsReprocessing(lockHash: string) {
try { try {
return readFileSync(lockFileHashFile).toString() !== lockHash; return readFileSync(lockFileHashFile).toString() !== lockHash;