Skip to content

feat: migrate to TypeScript#28

Merged
piecioshka merged 1 commit into
mainfrom
migrate-to-typescript
Jun 29, 2026
Merged

feat: migrate to TypeScript#28
piecioshka merged 1 commit into
mainfrom
migrate-to-typescript

Conversation

@piecioshka

Copy link
Copy Markdown
Owner

Migrates the package from JavaScript to TypeScript and replaces Jest with Vitest.

Changes

  • src/index.js -> src/index.ts with a typed public API (verify, EncodingResult).
  • src/index.spec.js -> src/index.spec.ts, converted from Jest to Vitest (describe/it/expect/vi). The two jschardet mock tests use Vitest's partial-mock pattern (vi.mock + vi.fn/mockReturnValueOnce) since ESM namespace exports cannot be redefined with vi.spyOn.
  • Added tsconfig.json (CommonJS, ES2020, strict, declaration). Build emits JS to dist/ and type declarations to types/.
  • bin/cli.js and root index.js now load the compiled dist/ output.
  • package.json: main -> index.js, added types -> types/index.d.ts, new scripts (check-ts, prebuild, build, test, coverage), files now ships dist/types instead of src. Removed jest/@types/jest; added typescript, vitest, @vitest/coverage-v8, @types/node.
  • .gitignore now ignores dist/, types/, .nyc_output/, tmp/ (build artifacts are not committed; they are published via the files allowlist).
  • colors (no shipped types) keeps patching String.prototype in bin/cli.js; an ambient src/colors.d.ts declares the accessors used, so no type assertions are needed.

Verification

  • npm run build: passes (emits dist/index.js, types/index.d.ts).
  • npm run check-ts: passes.
  • npm test (Vitest): 16 passed (16). src/index.ts reports 100% coverage.
  • CLI smoke test: node bin/cli.js --help, --version, and directory scans all work against the built output.

Closes #19

Build and tests pass under vitest.

Convert the source and tests from JavaScript to TypeScript and switch the
test runner from Jest to Vitest.

- src/index.js -> src/index.ts with typed public API (verify, EncodingResult)
- src/index.spec.js -> src/index.spec.ts using Vitest
- add tsconfig.json (CommonJS, ES2020, strict, declaration output)
- build to dist/, type declarations to types/
- bin/cli.js and root index.js now load the compiled dist/ output
- replace jest/@types/jest with typescript, vitest and @vitest/coverage-v8

Closes #19
@piecioshka
piecioshka merged commit 53a1533 into main Jun 29, 2026
4 checks passed
@piecioshka
piecioshka deleted the migrate-to-typescript branch June 29, 2026 13:34
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.

Migrate to TypeScript

1 participant