Skip to content

fix(src): strip .ts extensions from internal imports for consumer typecheck - #105

Merged
vibe-dex merged 1 commit into
mainfrom
fix/strip-ts-extensions-from-published-imports
May 1, 2026
Merged

vibe-dex merged 1 commit into
mainfrom
fix/strip-ts-extensions-from-published-imports

Conversation

@vibe-dex

@vibe-dex vibe-dex commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

`@decocms/start` publishes raw TypeScript source via `package.json` `exports` (e.g. `"./admin": "./src/admin/index.ts"`). Consumers' bundlers (Vite, tsx) compile on the fly and don't care about extensions, but consumer `tsc --noEmit` follows imports into `node_modules/@decocms/start/src/*` and surfaces a hard error for any import that ends with `.ts`:

```
error TS5097: An import path can only end with a '.ts' extension
when 'allowImportingTsExtensions' is enabled.
```

Today, every consumer site (baggagio-tanstack, casaevideo-storefront, etc.) sees ~8 of these errors when they run `tsc --noEmit` — purely as a side effect of importing from this package. Forcing each consumer to enable `allowImportingTsExtensions` in their tsconfig is awkward (it requires `noEmit` and limits other build flows).

The fix is one-line per import: drop the redundant `.ts` extension on internal relative imports in published source files. `moduleResolution: "bundler"` handles extensionless paths cleanly; tsx and Vite do too.

Scope

`src/` only. `scripts/` retain `.ts` for now since they're not published as importable modules — they run as bin scripts via tsx.

File Imports fixed
`src/admin/decofile.ts` 3
`src/admin/meta.ts` 2
`src/cms/loader.ts` 1
`src/daemon/fs.ts` 1
`src/daemon/index.ts` 8
`src/daemon/middleware.ts` 4
`src/sdk/cachedLoader.ts` 1
Total 20

Diff is exactly 20 insertions / 20 deletions — pure import path changes, no formatting noise.

Verification

Check Before After
`tsc --noEmit` errors in `src/` (TS5097) 20 0
`vitest run` 104/104 104/104
`tsc` emit (`dist/src/admin/meta.js`) `from "./schema.ts"` ❌ `from "./schema"` ✅

Consumer impact: a baggagio-tanstack `npm run typecheck` should drop from
8 framework-induced TS5097 errors → 0 once a release ships with this fix.

Why not biome auto-format too

Running `biome check --write` on these files reformats line widths
(collapsing multi-line function calls), bloating the diff with
unrelated changes. Kept this PR strictly to the import path fix
for reviewability. Formatting can be a follow-up if desired.

Test plan

  • Once released, `baggagio-tanstack/npm run typecheck` shows 0 framework-induced TS5097 errors (was 8)
  • No regression in `@decocms/start` build output (`dist/src/admin/meta.js` etc. shows extensionless imports)
  • Sample import verification: `import { djb2Hex } from "../sdk/djb2"` resolves correctly under bundler resolution

Made with Cursor

…echeck

