eddev 2.0.0-beta.12 → 2.0.0-beta.121

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 (224) hide show
  1. package/css/editor-styles.css +4 -0
  2. package/dist/app/entry/HydrationOverlay.d.ts +1 -0
  3. package/dist/app/entry/HydrationOverlay.js +2 -0
  4. package/dist/app/entry/MetaTags.d.ts +7 -0
  5. package/dist/app/entry/MetaTags.js +17 -0
  6. package/dist/app/entry/boot-admin.js +9 -3
  7. package/dist/app/entry/hydration-script.d.ts +1 -0
  8. package/dist/app/entry/hydration-script.js +18 -0
  9. package/dist/app/entry/spa-root.js +3 -5
  10. package/dist/app/entry/ssr-root-client.d.ts +3 -1
  11. package/dist/app/entry/ssr-root-client.js +18 -6
  12. package/dist/app/entry/ssr-root.d.ts +3 -4
  13. package/dist/app/entry/ssr-root.js +19 -19
  14. package/dist/app/lib/admin/index.d.ts +2 -2
  15. package/dist/app/lib/admin/index.js +2 -2
  16. package/dist/app/lib/admin/installFieldTypes.js +3 -1
  17. package/dist/app/lib/admin/runWidgets.js +1 -1
  18. package/dist/app/lib/blocks/ContentBlocks.d.ts +1 -1
  19. package/dist/app/lib/blocks/ContentBlocks.js +5 -5
  20. package/dist/app/lib/blocks/EditableText.d.ts +15 -2
  21. package/dist/app/lib/blocks/EditableText.js +10 -4
  22. package/dist/app/lib/blocks/InnerBlocks.d.ts +21 -7
  23. package/dist/app/lib/blocks/InnerBlocks.js +75 -28
  24. package/dist/app/lib/blocks/block-utils.d.ts +2 -2
  25. package/dist/app/lib/blocks/block-utils.js +2 -2
  26. package/dist/app/lib/blocks/defineBlock.d.ts +3 -0
  27. package/dist/app/lib/blocks/defineBlock.js +7 -0
  28. package/dist/app/lib/blocks/editor/EditorHighlights.d.ts +7 -0
  29. package/dist/app/lib/blocks/editor/EditorHighlights.js +164 -0
  30. package/dist/app/lib/blocks/editor/EditorSupport.js +17 -12
  31. package/dist/app/lib/blocks/editor/ErrorBoundaryEditor.d.ts +1 -1
  32. package/dist/app/lib/blocks/editor/block-templates.d.ts +6 -0
  33. package/dist/app/lib/blocks/editor/block-templates.js +64 -0
  34. package/dist/app/lib/blocks/editor/create-block.d.ts +9 -0
  35. package/dist/app/lib/blocks/editor/create-block.js +13 -0
  36. package/dist/app/lib/blocks/editor/editor-config.d.ts +70 -7
  37. package/dist/app/lib/blocks/editor/editor-config.js +29 -62
  38. package/dist/app/lib/blocks/editor/installGutenbergHooks.d.ts +3 -0
  39. package/dist/app/lib/blocks/editor/installGutenbergHooks.js +105 -16
  40. package/dist/app/lib/blocks/editor/root-blocks.d.ts +6 -0
  41. package/dist/app/lib/blocks/editor/root-blocks.js +30 -0
  42. package/dist/app/lib/blocks/editor/usePostEditor.d.ts +1 -1
  43. package/dist/app/lib/blocks/index.d.ts +10 -9
  44. package/dist/app/lib/blocks/index.js +10 -9
  45. package/dist/app/lib/blocks/inline-editing.d.ts +9 -1
  46. package/dist/app/lib/blocks/inline-editing.js +7 -5
  47. package/dist/app/lib/devtools/components/BreakpointIndicator.js +1 -1
  48. package/dist/app/lib/devtools/components/DevUI.js +4 -3
  49. package/dist/app/lib/devtools/components/GridIndicator.d.ts +1 -0
  50. package/dist/app/lib/devtools/components/GridIndicator.js +29 -0
  51. package/dist/app/lib/devtools/hooks/usePersistState.d.ts +1 -1
  52. package/dist/app/lib/devtools/hooks/usePersistState.js +11 -2
  53. package/dist/app/lib/devtools/hooks/useTailwind.d.ts +2305 -1261
  54. package/dist/app/lib/devtools/hooks/useTailwind.js +1 -1
  55. package/dist/app/lib/devtools/index.d.ts +1 -1
  56. package/dist/app/lib/devtools/index.js +1 -1
  57. package/dist/app/lib/devtools/loader.js +8 -7
  58. package/dist/app/lib/devtools/useQueryDebug.d.ts +7 -1
  59. package/dist/app/lib/devtools/useQueryDebug.js +5 -8
  60. package/dist/app/lib/dynamic/dynamic.d.ts +1 -1
  61. package/dist/app/lib/dynamic/dynamic.js +5 -1
  62. package/dist/app/lib/dynamic/index.d.ts +1 -1
  63. package/dist/app/lib/dynamic/index.js +1 -1
  64. package/dist/app/lib/hooks/index.d.ts +4 -5
  65. package/dist/app/lib/hooks/index.js +4 -5
  66. package/dist/app/lib/hooks/queryUtils.d.ts +37 -3
  67. package/dist/app/lib/hooks/queryUtils.js +66 -26
  68. package/dist/app/lib/hooks/useAppData.js +12 -1
  69. package/dist/app/lib/hooks/useRPC.d.ts +0 -4
  70. package/dist/app/lib/hooks/useRPC.js +1 -8
  71. package/dist/app/lib/internal/finalize-rpc.d.ts +17 -0
  72. package/dist/app/lib/internal/finalize-rpc.js +3 -0
  73. package/dist/app/lib/internal/index.d.ts +5 -4
  74. package/dist/app/lib/internal/index.js +5 -4
  75. package/dist/app/lib/internal/read-admin-manifest.d.ts +1 -1
  76. package/dist/app/lib/legacy-stitches/createStitches.d.ts +21 -21
  77. package/dist/app/lib/legacy-stitches/createStitches.js +1 -1
  78. package/dist/app/lib/legacy-stitches/index.d.ts +1 -1
  79. package/dist/app/lib/legacy-stitches/index.js +1 -1
  80. package/dist/app/lib/routing/components/BackButton.d.ts +49 -0
  81. package/dist/app/lib/routing/components/BackButton.js +47 -0
  82. package/dist/app/lib/routing/components/BrowserRouter.d.ts +5 -1
  83. package/dist/app/lib/routing/components/BrowserRouter.js +98 -19
  84. package/dist/app/lib/routing/components/ClientOnly.d.ts +1 -1
  85. package/dist/app/lib/routing/components/ClientOnly.js +2 -2
  86. package/dist/app/lib/routing/components/Link.d.ts +1 -0
  87. package/dist/app/lib/routing/components/Link.js +11 -12
  88. package/dist/app/lib/routing/components/RouteRenderer.d.ts +1 -1
  89. package/dist/app/lib/routing/components/RouteRenderer.js +7 -6
  90. package/dist/app/lib/routing/components/SSRRouter.d.ts +2 -2
  91. package/dist/app/lib/routing/components/SSRRouter.js +5 -6
  92. package/dist/app/lib/routing/components/ScrollRestoration.js +5 -2
  93. package/dist/app/lib/routing/context.d.ts +8 -5
  94. package/dist/app/lib/routing/context.js +13 -96
  95. package/dist/app/lib/routing/hooks/useRestorableState.d.ts +2 -1
  96. package/dist/app/lib/routing/hooks/useRestorableState.js +2 -1
  97. package/dist/app/lib/routing/hooks/useRoute.d.ts +16 -1
  98. package/dist/app/lib/routing/hooks/useRoute.js +22 -1
  99. package/dist/app/lib/routing/hooks/useRouteMeta.d.ts +5 -0
  100. package/dist/app/lib/routing/hooks/useRouteMeta.js +9 -0
  101. package/dist/app/lib/routing/hooks/useRouteTransition.d.ts +1 -1
  102. package/dist/app/lib/routing/hooks/useRouteTransition.js +1 -1
  103. package/dist/app/lib/routing/hooks/useRouter.d.ts +1 -1
  104. package/dist/app/lib/routing/hooks/useRouter.js +1 -1
  105. package/dist/app/lib/routing/hooks/useRouterEvents.d.ts +1 -1
  106. package/dist/app/lib/routing/hooks/useRouterEvents.js +1 -1
  107. package/dist/app/lib/routing/hooks/useRouterState.d.ts +1 -1
  108. package/dist/app/lib/routing/hooks/useRouterState.js +1 -1
  109. package/dist/app/lib/routing/hooks/useSearchParams.js +2 -2
  110. package/dist/app/lib/routing/index.d.ts +14 -13
  111. package/dist/app/lib/routing/index.js +14 -13
  112. package/dist/app/lib/routing/loader.d.ts +2 -2
  113. package/dist/app/lib/routing/loader.js +20 -11
  114. package/dist/app/lib/routing/types.d.ts +37 -10
  115. package/dist/app/lib/routing/utils.d.ts +5 -2
  116. package/dist/app/lib/routing/utils.js +37 -4
  117. package/dist/app/lib/{hooks → runtime}/apiConfig.d.ts +6 -2
  118. package/dist/app/lib/runtime/apiConfig.js +6 -0
  119. package/dist/app/lib/runtime/errorHandling.d.ts +39 -0
  120. package/dist/app/lib/runtime/errorHandling.js +6 -0
  121. package/dist/app/lib/runtime/index.d.ts +2 -0
  122. package/dist/app/lib/runtime/index.js +2 -0
  123. package/dist/app/lib/views/index.d.ts +1 -1
  124. package/dist/app/lib/views/index.js +1 -1
  125. package/dist/app/server/defineRouter.d.ts +2 -0
  126. package/dist/app/server/defineRouter.js +4 -0
  127. package/dist/app/server/index.d.ts +5 -3
  128. package/dist/app/server/index.js +5 -3
  129. package/dist/app/server/proxy-wp-admin.d.ts +1 -2
  130. package/dist/app/server/proxy-wp-admin.js +41 -14
  131. package/dist/app/server/render-ssr-page.d.ts +27 -2
  132. package/dist/app/server/render-ssr-page.js +192 -12
  133. package/dist/app/server/rpc.d.ts +56 -0
  134. package/dist/app/server/rpc.js +18 -0
  135. package/dist/app/server/server-context.d.ts +44 -4
  136. package/dist/app/server/server-context.js +305 -28
  137. package/dist/app/server/utils/replace-host.d.ts +1 -1
  138. package/dist/app/server/utils/replace-host.js +10 -2
  139. package/dist/app/server/utils/swr-cache.d.ts +4 -0
  140. package/dist/app/server/utils/swr-cache.js +31 -0
  141. package/dist/app/utils/APIProvider.d.ts +2 -0
  142. package/dist/app/utils/APIProvider.js +5 -0
  143. package/dist/app/utils/BlockErrorBoundary.d.ts +19 -0
  144. package/dist/app/utils/BlockErrorBoundary.js +38 -0
  145. package/dist/app/utils/ErrorMessage.d.ts +5 -0
  146. package/dist/app/utils/ErrorMessage.js +14 -0
  147. package/dist/app/utils/RouteErrorBoundary.d.ts +18 -0
  148. package/dist/app/utils/RouteErrorBoundary.js +38 -0
  149. package/dist/app/utils/asset-capture.d.ts +2 -0
  150. package/dist/app/utils/asset-capture.js +5 -0
  151. package/dist/app/utils/hydration-debugger.d.ts +13 -0
  152. package/dist/app/utils/hydration-debugger.js +11 -0
  153. package/dist/app/utils/query-client.d.ts +2 -0
  154. package/dist/app/utils/query-client.js +5 -1
  155. package/dist/app/utils/query-monitor.d.ts +26 -0
  156. package/dist/app/utils/query-monitor.js +7 -0
  157. package/dist/app/utils/trpc-client.d.ts +2 -0
  158. package/dist/app/utils/trpc-client.js +39 -0
  159. package/dist/node/cli/cli-worker.js +10 -5
  160. package/dist/node/cli/cli.js +81 -11
  161. package/dist/node/cli/display/CLIApp.js +3 -6
  162. package/dist/node/cli/display/boot-cli-app.js +1 -1
  163. package/dist/node/cli/display/tools/CreateBlock.d.ts +1 -1
  164. package/dist/node/cli/display/tools/cli-tools.d.ts +1 -11
  165. package/dist/node/cli/display/tools/cli-tools.js +9 -9
  166. package/dist/node/cli/version.d.ts +1 -1
  167. package/dist/node/cli/version.js +1 -1
  168. package/dist/node/compiler/build-vinxi.js +2 -1
  169. package/dist/node/compiler/bundler.admin.d.ts +1 -1
  170. package/dist/node/compiler/bundler.admin.js +1 -1
  171. package/dist/node/compiler/bundler.frontend.js +1 -1
  172. package/dist/node/compiler/dev-server.js +10 -0
  173. package/dist/node/compiler/get-vite-config.d.ts +7 -1
  174. package/dist/node/compiler/get-vite-config.js +96 -16
  175. package/dist/node/compiler/vinxi-app.d.ts +12 -0
  176. package/dist/node/compiler/vinxi-app.js +139 -32
  177. package/dist/node/compiler/vinxi-codegen.js +345 -112
  178. package/dist/node/graphql/graphql-codegen.d.ts +11 -1
  179. package/dist/node/graphql/graphql-codegen.js +210 -33
  180. package/dist/node/graphql/graphql-schema-loader.d.ts +2 -1
  181. package/dist/node/graphql/graphql-schema-loader.js +5 -16
  182. package/dist/node/graphql/plugins/gql-plugin-queries.js +1 -1
  183. package/dist/node/graphql/query-files-loader.d.ts +3 -0
  184. package/dist/node/graphql/query-files-loader.js +5 -0
  185. package/dist/node/project/config.d.ts +159 -73
  186. package/dist/node/project/config.js +69 -20
  187. package/dist/node/project/env.d.ts +4 -0
  188. package/dist/node/project/env.js +1 -0
  189. package/dist/node/project/manifest/block-manifest.js +2 -1
  190. package/dist/node/project/manifest/manifest.d.ts +1 -0
  191. package/dist/node/project/manifest/manifest.js +14 -10
  192. package/dist/node/project/manifest/routes-manifest.d.ts +20 -0
  193. package/dist/node/project/manifest/routes-manifest.js +74 -0
  194. package/dist/node/project/manifest/view-manifest.js +1 -1
  195. package/dist/node/project/project.d.ts +11 -1
  196. package/dist/node/project/project.js +61 -7
  197. package/dist/node/project/wp-info.d.ts +1 -0
  198. package/dist/node/project/wp-info.js +13 -1
  199. package/dist/node/storybook/index.d.ts +2 -0
  200. package/dist/node/storybook/index.js +13 -0
  201. package/dist/node/types/block-type.d.ts +25 -20
  202. package/dist/node/types/block-type.js +1 -0
  203. package/dist/node/types/view-type.d.ts +7 -7
  204. package/dist/node/utils/fetch-wp.d.ts +1 -0
  205. package/dist/node/utils/fetch-wp.js +27 -0
  206. package/dist/node/utils/fs-codegen.d.ts +2 -0
  207. package/dist/node/utils/fs-codegen.js +2 -1
  208. package/dist/node/utils/is-deploying.js +1 -1
  209. package/dist/node/utils/report-builder.d.ts +6 -6
  210. package/dist/node/utils/self-signed-cert.d.ts +2 -0
  211. package/dist/node/utils/self-signed-cert.js +10 -2
  212. package/dist/node/utils/stateful-log.js +2 -0
  213. package/dist/node/utils/watch-file-tree.d.ts +17 -3
  214. package/dist/node/utils/watch-file-tree.js +12 -5
  215. package/package.json +21 -12
  216. package/types.app.d.ts +4 -2
  217. package/types.app.internal.d.ts +2 -2
  218. package/types.meta.d.ts +105 -0
  219. package/types.node.d.ts +3 -3
  220. package/dist/app/lib/blocks/ErrorBoundaryFrontend.d.ts +0 -15
  221. package/dist/app/lib/blocks/ErrorBoundaryFrontend.js +0 -35
  222. package/dist/app/lib/hooks/apiConfig.js +0 -4
  223. package/dist/app/lib/hooks/usePageLoad.d.ts +0 -6
  224. package/dist/app/lib/hooks/usePageLoad.js +0 -5
