Skip to content

Conversation

@kingston
Copy link
Collaborator

@kingston kingston commented Dec 16, 2024

Allow for \ path separators in generations

Summary by CodeRabbit

  • New Features

    • Added support for Windows platform compatibility across multiple packages.
  • Bug Fixes

    • Enhanced module resolution and import handling for cross-platform compatibility.
  • Documentation

    • Updated method signatures and import statements to reflect changes in path handling.
  • Refactor

    • Improved path normalization and formatting in various modules to ensure consistent behavior across operating systems.

@kingston kingston requested a review from Copilot December 16, 2024 15:35
@linear
Copy link

linear bot commented Dec 16, 2024

@changeset-bot
Copy link

changeset-bot bot commented Dec 16, 2024

🦋 Changeset detected

Latest commit: e7540d4

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

This PR includes changesets to release 12 packages
Name Type
@halfdomelabs/baseplate-plugin-storage Patch
@halfdomelabs/project-builder-server Patch
@halfdomelabs/project-builder-test Patch
@halfdomelabs/project-builder-lib Patch
@halfdomelabs/core-generators Patch
@halfdomelabs/sync Patch
@halfdomelabs/project-builder-common Patch
@halfdomelabs/project-builder-cli Patch
@halfdomelabs/project-builder-web Patch
@halfdomelabs/cli Patch
@halfdomelabs/fastify-generators Patch
@halfdomelabs/react-generators 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

@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2024

Walkthrough

This pull request introduces comprehensive Windows platform compatibility improvements across multiple packages. The changes focus on enhancing path handling, module importing, and file resolution mechanisms to ensure consistent behavior across different operating systems. Key modifications include using pathToFileURL for module imports, normalizing path separators, and implementing POSIX-style path joining functions to create more robust cross-platform file path management.

Changes

File Path Change Summary
core-generators/src/generators/node/prettier/index.ts Added pathToFileURL import for module resolution, updated import statements to use URL-based module loading.
core-generators/src/utils/path.ts Updated makeImportAndFilePath to normalize path separators and changed parameter name for clarity.
core-generators/src/writers/typescript/imports.ts Modified resolveModule to replace path separators with POSIX-style separators.
project-builder-lib/src/plugin-tools/plugin-loader.ts Updated getWebEntrypointImport to replace backslashes with forward slashes.
project-builder-server/src/plugins/node-plugin-store.ts Modified module import to use pathToFileURL.
project-builder-test/src/runner/discover-tests.ts Added pathToFileURL for test file imports.
sync/src/core/generator-output.ts Normalized paths to POSIX style in resolvePath method.
sync/src/core/loader.ts Updated path separator handling in loadGeneratorsForModule.
sync/src/utils/require.ts Enhanced getModuleDefault to handle file URLs.
baseplate-plugin-storage/src/generators/fastify/storage-module/index.ts Replaced path.join with path.posix.join.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7f2d74d and e7540d4.

📒 Files selected for processing (2)
  • packages/core-generators/src/utils/path.ts (1 hunks)
  • plugins/baseplate-plugin-storage/src/generators/fastify/storage-module/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core-generators/src/utils/path.ts
  • plugins/baseplate-plugin-storage/src/generators/fastify/storage-module/index.ts

🪧 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. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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

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.

Copilot reviewed 5 out of 11 changed files in this pull request and generated 2 comments.

Files not reviewed (6)
  • packages/core-generators/src/generators/node/prettier/index.ts: Evaluated as low risk
  • packages/project-builder-lib/src/plugin-tools/plugin-loader.ts: Evaluated as low risk
  • packages/project-builder-server/src/plugins/node-plugin-store.ts: Evaluated as low risk
  • plugins/baseplate-plugin-storage/src/generators/fastify/storage-module/index.ts: Evaluated as low risk
  • packages/project-builder-test/src/runner/discover-tests.ts: Evaluated as low risk
  • packages/core-generators/src/writers/typescript/imports.ts: Evaluated as low risk

Copy link

@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: 1

🧹 Nitpick comments (1)
packages/core-generators/src/utils/path.ts (1)

3-6: Update JSDoc to match the new parameter name.

The JSDoc still references the old parameter name path while the function now uses filePath.

 /**
  * Builds out the full path so it can be used for imports/writing to file
- * @param path Path to the file with file extension
+ * @param filePath Path to the file with file extension
  */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3f51bfb and 7f2d74d.

📒 Files selected for processing (11)
  • .changeset/fair-eels-kiss.md (1 hunks)
  • packages/core-generators/src/generators/node/prettier/index.ts (3 hunks)
  • packages/core-generators/src/utils/path.ts (1 hunks)
  • packages/core-generators/src/writers/typescript/imports.ts (1 hunks)
  • packages/project-builder-lib/src/plugin-tools/plugin-loader.ts (1 hunks)
  • packages/project-builder-server/src/plugins/node-plugin-store.ts (2 hunks)
  • packages/project-builder-test/src/runner/discover-tests.ts (2 hunks)
  • packages/sync/src/core/generator-output.ts (1 hunks)
  • packages/sync/src/core/loader.ts (1 hunks)
  • packages/sync/src/utils/require.ts (1 hunks)
  • plugins/baseplate-plugin-storage/src/generators/fastify/storage-module/index.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (10)
  • .changeset/fair-eels-kiss.md
  • packages/project-builder-server/src/plugins/node-plugin-store.ts
  • packages/project-builder-lib/src/plugin-tools/plugin-loader.ts
  • packages/sync/src/utils/require.ts
  • packages/core-generators/src/writers/typescript/imports.ts
  • packages/project-builder-test/src/runner/discover-tests.ts
  • plugins/baseplate-plugin-storage/src/generators/fastify/storage-module/index.ts
  • packages/sync/src/core/generator-output.ts
  • packages/core-generators/src/generators/node/prettier/index.ts
  • packages/sync/src/core/loader.ts
