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
|
@@ -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-
|
|
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/
|
|
300
|
-
import { existsSync as existsSync3
|
|
301
|
-
import {
|
|
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 =
|
|
348
|
-
if (!
|
|
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
|
|
585
|
+
return readFileSync3(file, "utf-8");
|
|
351
586
|
}
|
|
352
587
|
function serverBuildConfig(root, preset) {
|
|
353
|
-
const outDir =
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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) ??
|
|
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
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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
|
-
|
|
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 =
|
|
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(
|
|
452
|
-
await
|
|
453
|
-
|
|
454
|
-
json(
|
|
455
|
-
|
|
456
|
-
|
|
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(
|
|
465
|
-
await
|
|
466
|
-
|
|
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 =
|
|
693
|
+
const index = path11.join(outDir, "public/index.html");
|
|
472
694
|
const html = applyHead(
|
|
473
|
-
|
|
695
|
+
readFileSync3(index, "utf-8"),
|
|
474
696
|
resolveHead(config.head)
|
|
475
697
|
).replace(SSR_OUTLET, () => "");
|
|
476
|
-
await
|
|
477
|
-
await
|
|
478
|
-
await
|
|
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
|
|
484
|
-
|
|
485
|
-
dockerfile(
|
|
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
|
|
497
|
-
import
|
|
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,8 +768,8 @@ function scanPageMiddleware(root) {
|
|
|
566
768
|
}
|
|
567
769
|
|
|
568
770
|
// src/vite/types.ts
|
|
569
|
-
import { existsSync as
|
|
570
|
-
import
|
|
771
|
+
import { existsSync as existsSync7, mkdirSync, readFileSync as readFileSync4, writeFileSync } from "fs";
|
|
772
|
+
import path12 from "path";
|
|
571
773
|
function doofpiTypes(fetch2 = "lfetch") {
|
|
572
774
|
return [
|
|
573
775
|
"// Generated by noofpi, do not edit",
|
|
@@ -605,14 +807,14 @@ function routeTypes(routes) {
|
|
|
605
807
|
}
|
|
606
808
|
function writeRouteTypes(root) {
|
|
607
809
|
const routes = Object.keys(scanPages(root, () => true)).map(filePathToRoute);
|
|
608
|
-
const file =
|
|
810
|
+
const file = path12.join(root, ".noofpi/routes.d.ts");
|
|
609
811
|
const content = routeTypes(routes);
|
|
610
|
-
if (
|
|
611
|
-
mkdirSync(
|
|
812
|
+
if (existsSync7(file) && readFileSync4(file, "utf8") === content) return;
|
|
813
|
+
mkdirSync(path12.dirname(file), { recursive: true });
|
|
612
814
|
writeFileSync(file, content);
|
|
613
815
|
}
|
|
614
816
|
function findLocaleFile(root, locale) {
|
|
615
|
-
return ["ts", "js", "json"].map((extension) => `app/locales/${locale}.${extension}`).find((file) =>
|
|
817
|
+
return ["ts", "js", "json"].map((extension) => `app/locales/${locale}.${extension}`).find((file) => existsSync7(path12.join(root, file)));
|
|
616
818
|
}
|
|
617
819
|
function i18nTypes(i18n, defaultLocaleFile) {
|
|
618
820
|
const specifier = defaultLocaleFile?.replace(/\.(ts|js)$/, "");
|
|
@@ -632,18 +834,18 @@ function i18nTypes(i18n, defaultLocaleFile) {
|
|
|
632
834
|
}
|
|
633
835
|
function writeI18nTypes(root, i18n) {
|
|
634
836
|
if (!i18n) return;
|
|
635
|
-
const file =
|
|
837
|
+
const file = path12.join(root, ".noofpi/i18n.d.ts");
|
|
636
838
|
const content = i18nTypes(i18n, findLocaleFile(root, i18n.defaultLocale));
|
|
637
|
-
if (
|
|
638
|
-
mkdirSync(
|
|
839
|
+
if (existsSync7(file) && readFileSync4(file, "utf8") === content) return;
|
|
840
|
+
mkdirSync(path12.dirname(file), { recursive: true });
|
|
639
841
|
writeFileSync(file, content);
|
|
640
842
|
}
|
|
641
843
|
function writeDoofpiTypes(root, fetch2) {
|
|
642
|
-
if (!
|
|
643
|
-
const file =
|
|
844
|
+
if (!existsSync7(path12.join(root, "server/doofpi.ts"))) return;
|
|
845
|
+
const file = path12.join(root, ".noofpi/doofpi.d.ts");
|
|
644
846
|
const content = doofpiTypes(fetch2);
|
|
645
|
-
if (
|
|
646
|
-
mkdirSync(
|
|
847
|
+
if (existsSync7(file) && readFileSync4(file, "utf8") === content) return;
|
|
848
|
+
mkdirSync(path12.dirname(file), { recursive: true });
|
|
647
849
|
writeFileSync(file, content);
|
|
648
850
|
}
|
|
649
851
|
|
|
@@ -669,26 +871,26 @@ function resolveCss(root, config, fonts) {
|
|
|
669
871
|
if (config.css) {
|
|
670
872
|
return [
|
|
671
873
|
...generated,
|
|
672
|
-
...config.css.map((file) =>
|
|
874
|
+
...config.css.map((file) => path13.resolve(root, file))
|
|
673
875
|
];
|
|
674
876
|
}
|
|
675
|
-
const main =
|
|
676
|
-
if (
|
|
877
|
+
const main = path13.join(root, "app/assets/main.css");
|
|
878
|
+
if (existsSync8(main)) return [...generated, main];
|
|
677
879
|
if (!config.tailwind) return generated;
|
|
678
|
-
const tailwindEntry =
|
|
679
|
-
mkdirSync2(
|
|
880
|
+
const tailwindEntry = path13.join(root, ".noofpi/tailwind.css");
|
|
881
|
+
mkdirSync2(path13.dirname(tailwindEntry), { recursive: true });
|
|
680
882
|
writeFileSync2(tailwindEntry, '@import "tailwindcss";\n');
|
|
681
883
|
return [...generated, tailwindEntry];
|
|
682
884
|
}
|
|
683
885
|
function indexHtmlPath(root) {
|
|
684
|
-
return normalizePath2(
|
|
886
|
+
return normalizePath2(path13.join(root, "index.html"));
|
|
685
887
|
}
|
|
686
888
|
function noofpiPlugin(options) {
|
|
687
889
|
const { root, config, css } = options;
|
|
688
890
|
const htmlId = indexHtmlPath(root);
|
|
689
891
|
const file = (relative) => {
|
|
690
|
-
const full =
|
|
691
|
-
return
|
|
892
|
+
const full = path13.join(root, relative);
|
|
893
|
+
return existsSync8(full) ? normalizePath2(full) : void 0;
|
|
692
894
|
};
|
|
693
895
|
const imp = (target) => JSON.stringify(normalizePath2(target));
|
|
694
896
|
let scannedPages = "";
|
|
@@ -816,10 +1018,9 @@ function noofpiPlugin(options) {
|
|
|
816
1018
|
}
|
|
817
1019
|
|
|
818
1020
|
// src/vite/config.ts
|
|
819
|
-
import
|
|
1021
|
+
import path15 from "path";
|
|
820
1022
|
import { fileURLToPath } from "url";
|
|
821
1023
|
import vue from "@vitejs/plugin-vue";
|
|
822
|
-
import tailwindcss from "@tailwindcss/vite";
|
|
823
1024
|
import { mergeConfig } from "vite";
|
|
824
1025
|
|
|
825
1026
|
// src/vite/auto-imports.ts
|
|
@@ -881,12 +1082,33 @@ function autoImportPlugins() {
|
|
|
881
1082
|
|
|
882
1083
|
// src/vite/images.ts
|
|
883
1084
|
import { createHash as createHash2 } from "crypto";
|
|
884
|
-
import { readFile as
|
|
885
|
-
import
|
|
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
|
|
886
1104
|
var IMAGE_QUERY = /^(.+\.(?:jpe?g|png|webp|avif))\?image$/i;
|
|
887
1105
|
async function processImage(file, images, options) {
|
|
888
|
-
const { default: sharp } = await
|
|
889
|
-
|
|
1106
|
+
const { default: sharp } = await importOptional(
|
|
1107
|
+
() => import("sharp"),
|
|
1108
|
+
["sharp"],
|
|
1109
|
+
"Importing an image with `?image`"
|
|
1110
|
+
);
|
|
1111
|
+
const input = await readFile3(file);
|
|
890
1112
|
const metadata = await sharp(input).metadata();
|
|
891
1113
|
const turned = (metadata.orientation ?? 1) >= 5;
|
|
892
1114
|
const width = turned ? metadata.height : metadata.width;
|
|
@@ -897,7 +1119,7 @@ async function processImage(file, images, options) {
|
|
|
897
1119
|
const files = [];
|
|
898
1120
|
if (!options.variants) return { image, files };
|
|
899
1121
|
const hash = createHash2("sha256").update(input).update(JSON.stringify(images)).digest("hex").slice(0, 8);
|
|
900
|
-
const name =
|
|
1122
|
+
const name = path14.basename(file, path14.extname(file)).replace(/[^\w.-]+/g, "-");
|
|
901
1123
|
const widths = variantWidths(width, images.widths);
|
|
902
1124
|
for (const format of images.formats) {
|
|
903
1125
|
const srcset = [];
|
|
@@ -943,6 +1165,16 @@ function imagesPlugin(images) {
|
|
|
943
1165
|
};
|
|
944
1166
|
}
|
|
945
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
|
+
|
|
946
1178
|
// src/vite/config.ts
|
|
947
1179
|
function createViteConfig(root, config, kind, fonts = NO_FONTS) {
|
|
948
1180
|
const base = {
|
|
@@ -954,7 +1186,7 @@ function createViteConfig(root, config, kind, fonts = NO_FONTS) {
|
|
|
954
1186
|
vue(),
|
|
955
1187
|
// Must come before Tailwind so the theme is in the stylesheet by the time Tailwind compiles it
|
|
956
1188
|
config.tailwind && fonts.theme ? fontThemePlugin(fonts.theme) : null,
|
|
957
|
-
config.tailwind ?
|
|
1189
|
+
config.tailwind ? tailwindPlugin() : null,
|
|
958
1190
|
config.autoImports ? autoImportPlugins() : null,
|
|
959
1191
|
imagesPlugin(config.images),
|
|
960
1192
|
noofpiPlugin({ root, config, css: resolveCss(root, config, fonts) })
|
|
@@ -982,7 +1214,7 @@ function createViteConfig(root, config, kind, fonts = NO_FONTS) {
|
|
|
982
1214
|
};
|
|
983
1215
|
if (kind === "client") {
|
|
984
1216
|
base.build = {
|
|
985
|
-
outDir:
|
|
1217
|
+
outDir: path15.join(root, OUTPUT_DIR, "public"),
|
|
986
1218
|
emptyOutDir: true,
|
|
987
1219
|
rollupOptions: { input: indexHtmlPath(root) }
|
|
988
1220
|
};
|
|
@@ -999,6 +1231,7 @@ function createViteConfig(root, config, kind, fonts = NO_FONTS) {
|
|
|
999
1231
|
export {
|
|
1000
1232
|
resolveFonts,
|
|
1001
1233
|
htmlTemplate,
|
|
1234
|
+
startPlatformProxy,
|
|
1002
1235
|
OUTPUT_DIR,
|
|
1003
1236
|
finishPresetBuild,
|
|
1004
1237
|
DEV_ENTRY,
|