From ee24bcdd4c9e5034f84b29c2e967e98a2f2cfd3d Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 28 Feb 2018 01:40:55 +0200 Subject: [PATCH] feat: add updated: boolean to PackageResponse.body The new field is true when the package's resolution has been updated. ref pnpm/pnpm#1054 --- src/packageRequester.ts | 11 ++++++++++- test/index.ts | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/packageRequester.ts b/src/packageRequester.ts index e5d94dfbfe..0bdfd0cf91 100644 --- a/src/packageRequester.ts +++ b/src/packageRequester.ts @@ -47,6 +47,7 @@ export type PackageResponse = { manifest: PackageManifest id: string, normalizedPref?: string, + updated: boolean, }, } | ( { @@ -63,6 +64,7 @@ export type PackageResponse = { // resolved package, it is out-of-date. latest?: string, normalizedPref?: string, + updated: boolean, }, } & ( { @@ -70,6 +72,7 @@ export type PackageResponse = { } | { body: { manifest: PackageManifest, + updated: boolean, }, } ) @@ -182,6 +185,7 @@ async function resolveAndFetch ( let pkgId = options.currentPkgId const skipResolution = resolution && !options.update let forceFetch = false + let updated = false // When fetching is skipped, resolution cannot be skipped. // We need the package's manifest when doing `shrinkwrap-only` installs. @@ -208,9 +212,10 @@ async function resolveAndFetch ( ) if (!skipResolution || forceFetch) { + updated = pkgId !== resolveResult.id || !resolution || forceFetch // Keep the shrinkwrap resolution when possible // to keep the original shasum. - if (pkgId !== resolveResult.id || !resolution || forceFetch) { + if (updated) { resolution = resolveResult.resolution } pkgId = resolveResult.id @@ -234,6 +239,7 @@ async function resolveAndFetch ( manifest: pkg, normalizedPref, resolution: resolution as DirectoryResolution, + updated, }, } } @@ -254,6 +260,7 @@ async function resolveAndFetch ( manifest: pkg, normalizedPref, resolution, + updated, }, } } @@ -286,6 +293,7 @@ async function resolveAndFetch ( manifest: pkg, normalizedPref, resolution, + updated, }, fetchingFiles: ctx.fetchingLocker[id].fetchingFiles, finishing: ctx.fetchingLocker[id].finishing, @@ -300,6 +308,7 @@ async function resolveAndFetch ( latest, normalizedPref, resolution, + updated, }, fetchingFiles: ctx.fetchingLocker[id].fetchingFiles, fetchingManifest: ctx.fetchingLocker[id].fetchingManifest as Promise, diff --git a/test/index.ts b/test/index.ts index 10cea4ccf8..42d23341e0 100644 --- a/test/index.ts +++ b/test/index.ts @@ -188,6 +188,7 @@ test('refetch local tarball if its integrity has changed', async t => { await response.fetchingFiles await response.finishing + t.ok(response.body.updated === false, 'resolution not updated') t.notOk((await response.fetchingFiles).fromStore, 'unpack tarball if it is not in store yet') } @@ -216,6 +217,7 @@ test('refetch local tarball if its integrity has changed', async t => { await response.fetchingFiles await response.finishing + t.ok(response.body.updated === true) t.notOk((await response.fetchingFiles).fromStore, 're-unpack tarball if its integrity has changed') } @@ -244,6 +246,7 @@ test('refetch local tarball if its integrity has changed', async t => { await response.fetchingFiles await response.finishing + t.ok(response.body.updated === false) t.ok((await response.fetchingFiles).fromStore, 'use existing package from store if integrities matched') }