Skip to content

Modernize, refactor, and document typectl#3

Merged
winton merged 4 commits into
mainfrom
modernize
Apr 9, 2026
Merged

Modernize, refactor, and document typectl#3
winton merged 4 commits into
mainfrom
modernize

Conversation

@winton

@winton winton commented Apr 9, 2026

Copy link
Copy Markdown
Owner

Summary

Modernize build, test, and packaging (previous work)

  • Migrate to Vitest 3 with v8 coverage (native TS, no build-before-test)
  • Dual CJS + ESM build with proper exports map, module, and types fields
  • ESLint flat config (eslint.config.mjs); add lint script
  • GitHub Actions CI on Node 18/20/22 running lint, build, and coverage
  • TypeScript 6 compatibility (moduleResolution, ignoreDeprecations)
  • Fix runtime bugs: toValue falsy-value drop, toStream error swallowing

Refactor into focused modules

  • Split monolithic src/typectl.ts (~500 lines) into eight focused modules: types.ts, polyfill.ts, wrap.ts, pick.ts, concurrency.ts, iterate.ts, mappers.ts, assign.ts
  • src/typectl.ts is now a pure barrel re-export; public API is unchanged

Bug fixes

  • for...inObject.entries() in iterate: no longer visits inherited prototype properties on plain-object records
  • Recursive stream pump → while loop: eliminates stack overflow risk on long ReadableStream inputs
  • pick error test: replaced silent try/catch with expect().rejects.toThrow() so a missing throw correctly fails the test

Documentation

  • JSDoc on every export: covers purpose, concurrency semantics, parameter shapes, and examples; IDE hover is now informative
  • Rewritten README: motivation section (before/after), full API reference with runnable examples, concurrency behaviour table for iterate, all 12 utility types listed, compatibility notes, dev commands

Tests (38 total, up from 26)

  • 11 new edge-case tests: empty array/record/stream for iterate, toArray, toRecord, toValue, toStream; wrap with zero args; all/each on []

Packaging

  • "files": ["dist"] whitelist in package.json (replaces .npmignore as the publish guard)
  • Condition-specific "types" in exports: ESM consumers get dist/esm/typectl.d.ts, CJS consumers get dist/cjs/typectl.d.ts
  • Remove unused jsx glob from lint-staged
  • bin/watch now watches both CJS and ESM targets in parallel

Test plan

  • npm run build — clean dual CJS + ESM build
  • npm run lint — zero errors
  • npm test — 38 tests pass
  • npm run test:coverage — coverage on src/typectl.ts and all modules
  • CI passes on Node 18, 20, 22

Made with Cursor

winton added 4 commits April 8, 2026 23:17
- Fix runtime bugs: toValue truthiness (falsy values dropped), toStream
  error swallowing (no .catch), IterableType | any union swallowing all
  other branches
- Migrate from Mocha to Vitest 3 with v8 coverage; fix toStream test
  reader variable bug; add 12 new edge-case tests (26 total, 96.5% coverage)
- Replace dual-CJS build with CJS + ESM; add exports map, module, and
  types fields to package.json; upgrade target to ES2020
- Migrate ESLint to flat config (eslint.config.mjs); add lint script
- Remove dead deps (@types/fs-extra, npm-check-updates, source-map-support);
  fix lint-staged (remove deprecated git add); split prepare/prepublishOnly
- Add LICENSE file; align functions.ts signature with README
- Add GitHub Actions CI (Node 18/20/22 matrix)
- Upgrade all packages to latest; fix TypeScript 6 breaking changes
  (baseUrl removed, moduleResolution → bundler, polyfill cast)

Made-with: Cursor
- Split monolithic src/typectl.ts into focused modules: types.ts,
  polyfill.ts, wrap.ts, pick.ts, concurrency.ts, iterate.ts,
  mappers.ts, assign.ts; typectl.ts is now a pure barrel re-export
- Fix for...in → Object.entries() in iterate (avoids inherited keys)
- Fix recursive ReadableStream pump → iterative while loop (no stack risk)
- Fix pick error test: silent try/catch → expect().rejects.toThrow()
- Add JSDoc to every exported function covering behaviour, concurrency
  semantics, and examples
- Add 11 edge-case tests: empty array/record/stream for iterate, toArray,
  toRecord, toValue, toStream; wrap with zero args; all/each on []
- Fix package.json exports: condition-specific "types" paths for ESM and
  CJS consumers; add "files": ["dist"] whitelist; remove jsx lint-staged glob
- Fix bin/watch to watch both CJS and ESM targets in parallel
- Fix README stale spec example (Jest import → Vitest)
- Rewrite README with motivation, full API reference with examples,
  concurrency table, type export table, compatibility, and dev commands

Made-with: Cursor
@winton winton changed the title Modernize build, test, and packaging infrastructure Modernize, refactor, and document typectl Apr 9, 2026
@winton winton merged commit 596f17c into main Apr 9, 2026
3 checks passed
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.

1 participant