fix(ngcc): capture entry-point dependencies from typings as well as source (#34494)
ngcc computes a dependency graph of entry-points to ensure that entry-points are processed in the correct order. Previously only the imports in source files were analysed to determine the dependencies for each entry-point. This is not sufficient when an entry-point has a "type-only" dependency - for example only importing an interface from another entry-point. In this case the "type-only" import does not appear in the source code. It only appears in the typings files. This can cause a dependency to be missed on the entry-point. This commit fixes this by additionally processing the imports in the typings program, as well as the source program. Note that these missing dependencies could cause unexpected flakes when running ngcc in async mode on multiple processes due to the way that ngcc caches files when they are first read from disk. Fixes #34411 // FW-1781 PR Close #34494
This commit is contained in:

committed by
Alex Rickabaugh

parent
69950e3888
commit
4f42de9704
@ -82,7 +82,8 @@ export interface SortedEntryPointsInfo extends DependencyDiagnostics {
|
||||
export class DependencyResolver {
|
||||
constructor(
|
||||
private fs: FileSystem, private logger: Logger,
|
||||
private hosts: Partial<Record<EntryPointFormat, DependencyHost>>) {}
|
||||
private hosts: Partial<Record<EntryPointFormat, DependencyHost>>,
|
||||
private typingsHost: DependencyHost) {}
|
||||
/**
|
||||
* Sort the array of entry points so that the dependant entry points always come later than
|
||||
* their dependencies in the array.
|
||||
@ -125,6 +126,7 @@ export class DependencyResolver {
|
||||
}
|
||||
const depInfo = createDependencyInfo();
|
||||
host.collectDependencies(formatInfo.path, depInfo);
|
||||
this.typingsHost.collectDependencies(entryPoint.typings, depInfo);
|
||||
return depInfo;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ import {NgccConfiguration} from './packages/configuration';
|
||||
import {EntryPoint, EntryPointJsonProperty, EntryPointPackageJson, SUPPORTED_FORMAT_PROPERTIES, getEntryPointFormat} from './packages/entry_point';
|
||||
import {makeEntryPointBundle} from './packages/entry_point_bundle';
|
||||
import {Transformer} from './packages/transformer';
|
||||
import {PathMappings} from './utils';
|
||||
import {PathMappings, createDtsDependencyHost} from './utils';
|
||||
import {FileWriter} from './writing/file_writer';
|
||||
import {InPlaceFileWriter} from './writing/in_place_file_writer';
|
||||
import {NewEntryPointFileWriter} from './writing/new_entry_point_file_writer';
|
||||
@ -164,12 +164,15 @@ export function mainNgcc(
|
||||
const esmDependencyHost = new EsmDependencyHost(fileSystem, moduleResolver);
|
||||
const umdDependencyHost = new UmdDependencyHost(fileSystem, moduleResolver);
|
||||
const commonJsDependencyHost = new CommonJsDependencyHost(fileSystem, moduleResolver);
|
||||
const dependencyResolver = new DependencyResolver(fileSystem, logger, {
|
||||
esm5: esmDependencyHost,
|
||||
esm2015: esmDependencyHost,
|
||||
umd: umdDependencyHost,
|
||||
commonjs: commonJsDependencyHost
|
||||
});
|
||||
const dtsDependencyHost = createDtsDependencyHost(fileSystem, pathMappings);
|
||||
const dependencyResolver = new DependencyResolver(
|
||||
fileSystem, logger, {
|
||||
esm5: esmDependencyHost,
|
||||
esm2015: esmDependencyHost,
|
||||
umd: umdDependencyHost,
|
||||
commonjs: commonJsDependencyHost
|
||||
},
|
||||
dtsDependencyHost);
|
||||
|
||||
const absBasePath = absoluteFrom(basePath);
|
||||
const config = new NgccConfiguration(fileSystem, dirname(absBasePath));
|
||||
|
@ -7,6 +7,8 @@
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom} from '../../src/ngtsc/file_system';
|
||||
import {EsmDependencyHost} from './dependencies/esm_dependency_host';
|
||||
import {ModuleResolver} from './dependencies/module_resolver';
|
||||
|
||||
/**
|
||||
* A list (`Array`) of partially ordered `T` items.
|
||||
@ -119,3 +121,8 @@ export function stripDollarSuffix(value: string): string {
|
||||
export function stripExtension(fileName: string): string {
|
||||
return fileName.replace(/\..+$/, '');
|
||||
}
|
||||
|
||||
export function createDtsDependencyHost(fileSystem: FileSystem, pathMappings?: PathMappings) {
|
||||
return new EsmDependencyHost(
|
||||
fileSystem, new ModuleResolver(fileSystem, pathMappings, ['', '.d.ts', '/index.d.ts']));
|
||||
}
|
Reference in New Issue
Block a user