Function
addDefaultVersions
(
paths: string[],
name: string,
version: string,
)
Source from the content-addressed store, hash-verified
| 2 | * Find NPM paths and resolve them to full URLs with the same package version as in this library. |
| 3 | */ |
| 4 | export function addDefaultVersions( |
| 5 | paths: string[], |
| 6 | name: string, |
| 7 | version: string, |
| 8 | ) { |
| 9 | return paths.map((path) => { |
| 10 | if (typeof path === 'string' && !path.includes('://')) { |
| 11 | if (!path.startsWith('npm:')) { |
| 12 | path = `npm:${path}`; |
| 13 | } |
| 14 | const prefixLength = 4 + name.length; |
| 15 | if (path.startsWith(`npm:${name}/`)) { |
| 16 | path = `${path.slice(0, prefixLength)}@${version}${path.slice( |
| 17 | prefixLength, |
| 18 | )}`; |
| 19 | } |
| 20 | } |
| 21 | return path; |
| 22 | }); |
| 23 | } |
Tested by
no test coverage detected