fix(ivy): ngcc should only index .d.ts exports within the package (#32129)
ngcc needs to solve a unique problem when compiling typings for an entrypoint: it must resolve a declaration within a .js file to its representation in a .d.ts file. Since such .d.ts files can be used in deep imports without ever being referenced from the "root" .d.ts, it's not enough to simply match exported types to the root .d.ts. ngcc must build an index of all .d.ts files. Previously, this operation had a bug: it scanned all .d.ts files in the .d.ts program, not only those within the package. Thus, if a class in the program happened to share a name with a class exported from a dependency's .d.ts, ngcc might accidentally modify the wrong .d.ts file, causing a variety of issues downstream. To fix this issue, ngcc's .d.ts scanner now limits the .d.ts files it indexes to only those declared in the current package. PR Close #32129
This commit is contained in:

committed by
Andrew Kushnir

parent
02bab8cf90
commit
964d72610f
@ -36,28 +36,31 @@ export function makeTestEntryPointBundle(
|
||||
dtsRootNames?: AbsoluteFsPath[]): EntryPointBundle {
|
||||
const entryPoint = makeTestEntryPoint(packageName);
|
||||
const src = makeTestBundleProgram(srcRootNames[0], isCore);
|
||||
const dts = dtsRootNames ? makeTestDtsBundleProgram(dtsRootNames[0], isCore) : null;
|
||||
const dts =
|
||||
dtsRootNames ? makeTestDtsBundleProgram(dtsRootNames[0], entryPoint.package, isCore) : null;
|
||||
const isFlatCore = isCore && src.r3SymbolsFile === null;
|
||||
return {entryPoint, format, rootDirs: [absoluteFrom('/')], src, dts, isCore, isFlatCore};
|
||||
}
|
||||
|
||||
export function makeTestBundleProgram(
|
||||
path: AbsoluteFsPath, isCore: boolean = false): BundleProgram {
|
||||
path: AbsoluteFsPath, isCore: boolean = false,
|
||||
additionalFiles?: AbsoluteFsPath[]): BundleProgram {
|
||||
const fs = getFileSystem();
|
||||
const entryPointPath = fs.dirname(path);
|
||||
const rootDir = fs.dirname(entryPointPath);
|
||||
const options: ts.CompilerOptions =
|
||||
{allowJs: true, maxNodeModuleJsDepth: Infinity, checkJs: false, rootDir, rootDirs: [rootDir]};
|
||||
const host = new NgccSourcesCompilerHost(fs, options, entryPointPath);
|
||||
return makeBundleProgram(fs, isCore, path, 'r3_symbols.js', options, host);
|
||||
return makeBundleProgram(
|
||||
fs, isCore, rootDir, path, 'r3_symbols.js', options, host, additionalFiles);
|
||||
}
|
||||
|
||||
export function makeTestDtsBundleProgram(
|
||||
path: AbsoluteFsPath, isCore: boolean = false): BundleProgram {
|
||||
path: AbsoluteFsPath, packagePath: AbsoluteFsPath, isCore: boolean = false): BundleProgram {
|
||||
const fs = getFileSystem();
|
||||
const options = {};
|
||||
const host = new NgtscCompilerHost(fs, options);
|
||||
return makeBundleProgram(fs, isCore, path, 'r3_symbols.d.ts', options, host);
|
||||
return makeBundleProgram(fs, isCore, packagePath, path, 'r3_symbols.d.ts', options, host);
|
||||
}
|
||||
|
||||
export function convertToDirectTsLibImport(filesystem: TestFile[]) {
|
||||
|
Reference in New Issue
Block a user