@getcronit/pylon 3.0.0-canary-20250312165655.826d17474bf64dfdbd9e31dd76e4f3898d48a6d1 → 3.0.0-canary-20250313071016.ae6b1c56cc44cc99648aaee747ea420a05ed0f84

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/dist/index.js CHANGED
@@ -1207,7 +1207,991 @@ function getEnv() {
1207
1207
 
1208
1208
  // src/index.ts
1209
1209
  import { createPubSub } from "graphql-yoga";
1210
- import { usePages } from "@getcronit/pylon-pages";
1210
+
1211
+ // src/plugins/use-pages/setup/index.tsx
1212
+ import fs2 from "fs";
1213
+ import path3 from "path";
1214
+ import reactServer from "react-dom/server";
1215
+ import { trimTrailingSlash } from "hono/trailing-slash";
1216
+ import { StaticRouter } from "react-router";
1217
+ import { PassThrough, Readable } from "stream";
1218
+
1219
+ // src/plugins/use-pages/setup/app-loader.tsx
1220
+ import { useMemo } from "react";
1221
+ import { jsx } from "react/jsx-runtime";
1222
+ var AppLoader = (props) => {
1223
+ props.client.useHydrateCache({ cacheSnapshot: props.pylonData.cacheSnapshot });
1224
+ const data = props.client.useQuery();
1225
+ const page = useMemo(() => {
1226
+ const page2 = /* @__PURE__ */ jsx(
1227
+ props.App,
1228
+ {
1229
+ pageProps: {
1230
+ ...props.pylonData.pageProps,
1231
+ data
1232
+ }
1233
+ }
1234
+ );
1235
+ return page2;
1236
+ }, [props]);
1237
+ return /* @__PURE__ */ jsx(props.Router, { ...props.routerProps, children: page });
1238
+ };
1239
+
1240
+ // src/components/global-error-page.tsx
1241
+ import { useEffect } from "react";
1242
+
1243
+ // src/lib/utils.ts
1244
+ import { clsx } from "clsx";
1245
+ import { twMerge } from "tailwind-merge";
1246
+ function cn(...inputs) {
1247
+ return twMerge(clsx(inputs));
1248
+ }
1249
+
1250
+ // src/components/logo.tsx
1251
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
1252
+ var Logo = (props) => {
1253
+ return /* @__PURE__ */ jsxs(
1254
+ "svg",
1255
+ {
1256
+ className: cn("h-12 w-auto", props.className),
1257
+ xmlns: "http://www.w3.org/2000/svg",
1258
+ xmlnsXlink: "http://www.w3.org/1999/xlink",
1259
+ zoomAndPan: "magnify",
1260
+ viewBox: "0 0 286.5 121.500001",
1261
+ preserveAspectRatio: "xMidYMid meet",
1262
+ version: "1.0",
1263
+ children: [
1264
+ /* @__PURE__ */ jsxs("defs", { children: [
1265
+ /* @__PURE__ */ jsx2("g", {}),
1266
+ /* @__PURE__ */ jsx2("clipPath", { id: "38f6fcde47", children: /* @__PURE__ */ jsx2(
1267
+ "path",
1268
+ {
1269
+ d: "M 0.339844 42 L 10 42 L 10 79 L 0.339844 79 Z M 0.339844 42 ",
1270
+ clipRule: "nonzero"
1271
+ }
1272
+ ) }),
1273
+ /* @__PURE__ */ jsx2("clipPath", { id: "af000f7256", children: /* @__PURE__ */ jsx2(
1274
+ "path",
1275
+ {
1276
+ d: "M 64 23.925781 L 72.789062 23.925781 L 72.789062 96.378906 L 64 96.378906 Z M 64 23.925781 ",
1277
+ clipRule: "nonzero"
1278
+ }
1279
+ ) })
1280
+ ] }),
1281
+ /* @__PURE__ */ jsx2("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx2("g", { transform: "translate(107.11969, 78.49768)", children: /* @__PURE__ */ jsx2("g", { children: /* @__PURE__ */ jsx2("path", { d: "M 10.078125 -25.046875 C 11.109375 -26.398438 12.507812 -27.535156 14.28125 -28.453125 C 16.0625 -29.378906 18.070312 -29.84375 20.3125 -29.84375 C 22.863281 -29.84375 25.195312 -29.210938 27.3125 -27.953125 C 29.425781 -26.691406 31.085938 -24.921875 32.296875 -22.640625 C 33.503906 -20.367188 34.109375 -17.757812 34.109375 -14.8125 C 34.109375 -11.863281 33.503906 -9.222656 32.296875 -6.890625 C 31.085938 -4.566406 29.425781 -2.753906 27.3125 -1.453125 C 25.195312 -0.160156 22.863281 0.484375 20.3125 0.484375 C 18.070312 0.484375 16.078125 0.03125 14.328125 -0.875 C 12.585938 -1.78125 11.171875 -2.910156 10.078125 -4.265625 L 10.078125 13.96875 L 4 13.96875 L 4 -29.359375 L 10.078125 -29.359375 Z M 27.921875 -14.8125 C 27.921875 -16.84375 27.503906 -18.59375 26.671875 -20.0625 C 25.835938 -21.539062 24.734375 -22.660156 23.359375 -23.421875 C 21.992188 -24.179688 20.53125 -24.5625 18.96875 -24.5625 C 17.445312 -24.5625 16 -24.171875 14.625 -23.390625 C 13.257812 -22.609375 12.160156 -21.472656 11.328125 -19.984375 C 10.492188 -18.492188 10.078125 -16.734375 10.078125 -14.703125 C 10.078125 -12.679688 10.492188 -10.914062 11.328125 -9.40625 C 12.160156 -7.894531 13.257812 -6.75 14.625 -5.96875 C 16 -5.1875 17.445312 -4.796875 18.96875 -4.796875 C 20.53125 -4.796875 21.992188 -5.191406 23.359375 -5.984375 C 24.734375 -6.785156 25.835938 -7.953125 26.671875 -9.484375 C 27.503906 -11.015625 27.921875 -12.789062 27.921875 -14.8125 Z M 27.921875 -14.8125 " }) }) }) }),
1282
+ /* @__PURE__ */ jsx2("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx2("g", { transform: "translate(143.259256, 78.49768)", children: /* @__PURE__ */ jsx2("g", { children: /* @__PURE__ */ jsx2("path", { d: "M 30.4375 -29.359375 L 12.421875 13.796875 L 6.125 13.796875 L 12.09375 -0.484375 L 0.53125 -29.359375 L 7.296875 -29.359375 L 15.5625 -6.984375 L 24.140625 -29.359375 Z M 30.4375 -29.359375 " }) }) }) }),
1283
+ /* @__PURE__ */ jsx2("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx2("g", { transform: "translate(174.281707, 78.49768)", children: /* @__PURE__ */ jsx2("g", { children: /* @__PURE__ */ jsx2("path", { d: "M 10.078125 -39.4375 L 10.078125 0 L 4 0 L 4 -39.4375 Z M 10.078125 -39.4375 " }) }) }) }),
1284
+ /* @__PURE__ */ jsx2("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx2("g", { transform: "translate(188.353752, 78.49768)", children: /* @__PURE__ */ jsx2("g", { children: /* @__PURE__ */ jsx2("path", { d: "M 16.734375 0.484375 C 13.960938 0.484375 11.457031 -0.144531 9.21875 -1.40625 C 6.976562 -2.664062 5.21875 -4.441406 3.9375 -6.734375 C 2.664062 -9.035156 2.03125 -11.691406 2.03125 -14.703125 C 2.03125 -17.691406 2.6875 -20.335938 4 -22.640625 C 5.3125 -24.953125 7.101562 -26.726562 9.375 -27.96875 C 11.65625 -29.21875 14.195312 -29.84375 17 -29.84375 C 19.8125 -29.84375 22.351562 -29.21875 24.625 -27.96875 C 26.894531 -26.726562 28.6875 -24.953125 30 -22.640625 C 31.320312 -20.335938 31.984375 -17.691406 31.984375 -14.703125 C 31.984375 -11.722656 31.304688 -9.078125 29.953125 -6.765625 C 28.597656 -4.453125 26.757812 -2.664062 24.4375 -1.40625 C 22.113281 -0.144531 19.546875 0.484375 16.734375 0.484375 Z M 16.734375 -4.796875 C 18.296875 -4.796875 19.757812 -5.164062 21.125 -5.90625 C 22.5 -6.65625 23.613281 -7.773438 24.46875 -9.265625 C 25.320312 -10.765625 25.75 -12.578125 25.75 -14.703125 C 25.75 -16.835938 25.335938 -18.640625 24.515625 -20.109375 C 23.703125 -21.585938 22.617188 -22.695312 21.265625 -23.4375 C 19.910156 -24.1875 18.453125 -24.5625 16.890625 -24.5625 C 15.328125 -24.5625 13.878906 -24.1875 12.546875 -23.4375 C 11.210938 -22.695312 10.15625 -21.585938 9.375 -20.109375 C 8.59375 -18.640625 8.203125 -16.835938 8.203125 -14.703125 C 8.203125 -11.546875 9.007812 -9.101562 10.625 -7.375 C 12.25 -5.65625 14.285156 -4.796875 16.734375 -4.796875 Z M 16.734375 -4.796875 " }) }) }) }),
1285
+ /* @__PURE__ */ jsx2("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx2("g", { transform: "translate(222.361196, 78.49768)", children: /* @__PURE__ */ jsx2("g", { children: /* @__PURE__ */ jsx2("path", { d: "M 18.8125 -29.84375 C 21.125 -29.84375 23.191406 -29.363281 25.015625 -28.40625 C 26.847656 -27.445312 28.28125 -26.023438 29.3125 -24.140625 C 30.34375 -22.253906 30.859375 -19.984375 30.859375 -17.328125 L 30.859375 0 L 24.84375 0 L 24.84375 -16.421875 C 24.84375 -19.046875 24.179688 -21.054688 22.859375 -22.453125 C 21.546875 -23.859375 19.753906 -24.5625 17.484375 -24.5625 C 15.210938 -24.5625 13.410156 -23.859375 12.078125 -22.453125 C 10.742188 -21.054688 10.078125 -19.046875 10.078125 -16.421875 L 10.078125 0 L 4 0 L 4 -29.359375 L 10.078125 -29.359375 L 10.078125 -26.015625 C 11.066406 -27.222656 12.332031 -28.160156 13.875 -28.828125 C 15.425781 -29.503906 17.070312 -29.84375 18.8125 -29.84375 Z M 18.8125 -29.84375 " }) }) }) }),
1286
+ /* @__PURE__ */ jsx2(
1287
+ "path",
1288
+ {
1289
+ fill: "currentColor",
1290
+ d: "M 53.359375 31.652344 L 53.359375 88.6875 L 62.410156 90.859375 L 62.410156 29.484375 Z M 53.359375 31.652344 ",
1291
+ fillOpacity: "1",
1292
+ fillRule: "nonzero"
1293
+ }
1294
+ ),
1295
+ /* @__PURE__ */ jsx2("g", { clipPath: "url(#38f6fcde47)", children: /* @__PURE__ */ jsx2(
1296
+ "path",
1297
+ {
1298
+ fill: "currentColor",
1299
+ d: "M 0.339844 47.433594 L 0.339844 72.910156 C 0.339844 73.34375 0.410156 73.769531 0.554688 74.179688 C 0.699219 74.59375 0.90625 74.96875 1.175781 75.3125 C 1.445312 75.65625 1.765625 75.945312 2.132812 76.179688 C 2.503906 76.414062 2.898438 76.582031 3.324219 76.683594 L 9.390625 78.140625 L 9.390625 42.195312 L 3.3125 43.660156 C 2.890625 43.761719 2.492188 43.929688 2.125 44.164062 C 1.761719 44.402344 1.441406 44.6875 1.171875 45.03125 C 0.902344 45.375 0.695312 45.75 0.554688 46.164062 C 0.410156 46.574219 0.339844 46.996094 0.339844 47.433594 Z M 0.339844 47.433594 ",
1300
+ fillOpacity: "1",
1301
+ fillRule: "nonzero"
1302
+ }
1303
+ ) }),
1304
+ /* @__PURE__ */ jsx2("g", { clipPath: "url(#af000f7256)", children: /* @__PURE__ */ jsx2(
1305
+ "path",
1306
+ {
1307
+ fill: "currentColor",
1308
+ d: "M 64.996094 95.085938 L 64.996094 25.253906 C 64.996094 25.082031 65.027344 24.917969 65.09375 24.761719 C 65.160156 24.601562 65.253906 24.460938 65.375 24.339844 C 65.496094 24.21875 65.636719 24.125 65.792969 24.0625 C 65.953125 23.996094 66.117188 23.960938 66.289062 23.960938 L 71.460938 23.960938 C 71.632812 23.960938 71.796875 23.996094 71.957031 24.0625 C 72.113281 24.125 72.253906 24.21875 72.375 24.339844 C 72.496094 24.460938 72.589844 24.601562 72.65625 24.761719 C 72.722656 24.917969 72.753906 25.082031 72.753906 25.253906 L 72.753906 95.085938 C 72.753906 95.257812 72.722656 95.421875 72.65625 95.582031 C 72.589844 95.738281 72.496094 95.878906 72.375 96 C 72.253906 96.121094 72.113281 96.214844 71.957031 96.28125 C 71.796875 96.347656 71.632812 96.378906 71.460938 96.378906 L 66.289062 96.378906 C 66.117188 96.378906 65.953125 96.347656 65.792969 96.28125 C 65.636719 96.214844 65.496094 96.121094 65.375 96 C 65.253906 95.878906 65.160156 95.738281 65.09375 95.582031 C 65.027344 95.421875 64.996094 95.257812 64.996094 95.085938 Z M 64.996094 95.085938 ",
1309
+ fillOpacity: "1",
1310
+ fillRule: "nonzero"
1311
+ }
1312
+ ) }),
1313
+ /* @__PURE__ */ jsx2(
1314
+ "path",
1315
+ {
1316
+ fill: "currentColor",
1317
+ d: "M 22.320312 81.238281 L 22.320312 39.101562 L 11.976562 41.585938 L 11.976562 78.757812 Z M 22.320312 81.238281 ",
1318
+ fillOpacity: "1",
1319
+ fillRule: "nonzero"
1320
+ }
1321
+ ),
1322
+ /* @__PURE__ */ jsx2(
1323
+ "path",
1324
+ {
1325
+ fill: "currentColor",
1326
+ d: "M 50.769531 88.066406 L 50.769531 32.277344 L 37.839844 35.378906 L 37.839844 84.960938 Z M 50.769531 88.066406 ",
1327
+ fillOpacity: "1",
1328
+ fillRule: "nonzero"
1329
+ }
1330
+ ),
1331
+ /* @__PURE__ */ jsx2(
1332
+ "path",
1333
+ {
1334
+ fill: "currentColor",
1335
+ d: "M 24.90625 81.863281 L 35.253906 84.34375 L 35.253906 35.996094 L 24.90625 38.480469 Z M 24.90625 81.863281 ",
1336
+ fillOpacity: "1",
1337
+ fillRule: "nonzero"
1338
+ }
1339
+ )
1340
+ ]
1341
+ }
1342
+ );
1343
+ };
1344
+ var logo_default = Logo;
1345
+
1346
+ // src/components/global-error-page.tsx
1347
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
1348
+ function GlobalError({ error }) {
1349
+ useEffect(() => {
1350
+ console.error("Global error:", error);
1351
+ }, [error]);
1352
+ const reset = () => {
1353
+ window.location.reload();
1354
+ };
1355
+ return /* @__PURE__ */ jsxs2("html", { lang: "en", children: [
1356
+ /* @__PURE__ */ jsxs2("head", { children: [
1357
+ /* @__PURE__ */ jsx3("meta", { charSet: "utf-8" }),
1358
+ /* @__PURE__ */ jsx3("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }),
1359
+ /* @__PURE__ */ jsx3(
1360
+ "link",
1361
+ {
1362
+ rel: "stylesheet",
1363
+ href: "/__pylon/static/pylon.css",
1364
+ precedence: "high"
1365
+ }
1366
+ )
1367
+ ] }),
1368
+ /* @__PURE__ */ jsx3("body", { children: /* @__PURE__ */ jsx3("div", { className: "fixed inset-0 bg-black/90 z-50 overflow-y-auto p-4 flex items-center justify-center", children: /* @__PURE__ */ jsxs2("div", { className: "w-full max-w-3xl bg-black border border-red-600 rounded-lg overflow-hidden text-white font-sans", children: [
1369
+ /* @__PURE__ */ jsx3("div", { className: "flex items-center justify-between border-b border-neutral-800 p-4", children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-3", children: [
1370
+ /* @__PURE__ */ jsx3("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx3(logo_default, { className: "h-8 w-auto text-white" }) }),
1371
+ /* @__PURE__ */ jsx3("div", { children: /* @__PURE__ */ jsx3("h1", { className: "text-xl font-medium text-red-500", children: "Application Crashed" }) })
1372
+ ] }) }),
1373
+ /* @__PURE__ */ jsxs2("div", { className: "p-4", children: [
1374
+ /* @__PURE__ */ jsx3("div", { className: "mb-4 text-neutral-400", children: "The application encountered a critical error and could not continue." }),
1375
+ /* @__PURE__ */ jsx3("h2", { className: "text-2xl font-bold mb-4 text-white", children: error.message || "A critical error occurred" }),
1376
+ error.digest && /* @__PURE__ */ jsxs2("div", { className: "mb-4", children: [
1377
+ /* @__PURE__ */ jsx3("h3", { className: "text-sm uppercase tracking-wider text-neutral-500 font-medium mb-2", children: "Error ID" }),
1378
+ /* @__PURE__ */ jsx3("div", { className: "bg-neutral-900 rounded-md p-3 text-neutral-300 font-mono", children: error.digest })
1379
+ ] })
1380
+ ] })
1381
+ ] }) }) })
1382
+ ] });
1383
+ }
1384
+
1385
+ // src/plugins/use-pages/setup/index.tsx
1386
+ import { tmpdir } from "os";
1387
+ import { pipeline } from "stream/promises";
1388
+ import { createHash } from "crypto";
1389
+ import { jsx as jsx4 } from "react/jsx-runtime";
1390
+ var disableCacheMiddleware = async (c, next) => {
1391
+ const env3 = getEnv();
1392
+ if (env3.NODE_ENV === "development") {
1393
+ c.header(
1394
+ "Cache-Control",
1395
+ "no-store, no-cache, must-revalidate, proxy-revalidate"
1396
+ );
1397
+ c.header("Pragma", "no-cache");
1398
+ c.header("Expires", "0");
1399
+ c.header("Surrogate-Control", "no-store");
1400
+ }
1401
+ return next();
1402
+ };
1403
+ var setup = (app2) => {
1404
+ const pagesFilePath = path3.resolve(process.cwd(), ".pylon", "pages.json");
1405
+ let pageRoutes = [];
1406
+ try {
1407
+ pageRoutes = JSON.parse(fs2.readFileSync(pagesFilePath, "utf-8"));
1408
+ } catch (error) {
1409
+ console.error("Error reading pages.json", error);
1410
+ }
1411
+ app2.use(trimTrailingSlash());
1412
+ let App = void 0;
1413
+ let client = void 0;
1414
+ app2.on(
1415
+ "GET",
1416
+ pageRoutes.map((pageRoute) => pageRoute.slug),
1417
+ disableCacheMiddleware,
1418
+ async (c) => {
1419
+ try {
1420
+ if (!App) {
1421
+ const module = await import(`${process.cwd()}/.pylon/__pylon/pages/app.js`);
1422
+ App = module.default;
1423
+ }
1424
+ if (!client) {
1425
+ client = await import(`${process.cwd()}/.pylon/client/index.js`);
1426
+ }
1427
+ const pageProps = {
1428
+ params: c.req.param(),
1429
+ searchParams: c.req.query(),
1430
+ path: c.req.path
1431
+ };
1432
+ let cacheSnapshot = void 0;
1433
+ try {
1434
+ const prepared = await client.prepareReactRender(
1435
+ /* @__PURE__ */ jsx4(
1436
+ AppLoader,
1437
+ {
1438
+ Router: StaticRouter,
1439
+ routerProps: {
1440
+ location: c.req.path
1441
+ },
1442
+ App,
1443
+ client,
1444
+ pylonData: {
1445
+ pageProps,
1446
+ cacheSnapshot: void 0
1447
+ }
1448
+ }
1449
+ )
1450
+ );
1451
+ cacheSnapshot = prepared.cacheSnapshot;
1452
+ } catch (error) {
1453
+ }
1454
+ if (reactServer.renderToReadableStream) {
1455
+ try {
1456
+ const stream = await reactServer.renderToReadableStream(
1457
+ /* @__PURE__ */ jsx4(
1458
+ AppLoader,
1459
+ {
1460
+ Router: StaticRouter,
1461
+ routerProps: {
1462
+ location: c.req.path
1463
+ },
1464
+ App,
1465
+ client,
1466
+ pylonData: {
1467
+ pageProps,
1468
+ cacheSnapshot
1469
+ }
1470
+ }
1471
+ ),
1472
+ {
1473
+ bootstrapModules: ["/__pylon/static/app.js"],
1474
+ bootstrapScriptContent: `window.__PYLON_DATA__ = ${JSON.stringify(
1475
+ {
1476
+ pageProps,
1477
+ cacheSnapshot
1478
+ }
1479
+ )}`
1480
+ }
1481
+ );
1482
+ return c.body(stream);
1483
+ } catch (error) {
1484
+ throw error;
1485
+ }
1486
+ } else if (reactServer.renderToPipeableStream) {
1487
+ return await new Promise((resolve, reject) => {
1488
+ const { pipe } = reactServer.renderToPipeableStream(
1489
+ /* @__PURE__ */ jsx4(
1490
+ AppLoader,
1491
+ {
1492
+ Router: StaticRouter,
1493
+ routerProps: {
1494
+ location: c.req.path
1495
+ },
1496
+ App,
1497
+ client,
1498
+ pylonData: {
1499
+ pageProps,
1500
+ cacheSnapshot
1501
+ }
1502
+ }
1503
+ ),
1504
+ {
1505
+ bootstrapModules: ["/__pylon/static/app.js"],
1506
+ bootstrapScriptContent: `window.__PYLON_DATA__ = ${JSON.stringify(
1507
+ {
1508
+ pageProps,
1509
+ cacheSnapshot
1510
+ }
1511
+ )}`,
1512
+ onShellReady: async () => {
1513
+ c.header("Content-Type", "text/html");
1514
+ const passThrough = new PassThrough();
1515
+ pipe(passThrough);
1516
+ resolve(c.body(Readable.toWeb(passThrough)));
1517
+ },
1518
+ onShellError: async (error) => {
1519
+ reject(error);
1520
+ }
1521
+ }
1522
+ );
1523
+ });
1524
+ } else {
1525
+ throw new Error("Environment not supported");
1526
+ }
1527
+ } catch (error) {
1528
+ c.header("Content-Type", "text/html");
1529
+ c.status(500);
1530
+ return c.html(
1531
+ reactServer.renderToString(/* @__PURE__ */ jsx4(GlobalError, { error }))
1532
+ );
1533
+ }
1534
+ }
1535
+ );
1536
+ const publicFilesPath = path3.resolve(
1537
+ process.cwd(),
1538
+ ".pylon",
1539
+ "__pylon",
1540
+ "public"
1541
+ );
1542
+ let publicFiles = [];
1543
+ try {
1544
+ publicFiles = fs2.readdirSync(publicFilesPath);
1545
+ } catch (error) {
1546
+ }
1547
+ app2.on(
1548
+ "GET",
1549
+ publicFiles.map((file) => `/${file}`),
1550
+ disableCacheMiddleware,
1551
+ async (c) => {
1552
+ const publicFilePath = path3.resolve(
1553
+ process.cwd(),
1554
+ ".pylon",
1555
+ "__pylon",
1556
+ "public",
1557
+ c.req.path.replace("/", "")
1558
+ );
1559
+ try {
1560
+ await fs2.promises.access(publicFilePath);
1561
+ if (publicFilePath.endsWith(".js")) {
1562
+ c.res.headers.set("Content-Type", "text/javascript");
1563
+ } else if (publicFilePath.endsWith(".css")) {
1564
+ c.res.headers.set("Content-Type", "text/css");
1565
+ } else if (publicFilePath.endsWith(".html")) {
1566
+ c.res.headers.set("Content-Type", "text/html");
1567
+ } else if (publicFilePath.endsWith(".json")) {
1568
+ c.res.headers.set("Content-Type", "application/json");
1569
+ } else if (publicFilePath.endsWith(".png")) {
1570
+ c.res.headers.set("Content-Type", "image/png");
1571
+ } else if (publicFilePath.endsWith(".jpg") || publicFilePath.endsWith(".jpeg")) {
1572
+ c.res.headers.set("Content-Type", "image/jpeg");
1573
+ } else if (publicFilePath.endsWith(".gif")) {
1574
+ c.res.headers.set("Content-Type", "image/gif");
1575
+ } else if (publicFilePath.endsWith(".svg")) {
1576
+ c.res.headers.set("Content-Type", "image/svg+xml");
1577
+ } else if (publicFilePath.endsWith(".ico")) {
1578
+ c.res.headers.set("Content-Type", "image/x-icon");
1579
+ } else if (publicFilePath.endsWith(".map")) {
1580
+ c.res.headers.set("Content-Type", "application/json");
1581
+ }
1582
+ const stream = fs2.createReadStream(publicFilePath);
1583
+ const webStream = Readable.toWeb(stream);
1584
+ return c.body(webStream);
1585
+ } catch {
1586
+ return c.status(404);
1587
+ }
1588
+ }
1589
+ );
1590
+ app2.get("/__pylon/static/*", disableCacheMiddleware, async (c) => {
1591
+ const filePath = path3.resolve(
1592
+ process.cwd(),
1593
+ ".pylon",
1594
+ "__pylon",
1595
+ "static",
1596
+ c.req.path.replace("/__pylon/static/", "")
1597
+ );
1598
+ if (!fs2.existsSync(filePath)) {
1599
+ return c.notFound();
1600
+ }
1601
+ if (filePath.endsWith(".js")) {
1602
+ c.res.headers.set("Content-Type", "text/javascript");
1603
+ } else if (filePath.endsWith(".css")) {
1604
+ c.res.headers.set("Content-Type", "text/css");
1605
+ } else if (filePath.endsWith(".html")) {
1606
+ c.res.headers.set("Content-Type", "text/html");
1607
+ } else if (filePath.endsWith(".json") || filePath.endsWith(".map")) {
1608
+ c.res.headers.set("Content-Type", "application/json");
1609
+ } else if (filePath.endsWith(".png")) {
1610
+ c.res.headers.set("Content-Type", "image/png");
1611
+ } else if (filePath.endsWith(".jpg") || filePath.endsWith(".jpeg")) {
1612
+ c.res.headers.set("Content-Type", "image/jpeg");
1613
+ } else if (filePath.endsWith(".gif")) {
1614
+ c.res.headers.set("Content-Type", "image/gif");
1615
+ } else if (filePath.endsWith(".svg")) {
1616
+ c.res.headers.set("Content-Type", "image/svg+xml");
1617
+ } else if (filePath.endsWith(".ico")) {
1618
+ c.res.headers.set("Content-Type", "image/x-icon");
1619
+ }
1620
+ const stream = fs2.createReadStream(filePath);
1621
+ const webStream = Readable.toWeb(stream);
1622
+ return c.body(webStream);
1623
+ });
1624
+ app2.get("/__pylon/image", async (c) => {
1625
+ try {
1626
+ let isSupportedFormat2 = function(format2) {
1627
+ const supportedFormats = sharp.format;
1628
+ return Object.keys(supportedFormats).includes(format2);
1629
+ };
1630
+ var isSupportedFormat = isSupportedFormat2;
1631
+ const sharp = (await import("sharp")).default;
1632
+ const { src, w, h, q = "75", format = "webp" } = c.req.query();
1633
+ const queryStringHash = createHash("sha256").update(JSON.stringify(c.req.query())).digest("hex");
1634
+ if (!src) {
1635
+ return c.json({ error: "Missing parameters." }, 400);
1636
+ }
1637
+ let imagePath = path3.join(process.cwd(), ".pylon", src);
1638
+ if (src.startsWith("http://") || src.startsWith("https://")) {
1639
+ imagePath = await downloadImage(src);
1640
+ }
1641
+ try {
1642
+ await fs2.promises.access(imagePath);
1643
+ } catch {
1644
+ return c.json({ error: "Image not found" }, 404);
1645
+ }
1646
+ const metadata = await sharp(imagePath).metadata();
1647
+ if (!metadata.width || !metadata.height) {
1648
+ return c.json(
1649
+ {
1650
+ error: "Invalid image metadata. Width and height are required for resizing."
1651
+ },
1652
+ 400
1653
+ );
1654
+ }
1655
+ const { width: finalWidth, height: finalHeight } = calculateDimensions(
1656
+ metadata.width,
1657
+ metadata.height,
1658
+ w ? parseInt(w) : void 0,
1659
+ h ? parseInt(h) : void 0
1660
+ );
1661
+ const cachePath = path3.join(IMAGE_CACHE_DIR, queryStringHash);
1662
+ let imageFormat = format.toLowerCase();
1663
+ if (!isSupportedFormat2(imageFormat)) {
1664
+ throw new Error("Unsupported image format");
1665
+ }
1666
+ const quality = parseInt(q);
1667
+ if (IS_IMAGE_CACHE_POSSIBLE) {
1668
+ const image = await sharp(imagePath).resize(finalWidth, finalHeight).toFormat(imageFormat, {
1669
+ quality
1670
+ }).toFile(cachePath);
1671
+ c.res.headers.set("Content-Type", getContentType(image.format));
1672
+ return c.body(
1673
+ Readable.toWeb(
1674
+ fs2.createReadStream(cachePath)
1675
+ )
1676
+ );
1677
+ } else {
1678
+ const image = await sharp(imagePath).resize(finalWidth, finalHeight).toFormat(imageFormat, {
1679
+ quality
1680
+ }).toBuffer({ resolveWithObject: true });
1681
+ c.res.headers.set("Content-Type", getContentType(image.info.format));
1682
+ return c.body(image.data);
1683
+ }
1684
+ } catch (error) {
1685
+ console.error("Error processing the image:", error);
1686
+ return c.json({ error: "Error processing the image" }, 500);
1687
+ }
1688
+ });
1689
+ };
1690
+ var IMAGE_CACHE_DIR = path3.join(process.cwd(), ".cache/__pylon/images");
1691
+ var IS_IMAGE_CACHE_POSSIBLE = true;
1692
+ try {
1693
+ await fs2.promises.mkdir(IMAGE_CACHE_DIR, { recursive: true });
1694
+ } catch (error) {
1695
+ IS_IMAGE_CACHE_POSSIBLE = false;
1696
+ }
1697
+ var calculateDimensions = (originalWidth, originalHeight, width, height) => {
1698
+ if (!width && !height) {
1699
+ return { width: originalWidth, height: originalHeight };
1700
+ }
1701
+ if (width && !height) {
1702
+ height = Math.round(width * originalHeight / originalWidth);
1703
+ } else if (height && !width) {
1704
+ width = Math.round(height * originalWidth / originalHeight);
1705
+ }
1706
+ return { width, height };
1707
+ };
1708
+ var getContentType = (format) => {
1709
+ switch (format.toLowerCase()) {
1710
+ case "webp":
1711
+ return "image/webp";
1712
+ case "jpeg":
1713
+ case "jpg":
1714
+ return "image/jpeg";
1715
+ case "png":
1716
+ return "image/png";
1717
+ case "gif":
1718
+ return "image/gif";
1719
+ case "svg":
1720
+ return "image/svg+xml";
1721
+ default:
1722
+ return "application/octet-stream";
1723
+ }
1724
+ };
1725
+ var downloadImage = async (url) => {
1726
+ const response = await fetch(url);
1727
+ if (!response.ok)
1728
+ throw new Error(`Failed to download image: ${response.statusText}`);
1729
+ const ext = path3.extname(new URL(url).pathname) || ".jpg";
1730
+ const tempFilePath = path3.join(tmpdir(), `image-${Date.now()}${ext}`);
1731
+ const fileStream = fs2.createWriteStream(tempFilePath);
1732
+ await pipeline(response.body, fileStream);
1733
+ return tempFilePath;
1734
+ };
1735
+
1736
+ // src/plugins/use-pages/build/index.ts
1737
+ import path7 from "path";
1738
+
1739
+ // src/plugins/use-pages/build/app-utils.ts
1740
+ import path4 from "path";
1741
+ import glob from "tiny-glob";
1742
+ function fnv1aHash(str) {
1743
+ let hash = 2166136261;
1744
+ for (let i = 0; i < str.length; i++) {
1745
+ hash ^= str.charCodeAt(i);
1746
+ hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
1747
+ }
1748
+ return (hash >>> 0).toString(16);
1749
+ }
1750
+ var APP_DIR = path4.join(process.cwd(), "pages");
1751
+ async function getPageRoutes(dir = APP_DIR) {
1752
+ const routes = [];
1753
+ const pagePattern = path4.join(dir, "**/page.{ts,tsx,js}");
1754
+ const layoutPattern = path4.join(dir, "**/layout.tsx");
1755
+ const pageFiles = await glob(pagePattern);
1756
+ const layoutFiles = await glob(layoutPattern);
1757
+ for (const pagePath of pageFiles) {
1758
+ const relativePagePath = path4.relative(APP_DIR, pagePath);
1759
+ let slug = "/" + relativePagePath.replace(/page\.(ts|tsx|js)$/, "").replace(/\[([\w-]+)\]/g, ":$1");
1760
+ slug = slug.replace(/\/$/, "");
1761
+ const layouts = layoutFiles.filter((layout) => {
1762
+ return pagePath.startsWith(layout.replace("layout.tsx", ""));
1763
+ });
1764
+ const layoutsWithoutRootLayout = layouts.slice(1);
1765
+ routes.push({
1766
+ pagePath,
1767
+ slug: slug || "/",
1768
+ layouts: layoutsWithoutRootLayout
1769
+ });
1770
+ }
1771
+ return routes;
1772
+ }
1773
+ var generateAppFile = (pageRoutes) => {
1774
+ const makePageMap = (routes) => {
1775
+ const pageMap2 = {};
1776
+ for (const route of routes) {
1777
+ pageMap2[route.pagePath] = `Page${fnv1aHash(route.pagePath)}`;
1778
+ }
1779
+ return pageMap2;
1780
+ };
1781
+ const makeLayoutMap = (routes) => {
1782
+ const layoutMap2 = {};
1783
+ for (const route of routes) {
1784
+ for (const layout of route.layouts) {
1785
+ layoutMap2[layout] = `Layout${fnv1aHash(layout)}`;
1786
+ }
1787
+ }
1788
+ return layoutMap2;
1789
+ };
1790
+ const pageMap = makePageMap(pageRoutes);
1791
+ const layoutMap = makeLayoutMap(pageRoutes);
1792
+ const importPages = Object.keys(pageMap).map((pagePath, index) => {
1793
+ const importLocation = `../${pagePath}`.replace(".tsx", ".js");
1794
+ const componentName = pageMap[pagePath];
1795
+ return `const ${componentName} = lazy(() => import('${importLocation}'))
1796
+ `;
1797
+ }).join("\n");
1798
+ const importLayouts = Object.keys(layoutMap).map((layoutPath, index) => {
1799
+ const importLocation = `../${layoutPath}`.replace(".tsx", ".js");
1800
+ const componentName = layoutMap[layoutPath];
1801
+ return `const ${componentName} = lazy(() => import('${importLocation}'))
1802
+ `;
1803
+ }).join("\n");
1804
+ const appComponent = `"use client";
1805
+ import {lazy, Suspense} from 'react'
1806
+ import { __PYLON_ROUTER_INTERNALS_DO_NOT_USE, DevOverlay} from '@getcronit/pylon/pages';
1807
+ const {Routes, Route} = __PYLON_ROUTER_INTERNALS_DO_NOT_USE
1808
+ ${importPages}
1809
+ const RootLayout = lazy(() => import('../pages/layout.js'))
1810
+ ${importLayouts}
1811
+
1812
+ const App: React.FC<{pageProps: any}> = ({pageProps}) => (
1813
+ <DevOverlay>
1814
+ <RootLayout>
1815
+ <meta charSet="utf-8" />
1816
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
1817
+ <link rel="stylesheet" href="/__pylon/static/app.css" precedence="high" />
1818
+ <Routes>
1819
+ ${pageRoutes.map((route, index) => {
1820
+ return `<Route key={${index}} index={${index === 0 ? "true" : "false"}} path="${route.slug}" element={
1821
+ ${route.layouts.reduceRight((child, layoutPath, layoutIndex) => {
1822
+ const layoutName = layoutMap[layoutPath];
1823
+ return `<${layoutName}>${child}</${layoutName}>`;
1824
+ }, `<${pageMap[route.pagePath]} {...pageProps} />`)}
1825
+ } />`;
1826
+ }).join("\n")}
1827
+ </Routes>
1828
+ </RootLayout>
1829
+ </DevOverlay>
1830
+ );
1831
+
1832
+ export default App;
1833
+ `;
1834
+ return appComponent;
1835
+ };
1836
+
1837
+ // src/plugins/use-pages/build/index.ts
1838
+ import chokidar from "chokidar";
1839
+ import fs6 from "fs/promises";
1840
+ import esbuild from "esbuild";
1841
+
1842
+ // src/plugins/use-pages/build/plugins/inject-app-hydration.ts
1843
+ import path5 from "path";
1844
+ import fs3 from "fs/promises";
1845
+ var injectAppHydrationPlugin = {
1846
+ name: "inject-hydration",
1847
+ setup(build2) {
1848
+ build2.onLoad({ filter: /.*/, namespace: "file" }, async (args) => {
1849
+ if (args.path === path5.resolve(process.cwd(), ".pylon", "app.tsx")) {
1850
+ let contents = await fs3.readFile(args.path, "utf-8");
1851
+ const clientPath = path5.resolve(process.cwd(), ".pylon/client");
1852
+ const pathToClient = path5.relative(path5.dirname(args.path), clientPath);
1853
+ contents += `
1854
+ import {hydrateRoot} from 'react-dom/client'
1855
+ import * as client from './${pathToClient}'
1856
+ import { __PYLON_ROUTER_INTERNALS_DO_NOT_USE, DevOverlay, onCaughtErrorProd, onRecoverableErrorProd, onUncaughtErrorProd } from '@getcronit/pylon/pages';
1857
+ const {BrowserRouter} = __PYLON_ROUTER_INTERNALS_DO_NOT_USE
1858
+ import React, {useMemo} from 'react'
1859
+
1860
+ const pylonData = window.__PYLON_DATA__
1861
+
1862
+ const AppLoader = (props: {
1863
+ client: any
1864
+ pylonData: {
1865
+ pageProps: Omit<PageProps, 'data'>
1866
+ cacheSnapshot?: any
1867
+ }
1868
+ App: React.FC<{
1869
+ pageProps: PageProps
1870
+ }>
1871
+ Router: React.FC<any>
1872
+ routerProps: any
1873
+ }) => {
1874
+ props.client.useHydrateCache({cacheSnapshot: props.pylonData.cacheSnapshot})
1875
+
1876
+ const data = props.client.useQuery()
1877
+ const page = useMemo(() => {
1878
+ const page = (
1879
+ <props.App
1880
+ pageProps={{
1881
+ ...props.pylonData.pageProps,
1882
+ data
1883
+ }}
1884
+ />
1885
+ )
1886
+
1887
+ return page
1888
+ }, [props])
1889
+
1890
+ return <props.Router {...props.routerProps}>{page}</props.Router>
1891
+ }
1892
+
1893
+
1894
+
1895
+
1896
+ hydrateRoot(
1897
+ document,
1898
+ <AppLoader Router={BrowserRouter} client={client} pylonData={pylonData} App={App} />, {
1899
+ onCaughtError: onCaughtErrorProd,
1900
+ onRecoverableError: onRecoverableErrorProd,
1901
+ onUncaughtError: onUncaughtErrorProd,
1902
+ }
1903
+ )
1904
+ `;
1905
+ return {
1906
+ loader: "tsx",
1907
+ contents
1908
+ };
1909
+ }
1910
+ });
1911
+ }
1912
+ };
1913
+
1914
+ // src/plugins/use-pages/build/plugins/image-plugin.ts
1915
+ import { createHash as createHash2 } from "crypto";
1916
+ import path6 from "path";
1917
+ import fs4 from "fs/promises";
1918
+ var imagePlugin = {
1919
+ name: "image-plugin",
1920
+ setup(build2) {
1921
+ const outdir = build2.initialOptions.outdir;
1922
+ const publicPath = build2.initialOptions.publicPath;
1923
+ if (!outdir || !publicPath) {
1924
+ throw new Error("outdir and publicPath must be set in esbuild options");
1925
+ }
1926
+ build2.onResolve({ filter: /\.(png|jpe?g)$/ }, async (args) => {
1927
+ const filePath = path6.resolve(args.resolveDir, args.path);
1928
+ const fileName = path6.basename(filePath);
1929
+ const extname = path6.extname(filePath);
1930
+ const hash = createHash2("md5").update(filePath + await fs4.readFile(filePath)).digest("hex").slice(0, 8);
1931
+ const newFilename = `${fileName}-${hash}${extname}`;
1932
+ const newFilePath = path6.join(outdir, "media", newFilename);
1933
+ await fs4.mkdir(path6.dirname(newFilePath), { recursive: true });
1934
+ await fs4.copyFile(filePath, newFilePath);
1935
+ return {
1936
+ path: newFilePath,
1937
+ namespace: "image"
1938
+ };
1939
+ });
1940
+ build2.onLoad({ filter: /\.png$|\.jpg$/ }, async (args) => {
1941
+ const sharp = (await import("sharp")).default;
1942
+ const image = sharp(args.path);
1943
+ const metadata = await image.metadata();
1944
+ const url = `${publicPath}/media/${path6.basename(args.path)}`;
1945
+ const searchParams = new URLSearchParams({});
1946
+ if (metadata.width) {
1947
+ searchParams.set("w", metadata.width.toString());
1948
+ }
1949
+ if (metadata.height) {
1950
+ searchParams.set("h", metadata.height.toString());
1951
+ }
1952
+ const output = image.resize({
1953
+ width: Math.min(metadata.width ?? 16, 16),
1954
+ height: Math.min(metadata.height ?? 16, 16),
1955
+ fit: "inside"
1956
+ }).toFormat("webp", {
1957
+ quality: 20,
1958
+ alphaQuality: 20,
1959
+ smartSubsample: true
1960
+ });
1961
+ const { data, info } = await output.toBuffer({ resolveWithObject: true });
1962
+ const dataURIBase64 = `data:image/${info.format};base64,${data.toString(
1963
+ "base64"
1964
+ )}`;
1965
+ if (dataURIBase64) {
1966
+ searchParams.set("blurDataURL", dataURIBase64);
1967
+ }
1968
+ return {
1969
+ contents: `${url}?${searchParams.toString()}`,
1970
+ loader: "text"
1971
+ };
1972
+ });
1973
+ }
1974
+ };
1975
+
1976
+ // src/plugins/use-pages/build/plugins/postcss-plugin.ts
1977
+ import fs5 from "fs/promises";
1978
+ import loadConfig from "postcss-load-config";
1979
+ import postcss from "postcss";
1980
+ var postcssPlugin = {
1981
+ name: "postcss-plugin",
1982
+ setup(build2) {
1983
+ build2.onLoad({ filter: /.css$/, namespace: "file" }, async (args) => {
1984
+ const { plugins, options } = await loadConfig();
1985
+ const css = await fs5.readFile(args.path, "utf-8");
1986
+ const result = await postcss(plugins).process(css, {
1987
+ ...options,
1988
+ from: args.path
1989
+ }).then((result2) => result2);
1990
+ return {
1991
+ contents: result.css,
1992
+ loader: "css"
1993
+ };
1994
+ });
1995
+ }
1996
+ };
1997
+
1998
+ // src/plugins/use-pages/build/index.ts
1999
+ var DIST_STATIC_DIR = path7.join(process.cwd(), ".pylon/__pylon/static");
2000
+ var DIST_PAGES_DIR = path7.join(process.cwd(), ".pylon/__pylon/pages");
2001
+ async function updateFileIfChanged(path8, newContent) {
2002
+ try {
2003
+ const currentContent = await fs6.readFile(path8, "utf8");
2004
+ if (currentContent === newContent) {
2005
+ return false;
2006
+ }
2007
+ } catch (err) {
2008
+ if (err.code !== "ENOENT") throw err;
2009
+ }
2010
+ await fs6.writeFile(path8, newContent, "utf8");
2011
+ return true;
2012
+ }
2013
+ var build = async () => {
2014
+ const buildAppFile = async () => {
2015
+ const pagesRoutes = await getPageRoutes();
2016
+ const appContent = generateAppFile(pagesRoutes);
2017
+ const pagesFile = path7.resolve(process.cwd(), ".pylon", "pages.json");
2018
+ await updateFileIfChanged(pagesFile, JSON.stringify(pagesRoutes, null, 2));
2019
+ const appFilePath = path7.resolve(process.cwd(), ".pylon", "app.tsx");
2020
+ const state = await updateFileIfChanged(appFilePath, appContent);
2021
+ if (state) {
2022
+ }
2023
+ };
2024
+ const copyPublicDir = async () => {
2025
+ const publicDir = path7.resolve(process.cwd(), "public");
2026
+ const pylonPublicDir = path7.resolve(
2027
+ process.cwd(),
2028
+ ".pylon",
2029
+ "__pylon",
2030
+ "public"
2031
+ );
2032
+ try {
2033
+ await fs6.access(publicDir);
2034
+ await fs6.mkdir(pylonPublicDir, { recursive: true });
2035
+ await fs6.cp(publicDir, pylonPublicDir, { recursive: true });
2036
+ } catch (err) {
2037
+ if (err.code !== "ENOENT") throw err;
2038
+ }
2039
+ };
2040
+ const copyPylonCSS = async () => {
2041
+ const pylonCssPathDir = path7.join(
2042
+ process.cwd(),
2043
+ "node_modules",
2044
+ "@getcronit/pylon",
2045
+ "node_modules",
2046
+ "@getcronit/pylon-pages/dist/browser"
2047
+ );
2048
+ const pylonCssDestDir = path7.join(
2049
+ process.cwd(),
2050
+ ".pylon",
2051
+ "__pylon",
2052
+ "static"
2053
+ );
2054
+ await fs6.mkdir(pylonCssDestDir, { recursive: true });
2055
+ await fs6.cp(
2056
+ path7.join(pylonCssPathDir, "index.css"),
2057
+ path7.join(pylonCssDestDir, "pylon.css")
2058
+ );
2059
+ await fs6.cp(
2060
+ path7.join(pylonCssPathDir, "index.css.map"),
2061
+ path7.join(pylonCssDestDir, "pylon.css.map")
2062
+ );
2063
+ };
2064
+ const writeOnEndPlugin = {
2065
+ name: "write-on-end",
2066
+ setup(build2) {
2067
+ build2.onEnd(async (result) => {
2068
+ await Promise.all(
2069
+ result.outputFiles.map(async (file) => {
2070
+ await fs6.mkdir(path7.dirname(file.path), { recursive: true });
2071
+ await updateFileIfChanged(file.path, file.text);
2072
+ })
2073
+ );
2074
+ });
2075
+ }
2076
+ };
2077
+ const nodePaths = [
2078
+ path7.join(process.cwd(), "node_modules"),
2079
+ path7.join(process.cwd(), "node_modules", "@getcronit/pylon/node_modules")
2080
+ ];
2081
+ let pagesWatcher = null;
2082
+ const clientCtx = await esbuild.context({
2083
+ sourcemap: "linked",
2084
+ write: false,
2085
+ metafile: true,
2086
+ nodePaths,
2087
+ absWorkingDir: process.cwd(),
2088
+ plugins: [
2089
+ injectAppHydrationPlugin,
2090
+ imagePlugin,
2091
+ postcssPlugin,
2092
+ writeOnEndPlugin
2093
+ ],
2094
+ publicPath: "/__pylon/static",
2095
+ assetNames: "assets/[name]-[hash]",
2096
+ chunkNames: "chunks/[name]-[hash]",
2097
+ format: "esm",
2098
+ platform: "browser",
2099
+ entryPoints: [".pylon/app.tsx"],
2100
+ outdir: DIST_STATIC_DIR,
2101
+ bundle: true,
2102
+ splitting: true,
2103
+ minify: false,
2104
+ loader: {
2105
+ // Map file extensions to the file loader
2106
+ ".svg": "file",
2107
+ ".woff": "file",
2108
+ ".woff2": "file"
2109
+ },
2110
+ define: {
2111
+ "process.env.NODE_ENV": JSON.stringify(
2112
+ process.env.NODE_ENV || "development"
2113
+ )
2114
+ },
2115
+ mainFields: ["browser", "module", "main"]
2116
+ });
2117
+ const serverCtx = await esbuild.context({
2118
+ sourcemap: "inline",
2119
+ write: false,
2120
+ absWorkingDir: process.cwd(),
2121
+ nodePaths,
2122
+ plugins: [imagePlugin, postcssPlugin, writeOnEndPlugin],
2123
+ publicPath: "/__pylon/static",
2124
+ assetNames: "assets/[name]-[hash]",
2125
+ chunkNames: "chunks/[name]-[hash]",
2126
+ format: "esm",
2127
+ platform: "node",
2128
+ entryPoints: [".pylon/app.tsx"],
2129
+ outdir: DIST_PAGES_DIR,
2130
+ bundle: true,
2131
+ splitting: false,
2132
+ external: [
2133
+ "@getcronit/pylon",
2134
+ "@getcronit/pylon-pages",
2135
+ "react",
2136
+ "react-dom",
2137
+ "gqty",
2138
+ "@gqty/react"
2139
+ ],
2140
+ minify: true,
2141
+ loader: {
2142
+ // Map file extensions to the file loader
2143
+ ".svg": "file",
2144
+ ".woff": "file",
2145
+ ".woff2": "file"
2146
+ },
2147
+ define: {
2148
+ "process.env.NODE_ENV": JSON.stringify(
2149
+ process.env.NODE_ENV || "development"
2150
+ )
2151
+ },
2152
+ mainFields: ["module", "main"]
2153
+ });
2154
+ return {
2155
+ watch: async () => {
2156
+ pagesWatcher = chokidar.watch("pages", { ignoreInitial: true });
2157
+ pagesWatcher.on("all", async (event, path8) => {
2158
+ if (["add", "change", "unlink"].includes(event)) {
2159
+ await buildAppFile();
2160
+ await copyPublicDir();
2161
+ await copyPylonCSS();
2162
+ }
2163
+ });
2164
+ await Promise.all([clientCtx.watch(), serverCtx.watch()]);
2165
+ },
2166
+ dispose: async () => {
2167
+ if (pagesWatcher) {
2168
+ pagesWatcher.close();
2169
+ }
2170
+ Promise.all([clientCtx.dispose(), serverCtx.dispose()]);
2171
+ },
2172
+ rebuild: async () => {
2173
+ await buildAppFile();
2174
+ await copyPublicDir();
2175
+ await copyPylonCSS();
2176
+ await Promise.all([clientCtx.rebuild(), serverCtx.rebuild()]);
2177
+ return {};
2178
+ },
2179
+ cancel: async () => {
2180
+ if (pagesWatcher) {
2181
+ await pagesWatcher.close();
2182
+ }
2183
+ await Promise.all([clientCtx.cancel(), serverCtx.cancel()]);
2184
+ }
2185
+ };
2186
+ };
2187
+
2188
+ // src/plugins/use-pages/index.ts
2189
+ function usePages() {
2190
+ return {
2191
+ setup,
2192
+ build
2193
+ };
2194
+ }
1211
2195
  export {
1212
2196
  ServiceError,
1213
2197
  app,