diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 8a0a53c9af..a69a474e7f 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -268,7 +268,15 @@ fn update_config_file_content( let insert_position = obj.range.end - 1; text_changes.push(TextChange { 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": { + // "": ":@" + // } + // } + new_text: format!("\"imports\": {{\n {} }}", generated_imports), }) } // we verified the shape of `imports` above diff --git a/tests/integration/pm_tests.rs b/tests/integration/pm_tests.rs index 668519bdc3..a8af67e5b7 100644 --- a/tests/integration/pm_tests.rs +++ b/tests/integration/pm_tests.rs @@ -39,11 +39,14 @@ fn add_basic_no_deno_json() { output.assert_exit_code(0); let output = output.combined_output(); assert_contains!(output, "Add @denotest/add"); - temp_dir.join("deno.json").assert_matches_json(json!({ - "imports": { - "@denotest/add": "jsr:@denotest/add@^1.0.0" - } - })); + // Don't use `assert_matches_json` to ensure the file is properly formatted. + let expected = r#"{ + "imports": { + "@denotest/add": "jsr:@denotest/add@^1.0.0" + } +} +"#; + temp_dir.join("deno.json").assert_matches_text(expected); } #[test]