mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(cli): handle local files with query params on emit (#13568)
Fixes #13562
This commit is contained in:
parent
975e55d524
commit
de5a4a1757
4 changed files with 91 additions and 34 deletions
|
@ -2453,6 +2453,11 @@ fn issue12807() {
|
||||||
assert!(status.success());
|
assert!(status.success());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itest!(issue_13562 {
|
||||||
|
args: "run issue13562.ts",
|
||||||
|
output: "issue13562.ts.out",
|
||||||
|
});
|
||||||
|
|
||||||
itest!(import_assertions_static_import {
|
itest!(import_assertions_static_import {
|
||||||
args: "run --allow-read import_assertions/static_import.ts",
|
args: "run --allow-read import_assertions/static_import.ts",
|
||||||
output: "import_assertions/static_import.out",
|
output: "import_assertions/static_import.out",
|
||||||
|
|
3
cli/tests/testdata/issue13562.ts
vendored
Normal file
3
cli/tests/testdata/issue13562.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import { printHello3 } from "./subdir/mod1.ts?q=.json";
|
||||||
|
|
||||||
|
printHello3();
|
2
cli/tests/testdata/issue13562.ts.out
vendored
Normal file
2
cli/tests/testdata/issue13562.ts.out
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[WILDCARD]
|
||||||
|
Hello
|
115
cli/tsc.rs
115
cli/tsc.rs
|
@ -349,32 +349,48 @@ struct EmitArgs {
|
||||||
maybe_specifiers: Option<Vec<String>>,
|
maybe_specifiers: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_emit(state: &mut State, args: Value) -> Result<Value, AnyError> {
|
fn op_emit(state: &mut State, args: EmitArgs) -> Result<Value, AnyError> {
|
||||||
let v: EmitArgs = serde_json::from_value(args)
|
match args.file_name.as_ref() {
|
||||||
.context("Invalid request from JavaScript for \"op_emit\".")?;
|
"deno:///.tsbuildinfo" => state.maybe_tsbuildinfo = Some(args.data),
|
||||||
match v.file_name.as_ref() {
|
_ => {
|
||||||
"deno:///.tsbuildinfo" => state.maybe_tsbuildinfo = Some(v.data),
|
let media_type = MediaType::from(&args.file_name);
|
||||||
_ => state.emitted_files.push(EmittedFile {
|
let media_type = if matches!(
|
||||||
data: v.data,
|
media_type,
|
||||||
maybe_specifiers: if let Some(specifiers) = &v.maybe_specifiers {
|
MediaType::JavaScript
|
||||||
let specifiers = specifiers
|
| MediaType::Mjs
|
||||||
.iter()
|
| MediaType::Cjs
|
||||||
.map(|s| {
|
| MediaType::Dts
|
||||||
if let Some(data_specifier) = state.remapped_specifiers.get(s) {
|
| MediaType::Dmts
|
||||||
data_specifier.clone()
|
| MediaType::Dcts
|
||||||
} else if let Some(remapped_specifier) = state.root_map.get(s) {
|
| MediaType::SourceMap
|
||||||
remapped_specifier.clone()
|
| MediaType::TsBuildInfo
|
||||||
} else {
|
) {
|
||||||
normalize_specifier(s).unwrap()
|
media_type
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
Some(specifiers)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
MediaType::JavaScript
|
||||||
},
|
};
|
||||||
media_type: MediaType::from(&v.file_name),
|
state.emitted_files.push(EmittedFile {
|
||||||
}),
|
data: args.data,
|
||||||
|
maybe_specifiers: if let Some(specifiers) = &args.maybe_specifiers {
|
||||||
|
let specifiers = specifiers
|
||||||
|
.iter()
|
||||||
|
.map(|s| {
|
||||||
|
if let Some(data_specifier) = state.remapped_specifiers.get(s) {
|
||||||
|
data_specifier.clone()
|
||||||
|
} else if let Some(remapped_specifier) = state.root_map.get(s) {
|
||||||
|
remapped_specifier.clone()
|
||||||
|
} else {
|
||||||
|
normalize_specifier(s).unwrap()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
Some(specifiers)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
media_type,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(json!(true))
|
Ok(json!(true))
|
||||||
|
@ -883,11 +899,11 @@ mod tests {
|
||||||
let mut state = setup(None, None, None).await;
|
let mut state = setup(None, None, None).await;
|
||||||
let actual = op_emit(
|
let actual = op_emit(
|
||||||
&mut state,
|
&mut state,
|
||||||
json!({
|
EmitArgs {
|
||||||
"data": "some file content",
|
data: "some file content".to_string(),
|
||||||
"fileName": "cache:///some/file.js",
|
file_name: "cache:///some/file.js".to_string(),
|
||||||
"maybeSpecifiers": ["file:///some/file.ts"]
|
maybe_specifiers: Some(vec!["file:///some/file.ts".to_string()]),
|
||||||
}),
|
},
|
||||||
)
|
)
|
||||||
.expect("should have invoked op");
|
.expect("should have invoked op");
|
||||||
assert_eq!(actual, json!(true));
|
assert_eq!(actual, json!(true));
|
||||||
|
@ -906,15 +922,46 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_emit_strange_specifier() {
|
||||||
|
let mut state = setup(None, None, None).await;
|
||||||
|
let actual = op_emit(
|
||||||
|
&mut state,
|
||||||
|
EmitArgs {
|
||||||
|
data: "some file content".to_string(),
|
||||||
|
file_name: "deno:///some.file.ts?q=.json".to_string(),
|
||||||
|
maybe_specifiers: Some(
|
||||||
|
vec!["file:///some/file.ts?q=.json".to_string()],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.expect("should have invoked op");
|
||||||
|
assert_eq!(actual, json!(true));
|
||||||
|
assert_eq!(state.emitted_files.len(), 1);
|
||||||
|
assert!(state.maybe_tsbuildinfo.is_none());
|
||||||
|
assert_eq!(
|
||||||
|
state.emitted_files[0],
|
||||||
|
EmittedFile {
|
||||||
|
data: "some file content".to_string(),
|
||||||
|
maybe_specifiers: Some(vec![resolve_url_or_path(
|
||||||
|
"file:///some/file.ts?q=.json"
|
||||||
|
)
|
||||||
|
.unwrap()]),
|
||||||
|
media_type: MediaType::JavaScript,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_emit_tsbuildinfo() {
|
async fn test_emit_tsbuildinfo() {
|
||||||
let mut state = setup(None, None, None).await;
|
let mut state = setup(None, None, None).await;
|
||||||
let actual = op_emit(
|
let actual = op_emit(
|
||||||
&mut state,
|
&mut state,
|
||||||
json!({
|
EmitArgs {
|
||||||
"data": "some file content",
|
data: "some file content".to_string(),
|
||||||
"fileName": "deno:///.tsbuildinfo",
|
file_name: "deno:///.tsbuildinfo".to_string(),
|
||||||
}),
|
maybe_specifiers: None,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.expect("should have invoked op");
|
.expect("should have invoked op");
|
||||||
assert_eq!(actual, json!(true));
|
assert_eq!(actual, json!(true));
|
||||||
|
|
Loading…
Add table
Reference in a new issue