fix: current lockfile up-to-date check

This commit is contained in:
Zoltan Kochan
2020-05-26 01:14:19 +03:00
parent 48e3f81073
commit 327bfbf02b
6 changed files with 16 additions and 31 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/get-context": minor
---
Add `currentLockfileIsUpToDate` to the context.

View File

@@ -0,0 +1,5 @@
---
"supi": patch
---
Fix current lockfile (the one at `node_modules/.pnpm/lock.yaml`) up-to-date check.

View File

@@ -23,6 +23,7 @@ import readLockfileFile from './readLockfiles'
export interface PnpmContext<T> {
currentLockfile: Lockfile,
currentLockfileIsUpToDate: boolean,
existsCurrentLockfile: boolean,
existsWantedLockfile: boolean,
extraBinPaths: string[],
@@ -292,6 +293,7 @@ function stringifyIncludedDeps (included: IncludedDependencies) {
export interface PnpmSingleContext {
currentLockfile: Lockfile,
currentLockfileIsUpToDate: boolean,
existsCurrentLockfile: boolean,
existsWantedLockfile: boolean,
extraBinPaths: string[],

View File

@@ -35,6 +35,7 @@ export default async function (
}
): Promise<{
currentLockfile: Lockfile,
currentLockfileIsUpToDate: boolean,
existsCurrentLockfile: boolean,
existsWantedLockfile: boolean,
wantedLockfile: Lockfile,
@@ -76,6 +77,7 @@ export default async function (
}
return {
currentLockfile,
currentLockfileIsUpToDate: R.equals(currentLockfile, wantedLockfile),
existsCurrentLockfile: !!files[1],
existsWantedLockfile: !!files[0],
wantedLockfile,

View File

@@ -64,7 +64,6 @@ import getWantedDependencies, {
PinnedVersion,
WantedDependency,
} from './getWantedDependencies'
import isCurrentLockfileUpToDate from './isCurrentLockfilesUpToDate'
import linkPackages, {
DependenciesGraph,
DependenciesGraphNode,
@@ -389,24 +388,15 @@ export async function mutateModules (
})
}
const currentLockfileIsUpToDate = isCurrentLockfileUpToDate(
ctx.currentLockfile,
{
skipped: Array.from(ctx.skipped),
wantedLockfile: ctx.wantedLockfile,
}
)
// Unfortunately, the private lockfile may differ from the public one.
// A user might run named installations on a project that has a pnpm-lock.yaml file before running a noop install
const makePartialCurrentLockfile = !installsOnly && (
ctx.existsWantedLockfile && !ctx.existsCurrentLockfile ||
// TODO: this operation is quite expensive. We'll have to find a better solution to do this.
// maybe in pnpm v2 it won't be needed. See: https://github.com/pnpm/pnpm/issues/841
!currentLockfileIsUpToDate
!ctx.currentLockfileIsUpToDate
)
const result = await installInContext(projectsToInstall, ctx, {
...opts,
currentLockfileIsUpToDate: !ctx.existsWantedLockfile || currentLockfileIsUpToDate,
currentLockfileIsUpToDate: !ctx.existsWantedLockfile || ctx.currentLockfileIsUpToDate,
makePartialCurrentLockfile,
update: opts.update || !installsOnly,
updateLockfileMinorVersion: true,

View File

@@ -1,19 +0,0 @@
import { Lockfile } from '@pnpm/lockfile-file'
import R = require('ramda')
export default function (
currentLockfile: Lockfile,
opts: {
skipped: string[],
wantedLockfile: Lockfile,
}
) {
const importers1 = R.keys(opts.wantedLockfile.importers)
const importers2 = R.keys(currentLockfile.importers)
if (importers1.length !== importers2.length || !R.equals(importers1, importers2)) {
return false
}
const pkgs1 = R.keys(opts.wantedLockfile.packages)
const pkgs2 = R.keys(currentLockfile.packages).concat(opts.skipped)
return pkgs1.length === pkgs2.length && R.equals(pkgs1, pkgs2.sort())
}