nrwl / nx

Smart Monorepos ยท Fast CI
https://nx.dev
MIT License
23.28k stars 2.32k forks source link

nx dep-graph file used to include npm dependencies #19256

Closed GeoedgeGuyMoreh closed 4 weeks ago

GeoedgeGuyMoreh commented 1 year ago

Current Behavior

Lately, in the recent version the nx dep-graph --file dep.json schema has been changed, it used to include the npm packages per file but it's not anymore.

I looked over the changelog and didn't see anything related to that, any idea why this change was? shouldn't I count on this file to be stable (structure-wise)?

Expected Behavior

include the npm packages as before, for example { "file": "apps/test-service/src/app/test-service/test-service.module.ts", "hash": "0ac96d6d11f862360f827746872562e9cb699603", "deps": [ "npm:@ssut/nestjs-sqs", "npm:@nestjs/common", "ces-events-hub-core", "data-access-s3-core", "npm:@willsoto/nestjs-prometheus" ] },

GitHub Repo

No response

Steps to Reproduce

1.Running nx dep-graph --file dep.json

  1. Open dep.json see the missing dependecies

Nx Report

Node   : 16.13.0
   OS     : darwin-arm64
   npm    : 9.1.1

   nx                 : 16.8.1
   @nx/js             : 16.8.1
   @nx/jest           : 16.8.1
   @nx/linter         : 16.8.1
   @nx/workspace      : 16.8.1
   @nx/devkit         : 16.8.1
   @nx/eslint-plugin  : 16.8.1
   @nx/nest           : 16.8.1
   @nx/node           : 16.8.1
   @nx/plugin         : 16.8.1
   @nrwl/tao          : 15.7.2
   @nx/webpack        : 16.8.1
   nx-cloud           : 16.4.0
   typescript         : 5.1.6
   ---------------------------------------
   Community plugins:
   @ns3/nx-serverless : 3.8.0
   ---------------------------------------
   Local workspace plugins:
         @geoedge-v2-backend/workspace-plugin
   ---------------------------------------
   The following packages should match the installed version of nx
     - @nrwl/tao@15.7.2

   To fix this, run `nx migrate nx@16.8.1`

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

No response

LucaVazz commented 11 months ago

This problem seems to be appearing from nx version 16.3.0 and later.

Before (nx version <= 16.2.2) inside the file generated by nx graph --file=graph.json relevant apps would have the following structure: Their data property would contain a files array, which in turn contained references to dependencies. For example (redacted for brevity):

{
  "graph": {
    "nodes": {
      "<app-name>": {
        "name": "<app-name>",
        "type": "app",
        "data": {
          "name": "<app-name>",
          "$schema": "../../node_modules/nx/schemas/project-schema.json",
          "projectType": "application",
          "sourceRoot": "apps/<app-name>/src",
          "prefix": "<app-prefix>",
          "targets": { 
            // ...
          },
          "tags": [],
          "root": "apps/<app-name>",
          "implicitDependencies": [],
          "files": [
            {
              "file": "apps/<app-name>/src/app/<module-name>/<module-name>.module.ts",
              "hash": "<app-hash>",
              "dependencies": [
                {
                  "target": "npm:@angular/common",  // ๐Ÿ‘ˆ desired reference to an npm dependency
                  "source": "<app-name>",
                  "type": "static"
                },
                // ...
              ],
              // ...
            }
          ]
        },
      },
      // ...

Now (nx version >= 16.3.0) the generated file lacks the whole files array inside the data property. For example (again redacted):

{
  "graph": {
    "nodes": {
      "<app-name>": {
        "name": "<app-name>",
        "type": "app",
        "data": {
          "name": "<app-name>",
          "$schema": "../../node_modules/nx/schemas/project-schema.json",
          "projectType": "application",
          "sourceRoot": "apps/<app-name>/src",
          "prefix": "<app-prefix>",
          "targets": { 
            // ...
          },
          "tags": [],
          "implicitDependencies": []
          // โŒ files array and therefore any reference to dependencies is missing in JSON output
        }
      },
      // ...

This should be reproducible with any project using nx, but if necessary I can provide an MWE repo.

@FrozenPandaz Did you have a chance to look into this issue already?
Is there a new flag to enable the files array to be included in the JSON output file again?

LucaVazz commented 11 months ago

I've tested a bit more and this problem seems to be caused by commit 0848031dd9c19672ab795e0494e54bbef61240c5

(I've tested 16.3.0-beta.0 and the problem / change already appears there).

@vsavkin Would it be possible for you to look into this problem please, as you authored that change?

andersonba commented 9 months ago

Up!

andersonba commented 2 months ago

Since print-affected was deprecated in v19 (where we had access through .projectGraph.dependencies), we need this fix to use the replacement graph command (now .graph.dependencies)

MaxKless commented 1 month ago

Can I ask what the exact use case for this is? If you want to just access the project graph programatically, you can use createProjectGraphAsync from @nx/devkit. It will contain all external nodes as well.

We specifically do not include external dependencies in the outputted .json file to avoid bloat.

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because more information has not been provided within 7 days. It will be closed in 21 days if no information is provided. If information has been provided, please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™