@getcronit/pylon 3.0.0-canary-20250328121549.7ad3dbef94d4506f66f9e5e084c9f1eedf4ad6e8 → 3.0.0-canary-20250407104538.a60dfeae82297f043070d0cbbaf98568962159d4
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/app/pylon-handler.d.ts +1 -1
- package/dist/components/global-error-page.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +290 -341
- package/dist/index.js.map +4 -4
- package/dist/pages/index.d.ts +2 -0
- package/dist/pages/index.js +109 -41
- package/dist/pages/index.js.map +4 -4
- package/dist/pages/internals.d.ts +6 -0
- package/dist/plugins/use-pages/build/app-utils.d.ts +7 -6
- package/package.json +1 -1
- package/dist/plugins/use-pages/setup/app-loader.d.ts +0 -13
package/dist/index.js
CHANGED
|
@@ -878,7 +878,7 @@ function useViewer() {
|
|
|
878
878
|
import { html as html2 } from "hono/html";
|
|
879
879
|
|
|
880
880
|
// package.json
|
|
881
|
-
var version = "3.0.0-canary-
|
|
881
|
+
var version = "3.0.0-canary-20250407104538.a60dfeae82297f043070d0cbbaf98568962159d4";
|
|
882
882
|
|
|
883
883
|
// src/plugins/use-unhandled-route.ts
|
|
884
884
|
function useUnhandledRoute() {
|
|
@@ -1063,15 +1063,15 @@ import { useDisableIntrospection } from "@graphql-yoga/plugin-disable-introspect
|
|
|
1063
1063
|
var resolveLazyObject = (obj) => {
|
|
1064
1064
|
return typeof obj === "function" ? obj() : obj;
|
|
1065
1065
|
};
|
|
1066
|
-
var loadPluginsMiddleware = (plugins) => {
|
|
1066
|
+
var loadPluginsMiddleware = async (plugins) => {
|
|
1067
1067
|
for (const plugin of plugins) {
|
|
1068
|
-
plugin.setup?.(app);
|
|
1068
|
+
await plugin.setup?.(app);
|
|
1069
1069
|
if (plugin.middleware) {
|
|
1070
1070
|
pluginsMiddleware.push(plugin.middleware);
|
|
1071
1071
|
}
|
|
1072
1072
|
}
|
|
1073
1073
|
};
|
|
1074
|
-
var executeConfig = (config) => {
|
|
1074
|
+
var executeConfig = async (config) => {
|
|
1075
1075
|
const plugins = [useSentry(), useViewer(), ...config?.plugins || []];
|
|
1076
1076
|
if (config?.landingPage ?? true) {
|
|
1077
1077
|
plugins.push(useUnhandledRoute());
|
|
@@ -1079,7 +1079,7 @@ var executeConfig = (config) => {
|
|
|
1079
1079
|
if (config?.graphiql === false) {
|
|
1080
1080
|
plugins.push(useDisableIntrospection());
|
|
1081
1081
|
}
|
|
1082
|
-
loadPluginsMiddleware(plugins);
|
|
1082
|
+
await loadPluginsMiddleware(plugins);
|
|
1083
1083
|
config.plugins = plugins;
|
|
1084
1084
|
app.config = config;
|
|
1085
1085
|
};
|
|
@@ -1199,22 +1199,13 @@ import fs2 from "fs";
|
|
|
1199
1199
|
import path3 from "path";
|
|
1200
1200
|
import reactServer from "react-dom/server";
|
|
1201
1201
|
import { trimTrailingSlash } from "hono/trailing-slash";
|
|
1202
|
-
import {
|
|
1202
|
+
import {
|
|
1203
|
+
createStaticHandler,
|
|
1204
|
+
createStaticRouter,
|
|
1205
|
+
StaticRouterProvider
|
|
1206
|
+
} from "react-router";
|
|
1203
1207
|
import { PassThrough, Readable as Readable2 } from "stream";
|
|
1204
1208
|
|
|
1205
|
-
// src/plugins/use-pages/setup/app-loader.tsx
|
|
1206
|
-
import { useMemo } from "react";
|
|
1207
|
-
import { jsx } from "react/jsx-runtime";
|
|
1208
|
-
var AppLoader = (props) => {
|
|
1209
|
-
props.client.useHydrateCache({ cacheSnapshot: props.pylonData.cacheSnapshot });
|
|
1210
|
-
const data = props.client.useQuery();
|
|
1211
|
-
const page = useMemo(() => {
|
|
1212
|
-
const page2 = /* @__PURE__ */ jsx(props.App, { data });
|
|
1213
|
-
return page2;
|
|
1214
|
-
}, [props]);
|
|
1215
|
-
return /* @__PURE__ */ jsx(props.Router, { ...props.routerProps, children: page });
|
|
1216
|
-
};
|
|
1217
|
-
|
|
1218
1209
|
// src/components/global-error-page.tsx
|
|
1219
1210
|
import { useEffect } from "react";
|
|
1220
1211
|
|
|
@@ -1226,7 +1217,7 @@ function cn(...inputs) {
|
|
|
1226
1217
|
}
|
|
1227
1218
|
|
|
1228
1219
|
// src/components/logo.tsx
|
|
1229
|
-
import { jsx
|
|
1220
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1230
1221
|
var Logo = (props) => {
|
|
1231
1222
|
return /* @__PURE__ */ jsxs(
|
|
1232
1223
|
"svg",
|
|
@@ -1240,15 +1231,15 @@ var Logo = (props) => {
|
|
|
1240
1231
|
version: "1.0",
|
|
1241
1232
|
children: [
|
|
1242
1233
|
/* @__PURE__ */ jsxs("defs", { children: [
|
|
1243
|
-
/* @__PURE__ */
|
|
1244
|
-
/* @__PURE__ */
|
|
1234
|
+
/* @__PURE__ */ jsx("g", {}),
|
|
1235
|
+
/* @__PURE__ */ jsx("clipPath", { id: "38f6fcde47", children: /* @__PURE__ */ jsx(
|
|
1245
1236
|
"path",
|
|
1246
1237
|
{
|
|
1247
1238
|
d: "M 0.339844 42 L 10 42 L 10 79 L 0.339844 79 Z M 0.339844 42 ",
|
|
1248
1239
|
clipRule: "nonzero"
|
|
1249
1240
|
}
|
|
1250
1241
|
) }),
|
|
1251
|
-
/* @__PURE__ */
|
|
1242
|
+
/* @__PURE__ */ jsx("clipPath", { id: "af000f7256", children: /* @__PURE__ */ jsx(
|
|
1252
1243
|
"path",
|
|
1253
1244
|
{
|
|
1254
1245
|
d: "M 64 23.925781 L 72.789062 23.925781 L 72.789062 96.378906 L 64 96.378906 Z M 64 23.925781 ",
|
|
@@ -1256,12 +1247,12 @@ var Logo = (props) => {
|
|
|
1256
1247
|
}
|
|
1257
1248
|
) })
|
|
1258
1249
|
] }),
|
|
1259
|
-
/* @__PURE__ */
|
|
1260
|
-
/* @__PURE__ */
|
|
1261
|
-
/* @__PURE__ */
|
|
1262
|
-
/* @__PURE__ */
|
|
1263
|
-
/* @__PURE__ */
|
|
1264
|
-
/* @__PURE__ */
|
|
1250
|
+
/* @__PURE__ */ jsx("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx("g", { transform: "translate(107.11969, 78.49768)", children: /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx("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 " }) }) }) }),
|
|
1251
|
+
/* @__PURE__ */ jsx("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx("g", { transform: "translate(143.259256, 78.49768)", children: /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx("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 " }) }) }) }),
|
|
1252
|
+
/* @__PURE__ */ jsx("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx("g", { transform: "translate(174.281707, 78.49768)", children: /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx("path", { d: "M 10.078125 -39.4375 L 10.078125 0 L 4 0 L 4 -39.4375 Z M 10.078125 -39.4375 " }) }) }) }),
|
|
1253
|
+
/* @__PURE__ */ jsx("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx("g", { transform: "translate(188.353752, 78.49768)", children: /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx("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 " }) }) }) }),
|
|
1254
|
+
/* @__PURE__ */ jsx("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx("g", { transform: "translate(222.361196, 78.49768)", children: /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx("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 " }) }) }) }),
|
|
1255
|
+
/* @__PURE__ */ jsx(
|
|
1265
1256
|
"path",
|
|
1266
1257
|
{
|
|
1267
1258
|
fill: "currentColor",
|
|
@@ -1270,7 +1261,7 @@ var Logo = (props) => {
|
|
|
1270
1261
|
fillRule: "nonzero"
|
|
1271
1262
|
}
|
|
1272
1263
|
),
|
|
1273
|
-
/* @__PURE__ */
|
|
1264
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#38f6fcde47)", children: /* @__PURE__ */ jsx(
|
|
1274
1265
|
"path",
|
|
1275
1266
|
{
|
|
1276
1267
|
fill: "currentColor",
|
|
@@ -1279,7 +1270,7 @@ var Logo = (props) => {
|
|
|
1279
1270
|
fillRule: "nonzero"
|
|
1280
1271
|
}
|
|
1281
1272
|
) }),
|
|
1282
|
-
/* @__PURE__ */
|
|
1273
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#af000f7256)", children: /* @__PURE__ */ jsx(
|
|
1283
1274
|
"path",
|
|
1284
1275
|
{
|
|
1285
1276
|
fill: "currentColor",
|
|
@@ -1288,7 +1279,7 @@ var Logo = (props) => {
|
|
|
1288
1279
|
fillRule: "nonzero"
|
|
1289
1280
|
}
|
|
1290
1281
|
) }),
|
|
1291
|
-
/* @__PURE__ */
|
|
1282
|
+
/* @__PURE__ */ jsx(
|
|
1292
1283
|
"path",
|
|
1293
1284
|
{
|
|
1294
1285
|
fill: "currentColor",
|
|
@@ -1297,7 +1288,7 @@ var Logo = (props) => {
|
|
|
1297
1288
|
fillRule: "nonzero"
|
|
1298
1289
|
}
|
|
1299
1290
|
),
|
|
1300
|
-
/* @__PURE__ */
|
|
1291
|
+
/* @__PURE__ */ jsx(
|
|
1301
1292
|
"path",
|
|
1302
1293
|
{
|
|
1303
1294
|
fill: "currentColor",
|
|
@@ -1306,7 +1297,7 @@ var Logo = (props) => {
|
|
|
1306
1297
|
fillRule: "nonzero"
|
|
1307
1298
|
}
|
|
1308
1299
|
),
|
|
1309
|
-
/* @__PURE__ */
|
|
1300
|
+
/* @__PURE__ */ jsx(
|
|
1310
1301
|
"path",
|
|
1311
1302
|
{
|
|
1312
1303
|
fill: "currentColor",
|
|
@@ -1322,8 +1313,8 @@ var Logo = (props) => {
|
|
|
1322
1313
|
var logo_default = Logo;
|
|
1323
1314
|
|
|
1324
1315
|
// src/components/global-error-page.tsx
|
|
1325
|
-
import { jsx as
|
|
1326
|
-
function GlobalError({ error }) {
|
|
1316
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1317
|
+
function GlobalError({ error, ...rest }) {
|
|
1327
1318
|
useEffect(() => {
|
|
1328
1319
|
console.error("Global error:", error);
|
|
1329
1320
|
}, [error]);
|
|
@@ -1332,9 +1323,9 @@ function GlobalError({ error }) {
|
|
|
1332
1323
|
};
|
|
1333
1324
|
return /* @__PURE__ */ jsxs2("html", { lang: "en", children: [
|
|
1334
1325
|
/* @__PURE__ */ jsxs2("head", { children: [
|
|
1335
|
-
/* @__PURE__ */
|
|
1336
|
-
/* @__PURE__ */
|
|
1337
|
-
/* @__PURE__ */
|
|
1326
|
+
/* @__PURE__ */ jsx2("meta", { charSet: "utf-8" }),
|
|
1327
|
+
/* @__PURE__ */ jsx2("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }),
|
|
1328
|
+
/* @__PURE__ */ jsx2(
|
|
1338
1329
|
"link",
|
|
1339
1330
|
{
|
|
1340
1331
|
rel: "stylesheet",
|
|
@@ -1343,17 +1334,17 @@ function GlobalError({ error }) {
|
|
|
1343
1334
|
}
|
|
1344
1335
|
)
|
|
1345
1336
|
] }),
|
|
1346
|
-
/* @__PURE__ */
|
|
1347
|
-
/* @__PURE__ */
|
|
1348
|
-
/* @__PURE__ */
|
|
1349
|
-
/* @__PURE__ */
|
|
1337
|
+
/* @__PURE__ */ jsx2("body", { children: /* @__PURE__ */ jsx2("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: [
|
|
1338
|
+
/* @__PURE__ */ jsx2("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: [
|
|
1339
|
+
/* @__PURE__ */ jsx2("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx2(logo_default, { className: "h-8 w-auto text-white" }) }),
|
|
1340
|
+
/* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsx2("h1", { className: "text-xl font-medium text-red-500", children: "Application Crashed" }) })
|
|
1350
1341
|
] }) }),
|
|
1351
1342
|
/* @__PURE__ */ jsxs2("div", { className: "p-4", children: [
|
|
1352
|
-
/* @__PURE__ */
|
|
1353
|
-
/* @__PURE__ */
|
|
1343
|
+
/* @__PURE__ */ jsx2("div", { className: "mb-4 text-neutral-400", children: "The application encountered a critical error and could not continue." }),
|
|
1344
|
+
/* @__PURE__ */ jsx2("h2", { className: "text-2xl font-bold mb-4 text-white", children: error.message || "A critical error occurred" }),
|
|
1354
1345
|
error.digest && /* @__PURE__ */ jsxs2("div", { className: "mb-4", children: [
|
|
1355
|
-
/* @__PURE__ */
|
|
1356
|
-
/* @__PURE__ */
|
|
1346
|
+
/* @__PURE__ */ jsx2("h3", { className: "text-sm uppercase tracking-wider text-neutral-500 font-medium mb-2", children: "Error ID" }),
|
|
1347
|
+
/* @__PURE__ */ jsx2("div", { className: "bg-neutral-900 rounded-md p-3 text-neutral-300 font-mono", children: error.digest })
|
|
1357
1348
|
] })
|
|
1358
1349
|
] })
|
|
1359
1350
|
] }) }) })
|
|
@@ -1441,7 +1432,8 @@ var serveFilePath = async ({
|
|
|
1441
1432
|
};
|
|
1442
1433
|
|
|
1443
1434
|
// src/plugins/use-pages/setup/index.tsx
|
|
1444
|
-
import {
|
|
1435
|
+
import { __PYLON_INTERNALS_DO_NOT_USE } from "@getcronit/pylon/pages";
|
|
1436
|
+
import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
|
|
1445
1437
|
var disableCacheMiddleware = async (c, next) => {
|
|
1446
1438
|
const env3 = getEnv();
|
|
1447
1439
|
if (true) {
|
|
@@ -1455,134 +1447,73 @@ var disableCacheMiddleware = async (c, next) => {
|
|
|
1455
1447
|
}
|
|
1456
1448
|
return next();
|
|
1457
1449
|
};
|
|
1458
|
-
var setup = (app2) => {
|
|
1459
|
-
const
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
console.error("Error reading pages.json", error);
|
|
1465
|
-
}
|
|
1450
|
+
var setup = async (app2) => {
|
|
1451
|
+
const cacheBustingSuffix = `?v=${Date.now()}`;
|
|
1452
|
+
const slugs = (await import(`${process.cwd()}/.pylon/slugs.js`)).default;
|
|
1453
|
+
const routes = (await import(`${process.cwd()}/.pylon/__pylon/pages/app.js`)).default;
|
|
1454
|
+
const client = await import(`${process.cwd()}/.pylon/client/index.js`);
|
|
1455
|
+
let handler2 = createStaticHandler(routes);
|
|
1466
1456
|
app2.use(trimTrailingSlash());
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1457
|
+
app2.get("/test1234", async (c) => {
|
|
1458
|
+
return c.json({ hello: "world" });
|
|
1459
|
+
});
|
|
1460
|
+
app2.on("GET", slugs, disableCacheMiddleware, async (c) => {
|
|
1461
|
+
const context = await handler2.query(c.req.raw);
|
|
1462
|
+
if (context instanceof Response) {
|
|
1463
|
+
return context;
|
|
1464
|
+
}
|
|
1465
|
+
const router = createStaticRouter(handler2.dataRoutes, context);
|
|
1466
|
+
const component = /* @__PURE__ */ jsx3(__PYLON_INTERNALS_DO_NOT_USE.DataClientProvider, { client, children: /* @__PURE__ */ jsx3(StaticRouterProvider, { router, context }) });
|
|
1467
|
+
if (c.req.header("accept")?.includes("application/json")) {
|
|
1468
|
+
const prepared = await client.prepareReactRender(component);
|
|
1469
|
+
const data = prepared.cacheSnapshot;
|
|
1470
|
+
return c.json(data);
|
|
1471
|
+
}
|
|
1472
|
+
try {
|
|
1473
|
+
let cacheSnapshot = void 0;
|
|
1474
1474
|
try {
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
client = await import(`${process.cwd()}/.pylon/client/index.js`);
|
|
1481
|
-
}
|
|
1482
|
-
const requestUrl = new URL(c.req.url);
|
|
1483
|
-
let cacheSnapshot = void 0;
|
|
1475
|
+
const prepared = await client.prepareReactRender(/* @__PURE__ */ jsx3(Fragment, {}));
|
|
1476
|
+
cacheSnapshot = prepared.cacheSnapshot;
|
|
1477
|
+
} catch (error) {
|
|
1478
|
+
}
|
|
1479
|
+
if (reactServer.renderToReadableStream) {
|
|
1484
1480
|
try {
|
|
1485
|
-
const
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
Router: StaticRouter,
|
|
1490
|
-
routerProps: {
|
|
1491
|
-
location: {
|
|
1492
|
-
pathname: requestUrl.pathname,
|
|
1493
|
-
search: requestUrl.search,
|
|
1494
|
-
hash: requestUrl.hash
|
|
1495
|
-
}
|
|
1496
|
-
},
|
|
1497
|
-
App,
|
|
1498
|
-
client,
|
|
1499
|
-
pylonData: {
|
|
1500
|
-
cacheSnapshot: void 0
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
)
|
|
1504
|
-
);
|
|
1505
|
-
cacheSnapshot = prepared.cacheSnapshot;
|
|
1481
|
+
const stream = await reactServer.renderToReadableStream(component, {
|
|
1482
|
+
bootstrapModules: ["/__pylon/static/app.js" + cacheBustingSuffix]
|
|
1483
|
+
});
|
|
1484
|
+
return c.body(stream);
|
|
1506
1485
|
} catch (error) {
|
|
1486
|
+
throw error;
|
|
1507
1487
|
}
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
),
|
|
1525
|
-
{
|
|
1526
|
-
bootstrapModules: ["/__pylon/static/app.js"],
|
|
1527
|
-
bootstrapScriptContent: `window.__PYLON_DATA__ = ${JSON.stringify(
|
|
1528
|
-
{
|
|
1529
|
-
cacheSnapshot
|
|
1530
|
-
}
|
|
1531
|
-
)}`
|
|
1532
|
-
}
|
|
1533
|
-
);
|
|
1534
|
-
return c.body(stream);
|
|
1535
|
-
} catch (error) {
|
|
1536
|
-
throw error;
|
|
1537
|
-
}
|
|
1538
|
-
} else if (reactServer.renderToPipeableStream) {
|
|
1539
|
-
return await new Promise((resolve, reject) => {
|
|
1540
|
-
const { pipe } = reactServer.renderToPipeableStream(
|
|
1541
|
-
/* @__PURE__ */ jsx4(
|
|
1542
|
-
AppLoader,
|
|
1543
|
-
{
|
|
1544
|
-
Router: StaticRouter,
|
|
1545
|
-
routerProps: {
|
|
1546
|
-
location: c.req.path
|
|
1547
|
-
},
|
|
1548
|
-
App,
|
|
1549
|
-
client,
|
|
1550
|
-
pylonData: {
|
|
1551
|
-
cacheSnapshot
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
),
|
|
1555
|
-
{
|
|
1556
|
-
bootstrapModules: ["/__pylon/static/app.js"],
|
|
1557
|
-
bootstrapScriptContent: `window.__PYLON_DATA__ = ${JSON.stringify(
|
|
1558
|
-
{
|
|
1559
|
-
cacheSnapshot
|
|
1560
|
-
}
|
|
1561
|
-
)}`,
|
|
1562
|
-
onShellReady: async () => {
|
|
1563
|
-
c.header("Content-Type", "text/html");
|
|
1564
|
-
const passThrough = new PassThrough();
|
|
1565
|
-
pipe(passThrough);
|
|
1566
|
-
resolve(c.body(Readable2.toWeb(passThrough)));
|
|
1567
|
-
},
|
|
1568
|
-
onShellError: async (error) => {
|
|
1569
|
-
reject(error);
|
|
1570
|
-
}
|
|
1488
|
+
} else if (reactServer.renderToPipeableStream) {
|
|
1489
|
+
return await new Promise((resolve, reject) => {
|
|
1490
|
+
const { pipe } = reactServer.renderToPipeableStream(
|
|
1491
|
+
component,
|
|
1492
|
+
{
|
|
1493
|
+
bootstrapModules: ["/__pylon/static/app.js" + cacheBustingSuffix],
|
|
1494
|
+
onShellReady: async () => {
|
|
1495
|
+
c.header("Content-Type", "text/html");
|
|
1496
|
+
const passThrough = new PassThrough();
|
|
1497
|
+
pipe(passThrough);
|
|
1498
|
+
resolve(c.body(Readable2.toWeb(passThrough)));
|
|
1499
|
+
},
|
|
1500
|
+
onShellError: async (error) => {
|
|
1501
|
+
reject(error);
|
|
1571
1502
|
}
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
} catch (error) {
|
|
1578
|
-
c.header("Content-Type", "text/html");
|
|
1579
|
-
c.status(500);
|
|
1580
|
-
return c.html(
|
|
1581
|
-
reactServer.renderToString(/* @__PURE__ */ jsx4(GlobalError, { error }))
|
|
1582
|
-
);
|
|
1503
|
+
}
|
|
1504
|
+
);
|
|
1505
|
+
});
|
|
1506
|
+
} else {
|
|
1507
|
+
throw new Error("Environment not supported");
|
|
1583
1508
|
}
|
|
1509
|
+
} catch (error) {
|
|
1510
|
+
c.header("Content-Type", "text/html");
|
|
1511
|
+
c.status(500);
|
|
1512
|
+
return c.html(
|
|
1513
|
+
reactServer.renderToString(/* @__PURE__ */ jsx3(GlobalError, { error }))
|
|
1514
|
+
);
|
|
1584
1515
|
}
|
|
1585
|
-
);
|
|
1516
|
+
});
|
|
1586
1517
|
const publicFilesPath = path3.resolve(
|
|
1587
1518
|
process.cwd(),
|
|
1588
1519
|
".pylon",
|
|
@@ -1795,184 +1726,207 @@ var downloadImage = async (url) => {
|
|
|
1795
1726
|
import path7 from "path";
|
|
1796
1727
|
|
|
1797
1728
|
// src/plugins/use-pages/build/app-utils.ts
|
|
1729
|
+
import fs3 from "fs";
|
|
1798
1730
|
import path4 from "path";
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1731
|
+
var PAGES_DIR = "./pages";
|
|
1732
|
+
var imports = [];
|
|
1733
|
+
var routeSlugs = [];
|
|
1734
|
+
function getLayoutComponentName(filePath) {
|
|
1735
|
+
return filePath.replace(PAGES_DIR, "").replace(/\\/g, "/").replace(/layout\.tsx$/, "").split("/").filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join("") + "Layout";
|
|
1736
|
+
}
|
|
1737
|
+
function convertToDynamicRoute(segment) {
|
|
1738
|
+
if (segment.startsWith("[") && segment.endsWith("]")) {
|
|
1739
|
+
return `:${segment.slice(1, -1)}`;
|
|
1805
1740
|
}
|
|
1806
|
-
return
|
|
1741
|
+
return segment;
|
|
1807
1742
|
}
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
const
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
const
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
const
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1743
|
+
function scanDirectory(directory, basePath = "") {
|
|
1744
|
+
const items = fs3.readdirSync(directory, { withFileTypes: true });
|
|
1745
|
+
const route = { path: basePath || "/", children: [] };
|
|
1746
|
+
let hasLayout = false;
|
|
1747
|
+
let pageFound = false;
|
|
1748
|
+
for (const item of items) {
|
|
1749
|
+
const itemPath = path4.join(directory, item.name);
|
|
1750
|
+
const relativePath = path4.join(basePath, item.name).replace(/\\/g, "/");
|
|
1751
|
+
const importPath = `"./${path4.join("..", PAGES_DIR, relativePath).replace(/\.tsx$/, "")}"`;
|
|
1752
|
+
if (item.isDirectory()) {
|
|
1753
|
+
const childRoute = scanDirectory(itemPath, relativePath);
|
|
1754
|
+
if (childRoute) {
|
|
1755
|
+
route.children.push(childRoute);
|
|
1756
|
+
}
|
|
1757
|
+
} else if (item.name === "layout.tsx") {
|
|
1758
|
+
const layoutComponentName = getLayoutComponentName(relativePath);
|
|
1759
|
+
imports.push(`import ${layoutComponentName} from ${importPath};`);
|
|
1760
|
+
const componentName = layoutComponentName === "Layout" ? `RootLayout` : `${layoutComponentName}`;
|
|
1761
|
+
route.Component = `withLoaderData(() => <${componentName} children={<Outlet />} />)`;
|
|
1762
|
+
if (route.path === "/") {
|
|
1763
|
+
route.errorElement = "<ErrorElement />";
|
|
1764
|
+
}
|
|
1765
|
+
hasLayout = true;
|
|
1766
|
+
} else if (item.name === "page.tsx") {
|
|
1767
|
+
route.children.push({
|
|
1768
|
+
path: void 0,
|
|
1769
|
+
index: true,
|
|
1770
|
+
lazy: `async () => {const i = await import(${importPath}); return {Component: withLoaderData(i.default)}}`,
|
|
1771
|
+
loader: `loader`
|
|
1772
|
+
});
|
|
1773
|
+
pageFound = true;
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
if (route.path) {
|
|
1777
|
+
const segments = route.path.split("/").map((segment) => convertToDynamicRoute(segment)).filter(Boolean);
|
|
1778
|
+
const fullPath = segments.length > 0 ? `/${segments.join("/")}` : "/";
|
|
1779
|
+
route.path = segments[segments.length - 1] || "/";
|
|
1780
|
+
if (hasLayout || pageFound) {
|
|
1781
|
+
routeSlugs.push(fullPath);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
if (hasLayout || route.lazy || route.children && route.children.length > 0) {
|
|
1785
|
+
return route;
|
|
1828
1786
|
}
|
|
1829
|
-
return
|
|
1787
|
+
return null;
|
|
1830
1788
|
}
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1789
|
+
function serialize(obj, parentKey) {
|
|
1790
|
+
if (Array.isArray(obj)) {
|
|
1791
|
+
return `[${obj.map(serialize).join(", ")}]`;
|
|
1792
|
+
} else if (obj && typeof obj === "object") {
|
|
1793
|
+
const entries = Object.entries(obj).map(
|
|
1794
|
+
([key, value]) => `${JSON.stringify(key)}: ${serialize(value, key)}`
|
|
1795
|
+
);
|
|
1796
|
+
return `{${entries.join(", ")}}`;
|
|
1797
|
+
} else if (typeof obj === "string") {
|
|
1798
|
+
if (parentKey === "lazy" || parentKey === "loader" || parentKey === "Component" || parentKey === "errorElement") {
|
|
1799
|
+
return obj;
|
|
1836
1800
|
}
|
|
1837
|
-
return
|
|
1801
|
+
return JSON.stringify(obj);
|
|
1802
|
+
} else {
|
|
1803
|
+
return String(obj);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
function makeAppFiles() {
|
|
1807
|
+
imports = [];
|
|
1808
|
+
routeSlugs = [];
|
|
1809
|
+
const rootRoute = scanDirectory(PAGES_DIR);
|
|
1810
|
+
const notFoundRoute = {
|
|
1811
|
+
path: "*",
|
|
1812
|
+
Component: "NotFoundPage"
|
|
1838
1813
|
};
|
|
1839
|
-
const
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1814
|
+
const routes = `${imports.join("\n")}
|
|
1815
|
+
|
|
1816
|
+
import {__PYLON_ROUTER_INTERNALS_DO_NOT_USE, __PYLON_INTERNALS_DO_NOT_USE, GlobalErrorPage} from '@getcronit/pylon/pages'
|
|
1817
|
+
const Outlet = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.Outlet
|
|
1818
|
+
|
|
1819
|
+
const ErrorElement = () => {
|
|
1820
|
+
const error = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.useRouteError()
|
|
1821
|
+
|
|
1822
|
+
return <GlobalErrorPage error={error} />
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
function withLoaderData<T>(Component: React.ComponentType<{ data: T }>) {
|
|
1826
|
+
return function WithLoaderDataWrapper(props: T) {
|
|
1827
|
+
const client = __PYLON_INTERNALS_DO_NOT_USE.useDataClient()
|
|
1828
|
+
const cacheSnapshot = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.useLoaderData()
|
|
1829
|
+
|
|
1830
|
+
|
|
1831
|
+
const location = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.useLocation()
|
|
1832
|
+
const [searchParams] = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.useSearchParams()
|
|
1833
|
+
const searchParamsObject = Object.fromEntries(searchParams.entries())
|
|
1834
|
+
const params = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.useParams()
|
|
1835
|
+
|
|
1836
|
+
client.useHydrateCache({cacheSnapshot})
|
|
1837
|
+
const data = client.useQuery()
|
|
1838
|
+
|
|
1839
|
+
return <Component {...(props as any)} path={location.pathname} params={params} searchParams={searchParamsObject} data={data} />;
|
|
1847
1840
|
};
|
|
1848
|
-
|
|
1849
|
-
const layoutMap = makeLayoutMap(pageRoutes);
|
|
1850
|
-
const importPages = Object.keys(pageMap).map((pagePath, index) => {
|
|
1851
|
-
const importLocation = `../${pagePath}`.replace(".tsx", ".js");
|
|
1852
|
-
const componentName = pageMap[pagePath];
|
|
1853
|
-
return `const ${componentName} = lazy(() => import('${importLocation}'))
|
|
1854
|
-
`;
|
|
1855
|
-
}).join("\n");
|
|
1856
|
-
const importLayouts = Object.keys(layoutMap).map((layoutPath, index) => {
|
|
1857
|
-
const importLocation = `../${layoutPath}`.replace(".tsx", ".js");
|
|
1858
|
-
const componentName = layoutMap[layoutPath];
|
|
1859
|
-
return `const ${componentName} = lazy(() => import('${importLocation}'))
|
|
1860
|
-
`;
|
|
1861
|
-
}).join("\n");
|
|
1862
|
-
const appComponent = `"use client";
|
|
1863
|
-
import {lazy, Suspense, useMemo} from 'react'
|
|
1864
|
-
import { __PYLON_ROUTER_INTERNALS_DO_NOT_USE, DevOverlay, PageProps} from '@getcronit/pylon/pages';
|
|
1865
|
-
const {Routes, Route, useParams, useSearchParams, useLocation} = __PYLON_ROUTER_INTERNALS_DO_NOT_USE
|
|
1866
|
-
${importPages}
|
|
1867
|
-
const RootLayout = lazy(() => import('../pages/layout.js'))
|
|
1868
|
-
${importLayouts}
|
|
1869
|
-
|
|
1870
|
-
const InjectPageProps: React.FC<{Page: React.FC, data: PageProps["data"]}> = ({Page, data}) => {
|
|
1871
|
-
const params = useParams();
|
|
1872
|
-
const [searchParams] = useSearchParams();
|
|
1873
|
-
const location = useLocation();
|
|
1874
|
-
|
|
1875
|
-
const pageProps = useMemo(() => {
|
|
1876
|
-
return {
|
|
1877
|
-
data,
|
|
1878
|
-
params,
|
|
1879
|
-
searchParams: Object.fromEntries(searchParams.entries()),
|
|
1880
|
-
location: location.pathname
|
|
1881
|
-
}
|
|
1882
|
-
}, [data, params, searchParams, location.pathname])
|
|
1841
|
+
}
|
|
1883
1842
|
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
<meta charSet="utf-8" />
|
|
1892
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
1893
|
-
<link rel="stylesheet" href="/__pylon/static/app.css" precedence="high" />
|
|
1894
|
-
<Routes>
|
|
1895
|
-
${pageRoutes.map((route, index) => {
|
|
1896
|
-
return `<Route key={${index}} index={${index === 0 ? "true" : "false"}} path="${route.slug}" element={
|
|
1897
|
-
${route.layouts.reduceRight(
|
|
1898
|
-
(child, layoutPath, layoutIndex) => {
|
|
1899
|
-
const layoutName = layoutMap[layoutPath];
|
|
1900
|
-
return `<${layoutName}>${child}</${layoutName}>`;
|
|
1901
|
-
},
|
|
1902
|
-
`<InjectPageProps Page={${pageMap[route.pagePath]} as React.FC} data={props.data} />`
|
|
1903
|
-
)}
|
|
1904
|
-
} />`;
|
|
1905
|
-
}).join("\n")}
|
|
1906
|
-
</Routes>
|
|
1907
|
-
</RootLayout>
|
|
1908
|
-
</DevOverlay>
|
|
1909
|
-
)
|
|
1843
|
+
const loader: __PYLON_ROUTER_INTERNALS_DO_NOT_USE.LoaderFunction = async ({ request }) => {
|
|
1844
|
+
if (
|
|
1845
|
+
request.headers.has('accept') &&
|
|
1846
|
+
request.headers.get('accept') === 'application/json'
|
|
1847
|
+
) {
|
|
1848
|
+
// Skip the loader if the request is for JSON
|
|
1849
|
+
return null
|
|
1910
1850
|
}
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1851
|
+
const url = new URL(request.url)
|
|
1852
|
+
const headers = new Headers()
|
|
1853
|
+
headers.set('Accept', 'application/json')
|
|
1854
|
+
try {
|
|
1855
|
+
const response = await fetch(url, {
|
|
1856
|
+
method: 'GET',
|
|
1857
|
+
headers: headers,
|
|
1858
|
+
})
|
|
1859
|
+
const data = await response.json<object>()
|
|
1860
|
+
return data
|
|
1861
|
+
} catch (error) {
|
|
1862
|
+
return null
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
const RootLayout = (props: { children: React.ReactNode; [key: string]: any }) => {
|
|
1867
|
+
return (
|
|
1868
|
+
<Layout {...props}>
|
|
1869
|
+
<meta charSet="utf-8" />
|
|
1870
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
1871
|
+
<link rel="stylesheet" href="/__pylon/static/app.css" precedence="high" />
|
|
1872
|
+
{props.children}
|
|
1873
|
+
</Layout>
|
|
1874
|
+
)
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
const NotFoundPage = () => {
|
|
1878
|
+
return <div>Page Not Found</div>
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
const routes = ${serialize([rootRoute, notFoundRoute].filter(Boolean))}
|
|
1882
|
+
|
|
1883
|
+
export default routes
|
|
1884
|
+
|
|
1885
|
+
`;
|
|
1886
|
+
const slugs = `export default ${JSON.stringify(routeSlugs, null, 2)}`;
|
|
1887
|
+
return {
|
|
1888
|
+
routes,
|
|
1889
|
+
slugs
|
|
1890
|
+
};
|
|
1891
|
+
}
|
|
1916
1892
|
|
|
1917
1893
|
// src/plugins/use-pages/build/index.ts
|
|
1918
1894
|
import chokidar from "chokidar";
|
|
1919
|
-
import
|
|
1895
|
+
import fs7 from "fs/promises";
|
|
1920
1896
|
import esbuild from "esbuild";
|
|
1921
1897
|
|
|
1922
1898
|
// src/plugins/use-pages/build/plugins/inject-app-hydration.ts
|
|
1923
1899
|
import path5 from "path";
|
|
1924
|
-
import
|
|
1900
|
+
import fs4 from "fs/promises";
|
|
1925
1901
|
var injectAppHydrationPlugin = {
|
|
1926
1902
|
name: "inject-hydration",
|
|
1927
1903
|
setup(build2) {
|
|
1928
1904
|
build2.onLoad({ filter: /.*/, namespace: "file" }, async (args) => {
|
|
1929
1905
|
if (args.path === path5.resolve(process.cwd(), ".pylon", "app.tsx")) {
|
|
1930
|
-
let contents = await
|
|
1906
|
+
let contents = await fs4.readFile(args.path, "utf-8");
|
|
1931
1907
|
const clientPath = path5.resolve(process.cwd(), ".pylon/client");
|
|
1932
1908
|
const pathToClient = path5.relative(path5.dirname(args.path), clientPath);
|
|
1933
1909
|
contents += `
|
|
1934
1910
|
import {hydrateRoot} from 'react-dom/client'
|
|
1935
1911
|
import * as client from './${pathToClient}'
|
|
1936
|
-
import { __PYLON_ROUTER_INTERNALS_DO_NOT_USE, DevOverlay, onCaughtErrorProd, onRecoverableErrorProd, onUncaughtErrorProd } from '@getcronit/pylon/pages';
|
|
1937
|
-
const {
|
|
1912
|
+
import { __PYLON_ROUTER_INTERNALS_DO_NOT_USE, __PYLON_INTERNALS_DO_NOT_USE, DevOverlay, onCaughtErrorProd, onRecoverableErrorProd, onUncaughtErrorProd } from '@getcronit/pylon/pages';
|
|
1913
|
+
const {createBrowserRouter, RouterProvider} = __PYLON_ROUTER_INTERNALS_DO_NOT_USE
|
|
1914
|
+
const {DataClientProvider} = __PYLON_INTERNALS_DO_NOT_USE
|
|
1938
1915
|
import React, {useMemo} from 'react'
|
|
1939
1916
|
|
|
1940
|
-
const
|
|
1941
|
-
|
|
1942
|
-
const AppLoader = (props: {
|
|
1943
|
-
client: any
|
|
1944
|
-
pylonData: {
|
|
1945
|
-
cacheSnapshot?: any
|
|
1946
|
-
}
|
|
1947
|
-
App: React.FC<{
|
|
1948
|
-
data: PageProps['data']
|
|
1949
|
-
}>
|
|
1950
|
-
Router: React.FC<any>
|
|
1951
|
-
routerProps: any
|
|
1952
|
-
}) => {
|
|
1953
|
-
props.client.useHydrateCache({cacheSnapshot: props.pylonData.cacheSnapshot})
|
|
1954
|
-
|
|
1955
|
-
const data = props.client.useQuery()
|
|
1956
|
-
const page = useMemo(() => {
|
|
1957
|
-
const page = (
|
|
1958
|
-
<props.App data={data} />
|
|
1959
|
-
)
|
|
1960
|
-
|
|
1961
|
-
return page
|
|
1962
|
-
}, [props])
|
|
1963
|
-
|
|
1964
|
-
return <props.Router {...props.routerProps}>{page}</props.Router>
|
|
1965
|
-
}
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1917
|
+
const router = createBrowserRouter(routes)
|
|
1969
1918
|
|
|
1970
1919
|
hydrateRoot(
|
|
1971
|
-
|
|
1972
|
-
<
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1920
|
+
document,
|
|
1921
|
+
<DevOverlay>
|
|
1922
|
+
<DataClientProvider client={client}>
|
|
1923
|
+
<RouterProvider router={router} />
|
|
1924
|
+
</DataClientProvider>
|
|
1925
|
+
</DevOverlay>,
|
|
1926
|
+
{
|
|
1927
|
+
onCaughtError: onCaughtErrorProd,
|
|
1928
|
+
onRecoverableError: onRecoverableErrorProd,
|
|
1929
|
+
onUncaughtError: onUncaughtErrorProd
|
|
1976
1930
|
}
|
|
1977
1931
|
)
|
|
1978
1932
|
`;
|
|
@@ -1988,7 +1942,7 @@ var injectAppHydrationPlugin = {
|
|
|
1988
1942
|
// src/plugins/use-pages/build/plugins/image-plugin.ts
|
|
1989
1943
|
import { createHash as createHash2 } from "crypto";
|
|
1990
1944
|
import path6 from "path";
|
|
1991
|
-
import
|
|
1945
|
+
import fs5 from "fs/promises";
|
|
1992
1946
|
var imagePlugin = {
|
|
1993
1947
|
name: "image-plugin",
|
|
1994
1948
|
setup(build2) {
|
|
@@ -2001,11 +1955,11 @@ var imagePlugin = {
|
|
|
2001
1955
|
const filePath = path6.resolve(args.resolveDir, args.path);
|
|
2002
1956
|
const fileName = path6.basename(filePath);
|
|
2003
1957
|
const extname = path6.extname(filePath);
|
|
2004
|
-
const hash = createHash2("md5").update(filePath + await
|
|
1958
|
+
const hash = createHash2("md5").update(filePath + await fs5.readFile(filePath)).digest("hex").slice(0, 8);
|
|
2005
1959
|
const newFilename = `${fileName}-${hash}${extname}`;
|
|
2006
1960
|
const newFilePath = path6.join(outdir, "media", newFilename);
|
|
2007
|
-
await
|
|
2008
|
-
await
|
|
1961
|
+
await fs5.mkdir(path6.dirname(newFilePath), { recursive: true });
|
|
1962
|
+
await fs5.copyFile(filePath, newFilePath);
|
|
2009
1963
|
return {
|
|
2010
1964
|
path: newFilePath,
|
|
2011
1965
|
namespace: "image"
|
|
@@ -2043,7 +1997,7 @@ var imagePlugin = {
|
|
|
2043
1997
|
};
|
|
2044
1998
|
|
|
2045
1999
|
// src/plugins/use-pages/build/plugins/postcss-plugin.ts
|
|
2046
|
-
import
|
|
2000
|
+
import fs6 from "fs/promises";
|
|
2047
2001
|
import loadConfig from "postcss-load-config";
|
|
2048
2002
|
import postcss from "postcss";
|
|
2049
2003
|
var postcssPlugin = {
|
|
@@ -2051,7 +2005,7 @@ var postcssPlugin = {
|
|
|
2051
2005
|
setup(build2) {
|
|
2052
2006
|
build2.onLoad({ filter: /.css$/, namespace: "file" }, async (args) => {
|
|
2053
2007
|
const { plugins, options } = await loadConfig();
|
|
2054
|
-
const css = await
|
|
2008
|
+
const css = await fs6.readFile(args.path, "utf-8");
|
|
2055
2009
|
const result = await postcss(plugins).process(css, {
|
|
2056
2010
|
...options,
|
|
2057
2011
|
from: args.path
|
|
@@ -2069,32 +2023,27 @@ var DIST_STATIC_DIR = path7.join(process.cwd(), ".pylon/__pylon/static");
|
|
|
2069
2023
|
var DIST_PAGES_DIR = path7.join(process.cwd(), ".pylon/__pylon/pages");
|
|
2070
2024
|
async function updateFileIfChanged(path8, newContent) {
|
|
2071
2025
|
try {
|
|
2072
|
-
const currentContent = await
|
|
2026
|
+
const currentContent = await fs7.readFile(path8);
|
|
2073
2027
|
if (currentContent.equals(newContent)) {
|
|
2074
2028
|
return false;
|
|
2075
2029
|
}
|
|
2076
2030
|
} catch (err) {
|
|
2077
2031
|
if (err.code !== "ENOENT") throw err;
|
|
2078
2032
|
}
|
|
2079
|
-
await
|
|
2033
|
+
await fs7.writeFile(path8, newContent);
|
|
2080
2034
|
return true;
|
|
2081
2035
|
}
|
|
2082
2036
|
var build = async () => {
|
|
2083
2037
|
const buildAppFile = async () => {
|
|
2084
|
-
const
|
|
2085
|
-
const appContent = generateAppFile(pagesRoutes);
|
|
2086
|
-
const pagesFile = path7.resolve(process.cwd(), ".pylon", "pages.json");
|
|
2038
|
+
const appFiles = makeAppFiles();
|
|
2087
2039
|
await updateFileIfChanged(
|
|
2088
|
-
|
|
2089
|
-
Buffer.from(
|
|
2040
|
+
path7.resolve(process.cwd(), ".pylon", "app.tsx"),
|
|
2041
|
+
Buffer.from(appFiles.routes)
|
|
2090
2042
|
);
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
Buffer.from(appContent)
|
|
2043
|
+
await updateFileIfChanged(
|
|
2044
|
+
path7.resolve(process.cwd(), ".pylon", "slugs.js"),
|
|
2045
|
+
Buffer.from(appFiles.slugs)
|
|
2095
2046
|
);
|
|
2096
|
-
if (state) {
|
|
2097
|
-
}
|
|
2098
2047
|
};
|
|
2099
2048
|
const copyPublicDir = async () => {
|
|
2100
2049
|
const publicDir = path7.resolve(process.cwd(), "public");
|
|
@@ -2105,9 +2054,9 @@ var build = async () => {
|
|
|
2105
2054
|
"public"
|
|
2106
2055
|
);
|
|
2107
2056
|
try {
|
|
2108
|
-
await
|
|
2109
|
-
await
|
|
2110
|
-
await
|
|
2057
|
+
await fs7.access(publicDir);
|
|
2058
|
+
await fs7.mkdir(pylonPublicDir, { recursive: true });
|
|
2059
|
+
await fs7.cp(publicDir, pylonPublicDir, { recursive: true });
|
|
2111
2060
|
} catch (err) {
|
|
2112
2061
|
if (err.code !== "ENOENT") throw err;
|
|
2113
2062
|
}
|
|
@@ -2124,12 +2073,12 @@ var build = async () => {
|
|
|
2124
2073
|
"__pylon",
|
|
2125
2074
|
"static"
|
|
2126
2075
|
);
|
|
2127
|
-
await
|
|
2128
|
-
await
|
|
2076
|
+
await fs7.mkdir(pylonCssDestDir, { recursive: true });
|
|
2077
|
+
await fs7.cp(
|
|
2129
2078
|
path7.join(pylonCssPathDir, "index.css"),
|
|
2130
2079
|
path7.join(pylonCssDestDir, "pylon.css")
|
|
2131
2080
|
);
|
|
2132
|
-
await
|
|
2081
|
+
await fs7.cp(
|
|
2133
2082
|
path7.join(pylonCssPathDir, "index.css.map"),
|
|
2134
2083
|
path7.join(pylonCssDestDir, "pylon.css.map")
|
|
2135
2084
|
);
|
|
@@ -2140,7 +2089,7 @@ var build = async () => {
|
|
|
2140
2089
|
build2.onEnd(async (result) => {
|
|
2141
2090
|
await Promise.all(
|
|
2142
2091
|
result.outputFiles.map(async (file) => {
|
|
2143
|
-
await
|
|
2092
|
+
await fs7.mkdir(path7.dirname(file.path), { recursive: true });
|
|
2144
2093
|
await updateFileIfChanged(file.path, file.contents);
|
|
2145
2094
|
})
|
|
2146
2095
|
);
|