fix(hooks): switch build to tsup for ESM compatibility#202
fix(hooks): switch build to tsup for ESM compatibility#202cameronapak wants to merge 3 commits intoyouversion:mainfrom
Conversation
The hooks package was using raw tsc to compile, which copies import specifiers verbatim without adding .js extensions. This breaks in strict ESM runtimes like Deno that require explicit file extensions on relative imports. Switch to tsup (matching core and ui packages) which bundles all modules into a single output file, eliminating extensionless relative imports entirely. Also adds proper CJS support via dual format output.
|
Greptile SummaryReview completed and submitted via submit_review tool. Confidence Score: 4/5Safe to merge after addressing the missing --dts flag in the dev watch script; production builds are correct. The fix is well-targeted and the production build output (both JS artifacts and type declarations) is correct. The only concrete issue is the dev watch script not regenerating .d.ts files, which affects monorepo development DX but not published artifacts. packages/hooks/package.json — dev script line 25 needs --dts to keep types fresh during watch Reviews (5): Last reviewed commit: "Updated pnpm-lock.yaml" | Re-trigger Greptile |
Split build into build:js (tsup) and build:types (tsc -p tsconfig.build.json) so that tsconfig.build.json declarations settings actually take effect.
3f1b660 to
35f111b
Compare
Problem
The hooks package uses raw
tscto compile, which copies import specifiers verbatim — e.g.export * from './useBook'in the source becomes the same extensionless import indist/index.js. Since the package declares"type": "module", strict ESM runtimes (Deno, Val Town) fail with:This only affects hooks — core and ui already use tsup, which bundles everything into a single file (no relative imports survive in the output).
Fix
Switch hooks to tsup, matching the build strategy of core and ui:
buildanddevscripts now usetsup src/index.ts --format cjs,esm --dtstsconfig.build.jsonupdated toemitDeclarationOnly(tsup handles JS output)dist/index.cjs) via dual format outputtsupadded to devDependencies (same version as core/ui:8.5.0)What changes
packages/hooks/package.jsonpackages/hooks/tsconfig.build.jsonNo source code changes. No API changes. The published package exports remain identical.