xanix 1.0.5 → 1.0.8

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 (143) hide show
  1. package/dist/bin/bundler/buildClient.js +3 -3
  2. package/dist/bin/bundler/buildServer.js +2 -3
  3. package/dist/bin/bundler/{buildCache.js → cacheNpmModules copy.js } +71 -21
  4. package/dist/bin/bundler/cacheNpmModules.js +9 -5
  5. package/dist/bin/bundler/config/output.js +9 -1
  6. package/dist/bin/bundler/plugins/XanixDocument/index.d.ts +2 -0
  7. package/dist/bin/bundler/plugins/XanixDocument/index.js +35 -0
  8. package/dist/bin/bundler/plugins/XanixEnv.js +10 -3
  9. package/dist/bin/bundler/plugins/XanixReactRefresh.js +29 -36
  10. package/dist/bin/bundler/plugins/XanixTransform/transformer copy.d.ts +16 -0
  11. package/dist/bin/bundler/plugins/XanixTransform/transformer copy.js +631 -0
  12. package/dist/bin/bundler/plugins/plugins.js +3 -1
  13. package/dist/bin/bundler/watchClient.js +3 -3
  14. package/dist/bin/bundler/watchServer.js +2 -3
  15. package/dist/bin/include/utils.d.ts +2 -1
  16. package/dist/bin/include/utils.js +9 -6
  17. package/dist/bin/index.js +0 -0
  18. package/dist/client-runtime.js +15 -15
  19. package/dist/components/BaseDocument.d.ts +1 -1
  20. package/dist/components/BaseDocument.js +1 -3
  21. package/dist/components/Body.js +3 -1
  22. package/dist/components/Document.js +3 -1
  23. package/dist/components/Head.d.ts +1 -1
  24. package/dist/components/Head.js +37 -34
  25. package/dist/components/Link.d.ts +1 -1
  26. package/dist/components/Link.js +23 -18
  27. package/dist/dataLoader.d.ts +1 -1
  28. package/dist/dataLoader.js +11 -5
  29. package/dist/hooks/useData.d.ts +2 -6
  30. package/dist/hooks/useData.js +1 -1
  31. package/dist/index.d.ts +5 -0
  32. package/dist/index.js +4 -0
  33. package/dist/navigate.js +11 -8
  34. package/dist/server/runtime/xanixPage.js +1 -4
  35. package/dist/types/assets.d.ts +34 -0
  36. package/dist/types/express.d.ts +12 -0
  37. package/dist/types/globals.d.ts +26 -0
  38. package/dist/types/xanix-virtual.d.ts +26 -0
  39. package/dist/utils.d.ts +4 -0
  40. package/dist/utils.js +4 -0
  41. package/package.json +79 -73
  42. package/dist/BaseDocument.d.ts +0 -3
  43. package/dist/BaseDocument.js +0 -8
  44. package/dist/bin/bundler/plugins/XanixAssets/index.d.ts +0 -4
  45. package/dist/bin/bundler/plugins/XanixAssets/index.js +0 -22
  46. package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.d.ts +0 -6
  47. package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.js +0 -350
  48. package/dist/bin/bundler/plugins/XanixHydrate.d.ts +0 -3
  49. package/dist/bin/bundler/plugins/XanixHydrate.js +0 -34
  50. package/dist/bin/bundler/plugins/commonjs.d.ts +0 -3
  51. package/dist/bin/bundler/plugins/commonjs.js +0 -10
  52. package/dist/bin/bundler/plugins/dep-XanixWatchChange.d.ts +0 -9
  53. package/dist/bin/bundler/plugins/dep-XanixWatchChange.js +0 -27
  54. package/dist/bin/bundler/plugins/nodeResolve.d.ts +0 -3
  55. package/dist/bin/bundler/plugins/nodeResolve.js +0 -10
  56. package/dist/bin/bundler/plugins/rollupEsbuild.d.ts +0 -3
  57. package/dist/bin/bundler/plugins/rollupEsbuild.js +0 -14
  58. package/dist/bin/cli/start copy.d.ts +0 -2
  59. package/dist/bin/cli/start copy.js +0 -34
  60. package/dist/client/client-runtime.d.ts +0 -10
  61. package/dist/client/client-runtime.js +0 -98
  62. package/dist/client/context/RouteContext.d.ts +0 -8
  63. package/dist/client/context/RouteContext.js +0 -16
  64. package/dist/client/hooks/usePageProps.d.ts +0 -1
  65. package/dist/client/hooks/usePageProps.js +0 -2
  66. package/dist/client/hooks/useRoute.d.ts +0 -1
  67. package/dist/client/hooks/useRoute.js +0 -2
  68. package/dist/client/hooks/useSearchParams.d.ts +0 -1
  69. package/dist/client/hooks/useSearchParams.js +0 -2
  70. package/dist/client/index.d.ts +0 -2
  71. package/dist/client/index.js +0 -2
  72. package/dist/client/navigation.d.ts +0 -3
  73. package/dist/client/navigation.js +0 -27
  74. package/dist/client/runtime.d.ts +0 -10
  75. package/dist/client/runtime.js +0 -98
  76. package/dist/components/Document/context.d.ts +0 -11
  77. package/dist/components/Document/context.js +0 -14
  78. package/dist/components/Document/index.d.ts +0 -8
  79. package/dist/components/Document/index.js +0 -6
  80. package/dist/document/BaseDocument.d.ts +0 -3
  81. package/dist/document/BaseDocument.js +0 -8
  82. package/dist/document/Body.d.ts +0 -5
  83. package/dist/document/Body.js +0 -8
  84. package/dist/document/Document.d.ts +0 -7
  85. package/dist/document/Document.js +0 -9
  86. package/dist/document/DocumentContext.d.ts +0 -18
  87. package/dist/document/DocumentContext.js +0 -6
  88. package/dist/document/Head.d.ts +0 -5
  89. package/dist/document/Head.js +0 -41
  90. package/dist/document/Link.d.ts +0 -7
  91. package/dist/document/Link.js +0 -28
  92. package/dist/document/Script.d.ts +0 -3
  93. package/dist/document/Script.js +0 -5
  94. package/dist/document/index.d.ts +0 -8
  95. package/dist/document/index.js +0 -7
  96. package/dist/document/useDocument.d.ts +0 -2
  97. package/dist/document/useDocument.js +0 -10
  98. package/dist/hooks/useCookie.d.ts +0 -2
  99. package/dist/hooks/useCookie.js +0 -13
  100. package/dist/hooks/useRequest copy.d.ts +0 -2
  101. package/dist/hooks/useRequest copy.js +0 -8
  102. package/dist/navigation/index.d.ts +0 -2
  103. package/dist/navigation/index.js +0 -2
  104. package/dist/navigation/navigate.d.ts +0 -7
  105. package/dist/navigation/navigate.js +0 -31
  106. package/dist/navigation/useLocation.d.ts +0 -1
  107. package/dist/navigation/useLocation.js +0 -22
  108. package/dist/router/index.d.ts +0 -3
  109. package/dist/router/index.js +0 -3
  110. package/dist/router/useParams.d.ts +0 -1
  111. package/dist/router/useParams.js +0 -5
  112. package/dist/router/usePathname.d.ts +0 -1
  113. package/dist/router/usePathname.js +0 -8
  114. package/dist/router/useSearchParams.d.ts +0 -11
  115. package/dist/router/useSearchParams.js +0 -74
  116. package/dist/runtime/createServer.d.ts +0 -12
  117. package/dist/runtime/createServer.js +0 -40
  118. package/dist/runtime/index.d.ts +0 -12
  119. package/dist/runtime/index.js +0 -40
  120. package/dist/runtime/readManifest.d.ts +0 -14
  121. package/dist/runtime/readManifest.js +0 -8
  122. package/dist/runtime/xanixPage.d.ts +0 -9
  123. package/dist/runtime/xanixPage.js +0 -62
  124. package/dist/server/createServer.d.ts +0 -12
  125. package/dist/server/createServer.js +0 -40
  126. package/dist/server/page.d.ts +0 -9
  127. package/dist/server/page.js +0 -62
  128. package/dist/server/readManifest.d.ts +0 -14
  129. package/dist/server/readManifest.js +0 -8
  130. package/dist/server/runtime copy.d.ts +0 -12
  131. package/dist/server/runtime copy.js +0 -40
  132. package/dist/server/runtime.d.ts +0 -12
  133. package/dist/server/runtime.js +0 -40
  134. package/dist/server/xanixPage.d.ts +0 -9
  135. package/dist/server/xanixPage.js +0 -62
  136. package/dist/types.d.ts +0 -12
  137. package/dist/types.js +0 -7
  138. package/dist/utils/index.d.ts +0 -0
  139. package/dist/utils/index.js +0 -1
  140. package/dist/xanix.d.ts +0 -3
  141. package/dist/xanix.js +0 -40
  142. package/xanix-env.d.ts +0 -79
  143. /package/dist/bin/bundler/{buildCache.d.ts → cacheNpmModules copy.d.ts} +0 -0
