Skip to content

Commit

Permalink
feat: update handling of ambiguous properties
Browse files Browse the repository at this point in the history
  • Loading branch information
velut committed Apr 23, 2024
1 parent 63bcefb commit 208a6bc
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/get-package-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,36 @@ export const PackageManifest = PackageJson.extend({
@remarks
In some old packages (like `[email protected]`) the `engines` property is an array of strings
instead of an object and with catch it becomes an empty object.
instead of an object and with catch it becomes `undefined`.
*/
engines: z.record(z.string()).catch({}).optional(),
engines: z.record(z.string()).optional().catch(undefined),

/**
SPDX license expression or a custom license.
@remarks
In some old packages (like `[email protected]`) the `license` property is an object
and with catch `license` becomes an empty string.
and with catch `license` becomes `undefined`.
*/
license: z.string().catch("").optional(),
license: z.string().optional().catch(undefined),

/**
URL of the package's homepage.
@remarks
In some old packages (like `[email protected]`) the `homepage` property is an array
of strings and with coercion it correctly becomes a string.
of strings and with catch it becomes `undefined`.
*/
homepage: z.coerce.string().optional(),
homepage: z.string().optional().catch(undefined),

/**
Deprecation message.
Deprecation status/message.
@remarks
In some old packages (like `[email protected]`) the `deprecated` property is a boolean
and with coercion it becomes either `"true"` or `"false"`.
In some packages (like `[email protected]`) the `deprecated` property is a boolean
instead of a deprecation message.
*/
deprecated: z.coerce.string().optional(),
deprecated: z.union([z.string(), z.boolean()]).optional(),
});

/**
Expand Down

0 comments on commit 208a6bc

Please sign in to comment.