| 150 | const arg = npa(spec, path) |
| 151 | |
| 152 | const retrievePackageMetadata = () => { |
| 153 | if (arg.type === 'directory') { |
| 154 | if (tree.path === arg.fetchSpec) { |
| 155 | // matches cwd, e.g: npm fund . |
| 156 | return tree.package |
| 157 | } else { |
| 158 | // matches any file path within current arborist inventory |
| 159 | for (const item of tree.inventory.values()) { |
| 160 | if (item.path === arg.fetchSpec) { |
| 161 | return item.package |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | } else { |
| 166 | // tries to retrieve a package from arborist inventory by matching resulted package name from the provided spec |
| 167 | const [item] = [...tree.inventory.query('name', arg.name)] |
| 168 | .filter(i => semver.valid(i.package.version)) |
| 169 | .sort((a, b) => semver.rcompare(a.package.version, b.package.version)) |
| 170 | |
| 171 | if (item) { |
| 172 | return item.package |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | const { funding } = |
| 178 | retrievePackageMetadata() || |