Skip to content

Commit

Permalink
fix: print more info when lockfile is outdated
Browse files Browse the repository at this point in the history
ref #6526
  • Loading branch information
zkochan committed May 12, 2023
1 parent 1de07a4 commit 1dc39a1
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions lockfile/lockfile-utils/src/satisfiesPackageManifest.ts
Expand Up @@ -14,8 +14,8 @@ export function satisfiesPackageManifest (
},
importer: ProjectSnapshot | undefined,
pkg: ProjectManifest
) {
if (!importer) return false
): { satisfies: boolean, detailedReason?: string } {
if (!importer) return { satisfies: false, detailedReason: 'no importer' }
let existingDeps: Record<string, string> = { ...pkg.devDependencies, ...pkg.dependencies, ...pkg.optionalDependencies }
if (opts?.autoInstallPeers) {
pkg = {
Expand All @@ -36,13 +36,24 @@ export function satisfiesPackageManifest (
existingDeps = pickNonLinkedDeps(existingDeps)
specs = pickNonLinkedDeps(specs)
}
if (
!equals(existingDeps, specs) ||
importer.publishDirectory !== pkg.publishConfig?.directory
) {
return false
if (!equals(existingDeps, specs)) {
return {
satisfies: false,
detailedReason: `importer specifiers don't match package manifest`,

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Strings must use singlequote

Check failure on line 42 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Strings must use singlequote
}
}
if (importer.publishDirectory !== pkg.publishConfig?.directory) {
return {
satisfies: false,
detailedReason: `importer publish directory doesn't match package manifest`,

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Strings must use singlequote

Check failure on line 48 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Strings must use singlequote
}
}
if (!equals(pkg.dependenciesMeta ?? {}, importer.dependenciesMeta ?? {})) {
return {
satisfies: false,
detailedReason: `importer dependencies meta doesn't match package manifest`,

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Strings must use singlequote

Check failure on line 54 in lockfile/lockfile-utils/src/satisfiesPackageManifest.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Strings must use singlequote
}
}
if (!equals(pkg.dependenciesMeta ?? {}, importer.dependenciesMeta ?? {})) return false
for (const depField of DEPENDENCIES_FIELDS) {
const importerDeps = importer[depField] ?? {}
let pkgDeps: Record<string, string> = pkg[depField] ?? {}
Expand All @@ -69,15 +80,25 @@ export function satisfiesPackageManifest (
default:
throw new Error(`Unknown dependency type "${depField as string}"`)
}
if (pkgDepNames.length !== Object.keys(importerDeps).length &&
pkgDepNames.length !== countOfNonLinkedDeps(importerDeps)) {
return false
if (
pkgDepNames.length !== Object.keys(importerDeps).length &&
pkgDepNames.length !== countOfNonLinkedDeps(importerDeps)
) {
return {
satisfies: false,
detailedReason: `importer ${depField} don't match package manifest`,
}
}
for (const depName of pkgDepNames) {
if (!importerDeps[depName] || importer.specifiers?.[depName] !== pkgDeps[depName]) return false
if (!importerDeps[depName] || importer.specifiers?.[depName] !== pkgDeps[depName]) {
return {
satisfies: false,
detailedReason: `importer ${depField} don't match package manifest`,
}
}
}
}
return true
return { satisfies: true }
}

function countOfNonLinkedDeps (lockfileDeps: { [depName: string]: string }): number {
Expand Down

0 comments on commit 1dc39a1

Please sign in to comment.