Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly detect npm 10 as supported #241

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/api/aws/AwsCliDetector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IProcessRunner } from "../../process/IProcessRunner.ts";
import { ProcessResultWithOutput } from "../../process/ProcessRunnerResult.ts";
import { CliDetector } from "../CliDetector.ts";
import * as semver from "std/semver";

export class AwsCliDetector extends CliDetector {
constructor(runner: IProcessRunner<ProcessResultWithOutput>) {
Expand All @@ -16,7 +17,6 @@ export class AwsCliDetector extends CliDetector {
}

protected isSupportedVersion(version: string): boolean {
// a simple lexicographic comparison is sufficient for our needs
return version > "2.0.0";
return semver.satisfies(version, ">=2.0.0");
}
}
4 changes: 2 additions & 2 deletions src/api/az/AzCliDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { parseJsonWithLog } from "../../json.ts";
import { IProcessRunner } from "../../process/IProcessRunner.ts";
import { ProcessResultWithOutput } from "../../process/ProcessRunnerResult.ts";
import { CliDetector } from "../CliDetector.ts";
import * as semver from "std/semver";

export class AzCliDetector extends CliDetector {
constructor(runner: IProcessRunner<ProcessResultWithOutput>) {
Expand All @@ -20,7 +21,6 @@ export class AzCliDetector extends CliDetector {
}

protected isSupportedVersion(version: string): boolean {
// a simple lexicographic comparison is sufficient for our needs
return version > "2.0.0";
return semver.satisfies(version, ">2.0.0");
}
}
4 changes: 2 additions & 2 deletions src/api/gcloud/GcloudCliDetector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IProcessRunner } from "../../process/IProcessRunner.ts";
import { ProcessResultWithOutput } from "../../process/ProcessRunnerResult.ts";
import { CliDetector } from "../CliDetector.ts";
import * as semver from "std/semver";

export class GcloudCliDetector extends CliDetector {
constructor(runner: IProcessRunner<ProcessResultWithOutput>) {
Expand All @@ -16,7 +17,6 @@ export class GcloudCliDetector extends CliDetector {
}

protected isSupportedVersion(version: string): boolean {
// a simple lexicographic comparison is sufficient for our needs
return version > "200.0.0";
return semver.satisfies(version, ">200.0.0");
}
}
4 changes: 2 additions & 2 deletions src/api/git/GitCliDetector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IProcessRunner } from "../../process/IProcessRunner.ts";
import { ProcessResultWithOutput } from "../../process/ProcessRunnerResult.ts";
import { CliDetector } from "../CliDetector.ts";
import * as semver from "std/semver";

export class GitCliDetector extends CliDetector {
constructor(runner: IProcessRunner<ProcessResultWithOutput>) {
Expand All @@ -18,7 +19,6 @@ export class GitCliDetector extends CliDetector {

protected isSupportedVersion(version: string): boolean {
// a simple lexicographic comparison is sufficient for our needs

return version > "2.0.0";
return semver.satisfies(version, ">=2.0.0");
}
}
49 changes: 49 additions & 0 deletions src/api/npm/NpmCliDetector.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { assertEquals } from "std/testing/assert";
import { StubProcessRunner } from "../../process/StubProcessRunner.ts";
import { InstallationStatus } from "../CliInstallationStatus.ts";
import { NpmCliDetector } from "./NpmCliDetector.ts";

Deno.test("detects npm cli version correct", async () => {
const runner = new StubProcessRunner();
const sut = new NpmCliDetector(runner);

runner.setupResult({
stdout: "8.19.2",
});

const result = await sut.detect();

assertEquals(result.status, InstallationStatus.Installed);
if (result.status == InstallationStatus.Installed) {
assertEquals(result.version, "8.19.2");
}
});

Deno.test("detects npm cli version correct also for npm > 10", async () => {
const runner = new StubProcessRunner();
const sut = new NpmCliDetector(runner);

runner.setupResult({
stdout: "10.1.2",
});

const result = await sut.detect();

assertEquals(result.status, InstallationStatus.Installed);
if (result.status == InstallationStatus.Installed) {
assertEquals(result.version, "10.1.2");
}
});

Deno.test("detects unsupported npm cli versions", async () => {
const runner = new StubProcessRunner();
const sut = new NpmCliDetector(runner);

runner.setupResult({
stdout: "6.1.2",
});

const result = await sut.detect();

assertEquals(result.status, InstallationStatus.UnsupportedVersion);
});
3 changes: 2 additions & 1 deletion src/api/npm/NpmCliDetector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IProcessRunner } from "../../process/IProcessRunner.ts";
import { ProcessResultWithOutput } from "../../process/ProcessRunnerResult.ts";
import { CliDetector } from "../CliDetector.ts";
import * as semver from "std/semver";

export class NpmCliDetector extends CliDetector {
constructor(runner: IProcessRunner<ProcessResultWithOutput>) {
Expand All @@ -12,6 +13,6 @@ export class NpmCliDetector extends CliDetector {
}

protected isSupportedVersion(version: string): boolean {
return version >= "8.0.0";
return semver.satisfies(version, ">=8.0.0");
}
}
3 changes: 2 additions & 1 deletion src/api/terraform-docs/TerraformDocsCliDetector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IProcessRunner } from "../../process/IProcessRunner.ts";
import { ProcessResultWithOutput } from "../../process/ProcessRunnerResult.ts";
import { CliDetector } from "../CliDetector.ts";
import * as semver from "std/semver";

export class TerraformDocsCliDetector extends CliDetector {
constructor(runner: IProcessRunner<ProcessResultWithOutput>) {
Expand All @@ -12,6 +13,6 @@ export class TerraformDocsCliDetector extends CliDetector {
}

protected isSupportedVersion(version: string): boolean {
return version > "v0.10.0";
return semver.satisfies(version, ">=0.10.0");
}
}
3 changes: 2 additions & 1 deletion src/api/terraform/TerraformCliDetector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IProcessRunner } from "../../process/IProcessRunner.ts";
import { ProcessResultWithOutput } from "../../process/ProcessRunnerResult.ts";
import { CliDetector } from "../CliDetector.ts";
import * as semver from "std/semver";

export class TerraformCliDetector extends CliDetector {
constructor(runner: IProcessRunner<ProcessResultWithOutput>) {
Expand All @@ -12,6 +13,6 @@ export class TerraformCliDetector extends CliDetector {
}

protected isSupportedVersion(version: string): boolean {
return version > "v1.0.0";
return semver.satisfies(version, ">=1.0.0");
}
}
3 changes: 2 additions & 1 deletion src/api/terragrunt/TerragruntCliDetector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IProcessRunner } from "../../process/IProcessRunner.ts";
import { ProcessResultWithOutput } from "../../process/ProcessRunnerResult.ts";
import { CliDetector } from "../CliDetector.ts";
import * as semver from "std/semver";

export class TerragruntCliDetector extends CliDetector {
constructor(runner: IProcessRunner<ProcessResultWithOutput>) {
Expand All @@ -15,6 +16,6 @@ export class TerragruntCliDetector extends CliDetector {

protected isSupportedVersion(version: string): boolean {
// required for "--terragrunt-no-auto-apply" option, see https://github.com/gruntwork-io/terragrunt/pull/2156
return version >= "v0.38.1";
return semver.satisfies(version, ">=0.38.1");
}
}
1 change: 1 addition & 0 deletions src/import_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"std/collections/distinct": "https://deno.land/std@0.170.0/collections/distinct.ts",
"std/fmt/colors": "https://deno.land/std@0.170.0/fmt/colors.ts",
"std/encoding/yaml": "https://deno.land/std@0.170.0/encoding/yaml.ts",
"std/semver": "https://deno.land/std@0.170.0/semver/mod.ts",
"std/testing/assert": "https://deno.land/std@0.170.0/testing/asserts.ts",
"std/testing/mock": "https://deno.land/std@0.170.0/testing/mock.ts",
"x/json_tree": "https://deno.land/x/json_tree@latest/mod.ts",
Expand Down