🔇 Additional comments (2)
packages/core-generators/src/utils/path.ts (2)

7-13: LGTM! Windows path normalization looks good.

The implementation correctly handles Windows path separators by normalizing them to POSIX style, ensuring consistent import paths across different operating systems.


1-19: Verify consistent path handling across the codebase.

Let's ensure these path utilities are used consistently throughout the codebase to maintain Windows compatibility.

✅ Verification successful

Path handling utilities are correctly implemented and used consistently

The codebase demonstrates proper Windows compatibility through:

  1. Consistent usage of makeImportAndFilePath for import paths across React and Fastify generators
  2. Proper path separator normalization using path.sep to path.posix.sep in core utilities
  3. Limited and appropriate usage of unixPathJoin for specific cases requiring POSIX paths
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential path handling issues in the codebase

# Find direct path.join usage that might need unixPathJoin
echo "Checking for path.join usage that might need unixPathJoin:"
rg "path\.join\(" --type ts

# Find potential Windows path separator usage
echo -e "\nChecking for hardcoded Windows path separators:"
rg "\\\\+" --type ts

# Find potential path string concatenation that might need unixPathJoin
echo -e "\nChecking for path string concatenation:"
rg "['\`\"]\/.*\+.*\/['\`\"]" --type ts

Length of output: 35398


Script:

#!/bin/bash
# Let's check for direct path handling in the codebase to verify Windows compatibility

# Search for direct path string concatenation patterns
echo "Checking for path string concatenation patterns:"
rg -A 2 "['\"`]/.*?\+" --type ts

# Search for path.sep usage to ensure Windows compatibility
echo -e "\nChecking path.sep usage:"
rg "path\.sep" --type ts

# Search for makeImportAndFilePath usage
echo -e "\nChecking makeImportAndFilePath usage:"
rg "makeImportAndFilePath" --type ts

# Search for unixPathJoin usage
echo -e "\nChecking unixPathJoin usage:"
rg "unixPathJoin" --type ts

Length of output: 223


Script:

#!/bin/bash
# Let's check for direct path handling in the codebase to verify Windows compatibility

# Search for direct path string concatenation patterns (fixed syntax)
echo "Checking for path string concatenation patterns:"
rg "['\"]\/" --type ts -A 2

# Search for path.sep usage to ensure Windows compatibility
echo -e "\nChecking path.sep usage:"
rg "path\.sep" --type ts

# Search for makeImportAndFilePath usage
echo -e "\nChecking makeImportAndFilePath usage:"
rg "makeImportAndFilePath" --type ts

# Search for unixPathJoin usage
echo -e "\nChecking unixPathJoin usage:"
rg "unixPathJoin" --type ts

Length of output: 15071

Comment on lines 15 to 19
export function unixPathJoin(...paths: string[]): string {
return paths
.join(path.posix.sep)
.replaceAll(`${path.posix.sep}${path.posix.sep}`, path.posix.sep);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add JSDoc documentation and improve path handling.

The function needs documentation and could benefit from more robust path handling.

  1. Add JSDoc documentation:
+/**
+ * Joins path segments using POSIX separators, ensuring consistent behavior across platforms
+ * @param paths - Array of path segments to join
+ * @returns Joined path using POSIX separators
+ */
 export function unixPathJoin(...paths: string[]): string {
  1. Consider using path.posix.normalize for more robust path handling:
 export function unixPathJoin(...paths: string[]): string {
-  return paths
-    .join(path.posix.sep)
-    .replaceAll(`${path.posix.sep}${path.posix.sep}`, path.posix.sep);
+  return path.posix.normalize(
+    paths
+      .filter(Boolean)
+      .join(path.posix.sep)
+  );
 }

This improvement:

  • Handles empty or undefined path segments
  • Normalizes relative path segments (../. or ./)
  • Consolidates consecutive separators
  • Maintains correct behavior for absolute paths
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function unixPathJoin(...paths: string[]): string {
return paths
.join(path.posix.sep)
.replaceAll(`${path.posix.sep}${path.posix.sep}`, path.posix.sep);
}
/**
* Joins path segments using POSIX separators, ensuring consistent behavior across platforms
* @param paths - Array of path segments to join
* @returns Joined path using POSIX separators
*/
export function unixPathJoin(...paths: string[]): string {
return path.posix.normalize(
paths
.filter(Boolean)
.join(path.posix.sep)
);
}

@kingston kingston merged commit 48bda89 into main Dec 16, 2024
5 checks passed
@kingston kingston deleted the kingston/eng-511-enable-generation-on-windows-machines branch December 16, 2024 16:05
@github-actions github-actions bot mentioned this pull request Jan 17, 2025
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.

2 participants