mirror of
https://github.com/denoland/deno
synced 2024-10-05 23:59:24 +00:00
feat(add): always produce multiline config file (#23077)
This commit changes `deno add` to always produce a multiline config file. In v1.41.3: ``` $ mkdir foo $ cd foo $ deno add @std/assert Created deno.json configuration file. Add @std/assert - jsr:@std/assert@^0.220.0 $ cat deno.json { "imports": { "@std/assert": "jsr:@std/assert@^0.220.0" } } ``` Now: ``` $ mkdir foo $ cd foo $ deno add @std/assert Created deno.json configuration file. Add @std/assert - jsr:@std/assert@^0.220.0 $ cat deno.json { "imports": { "@std/assert": "jsr:@std/assert@^0.220.0" } } ```
This commit is contained in:
parent
9841d3fdf1
commit
6b95c53e48
|
@ -268,7 +268,15 @@ fn update_config_file_content(
|
||||||
let insert_position = obj.range.end - 1;
|
let insert_position = obj.range.end - 1;
|
||||||
text_changes.push(TextChange {
|
text_changes.push(TextChange {
|
||||||
range: insert_position..insert_position,
|
range: insert_position..insert_position,
|
||||||
new_text: format!("\"imports\": {{ {} }}", generated_imports),
|
// NOTE(bartlomieju): adding `\n` here to force the formatter to always
|
||||||
|
// produce a config file that is multline, like so:
|
||||||
|
// ```
|
||||||
|
// {
|
||||||
|
// "imports": {
|
||||||
|
// "<package_name>": "<registry>:<package_name>@<semver>"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
new_text: format!("\"imports\": {{\n {} }}", generated_imports),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// we verified the shape of `imports` above
|
// we verified the shape of `imports` above
|
||||||
|
|
|
@ -39,11 +39,14 @@ fn add_basic_no_deno_json() {
|
||||||
output.assert_exit_code(0);
|
output.assert_exit_code(0);
|
||||||
let output = output.combined_output();
|
let output = output.combined_output();
|
||||||
assert_contains!(output, "Add @denotest/add");
|
assert_contains!(output, "Add @denotest/add");
|
||||||
temp_dir.join("deno.json").assert_matches_json(json!({
|
// Don't use `assert_matches_json` to ensure the file is properly formatted.
|
||||||
|
let expected = r#"{
|
||||||
"imports": {
|
"imports": {
|
||||||
"@denotest/add": "jsr:@denotest/add@^1.0.0"
|
"@denotest/add": "jsr:@denotest/add@^1.0.0"
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
|
"#;
|
||||||
|
temp_dir.join("deno.json").assert_matches_text(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue