@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.
- 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 +537 -492
- package/dist/bin/build.js +355 -353
- package/dist/bin/generate.js +513 -510
- package/dist/bin/webpack.config.js +4 -3
- 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.js +5 -4
- 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 +28 -28
- package/dist/build/rsc/react-client-reference-manifest.js +240 -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.react-server.d.ts +2 -2
- package/dist/client/link.react-server.js +11 -11
- 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.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 +43 -19
- package/dist/deploy/adapters/docker.d.ts +1 -0
- package/dist/deploy/adapters/docker.js +5 -4
- package/dist/deploy/adapters/netlify.js +62 -17
- 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 +1 -1
- package/dist/deploy/utils.js +31 -2
- package/dist/flashpack/command.js +1 -0
- package/dist/flashpack/runtime.js +2 -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/cookie-parse.d.ts +4 -4
- package/dist/server/cookie-parse.js +14 -14
- package/dist/server/engine.js +5 -5
- 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 +695 -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 +203 -219
- package/dist/server/rsc-upstream.js +893 -892
- package/dist/server/static-generator.js +4 -3
- 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
package/dist/bin/build-rsc.js
CHANGED
|
@@ -1,127 +1,130 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Vista RSC Build System
|
|
4
|
-
*
|
|
5
|
-
* Builds the application using the True RSC Architecture:
|
|
6
|
-
* 1. Server bundle (.vista/server/) - All code for SSR
|
|
7
|
-
* 2. Client bundle (.vista/static/) - Only client components
|
|
8
|
-
* 3. Manifests for hydration coordination
|
|
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.buildRSC = buildRSC;
|
|
15
|
-
exports.default = buildRSC;
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
17
|
-
const fs_1 = __importDefault(require("fs"));
|
|
18
|
-
const webpack_1 = __importDefault(require("webpack"));
|
|
19
|
-
const compiler_1 = require("../build/rsc/compiler");
|
|
20
|
-
const manifest_1 = require("../build/manifest");
|
|
21
|
-
const client_manifest_1 = require("../build/rsc/client-manifest");
|
|
22
|
-
const server_manifest_1 = require("../build/rsc/server-manifest");
|
|
23
|
-
const file_scanner_1 = require("./file-scanner");
|
|
24
|
-
const config_1 = require("../config");
|
|
25
|
-
const constants_1 = require("../constants");
|
|
26
|
-
const structure_validator_1 = require("../server/structure-validator");
|
|
27
|
-
const static_generator_1 = require("../server/static-generator");
|
|
28
|
-
const structure_log_1 = require("../server/structure-log");
|
|
29
|
-
const devtools_indicator_snippet_1 = require("./devtools-indicator-snippet");
|
|
30
|
-
const dev_error_overlay_snippet_1 = require("./dev-error-overlay-snippet");
|
|
31
|
-
const deploy_output_1 = require("./deploy-output");
|
|
32
|
-
const module_boundary_validator_1 = require("../server/module-boundary-validator");
|
|
33
|
-
const standalone_1 = require("../build/standalone");
|
|
34
|
-
const
|
|
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
|
-
if (
|
|
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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Vista RSC Build System
|
|
4
|
+
*
|
|
5
|
+
* Builds the application using the True RSC Architecture:
|
|
6
|
+
* 1. Server bundle (.vista/server/) - All code for SSR
|
|
7
|
+
* 2. Client bundle (.vista/static/) - Only client components
|
|
8
|
+
* 3. Manifests for hydration coordination
|
|
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.buildRSC = buildRSC;
|
|
15
|
+
exports.default = buildRSC;
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
|
18
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
19
|
+
const compiler_1 = require("../build/rsc/compiler");
|
|
20
|
+
const manifest_1 = require("../build/manifest");
|
|
21
|
+
const client_manifest_1 = require("../build/rsc/client-manifest");
|
|
22
|
+
const server_manifest_1 = require("../build/rsc/server-manifest");
|
|
23
|
+
const file_scanner_1 = require("./file-scanner");
|
|
24
|
+
const config_1 = require("../config");
|
|
25
|
+
const constants_1 = require("../constants");
|
|
26
|
+
const structure_validator_1 = require("../server/structure-validator");
|
|
27
|
+
const static_generator_1 = require("../server/static-generator");
|
|
28
|
+
const structure_log_1 = require("../server/structure-log");
|
|
29
|
+
const devtools_indicator_snippet_1 = require("./devtools-indicator-snippet");
|
|
30
|
+
const dev_error_overlay_snippet_1 = require("./dev-error-overlay-snippet");
|
|
31
|
+
const deploy_output_1 = require("./deploy-output");
|
|
32
|
+
const module_boundary_validator_1 = require("../server/module-boundary-validator");
|
|
33
|
+
const standalone_1 = require("../build/standalone");
|
|
34
|
+
const app_dir_1 = require("../server/app-dir");
|
|
35
|
+
const _debug = !!process.env.VISTA_DEBUG;
|
|
36
|
+
/**
|
|
37
|
+
* Run PostCSS for CSS compilation
|
|
38
|
+
*/
|
|
39
|
+
function runPostCSS(cwd, vistaDir) {
|
|
40
|
+
const globalsCss = path_1.default.join((0, app_dir_1.resolveAppDir)(cwd), 'globals.css');
|
|
41
|
+
if (fs_1.default.existsSync(globalsCss)) {
|
|
42
|
+
if (_debug)
|
|
43
|
+
console.log('[Vista JS RSC] Building CSS with PostCSS...');
|
|
44
|
+
const { execSync } = require('child_process');
|
|
45
|
+
try {
|
|
46
|
+
const cssOut = path_1.default.join(vistaDir, 'client.css');
|
|
47
|
+
const globalsCssRelative = path_1.default.relative(cwd, globalsCss).replace(/\\/g, '/');
|
|
48
|
+
execSync(`npx postcss "${globalsCssRelative}" -o "${cssOut}"`, {
|
|
49
|
+
stdio: _debug ? 'inherit' : 'pipe',
|
|
50
|
+
cwd,
|
|
51
|
+
});
|
|
52
|
+
if (_debug)
|
|
53
|
+
console.log('[Vista JS RSC] CSS Built Successfully!');
|
|
54
|
+
}
|
|
55
|
+
catch (cssErr) {
|
|
56
|
+
console.error('[Vista JS RSC] CSS Build failed (PostCSS error).');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function hasUseClientDirective(filePath) {
|
|
61
|
+
try {
|
|
62
|
+
const source = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
63
|
+
return /^\s*['"]use client['"]\s*;?/m.test(source);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function collectUseClientFiles(dir, collected) {
|
|
70
|
+
if (!fs_1.default.existsSync(dir))
|
|
71
|
+
return;
|
|
72
|
+
const entries = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
73
|
+
for (const entry of entries) {
|
|
74
|
+
const absolutePath = path_1.default.join(dir, entry.name);
|
|
75
|
+
if (entry.isDirectory()) {
|
|
76
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.'))
|
|
77
|
+
continue;
|
|
78
|
+
collectUseClientFiles(absolutePath, collected);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!entry.isFile())
|
|
82
|
+
continue;
|
|
83
|
+
const ext = path_1.default.extname(entry.name);
|
|
84
|
+
if (!['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'].includes(ext))
|
|
85
|
+
continue;
|
|
86
|
+
if (hasUseClientDirective(absolutePath)) {
|
|
87
|
+
collected.add(path_1.default.resolve(absolutePath));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function resolvePackageRoot(cwd, packageName) {
|
|
92
|
+
try {
|
|
93
|
+
return path_1.default.dirname(require.resolve(`${packageName}/package.json`, { paths: [cwd] }));
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function collectFrameworkClientReferences(cwd) {
|
|
100
|
+
const roots = [resolvePackageRoot(cwd, 'vista'), resolvePackageRoot(cwd, '@vistagenic/vista')].filter((value) => Boolean(value));
|
|
101
|
+
if (roots.length === 0) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
const collected = new Set();
|
|
105
|
+
for (const packageRoot of roots) {
|
|
106
|
+
collectUseClientFiles(path_1.default.join(packageRoot, 'dist'), collected);
|
|
107
|
+
collectUseClientFiles(path_1.default.join(packageRoot, 'src'), collected);
|
|
108
|
+
}
|
|
109
|
+
return Array.from(collected);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Generate the RSC-aware client entry file
|
|
113
|
+
*/
|
|
114
|
+
function generateRSCClientEntry(cwd, vistaDir, isDev) {
|
|
115
|
+
const devToolsBootId = `rsc-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
114
116
|
const clientEntryContent = `/**
|
|
115
117
|
* Vista RSC Client Entry
|
|
116
118
|
*
|
|
117
119
|
* This file is auto-generated. Do not edit directly.
|
|
118
|
-
* It hydrates
|
|
119
|
-
*
|
|
120
|
+
* It hydrates from the inline Flight payload in the HTML document when
|
|
121
|
+
* present (no /rsc refetch on first load). Client navigations still use
|
|
122
|
+
* /rsc via RSCRouter.
|
|
120
123
|
*/
|
|
121
124
|
|
|
122
125
|
import * as React from 'react';
|
|
123
126
|
import { hydrateRoot, createRoot } from 'react-dom/client';
|
|
124
|
-
import {
|
|
127
|
+
import { createFromReadableStream } from 'react-server-dom-webpack/client';
|
|
125
128
|
import { RSCRouter } from 'vista/client/rsc-router';
|
|
126
129
|
import { callServer } from 'vista/client/server-actions';
|
|
127
130
|
|
|
@@ -197,45 +200,87 @@ if (typeof window !== 'undefined') {
|
|
|
197
200
|
});
|
|
198
201
|
}
|
|
199
202
|
|
|
203
|
+
function flightTextToReadableStream(flightText: string): ReadableStream<Uint8Array> {
|
|
204
|
+
var encoder = new TextEncoder();
|
|
205
|
+
var bytes = encoder.encode(flightText);
|
|
206
|
+
return new ReadableStream({
|
|
207
|
+
start: function (controller) {
|
|
208
|
+
controller.enqueue(bytes);
|
|
209
|
+
controller.close();
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function waitForInlineFlightPayload(timeoutMs: number): Promise<string | null> {
|
|
215
|
+
var existing = (window as any).${constants_1.RSC_DATA_FLAG};
|
|
216
|
+
if (typeof existing === 'string' && existing.length > 0) {
|
|
217
|
+
return Promise.resolve(existing);
|
|
218
|
+
}
|
|
219
|
+
return new Promise(function (resolve) {
|
|
220
|
+
var started = Date.now();
|
|
221
|
+
var timer = setInterval(function () {
|
|
222
|
+
var value = (window as any).${constants_1.RSC_DATA_FLAG};
|
|
223
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
224
|
+
clearInterval(timer);
|
|
225
|
+
resolve(value);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (Date.now() - started >= timeoutMs) {
|
|
229
|
+
clearInterval(timer);
|
|
230
|
+
resolve(null);
|
|
231
|
+
}
|
|
232
|
+
}, 8);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
200
236
|
const pathname = window.location.pathname;
|
|
201
|
-
const search = window.location.search;
|
|
202
|
-
const initialResponse = createFromFetch(
|
|
203
|
-
fetch(\`/rsc\${pathname}\${search}\`, { headers: { Accept: 'text/x-component' } }),
|
|
204
|
-
{ callServer }
|
|
205
|
-
) as Promise<React.ReactNode>;
|
|
206
237
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
238
|
+
waitForInlineFlightPayload(4000).then(function (inlineFlight) {
|
|
239
|
+
if (typeof inlineFlight !== 'string' || inlineFlight.length === 0) {
|
|
240
|
+
reportDevRuntimeError(
|
|
241
|
+
'Hydration Error',
|
|
242
|
+
new Error('Missing inline Flight payload (window.${constants_1.RSC_DATA_FLAG}). First load no longer refetches /rsc.')
|
|
243
|
+
);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
211
246
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
247
|
+
const initialResponse = createFromReadableStream(flightTextToReadableStream(inlineFlight), {
|
|
248
|
+
callServer,
|
|
249
|
+
}) as Promise<React.ReactNode>;
|
|
250
|
+
|
|
251
|
+
var appElement = React.createElement(RSCRouter, {
|
|
252
|
+
initialResponse,
|
|
253
|
+
initialPathname: pathname,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
try {
|
|
257
|
+
hydrateRoot(
|
|
258
|
+
rootElement as Document | Element,
|
|
259
|
+
appElement,
|
|
260
|
+
{
|
|
261
|
+
onRecoverableError(error) {
|
|
262
|
+
var message = String((error as any)?.message || error || '');
|
|
263
|
+
if (/hydration|did not match|server rendered html|text content/i.test(message)) {
|
|
264
|
+
reportDevRuntimeError('Hydration Error', error);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
reportDevRuntimeError('Recoverable Error', error);
|
|
268
|
+
},
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
reportDevRuntimeError('Hydration Error', error);
|
|
273
|
+
if (!hydrateDocument && rootElement instanceof Element) {
|
|
274
|
+
try {
|
|
275
|
+
createRoot(rootElement).render(appElement);
|
|
276
|
+
} catch (fallbackError) {
|
|
277
|
+
reportDevRuntimeError('Client Render Fallback Failed', fallbackError);
|
|
278
|
+
}
|
|
234
279
|
}
|
|
235
280
|
}
|
|
236
|
-
}
|
|
281
|
+
});
|
|
237
282
|
|
|
238
|
-
${isDev
|
|
283
|
+
${isDev
|
|
239
284
|
? `// Vista live-reload: listen for server component changes via SSE
|
|
240
285
|
(function connectReload() {
|
|
241
286
|
const es = new EventSource('${constants_1.SSE_ENDPOINT}');
|
|
@@ -272,347 +317,347 @@ ${isDev
|
|
|
272
317
|
es.close();
|
|
273
318
|
setTimeout(connectReload, 3000);
|
|
274
319
|
};
|
|
275
|
-
})();`
|
|
320
|
+
})();`
|
|
276
321
|
: '// SSE live-reload disabled in production'}
|
|
277
|
-
`;
|
|
278
|
-
fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'rsc-client.tsx'), clientEntryContent);
|
|
279
|
-
if (_debug)
|
|
280
|
-
console.log('[vista:build] Generated RSC client entry file');
|
|
281
|
-
}
|
|
282
|
-
function syncReactServerManifests(vistaDir) {
|
|
283
|
-
const canonicalPath = path_1.default.join(vistaDir, 'react-server-manifest.json');
|
|
284
|
-
const legacyPath = path_1.default.join(vistaDir, 'react-ssr-manifest.json');
|
|
285
|
-
if (fs_1.default.existsSync(canonicalPath) && !fs_1.default.existsSync(legacyPath)) {
|
|
286
|
-
fs_1.default.copyFileSync(canonicalPath, legacyPath);
|
|
287
|
-
}
|
|
288
|
-
else if (fs_1.default.existsSync(legacyPath) && !fs_1.default.existsSync(canonicalPath)) {
|
|
289
|
-
fs_1.default.copyFileSync(legacyPath, canonicalPath);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Build with RSC architecture
|
|
294
|
-
*/
|
|
295
|
-
async function buildRSC(watch = false) {
|
|
296
|
-
const cwd = process.cwd();
|
|
297
|
-
const appDir =
|
|
298
|
-
const projectClientRoots = (0, client_manifest_1.discoverProjectClientRoots)(cwd);
|
|
299
|
-
const additionalClientRoots = projectClientRoots.filter((root) => path_1.default.resolve(root.dir) !== path_1.default.resolve(appDir));
|
|
300
|
-
let clientReferenceFiles = [];
|
|
301
|
-
if (_debug) {
|
|
302
|
-
console.log('');
|
|
303
|
-
console.log('╔══════════════════════════════════════════════════════════════╗');
|
|
304
|
-
console.log('║ Vista JS RSC Build System (React Server Components) ║');
|
|
305
|
-
console.log('╚══════════════════════════════════════════════════════════════╝');
|
|
306
|
-
console.log('');
|
|
307
|
-
}
|
|
308
|
-
// Create .vista directory structure
|
|
309
|
-
const vistaDirs = (0, manifest_1.createVistaDirectories)(cwd, 'rsc');
|
|
310
|
-
const buildId = (0, manifest_1.getBuildId)(vistaDirs.root, !watch);
|
|
311
|
-
if (_debug) {
|
|
312
|
-
console.log(`[vista:build] Build ID: ${buildId}`);
|
|
313
|
-
console.log(`[vista:build] Mode: ${watch ? 'Development (Watch)' : 'Production'}`);
|
|
314
|
-
console.log('');
|
|
315
|
-
}
|
|
316
|
-
// ========================================================================
|
|
317
|
-
// Pre-build Structure Validation
|
|
318
|
-
// ========================================================================
|
|
319
|
-
const vistaConfig = (0, config_1.loadConfig)(cwd);
|
|
320
|
-
const engineVariant = (0, config_1.resolveAndApplyEngineVariant)(vistaConfig);
|
|
321
|
-
const structureConfig = (0, config_1.resolveStructureValidationConfig)(vistaConfig);
|
|
322
|
-
const cacheComponentsConfig = (0, config_1.resolveCacheComponentsConfig)(vistaConfig);
|
|
323
|
-
if (_debug)
|
|
324
|
-
console.log(`[vista:build] Engine variant: ${engineVariant}`);
|
|
325
|
-
if (structureConfig.enabled) {
|
|
326
|
-
const result = (0, structure_validator_1.validateAppStructure)({ cwd });
|
|
327
|
-
(0, structure_log_1.logValidationResult)(result, structureConfig.logLevel);
|
|
328
|
-
if (result.state === 'error' && structureConfig.mode === 'strict') {
|
|
329
|
-
console.error((0, structure_log_1.formatBuildFailTable)(result));
|
|
330
|
-
process.exit(1);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
// Scan app/ plus every other top-level project directory (components/, utils/,
|
|
334
|
-
// lib/, src/, ...) so `'use client'` modules outside app/ still enter the
|
|
335
|
-
// React Client Manifest. Discovery is directory membership, not the import graph.
|
|
336
|
-
if (fs_1.default.existsSync(appDir)) {
|
|
337
|
-
if (_debug) {
|
|
338
|
-
console.log(`[Vista JS RSC] Using ${(0, file_scanner_1.isNativeAvailable)() ? 'Rust native' : 'JS fallback'} scanner (v${(0, file_scanner_1.getVersion)()})`);
|
|
339
|
-
}
|
|
340
|
-
const scanResult = (0, file_scanner_1.scanAppDirectory)(appDir);
|
|
341
|
-
clientReferenceFiles = scanResult.clientComponents.map((component) => component.absolutePath);
|
|
342
|
-
for (const root of additionalClientRoots) {
|
|
343
|
-
const extraScan = (0, file_scanner_1.scanAppDirectory)(root.dir);
|
|
344
|
-
clientReferenceFiles.push(...extraScan.clientComponents.map((component) => component.absolutePath));
|
|
345
|
-
if (_debug && extraScan.clientComponents.length > 0) {
|
|
346
|
-
console.log(`[Vista JS RSC] Found ${extraScan.clientComponents.length} client components ('use client') in ${root.prefix}`);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
clientReferenceFiles = Array.from(new Set(clientReferenceFiles));
|
|
350
|
-
if (_debug) {
|
|
351
|
-
console.log(`[Vista JS RSC] Found ${scanResult.serverComponents.length} server components`);
|
|
352
|
-
console.log(`[Vista JS RSC] Found ${scanResult.clientComponents.length} client components ('use client') in app/`);
|
|
353
|
-
console.log(`[Vista JS RSC] Total client reference modules: ${clientReferenceFiles.length}`);
|
|
354
|
-
console.log('');
|
|
355
|
-
}
|
|
356
|
-
if (scanResult.clientComponents.length > 0 && _debug) {
|
|
357
|
-
console.log('[Vista JS RSC] Client Components (will be hydrated on browser):');
|
|
358
|
-
scanResult.clientComponents.forEach((c) => {
|
|
359
|
-
console.log(` ✓ ${c.relativePath}`);
|
|
360
|
-
});
|
|
361
|
-
console.log('');
|
|
362
|
-
}
|
|
363
|
-
if (scanResult.serverComponents.length > 0 && _debug) {
|
|
364
|
-
console.log('[Vista JS RSC] Server Components (0kb client bundle contribution):');
|
|
365
|
-
scanResult.serverComponents.slice(0, 5).forEach((c) => {
|
|
366
|
-
console.log(` • ${c.relativePath}`);
|
|
367
|
-
});
|
|
368
|
-
if (scanResult.serverComponents.length > 5) {
|
|
369
|
-
console.log(` ... and ${scanResult.serverComponents.length - 5} more`);
|
|
370
|
-
}
|
|
371
|
-
console.log('');
|
|
372
|
-
}
|
|
373
|
-
const scanErrors = (0, module_boundary_validator_1.validateModuleBoundaries)({
|
|
374
|
-
appDir,
|
|
375
|
-
extraRoots: additionalClientRoots.map((root) => root.dir),
|
|
376
|
-
cacheComponentsEnabled: cacheComponentsConfig.enabled,
|
|
377
|
-
}).issues;
|
|
378
|
-
if (scanErrors.length > 0) {
|
|
379
|
-
console.log('\x1b[41m\x1b[37m ERROR \x1b[0m \x1b[31mServer/Segment Violations\x1b[0m');
|
|
380
|
-
console.log('');
|
|
381
|
-
for (const error of scanErrors) {
|
|
382
|
-
console.log(`\x1b[31m✗\x1b[0m ${path_1.default.relative(cwd, error.filePath)}`);
|
|
383
|
-
console.log(` ${error.message}`);
|
|
384
|
-
console.log('');
|
|
385
|
-
if (error.fix) {
|
|
386
|
-
console.log(` \x1b[36mTo fix:\x1b[0m ${error.fix}`);
|
|
387
|
-
console.log('');
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
if (!watch) {
|
|
391
|
-
console.log('\x1b[31mBuild failed due to server/segment violations.\x1b[0m');
|
|
392
|
-
process.exit(1);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
// Include framework-level client boundaries (e.g. vista/link) so external
|
|
397
|
-
// package client modules resolve in React Flight manifests.
|
|
398
|
-
const frameworkClientReferences = collectFrameworkClientReferences(cwd);
|
|
399
|
-
if (frameworkClientReferences.length > 0) {
|
|
400
|
-
clientReferenceFiles = Array.from(new Set([...clientReferenceFiles, ...frameworkClientReferences]));
|
|
401
|
-
if (_debug) {
|
|
402
|
-
console.log(`[Vista JS RSC] Added ${frameworkClientReferences.length} framework client references`);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
// Generate manifests
|
|
406
|
-
if (_debug)
|
|
407
|
-
console.log('[vista:build] Generating manifests...');
|
|
408
|
-
const clientManifest = (0, client_manifest_1.generateClientManifestWithRoots)(cwd, appDir, additionalClientRoots);
|
|
409
|
-
fs_1.default.writeFileSync(path_1.default.join(vistaDirs.root, 'client-manifest.json'), JSON.stringify(clientManifest, null, 2));
|
|
410
|
-
if (_debug) {
|
|
411
|
-
console.log(` ✓ client-manifest.json (${Object.keys(clientManifest.clientModules).length} modules)`);
|
|
412
|
-
}
|
|
413
|
-
const serverManifest = (0, server_manifest_1.generateServerManifest)(cwd, appDir);
|
|
414
|
-
fs_1.default.writeFileSync(path_1.default.join(vistaDirs.server, 'server-manifest.json'), JSON.stringify(serverManifest, null, 2));
|
|
415
|
-
if (_debug) {
|
|
416
|
-
console.log(` ✓ server-manifest.json (${Object.keys(serverManifest.serverModules).length} modules, ${serverManifest.routes.length} routes)`);
|
|
417
|
-
console.log('');
|
|
418
|
-
}
|
|
419
|
-
(0, manifest_1.writeCanonicalVistaArtifacts)(cwd, vistaDirs.root, buildId, serverManifest.routes.map((route) => ({
|
|
420
|
-
pattern: route.pattern,
|
|
421
|
-
pagePath: route.pagePath,
|
|
422
|
-
type: route.type,
|
|
423
|
-
})), serverManifest.routeHandlers.map((handler) => ({
|
|
424
|
-
pattern: handler.pattern,
|
|
425
|
-
filePath: handler.filePath,
|
|
426
|
-
type: handler.type,
|
|
427
|
-
methods: handler.methods,
|
|
428
|
-
runtime: handler.runtime,
|
|
429
|
-
})));
|
|
430
|
-
(0, manifest_1.writeReservedVistaArtifacts)(vistaDirs.root, {
|
|
431
|
-
buildId,
|
|
432
|
-
engineVariant,
|
|
433
|
-
imagesConfig: vistaConfig.images,
|
|
434
|
-
});
|
|
435
|
-
// Generate client entry
|
|
436
|
-
generateRSCClientEntry(cwd, vistaDirs.root, watch);
|
|
437
|
-
// Create webpack configs
|
|
438
|
-
const options = {
|
|
439
|
-
cwd,
|
|
440
|
-
isDev: watch,
|
|
441
|
-
vistaDirs,
|
|
442
|
-
buildId,
|
|
443
|
-
engineVariant,
|
|
444
|
-
clientReferenceFiles,
|
|
445
|
-
};
|
|
446
|
-
// Build CSS
|
|
447
|
-
runPostCSS(cwd, vistaDirs.root);
|
|
448
|
-
if (watch) {
|
|
449
|
-
// Development mode - return compilers for middleware
|
|
450
|
-
if (_debug)
|
|
451
|
-
console.log('[Vista JS RSC] Creating development compilers...');
|
|
452
|
-
// Clear stale webpack cache. ReactFlightWebpackPlugin adds
|
|
453
|
-
// AsyncDependenciesBlock entries that can't be serialised by webpack's
|
|
454
|
-
// pack file cache strategy. A stale cache that was written *before* the
|
|
455
|
-
// plugin ran will skip the parser hook entirely, causing empty Flight
|
|
456
|
-
// manifests. Clearing on every dev-start is the safest approach –
|
|
457
|
-
// first-compile is ~1s longer but guarantees correct manifests.
|
|
458
|
-
const cacheDir = engineVariant === 'flashpack'
|
|
459
|
-
? path_1.default.join(cwd, constants_1.FLASH_DIR, 'cache', 'webpack')
|
|
460
|
-
: path_1.default.join(vistaDirs.root, 'cache');
|
|
461
|
-
if (fs_1.default.existsSync(cacheDir)) {
|
|
462
|
-
fs_1.default.rmSync(cacheDir, { recursive: true, force: true });
|
|
463
|
-
if (_debug)
|
|
464
|
-
console.log('[Vista JS RSC] Cleared stale webpack cache');
|
|
465
|
-
}
|
|
466
|
-
// Write stub Flight manifests so upstream can start before first webpack compile.
|
|
467
|
-
// ReactFlightWebpackPlugin will overwrite these on first successful compilation.
|
|
468
|
-
const stubManifests = [
|
|
469
|
-
path_1.default.join(vistaDirs.root, 'react-client-manifest.json'),
|
|
470
|
-
path_1.default.join(vistaDirs.root, 'react-server-manifest.json'),
|
|
471
|
-
path_1.default.join(vistaDirs.root, 'react-ssr-manifest.json'),
|
|
472
|
-
];
|
|
473
|
-
for (const manifestPath of stubManifests) {
|
|
474
|
-
if (!fs_1.default.existsSync(manifestPath)) {
|
|
475
|
-
fs_1.default.writeFileSync(manifestPath, '{}');
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
const clientConfig = (0, compiler_1.createClientWebpackConfig)(options);
|
|
479
|
-
const clientCompiler = (0, webpack_1.default)(clientConfig);
|
|
480
|
-
syncReactServerManifests(vistaDirs.root);
|
|
481
|
-
// Watch for CSS + source changes that can affect Tailwind output.
|
|
482
|
-
try {
|
|
483
|
-
const chokidar = require('chokidar');
|
|
484
|
-
const styleWatchRoots = ['app', 'components', 'content', 'lib', 'ctx', 'data', 'utils', 'src']
|
|
485
|
-
.map((entry) => path_1.default.join(cwd, entry))
|
|
486
|
-
.filter((entry) => fs_1.default.existsSync(entry));
|
|
487
|
-
let cssTimer = null;
|
|
488
|
-
const scheduleCSSBuild = () => {
|
|
489
|
-
if (cssTimer)
|
|
490
|
-
clearTimeout(cssTimer);
|
|
491
|
-
cssTimer = setTimeout(() => {
|
|
492
|
-
if (_debug)
|
|
493
|
-
console.log('[Vista JS RSC] Style source changed, rebuilding CSS...');
|
|
494
|
-
runPostCSS(cwd, vistaDirs.root);
|
|
495
|
-
}, 120);
|
|
496
|
-
};
|
|
497
|
-
chokidar
|
|
498
|
-
.watch(styleWatchRoots, {
|
|
499
|
-
ignoreInitial: true,
|
|
500
|
-
ignored: (watchedPath) => watchedPath.includes(`${path_1.default.sep}node_modules${path_1.default.sep}`) ||
|
|
501
|
-
watchedPath.includes(`${path_1.default.sep}.git${path_1.default.sep}`) ||
|
|
502
|
-
watchedPath.includes(`${path_1.default.sep}.vista${path_1.default.sep}`),
|
|
503
|
-
})
|
|
504
|
-
.on('all', (_event, changedPath) => {
|
|
505
|
-
if (/\.(?:css|[cm]?[jt]sx?|md|mdx)$/i.test(changedPath)) {
|
|
506
|
-
scheduleCSSBuild();
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
catch (e) {
|
|
511
|
-
// chokidar not installed
|
|
512
|
-
}
|
|
513
|
-
if (_debug) {
|
|
514
|
-
console.log('[Vista JS RSC] Ready for development');
|
|
515
|
-
console.log('');
|
|
516
|
-
}
|
|
517
|
-
return { serverCompiler: null, clientCompiler };
|
|
518
|
-
}
|
|
519
|
-
else {
|
|
520
|
-
// Production build
|
|
521
|
-
console.log('[Vista JS RSC] Building for production...');
|
|
522
|
-
console.log('');
|
|
523
|
-
const serverConfig = (0, compiler_1.createServerWebpackConfig)(options);
|
|
524
|
-
const clientConfig = (0, compiler_1.createClientWebpackConfig)(options);
|
|
525
|
-
// Build server bundle
|
|
526
|
-
console.log('[Vista JS RSC] Building server bundle...');
|
|
527
|
-
await new Promise((resolve, reject) => {
|
|
528
|
-
(0, webpack_1.default)(serverConfig).run((err, stats) => {
|
|
529
|
-
if (err) {
|
|
530
|
-
console.error('[Vista RSC] Server build error:', err);
|
|
531
|
-
reject(err);
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
if (stats?.hasErrors()) {
|
|
535
|
-
console.error('[Vista RSC] Server compilation errors:', stats.toString('errors-only'));
|
|
536
|
-
reject(new Error('Server compilation failed'));
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
console.log('[Vista JS RSC] Server bundle complete');
|
|
540
|
-
resolve();
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
// Build client bundle
|
|
544
|
-
console.log('[Vista JS RSC] Building client bundle...');
|
|
545
|
-
await new Promise((resolve, reject) => {
|
|
546
|
-
(0, webpack_1.default)(clientConfig).run((err, stats) => {
|
|
547
|
-
if (err) {
|
|
548
|
-
console.error('[Vista RSC] Client build error:', err);
|
|
549
|
-
reject(err);
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
if (stats?.hasErrors()) {
|
|
553
|
-
console.error('[Vista RSC] Client compilation errors:', stats.toString('errors-only'));
|
|
554
|
-
reject(new Error('Client compilation failed'));
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
console.log('[Vista JS RSC] Client bundle complete');
|
|
558
|
-
console.log(stats?.toString('minimal'));
|
|
559
|
-
syncReactServerManifests(vistaDirs.root);
|
|
560
|
-
resolve();
|
|
561
|
-
});
|
|
562
|
-
});
|
|
563
|
-
// ------------------------------------------------------------------
|
|
564
|
-
// Static Generation (SSG / ISR)
|
|
565
|
-
// ------------------------------------------------------------------
|
|
566
|
-
console.log('[Vista JS RSC] Running static generation...');
|
|
567
|
-
const ssgResult = await (0, static_generator_1.generateStaticPages)({
|
|
568
|
-
cwd,
|
|
569
|
-
vistaDirRoot: vistaDirs.root,
|
|
570
|
-
manifest: serverManifest,
|
|
571
|
-
isDev: false,
|
|
572
|
-
buildId,
|
|
573
|
-
});
|
|
574
|
-
if (ssgResult.pagesGenerated > 0) {
|
|
575
|
-
console.log(`[Vista JS RSC] Pre-rendered ${ssgResult.pagesGenerated} page(s): ${ssgResult.generatedPaths.join(', ')}`);
|
|
576
|
-
}
|
|
577
|
-
if (ssgResult.failedPaths.length > 0) {
|
|
578
|
-
console.warn(`[Vista JS RSC] Failed to pre-render ${ssgResult.failedPaths.length} page(s):`, ssgResult.failedPaths.map((f) => `${f.path} (${f.error})`).join(', '));
|
|
579
|
-
}
|
|
580
|
-
// Write the real prerender manifest (overwrite the empty stub)
|
|
581
|
-
const prerenderManifestPath = path_1.default.join(vistaDirs.root, 'prerender-manifest.json');
|
|
582
|
-
fs_1.default.writeFileSync(prerenderManifestPath, JSON.stringify(ssgResult.manifest, null, 2));
|
|
583
|
-
console.log('[Vista JS RSC] Wrote prerender-manifest.json');
|
|
584
|
-
(0, standalone_1.generateStandaloneOutput)({
|
|
585
|
-
cwd,
|
|
586
|
-
vistaDir: vistaDirs.root,
|
|
587
|
-
buildId,
|
|
588
|
-
serverManifest,
|
|
589
|
-
debug: _debug,
|
|
590
|
-
});
|
|
591
|
-
(0, deploy_output_1.generateDeploymentOutputs)({
|
|
592
|
-
cwd,
|
|
593
|
-
vistaDir: vistaDirs.root,
|
|
594
|
-
debug: _debug,
|
|
595
|
-
});
|
|
596
|
-
(0, manifest_1.pruneEmptyVistaDirectories)(vistaDirs.root);
|
|
597
|
-
console.log('');
|
|
598
|
-
console.log('╔══════════════════════════════════════════════════════════════╗');
|
|
599
|
-
console.log('║ Build Complete! 🎉 ║');
|
|
600
|
-
console.log('╚══════════════════════════════════════════════════════════════╝');
|
|
601
|
-
console.log('');
|
|
602
|
-
console.log(' Output directory: .vista/');
|
|
603
|
-
console.log(' ├── server/ (Server-side bundle - NEVER sent to client)');
|
|
604
|
-
console.log(' ├── static/ (Client assets - only client components)');
|
|
605
|
-
if (engineVariant === 'flashpack') {
|
|
606
|
-
console.log(' └── cache/ (metadata bridge to the active Flashpack cache)');
|
|
607
|
-
console.log(' Flashpack directory: .flash/');
|
|
608
|
-
console.log(' ├── cache/ (Flashpack runtime cache)');
|
|
609
|
-
console.log(' ├── graph/ (Rust pipeline graph snapshots)');
|
|
610
|
-
console.log(' └── logs/ (Flashpack phase logs)');
|
|
611
|
-
}
|
|
612
|
-
else {
|
|
613
|
-
console.log(' └── cache/ (Build cache for faster rebuilds)');
|
|
614
|
-
}
|
|
615
|
-
console.log('');
|
|
616
|
-
return { serverCompiler: null, clientCompiler: null };
|
|
617
|
-
}
|
|
618
|
-
}
|
|
322
|
+
`;
|
|
323
|
+
fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'rsc-client.tsx'), clientEntryContent);
|
|
324
|
+
if (_debug)
|
|
325
|
+
console.log('[vista:build] Generated RSC client entry file');
|
|
326
|
+
}
|
|
327
|
+
function syncReactServerManifests(vistaDir) {
|
|
328
|
+
const canonicalPath = path_1.default.join(vistaDir, 'react-server-manifest.json');
|
|
329
|
+
const legacyPath = path_1.default.join(vistaDir, 'react-ssr-manifest.json');
|
|
330
|
+
if (fs_1.default.existsSync(canonicalPath) && !fs_1.default.existsSync(legacyPath)) {
|
|
331
|
+
fs_1.default.copyFileSync(canonicalPath, legacyPath);
|
|
332
|
+
}
|
|
333
|
+
else if (fs_1.default.existsSync(legacyPath) && !fs_1.default.existsSync(canonicalPath)) {
|
|
334
|
+
fs_1.default.copyFileSync(legacyPath, canonicalPath);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Build with RSC architecture
|
|
339
|
+
*/
|
|
340
|
+
async function buildRSC(watch = false) {
|
|
341
|
+
const cwd = process.cwd();
|
|
342
|
+
const appDir = (0, app_dir_1.resolveAppDir)(cwd);
|
|
343
|
+
const projectClientRoots = (0, client_manifest_1.discoverProjectClientRoots)(cwd);
|
|
344
|
+
const additionalClientRoots = projectClientRoots.filter((root) => path_1.default.resolve(root.dir) !== path_1.default.resolve(appDir));
|
|
345
|
+
let clientReferenceFiles = [];
|
|
346
|
+
if (_debug) {
|
|
347
|
+
console.log('');
|
|
348
|
+
console.log('╔══════════════════════════════════════════════════════════════╗');
|
|
349
|
+
console.log('║ Vista JS RSC Build System (React Server Components) ║');
|
|
350
|
+
console.log('╚══════════════════════════════════════════════════════════════╝');
|
|
351
|
+
console.log('');
|
|
352
|
+
}
|
|
353
|
+
// Create .vista directory structure
|
|
354
|
+
const vistaDirs = (0, manifest_1.createVistaDirectories)(cwd, 'rsc');
|
|
355
|
+
const buildId = (0, manifest_1.getBuildId)(vistaDirs.root, !watch);
|
|
356
|
+
if (_debug) {
|
|
357
|
+
console.log(`[vista:build] Build ID: ${buildId}`);
|
|
358
|
+
console.log(`[vista:build] Mode: ${watch ? 'Development (Watch)' : 'Production'}`);
|
|
359
|
+
console.log('');
|
|
360
|
+
}
|
|
361
|
+
// ========================================================================
|
|
362
|
+
// Pre-build Structure Validation
|
|
363
|
+
// ========================================================================
|
|
364
|
+
const vistaConfig = (0, config_1.loadConfig)(cwd);
|
|
365
|
+
const engineVariant = (0, config_1.resolveAndApplyEngineVariant)(vistaConfig);
|
|
366
|
+
const structureConfig = (0, config_1.resolveStructureValidationConfig)(vistaConfig);
|
|
367
|
+
const cacheComponentsConfig = (0, config_1.resolveCacheComponentsConfig)(vistaConfig);
|
|
368
|
+
if (_debug)
|
|
369
|
+
console.log(`[vista:build] Engine variant: ${engineVariant}`);
|
|
370
|
+
if (structureConfig.enabled) {
|
|
371
|
+
const result = (0, structure_validator_1.validateAppStructure)({ cwd });
|
|
372
|
+
(0, structure_log_1.logValidationResult)(result, structureConfig.logLevel);
|
|
373
|
+
if (result.state === 'error' && structureConfig.mode === 'strict') {
|
|
374
|
+
console.error((0, structure_log_1.formatBuildFailTable)(result));
|
|
375
|
+
process.exit(1);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
// Scan app/ plus every other top-level project directory (components/, utils/,
|
|
379
|
+
// lib/, src/, ...) so `'use client'` modules outside app/ still enter the
|
|
380
|
+
// React Client Manifest. Discovery is directory membership, not the import graph.
|
|
381
|
+
if (fs_1.default.existsSync(appDir)) {
|
|
382
|
+
if (_debug) {
|
|
383
|
+
console.log(`[Vista JS RSC] Using ${(0, file_scanner_1.isNativeAvailable)() ? 'Rust native' : 'JS fallback'} scanner (v${(0, file_scanner_1.getVersion)()})`);
|
|
384
|
+
}
|
|
385
|
+
const scanResult = (0, file_scanner_1.scanAppDirectory)(appDir);
|
|
386
|
+
clientReferenceFiles = scanResult.clientComponents.map((component) => component.absolutePath);
|
|
387
|
+
for (const root of additionalClientRoots) {
|
|
388
|
+
const extraScan = (0, file_scanner_1.scanAppDirectory)(root.dir);
|
|
389
|
+
clientReferenceFiles.push(...extraScan.clientComponents.map((component) => component.absolutePath));
|
|
390
|
+
if (_debug && extraScan.clientComponents.length > 0) {
|
|
391
|
+
console.log(`[Vista JS RSC] Found ${extraScan.clientComponents.length} client components ('use client') in ${root.prefix}`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
clientReferenceFiles = Array.from(new Set(clientReferenceFiles));
|
|
395
|
+
if (_debug) {
|
|
396
|
+
console.log(`[Vista JS RSC] Found ${scanResult.serverComponents.length} server components`);
|
|
397
|
+
console.log(`[Vista JS RSC] Found ${scanResult.clientComponents.length} client components ('use client') in app/`);
|
|
398
|
+
console.log(`[Vista JS RSC] Total client reference modules: ${clientReferenceFiles.length}`);
|
|
399
|
+
console.log('');
|
|
400
|
+
}
|
|
401
|
+
if (scanResult.clientComponents.length > 0 && _debug) {
|
|
402
|
+
console.log('[Vista JS RSC] Client Components (will be hydrated on browser):');
|
|
403
|
+
scanResult.clientComponents.forEach((c) => {
|
|
404
|
+
console.log(` ✓ ${c.relativePath}`);
|
|
405
|
+
});
|
|
406
|
+
console.log('');
|
|
407
|
+
}
|
|
408
|
+
if (scanResult.serverComponents.length > 0 && _debug) {
|
|
409
|
+
console.log('[Vista JS RSC] Server Components (0kb client bundle contribution):');
|
|
410
|
+
scanResult.serverComponents.slice(0, 5).forEach((c) => {
|
|
411
|
+
console.log(` • ${c.relativePath}`);
|
|
412
|
+
});
|
|
413
|
+
if (scanResult.serverComponents.length > 5) {
|
|
414
|
+
console.log(` ... and ${scanResult.serverComponents.length - 5} more`);
|
|
415
|
+
}
|
|
416
|
+
console.log('');
|
|
417
|
+
}
|
|
418
|
+
const scanErrors = (0, module_boundary_validator_1.validateModuleBoundaries)({
|
|
419
|
+
appDir,
|
|
420
|
+
extraRoots: additionalClientRoots.map((root) => root.dir),
|
|
421
|
+
cacheComponentsEnabled: cacheComponentsConfig.enabled,
|
|
422
|
+
}).issues;
|
|
423
|
+
if (scanErrors.length > 0) {
|
|
424
|
+
console.log('\x1b[41m\x1b[37m ERROR \x1b[0m \x1b[31mServer/Segment Violations\x1b[0m');
|
|
425
|
+
console.log('');
|
|
426
|
+
for (const error of scanErrors) {
|
|
427
|
+
console.log(`\x1b[31m✗\x1b[0m ${path_1.default.relative(cwd, error.filePath)}`);
|
|
428
|
+
console.log(` ${error.message}`);
|
|
429
|
+
console.log('');
|
|
430
|
+
if (error.fix) {
|
|
431
|
+
console.log(` \x1b[36mTo fix:\x1b[0m ${error.fix}`);
|
|
432
|
+
console.log('');
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (!watch) {
|
|
436
|
+
console.log('\x1b[31mBuild failed due to server/segment violations.\x1b[0m');
|
|
437
|
+
process.exit(1);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
// Include framework-level client boundaries (e.g. vista/link) so external
|
|
442
|
+
// package client modules resolve in React Flight manifests.
|
|
443
|
+
const frameworkClientReferences = collectFrameworkClientReferences(cwd);
|
|
444
|
+
if (frameworkClientReferences.length > 0) {
|
|
445
|
+
clientReferenceFiles = Array.from(new Set([...clientReferenceFiles, ...frameworkClientReferences]));
|
|
446
|
+
if (_debug) {
|
|
447
|
+
console.log(`[Vista JS RSC] Added ${frameworkClientReferences.length} framework client references`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
// Generate manifests
|
|
451
|
+
if (_debug)
|
|
452
|
+
console.log('[vista:build] Generating manifests...');
|
|
453
|
+
const clientManifest = (0, client_manifest_1.generateClientManifestWithRoots)(cwd, appDir, additionalClientRoots);
|
|
454
|
+
fs_1.default.writeFileSync(path_1.default.join(vistaDirs.root, 'client-manifest.json'), JSON.stringify(clientManifest, null, 2));
|
|
455
|
+
if (_debug) {
|
|
456
|
+
console.log(` ✓ client-manifest.json (${Object.keys(clientManifest.clientModules).length} modules)`);
|
|
457
|
+
}
|
|
458
|
+
const serverManifest = (0, server_manifest_1.generateServerManifest)(cwd, appDir);
|
|
459
|
+
fs_1.default.writeFileSync(path_1.default.join(vistaDirs.server, 'server-manifest.json'), JSON.stringify(serverManifest, null, 2));
|
|
460
|
+
if (_debug) {
|
|
461
|
+
console.log(` ✓ server-manifest.json (${Object.keys(serverManifest.serverModules).length} modules, ${serverManifest.routes.length} routes)`);
|
|
462
|
+
console.log('');
|
|
463
|
+
}
|
|
464
|
+
(0, manifest_1.writeCanonicalVistaArtifacts)(cwd, vistaDirs.root, buildId, serverManifest.routes.map((route) => ({
|
|
465
|
+
pattern: route.pattern,
|
|
466
|
+
pagePath: route.pagePath,
|
|
467
|
+
type: route.type,
|
|
468
|
+
})), serverManifest.routeHandlers.map((handler) => ({
|
|
469
|
+
pattern: handler.pattern,
|
|
470
|
+
filePath: handler.filePath,
|
|
471
|
+
type: handler.type,
|
|
472
|
+
methods: handler.methods,
|
|
473
|
+
runtime: handler.runtime,
|
|
474
|
+
})));
|
|
475
|
+
(0, manifest_1.writeReservedVistaArtifacts)(vistaDirs.root, {
|
|
476
|
+
buildId,
|
|
477
|
+
engineVariant,
|
|
478
|
+
imagesConfig: vistaConfig.images,
|
|
479
|
+
});
|
|
480
|
+
// Generate client entry
|
|
481
|
+
generateRSCClientEntry(cwd, vistaDirs.root, watch);
|
|
482
|
+
// Create webpack configs
|
|
483
|
+
const options = {
|
|
484
|
+
cwd,
|
|
485
|
+
isDev: watch,
|
|
486
|
+
vistaDirs,
|
|
487
|
+
buildId,
|
|
488
|
+
engineVariant,
|
|
489
|
+
clientReferenceFiles,
|
|
490
|
+
};
|
|
491
|
+
// Build CSS
|
|
492
|
+
runPostCSS(cwd, vistaDirs.root);
|
|
493
|
+
if (watch) {
|
|
494
|
+
// Development mode - return compilers for middleware
|
|
495
|
+
if (_debug)
|
|
496
|
+
console.log('[Vista JS RSC] Creating development compilers...');
|
|
497
|
+
// Clear stale webpack cache. ReactFlightWebpackPlugin adds
|
|
498
|
+
// AsyncDependenciesBlock entries that can't be serialised by webpack's
|
|
499
|
+
// pack file cache strategy. A stale cache that was written *before* the
|
|
500
|
+
// plugin ran will skip the parser hook entirely, causing empty Flight
|
|
501
|
+
// manifests. Clearing on every dev-start is the safest approach –
|
|
502
|
+
// first-compile is ~1s longer but guarantees correct manifests.
|
|
503
|
+
const cacheDir = engineVariant === 'flashpack'
|
|
504
|
+
? path_1.default.join(cwd, constants_1.FLASH_DIR, 'cache', 'webpack')
|
|
505
|
+
: path_1.default.join(vistaDirs.root, 'cache');
|
|
506
|
+
if (fs_1.default.existsSync(cacheDir)) {
|
|
507
|
+
fs_1.default.rmSync(cacheDir, { recursive: true, force: true });
|
|
508
|
+
if (_debug)
|
|
509
|
+
console.log('[Vista JS RSC] Cleared stale webpack cache');
|
|
510
|
+
}
|
|
511
|
+
// Write stub Flight manifests so upstream can start before first webpack compile.
|
|
512
|
+
// ReactFlightWebpackPlugin will overwrite these on first successful compilation.
|
|
513
|
+
const stubManifests = [
|
|
514
|
+
path_1.default.join(vistaDirs.root, 'react-client-manifest.json'),
|
|
515
|
+
path_1.default.join(vistaDirs.root, 'react-server-manifest.json'),
|
|
516
|
+
path_1.default.join(vistaDirs.root, 'react-ssr-manifest.json'),
|
|
517
|
+
];
|
|
518
|
+
for (const manifestPath of stubManifests) {
|
|
519
|
+
if (!fs_1.default.existsSync(manifestPath)) {
|
|
520
|
+
fs_1.default.writeFileSync(manifestPath, '{}');
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
const clientConfig = (0, compiler_1.createClientWebpackConfig)(options);
|
|
524
|
+
const clientCompiler = (0, webpack_1.default)(clientConfig);
|
|
525
|
+
syncReactServerManifests(vistaDirs.root);
|
|
526
|
+
// Watch for CSS + source changes that can affect Tailwind output.
|
|
527
|
+
try {
|
|
528
|
+
const chokidar = require('chokidar');
|
|
529
|
+
const styleWatchRoots = ['app', 'components', 'content', 'lib', 'ctx', 'data', 'utils', 'src']
|
|
530
|
+
.map((entry) => path_1.default.join(cwd, entry))
|
|
531
|
+
.filter((entry) => fs_1.default.existsSync(entry));
|
|
532
|
+
let cssTimer = null;
|
|
533
|
+
const scheduleCSSBuild = () => {
|
|
534
|
+
if (cssTimer)
|
|
535
|
+
clearTimeout(cssTimer);
|
|
536
|
+
cssTimer = setTimeout(() => {
|
|
537
|
+
if (_debug)
|
|
538
|
+
console.log('[Vista JS RSC] Style source changed, rebuilding CSS...');
|
|
539
|
+
runPostCSS(cwd, vistaDirs.root);
|
|
540
|
+
}, 120);
|
|
541
|
+
};
|
|
542
|
+
chokidar
|
|
543
|
+
.watch(styleWatchRoots, {
|
|
544
|
+
ignoreInitial: true,
|
|
545
|
+
ignored: (watchedPath) => watchedPath.includes(`${path_1.default.sep}node_modules${path_1.default.sep}`) ||
|
|
546
|
+
watchedPath.includes(`${path_1.default.sep}.git${path_1.default.sep}`) ||
|
|
547
|
+
watchedPath.includes(`${path_1.default.sep}.vista${path_1.default.sep}`),
|
|
548
|
+
})
|
|
549
|
+
.on('all', (_event, changedPath) => {
|
|
550
|
+
if (/\.(?:css|[cm]?[jt]sx?|md|mdx)$/i.test(changedPath)) {
|
|
551
|
+
scheduleCSSBuild();
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
catch (e) {
|
|
556
|
+
// chokidar not installed
|
|
557
|
+
}
|
|
558
|
+
if (_debug) {
|
|
559
|
+
console.log('[Vista JS RSC] Ready for development');
|
|
560
|
+
console.log('');
|
|
561
|
+
}
|
|
562
|
+
return { serverCompiler: null, clientCompiler };
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
// Production build
|
|
566
|
+
console.log('[Vista JS RSC] Building for production...');
|
|
567
|
+
console.log('');
|
|
568
|
+
const serverConfig = (0, compiler_1.createServerWebpackConfig)(options);
|
|
569
|
+
const clientConfig = (0, compiler_1.createClientWebpackConfig)(options);
|
|
570
|
+
// Build server bundle
|
|
571
|
+
console.log('[Vista JS RSC] Building server bundle...');
|
|
572
|
+
await new Promise((resolve, reject) => {
|
|
573
|
+
(0, webpack_1.default)(serverConfig).run((err, stats) => {
|
|
574
|
+
if (err) {
|
|
575
|
+
console.error('[Vista RSC] Server build error:', err);
|
|
576
|
+
reject(err);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (stats?.hasErrors()) {
|
|
580
|
+
console.error('[Vista RSC] Server compilation errors:', stats.toString('errors-only'));
|
|
581
|
+
reject(new Error('Server compilation failed'));
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
console.log('[Vista JS RSC] Server bundle complete');
|
|
585
|
+
resolve();
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
// Build client bundle
|
|
589
|
+
console.log('[Vista JS RSC] Building client bundle...');
|
|
590
|
+
await new Promise((resolve, reject) => {
|
|
591
|
+
(0, webpack_1.default)(clientConfig).run((err, stats) => {
|
|
592
|
+
if (err) {
|
|
593
|
+
console.error('[Vista RSC] Client build error:', err);
|
|
594
|
+
reject(err);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (stats?.hasErrors()) {
|
|
598
|
+
console.error('[Vista RSC] Client compilation errors:', stats.toString('errors-only'));
|
|
599
|
+
reject(new Error('Client compilation failed'));
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
console.log('[Vista JS RSC] Client bundle complete');
|
|
603
|
+
console.log(stats?.toString('minimal'));
|
|
604
|
+
syncReactServerManifests(vistaDirs.root);
|
|
605
|
+
resolve();
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
// ------------------------------------------------------------------
|
|
609
|
+
// Static Generation (SSG / ISR)
|
|
610
|
+
// ------------------------------------------------------------------
|
|
611
|
+
console.log('[Vista JS RSC] Running static generation...');
|
|
612
|
+
const ssgResult = await (0, static_generator_1.generateStaticPages)({
|
|
613
|
+
cwd,
|
|
614
|
+
vistaDirRoot: vistaDirs.root,
|
|
615
|
+
manifest: serverManifest,
|
|
616
|
+
isDev: false,
|
|
617
|
+
buildId,
|
|
618
|
+
});
|
|
619
|
+
if (ssgResult.pagesGenerated > 0) {
|
|
620
|
+
console.log(`[Vista JS RSC] Pre-rendered ${ssgResult.pagesGenerated} page(s): ${ssgResult.generatedPaths.join(', ')}`);
|
|
621
|
+
}
|
|
622
|
+
if (ssgResult.failedPaths.length > 0) {
|
|
623
|
+
console.warn(`[Vista JS RSC] Failed to pre-render ${ssgResult.failedPaths.length} page(s):`, ssgResult.failedPaths.map((f) => `${f.path} (${f.error})`).join(', '));
|
|
624
|
+
}
|
|
625
|
+
// Write the real prerender manifest (overwrite the empty stub)
|
|
626
|
+
const prerenderManifestPath = path_1.default.join(vistaDirs.root, 'prerender-manifest.json');
|
|
627
|
+
fs_1.default.writeFileSync(prerenderManifestPath, JSON.stringify(ssgResult.manifest, null, 2));
|
|
628
|
+
console.log('[Vista JS RSC] Wrote prerender-manifest.json');
|
|
629
|
+
(0, standalone_1.generateStandaloneOutput)({
|
|
630
|
+
cwd,
|
|
631
|
+
vistaDir: vistaDirs.root,
|
|
632
|
+
buildId,
|
|
633
|
+
serverManifest,
|
|
634
|
+
debug: _debug,
|
|
635
|
+
});
|
|
636
|
+
(0, deploy_output_1.generateDeploymentOutputs)({
|
|
637
|
+
cwd,
|
|
638
|
+
vistaDir: vistaDirs.root,
|
|
639
|
+
debug: _debug,
|
|
640
|
+
});
|
|
641
|
+
(0, manifest_1.pruneEmptyVistaDirectories)(vistaDirs.root);
|
|
642
|
+
console.log('');
|
|
643
|
+
console.log('╔══════════════════════════════════════════════════════════════╗');
|
|
644
|
+
console.log('║ Build Complete! 🎉 ║');
|
|
645
|
+
console.log('╚══════════════════════════════════════════════════════════════╝');
|
|
646
|
+
console.log('');
|
|
647
|
+
console.log(' Output directory: .vista/');
|
|
648
|
+
console.log(' ├── server/ (Server-side bundle - NEVER sent to client)');
|
|
649
|
+
console.log(' ├── static/ (Client assets - only client components)');
|
|
650
|
+
if (engineVariant === 'flashpack') {
|
|
651
|
+
console.log(' └── cache/ (metadata bridge to the active Flashpack cache)');
|
|
652
|
+
console.log(' Flashpack directory: .flash/');
|
|
653
|
+
console.log(' ├── cache/ (Flashpack runtime cache)');
|
|
654
|
+
console.log(' ├── graph/ (Rust pipeline graph snapshots)');
|
|
655
|
+
console.log(' └── logs/ (Flashpack phase logs)');
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
658
|
+
console.log(' └── cache/ (Build cache for faster rebuilds)');
|
|
659
|
+
}
|
|
660
|
+
console.log('');
|
|
661
|
+
return { serverCompiler: null, clientCompiler: null };
|
|
662
|
+
}
|
|
663
|
+
}
|