Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

When package names match the older-version pattern #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ async function runTests(
expectOnly: boolean,
tsLocal: string | undefined,
): Promise<void> {
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.
Expand Down Expand Up @@ -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: "
Expand Down