Skip to content

Commit

Permalink
fix(publish): error on missing name field (#27131)
Browse files Browse the repository at this point in the history
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": "<path_to_entrypoint>"
}
```

After:

```sh
deno publish --dry-run
error: Missing 'name' field in 'file:///Users/marvinh/dev/test/deno-pkg-timers/deno.json'.
```

Fixes #27116
  • Loading branch information
marvinhagemeister authored Nov 28, 2024
1 parent 12aea20 commit 3553aa9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cli/tools/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/publish/missing_name/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "publish --token 'sadfasdf'",
"output": "publish.out",
"exitCode": 1
}
4 changes: 4 additions & 0 deletions tests/specs/publish/missing_name/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "1.0.0",
"exports": "./mod.ts"
}
3 changes: 3 additions & 0 deletions tests/specs/publish/missing_name/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function add(a: number, b: number): number {
return a + b;
}
1 change: 1 addition & 0 deletions tests/specs/publish/missing_name/publish.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error: Missing 'name' field in 'file:///[WILDCARD]deno.json'.

0 comments on commit 3553aa9

Please sign in to comment.