@vistagenic/vista 0.2.16 → 0.3.2
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 +184 -177
- package/dist/ai/agent.d.ts +37 -0
- package/dist/ai/agent.js +385 -0
- package/dist/ai/embeddings.d.ts +11 -0
- package/dist/ai/embeddings.js +71 -0
- package/dist/ai/index.d.ts +10 -0
- package/dist/ai/index.js +26 -0
- package/dist/ai/memory.d.ts +16 -0
- package/dist/ai/memory.js +39 -0
- package/dist/ai/observability.d.ts +21 -0
- package/dist/ai/observability.js +69 -0
- package/dist/ai/providers/anthropic.d.ts +2 -0
- package/dist/ai/providers/anthropic.js +190 -0
- package/dist/ai/providers/base.d.ts +7 -0
- package/dist/ai/providers/base.js +85 -0
- package/dist/ai/providers/gemini.d.ts +2 -0
- package/dist/ai/providers/gemini.js +194 -0
- package/dist/ai/providers/index.d.ts +5 -0
- package/dist/ai/providers/index.js +21 -0
- package/dist/ai/providers/mock.d.ts +8 -0
- package/dist/ai/providers/mock.js +77 -0
- package/dist/ai/providers/openai.d.ts +2 -0
- package/dist/ai/providers/openai.js +211 -0
- package/dist/ai/rag.d.ts +35 -0
- package/dist/ai/rag.js +110 -0
- package/dist/ai/react/index.d.ts +1 -0
- package/dist/ai/react/index.js +17 -0
- package/dist/ai/react/react-server.d.ts +1 -0
- package/dist/ai/react/react-server.js +17 -0
- package/dist/ai/react/use-agent.d.ts +23 -0
- package/dist/ai/react/use-agent.js +138 -0
- package/dist/ai/stream.d.ts +24 -0
- package/dist/ai/stream.js +109 -0
- package/dist/ai/tool.d.ts +11 -0
- package/dist/ai/tool.js +47 -0
- package/dist/ai/types.d.ts +117 -0
- package/dist/ai/types.js +5 -0
- package/dist/auth/core.d.ts +140 -0
- package/dist/auth/core.js +165 -0
- package/dist/auth/index.d.ts +20 -8
- package/dist/auth/index.js +369 -16
- package/dist/auth/react-server.d.ts +1 -0
- package/dist/auth/react-server.js +10 -0
- package/dist/auth/react.d.ts +18 -0
- package/dist/auth/react.js +71 -0
- package/dist/bin/build-rsc.js +602 -604
- package/dist/bin/build.js +389 -388
- package/dist/bin/deploy-output.d.ts +2 -7
- package/dist/bin/deploy-output.js +3 -76
- package/dist/bin/deploy.d.ts +7 -0
- package/dist/bin/deploy.js +102 -0
- package/dist/bin/dev-error-overlay-snippet.js +778 -552
- package/dist/bin/devtools-indicator-snippet.js +387 -387
- package/dist/bin/generate.js +510 -248
- package/dist/build/manifest.d.ts +169 -139
- package/dist/build/manifest.js +423 -367
- package/dist/build/rsc/client-manifest.d.ts +62 -52
- package/dist/build/rsc/client-manifest.js +295 -193
- package/dist/build/rsc/client-reference-plugin.d.ts +37 -37
- package/dist/build/rsc/client-reference-plugin.js +160 -160
- package/dist/build/rsc/native-scanner.d.ts +135 -123
- package/dist/build/rsc/native-scanner.js +203 -170
- package/dist/build/rsc/react-client-reference-manifest.d.ts +28 -22
- package/dist/build/rsc/react-client-reference-manifest.js +240 -219
- package/dist/build/rsc/rsc-renderer.d.ts +99 -99
- package/dist/build/rsc/rsc-renderer.js +263 -263
- package/dist/build/rsc/server-component-loader.d.ts +19 -19
- package/dist/build/rsc/server-component-loader.js +91 -91
- package/dist/build/rsc/server-manifest.d.ts +17 -0
- package/dist/build/rsc/server-manifest.js +20 -0
- package/dist/build/standalone.js +337 -334
- package/dist/build/webpack/plugins/vista-flight-plugin.js +5 -5
- package/dist/client/dynamic.react-server.d.ts +2 -0
- package/dist/client/dynamic.react-server.js +23 -0
- package/dist/client/link.react-server.d.ts +2 -0
- package/dist/client/link.react-server.js +11 -0
- package/dist/client/navigation.react-server.d.ts +1 -0
- package/dist/client/navigation.react-server.js +17 -0
- package/dist/client/router.react-server.d.ts +1 -0
- package/dist/client/router.react-server.js +17 -0
- package/dist/client/rsc-router.react-server.d.ts +1 -0
- package/dist/client/rsc-router.react-server.js +17 -0
- package/dist/client/script.react-server.d.ts +2 -0
- package/dist/client/script.react-server.js +23 -0
- package/dist/components/client-island.d.ts +34 -34
- package/dist/components/client-island.js +75 -75
- package/dist/config.d.ts +17 -0
- package/dist/config.js +60 -1
- package/dist/deploy/adapters/cloudflare.d.ts +2 -0
- package/dist/deploy/adapters/cloudflare.js +124 -0
- package/dist/deploy/adapters/docker.d.ts +2 -0
- package/dist/deploy/adapters/docker.js +112 -0
- package/dist/deploy/adapters/index.d.ts +15 -0
- package/dist/deploy/adapters/index.js +24 -0
- package/dist/deploy/adapters/netlify.d.ts +2 -0
- package/dist/deploy/adapters/netlify.js +115 -0
- package/dist/deploy/adapters/render.d.ts +2 -0
- package/dist/deploy/adapters/render.js +95 -0
- package/dist/deploy/adapters/vercel.d.ts +7 -0
- package/dist/deploy/adapters/vercel.js +164 -0
- package/dist/deploy/cli-runner.d.ts +8 -0
- package/dist/deploy/cli-runner.js +58 -0
- package/dist/deploy/detect.d.ts +6 -0
- package/dist/deploy/detect.js +77 -0
- package/dist/deploy/index.d.ts +24 -0
- package/dist/deploy/index.js +112 -0
- package/dist/deploy/preflight.d.ts +8 -0
- package/dist/deploy/preflight.js +80 -0
- package/dist/deploy/types.d.ts +48 -0
- package/dist/deploy/types.js +2 -0
- package/dist/deploy/utils.d.ts +18 -0
- package/dist/deploy/utils.js +70 -0
- package/dist/dev-error.d.ts +14 -0
- package/dist/dev-error.js +1763 -705
- package/dist/index.d.ts +23 -21
- package/dist/index.js +61 -57
- package/dist/server/cookie-parse.d.ts +4 -0
- package/dist/server/cookie-parse.js +14 -0
- package/dist/server/engine.js +7 -26
- package/dist/server/index.d.ts +109 -102
- package/dist/server/index.js +315 -286
- package/dist/server/middleware-runner.d.ts +125 -57
- package/dist/server/middleware-runner.js +615 -218
- package/dist/server/middleware-security.d.ts +36 -0
- package/dist/server/middleware-security.js +183 -0
- package/dist/server/module-compile-hook.js +695 -662
- package/dist/server/route-handler-registry.d.ts +65 -0
- package/dist/server/route-handler-registry.js +195 -0
- package/dist/server/route-patterns.d.ts +67 -0
- package/dist/server/route-patterns.js +186 -0
- package/dist/server/rsc-engine.js +75 -92
- package/dist/server/rsc-module-system.d.ts +33 -33
- package/dist/server/rsc-module-system.js +87 -87
- package/dist/server/rsc-upstream.js +892 -888
- package/dist/server/static-generator.js +10 -10
- package/dist/server/typed-api-runtime.d.ts +18 -0
- package/dist/server/typed-api-runtime.js +635 -507
- package/dist/server/vista-import-map.js +134 -123
- package/dist/stack/index.d.ts +34 -32
- package/dist/stack/index.js +49 -45
- package/dist/stack/server/caller.d.ts +13 -0
- package/dist/stack/server/caller.js +42 -0
- package/dist/stack/server/executor.d.ts +40 -36
- package/dist/stack/server/executor.js +222 -174
- package/dist/stack/server/index.d.ts +11 -10
- package/dist/stack/server/index.js +24 -23
- package/dist/stack/server/procedure.d.ts +20 -18
- package/dist/stack/server/procedure.js +66 -58
- package/dist/stack/server/types.d.ts +113 -100
- package/dist/theme/react-server.d.ts +10 -0
- package/dist/theme/react-server.js +16 -0
- package/package.json +28 -3
- package/LICENSE +0 -21
|
@@ -1,52 +1,62 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client Component Manifest Generator
|
|
3
|
-
*
|
|
4
|
-
* Scans the app directory and builds a manifest of all Client Components.
|
|
5
|
-
* Client components are those with 'use client' directive.
|
|
6
|
-
*
|
|
7
|
-
* The manifest maps component paths to their chunk names for client-side loading.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Client Component Manifest Generator
|
|
3
|
+
*
|
|
4
|
+
* Scans the app directory and builds a manifest of all Client Components.
|
|
5
|
+
* Client components are those with 'use client' directive.
|
|
6
|
+
*
|
|
7
|
+
* The manifest maps component paths to their chunk names for client-side loading.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Top-level app directories that may contain `'use client'` modules.
|
|
11
|
+
* Discovery is directory membership, not the import graph, so `utils/`,
|
|
12
|
+
* `lib/`, and `src/` have to be scanned explicitly or they never enter
|
|
13
|
+
* the React Client Manifest.
|
|
14
|
+
*/
|
|
15
|
+
export declare function discoverProjectClientRoots(cwd: string): Array<{
|
|
16
|
+
dir: string;
|
|
17
|
+
prefix: string;
|
|
18
|
+
}>;
|
|
19
|
+
export interface ClientComponentEntry {
|
|
20
|
+
/** Unique ID for this component */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Relative path from app directory */
|
|
23
|
+
path: string;
|
|
24
|
+
/** Absolute file path */
|
|
25
|
+
absolutePath: string;
|
|
26
|
+
/** Generated chunk name */
|
|
27
|
+
chunkName: string;
|
|
28
|
+
/** Exported names from this module */
|
|
29
|
+
exports: string[];
|
|
30
|
+
/** Is async/lazy loaded */
|
|
31
|
+
async: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface ClientManifest {
|
|
34
|
+
/** Build ID for cache busting */
|
|
35
|
+
buildId: string;
|
|
36
|
+
/** Map of module ID to client component info */
|
|
37
|
+
clientModules: Record<string, ClientComponentEntry>;
|
|
38
|
+
/** Map of module path to module ID (for lookups) */
|
|
39
|
+
pathToId: Record<string, string>;
|
|
40
|
+
/** SSR module mapping (server paths to client chunks) */
|
|
41
|
+
ssrModuleMapping: Record<string, string>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Generate the client component manifest
|
|
45
|
+
*/
|
|
46
|
+
export declare function generateClientManifest(cwd: string, appDir: string): ClientManifest;
|
|
47
|
+
export declare function generateClientManifestWithRoots(cwd: string, appDir: string, additionalRoots?: Array<{
|
|
48
|
+
dir: string;
|
|
49
|
+
prefix?: string;
|
|
50
|
+
}>): ClientManifest;
|
|
51
|
+
/**
|
|
52
|
+
* Get client component info by module ID
|
|
53
|
+
*/
|
|
54
|
+
export declare function getClientComponent(manifest: ClientManifest, moduleId: string): ClientComponentEntry | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Get client component by file path
|
|
57
|
+
*/
|
|
58
|
+
export declare function getClientComponentByPath(manifest: ClientManifest, filePath: string): ClientComponentEntry | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Check if a path is a client component
|
|
61
|
+
*/
|
|
62
|
+
export declare function isClientComponentPath(manifest: ClientManifest, filePath: string): boolean;
|
|
@@ -1,193 +1,295 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Client Component Manifest Generator
|
|
4
|
-
*
|
|
5
|
-
* Scans the app directory and builds a manifest of all Client Components.
|
|
6
|
-
* Client components are those with 'use client' directive.
|
|
7
|
-
*
|
|
8
|
-
* The manifest maps component paths to their chunk names for client-side loading.
|
|
9
|
-
*/
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.
|
|
15
|
-
exports.
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Client Component Manifest Generator
|
|
4
|
+
*
|
|
5
|
+
* Scans the app directory and builds a manifest of all Client Components.
|
|
6
|
+
* Client components are those with 'use client' directive.
|
|
7
|
+
*
|
|
8
|
+
* The manifest maps component paths to their chunk names for client-side loading.
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.discoverProjectClientRoots = discoverProjectClientRoots;
|
|
15
|
+
exports.generateClientManifest = generateClientManifest;
|
|
16
|
+
exports.generateClientManifestWithRoots = generateClientManifestWithRoots;
|
|
17
|
+
exports.getClientComponent = getClientComponent;
|
|
18
|
+
exports.getClientComponentByPath = getClientComponentByPath;
|
|
19
|
+
exports.isClientComponentPath = isClientComponentPath;
|
|
20
|
+
const fs_1 = __importDefault(require("fs"));
|
|
21
|
+
const path_1 = __importDefault(require("path"));
|
|
22
|
+
const component_identity_1 = require("./component-identity");
|
|
23
|
+
const constants_1 = require("../../constants");
|
|
24
|
+
const native_scanner_1 = require("./native-scanner");
|
|
25
|
+
const PROJECT_CLIENT_SCAN_SKIP = new Set([
|
|
26
|
+
'node_modules',
|
|
27
|
+
'.vista',
|
|
28
|
+
'.flash',
|
|
29
|
+
'dist',
|
|
30
|
+
'public',
|
|
31
|
+
'coverage',
|
|
32
|
+
'build',
|
|
33
|
+
'out',
|
|
34
|
+
]);
|
|
35
|
+
/**
|
|
36
|
+
* Top-level app directories that may contain `'use client'` modules.
|
|
37
|
+
* Discovery is directory membership, not the import graph, so `utils/`,
|
|
38
|
+
* `lib/`, and `src/` have to be scanned explicitly or they never enter
|
|
39
|
+
* the React Client Manifest.
|
|
40
|
+
*/
|
|
41
|
+
function discoverProjectClientRoots(cwd) {
|
|
42
|
+
const roots = [];
|
|
43
|
+
if (!fs_1.default.existsSync(cwd)) {
|
|
44
|
+
return roots;
|
|
45
|
+
}
|
|
46
|
+
let entries;
|
|
47
|
+
try {
|
|
48
|
+
entries = fs_1.default.readdirSync(cwd, { withFileTypes: true });
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return roots;
|
|
52
|
+
}
|
|
53
|
+
for (const entry of entries) {
|
|
54
|
+
if (!entry.isDirectory())
|
|
55
|
+
continue;
|
|
56
|
+
if (entry.name.startsWith('.'))
|
|
57
|
+
continue;
|
|
58
|
+
if (PROJECT_CLIENT_SCAN_SKIP.has(entry.name))
|
|
59
|
+
continue;
|
|
60
|
+
roots.push({
|
|
61
|
+
dir: path_1.default.join(cwd, entry.name),
|
|
62
|
+
prefix: `${entry.name.replace(/\\/g, '/')}/`,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return roots;
|
|
66
|
+
}
|
|
67
|
+
// Try to load Rust NAPI bindings
|
|
68
|
+
let rustNative = null;
|
|
69
|
+
try {
|
|
70
|
+
const possiblePaths = [
|
|
71
|
+
path_1.default.resolve(__dirname, '../../../../../crates/vista-napi'),
|
|
72
|
+
path_1.default.resolve(__dirname, '../../../../crates/vista-napi'),
|
|
73
|
+
];
|
|
74
|
+
for (const p of possiblePaths) {
|
|
75
|
+
try {
|
|
76
|
+
rustNative = require(p);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
// Try next
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
// Fallback to JS
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if source has 'use client' directive
|
|
89
|
+
*/
|
|
90
|
+
function hasClientDirective(source) {
|
|
91
|
+
const trimmed = source.trimStart();
|
|
92
|
+
if (trimmed.startsWith("'use client'") || trimmed.startsWith('"use client"')) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
if (rustNative?.isClientComponent) {
|
|
96
|
+
return rustNative.isClientComponent(source);
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Extract export names from source (simple regex approach)
|
|
102
|
+
*/
|
|
103
|
+
function extractExports(source) {
|
|
104
|
+
const exports = [];
|
|
105
|
+
// Default export
|
|
106
|
+
if (/export\s+default\s+/.test(source)) {
|
|
107
|
+
exports.push('default');
|
|
108
|
+
}
|
|
109
|
+
// Named exports: export function Name, export const Name, export class Name
|
|
110
|
+
const namedExportRegex = /export\s+(?:async\s+)?(?:function|const|let|var|class)\s+([A-Z][a-zA-Z0-9_]*)/g;
|
|
111
|
+
let match;
|
|
112
|
+
while ((match = namedExportRegex.exec(source)) !== null) {
|
|
113
|
+
exports.push(match[1]);
|
|
114
|
+
}
|
|
115
|
+
// Export { Name1, Name2 }
|
|
116
|
+
const reExportRegex = /export\s+\{([^}]+)\}/g;
|
|
117
|
+
while ((match = reExportRegex.exec(source)) !== null) {
|
|
118
|
+
const names = match[1]
|
|
119
|
+
.split(',')
|
|
120
|
+
.map((n) => n
|
|
121
|
+
.trim()
|
|
122
|
+
.split(/\s+as\s+/)
|
|
123
|
+
.pop()
|
|
124
|
+
?.trim())
|
|
125
|
+
.filter(Boolean);
|
|
126
|
+
exports.push(...names);
|
|
127
|
+
}
|
|
128
|
+
return [...new Set(exports)];
|
|
129
|
+
}
|
|
130
|
+
function isSameOrInside(target, ancestor) {
|
|
131
|
+
const resolvedTarget = path_1.default.resolve(target);
|
|
132
|
+
const resolvedAncestor = path_1.default.resolve(ancestor);
|
|
133
|
+
if (resolvedTarget === resolvedAncestor)
|
|
134
|
+
return true;
|
|
135
|
+
const prefix = resolvedAncestor.endsWith(path_1.default.sep)
|
|
136
|
+
? resolvedAncestor
|
|
137
|
+
: `${resolvedAncestor}${path_1.default.sep}`;
|
|
138
|
+
return resolvedTarget.startsWith(prefix);
|
|
139
|
+
}
|
|
140
|
+
function additionalRootsMatchDiscovery(cwd, appDir, additionalRoots) {
|
|
141
|
+
const discovered = discoverProjectClientRoots(cwd).filter((root) => path_1.default.resolve(root.dir) !== path_1.default.resolve(appDir));
|
|
142
|
+
if (additionalRoots.length !== discovered.length)
|
|
143
|
+
return false;
|
|
144
|
+
const extra = new Set(additionalRoots.map((root) => path_1.default.resolve(root.dir)));
|
|
145
|
+
return discovered.every((root) => extra.has(path_1.default.resolve(root.dir)));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Scan directory recursively for client components
|
|
149
|
+
*/
|
|
150
|
+
function scanForClientComponents(dir, scanRoot, components, pathPrefix = '', skipInside) {
|
|
151
|
+
if (!fs_1.default.existsSync(dir))
|
|
152
|
+
return;
|
|
153
|
+
if (skipInside && isSameOrInside(dir, skipInside))
|
|
154
|
+
return;
|
|
155
|
+
const items = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
156
|
+
for (const item of items) {
|
|
157
|
+
const fullPath = path_1.default.join(dir, item.name);
|
|
158
|
+
if (item.isDirectory()) {
|
|
159
|
+
if (!item.name.startsWith('.') && item.name !== 'node_modules') {
|
|
160
|
+
scanForClientComponents(fullPath, scanRoot, components, pathPrefix, skipInside);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (item.isFile()) {
|
|
164
|
+
if (skipInside && isSameOrInside(fullPath, skipInside))
|
|
165
|
+
continue;
|
|
166
|
+
const ext = path_1.default.extname(item.name);
|
|
167
|
+
if (!['.tsx', '.ts', '.jsx', '.js'].includes(ext))
|
|
168
|
+
continue;
|
|
169
|
+
try {
|
|
170
|
+
const source = fs_1.default.readFileSync(fullPath, 'utf-8');
|
|
171
|
+
if (hasClientDirective(source)) {
|
|
172
|
+
const relativePathBase = (0, component_identity_1.relativeComponentPath)(scanRoot, fullPath);
|
|
173
|
+
const relativePath = pathPrefix ? `${pathPrefix}${relativePathBase}` : relativePathBase;
|
|
174
|
+
const moduleId = (0, component_identity_1.createComponentId)('client', relativePath);
|
|
175
|
+
components.push({
|
|
176
|
+
id: moduleId,
|
|
177
|
+
path: relativePath,
|
|
178
|
+
absolutePath: fullPath,
|
|
179
|
+
chunkName: (0, component_identity_1.createChunkName)(relativePath),
|
|
180
|
+
exports: extractExports(source),
|
|
181
|
+
async: false,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
console.warn(`[Vista RSC] Failed to read ${fullPath}:`, e);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Generate the client component manifest
|
|
193
|
+
*/
|
|
194
|
+
function generateClientManifest(cwd, appDir) {
|
|
195
|
+
const additionalRoots = discoverProjectClientRoots(cwd).filter((root) => path_1.default.resolve(root.dir) !== path_1.default.resolve(appDir));
|
|
196
|
+
return generateClientManifestWithRoots(cwd, appDir, additionalRoots);
|
|
197
|
+
}
|
|
198
|
+
function readBuildId(cwd) {
|
|
199
|
+
const buildIdPath = path_1.default.join(cwd, constants_1.BUILD_DIR, 'BUILD_ID');
|
|
200
|
+
try {
|
|
201
|
+
if (fs_1.default.existsSync(buildIdPath)) {
|
|
202
|
+
return fs_1.default.readFileSync(buildIdPath, 'utf-8').trim();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
// Use dev
|
|
207
|
+
}
|
|
208
|
+
return 'dev';
|
|
209
|
+
}
|
|
210
|
+
function nativeClientManifestToJs(native) {
|
|
211
|
+
const clientModules = {};
|
|
212
|
+
const pathToId = {};
|
|
213
|
+
const ssrModuleMapping = {};
|
|
214
|
+
for (const component of native.clientModules) {
|
|
215
|
+
const entry = {
|
|
216
|
+
id: component.id,
|
|
217
|
+
path: component.path,
|
|
218
|
+
absolutePath: component.absolutePath,
|
|
219
|
+
chunkName: component.chunkName,
|
|
220
|
+
exports: component.exports,
|
|
221
|
+
async: component.asyncLoad,
|
|
222
|
+
};
|
|
223
|
+
clientModules[component.id] = entry;
|
|
224
|
+
const normalizedRelativePath = (0, component_identity_1.normalizeComponentPath)(component.path);
|
|
225
|
+
const normalizedAbsolutePath = (0, component_identity_1.normalizeComponentPath)(component.absolutePath);
|
|
226
|
+
pathToId[component.path] = component.id;
|
|
227
|
+
pathToId[normalizedRelativePath] = component.id;
|
|
228
|
+
pathToId[component.absolutePath] = component.id;
|
|
229
|
+
pathToId[normalizedAbsolutePath] = component.id;
|
|
230
|
+
ssrModuleMapping[component.absolutePath] = `${constants_1.STATIC_CHUNKS_PATH}${component.chunkName}.js`;
|
|
231
|
+
ssrModuleMapping[normalizedAbsolutePath] = `${constants_1.STATIC_CHUNKS_PATH}${component.chunkName}.js`;
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
buildId: native.buildId,
|
|
235
|
+
clientModules,
|
|
236
|
+
pathToId,
|
|
237
|
+
ssrModuleMapping,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function generateClientManifestWithRoots(cwd, appDir, additionalRoots = []) {
|
|
241
|
+
if (additionalRootsMatchDiscovery(cwd, appDir, additionalRoots)) {
|
|
242
|
+
const native = (0, native_scanner_1.generateClientManifestForProjectNative)(cwd, appDir, readBuildId(cwd));
|
|
243
|
+
if (native && Array.isArray(native.clientModules)) {
|
|
244
|
+
return nativeClientManifestToJs(native);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const components = [];
|
|
248
|
+
scanForClientComponents(appDir, appDir, components);
|
|
249
|
+
for (const root of additionalRoots) {
|
|
250
|
+
if (!fs_1.default.existsSync(root.dir))
|
|
251
|
+
continue;
|
|
252
|
+
scanForClientComponents(root.dir, root.dir, components, root.prefix || '', appDir);
|
|
253
|
+
}
|
|
254
|
+
const clientModules = {};
|
|
255
|
+
const pathToId = {};
|
|
256
|
+
const ssrModuleMapping = {};
|
|
257
|
+
for (const component of components) {
|
|
258
|
+
clientModules[component.id] = component;
|
|
259
|
+
const normalizedRelativePath = (0, component_identity_1.normalizeComponentPath)(component.path);
|
|
260
|
+
const normalizedAbsolutePath = (0, component_identity_1.normalizeComponentPath)(component.absolutePath);
|
|
261
|
+
pathToId[component.path] = component.id;
|
|
262
|
+
pathToId[normalizedRelativePath] = component.id;
|
|
263
|
+
pathToId[component.absolutePath] = component.id;
|
|
264
|
+
pathToId[normalizedAbsolutePath] = component.id;
|
|
265
|
+
ssrModuleMapping[component.absolutePath] = `${constants_1.STATIC_CHUNKS_PATH}${component.chunkName}.js`;
|
|
266
|
+
ssrModuleMapping[normalizedAbsolutePath] = `${constants_1.STATIC_CHUNKS_PATH}${component.chunkName}.js`;
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
buildId: readBuildId(cwd),
|
|
270
|
+
clientModules,
|
|
271
|
+
pathToId,
|
|
272
|
+
ssrModuleMapping,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Get client component info by module ID
|
|
277
|
+
*/
|
|
278
|
+
function getClientComponent(manifest, moduleId) {
|
|
279
|
+
return manifest.clientModules[moduleId];
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Get client component by file path
|
|
283
|
+
*/
|
|
284
|
+
function getClientComponentByPath(manifest, filePath) {
|
|
285
|
+
const moduleId = manifest.pathToId[filePath];
|
|
286
|
+
if (!moduleId)
|
|
287
|
+
return undefined;
|
|
288
|
+
return manifest.clientModules[moduleId];
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Check if a path is a client component
|
|
292
|
+
*/
|
|
293
|
+
function isClientComponentPath(manifest, filePath) {
|
|
294
|
+
return filePath in manifest.pathToId;
|
|
295
|
+
}
|