`quartz.ts` overrides fail for scoped npm plugins due to registry key mismatch
Description
As previously noted in #2382 , the documented quartz.ts plugin override syntax does not work for scoped npm plugins:
import { loadQuartzConfig, loadQuartzLayout } from "./quartz/plugins/loader/config-loader"
import * as ExternalPlugin from "./.quartz/plugins"
ExternalPlugin.Explorer({
filterFn: (node) => {
// ...
},
})
const config = await loadQuartzConfig()
export default config
export const layout = await loadQuartzLayout()However, directly setting the override through componentRegistry works:
import { componentRegistry } from "./quartz/components/registry"
componentRegistry.setOptionOverrides("@quartz-community/explorer", {
filterFn: (node) => {
// ...
},
})This appears to be caused by a mismatch between the registry key generated in .quartz/plugins/index.ts and the key used by config-loader.ts.
Cause
Here I will explicitly use @quartz-community/explorer as an example. In quartz/plugins/loader/gitLoader.ts, scoped npm package names are sanitized when generating the plugin index:
const key = npmPkg.replace(/^@/, "").replace(/\//g, "__") //quartz-community__explorerThis sanitized key is then also used when generating the override wrapper:
componentRegistry.setOptionOverrides("quartz-community__explorer", options)However, config-loader.ts retrieves overrides using spec.name:
const spec = parsePluginSource(entry.source)
const pluginOverrides = componentRegistry.getOptionOverrides(spec.name)parsePluginSource() preserves the original npm package name, so:
spec.name === "@quartz-community/explorer"The override is stored under quartz-community__explorer but retrieved under @quartz-community/explorer. This must be why getOptionOverrides() returns undefined.
Source: jackyzha0/quartz