From 3553aa913249a5940cd2a0828119ae3c89ad2f3d Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 28 Nov 2024 18:11:36 +0100 Subject: [PATCH] fix(publish): error on missing name field (#27131) This PR improves the error output on publish when the `name` filed is missing: ```json { "exports": "./mod.ts", "version": "0.0.1" } ``` Before: ```sh deno publish --dry-run error: You did not specify an entrypoint in file:///Users/marvinh/dev/test/deno-pkg-timers/deno.json. Add `exports` mapping in the configuration file, eg: { "name": "@scope/name", "version": "0.0.0", "exports": "" } ``` After: ```sh deno publish --dry-run error: Missing 'name' field in 'file:///Users/marvinh/dev/test/deno-pkg-timers/deno.json'. ``` Fixes https://github.com/denoland/deno/issues/27116 --- cli/tools/registry/mod.rs | 7 +++---- tests/specs/publish/missing_name/__test__.jsonc | 5 +++++ tests/specs/publish/missing_name/deno.json | 4 ++++ tests/specs/publish/missing_name/mod.ts | 3 +++ tests/specs/publish/missing_name/publish.out | 1 + 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 tests/specs/publish/missing_name/__test__.jsonc create mode 100644 tests/specs/publish/missing_name/deno.json create mode 100644 tests/specs/publish/missing_name/mod.ts create mode 100644 tests/specs/publish/missing_name/publish.out diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index ba61d352d3..a866660f36 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -97,11 +97,10 @@ pub async fn publish( match cli_options.start_dir.maybe_deno_json() { Some(deno_json) => { debug_assert!(!deno_json.is_package()); + if deno_json.json.name.is_none() { + bail!("Missing 'name' field in '{}'.", deno_json.specifier); + } error_missing_exports_field(deno_json)?; - bail!( - "Missing 'name' or 'exports' field in '{}'.", - deno_json.specifier - ); } None => { bail!( diff --git a/tests/specs/publish/missing_name/__test__.jsonc b/tests/specs/publish/missing_name/__test__.jsonc new file mode 100644 index 0000000000..241bb87e04 --- /dev/null +++ b/tests/specs/publish/missing_name/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "publish --token 'sadfasdf'", + "output": "publish.out", + "exitCode": 1 +} diff --git a/tests/specs/publish/missing_name/deno.json b/tests/specs/publish/missing_name/deno.json new file mode 100644 index 0000000000..4b0018cf62 --- /dev/null +++ b/tests/specs/publish/missing_name/deno.json @@ -0,0 +1,4 @@ +{ + "version": "1.0.0", + "exports": "./mod.ts" +} diff --git a/tests/specs/publish/missing_name/mod.ts b/tests/specs/publish/missing_name/mod.ts new file mode 100644 index 0000000000..8d9b8a22a1 --- /dev/null +++ b/tests/specs/publish/missing_name/mod.ts @@ -0,0 +1,3 @@ +export function add(a: number, b: number): number { + return a + b; +} diff --git a/tests/specs/publish/missing_name/publish.out b/tests/specs/publish/missing_name/publish.out new file mode 100644 index 0000000000..10e0688ef2 --- /dev/null +++ b/tests/specs/publish/missing_name/publish.out @@ -0,0 +1 @@ +error: Missing 'name' field in 'file:///[WILDCARD]deno.json'.