Skip to content

fix(service): replace forbidden global Hono type augmentation with exported ServiceEnv#125

Merged
rickylabs merged 1 commit into
mainfrom
fix/service-hono-globaltypes
Jun 25, 2026
Merged

fix(service): replace forbidden global Hono type augmentation with exported ServiceEnv#125
rickylabs merged 1 commit into
mainfrom
fix/service-hono-globaltypes

Conversation

@rickylabs

Copy link
Copy Markdown
Owner

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:

modifying global types is not allowed
file:///src/auth/hono-context.ts:10:16

deno publish --dry-run does 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.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.

What

  • Remove the declare module 'hono' augmentation.
  • Export ServiceVariables + ServiceEnv 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).

Behavior-identical for the package's own code: its plumbing already typed contexts as plain Context/MiddlewareHandler (env defaults to any), so c.get/set('principal'|'logger') resolve the same before and after. The test suite owns its own AuthTestEnv and never depended on the augmentation.

Validation

  • deno check --unstable-kv ./mod.ts ./src/auth/mod.tsclean
  • deno test ./tests/57 passed, 0 failed

After merge, re-firing publish.yml --ref main publishes the remaining 13 packages at 0.0.1-alpha.2 (the 18 already-live skip via JSR idempotency).

🤖 Generated with Claude Code

…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
@rickylabs
rickylabs merged commit 0dc73f0 into main Jun 25, 2026
6 checks passed
@rickylabs
rickylabs deleted the fix/service-hono-globaltypes branch June 25, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant