Skip to content

fix: handle object format for author field in package.json#1344

Open
kaigritun wants to merge 1 commit into
PlasmoHQ:mainfrom
kaigritun:fix/author-object-format
Open

fix: handle object format for author field in package.json#1344
kaigritun wants to merge 1 commit into
PlasmoHQ:mainfrom
kaigritun:fix/author-object-format

Conversation

@kaigritun

Copy link
Copy Markdown

Summary

Fixes #1334

Chrome extension manifest requires the author field to be a string, but npm's package.json allows author to be either:

  • A string: "John Doe"
  • An object: { "name": "John Doe", "email": "john@example.com", "url": "https://example.com" }

When the author field is an object, Plasmo was passing it directly to the manifest, causing the validation error:

Invalid Web Extension manifest
Expected type string

Changes

  1. Added normalizeAuthor helper function in base.ts:

    • Returns undefined if no author is provided
    • Returns the string as-is if author is already a string
    • Converts object format to the standard npm string format: "Name <email> (url)"
  2. Updated PackageJSON type in package-file.ts:

    • Added PackageAuthor type that accepts both string and object formats
    • Updated PackageJSON to use the new type for the author field

Example

package.json with object author:

{
  "author": {
    "name": "Gil B. Chan",
    "email": "bnbcmindnpass@gmail.com",
    "url": "https://github.com/jjangga0214"
  }
}

Generated manifest author:

{
  "author": "Gil B. Chan <bnbcmindnpass@gmail.com> (https://github.com/jjangga0214)"
}

References

Chrome extension manifest requires author to be a string, but npm allows
author to be either a string or an object with name/email/url fields.

This commit adds a normalizeAuthor function that converts the object format
to the standard npm string format: "Name <email> (url)"

Fixes PlasmoHQ#1334
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Invalid Web Extension manifest when author field is json

1 participant