Compare commits

..
13 changed files with 167 additions and 25 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Plugins can declare `window.quartzStaticUrl` and `window.quartzPrefetch` in `capabilities.requires.globals` without a false "nothing provides it" warning: Quartz counts both as its own (`quartzPrefetch` unless `prefetch` is off).
+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
A plugin whose dependency is configured but disabled gets the intended warning ("depends on X which is disabled") instead of failing the build with "requires X. Run: npx quartz plugin add X".
+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Plugin option checks use the option schemas first-party plugins ship. These are declared as `quartz.optionSchema`, the name Quartz Syncer reads, as a flat map of option to type (`{ limit: { type: "number" }, mode: { type: "enum", values: [...] } }`). Before, only a JSON Schema in `quartz.configSchema` was read, so no first-party plugin's schema was used. A misspelled option, an enum value that isn't allowed, or a value of the wrong type is now a warning. A value of the same type as the plugin's default is always accepted, even where a schema disagrees.
+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Tag pages honour the TagPage `numPages` and `sort` options (tag-page 1.0.4); before, they always used the defaults. Plugin client scripts can use `window.quartzStaticUrl` and `window.quartzPrefetch` with the declarations in `@quartz-community/types` 1.3.1.
+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
The Roam Research plugin works with ObsidianFlavoredMarkdown on, as in the default config (roam 1.1.0). `{{[[TODO]]}}`, `{{[[DONE]]}}`, `[[>]]` and `{{[[video]]: …}}` no longer render as wikilinks, and `__italic__` is italic instead of bold.
+12 -12
View File
@@ -45,14 +45,14 @@
"@quartz-community/quartz-fonts": "^1.0.2",
"@quartz-community/reader-mode": "^1.0.2",
"@quartz-community/recent-notes": "^1.0.3",
"@quartz-community/roam": "^1.0.1",
"@quartz-community/roam": "^1.1.0",
"@quartz-community/search": "^1.0.3",
"@quartz-community/spacer": "^1.0.2",
"@quartz-community/stacked-pages": "^1.0.3",
"@quartz-community/syntax-highlighting": "^1.0.3",
"@quartz-community/table-of-contents": "^1.0.3",
"@quartz-community/tag-list": "^1.0.3",
"@quartz-community/tag-page": "^1.0.3",
"@quartz-community/tag-page": "^1.0.4",
"@quartz-community/unlisted-pages": "^1.1.0",
"@quartz-themes/core": "^2.0.1",
"ansi-truncate": "^1.4.0",
@@ -97,7 +97,7 @@
},
"devDependencies": {
"@changesets/cli": "^2.29.2",
"@quartz-community/types": "^1.3.0",
"@quartz-community/types": "^1.3.1",
"@quartz-community/utils": "^1.2.0",
"@types/hast": "^3.0.4",
"@types/js-yaml": "^4.0.9",
@@ -3110,9 +3110,9 @@
}
},
"node_modules/@quartz-community/roam": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@quartz-community/roam/-/roam-1.0.1.tgz",
"integrity": "sha512-JiNSu3u5ly+f4Y4ql9yC1geJ5+TN0jaSx8UEjpbZT8cnEBKNmCyaQJMBj4X18RWu0EIsUchp96ksFjmcaPG2Zg==",
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@quartz-community/roam/-/roam-1.1.0.tgz",
"integrity": "sha512-Q5mRS38G6M+YMek7zN1ecr7ZCsVZ8ccl15Lsagf1CTr1ZSOvGdvu+dJdV5QbAF+KHg0jwUwdQly4OUvUMEBrCQ==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0"
@@ -3269,9 +3269,9 @@
}
},
"node_modules/@quartz-community/tag-page": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@quartz-community/tag-page/-/tag-page-1.0.3.tgz",
"integrity": "sha512-2D9w5gXKxERPny9uFb64iOG+DqcAmieYDu+x0DFPULh/UTlYm6xk2adwrTfi6lFouzl/UoHRmHxjumC3zwNvWQ==",
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@quartz-community/tag-page/-/tag-page-1.0.4.tgz",
"integrity": "sha512-57SBbZGfdckzVtwGtnoFSzxIJbeFEtgATMCMrnfql+5o+kZENnCRP9m2BCl/W3i1u3ygpLQ9DPxSQn97rsqzaw==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0",
@@ -3295,9 +3295,9 @@
}
},
"node_modules/@quartz-community/types": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/@quartz-community/types/-/types-1.3.0.tgz",
"integrity": "sha512-tdLWSv+XWqHGiuo77etvXkd2XO1S12NlUUbiC9o+o9BWgW7E/lcNl6A+I8c9uKbAj9CrIn7suK7z9154rlSwlQ==",
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@quartz-community/types/-/types-1.3.1.tgz",
"integrity": "sha512-8tgpi+4EqLWZyCCA2CE3RC9hIUMc1vvzq4lHyhUpwao8v+Ij/CcLQQMh51jlnGFhbItSuFw1NH26TMjJ2cXgzA==",
"license": "MIT",
"dependencies": {
"unified": "^11.0.5",
+3 -3
View File
@@ -75,14 +75,14 @@
"@quartz-community/quartz-fonts": "^1.0.2",
"@quartz-community/reader-mode": "^1.0.2",
"@quartz-community/recent-notes": "^1.0.3",
"@quartz-community/roam": "^1.0.1",
"@quartz-community/roam": "^1.1.0",
"@quartz-community/search": "^1.0.3",
"@quartz-community/spacer": "^1.0.2",
"@quartz-community/stacked-pages": "^1.0.3",
"@quartz-community/syntax-highlighting": "^1.0.3",
"@quartz-community/table-of-contents": "^1.0.3",
"@quartz-community/tag-list": "^1.0.3",
"@quartz-community/tag-page": "^1.0.3",
"@quartz-community/tag-page": "^1.0.4",
"@quartz-community/unlisted-pages": "^1.1.0",
"@quartz-themes/core": "^2.0.1",
"ansi-truncate": "^1.4.0",
@@ -124,7 +124,7 @@
},
"devDependencies": {
"@changesets/cli": "^2.29.2",
"@quartz-community/types": "^1.3.0",
"@quartz-community/types": "^1.3.1",
"@quartz-community/utils": "^1.2.0",
"@types/hast": "^3.0.4",
"@types/js-yaml": "^4.0.9",
+35 -4
View File
@@ -137,14 +137,38 @@ export function findConfigEntries(plugins, query, { extractName, formatSource })
return { indices: [], suggestion }
}
/**
* The JSON Schema of a plugin's options: `configSchema`, or `optionSchema`, the name first-party
* plugins (and Quartz Syncer) use. An `optionSchema` is usually a flat map of option name to
* property schema (`{ limit: { type: "number" }, mode: { type: "enum", values: [...] } }`); it is
* read as `{ type: "object", properties: … }`, with `type: "enum"` + `values` as a JSON `enum`.
*
* @param {{ configSchema?: any, optionSchema?: any }} manifest
* @returns {any | null}
*/
export function optionsSchemaOf(manifest) {
const declared = manifest.configSchema ?? manifest.optionSchema
if (!isPlainObject(declared)) return null
if (isPlainObject(declared.properties) || declared.type === "object") return declared
const properties = {}
for (const [key, prop] of Object.entries(declared)) {
if (!isPlainObject(prop)) continue
properties[key] =
prop.type === "enum" && Array.isArray(prop.values)
? { ...prop, type: undefined, enum: prop.values }
: prop
}
return { type: "object", properties }
}
/**
* 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 +177,7 @@ 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
const schema = optionsSchemaOf(manifest)
const schemaProps = schema && isPlainObject(schema.properties) ? schema.properties : {}
const known = new Set([...Object.keys(defaults), ...Object.keys(schemaProps)])
if (known.size === 0) return issues
@@ -211,7 +235,14 @@ export function validatePluginOptions(options, manifest, prefix = "") {
? describeType(defaults[key])
: null
const actual = describeType(value)
if (expected && expected !== actual) {
// a value of the default's own type is fine even when the schema says otherwise (schemas
// can lag behind: recent-notes' `linkToMore` is typed string, its default is false)
const matchesDefault =
key in defaults &&
defaults[key] !== null &&
defaults[key] !== undefined &&
describeType(defaults[key]) === actual
if (expected && expected !== actual && !matchesDefault) {
const shown = key in defaults ? ` (default: ${JSON.stringify(defaults[key])})` : ""
issues.push({
severity: "warning",
+45
View File
@@ -137,6 +137,51 @@ describe("validatePluginOptions", () => {
assert.strictEqual(issues[0].suggestion, "dark")
assert.strictEqual(issues[1].severity, "warning")
})
// first-party plugins (and Quartz Syncer) name the field optionSchema, as a flat map
test("reads a flat optionSchema, with type enum + values", () => {
const manifest = {
defaultOptions: { limit: 3 },
optionSchema: {
limit: { type: "number" },
mode: { type: "enum", values: ["light", "dark"] },
show: { type: "boolean" },
},
}
const issues = validatePluginOptions({ mode: "drak", limit: "5", shwo: true }, manifest)
assert.deepStrictEqual(
issues.map((i) => [i.path, i.severity, i.suggestion]),
[
["mode", "warning", "dark"],
["limit", "warning", undefined],
["shwo", "warning", "show"],
],
)
assert.deepStrictEqual(validatePluginOptions({ mode: "dark", show: false }, manifest), [])
})
test("accepts a value of the default's type when the schema disagrees", () => {
const manifest = {
defaultOptions: { linkToMore: false },
optionSchema: { linkToMore: { type: "string" } },
}
assert.deepStrictEqual(validatePluginOptions({ linkToMore: false }, manifest), [])
assert.deepStrictEqual(validatePluginOptions({ linkToMore: "tags/" }, manifest), [])
assert.strictEqual(validatePluginOptions({ linkToMore: 3 }, manifest)[0]?.severity, "warning")
})
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", () => {
@@ -197,3 +197,12 @@ describe("validatePluginCapabilities", () => {
assert.deepStrictEqual(report.warnings, [])
})
})
describe("core globals", () => {
test("quartzStaticUrl always, quartzPrefetch unless prefetching is off", () => {
assert.ok(coreCapabilities().globals?.includes("quartzStaticUrl"))
assert.ok(coreCapabilities().globals?.includes("quartzPrefetch"))
assert.ok(coreCapabilities({ prefetch: "hover" }).globals?.includes("quartzPrefetch"))
assert.ok(!coreCapabilities({ prefetch: "off" }).globals?.includes("quartzPrefetch"))
})
})
+15 -4
View File
@@ -87,14 +87,25 @@ export interface CapabilityReport {
* Capabilities Quartz core itself always provides (independent of plugins).
* Kept deliberately small: only things core code sets or renders unconditionally.
*/
export function coreCapabilities(configuration?: { enableSPA?: boolean }): CapabilityList {
export function coreCapabilities(configuration?: {
enableSPA?: boolean
prefetch?: string | boolean
}): CapabilityList {
const prefetch = configuration?.prefetch !== "off" && configuration?.prefetch !== false
return {
// quartz/processors/parse.ts
data: ["slug", "filePath", "relativePath"],
// renderPage.tsx / frames
dom: ["#quartz-body", ".page", ".center", "article", ".popover-hint", ".sidebar"],
// renderPage.tsx (fetchData), componentResources.ts (spaNavigate/addCleanup, SPA or not)
globals: ["fetchData", "addCleanup", "spaNavigate"],
// renderPage.tsx (fetchData, quartzStaticUrl), componentResources.ts (spaNavigate/addCleanup,
// SPA or not; quartzPrefetch unless prefetching is off)
globals: [
"fetchData",
"addCleanup",
"spaNavigate",
"quartzStaticUrl",
...(prefetch ? ["quartzPrefetch"] : []),
],
// componentResources.ts dispatches "nav" in both modes; spa.inline.ts adds "prenav"
events: configuration?.enableSPA === false ? ["nav"] : ["nav", "prenav"],
}
@@ -303,7 +314,7 @@ export async function validatePluginCapabilities<E extends { enabled: boolean }>
manifestFor: (
entry: E,
) => Promise<ManifestLike | null | undefined> | ManifestLike | null | undefined
configuration?: { enableSPA?: boolean }
configuration?: { enableSPA?: boolean; prefetch?: string | boolean }
/** Built-in processing steps (see plugins/builtins): enabled ones provide, others are suggested. */
builtins?: { enabled: CapabilityPlugin[]; available: CapabilityPlugin[] }
}): Promise<CapabilityReport> {
@@ -373,3 +373,19 @@ describe("dependencies on plugins that are built in now", () => {
assert.match(errors[0], /requires "@quartz-community\/explorer"/)
})
})
describe("a dependency that is configured but disabled", () => {
test("is a warning, not a missing plugin", () => {
const dep = "@quartz-community/explorer"
const entries: PluginJsonEntry[] = [
{ source: "github:someone/x", enabled: true, options: {} },
{ source: dep, enabled: false, options: {} },
]
const manifests = new Map<string, PluginManifest>([
["github:someone/x", { dependencies: [dep] } as unknown as PluginManifest],
])
const { errors, warnings } = validateDependencies(entries, manifests, [])
assert.deepStrictEqual(errors, [])
assert.match(warnings[0], /depends on "@quartz-community\/explorer" which is disabled/)
})
})
+7 -2
View File
@@ -215,6 +215,8 @@ export function validateDependencies(
warnings.push(
`Plugin "${pluginName}" depends on "${depName}" which is disabled. "${pluginName}" may not function correctly.`,
)
// it doesn't run, so its order doesn't matter (and its manifest isn't loaded)
continue
}
const depManifest = manifests.get(dep)
@@ -325,7 +327,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,
}
@@ -505,7 +508,9 @@ export async function loadQuartzConfig(
)
// Validate dependencies
const validation = validateDependencies(enabledEntries, manifests, builtinPlan.builtins)
// all entries: a dependency that is configured but disabled is a warning, not "missing"
// (validateDependencies skips disabled plugins itself)
const validation = validateDependencies(pluginEntries, manifests, builtinPlan.builtins)
for (const warning of validation.warnings) {
console.warn(styleText("yellow", `⚠`) + ` ${warning}`)
}