Skip to content

fix(cli): use correct directory for vite-lib config in monorepos#364

Merged
fengmk2 merged 1 commit intomainfrom
12-24-fix_cli_write_vite_lib_config_from_current_directory
Dec 24, 2025
Merged

fix(cli): use correct directory for vite-lib config in monorepos#364
fengmk2 merged 1 commit intomainfrom
12-24-fix_cli_write_vite_lib_config_from_current_directory

Conversation

@fengmk2
Copy link
Copy Markdown
Member

@fengmk2 fengmk2 commented Dec 24, 2025

TL;DR

Fix the vite lib command to work correctly in monorepo packages by using the correct directory path.

What changed?

  • Fixed the lib command in the CLI to use the correct directory path when generating the Vite lib config
  • Instead of using the workspace root directory, now using the current working directory
  • Added a new snapshot test for the lib command in a monorepo setup to verify the fix

How to test?

  1. Navigate to a package within a monorepo
  2. Run vite lib or vite run <package>#build where the package uses vite lib in its build script
  3. Verify that the library builds correctly and outputs files to the package's dist directory
  4. Run the command again to verify caching works properly

Why make this change?

When running the vite lib command in a package within a monorepo, the command was incorrectly using the workspace root directory instead of the package directory to generate the Vite configuration. This caused the build to fail or produce incorrect output. This fix ensures that the command works correctly in monorepo setups by using the current working directory of the package.

@fengmk2 fengmk2 changed the title fix(cli): write vite lib config from current directory fix(cli): use correct directory for vite-lib config in monorepos Dec 24, 2025
Copy link
Copy Markdown
Member Author

fengmk2 commented Dec 24, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@fengmk2 fengmk2 requested a review from Brooooooklyn December 24, 2025 01:57
@fengmk2 fengmk2 marked this pull request as ready for review December 24, 2025 01:57
Copilot AI review requested due to automatic review settings December 24, 2025 01:57
@fengmk2 fengmk2 self-assigned this Dec 24, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug in the vite lib command where it was using the workspace root directory instead of the package's current working directory when generating the Vite lib config in monorepo setups, causing builds to fail or produce incorrect output.

Key Changes:

  • Updated the lib command to use the current working directory (cwd) instead of workspace.root_dir() when writing the Vite lib configuration
  • Added comprehensive snapshot tests for the lib command in a monorepo environment to verify the fix and prevent regressions

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/cli/binding/src/cli.rs Fixed the directory path used in write_vite_lib_config to use cwd instead of workspace.root_dir(), and added necessary clone of cwd since it's used twice in the command handler
packages/cli/snap-tests/command-lib-monorepo/steps.json Added test steps to verify the lib command works in monorepo packages, including build and caching verification
packages/cli/snap-tests/command-lib-monorepo/snap.txt Expected output snapshot showing successful library builds and cache hits in monorepo context
packages/cli/snap-tests/command-lib-monorepo/packages/hello/tsdown.config.ts Test fixture configuration for the library build tool
packages/cli/snap-tests/command-lib-monorepo/packages/hello/src/index.ts Test fixture entry point for the library
packages/cli/snap-tests/command-lib-monorepo/packages/hello/src/hello.ts Test fixture module demonstrating basic library functionality
packages/cli/snap-tests/command-lib-monorepo/packages/hello/package.json Test fixture package definition with build script using vite lib
packages/cli/snap-tests/command-lib-monorepo/package.json Monorepo workspace root configuration for the test fixture

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fengmk2 fengmk2 merged commit baaece5 into main Dec 24, 2025
17 of 18 checks passed
Copy link
Copy Markdown
Member Author

fengmk2 commented Dec 24, 2025

Merge activity

@fengmk2 fengmk2 deleted the 12-24-fix_cli_write_vite_lib_config_from_current_directory branch December 24, 2025 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants