@vistagenic/vista 0.3.2 → 0.3.3

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 (98) hide show
  1. package/bin/vista.js +79 -109
  2. package/dist/ai/embeddings.d.ts +11 -11
  3. package/dist/ai/embeddings.js +71 -71
  4. package/dist/ai/index.d.ts +10 -10
  5. package/dist/ai/index.js +26 -26
  6. package/dist/ai/providers/base.js +85 -85
  7. package/dist/ai/react/react-server.d.ts +1 -1
  8. package/dist/ai/react/react-server.js +17 -17
  9. package/dist/ai/react/use-agent.js +138 -138
  10. package/dist/auth/core.d.ts +140 -140
  11. package/dist/auth/core.js +165 -165
  12. package/dist/auth/index.d.ts +20 -20
  13. package/dist/auth/index.js +369 -369
  14. package/dist/auth/react-server.d.ts +1 -1
  15. package/dist/auth/react-server.js +10 -10
  16. package/dist/auth/react.d.ts +18 -18
  17. package/dist/auth/react.js +71 -71
  18. package/dist/bin/build-rsc-flashpack.js +6 -0
  19. package/dist/bin/build-rsc.js +537 -492
  20. package/dist/bin/build.js +355 -353
  21. package/dist/bin/generate.js +513 -510
  22. package/dist/bin/webpack.config.js +4 -3
  23. package/dist/build/manifest.d.ts +169 -169
  24. package/dist/build/manifest.js +423 -423
  25. package/dist/build/rsc/client-manifest.d.ts +62 -62
  26. package/dist/build/rsc/client-manifest.js +295 -295
  27. package/dist/build/rsc/compiler.js +5 -4
  28. package/dist/build/rsc/native-scanner.d.ts +135 -135
  29. package/dist/build/rsc/native-scanner.js +203 -203
  30. package/dist/build/rsc/react-client-reference-manifest.d.ts +28 -28
  31. package/dist/build/rsc/react-client-reference-manifest.js +240 -240
  32. package/dist/build/standalone.js +260 -254
  33. package/dist/client/dynamic.react-server.d.ts +2 -2
  34. package/dist/client/dynamic.react-server.js +23 -23
  35. package/dist/client/link.react-server.d.ts +2 -2
  36. package/dist/client/link.react-server.js +11 -11
  37. package/dist/client/navigation.react-server.d.ts +1 -1
  38. package/dist/client/navigation.react-server.js +17 -17
  39. package/dist/client/router.react-server.d.ts +1 -1
  40. package/dist/client/router.react-server.js +17 -17
  41. package/dist/client/rsc-router.react-server.d.ts +1 -1
  42. package/dist/client/rsc-router.react-server.js +17 -17
  43. package/dist/client/script.react-server.d.ts +2 -2
  44. package/dist/client/script.react-server.js +23 -23
  45. package/dist/config.d.ts +1 -1
  46. package/dist/config.js +1 -7
  47. package/dist/deploy/adapters/cloudflare.js +43 -19
  48. package/dist/deploy/adapters/docker.d.ts +1 -0
  49. package/dist/deploy/adapters/docker.js +5 -4
  50. package/dist/deploy/adapters/netlify.js +62 -17
  51. package/dist/deploy/adapters/vercel.js +80 -50
  52. package/dist/deploy/preflight.js +4 -3
  53. package/dist/deploy/runtime-pack.d.ts +11 -0
  54. package/dist/deploy/runtime-pack.js +300 -0
  55. package/dist/deploy/utils.d.ts +1 -1
  56. package/dist/deploy/utils.js +31 -2
  57. package/dist/flashpack/command.js +1 -0
  58. package/dist/flashpack/runtime.js +2 -1
  59. package/dist/index.d.ts +23 -23
  60. package/dist/index.js +61 -61
  61. package/dist/server/app-dir.d.ts +22 -0
  62. package/dist/server/app-dir.js +77 -0
  63. package/dist/server/cookie-parse.d.ts +4 -4
  64. package/dist/server/cookie-parse.js +14 -14
  65. package/dist/server/engine.js +5 -5
  66. package/dist/server/image-optimizer.js +2 -1
  67. package/dist/server/index.d.ts +109 -109
  68. package/dist/server/index.js +315 -315
  69. package/dist/server/middleware-runner.d.ts +125 -125
  70. package/dist/server/middleware-runner.js +607 -615
  71. package/dist/server/middleware-security.d.ts +36 -36
  72. package/dist/server/middleware-security.js +183 -183
  73. package/dist/server/module-compile-hook.js +695 -695
  74. package/dist/server/root-resolver.js +6 -5
  75. package/dist/server/rsc-engine-flashpack.d.ts +3 -1
  76. package/dist/server/rsc-engine-flashpack.js +12 -1
  77. package/dist/server/rsc-engine.d.ts +6 -1
  78. package/dist/server/rsc-engine.js +203 -219
  79. package/dist/server/rsc-upstream.js +893 -892
  80. package/dist/server/static-generator.js +4 -3
  81. package/dist/server/structure-validator.js +2 -1
  82. package/dist/server/structure-watch.js +2 -0
  83. package/dist/server/typed-api-runtime.js +639 -635
  84. package/dist/server/vista-import-map.js +134 -134
  85. package/dist/stack/index.d.ts +34 -34
  86. package/dist/stack/index.js +49 -49
  87. package/dist/stack/server/caller.d.ts +13 -13
  88. package/dist/stack/server/caller.js +42 -42
  89. package/dist/stack/server/executor.d.ts +40 -40
  90. package/dist/stack/server/executor.js +222 -222
  91. package/dist/stack/server/index.d.ts +11 -11
  92. package/dist/stack/server/index.js +24 -24
  93. package/dist/stack/server/procedure.d.ts +20 -20
  94. package/dist/stack/server/procedure.js +66 -66
  95. package/dist/stack/server/types.d.ts +113 -113
  96. package/dist/theme/react-server.d.ts +10 -10
  97. package/dist/theme/react-server.js +16 -16
  98. package/package.json +1 -1
