nrwl / nx

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

Exclude Storybook stories from dependency tree #14474

Closed TomONeill closed 1 year ago

TomONeill commented 1 year ago

Current Behavior

When having two libraries that do not depend on each other in their implementation, but do in one of their .stories.ts files, the libraries are seen as dependent on each other in the dependency tree (nx graph) and ESLint (enforce-module-boundaries).

Expected Behavior

As Storybook stories are not actual dependencies of the library, they should be ignored.

Github Repo

No response

Steps to Reproduce

Let's say I've got these libraries that are not dependent on each other in their implementation:

image

Adding this in the shared-ui-details library:

// details.stories.ts
import { Button } from "@my-app/shared/ui-button"

// ...

a dependency is created between the two libraries: image

Nx Report

>  NX   Report complete - copy this into the issue template

   Node : 18.12.1
   OS   : win32 x64
   npm  : 9.1.2

   nx : 15.3.3
   @nrwl/angular : 15.3.3
   @nrwl/cypress : 15.3.3
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.3.3
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.3.3
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.3.3
   @nrwl/js : 15.3.3
   @nrwl/linter : 15.3.3
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.3.3
   @nrwl/web : Not Found
   @nrwl/webpack : 15.3.3
   @nrwl/workspace : 15.3.3
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
         @auth0/auth0-angular: 1.11.1
         @ngrx/component-store: 15.0.0
         @ngrx/store: 15.0.0
         @ngrx/store-devtools: 15.0.0
         apollo-angular: 4.1.1
         @compodoc/compodoc: 1.1.19
         @ngrx/eslint-plugin: 14.3.1
         @storybook/angular: 6.5.14

Failure Logs

No response

Additional Information

No response

AgentEnder commented 1 year ago

We can't really exclude these from the graph. Imagine you publish your storybook instance, or run some e2e against it. You wouldn't want cache hits when changing the imported library, since it is a real dependency in this case.

That being said, in order to prevent the above import from breaking your cache, I'd recommend looking into namedInputs inside nx.json, you should be able to tune the prod input to exclude stories and then you would still get cache hits for build whenever you change storybook files on the library or its dependencies.

TomONeill commented 1 year ago

You're right, I didn't view it from Storybook's perspective. Thank you for your reply and suggestion!

github-actions[bot] commented 1 year ago

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.