mirror of
https://github.com/jackyzha0/quartz
synced 2026-11-27 22:14:40 +01:00
fix(plugins): compare dependency order only within a pipeline stage
This commit is contained in:
3 files changed
+44
-14
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
A plugin that depends on a plugin of another pipeline stage (an emitter or component on a transformer) no longer fails the build because of their `order`: order is checked only between plugins of the same stage.
|
||||
@@ -497,19 +497,28 @@ describe("dependency order between plugins", () => {
|
||||
})
|
||||
|
||||
// Order only decides between plugins of the same stage: all transformers run before any filter or
|
||||
// emitter, and a component-only plugin has no place in the pipeline. The check against a built-in
|
||||
// compares categories (above); the check between plugins doesn't, so an emitter (or a
|
||||
// component) depending on a transformer with a higher order fails the build with "is configured
|
||||
// to run first", although the transformer always runs first.
|
||||
test(
|
||||
"a dependency of another stage is not ordered against the plugin",
|
||||
{ todo: "bug: validateDependencies compares order across stages (config-loader.ts:225)" },
|
||||
() => {
|
||||
const transformer = { category: "transformer", defaultOrder: 60 } as const
|
||||
assert.deepStrictEqual(validate({ category: "emitter" }, transformer).errors, [])
|
||||
assert.deepStrictEqual(validate({ category: "component" }, transformer).errors, [])
|
||||
},
|
||||
)
|
||||
// emitter, and a component-only plugin has no place in the pipeline. An emitter (or a component)
|
||||
// depending on a transformer with a higher order used to fail the build with "is configured to
|
||||
// run first", although the transformer always runs first.
|
||||
test("a dependency of another stage is not ordered against the plugin", () => {
|
||||
const transformer = { category: "transformer", defaultOrder: 60 } as const
|
||||
assert.deepStrictEqual(validate({ category: "emitter" }, transformer).errors, [])
|
||||
assert.deepStrictEqual(validate({ category: "component" }, transformer).errors, [])
|
||||
assert.deepStrictEqual(
|
||||
validate({ category: "component" }, { category: "component", defaultOrder: 60 }).errors,
|
||||
[],
|
||||
)
|
||||
})
|
||||
|
||||
test("a plugin of several stages is ordered against a dependency in a stage they share", () => {
|
||||
const transformer = { category: "transformer", defaultOrder: 60 } as const
|
||||
assert.match(
|
||||
validate({ category: ["transformer", "emitter"] }, transformer).errors[0],
|
||||
/"x" \(order: 50\) depends on "y" \(order: 60\)/,
|
||||
)
|
||||
// without a category the stage is unknown: still compared
|
||||
assert.match(validate({}, { defaultOrder: 60 }).errors[0], /depends on "y" \(order: 60\)/)
|
||||
})
|
||||
})
|
||||
|
||||
describe("plugin names of each source form", () => {
|
||||
|
||||
@@ -159,6 +159,22 @@ interface DependencyValidationResult {
|
||||
warnings: string[]
|
||||
}
|
||||
|
||||
/** The pipeline stages a plugin's `order` decides its place in (a component has none). */
|
||||
const ORDERED_STAGES = ["transformer", "filter", "emitter", "pageType"] as const
|
||||
|
||||
/**
|
||||
* Whether `order` decides between the two plugins: they run in a stage they share (all
|
||||
* transformers run before any filter or emitter, whatever their order). Without a category on
|
||||
* either side the stage is unknown, and they are compared.
|
||||
*/
|
||||
function sameStage(a: PluginManifest, b: PluginManifest | undefined): boolean {
|
||||
if (!a.category || !b?.category) return true
|
||||
const stagesOfB = [b.category].flat()
|
||||
return [a.category]
|
||||
.flat()
|
||||
.some((c) => stagesOfB.includes(c) && (ORDERED_STAGES as readonly string[]).includes(c))
|
||||
}
|
||||
|
||||
export function validateDependencies(
|
||||
entries: PluginJsonEntry[],
|
||||
manifests: Map<string, PluginManifest>,
|
||||
@@ -229,7 +245,7 @@ export function validateDependencies(
|
||||
const depManifest = manifests.get(dep)
|
||||
const depOrder = depEntry.order ?? depManifest?.defaultOrder ?? 50
|
||||
|
||||
if (pluginOrder < depOrder) {
|
||||
if (pluginOrder < depOrder && sameStage(manifest, depManifest)) {
|
||||
errors.push(
|
||||
`Plugin "${pluginName}" (order: ${pluginOrder}) depends on "${depName}" (order: ${depOrder}), ` +
|
||||
`but "${pluginName}" is configured to run first. Either increase "${pluginName}"'s order above ${depOrder} ` +
|
||||
|
||||
Reference in new issue
Block a user