From e416b0a8b8deff5ec3e4a5165d602e344dfbe465 Mon Sep 17 00:00:00 2001 From: Jesse Jackson Date: Tue, 1 Sep 2020 00:27:29 -0500 Subject: [PATCH 1/5] Add support for URLs with non-default ports Ref. https://github.com/denoland/deno/blob/2da084058397efd6f517ba98c9882760ec0a7bd6/cli/disk_cache.rs#L55 --- core/module_resolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/module_resolver.ts b/core/module_resolver.ts index ce40ca9a..bb543e85 100644 --- a/core/module_resolver.ts +++ b/core/module_resolver.ts @@ -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); From 81262555054f02392a048b753e5da16c5e853782 Mon Sep 17 00:00:00 2001 From: Jesse Jackson Date: Tue, 1 Sep 2020 00:35:00 -0500 Subject: [PATCH 2/5] Format with Prettier --- core/module_resolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/module_resolver.ts b/core/module_resolver.ts index bb543e85..d9cd6892 100644 --- a/core/module_resolver.ts +++ b/core/module_resolver.ts @@ -75,7 +75,7 @@ export class ModuleResolver implements ModuleResolverInterface { const originDir = path.join( getDenoDepsDir(), url.protocol.replace(/:$/, ""), // https: -> https - `${url.hostname}${url.port ? `_PORT${url.port}` : ""}`, // hostname.xyz:3000 -> hostname.xyz_PORT3000 + `${url.hostname}${url.port ? `_PORT${url.port}` : ""}` // hostname.xyz:3000 -> hostname.xyz_PORT3000 ); const hash = hashURL(url); From d260b0965d7a430dd0f4e5fe5bb22d135b42d9df Mon Sep 17 00:00:00 2001 From: Jesse Jackson Date: Fri, 4 Sep 2020 05:58:36 -0500 Subject: [PATCH 3/5] Add tests - default port (https://example.com:443) - non-default port (http://localhost:3000) --- core/module_resolver.test.ts | 21 +++++++++++++++++++ ...7363be7846d6d3b84a2b8697b9bd50c60d4509ab60 | 0 ...b84a2b8697b9bd50c60d4509ab60.metadata.json | 4 ++++ 3 files changed, 25 insertions(+) create mode 100644 core/testdata/deno_dir_manifest/deps/http/localhost_PORT3000/51a61f14fdad404fd2c9187363be7846d6d3b84a2b8697b9bd50c60d4509ab60 create mode 100644 core/testdata/deno_dir_manifest/deps/http/localhost_PORT3000/51a61f14fdad404fd2c9187363be7846d6d3b84a2b8697b9bd50c60d4509ab60.metadata.json diff --git a/core/module_resolver.test.ts b/core/module_resolver.test.ts index ce68e039..0b3653f4 100644 --- a/core/module_resolver.test.ts +++ b/core/module_resolver.test.ts @@ -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", ]) @@ -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[]); diff --git a/core/testdata/deno_dir_manifest/deps/http/localhost_PORT3000/51a61f14fdad404fd2c9187363be7846d6d3b84a2b8697b9bd50c60d4509ab60 b/core/testdata/deno_dir_manifest/deps/http/localhost_PORT3000/51a61f14fdad404fd2c9187363be7846d6d3b84a2b8697b9bd50c60d4509ab60 new file mode 100644 index 00000000..e69de29b diff --git a/core/testdata/deno_dir_manifest/deps/http/localhost_PORT3000/51a61f14fdad404fd2c9187363be7846d6d3b84a2b8697b9bd50c60d4509ab60.metadata.json b/core/testdata/deno_dir_manifest/deps/http/localhost_PORT3000/51a61f14fdad404fd2c9187363be7846d6d3b84a2b8697b9bd50c60d4509ab60.metadata.json new file mode 100644 index 00000000..5f3b30f5 --- /dev/null +++ b/core/testdata/deno_dir_manifest/deps/http/localhost_PORT3000/51a61f14fdad404fd2c9187363be7846d6d3b84a2b8697b9bd50c60d4509ab60.metadata.json @@ -0,0 +1,4 @@ +{ + "headers": {}, + "url": "http://localhost:3000/mod.ts" +} From df3a6692008d8cdb37b2c05931a1e0faa3db5957 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Fri, 4 Sep 2020 13:58:37 +0200 Subject: [PATCH 4/5] fix test --- core/deno_cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/deno_cache.ts b/core/deno_cache.ts index 6a79a136..9ba15a16 100644 --- a/core/deno_cache.ts +++ b/core/deno_cache.ts @@ -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}` : url.port) ); } // invalid From 644b7dd592a29e74eb27e09024aab4e19880b647 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Fri, 4 Sep 2020 15:10:35 +0200 Subject: [PATCH 5/5] Update core/deno_cache.ts Co-authored-by: Jesse Jackson --- core/deno_cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/deno_cache.ts b/core/deno_cache.ts index 9ba15a16..9a1f695a 100644 --- a/core/deno_cache.ts +++ b/core/deno_cache.ts @@ -125,7 +125,7 @@ export class CacheModule implements DenoCacheModule { targetOriginDir = path.join( getDenoDepsDir(), url.protocol.replace(/:$/, ""), // https: -> https - url.hostname + (url.port ? `_PORT${url.port}` : url.port) + `${url.hostname}${url.port ? `_PORT${url.port}` : ""}` ); } // invalid