@moku-labs/web 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +26 -5
- package/dist/index.d.cts +9 -3
- package/dist/index.d.mts +9 -3
- package/dist/index.mjs +26 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3992,10 +3992,31 @@ function wrap(body) {
|
|
|
3992
3992
|
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>404 — Not Found</title></head><body>${body}</body></html>`;
|
|
3993
3993
|
}
|
|
3994
3994
|
/**
|
|
3995
|
+
* Resolve the 404 page HTML from `config.notFound`. Precedence: `path` (a
|
|
3996
|
+
* complete page file, read verbatim) > `body` (a fragment, wrapped in the
|
|
3997
|
+
* minimal shell) > the built-in default.
|
|
3998
|
+
*
|
|
3999
|
+
* @param notFound - The `config.notFound` value (already known to be truthy).
|
|
4000
|
+
* @returns The complete HTML document to write.
|
|
4001
|
+
* @example
|
|
4002
|
+
* ```ts
|
|
4003
|
+
* const html = await resolveHtml({ path: "src/404.html" });
|
|
4004
|
+
* ```
|
|
4005
|
+
*/
|
|
4006
|
+
async function resolveHtml(notFound) {
|
|
4007
|
+
if (typeof notFound === "object" && notFound.path) try {
|
|
4008
|
+
return await (0, node_fs_promises.readFile)(notFound.path, "utf8");
|
|
4009
|
+
} catch (error) {
|
|
4010
|
+
throw new Error(`build:not-found — could not read notFound.path "${notFound.path}"`, { cause: error });
|
|
4011
|
+
}
|
|
4012
|
+
return wrap(typeof notFound === "object" && notFound.body ? notFound.body : DEFAULT_BODY);
|
|
4013
|
+
}
|
|
4014
|
+
/**
|
|
3995
4015
|
* Emits `outDir/404.html`. When `config.notFound` is `true`, writes the built-in
|
|
3996
|
-
* default page;
|
|
3997
|
-
*
|
|
3998
|
-
*
|
|
4016
|
+
* default page; `{ body }` writes the supplied HTML body content inside the
|
|
4017
|
+
* minimal document shell; `{ path }` writes the referenced HTML page file
|
|
4018
|
+
* verbatim (the app owns the whole document). No-op (returns `null`) when
|
|
4019
|
+
* `notFound` is false/unset.
|
|
3999
4020
|
*
|
|
4000
4021
|
* @param ctx - Plugin context (provides `config`, `log`).
|
|
4001
4022
|
* @returns The written file path, or `null` when disabled.
|
|
@@ -4010,10 +4031,10 @@ async function generateNotFound(ctx) {
|
|
|
4010
4031
|
ctx.log.debug("build:not-found", { skipped: true });
|
|
4011
4032
|
return null;
|
|
4012
4033
|
}
|
|
4013
|
-
const
|
|
4034
|
+
const html = await resolveHtml(notFound);
|
|
4014
4035
|
await (0, node_fs_promises.mkdir)(outDir, { recursive: true });
|
|
4015
4036
|
const file = node_path$1.default.join(outDir, "404.html");
|
|
4016
|
-
await (0, node_fs_promises.writeFile)(file,
|
|
4037
|
+
await (0, node_fs_promises.writeFile)(file, html, "utf8");
|
|
4017
4038
|
ctx.log.debug("build:not-found", { path: file });
|
|
4018
4039
|
return { path: file };
|
|
4019
4040
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1663,12 +1663,18 @@ type Config$3 = {
|
|
|
1663
1663
|
injectAssets?: boolean; /** Directory copied verbatim into `outDir` (skipped silently if absent). Default `"public"`. */
|
|
1664
1664
|
publicDir?: string;
|
|
1665
1665
|
/**
|
|
1666
|
-
* Emit `outDir/404.html`.
|
|
1667
|
-
*
|
|
1668
|
-
*
|
|
1666
|
+
* Emit `outDir/404.html`. One of:
|
|
1667
|
+
* - `true` — the built-in default page.
|
|
1668
|
+
* - `{ body }` — literal HTML body content, wrapped in a minimal document shell.
|
|
1669
|
+
* - `{ path }` — path to a complete HTML page file (resolved from the project
|
|
1670
|
+
* root), written out VERBATIM so the app owns the whole document (its own
|
|
1671
|
+
* `<head>`, asset links, and body).
|
|
1672
|
+
*
|
|
1673
|
+
* `path` takes precedence over `body` when both are set. Default `false`.
|
|
1669
1674
|
*/
|
|
1670
1675
|
notFound?: boolean | {
|
|
1671
1676
|
body?: string;
|
|
1677
|
+
path?: string;
|
|
1672
1678
|
}; /** Emit per-path i18n bare-path redirect HTML pages. Default `false`. */
|
|
1673
1679
|
localeRedirects?: boolean; /** Authoritative client bundle entry path (overrides the conventional scan). */
|
|
1674
1680
|
clientEntry?: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -1663,12 +1663,18 @@ type Config$3 = {
|
|
|
1663
1663
|
injectAssets?: boolean; /** Directory copied verbatim into `outDir` (skipped silently if absent). Default `"public"`. */
|
|
1664
1664
|
publicDir?: string;
|
|
1665
1665
|
/**
|
|
1666
|
-
* Emit `outDir/404.html`.
|
|
1667
|
-
*
|
|
1668
|
-
*
|
|
1666
|
+
* Emit `outDir/404.html`. One of:
|
|
1667
|
+
* - `true` — the built-in default page.
|
|
1668
|
+
* - `{ body }` — literal HTML body content, wrapped in a minimal document shell.
|
|
1669
|
+
* - `{ path }` — path to a complete HTML page file (resolved from the project
|
|
1670
|
+
* root), written out VERBATIM so the app owns the whole document (its own
|
|
1671
|
+
* `<head>`, asset links, and body).
|
|
1672
|
+
*
|
|
1673
|
+
* `path` takes precedence over `body` when both are set. Default `false`.
|
|
1669
1674
|
*/
|
|
1670
1675
|
notFound?: boolean | {
|
|
1671
1676
|
body?: string;
|
|
1677
|
+
path?: string;
|
|
1672
1678
|
}; /** Emit per-path i18n bare-path redirect HTML pages. Default `false`. */
|
|
1673
1679
|
localeRedirects?: boolean; /** Authoritative client bundle entry path (overrides the conventional scan). */
|
|
1674
1680
|
clientEntry?: string;
|
package/dist/index.mjs
CHANGED
|
@@ -3979,10 +3979,31 @@ function wrap(body) {
|
|
|
3979
3979
|
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>404 — Not Found</title></head><body>${body}</body></html>`;
|
|
3980
3980
|
}
|
|
3981
3981
|
/**
|
|
3982
|
+
* Resolve the 404 page HTML from `config.notFound`. Precedence: `path` (a
|
|
3983
|
+
* complete page file, read verbatim) > `body` (a fragment, wrapped in the
|
|
3984
|
+
* minimal shell) > the built-in default.
|
|
3985
|
+
*
|
|
3986
|
+
* @param notFound - The `config.notFound` value (already known to be truthy).
|
|
3987
|
+
* @returns The complete HTML document to write.
|
|
3988
|
+
* @example
|
|
3989
|
+
* ```ts
|
|
3990
|
+
* const html = await resolveHtml({ path: "src/404.html" });
|
|
3991
|
+
* ```
|
|
3992
|
+
*/
|
|
3993
|
+
async function resolveHtml(notFound) {
|
|
3994
|
+
if (typeof notFound === "object" && notFound.path) try {
|
|
3995
|
+
return await readFile(notFound.path, "utf8");
|
|
3996
|
+
} catch (error) {
|
|
3997
|
+
throw new Error(`build:not-found — could not read notFound.path "${notFound.path}"`, { cause: error });
|
|
3998
|
+
}
|
|
3999
|
+
return wrap(typeof notFound === "object" && notFound.body ? notFound.body : DEFAULT_BODY);
|
|
4000
|
+
}
|
|
4001
|
+
/**
|
|
3982
4002
|
* Emits `outDir/404.html`. When `config.notFound` is `true`, writes the built-in
|
|
3983
|
-
* default page;
|
|
3984
|
-
*
|
|
3985
|
-
*
|
|
4003
|
+
* default page; `{ body }` writes the supplied HTML body content inside the
|
|
4004
|
+
* minimal document shell; `{ path }` writes the referenced HTML page file
|
|
4005
|
+
* verbatim (the app owns the whole document). No-op (returns `null`) when
|
|
4006
|
+
* `notFound` is false/unset.
|
|
3986
4007
|
*
|
|
3987
4008
|
* @param ctx - Plugin context (provides `config`, `log`).
|
|
3988
4009
|
* @returns The written file path, or `null` when disabled.
|
|
@@ -3997,10 +4018,10 @@ async function generateNotFound(ctx) {
|
|
|
3997
4018
|
ctx.log.debug("build:not-found", { skipped: true });
|
|
3998
4019
|
return null;
|
|
3999
4020
|
}
|
|
4000
|
-
const
|
|
4021
|
+
const html = await resolveHtml(notFound);
|
|
4001
4022
|
await mkdir(outDir, { recursive: true });
|
|
4002
4023
|
const file = path.join(outDir, "404.html");
|
|
4003
|
-
await writeFile(file,
|
|
4024
|
+
await writeFile(file, html, "utf8");
|
|
4004
4025
|
ctx.log.debug("build:not-found", { path: file });
|
|
4005
4026
|
return { path: file };
|
|
4006
4027
|
}
|
package/package.json
CHANGED