eddev 2.0.0-beta.11 → 2.0.0-beta.111

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 (213) hide show
  1. package/dist/app/entry/HydrationOverlay.d.ts +1 -0
  2. package/dist/app/entry/HydrationOverlay.js +2 -0
  3. package/dist/app/entry/MetaTags.d.ts +7 -0
  4. package/dist/app/entry/MetaTags.js +17 -0
  5. package/dist/app/entry/boot-admin.js +8 -3
  6. package/dist/app/entry/hydration-script.d.ts +1 -0
  7. package/dist/app/entry/hydration-script.js +18 -0
  8. package/dist/app/entry/spa-root.js +3 -5
  9. package/dist/app/entry/ssr-root-client.d.ts +3 -1
  10. package/dist/app/entry/ssr-root-client.js +17 -6
  11. package/dist/app/entry/ssr-root.d.ts +3 -4
  12. package/dist/app/entry/ssr-root.js +19 -19
  13. package/dist/app/lib/admin/index.d.ts +2 -2
  14. package/dist/app/lib/admin/index.js +2 -2
  15. package/dist/app/lib/admin/installFieldTypes.js +1 -1
  16. package/dist/app/lib/admin/runWidgets.js +1 -1
  17. package/dist/app/lib/blocks/ContentBlocks.d.ts +1 -1
  18. package/dist/app/lib/blocks/ContentBlocks.js +5 -5
  19. package/dist/app/lib/blocks/EditableText.d.ts +1 -1
  20. package/dist/app/lib/blocks/EditableText.js +3 -3
  21. package/dist/app/lib/blocks/InnerBlocks.d.ts +13 -3
  22. package/dist/app/lib/blocks/InnerBlocks.js +13 -5
  23. package/dist/app/lib/blocks/block-utils.d.ts +2 -2
  24. package/dist/app/lib/blocks/block-utils.js +2 -2
  25. package/dist/app/lib/blocks/editor/EditorHighlights.d.ts +7 -0
  26. package/dist/app/lib/blocks/editor/EditorHighlights.js +130 -0
  27. package/dist/app/lib/blocks/editor/EditorSupport.js +4 -5
  28. package/dist/app/lib/blocks/editor/ErrorBoundaryEditor.d.ts +1 -1
  29. package/dist/app/lib/blocks/editor/editor-config.d.ts +17 -4
  30. package/dist/app/lib/blocks/editor/editor-config.js +24 -10
  31. package/dist/app/lib/blocks/editor/installGutenbergHooks.js +20 -14
  32. package/dist/app/lib/blocks/editor/root-blocks.d.ts +6 -0
  33. package/dist/app/lib/blocks/editor/root-blocks.js +30 -0
  34. package/dist/app/lib/blocks/editor/usePostEditor.d.ts +1 -1
  35. package/dist/app/lib/blocks/index.d.ts +9 -9
  36. package/dist/app/lib/blocks/index.js +9 -9
  37. package/dist/app/lib/blocks/inline-editing.d.ts +1 -1
  38. package/dist/app/lib/blocks/inline-editing.js +7 -5
  39. package/dist/app/lib/devtools/components/BreakpointIndicator.js +1 -1
  40. package/dist/app/lib/devtools/components/DevUI.js +4 -3
  41. package/dist/app/lib/devtools/components/GridIndicator.d.ts +1 -0
  42. package/dist/app/lib/devtools/components/GridIndicator.js +29 -0
  43. package/dist/app/lib/devtools/hooks/usePersistState.d.ts +1 -1
  44. package/dist/app/lib/devtools/hooks/usePersistState.js +11 -2
  45. package/dist/app/lib/devtools/hooks/useTailwind.d.ts +2305 -1261
  46. package/dist/app/lib/devtools/hooks/useTailwind.js +1 -1
  47. package/dist/app/lib/devtools/index.d.ts +1 -1
  48. package/dist/app/lib/devtools/index.js +1 -1
  49. package/dist/app/lib/devtools/loader.js +8 -7
  50. package/dist/app/lib/devtools/useQueryDebug.d.ts +7 -1
  51. package/dist/app/lib/devtools/useQueryDebug.js +5 -8
  52. package/dist/app/lib/dynamic/dynamic.d.ts +1 -1
  53. package/dist/app/lib/dynamic/dynamic.js +5 -1
  54. package/dist/app/lib/dynamic/index.d.ts +1 -1
  55. package/dist/app/lib/dynamic/index.js +1 -1
  56. package/dist/app/lib/hooks/index.d.ts +4 -5
  57. package/dist/app/lib/hooks/index.js +4 -5
  58. package/dist/app/lib/hooks/queryUtils.d.ts +37 -3
  59. package/dist/app/lib/hooks/queryUtils.js +66 -26
  60. package/dist/app/lib/hooks/useAppData.js +1 -1
  61. package/dist/app/lib/hooks/useRPC.d.ts +0 -4
  62. package/dist/app/lib/hooks/useRPC.js +1 -8
  63. package/dist/app/lib/internal/finalize-rpc.d.ts +17 -0
  64. package/dist/app/lib/internal/finalize-rpc.js +3 -0
  65. package/dist/app/lib/internal/index.d.ts +5 -4
  66. package/dist/app/lib/internal/index.js +5 -4
  67. package/dist/app/lib/internal/read-admin-manifest.d.ts +1 -1
  68. package/dist/app/lib/legacy-stitches/createStitches.d.ts +21 -21
  69. package/dist/app/lib/legacy-stitches/createStitches.js +1 -1
  70. package/dist/app/lib/legacy-stitches/index.d.ts +1 -1
  71. package/dist/app/lib/legacy-stitches/index.js +1 -1
  72. package/dist/app/lib/routing/components/BackButton.d.ts +49 -0
  73. package/dist/app/lib/routing/components/BackButton.js +47 -0
  74. package/dist/app/lib/routing/components/BrowserRouter.d.ts +4 -1
  75. package/dist/app/lib/routing/components/BrowserRouter.js +95 -19
  76. package/dist/app/lib/routing/components/ClientOnly.d.ts +1 -1
  77. package/dist/app/lib/routing/components/ClientOnly.js +2 -2
  78. package/dist/app/lib/routing/components/Link.d.ts +1 -0
  79. package/dist/app/lib/routing/components/Link.js +11 -12
  80. package/dist/app/lib/routing/components/RouteRenderer.d.ts +1 -1
  81. package/dist/app/lib/routing/components/RouteRenderer.js +7 -6
  82. package/dist/app/lib/routing/components/SSRRouter.d.ts +2 -2
  83. package/dist/app/lib/routing/components/SSRRouter.js +5 -6
  84. package/dist/app/lib/routing/components/ScrollRestoration.js +5 -2
  85. package/dist/app/lib/routing/context.d.ts +8 -5
  86. package/dist/app/lib/routing/context.js +13 -96
  87. package/dist/app/lib/routing/hooks/useRestorableState.d.ts +2 -1
  88. package/dist/app/lib/routing/hooks/useRestorableState.js +2 -1
  89. package/dist/app/lib/routing/hooks/useRoute.d.ts +16 -1
  90. package/dist/app/lib/routing/hooks/useRoute.js +22 -1
  91. package/dist/app/lib/routing/hooks/useRouteMeta.d.ts +5 -0
  92. package/dist/app/lib/routing/hooks/useRouteMeta.js +9 -0
  93. package/dist/app/lib/routing/hooks/useRouteTransition.d.ts +1 -1
  94. package/dist/app/lib/routing/hooks/useRouteTransition.js +1 -1
  95. package/dist/app/lib/routing/hooks/useRouter.d.ts +1 -1
  96. package/dist/app/lib/routing/hooks/useRouter.js +1 -1
  97. package/dist/app/lib/routing/hooks/useRouterEvents.d.ts +1 -1
  98. package/dist/app/lib/routing/hooks/useRouterEvents.js +1 -1
  99. package/dist/app/lib/routing/hooks/useRouterState.d.ts +1 -1
  100. package/dist/app/lib/routing/hooks/useRouterState.js +1 -1
  101. package/dist/app/lib/routing/hooks/useSearchParams.js +2 -2
  102. package/dist/app/lib/routing/index.d.ts +14 -13
  103. package/dist/app/lib/routing/index.js +14 -13
  104. package/dist/app/lib/routing/loader.d.ts +2 -2
  105. package/dist/app/lib/routing/loader.js +20 -11
  106. package/dist/app/lib/routing/types.d.ts +37 -10
  107. package/dist/app/lib/routing/utils.d.ts +5 -2
  108. package/dist/app/lib/routing/utils.js +37 -4
  109. package/dist/app/lib/{hooks → runtime}/apiConfig.d.ts +6 -2
  110. package/dist/app/lib/runtime/apiConfig.js +6 -0
  111. package/dist/app/lib/runtime/errorHandling.d.ts +39 -0
  112. package/dist/app/lib/runtime/errorHandling.js +6 -0
  113. package/dist/app/lib/runtime/index.d.ts +2 -0
  114. package/dist/app/lib/runtime/index.js +2 -0
  115. package/dist/app/lib/views/index.d.ts +1 -1
  116. package/dist/app/lib/views/index.js +1 -1
  117. package/dist/app/server/defineRouter.d.ts +2 -0
  118. package/dist/app/server/defineRouter.js +4 -0
  119. package/dist/app/server/index.d.ts +5 -3
  120. package/dist/app/server/index.js +5 -3
  121. package/dist/app/server/proxy-wp-admin.d.ts +1 -2
  122. package/dist/app/server/proxy-wp-admin.js +41 -14
  123. package/dist/app/server/render-ssr-page.d.ts +27 -2
  124. package/dist/app/server/render-ssr-page.js +191 -12
  125. package/dist/app/server/rpc.d.ts +56 -0
  126. package/dist/app/server/rpc.js +18 -0
  127. package/dist/app/server/server-context.d.ts +42 -4
  128. package/dist/app/server/server-context.js +195 -28
  129. package/dist/app/server/utils/replace-host.d.ts +1 -1
  130. package/dist/app/server/utils/replace-host.js +10 -2
  131. package/dist/app/server/utils/swr-cache.d.ts +4 -0
  132. package/dist/app/server/utils/swr-cache.js +31 -0
  133. package/dist/app/utils/APIProvider.d.ts +2 -0
  134. package/dist/app/utils/APIProvider.js +5 -0
  135. package/dist/app/utils/BlockErrorBoundary.d.ts +19 -0
  136. package/dist/app/utils/BlockErrorBoundary.js +38 -0
  137. package/dist/app/utils/ErrorMessage.d.ts +5 -0
  138. package/dist/app/utils/ErrorMessage.js +14 -0
  139. package/dist/app/utils/RouteErrorBoundary.d.ts +18 -0
  140. package/dist/app/utils/RouteErrorBoundary.js +38 -0
  141. package/dist/app/utils/asset-capture.d.ts +2 -0
  142. package/dist/app/utils/asset-capture.js +5 -0
  143. package/dist/app/utils/hydration-debugger.d.ts +13 -0
  144. package/dist/app/utils/hydration-debugger.js +11 -0
  145. package/dist/app/utils/query-client.d.ts +2 -0
  146. package/dist/app/utils/query-client.js +5 -1
  147. package/dist/app/utils/trpc-client.d.ts +2 -0
  148. package/dist/app/utils/trpc-client.js +39 -0
  149. package/dist/node/cli/cli-worker.js +10 -5
  150. package/dist/node/cli/cli.js +79 -11
  151. package/dist/node/cli/display/CLIApp.js +3 -6
  152. package/dist/node/cli/display/boot-cli-app.js +1 -1
  153. package/dist/node/cli/display/tools/CreateBlock.d.ts +1 -1
  154. package/dist/node/cli/display/tools/cli-tools.d.ts +1 -11
  155. package/dist/node/cli/display/tools/cli-tools.js +9 -9
  156. package/dist/node/cli/version.d.ts +1 -1
  157. package/dist/node/cli/version.js +1 -1
  158. package/dist/node/compiler/build-vinxi.js +2 -1
  159. package/dist/node/compiler/bundler.admin.d.ts +1 -1
  160. package/dist/node/compiler/bundler.admin.js +1 -1
  161. package/dist/node/compiler/bundler.frontend.js +1 -1
  162. package/dist/node/compiler/dev-server.js +10 -0
  163. package/dist/node/compiler/get-vite-config.d.ts +2 -0
  164. package/dist/node/compiler/get-vite-config.js +42 -12
  165. package/dist/node/compiler/vinxi-app.d.ts +12 -0
  166. package/dist/node/compiler/vinxi-app.js +139 -32
  167. package/dist/node/compiler/vinxi-codegen.js +342 -112
  168. package/dist/node/graphql/graphql-codegen.d.ts +11 -1
  169. package/dist/node/graphql/graphql-codegen.js +210 -33
  170. package/dist/node/graphql/graphql-schema-loader.d.ts +2 -1
  171. package/dist/node/graphql/graphql-schema-loader.js +5 -16
  172. package/dist/node/graphql/plugins/gql-plugin-queries.js +1 -1
  173. package/dist/node/graphql/query-files-loader.d.ts +3 -0
  174. package/dist/node/graphql/query-files-loader.js +5 -0
  175. package/dist/node/project/config.d.ts +159 -73
  176. package/dist/node/project/config.js +69 -20
  177. package/dist/node/project/env.d.ts +4 -0
  178. package/dist/node/project/env.js +1 -0
  179. package/dist/node/project/manifest/block-manifest.js +2 -1
  180. package/dist/node/project/manifest/manifest.d.ts +1 -0
  181. package/dist/node/project/manifest/manifest.js +14 -10
  182. package/dist/node/project/manifest/routes-manifest.d.ts +20 -0
  183. package/dist/node/project/manifest/routes-manifest.js +74 -0
  184. package/dist/node/project/manifest/view-manifest.js +1 -1
  185. package/dist/node/project/project.d.ts +11 -1
  186. package/dist/node/project/project.js +61 -7
  187. package/dist/node/project/wp-info.d.ts +1 -0
  188. package/dist/node/project/wp-info.js +13 -1
  189. package/dist/node/storybook/index.d.ts +2 -0
  190. package/dist/node/storybook/index.js +13 -0
  191. package/dist/node/types/block-type.d.ts +25 -20
  192. package/dist/node/types/block-type.js +1 -0
  193. package/dist/node/types/view-type.d.ts +7 -7
  194. package/dist/node/utils/fetch-wp.d.ts +1 -0
  195. package/dist/node/utils/fetch-wp.js +27 -0
  196. package/dist/node/utils/fs-codegen.d.ts +2 -0
  197. package/dist/node/utils/fs-codegen.js +2 -1
  198. package/dist/node/utils/is-deploying.js +1 -1
  199. package/dist/node/utils/report-builder.d.ts +6 -6
  200. package/dist/node/utils/self-signed-cert.d.ts +2 -0
  201. package/dist/node/utils/self-signed-cert.js +10 -2
  202. package/dist/node/utils/stateful-log.js +2 -0
  203. package/dist/node/utils/watch-file-tree.d.ts +17 -3
  204. package/dist/node/utils/watch-file-tree.js +12 -5
  205. package/package.json +21 -12
  206. package/types.app.d.ts +4 -2
  207. package/types.app.internal.d.ts +2 -2
  208. package/types.node.d.ts +3 -3
  209. package/dist/app/lib/blocks/ErrorBoundaryFrontend.d.ts +0 -15
  210. package/dist/app/lib/blocks/ErrorBoundaryFrontend.js +0 -35
  211. package/dist/app/lib/hooks/apiConfig.js +0 -4
  212. package/dist/app/lib/hooks/usePageLoad.d.ts +0 -6
  213. package/dist/app/lib/hooks/usePageLoad.js +0 -5
