@cedarjs/vite 4.2.1-next.0 → 4.2.1-next.258

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.
Files changed (65) hide show
  1. package/bins/cedar-unified-dev.mjs +7 -0
  2. package/dist/apiDevMiddleware.d.ts.map +1 -1
  3. package/dist/apiDevMiddleware.js +18 -5
  4. package/dist/buildApp.d.ts +2 -1
  5. package/dist/buildApp.d.ts.map +1 -1
  6. package/dist/buildApp.js +125 -6
  7. package/dist/buildFeServer.d.ts.map +1 -1
  8. package/dist/buildFeServer.js +1 -1
  9. package/dist/buildRouteHooks.d.ts.map +1 -1
  10. package/dist/buildRouteHooks.js +7 -3
  11. package/dist/cedar-unified-dev.d.ts +13 -2
  12. package/dist/cedar-unified-dev.d.ts.map +1 -1
  13. package/dist/cedar-unified-dev.js +171 -16
  14. package/dist/cjs/apiDevMiddleware.js +18 -5
  15. package/dist/cjs/buildApp.js +129 -10
  16. package/dist/cjs/buildFeServer.js +1 -1
  17. package/dist/cjs/buildRouteHooks.js +17 -3
  18. package/dist/cjs/cedar-unified-dev.js +184 -16
  19. package/dist/cjs/devFeServer.js +2 -1
  20. package/dist/cjs/index.js +5 -0
  21. package/dist/cjs/lib/getMergedConfig.js +12 -4
  22. package/dist/cjs/lib/workspacePackageAliases.js +2 -8
  23. package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +20 -5
  24. package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +61 -0
  25. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +194 -14
  26. package/dist/cjs/runFeServer.js +2 -1
  27. package/dist/cjs/utils.js +2 -1
  28. package/dist/devFeServer.d.ts +1 -0
  29. package/dist/devFeServer.js +2 -1
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +4 -0
  33. package/dist/lib/getMergedConfig.d.ts.map +1 -1
  34. package/dist/lib/getMergedConfig.js +12 -4
  35. package/dist/lib/workspacePackageAliases.d.ts.map +1 -1
  36. package/dist/lib/workspacePackageAliases.js +2 -8
  37. package/dist/plugins/vite-plugin-cedar-entry-injection.d.ts.map +1 -1
  38. package/dist/plugins/vite-plugin-cedar-entry-injection.js +20 -5
  39. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.d.ts +15 -0
  40. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.d.ts.map +1 -0
  41. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +37 -0
  42. package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -1
  43. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +194 -14
  44. package/dist/runFeServer.d.ts +1 -0
  45. package/dist/runFeServer.d.ts.map +1 -1
  46. package/dist/runFeServer.js +2 -1
  47. package/dist/utils.d.ts.map +1 -1
  48. package/dist/utils.js +2 -1
  49. package/package.json +30 -60
  50. package/dist/buildUDApiServer.d.ts +0 -24
  51. package/dist/buildUDApiServer.d.ts.map +0 -1
  52. package/dist/buildUDApiServer.js +0 -41
  53. package/dist/cjs/buildUDApiServer.js +0 -75
  54. package/dist/cjs/ud-handlers/catch-all.js +0 -65
  55. package/dist/cjs/ud-handlers/function.js +0 -47
  56. package/dist/cjs/ud-handlers/graphql.js +0 -59
  57. package/dist/ud-handlers/catch-all.d.ts +0 -15
  58. package/dist/ud-handlers/catch-all.d.ts.map +0 -1
  59. package/dist/ud-handlers/catch-all.js +0 -41
  60. package/dist/ud-handlers/function.d.ts +0 -5
  61. package/dist/ud-handlers/function.d.ts.map +0 -1
  62. package/dist/ud-handlers/function.js +0 -23
  63. package/dist/ud-handlers/graphql.d.ts +0 -7
  64. package/dist/ud-handlers/graphql.d.ts.map +0 -1
  65. package/dist/ud-handlers/graphql.js +0 -35
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var vite_plugin_cedar_remove_dev_fatal_error_page_exports = {};
20
+ __export(vite_plugin_cedar_remove_dev_fatal_error_page_exports, {
21
+ cedarRemoveDevFatalErrorPage: () => cedarRemoveDevFatalErrorPage
22
+ });
23
+ module.exports = __toCommonJS(vite_plugin_cedar_remove_dev_fatal_error_page_exports);
24
+ const DEV_FATAL_ERROR_PAGE_MODULE = "@cedarjs/web/dist/components/DevFatalErrorPage";
25
+ function escapeRegExp(s) {
26
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
27
+ }
28
+ const ESCAPED_MODULE = escapeRegExp(DEV_FATAL_ERROR_PAGE_MODULE);
29
+ const IMPORT_PATTERN = new RegExp(
30
+ `import\\s*\\{[^}]*\\bDevFatalErrorPage\\b[^}]*\\}\\s*from\\s*['"]${ESCAPED_MODULE}['"]`
31
+ );
32
+ function cedarRemoveDevFatalErrorPage() {
33
+ let config;
34
+ return {
35
+ name: "cedar-remove-dev-fatal-error-page",
36
+ apply: "build",
37
+ configResolved(resolvedConfig) {
38
+ config = resolvedConfig;
39
+ },
40
+ transform(code) {
41
+ if (config.command === "build" && config.mode === "development") {
42
+ return null;
43
+ }
44
+ if (!code.includes(DEV_FATAL_ERROR_PAGE_MODULE)) {
45
+ return null;
46
+ }
47
+ const newCode = code.replace(
48
+ IMPORT_PATTERN,
49
+ "const DevFatalErrorPage = undefined"
50
+ );
51
+ if (newCode === code) {
52
+ return null;
53
+ }
54
+ return { code: newCode, map: null };
55
+ }
56
+ };
57
+ }
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ cedarRemoveDevFatalErrorPage
61
+ });
@@ -97,25 +97,39 @@ function toEntryMeta(route) {
97
97
  };
