fix(plugins): option checks read quartz.optionSchema as well as configSchema

This commit is contained in:
saberzero1 committed 2026-11-09 21:42:50 +01:00
1 parent 33ff9eaccf
commit e41ebf644a
4 files changed
+26 -4

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Plugin option checks use the plugin's schema when it is declared as `quartz.optionSchema`, the name first-party plugins and Quartz Syncer use, as well as `quartz.configSchema`. Before, only `configSchema` was read, so the checks for misspelled options or wrong values never used the schemas of first-party plugins.
+5 -3
View File
@@ -139,12 +139,12 @@ export function findConfigEntries(plugins, query, { extractName, formatSource })
/**
* Validate a plugin's options against its manifest (`defaultOptions` and, when
* present, `configSchema`). Unknown keys are only flagged as warnings when they
* present, `configSchema`, or its alias `optionSchema`). Unknown keys are only flagged as warnings when they
* look like a typo of a known key (or the schema forbids extra keys), because
* many plugins accept options that have no default.
*
* @param {unknown} options
* @param {{ defaultOptions?: Record<string, unknown>, configSchema?: any } | null | undefined} manifest
* @param {{ defaultOptions?: Record<string, unknown>, configSchema?: any, optionSchema?: any } | null | undefined} manifest
* @param {string} [prefix]
* @returns {Array<{ severity: "warning" | "info", path: string, message: string, suggestion?: string }>}
*/
@@ -153,7 +153,9 @@ export function validatePluginOptions(options, manifest, prefix = "") {
if (!isPlainObject(options) || !manifest) return issues
const defaults = isPlainObject(manifest.defaultOptions) ? manifest.defaultOptions : {}
const schema = isPlainObject(manifest.configSchema) ? manifest.configSchema : null
// `optionSchema` is the name first-party plugins (and Quartz Syncer) use for the same field
const declared = manifest.configSchema ?? manifest.optionSchema
const schema = isPlainObject(declared) ? declared : null
const schemaProps = schema && isPlainObject(schema.properties) ? schema.properties : {}
const known = new Set([...Object.keys(defaults), ...Object.keys(schemaProps)])
if (known.size === 0) return issues
+14
View File
@@ -137,6 +137,20 @@ describe("validatePluginOptions", () => {
assert.strictEqual(issues[0].suggestion, "dark")
assert.strictEqual(issues[1].severity, "warning")
})
// first-party plugins (and Quartz Syncer) name the field optionSchema
test("reads optionSchema as the same schema", () => {
const issues = validatePluginOptions(
{ mode: "drak" },
{
optionSchema: {
type: "object",
properties: { mode: { type: "string", enum: ["light", "dark"] } },
},
},
)
assert.strictEqual(issues[0]?.suggestion, "dark")
})
})
describe("validatePluginEntry", () => {
+2 -1
View File
@@ -325,7 +325,8 @@ async function readManifestFromPackageJson(source: PluginSource): Promise<Plugin
defaultOrder: q.defaultOrder,
defaultEnabled: q.defaultEnabled,
defaultOptions: q.defaultOptions,
configSchema: q.configSchema,
// first-party plugins (and Quartz Syncer) call it optionSchema
configSchema: q.configSchema ?? q.optionSchema,
components: q.components,
frames: q.frames,
}