diff --git a/.changeset/smart-tables-hammer.md b/.changeset/smart-tables-hammer.md new file mode 100644 index 0000000000..7e2ec0cb49 --- /dev/null +++ b/.changeset/smart-tables-hammer.md @@ -0,0 +1,5 @@ +--- +"@pnpm/get-context": minor +--- + +Add `currentLockfileIsUpToDate` to the context. diff --git a/.changeset/three-pens-clap.md b/.changeset/three-pens-clap.md new file mode 100644 index 0000000000..daa9c2807c --- /dev/null +++ b/.changeset/three-pens-clap.md @@ -0,0 +1,5 @@ +--- +"supi": patch +--- + +Fix current lockfile (the one at `node_modules/.pnpm/lock.yaml`) up-to-date check. diff --git a/packages/get-context/src/index.ts b/packages/get-context/src/index.ts index 1e5aab8064..0259581e6f 100644 --- a/packages/get-context/src/index.ts +++ b/packages/get-context/src/index.ts @@ -23,6 +23,7 @@ import readLockfileFile from './readLockfiles' export interface PnpmContext { 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[], diff --git a/packages/get-context/src/readLockfiles.ts b/packages/get-context/src/readLockfiles.ts index fdbd1c48ac..73b426ab16 100644 --- a/packages/get-context/src/readLockfiles.ts +++ b/packages/get-context/src/readLockfiles.ts @@ -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, diff --git a/packages/supi/src/install/index.ts b/packages/supi/src/install/index.ts index 6cdd9276cb..49e06e3ba9 100644 --- a/packages/supi/src/install/index.ts +++ b/packages/supi/src/install/index.ts @@ -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, diff --git a/packages/supi/src/install/isCurrentLockfilesUpToDate.ts b/packages/supi/src/install/isCurrentLockfilesUpToDate.ts deleted file mode 100644 index 956a94fe2f..0000000000 --- a/packages/supi/src/install/isCurrentLockfilesUpToDate.ts +++ /dev/null @@ -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()) -}