Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(type-utils): allowFileSpecifier to exclude paths#6860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Changes fromall 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
39 changes: 32 additions & 7 deletionspackages/type-utils/src/TypeOrValueSpecifier.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
import path from 'path';
import type * as ts from 'typescript';

interface FileSpecifier {
type FileSpecifier = {
from: 'file';
name: string | string[];
path?: string;
}
} & (
| {
path?: string;
excludePaths?: undefined;
}
| {
path?: undefined;
excludePaths?: string | string[]; // defaults to `["node_modules"]`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I also wonder if we should call thispathExcludes, to visually lump it in withpath... 🤔

}
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Starting a new conversation here: why makeexcludePaths andpath mutually exclusive? What if someone wants to provide both? E.g.:

{path:"examples",excludePaths:["examples/*/node_modules"]}

Proposal: can we switch this back to a straightforward interface?

interfaceFileSpecifier{from:'file';name:string|string[];path?:string;excludePaths?:string|string[];// defaults to `["node_modules"]`.}


interface LibSpecifier {
from: 'lib';
Expand DownExpand Up@@ -129,14 +137,26 @@ function specifierNameMatches(type: ts.Type, name: string | string[]): boolean {

function typeDeclaredInFile(
relativePath: string | undefined,
excludePaths: string | string[] | undefined,
declarationFiles: ts.SourceFile[],
program: ts.Program,
): boolean {
if (relativePath === undefined) {
const cwd = program.getCurrentDirectory().toLowerCase();
return declarationFiles.some(declaration =>
declaration.fileName.toLowerCase().startsWith(cwd),
);
const excludePathsArray =
excludePaths === undefined
? ['node_modules']
: Array.isArray(excludePaths)
? excludePaths
: [excludePaths];

return declarationFiles.some(declaration => {
const fileName = declaration.fileName.toLowerCase();
return (
fileName.startsWith(cwd) &&
excludePathsArray.every(p => !fileName.startsWith(path.join(cwd, p)))
);
});
}
const absolutePath = path
.join(program.getCurrentDirectory(), relativePath)
Expand DownExpand Up@@ -164,7 +184,12 @@ export function typeMatchesSpecifier(
?.map(declaration => declaration.getSourceFile()) ?? [];
switch (specifier.from) {
case 'file':
return typeDeclaredInFile(specifier.path, declarationFiles, program);
return typeDeclaredInFile(
specifier.path,
specifier.excludePaths,
declarationFiles,
program,
);
case 'lib':
return declarationFiles.some(declaration =>
program.isSourceFileDefaultLibrary(declaration),
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp