Skip to content

Commit

Permalink
fix: account for npx package-name with no spec
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Apr 19, 2023
1 parent 82c1582 commit 33dc428
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mock-registry/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 14 additions & 6 deletions workspaces/libnpmexec/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand All @@ -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 }
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 33dc428

Please sign in to comment.