Skip to content

Conversation

@huchenlei
Copy link
Contributor

@huchenlei huchenlei commented Aug 1, 2025

Summary

  • Fixed pre-commit hook shebang to use #\!/usr/bin/env bash for better cross-platform compatibility
  • Simplified script by removing OS-specific logic since npx works on both Windows and Unix systems
  • Ensures the hook is executable

Problem

The pre-commit hook was failing with "command not found" errors due to:

  1. Missing proper shebang line
  2. Windows line endings (CRLF) causing shebang parsing issues
  3. Unnecessary OS detection logic

Sample error messages:

.husky/pre-commit: line 10: syntax error: unexpected end of file
husky - pre-commit script failed (code 2)

Solution

  • Use #\!/usr/bin/env bash shebang for cross-platform compatibility
  • Remove OS-specific branching since npx works universally
  • Ensure proper Unix line endings

Test plan

  • Verify pre-commit hook executes without errors on macOS
  • Test on Windows environment
  • Test on Linux environment

┆Issue is synchronized with this Notion page by Unito

@huchenlei huchenlei requested a review from a team as a code owner August 1, 2025 18:11
@huchenlei
Copy link
Contributor Author

Follow-up: Can someone test the PR on windows? I do not have a windows machine to test it right now.

@benceruleanlu
Copy link
Member

tested working on windows wsl2 (linux), and windows native

Windows Native
PS C:\Users\ben\Developer\ComfyUI_frontend> git commit -m "test"
✔ Preparing lint-staged...
⚠ Running tasks for staged files...
  ❯ lint-staged.config.js — 5 files
    ↓ ./**/*.js — no files
    ❯ ./**/*.{ts,tsx,vue,mts} — 2 files
      ✔ eslint --fix C:/Users/ben/Developer/ComfyUI_frontend/src/components/MenuHambu…  
      ✔ prettier --write C:/Users/ben/Developer/ComfyUI_frontend/src/components/MenuH…  
      ✖ vue-tsc --noEmit [FAILED]
↓ Skipped because of errors from tasks.
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ vue-tsc --noEmit:
src/components/MenuHamburger.vue(32,7): error TS6133: 'testString' is declared but its value is never read.
src/main.ts(73,7): error TS6133: 'unusedVar' is declared but its value is never read.
husky - pre-commit script failed (code 1)
PS C:\Users\ben\Developer\ComfyUI_frontend> git commit -m "test"
→ No staged files match any configured task.

⚠️  Warning: Found unused NEW i18n keys:

  - g.unusedTestKey

✨ Total unused new keys: 1

These keys were added but are not used anywhere in the codebase.
Consider using them or removing them in a future update.
[pr-4643 759abe99] test
 1 file changed, 1 insertion(+), 1 deletion(-)
PS C:\Users\ben\Developer\ComfyUI_frontend> 
WSl2
ben@DESKTOP-MBL3P6I:~/Developer/comfy-workspace-2/frontend-2$ git commit -m "test"
✔ Preparing lint-staged...
⚠ Running tasks for staged files...
  ❯ lint-staged.config.js — 3 files
    ↓ ./**/*.js — no files
    ❯ ./**/*.{ts,tsx,vue,mts} — 2 files
      ✔ eslint --fix /home/ben/Developer/comfy-workspace-2/frontend-2/src/compo…
      ✔ prettier --write /home/ben/Developer/comfy-workspace-2/frontend-2/src/c…
      ✖ vue-tsc --noEmit [FAILED]
↓ Skipped because of errors from tasks.
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ vue-tsc --noEmit:
src/components/MenuHamburger.vue(32,7): error TS6133: 'testString' is declared but its value is never read.
src/main.ts(73,7): error TS6133: 'unusedVar' is declared but its value is never read.
husky - pre-commit script failed (code 1)
ben@DESKTOP-MBL3P6I:~/Developer/comfy-workspace-2/frontend-2$ git commit -m "test"
→ No staged files match any configured task.

⚠️  Warning: Found unused NEW i18n keys:

  - g.unusedTestKey

✨ Total unused new keys: 1

These keys were added but are not used anywhere in the codebase.
Consider using them or removing them in a future update.
[pr-4643 0eccc6be] test
 1 file changed, 1 insertion(+), 1 deletion(-)

@benceruleanlu
Copy link
Member

I wonder if we need a .gitattributes to force standardized line endings

@christian-byrne
Copy link
Contributor

Thanks for testing

I wonder if we need a .gitattributes to force standardized line endings

Could make it select more files

# Force TS to LF to make the unixy scripts not break on Windows
*.ts text eol=lf
*.vue text eol=lf
*.js text eol=lf

@christian-byrne christian-byrne merged commit d779df5 into Comfy-Org:main Aug 1, 2025
15 checks passed
@huchenlei huchenlei deleted the fix_precommit branch August 1, 2025 23:50
Myestery pushed a commit to Myestery/ComfyUI_frontend that referenced this pull request Aug 2, 2025
@christian-byrne christian-byrne mentioned this pull request Aug 3, 2025
@webfiltered
Copy link
Contributor

Below issue is already fixed - no action required.

Just in case relevant for future searches: the npx.cmd workaround is still required on Windows. Not all git apps work the same way; repro by using GitHub Desktop to make a commit on Windows. Will fail due to npx resolving to the wrong thing.

Various workarounds exist. This one being repo-based meant it always worked for everyone (the lack of shebang and CRLF endings being unrelated).
https://developercommunity.visualstudio.com/t/NPX-not-available-in-git-pre-commit-hook/10564290?sort=newest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants