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:
Pete Bacon Darwin
2019-05-23 18:49:16 +01:00
committed by Kara Erickson
parent 7c4c676413
commit 869e3e8edc
2 changed files with 62 additions and 4 deletions

View File

@ -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;
}