Skip to content

Commit

Permalink
fix: Correctly handle minimatch excludes on Windows
Browse files Browse the repository at this point in the history
Closes #1610
  • Loading branch information
Gerrit0 committed Jun 25, 2021
1 parent bde0b6a commit bf79e32
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
8 changes: 2 additions & 6 deletions src/lib/application.ts
Expand Up @@ -17,7 +17,7 @@ import {
discoverNpmPlugins,
NeverIfInternal,
} from "./utils/index";
import { createMinimatch } from "./utils/paths";
import { createMinimatch, matchesAny } from "./utils/paths";

import {
AbstractComponent,
Expand Down Expand Up @@ -544,10 +544,6 @@ export class Application extends ChildableComponent<

const exclude = createMinimatch(this.exclude);

function isExcluded(fileName: string): boolean {
return exclude.some((mm) => mm.match(fileName));
}

const supportedFileRegex =
this.options.getCompilerOptions().allowJs ||
this.options.getCompilerOptions().checkJs
Expand All @@ -566,7 +562,7 @@ export class Application extends ChildableComponent<
file = `${file}/`;
}

if (!entryPoint && isExcluded(normalizePath(file))) {
if (!entryPoint && matchesAny(exclude, file)) {
return;
}

Expand Down
13 changes: 5 additions & 8 deletions src/lib/converter/converter.ts
Expand Up @@ -11,7 +11,7 @@ import { BindOption } from "../utils";
import { convertType } from "./types";
import { ConverterEvents } from "./converter-events";
import { convertSymbol } from "./symbols";
import { createMinimatch } from "../utils/paths";
import { createMinimatch, matchesAny } from "../utils/paths";
import { IMinimatch } from "minimatch";
import { hasAllFlags, hasAnyFlag } from "../utils/enum";
import { resolveAliasedSymbol } from "./utils/symbols";
Expand Down Expand Up @@ -391,11 +391,7 @@ export class Converter extends ChildableComponent<
this.excludeCache ??= createMinimatch(this.application.exclude);

for (const node of symbol.getDeclarations() ?? []) {
if (
this.excludeCache.some((p) =>
p.match(node.getSourceFile().fileName)
)
) {
if (matchesAny(this.excludeCache, node.getSourceFile().fileName)) {
return true;
}
}
Expand All @@ -408,8 +404,9 @@ export class Converter extends ChildableComponent<
this.externalPatternCache ??= createMinimatch(this.externalPattern);
for (const node of symbol.getDeclarations() ?? []) {
if (
this.externalPatternCache.some((p) =>
p.match(node.getSourceFile().fileName)
matchesAny(
this.externalPatternCache,
node.getSourceFile().fileName
)
) {
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utils/paths.ts
Expand Up @@ -14,3 +14,8 @@ export function createMinimatch(patterns: string[]): IMinimatch[] {
})
);
}

export function matchesAny(patterns: readonly IMinimatch[], path: string) {
const normPath = normalizePath(path).replace(/^\w:\//, "");
return patterns.some((pat) => pat.match(normPath));
}

0 comments on commit bf79e32

Please sign in to comment.