From 8348ba3b68ae476f7e388a5dffe85ef70fd7e72a Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Fri, 4 Sep 2020 10:44:50 -0700 Subject: [PATCH] When package names match the older-version pattern --- src/index.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1763a56b..f1f22a50 100644 --- a/src/index.ts +++ b/src/index.ts @@ -122,7 +122,8 @@ async function runTests( expectOnly: boolean, tsLocal: string | undefined, ): Promise { - const isOlderVersion = /^v\d+$/.test(basename(dirPath)); + const parent = dirname(dirPath); + const isOlderVersion = basename(parent) !== "types" && /^v\d+(\.\d+)?$/.test(basename(dirPath)); const indexText = await readFile(joinPaths(dirPath, "index.d.ts"), "utf-8"); // If this *is* on DefinitelyTyped, types-publisher will fail if it can't parse the header. @@ -219,13 +220,10 @@ async function testTypesVersion( } function assertPathIsInDefinitelyTyped(dirPath: string): void { + // A DefinitelyTyped package must be a child of a "types" directory, + // or be an older version and a grandchild of a "types" directory const parent = dirname(dirPath); - const types = /^v\d+(\.\d+)?$/.test(basename(dirPath)) ? dirname(parent) : parent; - // TODO: It's not clear whether this assertion makes sense, and it's broken on Azure Pipelines - // Re-enable it later if it makes sense. - // const dt = dirname(types); - // if (basename(dt) !== "DefinitelyTyped" || basename(types) !== "types") { - if (basename(types) !== "types") { + if (basename(parent) !== "types" && (basename(dirname(parent)) !== "types" || !/^v\d+(\.\d+)?$/.test(basename(dirPath)))) { throw new Error("Since this type definition includes a header (a comment starting with `// Type definitions for`), " + "assumed this was a DefinitelyTyped package.\n" + "But it is not in a `DefinitelyTyped/types/xxx` directory: "