toplenboren / simple-git-hooks

A simple git hooks manager for small projects
MIT License
1.32k stars 43 forks source link

Issue with yarn2 #30

Closed igorkamyshev closed 3 years ago

igorkamyshev commented 3 years ago

Hello! Thanks for the lib. I tried migrate from husky4 to this solution and found a problem.

When I try to install this lib:

yarn add -D simple-git-hooks

I see in console the following message:

➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 0s 336ms
➤ YN0000: ┌ Link step
➤ YN0007: │ simple-git-hooks@npm:2.0.2 must be built because it never did before or the last one failed
➤ YN0009: │ simple-git-hooks@npm:2.0.2 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/15/zr9tfbrs1z9_5w9yzszys8vh0000gn/T/xfs-e4784d06/build.log)
➤ YN0009: │ simple-git-hooks@npm:2.0.2 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/15/zr9tfbrs1z9_5w9yzszys8vh0000gn/T/xfs-e4784d06/build.log)
➤ YN0000: └ Completed in 0s 391ms
➤ YN0000: Failed with errors in 0s 890ms

This is complete log:

# This file contains the result of Yarn building a package (simple-git-hooks@npm:2.0.2)
# Script name: postinstall

internal/fs/utils.js:307
    throw err;
    ^

Error: ENOENT: no such file or directory, stat '/Users/igorkamyshev/Code/Solid-Soda/scripts/.yarn/unplugged/simple-git-hooks-npm-2.0.2-48676c6cda/package.json'
    at Object.statSync (fs.js:1086:3)
    at NodeFS.statSync (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:7751:24)
    at makeCallSync.subPath.subPath (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:10325:26)
    at ZipOpenFS.makeCallSync (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:10861:26)
    at ZipOpenFS.statSync (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:10324:17)
    at VirtualFS.statSync (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:8120:24)
    at PosixFS.statSync (/Users/igorkamyshev/Code/Solid-Soda/scripts/.pnp.js:8120:24)
    at _getPackageJson (/Users/igorkamyshev/Code/Solid-Soda/scripts/.yarn/unplugged/simple-git-hooks-npm-2.0.2-48676c6cda/node_modules/simple-git-hooks/simple-git-hooks.js:134:13)
    at checkSimpleGitHooksInDependencies (/Users/igorkamyshev/Code/Solid-Soda/scripts/.yarn/unplugged/simple-git-hooks-npm-2.0.2-48676c6cda/node_modules/simple-git-hooks/simple-git-hooks.js:75:34)
    at postinstall (/Users/igorkamyshev/Code/Solid-Soda/scripts/.yarn/unplugged/simple-git-hooks-npm-2.0.2-48676c6cda/node_modules/simple-git-hooks/postinstall.js:15:9) {
  errno: -2,
  syscall: 'stat',
  code: 'ENOENT',
  path: '/Users/igorkamyshev/Code/Solid-Soda/scripts/.yarn/unplugged/simple-git-hooks-npm-2.0.2-48676c6cda/package.json'
}

I use yarn version 2.4.1.

Could you help me to find a solution, please?

toplenboren commented 3 years ago

whoa, gonna try to replicate and find out how to fix this issue

igorkamyshev commented 3 years ago

I try it in several repos with yarn2 and pnp linker and it reproduces every time 🤗

toplenboren commented 3 years ago

Hey! Thank you for the issue, was able to reproduce with yarn2

Thing is, yarn2 stores dependencies differently then npm or even yarn1, but in the package we rely on npm way of storing packages. node_modules/<package> and not .yarn/unplugged/<package> that's why it fails :(

I wasn't able to research this problem deep enough, but was able to create and release a stab. Could you check out @2.0.3 version? It fixed the problem for me :)

C:\Users\toplenboren\web\testy-thingy-project>yarn set version berry
Resolving berry to a url...
Downloading https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js...
Saving it into C:\Users\toplenboren\WebstormProjects\untitled\.yarn\releases\yarn-berry.cjs...
Updating C:\Users\toplenboren\WebstormProjects\untitled/.yarnrc.yml...
Done!

C:\Users\toplenboren\web\testy-thingy-project>yarn
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 1s 81ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ help@npm:3.0.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ simple-git-hooks@npm:2.0.3 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0031: │ One or more node_modules have been detected and will be removed. This operation may take some time.
➤ YN0007: │ simple-git-hooks@npm:2.0.3 must be built because it never did before or the last one failed
➤ YN0000: └ Completed in 0s 659ms
➤ YN0000: Done with warnings in 1s 897ms

C:\Users\toplenboren\web\testy-thingy-project>yarn dlx simple-git-hooks
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0007: │ simple-git-hooks@npm:2.0.3 must be built because it never did before or the last one failed
➤ YN0000: └ Completed in 0s 541ms
➤ YN0000: Done in 0s 612ms

[INFO] Successfully set the pre-push with command: exit 2
[INFO] Successfully set the pre-commit with command: exit 2
[INFO] Successfully set all git hooks

Also please note that I used yarn dlx simple-git-hooks to update the git hooks, instead of npx simple-git-hooks

igorkamyshev commented 3 years ago

Yes, this fix works correct. Thanks!