Skip to content

Commit 9ba8c7a

Browse files
authored
Allow autoImportFileExcludePatterns to match anywhere in the file path (#57090)
1 parent 6cb6fc9 commit 9ba8c7a

8 files changed

+3229
-4
lines changed

src/compiler/utilities.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -9140,7 +9140,8 @@ export const commonPackageFolders: readonly string[] = ["node_modules", "bower_c
91409140

91419141
const implicitExcludePathRegexPattern = `(?!(${commonPackageFolders.join("|")})(/|$))`;
91429142

9143-
interface WildcardMatcher {
9143+
/** @internal */
9144+
export interface WildcardMatcher {
91449145
singleAsteriskRegexFragment: string;
91459146
doubleAsteriskRegexFragment: string;
91469147
replaceWildcardCharacter: (match: string) => string;
@@ -9222,7 +9223,13 @@ export function getPatternFromSpec(spec: string, basePath: string, usage: "files
92229223
return pattern && `^(${pattern})${usage === "exclude" ? "($|/)" : "$"}`;
92239224
}
92249225

9225-
function getSubPatternFromSpec(spec: string, basePath: string, usage: "files" | "directories" | "exclude", { singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter }: WildcardMatcher): string | undefined {
9226+
/** @internal */
9227+
export function getSubPatternFromSpec(
9228+
spec: string,
9229+
basePath: string,
9230+
usage: "files" | "directories" | "exclude",
9231+
{ singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter }: WildcardMatcher = wildcardMatchers[usage],
9232+
): string | undefined {
92269233
let subpattern = "";
92279234
let hasWrittenComponent = false;
92289235
const components = getNormalizedPathComponents(spec, basePath);

src/services/exportInfoMap.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import {
2121
getNamesForExportedSymbol,
2222
getNodeModulePathParts,
2323
getPackageNameFromTypesPackageName,
24-
getPatternFromSpec,
2524
getRegexFromPattern,
25+
getSubPatternFromSpec,
2626
getSymbolId,
2727
hostGetCanonicalFileName,
2828
hostUsesCaseSensitiveFileNames,
@@ -425,7 +425,7 @@ export function forEachExternalModuleToImportFrom(
425425
const excludePatterns = preferences.autoImportFileExcludePatterns && mapDefined(preferences.autoImportFileExcludePatterns, spec => {
426426
// The client is expected to send rooted path specs since we don't know
427427
// what directory a relative path is relative to.
428-
const pattern = getPatternFromSpec(spec, "", "exclude");
428+
const pattern = getSubPatternFromSpec(spec, "", "exclude");
429429
return pattern ? getRegexFromPattern(pattern, useCaseSensitiveFileNames) : undefined;
430430
});
431431

0 commit comments

Comments
 (0)