From 37279e0b0a4300318da472bf0a8bdb894746537f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 20 Aug 2024 16:32:01 -0400 Subject: [PATCH] fix(add): error when config file contains importMap field (#25115) The "imports" field has higher precedence than "importMap", so we should error when `deno add` goes to add an `"imports"` field. Closes https://github.com/denoland/deno/issues/24264 Closes https://github.com/denoland/deno/pull/24478 --- cli/tools/registry/pm.rs | 11 +++++++++++ tests/specs/add/error_import_map_field/__test__.jsonc | 5 +++++ tests/specs/add/error_import_map_field/add.out | 2 ++ tests/specs/add/error_import_map_field/deno.json | 3 +++ .../specs/add/error_import_map_field/import_map.json | 1 + 5 files changed, 22 insertions(+) create mode 100644 tests/specs/add/error_import_map_field/__test__.jsonc create mode 100644 tests/specs/add/error_import_map_field/add.out create mode 100644 tests/specs/add/error_import_map_field/deno.json create mode 100644 tests/specs/add/error_import_map_field/import_map.json diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 52f3310ba4..3cdef071f9 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -289,6 +289,17 @@ pub async fn add( _ => bail!("Failed updating config file due to no object."), }; + if obj.get_string("importMap").is_some() { + bail!( + concat!( + "`deno add` is not supported when configuration file contains an \"importMap\" field. ", + "Inline the import map into the Deno configuration file.\n", + " at {}", + ), + config_specifier + ); + } + let mut existing_imports = config_file.existing_imports()?; let is_npm = config_file.is_npm(); diff --git a/tests/specs/add/error_import_map_field/__test__.jsonc b/tests/specs/add/error_import_map_field/__test__.jsonc new file mode 100644 index 0000000000..bf26b74e43 --- /dev/null +++ b/tests/specs/add/error_import_map_field/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "add jsr:@denotest/add", + "output": "add.out", + "exitCode": 1 +} diff --git a/tests/specs/add/error_import_map_field/add.out b/tests/specs/add/error_import_map_field/add.out new file mode 100644 index 0000000000..ab787ea78e --- /dev/null +++ b/tests/specs/add/error_import_map_field/add.out @@ -0,0 +1,2 @@ +error: `deno add` is not supported when configuration file contains an "importMap" field. Inline the import map into the Deno configuration file. + at file:///[WILDLINE]/deno.json diff --git a/tests/specs/add/error_import_map_field/deno.json b/tests/specs/add/error_import_map_field/deno.json new file mode 100644 index 0000000000..12a79304f3 --- /dev/null +++ b/tests/specs/add/error_import_map_field/deno.json @@ -0,0 +1,3 @@ +{ + "importMap": "./import_map.json" +} diff --git a/tests/specs/add/error_import_map_field/import_map.json b/tests/specs/add/error_import_map_field/import_map.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/tests/specs/add/error_import_map_field/import_map.json @@ -0,0 +1 @@ +{}