noofpi 2.0.1 → 3.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 +6 -2
- package/client.d.ts +2 -0
- package/dist/build-W5VMPOTQ.js +212 -0
- package/dist/chunk-A7XQWIA6.js +562 -0
- package/dist/chunk-GOJZ36X5.js +217 -0
- package/dist/{chunk-YJVMBHNL.js → chunk-JUVQEKLE.js} +43 -12
- package/dist/chunk-LJEKK4AK.js +51 -0
- package/dist/{chunk-G35DW4NA.js → chunk-PC3ZJN4D.js} +11 -1
- package/dist/{chunk-NHBXVKEQ.js → chunk-ROMSHDCI.js} +160 -86
- package/dist/{chunk-IE3WF5XF.js → chunk-SUECMRBX.js} +87 -4
- package/dist/{chunk-MN5PVHC5.js → chunk-W7ASRDAJ.js} +229 -7
- package/dist/cli.js +21 -9
- package/dist/{dev-OAGCOGHA.js → dev-2DM7VOYX.js} +7 -6
- package/dist/{devtools-PLUN2DYV.js → devtools-C3PFU57C.js} +1 -1
- package/dist/handler-BpyI3a5D.d.ts +26 -0
- package/dist/index.d.ts +26 -11
- package/dist/index.js +3 -2
- package/dist/payload-Cgul9YUP.d.ts +66 -0
- package/dist/{prepare-BN7NMCVQ.js → prepare-APN2E6PX.js} +6 -5
- package/dist/runtime/entry-client.js +4 -4
- package/dist/runtime/entry-server.d.ts +6 -4
- package/dist/runtime/entry-server.js +88 -25
- package/dist/runtime/index.d.ts +24 -6
- package/dist/runtime/index.js +5 -3
- package/dist/server/bun.d.ts +3 -3
- package/dist/server/index.d.ts +35 -7
- package/dist/server/index.js +12 -7
- package/dist/server/node.d.ts +3 -3
- package/dist/session-CAP_PIlN.d.ts +272 -0
- package/dist/{start-ITRND3BY.js → start-PXOLWPL4.js} +7 -6
- package/dist/{types-B6rQOOxS.d.ts → types-B7xDyUbg.d.ts} +30 -5
- package/package.json +6 -1
- package/dist/build-WPHZ7TYZ.js +0 -49
- package/dist/chunk-MTXQR32N.js +0 -8
- package/dist/chunk-X3DYEZLK.js +0 -253
- package/dist/handler-C6NnwBfC.d.ts +0 -17
- package/dist/payload-CL6tYBin.d.ts +0 -121
- package/dist/route-rules-COilNsVT.d.ts +0 -127
|
@@ -6,17 +6,24 @@ import {
|
|
|
6
6
|
toPublicConfig,
|
|
7
7
|
toServerConfig,
|
|
8
8
|
variantWidths
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-SUECMRBX.js";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
} from "./chunk-
|
|
11
|
+
cacheControl
|
|
12
|
+
} from "./chunk-LJEKK4AK.js";
|
|
13
|
+
import {
|
|
14
|
+
importOptional
|
|
15
|
+
} from "./chunk-GOJZ36X5.js";
|
|
13
16
|
import {
|
|
14
17
|
COMPRESSIBLE_EXTENSIONS
|
|
15
18
|
} from "./chunk-PPUFFGCH.js";
|
|
16
19
|
import {
|
|
20
|
+
SSR_OUTLET,
|
|
17
21
|
applyHead,
|
|
18
22
|
resolveHead
|
|
19
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-PC3ZJN4D.js";
|
|
24
|
+
import {
|
|
25
|
+
REDIRECT_STATUSES
|
|
26
|
+
} from "./chunk-W7ASRDAJ.js";
|
|
20
27
|
import {
|
|
21
28
|
filePathToRoute
|
|
22
29
|
} from "./chunk-Y3NBZ6DW.js";
|
|
@@ -303,10 +310,115 @@ function htmlTemplate(entry, stylesheets = []) {
|
|
|
303
310
|
`;
|
|
304
311
|
}
|
|
305
312
|
|
|
313
|
+
// src/vite/layouts.ts
|
|
314
|
+
import { existsSync as existsSync3, readdirSync, readFileSync } from "fs";
|
|
315
|
+
import path7 from "path";
|
|
316
|
+
var USE_LAYOUT = /\buseLayout\(\s*(?:(['"`])([^'"`$\n]+)\1|(false))\s*\)/;
|
|
317
|
+
function extractLayout(source) {
|
|
318
|
+
const match = USE_LAYOUT.exec(source);
|
|
319
|
+
if (!match) return void 0;
|
|
320
|
+
return match[3] ? false : match[2];
|
|
321
|
+
}
|
|
322
|
+
function scanPages(root, extract) {
|
|
323
|
+
const pagesDir = path7.join(root, "app/pages");
|
|
324
|
+
const result = {};
|
|
325
|
+
const walk = (dir) => {
|
|
326
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
327
|
+
const full = path7.join(dir, entry.name);
|
|
328
|
+
if (entry.isDirectory()) walk(full);
|
|
329
|
+
else if (entry.name.endsWith(".vue")) {
|
|
330
|
+
let value;
|
|
331
|
+
try {
|
|
332
|
+
value = extract(readFileSync(full, "utf-8"));
|
|
333
|
+
} catch (error) {
|
|
334
|
+
throw new Error(
|
|
335
|
+
`[noofpi] ${path7.relative(root, full)}: ${error.message}`
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
if (value !== void 0)
|
|
339
|
+
result["/" + path7.relative(root, full).split(path7.sep).join("/")] = value;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
if (existsSync3(pagesDir)) walk(pagesDir);
|
|
344
|
+
return result;
|
|
345
|
+
}
|
|
346
|
+
function scanPageLayouts(root) {
|
|
347
|
+
return scanPages(root, extractLayout);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// src/vite/static-files.ts
|
|
351
|
+
function cloudflarePaths(pattern) {
|
|
352
|
+
if (pattern.endsWith("/**")) {
|
|
353
|
+
const base = pattern.slice(0, -3);
|
|
354
|
+
if (base.includes("*")) return void 0;
|
|
355
|
+
return base ? [base, `${base}/*`] : ["/*"];
|
|
356
|
+
}
|
|
357
|
+
return pattern.includes("*") ? void 0 : [pattern];
|
|
358
|
+
}
|
|
359
|
+
function unsupportedStaticRules(config, preset) {
|
|
360
|
+
const unsupported = [];
|
|
361
|
+
for (const [pattern, rule] of Object.entries(config.routeRules)) {
|
|
362
|
+
const names = ["headers", "redirect", "cache"].filter(
|
|
363
|
+
(name) => rule[name] !== void 0 && rule[name] !== false
|
|
364
|
+
);
|
|
365
|
+
const cors = rule.cors !== void 0 && rule.cors !== false;
|
|
366
|
+
if (preset === "cloudflare-pages") {
|
|
367
|
+
if (!cloudflarePaths(pattern)) {
|
|
368
|
+
for (const name of cors ? [...names, "cors"] : names)
|
|
369
|
+
unsupported.push(`${pattern}: ${name} (pattern not supported)`);
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (cors) unsupported.push(`${pattern}: cors`);
|
|
373
|
+
} else
|
|
374
|
+
for (const name of cors ? [...names, "cors"] : names)
|
|
375
|
+
unsupported.push(`${pattern}: ${name}`);
|
|
376
|
+
}
|
|
377
|
+
return unsupported;
|
|
378
|
+
}
|
|
379
|
+
function headerBlocks(config) {
|
|
380
|
+
const blocks = [];
|
|
381
|
+
if (Object.keys(config.security.headers).length)
|
|
382
|
+
blocks.push({ path: "/*", headers: config.security.headers });
|
|
383
|
+
for (const [pattern, rule] of Object.entries(config.routeRules)) {
|
|
384
|
+
const paths = cloudflarePaths(pattern);
|
|
385
|
+
const headers = {
|
|
386
|
+
...rule.cache ? { "Cache-Control": cacheControl(rule.cache) } : {},
|
|
387
|
+
...rule.headers
|
|
388
|
+
};
|
|
389
|
+
if (!paths || !Object.keys(headers).length) continue;
|
|
390
|
+
for (const path16 of paths) blocks.push({ path: path16, headers });
|
|
391
|
+
}
|
|
392
|
+
return blocks;
|
|
393
|
+
}
|
|
394
|
+
function headersFile(config) {
|
|
395
|
+
return headerBlocks(config).map(
|
|
396
|
+
({ path: path16, headers }) => `${path16}
|
|
397
|
+
${Object.entries(headers).map(([name, value]) => ` ${name}: ${value}`).join("\n")}
|
|
398
|
+
`
|
|
399
|
+
).join("\n");
|
|
400
|
+
}
|
|
401
|
+
function redirectsFile(config) {
|
|
402
|
+
const lines = [];
|
|
403
|
+
for (const [pattern, rule] of Object.entries(config.routeRules)) {
|
|
404
|
+
const redirect = rule.redirect;
|
|
405
|
+
const paths = redirect === void 0 ? void 0 : cloudflarePaths(pattern);
|
|
406
|
+
if (redirect === void 0 || !paths) continue;
|
|
407
|
+
const { to, status } = typeof redirect === "string" ? { to: redirect, status: 307 } : { to: redirect.to, status: redirect.status ?? 307 };
|
|
408
|
+
if (!REDIRECT_STATUSES.includes(status)) continue;
|
|
409
|
+
const splat = to.endsWith("/**");
|
|
410
|
+
for (const path16 of paths) {
|
|
411
|
+
const target = splat ? path16.endsWith("/*") ? `${to.slice(0, -3)}/:splat` : to.slice(0, -3) || "/" : to;
|
|
412
|
+
lines.push(`${path16} ${target} ${status}`);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return lines.length ? lines.join("\n") + "\n" : "";
|
|
416
|
+
}
|
|
417
|
+
|
|
306
418
|
// src/vite/platform.ts
|
|
307
|
-
import { existsSync as
|
|
419
|
+
import { existsSync as existsSync4 } from "fs";
|
|
308
420
|
import { createRequire } from "module";
|
|
309
|
-
import
|
|
421
|
+
import path8 from "path";
|
|
310
422
|
import { pathToFileURL } from "url";
|
|
311
423
|
var WRANGLER_CONFIGS = [
|
|
312
424
|
"wrangler.json",
|
|
@@ -317,7 +429,7 @@ async function startPlatformProxy(root, config) {
|
|
|
317
429
|
if (!isCloudflarePreset(config.build.preset)) return void 0;
|
|
318
430
|
let entry;
|
|
319
431
|
try {
|
|
320
|
-
entry = createRequire(
|
|
432
|
+
entry = createRequire(path8.join(root, "package.json")).resolve("wrangler");
|
|
321
433
|
} catch {
|
|
322
434
|
console.warn(
|
|
323
435
|
"[noofpi] Cloudflare bindings are not available in dev: install wrangler (`wrangler` devDependency)"
|
|
@@ -325,8 +437,8 @@ async function startPlatformProxy(root, config) {
|
|
|
325
437
|
return void 0;
|
|
326
438
|
}
|
|
327
439
|
const { getPlatformProxy } = await import(pathToFileURL(entry).href);
|
|
328
|
-
const configPath = WRANGLER_CONFIGS.map((file) =>
|
|
329
|
-
|
|
440
|
+
const configPath = WRANGLER_CONFIGS.map((file) => path8.join(root, file)).find(
|
|
441
|
+
existsSync4
|
|
330
442
|
);
|
|
331
443
|
return getPlatformProxy({ configPath });
|
|
332
444
|
}
|
|
@@ -338,7 +450,7 @@ import path11 from "path";
|
|
|
338
450
|
|
|
339
451
|
// src/vite/compress.ts
|
|
340
452
|
import { readdir, readFile as readFile2, writeFile as writeFile3 } from "fs/promises";
|
|
341
|
-
import
|
|
453
|
+
import path9 from "path";
|
|
342
454
|
import { promisify } from "util";
|
|
343
455
|
import { brotliCompress, constants, gzip } from "zlib";
|
|
344
456
|
var brotli = promisify(brotliCompress);
|
|
@@ -347,7 +459,7 @@ var MIN_SIZE = 1024;
|
|
|
347
459
|
async function listFiles(dir) {
|
|
348
460
|
const files = [];
|
|
349
461
|
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
350
|
-
const full =
|
|
462
|
+
const full = path9.join(dir, entry.name);
|
|
351
463
|
if (entry.isDirectory()) files.push(...await listFiles(full));
|
|
352
464
|
else if (entry.isFile()) files.push(full);
|
|
353
465
|
}
|
|
@@ -355,8 +467,8 @@ async function listFiles(dir) {
|
|
|
355
467
|
}
|
|
356
468
|
async function precompressDir(dir) {
|
|
357
469
|
const files = (await listFiles(dir)).filter(
|
|
358
|
-
(file) => COMPRESSIBLE_EXTENSIONS.has(
|
|
359
|
-
|
|
470
|
+
(file) => COMPRESSIBLE_EXTENSIONS.has(path9.extname(file).toLowerCase()) && // The shell is inlined in the server bundle and never served as a file
|
|
471
|
+
path9.basename(file) !== "index.html"
|
|
360
472
|
);
|
|
361
473
|
await Promise.all(
|
|
362
474
|
files.map(async (file) => {
|
|
@@ -418,43 +530,6 @@ function dockerfile(options) {
|
|
|
418
530
|
].join("\n");
|
|
419
531
|
}
|
|
420
532
|
|
|
421
|
-
// src/vite/layouts.ts
|
|
422
|
-
import { existsSync as existsSync4, readdirSync, readFileSync } from "fs";
|
|
423
|
-
import path9 from "path";
|
|
424
|
-
var USE_LAYOUT = /\buseLayout\(\s*(?:(['"`])([^'"`$\n]+)\1|(false))\s*\)/;
|
|
425
|
-
function extractLayout(source) {
|
|
426
|
-
const match = USE_LAYOUT.exec(source);
|
|
427
|
-
if (!match) return void 0;
|
|
428
|
-
return match[3] ? false : match[2];
|
|
429
|
-
}
|
|
430
|
-
function scanPages(root, extract) {
|
|
431
|
-
const pagesDir = path9.join(root, "app/pages");
|
|
432
|
-
const result = {};
|
|
433
|
-
const walk = (dir) => {
|
|
434
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
435
|
-
const full = path9.join(dir, entry.name);
|
|
436
|
-
if (entry.isDirectory()) walk(full);
|
|
437
|
-
else if (entry.name.endsWith(".vue")) {
|
|
438
|
-
let value;
|
|
439
|
-
try {
|
|
440
|
-
value = extract(readFileSync(full, "utf-8"));
|
|
441
|
-
} catch (error) {
|
|
442
|
-
throw new Error(
|
|
443
|
-
`[noofpi] ${path9.relative(root, full)}: ${error.message}`
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
if (value !== void 0)
|
|
447
|
-
result["/" + path9.relative(root, full).split(path9.sep).join("/")] = value;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
if (existsSync4(pagesDir)) walk(pagesDir);
|
|
452
|
-
return result;
|
|
453
|
-
}
|
|
454
|
-
function scanPageLayouts(root) {
|
|
455
|
-
return scanPages(root, extractLayout);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
533
|
// src/vite/wrangler.ts
|
|
459
534
|
import { existsSync as existsSync5, readFileSync as readFileSync2 } from "fs";
|
|
460
535
|
import path10 from "path";
|
|
@@ -547,6 +622,7 @@ function presetEntryCode(preset, config) {
|
|
|
547
622
|
const { port } = config.devServer;
|
|
548
623
|
switch (preset) {
|
|
549
624
|
case "bun":
|
|
625
|
+
case "docker-bun":
|
|
550
626
|
return [
|
|
551
627
|
`import { fileURLToPath } from 'node:url';`,
|
|
552
628
|
`import { serveBun } from 'noofpi/server/bun';`,
|
|
@@ -558,7 +634,7 @@ function presetEntryCode(preset, config) {
|
|
|
558
634
|
case "cloudflare-worker":
|
|
559
635
|
return [
|
|
560
636
|
HANDLER,
|
|
561
|
-
`export default { fetch: (request, env) => handler(request, env) };`
|
|
637
|
+
`export default { fetch: (request, env, ctx) => handler(request, env, ctx) };`
|
|
562
638
|
].join("\n");
|
|
563
639
|
case "cloudflare-pages":
|
|
564
640
|
return [
|
|
@@ -568,7 +644,7 @@ function presetEntryCode(preset, config) {
|
|
|
568
644
|
`const apiRoot = mod.config.doofpi.root;`,
|
|
569
645
|
`const isApiPath = (pathname) => pathname.startsWith('/_noofpi/') || pathname === apiRoot || pathname.startsWith(apiRoot + '.') || pathname.startsWith(apiRoot + '/');`,
|
|
570
646
|
`const isFile = (request) => { const { pathname } = new URL(request.url); return (request.method === 'GET' || request.method === 'HEAD') && /\\.[a-z0-9]+$/i.test(pathname) && !isApiPath(pathname); };`,
|
|
571
|
-
`export default { fetch: (request, env) => isFile(request) && env.ASSETS ? env.ASSETS.fetch(request) : handler(request, env) };`
|
|
647
|
+
`export default { fetch: (request, env, ctx) => isFile(request) && env.ASSETS ? env.ASSETS.fetch(request) : handler(request, env, ctx) };`
|
|
572
648
|
].join("\n");
|
|
573
649
|
default:
|
|
574
650
|
return [
|
|
@@ -671,7 +747,16 @@ async function writeSeoFiles(root, config) {
|
|
|
671
747
|
}
|
|
672
748
|
if (seo.robots) await write("robots.txt", robotsTxt(seo));
|
|
673
749
|
}
|
|
674
|
-
async function
|
|
750
|
+
async function writeStaticShell(outDir, config) {
|
|
751
|
+
const index = path11.join(outDir, "public/index.html");
|
|
752
|
+
const html = applyHead(
|
|
753
|
+
readFileSync3(index, "utf-8"),
|
|
754
|
+
resolveHead(config.head)
|
|
755
|
+
).replace(SSR_OUTLET, () => "");
|
|
756
|
+
await writeFile4(index, html);
|
|
757
|
+
await writeFile4(path11.join(outDir, "public/404.html"), html);
|
|
758
|
+
}
|
|
759
|
+
async function finishPresetBuild(root, config, preset, options = {}) {
|
|
675
760
|
const outDir = path11.join(root, OUTPUT_DIR);
|
|
676
761
|
await writeSeoFiles(root, config);
|
|
677
762
|
const json = (value) => JSON.stringify(value, null, 2) + "\n";
|
|
@@ -686,6 +771,17 @@ async function finishPresetBuild(root, config, preset) {
|
|
|
686
771
|
);
|
|
687
772
|
return "deploy with `wrangler deploy -c .output/wrangler.json`";
|
|
688
773
|
case "cloudflare-pages":
|
|
774
|
+
if (options.generated) {
|
|
775
|
+
await writeStaticShell(outDir, config);
|
|
776
|
+
await writeFile4(
|
|
777
|
+
path11.join(outDir, "public/_headers"),
|
|
778
|
+
headersFile(config)
|
|
779
|
+
);
|
|
780
|
+
const redirects = redirectsFile(config);
|
|
781
|
+
if (redirects)
|
|
782
|
+
await writeFile4(path11.join(outDir, "public/_redirects"), redirects);
|
|
783
|
+
return "deploy with `wrangler pages deploy .output/public`";
|
|
784
|
+
}
|
|
689
785
|
await rm(path11.join(outDir, "public/index.html"), { force: true });
|
|
690
786
|
await writeFile4(
|
|
691
787
|
path11.join(outDir, "public/_routes.json"),
|
|
@@ -693,29 +789,20 @@ async function finishPresetBuild(root, config, preset) {
|
|
|
693
789
|
);
|
|
694
790
|
return "deploy with `wrangler pages deploy .output/public`";
|
|
695
791
|
case "github-pages": {
|
|
696
|
-
|
|
697
|
-
const html = applyHead(
|
|
698
|
-
readFileSync3(index, "utf-8"),
|
|
699
|
-
resolveHead(config.head)
|
|
700
|
-
).replace(SSR_OUTLET, () => "");
|
|
701
|
-
await writeFile4(index, html);
|
|
702
|
-
await writeFile4(path11.join(outDir, "public/404.html"), html);
|
|
792
|
+
await writeStaticShell(outDir, config);
|
|
703
793
|
await writeFile4(path11.join(outDir, "public/.nojekyll"), "");
|
|
704
794
|
return "publish `.output/public` to GitHub Pages (set `vite.base` to `/<repo>/` for project sites)";
|
|
705
795
|
}
|
|
706
|
-
case "docker":
|
|
796
|
+
case "docker-node":
|
|
797
|
+
case "docker-bun": {
|
|
798
|
+
const bun = preset === "docker-bun";
|
|
707
799
|
await precompressDir(path11.join(outDir, "public"));
|
|
708
800
|
await mkdir3(outDir, { recursive: true });
|
|
709
801
|
await writeFile4(
|
|
710
802
|
path11.join(outDir, "Dockerfile"),
|
|
711
803
|
dockerfile({
|
|
712
|
-
bun
|
|
713
|
-
lock: existsSync6(
|
|
714
|
-
path11.join(
|
|
715
|
-
root,
|
|
716
|
-
existsSync6(path11.join(root, "bun.lock")) ? "bun.lock" : "package-lock.json"
|
|
717
|
-
)
|
|
718
|
-
),
|
|
804
|
+
bun,
|
|
805
|
+
lock: bun ? existsSync6(path11.join(root, "bun.lock")) || existsSync6(path11.join(root, "bun.lockb")) : existsSync6(path11.join(root, "package-lock.json")),
|
|
719
806
|
port: config.devServer.port,
|
|
720
807
|
...config.build.docker
|
|
721
808
|
})
|
|
@@ -725,6 +812,7 @@ async function finishPresetBuild(root, config, preset) {
|
|
|
725
812
|
DOCKERIGNORE
|
|
726
813
|
);
|
|
727
814
|
return "build with `docker build -f .output/Dockerfile -t my-app .`";
|
|
815
|
+
}
|
|
728
816
|
case "bun":
|
|
729
817
|
await precompressDir(path11.join(outDir, "public"));
|
|
730
818
|
return "run with `bun .output/server/start.mjs`";
|
|
@@ -1007,7 +1095,7 @@ function noofpiPlugin(options) {
|
|
|
1007
1095
|
return [
|
|
1008
1096
|
userDoofpi ? `import userDoofpi from ${imp(userDoofpi)};` : "",
|
|
1009
1097
|
userProxy ? `import userProxyHook from ${imp(userProxy)};` : "",
|
|
1010
|
-
ssr ? `export { render } from 'noofpi/runtime/entry-server';` : "",
|
|
1098
|
+
ssr ? `export { render, renderStream } from 'noofpi/runtime/entry-server';` : "",
|
|
1011
1099
|
`export const config = ${JSON.stringify(toServerConfig(config))};`,
|
|
1012
1100
|
`export const doofpi = ${userDoofpi ? "userDoofpi" : "undefined"};`,
|
|
1013
1101
|
`export const proxyHook = ${userProxy ? "userProxyHook" : "undefined"};`,
|
|
@@ -1038,6 +1126,7 @@ var RUNTIME_IMPORTS = [
|
|
|
1038
1126
|
"useError",
|
|
1039
1127
|
"useCookie",
|
|
1040
1128
|
"useCookies",
|
|
1129
|
+
"useSession",
|
|
1041
1130
|
"useDoofpi",
|
|
1042
1131
|
"useDoofpiFetch",
|
|
1043
1132
|
"useDoofpiForm",
|
|
@@ -1089,23 +1178,6 @@ function autoImportPlugins() {
|
|
|
1089
1178
|
import { createHash as createHash2 } from "crypto";
|
|
1090
1179
|
import { readFile as readFile3 } from "fs/promises";
|
|
1091
1180
|
import path14 from "path";
|
|
1092
|
-
|
|
1093
|
-
// src/optional.ts
|
|
1094
|
-
async function importOptional(load, packages, feature) {
|
|
1095
|
-
try {
|
|
1096
|
-
return await load();
|
|
1097
|
-
} catch (error) {
|
|
1098
|
-
const { code, message } = error ?? {};
|
|
1099
|
-
if ((code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") && packages.some((name) => message?.includes(name)))
|
|
1100
|
-
throw new Error(
|
|
1101
|
-
`[noofpi] ${feature} needs ${packages.join(" and ")}: install ${packages.length > 1 ? "them" : "it"} with your package manager (for example \`bun add ${packages.join(" ")}\`)`,
|
|
1102
|
-
{ cause: error }
|
|
1103
|
-
);
|
|
1104
|
-
throw error;
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
// src/vite/images.ts
|
|
1109
1181
|
var IMAGE_QUERY = /^(.+\.(?:jpe?g|png|webp|avif))\?image$/i;
|
|
1110
1182
|
async function processImage(file, images, options) {
|
|
1111
1183
|
const { default: sharp } = await importOptional(
|
|
@@ -1236,6 +1308,8 @@ function createViteConfig(root, config, kind, fonts = NO_FONTS) {
|
|
|
1236
1308
|
export {
|
|
1237
1309
|
resolveFonts,
|
|
1238
1310
|
htmlTemplate,
|
|
1311
|
+
scanPages,
|
|
1312
|
+
unsupportedStaticRules,
|
|
1239
1313
|
startPlatformProxy,
|
|
1240
1314
|
OUTPUT_DIR,
|
|
1241
1315
|
finishPresetBuild,
|
|
@@ -1,20 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveSession
|
|
3
|
+
} from "./chunk-GOJZ36X5.js";
|
|
1
4
|
import {
|
|
2
5
|
resolveI18n
|
|
3
6
|
} from "./chunk-ELXCFUA4.js";
|
|
4
7
|
import {
|
|
5
8
|
FETCH_MODES,
|
|
9
|
+
isServerRendered,
|
|
10
|
+
matchRouteRules,
|
|
6
11
|
matchesRoutePattern,
|
|
7
12
|
resolveSecurity,
|
|
8
13
|
toPublicRouteRules,
|
|
9
14
|
usesFetchMode,
|
|
10
15
|
validateRouteRules
|
|
11
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-W7ASRDAJ.js";
|
|
12
17
|
|
|
13
18
|
// src/build-preset.ts
|
|
14
19
|
var BUILD_PRESETS = [
|
|
15
20
|
"node",
|
|
16
21
|
"bun",
|
|
17
|
-
"docker",
|
|
22
|
+
"docker-node",
|
|
23
|
+
"docker-bun",
|
|
18
24
|
"cloudflare-worker",
|
|
19
25
|
"cloudflare-pages",
|
|
20
26
|
"github-pages"
|
|
@@ -22,6 +28,16 @@ var BUILD_PRESETS = [
|
|
|
22
28
|
function isCloudflarePreset(preset) {
|
|
23
29
|
return preset === "cloudflare-worker" || preset === "cloudflare-pages";
|
|
24
30
|
}
|
|
31
|
+
var STATIC_PRESETS = ["github-pages", "cloudflare-pages"];
|
|
32
|
+
var isStaticPreset = (preset) => STATIC_PRESETS.includes(preset);
|
|
33
|
+
function generatePreset(requested, configured) {
|
|
34
|
+
const preset = requested ?? (isStaticPreset(configured) ? configured : "github-pages");
|
|
35
|
+
if (!isStaticPreset(preset))
|
|
36
|
+
throw new Error(
|
|
37
|
+
`[noofpi] noofpi generate writes static files, so its preset must be ${STATIC_PRESETS.join(" or ")} (got "${preset}")`
|
|
38
|
+
);
|
|
39
|
+
return preset;
|
|
40
|
+
}
|
|
25
41
|
function assertBuildPreset(value, source) {
|
|
26
42
|
if (!BUILD_PRESETS.includes(value)) {
|
|
27
43
|
throw new Error(
|
|
@@ -185,6 +201,61 @@ function variantWidths(imageWidth, widths) {
|
|
|
185
201
|
return [...widths.filter((width) => width < imageWidth), imageWidth];
|
|
186
202
|
}
|
|
187
203
|
|
|
204
|
+
// src/prerender.ts
|
|
205
|
+
var PATH = /^\/(?!\/)[^\s?#\\]*$/;
|
|
206
|
+
var normalizeRoute = (route) => route.length > 1 ? route.replace(/\/+$/, "") || "/" : route;
|
|
207
|
+
function resolvePrerender(input = {}) {
|
|
208
|
+
const routes = input.routes ?? [];
|
|
209
|
+
if (!Array.isArray(routes))
|
|
210
|
+
throw new Error("[noofpi] prerender.routes must be a list of URL paths");
|
|
211
|
+
for (const route of routes)
|
|
212
|
+
if (typeof route !== "string" || !PATH.test(route))
|
|
213
|
+
throw new Error(
|
|
214
|
+
`[noofpi] prerender.routes must be URL paths starting with "/", without a query or hash (got "${String(route)}")`
|
|
215
|
+
);
|
|
216
|
+
if (input.crawlLinks !== void 0 && typeof input.crawlLinks !== "boolean")
|
|
217
|
+
throw new Error("[noofpi] prerender.crawlLinks must be a boolean");
|
|
218
|
+
return {
|
|
219
|
+
routes: routes.map(normalizeRoute),
|
|
220
|
+
crawlLinks: input.crawlLinks ?? true
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function routeToFile(route) {
|
|
224
|
+
const path = normalizeRoute(route).replace(/^\/+/, "");
|
|
225
|
+
return path ? `${path}/index.html` : "index.html";
|
|
226
|
+
}
|
|
227
|
+
function planPrerender(options) {
|
|
228
|
+
const { pages, rules, ssr } = options;
|
|
229
|
+
const explicit = new Set(options.routes);
|
|
230
|
+
const marked = explicit.size > 0 || Object.values(rules).some((rule) => rule.prerender === true);
|
|
231
|
+
const accepts = (route) => {
|
|
232
|
+
if (!isServerRendered(ssr, rules, route)) return false;
|
|
233
|
+
if (explicit.has(normalizeRoute(route))) return true;
|
|
234
|
+
const { prerender } = matchRouteRules(rules, route);
|
|
235
|
+
return prerender === true || !marked && prerender !== false;
|
|
236
|
+
};
|
|
237
|
+
const seeds = [
|
|
238
|
+
.../* @__PURE__ */ new Set([
|
|
239
|
+
...pages.filter((page) => !page.includes(":")).map(normalizeRoute),
|
|
240
|
+
...explicit
|
|
241
|
+
])
|
|
242
|
+
].filter(accepts).sort();
|
|
243
|
+
return { marked, seeds, accepts };
|
|
244
|
+
}
|
|
245
|
+
var ANCHOR = /<a\s[^>]*?\bhref\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
|
|
246
|
+
var decodeEntities = (value) => value.replace(/&/g, "&").replace(/"/g, '"').replace(/�*39;|'/g, "'");
|
|
247
|
+
function extractLinks(html) {
|
|
248
|
+
const links = /* @__PURE__ */ new Set();
|
|
249
|
+
for (const match of html.matchAll(ANCHOR)) {
|
|
250
|
+
const href = decodeEntities(match[1] ?? match[2] ?? "").trim();
|
|
251
|
+
if (!href.startsWith("/") || href.startsWith("//")) continue;
|
|
252
|
+
const path = href.replace(/[?#].*$/, "");
|
|
253
|
+
if (!PATH.test(path) || /\.[a-z0-9]+$/i.test(path)) continue;
|
|
254
|
+
links.add(normalizeRoute(path));
|
|
255
|
+
}
|
|
256
|
+
return [...links];
|
|
257
|
+
}
|
|
258
|
+
|
|
188
259
|
// src/seo.ts
|
|
189
260
|
function resolveSeo(input = {}) {
|
|
190
261
|
let siteUrl;
|
|
@@ -269,6 +340,10 @@ function resolveConfig(input = {}) {
|
|
|
269
340
|
}
|
|
270
341
|
const routeRules = input.routeRules ?? {};
|
|
271
342
|
validateRouteRules(routeRules, ssr);
|
|
343
|
+
if (input.streaming !== void 0 && typeof input.streaming !== "boolean")
|
|
344
|
+
throw new Error("[noofpi] streaming must be a boolean");
|
|
345
|
+
if (input.streaming && !ssr)
|
|
346
|
+
throw new Error("[noofpi] streaming: true needs ssr: true");
|
|
272
347
|
let url = input.doofpi?.url;
|
|
273
348
|
const remoteRule = Object.entries(routeRules).find(
|
|
274
349
|
([, rule]) => rule.fetch !== void 0 && rule.fetch !== "lfetch"
|
|
@@ -312,7 +387,10 @@ function resolveConfig(input = {}) {
|
|
|
312
387
|
);
|
|
313
388
|
return {
|
|
314
389
|
ssr,
|
|
390
|
+
streaming: input.streaming ?? false,
|
|
315
391
|
routeRules,
|
|
392
|
+
prerender: resolvePrerender(input.prerender),
|
|
393
|
+
session: resolveSession(input.session),
|
|
316
394
|
head: input.head ?? {},
|
|
317
395
|
tailwind: input.tailwind ?? false,
|
|
318
396
|
autoImports: input.autoImports ?? true,
|
|
@@ -340,20 +418,25 @@ function toPublicConfig(config) {
|
|
|
340
418
|
routeRules: toPublicRouteRules(config.routeRules),
|
|
341
419
|
head: config.head,
|
|
342
420
|
doofpi: { fetch, url: direct ? url : void 0, root },
|
|
421
|
+
session: config.session !== void 0,
|
|
343
422
|
devtools: config.devtools
|
|
344
423
|
};
|
|
345
424
|
}
|
|
346
425
|
function toServerConfig(config) {
|
|
347
|
-
const { ssr, doofpi, routeRules, head, security } = config;
|
|
348
|
-
return { ssr, doofpi, routeRules, head, security };
|
|
426
|
+
const { ssr, streaming, doofpi, routeRules, head, security, session } = config;
|
|
427
|
+
return { ssr, streaming, doofpi, routeRules, head, security, session };
|
|
349
428
|
}
|
|
350
429
|
|
|
351
430
|
export {
|
|
352
431
|
BUILD_PRESETS,
|
|
353
432
|
isCloudflarePreset,
|
|
433
|
+
generatePreset,
|
|
354
434
|
assertBuildPreset,
|
|
355
435
|
FONT_PROVIDERS,
|
|
356
436
|
variantWidths,
|
|
437
|
+
routeToFile,
|
|
438
|
+
planPrerender,
|
|
439
|
+
extractLinks,
|
|
357
440
|
sitemapRoutes,
|
|
358
441
|
sitemapXml,
|
|
359
442
|
robotsTxt,
|