fix(plugin) resolve lockfile after create

This commit is contained in:
saberzero1
2026-03-16 13:05:12 +01:00
parent 52ca3aef4c
commit 6ec256dcbc
3 changed files with 69 additions and 64 deletions

View File

@@ -27,6 +27,7 @@ import {
handlePluginRestore,
handlePluginCheck,
handlePluginUpdate,
handlePluginResolve,
} from "./plugin-git-handlers.js"
import {
configExists,
@@ -274,15 +275,12 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
// Strip protocol prefix if user included it
baseUrl = baseUrl.replace(/^https?:\/\//, "").replace(/\/+$/, "")
// Create config if it doesn't exist
if (!configExists()) {
if (template && template !== "default") {
createConfigFromTemplate(template)
console.log(styleText("green", `Created quartz.config.yaml from '${template}' template`))
} else {
createConfigFromTemplate("default")
console.log(styleText("green", "Created quartz.config.yaml from defaults"))
}
if (template && template !== "default") {
createConfigFromTemplate(template)
console.log(styleText("green", `Created quartz.config.yaml from '${template}' template`))
} else {
createConfigFromTemplate("default")
console.log(styleText("green", "Created quartz.config.yaml from defaults"))
}
// Update markdownLinkResolution in the crawl-links plugin options via YAML config
@@ -303,6 +301,9 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
// Update baseUrl in configuration
updateGlobalConfig({ baseUrl })
// install plugins referenced in the template config
await handlePluginResolve()
// setup remote
execSync(`git remote show upstream || git remote add upstream ${QUARTZ_SOURCE_REPO}`, {
stdio: "ignore",

View File

@@ -993,7 +993,8 @@ export async function handlePluginResolve({ dryRun = false } = {}) {
// Find config entries whose source is a git/local-resolvable URL and not yet in lockfile
const missing = pluginsJson.plugins.filter((entry) => {
const name = extractPluginName(entry.source)
if (lockfile.plugins[name]) return false
const pluginDir = path.join(PLUGINS_DIR, name)
if (lockfile.plugins[name] && fs.existsSync(pluginDir)) return false
// Only attempt sources that parseGitSource can handle (git URLs + local paths)
const src = entry.source
return (
@@ -1117,6 +1118,21 @@ export async function handlePluginResolve({ dryRun = false } = {}) {
await regeneratePluginIndex()
}
const configNames = new Set(pluginsJson.plugins.map((entry) => extractPluginName(entry.source)))
const orphans = Object.keys(lockfile.plugins).filter((name) => !configNames.has(name))
if (orphans.length > 0) {
console.log()
for (const name of orphans) {
const pluginDir = path.join(PLUGINS_DIR, name)
if (fs.existsSync(pluginDir)) {
fs.rmSync(pluginDir, { recursive: true })
}
delete lockfile.plugins[name]
console.log(styleText("yellow", `✗ Removed ${name} (not in config)`))
}
await regeneratePluginIndex()
}
writeLockfile(lockfile)
console.log()
if (failed === 0) {