@vistagenic/vista 0.1.0-alpha.1
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 +98 -0
- package/dist/auth/index.d.ts +8 -0
- package/dist/auth/index.js +16 -0
- package/dist/bin/build-rsc.d.ts +17 -0
- package/dist/bin/build-rsc.js +320 -0
- package/dist/bin/build.d.ts +4 -0
- package/dist/bin/build.js +336 -0
- package/dist/bin/file-scanner.d.ts +66 -0
- package/dist/bin/file-scanner.js +399 -0
- package/dist/bin/server-component-plugin.d.ts +17 -0
- package/dist/bin/server-component-plugin.js +133 -0
- package/dist/bin/webpack.config.d.ts +6 -0
- package/dist/bin/webpack.config.js +138 -0
- package/dist/build/manifest.d.ts +95 -0
- package/dist/build/manifest.js +168 -0
- package/dist/build/rsc/client-manifest.d.ts +48 -0
- package/dist/build/rsc/client-manifest.js +191 -0
- package/dist/build/rsc/client-reference-plugin.d.ts +37 -0
- package/dist/build/rsc/client-reference-plugin.js +185 -0
- package/dist/build/rsc/compiler.d.ts +36 -0
- package/dist/build/rsc/compiler.js +311 -0
- package/dist/build/rsc/index.d.ts +16 -0
- package/dist/build/rsc/index.js +32 -0
- package/dist/build/rsc/native-scanner.d.ts +123 -0
- package/dist/build/rsc/native-scanner.js +165 -0
- package/dist/build/rsc/rsc-renderer.d.ts +99 -0
- package/dist/build/rsc/rsc-renderer.js +269 -0
- package/dist/build/rsc/server-component-loader.d.ts +19 -0
- package/dist/build/rsc/server-component-loader.js +147 -0
- package/dist/build/rsc/server-manifest.d.ts +63 -0
- package/dist/build/rsc/server-manifest.js +268 -0
- package/dist/build/webpack/loaders/vista-flight-loader.d.ts +17 -0
- package/dist/build/webpack/loaders/vista-flight-loader.js +93 -0
- package/dist/build/webpack/plugins/vista-flight-plugin.d.ts +36 -0
- package/dist/build/webpack/plugins/vista-flight-plugin.js +133 -0
- package/dist/client/dynamic.d.ts +25 -0
- package/dist/client/dynamic.js +68 -0
- package/dist/client/font.d.ts +98 -0
- package/dist/client/font.js +109 -0
- package/dist/client/head.d.ts +79 -0
- package/dist/client/head.js +261 -0
- package/dist/client/hydration.d.ts +45 -0
- package/dist/client/hydration.js +291 -0
- package/dist/client/link.d.ts +30 -0
- package/dist/client/link.js +188 -0
- package/dist/client/navigation.d.ts +28 -0
- package/dist/client/navigation.js +116 -0
- package/dist/client/router.d.ts +41 -0
- package/dist/client/router.js +190 -0
- package/dist/client/script.d.ts +51 -0
- package/dist/client/script.js +118 -0
- package/dist/components/client-island.d.ts +34 -0
- package/dist/components/client-island.js +75 -0
- package/dist/components/client.d.ts +29 -0
- package/dist/components/client.js +102 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +8 -0
- package/dist/components/link.d.ts +6 -0
- package/dist/components/link.js +13 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.js +31 -0
- package/dist/dev-error.d.ts +35 -0
- package/dist/dev-error.js +310 -0
- package/dist/image/get-img-props.d.ts +28 -0
- package/dist/image/get-img-props.js +49 -0
- package/dist/image/image-config.d.ts +20 -0
- package/dist/image/image-config.js +20 -0
- package/dist/image/image-loader.d.ts +7 -0
- package/dist/image/image-loader.js +14 -0
- package/dist/image/index.d.ts +6 -0
- package/dist/image/index.js +110 -0
- package/dist/image.d.ts +10 -0
- package/dist/image.js +7 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +53 -0
- package/dist/metadata/generate.d.ts +22 -0
- package/dist/metadata/generate.js +324 -0
- package/dist/metadata/index.d.ts +7 -0
- package/dist/metadata/index.js +26 -0
- package/dist/metadata/types.d.ts +325 -0
- package/dist/metadata/types.js +15 -0
- package/dist/router/context.d.ts +8 -0
- package/dist/router/context.js +13 -0
- package/dist/router/index.d.ts +2 -0
- package/dist/router/index.js +18 -0
- package/dist/router/provider.d.ts +5 -0
- package/dist/router/provider.js +31 -0
- package/dist/server/client-boundary.d.ts +48 -0
- package/dist/server/client-boundary.js +133 -0
- package/dist/server/engine.d.ts +4 -0
- package/dist/server/engine.js +651 -0
- package/dist/server/index.d.ts +95 -0
- package/dist/server/index.js +177 -0
- package/dist/server/rsc-engine.d.ts +20 -0
- package/dist/server/rsc-engine.js +588 -0
- package/dist/server/rsc-module-system.d.ts +33 -0
- package/dist/server/rsc-module-system.js +119 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +2 -0
- package/package.json +103 -0
package/bin/vista.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const command = process.argv[2];
|
|
4
|
+
const flags = process.argv.slice(3);
|
|
5
|
+
|
|
6
|
+
// Check for RSC mode flag
|
|
7
|
+
const useRSC = flags.includes('--rsc') || process.env.VISTA_RSC === 'true';
|
|
8
|
+
|
|
9
|
+
if (command === 'dev') {
|
|
10
|
+
if (useRSC) {
|
|
11
|
+
// RSC Mode - True React Server Components Architecture
|
|
12
|
+
console.log('');
|
|
13
|
+
console.log('🚀 Starting Vista in RSC mode (React Server Components)');
|
|
14
|
+
console.log('');
|
|
15
|
+
|
|
16
|
+
const { buildRSC } = require('../dist/bin/build-rsc');
|
|
17
|
+
const { startRSCServer } = require('../dist/server/rsc-engine');
|
|
18
|
+
|
|
19
|
+
buildRSC(true)
|
|
20
|
+
.then(({ clientCompiler }) => {
|
|
21
|
+
startRSCServer({
|
|
22
|
+
port: process.env.PORT || 3003,
|
|
23
|
+
compiler: clientCompiler,
|
|
24
|
+
});
|
|
25
|
+
})
|
|
26
|
+
.catch((err) => {
|
|
27
|
+
console.error('RSC Build failed:', err);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
// Legacy Mode
|
|
32
|
+
const { startServer } = require('../dist/server/engine');
|
|
33
|
+
const { buildClient } = require('../dist/bin/build');
|
|
34
|
+
|
|
35
|
+
buildClient(true)
|
|
36
|
+
.then((compiler) => {
|
|
37
|
+
startServer(process.env.PORT || 3003, compiler);
|
|
38
|
+
})
|
|
39
|
+
.catch((err) => {
|
|
40
|
+
console.error('Build failed:', err);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
} else if (command === 'build') {
|
|
45
|
+
if (useRSC) {
|
|
46
|
+
// RSC Production Build
|
|
47
|
+
const { buildRSC } = require('../dist/bin/build-rsc');
|
|
48
|
+
|
|
49
|
+
buildRSC(false)
|
|
50
|
+
.then(() => {
|
|
51
|
+
console.log('');
|
|
52
|
+
console.log('✅ RSC Production build complete!');
|
|
53
|
+
})
|
|
54
|
+
.catch((err) => {
|
|
55
|
+
console.error('RSC Build failed:', err);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
// Legacy Build
|
|
60
|
+
const { buildClient } = require('../dist/bin/build');
|
|
61
|
+
|
|
62
|
+
buildClient(false)
|
|
63
|
+
.then(() => {
|
|
64
|
+
console.log('Production build complete!');
|
|
65
|
+
})
|
|
66
|
+
.catch((err) => {
|
|
67
|
+
console.error('Build failed:', err);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
} else if (command === 'start') {
|
|
72
|
+
if (useRSC) {
|
|
73
|
+
const { startRSCServer } = require('../dist/server/rsc-engine');
|
|
74
|
+
startRSCServer({ port: process.env.PORT || 3003 });
|
|
75
|
+
} else {
|
|
76
|
+
const { startServer } = require('../dist/server/engine');
|
|
77
|
+
startServer(process.env.PORT || 3003);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
console.log('');
|
|
81
|
+
console.log('Vista Framework CLI');
|
|
82
|
+
console.log('');
|
|
83
|
+
console.log('Usage: vista <command> [options]');
|
|
84
|
+
console.log('');
|
|
85
|
+
console.log('Commands:');
|
|
86
|
+
console.log(' dev Start development server with HMR');
|
|
87
|
+
console.log(' build Create production build');
|
|
88
|
+
console.log(' start Start production server');
|
|
89
|
+
console.log('');
|
|
90
|
+
console.log('Options:');
|
|
91
|
+
console.log(' --rsc Enable React Server Components mode');
|
|
92
|
+
console.log('');
|
|
93
|
+
console.log('Examples:');
|
|
94
|
+
console.log(' vista dev # Start dev server (legacy mode)');
|
|
95
|
+
console.log(' vista dev --rsc # Start dev server with RSC');
|
|
96
|
+
console.log(' vista build --rsc # Production build with RSC');
|
|
97
|
+
console.log('');
|
|
98
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAuth = void 0;
|
|
4
|
+
exports.AuthProvider = AuthProvider;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const AuthContext = (0, react_1.createContext)({ user: null, login: () => { } });
|
|
8
|
+
function AuthProvider({ children }) {
|
|
9
|
+
const [user, setUser] = (0, react_1.useState)(null);
|
|
10
|
+
const login = () => {
|
|
11
|
+
setUser({ name: "Vista User" });
|
|
12
|
+
};
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)(AuthContext.Provider, { value: { user, login }, children: children }));
|
|
14
|
+
}
|
|
15
|
+
const useAuth = () => (0, react_1.useContext)(AuthContext);
|
|
16
|
+
exports.useAuth = useAuth;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vista RSC Build System
|
|
3
|
+
*
|
|
4
|
+
* Builds the application using the True RSC Architecture:
|
|
5
|
+
* 1. Server bundle (.vista/server/) - All code for SSR
|
|
6
|
+
* 2. Client bundle (.vista/static/) - Only client components
|
|
7
|
+
* 3. Manifests for hydration coordination
|
|
8
|
+
*/
|
|
9
|
+
import webpack from 'webpack';
|
|
10
|
+
/**
|
|
11
|
+
* Build with RSC architecture
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildRSC(watch?: boolean): Promise<{
|
|
14
|
+
serverCompiler: webpack.Compiler | null;
|
|
15
|
+
clientCompiler: webpack.Compiler | null;
|
|
16
|
+
}>;
|
|
17
|
+
export { buildRSC as default };
|
|
@@ -0,0 +1,320 @@
|
|
|
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
|
+
/**
|
|
25
|
+
* Run PostCSS for CSS compilation
|
|
26
|
+
*/
|
|
27
|
+
function runPostCSS(cwd, vistaDir) {
|
|
28
|
+
const globalsCss = path_1.default.join(cwd, 'app/globals.css');
|
|
29
|
+
if (fs_1.default.existsSync(globalsCss)) {
|
|
30
|
+
console.log('[Vista RSC] Building CSS with PostCSS...');
|
|
31
|
+
const { execSync } = require('child_process');
|
|
32
|
+
try {
|
|
33
|
+
const cssOut = path_1.default.join(vistaDir, 'client.css');
|
|
34
|
+
execSync(`npx postcss app/globals.css -o "${cssOut}"`, { stdio: 'inherit', cwd });
|
|
35
|
+
console.log('[Vista RSC] CSS Built Successfully!');
|
|
36
|
+
}
|
|
37
|
+
catch (cssErr) {
|
|
38
|
+
console.error('[Vista RSC] CSS Build failed (PostCSS error).');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Generate the RSC-aware client entry file
|
|
44
|
+
*/
|
|
45
|
+
function generateRSCClientEntry(cwd, vistaDir) {
|
|
46
|
+
const clientManifestPath = path_1.default.join(vistaDir, 'client-manifest.json');
|
|
47
|
+
let clientImports = '';
|
|
48
|
+
let clientComponents = '{}';
|
|
49
|
+
if (fs_1.default.existsSync(clientManifestPath)) {
|
|
50
|
+
const manifest = JSON.parse(fs_1.default.readFileSync(clientManifestPath, 'utf-8'));
|
|
51
|
+
// Generate imports for all client components
|
|
52
|
+
const imports = [];
|
|
53
|
+
const components = [];
|
|
54
|
+
Object.values(manifest.clientModules).forEach((entry, index) => {
|
|
55
|
+
const varName = `ClientComponent_${index}`;
|
|
56
|
+
const relativePath = './' + path_1.default.relative(vistaDir, entry.absolutePath).replace(/\\/g, '/');
|
|
57
|
+
imports.push(`import ${varName} from '${relativePath}';`);
|
|
58
|
+
components.push(`'${entry.id}': ${varName}`);
|
|
59
|
+
});
|
|
60
|
+
clientImports = imports.join('\n');
|
|
61
|
+
clientComponents = `{\n ${components.join(',\n ')}\n}`;
|
|
62
|
+
}
|
|
63
|
+
const clientEntryContent = `/**
|
|
64
|
+
* Vista RSC Client Entry
|
|
65
|
+
*
|
|
66
|
+
* This file is auto-generated. Do not edit directly.
|
|
67
|
+
* It handles selective hydration of client components.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
import * as React from 'react';
|
|
71
|
+
import { createRoot } from 'react-dom/client';
|
|
72
|
+
|
|
73
|
+
// Import all client components
|
|
74
|
+
${clientImports}
|
|
75
|
+
|
|
76
|
+
// Client component registry
|
|
77
|
+
const clientComponents = ${clientComponents};
|
|
78
|
+
|
|
79
|
+
// Hydration logic
|
|
80
|
+
interface ClientReference {
|
|
81
|
+
id: string;
|
|
82
|
+
mountId: string;
|
|
83
|
+
props: Record<string, any>;
|
|
84
|
+
chunkUrl: string;
|
|
85
|
+
exportName: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function deserializeProps(props: Record<string, any>): Record<string, any> {
|
|
89
|
+
const result: Record<string, any> = {};
|
|
90
|
+
for (const [key, value] of Object.entries(props)) {
|
|
91
|
+
if (value && typeof value === 'object' && value.__type) {
|
|
92
|
+
switch (value.__type) {
|
|
93
|
+
case 'Date':
|
|
94
|
+
result[key] = new Date(value.value);
|
|
95
|
+
break;
|
|
96
|
+
case 'undefined':
|
|
97
|
+
result[key] = undefined;
|
|
98
|
+
break;
|
|
99
|
+
default:
|
|
100
|
+
result[key] = value;
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
result[key] = value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function hydrateClientComponents() {
|
|
110
|
+
const references: ClientReference[] = (window as any).__VISTA_CLIENT_REFERENCES__ || [];
|
|
111
|
+
|
|
112
|
+
console.log('[Vista RSC] Hydrating', references.length, 'client component(s)');
|
|
113
|
+
|
|
114
|
+
for (const ref of references) {
|
|
115
|
+
try {
|
|
116
|
+
const mountPoint = document.getElementById(ref.mountId);
|
|
117
|
+
if (!mountPoint) {
|
|
118
|
+
console.warn('[Vista RSC] Mount point not found:', ref.mountId);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Get component from registry
|
|
123
|
+
let Component = clientComponents[ref.id];
|
|
124
|
+
|
|
125
|
+
if (!Component) {
|
|
126
|
+
// Try dynamic import
|
|
127
|
+
try {
|
|
128
|
+
const module = await import(/* webpackIgnore: true */ ref.chunkUrl);
|
|
129
|
+
Component = module[ref.exportName] || module.default;
|
|
130
|
+
} catch (e) {
|
|
131
|
+
console.error('[Vista RSC] Failed to load component:', ref.id, e);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (!Component) {
|
|
137
|
+
console.error('[Vista RSC] Component not found:', ref.id);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const props = deserializeProps(ref.props);
|
|
142
|
+
|
|
143
|
+
// Use createRoot since we render a placeholder on server
|
|
144
|
+
const root = createRoot(mountPoint);
|
|
145
|
+
root.render(React.createElement(Component, props));
|
|
146
|
+
|
|
147
|
+
mountPoint.setAttribute('data-hydrated', 'true');
|
|
148
|
+
|
|
149
|
+
} catch (e) {
|
|
150
|
+
console.error('[Vista RSC] Hydration error:', ref.id, e);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Initialize
|
|
156
|
+
if (document.readyState === 'loading') {
|
|
157
|
+
document.addEventListener('DOMContentLoaded', hydrateClientComponents);
|
|
158
|
+
} else {
|
|
159
|
+
hydrateClientComponents();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// HMR Support
|
|
163
|
+
if ((module as any).hot) {
|
|
164
|
+
(module as any).hot.accept();
|
|
165
|
+
}
|
|
166
|
+
`;
|
|
167
|
+
fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'rsc-client.tsx'), clientEntryContent);
|
|
168
|
+
console.log('[Vista RSC] Generated client entry file');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Build with RSC architecture
|
|
172
|
+
*/
|
|
173
|
+
async function buildRSC(watch = false) {
|
|
174
|
+
const cwd = process.cwd();
|
|
175
|
+
const appDir = path_1.default.join(cwd, 'app');
|
|
176
|
+
console.log('');
|
|
177
|
+
console.log('╔══════════════════════════════════════════════════════════════╗');
|
|
178
|
+
console.log('║ Vista RSC Build System (React Server Components) ║');
|
|
179
|
+
console.log('╚══════════════════════════════════════════════════════════════╝');
|
|
180
|
+
console.log('');
|
|
181
|
+
// Create .vista directory structure
|
|
182
|
+
const vistaDirs = (0, manifest_1.createVistaDirectories)(cwd);
|
|
183
|
+
const buildId = (0, manifest_1.getBuildId)(vistaDirs.root, !watch);
|
|
184
|
+
console.log(`[Vista RSC] Build ID: ${buildId}`);
|
|
185
|
+
console.log(`[Vista RSC] Mode: ${watch ? 'Development (Watch)' : 'Production'}`);
|
|
186
|
+
console.log('');
|
|
187
|
+
// Scan app directory
|
|
188
|
+
if (fs_1.default.existsSync(appDir)) {
|
|
189
|
+
console.log(`[Vista RSC] Using ${(0, file_scanner_1.isNativeAvailable)() ? 'Rust native' : 'JS fallback'} scanner (v${(0, file_scanner_1.getVersion)()})`);
|
|
190
|
+
const scanResult = (0, file_scanner_1.scanAppDirectory)(appDir);
|
|
191
|
+
console.log(`[Vista RSC] Found ${scanResult.serverComponents.length} server components`);
|
|
192
|
+
console.log(`[Vista RSC] Found ${scanResult.clientComponents.length} client components ('client load')`);
|
|
193
|
+
console.log('');
|
|
194
|
+
// List client components
|
|
195
|
+
if (scanResult.clientComponents.length > 0) {
|
|
196
|
+
console.log('[Vista RSC] Client Components (will be hydrated on browser):');
|
|
197
|
+
scanResult.clientComponents.forEach((c) => {
|
|
198
|
+
console.log(` ✓ ${c.relativePath}`);
|
|
199
|
+
});
|
|
200
|
+
console.log('');
|
|
201
|
+
}
|
|
202
|
+
// List server components (first few)
|
|
203
|
+
if (scanResult.serverComponents.length > 0) {
|
|
204
|
+
console.log('[Vista RSC] Server Components (0kb client bundle contribution):');
|
|
205
|
+
scanResult.serverComponents.slice(0, 5).forEach((c) => {
|
|
206
|
+
console.log(` • ${c.relativePath}`);
|
|
207
|
+
});
|
|
208
|
+
if (scanResult.serverComponents.length > 5) {
|
|
209
|
+
console.log(` ... and ${scanResult.serverComponents.length - 5} more`);
|
|
210
|
+
}
|
|
211
|
+
console.log('');
|
|
212
|
+
}
|
|
213
|
+
// Check for errors (using client hooks without 'client load')
|
|
214
|
+
if (scanResult.errors.length > 0) {
|
|
215
|
+
console.log('\x1b[41m\x1b[37m ERROR \x1b[0m \x1b[31mServer Component Violations\x1b[0m');
|
|
216
|
+
console.log('');
|
|
217
|
+
for (const error of scanResult.errors) {
|
|
218
|
+
console.log(`\x1b[31m✗\x1b[0m ${error.file}`);
|
|
219
|
+
console.log(` Using: \x1b[33m${error.hooks.slice(0, 3).join(', ')}\x1b[0m in a Server Component`);
|
|
220
|
+
console.log('');
|
|
221
|
+
console.log(` \x1b[36mTo fix:\x1b[0m Add \x1b[33m'client load'\x1b[0m at the top of the file`);
|
|
222
|
+
console.log('');
|
|
223
|
+
}
|
|
224
|
+
if (!watch) {
|
|
225
|
+
console.log('\x1b[31mBuild failed due to Server Component violations.\x1b[0m');
|
|
226
|
+
process.exit(1);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// Generate manifests
|
|
231
|
+
console.log('[Vista RSC] Generating manifests...');
|
|
232
|
+
const clientManifest = (0, client_manifest_1.generateClientManifest)(cwd, appDir);
|
|
233
|
+
fs_1.default.writeFileSync(path_1.default.join(vistaDirs.root, 'client-manifest.json'), JSON.stringify(clientManifest, null, 2));
|
|
234
|
+
console.log(` ✓ client-manifest.json (${Object.keys(clientManifest.clientModules).length} modules)`);
|
|
235
|
+
const serverManifest = (0, server_manifest_1.generateServerManifest)(cwd, appDir);
|
|
236
|
+
fs_1.default.writeFileSync(path_1.default.join(vistaDirs.server, 'server-manifest.json'), JSON.stringify(serverManifest, null, 2));
|
|
237
|
+
console.log(` ✓ server-manifest.json (${Object.keys(serverManifest.serverModules).length} modules, ${serverManifest.routes.length} routes)`);
|
|
238
|
+
console.log('');
|
|
239
|
+
// Generate client entry
|
|
240
|
+
generateRSCClientEntry(cwd, vistaDirs.root);
|
|
241
|
+
// Create webpack configs
|
|
242
|
+
const options = { cwd, isDev: watch, vistaDirs, buildId };
|
|
243
|
+
// Build CSS
|
|
244
|
+
runPostCSS(cwd, vistaDirs.root);
|
|
245
|
+
if (watch) {
|
|
246
|
+
// Development mode - return compilers for middleware
|
|
247
|
+
console.log('[Vista RSC] Creating development compilers...');
|
|
248
|
+
const clientConfig = (0, compiler_1.createClientWebpackConfig)(options);
|
|
249
|
+
const clientCompiler = (0, webpack_1.default)(clientConfig);
|
|
250
|
+
// Watch for CSS changes
|
|
251
|
+
try {
|
|
252
|
+
const chokidar = require('chokidar');
|
|
253
|
+
chokidar.watch(path_1.default.join(cwd, 'app/**/*.css'), { ignoreInitial: true }).on('change', () => {
|
|
254
|
+
console.log('[Vista RSC] CSS changed, rebuilding...');
|
|
255
|
+
runPostCSS(cwd, vistaDirs.root);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
// chokidar not installed
|
|
260
|
+
}
|
|
261
|
+
console.log('[Vista RSC] Ready for development');
|
|
262
|
+
console.log('');
|
|
263
|
+
return { serverCompiler: null, clientCompiler };
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
// Production build
|
|
267
|
+
console.log('[Vista RSC] Building for production...');
|
|
268
|
+
console.log('');
|
|
269
|
+
const serverConfig = (0, compiler_1.createServerWebpackConfig)(options);
|
|
270
|
+
const clientConfig = (0, compiler_1.createClientWebpackConfig)(options);
|
|
271
|
+
// Build server bundle
|
|
272
|
+
console.log('[Vista RSC] Building server bundle...');
|
|
273
|
+
await new Promise((resolve, reject) => {
|
|
274
|
+
(0, webpack_1.default)(serverConfig).run((err, stats) => {
|
|
275
|
+
if (err) {
|
|
276
|
+
console.error('[Vista RSC] Server build error:', err);
|
|
277
|
+
reject(err);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (stats?.hasErrors()) {
|
|
281
|
+
console.error('[Vista RSC] Server compilation errors:', stats.toString('errors-only'));
|
|
282
|
+
reject(new Error('Server compilation failed'));
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
console.log('[Vista RSC] Server bundle complete');
|
|
286
|
+
resolve();
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
// Build client bundle
|
|
290
|
+
console.log('[Vista RSC] Building client bundle...');
|
|
291
|
+
await new Promise((resolve, reject) => {
|
|
292
|
+
(0, webpack_1.default)(clientConfig).run((err, stats) => {
|
|
293
|
+
if (err) {
|
|
294
|
+
console.error('[Vista RSC] Client build error:', err);
|
|
295
|
+
reject(err);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (stats?.hasErrors()) {
|
|
299
|
+
console.error('[Vista RSC] Client compilation errors:', stats.toString('errors-only'));
|
|
300
|
+
reject(new Error('Client compilation failed'));
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
console.log('[Vista RSC] Client bundle complete');
|
|
304
|
+
console.log(stats?.toString('minimal'));
|
|
305
|
+
resolve();
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
console.log('');
|
|
309
|
+
console.log('╔══════════════════════════════════════════════════════════════╗');
|
|
310
|
+
console.log('║ Build Complete! 🎉 ║');
|
|
311
|
+
console.log('╚══════════════════════════════════════════════════════════════╝');
|
|
312
|
+
console.log('');
|
|
313
|
+
console.log(' Output directory: .vista/');
|
|
314
|
+
console.log(' ├── server/ (Server-side bundle - NEVER sent to client)');
|
|
315
|
+
console.log(' ├── static/ (Client assets - only client components)');
|
|
316
|
+
console.log(' └── cache/ (Build cache for faster rebuilds)');
|
|
317
|
+
console.log('');
|
|
318
|
+
return { serverCompiler: null, clientCompiler: null };
|
|
319
|
+
}
|
|
320
|
+
}
|