| 83 | } |
| 84 | |
| 85 | getNodes (tree, arg) { |
| 86 | // if it's just a name, return packages by that name |
| 87 | const { validForOldPackages: valid } = validName(arg) |
| 88 | if (valid) { |
| 89 | return tree.inventory.query('packageName', arg) |
| 90 | } |
| 91 | |
| 92 | // if it's a location, get that node |
| 93 | const maybeLoc = arg.replace(/\\/g, '/').replace(/(?<!\/)\/+$/, '') |
| 94 | const nodeByLoc = tree.inventory.get(maybeLoc) |
| 95 | if (nodeByLoc) { |
| 96 | return [nodeByLoc] |
| 97 | } |
| 98 | |
| 99 | // maybe a path to a node_modules folder |
| 100 | const maybePath = relative(this.npm.prefix, resolve(maybeLoc)) |
| 101 | .replace(/\\/g, '/').replace(/(?<!\/)\/+$/, '') |
| 102 | const nodeByPath = tree.inventory.get(maybePath) |
| 103 | if (nodeByPath) { |
| 104 | return [nodeByPath] |
| 105 | } |
| 106 | |
| 107 | // otherwise, try to select all matching nodes |
| 108 | try { |
| 109 | return this.getNodesByVersion(tree, arg) |
| 110 | } catch { |
| 111 | return [] |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | getNodesByVersion (tree, arg) { |
| 116 | const spec = npa(arg, this.npm.prefix) |