@@ -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,18 +28,41 @@ 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
  }
35
- export function reactPlugin() {
37
+ export function reactPlugin(args = {}) {
38
+ let currentFile = null;
36
39
  return react({
37
40
  babel: {
38
41
  overrides: [{ test: /types\./, compact: true }],
39
42
  plugins: [
40
43
  {
41
44
  visitor: {
42
- ExportNamedDeclaration: (path) => {
45
+ Program: {
46
+ enter: (path, state) => {
47
+ const filename = state.file.opts.filename;
48
+ if (filename.match(/.\/blocks\/.+\.tsx/)) {
49
+ currentFile = { type: "block", id: filename.replace(/.*\/blocks\/(.+)\.tsx/, "$1") };
50
+ }
51
+ else if (filename.match(/.\/views\/.+\.tsx/)) {
52
+ currentFile = { type: "view", id: filename.replace(/.*\/views\/(.+)\.tsx/, "$1") };
53
+ }
54
+ else {
55
+ currentFile = null;
56
+ }
57
+ },
58
+ exit: (path, state) => {
59
+ currentFile = null;
60
+ // console.log("Exiting", state.file.opts.filename)
61
+ },
62
+ },
63
+ ExportNamedDeclaration: (path, state) => {
64
+ if (!currentFile)
65
+ return;
43
66
  const decl = path.node.declaration;
44
67
  if (decl?.type !== "VariableDeclaration")
45
68
  return;
@@ -47,11 +70,20 @@ export function reactPlugin() {
47
70
  if (!t.isIdentifier(id))
48
71
  return;
49
72
  if (id.name === "meta") {
50
- path.remove();
73
+ if (args.retainBlockMeta && currentFile?.type === "block") {
74
+ // Adds a defineBlock.meta("name", meta) call, which can be used by the editor
75
+ path.replaceWith(t.callExpression(t.memberExpression(t.identifier("defineBlock"), t.identifier("meta")), [
76
+ t.stringLiteral(currentFile.id),
77
+ decl.declarations[0].init,
78
+ ]));
79
+ }
80
+ else {
81
+ path.remove();
82
+ }
51
83
  }
52
84
  },
53
85
  ExportDefaultDeclaration: (path) => {
54
- if (!path.hub.file.opts.filename.match(/\/(blocks|views)\//))
86
+ if (!currentFile)
55
87
  return;
56
88
  if (path.node.declaration.type === "CallExpression") {
57
89
  const call = path.node.declaration;
@@ -66,7 +98,11 @@ export function reactPlugin() {
66
98
  if (t.isExpression(body)) {
67
99
  body = t.blockStatement([t.returnStatement(body)]);
68
100
  }
69
- path.replaceWith(t.exportDefaultDeclaration(t.functionDeclaration(t.identifier(pascalCase(type + "-" + name)), args[1].params, body, args[1].generator, args[1].async)));
101
+ const componentName = pascalCase(type) + "_" + name.replace(/[^a-z0-9]/g, "_").replace(/_+/g, "_");
102
+ path.replaceWithMultiple([
103
+ t.exportDefaultDeclaration(t.functionDeclaration(t.identifier(componentName), args[1].params, body, args[1].generator, args[1].async)),
104
+ t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier(componentName), t.identifier("displayName")), t.stringLiteral(pascalCase(type) + "(" + name + ")"))),
105
+ ]);
70
106
  }
71
107
  }
72
108
  }
@@ -85,8 +121,34 @@ export function ssrPlugin() {
85
121
  name: "proxy-external-ssr-modules",
86
122
  config(config) {
87
123
  config.legacy = {
124
+ ...config.legacy,
88
125
  proxySsrExternalModules: true,
89
126
  };
127
+ config.ssr = {
128
+ ...config.ssr,
129
+ noExternal: [
130
+ "eddev",
131
+ "vinxi",
132
+ "react-use",
133
+ // @ts-ignore
134
+ ...(config?.optimizeDeps?.noExternal ?? []),
135
+ ],
136
+ optimizeDeps: {
137
+ exclude: ["eddev", "vinxi"],
138
+ },
139
+ };
140
+ config.optimizeDeps = {
141
+ ...config.optimizeDeps,
142
+ include: [
143
+ "valtio",
144
+ "@tanstack/react-query",
145
+ "qs",
146
+ "react",
147
+ "react-dom/client",
148
+ ...(config?.optimizeDeps?.include ?? []),
149
+ ],
150
+ exclude: ["eddev", "vinxi", ...(config?.optimizeDeps?.exclude ?? [])],
151
+ };
90
152
  return config;
91
153
  },
92
154
  };
@@ -114,12 +176,15 @@ function buildStatusPlugin(console) {
114
176
  }
115
177
  export function corePlugins(args) {
116
178
  return [
117
- tsconfigPaths(),
118
- reactPlugin(),
119
- args.mode === "development" && args.serverless && ssrPlugin(),
179
+ args.serverless && ssrPlugin(),
120
180
  envPlugin(args),
181
+ tsconfigPaths(),
182
+ reactPlugin({ retainBlockMeta: args.target === "cms" }),
121
183
  ].flat();
122
184
  }
185
+ export function storybookVitePlugins(args) {
186
+ return [args.serverless && ssrPlugin(), envPlugin(args), tsconfigPaths()].flat();
187
+ }
123
188
  export function getViteConfig(args) {
124
189
  const console = args.console;
125
190
  const logger = createLogger();
@@ -134,6 +199,7 @@ export function getViteConfig(args) {
134
199
  logger.clearScreen = () => {
135
200
  args.console.resetLog();
136
201
  };
202
+ const entryFile = `./.eddev/${args.mode === "production" ? "prod" : "dev"}-spa/entry.${args.target === "cms" ? "admin" : "client"}.tsx`;
137
203
  /** Initial config */
138
204
  const config = {
139
205
  appType: "custom",
@@ -145,16 +211,30 @@ export function getViteConfig(args) {
145
211
  define: {
146
212
  "process.env.NODE_ENV": JSON.stringify(args.mode),
147
213
  },
148
- plugins: [tsconfigPaths(), envPlugin(args), reactPlugin(), buildStatusPlugin(console)],
214
+ plugins: [
215
+ tsconfigPaths(),
216
+ envPlugin(args),
217
+ reactPlugin({
218
+ retainBlockMeta: args.target === "cms",
219
+ }),
220
+ buildStatusPlugin(console),
221
+ ],
149
222
  build: {
150
223
  manifest: true,
151
224
  sourcemap: true,
152
225
  minify: args.mode === "production",
153
226
  modulePreload: false,
154
227
  outDir: args.outDir,
155
- watch: {},
228
+ lib: args.target === "cms"
229
+ ? {
230
+ entry: [entryFile],
231
+ fileName: (format, entryName) => `${entryName}.${format}.js`,
232
+ name: "eddev",
233
+ formats: ["iife"],
234
+ }
235
+ : undefined,
156
236
  rollupOptions: {
157
- input: `/.eddev/${args.mode === "production" ? "prod" : "dev"}-spa/entry.${args.target === "cms" ? "admin" : "client"}.tsx`,
237
+ input: args.target === "frontend" ? entryFile : undefined,
158
238
  external: args.target === "cms" ? ["react", "react-dom"] : [],
159
239
  onwarn(warning, warn) {
160
240
  if (!cliMode.verbose &&
@@ -169,8 +249,8 @@ export function getViteConfig(args) {
169
249
  },
170
250
  output: args.target === "cms"
171
251
  ? {
172
- entryFileNames: "main.admin.js",
173
- format: "iife",
252
+ // entryFileNames: "main.admin.js",
253
+ // format: "iife",
174
254
  globals: {
175
255
  react: "window.React",
176
256
  "react-dom": "window.ReactDOM",
@@ -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
  },