From 88f68071fc0fffc33d24d4e9059c50c8c0171577 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 24 Jun 2022 10:33:30 +0200 Subject: [PATCH] feat: download the latest version instead of a pinned one Fixes: https://github.com/nodejs/corepack/issues/93 --- sources/Engine.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sources/Engine.ts b/sources/Engine.ts index e08bb1ee1..f9c105e25 100644 --- a/sources/Engine.ts +++ b/sources/Engine.ts @@ -7,6 +7,7 @@ import defaultConfig from '../config.js import * as corepackUtils from './corepackUtils'; import * as folderUtils from './folderUtils'; +import {fetchAsJson} from './httpUtils'; import * as semverUtils from './semverUtils'; import {Config, Descriptor, Locator} from './types'; import {SupportedPackageManagers, SupportedPackageManagerSet} from './types'; @@ -69,17 +70,16 @@ export class Engine { // Ignore errors; too bad } - if (typeof lastKnownGood !== `object` || lastKnownGood === null) - return definition.default; - - if (!Object.prototype.hasOwnProperty.call(lastKnownGood, packageManager)) - return definition.default; - - const override = (lastKnownGood as any)[packageManager]; - if (typeof override !== `string`) - return definition.default; + if (typeof lastKnownGood === `object` && lastKnownGood !== null && + Object.prototype.hasOwnProperty.call(lastKnownGood, packageManager)) { + const override = (lastKnownGood as any)[packageManager]; + if (typeof override === `string`) { + return override; + } + } - return override; + const latest = await fetchAsJson(`https://registry.npmjs.org/${packageManager}`); + return latest[`dist-tags`].latest; } async activatePackageManager(locator: Locator) {