noofpi 1.1.2 → 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.
Files changed (42) hide show
  1. package/README.md +20 -4
  2. package/dist/{build-GGRF4JTM.js → build-PFCGDPPJ.js} +5 -4
  3. package/dist/chunk-3PSMWWUB.js +68 -0
  4. package/dist/{chunk-NALDZ3PS.js → chunk-I6TFIGFO.js} +13 -5
  5. package/dist/{chunk-NX6BO7UB.js → chunk-IE3WF5XF.js} +82 -2
  6. package/dist/{chunk-M7TMNIVH.js → chunk-LL3NO5EI.js} +367 -133
  7. package/dist/{chunk-FIJJ3EGL.js → chunk-MN5PVHC5.js} +4 -0
  8. package/dist/chunk-OKNF6XDO.js +14 -0
  9. package/dist/chunk-PPUFFGCH.js +168 -0
  10. package/dist/{chunk-WX2V6EYH.js → chunk-RUNIVVFH.js} +34 -10
  11. package/dist/{chunk-2XCZWFIQ.js → chunk-X3DYEZLK.js} +1 -1
  12. package/dist/{chunk-4YOOGEOF.js → chunk-YJVMBHNL.js} +1 -1
  13. package/dist/cli.js +130 -34
  14. package/dist/{dev-Y5IW7464.js → dev-HTWUY27O.js} +47 -59
  15. package/dist/devtools-PLUN2DYV.js +958 -0
  16. package/dist/handler-C6NnwBfC.d.ts +17 -0
  17. package/dist/index.d.ts +21 -1
  18. package/dist/index.js +2 -2
  19. package/dist/{validation-ClXd_DAW.d.ts → payload-CL6tYBin.d.ts} +2 -40
  20. package/dist/prepare-KKQ2AEBW.js +24 -0
  21. package/dist/runtime/default-app.d.ts +6 -0
  22. package/dist/runtime/entry-client.d.ts +3 -0
  23. package/dist/runtime/entry-client.js +12 -4
  24. package/dist/runtime/entry-server.d.ts +8 -0
  25. package/dist/runtime/entry-server.js +2 -2
  26. package/dist/runtime/index.d.ts +55 -18
  27. package/dist/runtime/index.js +2 -2
  28. package/dist/runtime/routes.d.ts +13 -0
  29. package/dist/runtime/silent-diagnostics.d.ts +5 -0
  30. package/dist/server/bun.d.ts +15 -0
  31. package/dist/server/bun.js +14 -11
  32. package/dist/server/index.d.ts +9 -90
  33. package/dist/server/index.js +2 -2
  34. package/dist/server/node.d.ts +20 -0
  35. package/dist/server/node.js +2 -2
  36. package/dist/{start-IK3X6V3N.js → start-AJKNZRJQ.js} +11 -7
  37. package/dist/typecheck-QACZZ6FN.js +30 -0
  38. package/dist/types-B6rQOOxS.d.ts +76 -0
  39. package/dist/validation-Dwpex2JZ.d.ts +40 -0
  40. package/package.json +22 -6
  41. package/dist/chunk-KGZP2RCF.js +0 -51
  42. package/dist/devtools-KTDSD5PR.js +0 -564
@@ -1,11 +1,18 @@
1
1
  import {
2
+ isCloudflarePreset,
3
+ robotsTxt,
4
+ sitemapRoutes,
5
+ sitemapXml,
2
6
  toPublicConfig,
3
7
  toServerConfig,
4
8
  variantWidths
5
- } from "./chunk-NX6BO7UB.js";
9
+ } from "./chunk-IE3WF5XF.js";
6
10
  import {
7
11
  SSR_OUTLET
8
12
  } from "./chunk-MTXQR32N.js";
