diff --git a/packages/eslint-plugin/src/utils/runtime-lint-utils.spec.ts b/packages/eslint-plugin/src/utils/runtime-lint-utils.spec.ts index 97dfd5f759..2d40f2bf1c 100644 --- a/packages/eslint-plugin/src/utils/runtime-lint-utils.spec.ts +++ b/packages/eslint-plugin/src/utils/runtime-lint-utils.spec.ts @@ -448,21 +448,20 @@ describe('is terminal run', () => { }); describe('isAngularSecondaryEntrypoint', () => { - beforeEach(() => { - const tsConfig = { - compilerOptions: { - baseUrl: '.', - resolveJsonModule: true, - paths: { - '@project/standard': ['libs/standard/src/index.ts'], - '@project/standard/secondary': [ - 'libs/standard/secondary/src/index.ts', - ], - '@project/features': ['libs/features/index.ts'], - '@project/features/*': ['libs/features/*/random/folder/api.ts'], - }, + const tsConfig = { + compilerOptions: { + baseUrl: '.', + resolveJsonModule: true, + paths: { + '@project/standard': ['libs/standard/src/index.ts'], + '@project/standard/secondary': ['libs/standard/secondary/src/index.ts'], + '@project/features': ['libs/features/index.ts'], + '@project/features/*': ['libs/features/*/random/folder/api.ts'], }, - }; + }, + }; + + beforeEach(() => { const fsJson = { 'tsconfig.base.json': JSON.stringify(tsConfig), 'libs/standard/package.json': '{ "version": "0.0.0" }', @@ -549,6 +548,47 @@ describe('isAngularSecondaryEntrypoint', () => { ) ).toBe(true); }); + + it('should handle secondary entry points with no entry file defined in ng-package.json', () => { + vol.writeFileSync('/root/libs/standard/secondary/ng-package.json', '{}'); + vol.renameSync( + '/root/libs/standard/secondary/src/index.ts', + '/root/libs/standard/secondary/src/public_api.ts' + ); + const updatedTsConfig = { + ...tsConfig, + compilerOptions: { + ...tsConfig.compilerOptions, + paths: { + ...tsConfig.compilerOptions.paths, + '@project/standard/secondary': [ + 'libs/standard/secondary/src/public_api.ts', + ], + }, + }, + }; + vol.writeFileSync( + '/root/tsconfig.base.json', + JSON.stringify(updatedTsConfig) + ); + + // main + expect( + belongsToDifferentEntryPoint( + '@project/standard', + 'libs/standard/secondary/src/subfolder/index.ts', + 'libs/standard' + ) + ).toBe(true); + // secondary + expect( + belongsToDifferentEntryPoint( + '@project/standard/secondary', + 'libs/standard/src/subfolder/index.ts', + 'libs/standard' + ) + ).toBe(true); + }); }); describe('hasNoneOfTheseTags', () => { diff --git a/packages/eslint-plugin/src/utils/runtime-lint-utils.ts b/packages/eslint-plugin/src/utils/runtime-lint-utils.ts index ce960836ba..f5b38fddc7 100644 --- a/packages/eslint-plugin/src/utils/runtime-lint-utils.ts +++ b/packages/eslint-plugin/src/utils/runtime-lint-utils.ts @@ -556,7 +556,8 @@ function getEntryPoint(file: string, projectRoot: string): string { ); if (ngPackageContent) { // https://github.com/ng-packagr/ng-packagr/blob/23c718d04eea85e015b4c261310b7bd0c39e5311/src/ng-package.schema.json#L54 - const entryFile = parseJson(ngPackageContent)?.lib?.entryFile; + const entryFile = + parseJson(ngPackageContent)?.lib?.entryFile ?? 'src/public_api.ts'; return joinPathFragments(parent, entryFile); } parent = joinPathFragments(parent, '../');