eddev 2.0.0-beta.4 → 2.0.0-beta.40

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 (218) hide show
  1. package/dist/app/entry/MetaTags.d.ts +7 -0
  2. package/dist/app/entry/MetaTags.js +17 -0
  3. package/dist/app/entry/boot-admin.d.ts +1 -0
  4. package/dist/app/entry/{main.admin.js → boot-admin.js} +3 -5
  5. package/dist/app/entry/spa-root.d.ts +1 -0
  6. package/dist/app/entry/{Root.js → spa-root.js} +4 -4
  7. package/dist/app/entry/ssr-root-client.d.ts +6 -0
  8. package/dist/app/entry/ssr-root-client.js +16 -0
  9. package/dist/app/entry/ssr-root.d.ts +10 -0
  10. package/dist/app/entry/ssr-root.js +24 -0
  11. package/dist/app/lib/admin/index.d.ts +2 -2
  12. package/dist/app/lib/admin/index.js +2 -2
  13. package/dist/app/lib/admin/installFieldTypes.js +1 -1
  14. package/dist/app/lib/admin/runWidgets.js +1 -1
  15. package/dist/app/lib/blocks/ContentBlocks.js +4 -4
  16. package/dist/app/lib/blocks/EditableText.d.ts +1 -1
  17. package/dist/app/lib/blocks/EditableText.js +3 -3
  18. package/dist/app/lib/blocks/ErrorBoundaryFrontend.js +1 -0
  19. package/dist/app/lib/blocks/InnerBlocks.d.ts +13 -3
  20. package/dist/app/lib/blocks/InnerBlocks.js +13 -5
  21. package/dist/app/lib/blocks/block-utils.d.ts +2 -2
  22. package/dist/app/lib/blocks/block-utils.js +2 -2
  23. package/dist/app/lib/blocks/editor/EditorSupport.js +3 -3
  24. package/dist/app/lib/blocks/editor/editor-config.d.ts +1 -1
  25. package/dist/app/lib/blocks/editor/editor-config.js +1 -1
  26. package/dist/app/lib/blocks/editor/installGutenbergHooks.js +5 -5
  27. package/dist/app/lib/blocks/editor/usePostEditor.d.ts +1 -1
  28. package/dist/app/lib/blocks/index.d.ts +9 -9
  29. package/dist/app/lib/blocks/index.js +9 -9
  30. package/dist/app/lib/blocks/inline-editing.d.ts +1 -1
  31. package/dist/app/lib/blocks/inline-editing.js +7 -5
  32. package/dist/app/lib/devtools/components/BreakpointIndicator.js +6 -4
  33. package/dist/app/lib/devtools/components/DevUI.js +4 -3
  34. package/dist/app/lib/devtools/components/GridIndicator.d.ts +1 -0
  35. package/dist/app/lib/devtools/components/GridIndicator.js +24 -0
  36. package/dist/app/lib/devtools/dev-tools-store.d.ts +9 -0
  37. package/dist/app/lib/devtools/dev-tools-store.js +8 -0
  38. package/dist/app/lib/devtools/hooks/usePersistState.d.ts +1 -1
  39. package/dist/app/lib/devtools/hooks/usePersistState.js +11 -2
  40. package/dist/app/lib/devtools/hooks/useTailwind.d.ts +1078 -1079
  41. package/dist/app/lib/devtools/hooks/useTailwind.js +6 -3
  42. package/dist/app/lib/devtools/index.d.ts +1 -0
  43. package/dist/app/lib/devtools/index.js +1 -1
  44. package/dist/app/lib/devtools/loader.js +8 -7
  45. package/dist/app/lib/devtools/useQueryDebug.d.ts +7 -1
  46. package/dist/app/lib/devtools/useQueryDebug.js +5 -8
  47. package/dist/app/lib/dynamic/index.d.ts +1 -1
  48. package/dist/app/lib/dynamic/index.js +1 -1
  49. package/dist/app/lib/hooks/apiConfig.d.ts +3 -1
  50. package/dist/app/lib/hooks/apiConfig.js +9 -4
  51. package/dist/app/lib/hooks/index.d.ts +4 -5
  52. package/dist/app/lib/hooks/index.js +4 -5
  53. package/dist/app/lib/hooks/queryUtils.d.ts +5 -2
  54. package/dist/app/lib/hooks/queryUtils.js +19 -20
  55. package/dist/app/lib/hooks/useAppData.js +1 -1
  56. package/dist/app/lib/internal/index.d.ts +4 -4
  57. package/dist/app/lib/internal/index.js +4 -4
  58. package/dist/app/lib/internal/internal-store.d.ts +0 -2
  59. package/dist/app/lib/internal/internal-store.js +1 -3
  60. package/dist/app/lib/internal/read-admin-manifest.d.ts +1 -1
  61. package/dist/app/lib/legacy-stitches/createStitches.d.ts +21 -21
  62. package/dist/app/lib/legacy-stitches/createStitches.js +1 -1
  63. package/dist/app/lib/legacy-stitches/index.d.ts +1 -1
  64. package/dist/app/lib/legacy-stitches/index.js +1 -1
  65. package/dist/app/lib/routing/components/BackButton.d.ts +49 -0
  66. package/dist/app/lib/routing/components/BackButton.js +47 -0
  67. package/dist/app/lib/routing/components/BrowserRouter.d.ts +4 -1
  68. package/dist/app/lib/routing/components/BrowserRouter.js +68 -11
  69. package/dist/app/lib/routing/components/ClientOnly.js +1 -1
  70. package/dist/app/lib/routing/components/Link.d.ts +1 -0
  71. package/dist/app/lib/routing/components/Link.js +9 -10
  72. package/dist/app/lib/routing/components/RouteRenderer.d.ts +1 -1
  73. package/dist/app/lib/routing/components/RouteRenderer.js +7 -6
  74. package/dist/app/lib/routing/components/SSRRouter.d.ts +2 -2
  75. package/dist/app/lib/routing/components/SSRRouter.js +5 -6
  76. package/dist/app/lib/routing/components/ScrollRestoration.js +1 -1
  77. package/dist/app/lib/routing/context.d.ts +2 -2
  78. package/dist/app/lib/routing/context.js +6 -96
  79. package/dist/app/lib/routing/hooks/useRestorableState.js +2 -1
  80. package/dist/app/lib/routing/hooks/useRoute.d.ts +16 -1
  81. package/dist/app/lib/routing/hooks/useRoute.js +22 -1
  82. package/dist/app/lib/routing/hooks/useRouteMeta.d.ts +5 -0
  83. package/dist/app/lib/routing/hooks/useRouteMeta.js +9 -0
  84. package/dist/app/lib/routing/hooks/useRouteTransition.d.ts +1 -1
  85. package/dist/app/lib/routing/hooks/useRouteTransition.js +1 -1
  86. package/dist/app/lib/routing/hooks/useRouter.d.ts +1 -1
  87. package/dist/app/lib/routing/hooks/useRouter.js +1 -1
  88. package/dist/app/lib/routing/hooks/useRouterEvents.d.ts +1 -1
  89. package/dist/app/lib/routing/hooks/useRouterEvents.js +1 -1
  90. package/dist/app/lib/routing/hooks/useRouterState.d.ts +1 -1
  91. package/dist/app/lib/routing/hooks/useRouterState.js +1 -1
  92. package/dist/app/lib/routing/hooks/useSearchParams.js +2 -2
  93. package/dist/app/lib/routing/index.d.ts +14 -13
  94. package/dist/app/lib/routing/index.js +14 -13
  95. package/dist/app/lib/routing/loader.d.ts +2 -2
  96. package/dist/app/lib/routing/loader.js +7 -5
  97. package/dist/app/lib/routing/types.d.ts +28 -8
  98. package/dist/app/lib/routing/utils.d.ts +3 -1
  99. package/dist/app/lib/routing/utils.js +11 -0
  100. package/dist/app/lib/views/index.d.ts +1 -1
  101. package/dist/app/lib/views/index.js +1 -1
  102. package/dist/app/server/defineRouter.d.ts +2 -0
  103. package/dist/app/server/defineRouter.js +4 -0
  104. package/dist/app/server/index.d.ts +4 -0
  105. package/dist/app/server/index.js +4 -0
  106. package/dist/app/server/proxy-wp-admin.d.ts +3 -0
  107. package/dist/app/server/proxy-wp-admin.js +105 -0
  108. package/dist/app/server/render-ssr-page.d.ts +5 -0
  109. package/dist/app/server/render-ssr-page.js +31 -0
  110. package/dist/app/server/server-context.d.ts +50 -0
  111. package/dist/app/server/server-context.js +145 -0
  112. package/dist/app/server/utils/headers.d.ts +1 -0
  113. package/dist/app/server/utils/headers.js +17 -0
  114. package/dist/app/server/utils/replace-host.d.ts +6 -4
  115. package/dist/app/server/utils/replace-host.js +58 -11
  116. package/dist/node/cli/cli-worker.d.ts +1 -1
  117. package/dist/node/cli/cli-worker.js +7 -2
  118. package/dist/node/cli/cli.js +84 -12
  119. package/dist/node/cli/display/CLIApp.d.ts +1 -1
  120. package/dist/node/cli/display/CLIApp.js +3 -6
  121. package/dist/node/cli/display/components/LogEntries.d.ts +1 -1
  122. package/dist/node/cli/display/hooks/useStatefulLog.d.ts +1 -1
  123. package/dist/node/cli/display/tools/CreateBlock.d.ts +1 -1
  124. package/dist/node/cli/display/tools/cli-tools.d.ts +1 -11
  125. package/dist/node/cli/display/tools/cli-tools.js +9 -9
  126. package/dist/node/cli/display/util/colors.d.ts +2 -2
  127. package/dist/node/cli/version.d.ts +1 -1
  128. package/dist/node/cli/version.js +1 -1
  129. package/dist/node/compiler/build-vinxi.d.ts +8 -0
  130. package/dist/node/compiler/build-vinxi.js +37 -0
  131. package/dist/node/compiler/bundler.admin.d.ts +2 -2
  132. package/dist/node/compiler/bundler.admin.js +3 -4
  133. package/dist/node/compiler/bundler.frontend.d.ts +1 -1
  134. package/dist/node/compiler/bundler.frontend.js +3 -4
  135. package/dist/node/compiler/{serverless.dev.d.ts → dev-server.d.ts} +7 -5
  136. package/dist/node/compiler/dev-server.js +105 -0
  137. package/dist/node/compiler/get-vite-config.d.ts +19 -0
  138. package/dist/node/compiler/get-vite-config.js +200 -0
  139. package/dist/node/compiler/vinxi-app.d.ts +19 -0
  140. package/dist/node/compiler/vinxi-app.js +159 -0
  141. package/dist/node/compiler/vinxi-codegen.d.ts +12 -0
  142. package/dist/node/compiler/vinxi-codegen.js +464 -0
  143. package/dist/node/graphql/graphql-codegen.d.ts +1 -1
  144. package/dist/node/graphql/graphql-codegen.js +63 -16
  145. package/dist/node/graphql/graphql-schema-loader.js +15 -18
  146. package/dist/node/project/config.js +1 -1
  147. package/dist/node/project/env.d.ts +1 -1
  148. package/dist/node/project/env.js +1 -1
  149. package/dist/node/project/manifest/block-manifest.js +2 -2
  150. package/dist/node/project/manifest/manifest.d.ts +1 -1
  151. package/dist/node/project/manifest/manifest.js +1 -1
  152. package/dist/node/project/manifest/view-manifest.js +2 -2
  153. package/dist/node/project/project.d.ts +3 -2
  154. package/dist/node/project/project.js +18 -20
  155. package/dist/node/project/wp-info.js +3 -2
  156. package/dist/node/types/view-type.js +3 -4
  157. package/dist/node/utils/fs-codegen.d.ts +40 -0
  158. package/dist/node/utils/fs-codegen.js +97 -0
  159. package/dist/node/utils/fs.js +2 -0
  160. package/dist/node/utils/{selfSignedCert.js → self-signed-cert.js} +1 -1
  161. package/dist/node/utils/{statefulLog.js → stateful-log.js} +1 -1
  162. package/package.json +31 -32
  163. package/types.app.d.ts +2 -2
  164. package/types.app.internal.d.ts +2 -2
  165. package/types.node.d.ts +3 -3
  166. package/dist/app/entry/Root.d.ts +0 -1
  167. package/dist/app/entry/main.admin.d.ts +0 -3
  168. package/dist/app/entry/main.frontend.spa.d.ts +0 -3
  169. package/dist/app/entry/main.frontend.spa.js +0 -13
  170. package/dist/app/entry/main.frontend.ssr.d.ts +0 -21
  171. package/dist/app/entry/main.frontend.ssr.js +0 -79
  172. package/dist/app/entry/main.serverless.dev.d.ts +0 -4
  173. package/dist/app/entry/main.serverless.dev.js +0 -21
  174. package/dist/app/lib/hooks/usePageLoad.d.ts +0 -6
  175. package/dist/app/lib/hooks/usePageLoad.js +0 -5
  176. package/dist/app/server/create-api-builtin-hono.d.ts +0 -8
  177. package/dist/app/server/create-api-builtin-hono.js +0 -80
  178. package/dist/app/server/create-ssr-hono.d.ts +0 -18
  179. package/dist/app/server/create-ssr-hono.js +0 -104
  180. package/dist/app/server/utils/index.html.d.ts +0 -2
  181. package/dist/app/server/utils/index.html.js +0 -14
  182. package/dist/node/compiler/index.html.d.ts +0 -2
  183. package/dist/node/compiler/index.html.js +0 -15
  184. package/dist/node/compiler/serverless.dev.js +0 -215
  185. package/dist/node/compiler/vite/get-vite-config.d.ts +0 -13
  186. package/dist/node/compiler/vite/get-vite-config.js +0 -323
  187. package/dist/node/compiler/vite/plugin-admin.d.ts +0 -4
  188. package/dist/node/compiler/vite/plugin-admin.js +0 -67
  189. package/dist/node/compiler/vite/plugin-blocks.d.ts +0 -4
  190. package/dist/node/compiler/vite/plugin-blocks.js +0 -73
  191. package/dist/node/compiler/vite/plugin-entry.d.ts +0 -6
  192. package/dist/node/compiler/vite/plugin-entry.js +0 -16
  193. package/dist/node/compiler/vite/plugin-resolved-tailwind.d.ts +0 -4
  194. package/dist/node/compiler/vite/plugin-resolved-tailwind.js +0 -29
  195. package/dist/node/compiler/vite/plugin-theme.d.ts +0 -4
  196. package/dist/node/compiler/vite/plugin-theme.js +0 -40
  197. package/dist/node/compiler/vite/plugin-views.d.ts +0 -4
  198. package/dist/node/compiler/vite/plugin-views.js +0 -51
  199. package/dist/node/utils/console.d.ts +0 -21
  200. package/dist/node/utils/console.js +0 -28
  201. package/dist/node/utils/unsafe-fetch.d.ts +0 -2
  202. package/dist/node/utils/unsafe-fetch.js +0 -19
  203. package/tsup.config.ts +0 -40
  204. package/types.manifests.d.ts +0 -22
  205. /package/dist/node/utils/{formatZodError.d.ts → format-zod-error.d.ts} +0 -0
  206. /package/dist/node/utils/{formatZodError.js → format-zod-error.js} +0 -0
  207. /package/dist/node/utils/{getRepoInfo.d.ts → get-repo-info.d.ts} +0 -0
  208. /package/dist/node/utils/{getRepoInfo.js → get-repo-info.js} +0 -0
  209. /package/dist/node/utils/{highlightCode.d.ts → highlight-code.d.ts} +0 -0
  210. /package/dist/node/utils/{highlightCode.js → highlight-code.js} +0 -0
  211. /package/dist/node/utils/{isDeploying.d.ts → is-deploying.d.ts} +0 -0
  212. /package/dist/node/utils/{isDeploying.js → is-deploying.js} +0 -0
  213. /package/dist/node/utils/{selfSignedCert.d.ts → self-signed-cert.d.ts} +0 -0
  214. /package/dist/node/utils/{statefulLog.d.ts → stateful-log.d.ts} +0 -0
  215. /package/dist/node/utils/{export-extractor.d.ts → ts-export-extractor.d.ts} +0 -0
  216. /package/dist/node/utils/{export-extractor.js → ts-export-extractor.js} +0 -0
  217. /package/dist/node/utils/{watchFileTree.d.ts → watch-file-tree.d.ts} +0 -0
  218. /package/dist/node/utils/{watchFileTree.js → watch-file-tree.js} +0 -0
@@ -0,0 +1,464 @@
1
+ import { code, imp } from "ts-poet";
2
+ import { FSCodegen } from "../utils/fs-codegen.js";
3
+ export function getVinxiFolder(opts) {
4
+ return (opts.mode === "development" ? "dev" : "prod") + (opts.serverless ? "" : "-spa");
5
+ }
6
+ export async function runVinxiCodegen(opts) {
7
+ const codegen = createVinxiCodegen(opts);
8
+ await codegen.run();
9
+ codegen.stop();
10
+ }
11
+ export function createVinxiCodegen(opts) {
12
+ const project = opts.project;
13
+ const folder = ".eddev/" + getVinxiFolder(opts);
14
+ const codegen = new FSCodegen(opts.project, {
15
+ outDir: folder,
16
+ });
17
+ if (opts.serverless) {
18
+ codegen.registerFile({
19
+ name: "context.ts",
20
+ generate: () => {
21
+ const args = {
22
+ dev: true,
23
+ origin: project.origin,
24
+ replaceUrls: {
25
+ from: project.origin,
26
+ to: opts.endpoint ?? "",
27
+ prefixes: [
28
+ { prefix: "/wp-content/uploads", replace: project.config?.serverless.uploads === "proxy" },
29
+ { prefix: "/wp-content/plugins", replace: project.config?.serverless.plugins === "proxy" },
30
+ ],
31
+ },
32
+ };
33
+ return code /* tsx */ `
34
+ import { ServerContext } from "eddev/server"
35
+ import { getManifest } from "vinxi/manifest"
36
+
37
+ ServerContext.setRuntime({
38
+ getManifest
39
+ })
40
+
41
+ export const serverContext = new ServerContext({${Object.entries(args)
42
+ .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
43
+ .join(",\n")}
44
+ })
45
+ `.toString();
46
+ },
47
+ });
48
+ }
49
+ if (opts.serverless) {
50
+ codegen.registerFile({
51
+ name: "react-shim.js",
52
+ generate: code /* tsx */ `
53
+ import React from "react"
54
+ import ReactDOM from "react-dom/client"
55
+ Object.assign(React, window.React)
56
+ Object.assign(ReactDOM, window.ReactDOM)
57
+ `,
58
+ });
59
+ }
60
+ if (opts.serverless) {
61
+ // codegen.registerFile({
62
+ // name: "manifest/extra-routes.ts",
63
+ // generate: code/* tsx */ `
64
+ // import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders } from "vinxi/http"
65
+ // import { serverContext } from "./context.js"
66
+ // export const routes = [
67
+ // {
68
+ // pattern: '/test1',
69
+ // handler: () => import('../../../test.ts')
70
+ // }
71
+ // ]
72
+ // export default eventHandler((event) => {
73
+ // routes
74
+ // })
75
+ // `,
76
+ // })
77
+ }
78
+ codegen.registerFile({
79
+ name: "entry.admin.tsx",
80
+ generate: () => {
81
+ return code /* tsx */ `
82
+ ${opts.serverless ? `import "./react-shim.js"` : ""}
83
+ ${opts.serverless ? `import "vinxi/client"` : ""}
84
+ import "../../views/index.css"
85
+ import "./manifest/admin"
86
+ import "./manifest/blocks"
87
+ import "./manifest/styles"
88
+ import bootAdmin from "eddev/_internal/boot-admin.js"
89
+
90
+ bootAdmin()
91
+ `;
92
+ },
93
+ });
94
+ codegen.registerFile({
95
+ name: "entry.client.tsx",
96
+ generate: () => {
97
+ if (opts.serverless) {
98
+ /**
99
+ * Client entry for SSR mode
100
+ */
101
+ return code /* tsx */ `
102
+ /// <reference types="vinxi/types/client" />
103
+ /**
104
+ * SSR-mode frontend entry.
105
+ * Hydrates the main app, including the html/head/body elements.
106
+ * Also ensures that the assets used during SSR are loaded.
107
+ */
108
+ import "vinxi/client"
109
+ import "../../views/index.css"
110
+ import "./manifest/blocks"
111
+ import "./manifest/views"
112
+
113
+ import * as React from "react"
114
+ import { Root, hydrateRoot } from "react-dom/client"
115
+ import { SSRClientRoot } from "eddev/_internal/ssr-root-client.js"
116
+ import { getManifest } from "vinxi/manifest"
117
+ import { createAssets } from "@vinxi/react"
118
+ import { devToolsStore } from 'eddev/devtools'
119
+
120
+ // Set up a dynamic entry which will load the configured tailwind manifest
121
+ devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config.js')
122
+
123
+ // Create the asset renderer, which will ensure scripts/styles are mounted correctly
124
+ function getAssets() {
125
+ const Assets = createAssets(getManifest("client").handler, getManifest("client"))
126
+ return <React.Suspense><Assets /></React.Suspense>
127
+ }
128
+
129
+ window.$reactRoot =
130
+ window.$reactRoot ||
131
+ hydrateRoot(
132
+ document,
133
+ <SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} />,
134
+ )
135
+
136
+ if (import.meta.hot) {
137
+ import.meta.hot.accept((mod) => {
138
+ if (mod) {
139
+ const Assets = createAssets(getManifest("client").handler, getManifest("client"))
140
+ const app = <SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} />
141
+ window.$reactRoot?.render(app)
142
+ }
143
+ })
144
+ }
145
+
146
+ declare global {
147
+ interface Window {
148
+ $reactRoot?: Root
149
+ _PAGE_DATA: any
150
+ }
151
+ }
152
+
153
+ `;
154
+ }
155
+ else {
156
+ return code /* tsx */ `
157
+ /**
158
+ * SPA-mode frontend entry.
159
+ * Renders the main app into the empty <div id='root'> element, and expects window._PAGE_DATA to be set.
160
+ */
161
+ import "./manifest/blocks"
162
+ import "./manifest/views"
163
+ import "../../views/index.css"
164
+ import { devToolsStore } from 'eddev/devtools'
165
+ import { createRoot } from "react-dom/client"
166
+ import { SPARoot } from "eddev/_internal/spa-root.js"
167
+ import * as React from "react"
168
+
169
+ devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config')
170
+
171
+ createRoot(document.getElementById("root")!).render(<SPARoot />)
172
+ `;
173
+ }
174
+ },
175
+ });
176
+ if (opts.serverless) {
177
+ codegen.registerFile({
178
+ name: "handler.data-api.ts",
179
+ generate: code /* tsx */ `
180
+ /// <reference types="vinxi/types/server" />
181
+ import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders } from "vinxi/http"
182
+ import { serverContext } from "./context.js"
183
+
184
+ const router = createRouter()
185
+ .get(
186
+ "/route/",
187
+ eventHandler(async (event) => {
188
+ const id = "/"
189
+
190
+ return await serverContext.fetchRouteData({
191
+ pathname: id,
192
+ withAppData: false,
193
+ })
194
+ }),
195
+ )
196
+ .get(
197
+ "/route/**:name",
198
+ eventHandler(async (event) => {
199
+ const id = "/" + getRouterParam(event, "name")
200
+
201
+ return await serverContext.fetchRouteData({
202
+ pathname: id,
203
+ withAppData: false,
204
+ })
205
+ }),
206
+ )
207
+ .get(
208
+ "/query/**:name",
209
+ eventHandler(async (event) => {
210
+ const id = "/" + getRouterParam(event, "name")
211
+ const paramString = getQuery(event).params
212
+
213
+ const params = typeof paramString === "string" && paramString.length ? JSON.parse(paramString) : {}
214
+
215
+ return await serverContext.fetchNamedQuery({
216
+ name: id,
217
+ params: params,
218
+ headers: getRequestHeaders(event),
219
+ })
220
+ }),
221
+ )
222
+ .post(
223
+ "/mutation/**:name",
224
+ eventHandler(async (event) => {
225
+ const id = "/" + getRouterParam(event, "name")
226
+ const body = await getWebRequest(event).json()
227
+ return await serverContext.fetchMutation({
228
+ name: id,
229
+ body,
230
+ headers: getRequestHeaders(event),
231
+ })
232
+ }),
233
+ )
234
+
235
+ export default router.handler
236
+
237
+ `,
238
+ });
239
+ }
240
+ if (opts.serverless) {
241
+ codegen.registerFile({
242
+ name: "handler.ssr-page.ts",
243
+ generate: code /* tsx */ `
244
+ /// <reference types="vinxi/types/server" />
245
+ import "../../views/index.css"
246
+ import "./manifest/blocks.js"
247
+ import "./manifest/styles.js"
248
+ import "./manifest/views.js"
249
+
250
+ import { proxyWpAdmin, renderPageToSSRStream } from "eddev/server"
251
+ import { eventHandler, getRequestURL, setResponseHeader, setResponseStatus } from "vinxi/http"
252
+ import { serverContext } from "./context.js"
253
+ import { RouteData } from "eddev/routing"
254
+
255
+ export default eventHandler({
256
+ handler: async (event) => {
257
+ const url = getRequestURL(event)
258
+
259
+ if (url.pathname.includes(".")) {
260
+ return proxyWpAdmin(event, serverContext)
261
+ }
262
+
263
+ try {
264
+ const [{appData, trackers}, response] = await Promise.all([
265
+ serverContext.fetchAppData(),
266
+ serverContext.fetchRouteData({
267
+ pathname: url.pathname,
268
+ withAppData: false,
269
+ headers: {},
270
+ query: {},
271
+ }),
272
+ ])
273
+
274
+ let data: RouteData
275
+ try {
276
+ data = await response.json()
277
+ data.appData = appData
278
+ data.trackers = trackers
279
+ } catch (err) {
280
+ data = {
281
+ view: "_error",
282
+ viewType: "react",
283
+ viewData: {},
284
+ appData: appData,
285
+ }
286
+ console.error(err)
287
+ setResponseStatus(event, 500)
288
+ }
289
+ setResponseHeader(event, "Content-Type", "text/html; charset=utf-8")
290
+ return renderPageToSSRStream(url.pathname, data, serverContext)
291
+ } catch (err) {
292
+ console.error(err)
293
+ setResponseStatus(event, 500)
294
+ setResponseHeader(event, "Content-Type", "text/html; charset=utf-8")
295
+ return '<!DOCTYPE html><html><head><title>500 Internal Server Error</title></head><body><h1>500 Internal Server Error</h1><p>"'+err.message+'"</p></body></html>'
296
+ }
297
+ },
298
+ })
299
+ `,
300
+ });
301
+ }
302
+ if (opts.serverless) {
303
+ codegen.registerFile({
304
+ name: "handler.wp-proxy.ts",
305
+ generate: code /* tsx */ `
306
+ /// <reference types="vinxi/types/server" />
307
+ import { proxyWpAdmin } from "eddev/server"
308
+ import { eventHandler } from "vinxi/http"
309
+ import { serverContext } from "./context.js"
310
+
311
+ export default eventHandler(async (event) => {
312
+ return proxyWpAdmin(event, serverContext)
313
+ })
314
+ `,
315
+ });
316
+ }
317
+ codegen.registerFile({
318
+ name: "manifest/blocks.ts",
319
+ generate: async () => {
320
+ const blockManifest = await project.blocks.get();
321
+ return code /* ts */ `
322
+ import { blockManifestReader } from 'eddev/_internal'
323
+ import { dynamic } from 'eddev/dynamic'
324
+ import core from '../../../blocks/_core'
325
+
326
+ const manifest = {
327
+ ${Object.entries(blockManifest.blocks)
328
+ .filter(([name]) => !name.match(/^_[a-z]+$/i))
329
+ .map(([name, block]) => {
330
+ const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}))`;
331
+ return JSON.stringify(block.acfName) + ": " + importStatement;
332
+ })
333
+ .join(",\n")},
334
+ ...core
335
+ }
336
+
337
+ const info = {
338
+ ${Object.entries(blockManifest.blocks)
339
+ .filter(([name]) => !name.match(/^_[a-z]+$/i))
340
+ .map(([name, block]) => {
341
+ return (JSON.stringify(block.acfName) +
342
+ ": " +
343
+ JSON.stringify({
344
+ slug: block.slug,
345
+ tags: block.tags,
346
+ flags: block.flags ?? {},
347
+ }));
348
+ })
349
+ .join(",\n")}
350
+ }
351
+
352
+ blockManifestReader.set(manifest, info)
353
+
354
+ export default manifest
355
+
356
+ if (import.meta.hot) {
357
+ import.meta.hot.accept()
358
+ }
359
+ `;
360
+ },
361
+ subscribe: project.blocks.subscribe,
362
+ });
363
+ codegen.registerFile({
364
+ name: "manifest/admin.ts",
365
+ generate: async () => {
366
+ const fieldManifest = await project.fields.get();
367
+ const widgetManifest = await project.widgets.get();
368
+ return code /* ts */ `
369
+ import { adminManifestReader } from 'eddev/_internal'
370
+ import editorConfig from '../../../blocks/_editor'
371
+
372
+ const fields = {${Object.entries(fieldManifest.fields)
373
+ .map(([name, field]) => {
374
+ const importStatement = `() => import(${JSON.stringify("../../../" + field.fileName)}).then(m => m.default)`;
375
+ return JSON.stringify(field.slug) + ": " + importStatement;
376
+ })
377
+ .join(",\n")}}
378
+ const widgets = {${Object.entries(widgetManifest.widgets)
379
+ .map(([name, widget]) => {
380
+ const importStatement = `() => import(${JSON.stringify("../../../" + widget.fileName)}).then(m => m.default)`;
381
+ return JSON.stringify(widget.slug) + ": " + importStatement;
382
+ })
383
+ .join(",\n")}}
384
+
385
+ const manifest = {
386
+ fields,
387
+ widgets,
388
+ editorConfig
389
+ }
390
+
391
+ adminManifestReader.set(manifest)
392
+
393
+ export default manifest
394
+
395
+ export { editorConfig }
396
+
397
+ if (import.meta.hot) {
398
+ import.meta.hot.accept()
399
+ }
400
+ `;
401
+ },
402
+ subscribe: (callback) => {
403
+ const unsub = [project.fields.subscribe(callback), project.widgets.subscribe(callback)];
404
+ return () => unsub.forEach((u) => u());
405
+ },
406
+ });
407
+ codegen.registerFile({
408
+ name: "manifest/views.ts",
409
+ generate: async () => {
410
+ const viewManifest = await project.views.get();
411
+ return code /* ts */ `
412
+ import { viewManifestReader } from 'eddev/_internal'
413
+ import { dynamic } from 'eddev/dynamic'
414
+ const manifest = {${Object.entries(viewManifest.views).map(([name, view]) => {
415
+ const src = "../../../" + view.fileName;
416
+ let importStatement;
417
+ if (name.startsWith("_")) {
418
+ importStatement = imp(name + "=" + src);
419
+ }
420
+ else {
421
+ importStatement = code `dynamic(() => import(${JSON.stringify(src)}))`;
422
+ }
423
+ return code `${JSON.stringify(view.slug)}: ${importStatement},\n`;
424
+ })}}
425
+
426
+ viewManifestReader.value = manifest
427
+
428
+ export default manifest
429
+
430
+ if (import.meta.hot) {
431
+ import.meta.hot.accept()
432
+ }
433
+ `;
434
+ },
435
+ subscribe: project.views.subscribe,
436
+ });
437
+ codegen.registerFile({
438
+ name: "manifest/styles.ts",
439
+ generate: async () => {
440
+ return code /* ts */ `
441
+ export const getCssText = undefined
442
+ export const editorGlobalStyles = () => {}
443
+ `;
444
+ },
445
+ });
446
+ codegen.registerFile({
447
+ name: "manifest/tailwind-config.ts",
448
+ generate: async () => {
449
+ return code /* ts */ `
450
+ import tw from "../../../tailwind.config.ts"
451
+ import resolveConfig from 'tailwindcss/resolveConfig'
452
+ import { devToolsStore } from 'eddev/devtools'
453
+
454
+ const value = resolveConfig(tw)
455
+ devToolsStore.tailwindConfig = value
456
+
457
+ if (import.meta.hot) {
458
+ import.meta.hot.accept()
459
+ }
460
+ `;
461
+ },
462
+ });
463
+ return codegen;
464
+ }
@@ -1,5 +1,5 @@
1
1
  import { Project } from "../project/project.js";
2
- export declare const graphqlLog: import("../utils/statefulLog.js").StatefulLog<GraphQLGenerator>;
2
+ export declare const graphqlLog: import("../utils/stateful-log.js").StatefulLog<GraphQLGenerator>;
3
3
  export declare class GraphQLGenerator {
4
4
  project: Project;
5
5
  private needsRegenerate;
@@ -1,5 +1,5 @@
1
1
  import { codegen } from "@graphql-codegen/core";
2
- import { Kind } from "graphql";
2
+ import { Kind, visit } from "graphql";
3
3
  import { NoUnusedFragmentsRule, specifiedRules, validate } from "graphql/validation/index.js";
4
4
  import { join, relative, resolve } from "path";
5
5
  import { ProjectEnvUtils } from "../project/env.js";
@@ -10,9 +10,9 @@ import * as typescriptPlugin from "@graphql-codegen/typescript";
10
10
  import * as typescriptOperationsPlugin from "@graphql-codegen/typescript-operations";
11
11
  import chalk from "chalk";
12
12
  import { code } from "ts-poet";
13
- import { highlightCode } from "../utils/highlightCode.js";
14
- import { createConsole } from "../utils/statefulLog.js";
15
- import { watchFileTreeForChanges } from "../utils/watchFileTree.js";
13
+ import { highlightCode } from "../utils/highlight-code.js";
14
+ import { createConsole } from "../utils/stateful-log.js";
15
+ import { watchFileTreeForChanges } from "../utils/watch-file-tree.js";
16
16
  import pluginFiles from "./plugins/gql-plugin-files.js";
17
17
  import pluginNoDuplicates from "./plugins/gql-plugin-no-duplicates.js";
18
18
  import pluginQueries from "./plugins/gql-plugin-queries.js";
@@ -62,6 +62,11 @@ export class GraphQLGenerator {
62
62
  this.project = project;
63
63
  this.schemaLoader = new GraphQLSchemaLoader(ProjectEnvUtils.get("DEBUG_GRAPHQL_URL"));
64
64
  this.fileLoader = createGraphQLFileLoader(this.project, [
65
+ {
66
+ baseFolder: "queries/fragments",
67
+ pattern: "**/*.graphql",
68
+ key: "fragments",
69
+ },
65
70
  {
66
71
  baseFolder: "blocks",
67
72
  pattern: "**/*.graphql",
@@ -72,11 +77,6 @@ export class GraphQLGenerator {
72
77
  pattern: "**/*.graphql",
73
78
  key: "views",
74
79
  },
75
- {
76
- baseFolder: "queries/fragments",
77
- pattern: "**/*.graphql",
78
- key: "fragments",
79
- },
80
80
  {
81
81
  baseFolder: "queries",
82
82
  pattern: "**/*.graphql",
@@ -227,6 +227,9 @@ export class GraphQLGenerator {
227
227
  documents: getDocuments(["queries", "views", "blocks", "fragments"]),
228
228
  hasDocuments: true,
229
229
  banner: `import { ContentBlock } from "eddev/blocks"`,
230
+ footer: Object.keys(wp.scalarTypes)
231
+ .map((name) => `export type ${name}Scalar = Scalars["${name}"]["output"]`)
232
+ .join("\n"),
230
233
  plugins: {
231
234
  typescript: [typescriptPlugin, {}],
232
235
  typescriptOperations: [typescriptOperationsPlugin, {}],
@@ -342,6 +345,44 @@ export class GraphQLGenerator {
342
345
  * Use all rules, except for No Unused Fragments — since we prepend those fragments to every test
343
346
  */
344
347
  const validationRules = specifiedRules.filter((rule) => rule !== NoUnusedFragmentsRule);
348
+ /**
349
+ * Get all the base fragment definitions
350
+ */
351
+ const baseFragments = new Map();
352
+ Object.values(graphQLFiles.fragments)
353
+ .map((file) => file?.ast?.definitions ?? [])
354
+ .filter((def) => def.length > 0)
355
+ .flat()
356
+ .filter((n) => n.kind === Kind.FRAGMENT_DEFINITION)
357
+ .forEach((node) => baseFragments.set(node.name.value, node));
358
+ function findFragments(defs, map = new Map()) {
359
+ for (let def of defs) {
360
+ if (def.kind === Kind.FRAGMENT_DEFINITION) {
361
+ map.set(def.name.value, def);
362
+ }
363
+ }
364
+ for (let def of defs) {
365
+ visit(def, {
366
+ FragmentSpread: {
367
+ enter: (node) => {
368
+ const match = baseFragments.get(node.name.value);
369
+ if (match && !map.has(node.name.value)) {
370
+ map.set(node.name.value, match);
371
+ findFragments([match], map);
372
+ }
373
+ },
374
+ },
375
+ });
376
+ }
377
+ return {
378
+ fragments: [...map.values()],
379
+ definitions: defs.filter((n) => n.kind !== Kind.FRAGMENT_DEFINITION),
380
+ };
381
+ }
382
+ /**
383
+ * Only report the same error once (mostly for preventing repeats of the same fragment errors)
384
+ */
385
+ const errorsShown = new Map();
345
386
  /**
346
387
  * Validate everything
347
388
  */
@@ -353,19 +394,25 @@ export class GraphQLGenerator {
353
394
  }
354
395
  else {
355
396
  // Find all fragments
356
- const fragments = Object.values(graphQLFiles.fragments)
357
- .map((file) => file.ast.definitions)
358
- .filter((def) => def.length > 0)
359
- .filter((def) => def !== file.ast.definitions)
360
- .flat();
397
+ const { fragments, definitions } = findFragments(file?.ast?.definitions ?? []);
361
398
  const validationAST = {
362
399
  kind: Kind.DOCUMENT,
363
- definitions: [...fragments, ...file.ast.definitions],
400
+ definitions: [...fragments, ...definitions],
364
401
  loc: file.ast.loc,
365
402
  };
366
403
  const errors = validate(schema, validationAST, validationRules);
367
404
  if (errors.length > 0) {
368
405
  for (let error of errors) {
406
+ if (error.nodes && error.nodes[0]) {
407
+ const node = error.nodes[0];
408
+ if (errorsShown.has(node) && errorsShown.get(node)?.includes(error.message)) {
409
+ continue;
410
+ }
411
+ else {
412
+ errorsShown.set(node, [...(errorsShown.get(node) ?? []), error.message]);
413
+ }
414
+ }
415
+ // console.log(error.nodes?.map((n) => n.kind))
369
416
  report.push(new GraphQLValidationError(error.message, path, error.locations?.[0].line || 1, error.locations?.[0].column || 1, error.source?.body || ""));
370
417
  }
371
418
  }
@@ -400,7 +447,7 @@ export class GraphQLGenerator {
400
447
  errors.push(String(err));
401
448
  }
402
449
  if (args.banner) {
403
- output = args.banner + "\n\n" + output;
450
+ output = args.banner + "\n\n" + output + "\n" + (args.footer ?? "");
404
451
  }
405
452
  if (errors.length === 0) {
406
453
  const didWrite = await fs.writeIfUnchanged(config.filename, output);
@@ -1,8 +1,6 @@
1
1
  import { loadSchema } from "@graphql-tools/load";
2
2
  import { UrlLoader } from "@graphql-tools/url-loader";
3
3
  import { introspectionFromSchema } from "graphql";
4
- import { Agent } from "https";
5
- import fetch from "node-fetch";
6
4
  import { graphqlLog as console } from "./graphql-codegen.js";
7
5
  import chalk from "chalk";
8
6
  import { hash } from "object-code";
@@ -23,22 +21,21 @@ export class GraphQLSchemaLoader {
23
21
  console.info(`${this.lastHash ? "Reloading" : "Loading"} GraphQL schema from ${chalk.yellowBright(this.url)}`);
24
22
  const rawSchema = await loadSchema(this.url, {
25
23
  loaders: [new UrlLoader()],
26
- fetch: (url, opts) => {
27
- const httpsAgent = new Agent({
28
- rejectUnauthorized: false,
29
- });
30
- return fetch(url, {
31
- ...opts,
32
- agent: function (_parsedURL) {
33
- if (_parsedURL.protocol == "http:") {
34
- return undefined;
35
- }
36
- else {
37
- return httpsAgent;
38
- }
39
- },
40
- });
41
- },
24
+ // fetch: (url: string, opts: any) => {
25
+ // const httpsAgent = new Agent({
26
+ // rejectUnauthorized: false,
27
+ // })
28
+ // return fetch(url, {
29
+ // ...opts,
30
+ // agent: function (_parsedURL) {
31
+ // if (_parsedURL.protocol == "http:") {
32
+ // return undefined
33
+ // } else {
34
+ // return httpsAgent
35
+ // }
36
+ // },
37
+ // })
38
+ // },
42
39
  }).catch((e) => {
43
40
  return e;
44
41
  });
@@ -4,7 +4,7 @@ import { z } from "zod";
4
4
  import { zodToJsonSchema } from "zod-to-json-schema";
5
5
  import { cliMode } from "../cli/cli-mode.js";
6
6
  import { fs } from "../utils/fs.js";
7
- import { isDeploying } from "../utils/isDeploying.js";
7
+ import { isDeploying } from "../utils/is-deploying.js";
8
8
  import { projectLog as console } from "./project.js";
9
9
  export const EDConfigSchema = z.object({
10
10
  $schema: z.string().optional(),
@@ -35,5 +35,5 @@ export declare const ProjectEnvUtils: {
35
35
  valid: false;
36
36
  };
37
37
  getSafe<T extends ProjectEnvKey>(key: T): Required<ProjectEnvMap[T]> | undefined;
38
- get<T extends ProjectEnvKey>(key: T, cons?: import("../utils/statefulLog.js").StatefulLog<import("./project.js").Project>): z.infer<(typeof fields)[T]>;
38
+ get<T extends ProjectEnvKey>(key: T, cons?: import("../utils/stateful-log.js").StatefulLog<import("./project.js").Project>): z.infer<(typeof fields)[T]>;
39
39
  };
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { cliMode } from "../cli/cli-mode.js";
3
3
  import { projectLog as console } from "./project.js";
4
- import { formatZodError } from "../utils/formatZodError.js";
4
+ import { formatZodError } from "../utils/format-zod-error.js";
5
5
  const portNumber = z
6
6
  .string()
7
7
  .default("0")