@cedarjs/vite 5.0.0-canary.2343 → 5.0.0-canary.2347
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/buildUDApiServer.d.ts +16 -12
- package/dist/buildUDApiServer.d.ts.map +1 -1
- package/dist/buildUDApiServer.js +49 -19
- package/dist/cjs/buildUDApiServer.js +49 -19
- package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +28 -2
- package/dist/cjs/ud-handlers/function.js +2 -3
- package/dist/cjs/ud-handlers/graphql.js +1 -2
- package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-cedar-universal-deploy.js +28 -2
- package/dist/ud-handlers/function.d.ts +1 -1
- package/dist/ud-handlers/function.d.ts.map +1 -1
- package/dist/ud-handlers/function.js +2 -3
- package/dist/ud-handlers/graphql.d.ts +1 -1
- package/dist/ud-handlers/graphql.d.ts.map +1 -1
- package/dist/ud-handlers/graphql.js +1 -2
- package/package.json +13 -13
|
@@ -3,22 +3,26 @@ export interface BuildUDApiServerOptions {
|
|
|
3
3
|
apiRootPath?: string;
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
|
-
* Builds the API server Universal Deploy entry using Vite.
|
|
6
|
+
* Builds the API server Universal Deploy server entry using Vite.
|
|
7
7
|
*
|
|
8
|
-
* Runs a Vite
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* provides `catchAll()` (rou3-based route dispatch), `devServer()`, and
|
|
13
|
-
* auto-detection of deployment targets (Node by default, or Netlify/
|
|
14
|
-
* Vercel/Cloudflare if the user has added the corresponding Vite plugin).
|
|
8
|
+
* Runs a Vite SSR build that produces a pure WinterTC-compatible Fetchable
|
|
9
|
+
* (`export default { fetch }`) at `api/dist/ud/index.js`. The output
|
|
10
|
+
* contains NO HTTP server startup code — the Fetchable is wrapped by
|
|
11
|
+
* `cedar serve` at runtime.
|
|
15
12
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* Loads the user's Vite config (`web/vite.config.ts`) so provider plugins
|
|
14
|
+
* (Netlify, Vercel, etc.) can produce their own deployment artifacts
|
|
15
|
+
* alongside Cedar's canonical local-serve artifact. Cedar's own UD plugins
|
|
16
|
+
* (`cedarUniversalDeployPlugin`, `catchAll`, `devServer`) are injected
|
|
17
|
+
* independently and are not affected by user config.
|
|
18
|
+
*
|
|
19
|
+
* The emitted server entry is placed under `api/dist/ud/` so it does not
|
|
20
|
+
* collide with the existing esbuild output under `api/dist/`.
|
|
18
21
|
*
|
|
19
22
|
* NOTE: The Vite "ssr" build target used here is a server-side module build
|
|
20
|
-
* concern — it is NOT related to Cedar HTML SSR
|
|
21
|
-
* Vite produces a Node-compatible bundle rather than a browser
|
|
23
|
+
* concern — it is NOT related to Cedar HTML SSR / streaming / RSC. "ssr"
|
|
24
|
+
* simply means Vite produces a Node-compatible bundle rather than a browser
|
|
25
|
+
* bundle.
|
|
22
26
|
*/
|
|
23
27
|
export declare const buildUDApiServer: ({ verbose, apiRootPath, }?: BuildUDApiServerOptions) => Promise<void>;
|
|
24
28
|
//# sourceMappingURL=buildUDApiServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildUDApiServer.d.ts","sourceRoot":"","sources":["../src/buildUDApiServer.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED
|
|
1
|
+
{"version":3,"file":"buildUDApiServer.d.ts","sourceRoot":"","sources":["../src/buildUDApiServer.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,gBAAgB,GAAU,4BAGpC,uBAA4B,kBAyE9B,CAAA"}
|
package/dist/buildUDApiServer.js
CHANGED
|
@@ -6,33 +6,63 @@ const buildUDApiServer = async ({
|
|
|
6
6
|
} = {}) => {
|
|
7
7
|
const { build } = await import("vite");
|
|
8
8
|
const { cedarUniversalDeployPlugin } = await import("./plugins/vite-plugin-cedar-universal-deploy.js");
|
|
9
|
-
const {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const { catchAll, devServer } = await import("@universal-deploy/vite");
|
|
10
|
+
const { catchAllEntry, getAllEntries } = await import("@universal-deploy/store");
|
|
11
|
+
const cedarPaths = getPaths();
|
|
12
|
+
const outDir = path.join(cedarPaths.api.dist, "ud");
|
|
12
13
|
await build({
|
|
14
|
+
// Load the user's Vite config so provider plugins can run alongside
|
|
15
|
+
// Cedar's canonical UD build.
|
|
16
|
+
configFile: cedarPaths.web.viteConfig,
|
|
13
17
|
logLevel: verbose ? "info" : "warn",
|
|
14
18
|
plugins: [
|
|
15
19
|
// Registers per-route API entries with @universal-deploy/store.
|
|
20
|
+
// The apiRootPath is baked into the generated route patterns by
|
|
21
|
+
// cedarUniversalDeployPlugin's normaliseApiPrefix helper.
|
|
16
22
|
cedarUniversalDeployPlugin({ apiRootPath }),
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
universalDeploy()
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
// catchAll() generates the rou3-based route dispatcher
|
|
24
|
+
// (virtual:ud:catch-all). devServer() provides Vite dev support for
|
|
25
|
+
// cedar dev --ud.
|
|
26
|
+
//
|
|
27
|
+
// NOTE: We intentionally do NOT use universalDeploy() here — that
|
|
28
|
+
// plugin auto-detects deployment targets and would embed the Node
|
|
29
|
+
// HTTP server startup code into the output. Our plugin list is
|
|
30
|
+
// adapter-free: the output is a pure Fetchable export, and cedar
|
|
31
|
+
// serve wraps it in srvx at runtime.
|
|
32
|
+
catchAll(),
|
|
33
|
+
devServer(),
|
|
34
|
+
// Warn if no Cedar API routes were registered — likely means the
|
|
35
|
+
// user's vite config is missing cedarUniversalDeployPlugin or there
|
|
36
|
+
// are no API functions to serve.
|
|
37
|
+
{
|
|
38
|
+
name: "cedar-ud-verify-routes",
|
|
39
|
+
configResolved() {
|
|
40
|
+
const entries = getAllEntries();
|
|
41
|
+
if (entries.length === 0) {
|
|
42
|
+
console.warn(
|
|
43
|
+
"\n Warning: No Universal Deploy API routes were registered.",
|
|
44
|
+
"\n The built server entry will be an empty router (404 for all",
|
|
45
|
+
"\n requests). Check that you have API functions under",
|
|
46
|
+
"\n `api/src/functions/`.\n"
|
|
47
|
+
);
|
|
48
|
+
}
|
|
30
49
|
}
|
|
31
50
|
}
|
|
32
|
-
|
|
51
|
+
],
|
|
52
|
+
// Legacy ssr flag approach. The explicit rollupOptions.input prevents the
|
|
53
|
+
// "index.html as SSR entry" error. Vite will also build a 'client'
|
|
54
|
+
// environment from the user's config file (wasteful but harmless), and
|
|
55
|
+
// the 'ssr' environment produces our canonical Fetchable artifact at
|
|
56
|
+
// api/dist/ud/index.js.
|
|
33
57
|
build: {
|
|
34
|
-
|
|
35
|
-
|
|
58
|
+
ssr: true,
|
|
59
|
+
outDir,
|
|
60
|
+
rollupOptions: {
|
|
61
|
+
input: catchAllEntry,
|
|
62
|
+
output: {
|
|
63
|
+
entryFileNames: "index.js"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
36
66
|
}
|
|
37
67
|
});
|
|
38
68
|
};
|
|
@@ -39,33 +39,63 @@ const buildUDApiServer = async ({
|
|
|
39
39
|
} = {}) => {
|
|
40
40
|
const { build } = await import("vite");
|
|
41
41
|
const { cedarUniversalDeployPlugin } = await import("./plugins/vite-plugin-cedar-universal-deploy.js");
|
|
42
|
-
const {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
42
|
+
const { catchAll, devServer } = await import("@universal-deploy/vite");
|
|
43
|
+
const { catchAllEntry, getAllEntries } = await import("@universal-deploy/store");
|
|
44
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
45
|
+
const outDir = import_node_path.default.join(cedarPaths.api.dist, "ud");
|
|
45
46
|
await build({
|
|
47
|
+
// Load the user's Vite config so provider plugins can run alongside
|
|
48
|
+
// Cedar's canonical UD build.
|
|
49
|
+
configFile: cedarPaths.web.viteConfig,
|
|
46
50
|
logLevel: verbose ? "info" : "warn",
|
|
47
51
|
plugins: [
|
|
48
52
|
// Registers per-route API entries with @universal-deploy/store.
|
|
53
|
+
// The apiRootPath is baked into the generated route patterns by
|
|
54
|
+
// cedarUniversalDeployPlugin's normaliseApiPrefix helper.
|
|
49
55
|
cedarUniversalDeployPlugin({ apiRootPath }),
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
universalDeploy()
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
// catchAll() generates the rou3-based route dispatcher
|
|
57
|
+
// (virtual:ud:catch-all). devServer() provides Vite dev support for
|
|
58
|
+
// cedar dev --ud.
|
|
59
|
+
//
|
|
60
|
+
// NOTE: We intentionally do NOT use universalDeploy() here — that
|
|
61
|
+
// plugin auto-detects deployment targets and would embed the Node
|
|
62
|
+
// HTTP server startup code into the output. Our plugin list is
|
|
63
|
+
// adapter-free: the output is a pure Fetchable export, and cedar
|
|
64
|
+
// serve wraps it in srvx at runtime.
|
|
65
|
+
catchAll(),
|
|
66
|
+
devServer(),
|
|
67
|
+
// Warn if no Cedar API routes were registered — likely means the
|
|
68
|
+
// user's vite config is missing cedarUniversalDeployPlugin or there
|
|
69
|
+
// are no API functions to serve.
|
|
70
|
+
{
|
|
71
|
+
name: "cedar-ud-verify-routes",
|
|
72
|
+
configResolved() {
|
|
73
|
+
const entries = getAllEntries();
|
|
74
|
+
if (entries.length === 0) {
|
|
75
|
+
console.warn(
|
|
76
|
+
"\n Warning: No Universal Deploy API routes were registered.",
|
|
77
|
+
"\n The built server entry will be an empty router (404 for all",
|
|
78
|
+
"\n requests). Check that you have API functions under",
|
|
79
|
+
"\n `api/src/functions/`.\n"
|
|
80
|
+
);
|
|
81
|
+
}
|
|
63
82
|
}
|
|
64
83
|
}
|
|
65
|
-
|
|
84
|
+
],
|
|
85
|
+
// Legacy ssr flag approach. The explicit rollupOptions.input prevents the
|
|
86
|
+
// "index.html as SSR entry" error. Vite will also build a 'client'
|
|
87
|
+
// environment from the user's config file (wasteful but harmless), and
|
|
88
|
+
// the 'ssr' environment produces our canonical Fetchable artifact at
|
|
89
|
+
// api/dist/ud/index.js.
|
|
66
90
|
build: {
|
|
67
|
-
|
|
68
|
-
|
|
91
|
+
ssr: true,
|
|
92
|
+
outDir,
|
|
93
|
+
rollupOptions: {
|
|
94
|
+
input: catchAllEntry,
|
|
95
|
+
output: {
|
|
96
|
+
entryFileNames: "index.js"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
69
99
|
}
|
|
70
100
|
});
|
|
71
101
|
};
|
|
@@ -37,6 +37,7 @@ var import_files = require("@cedarjs/internal/dist/files.js");
|
|
|
37
37
|
var import_project_config = require("@cedarjs/project-config");
|
|
38
38
|
const VIRTUAL_CEDAR_FN_PREFIX = "virtual:cedar-api:fn:";
|
|
39
39
|
const RESOLVED_CEDAR_FN_PREFIX = "\0virtual:cedar-api:fn:";
|
|
40
|
+
const UD_STORE_SYMBOL = /* @__PURE__ */ Symbol.for("ud:store");
|
|
40
41
|
const GRAPHQL_METHODS = ["GET", "POST", "OPTIONS"];
|
|
41
42
|
function normaliseApiPrefix(apiPrefix) {
|
|
42
43
|
apiPrefix = apiPrefix.trim();
|
|
@@ -96,6 +97,15 @@ function toEntryMeta(route) {
|
|
|
96
97
|
}
|
|
97
98
|
};
|
|
98
99
|
}
|
|
100
|
+
function clearCedarEntries() {
|
|
101
|
+
const store = globalThis[UD_STORE_SYMBOL];
|
|
102
|
+
if (!store) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
store.entries = store.entries.filter(
|
|
106
|
+
(entry) => !entry.id?.startsWith(VIRTUAL_CEDAR_FN_PREFIX)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
99
109
|
function cedarUniversalDeployPlugin(options = {}) {
|
|
100
110
|
const { apiRootPath } = options;
|
|
101
111
|
const routes = discoverCedarRoutes(apiRootPath ?? "/");
|
|
@@ -110,11 +120,23 @@ function cedarUniversalDeployPlugin(options = {}) {
|
|
|
110
120
|
return;
|
|
111
121
|
}
|
|
112
122
|
entriesInjected = true;
|
|
123
|
+
clearCedarEntries();
|
|
113
124
|
for (const route of routes) {
|
|
114
125
|
(0, import_store.addEntry)(toEntryMeta(route));
|
|
115
126
|
}
|
|
116
127
|
}
|
|
117
128
|
},
|
|
129
|
+
buildStart() {
|
|
130
|
+
for (const route of routes) {
|
|
131
|
+
const resolvedId = RESOLVED_CEDAR_FN_PREFIX + route.id;
|
|
132
|
+
const safeName = route.id.replace(/[/\\?%*:|"<>]/g, "_").replace(/^_+/, "");
|
|
133
|
+
this.emitFile({
|
|
134
|
+
type: "chunk",
|
|
135
|
+
id: resolvedId,
|
|
136
|
+
fileName: safeName + "-handler.js"
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
},
|
|
118
140
|
resolveId(id) {
|
|
119
141
|
if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
|
|
120
142
|
return id;
|
|
@@ -141,15 +163,19 @@ function cedarUniversalDeployPlugin(options = {}) {
|
|
|
141
163
|
};
|
|
142
164
|
}
|
|
143
165
|
function generateGraphQLModule(distPath) {
|
|
166
|
+
const udOutDir = import_node_path.default.join((0, import_project_config.getPaths)().api.dist, "ud");
|
|
167
|
+
const relPath = "./" + import_node_path.default.relative(udOutDir, distPath);
|
|
144
168
|
return `
|
|
145
169
|
import { createGraphQLHandler } from '@cedarjs/vite/ud-handlers/graphql';
|
|
146
|
-
export default createGraphQLHandler({
|
|
170
|
+
export default createGraphQLHandler({ distUrl: new URL(${JSON.stringify(relPath)}, import.meta.url).href });
|
|
147
171
|
`;
|
|
148
172
|
}
|
|
149
173
|
function generateFunctionModule(distPath) {
|
|
174
|
+
const udOutDir = import_node_path.default.join((0, import_project_config.getPaths)().api.dist, "ud");
|
|
175
|
+
const relPath = "./" + import_node_path.default.relative(udOutDir, distPath);
|
|
150
176
|
return `
|
|
151
177
|
import { createFunctionHandler } from '@cedarjs/vite/ud-handlers/function';
|
|
152
|
-
export default createFunctionHandler({
|
|
178
|
+
export default createFunctionHandler({ distUrl: new URL(${JSON.stringify(relPath)}, import.meta.url).href });
|
|
153
179
|
`;
|
|
154
180
|
}
|
|
155
181
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -21,12 +21,11 @@ __export(function_exports, {
|
|
|
21
21
|
createFunctionHandler: () => createFunctionHandler
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(function_exports);
|
|
24
|
-
var import_node_url = require("node:url");
|
|
25
24
|
var import_runtime = require("@cedarjs/api/runtime");
|
|
26
25
|
var import_udFetchable = require("@cedarjs/api-server/udFetchable");
|
|
27
26
|
function createFunctionHandler(options) {
|
|
28
27
|
const handleRequest = async (request, ctx) => {
|
|
29
|
-
const mod = await import(
|
|
28
|
+
const mod = await import(options.distUrl);
|
|
30
29
|
const nativeHandler = mod.handleRequest || mod.default?.handleRequest;
|
|
31
30
|
if (nativeHandler) {
|
|
32
31
|
return nativeHandler(request, ctx);
|
|
@@ -36,7 +35,7 @@ function createFunctionHandler(options) {
|
|
|
36
35
|
return (0, import_runtime.wrapLegacyHandler)(legacyHandler)(request, ctx);
|
|
37
36
|
}
|
|
38
37
|
throw new Error(
|
|
39
|
-
`Handler not found in ${options.
|
|
38
|
+
`Handler not found in ${options.distUrl}. Expected \`export async function handleRequest(request, ctx)\`, \`export default { handleRequest }\`, or a legacy Lambda-shaped \`handler\`.`
|
|
40
39
|
);
|
|
41
40
|
};
|
|
42
41
|
return (0, import_udFetchable.createCedarFetchable)(handleRequest);
|
|
@@ -21,7 +21,6 @@ __export(graphql_exports, {
|
|
|
21
21
|
createGraphQLHandler: () => createGraphQLHandler
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(graphql_exports);
|
|
24
|
-
var import_node_url = require("node:url");
|
|
25
24
|
var import_runtime = require("@cedarjs/api/runtime");
|
|
26
25
|
var import_graphql_server = require("@cedarjs/graphql-server");
|
|
27
26
|
function createGraphQLHandler(options) {
|
|
@@ -29,7 +28,7 @@ function createGraphQLHandler(options) {
|
|
|
29
28
|
async function getYoga() {
|
|
30
29
|
if (!yogaInitPromise) {
|
|
31
30
|
yogaInitPromise = (async () => {
|
|
32
|
-
const mod = await import(
|
|
31
|
+
const mod = await import(options.distUrl);
|
|
33
32
|
const opts = mod.__rw_graphqlOptions;
|
|
34
33
|
const { yoga } = await (0, import_graphql_server.createGraphQLYoga)(opts);
|
|
35
34
|
return { yoga, graphqlOptions: opts };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-universal-deploy.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-universal-deploy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedar-universal-deploy.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-universal-deploy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC,MAAM,WAAW,iCAAiC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAuJD,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iCAAsC,GAC9C,MAAM,CAkFR"}
|
|
@@ -4,6 +4,7 @@ import { findApiServerFunctions } from "@cedarjs/internal/dist/files.js";
|
|
|
4
4
|
import { getPaths } from "@cedarjs/project-config";
|
|
5
5
|
const VIRTUAL_CEDAR_FN_PREFIX = "virtual:cedar-api:fn:";
|
|
6
6
|
const RESOLVED_CEDAR_FN_PREFIX = "\0virtual:cedar-api:fn:";
|
|
7
|
+
const UD_STORE_SYMBOL = /* @__PURE__ */ Symbol.for("ud:store");
|
|
7
8
|
const GRAPHQL_METHODS = ["GET", "POST", "OPTIONS"];
|
|
8
9
|
function normaliseApiPrefix(apiPrefix) {
|
|
9
10
|
apiPrefix = apiPrefix.trim();
|
|
@@ -63,6 +64,15 @@ function toEntryMeta(route) {
|
|
|
63
64
|
}
|
|
64
65
|
};
|
|
65
66
|
}
|
|
67
|
+
function clearCedarEntries() {
|
|
68
|
+
const store = globalThis[UD_STORE_SYMBOL];
|
|
69
|
+
if (!store) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
store.entries = store.entries.filter(
|
|
73
|
+
(entry) => !entry.id?.startsWith(VIRTUAL_CEDAR_FN_PREFIX)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
66
76
|
function cedarUniversalDeployPlugin(options = {}) {
|
|
67
77
|
const { apiRootPath } = options;
|
|
68
78
|
const routes = discoverCedarRoutes(apiRootPath ?? "/");
|
|
@@ -77,11 +87,23 @@ function cedarUniversalDeployPlugin(options = {}) {
|
|
|
77
87
|
return;
|
|
78
88
|
}
|
|
79
89
|
entriesInjected = true;
|
|
90
|
+
clearCedarEntries();
|
|
80
91
|
for (const route of routes) {
|
|
81
92
|
addEntry(toEntryMeta(route));
|
|
82
93
|
}
|
|
83
94
|
}
|
|
84
95
|
},
|
|
96
|
+
buildStart() {
|
|
97
|
+
for (const route of routes) {
|
|
98
|
+
const resolvedId = RESOLVED_CEDAR_FN_PREFIX + route.id;
|
|
99
|
+
const safeName = route.id.replace(/[/\\?%*:|"<>]/g, "_").replace(/^_+/, "");
|
|
100
|
+
this.emitFile({
|
|
101
|
+
type: "chunk",
|
|
102
|
+
id: resolvedId,
|
|
103
|
+
fileName: safeName + "-handler.js"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
},
|
|
85
107
|
resolveId(id) {
|
|
86
108
|
if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
|
|
87
109
|
return id;
|
|
@@ -108,15 +130,19 @@ function cedarUniversalDeployPlugin(options = {}) {
|
|
|
108
130
|
};
|
|
109
131
|
}
|
|
110
132
|
function generateGraphQLModule(distPath) {
|
|
133
|
+
const udOutDir = path.join(getPaths().api.dist, "ud");
|
|
134
|
+
const relPath = "./" + path.relative(udOutDir, distPath);
|
|
111
135
|
return `
|
|
112
136
|
import { createGraphQLHandler } from '@cedarjs/vite/ud-handlers/graphql';
|
|
113
|
-
export default createGraphQLHandler({
|
|
137
|
+
export default createGraphQLHandler({ distUrl: new URL(${JSON.stringify(relPath)}, import.meta.url).href });
|
|
114
138
|
`;
|
|
115
139
|
}
|
|
116
140
|
function generateFunctionModule(distPath) {
|
|
141
|
+
const udOutDir = path.join(getPaths().api.dist, "ud");
|
|
142
|
+
const relPath = "./" + path.relative(udOutDir, distPath);
|
|
117
143
|
return `
|
|
118
144
|
import { createFunctionHandler } from '@cedarjs/vite/ud-handlers/function';
|
|
119
|
-
export default createFunctionHandler({
|
|
145
|
+
export default createFunctionHandler({ distUrl: new URL(${JSON.stringify(relPath)}, import.meta.url).href });
|
|
120
146
|
`;
|
|
121
147
|
}
|
|
122
148
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/ud-handlers/function.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/ud-handlers/function.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,uDAyBpE"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { pathToFileURL } from "node:url";
|
|
2
1
|
import { wrapLegacyHandler } from "@cedarjs/api/runtime";
|
|
3
2
|
import { createCedarFetchable } from "@cedarjs/api-server/udFetchable";
|
|
4
3
|
function createFunctionHandler(options) {
|
|
5
4
|
const handleRequest = async (request, ctx) => {
|
|
6
|
-
const mod = await import(
|
|
5
|
+
const mod = await import(options.distUrl);
|
|
7
6
|
const nativeHandler = mod.handleRequest || mod.default?.handleRequest;
|
|
8
7
|
if (nativeHandler) {
|
|
9
8
|
return nativeHandler(request, ctx);
|
|
@@ -13,7 +12,7 @@ function createFunctionHandler(options) {
|
|
|
13
12
|
return wrapLegacyHandler(legacyHandler)(request, ctx);
|
|
14
13
|
}
|
|
15
14
|
throw new Error(
|
|
16
|
-
`Handler not found in ${options.
|
|
15
|
+
`Handler not found in ${options.distUrl}. Expected \`export async function handleRequest(request, ctx)\`, \`export default { handleRequest }\`, or a legacy Lambda-shaped \`handler\`.`
|
|
17
16
|
);
|
|
18
17
|
};
|
|
19
18
|
return createCedarFetchable(handleRequest);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/ud-handlers/graphql.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/ud-handlers/graphql.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB;mBAiB1C,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;EAenD"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { pathToFileURL } from "node:url";
|
|
2
1
|
import { buildCedarContext, requestToLegacyEvent } from "@cedarjs/api/runtime";
|
|
3
2
|
import { createGraphQLYoga } from "@cedarjs/graphql-server";
|
|
4
3
|
function createGraphQLHandler(options) {
|
|
@@ -6,7 +5,7 @@ function createGraphQLHandler(options) {
|
|
|
6
5
|
async function getYoga() {
|
|
7
6
|
if (!yogaInitPromise) {
|
|
8
7
|
yogaInitPromise = (async () => {
|
|
9
|
-
const mod = await import(
|
|
8
|
+
const mod = await import(options.distUrl);
|
|
10
9
|
const opts = mod.__rw_graphqlOptions;
|
|
11
10
|
const { yoga } = await createGraphQLYoga(opts);
|
|
12
11
|
return { yoga, graphqlOptions: opts };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/vite",
|
|
3
|
-
"version": "5.0.0-canary.
|
|
3
|
+
"version": "5.0.0-canary.2347",
|
|
4
4
|
"description": "Vite configuration package for CedarJS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -99,18 +99,18 @@
|
|
|
99
99
|
"@babel/generator": "7.29.1",
|
|
100
100
|
"@babel/parser": "7.29.3",
|
|
101
101
|
"@babel/traverse": "7.29.0",
|
|
102
|
-
"@cedarjs/api": "5.0.0-canary.
|
|
103
|
-
"@cedarjs/api-server": "5.0.0-canary.
|
|
104
|
-
"@cedarjs/auth": "5.0.0-canary.
|
|
105
|
-
"@cedarjs/babel-config": "5.0.0-canary.
|
|
106
|
-
"@cedarjs/context": "5.0.0-canary.
|
|
107
|
-
"@cedarjs/cookie-jar": "5.0.0-canary.
|
|
108
|
-
"@cedarjs/graphql-server": "5.0.0-canary.
|
|
109
|
-
"@cedarjs/internal": "5.0.0-canary.
|
|
110
|
-
"@cedarjs/project-config": "5.0.0-canary.
|
|
111
|
-
"@cedarjs/server-store": "5.0.0-canary.
|
|
112
|
-
"@cedarjs/testing": "5.0.0-canary.
|
|
113
|
-
"@cedarjs/web": "5.0.0-canary.
|
|
102
|
+
"@cedarjs/api": "5.0.0-canary.2347",
|
|
103
|
+
"@cedarjs/api-server": "5.0.0-canary.2347",
|
|
104
|
+
"@cedarjs/auth": "5.0.0-canary.2347",
|
|
105
|
+
"@cedarjs/babel-config": "5.0.0-canary.2347",
|
|
106
|
+
"@cedarjs/context": "5.0.0-canary.2347",
|
|
107
|
+
"@cedarjs/cookie-jar": "5.0.0-canary.2347",
|
|
108
|
+
"@cedarjs/graphql-server": "5.0.0-canary.2347",
|
|
109
|
+
"@cedarjs/internal": "5.0.0-canary.2347",
|
|
110
|
+
"@cedarjs/project-config": "5.0.0-canary.2347",
|
|
111
|
+
"@cedarjs/server-store": "5.0.0-canary.2347",
|
|
112
|
+
"@cedarjs/testing": "5.0.0-canary.2347",
|
|
113
|
+
"@cedarjs/web": "5.0.0-canary.2347",
|
|
114
114
|
"@fastify/url-data": "6.0.3",
|
|
115
115
|
"@swc/core": "1.15.33",
|
|
116
116
|
"@universal-deploy/node": "^0.1.6",
|