@@ -1,8 +0,0 @@
1
- import useDocument from "./useDocument";
2
- const useRequest = () => {
3
- const { request } = useDocument();
4
- if (__XANIX_SERVER__) {
5
- return request;
6
- }
7
- };
8
- export default useRequest;
@@ -1,2 +0,0 @@
1
- export * from "./navigate.js";
2
- export * from "./useLocation.js";
@@ -1,2 +0,0 @@
1
- export * from "./navigate.js";
2
- export * from "./useLocation.js";
@@ -1,7 +0,0 @@
1
- export declare const navigate: (path: string, replace?: boolean) => void;
2
- export declare const back: () => void;
3
- export declare const forward: () => void;
4
- export declare const preload: (path: string) => Promise<void>;
5
- export declare const reload: (hard?: boolean) => void;
6
- export declare const onNavigateStart: (callback: () => void) => void;
7
- export declare const onNavigateEnd: (callback: () => void) => void;
@@ -1,31 +0,0 @@
1
- export const navigate = (path, replace = false) => {
2
- window.dispatchEvent(new CustomEvent("xanix:navigate", {
3
- detail: { path, replace },
4
- }));
5
- };
6
- export const back = () => {
7
- window.history.back();
8
- };
9
- export const forward = () => {
10
- window.history.forward();
11
- };
12
- export const preload = async (path) => {
13
- window.dispatchEvent(new CustomEvent("xanix:preload", { detail: { path } }));
14
- };
15
- export const reload = (hard = false) => {
16
- if (hard) {
17
- window.location.reload();
18
- return;
19
- }
20
- window.dispatchEvent(new CustomEvent("xanix:reload"));
21
- };
22
- export const onNavigateStart = (callback) => {
23
- if (__XANIX_CLIENT__) {
24
- window.addEventListener("xanix:navigate:start", callback);
25
- }
26
- };
27
- export const onNavigateEnd = (callback) => {
28
- if (__XANIX_CLIENT__) {
29
- window.addEventListener("xanix:navigate:end", callback);
30
- }
31
- };
@@ -1 +0,0 @@
1
- export declare const useLocation: () => URL;
@@ -1,22 +0,0 @@
1
- import { useDocument } from "../document/index.js";
2
- import { useState, useEffect } from "react";
3
- export const useLocation = () => {
4
- const _document = useDocument();
5
- const req = _document?.request;
6
- let _url;
7
- if (__XANIX_SERVER__) {
8
- _url = new URL(req.originalUrl, `${req.protocol}://${req.get("host")}`);
9
- }
10
- else {
11
- _url = new URL(window.location.href);
12
- }
13
- const [url, setUrl] = useState(_url);
14
- useEffect(() => {
15
- const onNavigate = () => setUrl(new URL(window.location.href));
16
- window.addEventListener("xanix:navigate:end", onNavigate);
17
- return () => {
18
- window.removeEventListener("xanix:navigate:end", onNavigate);
19
- };
20
- }, []);
21
- return url;
22
- };
@@ -1,3 +0,0 @@
1
- export * from "../hooks/useSearchParams.js";
2
- export * from "../hooks/useParams.js";
3
- export * from "../hooks/usePathname.js";
@@ -1,3 +0,0 @@
1
- export * from "../hooks/useSearchParams.js";
2
- export * from "../hooks/useParams.js";
3
- export * from "../hooks/usePathname.js";
@@ -1 +0,0 @@
1
- export declare const useParams: () => any;
@@ -1,5 +0,0 @@
1
- import useDocument from "../hooks/useDocument.js";
2
- export const useParams = () => {
3
- const { params } = useDocument();
4
- return params;
5
- };
@@ -1 +0,0 @@
1
- export declare const usePathname: () => any;
@@ -1,8 +0,0 @@
1
- import useDocument from "../hooks/useDocument.js";
2
- export const usePathname = () => {
3
- if (__XANIX_CLIENT__) {
4
- return window.location.pathname;
5
- }
6
- const { request } = useDocument();
7
- return request?.path;
8
- };
@@ -1,11 +0,0 @@
1
- export declare const useSearchParams: () => {
2
- get: (key: string) => string | null;
3
- getAll: () => any;
4
- has: (key: string) => boolean;
5
- set: (key: string, value: string) => void;
6
- sets: (entries: Record<string, string>) => void;
7
- delete: (key: string) => void;
8
- deletes: (keys: string[]) => void;
9
- clear: () => void;
10
- toString: () => string;
11
- };
@@ -1,74 +0,0 @@
1
- import { navigate } from "../navigation/navigate.js";
2
- import { useEffect, useState } from "react";
3
- import useDocument from "../hooks/useDocument.js";
4
- const getParams = () => {
5
- return new URLSearchParams(window.location.search);
6
- };
7
- const buildUrl = (params) => {
8
- const search = params.toString();
9
- return (window.location.pathname +
10
- (search ? `?${search}` : "") +
11
- window.location.hash);
12
- };
13
- export const useSearchParams = () => {
14
- const { request } = useDocument();
15
- let _params = new URLSearchParams(__XANIX_SERVER__ ? request.url.split("?")[1] || "" : window.location.search);
16
- const [params, setParams] = useState(_params);
17
- useEffect(() => {
18
- const onNavigate = () => {
19
- setParams(getParams());
20
- };
21
- window.addEventListener("xanix:navigate:end", onNavigate);
22
- window.addEventListener("popstate", onNavigate);
23
- return () => {
24
- window.removeEventListener("xanix:navigate:end", onNavigate);
25
- window.removeEventListener("popstate", onNavigate);
26
- };
27
- }, []);
28
- const update = (newParams) => {
29
- setParams(newParams);
30
- navigate(buildUrl(newParams));
31
- };
32
- return {
33
- get: (key) => params.get(key),
34
- getAll: () => {
35
- const p = {};
36
- for (const [key, value] of params.entries()) {
37
- if (!p[key]) {
38
- p[key] = [];
39
- }
40
- p[key].push(value);
41
- }
42
- return p;
43
- },
44
- has: (key) => params.has(key),
45
- set: (key, value) => {
46
- const newParams = new URLSearchParams(params);
47
- newParams.set(key, value);
48
- update(newParams);
49
- },
50
- sets: (entries) => {
51
- const newParams = new URLSearchParams(params);
52
- for (const [key, value] of Object.entries(entries)) {
53
- newParams.set(key, value);
54
- }
55
- update(newParams);
56
- },
57
- delete: (key) => {
58
- const newParams = new URLSearchParams(params);
59
- newParams.delete(key);
60
- update(newParams);
61
- },
62
- deletes: (keys) => {
63
- const newParams = new URLSearchParams(params);
64
- for (const key of keys) {
65
- newParams.delete(key);
66
- }
67
- update(newParams);
68
- },
69
- clear: () => {
70
- update(new URLSearchParams());
71
- },
72
- toString: () => params.toString(),
73
- };
74
- };
@@ -1,12 +0,0 @@
1
- import express from "express";
2
- export interface XanixProps {
3
- clientId: string;
4
- req: any;
5
- res: any;
6
- component: React.ReactElement;
7
- }
8
- type Options = {
9
- mode: "watch" | "start";
10
- };
11
- export declare function createXanixServer({ mode }: Options): express.Express;
12
- export {};
@@ -1,40 +0,0 @@
1
- import express from "express";
2
- export function createXanixServer({ mode }) {
3
- const app = express();
4
- if (mode === "watch") {
5
- app.use("/.xanix/client", express.static(".xanix/client"));
6
- app.use("/assets", express.static(".xanix/assets"));
7
- app.use("/.xanix/cache", express.static(".xanix/cache"));
8
- }
9
- else {
10
- app.use("/.xanix/client", express.static(".xanix/client", {
11
- maxAge: "1y",
12
- immutable: true,
13
- etag: true,
14
- }));
15
- app.use("/assets", express.static(".xanix/assets", {
16
- maxAge: "1y",
17
- immutable: true,
18
- etag: true,
19
- }));
20
- }
21
- app.use((req, res, next) => {
22
- let data = {
23
- title: null,
24
- meta: [],
25
- };
26
- if (!req.page) {
27
- req.page = {
28
- setTitle(title) {
29
- data.title = title;
30
- },
31
- setMeta(name, content) {
32
- data.meta.push({ name, content });
33
- },
34
- };
35
- req.XanixPageData = data;
36
- }
37
- next();
38
- });
39
- return app;
40
- }
@@ -1,12 +0,0 @@
1
- import express from "express";
2
- export interface XanixProps {
3
- clientId: string;
4
- req: any;
5
- res: any;
6
- component: React.ReactElement;
7
- }
8
- type Options = {
9
- mode: "watch" | "start";
10
- };
11
- export declare function createXanixServer({ mode }: Options): express.Express;
12
- export {};
@@ -1,40 +0,0 @@
1
- import express from "express";
2
- export function createXanixServer({ mode }) {
3
- const app = express();
4
- if (mode === "watch") {
5
- app.use("/.xanix/client", express.static(".xanix/client"));
6
- app.use("/assets", express.static(".xanix/assets"));
7
- app.use("/.xanix/cache", express.static(".xanix/cache"));
8
- }
9
- else {
10
- app.use("/.xanix/client", express.static(".xanix/client", {
11
- maxAge: "1y",
12
- immutable: true,
13
- etag: true,
14
- }));
15
- app.use("/assets", express.static(".xanix/assets", {
16
- maxAge: "1y",
17
- immutable: true,
18
- etag: true,
19
- }));
20
- }
21
- app.use((req, res, next) => {
22
- let data = {
23
- title: null,
24
- meta: [],
25
- };
26
- if (!req.page) {
27
- req.page = {
28
- setTitle(title) {
29
- data.title = title;
30
- },
31
- setMeta(name, content) {
32
- data.meta.push({ name, content });
33
- },
34
- };
35
- req.XanixPageData = data;
36
- }
37
- next();
38
- });
39
- return app;
40
- }
@@ -1,14 +0,0 @@
1
- interface XanixManifestEntry {
2
- id: string;
3
- name: string;
4
- file: string;
5
- path: string;
6
- build: string;
7
- export: string;
8
- }
9
- interface XanixManifest {
10
- version: number;
11
- entries: XanixManifestEntry[];
12
- }
13
- declare function readManifest(): Promise<XanixManifest>;
14
- export default readManifest;
@@ -1,8 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- async function readManifest() {
4
- const manifestPath = path.resolve(process.cwd(), ".xanix", "client-manifest.json");
5
- const source = await fs.readFile(manifestPath, "utf8");
6
- return JSON.parse(source);
7
- }
8
- export default readManifest;
@@ -1,9 +0,0 @@
1
- interface XanixPageProps {
2
- pageId: string;
3
- req: any;
4
- res: any;
5
- Component: (props: Record<string, any>) => React.ReactElement;
6
- props: Record<string, any>;
7
- }
8
- export default function xanix_page({ pageId, req, res, Component, props, }: XanixPageProps): Promise<string | undefined>;
9
- export {};
@@ -1,62 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { renderToPipeableStream } from "react-dom/server";
3
- import readManifest from "./readManifest.js";
4
- import { PassThrough } from "node:stream";
5
- import path from "node:path";
6
- import { pathToFileURL } from "node:url";
7
- function renderPage(element) {
8
- return new Promise((resolve, reject) => {
9
- let html = "";
10
- const stream = new PassThrough();
11
- stream.on("data", (chunk) => {
12
- html += chunk.toString();
13
- });
14
- stream.on("end", () => {
15
- resolve(html);
16
- });
17
- stream.on("error", reject);
18
- const { pipe } = renderToPipeableStream(element, {
19
- onAllReady() {
20
- pipe(stream);
21
- },
22
- onError(error) {
23
- console.error("SSR error:", error);
24
- },
25
- });
26
- });
27
- }
28
- export default async function xanix_page({ pageId, req, res, Component, props, }) {
29
- const manifest = await readManifest();
30
- const { title, meta } = req.XanixPageData;
31
- const entry = manifest.entries.find((item) => item.id === pageId);
32
- const method = req.method.toUpperCase();
33
- if (method !== "GET") {
34
- res.status(405).send("Method Not Allowed");
35
- return;
36
- }
37
- if (!entry) {
38
- throw new Error(`Xanix client entry "${pageId}" was not found in the manifest.`);
39
- }
40
- if ("x-navigation" in req.headers) {
41
- res.setHeader("Content-Type", "application/json");
42
- return JSON.stringify({
43
- pageId,
44
- props,
45
- title: title ?? entry.name.replaceAll("-", " "),
46
- meta,
47
- params: req.params,
48
- request: null,
49
- });
50
- }
51
- const Document = (await import(pathToFileURL(path.join(process.cwd(), ".xanix", "xanix-document.js"))
52
- .href)).default;
53
- const html = await renderPage(_jsx(Document, { document: {
54
- pageId,
55
- props,
56
- title: title ?? entry.name.replaceAll("-", " "),
57
- meta,
58
- params: req.params,
59
- request: req,
60
- }, children: _jsx(Component, { ...props }) }));
61
- return `<!DOCTYPE html>${html}`;
62
- }
@@ -1,12 +0,0 @@
1
- import express from "express";
2
- export interface XanixProps {
3
- clientId: string;
4
- req: any;
5
- res: any;
6
- component: React.ReactElement;
7
- }
8
- type Options = {
9
- mode: "watch" | "start";
10
- };
11
- export declare function createXanixServer({ mode }: Options): express.Express;
12
- export {};
@@ -1,40 +0,0 @@
1
- import express from "express";
2
- export function createXanixServer({ mode }) {
3
- const app = express();
4
- if (mode === "watch") {
5
- app.use("/.xanix/client", express.static(".xanix/client"));
6
- app.use("/assets", express.static(".xanix/assets"));
7
- app.use("/.xanix/cache", express.static(".xanix/cache"));
8
- }
9
- else {
10
- app.use("/.xanix/client", express.static(".xanix/client", {
11
- maxAge: "1y",
12
- immutable: true,
13
- etag: true,
14
- }));
15
- app.use("/assets", express.static(".xanix/assets", {
16
- maxAge: "1y",
17
- immutable: true,
18
- etag: true,
19
- }));
20
- }
21
- app.use((req, res, next) => {
22
- let data = {
23
- title: null,
24
- meta: [],
25
- };
26
- if (!req.page) {
27
- req.page = {
28
- setTitle(title) {
29
- data.title = title;
30
- },
31
- setMeta(name, content) {
32
- data.meta.push({ name, content });
33
- },
34
- };
35
- req.XanixPageData = data;
36
- }
37
- next();
38
- });
39
- return app;
40
- }
@@ -1,9 +0,0 @@
1
- interface XanixPageProps {
2
- pageId: string;
3
- req: any;
4
- res: any;
5
- Component: (props: Record<string, any>) => React.ReactElement;
6
- props: Record<string, any>;
7
- }
8
- export default function xanix_page({ pageId, req, res, Component, props, }: XanixPageProps): Promise<string | undefined>;
9
- export {};
@@ -1,62 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { renderToPipeableStream } from "react-dom/server";
3
- import readManifest from "./readManifest.js";
4
- import { PassThrough } from "node:stream";
5
- import path from "node:path";
6
- import { pathToFileURL } from "node:url";
7
- function renderPage(element) {
8
- return new Promise((resolve, reject) => {
9
- let html = "";
10
- const stream = new PassThrough();
11
- stream.on("data", (chunk) => {
12
- html += chunk.toString();
13
- });
14
- stream.on("end", () => {
15
- resolve(html);
16
- });
17
- stream.on("error", reject);
18
- const { pipe } = renderToPipeableStream(element, {
19
- onAllReady() {
20
- pipe(stream);
21
- },
22
- onError(error) {
23
- console.error("SSR error:", error);
24
- },
25
- });
26
- });
27
- }
28
- export default async function xanix_page({ pageId, req, res, Component, props, }) {
29
- const manifest = await readManifest();
30
- const { title, meta } = req.XanixPageData;
31
- const entry = manifest.entries.find((item) => item.id === pageId);
32
- const method = req.method.toUpperCase();
33
- if (method !== "GET") {
34
- res.status(405).send("Method Not Allowed");
35
- return;
36
- }
37
- if (!entry) {
38
- throw new Error(`Xanix client entry "${pageId}" was not found in the manifest.`);
39
- }
40
- if ("x-navigation" in req.headers) {
41
- res.setHeader("Content-Type", "application/json");
42
- return JSON.stringify({
43
- pageId,
44
- props,
45
- title: title ?? entry.name.replaceAll("-", " "),
46
- meta,
47
- params: req.params,
48
- request: null,
49
- });
50
- }
51
- const Document = (await import(pathToFileURL(path.join(process.cwd(), ".xanix", "xanix-document.js"))
52
- .href)).default;
53
- const html = await renderPage(_jsx(Document, { document: {
54
- pageId,
55
- props,
56
- title: title ?? entry.name.replaceAll("-", " "),
57
- meta,
58
- params: req.params,
59
- request: req,
60
- }, children: _jsx(Component, { ...props }) }));
61
- return `<!DOCTYPE html>${html}`;
62
- }
@@ -1,14 +0,0 @@
1
- interface XanixManifestEntry {
2
- id: string;
3
- name: string;
4
- file: string;
5
- path: string;
6
- build: string;
7
- export: string;
8
- }
9
- interface XanixManifest {
10
- version: number;
11
- entries: XanixManifestEntry[];
12
- }
13
- declare function readManifest(): Promise<XanixManifest>;
14
- export default readManifest;
@@ -1,8 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- async function readManifest() {
4
- const manifestPath = path.resolve(process.cwd(), ".xanix", "client-manifest.json");
5
- const source = await fs.readFile(manifestPath, "utf8");
6
- return JSON.parse(source);
7
- }
8
- export default readManifest;
@@ -1,12 +0,0 @@
1
- import express from "express";
2
- export interface XanixProps {
3
- clientId: string;
4
- req: any;
5
- res: any;
6
- component: React.ReactElement;
7
- }
8
- type Options = {
9
- mode: "watch" | "start";
10
- };
11
- export declare function createXanixServer({ mode }: Options): express.Express;
12
- export {};
@@ -1,40 +0,0 @@
1
- import express from "express";
2
- export function createXanixServer({ mode }) {
3
- const app = express();
4
- if (mode === "watch") {
5
- app.use("/.xanix/client", express.static(".xanix/client"));
6
- app.use("/assets", express.static(".xanix/assets"));
7
- app.use("/.xanix/cache", express.static(".xanix/cache"));
8
- }
9
- else {
10
- app.use("/.xanix/client", express.static(".xanix/client", {
11
- maxAge: "1y",
12
- immutable: true,
13
- etag: true,
14
- }));
15
- app.use("/assets", express.static(".xanix/assets", {
16
- maxAge: "1y",
17
- immutable: true,
18
- etag: true,
19
- }));
20
- }
21
- app.use((req, res, next) => {
22
- let data = {
23
- title: null,
24
- meta: [],
25
- };
26
- if (!req.page) {
27
- req.page = {
28
- setTitle(title) {
29
- data.title = title;
30
- },
31
- setMeta(name, content) {
32
- data.meta.push({ name, content });
33
- },
34
- };
35
- req.XanixPageData = data;
36
- }
37
- next();
38
- });
39
- return app;
40
- }
@@ -1,12 +0,0 @@
1
- import express from "express";
2
- export interface XanixProps {
3
- clientId: string;
4
- req: any;
5
- res: any;
6
- component: React.ReactElement;
7
- }
8
- type Options = {
9
- mode: "watch" | "start";
10
- };
11
- export declare function createXanixServer({ mode }: Options): express.Express;
12
- export {};