From 37613e4e686e4891210acaabc9c23f41456eda3f Mon Sep 17 00:00:00 2001 From: Gar Date: Mon, 1 Feb 2021 13:40:44 -0800 Subject: [PATCH] fix(exec): use latest version when possible pull latest packument when getting info about package to run, also install newer version if one is available and user has not specified a version (i.e. is defaulting to @latest) PR-URL: https://github.com/npm/cli/pull/2592 Credit: @wraithgar Closes: #2395 Closes: #2329 Reviewed-by: @darcyclarke --- lib/exec.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/exec.js b/lib/exec.js index d36dd87cfb971..e90ec0866e4dd 100644 --- a/lib/exec.js +++ b/lib/exec.js @@ -169,8 +169,12 @@ const exec = async args => { return await readPackageJson(pj) } catch (er) {} } + // Force preferOnline to true so we are making sure to pull in the latest + // This is especially useful if the user didn't give us a version, and + // they expect to be running @latest return await pacote.manifest(p, { ...npm.flatOptions, + preferOnline: true, }) })) @@ -193,9 +197,13 @@ const exec = async args => { const arb = new Arborist({ ...npm.flatOptions, path: installDir }) const tree = await arb.loadActual() - // any that don't match the manifest we have, install them - // add installDir/node_modules/.bin to pathArr - const add = manis.filter(mani => manifestMissing(tree, mani)) + // at this point, we have to ensure that we get the exact same + // version, because it's something that has only ever been installed + // by npm exec in the cache install directory + const add = manis.filter(mani => manifestMissing(tree, { + ...mani, + _from: `${mani.name}@${mani.version}`, + })) .map(mani => mani._from) .sort((a, b) => a.localeCompare(b))