noofpi 1.2.0 → 2.0.1
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-WPHZ7TYZ.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-FIJJ3EGL.js → chunk-MN5PVHC5.js} +4 -0
- package/dist/{chunk-UF6YTIXD.js → chunk-NHBXVKEQ.js} +368 -130
- 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-OAGCOGHA.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-BN7NMCVQ.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 +18 -7
- 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-ITRND3BY.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 +24 -8
- 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';
|
|
@@ -328,8 +563,11 @@ function presetEntryCode(preset, config) {
|
|
|
328
563
|
case "cloudflare-pages":
|
|
329
564
|
return [
|
|
330
565
|
HANDLER,
|
|
331
|
-
// Pages serves static files through the ASSETS binding; everything else is a page or an API call
|
|
332
|
-
|
|
566
|
+
// Pages serves static files through the ASSETS binding; everything else is a page or an API call.
|
|
567
|
+
// API and proxy paths end in the endpoint name (`/_noofpi/proxy/doofpi.me.getMe`), which looks like a file extension
|
|
568
|
+
`const apiRoot = mod.config.doofpi.root;`,
|
|
569
|
+
`const isApiPath = (pathname) => pathname.startsWith('/_noofpi/') || pathname === apiRoot || pathname.startsWith(apiRoot + '.') || pathname.startsWith(apiRoot + '/');`,
|
|
570
|
+
`const isFile = (request) => { const { pathname } = new URL(request.url); return (request.method === 'GET' || request.method === 'HEAD') && /\\.[a-z0-9]+$/i.test(pathname) && !isApiPath(pathname); };`,
|
|
333
571
|
`export default { fetch: (request, env) => isFile(request) && env.ASSETS ? env.ASSETS.fetch(request) : handler(request, env) };`
|
|
334
572
|
].join("\n");
|
|
335
573
|
default:
|
|
@@ -344,20 +582,20 @@ function presetEntryCode(preset, config) {
|
|
|
344
582
|
}
|
|
345
583
|
}
|
|
346
584
|
function readBuiltTemplate(root) {
|
|
347
|
-
const file =
|
|
348
|
-
if (!
|
|
585
|
+
const file = path11.join(root, OUTPUT_DIR, "public/index.html");
|
|
586
|
+
if (!existsSync6(file))
|
|
349
587
|
throw new Error("[noofpi] The client build is missing (no index.html).");
|
|
350
|
-
return
|
|
588
|
+
return readFileSync3(file, "utf-8");
|
|
351
589
|
}
|
|
352
590
|
function serverBuildConfig(root, preset) {
|
|
353
|
-
const outDir =
|
|
591
|
+
const outDir = path11.join(root, OUTPUT_DIR);
|
|
354
592
|
switch (preset) {
|
|
355
593
|
case "cloudflare-worker":
|
|
356
594
|
return {
|
|
357
595
|
ssr: { target: "webworker", noExternal: true },
|
|
358
596
|
build: {
|
|
359
597
|
ssr: true,
|
|
360
|
-
outDir:
|
|
598
|
+
outDir: path11.join(outDir, "server"),
|
|
361
599
|
emptyOutDir: true,
|
|
362
600
|
rollupOptions: {
|
|
363
601
|
input: "virtual:noofpi/entry",
|
|
@@ -371,7 +609,7 @@ function serverBuildConfig(root, preset) {
|
|
|
371
609
|
build: {
|
|
372
610
|
ssr: true,
|
|
373
611
|
// The Worker is added to the static files (the client build is already there)
|
|
374
|
-
outDir:
|
|
612
|
+
outDir: path11.join(outDir, "public"),
|
|
375
613
|
emptyOutDir: false,
|
|
376
614
|
rollupOptions: {
|
|
377
615
|
input: "virtual:noofpi/entry",
|
|
@@ -386,7 +624,7 @@ function serverBuildConfig(root, preset) {
|
|
|
386
624
|
return {
|
|
387
625
|
build: {
|
|
388
626
|
ssr: true,
|
|
389
|
-
outDir:
|
|
627
|
+
outDir: path11.join(outDir, "server"),
|
|
390
628
|
emptyOutDir: true,
|
|
391
629
|
rollupOptions: {
|
|
392
630
|
// `index` is what `noofpi start` loads, `start` runs without the CLI
|
|
@@ -406,7 +644,7 @@ function serverBuildConfig(root, preset) {
|
|
|
406
644
|
function readPackageName(root) {
|
|
407
645
|
try {
|
|
408
646
|
const pkg = JSON.parse(
|
|
409
|
-
|
|
647
|
+
readFileSync3(path11.join(root, "package.json"), "utf-8")
|
|
410
648
|
);
|
|
411
649
|
return pkg.name;
|
|
412
650
|
} catch {
|
|
@@ -414,126 +652,93 @@ function readPackageName(root) {
|
|
|
414
652
|
}
|
|
415
653
|
}
|
|
416
654
|
function workerName(root) {
|
|
417
|
-
const name = (readPackageName(root) ??
|
|
655
|
+
const name = (readPackageName(root) ?? path11.basename(root)).replace(/^@[^/]+\//, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
418
656
|
return name || "noofpi-app";
|
|
419
657
|
}
|
|
420
|
-
function
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
658
|
+
async function writeSeoFiles(root, config) {
|
|
659
|
+
const { seo } = config;
|
|
660
|
+
const publicDir = path11.join(root, OUTPUT_DIR, "public");
|
|
661
|
+
const write = async (name, content) => {
|
|
662
|
+
if (!existsSync6(path11.join(publicDir, name)))
|
|
663
|
+
await writeFile4(path11.join(publicDir, name), content);
|
|
664
|
+
};
|
|
665
|
+
if (seo.sitemap && seo.siteUrl) {
|
|
666
|
+
const routes = sitemapRoutes(
|
|
667
|
+
Object.keys(scanPages(root, () => true)).map(filePathToRoute),
|
|
668
|
+
seo.exclude
|
|
669
|
+
);
|
|
670
|
+
await write("sitemap.xml", sitemapXml(seo.siteUrl, routes));
|
|
433
671
|
}
|
|
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
|
-
`;
|
|
672
|
+
if (seo.robots) await write("robots.txt", robotsTxt(seo));
|
|
445
673
|
}
|
|
446
674
|
async function finishPresetBuild(root, config, preset) {
|
|
447
|
-
const outDir =
|
|
675
|
+
const outDir = path11.join(root, OUTPUT_DIR);
|
|
676
|
+
await writeSeoFiles(root, config);
|
|
448
677
|
const json = (value) => JSON.stringify(value, null, 2) + "\n";
|
|
449
678
|
switch (preset) {
|
|
450
679
|
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
|
-
})
|
|
680
|
+
await rm(path11.join(outDir, "public/index.html"), { force: true });
|
|
681
|
+
await writeFile4(
|
|
682
|
+
path11.join(outDir, "wrangler.json"),
|
|
683
|
+
json(
|
|
684
|
+
workerWranglerConfig(workerName(root), readUserWranglerConfig(root))
|
|
685
|
+
)
|
|
461
686
|
);
|
|
462
687
|
return "deploy with `wrangler deploy -c .output/wrangler.json`";
|
|
463
688
|
case "cloudflare-pages":
|
|
464
|
-
await rm(
|
|
465
|
-
await
|
|
466
|
-
|
|
689
|
+
await rm(path11.join(outDir, "public/index.html"), { force: true });
|
|
690
|
+
await writeFile4(
|
|
691
|
+
path11.join(outDir, "public/_routes.json"),
|
|
467
692
|
json({ version: 1, include: ["/*"], exclude: ["/assets/*"] })
|
|
468
693
|
);
|
|
469
694
|
return "deploy with `wrangler pages deploy .output/public`";
|
|
470
695
|
case "github-pages": {
|
|
471
|
-
const index =
|
|
696
|
+
const index = path11.join(outDir, "public/index.html");
|
|
472
697
|
const html = applyHead(
|
|
473
|
-
|
|
698
|
+
readFileSync3(index, "utf-8"),
|
|
474
699
|
resolveHead(config.head)
|
|
475
700
|
).replace(SSR_OUTLET, () => "");
|
|
476
|
-
await
|
|
477
|
-
await
|
|
478
|
-
await
|
|
701
|
+
await writeFile4(index, html);
|
|
702
|
+
await writeFile4(path11.join(outDir, "public/404.html"), html);
|
|
703
|
+
await writeFile4(path11.join(outDir, "public/.nojekyll"), "");
|
|
479
704
|
return "publish `.output/public` to GitHub Pages (set `vite.base` to `/<repo>/` for project sites)";
|
|
480
705
|
}
|
|
481
706
|
case "docker":
|
|
707
|
+
await precompressDir(path11.join(outDir, "public"));
|
|
482
708
|
await mkdir3(outDir, { recursive: true });
|
|
483
|
-
await
|
|
484
|
-
|
|
485
|
-
dockerfile(
|
|
709
|
+
await writeFile4(
|
|
710
|
+
path11.join(outDir, "Dockerfile"),
|
|
711
|
+
dockerfile({
|
|
712
|
+
bun: existsSync6(path11.join(root, "bun.lock")) || existsSync6(path11.join(root, "bun.lockb")),
|
|
713
|
+
lock: existsSync6(
|
|
714
|
+
path11.join(
|
|
715
|
+
root,
|
|
716
|
+
existsSync6(path11.join(root, "bun.lock")) ? "bun.lock" : "package-lock.json"
|
|
717
|
+
)
|
|
718
|
+
),
|
|
719
|
+
port: config.devServer.port,
|
|
720
|
+
...config.build.docker
|
|
721
|
+
})
|
|
722
|
+
);
|
|
723
|
+
await writeFile4(
|
|
724
|
+
path11.join(outDir, "Dockerfile.dockerignore"),
|
|
725
|
+
DOCKERIGNORE
|
|
486
726
|
);
|
|
487
727
|
return "build with `docker build -f .output/Dockerfile -t my-app .`";
|
|
488
728
|
case "bun":
|
|
729
|
+
await precompressDir(path11.join(outDir, "public"));
|
|
489
730
|
return "run with `bun .output/server/start.mjs`";
|
|
490
731
|
default:
|
|
732
|
+
await precompressDir(path11.join(outDir, "public"));
|
|
491
733
|
return "run with `noofpi start` or `node .output/server/start.mjs`";
|
|
492
734
|
}
|
|
493
735
|
}
|
|
494
736
|
|
|
495
737
|
// src/vite/plugin.ts
|
|
496
|
-
import { existsSync as
|
|
497
|
-
import
|
|
738
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
739
|
+
import path13 from "path";
|
|
498
740
|
import { normalizePath as normalizePath2 } from "vite";
|
|
499
741
|
|
|
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
742
|
// src/vite/middleware.ts
|
|
538
743
|
var USE_MIDDLEWARE = /^\s*\(\s*(?:(['"`])([^'"`$\n]+)\1|\[([^\]]*)\])\s*\)/;
|
|
539
744
|
var CALL = /\buseMiddleware\b(?=\s*\()/g;
|
|
@@ -566,8 +771,8 @@ function scanPageMiddleware(root) {
|
|
|
566
771
|
}
|
|
567
772
|
|
|
568
773
|
// src/vite/types.ts
|
|
569
|
-
import { existsSync as
|
|
570
|
-
import
|
|
774
|
+
import { existsSync as existsSync7, mkdirSync, readFileSync as readFileSync4, writeFileSync } from "fs";
|
|
775
|
+
import path12 from "path";
|
|
571
776
|
function doofpiTypes(fetch2 = "lfetch") {
|
|
572
777
|
return [
|
|
573
778
|
"// Generated by noofpi, do not edit",
|
|
@@ -605,14 +810,14 @@ function routeTypes(routes) {
|
|
|
605
810
|
}
|
|
606
811
|
function writeRouteTypes(root) {
|
|
607
812
|
const routes = Object.keys(scanPages(root, () => true)).map(filePathToRoute);
|
|
608
|
-
const file =
|
|
813
|
+
const file = path12.join(root, ".noofpi/routes.d.ts");
|
|
609
814
|
const content = routeTypes(routes);
|
|
610
|
-
if (
|
|
611
|
-
mkdirSync(
|
|
815
|
+
if (existsSync7(file) && readFileSync4(file, "utf8") === content) return;
|
|
816
|
+
mkdirSync(path12.dirname(file), { recursive: true });
|
|
612
817
|
writeFileSync(file, content);
|
|
613
818
|
}
|
|
614
819
|
function findLocaleFile(root, locale) {
|
|
615
|
-
return ["ts", "js", "json"].map((extension) => `app/locales/${locale}.${extension}`).find((file) =>
|
|
820
|
+
return ["ts", "js", "json"].map((extension) => `app/locales/${locale}.${extension}`).find((file) => existsSync7(path12.join(root, file)));
|
|
616
821
|
}
|
|
617
822
|
function i18nTypes(i18n, defaultLocaleFile) {
|
|
618
823
|
const specifier = defaultLocaleFile?.replace(/\.(ts|js)$/, "");
|
|
@@ -632,18 +837,18 @@ function i18nTypes(i18n, defaultLocaleFile) {
|
|
|
632
837
|
}
|
|
633
838
|
function writeI18nTypes(root, i18n) {
|
|
634
839
|
if (!i18n) return;
|
|
635
|
-
const file =
|
|
840
|
+
const file = path12.join(root, ".noofpi/i18n.d.ts");
|
|
636
841
|
const content = i18nTypes(i18n, findLocaleFile(root, i18n.defaultLocale));
|
|
637
|
-
if (
|
|
638
|
-
mkdirSync(
|
|
842
|
+
if (existsSync7(file) && readFileSync4(file, "utf8") === content) return;
|
|
843
|
+
mkdirSync(path12.dirname(file), { recursive: true });
|
|
639
844
|
writeFileSync(file, content);
|
|
640
845
|
}
|
|
641
846
|
function writeDoofpiTypes(root, fetch2) {
|
|
642
|
-
if (!
|
|
643
|
-
const file =
|
|
847
|
+
if (!existsSync7(path12.join(root, "server/doofpi.ts"))) return;
|
|
848
|
+
const file = path12.join(root, ".noofpi/doofpi.d.ts");
|
|
644
849
|
const content = doofpiTypes(fetch2);
|
|
645
|
-
if (
|
|
646
|
-
mkdirSync(
|
|
850
|
+
if (existsSync7(file) && readFileSync4(file, "utf8") === content) return;
|
|
851
|
+
mkdirSync(path12.dirname(file), { recursive: true });
|
|
647
852
|
writeFileSync(file, content);
|
|
648
853
|
}
|
|
649
854
|
|
|
@@ -669,26 +874,26 @@ function resolveCss(root, config, fonts) {
|
|
|
669
874
|
if (config.css) {
|
|
670
875
|
return [
|
|
671
876
|
...generated,
|
|
672
|
-
...config.css.map((file) =>
|
|
877
|
+
...config.css.map((file) => path13.resolve(root, file))
|
|
673
878
|
];
|
|
674
879
|
}
|
|
675
|
-
const main =
|
|
676
|
-
if (
|
|
880
|
+
const main = path13.join(root, "app/assets/main.css");
|
|
881
|
+
if (existsSync8(main)) return [...generated, main];
|
|
677
882
|
if (!config.tailwind) return generated;
|
|
678
|
-
const tailwindEntry =
|
|
679
|
-
mkdirSync2(
|
|
883
|
+
const tailwindEntry = path13.join(root, ".noofpi/tailwind.css");
|
|
884
|
+
mkdirSync2(path13.dirname(tailwindEntry), { recursive: true });
|
|
680
885
|
writeFileSync2(tailwindEntry, '@import "tailwindcss";\n');
|
|
681
886
|
return [...generated, tailwindEntry];
|
|
682
887
|
}
|
|
683
888
|
function indexHtmlPath(root) {
|
|
684
|
-
return normalizePath2(
|
|
889
|
+
return normalizePath2(path13.join(root, "index.html"));
|
|
685
890
|
}
|
|
686
891
|
function noofpiPlugin(options) {
|
|
687
892
|
const { root, config, css } = options;
|
|
688
893
|
const htmlId = indexHtmlPath(root);
|
|
689
894
|
const file = (relative) => {
|
|
690
|
-
const full =
|
|
691
|
-
return
|
|
895
|
+
const full = path13.join(root, relative);
|
|
896
|
+
return existsSync8(full) ? normalizePath2(full) : void 0;
|
|
692
897
|
};
|
|
693
898
|
const imp = (target) => JSON.stringify(normalizePath2(target));
|
|
694
899
|
let scannedPages = "";
|
|
@@ -816,10 +1021,9 @@ function noofpiPlugin(options) {
|
|
|
816
1021
|
}
|
|
817
1022
|
|
|
818
1023
|
// src/vite/config.ts
|
|
819
|
-
import
|
|
1024
|
+
import path15 from "path";
|
|
820
1025
|
import { fileURLToPath } from "url";
|
|
821
1026
|
import vue from "@vitejs/plugin-vue";
|
|
822
|
-
import tailwindcss from "@tailwindcss/vite";
|
|
823
1027
|
import { mergeConfig } from "vite";
|
|
824
1028
|
|
|
825
1029
|
// src/vite/auto-imports.ts
|
|
@@ -866,6 +1070,8 @@ function autoImportPlugins() {
|
|
|
866
1070
|
"app/utils/*/index.{ts,js}"
|
|
867
1071
|
],
|
|
868
1072
|
include: [/\.[jt]sx?$/, /\.vue$/, /\.vue\?vue/],
|
|
1073
|
+
// Without it a util used only in a template compiles to `_ctx.name` and is undefined at runtime
|
|
1074
|
+
vueTemplate: true,
|
|
869
1075
|
dts: ".noofpi/auto-imports.d.ts"
|
|
870
1076
|
}),
|
|
871
1077
|
Components({
|
|
@@ -881,12 +1087,33 @@ function autoImportPlugins() {
|
|
|
881
1087
|
|
|
882
1088
|
// src/vite/images.ts
|
|
883
1089
|
import { createHash as createHash2 } from "crypto";
|
|
884
|
-
import { readFile as
|
|
885
|
-
import
|
|
1090
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1091
|
+
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
|
|
886
1109
|
var IMAGE_QUERY = /^(.+\.(?:jpe?g|png|webp|avif))\?image$/i;
|
|
887
1110
|
async function processImage(file, images, options) {
|
|
888
|
-
const { default: sharp } = await
|
|
889
|
-
|
|
1111
|
+
const { default: sharp } = await importOptional(
|
|
1112
|
+
() => import("sharp"),
|
|
1113
|
+
["sharp"],
|
|
1114
|
+
"Importing an image with `?image`"
|
|
1115
|
+
);
|
|
1116
|
+
const input = await readFile3(file);
|
|
890
1117
|
const metadata = await sharp(input).metadata();
|
|
891
1118
|
const turned = (metadata.orientation ?? 1) >= 5;
|
|
892
1119
|
const width = turned ? metadata.height : metadata.width;
|
|
@@ -897,7 +1124,7 @@ async function processImage(file, images, options) {
|
|
|
897
1124
|
const files = [];
|
|
898
1125
|
if (!options.variants) return { image, files };
|
|
899
1126
|
const hash = createHash2("sha256").update(input).update(JSON.stringify(images)).digest("hex").slice(0, 8);
|
|
900
|
-
const name =
|
|
1127
|
+
const name = path14.basename(file, path14.extname(file)).replace(/[^\w.-]+/g, "-");
|
|
901
1128
|
const widths = variantWidths(width, images.widths);
|
|
902
1129
|
for (const format of images.formats) {
|
|
903
1130
|
const srcset = [];
|
|
@@ -943,6 +1170,16 @@ function imagesPlugin(images) {
|
|
|
943
1170
|
};
|
|
944
1171
|
}
|
|
945
1172
|
|
|
1173
|
+
// src/vite/tailwind.ts
|
|
1174
|
+
async function tailwindPlugin() {
|
|
1175
|
+
const { default: tailwindcss } = await importOptional(
|
|
1176
|
+
() => import("@tailwindcss/vite"),
|
|
1177
|
+
["tailwindcss", "@tailwindcss/vite"],
|
|
1178
|
+
"`tailwind: true`"
|
|
1179
|
+
);
|
|
1180
|
+
return tailwindcss();
|
|
1181
|
+
}
|
|
1182
|
+
|
|
946
1183
|
// src/vite/config.ts
|
|
947
1184
|
function createViteConfig(root, config, kind, fonts = NO_FONTS) {
|
|
948
1185
|
const base = {
|
|
@@ -954,7 +1191,7 @@ function createViteConfig(root, config, kind, fonts = NO_FONTS) {
|
|
|
954
1191
|
vue(),
|
|
955
1192
|
// Must come before Tailwind so the theme is in the stylesheet by the time Tailwind compiles it
|
|
956
1193
|
config.tailwind && fonts.theme ? fontThemePlugin(fonts.theme) : null,
|
|
957
|
-
config.tailwind ?
|
|
1194
|
+
config.tailwind ? tailwindPlugin() : null,
|
|
958
1195
|
config.autoImports ? autoImportPlugins() : null,
|
|
959
1196
|
imagesPlugin(config.images),
|
|
960
1197
|
noofpiPlugin({ root, config, css: resolveCss(root, config, fonts) })
|
|
@@ -982,7 +1219,7 @@ function createViteConfig(root, config, kind, fonts = NO_FONTS) {
|
|
|
982
1219
|
};
|
|
983
1220
|
if (kind === "client") {
|
|
984
1221
|
base.build = {
|
|
985
|
-
outDir:
|
|
1222
|
+
outDir: path15.join(root, OUTPUT_DIR, "public"),
|
|
986
1223
|
emptyOutDir: true,
|
|
987
1224
|
rollupOptions: { input: indexHtmlPath(root) }
|
|
988
1225
|
};
|
|
@@ -999,6 +1236,7 @@ function createViteConfig(root, config, kind, fonts = NO_FONTS) {
|
|
|
999
1236
|
export {
|
|
1000
1237
|
resolveFonts,
|
|
1001
1238
|
htmlTemplate,
|
|
1239
|
+
startPlatformProxy,
|
|
1002
1240
|
OUTPUT_DIR,
|
|
1003
1241
|
finishPresetBuild,
|
|
1004
1242
|
DEV_ENTRY,
|