nrwl / nx

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

`nx-copy-assets.plugin` copy files to wrong location on `storybook-build` task #28786

Open batusai513 opened 3 weeks ago

batusai513 commented 3 weeks ago

Current Behavior

Whenever I run the build-storybook task on a vite generated library, it copies the files from nxCopyAssetsPlugin call in vite.config.ts to

/Users/{user}/path/to/monorepo/test-nx-workspace-2/packages/test-utils/Users/{user}/path/to/monorepo/test-nx-workspace-2/packages/test-utils/storybook-static/README.md

Expected Behavior

it copies the files from nxCopyAssetsPlugin to the configured output folder storybook-static/README.md

GitHub Repo

https://github.com/batusai513/example-nx-vite-lib

Steps to Reproduce

  1. create a new monorepo npx create-nx-workspace test-nx-workspace-2 --pm pnpm --preset react-monorepo
  2. create a new react library with storybook configurations and story
  3. run pnpm exec nx run test-utils:build-storybook
  4. check the new Readme.md created within two absolute paths concatenated.

Nx Report

Node           : 22.11.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.12.3

nx                 : 20.0.8
@nx/js             : 20.0.8
@nx/jest           : 20.0.8
@nx/eslint         : 20.0.8
@nx/workspace      : 20.0.8
@nx/cypress        : 20.0.8
@nx/devkit         : 20.0.8
@nx/eslint-plugin  : 20.0.8
@nx/react          : 20.0.8
@nx/rollup         : 20.0.8
@nx/storybook      : 20.0.8
@nx/vite           : 20.0.8
@nx/web            : 20.0.8
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin
@nx/jest/plugin
@nx/storybook/plugin

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

The nx-copy-assets.plugin was introduced to the vite template in this PR https://github.com/nrwl/nx/pull/27593 and the issue is happening in this line https://github.com/nrwl/nx/pull/27593/files#diff-f22d9966a821341f390da67f5737dcc4fadeda567e3ecd05f94db8d5807b6b7bR32, for some reason the config.build.outDir is an absolute path when triggered task is storybook-build, when running a vite build task, config.build.outDir is a relative path.

batusai513 commented 3 weeks ago

Related issues: https://github.com/nrwl/nx/issues/28670