@vistagenic/vista 0.3.2 → 0.3.4
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/bin/vista.js +79 -109
- package/dist/ai/embeddings.d.ts +11 -11
- package/dist/ai/embeddings.js +71 -71
- package/dist/ai/index.d.ts +10 -10
- package/dist/ai/index.js +26 -26
- package/dist/ai/providers/base.js +85 -85
- package/dist/ai/react/react-server.d.ts +1 -1
- package/dist/ai/react/react-server.js +17 -17
- package/dist/ai/react/use-agent.js +138 -138
- package/dist/auth/core.d.ts +140 -140
- package/dist/auth/core.js +165 -165
- package/dist/auth/index.d.ts +20 -20
- package/dist/auth/index.js +369 -369
- package/dist/auth/react-server.d.ts +1 -1
- package/dist/auth/react-server.js +10 -10
- package/dist/auth/react.d.ts +18 -18
- package/dist/auth/react.js +71 -71
- package/dist/bin/build-rsc-flashpack.js +6 -0
- package/dist/bin/build-rsc.js +555 -492
- package/dist/bin/build.js +365 -353
- package/dist/bin/generate.js +513 -510
- package/dist/bin/webpack.config.d.ts +3 -1
- package/dist/bin/webpack.config.js +7 -4
- package/dist/build/manifest.d.ts +169 -169
- package/dist/build/manifest.js +423 -423
- package/dist/build/rsc/client-manifest.d.ts +62 -62
- package/dist/build/rsc/client-manifest.js +295 -295
- package/dist/build/rsc/compiler.d.ts +3 -1
- package/dist/build/rsc/compiler.js +12 -7
- package/dist/build/rsc/native-scanner.d.ts +135 -135
- package/dist/build/rsc/native-scanner.js +203 -203
- package/dist/build/rsc/react-client-reference-manifest.d.ts +35 -28
- package/dist/build/rsc/react-client-reference-manifest.js +366 -240
- package/dist/build/standalone.js +260 -254
- package/dist/client/dynamic.react-server.d.ts +2 -2
- package/dist/client/dynamic.react-server.js +23 -23
- package/dist/client/link.js +1 -1
- package/dist/client/link.react-server.d.ts +2 -2
- package/dist/client/link.react-server.js +11 -11
- package/dist/client/navigation.js +2 -2
- package/dist/client/navigation.react-server.d.ts +1 -1
- package/dist/client/navigation.react-server.js +17 -17
- package/dist/client/router.react-server.d.ts +1 -1
- package/dist/client/router.react-server.js +17 -17
- package/dist/client/rsc-router.d.ts +1 -3
- package/dist/client/rsc-router.js +98 -45
- package/dist/client/rsc-router.react-server.d.ts +1 -1
- package/dist/client/rsc-router.react-server.js +17 -17
- package/dist/client/script.react-server.d.ts +2 -2
- package/dist/client/script.react-server.js +23 -23
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -7
- package/dist/deploy/adapters/cloudflare.js +42 -41
- package/dist/deploy/adapters/docker.d.ts +1 -0
- package/dist/deploy/adapters/docker.js +5 -4
- package/dist/deploy/adapters/netlify.js +60 -27
- package/dist/deploy/adapters/vercel.js +80 -50
- package/dist/deploy/preflight.js +4 -3
- package/dist/deploy/runtime-pack.d.ts +11 -0
- package/dist/deploy/runtime-pack.js +300 -0
- package/dist/deploy/utils.d.ts +7 -1
- package/dist/deploy/utils.js +95 -3
- package/dist/flashpack/command.js +1 -0
- package/dist/flashpack/runtime.js +2 -1
- package/dist/image/get-img-props.js +21 -11
- package/dist/image/image-config.d.ts +2 -0
- package/dist/image/image-config.js +17 -0
- package/dist/image/index.d.ts +18 -3
- package/dist/image/index.js +1 -1
- package/dist/image/react-server.d.ts +1 -2
- package/dist/image/react-server.js +1 -1
- package/dist/index.d.ts +23 -23
- package/dist/index.js +61 -61
- package/dist/server/app-dir.d.ts +22 -0
- package/dist/server/app-dir.js +77 -0
- package/dist/server/app-router-runtime.d.ts +1 -0
- package/dist/server/app-router-runtime.js +34 -9
- package/dist/server/cookie-parse.d.ts +4 -4
- package/dist/server/cookie-parse.js +14 -14
- package/dist/server/engine.js +5 -5
- package/dist/server/hydration-chunks.d.ts +7 -0
- package/dist/server/hydration-chunks.js +49 -0
- package/dist/server/image-optimizer.js +2 -1
- package/dist/server/index.d.ts +109 -109
- package/dist/server/index.js +315 -315
- package/dist/server/middleware-runner.d.ts +125 -125
- package/dist/server/middleware-runner.js +607 -615
- package/dist/server/middleware-security.d.ts +36 -36
- package/dist/server/middleware-security.js +183 -183
- package/dist/server/module-compile-hook.js +706 -695
- package/dist/server/root-resolver.js +6 -5
- package/dist/server/rsc-engine-flashpack.d.ts +3 -1
- package/dist/server/rsc-engine-flashpack.js +12 -1
- package/dist/server/rsc-engine.d.ts +6 -1
- package/dist/server/rsc-engine.js +217 -280
- package/dist/server/rsc-upstream.js +900 -892
- package/dist/server/ssr-webpack-shim.d.ts +6 -0
- package/dist/server/ssr-webpack-shim.js +29 -0
- package/dist/server/static-generator.d.ts +2 -0
- package/dist/server/static-generator.js +33 -32
- package/dist/server/structure-validator.js +2 -1
- package/dist/server/structure-watch.js +2 -0
- package/dist/server/typed-api-runtime.js +639 -635
- package/dist/server/vista-import-map.js +134 -134
- package/dist/stack/index.d.ts +34 -34
- package/dist/stack/index.js +49 -49
- package/dist/stack/server/caller.d.ts +13 -13
- package/dist/stack/server/caller.js +42 -42
- package/dist/stack/server/executor.d.ts +40 -40
- package/dist/stack/server/executor.js +222 -222
- package/dist/stack/server/index.d.ts +11 -11
- package/dist/stack/server/index.js +24 -24
- package/dist/stack/server/procedure.d.ts +20 -20
- package/dist/stack/server/procedure.js +66 -66
- package/dist/stack/server/types.d.ts +113 -113
- package/dist/theme/react-server.d.ts +10 -10
- package/dist/theme/react-server.js +16 -16
- package/package.json +1 -1
|
@@ -1,240 +1,366 @@
|
|
|
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.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.replace(/^file
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
variants.add(specifier.replace(/^file:\/\/\/([A-Za-z]):/, `file:///${
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (
|
|
159
|
-
return
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
function
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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.resolveReactClientManifestEntry = resolveReactClientManifestEntry;
|
|
7
|
+
exports.normalizeReactClientReferenceManifest = normalizeReactClientReferenceManifest;
|
|
8
|
+
exports.normalizeReactServerConsumerManifest = normalizeReactServerConsumerManifest;
|
|
9
|
+
exports.createGuardedReactClientManifest = createGuardedReactClientManifest;
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const url_1 = require("url");
|
|
12
|
+
function extractExportNames(source) {
|
|
13
|
+
const exports = new Set();
|
|
14
|
+
if (/export\s+default\s+/.test(source)) {
|
|
15
|
+
exports.add('default');
|
|
16
|
+
}
|
|
17
|
+
const namedExportRegex = /export\s+(?:async\s+)?(?:function|const|let|var|class)\s+([A-Za-z_$][\w$]*)/g;
|
|
18
|
+
let match;
|
|
19
|
+
while ((match = namedExportRegex.exec(source)) !== null) {
|
|
20
|
+
exports.add(match[1]);
|
|
21
|
+
}
|
|
22
|
+
const reExportRegex = /export\s+\{([^}]+)\}/g;
|
|
23
|
+
while ((match = reExportRegex.exec(source)) !== null) {
|
|
24
|
+
const names = match[1]
|
|
25
|
+
.split(',')
|
|
26
|
+
.map((entry) => entry
|
|
27
|
+
.trim()
|
|
28
|
+
.split(/\s+as\s+/)
|
|
29
|
+
.pop()
|
|
30
|
+
?.trim())
|
|
31
|
+
.filter(Boolean);
|
|
32
|
+
for (const name of names) {
|
|
33
|
+
exports.add(name);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const commonJsExportRegex = /exports\.([A-Za-z_$][\w$]*)\s*=/g;
|
|
37
|
+
while ((match = commonJsExportRegex.exec(source)) !== null) {
|
|
38
|
+
if (match[1] !== '__esModule') {
|
|
39
|
+
exports.add(match[1]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (/module\.exports\s*=/.test(source) || /exports\.default\s*=/.test(source)) {
|
|
43
|
+
exports.add('default');
|
|
44
|
+
}
|
|
45
|
+
return Array.from(exports);
|
|
46
|
+
}
|
|
47
|
+
function resolveManifestFilePath(specifier) {
|
|
48
|
+
const baseSpecifier = specifier.split('#', 1)[0];
|
|
49
|
+
if (!baseSpecifier.startsWith('file://')) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return (0, url_1.fileURLToPath)(baseSpecifier);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
try {
|
|
57
|
+
return decodeURI(baseSpecifier
|
|
58
|
+
.replace(/^file:\/\/\//, '')
|
|
59
|
+
.replace(/^file:\/\//, ''));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function addDriveLetterVariants(specifier, variants) {
|
|
67
|
+
variants.add(specifier);
|
|
68
|
+
const match = specifier.match(/^file:\/\/\/([A-Za-z]):/);
|
|
69
|
+
if (!match) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const lowerDrive = match[1].toLowerCase();
|
|
73
|
+
const upperDrive = match[1].toUpperCase();
|
|
74
|
+
variants.add(specifier.replace(/^file:\/\/\/([A-Za-z]):/, `file:///${lowerDrive}:`));
|
|
75
|
+
variants.add(specifier.replace(/^file:\/\/\/([A-Za-z]):/, `file:///${upperDrive}:`));
|
|
76
|
+
}
|
|
77
|
+
function addStandalonePathVariants(specifier, variants) {
|
|
78
|
+
addDriveLetterVariants(specifier, variants);
|
|
79
|
+
const standaloneProject = '/.vista/standalone/project';
|
|
80
|
+
const standaloneRuntime = '/.vista/standalone/runtime';
|
|
81
|
+
if (specifier.includes(standaloneProject)) {
|
|
82
|
+
addDriveLetterVariants(specifier.split(standaloneProject).join(''), variants);
|
|
83
|
+
}
|
|
84
|
+
if (specifier.includes(standaloneRuntime)) {
|
|
85
|
+
addDriveLetterVariants(specifier.split(standaloneRuntime).join(''), variants);
|
|
86
|
+
}
|
|
87
|
+
if (!specifier.includes('/.vista/standalone/') && specifier.startsWith('file://')) {
|
|
88
|
+
const inserted = specifier.replace(/^(file:\/\/\/(?:[A-Za-z]:)?(?:\/[^/]+)*)(\/(?:app|components|utils|lib|src|content|hooks)\/)/i, `$1${standaloneProject}$2`);
|
|
89
|
+
if (inserted !== specifier) {
|
|
90
|
+
addDriveLetterVariants(inserted, variants);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function buildSpecifierVariants(specifier) {
|
|
95
|
+
const baseSpecifier = specifier.split('#', 1)[0];
|
|
96
|
+
const variants = new Set();
|
|
97
|
+
addStandalonePathVariants(baseSpecifier, variants);
|
|
98
|
+
if (baseSpecifier.startsWith('file://')) {
|
|
99
|
+
try {
|
|
100
|
+
addStandalonePathVariants(decodeURI(baseSpecifier), variants);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// ignore decode failures
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
addStandalonePathVariants((0, url_1.pathToFileURL)((0, url_1.fileURLToPath)(baseSpecifier)).toString(), variants);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// ignore encode failures
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return Array.from(variants);
|
|
113
|
+
}
|
|
114
|
+
function splitManifestKey(key) {
|
|
115
|
+
const hashIdx = key.lastIndexOf('#');
|
|
116
|
+
if (hashIdx <= 0) {
|
|
117
|
+
return { specifier: key, exportName: null };
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
specifier: key.slice(0, hashIdx),
|
|
121
|
+
exportName: key.slice(hashIdx + 1),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function normalizeManifestSpecifier(specifier) {
|
|
125
|
+
return specifier
|
|
126
|
+
.replace(/\\/g, '/')
|
|
127
|
+
.replace(/^file:\/\//i, '')
|
|
128
|
+
.replace(/^\/+/, '')
|
|
129
|
+
.replace(/\/\.vista\/standalone\/(?:project|runtime)/gi, '')
|
|
130
|
+
.toLowerCase();
|
|
131
|
+
}
|
|
132
|
+
function relativeClientPath(normalized) {
|
|
133
|
+
const markers = [
|
|
134
|
+
'/app/',
|
|
135
|
+
'/components/',
|
|
136
|
+
'/utils/',
|
|
137
|
+
'/lib/',
|
|
138
|
+
'/src/',
|
|
139
|
+
'/content/',
|
|
140
|
+
'/hooks/',
|
|
141
|
+
'/packages/vista/',
|
|
142
|
+
];
|
|
143
|
+
let best = normalized;
|
|
144
|
+
for (const marker of markers) {
|
|
145
|
+
const idx = normalized.lastIndexOf(marker);
|
|
146
|
+
if (idx !== -1) {
|
|
147
|
+
const sliced = normalized.slice(idx);
|
|
148
|
+
if (sliced.length <= best.length) {
|
|
149
|
+
best = sliced;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return best.replace(/\.(tsx|ts|jsx|js|mjs|cjs)$/i, '');
|
|
154
|
+
}
|
|
155
|
+
function exportNamesCompatible(requested, existing) {
|
|
156
|
+
if (requested === null || existing === null)
|
|
157
|
+
return true;
|
|
158
|
+
if (requested === existing)
|
|
159
|
+
return true;
|
|
160
|
+
const aliases = new Set(['', '*', 'default']);
|
|
161
|
+
return aliases.has(requested) && aliases.has(existing);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Flight encode looks up `file://...#ExportName`. Webpack may have keyed the
|
|
165
|
+
* same module under a standalone copy, a different drive-letter case, or a
|
|
166
|
+
* slightly different absolute prefix. Resolve those aliases at lookup time so
|
|
167
|
+
* missing keys do not serialize as Flight `E{"digest":""}` rows.
|
|
168
|
+
*/
|
|
169
|
+
function resolveReactClientManifestEntry(manifest, key) {
|
|
170
|
+
if (Object.prototype.hasOwnProperty.call(manifest, key)) {
|
|
171
|
+
return manifest[key];
|
|
172
|
+
}
|
|
173
|
+
const { specifier, exportName } = splitManifestKey(key);
|
|
174
|
+
const candidates = [];
|
|
175
|
+
for (const variant of buildSpecifierVariants(specifier)) {
|
|
176
|
+
candidates.push(variant);
|
|
177
|
+
if (exportName !== null) {
|
|
178
|
+
candidates.push(`${variant}#${exportName}`);
|
|
179
|
+
candidates.push(`${variant}#`);
|
|
180
|
+
candidates.push(`${variant}#default`);
|
|
181
|
+
candidates.push(`${variant}#*`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
for (const candidate of candidates) {
|
|
185
|
+
if (Object.prototype.hasOwnProperty.call(manifest, candidate)) {
|
|
186
|
+
return manifest[candidate];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const needle = normalizeManifestSpecifier(specifier);
|
|
190
|
+
const needleFile = needle.split('/').pop() || needle;
|
|
191
|
+
let fuzzy;
|
|
192
|
+
for (const [existingKey, entry] of Object.entries(manifest)) {
|
|
193
|
+
if (!entry || typeof entry !== 'object')
|
|
194
|
+
continue;
|
|
195
|
+
const existing = splitManifestKey(existingKey);
|
|
196
|
+
const existingNorm = normalizeManifestSpecifier(existing.specifier);
|
|
197
|
+
const existingFile = existingNorm.split('/').pop() || existingNorm;
|
|
198
|
+
const existingStem = existingFile.replace(/\.(tsx|ts|jsx|js|mjs|cjs)$/i, '');
|
|
199
|
+
const needleStem = needleFile.replace(/\.(tsx|ts|jsx|js|mjs|cjs)$/i, '');
|
|
200
|
+
const genericStem = existingStem === 'index' || existingStem === 'page' || existingStem === 'layout';
|
|
201
|
+
const pathMatches = existingNorm === needle ||
|
|
202
|
+
relativeClientPath(existingNorm) === relativeClientPath(needle) ||
|
|
203
|
+
(Boolean(needleFile) && !genericStem && existingStem === needleStem);
|
|
204
|
+
if (!pathMatches || !exportNamesCompatible(exportName, existing.exportName)) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (existing.exportName === exportName) {
|
|
208
|
+
return entry;
|
|
209
|
+
}
|
|
210
|
+
fuzzy = entry;
|
|
211
|
+
}
|
|
212
|
+
return fuzzy;
|
|
213
|
+
}
|
|
214
|
+
function createAliasedEntry(entry, exportName) {
|
|
215
|
+
if (exportName === '') {
|
|
216
|
+
return {
|
|
217
|
+
...entry,
|
|
218
|
+
name: '',
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
...entry,
|
|
223
|
+
name: exportName,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function normalizeReactClientReferenceManifest(input) {
|
|
227
|
+
const manifest = { ...input };
|
|
228
|
+
for (const [rawSpecifier, rawEntry] of Object.entries(input || {})) {
|
|
229
|
+
if (!rawEntry || typeof rawEntry !== 'object') {
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const entry = {
|
|
233
|
+
id: rawEntry.id,
|
|
234
|
+
chunks: Array.isArray(rawEntry.chunks) ? rawEntry.chunks : [],
|
|
235
|
+
name: rawEntry.name || '*',
|
|
236
|
+
};
|
|
237
|
+
const sourcePath = resolveManifestFilePath(rawSpecifier);
|
|
238
|
+
const exportNames = new Set();
|
|
239
|
+
if (entry.name && entry.name !== '*') {
|
|
240
|
+
exportNames.add(entry.name);
|
|
241
|
+
}
|
|
242
|
+
if (sourcePath && fs_1.default.existsSync(sourcePath)) {
|
|
243
|
+
try {
|
|
244
|
+
const source = fs_1.default.readFileSync(sourcePath, 'utf-8');
|
|
245
|
+
for (const exportName of extractExportNames(source)) {
|
|
246
|
+
exportNames.add(exportName);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
// Keep manifest normalization resilient even if a source file disappears mid-build.
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
for (const baseSpecifier of buildSpecifierVariants(rawSpecifier)) {
|
|
254
|
+
if (!manifest[baseSpecifier]) {
|
|
255
|
+
manifest[baseSpecifier] = entry;
|
|
256
|
+
}
|
|
257
|
+
const emptyExportKey = `${baseSpecifier}#`;
|
|
258
|
+
if (!manifest[emptyExportKey]) {
|
|
259
|
+
manifest[emptyExportKey] = createAliasedEntry(entry, '');
|
|
260
|
+
}
|
|
261
|
+
const defaultExportKey = `${baseSpecifier}#default`;
|
|
262
|
+
if (!manifest[defaultExportKey]) {
|
|
263
|
+
manifest[defaultExportKey] = createAliasedEntry(entry, 'default');
|
|
264
|
+
}
|
|
265
|
+
for (const exportName of exportNames) {
|
|
266
|
+
const exportKey = `${baseSpecifier}#${exportName}`;
|
|
267
|
+
if (!manifest[exportKey]) {
|
|
268
|
+
manifest[exportKey] = createAliasedEntry(entry, exportName);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return manifest;
|
|
274
|
+
}
|
|
275
|
+
function normalizeReactServerConsumerManifest(input) {
|
|
276
|
+
if (!input?.moduleMap) {
|
|
277
|
+
return input;
|
|
278
|
+
}
|
|
279
|
+
for (const [moduleKey, rawExportsMap] of Object.entries(input.moduleMap)) {
|
|
280
|
+
const normalizedExportsMap = {};
|
|
281
|
+
const exportNames = new Set();
|
|
282
|
+
let sourceSpecifier = null;
|
|
283
|
+
let seedEntry = null;
|
|
284
|
+
for (const [exportName, rawEntry] of Object.entries(rawExportsMap || {})) {
|
|
285
|
+
const entry = {
|
|
286
|
+
id: rawEntry?.id ?? rawEntry?.specifier ?? moduleKey,
|
|
287
|
+
chunks: Array.isArray(rawEntry?.chunks) ? rawEntry.chunks : [],
|
|
288
|
+
name: rawEntry?.name || exportName,
|
|
289
|
+
};
|
|
290
|
+
normalizedExportsMap[exportName] = entry;
|
|
291
|
+
if (exportName !== '*') {
|
|
292
|
+
exportNames.add(exportName);
|
|
293
|
+
}
|
|
294
|
+
if (entry.name && entry.name !== '*') {
|
|
295
|
+
exportNames.add(entry.name);
|
|
296
|
+
}
|
|
297
|
+
if (!seedEntry) {
|
|
298
|
+
seedEntry = entry;
|
|
299
|
+
}
|
|
300
|
+
if (!sourceSpecifier && typeof entry.id === 'string' && entry.id.startsWith('file://')) {
|
|
301
|
+
sourceSpecifier = entry.id;
|
|
302
|
+
}
|
|
303
|
+
if (!sourceSpecifier && typeof rawEntry?.specifier === 'string' && rawEntry.specifier.startsWith('file://')) {
|
|
304
|
+
sourceSpecifier = rawEntry.specifier;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const sourcePath = sourceSpecifier ? resolveManifestFilePath(sourceSpecifier) : null;
|
|
308
|
+
if (sourcePath && fs_1.default.existsSync(sourcePath)) {
|
|
309
|
+
try {
|
|
310
|
+
const source = fs_1.default.readFileSync(sourcePath, 'utf-8');
|
|
311
|
+
for (const exportName of extractExportNames(source)) {
|
|
312
|
+
exportNames.add(exportName);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
// Keep manifest normalization resilient even if the source file changes mid-build.
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (seedEntry) {
|
|
320
|
+
if (!normalizedExportsMap['*']) {
|
|
321
|
+
normalizedExportsMap['*'] = {
|
|
322
|
+
...seedEntry,
|
|
323
|
+
name: '*',
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
for (const exportName of exportNames) {
|
|
327
|
+
if (!normalizedExportsMap[exportName]) {
|
|
328
|
+
normalizedExportsMap[exportName] = {
|
|
329
|
+
...seedEntry,
|
|
330
|
+
name: exportName,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
input.moduleMap[moduleKey] = normalizedExportsMap;
|
|
336
|
+
}
|
|
337
|
+
return input;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* React looks up `file://...#ExportName` in the Flight manifest and throws a
|
|
341
|
+
* generic error when the key is missing. Wrap the manifest so the message names
|
|
342
|
+
* the file and the scan-directory requirement.
|
|
343
|
+
*/
|
|
344
|
+
function createGuardedReactClientManifest(manifest) {
|
|
345
|
+
return new Proxy(manifest, {
|
|
346
|
+
get(target, prop, receiver) {
|
|
347
|
+
if (typeof prop === 'string' && (prop.startsWith('file:') || prop.includes('#'))) {
|
|
348
|
+
const resolved = resolveReactClientManifestEntry(target, prop);
|
|
349
|
+
if (resolved) {
|
|
350
|
+
return resolved;
|
|
351
|
+
}
|
|
352
|
+
const fileHint = prop.split('#')[0];
|
|
353
|
+
throw new Error(`Could not find the module "${prop}" in the React Client Manifest. ` +
|
|
354
|
+
`Client Components need a 'use client' directive and must live under a scanned project directory ` +
|
|
355
|
+
`(app/, components/, utils/, lib/, src/, ...). Missing: ${fileHint}`);
|
|
356
|
+
}
|
|
357
|
+
return Reflect.get(target, prop, receiver);
|
|
358
|
+
},
|
|
359
|
+
has(target, prop) {
|
|
360
|
+
if (typeof prop === 'string' && (prop.startsWith('file:') || prop.includes('#'))) {
|
|
361
|
+
return Boolean(resolveReactClientManifestEntry(target, prop));
|
|
362
|
+
}
|
|
363
|
+
return Reflect.has(target, prop);
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
}
|