fix(service): replace forbidden global Hono type augmentation with exported ServiceEnv#125
Merged
Merged
Conversation
…ported ServiceEnv (#114) JSR rejects publishing `@netscript/service@0.0.1-alpha.2`: modifying global types is not allowed file:///src/auth/hono-context.ts:10:16 `deno publish --dry-run` did NOT catch this — it is a server-side JSR check — so both local and CI dry-runs passed green while the real publish aborted at service, landing 18/31 packages then failing (the 12 queued after it never uploaded). Root cause: `hono-context.ts` used `declare module 'hono' { interface ContextVariableMap { ... } }` to globally augment every Hono app's context variables. JSR forbids ambient global-type modification in published packages. Fix (behavior-identical for this package's own code): - Remove the `declare module 'hono'` augmentation. - Export `ServiceVariables` + `ServiceEnv` from hono-context.ts as the JSR-compliant opt-in: consumers type their app `new Hono<ServiceEnv>()` instead of relying on global pollution. Re-exported from `@netscript/service/auth`. - Drop the three now-dead `import './hono-context.ts'` side-effect imports (types.ts, auth-middleware.ts, service-builder-impl.ts). The service's own plumbing already typed contexts as plain `Context` / `MiddlewareHandler` (env defaults to `any`), so `c.get('principal')` / `c.set('principal')` / `c.get('logger')` resolve identically before and after. The test suite owns its `AuthTestEnv` and never depended on the augmentation. Validation: - deno check --unstable-kv ./mod.ts ./src/auth/mod.ts — clean - deno test ./tests/ — 57 passed, 0 failed Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014gW4zfhMMQU6txC828ijct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The atomic JSR publish aborted at
@netscript/service@0.0.1-alpha.2(18/31 landed, then failed). This is root cause #3 — distinct from the relative-path escape fixed in #124 and the publish-loop bug fixed in #123.JSR rejected the package with:
deno publish --dry-rundoes not catch this — it is a server-side JSR check — so both local and CI dry-runs passed green while the real publish aborted. (Motivates the planned stronger internal preflight.)hono-context.tsuseddeclare module 'hono' { interface ContextVariableMap { … } }to globally augment every Hono app's context variables. JSR forbids ambient global-type modification in published packages.What
declare module 'hono'augmentation.ServiceVariables+ServiceEnvas the JSR-compliant opt-in — consumers type their appnew Hono<ServiceEnv>()instead of relying on global pollution. Re-exported from@netscript/service/auth.import './hono-context.ts'side-effect imports (types.ts,auth-middleware.ts,service-builder-impl.ts).Behavior-identical for the package's own code: its plumbing already typed contexts as plain
Context/MiddlewareHandler(env defaults toany), soc.get/set('principal'|'logger')resolve the same before and after. The test suite owns its ownAuthTestEnvand never depended on the augmentation.Validation
deno check --unstable-kv ./mod.ts ./src/auth/mod.ts— cleandeno test ./tests/— 57 passed, 0 failedAfter merge, re-firing
publish.yml --ref mainpublishes the remaining 13 packages at0.0.1-alpha.2(the 18 already-live skip via JSR idempotency).🤖 Generated with Claude Code