nix-community / yarn2nix

Generate nix expressions from a yarn.lock file [maintainer=???]
GNU General Public License v3.0
123 stars 61 forks source link

git deps and fixup_yarn_lock.js #159

Open ghost opened 3 years ago

ghost commented 3 years ago

For all lockfile entries with a 'resolved' containing a # character, they are changed by fixup_yarn_lock.js to contain a reference that matches the file name in the offline cache, for example:

  resolved "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"

is changed to

  resolved "https___registry.npmjs.org_test_exclude___test_exclude_6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"

However, some dependencies are not matched by the regex in fixup_yarn_lock.js and thus are not changed to refer to the correct filename:

  resolved "https://codeload.github.com/atlassian/tether/tar.gz/bf85430889b5231fbe5b383416cce6281225bf06"

Note how this does not contain a # character. Calling buildYarnPackage will complain about not being able to fetch the dependency, because it can not find a corresponding file in the offline cache.

ghost commented 3 years ago

an attempt to solve this:


diff --git a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js
index 86e92f85208..f77b60c985b 100755
--- a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js
+++ b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js
@@ -34,7 +34,16 @@ readFile

       result.push(`  resolved "${fileName}#${shaOrRev}"`)
     } else {
-      result.push(line)
+      const arr2 = line.match(/^ {2}resolved "(.+)\/([^\/"]+)"$/)
+      if (arr2 !== null) {
+        const [_, url, shaOrRev] = arr2
+
+        const fileName = urlToName(url + '/' + shaOrRev)
+
+        result.push(`  resolved "${fileName}"`)
+      } else {
+        result.push(line)
+      }
     }
   })
   .on('close', () => {