Skip to content

Commit

Permalink
fix(exec): use latest version when possible
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
wraithgar committed Feb 1, 2021
1 parent 7b1a539 commit 7ddbf2c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}))

Expand All @@ -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))

Expand Down

0 comments on commit 7ddbf2c

Please sign in to comment.