@@ -1,28 +1,28 @@
1
- export interface ReactClientReferenceManifestEntry {
2
- id: string | number;
3
- chunks: Array<string | number>;
4
- name: string;
5
- }
6
- export type ReactClientReferenceManifest = Record<string, ReactClientReferenceManifestEntry>;
7
- export interface ReactServerConsumerManifestEntry {
8
- specifier?: string;
9
- id?: string | number;
10
- chunks?: Array<string | number>;
11
- name?: string;
12
- }
13
- export interface ReactServerConsumerManifest {
14
- moduleLoading?: {
15
- prefix: string;
16
- crossOrigin: string | null;
17
- };
18
- moduleMap?: Record<string, Record<string, ReactServerConsumerManifestEntry>>;
19
- serverModuleMap?: Record<string, unknown>;
20
- }
21
- export declare function normalizeReactClientReferenceManifest(input: ReactClientReferenceManifest): ReactClientReferenceManifest;
22
- export declare function normalizeReactServerConsumerManifest(input: ReactServerConsumerManifest): ReactServerConsumerManifest;
23
- /**
24
- * React looks up `file://...#ExportName` in the Flight manifest and throws a
25
- * generic error when the key is missing. Wrap the manifest so the message names
26
- * the file and the scan-directory requirement.
27
- */
28
- export declare function createGuardedReactClientManifest(manifest: ReactClientReferenceManifest): ReactClientReferenceManifest;
1
+ export interface ReactClientReferenceManifestEntry {
2
+ id: string | number;
3
+ chunks: Array<string | number>;
4
+ name: string;
5
+ }
6
+ export type ReactClientReferenceManifest = Record<string, ReactClientReferenceManifestEntry>;
7
+ export interface ReactServerConsumerManifestEntry {
8
+ specifier?: string;
9
+ id?: string | number;
10
+ chunks?: Array<string | number>;
11
+ name?: string;
12
+ }
13
+ export interface ReactServerConsumerManifest {
14
+ moduleLoading?: {
15
+ prefix: string;
16
+ crossOrigin: string | null;
17
+ };
18
+ moduleMap?: Record<string, Record<string, ReactServerConsumerManifestEntry>>;
19
+ serverModuleMap?: Record<string, unknown>;
20
+ }
21
+ export declare function normalizeReactClientReferenceManifest(input: ReactClientReferenceManifest): ReactClientReferenceManifest;
22
+ export declare function normalizeReactServerConsumerManifest(input: ReactServerConsumerManifest): ReactServerConsumerManifest;
23
+ /**
24
+ * React looks up `file://...#ExportName` in the Flight manifest and throws a
25
+ * generic error when the key is missing. Wrap the manifest so the message names
26
+ * the file and the scan-directory requirement.
27
+ */
28
+ export declare function createGuardedReactClientManifest(manifest: ReactClientReferenceManifest): ReactClientReferenceManifest;
@@ -1,240 +1,240 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.normalizeReactClientReferenceManifest = normalizeReactClientReferenceManifest;
7
- exports.normalizeReactServerConsumerManifest = normalizeReactServerConsumerManifest;
8
- exports.createGuardedReactClientManifest = createGuardedReactClientManifest;
9
- const fs_1 = __importDefault(require("fs"));
10
- const url_1 = require("url");
11
- function extractExportNames(source) {
12
- const exports = new Set();
13
- if (/export\s+default\s+/.test(source)) {
14
- exports.add('default');
15
- }
16
- const namedExportRegex = /export\s+(?:async\s+)?(?:function|const|let|var|class)\s+([A-Za-z_$][\w$]*)/g;
17
- let match;
18
- while ((match = namedExportRegex.exec(source)) !== null) {
19
- exports.add(match[1]);
20
- }
21
- const reExportRegex = /export\s+\{([^}]+)\}/g;
22
- while ((match = reExportRegex.exec(source)) !== null) {
23
- const names = match[1]
24
- .split(',')
25
- .map((entry) => entry
26
- .trim()
27
- .split(/\s+as\s+/)
28
- .pop()
29
- ?.trim())
30
- .filter(Boolean);
31
- for (const name of names) {
32
- exports.add(name);
33
- }
34
- }
35
- const commonJsExportRegex = /exports\.([A-Za-z_$][\w$]*)\s*=/g;
36
- while ((match = commonJsExportRegex.exec(source)) !== null) {
37
- if (match[1] !== '__esModule') {
38
- exports.add(match[1]);
39
- }
40
- }
41
- if (/module\.exports\s*=/.test(source) || /exports\.default\s*=/.test(source)) {
42
- exports.add('default');
43
- }
44
- return Array.from(exports);
45
- }
46
- function resolveManifestFilePath(specifier) {
47
- const baseSpecifier = specifier.split('#', 1)[0];
48
- if (!baseSpecifier.startsWith('file://')) {
49
- return null;
50
- }
51
- try {
52
- return (0, url_1.fileURLToPath)(baseSpecifier);
53
- }
54
- catch {
55
- try {
56
- return decodeURI(baseSpecifier
57
- .replace(/^file:\/\/\//, '')
58
- .replace(/^file:\/\//, ''));
59
- }
60
- catch {
61
- return null;
62
- }
63
- }
64
- }
65
- function addDriveLetterVariants(specifier, variants) {
66
- variants.add(specifier);
67
- const match = specifier.match(/^file:\/\/\/([A-Za-z]):/);
68
- if (!match) {
69
- return;
70
- }
71
- const lowerDrive = match[1].toLowerCase();
72
- const upperDrive = match[1].toUpperCase();
73
- variants.add(specifier.replace(/^file:\/\/\/([A-Za-z]):/, `file:///${lowerDrive}:`));
74
- variants.add(specifier.replace(/^file:\/\/\/([A-Za-z]):/, `file:///${upperDrive}:`));
75
- }
76
- function buildSpecifierVariants(specifier) {
77
- const baseSpecifier = specifier.split('#', 1)[0];
78
- const variants = new Set();
79
- addDriveLetterVariants(baseSpecifier, variants);
80
- if (baseSpecifier.startsWith('file://')) {
81
- try {
82
- addDriveLetterVariants(decodeURI(baseSpecifier), variants);
83
- }
84
- catch {
85
- // ignore decode failures
86
- }
87
- try {
88
- addDriveLetterVariants((0, url_1.pathToFileURL)((0, url_1.fileURLToPath)(baseSpecifier)).toString(), variants);
89
- }
90
- catch {
91
- // ignore encode failures
92
- }
93
- }
94
- return Array.from(variants);
95
- }
96
- function createAliasedEntry(entry, exportName) {
97
- if (exportName === '') {
98
- return {
99
- ...entry,
100
- name: '',
101
- };
102
- }
103
- return {
104
- ...entry,
105
- name: exportName,
106
- };
107
- }
108
- function normalizeReactClientReferenceManifest(input) {
109
- const manifest = { ...input };
110
- for (const [rawSpecifier, rawEntry] of Object.entries(input || {})) {
111
- if (!rawEntry || typeof rawEntry !== 'object') {
112
- continue;
113
- }
114
- const entry = {
115
- id: rawEntry.id,
116
- chunks: Array.isArray(rawEntry.chunks) ? rawEntry.chunks : [],
117
- name: rawEntry.name || '*',
118
- };
119
- const sourcePath = resolveManifestFilePath(rawSpecifier);
120
- const exportNames = new Set();
121
- if (entry.name && entry.name !== '*') {
122
- exportNames.add(entry.name);
123
- }
124
- if (sourcePath && fs_1.default.existsSync(sourcePath)) {
125
- try {
126
- const source = fs_1.default.readFileSync(sourcePath, 'utf-8');
127
- for (const exportName of extractExportNames(source)) {
128
- exportNames.add(exportName);
129
- }
130
- }
131
- catch {
132
- // Keep manifest normalization resilient even if a source file disappears mid-build.
133
- }
134
- }
135
- for (const baseSpecifier of buildSpecifierVariants(rawSpecifier)) {
136
- if (!manifest[baseSpecifier]) {
137
- manifest[baseSpecifier] = entry;
138
- }
139
- const emptyExportKey = `${baseSpecifier}#`;
140
- if (!manifest[emptyExportKey]) {
141
- manifest[emptyExportKey] = createAliasedEntry(entry, '');
142
- }
143
- const defaultExportKey = `${baseSpecifier}#default`;
144
- if (!manifest[defaultExportKey]) {
145
- manifest[defaultExportKey] = createAliasedEntry(entry, 'default');
146
- }
147
- for (const exportName of exportNames) {
148
- const exportKey = `${baseSpecifier}#${exportName}`;
149
- if (!manifest[exportKey]) {
150
- manifest[exportKey] = createAliasedEntry(entry, exportName);
151
- }
152
- }
153
- }
154
- }
155
- return manifest;
156
- }
157
- function normalizeReactServerConsumerManifest(input) {
158
- if (!input?.moduleMap) {
159
- return input;
160
- }
161
- for (const [moduleKey, rawExportsMap] of Object.entries(input.moduleMap)) {
162
- const normalizedExportsMap = {};
163
- const exportNames = new Set();
164
- let sourceSpecifier = null;
165
- let seedEntry = null;
166
- for (const [exportName, rawEntry] of Object.entries(rawExportsMap || {})) {
167
- const entry = {
168
- id: rawEntry?.id ?? rawEntry?.specifier ?? moduleKey,
169
- chunks: Array.isArray(rawEntry?.chunks) ? rawEntry.chunks : [],
170
- name: rawEntry?.name || exportName,
171
- };
172
- normalizedExportsMap[exportName] = entry;
173
- if (exportName !== '*') {
174
- exportNames.add(exportName);
175
- }
176
- if (entry.name && entry.name !== '*') {
177
- exportNames.add(entry.name);
178
- }
179
- if (!seedEntry) {
180
- seedEntry = entry;
181
- }
182
- if (!sourceSpecifier && typeof entry.id === 'string' && entry.id.startsWith('file://')) {
183
- sourceSpecifier = entry.id;
184
- }
185
- if (!sourceSpecifier && typeof rawEntry?.specifier === 'string' && rawEntry.specifier.startsWith('file://')) {
186
- sourceSpecifier = rawEntry.specifier;
187
- }
188
- }
189
- const sourcePath = sourceSpecifier ? resolveManifestFilePath(sourceSpecifier) : null;
190
- if (sourcePath && fs_1.default.existsSync(sourcePath)) {
191
- try {
192
- const source = fs_1.default.readFileSync(sourcePath, 'utf-8');
193
- for (const exportName of extractExportNames(source)) {
194
- exportNames.add(exportName);
195
- }
196
- }
197
- catch {
198
- // Keep manifest normalization resilient even if the source file changes mid-build.
199
- }
200
- }
201
- if (seedEntry) {
202
- if (!normalizedExportsMap['*']) {
203
- normalizedExportsMap['*'] = {
204
- ...seedEntry,
205
- name: '*',
206
- };
207
- }
208
- for (const exportName of exportNames) {
209
- if (!normalizedExportsMap[exportName]) {
210
- normalizedExportsMap[exportName] = {
211
- ...seedEntry,
212
- name: exportName,
213
- };
214
- }
215
- }
216
- }
217
- input.moduleMap[moduleKey] = normalizedExportsMap;
218
- }
219
- return input;
220
- }
221
- /**
222
- * React looks up `file://...#ExportName` in the Flight manifest and throws a
223
- * generic error when the key is missing. Wrap the manifest so the message names
224
- * the file and the scan-directory requirement.
225
- */
226
- function createGuardedReactClientManifest(manifest) {
227
- return new Proxy(manifest, {
228
- get(target, prop, receiver) {
229
- if (typeof prop === 'string' &&
230
- (prop.startsWith('file:') || prop.includes('#')) &&
231
- !Object.prototype.hasOwnProperty.call(target, prop)) {
232
- const fileHint = prop.split('#')[0];
233
- throw new Error(`Could not find the module "${prop}" in the React Client Manifest. ` +
234
- `Client Components need a 'use client' directive and must live under a scanned project directory ` +
235
- `(app/, components/, utils/, lib/, src/, ...). Missing: ${fileHint}`);
236
- }
237
- return Reflect.get(target, prop, receiver);
238
- },
239
- });
240
- }
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.normalizeReactClientReferenceManifest = normalizeReactClientReferenceManifest;
7
+ exports.normalizeReactServerConsumerManifest = normalizeReactServerConsumerManifest;
8
+ exports.createGuardedReactClientManifest = createGuardedReactClientManifest;
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const url_1 = require("url");
11
+ function extractExportNames(source) {
12
+ const exports = new Set();
13
+ if (/export\s+default\s+/.test(source)) {
14
+ exports.add('default');
15
+ }
16
+ const namedExportRegex = /export\s+(?:async\s+)?(?:function|const|let|var|class)\s+([A-Za-z_$][\w$]*)/g;
17
+ let match;
18
+ while ((match = namedExportRegex.exec(source)) !== null) {
19
+ exports.add(match[1]);
20
+ }
21
+ const reExportRegex = /export\s+\{([^}]+)\}/g;
22
+ while ((match = reExportRegex.exec(source)) !== null) {
23
+ const names = match[1]
24
+ .split(',')
25
+ .map((entry) => entry
26
+ .trim()
27
+ .split(/\s+as\s+/)
28
+ .pop()
29
+ ?.trim())
30
+ .filter(Boolean);
31
+ for (const name of names) {
32
+ exports.add(name);
33
+ }
34
+ }
35
+ const commonJsExportRegex = /exports\.([A-Za-z_$][\w$]*)\s*=/g;
36
+ while ((match = commonJsExportRegex.exec(source)) !== null) {
37
+ if (match[1] !== '__esModule') {
38
+ exports.add(match[1]);
39
+ }
40
+ }
41
+ if (/module\.exports\s*=/.test(source) || /exports\.default\s*=/.test(source)) {
42
+ exports.add('default');
43
+ }
44
+ return Array.from(exports);
45
+ }
46
+ function resolveManifestFilePath(specifier) {
47
+ const baseSpecifier = specifier.split('#', 1)[0];
48
+ if (!baseSpecifier.startsWith('file://')) {
49
+ return null;
50
+ }
51
+ try {
52
+ return (0, url_1.fileURLToPath)(baseSpecifier);
53
+ }
54
+ catch {
55
+ try {
56
+ return decodeURI(baseSpecifier
57
+ .replace(/^file:\/\/\//, '')
58
+ .replace(/^file:\/\//, ''));
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ }
64
+ }
65
+ function addDriveLetterVariants(specifier, variants) {
66
+ variants.add(specifier);
67
+ const match = specifier.match(/^file:\/\/\/([A-Za-z]):/);
68
+ if (!match) {
69
+ return;
70
+ }
71
+ const lowerDrive = match[1].toLowerCase();
72
+ const upperDrive = match[1].toUpperCase();
73
+ variants.add(specifier.replace(/^file:\/\/\/([A-Za-z]):/, `file:///${lowerDrive}:`));
74
+ variants.add(specifier.replace(/^file:\/\/\/([A-Za-z]):/, `file:///${upperDrive}:`));
75
+ }
76
+ function buildSpecifierVariants(specifier) {
77
+ const baseSpecifier = specifier.split('#', 1)[0];
78
+ const variants = new Set();
79
+ addDriveLetterVariants(baseSpecifier, variants);
80
+ if (baseSpecifier.startsWith('file://')) {
81
+ try {
82
+ addDriveLetterVariants(decodeURI(baseSpecifier), variants);
83
+ }
84
+ catch {
85
+ // ignore decode failures
86
+ }
87
+ try {
88
+ addDriveLetterVariants((0, url_1.pathToFileURL)((0, url_1.fileURLToPath)(baseSpecifier)).toString(), variants);
89
+ }
90
+ catch {
91
+ // ignore encode failures
92
+ }
93
+ }
94
+ return Array.from(variants);
95
+ }
96
+ function createAliasedEntry(entry, exportName) {
97
+ if (exportName === '') {
98
+ return {
99
+ ...entry,
100
+ name: '',
101
+ };
102
+ }
103
+ return {
104
+ ...entry,
105
+ name: exportName,
106
+ };
107
+ }
108
+ function normalizeReactClientReferenceManifest(input) {
109
+ const manifest = { ...input };
110
+ for (const [rawSpecifier, rawEntry] of Object.entries(input || {})) {
111
+ if (!rawEntry || typeof rawEntry !== 'object') {
112
+ continue;
113
+ }
114
+ const entry = {
115
+ id: rawEntry.id,
116
+ chunks: Array.isArray(rawEntry.chunks) ? rawEntry.chunks : [],
117
+ name: rawEntry.name || '*',
118
+ };
119
+ const sourcePath = resolveManifestFilePath(rawSpecifier);
120
+ const exportNames = new Set();
121
+ if (entry.name && entry.name !== '*') {
122
+ exportNames.add(entry.name);
123
+ }
124
+ if (sourcePath && fs_1.default.existsSync(sourcePath)) {
125
+ try {
126
+ const source = fs_1.default.readFileSync(sourcePath, 'utf-8');
127
+ for (const exportName of extractExportNames(source)) {
128
+ exportNames.add(exportName);
129
+ }
130
+ }
131
+ catch {
132
+ // Keep manifest normalization resilient even if a source file disappears mid-build.
133
+ }
134
+ }
135
+ for (const baseSpecifier of buildSpecifierVariants(rawSpecifier)) {
136
+ if (!manifest[baseSpecifier]) {
137
+ manifest[baseSpecifier] = entry;
138
+ }
139
+ const emptyExportKey = `${baseSpecifier}#`;
140
+ if (!manifest[emptyExportKey]) {
141
+ manifest[emptyExportKey] = createAliasedEntry(entry, '');
142
+ }
143
+ const defaultExportKey = `${baseSpecifier}#default`;
144
+ if (!manifest[defaultExportKey]) {
145
+ manifest[defaultExportKey] = createAliasedEntry(entry, 'default');
146
+ }
147
+ for (const exportName of exportNames) {
148
+ const exportKey = `${baseSpecifier}#${exportName}`;
149
+ if (!manifest[exportKey]) {
150
+ manifest[exportKey] = createAliasedEntry(entry, exportName);
151
+ }
152
+ }
153
+ }
154
+ }
155
+ return manifest;
156
+ }
157
+ function normalizeReactServerConsumerManifest(input) {
158
+ if (!input?.moduleMap) {
159
+ return input;
160
+ }
161
+ for (const [moduleKey, rawExportsMap] of Object.entries(input.moduleMap)) {
162
+ const normalizedExportsMap = {};
163
+ const exportNames = new Set();
164
+ let sourceSpecifier = null;
165
+ let seedEntry = null;
166
+ for (const [exportName, rawEntry] of Object.entries(rawExportsMap || {})) {
167
+ const entry = {
168
+ id: rawEntry?.id ?? rawEntry?.specifier ?? moduleKey,
169
+ chunks: Array.isArray(rawEntry?.chunks) ? rawEntry.chunks : [],
170
+ name: rawEntry?.name || exportName,
171
+ };
172
+ normalizedExportsMap[exportName] = entry;
173
+ if (exportName !== '*') {
174
+ exportNames.add(exportName);
175
+ }
176
+ if (entry.name && entry.name !== '*') {
177
+ exportNames.add(entry.name);
178
+ }
179
+ if (!seedEntry) {
180
+ seedEntry = entry;
181
+ }
182
+ if (!sourceSpecifier && typeof entry.id === 'string' && entry.id.startsWith('file://')) {
183
+ sourceSpecifier = entry.id;
184
+ }
185
+ if (!sourceSpecifier && typeof rawEntry?.specifier === 'string' && rawEntry.specifier.startsWith('file://')) {
186
+ sourceSpecifier = rawEntry.specifier;
187
+ }
188
+ }
189
+ const sourcePath = sourceSpecifier ? resolveManifestFilePath(sourceSpecifier) : null;
190
+ if (sourcePath && fs_1.default.existsSync(sourcePath)) {
191
+ try {
192
+ const source = fs_1.default.readFileSync(sourcePath, 'utf-8');
193
+ for (const exportName of extractExportNames(source)) {
194
+ exportNames.add(exportName);
195
+ }
196
+ }
197
+ catch {
198
+ // Keep manifest normalization resilient even if the source file changes mid-build.
199
+ }
200
+ }
201
+ if (seedEntry) {
202
+ if (!normalizedExportsMap['*']) {
203
+ normalizedExportsMap['*'] = {
204
+ ...seedEntry,
205
+ name: '*',
206
+ };
207
+ }
208
+ for (const exportName of exportNames) {
209
+ if (!normalizedExportsMap[exportName]) {
210
+ normalizedExportsMap[exportName] = {
211
+ ...seedEntry,
212
+ name: exportName,
213
+ };
214
+ }
215
+ }
216
+ }
217
+ input.moduleMap[moduleKey] = normalizedExportsMap;
218
+ }
219
+ return input;
220
+ }
221
+ /**
222
+ * React looks up `file://...#ExportName` in the Flight manifest and throws a
223
+ * generic error when the key is missing. Wrap the manifest so the message names
224
+ * the file and the scan-directory requirement.
225
+ */
226
+ function createGuardedReactClientManifest(manifest) {
227
+ return new Proxy(manifest, {
228
+ get(target, prop, receiver) {
229
+ if (typeof prop === 'string' &&
230
+ (prop.startsWith('file:') || prop.includes('#')) &&
231
+ !Object.prototype.hasOwnProperty.call(target, prop)) {
232
+ const fileHint = prop.split('#')[0];
233
+ throw new Error(`Could not find the module "${prop}" in the React Client Manifest. ` +
234
+ `Client Components need a 'use client' directive and must live under a scanned project directory ` +
235
+ `(app/, components/, utils/, lib/, src/, ...). Missing: ${fileHint}`);
236
+ }
237
+ return Reflect.get(target, prop, receiver);
238
+ },
239
+ });
240
+ }