@cedarjs/vite 2.4.1 → 2.4.2-next.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -51,6 +51,7 @@ var import_vite_plugin_cedar_entry_injection = require("./plugins/vite-plugin-ce
51
51
  var import_vite_plugin_cedar_html_env = require("./plugins/vite-plugin-cedar-html-env.js");
52
52
  var import_vite_plugin_cedar_node_polyfills = require("./plugins/vite-plugin-cedar-node-polyfills.js");
53
53
  var import_vite_plugin_cedar_remove_from_bundle = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
54
+ var import_vite_plugin_cedar_wait_for_api_server = require("./plugins/vite-plugin-cedar-wait-for-api-server.js");
54
55
  var import_vite_plugin_jsx_loader = require("./plugins/vite-plugin-jsx-loader.js");
55
56
  var import_vite_plugin_merged_config = require("./plugins/vite-plugin-merged-config.js");
56
57
  var import_vite_plugin_swap_apollo_provider = require("./plugins/vite-plugin-swap-apollo-provider.js");
@@ -65,8 +66,8 @@ var import_vite_plugin_jsx_loader2 = require("./plugins/vite-plugin-jsx-loader.j
65
66
  var import_vite_plugin_merged_config2 = require("./plugins/vite-plugin-merged-config.js");
66
67
  var import_vite_plugin_swap_apollo_provider2 = require("./plugins/vite-plugin-swap-apollo-provider.js");
67
68
  function cedar({ mode } = {}) {
68
- const rwConfig = (0, import_project_config.getConfig)();
69
- const rscEnabled = rwConfig.experimental?.rsc?.enabled;
69
+ const cedarConfig = (0, import_project_config.getConfig)();
70
+ const rscEnabled = cedarConfig.experimental?.rsc?.enabled;
70
71
  const webSideDefaultBabelConfig = (0, import_babel_config.getWebSideDefaultBabelConfig)();
71
72
  const babelConfig = {
72
73
  ...webSideDefaultBabelConfig,
@@ -82,6 +83,7 @@ function cedar({ mode } = {}) {
82
83
  mode === "test" && (0, import_vitest.cedarJsRouterImportTransformPlugin)(),
83
84
  mode === "test" && (0, import_vitest.createAuthImportTransformPlugin)(),
84
85
  mode === "test" && (0, import_vitest.autoImportsPlugin)(),
86
+ (0, import_vite_plugin_cedar_wait_for_api_server.cedarWaitForApiServer)(),
85
87
  (0, import_vite_plugin_cedar_node_polyfills.cedarNodePolyfills)(),
86
88
  (0, import_vite_plugin_cedar_html_env.cedarHtmlEnvPlugin)(),
87
89
  (0, import_vite_plugin_cedar_entry_injection.cedarEntryInjectionPlugin)(),
@@ -34,21 +34,21 @@ module.exports = __toCommonJS(getMergedConfig_exports);
34
34
  var import_node_path = __toESM(require("node:path"), 1);
35
35
  var import_vite = require("vite");
36
36
  var import_project_config = require("@cedarjs/project-config");
37
- function getMergedConfig(rwConfig, rwPaths) {
37
+ function getMergedConfig(cedarConfig, cedarPaths) {
38
38
  return (userConfig, env) => {
39
39
  let apiHost = process.env.REDWOOD_API_HOST;
40
- apiHost ??= rwConfig.api.host;
40
+ apiHost ??= cedarConfig.api.host;
41
41
  apiHost ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "[::]";
42
- const streamingSsrEnabled = rwConfig.experimental.streamingSsr?.enabled;
43
- const rscEnabled = rwConfig.experimental.rsc?.enabled;
42
+ const streamingSsrEnabled = cedarConfig.experimental.streamingSsr?.enabled;
43
+ const rscEnabled = cedarConfig.experimental.rsc?.enabled;
44
44
  let apiPort;
45
45
  if (process.env.REDWOOD_API_PORT) {
46
46
  apiPort = parseInt(process.env.REDWOOD_API_PORT);
47
47
  } else {
48
- apiPort = rwConfig.api.port;
48
+ apiPort = cedarConfig.api.port;
49
49
  }
50
- const defaultRwViteConfig = {
51
- root: rwPaths.web.src,
50
+ const defaultCedarViteConfig = {
51
+ root: cedarPaths.web.src,
52
52
  // @MARK: when we have these aliases, the warnings from the FE server go
53
53
  // away BUT, if you have imports like this:
54
54
  // ```
@@ -62,56 +62,29 @@ function getMergedConfig(rwConfig, rwPaths) {
62
62
  // alias: [
63
63
  // {
64
64
  // find: 'src',
65
- // replacement: rwPaths.web.src,
65
+ // replacement: cedarPaths.web.src,
66
66
  // },
67
67
  // ],
68
68
  // },
69
69
  envPrefix: "REDWOOD_ENV_",
70
- publicDir: import_node_path.default.join(rwPaths.web.base, "public"),
70
+ publicDir: import_node_path.default.join(cedarPaths.web.base, "public"),
71
71
  define: (0, import_project_config.getEnvVarDefinitions)(),
72
72
  css: {
73
73
  // @NOTE config path is relative to where vite.config.js is if you use
74
74
  // a relative path
75
- postcss: rwPaths.web.config
75
+ postcss: cedarPaths.web.config
76
76
  },
77
77
  server: {
78
- open: rwConfig.browser.open,
79
- port: rwConfig.web.port,
78
+ open: cedarConfig.browser.open,
79
+ port: cedarConfig.web.port,
80
80
  host: true,
81
81
  // Listen to all hosts
82
82
  proxy: {
83
- [rwConfig.web.apiUrl]: {
83
+ [cedarConfig.web.apiUrl]: {
84
84
  target: `http://${apiHost}:${apiPort}`,
85
85
  changeOrigin: false,
86
- // Remove the `.redwood/functions` part, but leave the `/graphql`
87
- rewrite: (path2) => path2.replace(rwConfig.web.apiUrl, ""),
88
- configure: (proxy) => {
89
- let waitingForApiServer = true;
90
- setTimeout(() => {
91
- waitingForApiServer = false;
92
- }, 2500);
93
- proxy.on("error", (err, req, res) => {
94
- const isWaiting = waitingForApiServer && err.message.includes("ECONNREFUSED");
95
- if (!isWaiting) {
96
- console.error(err);
97
- }
98
- const isAuthTokenRequest = isWaiting && req.url === "/auth?method=getToken";
99
- const waitingMessage = "\u231B API Server launching, please refresh your page...";
100
- const genericMessage = "The Cedar API server is not available or is currently reloading. Please refresh.";
101
- const responseBody = {
102
- errors: [
103
- { message: isWaiting ? waitingMessage : genericMessage }
104
- ]
105
- };
106
- res.writeHead(203, {
107
- "Content-Type": "application/json",
108
- "Cache-Control": "no-cache"
109
- });
110
- if (!isAuthTokenRequest) {
111
- res.write(JSON.stringify(responseBody));
112
- }
113
- res.end();
114
- });
86
+ rewrite: (path2) => {
87
+ return path2.replace(cedarConfig.web.apiUrl, "");
115
88
  }
116
89
  }
117
90
  }
@@ -120,11 +93,11 @@ function getMergedConfig(rwConfig, rwPaths) {
120
93
  // TODO (RSC): Remove `minify: false` when we don't need to debug as often
121
94
  minify: false,
122
95
  // NOTE this gets overridden when build gets called anyway!
123
- outDir: streamingSsrEnabled || rscEnabled ? rwPaths.web.distBrowser : rwPaths.web.dist,
96
+ outDir: streamingSsrEnabled || rscEnabled ? cedarPaths.web.distBrowser : cedarPaths.web.dist,
124
97
  emptyOutDir: true,
125
98
  manifest: !env.isSsrBuild ? "client-build-manifest.json" : void 0,
126
99
  // Note that sourcemap can be boolean or 'inline'
127
- sourcemap: !env.isSsrBuild && rwConfig.web.sourceMap,
100
+ sourcemap: !env.isSsrBuild && cedarConfig.web.sourceMap,
128
101
  rollupOptions: {
129
102
  input: getRollupInput(!!env.isSsrBuild)
130
103
  }
@@ -133,7 +106,7 @@ function getMergedConfig(rwConfig, rwPaths) {
133
106
  // because rsc builds want false, client and server build wants true
134
107
  optimizeDeps: {
135
108
  esbuildOptions: {
136
- // @MARK this is because JS projects in Redwood don't have .jsx
109
+ // @MARK this is because JS projects in Cedar don't have .jsx
137
110
  // extensions
138
111
  loader: {
139
112
  ".js": "jsx"
@@ -156,26 +129,26 @@ function getMergedConfig(rwConfig, rwPaths) {
156
129
  environment: "jsdom"
157
130
  }
158
131
  };
159
- return (0, import_vite.mergeConfig)(defaultRwViteConfig, userConfig);
132
+ return (0, import_vite.mergeConfig)(defaultCedarViteConfig, userConfig);
160
133
  };
161
134
  }
162
135
  function getRollupInput(ssr) {
163
- const rwConfig = (0, import_project_config.getConfig)();
164
- const rwPaths = (0, import_project_config.getPaths)();
165
- if (!rwPaths.web.entryClient) {
136
+ const cedarConfig = (0, import_project_config.getConfig)();
137
+ const cedarPaths = (0, import_project_config.getPaths)();
138
+ if (!cedarPaths.web.entryClient) {
166
139
  throw new Error("entryClient not defined");
167
140
  }
168
- const streamingEnabled = rwConfig.experimental?.streamingSsr?.enabled;
169
- const rscEnabled = rwConfig.experimental?.rsc?.enabled;
141
+ const streamingEnabled = cedarConfig.experimental?.streamingSsr?.enabled;
142
+ const rscEnabled = cedarConfig.experimental?.rsc?.enabled;
170
143
  if (streamingEnabled) {
171
144
  if (ssr) {
172
- if (!rwPaths.web.entryServer) {
145
+ if (!cedarPaths.web.entryServer) {
173
146
  throw new Error("entryServer not defined");
174
147
  }
175
148
  if (rscEnabled) {
176
149
  return {
177
- Document: rwPaths.web.document,
178
- "entry.server": rwPaths.web.entryServer
150
+ Document: cedarPaths.web.document,
151
+ "entry.server": cedarPaths.web.entryServer
179
152
  };
180
153
  }
181
154
  return {
@@ -184,14 +157,14 @@ function getRollupInput(ssr) {
184
157
  // enabled, but not when RSC + SSR are both enabled
185
158
  // For RSC we have this configured in rscBuildForServer.ts to get a
186
159
  // build with the proper resolution conditions set.
187
- "entry.server": rwPaths.web.entryServer,
160
+ "entry.server": cedarPaths.web.entryServer,
188
161
  // We need the document for React's fallback
189
- Document: rwPaths.web.document
162
+ Document: cedarPaths.web.document
190
163
  };
191
164
  }
192
- return rwPaths.web.entryClient;
165
+ return cedarPaths.web.entryClient;
193
166
  }
194
- return rwPaths.web.html;
167
+ return cedarPaths.web.html;
195
168
  }
196
169
  // Annotate the CommonJS export names for ESM import in node:
197
170
  0 && (module.exports = {
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
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
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
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
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var vite_plugin_cedar_wait_for_api_server_exports = {};
30
+ __export(vite_plugin_cedar_wait_for_api_server_exports, {
31
+ cedarWaitForApiServer: () => cedarWaitForApiServer
32
+ });
33
+ module.exports = __toCommonJS(vite_plugin_cedar_wait_for_api_server_exports);
34
+ var import_node_net = __toESM(require("node:net"), 1);
35
+ var import_project_config = require("@cedarjs/project-config");
36
+ let waitingPromise = null;
37
+ let serverHasBeenUp = false;
38
+ function cedarWaitForApiServer() {
39
+ const cedarConfig = (0, import_project_config.getConfig)();
40
+ const apiPort = cedarConfig.api.port;
41
+ const apiHost = cedarConfig.api.host || "localhost";
42
+ return {
43
+ name: "cedar-wait-for-api-server",
44
+ apply: "serve",
45
+ configureServer(server) {
46
+ server.middlewares.use(async (req, res, next) => {
47
+ const url = req.originalUrl;
48
+ const apiUrl = cedarConfig.web.apiUrl.replace(/\/$/, "");
49
+ const apiGqlUrl = cedarConfig.web.apiGraphQLUrl ?? apiUrl + "/graphql";
50
+ const isApiRequest = url && (url.startsWith(apiUrl) || // Only match on .../graphql not on .../graphql-foo. That's why I
51
+ // don't use startsWith here
52
+ url === apiGqlUrl || // The two checks below are for when we support GraphQL-over-HTTP
53
+ url.startsWith(apiGqlUrl + "/") || url.startsWith(apiGqlUrl + "?"));
54
+ if (!isApiRequest || serverHasBeenUp) {
55
+ return next();
56
+ }
57
+ try {
58
+ if (!waitingPromise) {
59
+ waitingPromise = waitForPort(apiPort, apiHost).finally(() => {
60
+ waitingPromise = null;
61
+ });
62
+ }
63
+ await waitingPromise;
64
+ serverHasBeenUp = true;
65
+ } catch {
66
+ const message = `Vite timed out waiting for the Cedar API server at ${apiHost}:${apiPort}
67
+ Please manually refresh the page when the server is ready`;
68
+ console.error(message);
69
+ const isAuthTokenRequest = url === apiUrl + "/auth?method=getToken";
70
+ const responseBody = {
71
+ errors: [{ message }]
72
+ };
73
+ req.resume();
74
+ const body = JSON.stringify(responseBody);
75
+ res.writeHead(203, {
76
+ "Content-Type": "application/json",
77
+ "Cache-Control": "no-cache",
78
+ ...!isAuthTokenRequest && {
79
+ "Content-Length": Buffer.byteLength(body)
80
+ },
81
+ Connection: "close"
82
+ });
83
+ return isAuthTokenRequest ? res.end() : res.end(body);
84
+ }
85
+ next();
86
+ });
87
+ }
88
+ };
89
+ }
90
+ const ONE_MINUTE_IN_MS = 6e4;
91
+ async function waitForPort(port, host) {
92
+ const start = Date.now();
93
+ let lastLogTime = Date.now();
94
+ while (Date.now() - start < ONE_MINUTE_IN_MS) {
95
+ const isOpen = await checkPort(port, host);
96
+ if (isOpen) {
97
+ if (lastLogTime - start >= 6e3) {
98
+ console.log("\u2705 API server is ready");
99
+ }
100
+ return;
101
+ }
102
+ const now = Date.now();
103
+ if (now - lastLogTime >= 6e3) {
104
+ console.log("\u23F3 Waiting for API server...");
105
+ lastLogTime = now;
106
+ }
107
+ await new Promise((resolve) => setTimeout(resolve, 500));
108
+ }
109
+ throw new Error("Timeout waiting for port");
110
+ }
111
+ function checkPort(port, host) {
112
+ return new Promise((resolve) => {
113
+ const socket = new import_node_net.default.Socket();
114
+ socket.setTimeout(200);
115
+ socket.on("connect", () => {
116
+ socket.destroy();
117
+ resolve(true);
118
+ });
119
+ socket.on("timeout", () => {
120
+ socket.destroy();
121
+ resolve(false);
122
+ });
123
+ socket.on("error", () => {
124
+ socket.destroy();
125
+ resolve(false);
126
+ });
127
+ socket.connect(port, host);
128
+ });
129
+ }
130
+ // Annotate the CommonJS export names for ESM import in node:
131
+ 0 && (module.exports = {
132
+ cedarWaitForApiServer
133
+ });
@@ -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;AAmBxC,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,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,iCAAiC,EAAE,MAAM,yDAAyD,CAAA;AAC3G,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;AAEvF,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,CAqClE;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;AAoBxC,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,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,iCAAiC,EAAE,MAAM,yDAAyD,CAAA;AAC3G,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;AAEvF,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,CAsClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import { cedarEntryInjectionPlugin } from "./plugins/vite-plugin-cedar-entry-inj
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
13
  import { cedarRemoveFromBundle } from "./plugins/vite-plugin-cedar-remove-from-bundle.js";
14
+ import { cedarWaitForApiServer } from "./plugins/vite-plugin-cedar-wait-for-api-server.js";
14
15
  import { cedarTransformJsAsJsx } from "./plugins/vite-plugin-jsx-loader.js";
15
16
  import { cedarMergedConfig } from "./plugins/vite-plugin-merged-config.js";
16
17
  import { cedarSwapApolloProvider } from "./plugins/vite-plugin-swap-apollo-provider.js";
@@ -25,8 +26,8 @@ import { cedarTransformJsAsJsx as cedarTransformJsAsJsx2 } from "./plugins/vite-
25
26
  import { cedarMergedConfig as cedarMergedConfig2 } from "./plugins/vite-plugin-merged-config.js";
26
27
  import { cedarSwapApolloProvider as cedarSwapApolloProvider2 } from "./plugins/vite-plugin-swap-apollo-provider.js";
27
28
  function cedar({ mode } = {}) {
28
- const rwConfig = getConfig();
29
- const rscEnabled = rwConfig.experimental?.rsc?.enabled;
29
+ const cedarConfig = getConfig();
30
+ const rscEnabled = cedarConfig.experimental?.rsc?.enabled;
30
31
  const webSideDefaultBabelConfig = getWebSideDefaultBabelConfig();
31
32
  const babelConfig = {
32
33
  ...webSideDefaultBabelConfig,
@@ -42,6 +43,7 @@ function cedar({ mode } = {}) {
42
43
  mode === "test" && cedarJsRouterImportTransformPlugin(),
43
44
  mode === "test" && createAuthImportTransformPlugin(),
44
45
  mode === "test" && autoImportsPlugin(),
46
+ cedarWaitForApiServer(),
45
47
  cedarNodePolyfills(),
46
48
  cedarHtmlEnvPlugin(),
47
49
  cedarEntryInjectionPlugin(),
@@ -1,11 +1,11 @@
1
1
  import type { ConfigEnv, ViteUserConfig } from 'vitest/config';
2
2
  import type { Config, Paths } from '@cedarjs/project-config';
3
3
  /**
4
- * This function will merge in the default Redwood Vite config passed into the
4
+ * This function will merge in the default Cedar Vite config passed into the
5
5
  * build function (or in Vite.config.xxx)
6
6
  *
7
7
  * Note that returning plugins in this function will have no effect on the
8
8
  * build
9
9
  */
10
- export declare function getMergedConfig(rwConfig: Config, rwPaths: Paths): (userConfig: ViteUserConfig, env: ConfigEnv) => ViteUserConfig;
10
+ export declare function getMergedConfig(cedarConfig: Config, cedarPaths: Paths): (userConfig: ViteUserConfig, env: ConfigEnv) => ViteUserConfig;
11
11
  //# sourceMappingURL=getMergedConfig.d.ts.map
@@ -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;AAO5D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,IACtD,YAAY,cAAc,EAAE,KAAK,SAAS,KAAG,cAAc,CA0JpE"}
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;AAO5D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,IAC5D,YAAY,cAAc,EAAE,KAAK,SAAS,KAAG,cAAc,CAwGpE"}
@@ -5,21 +5,21 @@ import {
5
5
  getEnvVarDefinitions,
6
6
  getPaths
7
7
  } from "@cedarjs/project-config";
8
- function getMergedConfig(rwConfig, rwPaths) {
8
+ function getMergedConfig(cedarConfig, cedarPaths) {
9
9
  return (userConfig, env) => {
10
10
  let apiHost = process.env.REDWOOD_API_HOST;
11
- apiHost ??= rwConfig.api.host;
11
+ apiHost ??= cedarConfig.api.host;
12
12
  apiHost ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "[::]";
13
- const streamingSsrEnabled = rwConfig.experimental.streamingSsr?.enabled;
14
- const rscEnabled = rwConfig.experimental.rsc?.enabled;
13
+ const streamingSsrEnabled = cedarConfig.experimental.streamingSsr?.enabled;
14
+ const rscEnabled = cedarConfig.experimental.rsc?.enabled;
15
15
  let apiPort;
16
16
  if (process.env.REDWOOD_API_PORT) {
17
17
  apiPort = parseInt(process.env.REDWOOD_API_PORT);
18
18
  } else {
19
- apiPort = rwConfig.api.port;
19
+ apiPort = cedarConfig.api.port;
20
20
  }
21
- const defaultRwViteConfig = {
22
- root: rwPaths.web.src,
21
+ const defaultCedarViteConfig = {
22
+ root: cedarPaths.web.src,
23
23
  // @MARK: when we have these aliases, the warnings from the FE server go
24
24
  // away BUT, if you have imports like this:
25
25
  // ```
@@ -33,56 +33,29 @@ function getMergedConfig(rwConfig, rwPaths) {
33
33
  // alias: [
34
34
  // {
35
35
  // find: 'src',
36
- // replacement: rwPaths.web.src,
36
+ // replacement: cedarPaths.web.src,
37
37
  // },
38
38
  // ],
39
39
  // },
40
40
  envPrefix: "REDWOOD_ENV_",
41
- publicDir: path.join(rwPaths.web.base, "public"),
41
+ publicDir: path.join(cedarPaths.web.base, "public"),
42
42
  define: getEnvVarDefinitions(),
43
43
  css: {
44
44
  // @NOTE config path is relative to where vite.config.js is if you use
45
45
  // a relative path
46
- postcss: rwPaths.web.config
46
+ postcss: cedarPaths.web.config
47
47
  },
48
48
  server: {
49
- open: rwConfig.browser.open,
50
- port: rwConfig.web.port,
49
+ open: cedarConfig.browser.open,
50
+ port: cedarConfig.web.port,
51
51
  host: true,
52
52
  // Listen to all hosts
53
53
  proxy: {
54
- [rwConfig.web.apiUrl]: {
54
+ [cedarConfig.web.apiUrl]: {
55
55
  target: `http://${apiHost}:${apiPort}`,
56
56
  changeOrigin: false,
57
- // Remove the `.redwood/functions` part, but leave the `/graphql`
58
- rewrite: (path2) => path2.replace(rwConfig.web.apiUrl, ""),
59
- configure: (proxy) => {
60
- let waitingForApiServer = true;
61
- setTimeout(() => {
62
- waitingForApiServer = false;
63
- }, 2500);
64
- proxy.on("error", (err, req, res) => {
65
- const isWaiting = waitingForApiServer && err.message.includes("ECONNREFUSED");
66
- if (!isWaiting) {
67
- console.error(err);
68
- }
69
- const isAuthTokenRequest = isWaiting && req.url === "/auth?method=getToken";
70
- const waitingMessage = "\u231B API Server launching, please refresh your page...";
71
- const genericMessage = "The Cedar API server is not available or is currently reloading. Please refresh.";
72
- const responseBody = {
73
- errors: [
74
- { message: isWaiting ? waitingMessage : genericMessage }
75
- ]
76
- };
77
- res.writeHead(203, {
78
- "Content-Type": "application/json",
79
- "Cache-Control": "no-cache"
80
- });
81
- if (!isAuthTokenRequest) {
82
- res.write(JSON.stringify(responseBody));
83
- }
84
- res.end();
85
- });
57
+ rewrite: (path2) => {
58
+ return path2.replace(cedarConfig.web.apiUrl, "");
86
59
  }
87
60
  }
88
61
  }
@@ -91,11 +64,11 @@ function getMergedConfig(rwConfig, rwPaths) {
91
64
  // TODO (RSC): Remove `minify: false` when we don't need to debug as often
92
65
  minify: false,
93
66
  // NOTE this gets overridden when build gets called anyway!
94
- outDir: streamingSsrEnabled || rscEnabled ? rwPaths.web.distBrowser : rwPaths.web.dist,
67
+ outDir: streamingSsrEnabled || rscEnabled ? cedarPaths.web.distBrowser : cedarPaths.web.dist,
95
68
  emptyOutDir: true,
96
69
  manifest: !env.isSsrBuild ? "client-build-manifest.json" : void 0,
97
70
  // Note that sourcemap can be boolean or 'inline'
98
- sourcemap: !env.isSsrBuild && rwConfig.web.sourceMap,
71
+ sourcemap: !env.isSsrBuild && cedarConfig.web.sourceMap,
99
72
  rollupOptions: {
100
73
  input: getRollupInput(!!env.isSsrBuild)
101
74
  }
@@ -104,7 +77,7 @@ function getMergedConfig(rwConfig, rwPaths) {
104
77
  // because rsc builds want false, client and server build wants true
105
78
  optimizeDeps: {
106
79
  esbuildOptions: {
107
- // @MARK this is because JS projects in Redwood don't have .jsx
80
+ // @MARK this is because JS projects in Cedar don't have .jsx
108
81
  // extensions
109
82
  loader: {
110
83
  ".js": "jsx"
@@ -127,26 +100,26 @@ function getMergedConfig(rwConfig, rwPaths) {
127
100
  environment: "jsdom"
128
101
  }
129
102
  };
130
- return mergeConfig(defaultRwViteConfig, userConfig);
103
+ return mergeConfig(defaultCedarViteConfig, userConfig);
131
104
  };
132
105
  }
133
106
  function getRollupInput(ssr) {
134
- const rwConfig = getConfig();
135
- const rwPaths = getPaths();
136
- if (!rwPaths.web.entryClient) {
107
+ const cedarConfig = getConfig();
108
+ const cedarPaths = getPaths();
109
+ if (!cedarPaths.web.entryClient) {
137
110
  throw new Error("entryClient not defined");
138
111
  }
139
- const streamingEnabled = rwConfig.experimental?.streamingSsr?.enabled;
140
- const rscEnabled = rwConfig.experimental?.rsc?.enabled;
112
+ const streamingEnabled = cedarConfig.experimental?.streamingSsr?.enabled;
113
+ const rscEnabled = cedarConfig.experimental?.rsc?.enabled;
141
114
  if (streamingEnabled) {
142
115
  if (ssr) {
143
- if (!rwPaths.web.entryServer) {
116
+ if (!cedarPaths.web.entryServer) {
144
117
  throw new Error("entryServer not defined");
145
118
  }
146
119
  if (rscEnabled) {
147
120
  return {
148
- Document: rwPaths.web.document,
149
- "entry.server": rwPaths.web.entryServer
121
+ Document: cedarPaths.web.document,
122
+ "entry.server": cedarPaths.web.entryServer
150
123
  };
151
124
  }
152
125
  return {
@@ -155,14 +128,14 @@ function getRollupInput(ssr) {
155
128
  // enabled, but not when RSC + SSR are both enabled
156
129
  // For RSC we have this configured in rscBuildForServer.ts to get a
157
130
  // build with the proper resolution conditions set.
158
- "entry.server": rwPaths.web.entryServer,
131
+ "entry.server": cedarPaths.web.entryServer,
159
132
  // We need the document for React's fallback
160
- Document: rwPaths.web.document
133
+ Document: cedarPaths.web.document
161
134
  };
162
135
  }
163
- return rwPaths.web.entryClient;
136
+ return cedarPaths.web.entryClient;
164
137
  }
165
- return rwPaths.web.html;
138
+ return cedarPaths.web.html;
166
139
  }
167
140
  export {
168
141
  getMergedConfig
@@ -0,0 +1,3 @@
1
+ import type { PluginOption } from 'vite';
2
+ export declare function cedarWaitForApiServer(): PluginOption;
3
+ //# sourceMappingURL=vite-plugin-cedar-wait-for-api-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-cedar-wait-for-api-server.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-wait-for-api-server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,MAAM,CAAA;AAOvD,wBAAgB,qBAAqB,IAAI,YAAY,CA8FpD"}
@@ -0,0 +1,99 @@
1
+ import net from "node:net";
2
+ import { getConfig } from "@cedarjs/project-config";
3
+ let waitingPromise = null;
4
+ let serverHasBeenUp = false;
5
+ function cedarWaitForApiServer() {
6
+ const cedarConfig = getConfig();
7
+ const apiPort = cedarConfig.api.port;
8
+ const apiHost = cedarConfig.api.host || "localhost";
9
+ return {
10
+ name: "cedar-wait-for-api-server",
11
+ apply: "serve",
12
+ configureServer(server) {
13
+ server.middlewares.use(async (req, res, next) => {
14
+ const url = req.originalUrl;
15
+ const apiUrl = cedarConfig.web.apiUrl.replace(/\/$/, "");
16
+ const apiGqlUrl = cedarConfig.web.apiGraphQLUrl ?? apiUrl + "/graphql";
17
+ const isApiRequest = url && (url.startsWith(apiUrl) || // Only match on .../graphql not on .../graphql-foo. That's why I
18
+ // don't use startsWith here
19
+ url === apiGqlUrl || // The two checks below are for when we support GraphQL-over-HTTP
20
+ url.startsWith(apiGqlUrl + "/") || url.startsWith(apiGqlUrl + "?"));
21
+ if (!isApiRequest || serverHasBeenUp) {
22
+ return next();
23
+ }
24
+ try {
25
+ if (!waitingPromise) {
26
+ waitingPromise = waitForPort(apiPort, apiHost).finally(() => {
27
+ waitingPromise = null;
28
+ });
29
+ }
30
+ await waitingPromise;
31
+ serverHasBeenUp = true;
32
+ } catch {
33
+ const message = `Vite timed out waiting for the Cedar API server at ${apiHost}:${apiPort}
34
+ Please manually refresh the page when the server is ready`;
35
+ console.error(message);
36
+ const isAuthTokenRequest = url === apiUrl + "/auth?method=getToken";
37
+ const responseBody = {
38
+ errors: [{ message }]
39
+ };
40
+ req.resume();
41
+ const body = JSON.stringify(responseBody);
42
+ res.writeHead(203, {
43
+ "Content-Type": "application/json",
44
+ "Cache-Control": "no-cache",
45
+ ...!isAuthTokenRequest && {
46
+ "Content-Length": Buffer.byteLength(body)
47
+ },
48
+ Connection: "close"
49
+ });
50
+ return isAuthTokenRequest ? res.end() : res.end(body);
51
+ }
52
+ next();
53
+ });
54
+ }
55
+ };
56
+ }
57
+ const ONE_MINUTE_IN_MS = 6e4;
58
+ async function waitForPort(port, host) {
59
+ const start = Date.now();
60
+ let lastLogTime = Date.now();
61
+ while (Date.now() - start < ONE_MINUTE_IN_MS) {
62
+ const isOpen = await checkPort(port, host);
63
+ if (isOpen) {
64
+ if (lastLogTime - start >= 6e3) {
65
+ console.log("\u2705 API server is ready");
66
+ }
67
+ return;
68
+ }
69
+ const now = Date.now();
70
+ if (now - lastLogTime >= 6e3) {
71
+ console.log("\u23F3 Waiting for API server...");
72
+ lastLogTime = now;
73
+ }
74
+ await new Promise((resolve) => setTimeout(resolve, 500));
75
+ }
76
+ throw new Error("Timeout waiting for port");
77
+ }
78
+ function checkPort(port, host) {
79
+ return new Promise((resolve) => {
80
+ const socket = new net.Socket();
81
+ socket.setTimeout(200);
82
+ socket.on("connect", () => {
83
+ socket.destroy();
84
+ resolve(true);
85
+ });
86
+ socket.on("timeout", () => {
87
+ socket.destroy();
88
+ resolve(false);
89
+ });
90
+ socket.on("error", () => {
91
+ socket.destroy();
92
+ resolve(false);
93
+ });
94
+ socket.connect(port, host);
95
+ });
96
+ }
97
+ export {
98
+ cedarWaitForApiServer
99
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"runFeServer.d.ts","sourceRoot":"","sources":["../src/runFeServer.ts"],"names":[],"mappings":"AAgDA,wBAAsB,WAAW,kBAsJhC"}
1
+ {"version":3,"file":"runFeServer.d.ts","sourceRoot":"","sources":["../src/runFeServer.ts"],"names":[],"mappings":"AAgDA,wBAAsB,WAAW,kBAqJhC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/vite",
3
- "version": "2.4.1",
3
+ "version": "2.4.2-next.143+b69a4494c",
4
4
  "description": "Vite configuration package for CedarJS",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,19 +60,19 @@
60
60
  "test:watch": "vitest watch"
61
61
  },
62
62
  "dependencies": {
63
- "@ast-grep/napi": "0.40.4",
64
- "@babel/generator": "7.28.5",
65
- "@babel/parser": "7.28.5",
66
- "@babel/traverse": "7.28.5",
67
- "@cedarjs/auth": "2.4.1",
68
- "@cedarjs/babel-config": "2.4.1",
69
- "@cedarjs/cookie-jar": "2.4.1",
70
- "@cedarjs/internal": "2.4.1",
71
- "@cedarjs/project-config": "2.4.1",
72
- "@cedarjs/server-store": "2.4.1",
73
- "@cedarjs/testing": "2.4.1",
74
- "@cedarjs/web": "2.4.1",
75
- "@swc/core": "1.15.8",
63
+ "@ast-grep/napi": "0.40.5",
64
+ "@babel/generator": "7.28.6",
65
+ "@babel/parser": "7.28.6",
66
+ "@babel/traverse": "7.28.6",
67
+ "@cedarjs/auth": "2.4.2-next.143+b69a4494c",
68
+ "@cedarjs/babel-config": "2.4.2-next.143+b69a4494c",
69
+ "@cedarjs/cookie-jar": "2.4.2-next.143+b69a4494c",
70
+ "@cedarjs/internal": "2.4.2-next.143+b69a4494c",
71
+ "@cedarjs/project-config": "2.4.2-next.143+b69a4494c",
72
+ "@cedarjs/server-store": "2.4.2-next.143+b69a4494c",
73
+ "@cedarjs/testing": "2.4.2-next.143+b69a4494c",
74
+ "@cedarjs/web": "2.4.2-next.143+b69a4494c",
75
+ "@swc/core": "1.15.11",
76
76
  "@vitejs/plugin-react": "4.7.0",
77
77
  "@whatwg-node/fetch": "0.10.13",
78
78
  "@whatwg-node/server": "0.10.18",
@@ -80,19 +80,19 @@
80
80
  "buffer": "6.0.3",
81
81
  "busboy": "^1.6.0",
82
82
  "cookie": "1.1.1",
83
- "core-js": "3.47.0",
83
+ "core-js": "3.48.0",
84
84
  "dotenv-defaults": "5.0.2",
85
85
  "execa": "5.1.1",
86
86
  "express": "4.22.1",
87
87
  "find-my-way": "8.2.2",
88
88
  "http-proxy-middleware": "3.0.5",
89
- "isbot": "5.1.32",
89
+ "isbot": "5.1.34",
90
90
  "react": "18.3.1",
91
91
  "react-server-dom-webpack": "19.2.3",
92
92
  "rimraf": "6.1.2",
93
93
  "vite": "5.4.21",
94
94
  "vite-plugin-cjs-interop": "2.4.0",
95
- "vite-plugin-node-polyfills": "0.24.0",
95
+ "vite-plugin-node-polyfills": "0.25.0",
96
96
  "ws": "8.19.0",
97
97
  "yargs-parser": "21.1.1"
98
98
  },
@@ -106,9 +106,9 @@
106
106
  "@types/yargs-parser": "21.0.3",
107
107
  "concurrently": "9.2.1",
108
108
  "glob": "11.1.0",
109
- "memfs": "4.51.1",
110
- "publint": "0.3.16",
111
- "rollup": "4.55.1",
109
+ "memfs": "4.56.10",
110
+ "publint": "0.3.17",
111
+ "rollup": "4.57.1",
112
112
  "tsx": "4.21.0",
113
113
  "typescript": "5.9.3",
114
114
  "vitest": "3.2.4"
@@ -116,5 +116,5 @@
116
116
  "publishConfig": {
117
117
  "access": "public"
118
118
  },
119
- "gitHead": "d42ba2ec10b823aeb18587f04678bfec340d533a"
119
+ "gitHead": "b69a4494c40b0a4807f6b492ae65d0596f374e8a"
120
120
  }