From c6b5863996d5e4f309ff0d88be7e4550a28d1da3 Mon Sep 17 00:00:00 2001 From: Raine Revere Date: Sat, 25 Nov 2023 00:36:29 +0000 Subject: [PATCH] npm/fetchUpgradedPackument: Conditionally return dist-tags and engines. --- src/package-managers/npm.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/package-managers/npm.ts b/src/package-managers/npm.ts index b731a355..4293bd8e 100644 --- a/src/package-managers/npm.ts +++ b/src/package-managers/npm.ts @@ -1,6 +1,7 @@ import memoize from 'fast-memoize' import fs from 'fs' import ini from 'ini' +import { uniq } from 'lodash' import camelCase from 'lodash/camelCase' import filter from 'lodash/filter' import isEqual from 'lodash/isEqual' @@ -493,7 +494,12 @@ async function fetchUpgradedPackument( const tag = options.distTag || 'latest' result = await fetchPartialPackument( packageName, - ['deprecated', 'dist-tags', 'engines', 'versions'], + uniq([ + 'dist-tags', + ...fields, + ...(!options.deprecated ? (['deprecated', 'versions'] as const) : []), + ...(options.enginesNode ? (['engines', 'versions'] as const) : []), + ]), fullMetadata ? null : tag, npmConfigMerged, ) @@ -710,7 +716,14 @@ export const distTag: GetVersion = async ( npmConfigProject, ) const version = packument?.['dist-tags']?.[options.distTag || 'latest'] - const tagPackument = version && packument.versions?.[version] + + // if the packument does not contain versions, we need to add a minimal versions property with the upgraded version + const tagPackument = packument?.versions + ? packument.versions?.[version!] + : { + name: packageName, + version, + } // latest should not be deprecated // if latest exists and latest is not a prerelease version, return it @@ -719,7 +732,7 @@ export const distTag: GetVersion = async ( if (tagPackument && filterPredicate(options)(tagPackument)) { return { version: tagPackument.version, - ...(packument.time?.[version] ? { time: packument.time[version] } : null), + ...(packument?.time?.[version!] ? { time: packument.time[version!] } : null), } }