From 7f76c2bec3fc068acbc11d63b09daf4368b932a4 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Thu, 31 Aug 2023 17:11:01 -0400 Subject: [PATCH] fix(js): set external nodes when lockfile is not reprocessed (#18944) --- packages/nx/src/plugins/js/index.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/nx/src/plugins/js/index.ts b/packages/nx/src/plugins/js/index.ts index 62c13b89a34a3..e338685e6b43c 100644 --- a/packages/nx/src/plugins/js/index.ts +++ b/packages/nx/src/plugins/js/index.ts @@ -23,6 +23,7 @@ import { ProjectGraphDependencyWithFile } from '../../project-graph/project-grap import { hashArray } from '../../hasher/file-hasher'; import { detectPackageManager } from '../../utils/package-manager'; import { workspaceRoot } from '../../utils/workspace-root'; +import { nxVersion } from '../../utils/versions'; export const name = 'nx-js-graph-plugin'; @@ -50,11 +51,13 @@ export const createNodes: CreateNodes = [ const lockFilePath = join(workspaceRoot, lockFile); const lockFileContents = readFileSync(lockFilePath).toString(); - const lockFileHash = hashArray([lockFileContents]); + const lockFileHash = getLockFileHash(lockFileContents); if (!lockFileNeedsReprocessing(lockFileHash)) { + const nodes = readCachedParsedLockFile().externalNodes; + parsedLockFile.externalNodes = nodes; return { - externalNodes: readCachedParsedLockFile().externalNodes, + externalNodes: nodes, }; } @@ -86,7 +89,7 @@ export const createDependencies: CreateDependencies = ( ) { const lockFilePath = join(workspaceRoot, getLockFileName(packageManager)); const lockFileContents = readFileSync(lockFilePath).toString(); - const lockFileHash = hashArray([lockFileContents]); + const lockFileHash = getLockFileHash(lockFileContents); if (!lockFileNeedsReprocessing(lockFileHash)) { lockfileDependencies = readCachedParsedLockFile().dependencies ?? []; @@ -118,6 +121,10 @@ export const createDependencies: CreateDependencies = ( return lockfileDependencies.concat(explicitProjectDependencies); }; +function getLockFileHash(lockFileContents: string) { + return hashArray([nxVersion, lockFileContents]); +} + function lockFileNeedsReprocessing(lockHash: string) { try { return readFileSync(lockFileHashFile).toString() !== lockHash;