fetchYarnDeps: account for more yarn.lock spec edge cases

* Ignore relative `file:` paths.
* Support github codeload URLs with `refs/tags/tag` in addition to just `tag`.
* Support https://github.com/owner/repo/archive/ref.tar.gz URLs for git download.
This commit is contained in:
Lily Foster 2023-03-27 14:10:32 -04:00
parent 4361baa782
commit e7cd275cd8
No known key found for this signature in database
GPG Key ID: 49340081E484C893

View File

@ -91,12 +91,21 @@ const isGitUrl = pattern => {
}
const downloadPkg = (pkg, verbose) => {
const [ name, spec ] = pkg.key.split('@', 2);
if (spec.startsWith('file:')) {
console.info(`ignoring relative file:path dependency "${spec}"`)
return
}
const [ url, hash ] = pkg.resolved.split('#')
if (verbose) console.log('downloading ' + url)
const fileName = urlToName(url)
if (url.startsWith('https://codeload.github.com/') && url.includes('/tar.gz/')) {
const s = url.split('/')
downloadGit(fileName, `https://github.com/${s[3]}/${s[4]}.git`, s[6])
return downloadGit(fileName, `https://github.com/${s[3]}/${s[4]}.git`, s[s.length-1])
} else if (url.startsWith('https://github.com/') && url.endsWith('.tar.gz')) {
const s = url.split('/')
return downloadGit(fileName, `https://github.com/${s[3]}/${s[4]}.git`, s[s.length-1].replace(/.tar.gz$/, ''))
} else if (isGitUrl(url)) {
return downloadGit(fileName, url.replace(/^git\+/, ''), hash)
} else if (url.startsWith('https://')) {