From 46687399da4ef65ab6d574e05a5125e6238a9cac Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 28 Nov 2024 14:23:26 +0100 Subject: [PATCH] fix(publish): error on missing name field --- 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 ba61d352d30712..a866660f366670 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 00000000000000..241bb87e044023 --- /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 00000000000000..4b0018cf627cca --- /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 00000000000000..8d9b8a22a101a9 --- /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 00000000000000..10e0688ef2f415 --- /dev/null +++ b/tests/specs/publish/missing_name/publish.out @@ -0,0 +1 @@ +error: Missing 'name' field in 'file:///[WILDCARD]deno.json'.