about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorYureka <yuka@yuka.dev>2021-10-28 17:19:31 +0200
committerRaphael Megzari <raphael@megzari.com>2021-10-29 02:43:42 +0900
commit6c99b3d0b746e132fe6173e6dadc89fcc16f4d36 (patch)
tree2059c7c1229b2befc9b2eba8417d90232374c6e2 /pkgs/build-support
parente6123b607e321f18652b496c467db9b3535848af (diff)
prefetch-yarn-deps: support git:// dependencies
Diffstat (limited to 'pkgs/build-support')
-rwxr-xr-xpkgs/build-support/node/fetch-yarn-deps/index.js23
1 files changed, 17 insertions, 6 deletions
diff --git a/pkgs/build-support/node/fetch-yarn-deps/index.js b/pkgs/build-support/node/fetch-yarn-deps/index.js
index a9c5ab29cce56..81cf416c941a8 100755
--- a/pkgs/build-support/node/fetch-yarn-deps/index.js
+++ b/pkgs/build-support/node/fetch-yarn-deps/index.js
@@ -18,6 +18,20 @@ const exec = async (...args) => {
 	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) => {
 	return new Promise((resolve, reject) => {
 		https.get(url, (res) => {
@@ -61,18 +75,15 @@ const downloadGit = async (fileName, url, rev) => {
 const downloadPkg = (pkg, verbose) => {
 	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 fileName = path.basename(url)
 		const s = url.split('/')
 		downloadGit(fileName, `https://github.com/${s[3]}/${s[4]}.git`, s[6])
 	} 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)
+	} else if (url.startsWith('git:')) {
+		return downloadGit(fileName, url.replace(/^git\+/, ''), hash)
 	} else if (url.startsWith('git+')) {
-		const fileName = path.basename(url)
 		return downloadGit(fileName, url.replace(/^git\+/, ''), hash)
 	} else {
 		throw new Error('don\'t know how to download "' + url + '"')