Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 48 additions & 24 deletions quartz/plugins/loader/gitLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ function linkPeerDependencies(pluginDir: string): void {
}
}

const INSTALL_BUILD_ATTEMPTS = 3

function buildInstalledPlugin(pluginDir: string, name: string, verbose?: boolean): void {
if (hasPrebuiltDist(pluginDir)) {
if (verbose) {
Expand All @@ -366,41 +368,63 @@ function buildInstalledPlugin(pluginDir: string, name: string, verbose?: boolean
return
}

try {
const shouldBuild = needsBuild(pluginDir)
const shouldBuild = needsBuild(pluginDir)
let lastError: unknown

if (verbose) {
console.log(styleText("cyan", `→`), `${name}: installing dependencies...`)
}
execSync("npm install --ignore-scripts", {
cwd: pluginDir,
stdio: verbose ? "inherit" : "pipe",
timeout: 120_000,
})
for (let attempt = 1; attempt <= INSTALL_BUILD_ATTEMPTS; attempt++) {
try {
// A registry hiccup can make npm silently resolve only the production
// subtree (missing devDependencies like the build tool itself), so wipe
// any partial install before retrying rather than layering on top of it.
if (attempt > 1) {
if (verbose) {
console.log(
styleText("yellow", `⟳`),
`${name}: retrying install (attempt ${attempt}/${INSTALL_BUILD_ATTEMPTS})...`,
)
}
fs.rmSync(path.join(pluginDir, "node_modules"), { recursive: true, force: true })
}

if (shouldBuild) {
if (verbose) {
console.log(styleText("cyan", `→`), `${name}: building...`)
console.log(styleText("cyan", `→`), `${name}: installing dependencies...`)
}
execSync("npm run build", {
execSync("npm install --ignore-scripts", {
cwd: pluginDir,
stdio: verbose ? "inherit" : "pipe",
timeout: 120_000,
})
}

execSync("npm prune --omit=dev", {
cwd: pluginDir,
stdio: verbose ? "inherit" : "pipe",
timeout: 60_000,
})
if (shouldBuild) {
if (verbose) {
console.log(styleText("cyan", `→`), `${name}: building...`)
}
execSync("npm run build", {
cwd: pluginDir,
stdio: verbose ? "inherit" : "pipe",
timeout: 120_000,
})
}

linkPeerDependencies(pluginDir)
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
console.error(styleText("red", `✗`), `${name}: post-install build failed: ${message}`)
throw new Error(`Failed to build plugin ${name}: ${message}`)
execSync("npm prune --omit=dev", {
cwd: pluginDir,
stdio: verbose ? "inherit" : "pipe",
timeout: 60_000,
})

linkPeerDependencies(pluginDir)
return
} catch (error) {
lastError = error
}
}

const message = lastError instanceof Error ? lastError.message : String(lastError)
console.error(
styleText("red", `✗`),
`${name}: post-install build failed after ${INSTALL_BUILD_ATTEMPTS} attempts: ${message}`,
)
throw new Error(`Failed to build plugin ${name}: ${message}`)
Comment on lines +422 to +427

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use a phase-neutral failure message.

This catch also handles install, prune, and peer-link failures, so reporting every failure as a build failure misdirects troubleshooting.

Proposed fix
-    `${name}: post-install build failed after ${INSTALL_BUILD_ATTEMPTS} attempts: ${message}`,
+    `${name}: plugin setup failed after ${INSTALL_BUILD_ATTEMPTS} attempts: ${message}`,
...
-  throw new Error(`Failed to build plugin ${name}: ${message}`)
+  throw new Error(`Failed to set up plugin ${name}: ${message}`)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const message = lastError instanceof Error ? lastError.message : String(lastError)
console.error(
styleText("red", `✗`),
`${name}: post-install build failed after ${INSTALL_BUILD_ATTEMPTS} attempts: ${message}`,
)
throw new Error(`Failed to build plugin ${name}: ${message}`)
const message = lastError instanceof Error ? lastError.message : String(lastError)
console.error(
styleText("red", `✗`),
`${name}: plugin setup failed after ${INSTALL_BUILD_ATTEMPTS} attempts: ${message}`,
)
throw new Error(`Failed to set up plugin ${name}: ${message}`)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@quartz/plugins/loader/gitLoader.ts` around lines 422 - 427, Update the
failure reporting in the catch block around the plugin installation workflow to
use phase-neutral wording instead of identifying every error as a post-install
build failure. Adjust both the console.error message and the thrown Error in the
relevant loader flow, while preserving the attempt count, plugin name, and
original error message.

}

interface PluginInstallResult {
Expand Down