Skip to content

fix(types): correct shipped locals.d.ts EmDashHandlers path - #1077

Merged
ascorbic merged 6 commits into
mainfrom
fix/locals-emdash-handlers-path
May 17, 2026
Merged

ascorbic merged 6 commits into
mainfrom
fix/locals-emdash-handlers-path

Conversation

@ascorbic

@ascorbic ascorbic commented May 17, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Stacked on #1076 (compile source-exported subpaths). Merge #1076 first.

packages/core/locals.d.ts imported EmDashHandlers from ./dist/types.d.mts — a path tsdown never emits (the artifact is ./dist/astro/types.d.mts). The App.Locals augmentation therefore resolved EmDashHandlers to nothing and Astro.locals.emdash silently degraded to any for every EmDash site, losing autocomplete and type-checking on the handlers API in consumers' pages/endpoints. This points the import at the real artifact.

Correcting it un-masks exactly one previously-hidden real mismatch (it was hidden because emdash was any): @emdash-cms/auth-atproto's callback.ts passed Kysely<Database> into createKyselyAdapter (which expects Kysely<AuthTables>). Fixed with the canonical cast already used in core's cleanup.ts — Database contains the auth tables but uses Generated<> wrappers that confuse structural checks against AuthTables, and the adapter casts internally anyway; safe at runtime. Same comment + eslint-disable text as the existing precedent.

Why stacked on #1076: with the route subpaths still shipped as raw source, fixing this path reintroduces the full dual-package Database wall (~100 errors). With #1076's routes compiled, fixing it surfaces only this single bounded mismatch.

The shipped contract stays emdash: EmDashHandlers (required) — unchanged for consumers; only the broken import path is corrected.

Verified green: pnpm typecheck, demos + templates typecheck, lint at the existing baseline (adds 0), pnpm format, public-source guard.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes (PR adds 0 diagnostics; repo baseline unchanged)
  • pnpm test passes (or targeted tests for my change) — verified via full typecheck + demos/templates; no runtime behaviour change (type-declaration + a type-only cast matching existing precedent)
  • pnpm format has been run
  • I have added/updated tests for my changes — N/A (type-declaration fix; pnpm typecheck is the regression signal)
  • User-visible strings in the admin UI are wrapped for translation (if applicable) — N/A
  • I have added a changeset — emdash patch
  • New features link to an approved Discussion — N/A (not a feature)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.7

ascorbic and others added 2 commits May 17, 2026 10:26
Closes #1053.

Two parts:

1. wordpress-plugin.ts: the analyze-endpoint error body from
   response.json() is unknown under @cloudflare/workers-types; narrow
   it before reading .message (was the reported TS18046). The other
   reported error (byline.ts kysely Transaction variance) was TS5.x
   behaviour, resolved by the TS6 upgrade in #1074.

