Silence Asciidoctor warnings in the build

This commit is contained in:
Rūdolfs Ošiņš
2026-10-06 16:46:06 +02:00
parent 5aaf12500e
commit 6eec206caf
+36 -14
View File
@@ -18,22 +18,44 @@ export default defineConfig({
{ {
name: "asciidoctor-drop-node-paths", name: "asciidoctor-drop-node-paths",
enforce: "pre" as const, enforce: "pre" as const,
transform(code: string, id: string) { transform: {
if (!id.includes("@asciidoctor/core")) return; filter: { id: /@asciidoctor\/core/ },
handler(code: string, id: string) {
const pattern = /new URL\((.*?), import\.meta\.url\)/g;
const patched = code.replaceAll(pattern, "new URL($1, `file:///`)");
const expected = code.includes("DATA_DIR") ? 3 : 0;
const found = code.match(pattern)?.length ?? 0;
const pattern = /new URL\((.*?), import\.meta\.url\)/g; if (found !== expected) {
const patched = code.replaceAll(pattern, "new URL($1, `file:///`)"); throw new Error(
const expected = code.includes("DATA_DIR") ? 3 : 0; `Expected ${expected} import.meta.url uses in ${id}, found ${found}. ` +
const found = code.match(pattern)?.length ?? 0; `Asciidoctor may now rely on them at runtime; re-check before patching.`,
);
}
if (found !== expected) { return found > 0 ? { code: patched } : undefined;
throw new Error( },
`Expected ${expected} import.meta.url uses in ${id}, found ${found}. ` + },
`Asciidoctor may now rely on them at runtime; re-check before patching.`, },
); // Asciidoctor's browser build lazily imports Node built-ins for file input
} // and output, behind guards that tolerate them being absent. Resolve them
// to an empty module, as Vite would, without its externalization warning.
return found > 0 ? { code: patched } : undefined; {
name: "asciidoctor-stub-node-builtins",
enforce: "pre" as const,
resolveId: {
filter: { id: /^node:/ },
handler(source: string, importer: string | undefined) {
if (importer?.includes("@asciidoctor/core")) {
return `\0asciidoctor-node-stub:${source}`;
}
},
},
load: {
filter: { id: /^\0asciidoctor-node-stub:/ },
handler() {
return "export default {};";
},
}, },
}, },
svelte({ svelte({