Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git-hooks.hooks.prettier.settings.binPath does not allow value ./node_modules/.bin/prettier #1670

Open
Vages opened this issue Jan 14, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@Vages
Copy link

Vages commented Jan 14, 2025

Describe the bug

Using git-hooks.hooks.prettier.settings.binPath = ./node_modules/.bin/prettier (as suggested in https://devenv.sh/reference/options/#git-hookshooksprettiersettingsbinpath) makes devenv shell crash with the error message error: path '/node_modules' does not exist in Git repository '/Users/myusername/repo'. Checking in node_modules makes the shell evaluate, but the pre-commit hook crashes on execution.

There may be technical reasons for this behavior, but I have not found an explanation in the documentation. If the error cannot be remedied, I would suggest adding a warning to the documentation for the option.

To reproduce

When node_modules is not checked in (the main case).

git clone https://github.com/Vages/prettier-binpath-mwe
cd prettier-binpath-mwe
devenv shell # should crash with output like https://gist.github.com/Vages/2c4d41d3865cb7a3810455c7388fc059

When node_modules is checked in:

git clone https://github.com/Vages/prettier-binpath-mwe
cd prettier-binpath-mwe
git checkout node-modules-checked-in
echo "  console.log(  'badly formatted')" > foo.js
git add foo.js
devenv shell git commit # should crash with output like https://gist.github.com/Vages/1f68bb6b14301fc6affaf177dee356fc

Version

$ devenv version
devenv 1.3.1 (aarch64-darwin)
@Vages Vages added the bug Something isn't working label Jan 14, 2025
@thenonameguy
Copy link
Contributor

Try with:

package = null;
entry = "./node_modules/.bin/prettier ";

This just templates the correct .pre-commit-config.yaml file without referencing it through Nix evaluation.

Vages added a commit to Vages/prettier-binpath-mwe that referenced this issue Jan 19, 2025
@Vages
Copy link
Author

Vages commented Jan 19, 2025

Took your tip, @thenonameguy (added a -w to the prettier command). Result on the entry-overridden-package-null branch.

Prettier now tries to parse any file – which is not what I would expect without modifying git-hooks.hooks.prettier.files or .types explicitly. See output below.

Thank you for your help so far, @thenonameguy. Even though there is still work to be done, this was a step in the right direction 😄

$ devenv test
• Overriding .devenv to .devenv.XVf8SKCgSupD
• Building tests ...
• Using Cachix: devenv
this derivation will be built:
  /nix/store/dslfrpj5pqg29qbp1bcn70pwax9na86g-devenv-test.drv
building '/nix/store/dslfrpj5pqg29qbp1bcn70pwax9na86g-devenv-test.drv'
✔ Building tests in 6.3s.
• Running tests ...
• Building shell ...
building '/nix/store/0cvp65cwq48xw5ssyc8lhs9figyxks8h-devenv-shell-env.drv'
Sourcing pytest-check-hook
Using pytestCheckPhase
✔ Building shell in 2.5s.
Running tasks     devenv:enterShell

Succeeded         devenv:git-hooks:install 27ms
Succeeded         devenv:enterShell        10ms
2 Succeeded                                39.03ms

• Setting up shell environment ...
Running tasks     devenv:enterShell
Succeeded         devenv:git-hooks:install 20ms
Succeeded         devenv:enterShell        10ms
2 Succeeded                                30.73ms

• Testing ...
Running tasks     devenv:enterTest
Failed            devenv:git-hooks:run     352ms
Dependency failed devenv:enterTest
1 Failed, 1 Dependency Failed              352.53ms

--- devenv:git-hooks:run failed with error: Task exited with status: exit status: 1
--- devenv:git-hooks:run stdout:
0000.01: prettier.................................................................Failed
0000.01: - hook id: prettier
0000.01: - exit code: 2
0000.01: - files were modified by this hook
0000.01:
0000.01: [error] No parser could be inferred for file "/Users/myuser/prettier-binpath-mwe/.envrc".
0000.01: index.js 18ms
0000.01: [error] No parser could be inferred for file "/Users/myuser/prettier-binpath-mwe/devenv.nix".
0000.01: package-lock.json 2ms (unchanged)
0000.01: [error] No parser could be inferred for file "/Users/myuser/prettier-binpath-mwe/devenv.lock".
0000.01: [error] No parser could be inferred for file "/Users/myuser/prettier-binpath-mwe/.gitignore".
0000.01: devenv.yaml 10ms (unchanged)
0000.01: package.json 14ms (unchanged)
0000.01:
--- devenv:git-hooks:run stderr:
---

✔ Running tests in 4.4s.
✖ Tests failed :(
Error:   × Tests failed

@thenonameguy
Copy link
Contributor

thenonameguy commented Jan 19, 2025 via email

@thenonameguy
Copy link
Contributor

Great, you are welcome! Adding 'types_or = ["json" "yaml"];' should solve the remaining problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants