@cedarjs/vite 5.0.6 → 5.0.7-next.186

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 (150) hide show
  1. package/dist/api/vite-plugin-cedar-vitest-api-preset.d.ts.map +1 -1
  2. package/dist/api/vite-plugin-cedar-vitest-api-preset.js +4 -0
  3. package/dist/apiDevMiddleware.d.ts.map +1 -1
  4. package/dist/apiDevMiddleware.js +117 -15
  5. package/dist/buildApp.d.ts.map +1 -1
  6. package/dist/buildApp.js +79 -18
  7. package/dist/buildRouteHooks.d.ts.map +1 -1
  8. package/dist/buildRouteHooks.js +36 -4
  9. package/dist/bundled/react-server-dom-webpack.server.js +192 -99
  10. package/dist/cedar-unified-dev.d.ts +18 -0
  11. package/dist/cedar-unified-dev.d.ts.map +1 -1
  12. package/dist/cedar-unified-dev.js +39 -5
  13. package/dist/devFeServer.js +3 -8
  14. package/dist/index.d.ts +11 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +51 -19
  17. package/dist/lib/generateDiffSourceMap.d.ts +18 -0
  18. package/dist/lib/generateDiffSourceMap.d.ts.map +1 -0
  19. package/dist/lib/generateDiffSourceMap.js +151 -0
  20. package/dist/lib/getMergedConfig.d.ts.map +1 -1
  21. package/dist/lib/getMergedConfig.js +4 -0
  22. package/dist/plugins/vite-plugin-cedar-api-import-guard.d.ts +13 -0
  23. package/dist/plugins/vite-plugin-cedar-api-import-guard.d.ts.map +1 -0
  24. package/dist/plugins/vite-plugin-cedar-api-import-guard.js +17 -0
  25. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts +1 -1
  26. package/dist/plugins/vite-plugin-cedar-auto-import.d.ts.map +1 -1
  27. package/dist/plugins/vite-plugin-cedar-auto-import.js +8 -1
  28. package/dist/plugins/vite-plugin-cedar-cell.d.ts.map +1 -1
  29. package/dist/plugins/vite-plugin-cedar-cell.js +2 -1
  30. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +3 -0
  31. package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +1 -0
  32. package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +43 -0
  33. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts +12 -0
  34. package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts.map +1 -0
  35. package/dist/plugins/vite-plugin-cedar-directory-named-import.js +35 -0
  36. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +29 -0
  37. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +1 -0
  38. package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +76 -0
  39. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +42 -0
  40. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +1 -0
  41. package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +93 -0
  42. package/dist/plugins/vite-plugin-cedar-import-dir.d.ts.map +1 -1
  43. package/dist/plugins/vite-plugin-cedar-import-dir.js +44 -31
  44. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts +28 -0
  45. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts.map +1 -0
  46. package/dist/plugins/vite-plugin-cedar-log-formatter-dev.js +67 -0
  47. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts +28 -0
  48. package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts.map +1 -0
  49. package/dist/plugins/vite-plugin-cedar-mock-cell-data.js +247 -0
  50. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts +39 -0
  51. package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts.map +1 -0
  52. package/dist/plugins/vite-plugin-cedar-otel-wrapping.js +200 -0
  53. package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -1
  54. package/dist/plugins/vite-plugin-cedar-universal-deploy.js +92 -90
  55. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts +29 -0
  56. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts.map +1 -1
  57. package/dist/plugins/vite-plugin-cedarjs-job-path-injector.js +63 -81
  58. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.d.ts.map +1 -1
  59. package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +14 -0
  60. package/dist/plugins/{vite-plugin-cedar-context-wrapping.d.ts → vite-plugin-handler-als-wrapping.d.ts} +12 -12
  61. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +1 -0
  62. package/dist/plugins/{vite-plugin-cedar-context-wrapping.js → vite-plugin-handler-als-wrapping.js} +16 -16
  63. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts +3 -0
  64. package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts.map +1 -1
  65. package/dist/plugins/vite-plugin-swap-apollo-provider.js +2 -2
  66. package/dist/rsc/rscBuildForSsr.d.ts.map +1 -1
  67. package/dist/rsc/rscBuildForSsr.js +3 -5
  68. package/dist/streaming/buildForStreamingServer.d.ts.map +1 -1
  69. package/dist/streaming/buildForStreamingServer.js +3 -5
  70. package/package.json +41 -52
  71. package/dist/cjs/ClientRouter.d.ts +0 -1
  72. package/dist/cjs/api/vite-plugin-cedar-vitest-api-preset.js +0 -37
  73. package/dist/cjs/apiDevMiddleware.js +0 -371
  74. package/dist/cjs/build/build.d.ts +0 -1
  75. package/dist/cjs/build/build.js +0 -58
  76. package/dist/cjs/buildApp.js +0 -306
  77. package/dist/cjs/buildFeServer.d.ts +0 -1
  78. package/dist/cjs/buildFeServer.js +0 -63
  79. package/dist/cjs/buildRouteHooks.js +0 -80
  80. package/dist/cjs/buildRouteManifest.js +0 -92
  81. package/dist/cjs/buildRscClientAndServer.js +0 -54
  82. package/dist/cjs/cedar-unified-dev.js +0 -310
  83. package/dist/cjs/client.d.ts +0 -1
  84. package/dist/cjs/clientSsr.d.ts +0 -1
  85. package/dist/cjs/devFeServer.js +0 -157
  86. package/dist/cjs/index.d.ts +0 -1
  87. package/dist/cjs/index.js +0 -141
  88. package/dist/cjs/lib/StatusError.js +0 -37
  89. package/dist/cjs/lib/entries.js +0 -52
  90. package/dist/cjs/lib/getMergedConfig.js +0 -185
  91. package/dist/cjs/lib/onWarn.js +0 -36
  92. package/dist/cjs/lib/registerFwGlobalsAndShims.js +0 -102
  93. package/dist/cjs/lib/workspacePackageAliases.js +0 -107
  94. package/dist/cjs/middleware/index.js +0 -22
  95. package/dist/cjs/middleware/invokeMiddleware.js +0 -52
  96. package/dist/cjs/middleware/register.js +0 -105
  97. package/dist/cjs/middleware/types.js +0 -16
  98. package/dist/cjs/package.json +0 -1
  99. package/dist/cjs/plugins/vite-plugin-cedar-auto-import.js +0 -107
  100. package/dist/cjs/plugins/vite-plugin-cedar-cell.js +0 -183
  101. package/dist/cjs/plugins/vite-plugin-cedar-cjs-compat.js +0 -341
  102. package/dist/cjs/plugins/vite-plugin-cedar-context-wrapping.js +0 -95
  103. package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +0 -107
  104. package/dist/cjs/plugins/vite-plugin-cedar-html-env.js +0 -67
  105. package/dist/cjs/plugins/vite-plugin-cedar-import-dir.js +0 -118
  106. package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +0 -43
  107. package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +0 -61
  108. package/dist/cjs/plugins/vite-plugin-cedar-remove-from-bundle.js +0 -76
  109. package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +0 -126
  110. package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +0 -346
  111. package/dist/cjs/plugins/vite-plugin-cedar-wait-for-api-server.js +0 -134
  112. package/dist/cjs/plugins/vite-plugin-cedarjs-job-path-injector.js +0 -134
  113. package/dist/cjs/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +0 -106
  114. package/dist/cjs/plugins/vite-plugin-jsx-loader.js +0 -42
  115. package/dist/cjs/plugins/vite-plugin-merged-config.js +0 -39
  116. package/dist/cjs/plugins/vite-plugin-rsc-analyze.js +0 -104
  117. package/dist/cjs/plugins/vite-plugin-rsc-reload.js +0 -75
  118. package/dist/cjs/plugins/vite-plugin-rsc-routes-auto-loader.js +0 -159
  119. package/dist/cjs/plugins/vite-plugin-rsc-routes-imports.js +0 -125
  120. package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +0 -75
  121. package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +0 -228
  122. package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +0 -398
  123. package/dist/cjs/plugins/vite-plugin-swap-apollo-provider.js +0 -46
  124. package/dist/cjs/rsc/rscBuildAnalyze.js +0 -126
  125. package/dist/cjs/rsc/rscBuildClient.js +0 -91
  126. package/dist/cjs/rsc/rscBuildCopyCssAssets.js +0 -56
  127. package/dist/cjs/rsc/rscBuildEntriesFile.js +0 -115
  128. package/dist/cjs/rsc/rscBuildForServer.js +0 -168
  129. package/dist/cjs/rsc/rscBuildForSsr.js +0 -173
  130. package/dist/cjs/rsc/rscBuildRwEnvVars.js +0 -56
  131. package/dist/cjs/rsc/rscRenderer.js +0 -165
  132. package/dist/cjs/rsc/rscRequestHandler.js +0 -162
  133. package/dist/cjs/rsc/rscStudioHandlers.js +0 -156
  134. package/dist/cjs/runFeServer.js +0 -165
  135. package/dist/cjs/streaming/buildForStreamingServer.js +0 -65
  136. package/dist/cjs/streaming/collectCss.js +0 -52
  137. package/dist/cjs/streaming/createReactStreamingHandler.js +0 -173
  138. package/dist/cjs/streaming/streamHelpers.js +0 -230
  139. package/dist/cjs/streaming/transforms/bufferedTransform.js +0 -61
  140. package/dist/cjs/streaming/transforms/cancelTimeoutTransform.js +0 -34
  141. package/dist/cjs/streaming/transforms/encode-decode.js +0 -36
  142. package/dist/cjs/streaming/transforms/serverInjectionTransform.js +0 -84
  143. package/dist/cjs/streaming/triggerRouteHooks.js +0 -96
  144. package/dist/cjs/types.js +0 -16
  145. package/dist/cjs/utils.js +0 -92
  146. package/dist/package.json +0 -1
  147. package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +0 -1
  148. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +0 -3
  149. package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +0 -1
  150. package/dist/plugins/vite-plugin-cedar-node-polyfills.js +0 -19
