Repository navigation
fix: resolve #1053 type errors for strict consumers - #1076
Conversation
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 detectedLatest commit: 229b5dd The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-perf-coordinator | 229b5dd | May 17 2026, 11:53 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-i18n | 229b5dd | May 17 2026, 11:53 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
docs | 229b5dd | May 17 2026, 11:54 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | 229b5dd | May 17 2026, 11:54 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | 229b5dd | May 17 2026, 11:55 AM |
There was a problem hiding this comment.
Pull request overview
This PR addresses strict TypeScript consumer failures by narrowing the WordPress plugin analyze error body and moving several exported EmDash subpaths from raw source to compiled artifacts/declarations.
Changes:
- Adds a public export guard to prevent most raw
.ts/.tsxsubpath exports from returning. - Updates tsdown/package exports/route resolution to emit and resolve compiled route/API/auth-provider artifacts.
- Narrows
response.json()error handling in the WordPress plugin import source.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
scripts/typecheck-public-source.mjs |
Adds CI guard against raw TypeScript source in public exports. |
packages/core/tsdown.config.ts |
Adds route entry discovery, artifact naming, compiled public subpath entries, and broader externals. |
packages/core/src/import/sources/wordpress-plugin.ts |
Narrows unknown JSON error body before reading message. |
packages/core/src/astro/integration/routes.ts |
Resolves injected routes through compiled/sanitized route artifacts. |
packages/core/src/astro/integration/route-naming.ts |
Adds shared route artifact sanitization helper. |
packages/core/package.json |
Repoints route/API/auth-provider exports to compiled dist files. |
.github/workflows/ci.yml |
Runs the new public-source guard in CI. |
.changeset/wordpress-plugin-error-narrowing.md |
Adds patch changeset for WordPress plugin narrowing. |
.changeset/compile-source-exported-subpaths.md |
Adds patch changeset for compiled subpath exports. |
Comments suppressed due to low confidence (1)
packages/core/src/astro/integration/routes.ts:37
- This fallback no longer resolves a usable source route when
emdash/routes/*cannot be resolved. In source/dev or unbuilt test runs the files undersrc/astro/routesstill have their original.tsnames (including bracketed dynamic segments), but this now falls back to sanitized.mjspaths undersrc/astro/routes, which do not exist. That breaks the documented "dist not yet built" path and source-imported tests/development.
// Fallback for development (e.g. dist not yet built).
return isAstro
? resolve(__dirname, "../routes", route)
: resolve(__dirname, "../routes", `${specifier}.mjs`);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try { | ||
| // Try to resolve as package export | ||
| return require.resolve(`emdash/routes/${route}`); | ||
| return require.resolve(`emdash/routes/${specifier}`); |
| // `.ts`/`.tsx` source, but NOT `.d.ts` declarations (those are the desired | ||
| // shipping form -- `skipLibCheck` covers them). | ||
| const RAW_SOURCE = /(?<!\.d)\.tsx?$/; |
| "./routes/*": { | ||
| "types": "./dist/astro/routes/*.d.mts", | ||
| "default": "./dist/astro/routes/*.mjs" | ||
| }, |
| * Mirror each entry's path under src/ into dist/, preserving the original | ||
| * filename verbatim. tsdown/rolldown's default name template rewrites `[` and | ||
| * `]` to `_`, which would mangle dynamic-route entrypoints | ||
| * (`[collection]`, `[...path]`) and decouple `emdash/routes/*` resolution from | ||
| * the real filenames. Mirroring keeps dist a 1:1 image of src so route | ||
| * injection resolves entrypoints by their actual paths. |
…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).
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.
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
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.
* fix: resolve #1053 type errors for strict consumers 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. * style: format * fix(build): externalize self/optional deps so route entries don't bundle 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). * test: route-injection entrypoint now resolves to compiled artifact 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. * fix(types): correct shipped locals.d.ts EmDashHandlers path 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. --------- Co-authored-by: emdashbot[bot] <emdashbot[bot]@users.noreply.github.com>
* fix: resolve #1053 type errors for strict consumers 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. * style: format * fix(build): externalize self/optional deps so route entries don't bundle 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). * test: route-injection entrypoint now resolves to compiled artifact 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. --------- Co-authored-by: emdashbot[bot] <emdashbot[bot]@users.noreply.github.com>
* chore: harden pnpm supply-chain config Pin pnpm (packageManager: [email protected]) so the build-script/trust schema is deterministic, and add supply-chain hardening to pnpm-workspace.yaml: - minimumReleaseAge 1440 (24h publish cooldown); @rolldown/* and @emnapi/* excluded (vite8/rolldown-rc exact-pins these per-arch binaries; their release cadence structurally conflicts with the cooldown and they are not an attack surface worth the friction) - strictDepBuilds + explicit allowBuilds: build scripts run only for @parcel/watcher, sharp, better-sqlite3, esbuild, workerd; core-js-pure denied (donation postinstall, not needed) - dangerouslyAllowAllBuilds false - blockExoticSubdeps true, with an @astrojs/telemetry -> 3.3.0 override (infra/cache-demo's pkg.pr.new Astro cache-support preview pulls telemetry via URL; the override keeps the guard on) - trustPolicy no-downgrade with a reviewed, version-pinned trustPolicyExclude ([email protected], [email protected], [email protected], @portabletext/[email protected], [email protected] -- all benign publish-method changes / old pre-provenance pins, not takeovers) - verifyStoreIntegrity, strictStorePkgContentCheck, verifyDepsBeforeRun error Move enable-pre-post-scripts from .npmrc to pnpm-workspace.yaml (enablePrePostScripts: true; canonical location, also silences the npm "unknown config" warning). Remove .npmrc entirely -- provenance is implied by OIDC trusted publishing. Lockfile regenerated under the hardened config with pnpm 11.1.2. * chore: address Copilot review on supply-chain hardening - Remove stale root pnpm.onlyBuiltDependencies (dead under pinned pnpm 11; allowBuilds in pnpm-workspace.yaml is the single source) - Narrow cooldown excludes: @rolldown/* -> @rolldown/binding-*, and @emnapi/* -> @emnapi/core/@emnapi/runtime, so the cooldown stays active for JS like @rolldown/pluginutils / @emnapi/wasi-threads - Drop the dangling CONTRIBUTING.md pointer (no such policy doc) - Override @ungap/structured-clone to ^1.3.1 (1.3.0 deprecated, CWE-502) - Regenerate the lockfile from a clean store so the astro pkg.pr.new tarball regains its SRI integrity (the earlier warm-store regen dropped it; @astrojs/cloudflare and @lunariajs/core never had SRI, pre-PR included -- pnpm doesn't record it for those URLs) Re-resolved clean under pnpm 11.1.2 with the narrowed excludes. * fix: resolve #1053 type errors for strict consumers (#1076) * fix: resolve #1053 type errors for strict consumers 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. * style: format * fix(build): externalize self/optional deps so route entries don't bundle 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). * test: route-injection entrypoint now resolves to compiled artifact 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. --------- Co-authored-by: emdashbot[bot] <emdashbot[bot]@users.noreply.github.com> --------- Co-authored-by: emdashbot[bot] <emdashbot[bot]@users.noreply.github.com>
What does this PR do?
Closes #1053. Built on #1074 (TS6 upgrade, merged) — supersedes #1075, which is closed in favour of this single coherent change.
#1053 reported two type errors when consuming
[email protected]under a strict TypeScript project. Re-triaged:byline.ts:204(kyselyTransactionvariance) — TypeScript 5.x behaviour; does not reproduce on TS 6 and was already resolved by chore: upgrade to TypeScript 6 + pin tsgo beta + fix dual-load config #1074. No code change.wordpress-plugin.ts('error' is of type 'unknown') — real: the analyze-endpoint error body fromresponse.json()isunknownunder@cloudflare/workers-typesand was read without narrowing. Fixed with assertion-free narrowing (clean under both the consumer's Workers config and emdash's own typecheck; runtime unchanged).Root cause of the class: the reporter's premise was right, their repro wrong. Bare
import "emdash"resolves to compileddist/*.d.mts(skipLibCheckcovers it — verified clean). The errors only surfaced because several subpaths shipped raw source (emdash/routes/*,emdash/api/route-utils,emdash/api/schemas,emdash/auth/providers/*):skipLibCheckdoes not skip.ts, so a strict consumer'stsctype-checked EmDash's source and its transitive graph. And because that raw source importedDatabasefromsrcwhileemdash/localsprovided the compileddistidentity,Kysely<Database>had two nominally-distinct identities →TS2345whereveremdashmet route-local types.Structural fix: those subpaths are now compiled to
dist(.mjs+.d.mts). Consumers only ever see declarations, so there is a singleDatabaseidentity andskipLibCheckapplies. Import specifiers and runtime behaviour are unchanged (verified by an end-to-end demo build exercising route injection).tsdown: route entrypoints are fed viainputOptions.input(a literal object) rather thanentryglobs — Astro's[param]dynamic-route directories are glob character-classes, so any glob-based entry silently drops routes nested under a bracketed segment.entryFileNamesandresolveRouteshare onerouteArtifactName()(single source of truth) so rolldown's reserved[name]/[hash]output placeholders cannot mangle dynamic-route artifacts../uiand.astroexports remain source by necessity — the consumer's Astro build must process them.scripts/typecheck-public-source.mjs, wired into the CI typecheck job): it fails if any subpath export ships raw.ts/.tsxagain. Once raw source isn't shipped there is no raw-source graph to type-check, so a static export-shape check is the whole guarantee.Verified green:
pnpm build,pnpm typecheck, demos + templates typecheck, demo build with route injection, lint at the existing baseline (PR adds 0), formatting.Known follow-up (tracked, not in scope here)
packages/core/locals.d.tsimportsEmDashHandlersfrom./dist/types.d.mts, a path tsdown never emits (it is./dist/astro/types.d.mts), soAstro.locals.emdashisanyfor all consumers today. The one-line path fix un-masks a latentDatabase/AuthTablesinvariance cascade (e.g.@emdash-cms/auth-atproto), so it is a separate, deliberate follow-up.Type of change
Checklist
pnpm typecheckpassespnpm lintpasses (PR adds 0 diagnostics; repo baseline unchanged)pnpm testpasses (or targeted tests for my change) — verified viapnpm build+ full typecheck + an end-to-end demo build exercising route injection; the static guard is the regression testpnpm formathas been runscripts/typecheck-public-source.mjsguards against reshipping raw sourceemdashpatch changesets (wordpress-plugin narrowing; compile source-exported subpaths)AI-generated code disclosure