xanix 1.0.4 → 1.0.7

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 +4 -4
  3. package/dist/bin/bundler/cacheNpmModules.js +8 -2
  4. package/dist/bin/bundler/config/output.d.ts +1 -1
  5. package/dist/bin/bundler/config/output.js +11 -3
  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 +13 -3
  9. package/dist/bin/bundler/plugins/XanixReactRefresh.js +33 -33
  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 +8 -5
  15. package/dist/bin/cli/dev.js +2 -2
  16. package/dist/bin/include/utils.d.ts +3 -0
  17. package/dist/bin/include/utils.js +17 -0
  18. package/dist/bin/index.js +0 -0
  19. package/dist/client-runtime.js +17 -15
  20. package/dist/components/BaseDocument.d.ts +1 -1
  21. package/dist/components/BaseDocument.js +1 -3
  22. package/dist/components/Body.js +3 -1
  23. package/dist/components/Document.js +3 -1
  24. package/dist/components/Head.d.ts +1 -1
  25. package/dist/components/Head.js +37 -34
  26. package/dist/components/Link.d.ts +1 -1
  27. package/dist/components/Link.js +23 -18
  28. package/dist/dataLoader.d.ts +1 -1
  29. package/dist/dataLoader.js +14 -5
  30. package/dist/hooks/useData.d.ts +2 -6
  31. package/dist/hooks/useData.js +1 -1
  32. package/dist/index.d.ts +4 -0
  33. package/dist/index.js +3 -0
  34. package/dist/navigate.js +11 -8
  35. package/dist/server/runtime/xanixPage.js +1 -4
  36. package/dist/types/assets.d.ts +34 -0
  37. package/dist/types/express.d.ts +12 -0
  38. package/dist/types/globals.d.ts +27 -0
  39. package/dist/types/xanix-virtual.d.ts +26 -0
  40. package/package.json +75 -73
  41. package/dist/BaseDocument.d.ts +0 -3
  42. package/dist/BaseDocument.js +0 -8
  43. package/dist/bin/bundler/buildCache.d.ts +0 -11
  44. package/dist/bin/bundler/buildCache.js +0 -112
  45. package/dist/bin/bundler/plugins/XanixAssets/index.d.ts +0 -4
  46. package/dist/bin/bundler/plugins/XanixAssets/index.js +0 -22
  47. package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.d.ts +0 -6
  48. package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.js +0 -350
  49. package/dist/bin/bundler/plugins/XanixHydrate.d.ts +0 -3
  50. package/dist/bin/bundler/plugins/XanixHydrate.js +0 -34
  51. package/dist/bin/bundler/plugins/commonjs.d.ts +0 -3
  52. package/dist/bin/bundler/plugins/commonjs.js +0 -10
  53. package/dist/bin/bundler/plugins/dep-XanixWatchChange.d.ts +0 -9
  54. package/dist/bin/bundler/plugins/dep-XanixWatchChange.js +0 -27
  55. package/dist/bin/bundler/plugins/nodeResolve.d.ts +0 -3
  56. package/dist/bin/bundler/plugins/nodeResolve.js +0 -10
  57. package/dist/bin/bundler/plugins/rollupEsbuild.d.ts +0 -3
  58. package/dist/bin/bundler/plugins/rollupEsbuild.js +0 -14
  59. package/dist/bin/cli/start copy.d.ts +0 -2
  60. package/dist/bin/cli/start copy.js +0 -34
  61. package/dist/client/client-runtime.d.ts +0 -10
  62. package/dist/client/client-runtime.js +0 -98
  63. package/dist/client/context/RouteContext.d.ts +0 -8
  64. package/dist/client/context/RouteContext.js +0 -16
  65. package/dist/client/hooks/usePageProps.d.ts +0 -1
  66. package/dist/client/hooks/usePageProps.js +0 -2
  67. package/dist/client/hooks/useRoute.d.ts +0 -1
  68. package/dist/client/hooks/useRoute.js +0 -2
  69. package/dist/client/hooks/useSearchParams.d.ts +0 -1
  70. package/dist/client/hooks/useSearchParams.js +0 -2
  71. package/dist/client/index.d.ts +0 -2
  72. package/dist/client/index.js +0 -2
  73. package/dist/client/navigation.d.ts +0 -3
  74. package/dist/client/navigation.js +0 -27
  75. package/dist/client/runtime.d.ts +0 -10
  76. package/dist/client/runtime.js +0 -98
  77. package/dist/components/Document/context.d.ts +0 -11
  78. package/dist/components/Document/context.js +0 -14
  79. package/dist/components/Document/index.d.ts +0 -8
  80. package/dist/components/Document/index.js +0 -6
  81. package/dist/document/BaseDocument.d.ts +0 -3
  82. package/dist/document/BaseDocument.js +0 -8
  83. package/dist/document/Body.d.ts +0 -5
  84. package/dist/document/Body.js +0 -8
  85. package/dist/document/Document.d.ts +0 -7
  86. package/dist/document/Document.js +0 -9
  87. package/dist/document/DocumentContext.d.ts +0 -18
  88. package/dist/document/DocumentContext.js +0 -6
  89. package/dist/document/Head.d.ts +0 -5
  90. package/dist/document/Head.js +0 -41
  91. package/dist/document/Link.d.ts +0 -7
  92. package/dist/document/Link.js +0 -28
  93. package/dist/document/Script.d.ts +0 -3
  94. package/dist/document/Script.js +0 -5
  95. package/dist/document/index.d.ts +0 -8
  96. package/dist/document/index.js +0 -7
  97. package/dist/document/useDocument.d.ts +0 -2
  98. package/dist/document/useDocument.js +0 -10
  99. package/dist/hooks/useCookie.d.ts +0 -2
  100. package/dist/hooks/useCookie.js +0 -13
  101. package/dist/hooks/useRequest copy.d.ts +0 -2
  102. package/dist/hooks/useRequest copy.js +0 -8
  103. package/dist/navigation/index.d.ts +0 -2
  104. package/dist/navigation/index.js +0 -2
  105. package/dist/navigation/navigate.d.ts +0 -7
  106. package/dist/navigation/navigate.js +0 -31
  107. package/dist/navigation/useLocation.d.ts +0 -1
  108. package/dist/navigation/useLocation.js +0 -22
  109. package/dist/router/index.d.ts +0 -3
  110. package/dist/router/index.js +0 -3
  111. package/dist/router/useParams.d.ts +0 -1
  112. package/dist/router/useParams.js +0 -5
  113. package/dist/router/usePathname.d.ts +0 -1
  114. package/dist/router/usePathname.js +0 -8
  115. package/dist/router/useSearchParams.d.ts +0 -11
  116. package/dist/router/useSearchParams.js +0 -74
  117. package/dist/runtime/createServer.d.ts +0 -12
  118. package/dist/runtime/createServer.js +0 -40
  119. package/dist/runtime/index.d.ts +0 -12
  120. package/dist/runtime/index.js +0 -40
  121. package/dist/runtime/readManifest.d.ts +0 -14
  122. package/dist/runtime/readManifest.js +0 -8
  123. package/dist/runtime/xanixPage.d.ts +0 -9
  124. package/dist/runtime/xanixPage.js +0 -62
  125. package/dist/server/createServer.d.ts +0 -12
  126. package/dist/server/createServer.js +0 -40
  127. package/dist/server/page.d.ts +0 -9
  128. package/dist/server/page.js +0 -62
  129. package/dist/server/readManifest.d.ts +0 -14
  130. package/dist/server/readManifest.js +0 -8
  131. package/dist/server/runtime copy.d.ts +0 -12
  132. package/dist/server/runtime copy.js +0 -40
  133. package/dist/server/runtime.d.ts +0 -12
  134. package/dist/server/runtime.js +0 -40
  135. package/dist/server/xanixPage.d.ts +0 -9
  136. package/dist/server/xanixPage.js +0 -62
  137. package/dist/types.d.ts +0 -12
  138. package/dist/types.js +0 -7
  139. package/dist/utils/index.d.ts +0 -0
  140. package/dist/utils/index.js +0 -1
  141. package/dist/xanix.d.ts +0 -3
  142. package/dist/xanix.js +0 -40
  143. package/xanix-env.d.ts +0 -79