@decocms/start publishes raw TypeScript source via package.json `exports`.
Consumers' bundlers (Vite, tsx) compile on the fly and don't care about
extensions, but consumer `tsc --noEmit` follows imports into
node_modules/@decocms/start/src/* and surfaces a hard error for any
import that ends with `.ts`:

    error TS5097: An import path can only end with a '.ts' extension
    when 'allowImportingTsExtensions' is enabled.

Forcing every consumer to enable allowImportingTsExtensions in their
tsconfig is awkward (it requires noEmit and limits other build flows).
The fix is to drop the redundant `.ts` extension on internal relative
imports in published source files. moduleResolution: "bundler" handles
extensionless paths cleanly; tsx and Vite do too.

Scope: src/ only. scripts/ retain `.ts` for now since they're not
published as importable modules — they run as bin scripts via tsx.

Files (20 imports across 7 files):
- src/admin/decofile.ts (3)
- src/admin/meta.ts (2)
- src/cms/loader.ts (1)
- src/daemon/fs.ts (1)
- src/daemon/index.ts (8)
- src/daemon/middleware.ts (4)
- src/sdk/cachedLoader.ts (1)

Verification:
- typecheck: TS5097 errors in src/ go from 20 → 0 (consumer-facing)
- vitest: 104/104 pass
- tsc emit: dist/src/admin/meta.js now reads `from "./schema"`
  (previously `from "./schema.ts"` — caused downstream issues)

Diff is clean — 20 insertions / 20 deletions, just the imports. No
formatting changes.

Made-with: Cursor
@vibe-dex
vibe-dex merged commit 3195c20 into main May 1, 2026
1 check passed
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.4.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

vibe-dex added a commit that referenced this pull request May 1, 2026
Three independent issues that together broke `npm run build` on main:

1. **47× TS5097** in `scripts/**/*.ts` — relative imports ending in `.ts`
   (same shape as the consumer-facing fix in #105, just for scripts).
   Done with a one-shot regex replace: `from "./foo.ts"` → `from "./foo"`.
   80 imports across 34 files; mechanical, no semantic change.

2. **TS2322** in `scripts/migrate/phase-analyze.ts:393` — `reExport` was
   declared as `{ is: false, target: undefined as string | undefined }`
   (target required) but `isReExport(content)` returns
   `{ is: boolean; target?: string }` (target optional). Aligned the
   variable type to the return type.

3. **TS2493** in `src/cms/sectionLoaders.test.ts:36` — `vi.fn(async (props) => props)`
   declared a 1-arg function, so `loader.mock.calls[0]` typed as a
   1-tuple, but the test destructures `[calledProps, calledReq]`.
   Added the second `_req: Request` parameter to the mock signature.

Why it was masked:
The framework publishes raw TypeScript via `package.json` `exports`
pointing at `./src/...` (verified — no `dist/` in the export map).
Releases run `semantic-release` directly without `npm run build`, so
the build break didn't gate publishing. But it polluted `npm run check`,
broke `dist/` for anyone trying to use compiled output, and made the
typecheck signal worthless ("89 errors, all pre-existing" was a recurring
false alarm in this session).

Verification:
- `npm run build` exits 0 (was exit 2)
- `npm run typecheck` exits 0 (was exit 2)
- vitest: 104/104 pass
- `dist/src/admin/meta.js` emits with extensionless imports

Total: 35 files changed, +85/-82 (mostly 1-for-1 line replacements).
Made-with: Cursor
vibe-dex added a commit that referenced this pull request May 1, 2026
…build) (#112)

Adds a new Phase 8 to the migration pipeline that actually compiles the
migrated site after bootstrap completes. This is the gate that catches
regressions which slip past the static `phase-verify` checks — the same
class of bugs we hit in #105 (TS5097, rewriter leaving `.ts` in import
paths) and the dead `src/lib/*` shims that broke `phase-cleanup`.

## Behavior

- Default: runs `npx tsc --noEmit`. Failures are warnings — migration
  completes, but the user sees the truncated diagnostic output.
- `--strict`: failures abort the migration with exit code 2 so CI can
  fail the pipeline.
- `--with-build`: also runs `npx vite build` after typecheck. Slower
  (~30-90s) but catches runtime-only issues.
- `--no-compile`: skips the phase entirely.
- Auto-skipped when `node_modules/` is missing (bootstrap likely failed).

## Implementation

- `scripts/migrate/phase-compile.ts` — exports `compile(ctx, opts)`.
  Returns `{ shouldFail }` so the caller decides exit codes; we don't
  `process.exit` ourselves which keeps it unit-testable. The command
  runner is injectable via `opts.runner` for tests.
- `scripts/migrate.ts` — wires three new flags (`--strict`,
  `--with-build`, `--no-compile`) through to the phase. Updated
  `--help` output.
- `scripts/migrate/phase-compile.test.ts` — 11 tests covering dry-run,
  missing node_modules, success path, failure paths, strict promotion,
  build flag gating, and the truncate helper.
- `.agents/skills/deco-migrate-script/SKILL.md` — documents the new
  phase, flags, and CI usage pattern (`--strict --with-build`).

## Validation

- `npx vitest run` → 132 tests pass (was 121, +11 new)
- `npm run typecheck` → clean

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant