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
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
1
|
import { RouteMetaTag } from "../lib/routing/types.js";
|
|
3
2
|
export declare function SSRClientRoot(props: {
|
|
4
|
-
assets: ReactNode;
|
|
5
3
|
metaTags: RouteMetaTag[];
|
|
6
4
|
}): import("react").JSX.Element;
|
|
7
5
|
//# sourceMappingURL=ssr-root-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-root-client.d.ts","sourceRoot":"","sources":["../../../src/app/entry/ssr-root-client.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ssr-root-client.d.ts","sourceRoot":"","sources":["../../../src/app/entry/ssr-root-client.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAKtD,wBAAgB,aAAa,CAAC,KAAK,EAAE;IAAE,QAAQ,EAAE,YAAY,EAAE,CAAA;CAAE,+BAYhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-debugger.d.ts","sourceRoot":"","sources":["../../../../src/app/lib/blocks/block-debugger.tsx"],"names":[],"mappings":"AACA,OAAO,EAA2B,iBAAiB,EAAE,SAAS,EAAyC,MAAM,OAAO,CAAA;AAEpH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,oBAAoB,EAAmB,MAAM,qBAAqB,CAAA;AAG3E,MAAM,MAAM,iBAAiB,GACzB;IACE,IAAI,EAAE,OAAO,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,YAAY,CAAA;IACnB,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAAA;IACzC,QAAQ,EAAE,iBAAiB,EAAE,CAAA;IAC7B,WAAW,CAAC,EAAE,MAAM,WAAW,EAAE,CAAA;IACjC,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAC3B,GACD;IACE,IAAI,EAAE,OAAO,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,UAAU,CAAA;IACjB,QAAQ,EAAE,iBAAiB,EAAE,CAAA;IAC7B,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAC3B,GACD;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,EAAE,EAAE,MAAM,CAAA;IACV,aAAa,EAAE,OAAO,CAAA;IACtB,QAAQ,EAAE,iBAAiB,EAAE,CAAA;IAC7B,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,GACD;IACE,IAAI,EAAE,OAAO,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACzB,UAAU,EAAE;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,IAAI,EAAE,GAAG,EAAE,CAAA;KAAE,EAAE,CAAA;IACzC,QAAQ,EAAE,iBAAiB,EAAE,CAAA;IAC7B,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,WAAW,CAAC,EAAE,MAAM,WAAW,EAAE,CAAA;CAClC,GACD;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,iBAAiB,EAAE,CAAA;CAC9B,CAAA;AAEL,eAAO,MAAM,iBAAiB,mBAI5B,CAAA;AAOF,eAAO,MAAM,iBAAiB,4CAAsD,CAAA;
|
|
1
|
+
{"version":3,"file":"block-debugger.d.ts","sourceRoot":"","sources":["../../../../src/app/lib/blocks/block-debugger.tsx"],"names":[],"mappings":"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"}
|
|
@@ -14,6 +14,18 @@ if (env.client && !env.admin) {
|
|
|
14
14
|
window.pageStructure = pageStructureRoot;
|
|
15
15
|
}
|
|
16
16
|
export const BlockDebugContext = createContext(pageStructureRoot);
|
|
17
|
+
/**
|
|
18
|
+
* Keeps `useId` stable between server rendering and hydration.
|
|
19
|
+
*
|
|
20
|
+
* React folds "this component called useId" (and how many times) into the ids generated for everything
|
|
21
|
+
* rendered below it. The client-only debug paths below call `useId`, directly and through its-fine's
|
|
22
|
+
* `useFiber`, so their server paths must make the same number of calls. Otherwise every `useId` inside a
|
|
23
|
+
* block (eg. Radix's trigger/content ids) differs between the SSR markup and the hydrated page.
|
|
24
|
+
*/
|
|
25
|
+
function useMatchingIdCalls(count) {
|
|
26
|
+
for (let i = 0; i < count; i++)
|
|
27
|
+
useId();
|
|
28
|
+
}
|
|
17
29
|
export function usePageStructureNode(initial) {
|
|
18
30
|
const id = useId();
|
|
19
31
|
if (!env.client || env.admin) {
|
|
@@ -30,6 +42,7 @@ export function usePageStructureNode(initial) {
|
|
|
30
42
|
}
|
|
31
43
|
export function useDebugNode(label, initial) {
|
|
32
44
|
if (!env.client || env.admin) {
|
|
45
|
+
useMatchingIdCalls(2); // useFiber() + useId()
|
|
33
46
|
return {
|
|
34
47
|
log: console.log.bind(console, `[Debug: ${label}]`),
|
|
35
48
|
...initial,
|
|
@@ -67,8 +80,10 @@ export function useDebugNode(label, initial) {
|
|
|
67
80
|
return node.data;
|
|
68
81
|
}
|
|
69
82
|
export function DebugNode(props) {
|
|
70
|
-
if (!env.client || env.admin)
|
|
83
|
+
if (!env.client || env.admin) {
|
|
84
|
+
useMatchingIdCalls(2); // useFiber() + useId()
|
|
71
85
|
return _jsx(Fragment, { children: props.children });
|
|
86
|
+
}
|
|
72
87
|
const fiber = useFiber();
|
|
73
88
|
const parent = useContext(BlockDebugContext);
|
|
74
89
|
const id = useId();
|
|
@@ -136,8 +151,10 @@ function createGetElements(fiber) {
|
|
|
136
151
|
};
|
|
137
152
|
}
|
|
138
153
|
export function BlockDebug(props) {
|
|
139
|
-
if (!env.client || env.admin)
|
|
154
|
+
if (!env.client || env.admin) {
|
|
155
|
+
useMatchingIdCalls(2); // useFiber() + usePageStructureNode()
|
|
140
156
|
return _jsx(Fragment, { children: props.children });
|
|
157
|
+
}
|
|
141
158
|
const fiber = useFiber();
|
|
142
159
|
const blockContext = useBlockContext();
|
|
143
160
|
const node = usePageStructureNode({
|
|
@@ -62,7 +62,7 @@ function StructureNode(props) {
|
|
|
62
62
|
label = _jsxs(_Fragment, { children: [globeIcon, " App"] });
|
|
63
63
|
}
|
|
64
64
|
else if (node.type === "route") {
|
|
65
|
-
label = (_jsxs(_Fragment, { children: [routesIcon, " Route:", " ", _jsxs("em", { children: [node.route.uri, " ", node.route.view ? _jsxs(_Fragment, { children: ["(", node.route.view, ")"] }) : null] })] }));
|
|
65
|
+
label = (_jsxs(_Fragment, { children: [routesIcon, " Route:", " ", _jsxs("em", { className: "line-clamp-1 max-w-[200px]", children: [node.route.uri, " ", node.route.view ? _jsxs(_Fragment, { children: ["(", node.route.view, ")"] }) : null] })] }));
|
|
66
66
|
labelColor = "text-blue-400";
|
|
67
67
|
}
|
|
68
68
|
else if (node.type === "blocks") {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client asset lookups for server rendering.
|
|
3
|
+
*
|
|
4
|
+
* The generated `manifest/assets.ts` (server only) fills this in using the `?assets` imports provided by
|
|
5
|
+
* Nitro's Vite plugin, so the server knows which scripts and stylesheets each entry, view and block needs.
|
|
6
|
+
*/
|
|
7
|
+
/** A `<link>` to emit. `href` is required; any other attributes (eg. `data-vite-dev-id` in dev) are copied. */
|
|
8
|
+
export type AssetLink = {
|
|
9
|
+
href: string;
|
|
10
|
+
} & Record<string, string>;
|
|
11
|
+
export type AssetSet = {
|
|
12
|
+
/** The module script to boot, for entries */
|
|
13
|
+
entry?: string;
|
|
14
|
+
/** JS chunks to `modulepreload` */
|
|
15
|
+
js: AssetLink[];
|
|
16
|
+
/** Stylesheets */
|
|
17
|
+
css: AssetLink[];
|
|
18
|
+
};
|
|
19
|
+
export type ServerAssets = {
|
|
20
|
+
/** The public site's client entry, booted by the SSR page */
|
|
21
|
+
client: AssetSet & {
|
|
22
|
+
entry: string;
|
|
23
|
+
};
|
|
24
|
+
/** The admin bundle, injected into proxied wp-admin pages. */
|
|
25
|
+
admin: AssetSet & {
|
|
26
|
+
entry: string;
|
|
27
|
+
/** Dev only: extra tags for the head (the admin dev server's Vite client and React refresh preamble) */
|
|
28
|
+
head?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Dev only: the admin bundle's stylesheets, linked in the head so blocks don't render unstyled.
|
|
31
|
+
* Vite's client adopts these links (by `data-vite-dev-id`) for hot reloading.
|
|
32
|
+
*/
|
|
33
|
+
devStylesheets?: () => AssetLink[] | Promise<AssetLink[]>;
|
|
34
|
+
};
|
|
35
|
+
/** Dynamically imported views and blocks, keyed by project-relative file name (eg. `views/page.tsx`) */
|
|
36
|
+
modules: Record<string, AssetSet | undefined>;
|
|
37
|
+
};
|
|
38
|
+
export type AssetTag = {
|
|
39
|
+
tag: "link" | "script" | "style";
|
|
40
|
+
attrs: Record<string, string | boolean>;
|
|
41
|
+
children?: string;
|
|
42
|
+
};
|
|
43
|
+
/** Converts an asset set into `<link>` tags: stylesheets first, then module preloads. */
|
|
44
|
+
export declare function getAssetTags(assets: AssetSet | undefined): AssetTag[];
|
|
45
|
+
//# sourceMappingURL=assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../../src/app/server/assets.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+GAA+G;AAC/G,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEjE,MAAM,MAAM,QAAQ,GAAG;IACrB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,mCAAmC;IACnC,EAAE,EAAE,SAAS,EAAE,CAAA;IACf,kBAAkB;IAClB,GAAG,EAAE,SAAS,EAAE,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,6DAA6D;IAC7D,MAAM,EAAE,QAAQ,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IACpC,8DAA8D;IAC9D,KAAK,EAAE,QAAQ,GAAG;QAChB,KAAK,EAAE,MAAM,CAAA;QACb,wGAAwG;QACxG,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;QACf;;;WAGG;QACH,cAAc,CAAC,EAAE,MAAM,SAAS,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAA;KAC1D,CAAA;IACD,wGAAwG;IACxG,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAA;CAC9C,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;IAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAA;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,yFAAyF;AACzF,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,EAAE,CAQrE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client asset lookups for server rendering.
|
|
3
|
+
*
|
|
4
|
+
* The generated `manifest/assets.ts` (server only) fills this in using the `?assets` imports provided by
|
|
5
|
+
* Nitro's Vite plugin, so the server knows which scripts and stylesheets each entry, view and block needs.
|
|
6
|
+
*/
|
|
7
|
+
/** Converts an asset set into `<link>` tags: stylesheets first, then module preloads. */
|
|
8
|
+
export function getAssetTags(assets) {
|
|
9
|
+
if (!assets)
|
|
10
|
+
return [];
|
|
11
|
+
return [
|
|
12
|
+
...assets.css.map((link) => ({ tag: "link", attrs: { rel: "stylesheet", fetchPriority: "high", ...link, key: link.href } })),
|
|
13
|
+
...assets.js.map((link) => ({ tag: "link", attrs: { rel: "modulepreload", ...link, key: link.href } })),
|
|
14
|
+
];
|
|
15
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
export * from "./assets.js";
|
|
1
2
|
export * from "./proxy-wp-admin.js";
|
|
2
3
|
export * from "./render-ai-page.js";
|
|
3
4
|
export * from "./render-ssr-page.js";
|
|
4
5
|
export * from "./rpc.js";
|
|
6
|
+
export * from "./rpc-handler.js";
|
|
7
|
+
export * from "./server-app.js";
|
|
5
8
|
export * from "./server-context.js";
|
|
9
|
+
export type { RequestHeaders } from "./utils/request.js";
|
|
6
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,UAAU,CAAA;AACxB,cAAc,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA"}
|
package/dist/app/server/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export * from "./assets.js";
|
|
1
2
|
export * from "./proxy-wp-admin.js";
|
|
2
3
|
export * from "./render-ai-page.js";
|
|
3
4
|
export * from "./render-ssr-page.js";
|
|
4
5
|
export * from "./rpc.js";
|
|
6
|
+
export * from "./rpc-handler.js";
|
|
7
|
+
export * from "./server-app.js";
|
|
5
8
|
export * from "./server-context.js";
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Proxies a request through to the WordPress origin, rewriting origin URLs in text responses.
|
|
3
|
+
* For HTML responses, the admin bundle's tags are injected into the `VITE_HEADER`/`VITE_FOOTER`
|
|
4
|
+
* placeholders printed by the PHP side.
|
|
5
|
+
*/
|
|
6
|
+
export declare function proxyWpAdmin(req: Request): Promise<Response>;
|
|
3
7
|
//# sourceMappingURL=proxy-wp-admin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-wp-admin.d.ts","sourceRoot":"","sources":["../../../src/app/server/proxy-wp-admin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"proxy-wp-admin.d.ts","sourceRoot":"","sources":["../../../src/app/server/proxy-wp-admin.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkGlE"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
/// <reference types="vinxi/types/server" />
|
|
2
1
|
import { splitSetCookieString } from "cookie-es";
|
|
3
|
-
import {
|
|
4
|
-
import { ServerContext } from "./server-context.js";
|
|
2
|
+
import { getAssetTags } from "./assets.js";
|
|
5
3
|
import { renderErrorPage } from "./render-ssr-page.js";
|
|
6
|
-
|
|
4
|
+
import { ServerContext } from "./server-context.js";
|
|
5
|
+
import { getProxyRequestHeaders, getRequestURL } from "./utils/request.js";
|
|
6
|
+
/**
|
|
7
|
+
* Proxies a request through to the WordPress origin, rewriting origin URLs in text responses.
|
|
8
|
+
* For HTML responses, the admin bundle's tags are injected into the `VITE_HEADER`/`VITE_FOOTER`
|
|
9
|
+
* placeholders printed by the PHP side.
|
|
10
|
+
*/
|
|
11
|
+
export async function proxyWpAdmin(req) {
|
|
7
12
|
const serverContext = ServerContext.main;
|
|
8
|
-
const
|
|
9
|
-
const reqUrl = getRequestURL(event);
|
|
13
|
+
const reqUrl = getRequestURL(req);
|
|
10
14
|
const serverlessConfig = serverContext.config.serverless;
|
|
11
15
|
if (!serverContext.dev) {
|
|
12
16
|
if (reqUrl.pathname.toLowerCase().match(/\/+(graphql|xmlrpc|\.php|wp\-(admin|login|json|cron))/)) {
|
|
13
17
|
if (serverlessConfig.admin === "hide") {
|
|
14
|
-
//
|
|
15
18
|
return renderErrorPage({
|
|
16
19
|
statusCode: 404,
|
|
17
20
|
title: "Not found",
|
|
@@ -23,19 +26,10 @@ export async function proxyWpAdmin(event) {
|
|
|
23
26
|
}
|
|
24
27
|
const proxyUrl = serverContext.getOriginUrl(reqUrl.href);
|
|
25
28
|
// Prepare request headers to be sent to the origin server
|
|
26
|
-
const proxyHeaders = getProxyRequestHeaders(
|
|
29
|
+
const proxyHeaders = getProxyRequestHeaders(req);
|
|
27
30
|
proxyHeaders["X-ED-Dev-Proxy"] = "true";
|
|
28
31
|
const followRedirects = !reqUrl.pathname.match(/\.[a-z0-9]$/) && !reqUrl.pathname.match(/(^\/wp-|\.php$)/);
|
|
29
32
|
// Forward the request to the origin server
|
|
30
|
-
// console.log("Proxying request", proxyUrl, {
|
|
31
|
-
// method: req.method,
|
|
32
|
-
// referrer: req.referrer,
|
|
33
|
-
// referrerPolicy: req.referrerPolicy,
|
|
34
|
-
// headers: proxyHeaders,
|
|
35
|
-
// // body: req.method.match(/get|head|options/i) ? undefined : await req.blob(),
|
|
36
|
-
// redirect: followRedirects ? "follow" : "manual",
|
|
37
|
-
// cache: "no-cache",
|
|
38
|
-
// })
|
|
39
33
|
const response = await fetch(proxyUrl, {
|
|
40
34
|
method: req.method,
|
|
41
35
|
referrer: req.referrer,
|
|
@@ -65,10 +59,8 @@ export async function proxyWpAdmin(event) {
|
|
|
65
59
|
res.headers.set("document-isolation-policy", "none");
|
|
66
60
|
// Set cookies in the response headers
|
|
67
61
|
// TODO: May need to rewrite cookie domain here before setting.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
res.headers.append("set-cookie", cookie);
|
|
71
|
-
}
|
|
62
|
+
for (const cookie of cookies) {
|
|
63
|
+
res.headers.append("set-cookie", cookie);
|
|
72
64
|
}
|
|
73
65
|
// Replace URLs pointing to the origin server from the response itself
|
|
74
66
|
// This is only done for text-based content types, like application/json, text/plain, text/html etc
|
|
@@ -76,21 +68,14 @@ export async function proxyWpAdmin(event) {
|
|
|
76
68
|
body = serverContext.replaceUrls((await response.text()) ?? "", reqUrl.origin);
|
|
77
69
|
// If the content type is text/html, inject the Vite assets into the response — assuming the placeholder comments are found
|
|
78
70
|
if (contentType.startsWith("text/html")) {
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
type: "module",
|
|
87
|
-
src: clientManifest.inputs[clientManifest.handler].output.path,
|
|
88
|
-
},
|
|
89
|
-
children: "",
|
|
90
|
-
});
|
|
71
|
+
const admin = serverContext.runtime.assets.admin;
|
|
72
|
+
const devStylesheets = (await admin.devStylesheets?.()) ?? [];
|
|
73
|
+
const viteHeader = [
|
|
74
|
+
...getAssetTags({ ...admin, css: [...admin.css, ...devStylesheets] }).map(renderAsset),
|
|
75
|
+
...(admin.head ?? []),
|
|
76
|
+
].join("\n");
|
|
77
|
+
const viteFooter = renderAsset({ tag: "script", attrs: { type: "module", src: admin.entry }, children: "" });
|
|
91
78
|
const encodeForJSON = (str) => JSON.stringify(str).slice(1, -1).replaceAll("/", "\\/");
|
|
92
|
-
const viteHeader = getViteHeader();
|
|
93
|
-
const viteFooter = getViteFooter();
|
|
94
79
|
const baseDirective = `<base href="${reqUrl.origin}">`;
|
|
95
80
|
body = body.replaceAll("<!---VITE_HEADER--->", viteHeader);
|
|
96
81
|
body = body.replaceAll("<!---VITE_FOOTER--->", viteFooter);
|
|
@@ -105,36 +90,23 @@ export async function proxyWpAdmin(event) {
|
|
|
105
90
|
return new Response(body, res);
|
|
106
91
|
}
|
|
107
92
|
function printElement(element, props, innerText) {
|
|
93
|
+
const attrs = Object.entries(props)
|
|
94
|
+
.filter(([, value]) => value !== false && value !== undefined)
|
|
95
|
+
.map(([key, value]) => (value === true ? ` ${key}` : ` ${key}="${String(value).replace(/"/g, """)}"`))
|
|
96
|
+
.join("");
|
|
108
97
|
if (typeof innerText === "string") {
|
|
109
|
-
return `<${element}${
|
|
110
|
-
.map(([key, value]) => ` ${key}="${value}"`)
|
|
111
|
-
.join("")}>${innerText}</${element}>`;
|
|
98
|
+
return `<${element}${attrs}>${innerText}</${element}>`;
|
|
112
99
|
}
|
|
113
100
|
else {
|
|
114
|
-
return `<${element}${
|
|
115
|
-
.map(([key, value]) => ` ${key}="${value}"`)
|
|
116
|
-
.join("")} />`;
|
|
101
|
+
return `<${element}${attrs} />`;
|
|
117
102
|
}
|
|
118
103
|
}
|
|
119
|
-
function renderAsset({ tag, attrs: { key, ...attrs }
|
|
104
|
+
function renderAsset({ tag, attrs: { key, ...attrs }, children }) {
|
|
120
105
|
switch (tag) {
|
|
121
106
|
case "script":
|
|
122
|
-
|
|
123
|
-
return printElement("script", { ...attrs, key: attrs.src }, "");
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
return printElement("script", {
|
|
127
|
-
...attrs,
|
|
128
|
-
key: key,
|
|
129
|
-
}, children ?? "");
|
|
130
|
-
}
|
|
107
|
+
return printElement("script", attrs, children ?? "");
|
|
131
108
|
case "link":
|
|
132
|
-
return printElement("link",
|
|
133
|
-
case "style":
|
|
134
|
-
return printElement("style", {
|
|
135
|
-
...attrs,
|
|
136
|
-
key: key,
|
|
137
|
-
}, children ?? "");
|
|
109
|
+
return printElement("link", attrs);
|
|
138
110
|
}
|
|
139
111
|
return "";
|
|
140
112
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ErrorRouteProps, RouteDataWithTrackers } from "../lib/routing/types.js";
|
|
2
|
+
import { type AssetTag } from "./assets.js";
|
|
2
3
|
type SSRArgs = {
|
|
3
4
|
pathname: string;
|
|
4
5
|
hostname?: string;
|
|
@@ -22,11 +23,6 @@ type RenderErrorPageArgs = {
|
|
|
22
23
|
realError?: any;
|
|
23
24
|
} & ErrorRouteProps;
|
|
24
25
|
export declare function renderErrorPage(args: RenderErrorPageArgs): Promise<Response>;
|
|
25
|
-
|
|
26
|
-
tag: string;
|
|
27
|
-
attrs: Record<string, string | boolean>;
|
|
28
|
-
children?: string;
|
|
29
|
-
};
|
|
30
|
-
export declare function renderAsset({ tag, attrs, children }: Asset): string;
|
|
26
|
+
export declare function renderAsset({ tag, attrs, children }: AssetTag): string;
|
|
31
27
|
export {};
|
|
32
28
|
//# sourceMappingURL=render-ssr-page.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-ssr-page.d.ts","sourceRoot":"","sources":["../../../src/app/server/render-ssr-page.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"render-ssr-page.d.ts","sourceRoot":"","sources":["../../../src/app/server/render-ssr-page.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAErF,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAA;AAOzD,KAAK,OAAO,GAAG;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,qBAAqB,CAAA;IAClC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,OAAO,wDAgI/C;AAED,KAAK,UAAU,GAAG;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6GpE;AAED,KAAK,mBAAmB,GAAG;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,GAAG,CAAA;CAChB,GAAG,eAAe,CAAA;AAEnB,wBAAsB,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiBlF;AAED,wBAAgB,WAAW,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,QAAQ,UA8B7D"}
|
|
@@ -6,12 +6,15 @@ import { MetaTags } from "../entry/MetaTags.js";
|
|
|
6
6
|
import { SSRRoot } from "../entry/ssr-root.js";
|
|
7
7
|
import { RouteLoader } from "../lib/routing/loader.js";
|
|
8
8
|
import { ServerRenderResponseContext } from "../utils/ssr-response-data.js";
|
|
9
|
+
import { getAssetTags } from "./assets.js";
|
|
9
10
|
import { ServerContext } from "./server-context.js";
|
|
10
11
|
import { SecureHeaderBuilder } from "./utils/content-security.js";
|
|
12
|
+
/** Preload key for the client entry. Other keys are view/block file names registered via `dynamic()`. */
|
|
13
|
+
const CLIENT_ENTRY = "$client";
|
|
11
14
|
export async function getSsrStream(args) {
|
|
12
|
-
const
|
|
15
|
+
const assets = ServerContext.main.runtime.assets;
|
|
13
16
|
const ssrResponse = {
|
|
14
|
-
preloadAssets: new Set([
|
|
17
|
+
preloadAssets: new Set([CLIENT_ENTRY]),
|
|
15
18
|
includedAssets: new Set(),
|
|
16
19
|
queryCache: new Map(),
|
|
17
20
|
};
|
|
@@ -32,9 +35,9 @@ export async function getSsrStream(args) {
|
|
|
32
35
|
console.log("Error occurred after shell ready", err, errInfo);
|
|
33
36
|
console.error(err);
|
|
34
37
|
},
|
|
35
|
-
bootstrapModules: [
|
|
38
|
+
bootstrapModules: [assets.client.entry],
|
|
36
39
|
nonce: args.nonce,
|
|
37
|
-
bootstrapScriptContent: `\nwindow.
|
|
40
|
+
bootstrapScriptContent: `\nwindow._PAGE_DATA = ${JSON.stringify({
|
|
38
41
|
...args.initialData,
|
|
39
42
|
trackers: undefined,
|
|
40
43
|
hostname: args.hostname,
|
|
@@ -67,10 +70,8 @@ export async function getSsrStream(args) {
|
|
|
67
70
|
stream.pipe(writableStream);
|
|
68
71
|
});
|
|
69
72
|
for (const input of ssrResponse.preloadAssets) {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
for (const _asset of assets) {
|
|
73
|
-
const asset = _asset;
|
|
73
|
+
const tags = getAssetTags(input === CLIENT_ENTRY ? assets.client : assets.modules[input]);
|
|
74
|
+
for (const asset of tags) {
|
|
74
75
|
if (args.nonce)
|
|
75
76
|
asset.attrs.nonce = args.nonce;
|
|
76
77
|
// Ensure that each asset is only included once
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AnyRouter } from "@trpc/server";
|
|
2
|
+
import { type FetchCreateContextFnOptions } from "@trpc/server/adapters/fetch";
|
|
3
|
+
export type RPCHandlerOptions = {
|
|
4
|
+
router: AnyRouter;
|
|
5
|
+
createContext: (opts: FetchCreateContextFnOptions) => any;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Handles a request to one of the project's `server/routes` procedures.
|
|
9
|
+
*
|
|
10
|
+
* URLs use slashes (`/api/search/quickSearch/`), which are converted to tRPC's dotted names.
|
|
11
|
+
* A procedure may return a `Response`, which is sent as-is instead of the tRPC envelope.
|
|
12
|
+
*/
|
|
13
|
+
export declare function handleRPCRequest(originalReq: Request, opts: RPCHandlerOptions): Promise<Response>;
|
|
14
|
+
//# sourceMappingURL=rpc-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-handler.d.ts","sourceRoot":"","sources":["../../../src/app/server/rpc-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAuB,KAAK,2BAA2B,EAAE,MAAM,6BAA6B,CAAA;AAInG,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,SAAS,CAAA;IACjB,aAAa,EAAE,CAAC,IAAI,EAAE,2BAA2B,KAAK,GAAG,CAAA;CAC1D,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2CvG"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
2
|
+
import { parseURL, stringifyParsedURL } from "ufo";
|
|
3
|
+
import { ServerContext } from "./server-context.js";
|
|
4
|
+
/**
|
|
5
|
+
* Handles a request to one of the project's `server/routes` procedures.
|
|
6
|
+
*
|
|
7
|
+
* URLs use slashes (`/api/search/quickSearch/`), which are converted to tRPC's dotted names.
|
|
8
|
+
* A procedure may return a `Response`, which is sent as-is instead of the tRPC envelope.
|
|
9
|
+
*/
|
|
10
|
+
export async function handleRPCRequest(originalReq, opts) {
|
|
11
|
+
const serverContext = ServerContext.main;
|
|
12
|
+
// Handle CORS
|
|
13
|
+
const corsHeaders = serverContext.getCorsHeaders(originalReq.headers.get("origin") ?? originalReq.headers.get("referer") ?? "");
|
|
14
|
+
if (originalReq.method === "OPTIONS") {
|
|
15
|
+
return new Response("OK", { status: 204, statusText: "No Content.", headers: corsHeaders });
|
|
16
|
+
}
|
|
17
|
+
// Update URLs with dots, which tRPC prefers
|
|
18
|
+
const parsed = parseURL(originalReq.url);
|
|
19
|
+
parsed.pathname = "/" + parsed.pathname.replace(/(^\/|\/$)/g, "").replace(/\//g, ".");
|
|
20
|
+
const req = new Request(stringifyParsedURL(parsed), originalReq);
|
|
21
|
+
let earlyResponse;
|
|
22
|
+
const defaultResponse = await fetchRequestHandler({
|
|
23
|
+
endpoint: "/",
|
|
24
|
+
req,
|
|
25
|
+
router: opts.router,
|
|
26
|
+
createContext: async (ctxOpts) => {
|
|
27
|
+
return {
|
|
28
|
+
...(await opts.createContext(ctxOpts)),
|
|
29
|
+
searchParams: ctxOpts.info.url?.searchParams,
|
|
30
|
+
server: serverContext,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
onError: (err) => console.error(err),
|
|
34
|
+
batching: { enabled: false },
|
|
35
|
+
// If a Response object is returned by a route, it will be sent as the response
|
|
36
|
+
responseMeta(meta) {
|
|
37
|
+
const value = meta?.data?.[0]?.["result"]?.["data"];
|
|
38
|
+
if (value instanceof Response) {
|
|
39
|
+
earlyResponse = value;
|
|
40
|
+
}
|
|
41
|
+
return {};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const response = earlyResponse ?? defaultResponse;
|
|
45
|
+
return withCors(response, corsHeaders);
|
|
46
|
+
}
|
|
47
|
+
function withCors(response, corsHeaders) {
|
|
48
|
+
if (!Object.keys(corsHeaders).length)
|
|
49
|
+
return response;
|
|
50
|
+
try {
|
|
51
|
+
for (const [key, value] of Object.entries(corsHeaders)) {
|
|
52
|
+
response.headers.set(key, value);
|
|
53
|
+
}
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Some responses have immutable headers
|
|
58
|
+
const headers = new Headers(response.headers);
|
|
59
|
+
for (const [key, value] of Object.entries(corsHeaders))
|
|
60
|
+
headers.set(key, value);
|
|
61
|
+
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ServerAssets } from "./assets.js";
|
|
2
|
+
import { type RPCHandlerOptions } from "./rpc-handler.js";
|
|
3
|
+
export type ServerAppOptions = {
|
|
4
|
+
/** The project's `server/routes` procedures */
|
|
5
|
+
rpc: RPCHandlerOptions;
|
|
6
|
+
/** Client asset lookups, generated per build */
|
|
7
|
+
assets: ServerAssets;
|
|
8
|
+
/** Set when Vercel skew protection is enabled for the deployment */
|
|
9
|
+
skewProtection?: {
|
|
10
|
+
deploymentId: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type ServerApp = {
|
|
14
|
+
fetch(req: Request): Promise<Response>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The serverless app: route data, named queries and mutations, RPC procedures, WordPress proxying
|
|
18
|
+
* and server-rendered pages. Nitro calls `fetch` for every request that isn't a static asset or
|
|
19
|
+
* handled by a route rule (eg. the `/wp-content/**` proxies).
|
|
20
|
+
*/
|
|
21
|
+
export declare function createServerApp(opts: ServerAppOptions): ServerApp;
|
|
22
|
+
//# sourceMappingURL=server-app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-app.d.ts","sourceRoot":"","sources":["../../../src/app/server/server-app.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI/C,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAI3E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,+CAA+C;IAC/C,GAAG,EAAE,iBAAiB,CAAA;IACtB,gDAAgD;IAChD,MAAM,EAAE,YAAY,CAAA;IACpB,oEAAoE;IACpE,cAAc,CAAC,EAAE;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CACvC,CAAA;AAQD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,CAuLjE"}
|