Closed yjaaidi closed 2 years ago
This was done intentionally.
For the npm
preset, we decided to keep things closer to how npm
sees dependencies (via the package.json
files). This preset doesn't have typescript
setup which under the hood is responsible for the source code analysis. Nx will still analyze package.json
files where if you have dependencies between projects in your workspace.
The ts
preset may suit your needs better. It is very similar to the npm
preset but it utilizes typescript
to analyze dependencies.
Of course, you can choose to enable source code analysis in a npm
preset generate workspace via https://nx.dev/migration/adding-to-monorepo#enabling-js-analysis
Hopefully this clears up any confusion.
Thx @FrozenPandaz, this makes it clear. Is it documented somewhere so other users don't get confused?
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
Creating a new workspace with npm preset doesn't analyze dependencies so the dependency graph is always "flat" no matter how apps/libraries import each other.
Apparently, this seems to happen because
@nrwl/workspace/presets/npm.json
is replaced bynx/presets/npm.json
where source files are not analyzed due to the following configuration: https://github.com/nrwl/nx/blob/16ffa482b5cdd8e2b35732a40fdd26f333f8ecc8/packages/nx/presets/npm.json#L17-L21 I guess this was done to simplify nx integration with existing monorepos.Since 14.2.0, a migration script fixes this for existing nx workspaces using the following schematic: https://github.com/nrwl/nx/blob/master/packages/workspace/src/migrations/update-14-2-0/enable-source-analysis.ts but it is not enabled by default for new workspaces.
Expected Behavior
This can be done here https://github.com/nrwl/nx/blob/16ffa482b5cdd8e2b35732a40fdd26f333f8ecc8/packages/workspace/src/generators/workspace/workspace.ts#L34-L45 just like it's done in the migration script: https://github.com/nrwl/nx/blob/master/packages/workspace/src/migrations/update-14-2-0/enable-source-analysis.ts#L20-L22
@nrwl/workspace/presets/npm.json
?Steps to Reproduce
then import something from
a
intob
and runnx dep-graph
.Notice that the dep graph doesn't detect
a
as a dependency.Environment