98
98
  }
99
99
  function cedarUniversalDeployPlugin(options = {}) {
100
- const { apiRootPath } = options;
101
- const routes = discoverCedarRoutes(apiRootPath ?? "/");
102
- let entriesInjected = false;
100
+ const effectiveApiRootPath = process.env.CEDAR_API_ROOT_PATH ?? options.apiRootPath;
101
+ const routes = discoverCedarRoutes(effectiveApiRootPath ?? "/");
103
102
  return {
104
103
  name: "cedar-universal-deploy",
105
104
  apply: "build",
106
105
  config: {
107
106
  order: "pre",
108
107
  handler() {
109
- if (entriesInjected) {
110
- return;
111
- }
112
- entriesInjected = true;
113
108
  for (const route of routes) {
114
109
  (0, import_store.addEntry)(toEntryMeta(route));
115
110
  }
116
111
  }
117
112
  },
113
+ buildStart() {
114
+ if (this.environment.name !== "ssr") {
115
+ return;
116
+ }
117
+ for (const route of routes) {
118
+ const resolvedId = RESOLVED_CEDAR_FN_PREFIX + route.id;
119
+ const safeName = route.id.replace(/[/\\?%*:|"<>]/g, "_").replace(/^_+/, "");
120
+ this.emitFile({
121
+ type: "chunk",
122
+ id: resolvedId,
123
+ // Emit the functions into a sub-dir to "hide" them from Netlify
124
+ fileName: "chunks/" + safeName + "-handler.js"
125
+ });
126
+ }
127
+ },
118
128
  resolveId(id) {
129
+ const viteEnv = this.environment;
130
+ if (viteEnv.config.consumer === "client" || viteEnv.name === "api") {
131
+ return void 0;
132
+ }
119
133
  if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
120
134
  return id;
121
135
  }
@@ -124,7 +138,11 @@ function cedarUniversalDeployPlugin(options = {}) {
124
138
  }
125
139
  return void 0;
126
140
  },
127
- load(id) {
141
+ async load(id) {
142
+ const viteEnv = this.environment;
143
+ if (viteEnv.config.consumer === "client" || viteEnv.name === "api") {
144
+ return void 0;
145
+ }
128
146
  if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
129
147
  const routeId = id.slice(RESOLVED_CEDAR_FN_PREFIX.length);
130
148
  const route = routes.find((r) => r.id === routeId);
@@ -140,16 +158,178 @@ function cedarUniversalDeployPlugin(options = {}) {
140
158
  }
141
159
  };
142
160
  }
143
- function generateGraphQLModule(distPath) {
161
+ async function bundleDistFile(distPath, options = {}) {
162
+ const { build } = await import("esbuild");
163
+ const buildOptions = {
164
+ bundle: true,
165
+ write: false,
166
+ format: "esm",
167
+ platform: "node",
168
+ target: "node24",
169
+ plugins: [
170
+ {
171
+ name: "ud-external",
172
+ setup(build2) {
173
+ build2.onResolve({ filter: /^[^.]/ }, (args) => {
174
+ if (import_node_path.default.isAbsolute(args.path)) {
175
+ return;
176
+ }
177
+ if (args.path.startsWith("api/")) {
178
+ return;
179
+ }
180
+ return { external: true };
181
+ });
182
+ }
183
+ }
184
+ ],
185
+ logLevel: "silent"
186
+ };
187
+ if (options.include && options.include.length > 0) {
188
+ const resolveDir = import_node_path.default.dirname(distPath);
189
+ const relativeDistPath = "./" + import_node_path.default.basename(distPath);
190
+ const exportList = options.include.join(", ");
191
+ buildOptions.stdin = {
192
+ // Use stdin to define a synthetic entry point that exports only the
193
+ // requested named exports
194
+ contents: `export { ${exportList} } from ${JSON.stringify(relativeDistPath)}`,
195
+ resolveDir,
196
+ loader: "js"
197
+ };
198
+ } else {
199
+ buildOptions.entryPoints = [distPath];
200
+ }
201
+ const result = await build(buildOptions);
202
+ if (!result.outputFiles || result.outputFiles.length === 0) {
203
+ throw new Error("esbuild bundle produced no output files");
204
+ }
205
+ let text = result.outputFiles[0].text;
206
+ const exportBlock = text.match(/\nexport\s*\{([^}]*)\};\s*$/);
207
+ if (exportBlock) {
208
+ const defaultExportMatch = exportBlock[1].match(
209
+ /(?:^|,)\s*(\w+)\s+as\s+default\s*(?:,|$)/
210
+ );
211
+ if (defaultExportMatch) {
212
+ const defaultBinding = defaultExportMatch[1];
213
+ text = text.replace(/\nexport\s*\{[^}]*\};\s*$/, "") + `
214
+ const __cedar_default = ${defaultBinding};`;
215
+ } else {
216
+ text = text.replace(/\nexport\s*\{[^}]*\};\s*$/, "");
217
+ }
218
+ }
219
+ return text;
220
+ }
221
+ async function generateGraphQLModule(distPath) {
222
+ const bundledCode = await bundleDistFile(distPath, {
223
+ include: ["__cedar_graphqlOptions"]
224
+ });
144
225
  return `
145
- import { createGraphQLHandler } from '@cedarjs/vite/ud-handlers/graphql';
146
- export default createGraphQLHandler({ distPath: ${JSON.stringify(distPath)} });
226
+ import { buildCedarContext, requestToLegacyEvent } from '@cedarjs/api/runtime';
227
+ import { createGraphQLYoga } from '@cedarjs/graphql-server';
228
+
229
+ // Inlined bundle of ${import_node_path.default.basename(distPath)} (node_modules kept external)
230
+ ${bundledCode}
231
+
232
+ let yogaInitPromise = null;
233
+
234
+ function getYoga() {
235
+ if (!yogaInitPromise) {
236
+ yogaInitPromise = createGraphQLYoga(__cedar_graphqlOptions).then(
237
+ ({ yoga }) => ({ yoga, graphqlOptions: __cedar_graphqlOptions })
238
+ );
239
+ }
240
+ return yogaInitPromise;
241
+ }
242
+
243
+ export default {
244
+ async fetch(request) {
245
+ const { yoga, graphqlOptions } = await getYoga();
246
+ const cedarContext = await buildCedarContext(request, {
247
+ authDecoder: graphqlOptions ? graphqlOptions.authDecoder : undefined,
248
+ });
249
+ const event = await requestToLegacyEvent(request, cedarContext);
250
+ // Wrap yoga.handle in an AsyncLocalStorage run so directive
251
+ // validators can read from the global @cedarjs/context. Without
252
+ // this, the auth plugin's setContext() call writes to a store
253
+ // that's only visible inside the plugin's own callback \u2014 not
254
+ // during directive validation.
255
+ const { getAsyncStoreInstance } = await import('@cedarjs/context/dist/store')
256
+ const store = getAsyncStoreInstance()
257
+
258
+ return store.run(new Map(), () => {
259
+ return yoga.handle(request, {
260
+ request,
261
+ cedarContext,
262
+ event,
263
+ requestContext: undefined,
264
+ })
265
+ }).then((response) => {
266
+ // GraphQL Yoga returns a PonyfillResponse from @whatwg-node/fetch
267
+ // which is not an instanceof the native Response class. Netlify's
268
+ // bootstrap checks instanceof Response, so we wrap it.
269
+ return new Response(response.body, {
270
+ status: response.status,
271
+ statusText: response.statusText,
272
+ headers: response.headers,
273
+ })
274
+ }).catch((e) => {
275
+ if (e?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
276
+ // Client disconnected while the request was being processed (e.g.,
277
+ // page navigation, tab close). Return a 499 so the runtime doesn't
278
+ // treat this as a 500.
279
+ return new Response(null, { status: 499 })
280
+ }
281
+
282
+ throw e
283
+ })
284
+ }
285
+ };
147
286
  `;
148
287
  }
149
- function generateFunctionModule(distPath) {
288
+ async function generateFunctionModule(distPath) {
289
+ const bundledCode = await bundleDistFile(distPath);
290
+ const notFoundMsg = JSON.stringify(
291
+ `Handler not found in ${import_node_path.default.basename(distPath)}. Expected \`export async function handleRequest(request, ctx)\`, \`export default async (request, ctx) => Response\`, \`export default { handleRequest }\`, or a legacy Lambda-shaped \`handler\`.`
292
+ );
150
293
  return `
151
- import { createFunctionHandler } from '@cedarjs/vite/ud-handlers/function';
152
- export default createFunctionHandler({ distPath: ${JSON.stringify(distPath)} });
294
+ import { wrapLegacyHandler, buildCedarContext } from '@cedarjs/api/runtime';
295
+
296
+ // Inlined bundle of ${import_node_path.default.basename(distPath)} (node_modules kept external)
297
+ ${bundledCode}
298
+
299
+ const nativeHandler = (() => {
300
+ // Prefer named handleRequest export
301
+ if (typeof handleRequest !== 'undefined') { return handleRequest; }
302
+ // Handle export default { handleRequest } pattern
303
+ if (typeof __cedar_default !== 'undefined' && __cedar_default && typeof __cedar_default.handleRequest === 'function') {
304
+ return __cedar_default.handleRequest;
305
+ }
306
+ // Handle plain default-exported async function: export default async (req) => Response
307
+ if (typeof __cedar_default !== 'undefined' && typeof __cedar_default === 'function') {
308
+ return __cedar_default;
309
+ }
310
+ return undefined;
311
+ })();
312
+
313
+ const legacyFn = (() => {
314
+ if (typeof handler !== 'undefined') { return handler; }
315
+ if (typeof __cedar_default !== 'undefined' && __cedar_default && typeof __cedar_default.handler === 'function') {
316
+ return __cedar_default.handler;
317
+ }
318
+ return undefined;
319
+ })();
320
+
321
+ if (!nativeHandler && !legacyFn) {
322
+ throw new Error(${notFoundMsg});
323
+ }
324
+
325
+ const _handler = nativeHandler ?? wrapLegacyHandler(legacyFn);
326
+
327
+ export default {
328
+ async fetch(request) {
329
+ const ctx = await buildCedarContext(request);
330
+ return _handler(request, ctx);
331
+ }
332
+ };
153
333
  `;
154
334
  }
155
335
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
@@ -74,7 +75,7 @@ async function runFeServer() {
74
75
  import_node_path.default.join(rwPaths.web.distBrowser, "client-build-manifest.json")
75
76
  ).href;
76
77
  const clientBuildManifest = (await import(clientBuildManifestUrl, { with: { type: "json" } })).default;
77
- const clientEntry = rscEnabled ? clientBuildManifest["entry.client.tsx"] || clientBuildManifest["entry.client.jsx"] : Object.values(clientBuildManifest).find(
78
+ const clientEntry = rscEnabled ? clientBuildManifest["src/entry.client.tsx"] || clientBuildManifest["src/entry.client.jsx"] : Object.values(clientBuildManifest).find(
78
79
  (manifestItem) => manifestItem.isEntry
79
80
  );
80
81
  if (!clientEntry) {
package/dist/cjs/utils.js CHANGED
@@ -28,6 +28,7 @@ __export(utils_exports, {
28
28
  module.exports = __toCommonJS(utils_exports);
29
29
  var import_node_url = require("node:url");
30
30
  var import_project_config = require("@cedarjs/project-config");
31
+ var import_packageManager = require("@cedarjs/project-config/packageManager");
31
32
  function stripQueryStringAndHashFromPath(url) {
32
33
  return url.split("?")[0].split("#")[0];
33
34
  }
@@ -36,7 +37,7 @@ function ensureProcessDirWeb(webDir = (0, import_project_config.getPaths)().web.
36
37
  console.error("\u26A0\uFE0F Warning: CWD is ", process.cwd());
37
38
  console.warn("~".repeat(50));
38
39
  console.warn(
39
- "The cwd must be web/. Please use `yarn cedar <command>` or run the command from the web/ directory."
40
+ `The cwd must be web/. Please use \`${(0, import_packageManager.prettyPrintCedarCommand)(["<command>"])}\` or run the command from the web/ directory.`
40
41
  );
41
42
  console.log(`Changing cwd to ${webDir}....`);
42
43
  console.log();
@@ -1,2 +1,3 @@
1
+ #!/usr/bin/env node
1
2
  export {};
2
3
  //# sourceMappingURL=devFeServer.d.ts.map
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  import { createServerAdapter } from "@whatwg-node/server";
2
3
  import express from "express";
3
4
  import { createServer as createViteServer } from "vite";
@@ -40,7 +41,7 @@ async function createServer() {
40
41
  }
41
42
  if (!rwPaths.web.viteConfig) {
42
43
  throw new Error(
43
- "Vite config not found. You need to setup your project with Vite using `yarn cedar setup vite`"
44
+ "Vite config not found. Please set up Vite before running the dev server."
44
45
  );
45
46
  }
46
47
  const vite = await createViteServer({
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { cedarEntryInjectionPlugin } from './plugins/vite-plugin-cedar-entry-inj
6
6
  export { cedarHtmlEnvPlugin } from './plugins/vite-plugin-cedar-html-env.js';
7
7
  export { cedarImportDirPlugin } from './plugins/vite-plugin-cedar-import-dir.js';
8
8
  export { cedarNodePolyfills } from './plugins/vite-plugin-cedar-node-polyfills.js';
9
+ export { cedarRemoveDevFatalErrorPage } from './plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js';
9
10
  export { cedarRemoveFromBundle } from './plugins/vite-plugin-cedar-remove-from-bundle.js';
10
11
  export { cedarjsResolveCedarStyleImportsPlugin } from './plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js';
11
12
  export { cedarjsJobPathInjectorPlugin } from './plugins/vite-plugin-cedarjs-job-path-injector.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAqBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAA;AAE1F,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAyClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAsBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,4BAA4B,EAAE,MAAM,4DAA4D,CAAA;AACzG,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAA;AAE1F,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CA0ClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import { cedarCellTransform } from "./plugins/vite-plugin-cedar-cell.js";
10
10
  import { cedarEntryInjectionPlugin } from "./plugins/vite-plugin-cedar-entry-injection.js";
11
11
  import { cedarHtmlEnvPlugin } from "./plugins/vite-plugin-cedar-html-env.js";
12
12
  import { cedarNodePolyfills } from "./plugins/vite-plugin-cedar-node-polyfills.js";
13
+ import { cedarRemoveDevFatalErrorPage } from "./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js";
13
14
  import { cedarRemoveFromBundle } from "./plugins/vite-plugin-cedar-remove-from-bundle.js";
14
15
  import { cedarWaitForApiServer } from "./plugins/vite-plugin-cedar-wait-for-api-server.js";
15
16
  import { cedarjsResolveCedarStyleImportsPlugin } from "./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js";
@@ -23,6 +24,7 @@ import { cedarEntryInjectionPlugin as cedarEntryInjectionPlugin2 } from "./plugi
23
24
  import { cedarHtmlEnvPlugin as cedarHtmlEnvPlugin2 } from "./plugins/vite-plugin-cedar-html-env.js";
24
25
  import { cedarImportDirPlugin } from "./plugins/vite-plugin-cedar-import-dir.js";
25
26
  import { cedarNodePolyfills as cedarNodePolyfills2 } from "./plugins/vite-plugin-cedar-node-polyfills.js";
27
+ import { cedarRemoveDevFatalErrorPage as cedarRemoveDevFatalErrorPage2 } from "./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js";
26
28
  import { cedarRemoveFromBundle as cedarRemoveFromBundle2 } from "./plugins/vite-plugin-cedar-remove-from-bundle.js";
27
29
  import { cedarjsResolveCedarStyleImportsPlugin as cedarjsResolveCedarStyleImportsPlugin2 } from "./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js";
28
30
  import { cedarjsJobPathInjectorPlugin } from "./plugins/vite-plugin-cedarjs-job-path-injector.js";
@@ -61,6 +63,7 @@ function cedar({ mode } = {}) {
61
63
  cedarCellTransform(),
62
64
  cedarTransformJsAsJsx(),
63
65
  cedarRemoveFromBundle(),
66
+ cedarRemoveDevFatalErrorPage(),
64
67
  react({ babel: babelConfig })
65
68
  ];
66
69
  }
@@ -75,6 +78,7 @@ export {
75
78
  cedarImportDirPlugin,
76
79
  cedarMergedConfig2 as cedarMergedConfig,
77
80
  cedarNodePolyfills2 as cedarNodePolyfills,
81
+ cedarRemoveDevFatalErrorPage2 as cedarRemoveDevFatalErrorPage,
78
82
  cedarRemoveFromBundle2 as cedarRemoveFromBundle,
79
83
  cedarSwapApolloProvider2 as cedarSwapApolloProvider,
80
84
  cedarTransformJsAsJsx2 as cedarTransformJsAsJsx,
@@ -1 +1 @@
1
- {"version":3,"file":"getMergedConfig.d.ts","sourceRoot":"","sources":["../../src/lib/getMergedConfig.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAS5D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,IAC5D,YAAY,cAAc,EAAE,KAAK,SAAS,KAAG,cAAc,CAqHpE"}
1
+ {"version":3,"file":"getMergedConfig.d.ts","sourceRoot":"","sources":["../../src/lib/getMergedConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAS5D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,IAC5D,YAAY,cAAc,EAAE,KAAK,SAAS,KAAG,cAAc,CA4HpE"}
@@ -21,9 +21,14 @@ function getMergedConfig(cedarConfig, cedarPaths) {
21
21
  apiPort = cedarConfig.api.port;
22
22
  }
23
23
  const defaultCedarViteConfig = {
24
- root: cedarPaths.web.src,
24
+ root: cedarPaths.web.base,
25
25
  resolve: {
26
- alias: workspaceAliases
26
+ alias: {
27
+ ...workspaceAliases,
28
+ // In test mode, register the virtual module alias so that
29
+ // MockProviders can resolve the user's Routes file
30
+ ...env.mode === "test" ? { "~__CEDAR__USER_ROUTES_FOR_MOCK": cedarPaths.web.routes } : {}
31
+ }
27
32
  },
28
33
  // @MARK: when we have these aliases, the warnings from the FE server go
29
34
  // away BUT, if you have imports like this:
@@ -75,7 +80,7 @@ function getMergedConfig(cedarConfig, cedarPaths) {
75
80
  // Note that sourcemap can be boolean or 'inline'
76
81
  sourcemap: !env.isSsrBuild && cedarConfig.web.sourceMap,
77
82
  rollupOptions: {
78
- input: getRollupInput(!!env.isSsrBuild)
83
+ input: getRollupInput(userConfig, !!env.isSsrBuild)
79
84
  }
80
85
  },
81
86
  // @MARK: do not set buildSsrCjsExternalHeuristics here
@@ -108,9 +113,12 @@ function getMergedConfig(cedarConfig, cedarPaths) {
108
113
  return mergeConfig(defaultCedarViteConfig, userConfig);
109
114
  };
110
115
  }
111
- function getRollupInput(ssr) {
116
+ function getRollupInput(userConfig, ssr) {
112
117
  const cedarConfig = getConfig();
113
118
  const cedarPaths = getPaths();
119
+ if (userConfig.build?.rollupOptions?.input) {
120
+ return userConfig.build.rollupOptions.input;
121
+ }
114
122
  if (!cedarPaths.web.entryClient) {
115
123
  throw new Error("entryClient not defined");
116
124
  }
@@ -1 +1 @@
1
- {"version":3,"file":"workspacePackageAliases.d.ts","sourceRoot":"","sources":["../../src/lib/workspacePackageAliases.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AA2D5D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,KAAK,EACjB,WAAW,EAAE,MAAM,GAClB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiExB"}
1
+ {"version":3,"file":"workspacePackageAliases.d.ts","sourceRoot":"","sources":["../../src/lib/workspacePackageAliases.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AA4D5D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,KAAK,EACjB,WAAW,EAAE,MAAM,GAClB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoDxB"}
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { normalizePath } from "vite";
4
+ import { getNonApiWebWorkspaces } from "@cedarjs/project-config/workspaces";
4
5
  function findSourceEntry(pkgDir, pkgJson) {
5
6
  let distEntry = null;
6
7
  if (typeof pkgJson.main === "string") {
@@ -38,14 +39,7 @@ function getWorkspacePackageAliases(cedarPaths, cedarConfig) {
38
39
  return {};
39
40
  }
40
41
  try {
41
- const rootPkgPath = path.join(cedarPaths.base, "package.json");
42
- const rootPkg = JSON.parse(fs.readFileSync(rootPkgPath, "utf-8"));
43
- if (!Array.isArray(rootPkg.workspaces) || rootPkg.workspaces.length <= 2) {
44
- return {};
45
- }
46
- const nonApiWebWorkspaces = rootPkg.workspaces.filter(
47
- (w) => w !== "api" && w !== "web"
48
- );
42
+ const nonApiWebWorkspaces = getNonApiWebWorkspaces(cedarPaths.base);
49
43
  if (nonApiWebWorkspaces.length === 0) {
50
44
  return {};
51
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-cedar-entry-injection.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-entry-injection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC,wBAAgB,yBAAyB,IAAI,MAAM,CA6DlD"}
1
+ {"version":3,"file":"vite-plugin-cedar-entry-injection.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-entry-injection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC,wBAAgB,yBAAyB,IAAI,MAAM,CAqFlD"}
@@ -3,21 +3,36 @@ import path from "node:path";
3
3
  import { normalizePath } from "vite";
4
4
  import { getPaths } from "@cedarjs/project-config";
5
5
  function cedarEntryInjectionPlugin() {
6
- const rwPaths = getPaths();
7
- const clientEntryPath = rwPaths.web.entryClient;
6
+ const cedarPaths = getPaths();
7
+ const clientEntryPath = cedarPaths.web.entryClient;
8
8
  if (!clientEntryPath) {
9
9
  throw new Error(
10
10
  "Vite client entry point not found. Please check that your project has an entry.client.{jsx,tsx} file in the web/src directory."
11
11
  );
12
12
  }
13
- const relativeEntryPath = path.relative(rwPaths.web.src, clientEntryPath);
13
+ const relativeEntryPath = normalizePath(
14
+ path.relative(cedarPaths.web.base, clientEntryPath)
15
+ );
14
16
  return {
15
17
  name: "cedar-entry-injection",
18
+ // Vite's dependency optimizer and dev server resolve the script tag
19
+ // src="/src/entry.client.{tsx,jsx}" as an absolute filesystem path
20
+ // (/src/entry.client.tsx) instead of relative to the Vite root.
21
+ // This hook maps it to the real file path so Vite can find it.
22
+ resolveId(id) {
23
+ if (id === "/" + relativeEntryPath) {
24
+ return clientEntryPath;
25
+ }
26
+ return null;
27
+ },
16
28
  // ---------- Bundle injection ----------
17
29
  // Used by Vite during dev, to inject the entrypoint.
18
30
  transformIndexHtml: {
19
31
  order: "pre",
20
- handler: (html) => {
32
+ handler: (html, ctx) => {
33
+ if (!ctx.filename || normalizePath(ctx.filename) !== normalizePath(cedarPaths.web.html)) {
34
+ return html;
35
+ }
21
36
  if (fs.existsSync(clientEntryPath)) {
22
37
  return html.replace(
23
38
  "</head>",
@@ -34,7 +49,7 @@ function cedarEntryInjectionPlugin() {
34
49
  // Used by rollup during build to inject the entrypoint
35
50
  // but note index.html does not come through as an id during dev
36
51
  transform: (code, id) => {
37
- if (fs.existsSync(clientEntryPath) && normalizePath(id) === normalizePath(rwPaths.web.html)) {
52
+ if (fs.existsSync(clientEntryPath) && normalizePath(id) === normalizePath(cedarPaths.web.html)) {
38
53
  return {
39
54
  code: code.replace(
40
55
  "</head>",
@@ -0,0 +1,15 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Vite plugin to remove the DevFatalErrorPage import in production builds.
4
+ *
5
+ * Replaces:
6
+ * import { DevFatalErrorPage } from '@cedarjs/web/dist/components/DevFatalErrorPage'
7
+ * with:
8
+ * const DevFatalErrorPage = undefined
9
+ *
10
+ * This ensures the DevFatalErrorPage component is not shipped in the
11
+ * production bundle. In development, the import is kept so the page
12
+ * renders when an unhandled error bubbles to the top of the app.
13
+ */
14
+ export declare function cedarRemoveDevFatalErrorPage(): Plugin;
15
+ //# sourceMappingURL=vite-plugin-cedar-remove-dev-fatal-error-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-remove-dev-fatal-error-page.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAA;AAclD;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAgCrD"}
@@ -0,0 +1,37 @@
1
+ const DEV_FATAL_ERROR_PAGE_MODULE = "@cedarjs/web/dist/components/DevFatalErrorPage";
2
+ function escapeRegExp(s) {
3
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4
+ }
5
+ const ESCAPED_MODULE = escapeRegExp(DEV_FATAL_ERROR_PAGE_MODULE);
6
+ const IMPORT_PATTERN = new RegExp(
7
+ `import\\s*\\{[^}]*\\bDevFatalErrorPage\\b[^}]*\\}\\s*from\\s*['"]${ESCAPED_MODULE}['"]`
8
+ );
9
+ function cedarRemoveDevFatalErrorPage() {
10
+ let config;
11
+ return {
12
+ name: "cedar-remove-dev-fatal-error-page",
13
+ apply: "build",
14
+ configResolved(resolvedConfig) {
15
+ config = resolvedConfig;
16
+ },
17
+ transform(code) {
18
+ if (config.command === "build" && config.mode === "development") {
19
+ return null;
20
+ }
21
+ if (!code.includes(DEV_FATAL_ERROR_PAGE_MODULE)) {
22
+ return null;
23
+ }
24
+ const newCode = code.replace(
25
+ IMPORT_PATTERN,
26
+ "const DevFatalErrorPage = undefined"
27
+ );
28
+ if (newCode === code) {
29
+ return null;
30
+ }
31
+ return { code: newCode, map: null };
32
+ }
33
+ };
34
+ }
35
+ export {
36
+ cedarRemoveDevFatalErrorPage
37
+ };
@@ -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;AA6GD,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iCAAsC,GAC9C,MAAM,CA4DR"}
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,CA0GR"}