feat: migrate to TypeScript#28
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrates the package from JavaScript to TypeScript and replaces Jest with Vitest.
Changes
src/index.js->src/index.tswith a typed public API (verify,EncodingResult).src/index.spec.js->src/index.spec.ts, converted from Jest to Vitest (describe/it/expect/vi). The twojschardetmock tests use Vitest's partial-mock pattern (vi.mock+vi.fn/mockReturnValueOnce) since ESM namespace exports cannot be redefined withvi.spyOn.tsconfig.json(CommonJS, ES2020,strict,declaration). Build emits JS todist/and type declarations totypes/.bin/cli.jsand rootindex.jsnow load the compileddist/output.package.json:main->index.js, addedtypes->types/index.d.ts, new scripts (check-ts,prebuild,build,test,coverage),filesnow shipsdist/typesinstead ofsrc. Removedjest/@types/jest; addedtypescript,vitest,@vitest/coverage-v8,@types/node..gitignorenow ignoresdist/,types/,.nyc_output/,tmp/(build artifacts are not committed; they are published via thefilesallowlist).colors(no shipped types) keeps patchingString.prototypeinbin/cli.js; an ambientsrc/colors.d.tsdeclares the accessors used, so no type assertions are needed.Verification
npm run build: passes (emitsdist/index.js,types/index.d.ts).npm run check-ts: passes.npm test(Vitest): 16 passed (16).src/index.tsreports 100% coverage.node bin/cli.js --help,--version, and directory scans all work against the built output.Closes #19
Build and tests pass under vitest.