summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2024-09-18 12:15:13 -0700
committerGitHub <noreply@github.com>2024-09-18 21:15:13 +0200
commita1d0a427e807959666a6b23ae015e4e04659abf5 (patch)
treec588767979d1f7ded1830d042f737774b23addf6
parent7a41a939972b701e96cb70cbf0516595fefcae02 (diff)
feat: default to TS for file extension and support ext flag in more scenarios (#25472)
Closes #11220 Currently does lint, fmt, and repl
-rw-r--r--.dprint.json4
-rw-r--r--cli/args/flags.rs34
-rw-r--r--cli/args/mod.rs2
-rw-r--r--cli/cache/mod.rs2
-rw-r--r--cli/file_fetcher.rs11
-rw-r--r--cli/graph_container.rs4
-rw-r--r--cli/lsp/language_server.rs1
-rw-r--r--cli/lsp/testing/execution.rs2
-rw-r--r--cli/module_loader.rs22
-rw-r--r--cli/tools/bench/mod.rs6
-rw-r--r--cli/tools/check.rs2
-rw-r--r--cli/tools/fmt.rs51
-rw-r--r--cli/tools/lint/linter.rs9
-rw-r--r--cli/tools/lint/mod.rs29
-rw-r--r--cli/tools/registry/pm/cache_deps.rs1
-rw-r--r--cli/tools/test/mod.rs10
-rw-r--r--tests/integration/run_tests.rs11
-rw-r--r--tests/specs/bench/default_ts/__test__.jsonc13
-rw-r--r--tests/specs/bench/default_ts/as_ts.js3
-rw-r--r--tests/specs/bench/default_ts/ext.out5
-rw-r--r--tests/specs/bench/default_ts/extensionless3
-rw-r--r--tests/specs/bench/default_ts/extensionless.out5
-rw-r--r--tests/specs/fmt/default_ts/__test__.jsonc18
-rw-r--r--tests/specs/fmt/default_ts/as_ts.js1
-rw-r--r--tests/specs/fmt/default_ts/extensionless1
-rw-r--r--tests/specs/lint/default_ts/__test__.jsonc18
-rw-r--r--tests/specs/lint/default_ts/as_ts.js1
-rw-r--r--tests/specs/lint/default_ts/extensionless1
-rw-r--r--tests/specs/mod.rs5
-rw-r--r--tests/specs/run/default_ts/__test__.jsonc18
-rw-r--r--tests/specs/run/default_ts/as_ts.js2
-rw-r--r--tests/specs/run/default_ts/extensionless2
-rw-r--r--tests/specs/test/default_ts/__test__.jsonc13
-rw-r--r--tests/specs/test/default_ts/as_ts.js3
-rw-r--r--tests/specs/test/default_ts/ext.out4
-rw-r--r--tests/specs/test/default_ts/extensionless3
-rw-r--r--tests/specs/test/default_ts/extensionless.out4
-rwxr-xr-xtools/lint.js2
38 files changed, 257 insertions, 69 deletions
diff --git a/.dprint.json b/.dprint.json
index 0acfb5ca3..6ee3db3c5 100644
--- a/.dprint.json
+++ b/.dprint.json
@@ -39,10 +39,14 @@
"tests/node_compat/runner/TODO.md",
"tests/node_compat/test",
"tests/registry/",
+ "tests/specs/bench/default_ts",
"tests/specs/fmt",
"tests/specs/lint/bom",
+ "tests/specs/lint/default_ts",
"tests/specs/lint/syntax_error_reporting",
"tests/specs/publish/no_check_surfaces_syntax_error",
+ "tests/specs/run/default_ts",
+ "tests/specs/test/default_ts",
"tests/testdata/byte_order_mark.ts",
"tests/testdata/encoding",
"tests/testdata/file_extensions/ts_with_js_extension.js",
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 5d3929748..d66ee253f 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -299,7 +299,6 @@ pub struct LintFlags {
pub json: bool,
pub compact: bool,
pub watch: Option<WatchFlags>,
- pub ext: Option<String>,
}
impl LintFlags {
@@ -1629,6 +1628,7 @@ If you specify a directory instead of a file, the path is expanded to all contai
.arg(no_clear_screen_arg())
.arg(script_arg().last(true))
.arg(env_file_arg())
+ .arg(executable_ext_arg())
})
}
@@ -2125,9 +2125,6 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
Arg::new("ext")
.long("ext")
.help("Set content type of the supplied file")
- // prefer using ts for formatting instead of js because ts works in more scenarios
- .default_value("ts")
- .hide_default_value(true)
.value_parser([
"ts", "tsx", "js", "jsx", "md", "json", "jsonc", "css", "scss",
"sass", "less", "html", "svelte", "vue", "astro", "yml", "yaml",
@@ -2910,6 +2907,7 @@ or <c>**/__tests__/**</>:
.action(ArgAction::SetTrue)
)
.arg(env_file_arg())
+ .arg(executable_ext_arg())
)
}
@@ -4074,6 +4072,7 @@ fn bench_parse(
flags.type_check_mode = TypeCheckMode::Local;
runtime_args_parse(flags, matches, true, false)?;
+ ext_arg_parse(flags, matches);
// NOTE: `deno bench` always uses `--no-prompt`, tests shouldn't ever do
// interactive prompts, unless done by user code
@@ -4597,8 +4596,9 @@ fn lint_parse(
matches: &mut ArgMatches,
) -> clap::error::Result<()> {
unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionOnly);
-
+ ext_arg_parse(flags, matches);
config_args_parse(flags, matches);
+
let files = match matches.remove_many::<String>("files") {
Some(f) => f.collect(),
None => vec![],
@@ -4625,7 +4625,6 @@ fn lint_parse(
let json = matches.get_flag("json");
let compact = matches.get_flag("compact");
- let ext = matches.remove_one::<String>("ext");
flags.subcommand = DenoSubcommand::Lint(LintFlags {
files: FileFlags {
@@ -4640,7 +4639,6 @@ fn lint_parse(
json,
compact,
watch: watch_arg_parse(matches)?,
- ext,
});
Ok(())
}
@@ -4821,6 +4819,8 @@ fn test_parse(
) -> clap::error::Result<()> {
flags.type_check_mode = TypeCheckMode::Local;
runtime_args_parse(flags, matches, true, true)?;
+ ext_arg_parse(flags, matches);
+
// NOTE: `deno test` always uses `--no-prompt`, tests shouldn't ever do
// interactive prompts, unless done by user code
flags.permissions.no_prompt = true;
@@ -6273,7 +6273,6 @@ mod tests {
unstable_yaml: false,
watch: Default::default(),
}),
- ext: Some("ts".to_string()),
..Flags::default()
}
);
@@ -6300,7 +6299,6 @@ mod tests {
unstable_yaml: false,
watch: Default::default(),
}),
- ext: Some("ts".to_string()),
..Flags::default()
}
);
@@ -6327,7 +6325,6 @@ mod tests {
unstable_yaml: false,
watch: Default::default(),
}),
- ext: Some("ts".to_string()),
..Flags::default()
}
);
@@ -6354,7 +6351,6 @@ mod tests {
unstable_yaml: false,
watch: Some(Default::default()),
}),
- ext: Some("ts".to_string()),
..Flags::default()
}
);
@@ -6394,7 +6390,6 @@ mod tests {
exclude: vec![],
})
}),
- ext: Some("ts".to_string()),
..Flags::default()
}
);
@@ -6428,7 +6423,6 @@ mod tests {
unstable_yaml: false,
watch: Some(Default::default()),
}),
- ext: Some("ts".to_string()),
..Flags::default()
}
);
@@ -6455,7 +6449,6 @@ mod tests {
unstable_yaml: false,
watch: Default::default(),
}),
- ext: Some("ts".to_string()),
config_flag: ConfigFlag::Path("deno.jsonc".to_string()),
..Flags::default()
}
@@ -6491,7 +6484,6 @@ mod tests {
watch: Some(Default::default()),
}),
config_flag: ConfigFlag::Path("deno.jsonc".to_string()),
- ext: Some("ts".to_string()),
..Flags::default()
}
);
@@ -6530,7 +6522,6 @@ mod tests {
unstable_yaml: false,
watch: Default::default(),
}),
- ext: Some("ts".to_string()),
..Flags::default()
}
);
@@ -6564,7 +6555,6 @@ mod tests {
unstable_yaml: false,
watch: Default::default(),
}),
- ext: Some("ts".to_string()),
..Flags::default()
}
);
@@ -6589,7 +6579,6 @@ mod tests {
json: false,
compact: false,
watch: Default::default(),
- ext: None,
}),
..Flags::default()
}
@@ -6618,7 +6607,6 @@ mod tests {
json: false,
compact: false,
watch: Some(Default::default()),
- ext: None,
}),
..Flags::default()
}
@@ -6652,7 +6640,6 @@ mod tests {
no_clear_screen: true,
exclude: vec![],
}),
- ext: None,
}),
..Flags::default()
}
@@ -6680,7 +6667,6 @@ mod tests {
json: false,
compact: false,
watch: Default::default(),
- ext: None,
}),
..Flags::default()
}
@@ -6703,7 +6689,6 @@ mod tests {
json: false,
compact: false,
watch: Default::default(),
- ext: None,
}),
..Flags::default()
}
@@ -6731,7 +6716,6 @@ mod tests {
json: false,
compact: false,
watch: Default::default(),
- ext: None,
}),
..Flags::default()
}
@@ -6760,7 +6744,6 @@ mod tests {
json: false,
compact: false,
watch: Default::default(),
- ext: None,
}),
..Flags::default()
}
@@ -6783,7 +6766,6 @@ mod tests {
json: true,
compact: false,
watch: Default::default(),
- ext: None,
}),
..Flags::default()
}
@@ -6813,7 +6795,6 @@ mod tests {
json: true,
compact: false,
watch: Default::default(),
- ext: None,
}),
config_flag: ConfigFlag::Path("Deno.jsonc".to_string()),
..Flags::default()
@@ -6844,7 +6825,6 @@ mod tests {
json: false,
compact: true,
watch: Default::default(),
- ext: None,
}),
config_flag: ConfigFlag::Path("Deno.jsonc".to_string()),
..Flags::default()
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index 0851dfd6c..c4dda95ce 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -1131,7 +1131,7 @@ impl CliOptions {
resolve_url_or_path(&compile_flags.source_file, self.initial_cwd())?
}
DenoSubcommand::Eval(_) => {
- resolve_url_or_path("./$deno$eval", self.initial_cwd())?
+ resolve_url_or_path("./$deno$eval.ts", self.initial_cwd())?
}
DenoSubcommand::Repl(_) => {
resolve_url_or_path("./$deno$repl.ts", self.initial_cwd())?
diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs
index 86b65bc53..a95c35086 100644
--- a/cli/cache/mod.rs
+++ b/cli/cache/mod.rs
@@ -108,7 +108,7 @@ pub use deno_cache_dir::HttpCache;
/// a concise interface to the DENO_DIR when building module graphs.
pub struct FetchCacher {
file_fetcher: Arc<FileFetcher>,
- file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>,
+ pub file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>,
global_http_cache: Arc<GlobalHttpCache>,
npm_resolver: Arc<dyn CliNpmResolver>,
module_info_cache: Arc<ModuleInfoCache>,
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index ca8fcbee4..2f4b0b3dc 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -138,11 +138,20 @@ fn fetch_local(specifier: &ModuleSpecifier) -> Result<File, AnyError> {
let local = specifier.to_file_path().map_err(|_| {
uri_error(format!("Invalid file path.\n Specifier: {specifier}"))
})?;
+ // If it doesnt have a extension, we want to treat it as typescript by default
+ let headers = if local.extension().is_none() {
+ Some(HashMap::from([(
+ "content-type".to_string(),
+ "application/typescript".to_string(),
+ )]))
+ } else {
+ None
+ };
let bytes = fs::read(local)?;
Ok(File {
specifier: specifier.clone(),
- maybe_headers: None,
+ maybe_headers: headers,
source: bytes.into(),
})
}
diff --git a/cli/graph_container.rs b/cli/graph_container.rs
index 9f049946f..211b278e0 100644
--- a/cli/graph_container.rs
+++ b/cli/graph_container.rs
@@ -65,6 +65,7 @@ impl MainModuleGraphContainer {
pub async fn check_specifiers(
&self,
specifiers: &[ModuleSpecifier],
+ ext_overwrite: Option<&String>,
) -> Result<(), AnyError> {
let mut graph_permit = self.acquire_update_permit().await;
let graph = graph_permit.graph_mut();
@@ -76,6 +77,7 @@ impl MainModuleGraphContainer {
false,
self.cli_options.ts_type_lib_window(),
FetchPermissionsOption::AllowAll,
+ ext_overwrite,
)
.await?;
graph_permit.commit();
@@ -94,7 +96,7 @@ impl MainModuleGraphContainer {
log::warn!("{} No matching files found.", colors::yellow("Warning"));
}
- self.check_specifiers(&specifiers).await
+ self.check_specifiers(&specifiers, None).await
}
pub fn collect_specifiers(
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 5f6e38082..6626767dd 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -1420,6 +1420,7 @@ impl Inner {
document.content(),
&fmt_options,
&unstable_options,
+ None,
)
}
};
diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs
index 55d81f342..88fb496e4 100644
--- a/cli/lsp/testing/execution.rs
+++ b/cli/lsp/testing/execution.rs
@@ -235,7 +235,7 @@ impl TestRun {
)?;
let main_graph_container = factory.main_module_graph_container().await?;
main_graph_container
- .check_specifiers(&self.queue.iter().cloned().collect::<Vec<_>>())
+ .check_specifiers(&self.queue.iter().cloned().collect::<Vec<_>>(), None)
.await?;
let (concurrent_jobs, fail_fast) =
diff --git a/cli/module_loader.rs b/cli/module_loader.rs
index 86824cd70..a81c5a0aa 100644
--- a/cli/module_loader.rs
+++ b/cli/module_loader.rs
@@ -105,11 +105,32 @@ impl ModuleLoadPreparer {
is_dynamic: bool,
lib: TsTypeLib,
permissions: crate::file_fetcher::FetchPermissionsOption,
+ ext_overwrite: Option<&String>,
) -> Result<(), AnyError> {
log::debug!("Preparing module load.");
let _pb_clear_guard = self.progress_bar.clear_guard();
let mut cache = self.module_graph_builder.create_fetch_cacher(permissions);
+ if let Some(ext) = ext_overwrite {
+ let maybe_content_type = match ext.as_str() {
+ "ts" => Some("text/typescript"),
+ "tsx" => Some("text/tsx"),
+ "js" => Some("text/javascript"),
+ "jsx" => Some("text/jsx"),
+ _ => None,
+ };
+ if let Some(content_type) = maybe_content_type {
+ for root in roots {
+ cache.file_header_overrides.insert(
+ root.clone(),
+ std::collections::HashMap::from([(
+ "content-type".to_string(),
+ content_type.to_string(),
+ )]),
+ );
+ }
+ }
+ }
log::debug!("Building module graph.");
let has_type_checked = !graph.roots.is_empty();
@@ -763,6 +784,7 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
is_dynamic,
lib,
root_permissions.into(),
+ None,
)
.await?;
update_permit.commit();
diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs
index f133759c9..be5d0ad0e 100644
--- a/cli/tools/bench/mod.rs
+++ b/cli/tools/bench/mod.rs
@@ -442,7 +442,9 @@ pub async fn run_benchmarks(
}
let main_graph_container = factory.main_module_graph_container().await?;
- main_graph_container.check_specifiers(&specifiers).await?;
+ main_graph_container
+ .check_specifiers(&specifiers, cli_options.ext_flag().as_ref())
+ .await?;
if workspace_bench_options.no_run {
return Ok(());
@@ -569,7 +571,7 @@ pub async fn run_benchmarks_with_watch(
factory
.main_module_graph_container()
.await?
- .check_specifiers(&specifiers)
+ .check_specifiers(&specifiers, cli_options.ext_flag().as_ref())
.await?;
if workspace_bench_options.no_run {
diff --git a/cli/tools/check.rs b/cli/tools/check.rs
index 9c464fa16..c22afbb9a 100644
--- a/cli/tools/check.rs
+++ b/cli/tools/check.rs
@@ -73,7 +73,7 @@ pub async fn check(
};
main_graph_container
- .check_specifiers(&specifiers_for_typecheck)
+ .check_specifiers(&specifiers_for_typecheck, None)
.await
}
diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs
index 17ddf6c65..3f927545d 100644
--- a/cli/tools/fmt.rs
+++ b/cli/tools/fmt.rs
@@ -120,7 +120,13 @@ pub async fn format(
};
}
- format_files(caches, &fmt_flags, paths_with_options_batches).await?;
+ format_files(
+ caches,
+ cli_options,
+ &fmt_flags,
+ paths_with_options_batches,
+ )
+ .await?;
Ok(())
})
@@ -133,7 +139,8 @@ pub async fn format(
let caches = factory.caches()?;
let paths_with_options_batches =
resolve_paths_with_options_batches(cli_options, &fmt_flags)?;
- format_files(caches, &fmt_flags, paths_with_options_batches).await?;
+ format_files(caches, cli_options, &fmt_flags, paths_with_options_batches)
+ .await?;
}
Ok(())
@@ -172,6 +179,7 @@ fn resolve_paths_with_options_batches(
async fn format_files(
caches: &Arc<Caches>,
+ cli_options: &Arc<CliOptions>,
fmt_flags: &FmtFlags,
paths_with_options_batches: Vec<PathsWithOptions>,
) -> Result<(), AnyError> {
@@ -199,6 +207,7 @@ async fn format_files(
fmt_options.options,
fmt_options.unstable,
incremental_cache.clone(),
+ cli_options.ext_flag().clone(),
)
.await?;
incremental_cache.wait_completion().await;
@@ -211,11 +220,16 @@ fn collect_fmt_files(
cli_options: &CliOptions,
files: FilePatterns,
) -> Result<Vec<PathBuf>, AnyError> {
- FileCollector::new(|e| is_supported_ext_fmt(e.path))
- .ignore_git_folder()
- .ignore_node_modules()
- .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned))
- .collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files)
+ FileCollector::new(|e| {
+ cli_options.ext_flag().as_ref().is_some_and(|ext| {
+ is_supported_ext_fmt(Path::new(&format!("placeholder.{ext}")))
+ }) || is_supported_ext_fmt(e.path)
+ || e.path.extension().is_none()
+ })
+ .ignore_git_folder()
+ .ignore_node_modules()
+ .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned))
+ .collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files)
}
/// Formats markdown (using <https://github.com/dprint/dprint-plugin-markdown>) and its code blocks
@@ -449,8 +463,11 @@ pub fn format_file(
file_text: &str,
fmt_options: &FmtOptionsConfig,
unstable_options: &UnstableFmtOptions,
+ ext: Option<String>,
) -> Result<Option<String>, AnyError> {
- let ext = get_extension(file_path).unwrap_or_default();
+ let ext = ext
+ .or_else(|| get_extension(file_path))
+ .unwrap_or("ts".to_string());
match ext.as_str() {
"md" | "mkd" | "mkdn" | "mdwn" | "mdown" | "markdown" => {
@@ -493,14 +510,14 @@ pub fn format_file(
"ipynb" => dprint_plugin_jupyter::format_text(
file_text,
|file_path: &Path, file_text: String| {
- format_file(file_path, &file_text, fmt_options, unstable_options)
+ format_file(file_path, &file_text, fmt_options, unstable_options, None)
},
),
_ => {
let config = get_resolved_typescript_config(fmt_options);
dprint_plugin_typescript::format_text(
file_path,
- None,
+ Some(&ext),
file_text.to_string(),
&config,
)
@@ -526,6 +543,7 @@ trait Formatter {
fmt_options: FmtOptionsConfig,
unstable_options: UnstableFmtOptions,
incremental_cache: Arc<IncrementalCache>,
+ ext: Option<String>,
) -> Result<(), AnyError>;
fn finish(&self) -> Result<(), AnyError>;
@@ -545,6 +563,7 @@ impl Formatter for CheckFormatter {
fmt_options: FmtOptionsConfig,
unstable_options: UnstableFmtOptions,
incremental_cache: Arc<IncrementalCache>,
+ ext: Option<String>,
) -> Result<(), AnyError> {
// prevent threads outputting at the same time
let output_lock = Arc::new(Mutex::new(0));
@@ -566,6 +585,7 @@ impl Formatter for CheckFormatter {
&file_text,
&fmt_options,
&unstable_options,
+ ext.clone(),
) {
Ok(Some(formatted_text)) => {
not_formatted_files_count.fetch_add(1, Ordering::Relaxed);
@@ -643,6 +663,7 @@ impl Formatter for RealFormatter {
fmt_options: FmtOptionsConfig,
unstable_options: UnstableFmtOptions,
incremental_cache: Arc<IncrementalCache>,
+ ext: Option<String>,
) -> Result<(), AnyError> {
let output_lock = Arc::new(Mutex::new(0)); // prevent threads outputting at the same time
@@ -662,7 +683,13 @@ impl Formatter for RealFormatter {
&file_path,
&file_contents.text,
|file_path, file_text| {
- format_file(file_path, file_text, &fmt_options, &unstable_options)
+ format_file(
+ file_path,
+ file_text,
+ &fmt_options,
+ &unstable_options,
+ ext.clone(),
+ )
},
) {
Ok(Some(formatted_text)) => {
@@ -788,6 +815,7 @@ fn format_stdin(
&source,
&fmt_options.options,
&fmt_options.unstable,
+ None,
)?;
if fmt_flags.check {
#[allow(clippy::print_stdout)]
@@ -1269,6 +1297,7 @@ mod test {
..Default::default()
},
&UnstableFmtOptions::default(),
+ None,
)
.unwrap()
.unwrap();
diff --git a/cli/tools/lint/linter.rs b/cli/tools/lint/linter.rs
index 777fe4d09..2c2bc43ac 100644
--- a/cli/tools/lint/linter.rs
+++ b/cli/tools/lint/linter.rs
@@ -94,9 +94,16 @@ impl CliLinter {
&self,
file_path: &Path,
source_code: String,
+ ext: Option<&str>,
) -> Result<(ParsedSource, Vec<LintDiagnostic>), AnyError> {
let specifier = specifier_from_file_path(file_path)?;
- let media_type = MediaType::from_specifier(&specifier);
+ let media_type = if let Some(ext) = ext {
+ MediaType::from_str(&format!("placeholder.{ext}"))
+ } else if file_path.extension().is_none() {
+ MediaType::TypeScript
+ } else {
+ MediaType::from_specifier(&specifier)
+ };
if self.fix {
self.lint_file_and_fix(&specifier, media_type, source_code, file_path)
diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs
index d5d174bf7..a52d4e462 100644
--- a/cli/tools/lint/mod.rs
+++ b/cli/tools/lint/mod.rs
@@ -117,6 +117,7 @@ pub async fn lint(
for paths_with_options in paths_with_options_batches {
linter
.lint_files(
+ cli_options,
paths_with_options.options,
lint_config.clone(),
paths_with_options.dir,
@@ -155,7 +156,7 @@ pub async fn lint(
start_dir.maybe_deno_json().map(|c| c.as_ref()),
)?;
let mut file_path = cli_options.initial_cwd().join(STDIN_FILE_NAME);
- if let Some(ext) = &lint_flags.ext {
+ if let Some(ext) = cli_options.ext_flag() {
file_path.set_extension(ext);
}
let r = lint_stdin(&file_path, lint_rules, deno_lint_config);
@@ -179,6 +180,7 @@ pub async fn lint(
for paths_with_options in paths_with_options_batches {
linter
.lint_files(
+ cli_options,
paths_with_options.options,
deno_lint_config.clone(),
paths_with_options.dir,
@@ -264,6 +266,7 @@ impl WorkspaceLinter {
pub async fn lint_files(
&mut self,
+ cli_options: &Arc<CliOptions>,
lint_options: LintOptions,
lint_config: LintConfig,
member_dir: WorkspaceDirectory,
@@ -348,6 +351,7 @@ impl WorkspaceLinter {
let reporter_lock = self.reporter_lock.clone();
let maybe_incremental_cache = maybe_incremental_cache.clone();
let linter = linter.clone();
+ let cli_options = cli_options.clone();
async move {
run_parallelized(paths, {
move |file_path| {
@@ -361,7 +365,11 @@ impl WorkspaceLinter {
}
}
- let r = linter.lint_file(&file_path, file_text);
+ let r = linter.lint_file(
+ &file_path,
+ file_text,
+ cli_options.ext_flag().as_deref(),
+ );
if let Ok((file_source, file_diagnostics)) = &r {
if let Some(incremental_cache) = &maybe_incremental_cache {
if file_diagnostics.is_empty() {
@@ -421,11 +429,16 @@ fn collect_lint_files(
cli_options: &CliOptions,
files: FilePatterns,
) -> Result<Vec<PathBuf>, AnyError> {
- FileCollector::new(|e| is_script_ext(e.path))
- .ignore_git_folder()
- .ignore_node_modules()
- .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned))
- .collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files)
+ FileCollector::new(|e| {
+ cli_options.ext_flag().as_ref().is_some_and(|ext| {
+ is_script_ext(Path::new(&format!("placeholder.{ext}")))
+ }) || is_script_ext(e.path)
+ || e.path.extension().is_none()
+ })
+ .ignore_git_folder()
+ .ignore_node_modules()
+ .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned))
+ .collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files)
}
#[allow(clippy::print_stdout)]
@@ -497,7 +510,7 @@ fn lint_stdin(
});
linter
- .lint_file(file_path, deno_ast::strip_bom(source_code))
+ .lint_file(file_path, deno_ast::strip_bom(source_code), None)
.map_err(AnyError::from)
}
diff --git a/cli/tools/registry/pm/cache_deps.rs b/cli/tools/registry/pm/cache_deps.rs
index a03c30df8..a59817055 100644
--- a/cli/tools/registry/pm/cache_deps.rs
+++ b/cli/tools/registry/pm/cache_deps.rs
@@ -107,6 +107,7 @@ pub async fn cache_top_level_deps(
false,
deno_config::deno_json::TsTypeLib::DenoWorker,
crate::file_fetcher::FetchPermissionsOption::AllowAll,
+ None,
)
.await?;
}
diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs
index d043ffcba..e81abad0b 100644
--- a/cli/tools/test/mod.rs
+++ b/cli/tools/test/mod.rs
@@ -1583,7 +1583,10 @@ pub async fn run_tests(
// Typecheck
main_graph_container
- .check_specifiers(&specifiers_for_typecheck_and_test)
+ .check_specifiers(
+ &specifiers_for_typecheck_and_test,
+ cli_options.ext_flag().as_ref(),
+ )
.await?;
if workspace_test_options.no_run {
@@ -1757,7 +1760,10 @@ pub async fn run_tests_with_watch(
// Typecheck
main_graph_container
- .check_specifiers(&specifiers_for_typecheck_and_test)
+ .check_specifiers(
+ &specifiers_for_typecheck_and_test,
+ cli_options.ext_flag().as_ref(),
+ )
.await?;
if workspace_test_options.no_run {
diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs
index 50f0f58f8..6b0901e26 100644
--- a/tests/integration/run_tests.rs
+++ b/tests/integration/run_tests.rs
@@ -148,11 +148,6 @@ itest!(_021_mjs_modules {
output: "run/021_mjs_modules.ts.out",
});
-itest!(_023_no_ext {
- args: "run --reload --check run/023_no_ext",
- output: "run/023_no_ext.out",
-});
-
itest!(_025_reload_js_type_error {
args: "run --quiet --reload run/025_reload_js_type_error.js",
output: "run/025_reload_js_type_error.js.out",
@@ -4209,12 +4204,6 @@ itest!(error_cause_recursive {
exit_code: 1,
});
-itest!(default_file_extension_is_js {
- args: "run --check file_extensions/js_without_extension",
- output: "file_extensions/js_without_extension.out",
- exit_code: 0,
-});
-
itest!(js_without_extension {
args: "run --ext js --check file_extensions/js_without_extension",
output: "file_extensions/js_without_extension.out",
diff --git a/tests/specs/bench/default_ts/__test__.jsonc b/tests/specs/bench/default_ts/__test__.jsonc
new file mode 100644
index 000000000..a5657290d
--- /dev/null
+++ b/tests/specs/bench/default_ts/__test__.jsonc
@@ -0,0 +1,13 @@
+{
+ "tempDir": true,
+ "tests": {
+ "ext_flag": {
+ "args": "bench --ext=ts as_ts.js",
+ "output": "ext.out"
+ },
+ "extensionless": {
+ "args": "bench extensionless",
+ "output": "extensionless.out"
+ }
+ }
+}
diff --git a/tests/specs/bench/default_ts/as_ts.js b/tests/specs/bench/default_ts/as_ts.js
new file mode 100644
index 000000000..914439a9f
--- /dev/null
+++ b/tests/specs/bench/default_ts/as_ts.js
@@ -0,0 +1,3 @@
+Deno.bench(function foo() {
+ const x: string = "foo";
+});
diff --git a/tests/specs/bench/default_ts/ext.out b/tests/specs/bench/default_ts/ext.out
new file mode 100644
index 000000000..be4e34aac
--- /dev/null
+++ b/tests/specs/bench/default_ts/ext.out
@@ -0,0 +1,5 @@
+Check file:///[WILDCARD]/as_ts.js
+[WILDCARD]
+
+file:///[WILDCARD]/as_ts.js
+[WILDCARD]
diff --git a/tests/specs/bench/default_ts/extensionless b/tests/specs/bench/default_ts/extensionless
new file mode 100644
index 000000000..914439a9f
--- /dev/null
+++ b/tests/specs/bench/default_ts/extensionless
@@ -0,0 +1,3 @@
+Deno.bench(function foo() {
+ const x: string = "foo";
+});
diff --git a/tests/specs/bench/default_ts/extensionless.out b/tests/specs/bench/default_ts/extensionless.out
new file mode 100644
index 000000000..e9442310e
--- /dev/null
+++ b/tests/specs/bench/default_ts/extensionless.out
@@ -0,0 +1,5 @@
+Check file:///[WILDCARD]/extensionless
+[WILDCARD]
+
+file:///[WILDCARD]/extensionless
+[WILDCARD]
diff --git a/tests/specs/fmt/default_ts/__test__.jsonc b/tests/specs/fmt/default_ts/__test__.jsonc
new file mode 100644
index 000000000..24d77a79e
--- /dev/null
+++ b/tests/specs/fmt/default_ts/__test__.jsonc
@@ -0,0 +1,18 @@
+{
+ "tempDir": true,
+ "tests": {
+ "stdin": {
+ "args": "fmt -",
+ "input": "const x: string = \"foo\";",
+ "output": "const x: string = \"foo\";\n"
+ },
+ "ext_flag": {
+ "args": "fmt --ext=ts as_ts.js",
+ "output": "Checked 1 file\n"
+ },
+ "extensionless": {
+ "args": "fmt extensionless",
+ "output": "Checked 1 file\n"
+ }
+ }
+}
diff --git a/tests/specs/fmt/default_ts/as_ts.js b/tests/specs/fmt/default_ts/as_ts.js
new file mode 100644
index 000000000..72a35c2a8
--- /dev/null
+++ b/tests/specs/fmt/default_ts/as_ts.js
@@ -0,0 +1 @@
+const x: string = "foo";
diff --git a/tests/specs/fmt/default_ts/extensionless b/tests/specs/fmt/default_ts/extensionless
new file mode 100644
index 000000000..72a35c2a8
--- /dev/null
+++ b/tests/specs/fmt/default_ts/extensionless
@@ -0,0 +1 @@
+const x: string = "foo";
diff --git a/tests/specs/lint/default_ts/__test__.jsonc b/tests/specs/lint/default_ts/__test__.jsonc
new file mode 100644
index 000000000..ff0f342ab
--- /dev/null
+++ b/tests/specs/lint/default_ts/__test__.jsonc
@@ -0,0 +1,18 @@
+{
+ "tempDir": true,
+ "tests": {
+ "stdin": {
+ "args": "lint -",
+ "input": "const _x: string = \"foo\";",
+ "output": "Checked 1 file\n"
+ },
+ "ext_flag": {
+ "args": "lint --ext=ts as_ts.js",
+ "output": "Checked 1 file\n"
+ },
+ "extensionless": {
+ "args": "lint extensionless",
+ "output": "Checked 1 file\n"
+ }
+ }
+}
diff --git a/tests/specs/lint/default_ts/as_ts.js b/tests/specs/lint/default_ts/as_ts.js
new file mode 100644
index 000000000..3508e99b6
--- /dev/null
+++ b/tests/specs/lint/default_ts/as_ts.js
@@ -0,0 +1 @@
+const _x: string = "foo";
diff --git a/tests/specs/lint/default_ts/extensionless b/tests/specs/lint/default_ts/extensionless
new file mode 100644
index 000000000..3508e99b6
--- /dev/null
+++ b/tests/specs/lint/default_ts/extensionless
@@ -0,0 +1 @@
+const _x: string = "foo";
diff --git a/tests/specs/mod.rs b/tests/specs/mod.rs
index 9565aa71f..34221dd9d 100644
--- a/tests/specs/mod.rs
+++ b/tests/specs/mod.rs
@@ -176,6 +176,7 @@ struct StepMetaData {
pub command_name: Option<String>,
#[serde(default)]
pub envs: HashMap<String, String>,
+ pub input: Option<String>,
pub output: String,
#[serde(default)]
pub exit_code: i32,
@@ -406,6 +407,10 @@ fn run_step(
true => command.show_output(),
false => command,
};
+ let command = match &step.input {
+ Some(input) => command.stdin_text(input),
+ None => command,
+ };
let output = command.run();
if step.output.ends_with(".out") {
let test_output_path = cwd.join(&step.output);
diff --git a/tests/specs/run/default_ts/__test__.jsonc b/tests/specs/run/default_ts/__test__.jsonc
new file mode 100644
index 000000000..07e3d8336
--- /dev/null
+++ b/tests/specs/run/default_ts/__test__.jsonc
@@ -0,0 +1,18 @@
+{
+ "tempDir": true,
+ "tests": {
+ "stdin": {
+ "args": "run -",
+ "input": "const x: string = \"foo\";console.log(x)",
+ "output": "foo\n"
+ },
+ "ext_flag": {
+ "args": "run --ext=ts as_ts.js",
+ "output": "foo\n"
+ },
+ "extensionless": {
+ "args": "run extensionless",
+ "output": "foo\n"
+ }
+ }
+}
diff --git a/tests/specs/run/default_ts/as_ts.js b/tests/specs/run/default_ts/as_ts.js
new file mode 100644
index 000000000..cef8995bc
--- /dev/null
+++ b/tests/specs/run/default_ts/as_ts.js
@@ -0,0 +1,2 @@
+const x: string = "foo";
+console.log(x);
diff --git a/tests/specs/run/default_ts/extensionless b/tests/specs/run/default_ts/extensionless
new file mode 100644
index 000000000..cef8995bc
--- /dev/null
+++ b/tests/specs/run/default_ts/extensionless
@@ -0,0 +1,2 @@
+const x: string = "foo";
+console.log(x);
diff --git a/tests/specs/test/default_ts/__test__.jsonc b/tests/specs/test/default_ts/__test__.jsonc
new file mode 100644
index 000000000..778fca5c5
--- /dev/null
+++ b/tests/specs/test/default_ts/__test__.jsonc
@@ -0,0 +1,13 @@
+{
+ "tempDir": true,
+ "tests": {
+ "ext_flag": {
+ "args": "test --ext=ts as_ts.js",
+ "output": "ext.out"
+ },
+ "extensionless": {
+ "args": "test extensionless",
+ "output": "extensionless.out"
+ }
+ }
+}
diff --git a/tests/specs/test/default_ts/as_ts.js b/tests/specs/test/default_ts/as_ts.js
new file mode 100644
index 000000000..52cb8eacc
--- /dev/null
+++ b/tests/specs/test/default_ts/as_ts.js
@@ -0,0 +1,3 @@
+Deno.test(function foo() {
+ const x: string = "foo";
+});
diff --git a/tests/specs/test/default_ts/ext.out b/tests/specs/test/default_ts/ext.out
new file mode 100644
index 000000000..55f7526a5
--- /dev/null
+++ b/tests/specs/test/default_ts/ext.out
@@ -0,0 +1,4 @@
+Check file:///[WILDCARD]/as_ts.js
+running 1 test from ./as_ts.js
+[WILDCARD]
+
diff --git a/tests/specs/test/default_ts/extensionless b/tests/specs/test/default_ts/extensionless
new file mode 100644
index 000000000..52cb8eacc
--- /dev/null
+++ b/tests/specs/test/default_ts/extensionless
@@ -0,0 +1,3 @@
+Deno.test(function foo() {
+ const x: string = "foo";
+});
diff --git a/tests/specs/test/default_ts/extensionless.out b/tests/specs/test/default_ts/extensionless.out
new file mode 100644
index 000000000..20d4ee2cb
--- /dev/null
+++ b/tests/specs/test/default_ts/extensionless.out
@@ -0,0 +1,4 @@
+Check file:///[WILDCARD]/extensionless
+running 1 test from ./extensionless
+[WILDCARD]
+
diff --git a/tools/lint.js b/tools/lint.js
index a9f940006..de0db015f 100755
--- a/tools/lint.js
+++ b/tools/lint.js
@@ -218,7 +218,7 @@ async function ensureNoNewITests() {
"pm_tests.rs": 0,
"publish_tests.rs": 0,
"repl_tests.rs": 0,
- "run_tests.rs": 333,
+ "run_tests.rs": 331,
"shared_library_tests.rs": 0,
"task_tests.rs": 4,
"test_tests.rs": 0,