pkg-bisect
v1.0.0
Published
๐ Binary search tool to find which npm package version introduced a bug
Maintainers
Readme
pkg-bisect ๐
Binary search tool to find which npm package version introduced a bug.
The Problem
You know your tests passed with [email protected] but fail with [email protected]. Which exact version broke it? Manually testing each version is tedious.
The Solution
pkg-bisect uses binary search to efficiently find the first failing version:
pkg-bisect some-package 2.0.0 2.5.0 "npm test"It will:
- Fetch all versions between 2.0.0 and 2.5.0 from npm registry
- Binary search through them
- Install each candidate version
- Run your test command
- Report the exact version where things broke
Installation
npm install -g pkg-bisectUsage
pkg-bisect <package> <good-version> <bad-version> <test-command>Example:
pkg-bisect react 18.2.0 18.3.1 "npm test"Example with custom script:
pkg-bisect lodash 4.17.20 4.17.21 "node my-test.js"How It Works
- Fetch versions from npm registry API
- Filter range between known good and bad versions
- Binary search:
- Test middle version
- If pass โ bug is in newer half
- If fail โ bug is in older half or this one
- Repeat until culprit found
- Report the first version where test fails
Efficiency: For 100 versions, checks only ~7 versions instead of all 100.
Requirements
- Node.js 18+
- npm/yarn in your project
- A reproducible test command that exits with code 0 (pass) or non-zero (fail)
Example Output
๐ฏ Finding regression in some-package
Good: 2.0.0
Bad: 2.5.0
Test: npm test
๐ 12 versions to check
๐ Bisecting 12 versions...
[0...6...11] Testing [email protected]
๐ฆ Installing [email protected]...
๐งช Running: npm test
โ
Test passed
[7...9...11] Testing [email protected]
๐ฆ Installing [email protected]...
๐งช Running: npm test
โ Test failed
[7...8...8] Testing [email protected]
๐ฆ Installing [email protected]...
๐งช Running: npm test
โ
Test passed
๐ FOUND IT!
[email protected] is the first broken version
Previous version (2.4.0) was goodAPI
You can also use it programmatically:
import { pkgBisect } from 'pkg-bisect';
const culprit = await pkgBisect(
'some-package',
'2.0.0',
'2.5.0',
'npm test'
);
console.log(`Broken in: ${culprit}`);License
MIT
Author
Polaroid (@prodigieux)
Built with ๐ค during a 3AM #buildinpublic session
