diff options
author | nokazn <41154684+nokazn@users.noreply.github.com> | 2024-04-19 04:48:15 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-18 15:48:15 -0400 |
commit | 3d841acf4861220553614473538de935d24bcb21 (patch) | |
tree | d6e8a22bea4172d84730b7470ac83a2a9fce7a81 /cli/tools/registry/pm.rs | |
parent | c6d44dbda6cb833bff9f88de6c66ecb95ff62523 (diff) |
fix(cli): avoid `deno add` and `deno vendor` errors when deno.json is empty (#23439)
Diffstat (limited to 'cli/tools/registry/pm.rs')
-rw-r--r-- | cli/tools/registry/pm.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index a69a474e7..699b476cb 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -109,8 +109,14 @@ pub async fn add(flags: Flags, add_flags: AddFlags) -> Result<(), AnyError> { } } - let config_file_contents = - tokio::fs::read_to_string(&config_file_path).await.unwrap(); + let config_file_contents = { + let contents = tokio::fs::read_to_string(&config_file_path).await.unwrap(); + if contents.trim().is_empty() { + "{}\n".into() + } else { + contents + } + }; let ast = jsonc_parser::parse_to_ast( &config_file_contents, &Default::default(), |