diff --git a/mock-registry/lib/index.js b/mock-registry/lib/index.js index a89c8b72b7d58..176c5635fa1d1 100644 --- a/mock-registry/lib/index.js +++ b/mock-registry/lib/index.js @@ -36,7 +36,7 @@ class MockRegistry { // mocked with a 404, 500, etc. // XXX: this is opt-in currently because it breaks some existing CLI // tests. We should work towards making this the default for all tests. - t.fail(`Unmatched request: ${JSON.stringify(req.options, null, 2)}`) + t.fail(`Unmatched request: ${JSON.stringify(req, null, 2)}`) } if (debug) { console.error('NO MATCH', t.name, req.options ? req.options : req.path) diff --git a/workspaces/libnpmexec/lib/index.js b/workspaces/libnpmexec/lib/index.js index 719f81ec11d57..b7aa43588c0fd 100644 --- a/workspaces/libnpmexec/lib/index.js +++ b/workspaces/libnpmexec/lib/index.js @@ -35,12 +35,15 @@ const getManifest = async (spec, flatOptions) => { // Returns the required manifest if the spec is missing from the tree // Returns the found node if it is in the tree -const missingFromTree = async ({ spec, tree, flatOptions }) => { - if (spec.registry && spec.type !== 'tag') { +const missingFromTree = async ({ spec, tree, flatOptions, isNpxTree }) => { + // If asking for a spec by name only (spec.raw === spec.name): + // - In local or global mode go with anything in the tree that matches + // - If looking in the npx cache check if a newer version is available + const npxByNameOnly = isNpxTree && spec.name === spec.raw + if (spec.registry && spec.type !== 'tag' && !npxByNameOnly) { // registry spec that is not a specific tag. const nodesBySpec = tree.inventory.query('packageName', spec.name) for (const node of nodesBySpec) { - // package requested by name only (or name@*) if (spec.rawSpec === '*') { return { node } } @@ -56,8 +59,8 @@ const missingFromTree = async ({ spec, tree, flatOptions }) => { const manifest = await getManifest(spec, flatOptions) return { manifest } } else { - // non-registry spec, or a specific tag. Look up manifest and check - // resolved to see if it's in the tree. + // non-registry spec, or a specific tag, or name only in npx tree. Look up + // manifest and check resolved to see if it's in the tree. const manifest = await getManifest(spec, flatOptions) if (spec.type === 'directory') { return { manifest } @@ -224,7 +227,12 @@ const exec = async (opts) => { }) const npxTree = await npxArb.loadActual() await Promise.all(needInstall.map(async ({ spec }) => { - const { manifest } = await missingFromTree({ spec, tree: npxTree, flatOptions }) + const { manifest } = await missingFromTree({ + spec, + tree: npxTree, + flatOptions, + isNpxTree: true, + }) if (manifest) { // Manifest is not in npxCache, we need to install it there if (!spec.registry) {