Whether a hook's shebang names a shell (a hook with none runs under sh).
(content: string)
| 196 | |
| 197 | /** Whether a hook's shebang names a shell (a hook with none runs under sh). */ |
| 198 | function isShellHook(content: string): boolean { |
| 199 | const first = content.split('\n', 1)[0]!.trim(); |
| 200 | if (!first.startsWith('#!')) return true; |
| 201 | const words = first.slice(2).trim().split(/\s+/); |
| 202 | let program = path.posix.basename(words[0] ?? ''); |
| 203 | if (program === 'env') program = path.posix.basename(words.slice(1).find((w) => !w.startsWith('-')) ?? ''); |
| 204 | return SHELL_INTERPRETERS.has(program); |
| 205 | } |
| 206 | |
| 207 | /** Whether a hook body is just a shebang / blank lines (i.e. only ever ours). */ |
| 208 | function isEffectivelyEmpty(content: string): boolean { |
no test coverage detected