Skip to content

Commit

Permalink
feat(deno): detect deno.json and deno.jsonc (#3220)
Browse files Browse the repository at this point in the history
* feat(deno): detect `deno.json` and `deno.jsonc`

* update docs

* update tests

* cargo fmt

* revert lockfile changes

* revert doc updates to non-english files

* Restore README.md

* fmt
  • Loading branch information
maximousblk committed Dec 30, 2021
1 parent 67cddb6 commit f48c7a2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
22 changes: 11 additions & 11 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -747,20 +747,20 @@ format = "via [馃敯 $version](bold red) "

The `deno` module shows you your currently installed version of [Deno](https://deno.land/).
By default the module will be shown if any of the following conditions are met:
- The current directory contains a `mod.ts`, `mod.js`, `deps.ts` or `deps.js` file
- The current directory contains a `deno.json`, `deno.jsonc`, `mod.ts`, `mod.js`, `deps.ts` or `deps.js` file

### Options

| Option | Default | Description |
| ------------------- | ------------------------------------------------- | ------------------------------------------------------------------------- |
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
| `version_format` | `"v${raw}"` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
| `symbol` | `"馃 "` | A format string representing the symbol of Deno |
| `detect_extensions` | `[]` | Which extensions should trigger this module. |
| `detect_files` | `["mod.ts", "mod.js", "deps.ts", "deps.js"]` | Which filenames should trigger this module. |
| `detect_folders` | `[]` | Which folders should trigger this module. |
| `style` | `"green bold"` | The style for the module. |
| `disabled` | `false` | Disables the `deno` module. |
| Option | Default | Description |
| ------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
| `version_format` | `"v${raw}"` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
| `symbol` | `"馃 "` | A format string representing the symbol of Deno |
| `detect_extensions` | `[]` | Which extensions should trigger this module. |
| `detect_files` | `["deno.json", "deno.jsonc", "mod.ts", "mod.js", "deps.ts", "deps.js"]` | Which filenames should trigger this module. |
| `detect_folders` | `[]` | Which folders should trigger this module. |
| `style` | `"green bold"` | The style for the module. |
| `disabled` | `false` | Disables the `deno` module. |

### Variables

Expand Down
9 changes: 8 additions & 1 deletion src/configs/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ impl<'a> Default for DenoConfig<'a> {
style: "green bold",
disabled: false,
detect_extensions: vec![],
detect_files: vec!["mod.ts", "deps.ts", "mod.js", "deps.js"],
detect_files: vec![
"deno.json",
"deno.jsonc",
"mod.ts",
"deps.ts",
"mod.js",
"deps.js",
],
detect_folders: vec![],
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/modules/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ mod tests {
dir.close()
}

#[test]
fn folder_with_deno_json() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("deno.json"))?.sync_all()?;
let actual = ModuleRenderer::new("deno").path(dir.path()).collect();
let expected = Some(format!("via {}", Color::Green.bold().paint("馃 v1.8.3 ")));
assert_eq!(expected, actual);
dir.close()
}

#[test]
fn folder_with_deno_jsonc() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("deno.jsonc"))?.sync_all()?;
let actual = ModuleRenderer::new("deno").path(dir.path()).collect();
let expected = Some(format!("via {}", Color::Green.bold().paint("馃 v1.8.3 ")));
assert_eq!(expected, actual);
dir.close()
}

#[test]
fn folder_with_mod_ts() -> io::Result<()> {
let dir = tempfile::tempdir()?;
Expand Down

0 comments on commit f48c7a2

Please sign in to comment.