Skip to content

fix(ui~cli): windows path normalization for setup plugins #1541

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

Merged
merged 2 commits into from
Mar 25, 2025

Conversation

SutuSebastian
Copy link
Collaborator

@SutuSebastian SutuSebastian commented Mar 25, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Resolved Windows compatibility issues by improving how plugin paths are handled.
  • New Features
    • Introduced a unified path normalization utility to standardize plugin path resolution.
  • Tests
    • Added new tests to verify proper handling of various path formats across platforms.

@SutuSebastian SutuSebastian added 🐛 bug Something isn't working confirmed This bug was confirmed labels Mar 25, 2025
@SutuSebastian SutuSebastian self-assigned this Mar 25, 2025
Copy link

changeset-bot bot commented Mar 25, 2025

🦋 Changeset detected

Latest commit: 44be4e6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
flowbite-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Mar 25, 2025

Walkthrough

This pull request replaces all instances of Node.js's path.join with a custom utility function, joinNormalizedPath, to normalize plugin paths across multiple modules. The changes specifically target plugin setup files and the Tailwind configuration. Additionally, a new utility module along with its corresponding unit tests has been introduced, and a changeset entry records a patch for the flowbite-react package addressing Windows support.

Changes

File Change Summary
.changeset/shiny-parents-raise.md Added a new changeset entry for the flowbite-react patch addressing Windows path normalization.
packages/ui/src/cli/commands/plugins/setup-plugin-{astro,bun,farm,modernjs,nextjs,parcel,rolldown,rollup,rsbuild,rspack,tanstack-start,vite,webpack}.ts Replaced path.join with joinNormalizedPath for constructing plugin import paths and removed path module imports across multiple plugin setup files.
packages/ui/src/cli/commands/setup-tailwind.ts Updated both setupTailwindV4 and setupTailwindV3 functions to use joinNormalizedPath instead of path.join for constructing plugin paths.
packages/ui/src/cli/utils/normalize-path.ts Introduced new utility functions: normalizeImportPath and joinNormalizedPath for standardizing path formats across the project.
packages/ui/src/cli/utils/__tests__/normalize-path.test.ts Added unit tests for normalizeImportPath and joinNormalizedPath to validate behavior with Windows-style and Unix-style paths.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI Command
    participant Plugin as setupPlugin Function
    participant Norm as joinNormalizedPath
    participant Config as Plugin Config Handler

    CLI->>Plugin: Invoke plugin setup
    Plugin->>Norm: Normalize path (pluginPath, identifier)
    Norm-->>Plugin: Return normalized path
    Plugin->>Config: Pass normalized path for config update
    Config-->>Plugin: Configuration updated
Loading

Suggested labels

:books: documentation

Suggested reviewers

  • rluders
  • tulup-conner

Poem

I'm a rabbit in the codefield,
Hopping over paths with cheer,
Joined paths now neat and revealed,
Windows woes disappear,
With joinNormalizedPath I sing—
A merry, normalized spring!
🐰✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/ui/src/cli/commands/plugins/setup-plugin-astro.ts

