Skip to content

Commit

Permalink
refactor(ivy): ngcc - expose the package name from EntryPoint (angu…
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin authored and jasonaden committed Oct 8, 2018
1 parent 3ac8a63 commit 807070f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/compiler-cli/src/ngcc/src/packages/entry_point.ts
Expand Up @@ -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. */
Expand All @@ -36,6 +38,7 @@ export type EntryPoint = EntryPointPaths & {
};

interface EntryPointPackageJson {
name: string;
fesm2015?: string;
fesm5?: string;
esm2015?: string;
Expand All @@ -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) {
Expand All @@ -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),
Expand Down
Expand Up @@ -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', () => {
Expand Down
Expand Up @@ -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`,
Expand Down Expand Up @@ -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`,
Expand Down

0 comments on commit 807070f

Please sign in to comment.