Skip to content

feat: windows support#663

Merged
petermasking merged 4 commits intomainfrom
662-windows-support
Jul 12, 2025
Merged

feat: windows support#663
petermasking merged 4 commits intomainfrom
662-windows-support

Conversation

@basmasking
Copy link
Copy Markdown
Member

@basmasking basmasking commented Jul 12, 2025

Fixes #662

Changes proposed in this pull request:

  • normalize paths during build
  • normalize paths when reading and writing

Our internal model remains the posix model, and every input that does not comply with that is translated into it for easier maintenance.

@MaskingTechnology/jitar

Summary by CodeRabbit

  • New Features

    • Improved path normalization across file and module handling, ensuring consistent behavior on different platforms.
    • Added utilities to check if a path is absolute and to normalize paths in both local and remote file systems.
    • Updated documentation with clearer prerequisites for Jitar projects.
  • Bug Fixes

    • Enhanced reliability of import/export path resolution and resource/module filename generation through path normalization.
  • Chores

    • Updated external module definitions for server builds.
    • Added TODO comments for future test coverage improvements.

@basmasking basmasking requested a review from petermasking as a code owner July 12, 2025 21:17
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 12, 2025

Walkthrough

The changes introduce systematic path normalization and platform-aware path handling across multiple modules, enhancing cross-platform compatibility, particularly for Windows. New methods for checking absolute paths and normalizing paths are added to file system interfaces and implementations. Several internal methods now use these utilities to ensure consistent and correct path processing.

Changes

File(s) Change Summary
packages/sourcing/src/files/interfaces/FileSystem.ts Added isAbsolute and normalize methods to the FileSystem interface.
packages/sourcing/src/files/LocalFileSystem.ts
packages/sourcing/src/files/RemoteFileSystem.ts
Implemented isAbsolute and normalize methods in both file system classes.
packages/sourcing/src/files/FileManager.ts Normalized paths in constructor, getAbsoluteLocation, getRelativeLocation, filter, and added normalizeLocation.
packages/sourcing/src/modules/LocalModuleLocator.ts Now returns file://-prefixed, normalized absolute path in locate.
packages/build/src/source/module/LocationRewriter.ts Normalizes import/export source paths before processing in rewrite methods.
packages/build/src/source/resource/Reader.ts
packages/build/src/source/segment/Reader.ts
Normalizes filenames before directory and extension checks in resource and segment readers.
packages/plugin-vite/src/index.ts Normalizes all constructed paths in the Vite plugin configuration.
packages/jitar/rollup.definitions.js Added 'path' to the list of server externals.
packages/sourcing/test/FileManager.spec.ts Added TODO comments for future Windows and relative path tests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FileManager
    participant FileSystem

    User->>FileManager: getAbsoluteLocation(filename)
    FileManager->>FileSystem: isAbsolute(filename)
    alt not absolute
        FileManager->>FileSystem: resolve path
    end
    FileManager->>FileSystem: normalize(path)
    FileManager-->>User: normalized absolute path
Loading

Assessment against linked issues

