summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-03-27 14:14:27 -0700
committerGitHub <noreply@github.com>2024-03-27 14:14:27 -0700
commit2dc37f411e8947d3c20cd93d1fa1937edc239499 (patch)
tree0ecb10fb3cc0e9085130c3683155529c5de74e84 /cli
parent68fecc6de4b2e6556adeb2730798bf42017c4be6 (diff)
feat(task): Task description in the form of comments (#23101)
Closes #22786. TLDR; ```jsonc { "tasks": { // Some comment // // describing what the task does "dev": "deno run -A --watch main.ts" } } ``` ```bash deno task ``` ![Screenshot 2024-03-27 at 1 43 49 PM](https://github.com/denoland/deno/assets/17734409/7a14da8c-8e63-45ba-9bfb-590d250b56a9)
Diffstat (limited to 'cli')
-rw-r--r--cli/Cargo.toml2
-rw-r--r--cli/args/mod.rs23
-rw-r--r--cli/lsp/config.rs16
-rw-r--r--cli/lsp/diagnostics.rs7
-rw-r--r--cli/lsp/documents.rs2
-rw-r--r--cli/lsp/tsc.rs1
-rw-r--r--cli/tools/task.rs38
7 files changed, 73 insertions, 16 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 12a45aa43..5345f45cf 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -64,7 +64,7 @@ winres.workspace = true
[dependencies]
deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] }
deno_cache_dir = { workspace = true }
-deno_config = "=0.14.1"
+deno_config = "=0.15.0"
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_doc = { version = "=0.113.1", features = ["html"] }
deno_emit = "=0.38.2"
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index 330b10d0f..76de434fd 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -796,11 +796,18 @@ impl CliOptions {
} else {
None
};
+ let parse_options = deno_config::ParseOptions {
+ include_task_comments: matches!(
+ flags.subcommand,
+ DenoSubcommand::Task(..)
+ ),
+ };
let maybe_config_file = ConfigFile::discover(
&flags.config_flag,
flags.config_path_args(&initial_cwd),
&initial_cwd,
additional_config_file_names,
+ &parse_options,
)?;
let mut maybe_package_json = None;
@@ -1183,7 +1190,7 @@ impl CliOptions {
pub fn resolve_tasks_config(
&self,
- ) -> Result<IndexMap<String, String>, AnyError> {
+ ) -> Result<IndexMap<String, deno_config::Task>, AnyError> {
if let Some(config_file) = &self.maybe_config_file {
config_file.resolve_tasks_config()
} else if self.maybe_package_json.is_some() {
@@ -1850,7 +1857,12 @@ mod test {
let cwd = &std::env::current_dir().unwrap();
let config_specifier =
ModuleSpecifier::parse("file:///deno/deno.jsonc").unwrap();
- let config_file = ConfigFile::new(config_text, config_specifier).unwrap();
+ let config_file = ConfigFile::new(
+ config_text,
+ config_specifier,
+ &deno_config::ParseOptions::default(),
+ )
+ .unwrap();
let actual = resolve_import_map_specifier(
Some("import-map.json"),
Some(&config_file),
@@ -1869,7 +1881,12 @@ mod test {
let config_text = r#"{}"#;
let config_specifier =
ModuleSpecifier::parse("file:///deno/deno.jsonc").unwrap();
- let config_file = ConfigFile::new(config_text, config_specifier).unwrap();
+ let config_file = ConfigFile::new(
+ config_text,
+ config_specifier,
+ &deno_config::ParseOptions::default(),
+ )
+ .unwrap();
let actual = resolve_import_map_specifier(
None,
Some(&config_file),
diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs
index 5fa2a00a6..304a53b8b 100644
--- a/cli/lsp/config.rs
+++ b/cli/lsp/config.rs
@@ -1136,7 +1136,10 @@ impl ConfigData {
file_fetcher: Option<&FileFetcher>,
) -> Self {
if let Some(specifier) = config_file_specifier {
- match ConfigFile::from_specifier(specifier.clone()) {
+ match ConfigFile::from_specifier(
+ specifier.clone(),
+ &deno_config::ParseOptions::default(),
+ ) {
Ok(config_file) => {
lsp_log!(
" Resolved Deno configuration file: \"{}\"",
@@ -1949,7 +1952,12 @@ mod tests {
config
.tree
.inject_config_file(
- ConfigFile::new("{}", root_uri.join("deno.json").unwrap()).unwrap(),
+ ConfigFile::new(
+ "{}",
+ root_uri.join("deno.json").unwrap(),
+ &deno_config::ParseOptions::default(),
+ )
+ .unwrap(),
)
.await;
assert!(config.specifier_enabled(&root_uri));
@@ -1996,6 +2004,7 @@ mod tests {
})
.to_string(),
root_uri.join("deno.json").unwrap(),
+ &deno_config::ParseOptions::default(),
)
.unwrap(),
)
@@ -2021,6 +2030,7 @@ mod tests {
})
.to_string(),
root_uri.join("deno.json").unwrap(),
+ &deno_config::ParseOptions::default(),
)
.unwrap(),
)
@@ -2038,6 +2048,7 @@ mod tests {
})
.to_string(),
root_uri.join("deno.json").unwrap(),
+ &deno_config::ParseOptions::default(),
)
.unwrap(),
)
@@ -2067,6 +2078,7 @@ mod tests {
})
.to_string(),
root_uri.join("deno.json").unwrap(),
+ &deno_config::ParseOptions::default(),
)
.unwrap(),
)
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index 03d962741..e518f4c6e 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -1617,7 +1617,12 @@ mod tests {
let config = Config::new_with_roots([resolve_url("file:///").unwrap()]);
if let Some((base_url, json_string)) = maybe_import_map {
let base_url = resolve_url(base_url).unwrap();
- let config_file = ConfigFile::new(json_string, base_url).unwrap();
+ let config_file = ConfigFile::new(
+ json_string,
+ base_url,
+ &deno_config::ParseOptions::default(),
+ )
+ .unwrap();
config.tree.inject_config_file(config_file).await;
}
StateSnapshot {
diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs
index 7d1d89b8d..8feeab8de 100644
--- a/cli/lsp/documents.rs
+++ b/cli/lsp/documents.rs
@@ -1886,6 +1886,7 @@ console.log(b, "hello deno");
})
.to_string(),
config.root_uri().unwrap().join("deno.json").unwrap(),
+ &deno_config::ParseOptions::default(),
)
.unwrap(),
)
@@ -1926,6 +1927,7 @@ console.log(b, "hello deno");
})
.to_string(),
config.root_uri().unwrap().join("deno.json").unwrap(),
+ &deno_config::ParseOptions::default(),
)
.unwrap(),
)
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 691f7c91d..63c08331d 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -4711,6 +4711,7 @@ mod tests {
})
.to_string(),
resolve_url("file:///deno.json").unwrap(),
+ &deno_config::ParseOptions::default(),
)
.unwrap(),
)
diff --git a/cli/tools/task.rs b/cli/tools/task.rs
index 8f500df34..5eefda73f 100644
--- a/cli/tools/task.rs
+++ b/cli/tools/task.rs
@@ -49,7 +49,13 @@ pub async fn execute_script(
}
};
- if let Some(script) = tasks_config.get(task_name) {
+ if let Some(
+ deno_config::Task::Definition(script)
+ | deno_config::Task::Commented {
+ definition: script, ..
+ },
+ ) = tasks_config.get(task_name)
+ {
let config_file_url = cli_options.maybe_config_file_specifier().unwrap();
let config_file_path = if config_file_url.scheme() == "file" {
config_file_url.to_file_path().unwrap()
@@ -222,18 +228,22 @@ fn collect_env_vars() -> HashMap<String, String> {
fn print_available_tasks(
// order can be important, so these use an index map
- tasks_config: &IndexMap<String, String>,
+ tasks_config: &IndexMap<String, deno_config::Task>,
package_json_scripts: &IndexMap<String, String>,
) {
eprintln!("{}", colors::green("Available tasks:"));
let mut had_task = false;
- for (is_deno, (key, value)) in tasks_config.iter().map(|e| (true, e)).chain(
- package_json_scripts
- .iter()
- .filter(|(key, _)| !tasks_config.contains_key(*key))
- .map(|e| (false, e)),
- ) {
+ for (is_deno, (key, task)) in tasks_config
+ .iter()
+ .map(|(k, t)| (true, (k, t.clone())))
+ .chain(
+ package_json_scripts
+ .iter()
+ .filter(|(key, _)| !tasks_config.contains_key(*key))
+ .map(|(k, v)| (false, (k, deno_config::Task::Definition(v.clone())))),
+ )
+ {
eprintln!(
"- {}{}",
colors::cyan(key),
@@ -243,7 +253,17 @@ fn print_available_tasks(
format!(" {}", colors::italic_gray("(package.json)"))
}
);
- eprintln!(" {value}");
+ let definition = match &task {
+ deno_config::Task::Definition(definition) => definition,
+ deno_config::Task::Commented { definition, .. } => definition,
+ };
+ if let deno_config::Task::Commented { comments, .. } = &task {
+ let slash_slash = colors::italic_gray("//");
+ for comment in comments {
+ eprintln!(" {slash_slash} {}", colors::italic_gray(comment));
+ }
+ }
+ eprintln!(" {definition}");
had_task = true;
}
if !had_task {