mirror of
https://github.com/jackyzha0/quartz
synced 2026-11-27 22:14:40 +01:00
fix(plugins): dependencies on plugins built into core are satisfied by the built-in
This commit is contained in:
4 files changed
+111
-4
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
A plugin that lists a plugin now built into Quartz in `quartz.dependencies` (`@quartz-community/crawl-links`, `remove-draft` or `content-index`) no longer fails the build with "requires crawl-links. Run: npx quartz plugin add …". The built-in (`configuration.links`, `drafts`, `contentIndex`) satisfies the dependency. A warning is shown when that built-in is disabled. `npx quartz plugin doctor` checks the same way.
|
||||
@@ -52,6 +52,7 @@ import {
|
||||
} from "./subprocess.js"
|
||||
import { writePluginIndex } from "./plugin-index.js"
|
||||
import {
|
||||
builtinKeyFor,
|
||||
builtinMessage,
|
||||
describeBuiltins,
|
||||
findBuiltinMigrations,
|
||||
@@ -2662,6 +2663,23 @@ export async function handlePluginDoctor({ verbose = false, fix = false } = {})
|
||||
if (deprecation) report("warning", null, deprecation.message, deprecation.hint)
|
||||
if (enabled) {
|
||||
for (const dep of manifest.dependencies ?? []) {
|
||||
// A plugin that is built into core now (crawl-links → configuration.links, …) is
|
||||
// satisfied by the built-in: its entries were absorbed above.
|
||||
const builtinKey = builtinKeyFor(dep)
|
||||
if (builtinKey) {
|
||||
const builtin = describeBuiltins(config.data.configuration).find(
|
||||
(b) => b.key === builtinKey,
|
||||
)
|
||||
if (builtin && !builtin.enabled) {
|
||||
report(
|
||||
"warning",
|
||||
label,
|
||||
`depends on ${dep}, which is built into Quartz now as configuration.${builtinKey} and is disabled`,
|
||||
`Enable configuration.${builtinKey} in quartz.config.yaml.`,
|
||||
)
|
||||
}
|
||||
continue
|
||||
}
|
||||
const depEntry =
|
||||
enabledSources.get(dep) ??
|
||||
plugins.find((e) => {
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import test, { describe, afterEach } from "node:test"
|
||||
import assert from "node:assert"
|
||||
import { buildLayoutForEntries, isExcluded, resolveGroups } from "./config-loader"
|
||||
import {
|
||||
buildLayoutForEntries,
|
||||
isExcluded,
|
||||
resolveGroups,
|
||||
validateDependencies,
|
||||
} from "./config-loader"
|
||||
import { planBuiltins } from "../builtins"
|
||||
import type { PluginManifest } from "./types"
|
||||
import { componentRegistry } from "../../components/registry"
|
||||
import type { QuartzComponent, QuartzComponentConstructor } from "../../components/types"
|
||||
import { PluginJsonEntry, LayoutPosition } from "./types"
|
||||
@@ -321,3 +328,48 @@ describe("isExcluded", () => {
|
||||
assert.ok(!isExcluded("@quartz-community/explorer", ["reader-mode"]))
|
||||
})
|
||||
})
|
||||
|
||||
// crawl-links, remove-draft and content-index are built into core in 5.1: their entries are
|
||||
// absorbed before dependencies are checked, so a plugin depending on one must be satisfied by the
|
||||
// built-in (a community plugin depending on crawl-links failed every 5.1 build).
|
||||
describe("dependencies on plugins that are built in now", () => {
|
||||
const source = "github:someone/cloudflare-media"
|
||||
const check = (configuration: Record<string, unknown>, order?: number) => {
|
||||
const entry: PluginJsonEntry = { source, enabled: true, options: {}, order }
|
||||
const manifest = {
|
||||
name: "cloudflare-media",
|
||||
category: "transformer",
|
||||
defaultOrder: 65,
|
||||
dependencies: ["@quartz-community/crawl-links"],
|
||||
} as unknown as PluginManifest
|
||||
const plan = planBuiltins({
|
||||
configuration,
|
||||
entries: [],
|
||||
nameOf: () => "",
|
||||
providesOf: () => undefined,
|
||||
})
|
||||
return validateDependencies([entry], new Map([[source, manifest]]), plan.builtins)
|
||||
}
|
||||
|
||||
test("are satisfied by the enabled built-in", () => {
|
||||
assert.deepStrictEqual(check({}), { errors: [], warnings: [] })
|
||||
})
|
||||
|
||||
test("warn when the built-in is disabled", () => {
|
||||
const { errors, warnings } = check({ links: false })
|
||||
assert.deepStrictEqual(errors, [])
|
||||
assert.match(warnings[0], /built into Quartz now as configuration\.links and is disabled/)
|
||||
})
|
||||
|
||||
test("must still run after the built-in in the same stage", () => {
|
||||
const { errors } = check({}, 50)
|
||||
assert.match(errors[0], /order: 50.*configuration\.links, order: 60/)
|
||||
})
|
||||
|
||||
test("other missing dependencies still fail", () => {
|
||||
const entry: PluginJsonEntry = { source, enabled: true, options: {} }
|
||||
const manifest = { dependencies: ["@quartz-community/explorer"] } as unknown as PluginManifest
|
||||
const { errors } = validateDependencies([entry], new Map([[source, manifest]]), [])
|
||||
assert.match(errors[0], /requires "@quartz-community\/explorer"/)
|
||||
})
|
||||
})
|
||||
@@ -41,7 +41,13 @@ import {
|
||||
parseCapabilities,
|
||||
CapabilityPlugin,
|
||||
} from "./capabilities"
|
||||
import { absorbingBuiltin, BuiltinPlan, instantiateBuiltins, planBuiltins } from "../builtins"
|
||||
import {
|
||||
absorbingBuiltin,
|
||||
BuiltinPlan,
|
||||
instantiateBuiltins,
|
||||
PlannedBuiltin,
|
||||
planBuiltins,
|
||||
} from "../builtins"
|
||||
import { registerPluginOrigin, reportError, warn } from "../../util/diagnostics"
|
||||
import { firstPluginFrame } from "../../util/trace"
|
||||
import {
|
||||
@@ -146,9 +152,10 @@ interface DependencyValidationResult {
|
||||
warnings: string[]
|
||||
}
|
||||
|
||||
function validateDependencies(
|
||||
export function validateDependencies(
|
||||
entries: PluginJsonEntry[],
|
||||
manifests: Map<string, PluginManifest>,
|
||||
builtins: PlannedBuiltin[] = [],
|
||||
): DependencyValidationResult {
|
||||
const errors: string[] = []
|
||||
const warnings: string[] = []
|
||||
@@ -172,6 +179,31 @@ function validateDependencies(
|
||||
const depEntry = sourceToEntry.get(dep)
|
||||
const depName = extractPluginName(dep)
|
||||
|
||||
// A plugin that is built into core now (crawl-links → configuration.links, …) has no entry
|
||||
// to find: its entries are absorbed before this check. The built-in satisfies it.
|
||||
const builtin = depEntry
|
||||
? undefined
|
||||
: builtins.find((b) => b.spec === absorbingBuiltin({ source: dep } as PluginJsonEntry))
|
||||
if (builtin) {
|
||||
if (!builtin.enabled) {
|
||||
warnings.push(
|
||||
`Plugin "${pluginName}" depends on "${depName}", which is built into Quartz now as ` +
|
||||
`configuration.${builtin.spec.configKey} and is disabled. "${pluginName}" may not function correctly.`,
|
||||
)
|
||||
} else if (
|
||||
pluginOrder < builtin.order &&
|
||||
[manifest.category].flat().includes(builtin.spec.category)
|
||||
) {
|
||||
// order only decides between plugins of the same stage (a transformer after links)
|
||||
errors.push(
|
||||
`Plugin "${pluginName}" (order: ${pluginOrder}) depends on "${depName}" (built in as ` +
|
||||
`configuration.${builtin.spec.configKey}, order: ${builtin.order}), but "${pluginName}" is ` +
|
||||
`configured to run first. Increase "${pluginName}"'s order above ${builtin.order}.`,
|
||||
)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if (!depEntry) {
|
||||
errors.push(
|
||||
`Plugin "${pluginName}" requires "${depName}". Run: npx quartz plugin add ${dep}`,
|
||||
@@ -473,7 +505,7 @@ export async function loadQuartzConfig(
|
||||
)
|
||||
|
||||
// Validate dependencies
|
||||
const validation = validateDependencies(enabledEntries, manifests)
|
||||
const validation = validateDependencies(enabledEntries, manifests, builtinPlan.builtins)
|
||||
for (const warning of validation.warnings) {
|
||||
console.warn(styleText("yellow", `⚠`) + ` ${warning}`)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user