Oops! Something went wrong! :(

ESLint: 8.57.0

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/packages/ui".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in "packages/ui/.eslintrc.cjs".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/ui/src/cli/commands/plugins/setup-plugin-farm.ts

Oops! Something went wrong! :(

ESLint: 8.57.0

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/packages/ui".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in "packages/ui/.eslintrc.cjs".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/ui/src/cli/commands/plugins/setup-plugin-bun.ts

Oops! Something went wrong! :(

ESLint: 8.57.0

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/packages/ui".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in "packages/ui/.eslintrc.cjs".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 13 others
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

vercel bot commented Mar 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 25, 2025 8:43am
flowbite-react-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 25, 2025 8:43am

@SutuSebastian SutuSebastian changed the title Fix/windows/path normalization fix(ui~cli): windows path normalization for setup plugins Mar 25, 2025
@SutuSebastian SutuSebastian linked an issue Mar 25, 2025 that may be closed by this pull request
@SutuSebastian SutuSebastian merged commit af49b10 into main Mar 25, 2025
8 checks passed
@SutuSebastian SutuSebastian deleted the fix/windows/path-normalization branch March 25, 2025 08:46
@github-actions github-actions bot mentioned this pull request Mar 25, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
.changeset/shiny-parents-raise.md (1)

5-5: Fix typo in changeset message.

There's a minor typo in the changeset description: "normalzation" should be "normalization".

-fix(ui~cli): path normalzation for windows support (setup plugins paths)
+fix(ui~cli): path normalization for windows support (setup plugins paths)
packages/ui/src/cli/commands/setup-tailwind.ts (1)

61-63: Consider using joinNormalizedPath for sourceDirectivePath.

There's still a manual path normalization happening for the sourceDirectivePath that could potentially benefit from using the joinNormalizedPath utility for consistency.

-const sourceDirectivePath = path
-  .join(path.relative(path.dirname(file), process.cwd()), classListFilePath)
-  .replace(/\\/g, "/");
+const sourceDirectivePath = joinNormalizedPath(
+  path.relative(path.dirname(file), process.cwd()), 
+  classListFilePath
+);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6caecce and 44be4e6.

📒 Files selected for processing (17)
  • .changeset/shiny-parents-raise.md (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-astro.ts (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-bun.ts (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-farm.ts (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-modernjs.ts (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-nextjs.ts (2 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-parcel.ts (2 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-rolldown.ts (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-rollup.ts (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-rsbuild.ts (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-rspack.ts (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-tanstack-start.ts (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-vite.ts (1 hunks)
  • packages/ui/src/cli/commands/plugins/setup-plugin-webpack.ts (1 hunks)
  • packages/ui/src/cli/commands/setup-tailwind.ts (3 hunks)
  • packages/ui/src/cli/utils/__tests__/normalize-path.test.ts (1 hunks)
  • packages/ui/src/cli/utils/normalize-path.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (15)
packages/ui/src/cli/commands/plugins/setup-plugin-parcel.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-tanstack-start.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-webpack.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-nextjs.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-bun.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-rsbuild.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-vite.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-modernjs.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-rspack.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-farm.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-astro.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-rolldown.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/setup-tailwind.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/commands/plugins/setup-plugin-rollup.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (1)
  • joinNormalizedPath (21-23)
packages/ui/src/cli/utils/__tests__/normalize-path.test.ts (1)
packages/ui/src/cli/utils/normalize-path.ts (2)
  • normalizeImportPath (10-12)
  • joinNormalizedPath (21-23)
🔇 Additional comments (17)
packages/ui/src/cli/commands/plugins/setup-plugin-tanstack-start.ts (1)

3-3: Path normalization looks good.

The replacement of path.join with joinNormalizedPath for plugin import paths will help ensure consistent path formatting across platforms, particularly for Windows where backslashes can cause issues in import statements.

Also applies to: 9-9

packages/ui/src/cli/commands/plugins/setup-plugin-parcel.ts (2)

4-4: Path normalization for import path looks good.

Correctly replaces path.join with joinNormalizedPath for the plugin import path to ensure consistent path formatting across platforms.

Also applies to: 42-42


11-11:

❓ Verification inconclusive

Consider using joinNormalizedPath for other paths if needed.

I notice that other path.join instances in this file weren't replaced. If these paths are used for imports or in places where path format matters for cross-platform compatibility, consider using joinNormalizedPath for them as well.

Also applies to: 23-23, 44-44


🏁 Script executed:

#!/bin/bash
# Check if other path.join instances in this file are used in similar contexts
# where normalization would be beneficial

# Find how the variables parcelConfigDir, parcelConfigFilePath, and parcelReporterFilePath are used
rg -A 5 "parcelConfigDir|parcelConfigFilePath|parcelReporterFilePath" --type ts packages/ui/src/cli/commands/plugins/setup-plugin-parcel.ts

Length of output: 2637


Path Normalization Considerations in setup-plugin-parcel.ts

After verifying the usage of path.join in this file, it appears that:

  • parcelConfigDir, parcelConfigFilePath, and parcelReporterFilePath: These are used exclusively for file system operations (e.g., creating directories, reading and writing files). For these purposes, the native behavior of path.join (which handles OS-specific separators) is appropriate.
  • pluginImportPath: Already uses joinNormalizedPath because it’s used in a module import context where a normalized, POSIX-style path is beneficial.

Recommendation:

  • If the file system paths (lines 11, 23, and 44) are solely for interacting with the file system, no changes are necessary.
  • However, if any of these paths might later be used in contexts where cross-platform path normalization (like in module imports) is required, then consider refactoring them to use joinNormalizedPath.
packages/ui/src/cli/commands/plugins/setup-plugin-rolldown.ts (1)

3-3: Path normalization looks good.

The replacement of path.join with joinNormalizedPath for the plugin import path will ensure consistent path formatting across all platforms, addressing Windows compatibility issues.

Also applies to: 9-9

packages/ui/src/cli/commands/plugins/setup-plugin-rspack.ts (1)

3-3: Good implementation of cross-platform path normalization.

The change from the native path.join to the custom joinNormalizedPath function is appropriate for ensuring consistent path handling across different operating systems, particularly Windows where backslashes could cause issues in import paths.

Also applies to: 9-9

packages/ui/src/cli/commands/plugins/setup-plugin-webpack.ts (1)

3-3: Good implementation of cross-platform path normalization.

The replacement of the native path.join with joinNormalizedPath ensures proper path normalization across different operating systems, especially on Windows where backslashes in paths could cause import issues.

Also applies to: 9-9

packages/ui/src/cli/utils/normalize-path.ts (1)

1-23: Well-designed utility functions with good documentation.

The implementation of these path normalization utilities is clean and effective:

  • normalizeImportPath correctly handles the conversion of backslashes to forward slashes
  • joinNormalizedPath combines path.join with normalization in a logical way
  • JSDoc comments clearly explain the purpose and usage of both functions

This is a solid approach to ensuring consistent path handling across different operating systems, particularly addressing Windows compatibility issues where backslashes in paths can cause problems in import statements.

packages/ui/src/cli/commands/plugins/setup-plugin-farm.ts (1)

3-3: Good implementation of cross-platform path normalization.

The change from path.join to joinNormalizedPath ensures consistent handling of paths across different operating systems, particularly improving Windows compatibility by normalizing backslashes to forward slashes for import paths.

Also applies to: 9-9

packages/ui/src/cli/commands/plugins/setup-plugin-nextjs.ts (1)

4-4: Good improvement for Windows path compatibility.

The introduction of joinNormalizedPath is a good approach to ensure path normalization consistency across different operating systems, especially Windows. This will help prevent issues related to backslash vs forward slash path separators.

Also applies to: 16-16

packages/ui/src/cli/commands/plugins/setup-plugin-modernjs.ts (1)

5-5: Consistent usage of normalized path function.

The implementation correctly replaces path.join with joinNormalizedPath, maintaining consistency with other plugin setup files and ensuring proper path normalization for cross-platform compatibility.

Also applies to: 11-11

packages/ui/src/cli/commands/plugins/setup-plugin-astro.ts (1)

3-3: Path normalization correctly implemented.

The change appropriately implements the joinNormalizedPath function to handle cross-platform path normalization, which should resolve Windows-specific path issues.

Also applies to: 9-9

packages/ui/src/cli/commands/setup-tailwind.ts (1)

7-7: Path normalization correctly applied to plugin paths.

The implementation correctly uses joinNormalizedPath to normalize the plugin-related paths, which is consistent with the approach in other files.

Also applies to: 60-60, 122-122

packages/ui/src/cli/commands/plugins/setup-plugin-rollup.ts (1)

3-3: Great improvement for cross-platform compatibility!

The switch from path.join to joinNormalizedPath will help ensure consistent path formatting across different operating systems, especially Windows where backslashes in paths can cause issues. This change will normalize the plugin import path to use forward slashes which is more compatible with JavaScript import statements.

Also applies to: 9-9

packages/ui/src/cli/commands/plugins/setup-plugin-vite.ts (1)

3-3: Good path normalization implementation

Consistent with the other plugin setup files, this properly replaces path.join with joinNormalizedPath to ensure Windows compatibility.

Also applies to: 9-9

packages/ui/src/cli/commands/plugins/setup-plugin-rsbuild.ts (1)

3-3: Clean implementation of path normalization

The replacement of path.join with joinNormalizedPath maintains functionality while ensuring consistent path formatting across operating systems.

Also applies to: 9-9

packages/ui/src/cli/commands/plugins/setup-plugin-bun.ts (1)

4-4: Properly normalized paths for Bun setup

Good implementation of the path normalization strategy. This is especially important for the Bun setup where the plugin path is used in multiple places - both for checking if it's already in the plugins array and for setting the pluginImportPath in the updateBuildConfig call.

Also applies to: 12-12

packages/ui/src/cli/utils/__tests__/normalize-path.test.ts (1)

1-44: Well-structured and comprehensive test coverage!

The test suite provides excellent coverage for the path normalization utilities, ensuring proper behavior across different operating systems. The organization is clear and logical, with distinct test cases for various scenarios.

A few suggestions to make the tests even more robust:

  • Consider adding tests for paths with special characters (spaces, Unicode)
  • Add tests for paths with ".." and "." segments to ensure proper normalization
  • Test with absolute path edge cases (e.g., root paths like "/" or "C:\")

These utilities will be very helpful for ensuring consistent path handling across different platforms, particularly for Windows compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working confirmed This bug was confirmed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot find package 'flowbite-reactplugin♂ite'
1 participant