Skip to content

Commit 0863ab1

Browse files
committed
fix(publish): fail early on invalid npm authentication
fix(publish): prompt for npm login when needed
1 parent 5a98b67 commit 0863ab1

4 files changed

Lines changed: 50 additions & 9 deletions

File tree

‎Makefile‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PACKAGES := $(patsubst packages/%/Makefile,%,$(wildcard packages/*/Makefile))
88
# The per-package targets are deliberately not .PHONY: make skips the implicit
99
# rule search for phony targets, which would leave the pattern rules unmatched.
1010
# No file is ever named after them, so they always run.
11-
.PHONY: install test test-load check-publish publish
11+
.PHONY: install test test-load check-publish-auth check-publish publish
1212

1313
install:
1414
$(BUN) install
@@ -21,6 +21,17 @@ test-load: $(PACKAGES:%=test-load-%)
2121
test-load-%:
2222
$(MAKE) -C packages/$* test-load OPENCODE="$(OPENCODE)"
2323

24+
check-publish-auth:
25+
@if ! $(NPM) whoami >/dev/null 2>&1; then \
26+
echo "npm authentication is missing or expired; starting login..."; \
27+
$(NPM) login || exit $$?; \
28+
fi
29+
@identity="$$( $(NPM) whoami 2>/dev/null )" || { \
30+
echo "Cannot publish: npm authentication still failed after login." >&2; \
31+
exit 1; \
32+
}; \
33+
echo "npm authenticated as $$identity"
34+
2435
# The registry rejects a version it already has, so a release that only bumps
2536
# one package publishes that one alone: make publish-reviewer. Publishing every
2637
# package remains available for a release that bumps all of them. Check every
@@ -31,7 +42,7 @@ check-publish:
3142
if [ $$status -ne 0 ] && [ $$status -ne 3 ]; then exit $$status; fi; \
3243
done
3344

34-
publish: test test-load
45+
publish: check-publish-auth test test-load
3546
@candidates=""; \
3647
for package in $(PACKAGES); do \
3748
$(NODE) scripts/check-publish-version.mjs packages/$$package "$(NPM)" --aggregate; status=$$?; \
@@ -46,5 +57,5 @@ publish: test test-load
4657
check-publish-%:
4758
$(NODE) scripts/check-publish-version.mjs packages/$* "$(NPM)"
4859

49-
publish-%: check-publish-% test test-load-%
60+
publish-%: check-publish-auth check-publish-% test test-load-%
5061
$(MAKE) -C packages/$* publish

‎packages/commands/Makefile‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
BUN ?= bun
22
NPM ?= npm
33

4-
.PHONY: test test-load publish
4+
.PHONY: test test-load check-publish-auth publish
55

66
test:
77
$(BUN) run test
88

99
test-load:
1010
./scripts/load-check.sh
1111

12+
check-publish-auth:
13+
@if ! $(NPM) whoami >/dev/null 2>&1; then \
14+
echo "npm authentication is missing or expired; starting login..."; \
15+
$(NPM) login || exit $$?; \
16+
fi
17+
@$(NPM) whoami >/dev/null 2>&1 || { \
18+
echo "Cannot publish: npm authentication still failed after login." >&2; \
19+
exit 1; \
20+
}
21+
1222
# Prompts for an npm one-time password unless a bypass-2FA token is configured.
13-
publish:
23+
publish: check-publish-auth
1424
$(NPM) publish --access public

‎packages/reviewer/Makefile‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
BUN ?= bun
22
NPM ?= npm
33

4-
.PHONY: install test test-load test-security publish
4+
.PHONY: install test test-load test-security check-publish-auth publish
55

66
install:
77
$(BUN) install
@@ -16,6 +16,16 @@ test-load:
1616
test-security:
1717
REVIEWER_LIVE=1 $(BUN) test test/reviewer.test.ts --test-name-pattern 'live classifier'
1818

19+
check-publish-auth:
20+
@if ! $(NPM) whoami >/dev/null 2>&1; then \
21+
echo "npm authentication is missing or expired; starting login..."; \
22+
$(NPM) login || exit $$?; \
23+
fi
24+
@$(NPM) whoami >/dev/null 2>&1 || { \
25+
echo "Cannot publish: npm authentication still failed after login." >&2; \
26+
exit 1; \
27+
}
28+
1929
# Prompts for an npm one-time password unless a bypass-2FA token is configured.
20-
publish:
30+
publish: check-publish-auth
2131
$(NPM) publish --access public

‎packages/subagent-model/Makefile‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
BUN ?= bun
22
NPM ?= npm
33

4-
.PHONY: test test-load publish
4+
.PHONY: test test-load check-publish-auth publish
55

66
test:
77
$(BUN) run test
88

99
test-load:
1010
./scripts/load-check.sh
1111

12+
check-publish-auth:
13+
@if ! $(NPM) whoami >/dev/null 2>&1; then \
14+
echo "npm authentication is missing or expired; starting login..."; \
15+
$(NPM) login || exit $$?; \
16+
fi
17+
@$(NPM) whoami >/dev/null 2>&1 || { \
18+
echo "Cannot publish: npm authentication still failed after login." >&2; \
19+
exit 1; \
20+
}
21+
1222
# Prompts for an npm one-time password unless a bypass-2FA token is configured.
13-
publish:
23+
publish: check-publish-auth
1424
$(NPM) publish --access public

0 commit comments

Comments
 (0)