@@ -1,126 +0,0 @@
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_routes_auto_loader_exports = {};
30
- __export(vite_plugin_cedar_routes_auto_loader_exports, {
31
- cedarRoutesAutoLoaderPlugin: () => cedarRoutesAutoLoaderPlugin
32
- });
33
- module.exports = __toCommonJS(vite_plugin_cedar_routes_auto_loader_exports);
34
- var import_node_fs = __toESM(require("node:fs"), 1);
35
- var import_node_path = __toESM(require("node:path"), 1);
36
- var import_vite = require("vite");
37
- var import_project_config = require("@cedarjs/project-config");
38
- function getPathRelativeToSrc(maybeAbsolutePath) {
39
- const withoutExt = maybeAbsolutePath.replace(/\.[^/.]+$/, "");
40
- if (withoutExt.startsWith("src/")) {
41
- const basePath = import_node_path.default.join((0, import_project_config.getPaths)().web.base, withoutExt);
42
- const resolved = (0, import_project_config.resolveFile)(basePath) || (0, import_project_config.resolveFile)(import_node_path.default.join(basePath, "index")) || (0, import_project_config.resolveFile)(import_node_path.default.join(basePath, import_node_path.default.basename(basePath)));
43
- if (resolved) {
44
- const resolvedWithoutExt = resolved.replace(/\.[^/.]+$/, "");
45
- return "./" + import_node_path.default.relative((0, import_project_config.getPaths)().web.src, resolvedWithoutExt);
46
- }
47
- return "./" + withoutExt.slice("src/".length);
48
- }
49
- if (!import_node_path.default.isAbsolute(withoutExt)) {
50
- return withoutExt;
51
- }
52
- return `./${import_node_path.default.relative((0, import_project_config.getPaths)().web.src, withoutExt)}`;
53
- }
54
- function withRelativeImports(page) {
55
- return {
56
- ...page,
57
- relativeImport: (0, import_project_config.ensurePosixPath)(getPathRelativeToSrc(page.importPath))
58
- };
59
- }
60
- function cedarRoutesAutoLoaderPlugin() {
61
- const routesFileId = (0, import_vite.normalizePath)((0, import_project_config.getPaths)().web.routes);
62
- const initialPages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
63
- const duplicatePageImportNames = /* @__PURE__ */ new Set();
64
- const sortedPageImportNames = initialPages.map((page) => page.importName).sort();
65
- for (let i = 0; i < sortedPageImportNames.length - 1; i++) {
66
- if (sortedPageImportNames[i + 1] === sortedPageImportNames[i]) {
67
- duplicatePageImportNames.add(sortedPageImportNames[i]);
68
- }
69
- }
70
- if (duplicatePageImportNames.size > 0) {
71
- const pageNames = Array.from(duplicatePageImportNames).map((name) => `'${name}'`).join(", ");
72
- throw new Error(
73
- `Unable to find only a single file ending in 'Page.{js,jsx,ts,tsx}' in the following page directories: ${pageNames}`
74
- );
75
- }
76
- return {
77
- name: "cedar-routes-auto-loader",
78
- transform(code, id) {
79
- if ((0, import_vite.normalizePath)(id) !== routesFileId) {
80
- return null;
81
- }
82
- let pages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
83
- const importRe = /^import\s+\w+\s+from\s+['"]([^'"]+)['"]/gm;
84
- const appPath = (0, import_project_config.resolveFile)(import_node_path.default.join((0, import_project_config.getPaths)().web.src, "App"));
85
- if (appPath) {
86
- const appSource = import_node_fs.default.readFileSync(appPath, "utf8");
87
- let appMatch;
88
- while ((appMatch = importRe.exec(appSource)) !== null) {
89
- const rel = (0, import_project_config.ensurePosixPath)(
90
- getPathRelativeToSrc((0, import_project_config.importStatementPath)(appMatch[1]))
91
- );
92
- pages = pages.filter((page) => page.relativeImport !== rel);
93
- }
94
- }
95
- importRe.lastIndex = 0;
96
- let routesMatch;
97
- while ((routesMatch = importRe.exec(code)) !== null) {
98
- const rel = (0, import_project_config.ensurePosixPath)(
99
- getPathRelativeToSrc((0, import_project_config.importStatementPath)(routesMatch[1]))
100
- );
101
- pages = pages.filter((page) => page.relativeImport !== rel);
102
- }
103
- if (pages.length === 0) {
104
- return null;
105
- }
106
- const lines = [`import { lazy } from 'react'`];
107
- for (const { importName, relativeImport } of pages) {
108
- lines.push(
109
- `const ${importName} = {`,
110
- ` name: "${importName}",`,
111
- ` prerenderLoader: (name) => ({ default: globalThis.__REDWOOD__PRERENDER_PAGES[name] }),`,
112
- ` LazyComponent: lazy(() => import("${relativeImport}")),`,
113
- `}`
114
- );
115
- }
116
- return {
117
- code: lines.join("\n") + "\n\n" + code,
118
- map: null
119
- };
120
- }
121
- };
122
- }
123
- // Annotate the CommonJS export names for ESM import in node:
124
- 0 && (module.exports = {
125
- cedarRoutesAutoLoaderPlugin
126
- });
@@ -1,346 +0,0 @@
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_universal_deploy_exports = {};
30
- __export(vite_plugin_cedar_universal_deploy_exports, {
31
- cedarUniversalDeployPlugin: () => cedarUniversalDeployPlugin
32
- });
33
- module.exports = __toCommonJS(vite_plugin_cedar_universal_deploy_exports);
34
- var import_node_path = __toESM(require("node:path"), 1);
35
- var import_store = require("@universal-deploy/store");
36
- var import_files = require("@cedarjs/internal/dist/files.js");
37
- var import_project_config = require("@cedarjs/project-config");
38
- const VIRTUAL_CEDAR_FN_PREFIX = "virtual:cedar-api:fn:";
39
- const RESOLVED_CEDAR_FN_PREFIX = "\0virtual:cedar-api:fn:";
40
- const GRAPHQL_METHODS = ["GET", "POST", "OPTIONS"];
41
- function normaliseApiPrefix(apiPrefix) {
42
- apiPrefix = apiPrefix.trim();
43
- while (apiPrefix.startsWith("/")) {
44
- apiPrefix = apiPrefix.slice(1);
45
- }
46
- while (apiPrefix.endsWith("/")) {
47
- apiPrefix = apiPrefix.slice(0, -1);
48
- }
49
- return apiPrefix ? "/" + apiPrefix : "";
50
- }
51
- function discoverCedarRoutes(apiRootPath) {
52
- const srcFunctions = (0, import_project_config.getPaths)().api.functions;
53
- const distFunctions = import_node_path.default.join((0, import_project_config.getPaths)().api.base, "dist", "functions");
54
- const sourceFiles = (0, import_files.findApiServerFunctions)(srcFunctions);
55
- const routes = [];
56
- for (const sourcePath of sourceFiles) {
57
- const relative = import_node_path.default.relative(srcFunctions, sourcePath);
58
- const { dir, name, ext: _ext } = import_node_path.default.parse(relative);
59
- let routeName;
60
- if (dir === name) {
61
- routeName = dir;
62
- } else if (dir === "") {
63
- routeName = name;
64
- } else if (dir.length && name === "index") {
65
- routeName = dir;
66
- } else {
67
- continue;
68
- }
69
- const apiPrefix = normaliseApiPrefix(apiRootPath);
70
- const routePath = routeName === "graphql" ? `${apiPrefix}/graphql` : `${apiPrefix}/${routeName}`;
71
- const methods = routeName === "graphql" ? [...GRAPHQL_METHODS] : [];
72
- const type = routeName === "graphql" ? "graphql" : routeName === "health" ? "health" : routeName.toLowerCase().includes("auth") ? "auth" : "function";
73
- const distPath = import_node_path.default.join(distFunctions, dir, name + ".js");
74
- routes.push({
75
- id: routePath,
76
- path: routePath,
77
- methods,
78
- type,
79
- entry: distPath
80
- });
81
- }
82
- const gqlIndex = routes.findIndex((r) => r.type === "graphql");
83
- if (gqlIndex > 0) {
84
- const [gqlRoute] = routes.splice(gqlIndex, 1);
85
- routes.unshift(gqlRoute);
86
- }
87
- return routes;
88
- }
89
- function toEntryMeta(route) {
90
- const routePatterns = route.path === "/**" ? ["/**"] : [route.path, `${route.path}/**`];
91
- return {
92
- id: `${VIRTUAL_CEDAR_FN_PREFIX}${route.id}`,
93
- route: routePatterns,
94
- ...route.methods.length > 0 && {
95
- method: route.methods
96
- }
97
- };
98
- }
99
- function cedarUniversalDeployPlugin(options = {}) {
100
- const effectiveApiRootPath = process.env.CEDAR_API_ROOT_PATH ?? options.apiRootPath;
101
- const routes = discoverCedarRoutes(effectiveApiRootPath ?? "/");
102
- return {
103
- name: "cedar-universal-deploy",
104
- apply: "build",
105
- config: {
106
- order: "pre",
107
- handler() {
108
- for (const route of routes) {
109
- (0, import_store.addEntry)(toEntryMeta(route));
110
- }
111
- }
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
- },
128
- resolveId(id) {
129
- const viteEnv = this.environment;
130
- if (viteEnv.config.consumer === "client" || viteEnv.name === "api") {
131
- return void 0;
132
- }
133
- if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
134
- return id;
135
- }
136
- if (id.startsWith(VIRTUAL_CEDAR_FN_PREFIX)) {
137
- return "\0" + id;
138
- }
139
- return void 0;
140
- },
141
- async load(id) {
142
- const viteEnv = this.environment;
143
- if (viteEnv.config.consumer === "client" || viteEnv.name === "api") {
144
- return void 0;
145
- }
146
- if (id.startsWith(RESOLVED_CEDAR_FN_PREFIX)) {
147
- const routeId = id.slice(RESOLVED_CEDAR_FN_PREFIX.length);
148
- const route = routes.find((r) => r.id === routeId);
149
- if (!route) {
150
- return void 0;
151
- }
152
- if (route.type === "graphql") {
153
- return generateGraphQLModule(route.entry);
154
- }
155
- return generateFunctionModule(route.entry);
156
- }
157
- return void 0;
158
- }
159
- };
160
- }
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
- });
225
- return `
226
- import { buildCedarContext, noopAuthDecoder, 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?.authDecoder ?? noopAuthDecoder,
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
- };
286
- `;
287
- }
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
- );
293
- return `
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
- // Wrap the handler in an AsyncLocalStorage run so the global
331
- // @cedarjs/context is available inside it (and isolated per request).
332
- // Mirrors the GraphQL module above and the cedarContextWrappingPlugin
333
- // used for non-UD builds.
334
- const { getAsyncStoreInstance } = await import(
335
- '@cedarjs/context/dist/store'
336
- );
337
- const store = getAsyncStoreInstance();
338
- return store.run(new Map(), () => _handler(request, ctx));
339
- }
340
- };
341
- `;
342
- }
343
- // Annotate the CommonJS export names for ESM import in node:
344
- 0 && (module.exports = {
345
- cedarUniversalDeployPlugin
346
- });
@@ -1,134 +0,0 @@
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
- const isUnifiedDev = process.env.__CEDAR_UNIFIED_DEV === "true";
43
- return {
44
- name: "cedar-wait-for-api-server",
45
- apply: "serve",
46
- configureServer(server) {
47
- server.middlewares.use(async (req, res, next) => {
48
- const url = req.originalUrl;
49
- const apiUrl = cedarConfig.web.apiUrl.replace(/\/$/, "");
50
- const apiGqlUrl = cedarConfig.web.apiGraphQLUrl ?? apiUrl + "/graphql";
51
- const isApiRequest = url && (url.startsWith(apiUrl) || // Only match on .../graphql not on .../graphql-foo. That's why I
52
- // don't use startsWith here
53
- url === apiGqlUrl || // The two checks below are for when we support GraphQL-over-HTTP
54
- url.startsWith(apiGqlUrl + "/") || url.startsWith(apiGqlUrl + "?"));
55
- if (!isApiRequest || serverHasBeenUp || isUnifiedDev) {
56
- return next();
57
- }
58
- try {
59
- if (!waitingPromise) {
60
- waitingPromise = waitForPort(apiPort, apiHost).finally(() => {
61
- waitingPromise = null;
62
- });
63
- }
64
- await waitingPromise;
65
- serverHasBeenUp = true;
66
- } catch {
67
- const message = `Vite timed out waiting for the Cedar API server at ${apiHost}:${apiPort}
68
- Please manually refresh the page when the server is ready`;
69
- console.error(message);
70
- const isAuthTokenRequest = url === apiUrl + "/auth?method=getToken";
71
- const responseBody = {
72
- errors: [{ message }]
73
- };
74
- req.resume();
75
- const body = JSON.stringify(responseBody);
76
- res.writeHead(203, {
77
- "Content-Type": "application/json",
78
- "Cache-Control": "no-cache",
79
- ...!isAuthTokenRequest && {
80
- "Content-Length": Buffer.byteLength(body)
81
- },
82
- Connection: "close"
83
- });
84
- return isAuthTokenRequest ? res.end() : res.end(body);
85
- }
86
- next();
87
- });
88
- }
89
- };
90
- }
91
- const ONE_MINUTE_IN_MS = 6e4;
92
- async function waitForPort(port, host) {
93
- const start = Date.now();
94
- let lastLogTime = Date.now();
95
- while (Date.now() - start < ONE_MINUTE_IN_MS) {
96
- const isOpen = await checkPort(port, host);
97
- if (isOpen) {
98
- if (lastLogTime - start >= 6e3) {
99
- console.log("\u2705 API server is ready");
100
- }
101
- return;
102
- }
103
- const now = Date.now();
104
- if (now - lastLogTime >= 6e3) {
105
- console.log("\u23F3 Waiting for API server...");
106
- lastLogTime = now;
107
- }
108
- await new Promise((resolve) => setTimeout(resolve, 500));
109
- }
110
- throw new Error("Timeout waiting for port");
111
- }
112
- function checkPort(port, host) {
113
- return new Promise((resolve) => {
114
- const socket = new import_node_net.default.Socket();
115
- socket.setTimeout(200);
116
- socket.on("connect", () => {
117
- socket.destroy();
118
- resolve(true);
119
- });
120
- socket.on("timeout", () => {
121
- socket.destroy();
122
- resolve(false);
123
- });
124
- socket.on("error", () => {
125
- socket.destroy();
126
- resolve(false);
127
- });
128
- socket.connect(port, host);
129
- });
130
- }
131
- // Annotate the CommonJS export names for ESM import in node:
132
- 0 && (module.exports = {
133
- cedarWaitForApiServer
134
- });