mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-18 19:30:27 +08:00
Silence Asciidoctor warnings in the build
This commit is contained in:
+36
-14
@@ -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({
|
||||||
|
|||||||
Reference in New Issue
Block a user