noofpi 0.0.0-stage → 1.1.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 (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -2
  3. package/bin/noofpi.mjs +2 -0
  4. package/client.d.ts +79 -0
  5. package/dist/build-63DMFZJY.js +48 -0
  6. package/dist/chunk-2XCZWFIQ.js +253 -0
  7. package/dist/chunk-6OWKWAIW.js +68 -0
  8. package/dist/chunk-ELXCFUA4.js +97 -0
  9. package/dist/chunk-EZPJF4D4.js +314 -0
  10. package/dist/chunk-FIJJ3EGL.js +353 -0
  11. package/dist/chunk-G35DW4NA.js +129 -0
  12. package/dist/chunk-KGZP2RCF.js +51 -0
  13. package/dist/chunk-MTWSTW7V.js +44 -0
  14. package/dist/chunk-MTXQR32N.js +8 -0
  15. package/dist/chunk-NALDZ3PS.js +90 -0
  16. package/dist/chunk-NX6BO7UB.js +284 -0
  17. package/dist/chunk-SSJ2KKBZ.js +996 -0
  18. package/dist/chunk-WX2V6EYH.js +102 -0
  19. package/dist/chunk-X34Y6ESE.js +810 -0
  20. package/dist/chunk-Y3NBZ6DW.js +55 -0
  21. package/dist/chunk-YZAZ7IWK.js +27 -0
  22. package/dist/cli.js +93 -0
  23. package/dist/dev-USSN6KFV.js +149 -0
  24. package/dist/devtools-KTDSD5PR.js +564 -0
  25. package/dist/images-BNwTAi50.d.ts +36 -0
  26. package/dist/index.d.ts +115 -0
  27. package/dist/index.js +15 -0
  28. package/dist/route-rules-COilNsVT.d.ts +127 -0
  29. package/dist/runtime/default-app.js +15 -0
  30. package/dist/runtime/entry-client.js +70 -0
  31. package/dist/runtime/entry-server.js +107 -0
  32. package/dist/runtime/index.d.ts +523 -0
  33. package/dist/runtime/index.js +224 -0
  34. package/dist/runtime/routes.js +14 -0
  35. package/dist/server/bun.js +47 -0
  36. package/dist/server/index.d.ts +109 -0
  37. package/dist/server/index.js +48 -0
  38. package/dist/server/node.js +15 -0
  39. package/dist/start-U6A3PBRI.js +61 -0
  40. package/dist/validation-ClXd_DAW.d.ts +159 -0
  41. package/package.json +101 -4
@@ -0,0 +1,55 @@
1
+ // src/runtime/routes.ts
2
+ var PAGES_DIR = "/app/pages/";
3
+ function filePathToRoute(file) {
4
+ const relative = file.slice(file.indexOf(PAGES_DIR) + PAGES_DIR.length).replace(/\.vue$/, "");
5
+ const segments = relative.split("/").filter(
6
+ (segment, index, all) => !(segment === "index" && index === all.length - 1)
7
+ ).map((segment) => {
8
+ const catchAll = /^\[\.\.\.(\w+)\]$/.exec(segment);
9
+ if (catchAll) return `:${catchAll[1]}(.*)*`;
10
+ const param = /^\[(\w+)\]$/.exec(segment);
11
+ return param ? `:${param[1]}` : segment;
12
+ });
13
+ return "/" + segments.join("/");
14
+ }
15
+ function createRoutes(pages, layouts = {}, middleware = {}) {
16
+ return Object.entries(pages).map(([file, importPage]) => {
17
+ const meta = {
18
+ layout: layouts[file],
19
+ middleware: middleware[file]
20
+ };
21
+ return {
22
+ path: filePathToRoute(file),
23
+ // The page's `definePage()` export is read once the module is imported, which the router awaits before it resolves a navigation
24
+ component: async () => {
25
+ const module = await importPage();
26
+ meta.loader = module?.page?.loader;
27
+ return module;
28
+ },
29
+ meta
30
+ };
31
+ });
32
+ }
33
+ function filePathToLayoutName(file) {
34
+ const name = file.slice(file.lastIndexOf("/") + 1).replace(/\.vue$/, "");
35
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
36
+ }
37
+ function createLayouts(modules) {
38
+ return Object.fromEntries(
39
+ Object.entries(modules).map(([file, component]) => [
40
+ filePathToLayoutName(file),
41
+ component
42
+ ])
43
+ );
44
+ }
45
+ function normalizeLayout(value) {
46
+ return typeof value === "string" || value === false ? value : void 0;
47
+ }
48
+
49
+ export {
50
+ filePathToRoute,
51
+ createRoutes,
52
+ filePathToLayoutName,
53
+ createLayouts,
54
+ normalizeLayout
55
+ };
@@ -0,0 +1,27 @@
1
+ // src/validation.ts
2
+ var FORM_ERROR_KEY = "";
3
+ function issuesToErrors(issues) {
4
+ const errors = {};
5
+ for (const issue of issues ?? []) {
6
+ const key = issue.path.map(String).join(".");
7
+ (errors[key] ??= []).push(issue.message);
8
+ }
9
+ return errors;
10
+ }
11
+ function validate(schema, value) {
12
+ const result = schema.safeParse(value);
13
+ return result.success ? { ok: true, data: result.data } : { ok: false, errors: issuesToErrors(result.error.issues) };
14
+ }
15
+ function errorsFromFailure(failure) {
16
+ if (typeof failure !== "object" || failure === null) return void 0;
17
+ const { status, issues } = failure;
18
+ if (status !== 400 || !Array.isArray(issues)) return void 0;
19
+ return issuesToErrors(issues);
20
+ }
21
+
22
+ export {
23
+ FORM_ERROR_KEY,
24
+ issuesToErrors,
25
+ validate,
26
+ errorsFromFailure
27
+ };
package/dist/cli.js ADDED
@@ -0,0 +1,93 @@
1
+ import {
2
+ BUILD_PRESETS,
3
+ assertBuildPreset,
4
+ resolveConfig
5
+ } from "./chunk-NX6BO7UB.js";
6
+ import "./chunk-ELXCFUA4.js";
7
+ import "./chunk-FIJJ3EGL.js";
8
+
9
+ // src/cli.ts
10
+ import path2 from "path";
11
+
12
+ // src/load-config.ts
13
+ import { existsSync } from "fs";
14
+ import path from "path";
15
+ import { createJiti } from "jiti";
16
+ var CONFIG_FILES = [
17
+ "noofpi.config.ts",
18
+ "noofpi.config.mts",
19
+ "noofpi.config.js",
20
+ "noofpi.config.mjs"
21
+ ];
22
+ async function loadConfig(root) {
23
+ const file = CONFIG_FILES.map((name) => path.join(root, name)).find(
24
+ existsSync
25
+ );
26
+ if (!file) return resolveConfig({});
27
+ const jiti = createJiti(import.meta.url, { interopDefault: true });
28
+ const loaded = await jiti.import(
29
+ file
30
+ );
31
+ const config = loaded && "default" in loaded ? loaded.default : loaded;
32
+ return resolveConfig(config);
33
+ }
34
+
35
+ // src/cli.ts
36
+ var USAGE = `noofpi <command> [options]
37
+
38
+ Commands:
39
+ dev Start the dev server with live reload
40
+ build Build for production into .output/
41
+ start Run the production build
42
+
43
+ Options:
44
+ --root <dir> Project root (default: current directory)
45
+ --port <port> Server port
46
+ --host <host> Server host
47
+ --preset <name> Build target: ${BUILD_PRESETS.join(" | ")} (default: build.preset or node)`;
48
+ function option(args, name) {
49
+ const index = args.indexOf(name);
50
+ return index === -1 ? void 0 : args[index + 1];
51
+ }
52
+ async function loadEnvFiles(root, mode) {
53
+ const { loadEnv } = await import("vite");
54
+ const env = loadEnv(mode, root, "");
55
+ for (const [key, value] of Object.entries(env)) {
56
+ process.env[key] ??= value;
57
+ }
58
+ }
59
+ async function main() {
60
+ const [command, ...args] = process.argv.slice(2);
61
+ const root = path2.resolve(option(args, "--root") ?? process.cwd());
62
+ const portArg = option(args, "--port");
63
+ const overrides = {
64
+ port: portArg ? Number(portArg) : void 0,
65
+ host: option(args, "--host")
66
+ };
67
+ if (command !== "dev" && command !== "build" && command !== "start") {
68
+ console.log(USAGE);
69
+ process.exit(command ? 1 : 0);
70
+ }
71
+ process.env.NODE_ENV ??= command === "dev" ? "development" : "production";
72
+ await loadEnvFiles(root, command === "dev" ? "development" : "production");
73
+ const config = await loadConfig(root);
74
+ if (command === "dev") {
75
+ const { startDev } = await import("./dev-USSN6KFV.js");
76
+ await startDev(root, config, overrides);
77
+ } else if (command === "build") {
78
+ const { buildApp } = await import("./build-63DMFZJY.js");
79
+ const preset = option(args, "--preset");
80
+ await buildApp(
81
+ root,
82
+ config,
83
+ preset ? assertBuildPreset(preset, "--preset") : void 0
84
+ );
85
+ } else {
86
+ const { startProd } = await import("./start-U6A3PBRI.js");
87
+ await startProd(root, config, overrides);
88
+ }
89
+ }
90
+ main().catch((error) => {
91
+ console.error(error instanceof Error ? error.message : error);
92
+ process.exit(1);
93
+ });
@@ -0,0 +1,149 @@
1
+ import {
2
+ localUrl,
3
+ printBanner
4
+ } from "./chunk-WX2V6EYH.js";
5
+ import {
6
+ DEV_ENTRY,
7
+ createViteConfig,
8
+ htmlTemplate,
9
+ resolveCss,
10
+ resolveFonts
11
+ } from "./chunk-SSJ2KKBZ.js";
12
+ import {
13
+ isCloudflarePreset
14
+ } from "./chunk-NX6BO7UB.js";
15
+ import {
16
+ createHandler
17
+ } from "./chunk-2XCZWFIQ.js";
18
+ import "./chunk-MTXQR32N.js";
19
+ import {
20
+ sendWebResponse,
21
+ toWebRequest
22
+ } from "./chunk-NALDZ3PS.js";
23
+ import "./chunk-KGZP2RCF.js";
24
+ import "./chunk-ELXCFUA4.js";
25
+ import "./chunk-EZPJF4D4.js";
26
+ import "./chunk-G35DW4NA.js";
27
+ import "./chunk-FIJJ3EGL.js";
28
+ import "./chunk-Y3NBZ6DW.js";
29
+
30
+ // src/vite/dev.ts
31
+ import { createServer as createHttpServer } from "http";
32
+ import path2 from "path";
33
+ import { createServer as createViteServer, normalizePath } from "vite";
34
+
35
+ // src/shortcuts.ts
36
+ import { spawn } from "child_process";
37
+ function openBrowser(url) {
38
+ const [command, args] = process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : process.platform === "darwin" ? ["open", [url]] : ["xdg-open", [url]];
39
+ const child = spawn(command, args, { stdio: "ignore", detached: true });
40
+ child.on("error", () => console.log(` Could not open the browser: ${url}`));
41
+ child.unref();
42
+ }
43
+ function bindShortcuts(options) {
44
+ const { stdin } = process;
45
+ if (!stdin.isTTY || !process.stdout.isTTY) return false;
46
+ let closing = false;
47
+ const quit = () => {
48
+ if (closing) return;
49
+ closing = true;
50
+ options.close().finally(() => process.exit(0));
51
+ };
52
+ stdin.setRawMode(true);
53
+ stdin.setEncoding("utf-8");
54
+ stdin.resume();
55
+ stdin.on("data", (key) => {
56
+ if (key === "" || key.toLowerCase() === "q") quit();
57
+ else if (key.toLowerCase() === "b") openBrowser(options.url);
58
+ });
59
+ return true;
60
+ }
61
+
62
+ // src/vite/platform.ts
63
+ import { existsSync } from "fs";
64
+ import { createRequire } from "module";
65
+ import path from "path";
66
+ import { pathToFileURL } from "url";
67
+ var WRANGLER_CONFIGS = ["wrangler.json", "wrangler.jsonc", "wrangler.toml"];
68
+ async function startPlatformProxy(root, config) {
69
+ if (!isCloudflarePreset(config.build.preset)) return void 0;
70
+ let entry;
71
+ try {
72
+ entry = createRequire(path.join(root, "package.json")).resolve("wrangler");
73
+ } catch {
74
+ console.warn(
75
+ "[noofpi] Cloudflare bindings are not available in dev: install wrangler (`wrangler` devDependency)"
76
+ );
77
+ return void 0;
78
+ }
79
+ const { getPlatformProxy } = await import(pathToFileURL(entry).href);
80
+ const configPath = WRANGLER_CONFIGS.map((file) => path.join(root, file)).find(
81
+ existsSync
82
+ );
83
+ return getPlatformProxy({ configPath });
84
+ }
85
+
86
+ // src/vite/dev.ts
87
+ async function startDev(root, config, overrides) {
88
+ const startedAt = performance.now();
89
+ const port = overrides.port ?? config.devServer.port;
90
+ const host = overrides.host ?? config.devServer.host;
91
+ const httpServer = createHttpServer();
92
+ const fonts = await resolveFonts(root, config);
93
+ const vite = await createViteServer(
94
+ createViteConfig(
95
+ root,
96
+ {
97
+ ...config,
98
+ vite: {
99
+ ...config.vite,
100
+ server: { middlewareMode: true, hmr: { server: httpServer } }
101
+ }
102
+ },
103
+ "dev",
104
+ fonts
105
+ )
106
+ );
107
+ const stylesheets = resolveCss(root, config, fonts).map((file) => {
108
+ const relative = path2.relative(root, file);
109
+ const outside = relative.startsWith("..") || path2.isAbsolute(relative);
110
+ const url = outside ? "/@fs/" + normalizePath(file) : "/" + normalizePath(relative);
111
+ return url + "?direct";
112
+ });
113
+ const platform = await startPlatformProxy(root, config);
114
+ const handler = createHandler({
115
+ load: () => vite.ssrLoadModule("virtual:noofpi/server"),
116
+ getTemplate: (url) => vite.transformIndexHtml(url, htmlTemplate(DEV_ENTRY, stylesheets)),
117
+ onError: (error) => {
118
+ if (error instanceof Error) vite.ssrFixStacktrace(error);
119
+ console.error(error);
120
+ }
121
+ });
122
+ httpServer.on("request", (req, res) => {
123
+ vite.middlewares(req, res, () => {
124
+ handler(toWebRequest(req), platform?.env).then(
125
+ (response) => sendWebResponse(res, response),
126
+ (error) => {
127
+ console.error(error);
128
+ res.statusCode = 500;
129
+ res.end("Internal Server Error");
130
+ }
131
+ );
132
+ });
133
+ });
134
+ await new Promise((resolve) => httpServer.listen(port, host, resolve));
135
+ vite.ssrLoadModule("virtual:noofpi/server").catch(() => {
136
+ });
137
+ for (const url of stylesheets) vite.warmupRequest(url).catch(() => {
138
+ });
139
+ const close = () => Promise.all([vite.close(), platform?.dispose()]).then(() => {
140
+ httpServer.closeAllConnections();
141
+ httpServer.close();
142
+ });
143
+ const shortcuts = bindShortcuts({ url: localUrl(host, port), close });
144
+ printBanner({ mode: "development", host, port, startedAt, shortcuts });
145
+ return { vite, httpServer, close };
146
+ }
147
+ export {
148
+ startDev
149
+ };