@@ -1,15 +1,15 @@
1
1
  import { rollup } from "rollup";
2
2
  import fs from "node:fs";
3
3
  import bundlerOutput, { outDir } from "./config/output.js";
4
- import { getDocumentFile, getClientRuntimeFile } from "../include/utils.js";
4
+ import { getClientRuntimeFile, getClientRuntimeFileName, } from "../include/utils.js";
5
5
  import { xanixDefaultPlugins } from "./plugins/plugins.js";
6
6
  const buildClient = async (entries) => {
7
7
  const input = {};
8
8
  for (const entry of entries) {
9
9
  input[entry.name] = entry.file;
10
10
  }
11
- input["xanix-runtime"] = getClientRuntimeFile();
12
- input["xanix-document"] = await getDocumentFile();
11
+ const runtimeFileName = getClientRuntimeFileName("production");
12
+ input[runtimeFileName] = getClientRuntimeFile();
13
13
  fs.rmSync(outDir.client, {
14
14
  recursive: true,
15
15
  force: true,
@@ -4,7 +4,6 @@ import bundlerOutput, { outDir } from "./config/output.js";
4
4
  import fs from "node:fs";
5
5
  import { createManifest } from "../include/manifest.js";
6
6
  import generateClientEntries from "./generateClientEntries.js";
7
- import { getDocumentFile } from "../include/utils.js";
8
7
  import { xanixDefaultPlugins } from "./plugins/plugins.js";
9
8
  const root = process.cwd();
10
9
  const BuildServer = async ({ rootEntry, onBuildEnd }) => {
@@ -19,7 +18,6 @@ const BuildServer = async ({ rootEntry, onBuildEnd }) => {
19
18
  await createManifest(entries);
20
19
  const input = {
21
20
  index: path.resolve(root, rootEntry),
22
- "xanix-document": await getDocumentFile(),
23
21
  };
24
22
  const build = await rollup({
25
23
  input,
@@ -42,13 +40,15 @@ const BuildServer = async ({ rootEntry, onBuildEnd }) => {
42
40
  if (id.startsWith(".") ||
43
41
  path.isAbsolute(id) ||
44
42
  id === "@" ||
45
- id.startsWith("@/")) {
43
+ id.startsWith("@/") ||
44
+ id.startsWith("xanix") ||
45
+ id === "virtual:xanix-document") {
46
46
  return false;
47
47
  }
48
48
  return true;
49
49
  },
50
50
  });
51
- await build.write(bundlerOutput.server());
51
+ await build.write(bundlerOutput.server({ isDev: false }));
52
52
  await build.close();
53
53
  await onBuildEnd(entries);
54
54
  };
@@ -6,6 +6,7 @@ import { createRequire } from "node:module";
6
6
  import { getClientRuntimeFile, getDocumentFile } from "../include/utils.js";
7
7
  import esbuild from "rollup-plugin-esbuild";
8
8
  import url from "@rollup/plugin-url";
9
+ import XanixDocument from "./plugins/XanixDocument/index.js";
9
10
  const require = createRequire(import.meta.url);
10
11
  const GenerateGraph = async (entries) => {
11
12
  const collector = new Map();
@@ -41,6 +42,7 @@ const GenerateGraph = async (entries) => {
41
42
  fileName: "assets/[name]-[hash][extname]",
42
43
  emitFiles: false,
43
44
  }),
45
+ XanixDocument(),
44
46
  esbuild({
45
47
  target: "es2022",
46
48
  jsx: "automatic",
@@ -51,7 +53,8 @@ const GenerateGraph = async (entries) => {
51
53
  if (id.startsWith(".") ||
52
54
  path.isAbsolute(id) ||
53
55
  id === "@" ||
54
- id.startsWith("@/")) {
56
+ id.startsWith("@/") ||
57
+ id === "virtual:xanix-document") {
55
58
  return false;
56
59
  }
57
60
  collector.set(id, {
@@ -96,7 +99,9 @@ const buildWrappers = (input) => {
96
99
  "default" in mod;
97
100
  namedExports = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
98
101
  }
99
- catch { }
102
+ catch (err) {
103
+ console.log(err);
104
+ }
100
105
  const lines = [`import * as __mod from ${JSON.stringify(resolved)};`];
101
106
  if (hasDefault) {
102
107
  lines.push(`export default __mod.default;`);
@@ -104,6 +109,7 @@ const buildWrappers = (input) => {
104
109
  else {
105
110
  lines.push(`export default __mod;`);
106
111
  }
112
+ lines.push("");
107
113
  for (const exportName of namedExports) {
108
114
  if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
109
115
  lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}];`);
@@ -9,6 +9,6 @@ type Options = {
9
9
  };
10
10
  declare const bundlerOutput: {
11
11
  client: (entries: XanixClientEntry[], { isDev }: Options) => OutputOptions;
12
- server: () => OutputOptions;
12
+ server: (opt: Options) => OutputOptions;
13
13
  };
14
14
  export default bundlerOutput;
@@ -31,14 +31,22 @@ const client = (entries, { isDev }) => {
31
31
  }
32
32
  return opt;
33
33
  };
34
- const server = () => {
34
+ const server = (opt) => {
35
35
  return {
36
36
  dir: outDir.server,
37
37
  format: "esm",
38
- sourcemap: false,
38
+ sourcemap: opt.isDev ?? true,
39
39
  entryFileNames: "[name].js",
40
- chunkFileNames: "chunks/[hash].js",
40
+ chunkFileNames: "chunks/[name].js",
41
41
  assetFileNames: "assets/[hash][extname]",
42
+ // manualChunks(id) {
43
+ // const filename = path.basename(id);
44
+ // return filename.split(".")[0];
45
+ // return "vendor";
46
+ // if (id.includes("virtual:xanix-document")) {
47
+ // return "vendor";
48
+ // }
49
+ // },
42
50
  };
43
51
  };
44
52
  const bundlerOutput = {
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from "rollup";
2
+ export default function xanixDocument(): Plugin;
@@ -0,0 +1,35 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { createRequire } from "node:module";
4
+ import { fileURLToPath } from "node:url";
5
+ const __dirname = fileURLToPath(import.meta.url);
6
+ const require = createRequire(import.meta.url);
7
+ const VIRTUAL_ID = "virtual:xanix-document";
8
+ const RESOLVED_ID = "\0virtual:xanix-document";
9
+ export default function xanixDocument() {
10
+ const root = process.cwd();
11
+ const userDocument = path.resolve(root, "Document.tsx");
12
+ const baseDocument = require.resolve("../../../../../dist/components/BaseDocument.js");
13
+ return {
14
+ name: "xanix-document",
15
+ resolveId(id) {
16
+ if (id === VIRTUAL_ID) {
17
+ return RESOLVED_ID;
18
+ }
19
+ return null;
20
+ },
21
+ load(id) {
22
+ if (id !== RESOLVED_ID) {
23
+ return null;
24
+ }
25
+ const document = fs.existsSync(userDocument)
26
+ ? userDocument
27
+ : baseDocument;
28
+ return `
29
+ import Document from ${JSON.stringify(document)};
30
+
31
+ export default Document;
32
+ `;
33
+ },
34
+ };
35
+ }
@@ -2,6 +2,7 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import dotenv from "dotenv";
4
4
  import replace from "@rollup/plugin-replace";
5
+ import { getClientRuntimeFileName, getDocumentFileName, } from "../../include/utils.js";
5
6
  export default function XanixEnvPlugin(options = {}) {
6
7
  const root = process.cwd();
7
8
  const mode = options.mode ?? "development";
@@ -31,13 +32,22 @@ export default function XanixEnvPlugin(options = {}) {
31
32
  }
32
33
  const envs = {
33
34
  "process.env.NODE_ENV": JSON.stringify(mode),
34
- // "typeof window": isClient ? '"object"' : '"undefined"',
35
- // "typeof document": isClient ? '"object"' : '"undefined"',
35
+ ...(isClient ? clientEnv : serverEnv),
36
+ __XANIX_CLIENT_RUNTIME_FILE_NAME__: JSON.stringify(getClientRuntimeFileName(mode)),
37
+ __XANIX_DOCUMENT_FILE_NAME__: JSON.stringify(getDocumentFileName(mode)),
38
+ // XANIX Data
39
+ XANIXDT: JSON.stringify("globalThis.$XANIXDT"),
36
40
  __XANIX_CLIENT__: JSON.stringify(isClient),
37
41
  __XANIX_SERVER__: JSON.stringify(!isClient),
38
42
  __XANIX_DEV__: JSON.stringify(mode === "development"),
39
43
  __XANIX_PROD__: JSON.stringify(mode === "production"),
40
- ...(isClient ? clientEnv : serverEnv),
44
+ XANIX_NAVIGATE: JSON.stringify("xanix:navigate"),
45
+ XANIX_NAVIGATE_START: JSON.stringify("xanix:navigate:start"),
46
+ XANIX_NAVIGATE_END: JSON.stringify("xanix:navigate:end"),
47
+ XANIX_NAVIGATE_RELOAD: JSON.stringify("xanix:navigate:reload"),
48
+ XANIX_PRELOAD: JSON.stringify("xanix:preload"),
49
+ XANIX_PRELOAD_START: JSON.stringify("xanix:preload:start"),
50
+ XANIX_PRELOAD_END: JSON.stringify("xanix:preload:end"),
41
51
  };
42
52
  return replace({
43
53
  preventAssignment: true,
@@ -16,39 +16,39 @@ export default function xanixReactRefresh() {
16
16
  return null;
17
17
  }
18
18
  const code = fs.readFileSync(id, "utf8");
19
- const refreshCode = `
20
- import * as RefreshRuntime from "react-refresh/runtime";
21
-
22
- ${code}
23
-
24
- if (typeof window !== "undefined") {
25
- RefreshRuntime.injectIntoGlobalHook(window);
26
-
27
- window.$RefreshReg$ = RefreshRuntime.register;
28
- window.$RefreshSig$ = () => (type) => type;
29
-
30
- const ws = new WebSocket("ws://localhost:8080");
31
-
32
- ws.onmessage = async (event) => {
33
- const files = JSON.parse(event.data);
34
-
35
- for (const file of files) {
36
- if (!file.endsWith(".js")) {
37
- continue;
38
- }
39
-
40
- const url =
41
- getImportUrl(file.replace(/\\.js$/, "")) +
42
- "?t=" +
43
- Date.now();
44
-
45
- await import(url);
46
- }
47
-
48
- RefreshRuntime.performReactRefresh();
49
- ws.send("reload")
50
- };
51
- }
19
+ const refreshCode = `
20
+ import * as RefreshRuntime from "react-refresh/runtime";
21
+
22
+ ${code}
23
+
24
+ if (typeof window !== "undefined") {
25
+ RefreshRuntime.injectIntoGlobalHook(window);
26
+
27
+ window.$RefreshReg$ = RefreshRuntime.register;
28
+ window.$RefreshSig$ = () => (type) => type;
29
+
30
+ const ws = new WebSocket("ws://localhost:8080");
31
+
32
+ ws.onmessage = async (event) => {
33
+ const files = JSON.parse(event.data);
34
+
35
+ for (const file of files) {
36
+ if (!file.endsWith(".js")) {
37
+ continue;
38
+ }
39
+
40
+ const url =
41
+ getImportUrl(file.replace(/\\.js$/, "")) +
42
+ "?t=" +
43
+ Date.now();
44
+
45
+ await import(url);
46
+ }
47
+
48
+ RefreshRuntime.performReactRefresh();
49
+ ws.send("reload")
50
+ };
51
+ }
52
52
  `;
53
53
  return {
54
54
  code: refreshCode,
@@ -0,0 +1,16 @@
1
+ import * as t from "@babel/types";
2
+ export interface XanixTransformResult {
3
+ code: string;
4
+ map: any;
5
+ }
6
+ export declare function resolveFile(file: string): string;
7
+ export declare function resolveComponentFile(importer: string, importPath: string): string;
8
+ export declare function createPageId(file: string): string;
9
+ export declare function getJSXComponentName(node: t.JSXElement): string | null;
10
+ export declare function findComponentImport(ast: t.File, componentName: string): {
11
+ file: string;
12
+ export: string;
13
+ declaration: t.ImportDeclaration;
14
+ specifier: t.ImportSpecifier | t.ImportDefaultSpecifier;
15
+ } | null;
16
+ export declare function transformer(code: string, id: string, mode: "watch" | "start"): XanixTransformResult | null;