fix(ngcc): support simple browser property in entry-points (#36396)

The `browser` package.json property is now supported to the same
level as `main` - i.e. it is sniffed for UMD, ESM5 and CommonJS.

The `browser` property can also contain an object with file overrides
but this is not supported by ngcc.

Fixes #36062

PR Close #36396
This commit is contained in:
Pete Bacon Darwin
2020-04-02 16:47:17 +01:00
committed by Kara Erickson
parent 93cbef26c7
commit b0d680daa0
3 changed files with 64 additions and 44 deletions

View File

@ -50,6 +50,7 @@ export interface JsonObject {
}
export interface PackageJsonFormatPropertiesMap {
browser?: string;
fesm2015?: string;
fesm5?: string;
es2015?: string; // if exists then it is actually FESM2015
@ -75,7 +76,7 @@ export interface EntryPointPackageJson extends JsonObject, PackageJsonFormatProp
export type EntryPointJsonProperty = Exclude<PackageJsonFormatProperties, 'types'|'typings'>;
// We need to keep the elements of this const and the `EntryPointJsonProperty` type in sync.
export const SUPPORTED_FORMAT_PROPERTIES: EntryPointJsonProperty[] =
['fesm2015', 'fesm5', 'es2015', 'esm2015', 'esm5', 'main', 'module'];
['fesm2015', 'fesm5', 'es2015', 'esm2015', 'esm5', 'main', 'module', 'browser'];
/**
@ -193,13 +194,18 @@ export function getEntryPointFormat(
return 'esm2015';
case 'esm5':
return 'esm5';
case 'browser':
const browserFile = entryPoint.packageJson['browser'];
if (typeof browserFile !== 'string') {
return undefined;
}
return sniffModuleFormat(fs, join(entryPoint.path, browserFile));
case 'main':
const mainFile = entryPoint.packageJson['main'];
if (mainFile === undefined) {
return undefined;
}
const pathToMain = join(entryPoint.path, mainFile);
return sniffModuleFormat(fs, pathToMain);
return sniffModuleFormat(fs, join(entryPoint.path, mainFile));
case 'module':
return 'esm5';
default: