eddev 2.3.31 → 2.4.0-beta.2
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.
- package/dist/app/entry/ssr-root-client.d.ts +0 -2
- package/dist/app/entry/ssr-root-client.d.ts.map +1 -1
- package/dist/app/lib/blocks/block-debugger.d.ts.map +1 -1
- package/dist/app/lib/blocks/block-debugger.js +19 -2
- package/dist/app/lib/devtools/components/panels/StructurePanel.js +1 -1
- package/dist/app/server/assets.d.ts +45 -0
- package/dist/app/server/assets.d.ts.map +1 -0
- package/dist/app/server/assets.js +15 -0
- package/dist/app/server/index.d.ts +4 -0
- package/dist/app/server/index.d.ts.map +1 -1
- package/dist/app/server/index.js +3 -0
- package/dist/app/server/proxy-wp-admin.d.ts +6 -2
- package/dist/app/server/proxy-wp-admin.d.ts.map +1 -1
- package/dist/app/server/proxy-wp-admin.js +29 -57
- package/dist/app/server/render-ssr-page.d.ts +2 -6
- package/dist/app/server/render-ssr-page.d.ts.map +1 -1
- package/dist/app/server/render-ssr-page.js +9 -8
- package/dist/app/server/rpc-handler.d.ts +14 -0
- package/dist/app/server/rpc-handler.d.ts.map +1 -0
- package/dist/app/server/rpc-handler.js +63 -0
- package/dist/app/server/server-app.d.ts +22 -0
- package/dist/app/server/server-app.d.ts.map +1 -0
- package/dist/app/server/server-app.js +186 -0
- package/dist/app/server/server-context.d.ts +5 -5
- package/dist/app/server/server-context.d.ts.map +1 -1
- package/dist/app/server/server-context.js +21 -13
- package/dist/app/server/utils/fetch-origin.d.ts +13 -0
- package/dist/app/server/utils/fetch-origin.d.ts.map +1 -0
- package/dist/app/server/utils/fetch-origin.js +21 -0
- package/dist/app/server/utils/request.d.ts +20 -0
- package/dist/app/server/utils/request.d.ts.map +1 -0
- package/dist/app/server/utils/request.js +60 -0
- package/dist/node/cli/cli-worker.d.ts +10 -6
- package/dist/node/cli/cli-worker.d.ts.map +1 -1
- package/dist/node/cli/cli-worker.js +7 -14
- package/dist/node/cli/cli.js +37 -43
- package/dist/node/cli/display/CLIApp.d.ts +2 -4
- package/dist/node/cli/display/CLIApp.d.ts.map +1 -1
- package/dist/node/cli/display/CLIApp.js +2 -3
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.d.ts.map +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/app-codegen.d.ts +18 -0
- package/dist/node/compiler/app-codegen.d.ts.map +1 -0
- package/dist/node/compiler/app-codegen.js +473 -0
- package/dist/node/compiler/build-serverless.d.ts +16 -0
- package/dist/node/compiler/build-serverless.d.ts.map +1 -0
- package/dist/node/compiler/build-serverless.js +40 -0
- package/dist/node/compiler/bundler.spa.d.ts +33 -0
- package/dist/node/compiler/bundler.spa.d.ts.map +1 -0
- package/dist/node/compiler/bundler.spa.js +59 -0
- package/dist/node/compiler/dev-css-links.d.ts +25 -0
- package/dist/node/compiler/dev-css-links.d.ts.map +1 -0
- package/dist/node/compiler/dev-css-links.js +87 -0
- package/dist/node/compiler/dev-server.d.ts +2 -0
- package/dist/node/compiler/dev-server.d.ts.map +1 -1
- package/dist/node/compiler/dev-server.js +43 -75
- package/dist/node/compiler/get-vite-config.d.ts +37 -6
- package/dist/node/compiler/get-vite-config.d.ts.map +1 -1
- package/dist/node/compiler/get-vite-config.js +113 -121
- package/dist/node/compiler/serverless-app.d.ts +35 -0
- package/dist/node/compiler/serverless-app.d.ts.map +1 -0
- package/dist/node/compiler/serverless-app.js +332 -0
- package/dist/node/compiler/transforms/block-meta.d.ts +10 -0
- package/dist/node/compiler/transforms/block-meta.d.ts.map +1 -0
- package/dist/node/compiler/transforms/block-meta.js +27 -0
- package/dist/node/compiler/transforms/component-names.d.ts +19 -0
- package/dist/node/compiler/transforms/component-names.d.ts.map +1 -0
- package/dist/node/compiler/transforms/component-names.js +45 -0
- package/dist/node/compiler/transforms/index.d.ts +36 -0
- package/dist/node/compiler/transforms/index.d.ts.map +1 -0
- package/dist/node/compiler/transforms/index.js +80 -0
- package/dist/node/compiler/transforms/types.d.ts +48 -0
- package/dist/node/compiler/transforms/types.d.ts.map +1 -0
- package/dist/node/compiler/transforms/types.js +1 -0
- package/dist/node/project/config.d.ts +1 -1
- package/dist/node/project/config.d.ts.map +1 -1
- package/dist/node/project/config.js +1 -1
- package/dist/node/project/env.js +1 -1
- package/dist/node/project/project-log.d.ts +7 -0
- package/dist/node/project/project-log.d.ts.map +1 -0
- package/dist/node/project/project-log.js +6 -0
- package/dist/node/project/project.d.ts +2 -2
- package/dist/node/project/project.d.ts.map +1 -1
- package/dist/node/project/project.js +3 -3
- package/dist/node/utils/fs.d.ts +70 -69
- package/dist/node/utils/fs.d.ts.map +1 -1
- package/package.json +12 -13
- package/skills/eddev/docs/devtool/cli.mdx +10 -8
- package/tsconfig.node.json +17 -5
- package/types.env.d.ts +1 -1
- package/dist/node/compiler/build-vinxi.d.ts +0 -9
- package/dist/node/compiler/build-vinxi.d.ts.map +0 -1
- package/dist/node/compiler/build-vinxi.js +0 -39
- package/dist/node/compiler/bundler.admin.d.ts +0 -14
- package/dist/node/compiler/bundler.admin.d.ts.map +0 -1
- package/dist/node/compiler/bundler.admin.js +0 -37
- package/dist/node/compiler/bundler.frontend.d.ts +0 -15
- package/dist/node/compiler/bundler.frontend.d.ts.map +0 -1
- package/dist/node/compiler/bundler.frontend.js +0 -51
- package/dist/node/compiler/vinxi-app.d.ts +0 -23
- package/dist/node/compiler/vinxi-app.d.ts.map +0 -1
- package/dist/node/compiler/vinxi-app.js +0 -261
- package/dist/node/compiler/vinxi-codegen.d.ts +0 -13
- package/dist/node/compiler/vinxi-codegen.d.ts.map +0 -1
- package/dist/node/compiler/vinxi-codegen.js +0 -764
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import react from "@vitejs/plugin-react";
|
|
2
|
+
import { camelCase, pascalCase } from "change-case-all";
|
|
3
|
+
import { code, imp } from "ts-poet";
|
|
4
|
+
import { ProjectEnvUtils } from "../project/env.js";
|
|
5
|
+
import { FSCodegen } from "../utils/fs-codegen.js";
|
|
6
|
+
import { getCacheConfig } from "./cache-config.js";
|
|
7
|
+
/** The generated entry folder, relative to `.eddev`: `dev`, `prod`, `dev-spa` or `prod-spa`. */
|
|
8
|
+
export function getAppFolder(opts) {
|
|
9
|
+
return (opts.mode === "development" ? "dev" : "prod") + (opts.serverless ? "" : "-spa");
|
|
10
|
+
}
|
|
11
|
+
export async function runAppCodegen(opts) {
|
|
12
|
+
const codegen = createAppCodegen(opts);
|
|
13
|
+
await codegen.run();
|
|
14
|
+
codegen.stop();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generates the entry points and manifests in `.eddev/<folder>`, which the bundlers compile.
|
|
18
|
+
* SPA mode gets client + admin entries; serverless mode additionally gets the server entry.
|
|
19
|
+
*/
|
|
20
|
+
export function createAppCodegen(opts) {
|
|
21
|
+
const project = opts.project;
|
|
22
|
+
const folder = ".eddev/" + getAppFolder(opts);
|
|
23
|
+
const codegen = new FSCodegen(opts.project, {
|
|
24
|
+
outDir: folder,
|
|
25
|
+
});
|
|
26
|
+
if (opts.serverless) {
|
|
27
|
+
codegen.registerFile({
|
|
28
|
+
name: "context.ts",
|
|
29
|
+
generate: async () => {
|
|
30
|
+
const args = {
|
|
31
|
+
dev: opts.mode === "development",
|
|
32
|
+
origin: project.origin,
|
|
33
|
+
replaceUrls: {
|
|
34
|
+
from: project.origin,
|
|
35
|
+
to: opts.endpoint ?? "",
|
|
36
|
+
prefixes: [
|
|
37
|
+
{ prefix: "/wp-content/uploads", replace: project.config?.serverless.uploads === "remote" },
|
|
38
|
+
{ prefix: "/wp-content/plugins", replace: project.config?.serverless.plugins === "remote" },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
rpcBases: (await project.serverRoutes.get()).bases ?? [],
|
|
42
|
+
config: project.config,
|
|
43
|
+
cacheConfig: getCacheConfig(project.origin, project.config),
|
|
44
|
+
};
|
|
45
|
+
return code /* tsx */ `
|
|
46
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
47
|
+
import { ServerContext } from "eddev/server"
|
|
48
|
+
import { apiConfig } from 'eddev/hooks'
|
|
49
|
+
|
|
50
|
+
export const serverContext = new ServerContext({${Object.entries(args)
|
|
51
|
+
.map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
|
|
52
|
+
.join(",\n")}
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
apiConfig.apiKey = ${JSON.stringify(ProjectEnvUtils.getSafe("SITE_API_KEY") ?? "")}
|
|
56
|
+
`.toString();
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (opts.serverless) {
|
|
61
|
+
codegen.registerFile({
|
|
62
|
+
name: "react-shim.js",
|
|
63
|
+
generate: code /* tsx */ `
|
|
64
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
65
|
+
import React from "react"
|
|
66
|
+
import ReactDOM from "react-dom/client"
|
|
67
|
+
Object.assign(React, window.React)
|
|
68
|
+
Object.assign(ReactDOM, window.ReactDOM)
|
|
69
|
+
`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
codegen.registerFile({
|
|
73
|
+
name: "entry.admin.tsx",
|
|
74
|
+
generate: () => {
|
|
75
|
+
return code /* tsx */ `
|
|
76
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
77
|
+
${opts.serverless ? `import "./react-shim.js"` : ""}
|
|
78
|
+
import "../../${project.cssEntryFile}"
|
|
79
|
+
import "./manifest/admin"
|
|
80
|
+
import "./manifest/blocks"
|
|
81
|
+
import "./manifest/styles"
|
|
82
|
+
import bootAdmin from "eddev/_internal/boot-admin.js"
|
|
83
|
+
|
|
84
|
+
bootAdmin()
|
|
85
|
+
|
|
86
|
+
if (import.meta.hot) {
|
|
87
|
+
import.meta.hot.on('vite:beforeFullReload', () => {
|
|
88
|
+
throw '(skipping full reload in editor)';
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
`;
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
codegen.registerFile({
|
|
96
|
+
name: "entry.client.tsx",
|
|
97
|
+
generate: () => {
|
|
98
|
+
if (opts.serverless) {
|
|
99
|
+
/**
|
|
100
|
+
* Client entry for SSR mode
|
|
101
|
+
*/
|
|
102
|
+
return code /* tsx */ `
|
|
103
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
104
|
+
/**
|
|
105
|
+
* SSR-mode frontend entry.
|
|
106
|
+
* Hydrates the main app, including the html/head/body elements.
|
|
107
|
+
* The server renders the stylesheet and preload tags this entry needs.
|
|
108
|
+
*/
|
|
109
|
+
import "@vitejs/plugin-react/preamble"
|
|
110
|
+
import "../../${project.cssEntryFile}"
|
|
111
|
+
import "./manifest/blocks"
|
|
112
|
+
import "./manifest/views"
|
|
113
|
+
|
|
114
|
+
import * as React from "react"
|
|
115
|
+
import { Root, hydrateRoot } from "react-dom/client"
|
|
116
|
+
import { SSRClientRoot } from "eddev/_internal/ssr-root-client.js"
|
|
117
|
+
import { devToolsStore } from 'eddev/devtools'
|
|
118
|
+
|
|
119
|
+
${process.env.VERCEL_SKEW_PROTECTION_ENABLED &&
|
|
120
|
+
code /* tsx*/ `
|
|
121
|
+
// Skew protection
|
|
122
|
+
const updateSkewCookie = () => {
|
|
123
|
+
document.cookie = "__vdpl=${process.env.VERCEL_DEPLOYMENT_ID}; expires=" + new Date(Date.now() + 24 * 60 * 60 * 1000).toUTCString() + "; path=/"
|
|
124
|
+
}
|
|
125
|
+
window.onfocus = updateSkewCookie
|
|
126
|
+
updateSkewCookie()
|
|
127
|
+
`}
|
|
128
|
+
|
|
129
|
+
// Set up a dynamic entry which will load the configured tailwind manifest
|
|
130
|
+
devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config.js')
|
|
131
|
+
|
|
132
|
+
window.$reactRoot =
|
|
133
|
+
window.$reactRoot ||
|
|
134
|
+
hydrateRoot(
|
|
135
|
+
document.getElementById('root')!,
|
|
136
|
+
<React.Suspense><SSRClientRoot metaTags={window._PAGE_DATA?.meta?.head} /></React.Suspense>,
|
|
137
|
+
{
|
|
138
|
+
identifierPrefix: "ed",
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
if (import.meta.hot) {
|
|
143
|
+
import.meta.hot.accept((mod) => {
|
|
144
|
+
if (mod) {
|
|
145
|
+
const app = <React.Suspense><SSRClientRoot metaTags={window._PAGE_DATA?.meta?.head} /></React.Suspense>
|
|
146
|
+
window.$reactRoot?.render(app)
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
declare global {
|
|
152
|
+
interface Window {
|
|
153
|
+
$reactRoot?: Root
|
|
154
|
+
_PAGE_DATA: any
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
return code /* tsx */ `
|
|
162
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
163
|
+
/**
|
|
164
|
+
* SPA-mode frontend entry.
|
|
165
|
+
* Renders the main app into the empty <div id='root'> element, and expects window._PAGE_DATA to be set.
|
|
166
|
+
*/
|
|
167
|
+
import "./manifest/blocks"
|
|
168
|
+
import "./manifest/views"
|
|
169
|
+
import "../../${project.cssEntryFile}"
|
|
170
|
+
import { devToolsStore } from 'eddev/devtools'
|
|
171
|
+
import { createRoot } from "react-dom/client"
|
|
172
|
+
import { SPARoot } from "eddev/_internal/spa-root.js"
|
|
173
|
+
import * as React from "react"
|
|
174
|
+
|
|
175
|
+
devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config')
|
|
176
|
+
|
|
177
|
+
createRoot(document.getElementById("root")!).render(<React.Suspense><SPARoot /></React.Suspense>)
|
|
178
|
+
`;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
if (opts.serverless) {
|
|
183
|
+
codegen.registerFile({
|
|
184
|
+
name: "entry.server.ts",
|
|
185
|
+
generate: () => {
|
|
186
|
+
const skewProtection = process.env.VERCEL_SKEW_PROTECTION_ENABLED
|
|
187
|
+
? { deploymentId: process.env.VERCEL_DEPLOYMENT_ID ?? "" }
|
|
188
|
+
: undefined;
|
|
189
|
+
return code /* tsx */ `
|
|
190
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
191
|
+
/**
|
|
192
|
+
* Serverless entry. Nitro forwards every request that isn't a static asset or route rule here.
|
|
193
|
+
*/
|
|
194
|
+
import "../../${project.cssEntryFile}"
|
|
195
|
+
import "./manifest/blocks.js"
|
|
196
|
+
import "./manifest/styles.js"
|
|
197
|
+
import "./manifest/views.js"
|
|
198
|
+
import "./context.js"
|
|
199
|
+
import { createServerApp } from "eddev/server"
|
|
200
|
+
import { router, createContext } from "./manifest/routes.js"
|
|
201
|
+
import { assets } from "./manifest/assets.js"
|
|
202
|
+
|
|
203
|
+
export default createServerApp({
|
|
204
|
+
rpc: { router, createContext },
|
|
205
|
+
assets,
|
|
206
|
+
skewProtection: ${JSON.stringify(skewProtection)},
|
|
207
|
+
})
|
|
208
|
+
`;
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
codegen.registerFile({
|
|
212
|
+
name: "manifest/assets.ts",
|
|
213
|
+
generate: async () => {
|
|
214
|
+
const [viewManifest, blockManifest] = await Promise.all([project.views.get(), project.blocks.get()]);
|
|
215
|
+
const dev = opts.mode === "development";
|
|
216
|
+
// Every module passed to dynamic() in manifest/views.ts and manifest/blocks.ts
|
|
217
|
+
const dynamicFiles = [
|
|
218
|
+
...Object.entries(viewManifest.views)
|
|
219
|
+
.filter(([name]) => !name.startsWith("_"))
|
|
220
|
+
.map(([, view]) => view.fileName),
|
|
221
|
+
...Object.entries(blockManifest.blocks)
|
|
222
|
+
.filter(([name, block]) => !name.match(/^_[a-z]+$/i) && block.dynamic)
|
|
223
|
+
.map(([, block]) => block.fileName),
|
|
224
|
+
];
|
|
225
|
+
// In production, client chunks carry everything (CSS included). In dev, client entries only
|
|
226
|
+
// provide the script URL, and CSS is collected from the server module graph.
|
|
227
|
+
const moduleAssets = (fileName) => dev
|
|
228
|
+
? `import.meta.vite.assets({ import: ${JSON.stringify("../../../" + fileName)} })`
|
|
229
|
+
: `import.meta.vite.assets({ import: ${JSON.stringify("../../../" + fileName)}, environment: "client" })`;
|
|
230
|
+
const reactPreamble = react.preambleCode.replace("__BASE__", "/_admin/");
|
|
231
|
+
return code /* ts */ `
|
|
232
|
+
// @ts-nocheck — uses Nitro's \`?assets\` imports
|
|
233
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
234
|
+
import type { ServerAssets } from "eddev/server"
|
|
235
|
+
import clientEntry from "../entry.client.tsx?assets=client"
|
|
236
|
+
${dev ? `import serverEntry from "../entry.server.ts?assets=ssr"` : ""}
|
|
237
|
+
|
|
238
|
+
export const assets: ServerAssets = {
|
|
239
|
+
client: ${dev ? "clientEntry.merge(serverEntry)" : "clientEntry"} as ServerAssets["client"],
|
|
240
|
+
admin: ${dev
|
|
241
|
+
? `{
|
|
242
|
+
// Served by a separate Vite dev server mounted at /_admin/
|
|
243
|
+
entry: "/_admin/${folder}/entry.admin.tsx",
|
|
244
|
+
js: [],
|
|
245
|
+
css: [],
|
|
246
|
+
head: [
|
|
247
|
+
'<script type="module" src="/_admin/@vite/client"></script>',
|
|
248
|
+
${JSON.stringify(`<script type="module">${reactPreamble}</script>`)},
|
|
249
|
+
],
|
|
250
|
+
// Provided by the admin dev server (see serverless-app.ts)
|
|
251
|
+
devStylesheets: () => globalThis.__EDDEV_ADMIN_DEV_STYLESHEETS__?.() ?? [],
|
|
252
|
+
}`
|
|
253
|
+
: `{
|
|
254
|
+
...import.meta.vite.assets({ import: "../entry.admin.tsx", environment: "admin" }),
|
|
255
|
+
entry: "/_admin/entry.admin.js",
|
|
256
|
+
}`},
|
|
257
|
+
modules: {
|
|
258
|
+
${dynamicFiles.map((fileName) => `${JSON.stringify(fileName)}: ${moduleAssets(fileName)},`).join("\n")}
|
|
259
|
+
},
|
|
260
|
+
}
|
|
261
|
+
`;
|
|
262
|
+
},
|
|
263
|
+
subscribe: (callback) => {
|
|
264
|
+
const unsub = [project.views.subscribe(callback), project.blocks.subscribe(callback)];
|
|
265
|
+
return () => unsub.forEach((u) => u());
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
codegen.registerFile({
|
|
270
|
+
name: "manifest/blocks.ts",
|
|
271
|
+
generate: async () => {
|
|
272
|
+
const blockManifest = await project.blocks.get();
|
|
273
|
+
let blockImports = [];
|
|
274
|
+
let blockEntries = [];
|
|
275
|
+
for (const [name, block] of Object.entries(blockManifest.blocks)) {
|
|
276
|
+
if (name.match(/^_[a-z]+$/i))
|
|
277
|
+
continue;
|
|
278
|
+
const importSource = JSON.stringify("../../../" + block.fileName);
|
|
279
|
+
const jsName = pascalCase(name);
|
|
280
|
+
if (block.dynamic) {
|
|
281
|
+
const importStatement = `dynamic(() => import(${importSource}), ${JSON.stringify(block.fileName)})`;
|
|
282
|
+
blockEntries.push(JSON.stringify(block.acfName) + ": " + importStatement);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
blockImports.push(`import ${jsName} from ${importSource}`);
|
|
286
|
+
blockEntries.push(JSON.stringify(block.acfName) + ": " + jsName);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return code /* ts */ `
|
|
290
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
291
|
+
import { blockManifestReader } from 'eddev/_internal'
|
|
292
|
+
import { dynamic } from 'eddev/dynamic'
|
|
293
|
+
import core from '../../../blocks/_core'
|
|
294
|
+
${blockImports.join("\n")}
|
|
295
|
+
|
|
296
|
+
const manifest = {
|
|
297
|
+
${blockEntries.join(",\n")},
|
|
298
|
+
...core
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const info = {
|
|
302
|
+
${Object.entries(blockManifest.blocks)
|
|
303
|
+
.filter(([name]) => !name.match(/^_[a-z]+$/i))
|
|
304
|
+
.map(([name, block]) => {
|
|
305
|
+
return (JSON.stringify(block.acfName) +
|
|
306
|
+
": " +
|
|
307
|
+
JSON.stringify({
|
|
308
|
+
slug: block.slug,
|
|
309
|
+
tags: block.tags,
|
|
310
|
+
flags: block.flags ?? {},
|
|
311
|
+
}));
|
|
312
|
+
})
|
|
313
|
+
.join(",\n")}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
blockManifestReader.set(manifest, info)
|
|
317
|
+
|
|
318
|
+
export default manifest
|
|
319
|
+
|
|
320
|
+
if (import.meta.hot) {
|
|
321
|
+
import.meta.hot.accept()
|
|
322
|
+
}
|
|
323
|
+
`;
|
|
324
|
+
},
|
|
325
|
+
subscribe: project.blocks.subscribe,
|
|
326
|
+
});
|
|
327
|
+
codegen.registerFile({
|
|
328
|
+
name: "manifest/admin.ts",
|
|
329
|
+
generate: async () => {
|
|
330
|
+
const fieldManifest = await project.fields.get();
|
|
331
|
+
const widgetManifest = await project.widgets.get();
|
|
332
|
+
const blockManifest = await project.blocks.get();
|
|
333
|
+
return code /* ts */ `
|
|
334
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
335
|
+
import { adminManifestReader } from 'eddev/_internal'
|
|
336
|
+
import editorConfig from '../../../blocks/_editor'
|
|
337
|
+
|
|
338
|
+
const fields = {${Object.entries(fieldManifest.fields)
|
|
339
|
+
.map(([name, field]) => {
|
|
340
|
+
const importStatement = `() => import(${JSON.stringify("../../../" + field.fileName)}).then(m => m.default)`;
|
|
341
|
+
return JSON.stringify(field.slug) + ": " + importStatement;
|
|
342
|
+
})
|
|
343
|
+
.join(",\n")}}
|
|
344
|
+
const widgets = {${Object.entries(widgetManifest.widgets)
|
|
345
|
+
.map(([name, widget]) => {
|
|
346
|
+
const importStatement = `() => import(${JSON.stringify("../../../" + widget.fileName)}).then(m => m.default)`;
|
|
347
|
+
return JSON.stringify(widget.slug) + ": " + importStatement;
|
|
348
|
+
})
|
|
349
|
+
.join(",\n")}}
|
|
350
|
+
|
|
351
|
+
const blockTemplateParts = {${Object.entries(blockManifest.templateParts)
|
|
352
|
+
.map(([name, part]) => {
|
|
353
|
+
return JSON.stringify(name) + ": " + JSON.stringify(part);
|
|
354
|
+
})
|
|
355
|
+
.join(",\n")}}
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
const manifest = {
|
|
359
|
+
fields,
|
|
360
|
+
widgets,
|
|
361
|
+
editorConfig,
|
|
362
|
+
blockTemplateParts
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
adminManifestReader.set(manifest)
|
|
366
|
+
|
|
367
|
+
export default manifest
|
|
368
|
+
|
|
369
|
+
export { editorConfig }
|
|
370
|
+
|
|
371
|
+
if (import.meta.hot) {
|
|
372
|
+
import.meta.hot.accept()
|
|
373
|
+
}
|
|
374
|
+
`;
|
|
375
|
+
},
|
|
376
|
+
subscribe: (callback) => {
|
|
377
|
+
const unsub = [
|
|
378
|
+
project.fields.subscribe(callback),
|
|
379
|
+
project.widgets.subscribe(callback),
|
|
380
|
+
project.blocks.subscribe(callback),
|
|
381
|
+
];
|
|
382
|
+
return () => unsub.forEach((u) => u());
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
codegen.registerFile({
|
|
386
|
+
name: "manifest/views.ts",
|
|
387
|
+
generate: async () => {
|
|
388
|
+
const viewManifest = await project.views.get();
|
|
389
|
+
return code /* ts */ `
|
|
390
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
391
|
+
import { viewManifestReader } from 'eddev/_internal'
|
|
392
|
+
import { dynamic } from 'eddev/dynamic'
|
|
393
|
+
const manifest = {${Object.entries(viewManifest.views).map(([name, view]) => {
|
|
394
|
+
const src = "../../../" + view.fileName;
|
|
395
|
+
let importStatement;
|
|
396
|
+
if (name.startsWith("_")) {
|
|
397
|
+
importStatement = imp(name + "=" + src);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
importStatement = code `dynamic(() => import(${JSON.stringify(src)}), ${JSON.stringify(view.fileName)})`;
|
|
401
|
+
}
|
|
402
|
+
return code `${JSON.stringify(view.slug)}: ${importStatement},\n`;
|
|
403
|
+
})}}
|
|
404
|
+
|
|
405
|
+
viewManifestReader.set(manifest)
|
|
406
|
+
|
|
407
|
+
export default manifest
|
|
408
|
+
|
|
409
|
+
if (import.meta.hot) {
|
|
410
|
+
import.meta.hot.accept()
|
|
411
|
+
}
|
|
412
|
+
`;
|
|
413
|
+
},
|
|
414
|
+
subscribe: project.views.subscribe,
|
|
415
|
+
});
|
|
416
|
+
codegen.registerFile({
|
|
417
|
+
name: "manifest/styles.ts",
|
|
418
|
+
generate: async () => {
|
|
419
|
+
return code /* ts */ `
|
|
420
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
421
|
+
export const getCssText = undefined
|
|
422
|
+
export const editorGlobalStyles = () => {}
|
|
423
|
+
`;
|
|
424
|
+
},
|
|
425
|
+
});
|
|
426
|
+
codegen.registerFile({
|
|
427
|
+
name: "manifest/tailwind-config.ts",
|
|
428
|
+
generate: async () => {
|
|
429
|
+
return code /* ts */ `
|
|
430
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
431
|
+
import tw from "../../../tailwind.config.ts"
|
|
432
|
+
import resolveConfig from 'tailwindcss/resolveConfig'
|
|
433
|
+
import { devToolsStore } from 'eddev/devtools'
|
|
434
|
+
|
|
435
|
+
const value = resolveConfig(tw)
|
|
436
|
+
devToolsStore.tailwindConfig = value
|
|
437
|
+
|
|
438
|
+
if (import.meta.hot) {
|
|
439
|
+
import.meta.hot.accept()
|
|
440
|
+
}
|
|
441
|
+
`;
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
if (opts.serverless) {
|
|
445
|
+
codegen.registerFile({
|
|
446
|
+
name: "manifest/routes.ts",
|
|
447
|
+
generate: async () => {
|
|
448
|
+
const routeManifest = await project.serverRoutes.get();
|
|
449
|
+
return code /* ts */ `
|
|
450
|
+
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
451
|
+
import { instantiateRouter } from "eddev/server"
|
|
452
|
+
${routeManifest.contextFileName
|
|
453
|
+
? code /*ts*/ `
|
|
454
|
+
import createContext from "../../../${routeManifest.contextFileName}"
|
|
455
|
+
`
|
|
456
|
+
: code /*ts*/ `
|
|
457
|
+
const createContext = () => ({})
|
|
458
|
+
`}
|
|
459
|
+
|
|
460
|
+
const router = instantiateRouter({${Object.entries(routeManifest.routes).map(([name, route]) => {
|
|
461
|
+
const src = "../../../" + route.fileName;
|
|
462
|
+
const importStatement = imp(camelCase(name) + "=" + src);
|
|
463
|
+
return code `${JSON.stringify(route.prefix)}: ${importStatement},\n`;
|
|
464
|
+
})}})
|
|
465
|
+
|
|
466
|
+
export { createContext, router }
|
|
467
|
+
`;
|
|
468
|
+
},
|
|
469
|
+
subscribe: project.serverRoutes.subscribe,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
return codegen;
|
|
473
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Project } from "../project/project.js";
|
|
2
|
+
import { StatefulLog } from "../utils/stateful-log.js";
|
|
3
|
+
type Options = {
|
|
4
|
+
project: Project;
|
|
5
|
+
console: StatefulLog<any>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The Nitro preset to build for. Nitro also detects Vercel/Cloudflare itself; these variables are
|
|
9
|
+
* kept for compatibility with earlier eddev versions.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getServerlessPreset(opts: {
|
|
12
|
+
dev: boolean;
|
|
13
|
+
}): string | undefined;
|
|
14
|
+
export declare function buildServerless(opts: Options): Promise<void>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=build-serverless.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-serverless.d.ts","sourceRoot":"","sources":["../../../src/node/compiler/build-serverless.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAItD,KAAK,OAAO,GAAG;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,CAAA;CAC1B,CAAA;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,GAAG,SAAS,CAW9E;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,OAAO,iBA2BlD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createBuilder } from "vite";
|
|
2
|
+
import { createAppCodegen } from "./app-codegen.js";
|
|
3
|
+
import { getServerlessViteConfig } from "./serverless-app.js";
|
|
4
|
+
/**
|
|
5
|
+
* The Nitro preset to build for. Nitro also detects Vercel/Cloudflare itself; these variables are
|
|
6
|
+
* kept for compatibility with earlier eddev versions.
|
|
7
|
+
*/
|
|
8
|
+
export function getServerlessPreset(opts) {
|
|
9
|
+
return (process.env.TARGET ??
|
|
10
|
+
process.env.PRESET ??
|
|
11
|
+
process.env.SERVER_PRESET ??
|
|
12
|
+
process.env.SERVER_TARGET ??
|
|
13
|
+
process.env.NITRO_PRESET ??
|
|
14
|
+
process.env.NITRO_TARGET ??
|
|
15
|
+
(!opts.dev && process.env.VERCEL ? "vercel" : undefined) ??
|
|
16
|
+
(process.versions.bun !== undefined ? "bun" : opts.dev ? undefined : "node-server"));
|
|
17
|
+
}
|
|
18
|
+
export async function buildServerless(opts) {
|
|
19
|
+
const { project, console } = opts;
|
|
20
|
+
const preset = getServerlessPreset({ dev: false });
|
|
21
|
+
console.log("Building serverless app with preset:", preset);
|
|
22
|
+
const codegen = createAppCodegen({
|
|
23
|
+
mode: "production",
|
|
24
|
+
project: project,
|
|
25
|
+
serverless: true,
|
|
26
|
+
});
|
|
27
|
+
await codegen.run();
|
|
28
|
+
codegen.stop();
|
|
29
|
+
const builder = await createBuilder(getServerlessViteConfig({
|
|
30
|
+
mode: "production",
|
|
31
|
+
origin: project.origin,
|
|
32
|
+
publicUrl: project.publicUrl,
|
|
33
|
+
rootDir: project.rootDir,
|
|
34
|
+
rpcBases: (await project.serverRoutes.get()).bases,
|
|
35
|
+
preset,
|
|
36
|
+
config: project.config,
|
|
37
|
+
log: console,
|
|
38
|
+
}));
|
|
39
|
+
await builder.buildApp();
|
|
40
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Project } from "../project/project.js";
|
|
2
|
+
export declare const spaLog: import("../utils/stateful-log.js").StatefulLog<unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* The bundles served by WordPress (SPA mode):
|
|
5
|
+
* - `frontend`: the public site, written to `dist/frontend`
|
|
6
|
+
* - `cms`: the WordPress admin/editor bundle, written to `dist/cms`
|
|
7
|
+
*/
|
|
8
|
+
export type SPATarget = "frontend" | "cms";
|
|
9
|
+
export declare const SPA_TARGETS: SPATarget[];
|
|
10
|
+
type Options = {
|
|
11
|
+
mode: "development" | "production";
|
|
12
|
+
watch?: boolean;
|
|
13
|
+
/** Which bundles to build. Defaults to both. */
|
|
14
|
+
targets?: SPATarget[];
|
|
15
|
+
/** Emit a bundle size report for the frontend bundle, into `dist/frontend-analysis` */
|
|
16
|
+
bundleAnalysis?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Builds the WordPress-hosted SPA bundles concurrently, reporting into a single log.
|
|
20
|
+
*
|
|
21
|
+
* The frontend and cms bundles are separate Vite builds rather than environments of one builder,
|
|
22
|
+
* because they need different `base` URLs (`dist/frontend` vs `dist/cms`), and Vite only supports a
|
|
23
|
+
* single `base` per config. Both builds run in the same process.
|
|
24
|
+
*/
|
|
25
|
+
export declare class SPABundler {
|
|
26
|
+
project: Project;
|
|
27
|
+
opts: Options;
|
|
28
|
+
constructor(project: Project, opts: Options);
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
private getConfig;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=bundler.spa.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler.spa.d.ts","sourceRoot":"","sources":["../../../src/node/compiler/bundler.spa.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAM/C,eAAO,MAAM,MAAM,yDAAU,CAAA;AAE7B;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,KAAK,CAAA;AAE1C,eAAO,MAAM,WAAW,EAAE,SAAS,EAAwB,CAAA;AAO3D,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,aAAa,GAAG,YAAY,CAAA;IAClC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,gDAAgD;IAChD,OAAO,CAAC,EAAE,SAAS,EAAE,CAAA;IACrB,uFAAuF;IACvF,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAED;;;;;;GAMG;AACH,qBAAa,UAAU;IAEZ,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,OAAO;gBADb,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,OAAO;IAGhB,KAAK;IAQX,OAAO,CAAC,SAAS;CA8BlB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { relative } from "path";
|
|
2
|
+
import { visualizer } from "rollup-plugin-visualizer";
|
|
3
|
+
import { build, mergeConfig } from "vite";
|
|
4
|
+
import { createConsole } from "../utils/stateful-log.js";
|
|
5
|
+
import { createBuildStatusTracker, getViteConfig } from "./get-vite-config.js";
|
|
6
|
+
const console = createConsole("SPA Client", "spa");
|
|
7
|
+
export const spaLog = console;
|
|
8
|
+
export const SPA_TARGETS = ["frontend", "cms"];
|
|
9
|
+
const LOG_LABELS = {
|
|
10
|
+
frontend: "frontend",
|
|
11
|
+
cms: "admin",
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Builds the WordPress-hosted SPA bundles concurrently, reporting into a single log.
|
|
15
|
+
*
|
|
16
|
+
* The frontend and cms bundles are separate Vite builds rather than environments of one builder,
|
|
17
|
+
* because they need different `base` URLs (`dist/frontend` vs `dist/cms`), and Vite only supports a
|
|
18
|
+
* single `base` per config. Both builds run in the same process.
|
|
19
|
+
*/
|
|
20
|
+
export class SPABundler {
|
|
21
|
+
project;
|
|
22
|
+
opts;
|
|
23
|
+
constructor(project, opts) {
|
|
24
|
+
this.project = project;
|
|
25
|
+
this.opts = opts;
|
|
26
|
+
}
|
|
27
|
+
async start() {
|
|
28
|
+
const targets = this.opts.targets ?? SPA_TARGETS;
|
|
29
|
+
console.info(`Creating ${this.opts.mode} SPA build (${targets.map((t) => LOG_LABELS[t]).join(", ")})...`);
|
|
30
|
+
const status = createBuildStatusTracker(console);
|
|
31
|
+
await Promise.all(targets.map((target) => build(this.getConfig(target, status))));
|
|
32
|
+
}
|
|
33
|
+
getConfig(target, status) {
|
|
34
|
+
const analyze = target === "frontend" && this.opts.bundleAnalysis;
|
|
35
|
+
const outDir = relative(this.project.rootDir, analyze ? "./dist/frontend-analysis/" : `./dist/${target}/`);
|
|
36
|
+
const baseConfig = getViteConfig({
|
|
37
|
+
console,
|
|
38
|
+
status,
|
|
39
|
+
logLabel: LOG_LABELS[target],
|
|
40
|
+
mode: this.opts.mode,
|
|
41
|
+
publicUrl: this.project.publicUrl,
|
|
42
|
+
rootDir: this.project.rootDir,
|
|
43
|
+
outDir,
|
|
44
|
+
serverless: false,
|
|
45
|
+
target,
|
|
46
|
+
client: true,
|
|
47
|
+
});
|
|
48
|
+
const overrides = {
|
|
49
|
+
build: {
|
|
50
|
+
watch: this.opts.watch ? { buildDelay: 200 } : undefined,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
if (analyze) {
|
|
54
|
+
overrides.plugins = [visualizer({ emitFile: true, filename: "stats.html", template: "sunburst" })];
|
|
55
|
+
}
|
|
56
|
+
console.verbose(`Vite config (${target}):`, baseConfig);
|
|
57
|
+
return mergeConfig(baseConfig, overrides);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type DevEnvironment, type Plugin } from "vite";
|
|
2
|
+
/**
|
|
3
|
+
* Lets stylesheets that are rendered as `<link rel="stylesheet" data-vite-dev-id>` hot reload.
|
|
4
|
+
*
|
|
5
|
+
* A `<link>` request is a separate "direct" CSS module from the copy the JS imports. Marking it as
|
|
6
|
+
* self-accepting makes Vite send a `css-update` when the file (or Tailwind's output) changes, and the
|
|
7
|
+
* client swaps the link's `href`: the new sheet loads before the old one is removed, so there's no flash.
|
|
8
|
+
* The JS-imported copy stays out of the page, because Vite's client skips injecting a `<style>` for an
|
|
9
|
+
* id that a link already owns.
|
|
10
|
+
*
|
|
11
|
+
* This is the same approach Nitro's assets plugin uses for the main dev server's client environment.
|
|
12
|
+
*/
|
|
13
|
+
export declare function cssLinkHmrPlugin(): Plugin;
|
|
14
|
+
export type DevStylesheet = {
|
|
15
|
+
/** The module id, which Vite's client uses as `data-vite-dev-id` */
|
|
16
|
+
id: string;
|
|
17
|
+
/** The module URL, relative to the dev server's base (eg. `/styles/index.css`) */
|
|
18
|
+
url: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Finds every stylesheet imported (statically or dynamically) by an entry, in import order, by
|
|
22
|
+
* transforming the entry's module graph in a dev environment.
|
|
23
|
+
*/
|
|
24
|
+
export declare function collectDevStylesheets(environment: DevEnvironment, entryUrl: string): Promise<DevStylesheet[]>;
|
|
25
|
+
//# sourceMappingURL=dev-css-links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-css-links.d.ts","sourceRoot":"","sources":["../../../src/node/compiler/dev-css-links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,cAAc,EAA8B,KAAK,MAAM,EAAE,MAAM,MAAM,CAAA;AAKjG;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAazC;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,oEAAoE;IACpE,EAAE,EAAE,MAAM,CAAA;IACV,kFAAkF;IAClF,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAwDnH"}
|