@cedarjs/vite 5.0.0-canary.2355 → 5.0.0-canary.2356

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.
@@ -10,11 +10,13 @@ export interface BuildUDApiServerOptions {
10
10
  * contains NO HTTP server startup code — the Fetchable is wrapped by
11
11
  * `cedar serve` at runtime.
12
12
  *
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.
13
+ * Loads the user's Vite config (`web/vite.config.ts`) so both provider
14
+ * plugins (Netlify, Vercel, etc.) and Cedar's own UD plugin
15
+ * (`cedarUniversalDeployPlugin`) run during the build.
16
+ * Provider plugins produce their own deployment artifacts alongside Cedar's UD
17
+ * output.
18
+ * The user must include `cedarUniversalDeployPlugin()` in their Vite config to
19
+ * register API routes.
18
20
  *
19
21
  * The emitted server entry is placed under `api/dist/ud/` so it does not
20
22
  * collide with the existing esbuild output under `api/dist/`.
@@ -24,5 +26,5 @@ export interface BuildUDApiServerOptions {
24
26
  * simply means Vite produces a Node-compatible bundle rather than a browser
25
27
  * bundle.
26
28
  */
27
- export declare const buildUDApiServer: ({ verbose, apiRootPath, }?: BuildUDApiServerOptions) => Promise<void>;
29
+ export declare function buildUDApiServer({ verbose, apiRootPath, }?: BuildUDApiServerOptions): Promise<void>;
28
30
  //# 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;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,gBAAgB,GAAU,4BAGpC,uBAA4B,kBAyE9B,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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,OAAe,EACf,WAAW,GACZ,GAAE,uBAA4B,iBAiF9B"}
@@ -1,71 +1,76 @@
1
1
  import path from "node:path";
2
2
  import { getPaths } from "@cedarjs/project-config";
3
- const buildUDApiServer = async ({
3
+ async function buildUDApiServer({
4
4
  verbose = false,
5
5
  apiRootPath
6
- } = {}) => {
6
+ } = {}) {
7
7
  const { build } = await import("vite");
8
- const { cedarUniversalDeployPlugin } = await import("./plugins/vite-plugin-cedar-universal-deploy.js");
9
8
  const { catchAll, devServer } = await import("@universal-deploy/vite");
10
9
  const { catchAllEntry, getAllEntries } = await import("@universal-deploy/store");
11
10
  const cedarPaths = getPaths();
12
11
  const outDir = path.join(cedarPaths.api.dist, "ud");
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,
17
- logLevel: verbose ? "info" : "warn",
18
- plugins: [
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.
22
- cedarUniversalDeployPlugin({ apiRootPath }),
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
- );
12
+ if (apiRootPath !== void 0) {
13
+ process.env.CEDAR_API_ROOT_PATH = apiRootPath;
14
+ }
15
+ try {
16
+ await build({
17
+ // Load the user's Vite config so all plugins (Cedar's UD plugin,
18
+ // provider plugins, etc.) run during the build.
19
+ configFile: cedarPaths.web.viteConfig,
20
+ logLevel: verbose ? "info" : "warn",
21
+ plugins: [
22
+ // catchAll() generates the rou3-based route dispatcher
23
+ // (virtual:ud:catch-all). devServer() provides Vite dev support for
24
+ // cedar dev --ud.
25
+ //
26
+ // NOTE: We intentionally do NOT use universalDeploy() here — that
27
+ // plugin auto-detects deployment targets and would embed the Node
28
+ // HTTP server startup code into the output. Our plugin list is
29
+ // adapter-free: the output is a pure Fetchable export, and cedar
30
+ // serve wraps it in srvx at runtime.
31
+ catchAll(),
32
+ devServer(),
33
+ // Warn if no Cedar API routes were registered — likely means the
34
+ // user's vite config is missing cedarUniversalDeployPlugin or there
35
+ // are no API functions to serve.
36
+ {
37
+ name: "cedar-ud-verify-routes",
38
+ configResolved() {
39
+ const entries = getAllEntries();
40
+ if (entries.length === 0) {
41
+ console.warn(
42
+ "\n Warning: No Universal Deploy API routes were registered.",
43
+ "\n The built server entry will be an empty router (404 for all",
44
+ "\n requests). Check that you have API functions under",
45
+ "\n `api/src/functions/` and that your vite config includes",
46
+ "\n `cedarUniversalDeployPlugin()`.\n"
47
+ );
48
+ }
48
49
  }
49
50
  }
50
- }
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.
57
- build: {
58
- ssr: true,
59
- outDir,
60
- rollupOptions: {
61
- input: catchAllEntry,
62
- output: {
63
- entryFileNames: "index.js"
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.
57
+ build: {
58
+ ssr: true,
59
+ outDir,
60
+ rollupOptions: {
61
+ input: catchAllEntry,
62
+ output: {
63
+ entryFileNames: "index.js"
64
+ }
64
65
  }
65
66
  }
67
+ });
68
+ } finally {
69
+ if (apiRootPath !== void 0) {
70
+ delete process.env.CEDAR_API_ROOT_PATH;
66
71
  }
67
- });
68
- };
72
+ }
73
+ }
69
74
  export {
70
75
  buildUDApiServer
71
76
  };
@@ -33,72 +33,77 @@ __export(buildUDApiServer_exports, {
33
33
  module.exports = __toCommonJS(buildUDApiServer_exports);
34
34
  var import_node_path = __toESM(require("node:path"), 1);
35
35
  var import_project_config = require("@cedarjs/project-config");
36
- const buildUDApiServer = async ({
36
+ async function buildUDApiServer({
37
37
  verbose = false,
38
38
  apiRootPath
39
- } = {}) => {
39
+ } = {}) {
40
40
  const { build } = await import("vite");
41
- const { cedarUniversalDeployPlugin } = await import("./plugins/vite-plugin-cedar-universal-deploy.js");
42
41
  const { catchAll, devServer } = await import("@universal-deploy/vite");
43
42
  const { catchAllEntry, getAllEntries } = await import("@universal-deploy/store");
44
43
  const cedarPaths = (0, import_project_config.getPaths)();
45
44
  const outDir = import_node_path.default.join(cedarPaths.api.dist, "ud");
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,
50
- logLevel: verbose ? "info" : "warn",
51
- plugins: [
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.
55
- cedarUniversalDeployPlugin({ apiRootPath }),
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
- );
45
+ if (apiRootPath !== void 0) {
46
+ process.env.CEDAR_API_ROOT_PATH = apiRootPath;
47
+ }
48
+ try {
49
+ await build({
50
+ // Load the user's Vite config so all plugins (Cedar's UD plugin,
51
+ // provider plugins, etc.) run during the build.
52
+ configFile: cedarPaths.web.viteConfig,
53
+ logLevel: verbose ? "info" : "warn",
54
+ plugins: [
55
+ // catchAll() generates the rou3-based route dispatcher
56
+ // (virtual:ud:catch-all). devServer() provides Vite dev support for
57
+ // cedar dev --ud.
58
+ //
59
+ // NOTE: We intentionally do NOT use universalDeploy() here — that
60
+ // plugin auto-detects deployment targets and would embed the Node
61
+ // HTTP server startup code into the output. Our plugin list is
62
+ // adapter-free: the output is a pure Fetchable export, and cedar
63
+ // serve wraps it in srvx at runtime.
64
+ catchAll(),
65
+ devServer(),
66
+ // Warn if no Cedar API routes were registered — likely means the
67
+ // user's vite config is missing cedarUniversalDeployPlugin or there
68
+ // are no API functions to serve.
69
+ {
70
+ name: "cedar-ud-verify-routes",
71
+ configResolved() {
72
+ const entries = getAllEntries();
73
+ if (entries.length === 0) {
74
+ console.warn(
75
+ "\n Warning: No Universal Deploy API routes were registered.",
76
+ "\n The built server entry will be an empty router (404 for all",
77
+ "\n requests). Check that you have API functions under",
78
+ "\n `api/src/functions/` and that your vite config includes",
79
+ "\n `cedarUniversalDeployPlugin()`.\n"
80
+ );
81
+ }
81
82
  }
82
83
  }
83
- }
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.
90
- build: {
91
- ssr: true,
92
- outDir,
93
- rollupOptions: {
94
- input: catchAllEntry,
95
- output: {
96
- entryFileNames: "index.js"
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.
90
+ build: {
91
+ ssr: true,
92
+ outDir,
93
+ rollupOptions: {
94
+ input: catchAllEntry,
95
+ output: {
96
+ entryFileNames: "index.js"
97
+ }
97
98
  }
98
99
  }
100
+ });
101
+ } finally {
102
+ if (apiRootPath !== void 0) {
103
+ delete process.env.CEDAR_API_ROOT_PATH;
99
104
  }
100
- });
101
- };
105
+ }
106
+ }
102
107
  // Annotate the CommonJS export names for ESM import in node:
103
108
  0 && (module.exports = {
104
109
  buildUDApiServer
@@ -107,15 +107,18 @@ function clearCedarEntries() {
107
107
  );
108
108
  }
109
109
  function cedarUniversalDeployPlugin(options = {}) {
110
- const { apiRootPath } = options;
111
- const routes = discoverCedarRoutes(apiRootPath ?? "/");
110
+ const effectiveApiRootPath = process.env.CEDAR_API_ROOT_PATH ?? options.apiRootPath;
111
+ const routes = discoverCedarRoutes(effectiveApiRootPath ?? "/");
112
112
  let entriesInjected = false;
113
113
  return {
114
114
  name: "cedar-universal-deploy",
115
115
  apply: "build",
116
116
  config: {
117
117
  order: "pre",
118
- handler() {
118
+ handler(_config, env) {
119
+ if (!env.isSsrBuild) {
120
+ return;
121
+ }
119
122
  if (entriesInjected) {
120
123
  return;
121
124
  }
@@ -127,6 +130,9 @@ function cedarUniversalDeployPlugin(options = {}) {
127
130
  }
128
131
  },
129
132
  buildStart() {
133
+ if (this.environment?.name !== "ssr") {
134
+ return;
135
+ }
130
136
  for (const route of routes) {
131
137
  const resolvedId = RESOLVED_CEDAR_FN_PREFIX + route.id;
132
138
  const safeName = route.id.replace(/[/\\?%*:|"<>]/g, "_").replace(/^_+/, "");
@@ -138,6 +144,9 @@ function cedarUniversalDeployPlugin(options = {}) {
138
144
  }
139
145
  },
140
146
  resolveId(id) {
147
+ if (this.environment?.name !== "ssr") {
148
+ return void 0;
149
+ }
141
150
  if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
142
151
  return id;
143
152
  }
@@ -147,6 +156,9 @@ function cedarUniversalDeployPlugin(options = {}) {
147
156
  return void 0;
148
157
  },
149
158
  load(id) {
159
+ if (this.environment?.name !== "ssr") {
160
+ return void 0;
161
+ }
150
162
  if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
151
163
  const routeId = id.slice(RESOLVED_CEDAR_FN_PREFIX.length);
152
164
  const route = routes.find((r) => r.id === routeId);
@@ -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":"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"}
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,CA+GR"}
@@ -74,15 +74,18 @@ function clearCedarEntries() {
74
74
  );
75
75
  }
76
76
  function cedarUniversalDeployPlugin(options = {}) {
77
- const { apiRootPath } = options;
78
- const routes = discoverCedarRoutes(apiRootPath ?? "/");
77
+ const effectiveApiRootPath = process.env.CEDAR_API_ROOT_PATH ?? options.apiRootPath;
78
+ const routes = discoverCedarRoutes(effectiveApiRootPath ?? "/");
79
79
  let entriesInjected = false;
80
80
  return {
81
81
  name: "cedar-universal-deploy",
82
82
  apply: "build",
83
83
  config: {
84
84
  order: "pre",
85
- handler() {
85
+ handler(_config, env) {
86
+ if (!env.isSsrBuild) {
87
+ return;
88
+ }
86
89
  if (entriesInjected) {
87
90
  return;
88
91
  }
@@ -94,6 +97,9 @@ function cedarUniversalDeployPlugin(options = {}) {
94
97
  }
95
98
  },
96
99
  buildStart() {
100
+ if (this.environment?.name !== "ssr") {
101
+ return;
102
+ }
97
103
  for (const route of routes) {
98
104
  const resolvedId = RESOLVED_CEDAR_FN_PREFIX + route.id;
99
105
  const safeName = route.id.replace(/[/\\?%*:|"<>]/g, "_").replace(/^_+/, "");
@@ -105,6 +111,9 @@ function cedarUniversalDeployPlugin(options = {}) {
105
111
  }
106
112
  },
107
113
  resolveId(id) {
114
+ if (this.environment?.name !== "ssr") {
115
+ return void 0;
116
+ }
108
117
  if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
109
118
  return id;
110
119
  }
@@ -114,6 +123,9 @@ function cedarUniversalDeployPlugin(options = {}) {
114
123
  return void 0;
115
124
  },
116
125
  load(id) {
126
+ if (this.environment?.name !== "ssr") {
127
+ return void 0;
128
+ }
117
129
  if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
118
130
  const routeId = id.slice(RESOLVED_CEDAR_FN_PREFIX.length);
119
131
  const route = routes.find((r) => r.id === routeId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/vite",
3
- "version": "5.0.0-canary.2355",
3
+ "version": "5.0.0-canary.2356",
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.2355",
103
- "@cedarjs/api-server": "5.0.0-canary.2355",
104
- "@cedarjs/auth": "5.0.0-canary.2355",
105
- "@cedarjs/babel-config": "5.0.0-canary.2355",
106
- "@cedarjs/context": "5.0.0-canary.2355",
107
- "@cedarjs/cookie-jar": "5.0.0-canary.2355",
108
- "@cedarjs/graphql-server": "5.0.0-canary.2355",
109
- "@cedarjs/internal": "5.0.0-canary.2355",
110
- "@cedarjs/project-config": "5.0.0-canary.2355",
111
- "@cedarjs/server-store": "5.0.0-canary.2355",
112
- "@cedarjs/testing": "5.0.0-canary.2355",
113
- "@cedarjs/web": "5.0.0-canary.2355",
102
+ "@cedarjs/api": "5.0.0-canary.2356",
103
+ "@cedarjs/api-server": "5.0.0-canary.2356",
104
+ "@cedarjs/auth": "5.0.0-canary.2356",
105
+ "@cedarjs/babel-config": "5.0.0-canary.2356",
106
+ "@cedarjs/context": "5.0.0-canary.2356",
107
+ "@cedarjs/cookie-jar": "5.0.0-canary.2356",
108
+ "@cedarjs/graphql-server": "5.0.0-canary.2356",
109
+ "@cedarjs/internal": "5.0.0-canary.2356",
110
+ "@cedarjs/project-config": "5.0.0-canary.2356",
111
+ "@cedarjs/server-store": "5.0.0-canary.2356",
112
+ "@cedarjs/testing": "5.0.0-canary.2356",
113
+ "@cedarjs/web": "5.0.0-canary.2356",
114
114
  "@fastify/url-data": "6.0.3",
115
115
  "@swc/core": "1.15.33",
116
116
  "@universal-deploy/store": "^0.2.1",