From d4bdbd09ec8038426e8788df8a19c61ad52a1af9 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:49:11 -0800 Subject: [PATCH 01/16] Test on all OSs --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3d6280d0e..d655a3ce08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,11 @@ defaults: jobs: build_and_test: name: build and test - runs-on: ubuntu-latest + strategy: + matrix: + version: [10, 12, 14] + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 From f49ba15329a05a70db4f583a45d3f5e3499a7a79 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:50:29 -0800 Subject: [PATCH 02/16] remove oops --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d655a3ce08..bc7107bd70 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,6 @@ jobs: name: build and test strategy: matrix: - version: [10, 12, 14] os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: From c6445c8e33e16cf84ffc521e7adb10d093393ff7 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:53:52 -0800 Subject: [PATCH 03/16] no fail fast --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc7107bd70..6c841c9488 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: build_and_test: name: build and test strategy: + fail-fast: true matrix: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} From 97dec583b73d72944cc99c14d487f4f870110078 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:56:47 -0800 Subject: [PATCH 04/16] I am dumb --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c841c9488..e5355955f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: build_and_test: name: build and test strategy: - fail-fast: true + fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} From be9d181adf72263be74db51ae404ee3b4b97eae6 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:08:31 -0800 Subject: [PATCH 05/16] Normalize baseline slashes --- packages/eslint-plugin/test/eslint.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/test/eslint.test.ts b/packages/eslint-plugin/test/eslint.test.ts index ec624c4e42..d73be324a7 100644 --- a/packages/eslint-plugin/test/eslint.test.ts +++ b/packages/eslint-plugin/test/eslint.test.ts @@ -6,6 +6,7 @@ import { fixtureRoot } from "./util"; import { toMatchFile } from "jest-file-snapshot"; import * as plugin from "../src/index"; import fs from "fs"; +import { normalizeSlashes } from "@definitelytyped/utils"; expect.extend({ toMatchFile }); const snapshotDir = path.join(__dirname, "__file_snapshots__"); @@ -74,7 +75,7 @@ function formatResultsWithInlineErrors(results: ESLint.LintResult[]): string { const indent = " "; for (const result of results) { - output.push(`==== ${result.filePath} ====`); + output.push(`==== ${normalizeSlashes(result.filePath)} ====`); output.push(""); const sourceText = fs.readFileSync(path.join(fixtureRoot, result.filePath), "utf-8"); From 0f385ce619da07df9c7bdae1888b306b1daf9a6f Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:13:38 -0800 Subject: [PATCH 06/16] Maybe it's line endings --- packages/eslint-plugin/test/eslint.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/test/eslint.test.ts b/packages/eslint-plugin/test/eslint.test.ts index d73be324a7..fc94899c1b 100644 --- a/packages/eslint-plugin/test/eslint.test.ts +++ b/packages/eslint-plugin/test/eslint.test.ts @@ -108,7 +108,12 @@ function formatResultsWithInlineErrors(results: ESLint.LintResult[]): string { output.push(""); } - return output.join("\n").trim() + "\n"; + return ( + output + .map((o) => o.replace(/\r?\n/g, "\n")) + .join("\n") + .trim() + "\n" + ); } // Similar to https://github.com/storybookjs/storybook/blob/df357020e010f49e7c325942f0c891e6702527d6/code/addons/storyshots-core/src/api/integrityTestTemplate.ts From 76643994a9d7395559bf79befc8dba127c1823e0 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:20:08 -0800 Subject: [PATCH 07/16] attempt to ensure that files are checked out as-is --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..fa1385d99a --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* -text From c432a429ad8496d5d4f91c55a29d235fbea9ab8e Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:39:24 -0800 Subject: [PATCH 08/16] attempt to fix more --- packages/eslint-plugin/test/eslint.test.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/eslint-plugin/test/eslint.test.ts b/packages/eslint-plugin/test/eslint.test.ts index fc94899c1b..38e725c123 100644 --- a/packages/eslint-plugin/test/eslint.test.ts +++ b/packages/eslint-plugin/test/eslint.test.ts @@ -51,11 +51,23 @@ for (const fixture of allFixtures) { const resultText = stripAnsi(formatted).trim() || "No errors"; expect(resultText).not.toContain("Parsing error"); const newOutput = formatResultsWithInlineErrors(results); - expect(resultText + "\n\n" + newOutput).toMatchFile(getLintSnapshotPath(fixture)); + expect(normalizeSnapshot(resultText + "\n\n" + newOutput)).toMatchFile(getLintSnapshotPath(fixture)); }); }); } +function normalizeSnapshot(snapshot: string): string { + return snapshot + .split(/\r?\n/g) + .map((line) => { + if (line.startsWith("types\\")) { + return normalizeSlashes(line); + } + return line; + }) + .join("\n"); +} + function formatResultsWithInlineErrors(results: ESLint.LintResult[]): string { const output: string[] = []; @@ -108,12 +120,7 @@ function formatResultsWithInlineErrors(results: ESLint.LintResult[]): string { output.push(""); } - return ( - output - .map((o) => o.replace(/\r?\n/g, "\n")) - .join("\n") - .trim() + "\n" - ); + return output.join("\n").trim() + "\n"; } // Similar to https://github.com/storybookjs/storybook/blob/df357020e010f49e7c325942f0c891e6702527d6/code/addons/storyshots-core/src/api/integrityTestTemplate.ts From 2d1e35b2ce87008b11c99b989724dab3e897609b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 15:12:52 -0800 Subject: [PATCH 09/16] jest baffles me --- tsconfig.test.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tsconfig.test.json b/tsconfig.test.json index 4da564fa2f..7d094e189b 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -7,9 +7,17 @@ }, "files": [], "references": [ - { "path": "packages/header-parser/test" }, { "path": "packages/definitions-parser/test" }, + { "path": "packages/dts-critic" }, + { "path": "packages/dts-gen" }, + { "path": "packages/dtslint/test" }, + { "path": "packages/dtslint-runner" }, + { "path": "packages/eslint-plugin/test" }, + { "path": "packages/header-parser/test" }, { "path": "packages/publisher/test" }, - { "path": "packages/utils/test" } + { "path": "packages/retag" }, + { "path": "packages/typescript-packages/test" }, + { "path": "packages/typescript-versions/test" }, + { "path": "packages/utils/test" }, ] } From 87de946c722e91ad76233397639718dd85e04dfb Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 15:20:49 -0800 Subject: [PATCH 10/16] Fix incorrect use of path lib in fs.ts --- packages/utils/src/fs.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/utils/src/fs.ts b/packages/utils/src/fs.ts index 4d69779f45..6b8e87ec19 100644 --- a/packages/utils/src/fs.ts +++ b/packages/utils/src/fs.ts @@ -1,12 +1,12 @@ import assert from "assert"; -import { join, relative, resolve, isAbsolute } from "path"; +import systemPath, { posix as posixPath } from "path"; import getCacheDir = require("cachedir"); import { assertDefined } from "./assertions"; import fs from "fs"; import { readFileSync, readJsonSync } from "./io"; /** The directory to read/write suggestsions from */ -export const suggestionsDir = join(getCacheDir("dts"), "suggestions"); +export const suggestionsDir = systemPath.join(getCacheDir("dts"), "suggestions"); /** Convert a path to use "/" instead of "\\" for consistency. (This affects content hash.) */ export function normalizeSlashes(path: string): string { @@ -91,7 +91,7 @@ export class InMemoryFS implements FS { private tryGetEntry(path: string): ReadonlyDir | string | undefined { if (path[0] === "/") { - path = relative(this.rootPrefix, path); + path = posixPath.relative(this.rootPrefix, path); } if (path === "") { return this.curDir; @@ -162,7 +162,7 @@ export class InMemoryFS implements FS { subDir(path: string): FS { assert(path[0] !== "/", "Cannot use absolute paths with InMemoryFS.subDir"); - return new InMemoryFS(this.getDir(path), resolve(this.rootPrefix, path)); + return new InMemoryFS(this.getDir(path), posixPath.join(this.rootPrefix, path)); } debugPath(): string { @@ -179,12 +179,12 @@ export class InMemoryFS implements FS { export class DiskFS implements FS { constructor(private readonly rootPrefix: string) { - assert(isAbsolute(rootPrefix), "DiskFS must use absolute paths"); + assert(systemPath.isAbsolute(rootPrefix), "DiskFS must use absolute paths"); this.rootPrefix = ensureTrailingSlash(rootPrefix); } private getPath(path: string | undefined): string { - return resolve(this.rootPrefix, path ?? ""); + return systemPath.resolve(this.rootPrefix, path ?? ""); } readdir(dirPath?: string): readonly string[] { From a80dc035319f5bc8a6669a798322abcf1fe032bc Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 15:48:41 -0800 Subject: [PATCH 11/16] Shift around absolute checks --- packages/definitions-parser/src/get-affected-packages.ts | 6 ++++-- packages/dtslint-runner/src/main.ts | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/definitions-parser/src/get-affected-packages.ts b/packages/definitions-parser/src/get-affected-packages.ts index 701c66bc7a..28a2a0a642 100644 --- a/packages/definitions-parser/src/get-affected-packages.ts +++ b/packages/definitions-parser/src/get-affected-packages.ts @@ -1,7 +1,8 @@ import { assertDefined, execAndThrowErrors, mapDefined, normalizeSlashes, withoutStart } from "@definitelytyped/utils"; import { AllPackages, PackageId, formatTypingVersion, getDependencyFromFile } from "./packages"; -import { resolve } from "path"; +import { isAbsolute, resolve } from "path"; import { satisfies } from "semver"; +import assert from "assert"; export interface PreparePackagesResult { readonly packageNames: Set; readonly dependents: Set; @@ -77,7 +78,8 @@ export async function getAffectedPackagesWorker( dependentOutputs: string[], definitelyTypedPath: string, ): Promise { - const dt = resolve(definitelyTypedPath); + assert(isAbsolute(definitelyTypedPath), "definitelyTypedPath should be absolute"); + const dt = definitelyTypedPath; const changedDirs = mapDefined(changedOutput.split("\n"), getDirectoryName(dt)); const dependentDirs = mapDefined(dependentOutputs.join("\n").split("\n"), getDirectoryName(dt)); const packageNames = new Set([ diff --git a/packages/dtslint-runner/src/main.ts b/packages/dtslint-runner/src/main.ts index ff74d49247..d1ce81ac41 100644 --- a/packages/dtslint-runner/src/main.ts +++ b/packages/dtslint-runner/src/main.ts @@ -9,6 +9,7 @@ import fs from "fs"; import { RunDTSLintOptions } from "./types"; import { prepareAllPackages } from "./prepareAllPackages"; import { prepareAffectedPackages } from "./prepareAffectedPackages"; +import { resolve } from "path"; export async function runDTSLint({ definitelyTypedAcquisition, @@ -36,6 +37,7 @@ export async function runDTSLint({ } else { definitelyTypedPath = definitelyTypedAcquisition.path; } + definitelyTypedPath = resolve(definitelyTypedPath); if (!fs.existsSync(definitelyTypedPath)) { throw new Error(`Path '${definitelyTypedPath}' does not exist.`); From db655996926b157eb9738923db2fa31493649464 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 15:51:32 -0800 Subject: [PATCH 12/16] Remove dead code --- packages/definitions-parser/src/get-affected-packages.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/definitions-parser/src/get-affected-packages.ts b/packages/definitions-parser/src/get-affected-packages.ts index 28a2a0a642..cd8be93663 100644 --- a/packages/definitions-parser/src/get-affected-packages.ts +++ b/packages/definitions-parser/src/get-affected-packages.ts @@ -1,6 +1,6 @@ import { assertDefined, execAndThrowErrors, mapDefined, normalizeSlashes, withoutStart } from "@definitelytyped/utils"; import { AllPackages, PackageId, formatTypingVersion, getDependencyFromFile } from "./packages"; -import { isAbsolute, resolve } from "path"; +import { isAbsolute } from "path"; import { satisfies } from "semver"; import assert from "assert"; export interface PreparePackagesResult { From d473c459267640f80f82a4243054fa0c9dada4be Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:00:18 -0800 Subject: [PATCH 13/16] Fix most path issues in no-bad-references --- packages/eslint-plugin/src/rules/no-bad-reference.ts | 7 +++---- packages/eslint-plugin/src/util.ts | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-bad-reference.ts b/packages/eslint-plugin/src/rules/no-bad-reference.ts index 90ac5e2533..7f59445a41 100644 --- a/packages/eslint-plugin/src/rules/no-bad-reference.ts +++ b/packages/eslint-plugin/src/rules/no-bad-reference.ts @@ -88,8 +88,7 @@ const rule = createRule({ ) : ref.text; - const resolved = path.resolve(containingDirectory, p); - const otherPackage = findTypesPackage(resolved); + const otherPackage = findTypesPackage(path.resolve(containingDirectory, p)); if (otherPackage && otherPackage.dir === typesPackage.dir) { // Perf trick; if a path doesn't have ".." anywhere, then it can't have resolved @@ -105,9 +104,9 @@ const rule = createRule({ continue; } if (part === "..") { - cwd = path.posix.dirname(cwd); + cwd = path.dirname(cwd); } else { - cwd = path.posix.join(cwd, part); + cwd = path.join(cwd, part); } const otherPackage = findTypesPackage(cwd); if (otherPackage && otherPackage.dir === typesPackage.dir) { diff --git a/packages/eslint-plugin/src/util.ts b/packages/eslint-plugin/src/util.ts index cf37f16d34..6297f0899c 100644 --- a/packages/eslint-plugin/src/util.ts +++ b/packages/eslint-plugin/src/util.ts @@ -53,6 +53,7 @@ export function findUp(p: string, fn: (p: string) => T | undefined } export interface TypesPackageInfo { + /** directory containing package json; this is a OS-specific path */ dir: string; /** package.json with name="@types/foo__bar-baz" */ packageJson: PackageJSON; From 80a6981097528ac2a7f26f4b0f07d19a9e685722 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:00:41 -0800 Subject: [PATCH 14/16] Don't test on macos, OOMs --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5355955f2..05cdf9bb60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,10 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: + - ubuntu-latest + - windows-latest + # - macos-latest # OOMs runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 From 4abf059154346d53e2de9edc7aa27e1098dc7d72 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:02:46 -0800 Subject: [PATCH 15/16] Don't continue to check paths with backslashes --- packages/eslint-plugin/src/rules/no-bad-reference.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-plugin/src/rules/no-bad-reference.ts b/packages/eslint-plugin/src/rules/no-bad-reference.ts index 7f59445a41..d4dc4ff5bb 100644 --- a/packages/eslint-plugin/src/rules/no-bad-reference.ts +++ b/packages/eslint-plugin/src/rules/no-bad-reference.ts @@ -79,6 +79,7 @@ const rule = createRule({ messageId: "backslashes", loc: tsRangeToESLintLocation(ref.range), }); + continue; } const p = ref.text.startsWith(realNamePlusSlash) From d0bf2b913f2d95e31d6de82498359905491b01d8 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:04:27 -0800 Subject: [PATCH 16/16] Changeset --- .changeset/twenty-eyes-matter.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .changeset/twenty-eyes-matter.md diff --git a/.changeset/twenty-eyes-matter.md b/.changeset/twenty-eyes-matter.md new file mode 100644 index 0000000000..08389920cf --- /dev/null +++ b/.changeset/twenty-eyes-matter.md @@ -0,0 +1,8 @@ +--- +"@definitelytyped/definitions-parser": patch +"@definitelytyped/dtslint-runner": patch +"@definitelytyped/eslint-plugin": patch +"@definitelytyped/utils": patch +--- + +Fix compatibility with Windows