yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.37k stars 2.72k forks source link

yarn version failing on cygwin #8970

Open jason-crawford-xio opened 11 months ago

jason-crawford-xio commented 11 months ago

On yarn version 1.22.19 On cygwin vintage 2023-07

   yarn version --new-version patch

results in

yarn version v1.22.19
info Current version: 0.2.18
info New version: 0.2.19
error Couldn't find the binary git
info Visit https://yarnpkg.com/en/docs/cli/version for documentation about this command.

The root of the problem is not that yarn can not find git. The root of the problem appears to be

yarn assigns that to gitRoot and then calls

   path.relative(gitRoot, pkgLoc)

where pkgLoc is expressed in DOS/Window's native syntax, ex. C:\Users\nnd15\work\slogger\package.json. The path returned by path.relative() is understandably nonsensical and this eventually results in the above error reported to the user.

This post suggests that this is fixed in yarn 2.x. But some of us are not able to upgrade because of issues like np not yet working with yarn 2.x.

My current work-around is to update a few lines in cli.js which might be found in a location like: c:\Users\nnd15\AppData\Roaming\npm\node_modules\yarn\lib\cli.js

          var gitRoot = (yield (0, (_gitSpawn || _load_gitSpawn()).spawn)(['rev-parse', '--show-toplevel'], { cwd: config.cwd })).trim();
          if (true) { //jasonnet cygwin fix BEGIN
            //   gitRoot is sometimes expressed in cygwin form and here we need it in Windows form
            let regex = /^[/]cygdrive[/]c[/]Users[/]/
            gitRoot = gitRoot.replace(regex,"C:\\Users\\")
          } //jasonnet cygwin fix END

I have not yet scanned the source code for other locations where this same change might be beneficial.