From 6eec206caf9ebec324683501654ed701062b8360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Tue, 6 Oct 2026 16:45:23 +0200 Subject: [PATCH] Silence Asciidoctor warnings in the build --- vite.config.ts | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index 91f0c1949..cb715046c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -18,22 +18,44 @@ export default defineConfig({ { name: "asciidoctor-drop-node-paths", enforce: "pre" as const, - transform(code: string, id: string) { - if (!id.includes("@asciidoctor/core")) return; + transform: { + 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; - const patched = code.replaceAll(pattern, "new URL($1, `file:///`)"); - const expected = code.includes("DATA_DIR") ? 3 : 0; - const found = code.match(pattern)?.length ?? 0; + if (found !== expected) { + 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.`, + ); + } - if (found !== expected) { - 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.`, - ); - } - - return found > 0 ? { code: patched } : undefined; + return found > 0 ? { code: patched } : undefined; + }, + }, + }, + // 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. + { + 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({