refactor(ivy): ngcc - expose the package name from `EntryPoint` (#26236)

PR Close #26236
This commit is contained in:
Pete Bacon Darwin 2018-10-03 11:46:57 +01:00 committed by Jason Aden
parent 3ac8a63499
commit 807070fe83
3 changed files with 9 additions and 3 deletions

View File

@ -27,6 +27,8 @@ export type EntryPointPaths = {
* to each of the possible entry-point formats.
*/
export type EntryPoint = EntryPointPaths & {
/** The name of the package (e.g. `@angular/core`). */
name: string;
/** The path to the package that contains this entry-point. */
package: string;
/** The path to this entry point. */
@ -36,6 +38,7 @@ export type EntryPoint = EntryPointPaths & {
};
interface EntryPointPackageJson {
name: string;
fesm2015?: string;
fesm5?: string;
esm2015?: string;
@ -59,8 +62,8 @@ export function getEntryPointInfo(pkgPath: string, entryPoint: string): EntryPoi
// According to https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html,
// `types` and `typings` are interchangeable.
const {fesm2015, fesm5, esm2015, esm5, main, types, typings = types}: EntryPointPackageJson =
JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const {name, fesm2015, fesm5, esm2015, esm5, main, types, typings = types}:
EntryPointPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// Minimum requirement is that we have esm2015 format and typings.
if (!typings || !esm2015) {
@ -74,6 +77,7 @@ export function getEntryPointInfo(pkgPath: string, entryPoint: string): EntryPoi
}
const entryPointInfo: EntryPoint = {
name,
package: pkgPath,
path: entryPoint,
typings: path.resolve(entryPoint, typings),

View File

@ -94,7 +94,7 @@ function restoreRealFileSystem() {
}
function createEntryPoint(path: string): EntryPoint {
return {path, package: '', typings: ''};
return {name: 'some-package', path, package: '', typings: ''};
}
describe('Marker files', () => {

View File

@ -18,6 +18,7 @@ describe('getEntryPointInfo()', () => {
() => {
const entryPoint = getEntryPointInfo('/some_package', '/some_package/valid_entry_point');
expect(entryPoint).toEqual({
name: 'some-package',
package: '/some_package',
path: '/some_package/valid_entry_point',
typings: `/some_package/valid_entry_point/valid_entry_point.d.ts`,
@ -83,6 +84,7 @@ function restoreRealFileSystem() {
function createPackageJson(packageName: string, {exclude}: {exclude?: string} = {}): string {
const packageJson: any = {
name: 'some-package',
typings: `./${packageName}.d.ts`,
fesm2015: `./fesm2015/${packageName}.js`,
esm2015: `./esm2015/${packageName}.js`,