Skip to content

Commit

Permalink
feat: allow overriding install command
Browse files Browse the repository at this point in the history
  • Loading branch information
CarinaChenot committed Apr 28, 2024
1 parent 6bdd21b commit 82f8f1e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ Package Version Bisect works by following a process similar to git bisect. Here'
```bash
npx package-version-bisect --package <package-name> --good <good-version> --bad <bad-version>
```
Where `<package-name>` is the name of the package you want to bisect, `<good-version>` is a known good version of the package, and `<bad-version>` is a known bad version of the package.

From there you will be prompted to test different versions of the package and mark them as good or bad based on whether they exhibit the issue.

<img alt="A screenshot of a terminal to illustrate the prompts when using package-version-bisect" src="https://github.com/CarinaChenot/package-version-bisect/assets/16705167/0f8ee0c0-c8cf-4c0b-9741-c7c8fd660a47" height=80 />

## Reference
| Parameter | Description | Required | Example |
|--------------|--------------------------------------------------------------------------------------------------------|----------|-------------------------|
| `--package` | The name of the package | Yes | `--package my-package` |
| `--good` | A known good version of the package | Yes | `--good 1.0.0` |
| `--bad` | A known bad version of the package | Yes | `--bad 1.2.0` |
| `--install` | Command to run instead of `npm install` (useful when using another package manager or devDependencies) | No | `--install yarn add -D` |

## Future improvements

- Improve algorithm by prioritizing testing major versions
Expand Down
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ function isNotPreRelease(version) {
/**
* Installs a specific version of a package using npm
* @param {string} version
* @param {string} installCommand - command to use when installing the package
*/
function installVersion(version) {
// TODO: add option to use another package manager?
child_process.execSync(`npm install ${pkg}@${version}`);
function installVersion(version, installCommand = 'npm install') {
child_process.execSync(`${installCommand} ${pkg}@${version}`);
}

function ask(version) {
Expand All @@ -48,7 +48,12 @@ function ask(version) {
});
}

const { good, bad, package: pkg } = yargs(process.argv.slice(2)).parse();
const {
good,
bad,
package: pkg,
install: installCommand,
} = yargs(process.argv.slice(2)).parse();

const versionsToCheck = getVersions(pkg, good, bad);

Expand All @@ -59,7 +64,7 @@ while (bisectStart !== bisectEnd) {
const mid = Math.floor((bisectStart + bisectEnd) / 2);
const midVersion = versionsToCheck[mid];

installVersion(midVersion);
installVersion(midVersion, installCommand);

if (await ask(midVersion)) {
bisectStart = mid + 1;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "package-version-bisect",
"version": "0.0.2",
"version": "0.0.3",
"description": "A CLI tool for pinpointing which package version introduced a bug or regression in your project.",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit 82f8f1e

Please sign in to comment.