fix(ivy): ngcc - infer entry-point typings from format paths (#30591)
Some packages do not actually provide a `typings` field in their package.json. But TypeScript naturally infers the typings file from the location of the JavaScript source file. This commit modifies ngcc to do a similar inference when finding entry-points to process. Fixes #28603 (FW-1299) PR Close #30591
This commit is contained in:

committed by
Kara Erickson

parent
7c4c676413
commit
869e3e8edc
@ -91,7 +91,8 @@ export function getEntryPointInfo(
|
||||
}
|
||||
|
||||
// We must have a typings property
|
||||
const typings = entryPointPackageJson.typings || entryPointPackageJson.types;
|
||||
const typings = entryPointPackageJson.typings || entryPointPackageJson.types ||
|
||||
guessTypingsFromPackageJson(fs, entryPointPath, entryPointPackageJson);
|
||||
if (!typings) {
|
||||
return null;
|
||||
}
|
||||
@ -191,3 +192,21 @@ function mergeConfigAndPackageJson(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function guessTypingsFromPackageJson(
|
||||
fs: FileSystem, entryPointPath: AbsoluteFsPath,
|
||||
entryPointPackageJson: EntryPointPackageJson): AbsoluteFsPath|null {
|
||||
for (const prop of SUPPORTED_FORMAT_PROPERTIES) {
|
||||
const field = entryPointPackageJson[prop];
|
||||
if (typeof field !== 'string') {
|
||||
// Some crazy packages have things like arrays in these fields!
|
||||
continue;
|
||||
}
|
||||
const relativeTypingsPath = field.replace(/\.js$/, '.d.ts');
|
||||
const typingsPath = resolve(entryPointPath, relativeTypingsPath);
|
||||
if (fs.exists(typingsPath)) {
|
||||
return typingsPath;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user