@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,125 +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_rsc_routes_imports_exports = {};
30
- __export(vite_plugin_rsc_routes_imports_exports, {
31
- rscRoutesImports: () => rscRoutesImports
32
- });
33
- module.exports = __toCommonJS(vite_plugin_rsc_routes_imports_exports);
34
- var import_node_path = __toESM(require("node:path"), 1);
35
- var import_generator = __toESM(require("@babel/generator"), 1);
36
- var import_parser = require("@babel/parser");
37
- var import_traverse = __toESM(require("@babel/traverse"), 1);
38
- var t = __toESM(require("@babel/types"), 1);
39
- var import_vite = require("vite");
40
- var import_project_config = require("@cedarjs/project-config");
41
- const { default: generate } = import_generator.default;
42
- const { default: traverse } = import_traverse.default;
43
- const getPathRelativeToSrc = (maybeAbsolutePath) => {
44
- if (!import_node_path.default.isAbsolute(maybeAbsolutePath)) {
45
- return maybeAbsolutePath;
46
- }
47
- return `./${import_node_path.default.relative((0, import_project_config.getPaths)().web.src, maybeAbsolutePath)}`;
48
- };
49
- const withRelativeImports = (page) => {
50
- return {
51
- ...page,
52
- relativeImport: (0, import_project_config.ensurePosixPath)(getPathRelativeToSrc(page.importPath))
53
- };
54
- };
55
- function rscRoutesImports() {
56
- const routesFileId = (0, import_vite.normalizePath)((0, import_project_config.getPaths)().web.routes);
57
- const pages = (0, import_project_config.processPagesDir)().map(withRelativeImports);
58
- const duplicatePageImportNames = /* @__PURE__ */ new Set();
59
- const sortedPageImportNames = pages.map((page) => page.importName).sort();
60
- for (let i = 0; i < sortedPageImportNames.length - 1; i++) {
61
- if (sortedPageImportNames[i + 1] === sortedPageImportNames[i]) {
62
- duplicatePageImportNames.add(sortedPageImportNames[i]);
63
- }
64
- }
65
- if (duplicatePageImportNames.size > 0) {
66
- const pageNames = Array.from(duplicatePageImportNames).map((name) => `'${name}'`).join(", ");
67
- throw new Error(
68
- `Unable to find only a single file ending in 'Page.{js,jsx,ts,tsx}' in the following page directories: ${pageNames}`
69
- );
70
- }
71
- return {
72
- name: "rsc-routes-imports",
73
- transform: async function(code, id) {
74
- if (id !== routesFileId) {
75
- return null;
76
- }
77
- if (pages.length === 0) {
78
- return null;
79
- }
80
- const ext = import_node_path.default.extname(id);
81
- const plugins = [];
82
- if (ext === ".jsx") {
83
- plugins.push("jsx");
84
- }
85
- const ast = (0, import_parser.parse)(code, {
86
- sourceType: "unambiguous",
87
- plugins
88
- });
89
- const importedNames = /* @__PURE__ */ new Set();
90
- traverse(ast, {
91
- ImportDeclaration(path2) {
92
- const importPath = path2.node.source.value;
93
- if (importPath === null) {
94
- return;
95
- }
96
- const userImportRelativePath = getPathRelativeToSrc(
97
- (0, import_project_config.importStatementPath)(path2.node.source?.value)
98
- );
99
- const defaultSpecifier = path2.node.specifiers.find(
100
- (specifier) => t.isImportDefaultSpecifier(specifier)
101
- );
102
- if (userImportRelativePath && defaultSpecifier) {
103
- importedNames.add(defaultSpecifier.local.name);
104
- }
105
- }
106
- });
107
- const nonImportedPages = pages.filter((page) => {
108
- return !importedNames.has(page.importName);
109
- });
110
- for (const page of nonImportedPages) {
111
- ast.program.body.unshift(
112
- t.importDeclaration(
113
- [t.importDefaultSpecifier(t.identifier(page.importName))],
114
- t.stringLiteral(page.importPath)
115
- )
116
- );
117
- }
118
- return generate(ast).code;
119
- }
120
- };
121
- }
122
- // Annotate the CommonJS export names for ESM import in node:
123
- 0 && (module.exports = {
124
- rscRoutesImports
125
- });
@@ -1,75 +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_rsc_ssr_router_import_exports = {};
30
- __export(vite_plugin_rsc_ssr_router_import_exports, {
31
- rscSsrRouterImport: () => rscSsrRouterImport
32
- });
33
- module.exports = __toCommonJS(vite_plugin_rsc_ssr_router_import_exports);
34
- var import_node_path = __toESM(require("node:path"), 1);
35
- var import_generator = __toESM(require("@babel/generator"), 1);
36
- var import_parser = require("@babel/parser");
37
- var import_traverse = __toESM(require("@babel/traverse"), 1);
38
- var t = __toESM(require("@babel/types"), 1);
39
- var import_vite = require("vite");
40
- var import_project_config = require("@cedarjs/project-config");
41
- const { default: generate } = import_generator.default;
42
- const { default: traverse } = import_traverse.default;
43
- function rscSsrRouterImport() {
44
- const routesFileId = (0, import_vite.normalizePath)((0, import_project_config.getPaths)().web.routes);
45
- return {
46
- name: "rsc-ssr-router-import",
47
- transform: async function(code, id) {
48
- if (id !== routesFileId) {
49
- return null;
50
- }
51
- const ext = import_node_path.default.extname(id);
52
- const plugins = [];
53
- if (ext === ".jsx") {
54
- plugins.push("jsx");
55
- }
56
- const ast = (0, import_parser.parse)(code, {
57
- sourceType: "unambiguous",
58
- plugins
59
- });
60
- traverse(ast, {
61
- ImportDeclaration(path2) {
62
- const source = path2.node.source.value;
63
- if (source === "@cedarjs/router/RscRouter") {
64
- path2.node.source = t.stringLiteral("@cedarjs/router/SsrRouter");
65
- }
66
- }
67
- });
68
- return generate(ast).code;
69
- }
70
- };
71
- }
72
- // Annotate the CommonJS export names for ESM import in node:
73
- 0 && (module.exports = {
74
- rscSsrRouterImport
75
- });
@@ -1,228 +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_rsc_transform_client_exports = {};
30
- __export(vite_plugin_rsc_transform_client_exports, {
31
- rscTransformUseClientPlugin: () => rscTransformUseClientPlugin
32
- });
33
- module.exports = __toCommonJS(vite_plugin_rsc_transform_client_exports);
34
- var import_node_path = __toESM(require("node:path"), 1);
35
- var acorn = __toESM(require("acorn-loose"), 1);
36
- var import_vite = require("vite");
37
- var import_project_config = require("@cedarjs/project-config");
38
- function rscTransformUseClientPlugin(clientEntryFiles) {
39
- return {
40
- name: "rsc-transform-use-client-plugin",
41
- transform: async function(code, id) {
42
- if (!code.includes("use client")) {
43
- return code;
44
- }
45
- if (code.includes("$$id")) {
46
- return code;
47
- }
48
- let body;
49
- try {
50
- body = acorn.parse(code, {
51
- ecmaVersion: 2024,
52
- sourceType: "module"
53
- }).body;
54
- } catch (x) {
55
- console.error("Error parsing %s %s", id, x.message);
56
- return code;
57
- }
58
- let useClient = false;
59
- let useServer = false;
60
- for (const node of body) {
61
- if (node.type !== "ExpressionStatement" || !node.directive) {
62
- break;
63
- }
64
- if (node.directive === "use client") {
65
- useClient = true;
66
- }
67
- if (node.directive === "use server") {
68
- useServer = true;
69
- }
70
- }
71
- if (!useClient) {
72
- return code;
73
- }
74
- if (useClient && useServer) {
75
- throw new Error(
76
- 'Cannot have both "use client" and "use server" directives in the same file.'
77
- );
78
- }
79
- const transformedCode = await transformClientModule(
80
- code,
81
- body,
82
- id,
83
- clientEntryFiles
84
- );
85
- return transformedCode;
86
- }
87
- };
88
- }
89
- function addExportNames(names, node) {
90
- switch (node.type) {
91
- case "Identifier":
92
- names.push(node.name);
93
- return;
94
- case "ObjectPattern":
95
- for (const property of node.properties) {
96
- addExportNames(names, property);
97
- }
98
- return;
99
- case "ArrayPattern":
100
- for (const element of node.elements) {
101
- if (element) {
102
- addExportNames(names, element);
103
- }
104
- }
105
- return;
106
- case "Property":
107
- addExportNames(names, node.value);
108
- return;
109
- case "AssignmentPattern":
110
- addExportNames(names, node.left);
111
- return;
112
- case "RestElement":
113
- addExportNames(names, node.argument);
114
- return;
115
- case "ParenthesizedExpression":
116
- addExportNames(names, node.expression);
117
- return;
118
- }
119
- }
120
- async function parseExportNamesIntoNames(code, body, names) {
121
- for (const node of body) {
122
- switch (node.type) {
123
- case "ExportAllDeclaration":
124
- if (node.exported) {
125
- addExportNames(names, node.exported);
126
- continue;
127
- } else {
128
- let childBody;
129
- try {
130
- childBody = acorn.parse(code, {
131
- ecmaVersion: 2024,
132
- sourceType: "module"
133
- }).body;
134
- } catch (x) {
135
- console.error("Error parsing %s %s", "", x.message);
136
- continue;
137
- }
138
- await parseExportNamesIntoNames(code, childBody, names);
139
- continue;
140
- }
141
- case "ExportDefaultDeclaration":
142
- names.push("default");
143
- continue;
144
- case "ExportNamedDeclaration":
145
- if (node.declaration) {
146
- if (node.declaration.type === "VariableDeclaration") {
147
- const declarations = node.declaration.declarations;
148
- for (const declaration of declarations) {
149
- addExportNames(names, declaration.id);
150
- }
151
- } else {
152
- addExportNames(names, node.declaration.id);
153
- }
154
- }
155
- if (node.specifiers) {
156
- const specifiers = node.specifiers;
157
- for (const specifier of specifiers) {
158
- addExportNames(names, specifier.exported);
159
- }
160
- }
161
- continue;
162
- // For CJS support
163
- case "ExpressionStatement": {
164
- let assignmentExpression = null;
165
- if (node.expression.type === "AssignmentExpression") {
166
- assignmentExpression = node.expression;
167
- } else if (node.expression.type === "LogicalExpression" && node.expression.right.type === "AssignmentExpression") {
168
- assignmentExpression = node.expression.right;
169
- }
170
- if (!assignmentExpression) {
171
- continue;
172
- }
173
- if (assignmentExpression.left.type !== "MemberExpression") {
174
- continue;
175
- }
176
- if (assignmentExpression.left.object.type !== "Identifier") {
177
- continue;
178
- }
179
- if (assignmentExpression.left.object.name === "exports" && assignmentExpression.left.property.type === "Identifier") {
180
- if (!names.includes(assignmentExpression.left.property.name)) {
181
- names.push(assignmentExpression.left.property.name);
182
- }
183
- } else if (assignmentExpression.left.object.name === "module" && assignmentExpression.left.property.type === "Identifier" && assignmentExpression.left.property.name === "exports" && assignmentExpression.right.type === "ObjectExpression") {
184
- assignmentExpression.right.properties.forEach((property) => {
185
- if (property.type === "Property" && property.key.type === "Identifier") {
186
- if (!names.includes(property.key.name)) {
187
- names.push(property.key.name);
188
- }
189
- }
190
- });
191
- }
192
- continue;
193
- }
194
- }
195
- }
196
- }
197
- async function transformClientModule(code, body, url, clientEntryFiles) {
198
- const names = [];
199
- await parseExportNamesIntoNames(code, body, names);
200
- const entryRecord = Object.entries(clientEntryFiles).find(
201
- ([_key, value]) => value === url
202
- );
203
- const loadId = (0, import_vite.normalizePath)(
204
- entryRecord ? import_node_path.default.join((0, import_project_config.getPaths)().web.distRsc, "assets", `${entryRecord[0]}.mjs`) : url
205
- );
206
- let newSrc = 'import {registerClientReference} from "react-server-dom-webpack/server";\n';
207
- for (const name of names) {
208
- if (name === "default") {
209
- newSrc += "export default registerClientReference(function() {";
210
- newSrc += "throw new Error(" + JSON.stringify(
211
- "Attempted to call the default export of " + url + " from the server but it's on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component."
212
- ) + ");";
213
- } else {
214
- newSrc += "export const " + name + " = ";
215
- newSrc += "registerClientReference(function() {";
216
- newSrc += "throw new Error(" + JSON.stringify(
217
- "Attempted to call " + name + "() from the server but " + name + " is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component."
218
- ) + ");";
219
- }
220
- newSrc += `},${JSON.stringify(loadId)},${JSON.stringify(name)})
221
- ;`;
222
- }
223
- return newSrc;
224
- }
225
- // Annotate the CommonJS export names for ESM import in node:
226
- 0 && (module.exports = {
227
- rscTransformUseClientPlugin
228
- });