Skip to content

Commit

Permalink
Add support for URLs with non-default ports (#173)
Browse files Browse the repository at this point in the history
Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
  • Loading branch information
jsejcksn and lucacasonato authored Sep 4, 2020
1 parent 5eb19c6 commit 6f05bab
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/deno_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class CacheModule implements DenoCacheModule {
targetOriginDir = path.join(
getDenoDepsDir(),
url.protocol.replace(/:$/, ""), // https: -> https
url.hostname
`${url.hostname}${url.port ? `_PORT${url.port}` : ""}`
);
}
// invalid
Expand Down
21 changes: 21 additions & 0 deletions core/module_resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ test("core / module_resolver: resolve module from Deno cache", () => {
"./sub/mod.ts",
"/esm/mod.ts",
"https://example.com/esm/mod.ts",
"https://example.com:443/esm/mod.ts",
"http://localhost:3000/mod.ts",
"./module_not_exist.ts",
"https://module.not.exist.com/mod.ts",
])
Expand Down Expand Up @@ -56,6 +58,25 @@ test("core / module_resolver: resolve module from Deno cache", () => {
"8afd52da760dab7f2deda4b7453197f50421f310372c5da3f3847ffd062fa1cf"
),
},
{
extension: ".ts",
origin: "https://example.com:443/esm/mod.ts",
filepath: path.join(
path.dirname(cacheFilepath),
"8afd52da760dab7f2deda4b7453197f50421f310372c5da3f3847ffd062fa1cf"
),
},
{
extension: ".ts",
origin: "http://localhost:3000/mod.ts",
filepath: path.join(
denoDir,
"deps",
"http",
"localhost_PORT3000",
"51a61f14fdad404fd2c9187363be7846d6d3b84a2b8697b9bd50c60d4509ab60"
),
},
undefined,
undefined,
] as ResolvedModule[]);
Expand Down
2 changes: 1 addition & 1 deletion core/module_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ModuleResolver implements ModuleResolverInterface {
const originDir = path.join(
getDenoDepsDir(),
url.protocol.replace(/:$/, ""), // https: -> https
url.hostname
`${url.hostname}${url.port ? `_PORT${url.port}` : ""}` // hostname.xyz:3000 -> hostname.xyz_PORT3000
);

const hash = hashURL(url);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"headers": {},
"url": "http://localhost:3000/mod.ts"
}

0 comments on commit 6f05bab

Please sign in to comment.