@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
package/dist/bin/build-rsc.js
CHANGED
|
@@ -1,620 +1,618 @@
|
|
|
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 _debug = !!process.env.VISTA_DEBUG;
|
|
35
|
-
/**
|
|
36
|
-
* Run PostCSS for CSS compilation
|
|
37
|
-
*/
|
|
38
|
-
function runPostCSS(cwd, vistaDir) {
|
|
39
|
-
const globalsCss = path_1.default.join(cwd, 'app/globals.css');
|
|
40
|
-
if (fs_1.default.existsSync(globalsCss)) {
|
|
41
|
-
if (_debug)
|
|
42
|
-
console.log('[Vista JS RSC] Building CSS with PostCSS...');
|
|
43
|
-
const { execSync } = require('child_process');
|
|
44
|
-
try {
|
|
45
|
-
const cssOut = path_1.default.join(vistaDir, 'client.css');
|
|
46
|
-
execSync(`npx postcss app/globals.css -o "${cssOut}"`, {
|
|
47
|
-
stdio: _debug ? 'inherit' : 'pipe',
|
|
48
|
-
cwd,
|
|
49
|
-
});
|
|
50
|
-
if (_debug)
|
|
51
|
-
console.log('[Vista JS RSC] CSS Built Successfully!');
|
|
52
|
-
}
|
|
53
|
-
catch (cssErr) {
|
|
54
|
-
console.error('[Vista JS RSC] CSS Build failed (PostCSS error).');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function hasUseClientDirective(filePath) {
|
|
59
|
-
try {
|
|
60
|
-
const source = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
61
|
-
return /^\s*['"]use client['"]\s*;?/m.test(source);
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function collectUseClientFiles(dir, collected) {
|
|
68
|
-
if (!fs_1.default.existsSync(dir))
|
|
69
|
-
return;
|
|
70
|
-
const entries = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
71
|
-
for (const entry of entries) {
|
|
72
|
-
const absolutePath = path_1.default.join(dir, entry.name);
|
|
73
|
-
if (entry.isDirectory()) {
|
|
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
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*
|
|
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 _debug = !!process.env.VISTA_DEBUG;
|
|
35
|
+
/**
|
|
36
|
+
* Run PostCSS for CSS compilation
|
|
37
|
+
*/
|
|
38
|
+
function runPostCSS(cwd, vistaDir) {
|
|
39
|
+
const globalsCss = path_1.default.join(cwd, 'app/globals.css');
|
|
40
|
+
if (fs_1.default.existsSync(globalsCss)) {
|
|
41
|
+
if (_debug)
|
|
42
|
+
console.log('[Vista JS RSC] Building CSS with PostCSS...');
|
|
43
|
+
const { execSync } = require('child_process');
|
|
44
|
+
try {
|
|
45
|
+
const cssOut = path_1.default.join(vistaDir, 'client.css');
|
|
46
|
+
execSync(`npx postcss app/globals.css -o "${cssOut}"`, {
|
|
47
|
+
stdio: _debug ? 'inherit' : 'pipe',
|
|
48
|
+
cwd,
|
|
49
|
+
});
|
|
50
|
+
if (_debug)
|
|
51
|
+
console.log('[Vista JS RSC] CSS Built Successfully!');
|
|
52
|
+
}
|
|
53
|
+
catch (cssErr) {
|
|
54
|
+
console.error('[Vista JS RSC] CSS Build failed (PostCSS error).');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function hasUseClientDirective(filePath) {
|
|
59
|
+
try {
|
|
60
|
+
const source = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
61
|
+
return /^\s*['"]use client['"]\s*;?/m.test(source);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function collectUseClientFiles(dir, collected) {
|
|
68
|
+
if (!fs_1.default.existsSync(dir))
|
|
69
|
+
return;
|
|
70
|
+
const entries = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
const absolutePath = path_1.default.join(dir, entry.name);
|
|
73
|
+
if (entry.isDirectory()) {
|
|
74
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.'))
|
|
75
|
+
continue;
|
|
76
|
+
collectUseClientFiles(absolutePath, collected);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (!entry.isFile())
|
|
80
|
+
continue;
|
|
81
|
+
const ext = path_1.default.extname(entry.name);
|
|
82
|
+
if (!['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'].includes(ext))
|
|
83
|
+
continue;
|
|
84
|
+
if (hasUseClientDirective(absolutePath)) {
|
|
85
|
+
collected.add(path_1.default.resolve(absolutePath));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function resolvePackageRoot(cwd, packageName) {
|
|
90
|
+
try {
|
|
91
|
+
return path_1.default.dirname(require.resolve(`${packageName}/package.json`, { paths: [cwd] }));
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function collectFrameworkClientReferences(cwd) {
|
|
98
|
+
const roots = [resolvePackageRoot(cwd, 'vista'), resolvePackageRoot(cwd, '@vistagenic/vista')].filter((value) => Boolean(value));
|
|
99
|
+
if (roots.length === 0) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
const collected = new Set();
|
|
103
|
+
for (const packageRoot of roots) {
|
|
104
|
+
collectUseClientFiles(path_1.default.join(packageRoot, 'dist'), collected);
|
|
105
|
+
collectUseClientFiles(path_1.default.join(packageRoot, 'src'), collected);
|
|
106
|
+
}
|
|
107
|
+
return Array.from(collected);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Generate the RSC-aware client entry file
|
|
111
|
+
*/
|
|
112
|
+
function generateRSCClientEntry(cwd, vistaDir, isDev) {
|
|
113
|
+
const devToolsBootId = `rsc-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
114
|
+
const clientEntryContent = `/**
|
|
115
|
+
* Vista RSC Client Entry
|
|
111
116
|
*
|
|
112
117
|
* This file is auto-generated. Do not edit directly.
|
|
113
118
|
* It hydrates using React Flight data from /rsc and enables
|
|
114
119
|
* RSC-aware client-side navigation via RSCRouter.
|
|
115
120
|
*/
|
|
116
121
|
|
|
117
|
-
import * as React from 'react';
|
|
118
|
-
import { hydrateRoot, createRoot } from 'react-dom/client';
|
|
119
|
-
import { createFromFetch } from 'react-server-dom-webpack/client';
|
|
120
|
-
import { RSCRouter } from 'vista/client/rsc-router';
|
|
121
|
-
import { callServer } from 'vista/client/server-actions';
|
|
122
|
+
import * as React from 'react';
|
|
123
|
+
import { hydrateRoot, createRoot } from 'react-dom/client';
|
|
124
|
+
import { createFromFetch } from 'react-server-dom-webpack/client';
|
|
125
|
+
import { RSCRouter } from 'vista/client/rsc-router';
|
|
126
|
+
import { callServer } from 'vista/client/server-actions';
|
|
122
127
|
|
|
123
128
|
const hydrateDocument = (window as any).${constants_1.HYDRATE_DOCUMENT_FLAG} === true;
|
|
124
129
|
const rootElement = hydrateDocument ? document : document.getElementById('root');
|
|
125
|
-
if (!rootElement) {
|
|
126
|
-
throw new Error('Missing #root element for hydration.');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
${isDev ? (0, devtools_indicator_snippet_1.getDevToolsIndicatorBootstrapSource)(devToolsBootId) : ''}
|
|
130
|
-
${isDev ? (0, dev_error_overlay_snippet_1.getDevErrorOverlayBootstrapSource)() : ''}
|
|
131
|
-
|
|
132
|
-
function buildRuntimeMessage(title: string, error: unknown): string {
|
|
133
|
-
var value = error as any;
|
|
134
|
-
var text = '';
|
|
135
|
-
if (value && typeof value === 'object') {
|
|
136
|
-
if (typeof value.message === 'string' && value.message.trim().length > 0) {
|
|
137
|
-
text = value.message;
|
|
138
|
-
}
|
|
139
|
-
if (typeof value.stack === 'string' && value.stack.trim().length > 0) {
|
|
140
|
-
text = text ? text + '\\n\\n' + value.stack : value.stack;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (!text) {
|
|
144
|
-
text = typeof error === 'string' ? error : String(error || 'Unknown runtime error.');
|
|
145
|
-
}
|
|
146
|
-
return title + '\\n\\n' + text;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function reportDevRuntimeError(title: string, error: unknown): void {
|
|
150
|
-
if (typeof window === 'undefined') return;
|
|
151
|
-
var indicator = (window as any).__VISTA_DEVTOOLS_INDICATOR__;
|
|
152
|
-
var overlay = (window as any).__VISTA_DEV_ERROR_OVERLAY__;
|
|
153
|
-
var message = buildRuntimeMessage(title, error);
|
|
154
|
-
var canRestoreFromIndicator = false;
|
|
155
|
-
if (indicator && indicator.hidden !== true && typeof indicator.setError === 'function') {
|
|
156
|
-
canRestoreFromIndicator = true;
|
|
157
|
-
if (typeof indicator.ensureAttached === 'function') {
|
|
158
|
-
try {
|
|
159
|
-
canRestoreFromIndicator = indicator.ensureAttached() !== false;
|
|
160
|
-
} catch {
|
|
161
|
-
canRestoreFromIndicator = false;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (indicator && typeof indicator.setError === 'function') {
|
|
166
|
-
indicator.setError(title, 1);
|
|
167
|
-
}
|
|
168
|
-
if (overlay && typeof overlay.capture === 'function') {
|
|
169
|
-
overlay.capture([message]);
|
|
170
|
-
if (!canRestoreFromIndicator && typeof overlay.show === 'function') {
|
|
171
|
-
overlay.show([message]);
|
|
172
|
-
}
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (overlay && typeof overlay.show === 'function') {
|
|
176
|
-
overlay.show([message]);
|
|
177
|
-
if (typeof overlay.minimize === 'function') {
|
|
178
|
-
overlay.minimize();
|
|
179
|
-
}
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
console.error('[vista] ' + title + ':', error);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (typeof window !== 'undefined') {
|
|
186
|
-
window.addEventListener('error', function (event) {
|
|
187
|
-
var runtimeError = (event as ErrorEvent).error || (event as ErrorEvent).message;
|
|
188
|
-
reportDevRuntimeError('Runtime Error', runtimeError);
|
|
189
|
-
});
|
|
190
|
-
window.addEventListener('unhandledrejection', function (event) {
|
|
191
|
-
reportDevRuntimeError('Unhandled Promise Rejection', (event as PromiseRejectionEvent).reason);
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const pathname = window.location.pathname;
|
|
196
|
-
const search = window.location.search;
|
|
197
|
-
const initialResponse = createFromFetch(
|
|
198
|
-
fetch(\`/rsc\${pathname}\${search}\`, { headers: { Accept: 'text/x-component' } }),
|
|
199
|
-
{ callServer }
|
|
200
|
-
) as Promise<React.ReactNode>;
|
|
201
|
-
|
|
202
|
-
var appElement = React.createElement(RSCRouter, {
|
|
203
|
-
initialResponse,
|
|
204
|
-
initialPathname: pathname,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
try {
|
|
208
|
-
hydrateRoot(
|
|
209
|
-
rootElement as Document | Element,
|
|
210
|
-
appElement,
|
|
211
|
-
{
|
|
212
|
-
onRecoverableError(error) {
|
|
213
|
-
var message = String((error as any)?.message || error || '');
|
|
214
|
-
if (/hydration|did not match|server rendered html|text content/i.test(message)) {
|
|
215
|
-
reportDevRuntimeError('Hydration Error', error);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
reportDevRuntimeError('Recoverable Error', error);
|
|
219
|
-
},
|
|
220
|
-
}
|
|
221
|
-
);
|
|
222
|
-
} catch (error) {
|
|
223
|
-
reportDevRuntimeError('Hydration Error', error);
|
|
224
|
-
if (!hydrateDocument && rootElement instanceof Element) {
|
|
225
|
-
try {
|
|
226
|
-
createRoot(rootElement).render(appElement);
|
|
227
|
-
} catch (fallbackError) {
|
|
228
|
-
reportDevRuntimeError('Client Render Fallback Failed', fallbackError);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
${isDev
|
|
234
|
-
? `// Vista live-reload: listen for server component changes via SSE
|
|
235
|
-
(function connectReload() {
|
|
236
|
-
const es = new EventSource('${constants_1.SSE_ENDPOINT}');
|
|
237
|
-
es.onmessage = (e) => {
|
|
238
|
-
if (e.data === 'reload') {
|
|
239
|
-
const errorOverlay = window.__VISTA_DEV_ERROR_OVERLAY__;
|
|
240
|
-
if (errorOverlay && typeof errorOverlay.clear === 'function') {
|
|
241
|
-
errorOverlay.clear();
|
|
242
|
-
}
|
|
243
|
-
const indicator = window.__VISTA_DEVTOOLS_INDICATOR__;
|
|
244
|
-
if (indicator && typeof indicator.pulse === 'function') {
|
|
245
|
-
indicator.pulse('hmr', 460);
|
|
246
|
-
}
|
|
247
|
-
setTimeout(() => window.location.reload(), 80);
|
|
248
|
-
} else {
|
|
249
|
-
try {
|
|
250
|
-
const msg = JSON.parse(e.data);
|
|
251
|
-
if (msg.type === 'error' || msg.type === 'structure-error') {
|
|
252
|
-
const errorOverlay = window.__VISTA_DEV_ERROR_OVERLAY__;
|
|
253
|
-
if (errorOverlay && typeof errorOverlay.show === 'function') {
|
|
254
|
-
errorOverlay.show(msg.errors || msg.message);
|
|
255
|
-
}
|
|
256
|
-
console.error('[vista] Build error:', msg.message);
|
|
257
|
-
} else if (msg.type === 'ok' || msg.type === 'structure-ok') {
|
|
258
|
-
const errorOverlay = window.__VISTA_DEV_ERROR_OVERLAY__;
|
|
259
|
-
if (errorOverlay && typeof errorOverlay.clear === 'function') {
|
|
260
|
-
errorOverlay.clear();
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
} catch {}
|
|
130
|
+
if (!rootElement) {
|
|
131
|
+
throw new Error('Missing #root element for hydration.');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
${isDev ? (0, devtools_indicator_snippet_1.getDevToolsIndicatorBootstrapSource)(devToolsBootId) : ''}
|
|
135
|
+
${isDev ? (0, dev_error_overlay_snippet_1.getDevErrorOverlayBootstrapSource)() : ''}
|
|
136
|
+
|
|
137
|
+
function buildRuntimeMessage(title: string, error: unknown): string {
|
|
138
|
+
var value = error as any;
|
|
139
|
+
var text = '';
|
|
140
|
+
if (value && typeof value === 'object') {
|
|
141
|
+
if (typeof value.message === 'string' && value.message.trim().length > 0) {
|
|
142
|
+
text = value.message;
|
|
143
|
+
}
|
|
144
|
+
if (typeof value.stack === 'string' && value.stack.trim().length > 0) {
|
|
145
|
+
text = text ? text + '\\n\\n' + value.stack : value.stack;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!text) {
|
|
149
|
+
text = typeof error === 'string' ? error : String(error || 'Unknown runtime error.');
|
|
150
|
+
}
|
|
151
|
+
return title + '\\n\\n' + text;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function reportDevRuntimeError(title: string, error: unknown): void {
|
|
155
|
+
if (typeof window === 'undefined') return;
|
|
156
|
+
var indicator = (window as any).__VISTA_DEVTOOLS_INDICATOR__;
|
|
157
|
+
var overlay = (window as any).__VISTA_DEV_ERROR_OVERLAY__;
|
|
158
|
+
var message = buildRuntimeMessage(title, error);
|
|
159
|
+
var canRestoreFromIndicator = false;
|
|
160
|
+
if (indicator && indicator.hidden !== true && typeof indicator.setError === 'function') {
|
|
161
|
+
canRestoreFromIndicator = true;
|
|
162
|
+
if (typeof indicator.ensureAttached === 'function') {
|
|
163
|
+
try {
|
|
164
|
+
canRestoreFromIndicator = indicator.ensureAttached() !== false;
|
|
165
|
+
} catch {
|
|
166
|
+
canRestoreFromIndicator = false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (indicator && typeof indicator.setError === 'function') {
|
|
171
|
+
indicator.setError(title, 1);
|
|
172
|
+
}
|
|
173
|
+
if (overlay && typeof overlay.capture === 'function') {
|
|
174
|
+
overlay.capture([message]);
|
|
175
|
+
if (!canRestoreFromIndicator && typeof overlay.show === 'function') {
|
|
176
|
+
overlay.show([message]);
|
|
177
|
+
}
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (overlay && typeof overlay.show === 'function') {
|
|
181
|
+
overlay.show([message]);
|
|
182
|
+
if (typeof overlay.minimize === 'function') {
|
|
183
|
+
overlay.minimize();
|
|
184
|
+
}
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
console.error('[vista] ' + title + ':', error);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (typeof window !== 'undefined') {
|
|
191
|
+
window.addEventListener('error', function (event) {
|
|
192
|
+
var runtimeError = (event as ErrorEvent).error || (event as ErrorEvent).message;
|
|
193
|
+
reportDevRuntimeError('Runtime Error', runtimeError);
|
|
194
|
+
});
|
|
195
|
+
window.addEventListener('unhandledrejection', function (event) {
|
|
196
|
+
reportDevRuntimeError('Unhandled Promise Rejection', (event as PromiseRejectionEvent).reason);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
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
|
+
|
|
207
|
+
var appElement = React.createElement(RSCRouter, {
|
|
208
|
+
initialResponse,
|
|
209
|
+
initialPathname: pathname,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
try {
|
|
213
|
+
hydrateRoot(
|
|
214
|
+
rootElement as Document | Element,
|
|
215
|
+
appElement,
|
|
216
|
+
{
|
|
217
|
+
onRecoverableError(error) {
|
|
218
|
+
var message = String((error as any)?.message || error || '');
|
|
219
|
+
if (/hydration|did not match|server rendered html|text content/i.test(message)) {
|
|
220
|
+
reportDevRuntimeError('Hydration Error', error);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
reportDevRuntimeError('Recoverable Error', error);
|
|
224
|
+
},
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
reportDevRuntimeError('Hydration Error', error);
|
|
229
|
+
if (!hydrateDocument && rootElement instanceof Element) {
|
|
230
|
+
try {
|
|
231
|
+
createRoot(rootElement).render(appElement);
|
|
232
|
+
} catch (fallbackError) {
|
|
233
|
+
reportDevRuntimeError('Client Render Fallback Failed', fallbackError);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
${isDev
|
|
239
|
+
? `// Vista live-reload: listen for server component changes via SSE
|
|
240
|
+
(function connectReload() {
|
|
241
|
+
const es = new EventSource('${constants_1.SSE_ENDPOINT}');
|
|
242
|
+
es.onmessage = (e) => {
|
|
243
|
+
if (e.data === 'reload') {
|
|
244
|
+
const errorOverlay = window.__VISTA_DEV_ERROR_OVERLAY__;
|
|
245
|
+
if (errorOverlay && typeof errorOverlay.clear === 'function') {
|
|
246
|
+
errorOverlay.clear();
|
|
247
|
+
}
|
|
248
|
+
const indicator = window.__VISTA_DEVTOOLS_INDICATOR__;
|
|
249
|
+
if (indicator && typeof indicator.pulse === 'function') {
|
|
250
|
+
indicator.pulse('hmr', 460);
|
|
251
|
+
}
|
|
252
|
+
setTimeout(() => window.location.reload(), 80);
|
|
253
|
+
} else {
|
|
254
|
+
try {
|
|
255
|
+
const msg = JSON.parse(e.data);
|
|
256
|
+
if (msg.type === 'error' || msg.type === 'structure-error') {
|
|
257
|
+
const errorOverlay = window.__VISTA_DEV_ERROR_OVERLAY__;
|
|
258
|
+
if (errorOverlay && typeof errorOverlay.show === 'function') {
|
|
259
|
+
errorOverlay.show(msg.errors || msg.message);
|
|
260
|
+
}
|
|
261
|
+
console.error('[vista] Build error:', msg.message);
|
|
262
|
+
} else if (msg.type === 'ok' || msg.type === 'structure-ok') {
|
|
263
|
+
const errorOverlay = window.__VISTA_DEV_ERROR_OVERLAY__;
|
|
264
|
+
if (errorOverlay && typeof errorOverlay.clear === 'function') {
|
|
265
|
+
errorOverlay.clear();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
} catch {}
|
|
264
269
|
}
|
|
265
270
|
};
|
|
266
271
|
es.onerror = () => {
|
|
267
272
|
es.close();
|
|
268
273
|
setTimeout(connectReload, 3000);
|
|
269
274
|
};
|
|
270
|
-
})();`
|
|
275
|
+
})();`
|
|
271
276
|
: '// SSE live-reload disabled in production'}
|
|
272
|
-
`;
|
|
273
|
-
fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'rsc-client.tsx'), clientEntryContent);
|
|
274
|
-
if (_debug)
|
|
275
|
-
console.log('[vista:build] Generated RSC client entry file');
|
|
276
|
-
}
|
|
277
|
-
function syncReactServerManifests(vistaDir) {
|
|
278
|
-
const canonicalPath = path_1.default.join(vistaDir, 'react-server-manifest.json');
|
|
279
|
-
const legacyPath = path_1.default.join(vistaDir, 'react-ssr-manifest.json');
|
|
280
|
-
if (fs_1.default.existsSync(canonicalPath) && !fs_1.default.existsSync(legacyPath)) {
|
|
281
|
-
fs_1.default.copyFileSync(canonicalPath, legacyPath);
|
|
282
|
-
}
|
|
283
|
-
else if (fs_1.default.existsSync(legacyPath) && !fs_1.default.existsSync(canonicalPath)) {
|
|
284
|
-
fs_1.default.copyFileSync(legacyPath, canonicalPath);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Build with RSC architecture
|
|
289
|
-
*/
|
|
290
|
-
async function buildRSC(watch = false) {
|
|
291
|
-
const cwd = process.cwd();
|
|
292
|
-
const appDir = path_1.default.join(cwd, 'app');
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
console.log('
|
|
298
|
-
console.log('
|
|
299
|
-
console.log('
|
|
300
|
-
console.log('');
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
console.log(`[vista:build]
|
|
308
|
-
console.log('');
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
//
|
|
312
|
-
//
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
const
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
(0,
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
348
|
-
console.log(`[Vista JS RSC] Total client reference modules: ${clientReferenceFiles.length}`);
|
|
349
|
-
console.log('');
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
console.log('');
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
console.log('
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
:
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
//
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
.
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
(0,
|
|
587
|
-
cwd,
|
|
588
|
-
vistaDir: vistaDirs.root,
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
(
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
(
|
|
599
|
-
console.log('');
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
console.log(' └── cache/ (
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
else {
|
|
615
|
-
console.log(' └── cache/ (Build cache for faster rebuilds)');
|
|
616
|
-
}
|
|
617
|
-
console.log('');
|
|
618
|
-
return { serverCompiler: null, clientCompiler: null };
|
|
619
|
-
}
|
|
620
|
-
}
|
|
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 = path_1.default.join(cwd, 'app');
|
|
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
|
+
}
|