diff --git a/cli/args/mod.rs b/cli/args/mod.rs index fb44c0a8fee91d..33863745514d44 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -696,7 +696,8 @@ impl CliOptions { std::env::current_dir() .context("Unable to get CWD") .and_then(|cwd| { - resolve_url_or_path("./$deno$stdin", &cwd).map_err(AnyError::from) + resolve_url_or_path("./$deno$stdin.ts", &cwd) + .map_err(AnyError::from) }) } else if self.flags.watch.is_some() { resolve_url_or_path(&run_flags.script, self.initial_cwd()) diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index d46684905792ee..b29f735c45d56d 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -1824,6 +1824,56 @@ fn exec_path() { assert_eq!(expected, actual); } +#[test] +fn run_from_stdin_defaults_to_ts() { + let source_code = r#" +interface Lollipop { + _: number; +} +console.log("executing typescript"); +"#; + + let mut p = util::deno_cmd() + .arg("run") + .arg("--check") + .arg("-") + .stdin(std::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) + .spawn() + .unwrap(); + let stdin = p.stdin.as_mut().unwrap(); + stdin.write_all(source_code.as_bytes()).unwrap(); + let result = p.wait_with_output().unwrap(); + assert!(result.status.success()); + let stdout_str = std::str::from_utf8(&result.stdout).unwrap().trim(); + assert_eq!(stdout_str, "executing typescript"); +} + +#[test] +fn run_from_stdin_ext() { + let source_code = r#" +let i = 123; +i = "hello" +console.log("executing javascript"); +"#; + + let mut p = util::deno_cmd() + .arg("run") + .args(["--ext", "js"]) + .arg("--check") + .arg("-") + .stdin(std::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) + .spawn() + .unwrap(); + let stdin = p.stdin.as_mut().unwrap(); + stdin.write_all(source_code.as_bytes()).unwrap(); + let result = p.wait_with_output().unwrap(); + assert!(result.status.success()); + let stdout_str = std::str::from_utf8(&result.stdout).unwrap().trim(); + assert_eq!(stdout_str, "executing javascript"); +} + #[cfg(windows)] // Clippy suggests to remove the `NoStd` prefix from all variants. I disagree. #[allow(clippy::enum_variant_names)] @@ -3836,14 +3886,14 @@ itest!(js_without_extension { }); itest!(ts_without_extension { - args: "run --ext ts file_extensions/ts_without_extension", + args: "run --ext ts --check file_extensions/ts_without_extension", output: "file_extensions/ts_without_extension.out", exit_code: 0, }); itest!(ext_flag_takes_precedence_over_extension { - args: "run --ext ts file_extensions/ts_with_js_extension.js", - output: "file_extensions/ts_with_extension.out", + args: "run --ext ts --check file_extensions/ts_with_js_extension.js", + output: "file_extensions/ts_with_js_extension.out", exit_code: 0, }); diff --git a/cli/tests/testdata/file_extensions/ts_with_js_extension.out b/cli/tests/testdata/file_extensions/ts_with_js_extension.out new file mode 100644 index 00000000000000..1c3739bb928e07 --- /dev/null +++ b/cli/tests/testdata/file_extensions/ts_with_js_extension.out @@ -0,0 +1,2 @@ +Check [WILDCARD]/file_extensions/ts_with_js_extension.js +executing typescript with extension diff --git a/cli/tests/testdata/file_extensions/ts_without_extension.out b/cli/tests/testdata/file_extensions/ts_without_extension.out index b15c063c8519c9..e1f019f9eeb917 100644 --- a/cli/tests/testdata/file_extensions/ts_without_extension.out +++ b/cli/tests/testdata/file_extensions/ts_without_extension.out @@ -1 +1,2 @@ +Check [WILDCARD]/file_extensions/ts_without_extension executing typescript with no extension