Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix lock file mapping for yarn berry #13026

Merged
merged 1 commit into from Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/nx/src/utils/lock-file/npm.ts
Expand Up @@ -378,7 +378,7 @@ export function transitiveDependencyNpmLookup(
parentPackage: string,
versions: PackageVersions,
version: string
): string {
): PackageDependency {
const nestedVersion = Object.values(versions).find((v) =>
v.packageMeta.some(
(p) =>
Expand All @@ -387,11 +387,11 @@ export function transitiveDependencyNpmLookup(
);

if (nestedVersion) {
return nestedVersion.version;
return nestedVersion;
}

// otherwise search for the matching version
return Object.values(versions).find((v) => v.rootVersion)?.version;
return Object.values(versions).find((v) => v.rootVersion);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions packages/nx/src/utils/lock-file/pnpm.ts
Expand Up @@ -281,10 +281,9 @@ export function transitiveDependencyPnpmLookup(
parentPackage: string,
versions: PackageVersions,
version: string
): string {
): PackageDependency {
// pnpm's dependencies always point to the exact version so this block is only for insurrance
return Object.values(versions).find((v) => satisfies(v.version, version))
?.version;
return Object.values(versions).find((v) => satisfies(v.version, version));
}

/**
Expand Down
10 changes: 7 additions & 3 deletions packages/nx/src/utils/lock-file/utils.ts
@@ -1,6 +1,10 @@
import { satisfies } from 'semver';
import { defaultHashing } from '../../hasher/hashing-impl';
import { LockFileData, PackageVersions } from './lock-file-type';
import {
LockFileData,
PackageDependency,
PackageVersions,
} from './lock-file-type';
import { workspaceRoot } from '../workspace-root';
import { existsSync, readFileSync } from 'fs';
import {
Expand Down Expand Up @@ -84,7 +88,7 @@ type TransitiveLookupFunction = (
parentPackage: string,
versions: PackageVersions,
version: string
) => string;
) => PackageDependency;

export function mapExternalNodes(
lockFileData: LockFileData,
Expand Down Expand Up @@ -182,7 +186,7 @@ function mapTransitiveDependencies(
parentPackage,
packages[packageName],
cleanVersion
);
)?.version;
// for some peer dependencies, we won't find installed version so we'll just ignore these
if (version) {
const nodeName = getNodeName(
Expand Down
10 changes: 7 additions & 3 deletions packages/nx/src/utils/lock-file/yarn.ts
Expand Up @@ -160,10 +160,14 @@ export function transitiveDependencyYarnLookup(
parentPackage: string,
versions: PackageVersions,
version: string
): string {
): PackageDependency {
return Object.values(versions).find((v) =>
v.packageMeta.some((p) => p === `${packageName}@${version}`)
)?.version;
v.packageMeta.some(
(p) =>
p === `${packageName}@${version}` ||
p === `${packageName}@npm:${version}`
)
);
}

/**
Expand Down