mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-09-23 13:48:21 +03:00
prefetch-yarn-deps: support git:// dependencies
This commit is contained in:
parent
e6123b607e
commit
6c99b3d0b7
@ -18,6 +18,20 @@ const exec = async (...args) => {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This has to match the logic in pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/urlToName.js
|
||||||
|
// so that fixup_yarn_lock produces the same paths
|
||||||
|
const urlToName = url => {
|
||||||
|
const isCodeloadGitTarballUrl = url.startsWith('https://codeload.github.com/') && url.includes('/tar.gz/')
|
||||||
|
|
||||||
|
if (url.startsWith('git+') || isCodeloadGitTarballUrl) {
|
||||||
|
return path.basename(url)
|
||||||
|
} else {
|
||||||
|
return url
|
||||||
|
.replace(/https:\/\/(.)*(.com)\//g, '') // prevents having long directory names
|
||||||
|
.replace(/[@/%:-]/g, '_') // replace @ and : and - and % characters with underscore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const downloadFileHttps = (fileName, url, expectedHash) => {
|
const downloadFileHttps = (fileName, url, expectedHash) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
https.get(url, (res) => {
|
https.get(url, (res) => {
|
||||||
@ -61,18 +75,15 @@ const downloadGit = async (fileName, url, rev) => {
|
|||||||
const downloadPkg = (pkg, verbose) => {
|
const downloadPkg = (pkg, verbose) => {
|
||||||
const [ url, hash ] = pkg.resolved.split('#')
|
const [ url, hash ] = pkg.resolved.split('#')
|
||||||
if (verbose) console.log('downloading ' + url)
|
if (verbose) console.log('downloading ' + url)
|
||||||
|
const fileName = urlToName(url)
|
||||||
if (url.startsWith('https://codeload.github.com/') && url.includes('/tar.gz/')) {
|
if (url.startsWith('https://codeload.github.com/') && url.includes('/tar.gz/')) {
|
||||||
const fileName = path.basename(url)
|
|
||||||
const s = url.split('/')
|
const s = url.split('/')
|
||||||
downloadGit(fileName, `https://github.com/${s[3]}/${s[4]}.git`, s[6])
|
downloadGit(fileName, `https://github.com/${s[3]}/${s[4]}.git`, s[6])
|
||||||
} else if (url.startsWith('https://')) {
|
} else if (url.startsWith('https://')) {
|
||||||
const fileName = url
|
|
||||||
.replace(/https:\/\/(.)*(.com)\//g, '') // prevents having long directory names
|
|
||||||
.replace(/[@/%:-]/g, '_') // replace @ and : and - and % characters with underscore
|
|
||||||
|
|
||||||
return downloadFileHttps(fileName, url, hash)
|
return downloadFileHttps(fileName, url, hash)
|
||||||
|
} else if (url.startsWith('git:')) {
|
||||||
|
return downloadGit(fileName, url.replace(/^git\+/, ''), hash)
|
||||||
} else if (url.startsWith('git+')) {
|
} else if (url.startsWith('git+')) {
|
||||||
const fileName = path.basename(url)
|
|
||||||
return downloadGit(fileName, url.replace(/^git\+/, ''), hash)
|
return downloadGit(fileName, url.replace(/^git\+/, ''), hash)
|
||||||
} else {
|
} else {
|
||||||
throw new Error('don\'t know how to download "' + url + '"')
|
throw new Error('don\'t know how to download "' + url + '"')
|
||||||
|
Loading…
Reference in New Issue
Block a user