Skip to content

YPE-1911: Fix imports in strict ESM runtimes like Deno#206

Merged
cameronapak merged 2 commits intomainfrom
YPE-1911-react-sdk-hooks-pkg-properly-package-hook
Mar 27, 2026
Merged

YPE-1911: Fix imports in strict ESM runtimes like Deno#206
cameronapak merged 2 commits intomainfrom
YPE-1911-react-sdk-hooks-pkg-properly-package-hook

Conversation

@cameronapak
Copy link
Copy Markdown
Collaborator

@cameronapak cameronapak commented Mar 27, 2026

https://lifechurch.atlassian.net/browse/YPE-1911

Use tsup to produce proper index.js (ESM) and index.cjs (CJS) bundles instead of loose tsc output. Fixes imports in strict ESM runtimes like Deno that don't support Node-specific module resolution

Use tsup to produce proper index.js (ESM) and index.cjs (CJS) bundles instead of loose tsc output. Fixes imports in strict ESM runtimes like Deno that don't support Node-specific module resolution
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 27, 2026

🦋 Changeset detected

Latest commit: b19f943

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

This PR includes changesets to release 4 packages
Name Type
@youversion/platform-react-hooks Patch
@youversion/platform-core Patch
@youversion/platform-react-ui Patch
vite-react 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

@cameronapak cameronapak changed the title build(hooks): switch from tsc to tsup for CJS/ESM bundling YPE-1911: Fix imports in strict ESM runtimes like Deno Mar 27, 2026
@cameronapak cameronapak marked this pull request as ready for review March 27, 2026 16:55
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 27, 2026

Greptile Summary

This PR migrates @youversion/platform-react-hooks from loose tsc output to proper tsup-generated CJS and ESM bundles, resolving import failures in strict ESM runtimes like Deno. It aligns the hooks package with the already-established pattern in packages/ui and packages/core.\n\nKey changes:\n- \"main\" and exports[\"require\"] now correctly point to dist/index.cjs (CJS bundle), while \"module\" and exports[\"import\"] keep dist/index.js (ESM bundle). Previously both pointed to the same .js file, which broke require() in runtimes that honour package.json#type: \"module\".\n- build is split into build:js (tsup, no type declarations) and build:types (tsc with emitDeclarationOnly: true), sequenced via pnpm build:js && pnpm build:types. tsconfig.build.json is updated accordingly.\n- tsup 8.5.0 is added as a devDependency, matching the versions already in use across packages/core and packages/ui.\n- The changeset bumps all three public packages as a patch, correctly honouring the unified versioning policy.\n- One minor observation: unlike packages/ui's explicit tsup.config.ts (which marks react and react/jsx-runtime as external), the hooks package relies on tsup CLI flags with no explicit external declaration. In practice tsup leaves node_modules unbundled by default, but an explicit config would make this more robust.

Confidence Score: 5/5

Safe to merge — the change is a well-scoped bundler migration with no runtime logic changes.

All remaining findings are P2 style suggestions. The core fix (correct CJS/ESM split) is sound and consistent with the existing pattern in packages/core and packages/ui. Unified versioning is maintained via the changeset.

packages/hooks/package.json — consider adding explicit React externals to the tsup invocations.

Important Files Changed

Filename Overview
packages/hooks/package.json Switches from raw tsc output to tsup CJS+ESM bundles; correctly separates main/require (.cjs) from module/import (.js); React not explicitly marked external in tsup CLI invocations.
packages/hooks/tsconfig.build.json Correctly adds emitDeclarationOnly, declaration, and declarationMap so tsc only emits type declarations while tsup handles JS bundling.
.changeset/fair-parks-notice.md Bumps all three packages (platform-react-hooks, platform-core, platform-react-ui) as patch to maintain unified versioning policy.
pnpm-lock.yaml Adds tsup 8.5.0 lockfile entry for hooks package; incidentally upgrades shared esbuild and debug snapshots used by the tsup resolution graph.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[src/index.ts] --> B{pnpm build}
    B --> C[build:js\ntsup --format cjs,esm]
    B --> D[build:types\ntsc -p tsconfig.build.json]
    C --> E[dist/index.js\nESM bundle]
    C --> F[dist/index.cjs\nCJS bundle]
    D --> G[dist/index.d.ts\nType declarations]
    D --> H[dist/index.d.ts.map\nDeclaration maps]
    E --> I["exports.import / module field"]
    F --> J["exports.require / main field"]
    G --> K["exports.types / types field"]
    L[pnpm dev] --> M[tsup --format cjs,esm --watch --dts]
    M --> E
    M --> F
    M --> N[dist/index.d.ts\ntsup-bundled declarations]
Loading

Reviews (2): Last reviewed commit: "fix(hooks): emit type declarations durin..." | Re-trigger Greptile

Add --dts flag to tsup watch command so consuming workspace packages
get live type updates during local development.

Amp-Thread-ID: https://ampcode.com/threads/T-019d303c-619e-76fe-870a-8df84da40419
Co-authored-by: Amp <amp@ampcode.com>
@cameronapak
Copy link
Copy Markdown
Collaborator Author

Hey @jaredhightower-youversion can you review this? These changes will allow people to use the React hooks and React UI SDK's in strict ESM runtimes, like Deno

@cameronapak cameronapak merged commit b8b5cf0 into main Mar 27, 2026
6 checks passed
@cameronapak cameronapak deleted the YPE-1911-react-sdk-hooks-pkg-properly-package-hook branch March 27, 2026 19:35
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