13
+ import {
14
+ COMPRESSIBLE_EXTENSIONS
15
+ } from "./chunk-PPUFFGCH.js";
9
16
  import {
10
17
  applyHead,
11
18
  resolveHead
@@ -296,10 +303,238 @@ function htmlTemplate(entry, stylesheets = []) {
296
303
  `;
297
304
  }
298
305
 
299
- // src/vite/presets.ts
300
- import { existsSync as existsSync3, readFileSync } from "fs";
301
- import { mkdir as mkdir3, rm, writeFile as writeFile3 } from "fs/promises";
306
+ // src/vite/platform.ts
307
+ import { existsSync as existsSync3 } from "fs";
308
+ import { createRequire } from "module";
302
309
  import path7 from "path";
310
+ import { pathToFileURL } from "url";
311
+ var WRANGLER_CONFIGS = [
312
+ "wrangler.json",
313
+ "wrangler.jsonc",
314
+ "wrangler.toml"
315
+ ];
316
+ async function startPlatformProxy(root, config) {
317
+ if (!isCloudflarePreset(config.build.preset)) return void 0;
318
+ let entry;
319
+ try {
320
+ entry = createRequire(path7.join(root, "package.json")).resolve("wrangler");
321
+ } catch {
322
+ console.warn(
323
+ "[noofpi] Cloudflare bindings are not available in dev: install wrangler (`wrangler` devDependency)"
324
+ );
325
+ return void 0;
326
+ }
327
+ const { getPlatformProxy } = await import(pathToFileURL(entry).href);
328
+ const configPath = WRANGLER_CONFIGS.map((file) => path7.join(root, file)).find(
329
+ existsSync3
330
+ );
331
+ return getPlatformProxy({ configPath });
332
+ }
333
+
334
+ // src/vite/presets.ts
335
+ import { existsSync as existsSync6, readFileSync as readFileSync3 } from "fs";
336
+ import { mkdir as mkdir3, rm, writeFile as writeFile4 } from "fs/promises";
337
+ import path11 from "path";
338
+
339
+ // src/vite/compress.ts
340
+ import { readdir, readFile as readFile2, writeFile as writeFile3 } from "fs/promises";
341
+ import path8 from "path";
342
+ import { promisify } from "util";
343
+ import { brotliCompress, constants, gzip } from "zlib";
344
+ var brotli = promisify(brotliCompress);
345
+ var gzipAsync = promisify(gzip);
346
+ var MIN_SIZE = 1024;
347
+ async function listFiles(dir) {
348
+ const files = [];
349
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
350
+ const full = path8.join(dir, entry.name);
351
+ if (entry.isDirectory()) files.push(...await listFiles(full));
352
+ else if (entry.isFile()) files.push(full);
353
+ }
354
+ return files;
355
+ }
356
+ async function precompressDir(dir) {
357
+ const files = (await listFiles(dir)).filter(
358
+ (file) => COMPRESSIBLE_EXTENSIONS.has(path8.extname(file).toLowerCase()) && // The shell is inlined in the server bundle and never served as a file
359
+ path8.basename(file) !== "index.html"
360
+ );
361
+ await Promise.all(
362
+ files.map(async (file) => {
363
+ const content = await readFile2(file);
364
+ if (content.length < MIN_SIZE) return;
365
+ const [br, gz] = await Promise.all([
366
+ brotli(content, {
367
+ params: {
368
+ [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY,
369
+ [constants.BROTLI_PARAM_SIZE_HINT]: content.length
370
+ }
371
+ }),
372
+ gzipAsync(content, { level: constants.Z_BEST_COMPRESSION })
373
+ ]);
374
+ await Promise.all([
375
+ br.length < content.length ? writeFile3(`${file}.br`, br) : void 0,
376
+ gz.length < content.length ? writeFile3(`${file}.gz`, gz) : void 0
377
+ ]);
378
+ })
379
+ );
380
+ }
381
+
382
+ // src/vite/docker.ts
383
+ var DOCKERIGNORE = `*
384
+ !package.json
385
+ !package-lock.json
386
+ !bun.lock
387
+ !bun.lockb
388
+ !.output
389
+ .output/Dockerfile
390
+ .output/Dockerfile.dockerignore
391
+ `;
392
+ function dockerfile(options) {
393
+ const { bun, lock, port, healthcheck } = options;
394
+ const runtime = bun ? "bun" : "node";
395
+ const image = options.image ?? (bun ? "oven/bun:1" : "node:22-alpine");
396
+ const lockfile = bun ? "bun.lock*" : "package-lock.json*";
397
+ const install = bun ? `bun install --production${lock ? " --frozen-lockfile" : ""}` : lock ? "npm ci --omit=dev" : "npm install --omit=dev";
398
+ const probe = `fetch('http://127.0.0.1:'+(process.env.PORT||${port})+${JSON.stringify(healthcheck || "/")}).then(r=>process.exit(r.status<500?0:1),()=>process.exit(1))`;
399
+ return [
400
+ `FROM ${image} AS deps`,
401
+ "WORKDIR /app",
402
+ `COPY package.json ${lockfile} ./`,
403
+ `RUN ${install}`,
404
+ "",
405
+ `FROM ${image}`,
406
+ "WORKDIR /app",
407
+ `ENV NODE_ENV=production PORT=${port}`,
408
+ "COPY --from=deps /app/node_modules ./node_modules",
409
+ "COPY package.json ./",
410
+ "COPY .output .output",
411
+ `USER ${bun ? "bun" : "node"}`,
412
+ `EXPOSE ${port}`,
413
+ ...healthcheck === false ? [] : [
414
+ `HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 CMD ${JSON.stringify([runtime, "-e", probe])}`
415
+ ],
416
+ `CMD ["${runtime}", ".output/server/start.mjs"]`,
417
+ ""
418
+ ].join("\n");
419
+ }
420
+
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
+ // src/vite/wrangler.ts
459
+ import { existsSync as existsSync5, readFileSync as readFileSync2 } from "fs";
460
+ import path10 from "path";
461
+ var DEFAULT_COMPATIBILITY_DATE = "2026-01-01";
462
+ function stripJsonc(text) {
463
+ let out = "";
464
+ let i = text.charCodeAt(0) === 65279 ? 1 : 0;
465
+ while (i < text.length) {
466
+ const ch = text[i];
467
+ const next = text[i + 1];
468
+ if (ch === '"') {
469
+ let end = i + 1;
470
+ while (end < text.length && text[end] !== '"')
471
+ end += text[end] === "\\" ? 2 : 1;
472
+ out += text.slice(i, end + 1);
473
+ i = end + 1;
474
+ } else if (ch === "/" && next === "/") {
475
+ while (i < text.length && text[i] !== "\n") i++;
476
+ } else if (ch === "/" && next === "*") {
477
+ const end = text.indexOf("*/", i + 2);
478
+ i = end === -1 ? text.length : end + 2;
479
+ } else {
480
+ if (ch === "}" || ch === "]") out = out.replace(/,(\s*)$/, "$1");
481
+ out += ch;
482
+ i++;
483
+ }
484
+ }
485
+ return out;
486
+ }
487
+ function readUserWranglerConfig(root) {
488
+ const file = WRANGLER_CONFIGS.map((name) => path10.join(root, name)).find(
489
+ existsSync5
490
+ );
491
+ if (!file) return void 0;
492
+ if (file.endsWith(".toml")) {
493
+ console.warn(
494
+ "[noofpi] wrangler.toml is not merged into .output/wrangler.json: use wrangler.json or wrangler.jsonc for bindings and vars"
495
+ );
496
+ return void 0;
497
+ }
498
+ let parsed;
499
+ try {
500
+ parsed = JSON.parse(stripJsonc(readFileSync2(file, "utf-8")));
501
+ } catch (error) {
502
+ throw new Error(
503
+ `[noofpi] Could not parse ${path10.basename(file)}: ${error.message}`
504
+ );
505
+ }
506
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
507
+ throw new Error(
508
+ `[noofpi] ${path10.basename(file)} must contain a JSON object`
509
+ );
510
+ return parsed;
511
+ }
512
+ function workerWranglerConfig(name, user = {}) {
513
+ const {
514
+ $schema: _schema,
515
+ build: _build,
516
+ pages_build_output_dir: _pages,
517
+ main: _main,
518
+ assets,
519
+ compatibility_flags: flags,
520
+ ...rest
521
+ } = user;
522
+ return {
523
+ name,
524
+ compatibility_date: DEFAULT_COMPATIBILITY_DATE,
525
+ ...rest,
526
+ compatibility_flags: [
527
+ .../* @__PURE__ */ new Set(["nodejs_compat", ...Array.isArray(flags) ? flags : []])
528
+ ],
529
+ main: "server/index.mjs",
530
+ assets: {
531
+ ...assets && typeof assets === "object" ? assets : {},
532
+ directory: "public"
533
+ }
534
+ };
535
+ }
536
+
537
+ // src/vite/presets.ts
303
538
  var OUTPUT_DIR = ".output";
304
539
  var HANDLER = `import { createHandler } from 'noofpi/server';
305
540
  import * as mod from 'virtual:noofpi/server';
@@ -344,20 +579,20 @@ function presetEntryCode(preset, config) {
344
579
  }
345
580
  }
346
581
  function readBuiltTemplate(root) {
347
- const file = path7.join(root, OUTPUT_DIR, "public/index.html");
348
- if (!existsSync3(file))
582
+ const file = path11.join(root, OUTPUT_DIR, "public/index.html");
583
+ if (!existsSync6(file))
349
584
  throw new Error("[noofpi] The client build is missing (no index.html).");
350
- return readFileSync(file, "utf-8");
585
+ return readFileSync3(file, "utf-8");
351
586
  }
352
587
  function serverBuildConfig(root, preset) {
353
- const outDir = path7.join(root, OUTPUT_DIR);
588
+ const outDir = path11.join(root, OUTPUT_DIR);
354
589
  switch (preset) {
355
590
  case "cloudflare-worker":
356
591
  return {
357
592
  ssr: { target: "webworker", noExternal: true },
358
593
  build: {
359
594
  ssr: true,
360
- outDir: path7.join(outDir, "server"),
595
+ outDir: path11.join(outDir, "server"),
361
596
  emptyOutDir: true,
362
597
  rollupOptions: {
363
598
  input: "virtual:noofpi/entry",
@@ -371,7 +606,7 @@ function serverBuildConfig(root, preset) {
371
606
  build: {
372
607
  ssr: true,
373
608
  // The Worker is added to the static files (the client build is already there)
374
- outDir: path7.join(outDir, "public"),
609
+ outDir: path11.join(outDir, "public"),
375
610
  emptyOutDir: false,
376
611
  rollupOptions: {
377
612
  input: "virtual:noofpi/entry",
@@ -386,7 +621,7 @@ function serverBuildConfig(root, preset) {
386
621
  return {
387
622
  build: {
388
623
  ssr: true,
389
- outDir: path7.join(outDir, "server"),
624
+ outDir: path11.join(outDir, "server"),
390
625
  emptyOutDir: true,
391
626
  rollupOptions: {
392
627
  // `index` is what `noofpi start` loads, `start` runs without the CLI
@@ -406,7 +641,7 @@ function serverBuildConfig(root, preset) {
406
641
  function readPackageName(root) {
407
642
  try {
408
643
  const pkg = JSON.parse(
409
- readFileSync(path7.join(root, "package.json"), "utf-8")
644
+ readFileSync3(path11.join(root, "package.json"), "utf-8")
410
645
  );
411
646
  return pkg.name;
412
647
  } catch {
@@ -414,126 +649,93 @@ function readPackageName(root) {
414
649
  }
415
650
  }
416
651
  function workerName(root) {
417
- const name = (readPackageName(root) ?? path7.basename(root)).replace(/^@[^/]+\//, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
652
+ const name = (readPackageName(root) ?? path11.basename(root)).replace(/^@[^/]+\//, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
418
653
  return name || "noofpi-app";
419
654
  }
420
- function dockerfile(root, port) {
421
- const bun = existsSync3(path7.join(root, "bun.lock")) || existsSync3(path7.join(root, "bun.lockb"));
422
- if (bun) {
423
- return `FROM oven/bun:1
424
- WORKDIR /app
425
- COPY package.json bun.lock* ./
426
- RUN bun install${existsSync3(path7.join(root, "bun.lock")) ? " --frozen-lockfile" : ""}
427
- COPY .output .output
428
- USER bun
429
- ENV NODE_ENV=production PORT=${port}
430
- EXPOSE ${port}
431
- CMD ["bun", ".output/server/start.mjs"]
432
- `;
655
+ async function writeSeoFiles(root, config) {
656
+ const { seo } = config;
657
+ const publicDir = path11.join(root, OUTPUT_DIR, "public");
658
+ const write = async (name, content) => {
659
+ if (!existsSync6(path11.join(publicDir, name)))
660
+ await writeFile4(path11.join(publicDir, name), content);
661
+ };
662
+ if (seo.sitemap && seo.siteUrl) {
663
+ const routes = sitemapRoutes(
664
+ Object.keys(scanPages(root, () => true)).map(filePathToRoute),
665
+ seo.exclude
666
+ );
667
+ await write("sitemap.xml", sitemapXml(seo.siteUrl, routes));
433
668
  }
434
- const lock = existsSync3(path7.join(root, "package-lock.json"));
435
- return `FROM node:22-alpine
436
- WORKDIR /app
437
- COPY package.json package-lock.json* ./
438
- RUN ${lock ? "npm ci" : "npm install"}
439
- COPY .output .output
440
- USER node
441
- ENV NODE_ENV=production PORT=${port}
442
- EXPOSE ${port}
443
- CMD ["node", ".output/server/start.mjs"]
444
- `;
669
+ if (seo.robots) await write("robots.txt", robotsTxt(seo));
445
670
  }
446
671
  async function finishPresetBuild(root, config, preset) {
447
- const outDir = path7.join(root, OUTPUT_DIR);
672
+ const outDir = path11.join(root, OUTPUT_DIR);
673
+ await writeSeoFiles(root, config);
448
674
  const json = (value) => JSON.stringify(value, null, 2) + "\n";
449
675
  switch (preset) {
450
676
  case "cloudflare-worker":
451
- await rm(path7.join(outDir, "public/index.html"), { force: true });
452
- await writeFile3(
453
- path7.join(outDir, "wrangler.json"),
454
- json({
455
- name: workerName(root),
456
- main: "server/index.mjs",
457
- compatibility_date: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
458
- compatibility_flags: ["nodejs_compat"],
459
- assets: { directory: "public" }
460
- })
677
+ await rm(path11.join(outDir, "public/index.html"), { force: true });
678
+ await writeFile4(
679
+ path11.join(outDir, "wrangler.json"),
680
+ json(
681
+ workerWranglerConfig(workerName(root), readUserWranglerConfig(root))
682
+ )
461
683
  );
462
684
  return "deploy with `wrangler deploy -c .output/wrangler.json`";
463
685
  case "cloudflare-pages":
464
- await rm(path7.join(outDir, "public/index.html"), { force: true });
465
- await writeFile3(
466
- path7.join(outDir, "public/_routes.json"),
686
+ await rm(path11.join(outDir, "public/index.html"), { force: true });
687
+ await writeFile4(
688
+ path11.join(outDir, "public/_routes.json"),
467
689
  json({ version: 1, include: ["/*"], exclude: ["/assets/*"] })
468
690
  );
469
691
  return "deploy with `wrangler pages deploy .output/public`";
470
692
  case "github-pages": {
471
- const index = path7.join(outDir, "public/index.html");
693
+ const index = path11.join(outDir, "public/index.html");
472
694
  const html = applyHead(
473
- readFileSync(index, "utf-8"),
695
+ readFileSync3(index, "utf-8"),
474
696
  resolveHead(config.head)
475
697
  ).replace(SSR_OUTLET, () => "");
476
- await writeFile3(index, html);
477
- await writeFile3(path7.join(outDir, "public/404.html"), html);
478
- await writeFile3(path7.join(outDir, "public/.nojekyll"), "");
698
+ await writeFile4(index, html);
699
+ await writeFile4(path11.join(outDir, "public/404.html"), html);
700
+ await writeFile4(path11.join(outDir, "public/.nojekyll"), "");
479
701
  return "publish `.output/public` to GitHub Pages (set `vite.base` to `/<repo>/` for project sites)";
480
702
  }
481
703
  case "docker":
704
+ await precompressDir(path11.join(outDir, "public"));
482
705
  await mkdir3(outDir, { recursive: true });
483
- await writeFile3(
484
- path7.join(outDir, "Dockerfile"),
485
- dockerfile(root, config.devServer.port)
706
+ await writeFile4(
707
+ path11.join(outDir, "Dockerfile"),
708
+ dockerfile({
709
+ bun: existsSync6(path11.join(root, "bun.lock")) || existsSync6(path11.join(root, "bun.lockb")),
710
+ lock: existsSync6(
711
+ path11.join(
712
+ root,
713
+ existsSync6(path11.join(root, "bun.lock")) ? "bun.lock" : "package-lock.json"
714
+ )
715
+ ),
716
+ port: config.devServer.port,
717
+ ...config.build.docker
718
+ })
719
+ );
720
+ await writeFile4(
721
+ path11.join(outDir, "Dockerfile.dockerignore"),
722
+ DOCKERIGNORE
486
723
  );
487
724
  return "build with `docker build -f .output/Dockerfile -t my-app .`";
488
725
  case "bun":
726
+ await precompressDir(path11.join(outDir, "public"));
489
727
  return "run with `bun .output/server/start.mjs`";
490
728
  default:
729
+ await precompressDir(path11.join(outDir, "public"));
491
730
  return "run with `noofpi start` or `node .output/server/start.mjs`";
492
731
  }
493
732
  }
494
733
 
495
734
  // src/vite/plugin.ts
496
- import { existsSync as existsSync6, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
497
- import path10 from "path";
735
+ import { existsSync as existsSync8, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
736
+ import path13 from "path";
498
737
  import { normalizePath as normalizePath2 } from "vite";
499
738
 
500
- // src/vite/layouts.ts
501
- import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync2 } from "fs";
502
- import path8 from "path";
503
- var USE_LAYOUT = /\buseLayout\(\s*(?:(['"`])([^'"`$\n]+)\1|(false))\s*\)/;
504
- function extractLayout(source) {
505
- const match = USE_LAYOUT.exec(source);
506
- if (!match) return void 0;
507
- return match[3] ? false : match[2];
508
- }
509
- function scanPages(root, extract) {
510
- const pagesDir = path8.join(root, "app/pages");
511
- const result = {};
512
- const walk = (dir) => {
513
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
514
- const full = path8.join(dir, entry.name);
515
- if (entry.isDirectory()) walk(full);
516
- else if (entry.name.endsWith(".vue")) {
517
- let value;
518
- try {
519
- value = extract(readFileSync2(full, "utf-8"));
520
- } catch (error) {
521
- throw new Error(
522
- `[noofpi] ${path8.relative(root, full)}: ${error.message}`
523
- );
524
- }
525
- if (value !== void 0)
526
- result["/" + path8.relative(root, full).split(path8.sep).join("/")] = value;
527
- }
528
- }
529
- };
530
- if (existsSync4(pagesDir)) walk(pagesDir);
531
- return result;
532
- }
533
- function scanPageLayouts(root) {
534
- return scanPages(root, extractLayout);
535
- }
536
-
537
739
  // src/vite/middleware.ts
538
740
  var USE_MIDDLEWARE = /^\s*\(\s*(?:(['"`])([^'"`$\n]+)\1|\[([^\]]*)\])\s*\)/;
539
741
  var CALL = /\buseMiddleware\b(?=\s*\()/g;
@@ -566,16 +768,17 @@ function scanPageMiddleware(root) {
566
768
  }
567
769
 
568
770
  // src/vite/types.ts
569
- import { existsSync as existsSync5, mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
570
- import path9 from "path";
571
- function doofpiTypes() {
771
+ import { existsSync as existsSync7, mkdirSync, readFileSync as readFileSync4, writeFileSync } from "fs";
772
+ import path12 from "path";
773
+ function doofpiTypes(fetch2 = "lfetch") {
572
774
  return [
573
775
  "// Generated by noofpi, do not edit",
574
776
  'import type * as server from "../server/doofpi";',
575
777
  "",
576
778
  'declare module "noofpi/runtime" {',
577
779
  " interface Register {",
578
- " routes: typeof server extends { routes: infer R } ? R : any;",
780
+ " localRoutes: typeof server extends { routes: infer R } ? R : any;",
781
+ ` defaultFetch: "${fetch2}";`,
579
782
  " }",
580
783
  "}",
581
784
  ""
@@ -604,14 +807,14 @@ function routeTypes(routes) {
604
807
  }
605
808
  function writeRouteTypes(root) {
606
809
  const routes = Object.keys(scanPages(root, () => true)).map(filePathToRoute);
607
- const file = path9.join(root, ".noofpi/routes.d.ts");
810
+ const file = path12.join(root, ".noofpi/routes.d.ts");
608
811
  const content = routeTypes(routes);
609
- if (existsSync5(file) && readFileSync3(file, "utf8") === content) return;
610
- mkdirSync(path9.dirname(file), { recursive: true });
812
+ if (existsSync7(file) && readFileSync4(file, "utf8") === content) return;
813
+ mkdirSync(path12.dirname(file), { recursive: true });
611
814
  writeFileSync(file, content);
612
815
  }
613
816
  function findLocaleFile(root, locale) {
614
- return ["ts", "js", "json"].map((extension) => `app/locales/${locale}.${extension}`).find((file) => existsSync5(path9.join(root, file)));
817
+ return ["ts", "js", "json"].map((extension) => `app/locales/${locale}.${extension}`).find((file) => existsSync7(path12.join(root, file)));
615
818
  }
616
819
  function i18nTypes(i18n, defaultLocaleFile) {
617
820
  const specifier = defaultLocaleFile?.replace(/\.(ts|js)$/, "");
@@ -631,18 +834,18 @@ function i18nTypes(i18n, defaultLocaleFile) {
631
834
  }
632
835
  function writeI18nTypes(root, i18n) {
633
836
  if (!i18n) return;
634
- const file = path9.join(root, ".noofpi/i18n.d.ts");
837
+ const file = path12.join(root, ".noofpi/i18n.d.ts");
635
838
  const content = i18nTypes(i18n, findLocaleFile(root, i18n.defaultLocale));
636
- if (existsSync5(file) && readFileSync3(file, "utf8") === content) return;
637
- mkdirSync(path9.dirname(file), { recursive: true });
839
+ if (existsSync7(file) && readFileSync4(file, "utf8") === content) return;
840
+ mkdirSync(path12.dirname(file), { recursive: true });
638
841
  writeFileSync(file, content);
639
842
  }
640
- function writeDoofpiTypes(root) {
641
- if (!existsSync5(path9.join(root, "server/doofpi.ts"))) return;
642
- const file = path9.join(root, ".noofpi/doofpi.d.ts");
643
- const content = doofpiTypes();
644
- if (existsSync5(file) && readFileSync3(file, "utf8") === content) return;
645
- mkdirSync(path9.dirname(file), { recursive: true });
843
+ function writeDoofpiTypes(root, fetch2) {
844
+ if (!existsSync7(path12.join(root, "server/doofpi.ts"))) return;
845
+ const file = path12.join(root, ".noofpi/doofpi.d.ts");
846
+ const content = doofpiTypes(fetch2);
847
+ if (existsSync7(file) && readFileSync4(file, "utf8") === content) return;
848
+ mkdirSync(path12.dirname(file), { recursive: true });
646
849
  writeFileSync(file, content);
647
850
  }
648
851
 
@@ -668,26 +871,26 @@ function resolveCss(root, config, fonts) {
668
871
  if (config.css) {
669
872
  return [
670
873
  ...generated,
671
- ...config.css.map((file) => path10.resolve(root, file))
874
+ ...config.css.map((file) => path13.resolve(root, file))
672
875
  ];
673
876
  }
674
- const main = path10.join(root, "app/assets/main.css");
675
- if (existsSync6(main)) return [...generated, main];
877
+ const main = path13.join(root, "app/assets/main.css");
878
+ if (existsSync8(main)) return [...generated, main];
676
879
  if (!config.tailwind) return generated;
677
- const tailwindEntry = path10.join(root, ".noofpi/tailwind.css");
678
- mkdirSync2(path10.dirname(tailwindEntry), { recursive: true });
880
+ const tailwindEntry = path13.join(root, ".noofpi/tailwind.css");
881
+ mkdirSync2(path13.dirname(tailwindEntry), { recursive: true });
679
882
  writeFileSync2(tailwindEntry, '@import "tailwindcss";\n');
680
883
  return [...generated, tailwindEntry];
681
884
  }
682
885
  function indexHtmlPath(root) {
683
- return normalizePath2(path10.join(root, "index.html"));
886
+ return normalizePath2(path13.join(root, "index.html"));
684
887
  }
685
888
  function noofpiPlugin(options) {
686
889
  const { root, config, css } = options;
687
890
  const htmlId = indexHtmlPath(root);
688
891
  const file = (relative) => {
689
- const full = path10.join(root, relative);
690
- return existsSync6(full) ? normalizePath2(full) : void 0;
892
+ const full = path13.join(root, relative);
893
+ return existsSync8(full) ? normalizePath2(full) : void 0;
691
894
  };
692
895
  const imp = (target) => JSON.stringify(normalizePath2(target));
693
896
  let scannedPages = "";
@@ -707,7 +910,7 @@ function noofpiPlugin(options) {
707
910
  `[noofpi] i18n locale "${locale}" has no file app/locales/${locale}.ts, it falls back to "${config.i18n.defaultLocale}"`
708
911
  );
709
912
  }
710
- writeDoofpiTypes(root);
913
+ writeDoofpiTypes(root, config.doofpi.fetch);
711
914
  writeRouteTypes(root);
712
915
  writeI18nTypes(root, config.i18n);
713
916
  },
@@ -815,10 +1018,9 @@ function noofpiPlugin(options) {
815
1018
  }
816
1019
 
817
1020
  // src/vite/config.ts
818
- import path12 from "path";
1021
+ import path15 from "path";
819
1022
  import { fileURLToPath } from "url";
820
1023
  import vue from "@vitejs/plugin-vue";
821
- import tailwindcss from "@tailwindcss/vite";
822
1024
  import { mergeConfig } from "vite";
823
1025
 
824
1026
  // src/vite/auto-imports.ts
@@ -880,12 +1082,33 @@ function autoImportPlugins() {
880
1082
 
881
1083
  // src/vite/images.ts
882
1084
  import { createHash as createHash2 } from "crypto";
883
- import { readFile as readFile2 } from "fs/promises";
884
- import path11 from "path";
1085
+ import { readFile as readFile3 } from "fs/promises";
1086
+ import path14 from "path";
1087
+
1088
+ // src/optional.ts
1089
+ async function importOptional(load, packages, feature) {
1090
+ try {
1091
+ return await load();
1092
+ } catch (error) {
1093
+ const { code, message } = error ?? {};
1094
+ if ((code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") && packages.some((name) => message?.includes(name)))
1095
+ throw new Error(
1096
+ `[noofpi] ${feature} needs ${packages.join(" and ")}: install ${packages.length > 1 ? "them" : "it"} with your package manager (for example \`bun add ${packages.join(" ")}\`)`,
1097
+ { cause: error }
1098
+ );
1099
+ throw error;
1100
+ }
1101
+ }
1102
+
1103
+ // src/vite/images.ts
885
1104
  var IMAGE_QUERY = /^(.+\.(?:jpe?g|png|webp|avif))\?image$/i;
886
1105
  async function processImage(file, images, options) {
887
- const { default: sharp } = await import("sharp");
888
- const input = await readFile2(file);
1106
+ const { default: sharp } = await importOptional(
1107
+ () => import("sharp"),
1108
+ ["sharp"],
1109
+ "Importing an image with `?image`"
1110
+ );
1111
+ const input = await readFile3(file);
889
1112
  const metadata = await sharp(input).metadata();
890
1113
  const turned = (metadata.orientation ?? 1) >= 5;
891
1114
  const width = turned ? metadata.height : metadata.width;
@@ -896,7 +1119,7 @@ async function processImage(file, images, options) {
896
1119
  const files = [];
897
1120
  if (!options.variants) return { image, files };
898
1121
  const hash = createHash2("sha256").update(input).update(JSON.stringify(images)).digest("hex").slice(0, 8);
899
- const name = path11.basename(file, path11.extname(file)).replace(/[^\w.-]+/g, "-");
1122
+ const name = path14.basename(file, path14.extname(file)).replace(/[^\w.-]+/g, "-");
900
1123
  const widths = variantWidths(width, images.widths);
901
1124
  for (const format of images.formats) {
902
1125
  const srcset = [];
@@ -942,6 +1165,16 @@ function imagesPlugin(images) {
942
1165
  };
943
1166
  }
944
1167
 
1168
+ // src/vite/tailwind.ts
1169
+ async function tailwindPlugin() {
1170
+ const { default: tailwindcss } = await importOptional(
1171
+ () => import("@tailwindcss/vite"),
1172
+ ["tailwindcss", "@tailwindcss/vite"],
1173
+ "`tailwind: true`"
1174
+ );
1175
+ return tailwindcss();
1176
+ }
1177
+
945
1178
  // src/vite/config.ts
946
1179
  function createViteConfig(root, config, kind, fonts = NO_FONTS) {
947
1180
  const base = {
@@ -953,7 +1186,7 @@ function createViteConfig(root, config, kind, fonts = NO_FONTS) {
953
1186
  vue(),
954
1187
  // Must come before Tailwind so the theme is in the stylesheet by the time Tailwind compiles it
955
1188
  config.tailwind && fonts.theme ? fontThemePlugin(fonts.theme) : null,
956
- config.tailwind ? tailwindcss() : null,
1189
+ config.tailwind ? tailwindPlugin() : null,
957
1190
  config.autoImports ? autoImportPlugins() : null,
958
1191
  imagesPlugin(config.images),
959
1192
  noofpiPlugin({ root, config, css: resolveCss(root, config, fonts) })
@@ -981,7 +1214,7 @@ function createViteConfig(root, config, kind, fonts = NO_FONTS) {
981
1214
  };
982
1215
  if (kind === "client") {
983
1216
  base.build = {
984
- outDir: path12.join(root, OUTPUT_DIR, "public"),
1217
+ outDir: path15.join(root, OUTPUT_DIR, "public"),
985
1218
  emptyOutDir: true,
986
1219
  rollupOptions: { input: indexHtmlPath(root) }
987
1220
  };
@@ -998,6 +1231,7 @@ function createViteConfig(root, config, kind, fonts = NO_FONTS) {
998
1231
  export {
999
1232
  resolveFonts,
1000
1233
  htmlTemplate,
1234
+ startPlatformProxy,
1001
1235
  OUTPUT_DIR,
1002
1236
  finishPresetBuild,
1003
1237
  DEV_ENTRY,