Skip to content

Let stricter TypeScript apps and plain Node import pi-optchat/core and pi-optchat/durable - #260

Merged
jonaslsaa merged 3 commits into
mainfrom
fix/ship-built-entry-points
Oct 31, 2026
Merged

jonaslsaa merged 3 commits into
mainfrom
fix/ship-built-entry-points

Conversation

@jonaslsaa

Copy link
Copy Markdown
Owner

A Cloudflare Workers app with stricter settings than ours (noUncheckedIndexedAccess, exactOptionalPropertyTypes, Workers types instead of Node's) couldn't typecheck once it imported pi-optchat/core or pi-optchat/durable. Both pointed at our raw .ts source, so the app's compiler checked our files under the app's own settings; skipLibCheck only skips .d.ts. Such an app got dozens of errors in our code (66 in the test app below). Plain Node couldn't load them either, since it won't strip types from files in node_modules.

Fix

The package now ships core and durable built: tsconfig.build.json emits .js and .d.ts to dist/ (rewriteRelativeImportExtensions turns our .ts imports into .js), and prepack runs npm run build, so npm pack and the Publish workflow's npm publish always include it. Source stays in src/, and our own tsconfig is unchanged: no stricter flags, no guard edits.

. and pi.extensions stay on ./src/index.ts: Pi loads and compiles its extensions itself, so that path works today and is left alone.

Entry points changed

  • pi-optchat/core: now dist/core/index.js with types dist/core/index.d.ts (was src/core/index.ts).
  • pi-optchat/durable: now dist/durable/index.js with types dist/durable/index.d.ts (was src/durable/index.ts).
  • pi-optchat (the Pi extension): unchanged.

Test

test/consumer-workers is a tiny Workers app (strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes, skipLibCheck, only @cloudflare/workers-types) that opens a memory on SqliteStore and builds optchat() and optchatImport(). CI installs it from the tarball npm pack produces, typechecks it, and imports both entry points in plain Node, so a missing dist/ in files fails too. The branch's first commit adds only this check, and it failed against the old exports.

examples/durable-object still links the repo with file:../.., so run npm run build first (noted in docs/durable.md); its tsc and wrangler deploy --dry-run pass.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the package build and subpath export changes.

No open issues 🎉

What changed in this PR

This PR ships built JavaScript and declarations for pi-optchat/core and pi-optchat/durable, supporting stricter TypeScript consumers and plain Node imports while leaving the Pi extension entry point unchanged.

Changes:

  • Adds a build and prepack step, redirects subpath exports to dist/, and includes build output in the package.
  • Adds a strict Workers consumer fixture and CI checks against the packed package.
  • Documents the build prerequisite for the linked Durable Object example.
File Description
tsconfig.json Excludes the separately checked Workers fixture.
tsconfig.build.json Emits JavaScript and declarations with rewritten import extensions.
test/​consumer-workers/​worker.ts Exercises core and durable APIs with Workers storage types.
test/​consumer-workers/​tsconfig.json Configures stricter, Workers-only consumer typechecking.
test/​consumer-workers/​package.json Defines a private ESM consumer fixture.
package.json Updates exports, adds build hooks, and packages dist/.
package-lock.json Locks the added Workers types dependency.
docs/​durable.md Documents building before using the linked example.
.gitignore Ignores generated dist/ output.
.github/​workflows/​check.yml Checks packed-package types and plain Node imports.

Review effort: Balanced

@jonaslsaa
jonaslsaa merged commit 28d539e into main Oct 31, 2026
4 checks passed
@jonaslsaa
jonaslsaa deleted the fix/ship-built-entry-points branch October 31, 2026 21:11
@jonaslsaa jonaslsaa mentioned this pull request Oct 31, 2026
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.

2 participants