-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(plugin-manifest): Allow for all valid WebAppManifest properties #27951
Merged
+276
−38
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bfd1e2d
bring in complete(albeit outdated) WebAppManifest validation frrom pr…
moonmeister 07d0009
Cleanup Gatsby Plugin Options
moonmeister e47ecf9
update validation to match recent spec changes
moonmeister 01fc53c
update compatible gatsby version
moonmeister e75ebec
reomve unused service worker object and fix numberic string
moonmeister 60006ca
lint
moonmeister 0d38cbf
add details from suplementry spec
moonmeister 7f95c9b
final return
moonmeister b3c041d
Prettify
mxstbr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
236 changes: 236 additions & 0 deletions
236
packages/gatsby-plugin-manifest/src/pluginOptionsSchema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
export default function pluginOptionSchema({ Joi }) { | ||
/* Descriptions copied from or based on documentation at https://developer.mozilla.org/en-US/docs/Web/Manifest | ||
* | ||
* Currently based on https://www.w3.org/TR/2020/WD-appmanifest-20201019/ | ||
*/ | ||
|
||
const platform = Joi.string() | ||
.optional() | ||
.empty(``) | ||
.description(`The platform on which the application can be found.`) | ||
|
||
const FingerPrint = Joi.object().keys({ | ||
type: Joi.string() | ||
.required() | ||
.description(`syntax and semantics are platform-defined`), | ||
value: Joi.string() | ||
.required() | ||
.description(`syntax and semantics are platform-defined`), | ||
}) | ||
|
||
const ManifestImageResource = Joi.object().keys({ | ||
sizes: Joi.string() | ||
.optional() | ||
.description(`A string containing space-separated image dimensions`), | ||
src: Joi.string() | ||
.required() | ||
.description( | ||
`The path to the image file. If src is a relative URL, the base URL will be the URL of the manifest.` | ||
), | ||
type: Joi.string().description( | ||
moonmeister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`A hint as to the media type of the image. The purpose of this member is to allow a user agent to quickly ignore images with media types it does not support.` | ||
), | ||
purpose: Joi.string() | ||
.optional() | ||
.description( | ||
`Defines the purpose of the image, for example if the image is intended to serve some special purpose in the context of the host OS.` | ||
), | ||
}) | ||
|
||
const ShortcutItem = Joi.object().keys({ | ||
name: Joi.string() | ||
.required() | ||
.description( | ||
`The name member of a ShortcutItem is a string that represents the name of the shortcut as it is usually displayed to the user in a context menu. ` | ||
), | ||
short_name: Joi.string() | ||
.optional() | ||
.description( | ||
`The short_name member of a ShortcutItem is a string that represents a short version of the name of the shortcut. ` | ||
), | ||
description: Joi.string() | ||
.optional() | ||
.description( | ||
`The description member of a ShortcutItem is a string that allows the developer to describe the purpose of the shortcut. ` | ||
), | ||
url: Joi.string() | ||
.required() | ||
.description( | ||
`The url member of a ShortcutItem is a URL within scope of a processed manifest that opens when the associated shortcut is activated. ` | ||
), | ||
icons: Joi.array() | ||
.optional() | ||
.items(ManifestImageResource) | ||
.description( | ||
`The icons member of an ShortcutItem member serve as iconic representations of the shortcut in various contexts. ` | ||
), | ||
}) | ||
|
||
const ExternalApplicationResource = Joi.object() | ||
.keys({ | ||
platform: platform.required(), | ||
url: Joi.string() | ||
.uri() | ||
.required() | ||
.description(`The URL at which the application can be found.`), | ||
id: Joi.string() | ||
.required() | ||
.description( | ||
`The ID used to represent the application on the specified platform.` | ||
), | ||
min_version: Joi.string() | ||
.optional() | ||
.description( | ||
`The minimum version of the application that is considered related to this web app.` | ||
), | ||
fingerprints: Joi.array() | ||
.optional() | ||
.items(FingerPrint) | ||
.description( | ||
`Each Fingerprints represents a set of cryptographic fingerprints used for verifying the application.` | ||
), | ||
}) | ||
.or("url", "id") | ||
|
||
const WebAppManifest = Joi.object().keys({ | ||
background_color: Joi.string() | ||
.optional() | ||
.description( | ||
`The background_color member defines a placeholder background color for the application page to display before its stylesheet is loaded.` | ||
), | ||
categories: Joi.array() | ||
moonmeister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.items(Joi.string().empty(``)) | ||
.optional() | ||
.description( | ||
`The categories member is an array of strings defining the names of categories that the application supposedly belongs to.` | ||
), | ||
description: Joi.string() | ||
.optional() | ||
.description( | ||
`The description member is a string in which developers can explain what the application does. ` | ||
), | ||
dir: Joi.string() | ||
.optional() | ||
.valid(`auto`, `ltr`, `rtl`) | ||
.description( | ||
`The base direction in which to display direction-capable members of the manifest.` | ||
), | ||
display: Joi.string() | ||
.optional() | ||
.valid(`fullscreen`, `standalone`, `minimal-ui`, `browser`) | ||
.description( | ||
`The display member is a string that determines the developers’ preferred display mode for the website` | ||
), | ||
iarc_rating_id: Joi.string() | ||
.guid() | ||
.optional() | ||
.description( | ||
`The iarc_rating_id member is a string that represents the International Age Rating Coalition (IARC) certification code of the web application.` | ||
), | ||
icons: Joi.array() | ||
.optional() | ||
.items(ManifestImageResource) | ||
.description( | ||
`The icons member specifies an array of objects representing image files that can serve as application icons for different contexts.` | ||
), | ||
lang: Joi.string() | ||
.optional() | ||
.description( | ||
`The lang member is a string containing a single language tag.` | ||
), | ||
name: Joi.string() | ||
.optional() | ||
.description( | ||
`The name member is a string that represents the name of the web application as it is usually displayed to the user.` | ||
), | ||
orientation: Joi.string() | ||
.optional() | ||
.valid( | ||
`any`, | ||
`natural`, | ||
`landscape`, | ||
`landscape-primary`, | ||
`landscape-secondary`, | ||
`portrait`, | ||
`portrait-primary`, | ||
`portrait-secondary` | ||
) // From: https://www.w3.org/TR/screen-orientation/#screenorientation-interface | ||
.description( | ||
`The orientation member defines the default orientation for all the website's top-level browsing contexts` | ||
), | ||
prefer_related_applications: Joi.boolean() | ||
.optional() | ||
.description( | ||
`The prefer_related_applications member is a boolean value that specifies that applications listed in related_applications should be preferred over the web application.` | ||
), | ||
related_applications: Joi.array() | ||
.optional() | ||
.items(ExternalApplicationResource) | ||
.description( | ||
`The related_applications field is an array of objects specifying native applications that are installable by, or accessible to, the underlying platform.` | ||
), | ||
scope: Joi.string() | ||
.optional() | ||
.description( | ||
`The scope member is a string that defines the navigation scope of this web application's application context.` | ||
), | ||
screenshots: Joi.array() | ||
.optional() | ||
.items(ManifestImageResource) | ||
moonmeister marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.description( | ||
`The screenshots member defines an array of screenshots intended to showcase the application.` | ||
), | ||
short_name: Joi.string() | ||
.optional() | ||
.description( | ||
`The short_name member is a string that represents the name of the web application displayed to the user if there is not enough space to display name.` | ||
), | ||
shortcuts: Joi.array() | ||
.optional() | ||
.items(ShortcutItem) | ||
.description( | ||
`Each ShortcutItem represents a link to a key task or page within a web app. ` | ||
), | ||
start_url: Joi.string() | ||
.optional() | ||
.description( | ||
`The start_url member is a string that represents the start URL of the web application.` | ||
), | ||
theme_color: Joi.string() | ||
.optional() | ||
.description( | ||
`The theme_color member is a string that defines the default theme color for the application.` | ||
), | ||
}) | ||
|
||
const GatsbyPluginOptions = Joi.object() | ||
.keys({ | ||
icon: Joi.string(), | ||
legacy: Joi.boolean().default(true), | ||
theme_color_in_head: Joi.boolean().default(true), | ||
cache_busting_mode: Joi.string() | ||
.valid(`none`, `query`, `name`) | ||
.default("query"), | ||
crossOrigin: Joi.string() | ||
.valid(`anonymous`, `use-credentials`) | ||
.default("anonymous"), | ||
include_favicon: Joi.boolean().default(true), | ||
icon_options: ManifestImageResource.keys({ | ||
src: Joi.string().forbidden(), | ||
sizes: Joi.string().forbidden(), | ||
}), | ||
|
||
localize: Joi.array() | ||
.items( | ||
WebAppManifest.keys({ | ||
lang: Joi.required(), | ||
start_url: Joi.required(), | ||
}) | ||
) | ||
.description(`Used for localizing your WebAppManifest`), | ||
}) | ||
.or(`icon`, `icons`) | ||
.with(`localize`, `lang`) | ||
|
||
return WebAppManifest.concat(GatsbyPluginOptions) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prettier should fix this (you could tune your editor ;) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(won't show up in discussions but the line ending is missing here)