Objective Addressed Explanation
Use Node path utilities for separator, absolute checks, normalization, and improve Windows support (Issue #662)

Poem

From UNIX to Windows, we hop and we skip,
Normalizing paths so nothing will trip.
With slashes and checks, our code now aligns,
Across every platform, through folders and pines.
A rabbit’s delight—no more path confusion,
Cross-system support, a hopping conclusion!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f6bd28b and c1a01fe.

📒 Files selected for processing (2)
  • documentation/docs/guides/add-jitar-to-an-existing-project.md (1 hunks)
  • documentation/docs/introduction/what-is-jitar.md (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • documentation/docs/guides/add-jitar-to-an-existing-project.md
  • documentation/docs/introduction/what-is-jitar.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
  • GitHub Check: Analyze (javascript, packages/serialization)
  • GitHub Check: Analyze (javascript, packages/validation)
  • GitHub Check: Analyze (javascript, packages/sourcing)
  • GitHub Check: Analyze (javascript, packages/plugin-vite)
  • GitHub Check: Analyze (javascript, packages/services)
  • GitHub Check: Analyze (javascript, packages/logging)
  • GitHub Check: Analyze (javascript, packages/middleware)
  • GitHub Check: Analyze (javascript, packages/analysis)
  • GitHub Check: Analyze (javascript, packages/configuration)
  • GitHub Check: Analyze (javascript, packages/errors)
  • GitHub Check: Analyze (javascript, packages/execution)
  • GitHub Check: Analyze (javascript, packages/health)
  • GitHub Check: Analyze (javascript, packages/build)
  • GitHub Check: build (22.x)
  • GitHub Check: build (20.x)

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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
Copy Markdown

@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 (1)
packages/sourcing/test/FileManager.spec.ts (1)

76-78: Critical test coverage missing for new path normalization functionality.

The TODO comments indicate missing tests for getRelativeLocation method and Windows path scenarios, which are crucial for the path normalization functionality introduced in this PR. Without proper test coverage, there's a risk of regressions in cross-platform path handling.

Would you like me to help generate comprehensive test cases for:

  1. The getRelativeLocation method with various path scenarios
  2. Windows-specific path handling (backslashes, drive letters, UNC paths)
  3. Edge cases like mixed separators and relative path resolution

These tests are essential to ensure the path normalization works correctly across platforms.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5f8fbf and f6bd28b.

📒 Files selected for processing (11)
  • packages/build/src/source/module/LocationRewriter.ts (2 hunks)
  • packages/build/src/source/resource/Reader.ts (1 hunks)
  • packages/build/src/source/segment/Reader.ts (1 hunks)
  • packages/jitar/rollup.definitions.js (1 hunks)
  • packages/plugin-vite/src/index.ts (1 hunks)
  • packages/sourcing/src/files/FileManager.ts (2 hunks)
  • packages/sourcing/src/files/LocalFileSystem.ts (2 hunks)
  • packages/sourcing/src/files/RemoteFileSystem.ts (2 hunks)
  • packages/sourcing/src/files/interfaces/FileSystem.ts (2 hunks)
  • packages/sourcing/src/modules/LocalModuleLocator.ts (1 hunks)
  • packages/sourcing/test/FileManager.spec.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: basmasking
PR: MaskingTechnology/jitar#649
File: CHANGELOG.md:6-7
Timestamp: 2025-06-02T10:44:10.408Z
Learning: In CHANGELOG.md for the jitar project, the format `[[PR_NUMBER](link)] description (#ISSUE_NUMBER) by author` is intentionally used where the first number is the pull request ID and the second number in parentheses is the issue ID that the PR addresses. These numbers are often different and this is not an error but a deliberate formatting convention used consistently throughout the changelog.
🧬 Code Graph Analysis (3)
packages/plugin-vite/src/index.ts (1)
packages/init/src/InitManager.ts (1)
  • rootPath (54-57)
packages/sourcing/src/files/interfaces/FileSystem.ts (3)
packages/sourcing/src/files/FileManager.ts (1)
  • location (133-142)
packages/sourcing/src/files/errors/InvalidLocation.ts (1)
  • location (13-13)
packages/sourcing/src/files/models/File.ts (1)
  • location (15-15)
packages/sourcing/src/files/RemoteFileSystem.ts (3)
packages/sourcing/src/files/FileManager.ts (1)
  • location (133-142)
packages/sourcing/src/files/errors/InvalidLocation.ts (1)
  • location (13-13)
packages/sourcing/src/files/models/File.ts (1)
  • location (15-15)
🔇 Additional comments (18)
packages/jitar/rollup.definitions.js (1)

9-9: Good addition of 'path' module as external dependency.

Adding the Node.js 'path' module to SERVER_EXTERNALS is necessary since the codebase now uses it for path normalization. This ensures the native module isn't bundled and remains available at runtime.

packages/build/src/source/resource/Reader.ts (1)

56-60: Excellent implementation of path normalization.

The addition of path normalization before processing ensures consistent behavior across platforms. The normalized filename is correctly used for both directory checking and extension processing, maintaining the original logic flow while adding cross-platform compatibility.

packages/plugin-vite/src/index.ts (1)

82-86: Comprehensive path normalization implementation.

Applying normalizePath to all constructed paths (rootPath, sourcePath, targetPath, outputPath, and jitarPath) ensures consistent cross-platform path handling throughout the Vite plugin. Using Vite's built-in normalizePath function is the correct approach for plugin compatibility.

packages/sourcing/src/files/interfaces/FileSystem.ts (2)

12-12: All FileSystem implementations include isAbsolute

Both LocalFileSystem.ts and RemoteFileSystem.ts define the new isAbsolute(location: string): boolean method, so no further changes are needed:

  • packages/sourcing/src/files/LocalFileSystem.ts:
    isAbsolute(location: string): boolean {
        return path.isAbsolute(location);
    }
  • packages/sourcing/src/files/RemoteFileSystem.ts:
    isAbsolute(location: string): boolean {
        return location.startsWith('/');
    }

24-24: All FileSystem implementations include normalize

Both LocalFileSystem.ts and RemoteFileSystem.ts now define the normalize(location: string): string method as required. No further action is needed.

packages/sourcing/src/modules/LocalModuleLocator.ts (1)

20-24: LGTM! Good URI formation pattern.

The change to store the resolved location before returning it with the file:// prefix follows good practices and aligns with the path normalization strategy across the codebase.

packages/build/src/source/segment/Reader.ts (1)

129-133: LGTM! Proper normalization placement.

The path normalization is correctly applied before directory checks and filename adjustments, ensuring consistent path handling across platforms while maintaining the existing logic flow.

packages/sourcing/src/files/LocalFileSystem.ts (2)

26-29: LGTM! Correct use of Node.js path utilities.

The isAbsolute method properly delegates to Node.js's path.isAbsolute, ensuring platform-appropriate absolute path detection.


80-83: Confirmed: normalize Is Only Applied to File Paths

I searched all fileSystem.normalize() usages in packages/sourcing/src/files/FileManager.ts and confirmed they’re exclusively applied to path values (locations, patterns, filenames). There are no instances of it being used on arbitrary content that might legitimately contain backslashes.

No changes needed.

packages/sourcing/src/files/RemoteFileSystem.ts (2)

34-37: LGTM! Simple but functional implementation.

The isAbsolute method uses a straightforward check for leading slash, which is appropriate for remote file systems. The minimal implementation aligns with the class's role as a placeholder.


64-67: LGTM! Conservative approach for remote systems.

The normalize method returning the location unchanged is a safe approach for remote file systems where path modification might not be appropriate or predictable.

packages/build/src/source/module/LocationRewriter.ts (2)

48-55: LGTM! Consistent normalization in import rewriting.

The path normalization is properly applied before application module checks and path rewriting, ensuring consistent behavior across different input path formats.


70-77: LGTM! Consistent pattern maintained for exports.

The export rewriting follows the same normalization pattern as imports, maintaining consistency across the module and ensuring proper path handling for both import and export statements.

packages/sourcing/src/files/FileManager.ts (5)

20-24: LGTM! Constructor normalization ensures consistent state.

The constructor now properly normalizes both the location and root location at initialization, which establishes a consistent baseline for all subsequent path operations. This is a solid approach for the Windows compatibility goals.


32-38: LGTM! Improved absolute path handling with proper normalization.

The changes enhance cross-platform compatibility by:

  • Using the new isAbsolute() method for proper absolute path detection
  • Normalizing the absolute path before validation to ensure consistent format
  • Maintaining security by validating the normalized path

This approach should handle Windows drive letters and UNC paths correctly.


43-46: LGTM! Consistent path normalization for relative paths.

The normalization of relative paths maintains consistency with the overall approach and ensures that relative path operations work correctly across platforms.


48-51: LGTM! Useful public API for external path normalization.

The new normalizeLocation method provides a clean public interface for external consumers to normalize paths using the same logic as the FileManager internally. This is particularly valuable for the build system components mentioned in the AI summary.


125-131: LGTM! Comprehensive normalization in filter operations.

The normalization of both the input pattern and output filenames ensures that filtering operations work consistently across platforms. The mapping of results through normalization maintains the expected format for all returned paths.

petermasking
petermasking previously approved these changes Jul 12, 2025
@sonarqubecloud
Copy link
Copy Markdown

@petermasking petermasking merged commit f6e97ff into main Jul 12, 2025
23 checks passed
@petermasking petermasking deleted the 662-windows-support branch July 12, 2025 21:34
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.

Replace "/" with path.sep and use other Node path utilities to improve Windows support

2 participants