noofpi 1.2.0 → 2.0.0
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/README.md +20 -4
- package/dist/{build-25H52PWT.js → build-PFCGDPPJ.js} +5 -4
- package/dist/chunk-3PSMWWUB.js +68 -0
- package/dist/{chunk-NALDZ3PS.js → chunk-I6TFIGFO.js} +13 -5
- package/dist/{chunk-NX6BO7UB.js → chunk-IE3WF5XF.js} +82 -2
- package/dist/{chunk-UF6YTIXD.js → chunk-LL3NO5EI.js} +361 -128
- package/dist/{chunk-FIJJ3EGL.js → chunk-MN5PVHC5.js} +4 -0
- package/dist/chunk-OKNF6XDO.js +14 -0
- package/dist/chunk-PPUFFGCH.js +168 -0
- package/dist/{chunk-WX2V6EYH.js → chunk-RUNIVVFH.js} +34 -10
- package/dist/{chunk-2XCZWFIQ.js → chunk-X3DYEZLK.js} +1 -1
- package/dist/{chunk-4YOOGEOF.js → chunk-YJVMBHNL.js} +1 -1
- package/dist/cli.js +130 -34
- package/dist/{dev-CC3RXV3G.js → dev-HTWUY27O.js} +47 -59
- package/dist/devtools-PLUN2DYV.js +958 -0
- package/dist/handler-C6NnwBfC.d.ts +17 -0
- package/dist/index.d.ts +21 -1
- package/dist/index.js +2 -2
- package/dist/{validation-ClXd_DAW.d.ts → payload-CL6tYBin.d.ts} +2 -40
- package/dist/prepare-KKQ2AEBW.js +24 -0
- package/dist/runtime/default-app.d.ts +6 -0
- package/dist/runtime/entry-client.d.ts +3 -0
- package/dist/runtime/entry-client.js +12 -4
- package/dist/runtime/entry-server.d.ts +8 -0
- package/dist/runtime/entry-server.js +2 -2
- package/dist/runtime/index.d.ts +7 -8
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/routes.d.ts +13 -0
- package/dist/runtime/silent-diagnostics.d.ts +5 -0
- package/dist/server/bun.d.ts +15 -0
- package/dist/server/bun.js +14 -11
- package/dist/server/index.d.ts +9 -90
- package/dist/server/index.js +2 -2
- package/dist/server/node.d.ts +20 -0
- package/dist/server/node.js +2 -2
- package/dist/{start-PARBW5KN.js → start-AJKNZRJQ.js} +11 -7
- package/dist/typecheck-QACZZ6FN.js +30 -0
- package/dist/types-B6rQOOxS.d.ts +76 -0
- package/dist/validation-Dwpex2JZ.d.ts +40 -0
- package/package.json +22 -6
- package/dist/chunk-KGZP2RCF.js +0 -51
- package/dist/devtools-KTDSD5PR.js +0 -564
package/README.md
CHANGED
|
@@ -29,15 +29,31 @@ bun add noofpi doofpi
|
|
|
29
29
|
|
|
30
30
|
Requires Node.js 20 or newer (or Bun). `doofpi` is a peer dependency (`>=1.3.1`).
|
|
31
31
|
|
|
32
|
+
`tailwindcss`, `@tailwindcss/vite` and `sharp` are optional peer dependencies, install them when you use the feature:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
bun add tailwindcss @tailwindcss/vite # tailwind: true
|
|
36
|
+
bun add sharp # importing images with ?image
|
|
37
|
+
```
|
|
38
|
+
|
|
32
39
|
## CLI
|
|
33
40
|
|
|
34
41
|
```
|
|
35
|
-
noofpi dev
|
|
36
|
-
noofpi build
|
|
37
|
-
noofpi start
|
|
42
|
+
noofpi dev Start the dev server with live reload
|
|
43
|
+
noofpi build Build for production into .output/
|
|
44
|
+
noofpi start Run the production build
|
|
45
|
+
noofpi preview Build, then run the production build
|
|
46
|
+
noofpi prepare Generate the .noofpi/ type declarations
|
|
47
|
+
noofpi typecheck Run prepare, then vue-tsc --noEmit
|
|
38
48
|
```
|
|
39
49
|
|
|
40
|
-
Options: `--root <dir>`, `--port <port>`, `--host <host>`, `--preset <name
|
|
50
|
+
Options: `--root <dir>`, `--port <port>`, `--host <host>`, `--open`, `--preset <name>`, `-h, --help` and `-v, --version`. Options accept `--port 3000` and `--port=3000`.
|
|
51
|
+
|
|
52
|
+
`noofpi prepare` writes the `.noofpi/*.d.ts` files without starting a server, so editor types work right after install. Run it from a `postinstall` script: `"postinstall": "noofpi prepare"`.
|
|
53
|
+
|
|
54
|
+
`noofpi typecheck` needs `vue-tsc` and `typescript` in the project. Arguments after `--` go to vue-tsc: `noofpi typecheck -- --project tsconfig.app.json`.
|
|
55
|
+
|
|
56
|
+
`noofpi preview` works with the `node`, `bun` and `docker` presets.
|
|
41
57
|
|
|
42
58
|
## Documentation
|
|
43
59
|
|
|
@@ -3,14 +3,15 @@ import {
|
|
|
3
3
|
createViteConfig,
|
|
4
4
|
finishPresetBuild,
|
|
5
5
|
resolveFonts
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-LL3NO5EI.js";
|
|
7
|
+
import "./chunk-IE3WF5XF.js";
|
|
8
8
|
import "./chunk-MTXQR32N.js";
|
|
9
|
+
import "./chunk-PPUFFGCH.js";
|
|
9
10
|
import "./chunk-ELXCFUA4.js";
|
|
10
11
|
import "./chunk-G35DW4NA.js";
|
|
11
12
|
import {
|
|
12
13
|
usesFetchMode
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-MN5PVHC5.js";
|
|
14
15
|
import "./chunk-Y3NBZ6DW.js";
|
|
15
16
|
|
|
16
17
|
// src/vite/build.ts
|
|
@@ -18,7 +19,7 @@ import { rm } from "fs/promises";
|
|
|
18
19
|
import path from "path";
|
|
19
20
|
import { build } from "vite";
|
|
20
21
|
async function buildApp(root, resolved, preset = resolved.build.preset) {
|
|
21
|
-
const config = { ...resolved, build: { preset } };
|
|
22
|
+
const config = { ...resolved, build: { ...resolved.build, preset } };
|
|
22
23
|
const isStatic = preset === "github-pages";
|
|
23
24
|
if (isStatic) {
|
|
24
25
|
const { fetch } = config.doofpi;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/dev-errors.ts
|
|
2
|
+
var DEV_ERRORS_ELEMENT_ID = "__noofpi_dev_errors__";
|
|
3
|
+
function toDevError(value, source, info) {
|
|
4
|
+
const error = value;
|
|
5
|
+
const isObject = typeof value === "object" && value !== null;
|
|
6
|
+
return {
|
|
7
|
+
source,
|
|
8
|
+
name: isObject && typeof error.name === "string" ? error.name : "Error",
|
|
9
|
+
message: isObject && typeof error.message === "string" ? error.message : String(value),
|
|
10
|
+
...isObject && typeof error.stack === "string" ? { stack: error.stack } : {},
|
|
11
|
+
...info ? { info } : {}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function serializeDevErrors(errors) {
|
|
15
|
+
const json = JSON.stringify(errors).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
16
|
+
return `<script type="application/json" id="${DEV_ERRORS_ELEMENT_ID}">${json}</script>`;
|
|
17
|
+
}
|
|
18
|
+
function parseDevErrors(text) {
|
|
19
|
+
try {
|
|
20
|
+
const parsed = JSON.parse(text);
|
|
21
|
+
if (!Array.isArray(parsed)) return [];
|
|
22
|
+
return parsed.filter(
|
|
23
|
+
(entry) => typeof entry === "object" && entry !== null && typeof entry.message === "string"
|
|
24
|
+
).map((entry) => toDevError(entry, "server", entry.info));
|
|
25
|
+
} catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var escapeHtml = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
30
|
+
function devErrorPage(errors) {
|
|
31
|
+
const items = errors.map(
|
|
32
|
+
(error) => `<section><h2>${escapeHtml(error.name)}</h2><p class="message">${escapeHtml(error.message)}</p>${error.stack ? `<pre>${escapeHtml(error.stack)}</pre>` : ""}</section>`
|
|
33
|
+
).join("");
|
|
34
|
+
return `<!doctype html>
|
|
35
|
+
<html lang="en">
|
|
36
|
+
<head>
|
|
37
|
+
<meta charset="utf-8">
|
|
38
|
+
<title>Server error \xB7 noofpi</title>
|
|
39
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
40
|
+
<style>
|
|
41
|
+
body{margin:0;padding:32px;background:#18181b;color:#e4e4e7;font:14px/1.6 ui-sans-serif,system-ui,sans-serif}
|
|
42
|
+
main{max-width:960px;margin:0 auto}
|
|
43
|
+
h1{margin:0 0 4px;font-size:20px;color:#f87171}
|
|
44
|
+
.hint{margin:0 0 24px;color:#a1a1aa}
|
|
45
|
+
section{margin:0 0 16px;padding:16px;border:1px solid rgba(248,113,113,.4);border-radius:12px;background:rgba(248,113,113,.06)}
|
|
46
|
+
h2{margin:0;font-size:12px;letter-spacing:.1em;text-transform:uppercase;color:#fca5a5}
|
|
47
|
+
.message{margin:6px 0 12px;font:600 16px/1.4 ui-monospace,Consolas,monospace;word-break:break-word}
|
|
48
|
+
pre{margin:0;overflow:auto;padding:12px;border-radius:8px;background:rgba(0,0,0,.35);font:12px/1.6 ui-monospace,Consolas,monospace;white-space:pre-wrap;word-break:break-all}
|
|
49
|
+
</style>
|
|
50
|
+
</head>
|
|
51
|
+
<body>
|
|
52
|
+
<main>
|
|
53
|
+
<h1>Server error</h1>
|
|
54
|
+
<p class="hint">The server failed to render this page. Only shown by <code>noofpi dev</code>; production responds with a plain 500.</p>
|
|
55
|
+
${items}
|
|
56
|
+
</main>
|
|
57
|
+
</body>
|
|
58
|
+
</html>
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
DEV_ERRORS_ELEMENT_ID,
|
|
64
|
+
toDevError,
|
|
65
|
+
serializeDevErrors,
|
|
66
|
+
parseDevErrors,
|
|
67
|
+
devErrorPage
|
|
68
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveStaticFile
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PPUFFGCH.js";
|
|
4
4
|
|
|
5
5
|
// src/server/node.ts
|
|
6
6
|
import { createReadStream } from "fs";
|
|
@@ -37,6 +37,10 @@ async function sendWebResponse(res, response) {
|
|
|
37
37
|
res.end();
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
+
if (res.destroyed) {
|
|
41
|
+
await response.body.cancel().catch(ignoreStreamError);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
40
44
|
pipeline(
|
|
41
45
|
Readable.fromWeb(response.body),
|
|
42
46
|
res,
|
|
@@ -49,14 +53,18 @@ async function serveStatic(dir, req, res) {
|
|
|
49
53
|
const found = await resolveStaticFile(
|
|
50
54
|
dir,
|
|
51
55
|
req.method ?? "GET",
|
|
52
|
-
req.url ?? "/"
|
|
56
|
+
req.url ?? "/",
|
|
57
|
+
req.headers
|
|
53
58
|
);
|
|
54
59
|
if (!found) return false;
|
|
60
|
+
res.statusCode = found.status;
|
|
55
61
|
for (const [name, value] of Object.entries(found.headers))
|
|
56
62
|
res.setHeader(name, value);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
if (req.method === "HEAD" || !found.body || res.destroyed) res.end();
|
|
64
|
+
else {
|
|
65
|
+
const { file, start, end } = found.body;
|
|
66
|
+
pipeline(createReadStream(file, { start, end }), res, ignoreStreamError);
|
|
67
|
+
}
|
|
60
68
|
return true;
|
|
61
69
|
}
|
|
62
70
|
function createNodeServer(options) {
|
|
@@ -3,11 +3,12 @@ import {
|
|
|
3
3
|
} from "./chunk-ELXCFUA4.js";
|
|
4
4
|
import {
|
|
5
5
|
FETCH_MODES,
|
|
6
|
+
matchesRoutePattern,
|
|
6
7
|
resolveSecurity,
|
|
7
8
|
toPublicRouteRules,
|
|
8
9
|
usesFetchMode,
|
|
9
10
|
validateRouteRules
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-MN5PVHC5.js";
|
|
11
12
|
|
|
12
13
|
// src/build-preset.ts
|
|
13
14
|
var BUILD_PRESETS = [
|
|
@@ -184,6 +185,71 @@ function variantWidths(imageWidth, widths) {
|
|
|
184
185
|
return [...widths.filter((width) => width < imageWidth), imageWidth];
|
|
185
186
|
}
|
|
186
187
|
|
|
188
|
+
// src/seo.ts
|
|
189
|
+
function resolveSeo(input = {}) {
|
|
190
|
+
let siteUrl;
|
|
191
|
+
if (input.siteUrl !== void 0) {
|
|
192
|
+
try {
|
|
193
|
+
const parsed = new URL(input.siteUrl);
|
|
194
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
195
|
+
throw new Error();
|
|
196
|
+
siteUrl = (parsed.origin + parsed.pathname).replace(/\/+$/, "");
|
|
197
|
+
} catch {
|
|
198
|
+
throw new Error(
|
|
199
|
+
`[noofpi] seo.siteUrl must be an absolute http(s) URL (got "${input.siteUrl}")`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (input.sitemap === true && !siteUrl)
|
|
204
|
+
throw new Error(
|
|
205
|
+
"[noofpi] seo.sitemap needs seo.siteUrl (sitemap URLs are absolute)"
|
|
206
|
+
);
|
|
207
|
+
const exclude = input.exclude ?? [];
|
|
208
|
+
for (const pattern of exclude)
|
|
209
|
+
if (typeof pattern !== "string" || !pattern.startsWith("/"))
|
|
210
|
+
throw new Error(
|
|
211
|
+
`[noofpi] seo.exclude patterns must start with "/" (got "${String(pattern)}")`
|
|
212
|
+
);
|
|
213
|
+
return {
|
|
214
|
+
siteUrl,
|
|
215
|
+
sitemap: input.sitemap ?? siteUrl !== void 0,
|
|
216
|
+
robots: input.robots ?? true,
|
|
217
|
+
exclude
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function sitemapRoutes(routes, exclude) {
|
|
221
|
+
return [...new Set(routes)].filter(
|
|
222
|
+
(route) => !route.includes(":") && !exclude.some((pattern) => matchesRoutePattern(pattern, route))
|
|
223
|
+
).sort();
|
|
224
|
+
}
|
|
225
|
+
var escapeXml = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
226
|
+
function sitemapXml(siteUrl, routes) {
|
|
227
|
+
const urls = routes.map(
|
|
228
|
+
(route) => ` <url><loc>${escapeXml(siteUrl + (route === "/" ? "/" : route))}</loc></url>`
|
|
229
|
+
);
|
|
230
|
+
return [
|
|
231
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
232
|
+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
233
|
+
...urls,
|
|
234
|
+
"</urlset>",
|
|
235
|
+
""
|
|
236
|
+
].join("\n");
|
|
237
|
+
}
|
|
238
|
+
function robotsTxt(seo) {
|
|
239
|
+
const lines = ["User-agent: *"];
|
|
240
|
+
if (!seo.exclude.length) lines.push("Allow: /");
|
|
241
|
+
for (const pattern of seo.exclude) {
|
|
242
|
+
if (pattern.endsWith("/**")) {
|
|
243
|
+
const base = pattern.slice(0, -3);
|
|
244
|
+
lines.push(`Disallow: ${base}/`);
|
|
245
|
+
if (base) lines.push(`Disallow: ${base}$`);
|
|
246
|
+
} else lines.push(`Disallow: ${pattern}$`);
|
|
247
|
+
}
|
|
248
|
+
if (seo.sitemap && seo.siteUrl)
|
|
249
|
+
lines.push("", `Sitemap: ${seo.siteUrl}/sitemap.xml`);
|
|
250
|
+
return lines.join("\n") + "\n";
|
|
251
|
+
}
|
|
252
|
+
|
|
187
253
|
// src/config.ts
|
|
188
254
|
function defineNoofpiConfig(config) {
|
|
189
255
|
return config;
|
|
@@ -234,6 +300,16 @@ function resolveConfig(input = {}) {
|
|
|
234
300
|
input.build?.preset ?? "node",
|
|
235
301
|
"build.preset"
|
|
236
302
|
);
|
|
303
|
+
const image = input.build?.docker?.image;
|
|
304
|
+
if (image !== void 0 && !/^\S+$/.test(image.trim()))
|
|
305
|
+
throw new Error(
|
|
306
|
+
`[noofpi] build.docker.image must be an image name without spaces (got "${image}")`
|
|
307
|
+
);
|
|
308
|
+
const healthcheck = input.build?.docker?.healthcheck ?? "/";
|
|
309
|
+
if (healthcheck !== false && (typeof healthcheck !== "string" || !healthcheck.startsWith("/") || healthcheck.startsWith("//") || /[\s"'\\$`]/.test(healthcheck)))
|
|
310
|
+
throw new Error(
|
|
311
|
+
`[noofpi] build.docker.healthcheck must be a path starting with "/" (without spaces or quotes) or false (got "${String(healthcheck)}")`
|
|
312
|
+
);
|
|
237
313
|
return {
|
|
238
314
|
ssr,
|
|
239
315
|
routeRules,
|
|
@@ -245,12 +321,13 @@ function resolveConfig(input = {}) {
|
|
|
245
321
|
images: resolveImages(input.images),
|
|
246
322
|
security,
|
|
247
323
|
i18n: resolveI18n(input.i18n),
|
|
324
|
+
seo: resolveSeo(input.seo),
|
|
248
325
|
doofpi: { fetch: mode, url, root },
|
|
249
326
|
devServer: {
|
|
250
327
|
port: input.devServer?.port ?? 3e3,
|
|
251
328
|
host: input.devServer?.host ?? "localhost"
|
|
252
329
|
},
|
|
253
|
-
build: { preset },
|
|
330
|
+
build: { preset, docker: { image: image?.trim(), healthcheck } },
|
|
254
331
|
devtools: input.devtools ?? true,
|
|
255
332
|
vite: input.vite ?? {}
|
|
256
333
|
};
|
|
@@ -277,6 +354,9 @@ export {
|
|
|
277
354
|
assertBuildPreset,
|
|
278
355
|
FONT_PROVIDERS,
|
|
279
356
|
variantWidths,
|
|
357
|
+
sitemapRoutes,
|
|
358
|
+
sitemapXml,
|
|
359
|
+
robotsTxt,
|
|
280
360
|
defineNoofpiConfig,
|
|
281
361
|
resolveConfig,
|
|
282
362
|
toPublicConfig,
|