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

Resimplify typesVersions format #572

Merged
merged 2 commits into from Nov 30, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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