Skip to content

Commit

Permalink
build: drop typanion
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Aug 6, 2024
1 parent e1ab693 commit 59cbc95
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 83 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"reflect-metadata": "0.2.2",
"semver": "7.6.3",
"simple-git": "3.25.0",
"typanion": "3.14.0",
"zod": "3.23.8"
},
"devDependencies": {
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

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

12 changes: 4 additions & 8 deletions src/cli/command/install-tool.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is';
import { Command, Option } from 'clipanion';
import prettyMilliseconds from 'pretty-ms';
import * as t from 'typanion';
import {
type InstallToolType,
installTool,
resolveVersion,
} from '../install-tool';
import { DeprecatedTools, ResolverMap } from '../tools';
import { logger, validateVersion } from '../utils';
import { logger } from '../utils';
import { MissingVersion } from '../utils/codes';
import { getVersion, isToolIgnored } from './utils';

Expand All @@ -31,10 +30,7 @@ export class InstallToolCommand extends Command {

dryRun = Option.Boolean('-d,--dry-run', false);

version = Option.String({
validator: t.cascade(t.isString(), validateVersion()),
required: false,
});
version = Option.String({ required: false });

protected type: InstallToolType | undefined;

Expand All @@ -46,7 +42,7 @@ export class InstallToolCommand extends Command {
return 0;
}

let version = this.version;
let version = this.version?.replace(/^v/, ''); // trim optional 'v' prefix

let type = DeprecatedTools[this.name];

Expand All @@ -59,7 +55,7 @@ export class InstallToolCommand extends Command {
}

if (!isNonEmptyStringAndNotWhitespace(version)) {
version = getVersion(this.name);
version = getVersion(this.name)?.replace(/^v/, ''); // trim optional 'v' prefix
}

logger.debug(
Expand Down
28 changes: 2 additions & 26 deletions src/cli/utils/versions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test, vi } from 'vitest';
import { isValid, parse, validateSemver, validateVersion } from './versions';
import { describe, expect, test } from 'vitest';
import { isValid, parse } from './versions';

describe('versions', () => {
test('isValid', () => {
Expand All @@ -11,28 +11,4 @@ describe('versions', () => {
expect(parse('1.0.0')).not.toBeNull();
expect(() => parse('abc')).toThrow('Invalid version: abc');
});

test('validateSemver', () => {
expect(validateSemver()('1.0.0', {})).toBe(true);
expect(
validateSemver()('1.0.0', { coercion: vi.fn(), coercions: [] }),
).toBe(true);

expect(validateSemver()('1.0.0', { coercions: [], errors: [] })).toBe(
false,
);
expect(validateSemver()('abc', { errors: [] })).toBe(false);
});

test('validateVersion', () => {
expect(validateVersion()('1.0.0', {})).toBe(true);
expect(
validateVersion()('v1.0.0', { coercion: vi.fn(), coercions: [] }),
).toBe(true);

expect(validateVersion()('v1.0.0', { coercions: [], errors: [] })).toBe(
false,
);
// expect(validateVersion()('abc', { errors: [] })).toBe(false);
});
});
45 changes: 0 additions & 45 deletions src/cli/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import semverParse from 'semver/functions/parse';
import semverSatisfies from 'semver/functions/satisfies';
import semverSort from 'semver/functions/sort';
import semverValid from 'semver/functions/valid';
import { type StrictValidator, makeValidator } from 'typanion';

export { semverGte, semverSort, semverCoerce, semverSatisfies };

Expand All @@ -20,47 +19,3 @@ export function parse(version: string | undefined): SemVer {
}
return res;
}

export function validateSemver(): StrictValidator<string, string> {
return makeValidator<string, string>({
test: (value, state): value is string => {
const version = semverValid(value);
if (version !== null) {
if (state?.coercions) {
if (!state.coercion) {
state.errors?.push(`${state?.p ?? '.'}: Unbound coercion result`);
return false;
}
state.coercions.push([
state.p ?? '.',
state.coercion.bind(null, version),
]);
}
return true;
}

state?.errors?.push(`${state?.p ?? '.'}: must be a valid semver version`);
return false;
},
});
}

export function validateVersion(): StrictValidator<string, string> {
return makeValidator<string, string>({
test: (value, state): value is string => {
if (value.startsWith('v')) {
if (state?.coercions) {
if (!state.coercion) {
state.errors?.push(`${state?.p ?? '.'}: Unbound coercion result`);
return false;
}
state.coercions.push([
state.p ?? '.',
state.coercion.bind(null, value.slice(1)),
]);
}
}
return true;
},
});
}

0 comments on commit 59cbc95

Please sign in to comment.