Skip to content

refactor: rewrite library in pure TypeScript - #25

Open
tecfu wants to merge 2 commits into
masterfrom
typescript-rewrite
Open

tecfu wants to merge 2 commits into
masterfrom
typescript-rewrite

Conversation

@tecfu

@tecfu tecfu commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Summary

Full rewrite of the library source in pure TypeScript while preserving runtime behavior and the existing unit tests.

Changes

  • src/main.ts / src/terminal-adapter.ts replace the JS sources
  • tsc emits CommonJS + declaration files + source maps into dist/
  • package.json: maindist/main.js, typesdist/main.d.ts, bindist/terminal-adapter.js
  • Typed SmartwrapOptions (exposed as smartwrap.Options)
  • Ambient modules for breakword and wcwidth
  • pretest / prepublishOnly run the build
  • CI builds with tsc then runs tests on Node 14–26
  • Engines set to Node ≥ 14 (TypeScript 5)
  • README updated for TypeScript consumers

Public API

import smartwrap = require('smartwrap')
smartwrap('宽字符', { width: 2 })

Behavior for supported inputs is unchanged; all 25 existing unit tests pass after compile.

Test plan

  • npm run build (tsc clean)
  • npm test — 25 passing
  • CI green on Node 14–26
  • npm pack contains dist/*.js + dist/*.d.ts and no src/*.ts

- Convert src/main.js and src/terminal-adapter.js to TypeScript
- Add tsconfig with strict mode; emit CJS + .d.ts + source maps to dist/
- Export SmartwrapOptions via namespace on the default export
- Ship types via package.json "types": "dist/main.d.ts"
- Build on pretest / prepublishOnly; CI runs tsc before tests
- Raise engines to Node >= 14 (TypeScript 5 toolchain)
- Drop Node 12 from CI matrix; keep 14–26
- Document TypeScript usage in README
- Emit dist/esm (type:module) and dist/cjs (type:commonjs)
- package.json \"exports\" maps import → ESM and require → CJS
- Default + named export: import smartwrap from '…' / import { smartwrap }
- CJS interop so require('smartwrap') still returns the function
- export interface SmartwrapOptions for TypeScript consumers
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