mirror of
https://github.com/chenasraf/DefinitelyTyped-tools.git
synced 2026-05-18 01:49:03 +00:00
Add additional functions for use with typesVersions
This commit is contained in:
committed by
Andrew Branch
parent
dfe935d206
commit
f466802083
@@ -1,3 +1,4 @@
|
||||
import assert = require("assert");
|
||||
import pm = require("parsimmon");
|
||||
|
||||
/*
|
||||
@@ -10,14 +11,16 @@ Example:
|
||||
*/
|
||||
|
||||
/** Parse-able TypeScript versions. Only add to this list if we will support this version on DefinitelyTyped. */
|
||||
export type TypeScriptVersion = "2.0" | "2.1" | "2.2" | "2.3" | "2.4" | "2.5" | "2.6" | "2.7" | "2.8" | "2.9";
|
||||
export type TypeScriptVersion =
|
||||
"2.0" | "2.1" | "2.2" | "2.3" | "2.4" | "2.5" | "2.6" | "2.7" | "2.8" | "2.9" | "3.0" | "3.1";
|
||||
export namespace TypeScriptVersion {
|
||||
export const all: ReadonlyArray<TypeScriptVersion> = ["2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8", "2.9"];
|
||||
export const all: ReadonlyArray<TypeScriptVersion> =
|
||||
["2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8", "2.9", "3.0", "3.1"];
|
||||
export const lowest = all[0];
|
||||
/** Latest version that may be specified in a `// TypeScript Version:` header. */
|
||||
export const latest = all[all.length - 1];
|
||||
|
||||
/** True if a package with the given typescript version should be published as prerelease. */
|
||||
/** @deprecated */
|
||||
export function isPrerelease(_version: TypeScriptVersion): boolean {
|
||||
return false;
|
||||
}
|
||||
@@ -39,6 +42,7 @@ export namespace TypeScriptVersion {
|
||||
"ts2.9",
|
||||
"ts3.0",
|
||||
"ts3.1",
|
||||
"ts3.2",
|
||||
"latest",
|
||||
];
|
||||
|
||||
@@ -50,6 +54,16 @@ export namespace TypeScriptVersion {
|
||||
if (idx === -1) { throw new Error(); }
|
||||
return allTags.slice(idx);
|
||||
}
|
||||
|
||||
export function previous(v: TypeScriptVersion): TypeScriptVersion | undefined {
|
||||
const index = all.indexOf(v);
|
||||
assert(index !== -1);
|
||||
return index === 0 ? undefined : all[index - 1];
|
||||
}
|
||||
|
||||
export function isRedirectable(v: TypeScriptVersion): boolean {
|
||||
return all.indexOf(v) >= all.indexOf("3.1");
|
||||
}
|
||||
}
|
||||
|
||||
export interface Header {
|
||||
@@ -61,7 +75,11 @@ export interface Header {
|
||||
readonly contributors: ReadonlyArray<Author>;
|
||||
}
|
||||
|
||||
export interface Author { name: string; url: string; githubUsername: string | undefined; }
|
||||
export interface Author {
|
||||
readonly name: string;
|
||||
readonly url: string;
|
||||
readonly githubUsername: string | undefined;
|
||||
}
|
||||
|
||||
export interface ParseError {
|
||||
readonly index: number;
|
||||
@@ -70,6 +88,20 @@ export interface ParseError {
|
||||
readonly expected: ReadonlyArray<string>;
|
||||
}
|
||||
|
||||
export function isTypeScriptVersion(str: string): str is TypeScriptVersion {
|
||||
return TypeScriptVersion.all.includes(str as TypeScriptVersion);
|
||||
}
|
||||
|
||||
export function makeTypesVersionsForPackageJson(typesVersions: ReadonlyArray<TypeScriptVersion>): unknown {
|
||||
if (typesVersions.length === 0) { return undefined; }
|
||||
|
||||
const out: { [key: string]: { readonly "*": ReadonlyArray<string> } } = {};
|
||||
for (const version of typesVersions) {
|
||||
out[`>=${version}.0-0`] = { "*": [`ts${version}/*`] };
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function parseHeaderOrFail(mainFileContent: string): Header {
|
||||
const header = parseHeader(mainFileContent, /*strict*/false);
|
||||
if (isParseError(header)) {
|
||||
|
||||
572
packages/definitelytyped-header-parser/package-lock.json
generated
572
packages/definitelytyped-header-parser/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -77,7 +77,9 @@ describe("parseTypeScriptVersionLine", () => {
|
||||
|
||||
describe("tagsToUpdate", () => {
|
||||
it("works", () => {
|
||||
assert.deepEqual(TypeScriptVersion.tagsToUpdate("2.5"), ["ts2.5", "ts2.6", "ts2.7", "ts2.8", "ts2.9", "latest"]);
|
||||
assert.deepEqual(
|
||||
TypeScriptVersion.tagsToUpdate("2.5"),
|
||||
["ts2.5", "ts2.6", "ts2.7", "ts2.8", "ts2.9", "ts3.0", "ts3.1", "ts3.2", "latest"]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user