Skip to content

refactor: rewrite library in pure TypeScript - #25

Merged
tecfu merged 4 commits into
masterfrom
typescript-rewrite
Sep 20, 2026
Merged

tecfu merged 4 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: main → dist/main.js, types → dist/main.d.ts, bin → dist/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
Replace the breakword re-queue path with single-pass chunking so a long
token (URL, hash, base64) is O(n) instead of O(n^2). Drop the now-unused
breakword dependency and ambient module.
src/main.js was deleted in the TypeScript rewrite; the one-pass long-word
fix from #26 is already ported in src/main.ts (33dcca0). Keep the JS
file removed.
@tecfu
tecfu merged commit b5b3d55 into master Sep 20, 2026
8 checks passed
tecfu added a commit that referenced this pull request Sep 20, 2026
Closes #19.

Library users who only need text wrapping no longer pull in yargs or the
CLI binary.

- smartwrap (root): core TypeScript library only (strip-ansi, wcwidth)
- packages/smartwrap-cli: separate package with the smartwrap bin + yargs
- Remove src/terminal-adapter.ts and bin field from the core package
- README documents the install matrix

Rebased onto master after the TypeScript rewrite (#25) and long-word
perf fix (#26).
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