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): treat custom type roots as external#6870

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

Merged
Merged
Show file tree
Hide file tree
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
26 changes: 17 additions & 9 deletionspackages/type-utils/src/TypeOrValueSpecifier.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -155,16 +155,20 @@ function typeDeclaredInFile(
function typeDeclaredInPackage(
packageName: string,
declarationFiles: ts.SourceFile[],
program: ts.Program,
): boolean {
// Handle scoped packages - if the name starts with @, remove it and replace / with __
const typesPackageName =
'@types/' + packageName.replace(/^@([^/]+)\//, '$1__');
const matcher = new RegExp(
`node_modules/(?:${packageName}|${typesPackageName})/`,
);
return declarationFiles.some(declaration =>
matcher.test(declaration.fileName),
);
const typesPackageName = packageName.replace(/^@([^/]+)\//, '$1__');

const matcher = new RegExp(`${packageName}|${typesPackageName}`);
return declarationFiles.some(declaration => {
const packageIdName = program.sourceFileToPackageName.get(declaration.path);
return (
packageIdName !== undefined &&
matcher.test(packageIdName) &&
program.isSourceFileFromExternalLibrary(declaration)
);
});
}

function typeDeclaredInLib(
Expand DownExpand Up@@ -207,6 +211,10 @@ export function typeMatchesSpecifier(
case 'lib':
return typeDeclaredInLib(declarationFiles, program);
case 'package':
return typeDeclaredInPackage(specifier.package, declarationFiles);
return typeDeclaredInPackage(
specifier.package,
declarationFiles,
program,
);
}
}
11 changes: 11 additions & 0 deletionspackages/type-utils/typings/typescript.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,4 +30,15 @@ declare module 'typescript' {
*/
intrinsicName?: string;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding our own type declarations for the internalsourceFileToPackageName seems fishy to me, but that's a decision the maintainers need to do.

I presume you are aware of#6861 - however, there has been no response in the corresponding TS issue....

Choose a reason for hiding this comment

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

Yeah for now I think it's fine. If they change that API we should see breakages in the TS version upgrade PR.

interface Program {
/**
* Maps from a SourceFile's `.path` to the name of the package it was imported with.
*/
readonly sourceFileToPackageName: ReadonlyMap<Path, string>;
}

interface SourceFile extends Declaration, LocalsContainer {
path: Path;
}
}

[8]ページ先頭

©2009-2025 Movatter.jp