Repository navigation
Convert to a TypeScript project, ship ESM only - #98
Merged
Merged
Conversation
Source is now src/diff3.ts with its types inline, replacing the hand-written src/diff3.d.ts. Declarations are generated by tsc into dist/ts/ under isolatedDeclarations; Bun.build writes the ESM and IIFE bundles into dist/js/. - Replace `any` with generics; inputs accept readonly arrays - Add IStrippedPatchRes so stripPatch() output type-checks with patch() - Make MergeRegion a discriminated union of ok and conflict regions - Drop the CJS build; require() loads the ESM build (Node 20.19+/22.12+) - Add a `bun` export condition pointing at the TypeScript source - Convert tests to TypeScript with whole-result assertions - Add tsconfig.build.json and a check:types script BREAKING CHANGE: CommonJS build removed; the IIFE moves to dist/js/diff3.iife.js; MergeRegion is now a type alias union. Co-Authored-By: Claude Opus 5.5 <[email protected]>
TypeScript 7 no longer includes @types packages automatically. The Bun globals only type-checked because scripts/clean.ts imports from bun. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Converts node-diff3 to a TypeScript project and drops the CommonJS build. Targets v4.
src/diff3.mjsis nowsrc/diff3.tswith its types inline, so the hand-writtensrc/diff3.d.tsis gone.tscgenerates the declarations (withisolatedDeclarationson, so the public API can't change by accident), andBun.buildwrites the ESM and IIFE bundles. The layout followslocation-conflation: bundles indist/js/, declarations indist/ts/.Types
any: everything is generic over the buffer item type, and inputs acceptreadonlyarrays. The existingI*type names are kept.IStrippedPatchRes<T>is whatstripPatch()returns andpatch()accepts, so stripped patches type-check now.MergeRegion<T>is a discriminated union of{ ok }and{ conflict }, so checkingregion.oknarrows the type. It's now a type alias, so code thatextends MergeRegionwill need updating.tsconfig.jsonsets"types": ["bun"]. TypeScript 7 no longer loads@types/*packages automatically, and theBunglobal had only been type-checking becausescripts/clean.tshappens to import frombun.Packaging
require()can load the ESM build on Node 20.19+ and 22.12+.requirestays ahead ofbrowser. Otherwise a bundler resolving arequire()call for the browser would pick the IIFE, which has no exports.browseris never chosen overimport. It's kept to point readers at the IIFE.Tests
The tests are now TypeScript and use
node:assert, becausebun:asserthas no type declarations. Most of them compare the whole result at once, which also covers conflictaIndex/oIndex/bIndex(not checked before). The LCS helper now checks that the chain ends at the empty result.Verification
bun run allpasses: lint, types, build, 37 tests, 100% coverage.dist/js/diff3.mjsand the TypeScript source give identical output tomainon 330k random inputs and all benchmark workloads. Performance is unchanged within noise on Bun and Node.bundler,nodenextESM andnodenextCJSrequire()andimportwork on Node 22src/diff3.tsBreaking changes (for the v4 changelog)
require()needs Node 20.19+ or 22.12+.dist/diff3.iife.min.jstodist/js/diff3.iife.min.js. Pages loading@latestfrom the old path will break.MergeRegionis now a discriminated union type alias.===.)No
engines.nodewas added on purpose. npm only warns on a mismatch, but Yarn 1 fails the install outright, even for devDependencies. The minimum is documented in the README instead.🤖 Generated with Claude Code