@cedarjs/vite 5.0.0-canary.2318 → 5.0.0-canary.2319

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.
@@ -3,14 +3,15 @@ export interface BuildUDApiServerOptions {
3
3
  apiRootPath?: string;
4
4
  }
5
5
  /**
6
- * Builds the API server Universal Deploy Node entry using Vite.
6
+ * Builds the API server Universal Deploy entry using Vite.
7
7
  *
8
8
  * Runs a Vite server build that:
9
9
  * 1. Installs `cedarUniversalDeployPlugin()` to register per-route API
10
- * entries (GraphQL, auth, functions) with UD's store and resolve
11
- * `virtual:ud:catch-all` Cedar's multi-route rou3 dispatcher.
12
- * 2. Installs `node()` from `@universal-deploy/node/vite` to emit a
13
- * self-contained Node server entry at `api/dist/ud/index.js`
10
+ * entries (GraphQL, auth, functions) with UD's store.
11
+ * 2. Installs `universalDeploy()` from `@universal-deploy/vite` which
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).
14
15
  *
15
16
  * The emitted entry can be launched directly: node api/dist/ud/index.js
16
17
  * That is what `cedar serve api` does.
@@ -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;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,gBAAgB,GAAU,4BAGpC,uBAA4B,kBA+D9B,CAAA"}
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;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,GAAU,4BAGpC,uBAA4B,kBA6C9B,CAAA"}
@@ -6,23 +6,19 @@ 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 { node } = await import("@universal-deploy/node/vite");
9
+ const { default: universalDeploy } = await import("@universal-deploy/vite");
10
10
  const rwPaths = getPaths();
11
11
  const outDir = path.join(rwPaths.api.dist, "ud");
12
12
  await build({
13
- // No configFile — we configure everything inline so this build is
14
- // self-contained and does not require a vite.config.ts in api/.
15
- configFile: false,
16
- envFile: false,
17
13
  logLevel: verbose ? "info" : "warn",
18
14
  plugins: [
19
- // Registers per-route API entries with @universal-deploy/store and
20
- // resolves virtual:ud:catch-all → Cedar's multi-route rou3 dispatcher.
15
+ // Registers per-route API entries with @universal-deploy/store.
21
16
  cedarUniversalDeployPlugin({ apiRootPath }),
22
- // Emits a self-contained Node server entry (api/dist/ud/index.js) that
23
- // imports virtual:ud:catch-all and starts an srvx HTTP server.
24
- // This is a Vite server-build concern, not Cedar HTML SSR.
25
- ...node()
17
+ // Includes catchAll(), devServer(), and auto-detection of
18
+ // deployment targets. Enables @universal-deploy/node by default
19
+ // when no other target (Netlify, Vercel, Cloudflare) is detected
20
+ // in the user's Vite config.
21
+ universalDeploy()
26
22
  ],
27
23
  // The ssr environment is the Vite mechanism for server-side builds.
28
24
  // Reminder: "ssr" here means "server-side module execution", NOT
@@ -30,21 +26,7 @@ const buildUDApiServer = async ({
30
26
  environments: {
31
27
  ssr: {
32
28
  build: {
33
- outDir,
34
- // Ensure @universal-deploy/node is bundled into the output so the
35
- // emitted entry is self-contained.
36
- rollupOptions: {
37
- output: {
38
- // Produce a single-file entry where possible; srvx chunks are
39
- // split by the node() plugin automatically.
40
- entryFileNames: "[name].js"
41
- }
42
- }
43
- },
44
- resolve: {
45
- // Do not externalise @universal-deploy/node — the node() plugin
46
- // requires it to be bundled into the server entry.
47
- noExternal: ["@universal-deploy/node"]
29
+ outDir
48
30
  }
49
31
  }
50
32
  },
@@ -39,23 +39,19 @@ 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 { node } = await import("@universal-deploy/node/vite");
42
+ const { default: universalDeploy } = await import("@universal-deploy/vite");
43
43
  const rwPaths = (0, import_project_config.getPaths)();
44
44
  const outDir = import_node_path.default.join(rwPaths.api.dist, "ud");
45
45
  await build({
46
- // No configFile — we configure everything inline so this build is
47
- // self-contained and does not require a vite.config.ts in api/.
48
- configFile: false,
49
- envFile: false,
50
46
  logLevel: verbose ? "info" : "warn",
51
47
  plugins: [
52
- // Registers per-route API entries with @universal-deploy/store and
53
- // resolves virtual:ud:catch-all → Cedar's multi-route rou3 dispatcher.
48
+ // Registers per-route API entries with @universal-deploy/store.
54
49
  cedarUniversalDeployPlugin({ apiRootPath }),
55
- // Emits a self-contained Node server entry (api/dist/ud/index.js) that
56
- // imports virtual:ud:catch-all and starts an srvx HTTP server.
57
- // This is a Vite server-build concern, not Cedar HTML SSR.
58
- ...node()
50
+ // Includes catchAll(), devServer(), and auto-detection of
51
+ // deployment targets. Enables @universal-deploy/node by default
52
+ // when no other target (Netlify, Vercel, Cloudflare) is detected
53
+ // in the user's Vite config.
54
+ universalDeploy()
59
55
  ],
60
56
  // The ssr environment is the Vite mechanism for server-side builds.
61
57
  // Reminder: "ssr" here means "server-side module execution", NOT
@@ -63,21 +59,7 @@ const buildUDApiServer = async ({
63
59
  environments: {
64
60
  ssr: {
65
61
  build: {
66
- outDir,
67
- // Ensure @universal-deploy/node is bundled into the output so the
68
- // emitted entry is self-contained.
69
- rollupOptions: {
70
- output: {
71
- // Produce a single-file entry where possible; srvx chunks are
72
- // split by the node() plugin automatically.
73
- entryFileNames: "[name].js"
74
- }
75
- }
76
- },
77
- resolve: {
78
- // Do not externalise @universal-deploy/node — the node() plugin
79
- // requires it to be bundled into the server entry.
80
- noExternal: ["@universal-deploy/node"]
62
+ outDir
81
63
  }
82
64
  }
83
65
  },
@@ -37,19 +37,18 @@ 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 RESOLVED_VIRTUAL_UD_CATCH_ALL = "\0virtual:ud:catch-all";
41
40
  const GRAPHQL_METHODS = ["GET", "POST", "OPTIONS"];
42
- function normalizeApiRootPath(rootPath) {
43
- let normalized = rootPath;
44
- if (!normalized.startsWith("/")) {
45
- normalized = "/" + normalized;
41
+ function normaliseApiPrefix(apiPrefix) {
42
+ apiPrefix = apiPrefix.trim();
43
+ while (apiPrefix.startsWith("/")) {
44
+ apiPrefix = apiPrefix.slice(1);
46
45
  }
47
- if (!normalized.endsWith("/")) {
48
- normalized = normalized + "/";
46
+ while (apiPrefix.endsWith("/")) {
47
+ apiPrefix = apiPrefix.slice(0, -1);
49
48
  }
50
- return normalized;
49
+ return apiPrefix ? "/" + apiPrefix : "";
51
50
  }
52
- function discoverCedarRoutes() {
51
+ function discoverCedarRoutes(apiRootPath) {
53
52
  const srcFunctions = (0, import_project_config.getPaths)().api.functions;
54
53
  const distFunctions = import_node_path.default.join((0, import_project_config.getPaths)().api.base, "dist", "functions");
55
54
  const sourceFiles = (0, import_files.findApiServerFunctions)(srcFunctions);
@@ -67,7 +66,8 @@ function discoverCedarRoutes() {
67
66
  } else {
68
67
  continue;
69
68
  }
70
- const routePath = routeName === "graphql" ? "/graphql" : `/${routeName}`;
69
+ const apiPrefix = normaliseApiPrefix(apiRootPath);
70
+ const routePath = routeName === "graphql" ? `${apiPrefix}/graphql` : `${apiPrefix}/${routeName}`;
71
71
  const methods = routeName === "graphql" ? [...GRAPHQL_METHODS] : [];
72
72
  const type = routeName === "graphql" ? "graphql" : routeName === "health" ? "health" : routeName.toLowerCase().includes("auth") ? "auth" : "function";
73
73
  const distPath = import_node_path.default.join(distFunctions, dir, name + ".js");
@@ -98,8 +98,7 @@ function toEntryMeta(route) {
98
98
  }
99
99
  function cedarUniversalDeployPlugin(options = {}) {
100
100
  const { apiRootPath } = options;
101
- const normalizedApiRootPath = normalizeApiRootPath(apiRootPath ?? "/");
102
- const routes = discoverCedarRoutes();
101
+ const routes = discoverCedarRoutes(apiRootPath ?? "/");
103
102
  let entriesInjected = false;
104
103
  return {
105
104
  name: "cedar-universal-deploy",
@@ -114,15 +113,11 @@ function cedarUniversalDeployPlugin(options = {}) {
114
113
  for (const route of routes) {
115
114
  (0, import_store.addEntry)(toEntryMeta(route));
116
115
  }
117
- (0, import_store.addEntry)({
118
- id: import_store.catchAllEntry,
119
- route: "/**"
120
- });
121
116
  }
122
117
  },
123
118
  resolveId(id) {
124
- if (id === import_store.catchAllEntry) {
125
- return RESOLVED_VIRTUAL_UD_CATCH_ALL;
119
+ if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
120
+ return id;
126
121
  }
127
122
  if (id.startsWith(VIRTUAL_CEDAR_FN_PREFIX)) {
128
123
  return "\0" + id;
@@ -141,9 +136,6 @@ function cedarUniversalDeployPlugin(options = {}) {
141
136
  }
142
137
  return generateFunctionModule(route.entry);
143
138
  }
144
- if (id === RESOLVED_VIRTUAL_UD_CATCH_ALL) {
145
- return generateCatchAllModule(routes, normalizedApiRootPath);
146
- }
147
139
  return void 0;
148
140
  }
149
141
  };
@@ -160,27 +152,6 @@ function generateFunctionModule(distPath) {
160
152
  export default createFunctionHandler({ distPath: ${JSON.stringify(distPath)} });
161
153
  `;
162
154
  }
163
- function generateCatchAllModule(routes, normalizedApiRootPath) {
164
- const imports = routes.map(
165
- (route, i) => `import mod${i} from '${VIRTUAL_CEDAR_FN_PREFIX}${route.id}';`
166
- ).join("\n");
167
- const routesArray = routes.map(
168
- (route, i) => `{
169
- path: ${JSON.stringify(route.path)},
170
- methods: ${JSON.stringify(route.methods)},
171
- module: mod${i}
172
- }`
173
- ).join(", ");
174
- return `
175
- import { createCatchAllHandler } from '@cedarjs/vite/ud-handlers/catch-all';
176
- ${imports}
177
-
178
- export default createCatchAllHandler({
179
- routes: [${routesArray}],
180
- apiRootPath: ${JSON.stringify(normalizedApiRootPath)}
181
- });
182
- `;
183
- }
184
155
  // Annotate the CommonJS export names for ESM import in node:
185
156
  0 && (module.exports = {
186
157
  cedarUniversalDeployPlugin
@@ -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":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC,MAAM,WAAW,iCAAiC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAyGD,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iCAAsC,GAC9C,MAAM,CAsER"}
1
+ {"version":3,"file":"vite-plugin-cedar-universal-deploy.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-universal-deploy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC,MAAM,WAAW,iCAAiC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AA6GD,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iCAAsC,GAC9C,MAAM,CA4DR"}
@@ -1,22 +1,21 @@
1
1
  import path from "node:path";
2
- import { addEntry, catchAllEntry } from "@universal-deploy/store";
2
+ import { addEntry } from "@universal-deploy/store";
3
3
  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 RESOLVED_VIRTUAL_UD_CATCH_ALL = "\0virtual:ud:catch-all";
8
7
  const GRAPHQL_METHODS = ["GET", "POST", "OPTIONS"];
9
- function normalizeApiRootPath(rootPath) {
10
- let normalized = rootPath;
11
- if (!normalized.startsWith("/")) {
12
- normalized = "/" + normalized;
8
+ function normaliseApiPrefix(apiPrefix) {
9
+ apiPrefix = apiPrefix.trim();
10
+ while (apiPrefix.startsWith("/")) {
11
+ apiPrefix = apiPrefix.slice(1);
13
12
  }
14
- if (!normalized.endsWith("/")) {
15
- normalized = normalized + "/";
13
+ while (apiPrefix.endsWith("/")) {
14
+ apiPrefix = apiPrefix.slice(0, -1);
16
15
  }
17
- return normalized;
16
+ return apiPrefix ? "/" + apiPrefix : "";
18
17
  }
19
- function discoverCedarRoutes() {
18
+ function discoverCedarRoutes(apiRootPath) {
20
19
  const srcFunctions = getPaths().api.functions;
21
20
  const distFunctions = path.join(getPaths().api.base, "dist", "functions");
22
21
  const sourceFiles = findApiServerFunctions(srcFunctions);
@@ -34,7 +33,8 @@ function discoverCedarRoutes() {
34
33
  } else {
35
34
  continue;
36
35
  }
37
- const routePath = routeName === "graphql" ? "/graphql" : `/${routeName}`;
36
+ const apiPrefix = normaliseApiPrefix(apiRootPath);
37
+ const routePath = routeName === "graphql" ? `${apiPrefix}/graphql` : `${apiPrefix}/${routeName}`;
38
38
  const methods = routeName === "graphql" ? [...GRAPHQL_METHODS] : [];
39
39
  const type = routeName === "graphql" ? "graphql" : routeName === "health" ? "health" : routeName.toLowerCase().includes("auth") ? "auth" : "function";
40
40
  const distPath = path.join(distFunctions, dir, name + ".js");
@@ -65,8 +65,7 @@ function toEntryMeta(route) {
65
65
  }
66
66
  function cedarUniversalDeployPlugin(options = {}) {
67
67
  const { apiRootPath } = options;
68
- const normalizedApiRootPath = normalizeApiRootPath(apiRootPath ?? "/");
69
- const routes = discoverCedarRoutes();
68
+ const routes = discoverCedarRoutes(apiRootPath ?? "/");
70
69
  let entriesInjected = false;
71
70
  return {
72
71
  name: "cedar-universal-deploy",
@@ -81,15 +80,11 @@ function cedarUniversalDeployPlugin(options = {}) {
81
80
  for (const route of routes) {
82
81
  addEntry(toEntryMeta(route));
83
82
  }
84
- addEntry({
85
- id: catchAllEntry,
86
- route: "/**"
87
- });
88
83
  }
89
84
  },
90
85
  resolveId(id) {
91
- if (id === catchAllEntry) {
92
- return RESOLVED_VIRTUAL_UD_CATCH_ALL;
86
+ if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
87
+ return id;
93
88
  }
94
89
  if (id.startsWith(VIRTUAL_CEDAR_FN_PREFIX)) {
95
90
  return "\0" + id;
@@ -108,9 +103,6 @@ function cedarUniversalDeployPlugin(options = {}) {
108
103
  }
109
104
  return generateFunctionModule(route.entry);
110
105
  }
111
- if (id === RESOLVED_VIRTUAL_UD_CATCH_ALL) {
112
- return generateCatchAllModule(routes, normalizedApiRootPath);
113
- }
114
106
  return void 0;
115
107
  }
116
108
  };
@@ -127,27 +119,6 @@ function generateFunctionModule(distPath) {
127
119
  export default createFunctionHandler({ distPath: ${JSON.stringify(distPath)} });
128
120
  `;
129
121
  }
130
- function generateCatchAllModule(routes, normalizedApiRootPath) {
131
- const imports = routes.map(
132
- (route, i) => `import mod${i} from '${VIRTUAL_CEDAR_FN_PREFIX}${route.id}';`
133
- ).join("\n");
134
- const routesArray = routes.map(
135
- (route, i) => `{
136
- path: ${JSON.stringify(route.path)},
137
- methods: ${JSON.stringify(route.methods)},
138
- module: mod${i}
139
- }`
140
- ).join(", ");
141
- return `
142
- import { createCatchAllHandler } from '@cedarjs/vite/ud-handlers/catch-all';
143
- ${imports}
144
-
145
- export default createCatchAllHandler({
146
- routes: [${routesArray}],
147
- apiRootPath: ${JSON.stringify(normalizedApiRootPath)}
148
- });
149
- `;
150
- }
151
122
  export {
152
123
  cedarUniversalDeployPlugin
153
124
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/vite",
3
- "version": "5.0.0-canary.2318",
3
+ "version": "5.0.0-canary.2319",
4
4
  "description": "Vite configuration package for CedarJS",
5
5
  "repository": {
6
6
  "type": "git",
@@ -99,22 +99,23 @@
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.2318",
103
- "@cedarjs/api-server": "5.0.0-canary.2318",
104
- "@cedarjs/auth": "5.0.0-canary.2318",
105
- "@cedarjs/babel-config": "5.0.0-canary.2318",
106
- "@cedarjs/context": "5.0.0-canary.2318",
107
- "@cedarjs/cookie-jar": "5.0.0-canary.2318",
108
- "@cedarjs/graphql-server": "5.0.0-canary.2318",
109
- "@cedarjs/internal": "5.0.0-canary.2318",
110
- "@cedarjs/project-config": "5.0.0-canary.2318",
111
- "@cedarjs/server-store": "5.0.0-canary.2318",
112
- "@cedarjs/testing": "5.0.0-canary.2318",
113
- "@cedarjs/web": "5.0.0-canary.2318",
102
+ "@cedarjs/api": "5.0.0-canary.2319",
103
+ "@cedarjs/api-server": "5.0.0-canary.2319",
104
+ "@cedarjs/auth": "5.0.0-canary.2319",
105
+ "@cedarjs/babel-config": "5.0.0-canary.2319",
106
+ "@cedarjs/context": "5.0.0-canary.2319",
107
+ "@cedarjs/cookie-jar": "5.0.0-canary.2319",
108
+ "@cedarjs/graphql-server": "5.0.0-canary.2319",
109
+ "@cedarjs/internal": "5.0.0-canary.2319",
110
+ "@cedarjs/project-config": "5.0.0-canary.2319",
111
+ "@cedarjs/server-store": "5.0.0-canary.2319",
112
+ "@cedarjs/testing": "5.0.0-canary.2319",
113
+ "@cedarjs/web": "5.0.0-canary.2319",
114
114
  "@fastify/url-data": "6.0.3",
115
115
  "@swc/core": "1.15.32",
116
116
  "@universal-deploy/node": "^0.1.6",
117
117
  "@universal-deploy/store": "^0.2.1",
118
+ "@universal-deploy/vite": "^0.1.9",
118
119
  "@vitejs/plugin-react": "4.7.0",
119
120
  "@whatwg-node/fetch": "0.10.13",
120
121
  "@whatwg-node/server": "0.10.18",