Skip to content

Commit

Permalink
Resimplify typesVersions format (#572)
Browse files Browse the repository at this point in the history
* Resimplify typesVersions format

Undoes #536. Needs a matching PR on Definitely Typed before it's ready
to go. (Insert PR number here)

* delete mistakenly added script
  • Loading branch information
sandersn committed Nov 30, 2022
1 parent 906412b commit 9fd0ee5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
5 changes: 1 addition & 4 deletions packages/header-parser/src/index.ts
@@ -1,6 +1,5 @@
import pm = require("parsimmon");
import { AllTypeScriptVersion, TypeScriptVersion } from "@definitelytyped/typescript-versions";
import assert = require("assert");

/*
Expand Down Expand Up @@ -46,9 +45,7 @@ export function makeTypesVersionsForPackageJson(typesVersions: readonly TypeScri
oldestFirst.sort((v1, v2) => (v1 > v2 ? 1 : v1 < v2 ? -1 : 0));
const out: { [key: string]: { readonly "*": readonly string[] } } = {};
for (const version of oldestFirst) {
const next = TypeScriptVersion.next(version);
assert(!!next, `ts${version} is too new: it covers all versions of typescript`);
out[`<${next}.0-0`] = { "*": [`ts${version}/*`] };
out[`<=${version}`] = { "*": [`ts${version}/*`] };
}
return out;
}
Expand Down
19 changes: 7 additions & 12 deletions packages/header-parser/test/index.test.ts
Expand Up @@ -204,24 +204,24 @@ describe("makeTypesVersionsForPackageJson", () => {
});
it("works for one version", () => {
expect(makeTypesVersionsForPackageJson(["4.3"])).toEqual({
"<4.4.0-0": {
"<=4.3": {
"*": ["ts4.3/*"],
},
});
});
it("orders versions old to new with old-to-new input", () => {
expect(JSON.stringify(makeTypesVersionsForPackageJson(["4.2", "4.3", "4.6"]), undefined, 4)).toEqual(`{
"<4.3.0-0": {
"<=4.2": {
"*": [
"ts4.2/*"
]
},
"<4.4.0-0": {
"<=4.3": {
"*": [
"ts4.3/*"
]
},
"<4.7.0-0": {
"<=4.6": {
"*": [
"ts4.6/*"
]
Expand All @@ -230,28 +230,23 @@ describe("makeTypesVersionsForPackageJson", () => {
});
it("orders versions old to new with new-to-old input", () => {
expect(JSON.stringify(makeTypesVersionsForPackageJson(["4.6", "4.3", "4.2"]), undefined, 4)).toEqual(`{
"<4.3.0-0": {
"<=4.2": {
"*": [
"ts4.2/*"
]
},
"<4.4.0-0": {
"<=4.3": {
"*": [
"ts4.3/*"
]
},
"<4.7.0-0": {
"<=4.6": {
"*": [
"ts4.6/*"
]
}
}`);
});
it("asserts when trying to redirect from newest version and below", () => {
expect(() => makeTypesVersionsForPackageJson(["5.0"])).toThrow(
/ts5.0 is too new: it covers all versions of typescript/
);
});
});

function dedent(strings: TemplateStringsArray): string {
Expand Down

0 comments on commit 9fd0ee5

Please sign in to comment.