2. Stop shipping raw .ts for the source-exported subpaths
   (emdash/routes/*, emdash/api/route-utils, emdash/api/schemas,
   emdash/auth/providers/*). They are compiled to dist (.mjs +
   .d.mts), so a strict consumer's tsc only ever sees declarations
   (skipLibCheck covers them), eliminating the dual-package Database
   identity wall that is #1053's root cause. ./ui and .astro stay
   source (the consumer's Astro build must process them).

   - tsdown: route entrypoints fed via inputOptions.input (literal
     object, not entry globs -- [param] dirs are glob char-classes).
     entryFileNames + resolveRoute share one routeArtifactName() so
     rolldown's reserved [name]/[hash] placeholders cannot mangle
     dynamic-route artifacts.
   - A fast static guard (scripts/typecheck-public-source.mjs, wired
     into CI) fails if any subpath export ships raw .ts/.tsx again.

Verified: pnpm build, pnpm typecheck, demos+templates typecheck,
demo build (route injection e2e), lint baseline unchanged.
@changeset-bot

changeset-bot Bot commented May 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 54613d6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-perf-coordinator 54613d6 May 17 2026, 12:03 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-i18n 54613d6 May 17 2026, 12:04 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 54613d6 May 17 2026, 12:05 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 54613d6 May 17 2026, 12:06 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 17, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs 54613d6 May 17 2026, 12:04 PM

@ascorbic

Copy link
Copy Markdown
Member Author

/review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a shipped type-declaration regression where emdash/locals imported EmDashHandlers from a non-emitted build artifact, causing Astro.locals.emdash to silently become any in consumer projects. Also resolves the one newly-unmasked type mismatch in the ATProto auth provider by aligning with an existing core casting precedent.

Changes:

  • Update packages/core/locals.d.ts to import EmDashHandlers from the actual emitted ./dist/astro/types.d.mts artifact.
  • Fix @emdash-cms/auth-atproto’s createKyselyAdapter() call site by casting emdash.db to Kysely<AuthTables> (matching the established cast pattern in core).
  • Add a changeset documenting the consumer-facing typing fix for Astro.locals.emdash.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
packages/core/locals.d.ts Corrects the EmDashHandlers import path so locals.emdash no longer degrades to any.
packages/auth-atproto/src/routes/callback.ts Applies the same Kysely<AuthTables> cast pattern used in core to satisfy createKyselyAdapter’s expected DB type.
.changeset/locals-emdash-typing.md Adds a patch changeset describing the restored Astro.locals.emdash typing for consumers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ask-bonk

ask-bonk Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

The PR adds two eslint-disable directives where there were zero before in this file, which the description handwaves as "PR adds 0 diagnostics". Let me check if cleanup.ts's precedent uses identical eslint disable form:

The new line in callback.ts uses:

// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Database uses Generated<> wrappers incompatible with AuthTables structurally; safe at runtime

The cleanup.ts line 73 precedent text:

// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Database uses Generated<> wrappers incompatible with AuthTables structurally; safe at runtime

Identical. Good.

One more thing — the description claims this is "stacked on #1076". Let me check that the base branch is correct and won't accidentally merge unrelated code:

The PR base is fix/1053-compile-subpaths (PR #1076), head is fix/locals-emdash-handlers-path. Total: 12 additions, 3 deletions across 3 files matching the diff. Base discipline is correct.

Summary of review

The PR is correct, narrowly-scoped, and well-justified:

  1. Verified core claim: EmDashHandlers is only exported from src/astro/types.ts, so tsdown emits it to dist/astro/types.d.mts. The old ./dist/types.d.mts path never existed — confirmed empirically by building the package.

  2. EmDashHandlers is in shipped artifact: line 347 of the built dist/astro/types.d.mts exports it.

  3. The auth-atproto cast is the documented precedent: comment text and eslint-disable directive are byte-identical to packages/core/src/cleanup.ts:71-74.

  4. The fix is necessarily stacked on fix: resolve #1053 type errors for strict consumers #1076: I'll take this on faith since the base branch is fix/1053-compile-subpaths and the PR description explains the dependency clearly. Reviewing fix: resolve #1053 type errors for strict consumers #1076 is out of scope here.

  5. The bug is real and impactful: every EmDash consumer site had Astro.locals.emdash: any instead of EmDashHandlers. No autocomplete or typecheck in user pages/endpoints.

No bugs to file. One minor observation worth raising: there's no regression test guarding the import path, and the bug is exactly the kind that would re-occur if entries get reshuffled in tsdown.config.ts. A small smoke test (e.g. consume emdash/locals from a fixture and assert EmDashHandlers isn't any) would prevent recurrence — but this is a "consider for a follow-up" nit, not a blocker.

Given there are no actual issues with the code changes, this is LGTM territory.

LGTM!

github run

…dle them

Compiling the route/admin entries made tsdown try to bundle deps it
could not resolve at build time -- 'emdash' (the package importing
itself) and '@cloudflare/kumo' (admin-only, not an emdash dep). CI
escalates tsdown's bundling advisory to a fatal error.

- Externalize 'emdash' (self): compiled routes import it; resolved at
  the consumer's runtime where the package is installed.
- Externalize @aws-sdk/* (optional S3 deps, runtime-only).
- Keep the *-admin.tsx providers as source (bridge the admin React +
  @cloudflare/kumo runtime, like .astro/./ui); revert their exports.
- inlineOnly: false -- nothing is unintentionally bundled (all deps
  external, only our own src is); silences the CI-escalated advisory.

Guard's allowlist generalized to RUNTIME_COUPLED (Astro + admin React).
@ascorbic
ascorbic force-pushed the fix/locals-emdash-handlers-path branch from a11fda7 to 50322ba Compare May 17, 2026 11:45
ascorbic added 2 commits May 17, 2026 12:52
resolveRoute resolves emdash/routes/* to the compiled dist artifact
with routeArtifactName applied ([ ] -> _), so the media catch-all
route's entrypoint is api/media/file/_...key_ not [...key].ts. The
catch-all pattern assertion (the actual guarantee) is unchanged.
locals.d.ts imported EmDashHandlers from ./dist/types.d.mts, a path
tsdown never emits (it is ./dist/astro/types.d.mts). The augmentation
silently resolved to nothing, so Astro.locals.emdash was `any` for
every consumer. Point it at the real artifact.

This un-masks one real, previously-hidden mismatch: auth-atproto's
callback.ts passed Kysely<Database> to createKyselyAdapter (expects
Kysely<AuthTables>). Fixed with the canonical cast already used in
core's cleanup.ts (Database uses Generated<> wrappers that confuse
structural checks; the adapter casts internally; safe at runtime).

Stacked on the compile-subpaths change (#1076): with routes compiled,
fixing locals only surfaces this single bounded mismatch rather than
the dual-package wall.

Verified: pnpm typecheck, demos+templates typecheck, lint baseline
unchanged, public-source guard.
@ascorbic
ascorbic force-pushed the fix/locals-emdash-handlers-path branch from 50322ba to 0d718d0 Compare May 17, 2026 11:53
Base automatically changed from fix/1053-compile-subpaths to main May 17, 2026 12:02
@ascorbic
ascorbic enabled auto-merge (squash) May 17, 2026 12:03
@pkg-pr-new

pkg-pr-new Bot commented May 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1077

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1077

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1077

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1077

emdash

npm i https://pkg.pr.new/emdash@1077

create-emdash

npm i https://pkg.pr.new/create-emdash@1077

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1077

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1077

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1077

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1077

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1077

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1077

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1077

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1077

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1077

commit: 54613d6

@ascorbic
ascorbic merged commit f4a9711 into main May 17, 2026
38 checks passed
@ascorbic
ascorbic deleted the fix/locals-emdash-handlers-path branch May 17, 2026 12:14
@emdashbot emdashbot Bot mentioned this pull request May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants