Skip to content

Commit 8495be6

Browse files
authored
Enhance non-interactive-env hook with additional env vars and command patterns (#172)
- Add npm_config_yes, PIP_NO_INPUT, YARN_ENABLE_IMMUTABLE_INSTALLS env vars - Add SHELL_COMMAND_PATTERNS documentation for common command patterns - Document good/bad patterns for npm, apt, pip, git, system commands - List banned commands that will always hang (editors, pagers, REPLs) - Include workarounds for scripts requiring input (yes pipe, heredoc)
1 parent a65c3b0 commit 8495be6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/hooks/non-interactive-env/constants.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,56 @@ export const NON_INTERACTIVE_ENV: Record<string, string> = {
1414
// Block pagers
1515
GIT_PAGER: "cat",
1616
PAGER: "cat",
17+
// NPM non-interactive
18+
npm_config_yes: "true",
19+
// Pip non-interactive
20+
PIP_NO_INPUT: "1",
21+
// Yarn non-interactive
22+
YARN_ENABLE_IMMUTABLE_INSTALLS: "false",
1723
}
24+
25+
/**
26+
* Shell command guidance for non-interactive environments.
27+
* These patterns should be followed to avoid hanging on user input.
28+
*/
29+
export const SHELL_COMMAND_PATTERNS = {
30+
// Package managers - always use non-interactive flags
31+
npm: {
32+
bad: ["npm init", "npm install (prompts)"],
33+
good: ["npm init -y", "npm install --yes"],
34+
},
35+
apt: {
36+
bad: ["apt-get install pkg"],
37+
good: ["apt-get install -y pkg", "DEBIAN_FRONTEND=noninteractive apt-get install pkg"],
38+
},
39+
pip: {
40+
bad: ["pip install pkg (with prompts)"],
41+
good: ["pip install --no-input pkg", "PIP_NO_INPUT=1 pip install pkg"],
42+
},
43+
// Git operations - always provide messages/flags
44+
git: {
45+
bad: ["git commit", "git merge branch", "git add -p", "git rebase -i"],
46+
good: ["git commit -m 'msg'", "git merge --no-edit branch", "git add .", "git rebase --no-edit"],
47+
},
48+
// System commands - force flags
49+
system: {
50+
bad: ["rm file (prompts)", "cp a b (prompts)", "ssh host"],
51+
good: ["rm -f file", "cp -f a b", "ssh -o BatchMode=yes host", "unzip -o file.zip"],
52+
},
53+
// Banned commands - will always hang
54+
banned: [
55+
"vim", "nano", "vi", "emacs", // Editors
56+
"less", "more", "man", // Pagers
57+
"python (REPL)", "node (REPL)", // REPLs without -c/-e
58+
"git add -p", "git rebase -i", // Interactive git modes
59+
],
60+
// Workarounds for scripts that require input
61+
workarounds: {
62+
yesPipe: "yes | ./script.sh",
63+
heredoc: `./script.sh <<EOF
64+
option1
65+
option2
66+
EOF`,
67+
expectAlternative: "Use environment variables or config files instead of expect",
68+
},
69+
} as const

0 commit comments

Comments
 (0)