Skip to content

Commit 110863e

Browse files
brianstrauchclaude
andauthored
Fix pre-push hook when no terminal is attached (#475)
* Fix pre-push hook when no terminal is attached Pushing from non-interactive environments (Claude Code, IDE integrations, CI) failed for two reasons: - The hook's `exec < /dev/tty` errors out when no TTY exists. Only redirect stdin when /dev/tty is actually readable. - Git feeds the pre-push hook its ref list on stdin, so without the redirect, copy-shared-files' confirmation prompt read a ref line as the answer and aborted the push. Only prompt when stdin is a terminal; otherwise proceed with the default. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Move pnpm settings from .npmrc to pnpm-workspace.yaml The root .npmrc contained only pnpm-specific workspace settings, which npm doesn't understand, so every `npm run` (including the pre-push hook) printed "Unknown project config" warnings. pnpm 10 reads its settings from pnpm-workspace.yaml, which npm never touches. No resolution change: `pnpm install --lockfile-only` leaves pnpm-lock.yaml untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent fb8de90 commit 110863e

4 files changed

Lines changed: 29 additions & 18 deletions

File tree

.husky/pre-push

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
exec < /dev/tty
4+
# Attach the terminal so copy-shared-files can prompt, but skip when there is
5+
# no TTY (Claude Code, IDE integrations, CI).
6+
if sh -c ': < /dev/tty' 2> /dev/null; then
7+
exec < /dev/tty
8+
fi
59
npm run copy-shared-files

.npmrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

.scripts/copy-shared-files.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,16 @@ if (numSharedFilesChanged === 0 && !hasNewSamples) {
146146

147147
await $`git add ${'./.scripts/list-of-samples.json'}`;
148148

149-
let [answer] = await question(
150-
`Running pre-commit hook.
149+
let answer;
150+
// Only prompt when stdin is a terminal — in non-interactive runs (Claude Code, CI,
151+
// git hooks where stdin carries ref data), proceed with the default.
152+
if (process.stdin.isTTY) {
153+
[answer] = await question(
154+
`Running pre-commit hook.
151155
This will overwrite changes made to most config files in samples (like ${chalk.bold('hello-world/tsconfig.json')}).
152156
Proceed? [Y/n] `
153-
);
157+
);
158+
}
154159

155160
if ((answer ?? 'y').toUpperCase() !== 'Y') {
156161
console.log(`To change config files, edit them in the ${chalk.bold('.shared/')} directory.\nAborting commit.`);

pnpm-workspace.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ packages:
1010
- 'food-delivery/apps/*'
1111
- 'food-delivery/packages/*'
1212
- 'polling/*'
13+
14+
linkWorkspacePackages: true
15+
sharedWorkspaceLockfile: true
16+
hoist: false
17+
18+
# By default, PNPM hoists eslint and prettier to the workspace root, but that may causes issues
19+
# with this workspace, as some samples have completely different versions of these packages, or
20+
# depends on incompatible plugins.
21+
#
22+
# The monorepo sample uses postcss with an external configuration file that refers to plugins by
23+
# their package name, rather than passing objects. That doesn't work with PNPM's strict node_modules
24+
# structure. To work around this, hoist all postcss-* packages.
25+
# FIXME: Can't we do something equivalent at the project-level instead?
26+
publicHoistPattern:
27+
- postcss-*
28+
1329
allowBuilds:
1430
'@nestjs/core': true
1531
'@swc/core': true

0 commit comments

Comments
 (0)