@@ -10,7 +10,6 @@ export class FrontendBundler {
10
10
  constructor(project, opts) {
11
11
  this.project = project;
12
12
  this.opts = opts;
13
- this.start();
14
13
  }
15
14
  async start() {
16
15
  console.info(`Creating ${this.opts.mode} SPA build...`);
@@ -22,6 +21,7 @@ export class FrontendBundler {
22
21
  outDir: relative(this.project.rootDir, "./dist/frontend/"),
23
22
  serverless: false,
24
23
  target: "frontend",
24
+ client: true,
25
25
  });
26
26
  console.verbose("Vite config:", baseConfig);
27
27
  await build(mergeConfig(baseConfig, defineConfig({
@@ -25,18 +25,22 @@ export class DevServer {
25
25
  }
26
26
  async start() {
27
27
  console.setWorking(true);
28
+ // console.log("Setting up vinxi codegen")
28
29
  const codegen = createVinxiCodegen({
29
30
  mode: "development",
30
31
  project: this.project,
31
32
  serverless: true,
32
33
  });
33
34
  await codegen.runAndWatch();
35
+ // console.log("Has run once")
34
36
  const app = createVinxiApp({
35
37
  mode: "development",
36
38
  origin: this.origin,
37
39
  publicUrl: this.project.publicUrl,
38
40
  rootDir: this.project.rootDir,
39
41
  log: console,
42
+ rpcBases: (await this.project.serverRoutes.get()).bases,
43
+ config: this.project.config,
40
44
  });
41
45
  const preset = process.env.TARGET ??
42
46
  process.env.PRESET ??
@@ -45,7 +49,9 @@ export class DevServer {
45
49
  process.env.NITRO_PRESET ??
46
50
  process.env.NITRO_TARGET ??
47
51
  (process.versions.bun !== undefined ? "bun" : "node-server");
52
+ // console.log("Ensuring self signed cert")
48
53
  const keys = await ensureSelfSignedCert(this.hostname, this.project.rootDir);
54
+ // console.log("Done")
49
55
  const httpsConfig = {
50
56
  cert: keys.certFile,
51
57
  key: keys.keyFile,
@@ -61,6 +67,7 @@ export class DevServer {
61
67
  devApp = args.devApp;
62
68
  },
63
69
  });
70
+ // console.log("Creating dev server")
64
71
  await createDevServer(app, {
65
72
  force: false,
66
73
  devtools: false,
@@ -71,11 +78,13 @@ export class DevServer {
71
78
  preset: preset,
72
79
  https: httpsConfig,
73
80
  });
81
+ // console.log("Rnning listen hook")
74
82
  // @ts-ignore
75
83
  await app.hooks.callHook("app:dev:server:listener:creating", {
76
84
  app,
77
85
  devApp,
78
86
  });
87
+ // console.log("Creating another listener")
79
88
  const listener = await devApp.listen(this.port, {
80
89
  hostname: this.hostname,
81
90
  port: this.port,
@@ -88,6 +97,7 @@ export class DevServer {
88
97
  devApp,
89
98
  listener,
90
99
  });
100
+ // console.log("Listening")
91
101
  console.setWorking(false);
92
102
  console.setState({
93
103
  serverlessUrl: this.hostOrigin,
@@ -8,6 +8,7 @@ export type Args = {
8
8
  outDir?: string;
9
9
  publicUrl: string;
10
10
  console: StatefulLog<any>;
11
+ client: boolean;
11
12
  };
12
13
  export declare function envPlugin(args: Args): PluginOption;
13
14
  export declare function reactPlugin(): PluginOption[];
@@ -16,4 +17,5 @@ export declare function reactPlugin(): PluginOption[];
16
17
  */
17
18
  export declare function ssrPlugin(): PluginOption;
18
19
  export declare function corePlugins(args: Args): PluginOption[];
20
+ export declare function storybookVitePlugins(args: Args): PluginOption[];
19
21
  export declare function getViteConfig(args: Args): InlineConfig;
@@ -8,14 +8,14 @@ import tsconfigPaths from "vite-tsconfig-paths";
8
8
  import { cliMode } from "../cli/cli-mode.js";
9
9
  export function envPlugin(args) {
10
10
  const envDefines = {
11
- client: args.serverless ? "!import.meta.env.SSR" : "true",
11
+ client: args.client ? "true" : "false",
12
12
  serverless: args.serverless ? "true" : "false",
13
13
  dev: args.mode === "development" ? "true" : "false",
14
14
  admin: args.target === "cms" ? "true" : "false",
15
15
  themePath: JSON.stringify(args.publicUrl),
16
16
  devUI: args.mode === "development" ? "true" : "false",
17
17
  serverlessOrigin: JSON.stringify("http://serverleress-endpoint"),
18
- rpcEnabled: "false",
18
+ rpcEnabled: "true",
19
19
  origin: JSON.stringify(process.env.SITE_URL ?? "/"),
20
20
  };
21
21
  const expandDefines = (obj, prefixes = []) => {
@@ -28,7 +28,9 @@ export function envPlugin(args) {
28
28
  return result;
29
29
  };
30
30
  return replace({
31
- values: expandDefines(envDefines, ["process.env.", "process.", "env."]),
31
+ values: {
32
+ ...expandDefines(envDefines, ["process.env.", "process.", "env."]),
33
+ },
32
34
  preventAssignment: true,
33
35
  });
34
36
  }
@@ -66,7 +68,11 @@ export function reactPlugin() {
66
68
  if (t.isExpression(body)) {
67
69
  body = t.blockStatement([t.returnStatement(body)]);
68
70
  }
69
- path.replaceWith(t.exportDefaultDeclaration(t.functionDeclaration(t.identifier(pascalCase(type + "-" + name)), args[1].params, body, args[1].generator, args[1].async)));
71
+ const componentName = pascalCase(type) + "_" + name.replace(/[^a-z0-9]/g, "_").replace(/_+/g, "_");
72
+ path.replaceWithMultiple([
73
+ t.exportDefaultDeclaration(t.functionDeclaration(t.identifier(componentName), args[1].params, body, args[1].generator, args[1].async)),
74
+ t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier(componentName), t.identifier("displayName")), t.stringLiteral(pascalCase(type) + "(" + name + ")"))),
75
+ ]);
70
76
  }
71
77
  }
72
78
  }
@@ -85,8 +91,34 @@ export function ssrPlugin() {
85
91
  name: "proxy-external-ssr-modules",
86
92
  config(config) {
87
93
  config.legacy = {
94
+ ...config.legacy,
88
95
  proxySsrExternalModules: true,
89
96
  };
97
+ config.ssr = {
98
+ ...config.ssr,
99
+ noExternal: [
100
+ "eddev",
101
+ "vinxi",
102
+ "react-use",
103
+ // @ts-ignore
104
+ ...(config?.optimizeDeps?.noExternal ?? []),
105
+ ],
106
+ optimizeDeps: {
107
+ exclude: ["eddev", "vinxi"],
108
+ },
109
+ };
110
+ config.optimizeDeps = {
111
+ ...config.optimizeDeps,
112
+ include: [
113
+ "valtio",
114
+ "@tanstack/react-query",
115
+ "qs",
116
+ "react",
117
+ "react-dom/client",
118
+ ...(config?.optimizeDeps?.include ?? []),
119
+ ],
120
+ exclude: ["eddev", "vinxi", ...(config?.optimizeDeps?.exclude ?? [])],
121
+ };
90
122
  return config;
91
123
  },
92
124
  };
@@ -113,12 +145,10 @@ function buildStatusPlugin(console) {
113
145
  };
114
146
  }
115
147
  export function corePlugins(args) {
116
- return [
117
- tsconfigPaths(),
118
- reactPlugin(),
119
- args.mode === "development" && args.serverless && ssrPlugin(),
120
- envPlugin(args),
121
- ].flat();
148
+ return [args.serverless && ssrPlugin(), envPlugin(args), tsconfigPaths(), reactPlugin()].flat();
149
+ }
150
+ export function storybookVitePlugins(args) {
151
+ return [args.serverless && ssrPlugin(), envPlugin(args), tsconfigPaths()].flat();
122
152
  }
123
153
  export function getViteConfig(args) {
124
154
  const console = args.console;
@@ -152,9 +182,9 @@ export function getViteConfig(args) {
152
182
  minify: args.mode === "production",
153
183
  modulePreload: false,
154
184
  outDir: args.outDir,
155
- watch: {},
185
+ // watch: {},
156
186
  rollupOptions: {
157
- input: `/.eddev/${args.mode === "production" ? "prod" : "dev"}-spa/entry.${args.target === "cms" ? "admin" : "client"}.tsx`,
187
+ input: `./.eddev/${args.mode === "production" ? "prod" : "dev"}-spa/entry.${args.target === "cms" ? "admin" : "client"}.tsx`,
158
188
  external: args.target === "cms" ? ["react", "react-dom"] : [],
159
189
  onwarn(warning, warn) {
160
190
  if (!cliMode.verbose &&
@@ -1,4 +1,5 @@
1
1
  import { StatefulLog } from "../utils/stateful-log.js";
2
+ import { EDConfig } from "../project/config.js";
2
3
  export type AppArgs = {
3
4
  mode: "development" | "production";
4
5
  publicUrl: string;
@@ -6,5 +7,16 @@ export type AppArgs = {
6
7
  origin: string;
7
8
  log?: StatefulLog<any>;
8
9
  preset?: string;
10
+ routes?: CustomRoute[];
11
+ rpcBases?: string[];
12
+ config: EDConfig;
13
+ };
14
+ type HTTPMethod = "GET" | "POST" | "PUT" | "OPTIONS" | "HEAD";
15
+ type CustomRouteFunction = (req: Request) => Response;
16
+ type CustomRouteModule = Record<HTTPMethod, CustomRouteFunction>;
17
+ type CustomRoute = {
18
+ pattern: string;
19
+ handler: () => Promise<CustomRouteModule>;
9
20
  };
10
21
  export declare function createVinxiApp(args: AppArgs): import("vinxi").App;
22
+ export {};
@@ -18,53 +18,140 @@ export function createVinxiApp(args) {
18
18
  // },
19
19
  preset: args.preset,
20
20
  routeRules: {
21
+ "/wp-content/uploads/**": {
22
+ proxy: joinURL(args.origin, "wp-content/uploads/**"),
23
+ static: true,
24
+ cache: {
25
+ maxAge: 86400,
26
+ varies: [],
27
+ },
28
+ },
29
+ "/favicon.ico": {
30
+ proxy: joinURL(args.origin, "favicon.ico"),
31
+ static: true,
32
+ cache: {
33
+ maxAge: 3600,
34
+ varies: [],
35
+ },
36
+ },
37
+ "/robots.txt": {
38
+ cache: {
39
+ maxAge: 3600,
40
+ varies: [],
41
+ },
42
+ },
43
+ "/sitemap.xml": {
44
+ cache: {
45
+ maxAge: 3600,
46
+ swr: true,
47
+ },
48
+ },
49
+ "/sitemap*.xml": {
50
+ cache: {
51
+ maxAge: 3600,
52
+ swr: true,
53
+ },
54
+ },
55
+ "/wp-content/plugins/**": {
56
+ proxy: joinURL(args.origin, "wp-content/plugins/**"),
57
+ headers: {
58
+ "Cache-Control": "max-age=86400",
59
+ "CDN-Cache-Control": "max-age=86400",
60
+ "Vercel-CDN-Cache-Control": "max-age=86400",
61
+ },
62
+ },
21
63
  "/wp-content/**": { proxy: joinURL(args.origin, "wp-content/**") },
22
64
  "/wp-includes/**": { proxy: joinURL(args.origin, "wp-includes/**") },
65
+ "/_data/route/**": {
66
+ isr: 300,
67
+ swr: true,
68
+ cache: {
69
+ maxAge: 300,
70
+ swr: true,
71
+ varies: ["Authorization", "woocommerce-session"],
72
+ },
73
+ },
74
+ "/_data/query/**": {
75
+ isr: false,
76
+ cache: {
77
+ maxAge: 300,
78
+ varies: ["Authorization", "woocommerce-session"],
79
+ },
80
+ },
81
+ ...args.rpcBases?.reduce((acc, base) => {
82
+ return {
83
+ ...acc,
84
+ ["/" + base.replace(/(^\/|\/$)/g, "") + "/**/*"]: {
85
+ isr: false,
86
+ swr: false,
87
+ },
88
+ };
89
+ }, {}),
90
+ "/**/*": {
91
+ isr: 300,
92
+ swr: true,
93
+ cache: {
94
+ maxAge: 300,
95
+ swr: true,
96
+ staleMaxAge: 3600,
97
+ },
98
+ },
99
+ },
100
+ vercel: {
101
+ config: {
102
+ bypassToken: process.env.VERCEL_BYPASS_TOKEN,
103
+ },
23
104
  },
24
105
  },
25
106
  routers: [
107
+ ...args.config.serverless.themeAssets.map((folder) => {
108
+ const folderName = folder
109
+ .split("/")
110
+ .filter((p) => !p.includes("*") && p !== ".")
111
+ .join("/");
112
+ return {
113
+ name: "public_" + folderName,
114
+ type: "static",
115
+ dir: args.rootDir + "/" + folderName,
116
+ base: joinURL(args.publicUrl, folderName),
117
+ };
118
+ }),
26
119
  {
27
- name: "public",
28
- type: "static",
29
- dir: "./assets",
30
- base: joinURL(args.publicUrl, "assets"),
31
- },
32
- {
33
- name: "data-api",
34
- type: "http",
35
- base: "/_data/",
36
- handler: `${folder}/handler.data-api.ts`,
37
- target: "server",
38
- plugins: () => [
39
- tsconfigPaths(),
40
- envPlugin({
41
- rootDir: args.rootDir,
42
- console: log,
43
- mode: "development",
44
- publicUrl: args.publicUrl,
45
- serverless: true,
46
- target: "frontend",
47
- }),
48
- ],
49
- },
50
- {
51
- name: "wp-proxy",
120
+ name: "bypass-api",
52
121
  type: "http",
53
- base: "/wp-",
54
- handler: `${folder}/handler.wp-proxy.ts`,
122
+ base: "/_bypass",
123
+ handler: `${folder}/handler.bypass.ts`,
55
124
  target: "server",
56
125
  plugins: () => [
57
126
  tsconfigPaths(),
58
127
  envPlugin({
59
128
  rootDir: args.rootDir,
60
129
  console: log,
61
- mode: "development",
130
+ mode: args.mode,
62
131
  publicUrl: args.publicUrl,
63
132
  serverless: true,
64
133
  target: "frontend",
134
+ client: false,
65
135
  }),
66
136
  ],
67
137
  },
138
+ // {
139
+ // name: "wp-proxy",
140
+ // type: "http",
141
+ // base: "/wp-",
142
+ // handler: `${folder}/handler.wp-proxy.ts`,
143
+ // target: "server",
144
+ // plugins: () => [
145
+ // ...corePlugins({
146
+ // rootDir: args.rootDir,
147
+ // console: log,
148
+ // mode: args.mode,
149
+ // publicUrl: args.publicUrl,
150
+ // serverless: true,
151
+ // target: "frontend",
152
+ // }),
153
+ // ],
154
+ // },
68
155
  {
69
156
  name: "client",
70
157
  type: "client",
@@ -74,10 +161,11 @@ export function createVinxiApp(args) {
74
161
  ...corePlugins({
75
162
  rootDir: args.rootDir,
76
163
  console: log,
77
- mode: "development",
164
+ mode: args.mode,
78
165
  publicUrl: args.publicUrl,
79
166
  serverless: true,
80
167
  target: "frontend",
168
+ client: true,
81
169
  }),
82
170
  ],
83
171
  base: "/_build",
@@ -91,28 +179,47 @@ export function createVinxiApp(args) {
91
179
  ...corePlugins({
92
180
  rootDir: args.rootDir,
93
181
  console: log,
94
- mode: "development",
182
+ mode: args.mode,
95
183
  publicUrl: args.publicUrl,
96
184
  serverless: true,
97
185
  target: "cms",
186
+ client: true,
98
187
  }),
99
188
  ],
100
189
  base: "/_admin",
101
190
  },
191
+ // ...((args.rpcBases ?? []).map((base) => ({
192
+ // name: "trpc" + base.replace(/^\//, "-"),
193
+ // type: "http",
194
+ // base: "/" + base.replace(/^\//, ""),
195
+ // handler: `${folder}/handler.trpc-api.ts`,
196
+ // target: "server",
197
+ // plugins: () => [
198
+ // tsconfigPaths(),
199
+ // envPlugin({
200
+ // rootDir: args.rootDir,
201
+ // console: log,
202
+ // mode: args.mode,
203
+ // publicUrl: args.publicUrl,
204
+ // serverless: true,
205
+ // target: "frontend",
206
+ // }),
207
+ // ],
208
+ // })) as RouterSchemaInput[]),
102
209
  {
103
210
  name: "ssr",
104
211
  type: "http",
105
212
  handler: `${folder}/handler.ssr-page.ts`,
106
213
  target: "server",
107
214
  plugins: () => [
108
- // reactRefresh(),
109
215
  ...corePlugins({
110
216
  rootDir: args.rootDir,
111
217
  console: log,
112
- mode: "development",
218
+ mode: args.mode,
113
219
  publicUrl: args.publicUrl,
114
220
  serverless: true,
115
221
  target: "frontend",
222
+ client: false,
116
223
  }),
117
224
  ],
118
225
  },