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

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 (73) 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 +151 -26
  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 +154 -29
  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 +18 -8
  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-context-wrapping.js +95 -0
  24. package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +20 -5
  25. package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +61 -0
  26. package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +126 -0
  27. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +202 -14
  28. package/dist/cjs/runFeServer.js +2 -1
  29. package/dist/cjs/utils.js +2 -1
  30. package/dist/devFeServer.d.ts +1 -0
  31. package/dist/devFeServer.js +2 -1
  32. package/dist/index.d.ts +4 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +14 -8
  35. package/dist/lib/getMergedConfig.d.ts.map +1 -1
  36. package/dist/lib/getMergedConfig.js +12 -4
  37. package/dist/lib/workspacePackageAliases.d.ts.map +1 -1
  38. package/dist/lib/workspacePackageAliases.js +2 -8
  39. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts +44 -0
  40. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +1 -0
  41. package/dist/plugins/vite-plugin-cedar-context-wrapping.js +60 -0
  42. package/dist/plugins/vite-plugin-cedar-entry-injection.d.ts.map +1 -1
  43. package/dist/plugins/vite-plugin-cedar-entry-injection.js +20 -5
  44. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.d.ts +15 -0
  45. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.d.ts.map +1 -0
  46. package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +37 -0
  47. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts +24 -0
  48. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.d.ts.map +1 -0
  49. package/dist/plugins/vite-plugin-cedar-routes-auto-loader.js +98 -0
  50. package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -1
  51. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +202 -14
  52. package/dist/runFeServer.d.ts +1 -0
  53. package/dist/runFeServer.d.ts.map +1 -1
  54. package/dist/runFeServer.js +2 -1
  55. package/dist/utils.d.ts.map +1 -1
  56. package/dist/utils.js +2 -1
  57. package/package.json +31 -61
  58. package/dist/buildUDApiServer.d.ts +0 -24
  59. package/dist/buildUDApiServer.d.ts.map +0 -1
  60. package/dist/buildUDApiServer.js +0 -41
  61. package/dist/cjs/buildUDApiServer.js +0 -75
  62. package/dist/cjs/ud-handlers/catch-all.js +0 -65
  63. package/dist/cjs/ud-handlers/function.js +0 -47
  64. package/dist/cjs/ud-handlers/graphql.js +0 -59
  65. package/dist/ud-handlers/catch-all.d.ts +0 -15
  66. package/dist/ud-handlers/catch-all.d.ts.map +0 -1
  67. package/dist/ud-handlers/catch-all.js +0 -41
  68. package/dist/ud-handlers/function.d.ts +0 -5
  69. package/dist/ud-handlers/function.d.ts.map +0 -1
  70. package/dist/ud-handlers/function.js +0 -23
  71. package/dist/ud-handlers/graphql.d.ts +0 -7
  72. package/dist/ud-handlers/graphql.d.ts.map +0 -1
  73. package/dist/ud-handlers/graphql.js +0 -35
