summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-08-20 16:32:01 -0400
committerGitHub <noreply@github.com>2024-08-20 16:32:01 -0400
commit37279e0b0a4300318da472bf0a8bdb894746537f (patch)
treefffc0425e931f70e8297456ddbf7b106fb72e9e9
parenta7c002ae634b20a2f84c90417327a88c9ac2df99 (diff)
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
-rw-r--r--cli/tools/registry/pm.rs11
-rw-r--r--tests/specs/add/error_import_map_field/__test__.jsonc5
-rw-r--r--tests/specs/add/error_import_map_field/add.out2
-rw-r--r--tests/specs/add/error_import_map_field/deno.json3
-rw-r--r--tests/specs/add/error_import_map_field/import_map.json1
5 files changed, 22 insertions, 0 deletions
diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs
index 52f3310ba..3cdef071f 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 000000000..bf26b74e4
--- /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 000000000..ab787ea78
--- /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 000000000..12a79304f
--- /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 000000000..0967ef424
--- /dev/null
+++ b/tests/specs/add/error_import_map_field/import_map.json
@@ -0,0 +1 @@
+{}