Commit a24084c
authored
fix: upgrade cross-spawn (ReDoS), harden hook install and spawn handling (#169)
* fix: upgrade cross-spawn (ReDoS), harden hook install and spawn handling
- Bump cross-spawn to ^7.0.5 and which to ^4; drop unused spawn-sync.
- Fix spawnSync result checks (use status/signal/error, not .code).
- Treat non-zero / null close codes from npm run spawns reliably.
- Install hook via absolute path to package hook script for Yarn PnP; chmod 0755.
- Hook: cd to git root before require.resolve; use exec for node.
- Install: guard gitdir parse; avoid fs.existsSync(null) on missing .git.
- Dev: mocha 10, assume 2, nyc; engines node>=16; stub tty in tests.
- Version 1.2.3; add package-lock.json; ignore .nyc_output.
Addresses GH-167, GH-160, GH-157; mitigates GH-166 (cwd / exit handling).
Made-with: Cursor
* chore: fold in fixes from open PRs (#127, #148, #112)
Addresses long-standing open PRs whose intent fits the cross-spawn /
hook-hardening cleanup:
* #127 - install.js: "backuped" -> "backed up".
* #148 - magit workaround: emit `unset GIT_LITERAL_PATHSPECS` in the
generated `.git/hooks/pre-commit` wrapper, and also at the top of
the package's `hook` script for defense-in-depth, so hooks invoked
from emacs/magit behave the same as on the command line.
* #112 - resilience for missing pre-commit package: when a user
switches to a branch without `node_modules`, the generated wrapper
now exits 0 instead of failing the commit, and the `hook` script
detects an unresolvable `pre-commit` package and skips with a
friendly warning instead of throwing a Node module-not-found stack.
Made-with: Cursor
* fix(install): handle submodules and tighten engines.node
* getGitFolderPath previously recursed past a `.git` *file*, which made
the existing submodule-aware gitdir parsing block unreachable -- in a
submodule we silently walked up to the super-project's `.git` dir and
installed the hook there instead. Return the `.git` path whether it is
a file or directory.
* Resolve `gitdir:` pointers against the directory containing the `.git`
file (path.dirname(git)) instead of the package root, since git stores
those paths relative to the file. Fixes submodules whose `.git` file
is not at the package root, and linked worktrees.
* Tighten engines.node to >=16.13.0 to match `which@4`'s minimum
(`^16.13.0 || >=18.0.0`); the previous `>=16` allowed Node 16.0-16.12
where `which@4` will warn/fail at install time.
Addresses copilot-pull-request-reviewer feedback on PR #169.
Supersedes the submodule-install half of #75.
Made-with: Cursor
* chore: regenerate package-lock
* chore(release): bump to 2.0.0
This release contains breaking changes that warrant a major bump:
* Drops support for Node < 16.13 by introducing
`engines.node: ">=16.13.0"` (matches `which@4`'s minimum). Previous
releases declared no engine, so anything old enough to run them is
now incompatible.
* Production deps make jumps that raise the floor and change result
shapes: `cross-spawn` ^5 -> ^7 (`spawnSync` returns `status`, not
`code`), `which` 1.2.x -> ^4. The runtime `spawn-sync` dep is dropped
in favor of `cross-spawn.spawnSync`.
* The generated `.git/hooks/pre-commit` wrapper format is rewritten
(single `exec bash <abs-hook> "\$@"` instead of the previous inline
bash). Anyone parsing or scripting against the previous wrapper
shape will see a different file.
* Hook file mode tightened from 0777 to 0755 (CIS 6.1.10).
* Submodule install location now resolves correctly to
`<super>/.git/modules/<sub>/hooks` (previously the unreachable
gitdir-parsing block silently caused submodule hooks to land in the
super-project).
Minor / patch additions in the same release (carried by the same PR):
* Magit fix: generated wrapper and hook script `unset
GIT_LITERAL_PATHSPECS` so hooks behave the same way under emacs.
* Resilient missing-package handling: a removed `pre-commit` (e.g.
branch-switch without `node_modules`) skips with a friendly warning
instead of breaking the commit.
* Internal: harden `index.js` spawn result checks; guard install-time
gitdir parsing against null matches; spelling fix
("backuped" -> "backed up"); drop `istanbul` for `nyc`; modernize
`mocha` and `assume` test deps.
Made-with: Cursor1 parent a84bdc8 commit a24084c
7 files changed
Lines changed: 2978 additions & 58 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
3 | 10 | | |
4 | 11 | | |
5 | 12 | | |
| |||
37 | 44 | | |
38 | 45 | | |
39 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
40 | 70 | | |
41 | 71 | | |
42 | 72 | | |
43 | 73 | | |
44 | 74 | | |
45 | | - | |
| 75 | + | |
46 | 76 | | |
47 | 77 | | |
48 | 78 | | |
49 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
50 | 84 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
3 | 14 | | |
4 | 15 | | |
5 | 16 | | |
| |||
173 | 184 | | |
174 | 185 | | |
175 | 186 | | |
176 | | - | |
177 | | - | |
| 187 | + | |
| 188 | + | |
178 | 189 | | |
179 | 190 | | |
180 | 191 | | |
| |||
229 | 240 | | |
230 | 241 | | |
231 | 242 | | |
232 | | - | |
233 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
234 | 248 | | |
235 | 249 | | |
236 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
13 | 21 | | |
14 | 22 | | |
15 | 23 | | |
| |||
19 | 27 | | |
20 | 28 | | |
21 | 29 | | |
22 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
23 | 36 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
35 | 45 | | |
36 | | - | |
37 | | - | |
38 | 46 | | |
39 | 47 | | |
40 | 48 | | |
41 | | - | |
42 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
43 | 55 | | |
44 | 56 | | |
45 | 57 | | |
46 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
47 | 62 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
57 | 74 | | |
58 | 75 | | |
59 | 76 | | |
| |||
81 | 98 | | |
82 | 99 | | |
83 | 100 | | |
84 | | - | |
| 101 | + | |
85 | 102 | | |
86 | 103 | | |
87 | 104 | | |
| |||
92 | 109 | | |
93 | 110 | | |
94 | 111 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
102 | 119 | | |
103 | 120 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
109 | 140 | | |
110 | 141 | | |
111 | 142 | | |
| |||
121 | 152 | | |
122 | 153 | | |
123 | 154 | | |
124 | | - | |
| 155 | + | |
125 | 156 | | |
126 | 157 | | |
127 | | - | |
| 158 | + | |
128 | 159 | | |
129 | 160 | | |
130 | 161 | | |
0 commit comments