Skip to content

Commit

Permalink
fix(js): set external nodes when lockfile is not reprocessed (#18944)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Aug 31, 2023
1 parent f6ad699 commit 7f76c2b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/nx/src/plugins/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
};
}

Expand Down Expand Up @@ -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 ?? [];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7f76c2b

Please sign in to comment.