Compare commits

..
Author SHA1 Message Date
saberzero1 28fcb64720 fix: stop esbuild before exiting on a build error 2026-11-09 02:33:30 +01:00
6 changed files with 21 additions and 66 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
When a build stops on an error, Quartz stops esbuild before exiting. esbuild runs as a child process that writes to the same terminal; left running, it could print "fatal error: all goroutines are asleep - deadlock!" and a long goroutine dump after Quartz's error message.
-5
View File
@@ -1,5 +0,0 @@
---
"@jackyzha0/quartz": patch
---
Embedding a section by the anchor Obsidian writes for its heading works when that anchor differs from the heading's id: `![[note#Colon unspaced]]` now embeds `## Colon:unspaced`. It needs GitHubFlavoredMarkdown 2.1.0 or later, which marks those anchors on the heading.
+2
View File
@@ -428,6 +428,8 @@ export async function handleBuild(argv) {
`${styleText("red", "Failed to build Quartz.")} Check for syntax errors in your configuration or plugins.`,
)
console.log(`Reason: ${styleText("gray", err.message ?? String(err))}`)
// stop esbuild's child process first: it shares our stderr and outlives us otherwise
void esbuild.stop()
process.exit(1)
})
release()
-40
View File
@@ -183,46 +183,6 @@ describe("renderTranscludes", () => {
assert.ok(!secondText.includes("Circular transclusion"), "should not show circular warning")
})
test("a header transclusion matches a heading's Obsidian-anchor alias", () => {
const root: Root = {
type: "root",
children: [makeTranscludeBlockquote("target", "#colon-unspaced")],
}
const targetHtml: Root = {
type: "root",
children: [
{
type: "element",
tagName: "h2",
properties: { id: "colonunspaced" },
children: [
{
type: "element",
tagName: "span",
properties: { id: "colon-unspaced", className: ["heading-alias"] },
children: [],
},
{ type: "text", value: "Colon:unspaced" },
],
},
{
type: "element",
tagName: "p",
properties: {},
children: [{ type: "text", value: "Section text" }],
},
],
}
renderTranscludes(
root,
cfg,
"current" as FullSlug,
makeComponentData([makePageData("target", targetHtml)]) as QuartzComponentProps,
new Set<FullSlug>(["current" as FullSlug]),
)
assert.ok(JSON.stringify((root.children[0] as Element).children).includes("Section text"))
})
test("detects actual circular transclusion (A -> B -> A)", () => {
// Page A embeds B, and B's htmlAst contains a transclusion of A
const bTranscludesA = makeTranscludeBlockquote("pageA")
+1 -20
View File
@@ -31,25 +31,6 @@ interface RenderComponents {
}
const headerRegex = new RegExp(/h[1-6]/)
/**
* Whether a heading answers to `id`: its own id, or the id of a `span.heading-alias` inside it.
* GitHubFlavoredMarkdown adds that alias when the anchor Obsidian writes for a heading (`:`, `|`,
* `^`, `#` and `\` become spaces) slugs differently, e.g. `![[note#Colon unspaced]]` for
* `## Colon:unspaced`.
*/
function headingHasId(heading: Element, id: string): boolean {
if (heading.properties?.id === id) return true
const hasAlias = (el: Element): boolean =>
el.children.some(
(child) =>
child.type === "element" &&
((child.properties?.id === id &&
([] as unknown[]).concat(child.properties?.className ?? []).includes("heading-alias")) ||
hasAlias(child)),
)
return hasAlias(heading)
}
export function pageResources(
baseDir: FullSlug | RelativeURL,
staticResources: StaticResources,
@@ -250,7 +231,7 @@ export function renderTranscludes(
const depth = Number(htmlEl.tagName.substring(1))
if (startIdx === undefined || startDepth === undefined) {
if (headingHasId(htmlEl, blockRef)) {
if (htmlEl.properties?.id === blockRef) {
startIdx = i
startDepth = depth
}
+13 -1
View File
@@ -1,5 +1,6 @@
import { styleText } from "util"
import process from "process"
import esbuild from "esbuild"
import { isMainThread } from "workerpool"
import { isContentError, pluginErrorInfo, PluginErrorInfo } from "./pluginErrors"
import { knownProblemsFor } from "./diagnostics"
@@ -130,6 +131,17 @@ export function trace(msg: string, err: Error) {
} else {
// print and exit
console.error(traceMsg)
process.exit(1)
exitBuild(1)
}
}
/**
* Exit the build process. esbuild's service is a child process that shares our stderr; exiting
* while it has requests in flight (bundling component scripts, the CLI's build context) left it
* running without its parent, and it printed "fatal error: all goroutines are asleep - deadlock!"
* and a goroutine dump after Quartz's error. Stop it first.
*/
export function exitBuild(code: number): never {
void esbuild.stop()
process.exit(code)
}