@@ -33,11 +33,14 @@ __export(buildApp_exports, {
33
33
  module.exports = __toCommonJS(buildApp_exports);
34
34
  var import_node_fs = __toESM(require("node:fs"), 1);
35
35
  var import_node_path = __toESM(require("node:path"), 1);
36
- var import_vite = require("vite");
36
+ var import_store = require("@universal-deploy/store");
37
+ var import_vite = require("@universal-deploy/vite");
38
+ var import_vite2 = require("vite");
37
39
  var import_babel_config = require("@cedarjs/babel-config");
38
40
  var import_files = require("@cedarjs/internal/dist/files.js");
39
41
  var import_project_config = require("@cedarjs/project-config");
40
42
  var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
43
+ var import_vite_plugin_cedar_context_wrapping = require("./plugins/vite-plugin-cedar-context-wrapping.js");
41
44
  function resolveWithExtensions(id) {
42
45
  if (import_node_fs.default.existsSync(id)) {
43
46
  return id;
@@ -52,7 +55,8 @@ function resolveWithExtensions(id) {
52
55
  }
53
56
  async function buildCedarApp({
54
57
  verbose = false,
55
- workspace = ["api", "web"]
58
+ workspace = ["api", "web"],
59
+ ud = false
56
60
  } = {}) {
57
61
  const cedarPaths = (0, import_project_config.getPaths)();
58
62
  const cedarConfig = (0, import_project_config.getConfig)();
@@ -85,13 +89,13 @@ async function buildCedarApp({
85
89
  format,
86
90
  preserveModules: true,
87
91
  preserveModulesRoot: cedarPaths.api.src,
88
- entryFileNames: "[name].js"
92
+ entryFileNames: "[name].js",
93
+ exports: "named"
89
94
  },
90
95
  external: (id) => {
91
96
  if (id.startsWith("node:")) {
92
97
  return true;
93
- }
94
- if (!id.startsWith(".") && !import_node_path.default.isAbsolute(id)) {
98
+ } else if (!id.startsWith(".") && !import_node_path.default.isAbsolute(id)) {
95
99
  return true;
96
100
  }
97
101
  return false;
@@ -99,6 +103,31 @@ async function buildCedarApp({
99
103
  }
100
104
  }
101
105
  };
106
+ if (ud) {
107
+ environments["ssr"] = {
108
+ build: {
109
+ ssr: true,
110
+ outDir: import_node_path.default.join(cedarPaths.api.dist, "ud"),
111
+ emptyOutDir: true,
112
+ rollupOptions: {
113
+ input: import_store.catchAllEntry,
114
+ output: {
115
+ entryFileNames: "index.js"
116
+ },
117
+ external: (id) => {
118
+ if (id.startsWith("virtual:")) {
119
+ return false;
120
+ } else if (id.startsWith("node:")) {
121
+ return true;
122
+ } else if (!id.startsWith(".") && !import_node_path.default.isAbsolute(id)) {
123
+ return true;
124
+ }
125
+ return false;
126
+ }
127
+ }
128
+ }
129
+ };
130
+ }
102
131
  }
103
132
  const babelPlugins = workspace.includes("api") ? (0, import_babel_config.getApiSideBabelPlugins)({
104
133
  openTelemetry: (cedarConfig.experimental?.opentelemetry?.enabled ?? false) && (cedarConfig.experimental?.opentelemetry?.wrapApi ?? false),
@@ -106,10 +135,45 @@ async function buildCedarApp({
106
135
  }) : null;
107
136
  const workspacePkgSourceMap = workspace.includes("api") ? Object.fromEntries(
108
137
  Object.entries((0, import_workspacePackageAliases.getWorkspacePackageAliases)(cedarPaths, cedarConfig)).map(
109
- ([name, sourceFile]) => [name, (0, import_vite.normalizePath)(sourceFile)]
138
+ ([name, sourceFile]) => [name, (0, import_vite2.normalizePath)(sourceFile)]
110
139
  )
111
140
  ) : {};
112
141
  const plugins = [
142
+ // Suppress noisy warnings from third-party dependencies across all
143
+ // environments by injecting onwarn into every environment's rollupOptions.
144
+ {
145
+ name: "cedar-suppress-third-party-warnings",
146
+ configResolved(config) {
147
+ function onwarn(warning, warn) {
148
+ if (warning.code === "EVAL" && warning.id?.includes("@prisma/internals")) {
149
+ return;
150
+ }
151
+ if (warning.code === "INVALID_ANNOTATION" && warning.id?.includes("graphql-scalars")) {
152
+ return;
153
+ }
154
+ warn(warning);
155
+ }
156
+ for (const env of Object.values(config.environments ?? {})) {
157
+ env.build.rollupOptions ??= {};
158
+ const existingOnwarn = env.build.rollupOptions.onwarn;
159
+ env.build.rollupOptions.onwarn = existingOnwarn ? (warning, warn) => {
160
+ onwarn(warning, (w) => existingOnwarn(w, warn));
161
+ } : onwarn;
162
+ }
163
+ }
164
+ },
165
+ // Resolve bare-specifier dynamic imports from node_modules as external
166
+ // before Rollup attempts resolution, avoiding UNRESOLVED_IMPORT warnings
167
+ // for optional peer dependencies (e.g. @simplewebauthn/server).
168
+ {
169
+ name: "cedar-optional-peer-deps",
170
+ resolveDynamicImport(specifier, importer) {
171
+ if (typeof specifier === "string" && !specifier.startsWith(".") && !specifier.startsWith("/") && importer?.includes("node_modules") && this.environment.config.consumer === "server") {
172
+ return { id: specifier, external: true };
173
+ }
174
+ return null;
175
+ }
176
+ },
113
177
  {
114
178
  name: "cedar-build-app-cleanup",
115
179
  configResolved(config) {
@@ -120,8 +184,58 @@ async function buildCedarApp({
120
184
  delete config.environments.ssr;
121
185
  }
122
186
  }
187
+ },
188
+ {
189
+ name: "cedar-build-app",
190
+ buildApp: {
191
+ order: "pre",
192
+ async handler(builder2) {
193
+ if (workspace.includes("web") && builder2.environments.client && !builder2.environments.client.isBuilt) {
194
+ await builder2.build(builder2.environments.client);
195
+ }
196
+ if (workspace.includes("api") && builder2.environments.api && !builder2.environments.api.isBuilt) {
197
+ await builder2.build(builder2.environments.api);
198
+ }
199
+ if (workspace.includes("api") && builder2.environments["ssr"] && !builder2.environments["ssr"].isBuilt) {
200
+ await builder2.build(builder2.environments["ssr"]);
201
+ }
202
+ }
203
+ }
123
204
  }
124
205
  ];
206
+ if (ud) {
207
+ plugins.push((0, import_vite.catchAll)());
208
+ plugins.push({
209
+ name: "cedar-ud-verify-routes",
210
+ configResolved() {
211
+ const entries = (0, import_store.getAllEntries)();
212
+ if (entries.length === 0) {
213
+ console.warn(
214
+ "\n",
215
+ " Warning: No Universal Deploy API routes were registered.\n",
216
+ " The built server entry will be an empty router (404 for all\n",
217
+ " requests). Check that you have API functions under\n",
218
+ " `api/src/functions/` and that your vite config includes\n",
219
+ " `cedarUniversalDeployPlugin()`.\n"
220
+ );
221
+ }
222
+ }
223
+ });
224
+ plugins.push({
225
+ name: "cedar-ud-write-package-json",
226
+ applyToEnvironment(env) {
227
+ return env.name === "ssr";
228
+ },
229
+ closeBundle() {
230
+ const dir = import_node_path.default.join(cedarPaths.api.dist, "ud");
231
+ import_node_fs.default.mkdirSync(dir, { recursive: true });
232
+ import_node_fs.default.writeFileSync(
233
+ import_node_path.default.join(dir, "package.json"),
234
+ JSON.stringify({ type: "module" }, null, 2)
235
+ );
236
+ }
237
+ });
238
+ }
125
239
  if (workspace.includes("api")) {
126
240
  plugins.push({
127
241
  name: "cedar-api-src-redirect",
@@ -138,32 +252,43 @@ async function buildCedarApp({
138
252
  return null;
139
253
  }
140
254
  });
141
- if (babelPlugins) {
142
- plugins.push({
143
- name: "cedar-vite-api-babel-transform",
144
- async transform(_code, id) {
145
- if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
146
- return null;
147
- }
148
- if (id.includes("node_modules")) {
149
- return null;
150
- }
151
- if (!(0, import_vite.normalizePath)(id).startsWith((0, import_vite.normalizePath)(cedarPaths.api.base))) {
152
- return null;
153
- }
154
- const transformedCode = await (0, import_babel_config.transformWithBabel)(id, babelPlugins);
155
- if (transformedCode?.code) {
156
- return {
157
- code: transformedCode.code,
158
- map: transformedCode.map ?? null
159
- };
160
- }
255
+ }
256
+ if (workspace.includes("api")) {
257
+ plugins.push(
258
+ (0, import_vite_plugin_cedar_context_wrapping.cedarContextWrappingPlugin)({ projectIsEsm: (0, import_project_config.projectSideIsEsm)("api") })
259
+ );
260
+ }
261
+ if (babelPlugins) {
262
+ plugins.push({
263
+ name: "cedar-vite-api-babel-transform",
264
+ enforce: "pre",
265
+ async transform(code, id) {
266
+ if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
161
267
  return null;
162
268
  }
163
- });
164
- }
269
+ if (id.includes("node_modules")) {
270
+ return null;
271
+ }
272
+ if (!(0, import_vite2.normalizePath)(id).startsWith((0, import_vite2.normalizePath)(cedarPaths.api.base))) {
273
+ return null;
274
+ }
275
+ const transformedCode = await (0, import_babel_config.transformWithBabel)(
276
+ code,
277
+ id,
278
+ babelPlugins,
279
+ true
280
+ );
281
+ if (transformedCode?.code) {
282
+ return {
283
+ code: transformedCode.code,
284
+ map: transformedCode.map ?? null
285
+ };
286
+ }
287
+ return null;
288
+ }
289
+ });
165
290
  }
166
- const builder = await (0, import_vite.createBuilder)({
291
+ const builder = await (0, import_vite2.createBuilder)({
167
292
  configFile: cedarPaths.web.viteConfig,
168
293
  envFile: false,
169
294
  logLevel: verbose ? "info" : "warn",
@@ -37,7 +37,7 @@ const buildFeServer = async ({ verbose, webDir } = {}) => {
37
37
  const streamingSsrEnabled = rwConfig.experimental?.streamingSsr?.enabled;
38
38
  if (!viteConfigPath) {
39
39
  throw new Error(
40
- "Vite config not found. You need to setup your project with Vite using `yarn cedar setup vite`"
40
+ "Vite config not found. Please set up Vite before building."
41
41
  );
42
42
  }
43
43
  if (!rwPaths.web.entryServer || !rwPaths.web.entryClient) {
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,12 +17,21 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var buildRouteHooks_exports = {};
20
30
  __export(buildRouteHooks_exports, {
21
31
  buildRouteHooks: () => buildRouteHooks
22
32
  });
23
33
  module.exports = __toCommonJS(buildRouteHooks_exports);
34
+ var import_node_fs = __toESM(require("node:fs"), 1);
24
35
  var import_esbuild = require("esbuild");
25
36
  var import_babel_config = require("@cedarjs/babel-config");
26
37
  var import_files = require("@cedarjs/internal/dist/files.js");
@@ -31,9 +42,12 @@ async function buildRouteHooks(verbose, rwPaths) {
31
42
  name: "rw-esbuild-babel-transform",
32
43
  setup(build) {
33
44
  build.onLoad({ filter: /\.(js|ts|tsx|jsx)$/ }, async (args) => {
34
- const transformedCode = await (0, import_babel_config.transformWithBabel)(args.path, [
35
- ...(0, import_babel_config.getRouteHookBabelPlugins)()
36
- ]);
45
+ const fileContents = await import_node_fs.default.promises.readFile(args.path, "utf-8");
46
+ const transformedCode = await (0, import_babel_config.transformWithBabel)(
47
+ fileContents,
48
+ args.path,
49
+ [...(0, import_babel_config.getRouteHookBabelPlugins)()]
50
+ );
37
51
  if (transformedCode?.code) {
38
52
  return {
39
53
  contents: transformedCode.code,
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  "use strict";
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
@@ -6,6 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
6
  var __getProtoOf = Object.getPrototypeOf;
8
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
9
12
  var __copyProps = (to, from, except, desc) => {
10
13
  if (from && typeof from === "object" || typeof from === "function") {
11
14
  for (let key of __getOwnPropNames(from))
@@ -22,6 +25,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
26
  mod
24
27
  ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var cedar_unified_dev_exports = {};
30
+ __export(cedar_unified_dev_exports, {
31
+ openDebugger: () => openDebugger,
32
+ parseCliArgs: () => parseCliArgs,
33
+ startUnifiedDevServer: () => startUnifiedDevServer
34
+ });
35
+ module.exports = __toCommonJS(cedar_unified_dev_exports);
25
36
  var import_server = require("@whatwg-node/server");
26
37
  var import_vite = require("vite");
27
38
  var import_yargs_parser = __toESM(require("yargs-parser"), 1);
@@ -34,25 +45,180 @@ function isViteInternalRequest(url) {
34
45
  function isApiRequest(url, apiUrl, apiGqlUrl) {
35
46
  return url === apiUrl || url.startsWith(apiUrl + "/") || url.startsWith(apiUrl + "?") || url === apiGqlUrl || url.startsWith(apiGqlUrl + "/") || url.startsWith(apiGqlUrl + "?");
36
47
  }
37
- const startUnifiedDevServer = async () => {
38
- process.env.__CEDAR_UNIFIED_DEV = "true";
39
- const rwPaths = (0, import_project_config.getPaths)();
40
- const cedarConfig = (0, import_project_config.getConfig)();
41
- const configFile = rwPaths.web.viteConfig;
42
- if (!configFile) {
43
- throw new Error("Could not locate your web/vite.config.{js,ts} file");
44
- }
48
+ function parseCliArgs(argv = process.argv) {
45
49
  const {
46
50
  force: forceOptimize,
47
51
  debug,
48
52
  port: portArg,
49
53
  apiPort: _apiPortArg,
54
+ "debug-port": debugPort,
55
+ "debug-brk": debugBrk,
50
56
  _: _positional,
51
57
  ...serverArgs
52
- } = (0, import_yargs_parser.default)(process.argv.slice(2), {
53
- boolean: ["https", "open", "strictPort", "force", "cors", "debug"],
54
- number: ["port", "apiPort"]
58
+ } = (0, import_yargs_parser.default)(argv.slice(2), {
59
+ boolean: [
60
+ "https",
61
+ "open",
62
+ "strictPort",
63
+ "force",
64
+ "cors",
65
+ "debug",
66
+ "debug-brk"
67
+ ],
68
+ number: ["port", "apiPort", "debug-port"]
55
69
  });
70
+ return { forceOptimize, debug, portArg, debugPort, debugBrk, serverArgs };
71
+ }
72
+ async function clearPendingPause() {
73
+ const inspector = await import("node:inspector");
74
+ const s = new inspector.Session();
75
+ try {
76
+ s.connect();
77
+ await new Promise((resolve, reject) => {
78
+ s.post("Debugger.enable", (err) => err ? reject(err) : resolve());
79
+ });
80
+ await new Promise((resolve) => {
81
+ let done = false;
82
+ s.once("Debugger.paused", () => {
83
+ s.post("Debugger.resume", () => {
84
+ done = true;
85
+ resolve();
86
+ });
87
+ });
88
+ s.post("Runtime.evaluate", { expression: "1" }, () => {
89
+ if (!done) {
90
+ resolve();
91
+ }
92
+ });
93
+ });
94
+ } catch {
95
+ } finally {
96
+ s.disconnect();
97
+ }
98
+ }
99
+ async function openDebugger(port, waitForDebugger = false) {
100
+ const inspector = await import("node:inspector");
101
+ inspector.open(port, "127.0.0.1");
102
+ if (waitForDebugger) {
103
+ inspector.waitForDebugger();
104
+ const session = new inspector.Session();
105
+ session.connect();
106
+ await session.post("Debugger.enable");
107
+ let resumedResolve;
108
+ const resumedPromise = new Promise((resolve) => {
109
+ resumedResolve = resolve;
110
+ });
111
+ const onSessionDead = () => {
112
+ if (paused) {
113
+ tryResume();
114
+ } else {
115
+ clearPendingPause().then(
116
+ () => resumedResolve?.(),
117
+ () => resumedResolve?.()
118
+ );
119
+ }
120
+ };
121
+ session.once("error", onSessionDead);
122
+ session.once("Inspector.detached", onSessionDead);
123
+ let paused = false;
124
+ session.once("Debugger.paused", () => {
125
+ paused = true;
126
+ tryResume();
127
+ });
128
+ session.once("Debugger.resumed", () => {
129
+ resumedResolve?.();
130
+ });
131
+ const FIVE_MINUTES_MS = 5 * 60 * 1e3;
132
+ const timeout = setTimeout(() => {
133
+ if (paused) {
134
+ tryResume();
135
+ } else {
136
+ resumedResolve?.();
137
+ }
138
+ }, FIVE_MINUTES_MS);
139
+ let hasTriedResume = false;
140
+ const tryResume = () => {
141
+ if (hasTriedResume) {
142
+ return;
143
+ }
144
+ if (!paused) {
145
+ return;
146
+ }
147
+ hasTriedResume = true;
148
+ (async () => {
149
+ for (let attempt = 0; attempt < 3; attempt++) {
150
+ const s = attempt === 0 ? session : new inspector.Session();
151
+ if (attempt > 0) {
152
+ try {
153
+ s.connect();
154
+ await new Promise((resolve, reject) => {
155
+ s.post(
156
+ "Debugger.enable",
157
+ (err) => err ? reject(err) : resolve()
158
+ );
159
+ });
160
+ } catch {
161
+ continue;
162
+ }
163
+ }
164
+ const ok = await new Promise((resolve) => {
165
+ s.post("Debugger.resume", (err) => resolve(!err));
166
+ });
167
+ if (attempt > 0) {
168
+ s.disconnect();
169
+ }
170
+ if (ok) {
171
+ resumedResolve?.();
172
+ return;
173
+ }
174
+ }
175
+ console.warn(
176
+ "[cedar-unified-dev] Failed to clear debugger pause after external debugger disconnect. API functions may pause on next execution."
177
+ );
178
+ resumedResolve?.();
179
+ })();
180
+ };
181
+ void new Promise((resolve, reject) => {
182
+ session.post("Debugger.pause", (err) => {
183
+ if (err) {
184
+ reject(err);
185
+ } else {
186
+ resolve();
187
+ }
188
+ });
189
+ }).catch(() => {
190
+ resumedResolve?.();
191
+ });
192
+ void new Promise((resolve, reject) => {
193
+ session.post("Runtime.evaluate", { expression: "1" }, (err) => {
194
+ if (err) {
195
+ reject(err);
196
+ } else {
197
+ resolve();
198
+ }
199
+ });
200
+ }).catch(() => {
201
+ clearPendingPause().then(
202
+ () => resumedResolve?.(),
203
+ () => resumedResolve?.()
204
+ );
205
+ });
206
+ await resumedPromise;
207
+ clearTimeout(timeout);
208
+ }
209
+ }
210
+ async function startUnifiedDevServer() {
211
+ process.env.__CEDAR_UNIFIED_DEV = "true";
212
+ const rwPaths = (0, import_project_config.getPaths)();
213
+ const cedarConfig = (0, import_project_config.getConfig)();
214
+ const configFile = rwPaths.web.viteConfig;
215
+ if (!configFile) {
216
+ throw new Error("Could not locate your web/vite.config.{js,ts} file");
217
+ }
218
+ const { forceOptimize, debug, portArg, debugPort, debugBrk, serverArgs } = parseCliArgs();
219
+ if (debugPort !== void 0) {
220
+ await openDebugger(debugPort, debugBrk);
221
+ }
56
222
  const webPort = portArg ?? cedarConfig.web.port ?? 8910;
57
223
  const { close: closeApi, handler: apiHandler } = await (0, import_apiDevMiddleware.startApiDevMiddleware)();
58
224
  const apiAdapter = (0, import_server.createServerAdapter)(apiHandler);
@@ -135,8 +301,10 @@ const startUnifiedDevServer = async () => {
135
301
  };
136
302
  process.on("SIGINT", shutdown);
137
303
  process.on("SIGTERM", shutdown);
138
- };
139
- startUnifiedDevServer().catch((err) => {
140
- console.error("Failed to start unified dev server:", err);
141
- process.exit(1);
304
+ }
305
+ // Annotate the CommonJS export names for ESM import in node:
306
+ 0 && (module.exports = {
307
+ openDebugger,
308
+ parseCliArgs,
309
+ startUnifiedDevServer
142
310
  });
@@ -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;
@@ -59,7 +60,7 @@ async function createServer() {
59
60
  }
60
61
  if (!rwPaths.web.viteConfig) {
61
62
  throw new Error(
62
- "Vite config not found. You need to setup your project with Vite using `yarn cedar setup vite`"
63
+ "Vite config not found. Please set up Vite before running the dev server."
63
64
  );
64
65
  }
65
66
  const vite = await (0, import_vite.createServer)({
package/dist/cjs/index.js CHANGED
@@ -28,16 +28,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var index_exports = {};
30
30
  __export(index_exports, {
31
+ applyContextWrapping: () => import_vite_plugin_cedar_context_wrapping2.applyContextWrapping,
31
32
  cedar: () => cedar,
32
33
  cedarAutoImportsPlugin: () => import_vite_plugin_cedar_auto_import.cedarAutoImportsPlugin,
33
34
  cedarCellTransform: () => import_vite_plugin_cedar_cell2.cedarCellTransform,
34
35
  cedarCjsCompatPlugin: () => import_vite_plugin_cedar_cjs_compat.cedarCjsCompatPlugin,
36
+ cedarContextWrappingPlugin: () => import_vite_plugin_cedar_context_wrapping.cedarContextWrappingPlugin,
35
37
  cedarEntryInjectionPlugin: () => import_vite_plugin_cedar_entry_injection2.cedarEntryInjectionPlugin,
36
38
  cedarHtmlEnvPlugin: () => import_vite_plugin_cedar_html_env2.cedarHtmlEnvPlugin,
37
39
  cedarImportDirPlugin: () => import_vite_plugin_cedar_import_dir.cedarImportDirPlugin,
38
40
  cedarMergedConfig: () => import_vite_plugin_merged_config2.cedarMergedConfig,
39
41
  cedarNodePolyfills: () => import_vite_plugin_cedar_node_polyfills2.cedarNodePolyfills,
42
+ cedarRemoveDevFatalErrorPage: () => import_vite_plugin_cedar_remove_dev_fatal_error_page2.cedarRemoveDevFatalErrorPage,
40
43
  cedarRemoveFromBundle: () => import_vite_plugin_cedar_remove_from_bundle2.cedarRemoveFromBundle,
44
+ cedarRoutesAutoLoaderPlugin: () => import_vite_plugin_cedar_routes_auto_loader2.cedarRoutesAutoLoaderPlugin,
41
45
  cedarSwapApolloProvider: () => import_vite_plugin_swap_apollo_provider2.cedarSwapApolloProvider,
42
46
  cedarTransformJsAsJsx: () => import_vite_plugin_jsx_loader2.cedarTransformJsAsJsx,
43
47
  cedarUniversalDeployPlugin: () => import_vite_plugin_cedar_universal_deploy.cedarUniversalDeployPlugin,
@@ -55,7 +59,9 @@ var import_vite_plugin_cedar_cell = require("./plugins/vite-plugin-cedar-cell.js
55
59
  var import_vite_plugin_cedar_entry_injection = require("./plugins/vite-plugin-cedar-entry-injection.js");
56
60
  var import_vite_plugin_cedar_html_env = require("./plugins/vite-plugin-cedar-html-env.js");
57
61
  var import_vite_plugin_cedar_node_polyfills = require("./plugins/vite-plugin-cedar-node-polyfills.js");
62
+ var import_vite_plugin_cedar_remove_dev_fatal_error_page = require("./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js");
58
63
  var import_vite_plugin_cedar_remove_from_bundle = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
64
+ var import_vite_plugin_cedar_routes_auto_loader = require("./plugins/vite-plugin-cedar-routes-auto-loader.js");
59
65
  var import_vite_plugin_cedar_wait_for_api_server = require("./plugins/vite-plugin-cedar-wait-for-api-server.js");
60
66
  var import_vite_plugin_cedarjs_resolve_cedar_style_imports = require("./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js");
61
67
  var import_vite_plugin_jsx_loader = require("./plugins/vite-plugin-jsx-loader.js");
@@ -64,10 +70,14 @@ var import_vite_plugin_swap_apollo_provider = require("./plugins/vite-plugin-swa
64
70
  var import_vite_plugin_cedar_auto_import = require("./plugins/vite-plugin-cedar-auto-import.js");
65
71
  var import_vite_plugin_cedar_cjs_compat = require("./plugins/vite-plugin-cedar-cjs-compat.js");
66
72
  var import_vite_plugin_cedar_cell2 = require("./plugins/vite-plugin-cedar-cell.js");
73
+ var import_vite_plugin_cedar_context_wrapping = require("./plugins/vite-plugin-cedar-context-wrapping.js");
74
+ var import_vite_plugin_cedar_context_wrapping2 = require("./plugins/vite-plugin-cedar-context-wrapping.js");
67
75
  var import_vite_plugin_cedar_entry_injection2 = require("./plugins/vite-plugin-cedar-entry-injection.js");
68
76
  var import_vite_plugin_cedar_html_env2 = require("./plugins/vite-plugin-cedar-html-env.js");
69
77
  var import_vite_plugin_cedar_import_dir = require("./plugins/vite-plugin-cedar-import-dir.js");
70
78
  var import_vite_plugin_cedar_node_polyfills2 = require("./plugins/vite-plugin-cedar-node-polyfills.js");
79
+ var import_vite_plugin_cedar_remove_dev_fatal_error_page2 = require("./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js");
80
+ var import_vite_plugin_cedar_routes_auto_loader2 = require("./plugins/vite-plugin-cedar-routes-auto-loader.js");
71
81
  var import_vite_plugin_cedar_remove_from_bundle2 = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
72
82
  var import_vite_plugin_cedarjs_resolve_cedar_style_imports2 = require("./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js");
73
83
  var import_vite_plugin_cedarjs_job_path_injector = require("./plugins/vite-plugin-cedarjs-job-path-injector.js");
@@ -83,14 +93,7 @@ function cedar({ mode } = {}) {
83
93
  forVite: true
84
94
  });
85
95
  const babelConfig = {
86
- ...webSideDefaultBabelConfig,
87
- // For RSC we don't want to include the routes auto-loader plugin as we
88
- // handle that differently in each specific RSC build stage
89
- overrides: rscEnabled ? webSideDefaultBabelConfig.overrides.filter((override) => {
90
- return !override.plugins?.some((plugin) => {
91
- return Array.isArray(plugin) && plugin[2] === "babel-plugin-redwood-routes-auto-loader";
92
- });
93
- }) : webSideDefaultBabelConfig.overrides
96
+ ...webSideDefaultBabelConfig
94
97
  };
95
98
  return [
96
99
  mode === "test" && (0, import_vitest.cedarJsRouterImportTransformPlugin)(),
@@ -106,22 +109,29 @@ function cedar({ mode } = {}) {
106
109
  (0, import_vite_plugin_cedar_cell.cedarCellTransform)(),
107
110
  (0, import_vite_plugin_jsx_loader.cedarTransformJsAsJsx)(),
108
111
  (0, import_vite_plugin_cedar_remove_from_bundle.cedarRemoveFromBundle)(),
112
+ (0, import_vite_plugin_cedar_remove_dev_fatal_error_page.cedarRemoveDevFatalErrorPage)(),
113
+ // RSC handles route auto-loading differently in each build stage
114
+ !rscEnabled && (0, import_vite_plugin_cedar_routes_auto_loader.cedarRoutesAutoLoaderPlugin)(),
109
115
  (0, import_plugin_react.default)({ babel: babelConfig })
110
116
  ];
111
117
  }
112
118
  var index_default = cedar;
113
119
  // Annotate the CommonJS export names for ESM import in node:
114
120
  0 && (module.exports = {
121
+ applyContextWrapping,
115
122
  cedar,
116
123
  cedarAutoImportsPlugin,
117
124
  cedarCellTransform,
118
125
  cedarCjsCompatPlugin,
126
+ cedarContextWrappingPlugin,
119
127
  cedarEntryInjectionPlugin,
120
128
  cedarHtmlEnvPlugin,
121
129
  cedarImportDirPlugin,
122
130
  cedarMergedConfig,
123
131
  cedarNodePolyfills,
132
+ cedarRemoveDevFatalErrorPage,
124
133
  cedarRemoveFromBundle,
134
+ cedarRoutesAutoLoaderPlugin,
125
135
  cedarSwapApolloProvider,
126
136
  cedarTransformJsAsJsx,
127
137
  cedarUniversalDeployPlugin,