Skip to content

fix: ensure nx builders provide the right paths to tsconfig files and… #31648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

Bricklou
Copy link

@Bricklou Bricklou commented Jun 2, 2025

… config dir for storybook

What I did

The Storybook integration for NX is very nice, but it comes with some problems: depending on where you are doing the nx run commands, it can't always resolve the config dir and/or the storybook tsconfig.json file.
This PR is here to fix this issue. This is my first contribution to this project and I hope I did things properly (I have to say, the workflow is a bit confusing to work with).

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

  1. To test this change, you need a NX monorepo with a project located in (in example) projects/my-app.
  2. You then need to configure all the necessary configuration in projects/my-app/project.json. (paths are relatives to the workspace root).
  3. Finally, run the command nx run my-app:storybook in either the workspace root and the project root: this should work either way. (which wasn't the case before).

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

Greptile Summary

Fixes path resolution issues in NX builders for Storybook's Angular framework, ensuring correct paths to tsconfig files and configuration directories regardless of execution context.

  • Added joinPathFragments utility from @nx/devkit for consistent path resolution relative to workspace root
  • Updated path resolution logic in code/frameworks/angular/src/builders/build-storybook/index.ts to handle config directory and tsconfig paths
  • Fixed RxJS operator usage by replacing deprecated mapTo with map for better type safety
  • Added @nx/devkit dependency in package.json for proper NX integration
  • Improved error handling in builder configuration to use factory functions

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

@Bricklou Bricklou marked this pull request as ready for review June 2, 2025 18:21
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 171 to 173
options.tsConfig ??
findUpSync('tsconfig.json', { cwd: options.configDir }) ??
findUpSync('tsconfig.json', { cwd: pathToConfigDir }) ??
browserOptions.tsConfig,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Check that browserOptions.tsConfig exists before accessing it to prevent potential undefined errors

Suggested change
options.tsConfig ??
findUpSync('tsconfig.json', { cwd: options.configDir }) ??
findUpSync('tsconfig.json', { cwd: pathToConfigDir }) ??
browserOptions.tsConfig,
options.tsConfig ??
findUpSync('tsconfig.json', { cwd: pathToConfigDir }) ??
browserOptions?.tsConfig,

Comment on lines +85 to 86
).pipe(map(() => ({ tsConfig })))
: of({});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Duplicate tsConfig mapping in pipe chain - the second map operation on line 88 overwrites the first one

Suggested change
).pipe(map(() => ({ tsConfig })))
: of({});
).pipe(map(() => ({ tsConfig })))
: of({ tsConfig });

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

const runCompodoc$ = options.compodoc
? runCompodoc(
{ compodocArgs: options.compodocArgs, tsconfig: docTSConfig ?? tsConfig },
context
).pipe(mapTo({ tsConfig }))
).pipe(map(() => ({ tsConfig })))
: of({});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Redundant pipe - the next line repeats the same transformation

@@ -109,9 +111,11 @@ const commandBuilder: BuilderHandlerFn<StorybookBuilderOptions> = (
experimentalZoneless = false,
} = options;

const pathToConfigDir = joinPathFragments(context.workspaceRoot, configDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Duplicate pathToConfigDir calculation - already done on line 74

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@valentinpalkovic
Copy link
Contributor

Hi @Bricklou

Thank you for your contribution!

Can you please create a GitHub ticket which explains the issue with a good reproduction?

@Bricklou
Copy link
Author

Sure, I'll do it when I have time this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants