-
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix JSR URL template resolution for Homebrew installations #99
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,9 +35,13 @@ export async function resolveSubprocessTemplate( | |||||
| // Build dependency graph to find all imports | ||||||
| const graph = await createGraph(templateUrl.href); | ||||||
|
|
||||||
| // Collect all local (file://) modules from the graph | ||||||
| // 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); | ||||||
|
|
||||||
| const localModules = graph.modules.filter( | ||||||
| (m) => m.specifier.startsWith("file://") && !m.error, | ||||||
| (m) => m.specifier.startsWith(localModulePrefix) && !m.error, | ||||||
| ); | ||||||
|
|
||||||
| if (localModules.length === 0) { | ||||||
|
|
@@ -87,6 +91,31 @@ export async function resolveSubprocessTemplate( | |||||
| return files; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get the prefix for identifying "local" modules that should be bundled | ||||||
| * | ||||||
| * - For file:// URLs: all file:// modules are considered local | ||||||
| * - For JSR URLs (https://jsr.io/@scope/package/version/...): modules under the same package | ||||||
| * - For other remote URLs: modules in the same directory tree as the template | ||||||
| */ | ||||||
| function getLocalModulePrefix(templateUrl: URL): string { | ||||||
| if (templateUrl.protocol === "file:") { | ||||||
| return "file://"; | ||||||
| } | ||||||
|
|
||||||
| // 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\/@[^/]+\/[^/]+\/[^/]+\/)/, | ||||||
|
||||||
| /^(https?:\/\/jsr\.io\/@[^/]+\/[^/]+\/[^/]+\/)/, | |
| /^(https?:\/\/jsr\.io\/@[^/]+\/[^/]+\/[^/]+\/?)/, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { assertEquals } from "@std/assert"; | ||
| import { _internal } from "./subprocess_template.ts"; | ||
|
|
||
| const { getLocalModulePrefix } = _internal; | ||
|
|
||
| Deno.test("getLocalModulePrefix", async (t) => { | ||
| await t.step("returns file:// for local file URLs", () => { | ||
| const url = new URL("file:///path/to/template.ts"); | ||
| assertEquals(getLocalModulePrefix(url), "file://"); | ||
| }); | ||
|
|
||
| await t.step("extracts JSR package base for JSR URLs", () => { | ||
| const url = new URL( | ||
| "https://jsr.io/@probitas/probitas/0.19.0/src/cli/_templates/run.ts", | ||
| ); | ||
| assertEquals( | ||
| getLocalModulePrefix(url), | ||
| "https://jsr.io/@probitas/probitas/0.19.0/", | ||
| ); | ||
| }); | ||
|
|
||
| await t.step("handles scoped JSR packages with different versions", () => { | ||
| const url = new URL( | ||
| "https://jsr.io/@std/path/1.0.0/mod.ts", | ||
| ); | ||
| assertEquals( | ||
| getLocalModulePrefix(url), | ||
| "https://jsr.io/@std/path/1.0.0/", | ||
| ); | ||
| }); | ||
|
|
||
| await t.step("returns directory for non-JSR remote URLs", () => { | ||
| const url = new URL( | ||
| "https://example.com/modules/template.ts", | ||
| ); | ||
| assertEquals( | ||
| getLocalModulePrefix(url), | ||
| "https://example.com/modules/", | ||
| ); | ||
| }); | ||
|
|
||
| await t.step("handles HTTP (non-HTTPS) JSR URLs", () => { | ||
| const url = new URL( | ||
| "http://jsr.io/@probitas/probitas/0.19.0/src/cli/_templates/run.ts", | ||
| ); | ||
| assertEquals( | ||
| getLocalModulePrefix(url), | ||
| "http://jsr.io/@probitas/probitas/0.19.0/", | ||
| ); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
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)"