Skip to content

Fix JSR URL template resolution for Homebrew installations#99

Merged
lambdalisue merged 1 commit into
mainfrom
fix/remote-jsr-template-resolution
Jan 11, 2026
Merged

Fix JSR URL template resolution for Homebrew installations#99
lambdalisue merged 1 commit into
mainfrom
fix/remote-jsr-template-resolution

Conversation

@lambdalisue
Copy link
Copy Markdown
Member

Summary

  • Add getLocalModulePrefix() to determine "local" module prefix based on URL protocol
  • Support file://, JSR (https://jsr.io/@scope/package/version/), and other remote URLs
  • Add comprehensive unit tests covering different URL types

Why

The subprocess template resolver previously only accepted file:// modules, causing failures when the CLI was run from JSR URLs (e.g., Homebrew installations). This prevented the CLI from working in compiled or remote execution contexts.

The fix introduces protocol-aware "local module" detection:

  • Local development (file://): Bundles all local file modules
  • JSR distribution (https://jsr.io/...): Bundles all modules within the same package
  • Other remote URLs: Bundles modules in the same directory tree

This enables Homebrew and other JSR-based distributions to work without requiring pre-embedded templates.

Test Plan

  • Unit tests for getLocalModulePrefix() with various URL types
  • Verified template resolution from JSR URL succeeds (resolves 5 template files)
  • Confirmed local development workflow still works (deno task verify passes)
  • All 33 tests pass including new tests

…ocess

The subprocess template resolver failed when running from JSR URLs
(e.g., Homebrew installations) because it only accepted file:// modules.
This prevented the CLI from working in compiled/remote execution contexts.

Changes:
- Add getLocalModulePrefix() to determine "local" module prefix by protocol
- Support file://, JSR (https://jsr.io/@scope/package/version/), and other URLs
- Add comprehensive tests for different URL types

This enables Homebrew and other JSR-based distributions to work without
pre-embedded templates.
Copilot AI review requested due to automatic review settings January 11, 2026 15:54
@lambdalisue lambdalisue enabled auto-merge January 11, 2026 15:55
@lambdalisue lambdalisue merged commit 2c0f28d into main Jan 11, 2026
9 checks passed
@lambdalisue lambdalisue deleted the fix/remote-jsr-template-resolution branch January 11, 2026 15:57
Copy link
Copy Markdown

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 JSR URL template resolution to enable the CLI to work from Homebrew installations and other JSR-based distributions. Previously, only file:// URLs were supported for template resolution, which broke when the CLI was run from remote JSR URLs.

Changes:

  • Added getLocalModulePrefix() function to determine "local" modules based on URL protocol (file://, JSR, or other remote URLs)
  • Modified template resolver to use protocol-aware filtering instead of hardcoded file:// prefix
  • Added comprehensive unit tests covering different URL types and protocols

Reviewed changes

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

File Description
src/cli/subprocess_template.ts Implements protocol-aware local module detection with new getLocalModulePrefix() function and exposes it via _internal for testing
src/cli/subprocess_template_test.ts Adds unit tests covering file://, JSR (HTTP/HTTPS), and other remote URL scenarios

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

Comment on lines +38 to +41
// Determine which modules are "local" (should be bundled)
// For file:// URLs, all file:// modules are local
// For https:// URLs (JSR), modules under the same package are local
const localModulePrefix = getLocalModulePrefix(templateUrl);
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

This comment is now outdated since the function handles more than just file:// URLs. The code now also processes JSR URLs and other remote URLs as "local" modules. Consider updating the comment to reflect the broader scope, such as: "Collect all local modules from the graph (based on the module prefix)"

Copilot uses AI. Check for mistakes.
// For JSR URLs: https://jsr.io/@scope/package/version/...
// Extract the package base URL to include all modules from the same package
const jsrMatch = templateUrl.href.match(
/^(https?:\/\/jsr\.io\/@[^/]+\/[^/]+\/[^/]+\/)/,
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

The regex requires a trailing slash after the version to match JSR URLs. If a JSR URL is provided without a trailing slash and without additional path segments (e.g., https://jsr.io/@scope/package/0.19.0), the regex won't match and the fallback logic will incorrectly strip the version part. While template URLs should typically point to actual files with paths, consider making the trailing slash optional in the regex pattern by changing the last \/ to \/? to handle edge cases more robustly: /^(https?:\/\/jsr\.io\/@[^/]+\/[^/]+\/[^/]+\/?)/

Suggested change
/^(https?:\/\/jsr\.io\/@[^/]+\/[^/]+\/[^/]+\/)/,
/^(https?:\/\/jsr\.io\/@[^/]+\/[^/]+\/[^/]+\/?)/,

Copilot uses AI. Check for mistakes.
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