diff --git a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts index 17d023a2e6ea6..e132cbeef311a 100644 --- a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts +++ b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts @@ -317,7 +317,11 @@ export default createESLintRule({ if ( !allowCircularSelfDependency && !isRelativePath(imp) && - !isAngularSecondaryEntrypoint(imp, sourceFilePath) + !isAngularSecondaryEntrypoint( + imp, + sourceFilePath, + sourceProject.data.root + ) ) { context.report({ node, diff --git a/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.spec.ts b/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.spec.ts index 6952b03cecccd..2f9c20d4ebfa6 100644 --- a/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.spec.ts +++ b/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.spec.ts @@ -401,6 +401,7 @@ describe('isAngularSecondaryEntrypoint', () => { ], '@project/features': ['libs/features/src/index.ts'], '@project/features/*': ['libs/features/*/random/folder/api.ts'], + '@project/buildable': ['libs/buildable/src/index.ts'], }, }, }; @@ -421,25 +422,55 @@ describe('isAngularSecondaryEntrypoint', () => { lib: { entryFile: 'random/folder/api.ts' }, }), 'libs/features/secondary/random/folder/api.ts': 'const bla = "foo"', + 'libs/buildable/ng-package.json': JSON.stringify({ + lib: { entryFile: 'src/index.ts' }, + }), }; vol.fromJSON(fsJson, '/root'); }); it('should return true for secondary entrypoints', () => { expect( - isAngularSecondaryEntrypoint('@project/standard', 'apps/app.ts') + isAngularSecondaryEntrypoint( + '@project/standard', + 'apps/app.ts', + 'libs/standard' + ) ).toBe(false); expect( - isAngularSecondaryEntrypoint('@project/standard/secondary', 'apps/app.ts') + isAngularSecondaryEntrypoint( + '@project/standard/secondary', + 'apps/app.ts', + 'libs/standard' + ) ).toBe(true); expect( - isAngularSecondaryEntrypoint('@project/standard/tertiary', 'apps/app.ts') + isAngularSecondaryEntrypoint( + '@project/standard/tertiary', + 'apps/app.ts', + 'libs/standard' + ) ).toBe(true); expect( - isAngularSecondaryEntrypoint('@project/features', 'apps/app.ts') + isAngularSecondaryEntrypoint( + '@project/features', + 'apps/app.ts', + 'libs/features' + ) ).toBe(false); expect( - isAngularSecondaryEntrypoint('@project/features/secondary', 'apps/app.ts') + isAngularSecondaryEntrypoint( + '@project/features/secondary', + 'apps/app.ts', + 'libs/features' + ) ).toBe(true); + expect( + isAngularSecondaryEntrypoint( + '@project/buildable', + 'apps/app.ts', + 'libs/buildable' + ) + ).toBe(false); }); }); diff --git a/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts b/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts index 73ccfcf4e8385..2f0cb78f4b46e 100644 --- a/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts +++ b/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts @@ -447,7 +447,8 @@ export function groupImports( */ export function isAngularSecondaryEntrypoint( importExpr: string, - filePath: string + filePath: string, + projectRoot: string ): boolean { const resolvedModule = resolveModuleByImport( importExpr, @@ -455,12 +456,14 @@ export function isAngularSecondaryEntrypoint( join(workspaceRoot, getRootTsConfigFileName()) ); - return !!resolvedModule && fileIsSecondaryEntryPoint(resolvedModule); + return ( + !!resolvedModule && fileIsSecondaryEntryPoint(resolvedModule, projectRoot) + ); } -function fileIsSecondaryEntryPoint(file: string): boolean { +function fileIsSecondaryEntryPoint(file: string, projectRoot: string): boolean { let parent = joinPathFragments(file, '../'); - while (parent !== './') { + while (parent !== `${projectRoot}/`) { // we need to find closest existing ng-package.json // in order to determine if the file matches the secondary entry point const ngPackageContent = readFileIfExisting( diff --git a/tsconfig.base.json b/tsconfig.base.json index 8c70e65a4618e..b14d71e378e19 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -93,9 +93,9 @@ "@nx/nx-plugin": ["packages/nx-plugin"], "@nx/nx-plugin/*": ["packages/nx-plugin/*"], "@nx/react": ["packages/react"], - "@nx/react/*": ["packages/react/*"], "@nx/react-native": ["packages/react-native"], "@nx/react-native/*": ["packages/react-native/*"], + "@nx/react/*": ["packages/react/*"], "@nx/rollup": ["packages/rollup"], "@nx/rollup/*": ["packages/rollup/*"], "@nx/storybook": ["packages/storybook"],