@@ -35,12 +35,15 @@ const getManifest = async (spec, flatOptions) => {
3535
3636// Returns the required manifest if the spec is missing from the tree
3737// Returns the found node if it is in the tree
38- const missingFromTree = async ( { spec, tree, flatOptions } ) => {
39- if ( spec . registry && spec . type !== 'tag' ) {
38+ const missingFromTree = async ( { spec, tree, flatOptions, isNpxTree } ) => {
39+ // If asking for a spec by name only (spec.raw === spec.name):
40+ // - In local or global mode go with anything in the tree that matches
41+ // - If looking in the npx cache check if a newer version is available
42+ const npxByNameOnly = isNpxTree && spec . name === spec . raw
43+ if ( spec . registry && spec . type !== 'tag' && ! npxByNameOnly ) {
4044 // registry spec that is not a specific tag.
4145 const nodesBySpec = tree . inventory . query ( 'packageName' , spec . name )
4246 for ( const node of nodesBySpec ) {
43- // package requested by name only (or name@*)
4447 if ( spec . rawSpec === '*' ) {
4548 return { node }
4649 }
@@ -56,8 +59,8 @@ const missingFromTree = async ({ spec, tree, flatOptions }) => {
5659 const manifest = await getManifest ( spec , flatOptions )
5760 return { manifest }
5861 } else {
59- // non-registry spec, or a specific tag. Look up manifest and check
60- // resolved to see if it's in the tree.
62+ // non-registry spec, or a specific tag, or name only in npx tree. Look up
63+ // manifest and check resolved to see if it's in the tree.
6164 const manifest = await getManifest ( spec , flatOptions )
6265 if ( spec . type === 'directory' ) {
6366 return { manifest }
@@ -224,7 +227,12 @@ const exec = async (opts) => {
224227 } )
225228 const npxTree = await npxArb . loadActual ( )
226229 await Promise . all ( needInstall . map ( async ( { spec } ) => {
227- const { manifest } = await missingFromTree ( { spec, tree : npxTree , flatOptions } )
230+ const { manifest } = await missingFromTree ( {
231+ spec,
232+ tree : npxTree ,
233+ flatOptions,
234+ isNpxTree : true ,
235+ } )
228236 if ( manifest ) {
229237 // Manifest is not in npxCache, we need to install it there
230238 if ( ! spec . registry ) {
0 commit comments