nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.69k stars 2.36k forks source link

eslint enforce-module-boundaries rule throws error if there's no entryFile in ng-package.json of secondary entry point #27949

Open mkhodan opened 2 months ago

mkhodan commented 2 months ago

Current Behavior

Right now if user hasn't specified entryFile in ng-package.json of secondary entry point enforce-module-boundaries throws an error:

Oops! Something went wrong! :(

ESLint: 8.57.0

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
Occurred while linting 
Rule: "@nrwl/nx/enforce-module-boundaries"
    at Object.join (node:path:433:7)
    at joinPathFragments (C:\dev\app-3\node_modules\nx\src\utils\path.js:22:31)
    at getAngularEntryPoint (C:\dev\app-3\node_modules\@nx\eslint-plugin\src\utils\runtime-lint-utils.js:348:51)
    at belongsToDifferentNgEntryPoint (C:\dev\app-3\node_modules\@nx\eslint-plugin\src\utils\runtime-lint-utils.js:333:30)
    at run (C:\dev\app-3\node_modules\@nx\eslint-plugin\src\rules\enforce-module-boundaries.js:228:78)
    at ImportDeclaration (C:\dev\app-3\node_modules\@nx\eslint-plugin\src\rules\enforce-module-boundaries.js:467:17)
    at ruleErrorHandler (C:\dev\app-3\node_modules\eslint\lib\linter\linter.js:1076:28)
    at C:\dev\app-3\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (C:\dev\app-3\node_modules\eslint\lib\linter\safe-emitter.js:45:38)

Expected Behavior

According to https://github.com/ng-packagr/ng-packagr/blob/main/docs/secondary-entrypoints.md the contents of my_package/testing/ng-package.json can be as simple as:

{}

and ng-packagr will assume that it is src/public_api.ts

GitHub Repo

No response

Steps to Reproduce

  1. Create an angular library with secondary entry point
  2. leave ng-package.json config of secondary entry point as an empty object
  3. run eslint with a rule enforce-module-boundaries enabled

Nx Report

Node   : 20.15.1
OS     : win32-x64
npm    : 10.7.0

nx                 : 18.2.4
@nx/js             : 18.2.4
@nx/jest           : 18.2.4
@nx/linter         : 18.2.4
@nx/eslint         : 18.2.4
@nx/workspace      : 18.2.4
@nx/angular        : 18.2.4
@nx/cypress        : 18.2.4
@nx/devkit         : 18.2.4
@nx/eslint-plugin  : 18.2.4
@nx/plugin         : 18.2.4
@nx/storybook      : 18.2.4
@nrwl/tao          : 18.2.4
@nx/web            : 18.2.4
@nx/webpack        : 18.2.4
typescript         : 5.4.5
---------------------------------------
Community plugins:
@ngrx/component-store : 17.0.1
@ngrx/effects         : 17.0.1
@ngrx/entity          : 17.0.1
@ngrx/router-store    : 17.0.1
@ngrx/schematics      : 17.0.1
@ngrx/signals         : 17.2.0
@ngrx/store           : 17.0.1
@ngrx/store-devtools  : 17.0.1
@storybook/angular    : 7.6.17
ngx-build-plus        : 14.0.0

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

No response

mkhodan commented 2 months ago

The issue seems to be in this file: https://github.com/nrwl/nx/blob/57a201a56202b7cf97ca7d55a5e0a0a3f138b8cc/packages/eslint-plugin/src/utils/runtime-lint-utils.ts#L528C1-L528C7

where it checks if ng-package.json exists it calls joinPathFragments(parent, entryFile) even though entryFile is undefined