summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-10-28 20:38:09 +1100
committerGitHub <noreply@github.com>2020-10-28 20:38:09 +1100
commite01664d0ae6259022a901b0dea026ca350a49446 (patch)
treee87f55f4b267dd0d0847d0ba764884cfc61ca1a5 /cli
parenta2f126068e17f6b586a049d5167f48284ed14f8e (diff)
fix(cli): module graph handles redirects properly (#8159)
Fixes #8154
Diffstat (limited to 'cli')
-rw-r--r--cli/module_graph2.rs23
-rw-r--r--cli/tests/integration_tests.rs6
-rw-r--r--cli/tests/redirect_cache.out6
-rw-r--r--cli/tests/subdir/redirects/a.ts9
-rw-r--r--cli/tests/subdir/redirects/b.ts5
5 files changed, 43 insertions, 6 deletions
diff --git a/cli/module_graph2.rs b/cli/module_graph2.rs
index 6c25ca8f2..df2e5fc61 100644
--- a/cli/module_graph2.rs
+++ b/cli/module_graph2.rs
@@ -763,7 +763,14 @@ impl Graph2 {
let root_names: Vec<(ModuleSpecifier, MediaType)> = self
.roots
.iter()
- .map(|ms| (ms.clone(), self.get_media_type(ms).unwrap()))
+ .map(|ms| {
+ (
+ // root modules can be redirects, so before we pass it to tsc we need
+ // to resolve the redirect
+ self.resolve_specifier(ms).clone(),
+ self.get_media_type(ms).unwrap(),
+ )
+ })
.collect();
let maybe_tsbuildinfo = self.maybe_tsbuildinfo.clone();
let hash_data =
@@ -793,7 +800,9 @@ impl Graph2 {
for emit in &response.emitted_files {
if let Some(specifiers) = &emit.maybe_specifiers {
assert!(specifiers.len() == 1, "Unexpected specifier length");
- let specifier = specifiers[0].clone();
+ // The specifier emitted might not be the redirected specifier, and
+ // therefore we need to ensure it is the correct one.
+ let specifier = graph.resolve_specifier(&specifiers[0]);
// Sometimes if tsc sees a CommonJS file it will _helpfully_ output it
// to ESM, which we don't really want unless someone has enabled the
// check_js option.
@@ -805,10 +814,10 @@ impl Graph2 {
}
match emit.media_type {
MediaType::JavaScript => {
- codes.insert(specifier, emit.data.clone());
+ codes.insert(specifier.clone(), emit.data.clone());
}
MediaType::SourceMap => {
- maps.insert(specifier, emit.data.clone());
+ maps.insert(specifier.clone(), emit.data.clone());
}
_ => unreachable!(),
}
@@ -1139,9 +1148,11 @@ impl Graph2 {
// instead.
let result = if prefer_types && dep_module.maybe_types.is_some() {
let (_, types) = dep_module.maybe_types.clone().unwrap();
- types
+ // It is possible that `types` points to a redirected specifier, so we
+ // need to ensure it resolves to the final specifier in the graph.
+ self.resolve_specifier(&types).clone()
} else {
- resolved_specifier
+ dep_module.specifier.clone()
};
Ok(result)
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index cfc946a36..da0a311bb 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -2859,6 +2859,12 @@ itest!(proto_exploit {
output: "proto_exploit.js.out",
});
+itest!(redirect_cache {
+ http_server: true,
+ args: "cache --reload http://localhost:4548/cli/tests/subdir/redirects/a.ts",
+ output: "redirect_cache.out",
+});
+
itest!(deno_test_coverage {
args: "test --coverage --unstable test_coverage.ts",
output: "test_coverage.out",
diff --git a/cli/tests/redirect_cache.out b/cli/tests/redirect_cache.out
new file mode 100644
index 000000000..ad26d0108
--- /dev/null
+++ b/cli/tests/redirect_cache.out
@@ -0,0 +1,6 @@
+Download http://localhost:4548/cli/tests/subdir/redirects/a.ts
+Download http://localhost:4546/cli/tests/subdir/redirects/a.ts
+Download http://localhost:4545/cli/tests/subdir/redirects/a.ts
+Download http://localhost:4545/cli/tests/subdir/redirects/b.ts
+Download http://localhost:4545/cli/tests/subdir/redirects/a.ts
+Check http://localhost:4548/cli/tests/subdir/redirects/a.ts
diff --git a/cli/tests/subdir/redirects/a.ts b/cli/tests/subdir/redirects/a.ts
new file mode 100644
index 000000000..071ee4728
--- /dev/null
+++ b/cli/tests/subdir/redirects/a.ts
@@ -0,0 +1,9 @@
+import { createA } from "./b.ts";
+
+export class A {
+ private _a = "a";
+}
+
+export function start(): A {
+ return createA();
+}
diff --git a/cli/tests/subdir/redirects/b.ts b/cli/tests/subdir/redirects/b.ts
new file mode 100644
index 000000000..cdb71eaae
--- /dev/null
+++ b/cli/tests/subdir/redirects/b.ts
@@ -0,0 +1,5 @@
+import { A } from "./a.ts";
+
+export function createA(): A {
+ return new A();
+}