@vistagenic/vista 0.3.0 → 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.
Files changed (101) hide show
  1. package/bin/vista.js +79 -109
  2. package/dist/ai/embeddings.d.ts +11 -11
  3. package/dist/ai/embeddings.js +71 -71
  4. package/dist/ai/index.d.ts +10 -10
  5. package/dist/ai/index.js +26 -26
  6. package/dist/ai/providers/base.js +85 -85
  7. package/dist/ai/react/react-server.d.ts +1 -1
  8. package/dist/ai/react/react-server.js +17 -17
  9. package/dist/ai/react/use-agent.js +138 -138
  10. package/dist/auth/core.d.ts +140 -140
  11. package/dist/auth/core.js +165 -165
  12. package/dist/auth/index.d.ts +20 -20
  13. package/dist/auth/index.js +369 -369
  14. package/dist/auth/react-server.d.ts +1 -1
  15. package/dist/auth/react-server.js +10 -10
  16. package/dist/auth/react.d.ts +18 -18
  17. package/dist/auth/react.js +71 -71
  18. package/dist/bin/build-rsc-flashpack.js +6 -0
  19. package/dist/bin/build-rsc.js +537 -492
  20. package/dist/bin/build.js +355 -353
  21. package/dist/bin/dev-error-overlay-snippet.js +379 -153
  22. package/dist/bin/generate.js +513 -510
  23. package/dist/bin/webpack.config.js +4 -3
  24. package/dist/build/manifest.d.ts +169 -169
  25. package/dist/build/manifest.js +423 -423
  26. package/dist/build/rsc/client-manifest.d.ts +62 -62
  27. package/dist/build/rsc/client-manifest.js +295 -295
  28. package/dist/build/rsc/compiler.js +5 -4
  29. package/dist/build/rsc/native-scanner.d.ts +135 -135
  30. package/dist/build/rsc/native-scanner.js +203 -203
  31. package/dist/build/rsc/react-client-reference-manifest.d.ts +28 -28
  32. package/dist/build/rsc/react-client-reference-manifest.js +240 -240
  33. package/dist/build/standalone.js +260 -254
  34. package/dist/client/dynamic.react-server.d.ts +2 -2
  35. package/dist/client/dynamic.react-server.js +23 -23
  36. package/dist/client/link.react-server.d.ts +2 -2
  37. package/dist/client/link.react-server.js +11 -11
  38. package/dist/client/navigation.react-server.d.ts +1 -1
  39. package/dist/client/navigation.react-server.js +17 -17
  40. package/dist/client/router.react-server.d.ts +1 -1
  41. package/dist/client/router.react-server.js +17 -17
  42. package/dist/client/rsc-router.react-server.d.ts +1 -1
  43. package/dist/client/rsc-router.react-server.js +17 -17
  44. package/dist/client/script.react-server.d.ts +2 -2
  45. package/dist/client/script.react-server.js +23 -23
  46. package/dist/config.d.ts +1 -1
  47. package/dist/config.js +1 -7
  48. package/dist/deploy/adapters/cloudflare.js +43 -19
  49. package/dist/deploy/adapters/docker.d.ts +1 -0
  50. package/dist/deploy/adapters/docker.js +5 -4
  51. package/dist/deploy/adapters/netlify.js +62 -17
  52. package/dist/deploy/adapters/vercel.js +80 -50
  53. package/dist/deploy/preflight.js +4 -3
  54. package/dist/deploy/runtime-pack.d.ts +11 -0
  55. package/dist/deploy/runtime-pack.js +300 -0
  56. package/dist/deploy/utils.d.ts +1 -1
  57. package/dist/deploy/utils.js +31 -2
  58. package/dist/dev-error.d.ts +14 -0
  59. package/dist/dev-error.js +1394 -336
  60. package/dist/flashpack/command.js +1 -0
  61. package/dist/flashpack/runtime.js +2 -1
  62. package/dist/index.d.ts +23 -23
  63. package/dist/index.js +61 -61
  64. package/dist/server/app-dir.d.ts +22 -0
  65. package/dist/server/app-dir.js +77 -0
  66. package/dist/server/cookie-parse.d.ts +4 -4
  67. package/dist/server/cookie-parse.js +14 -14
  68. package/dist/server/engine.js +6 -12
  69. package/dist/server/image-optimizer.js +2 -1
  70. package/dist/server/index.d.ts +109 -109
  71. package/dist/server/index.js +315 -315
  72. package/dist/server/middleware-runner.d.ts +125 -125
  73. package/dist/server/middleware-runner.js +607 -615
  74. package/dist/server/middleware-security.d.ts +36 -36
  75. package/dist/server/middleware-security.js +183 -183
  76. package/dist/server/module-compile-hook.js +695 -695
  77. package/dist/server/root-resolver.js +6 -5
  78. package/dist/server/rsc-engine-flashpack.d.ts +3 -1
  79. package/dist/server/rsc-engine-flashpack.js +12 -1
  80. package/dist/server/rsc-engine.d.ts +6 -1
  81. package/dist/server/rsc-engine.js +203 -229
  82. package/dist/server/rsc-upstream.js +893 -892
  83. package/dist/server/static-generator.js +4 -3
  84. package/dist/server/structure-validator.js +2 -1
  85. package/dist/server/structure-watch.js +2 -0
  86. package/dist/server/typed-api-runtime.js +639 -635
  87. package/dist/server/vista-import-map.js +134 -134
  88. package/dist/stack/index.d.ts +34 -34
  89. package/dist/stack/index.js +49 -49
  90. package/dist/stack/server/caller.d.ts +13 -13
  91. package/dist/stack/server/caller.js +42 -42
  92. package/dist/stack/server/executor.d.ts +40 -40
  93. package/dist/stack/server/executor.js +222 -222
  94. package/dist/stack/server/index.d.ts +11 -11
  95. package/dist/stack/server/index.js +24 -24
  96. package/dist/stack/server/procedure.d.ts +20 -20
  97. package/dist/stack/server/procedure.js +66 -66
  98. package/dist/stack/server/types.d.ts +113 -113
  99. package/dist/theme/react-server.d.ts +10 -10
  100. package/dist/theme/react-server.js +16 -16
  101. package/package.json +178 -178
package/dist/bin/build.js CHANGED
@@ -1,151 +1,153 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.compiler = void 0;
7
- exports.buildClient = buildClient;
8
- const path_1 = __importDefault(require("path"));
9
- const fs_1 = __importDefault(require("fs"));
10
- const webpack_1 = __importDefault(require("webpack"));
11
- const webpack_config_1 = require("./webpack.config");
12
- const file_scanner_1 = require("./file-scanner");
13
- const manifest_1 = require("../build/manifest");
14
- const config_1 = require("../config");
15
- const constants_1 = require("../constants");
16
- const structure_validator_1 = require("../server/structure-validator");
17
- const structure_log_1 = require("../server/structure-log");
18
- const devtools_indicator_snippet_1 = require("./devtools-indicator-snippet");
19
- const dev_error_overlay_snippet_1 = require("./dev-error-overlay-snippet");
20
- const deploy_output_1 = require("./deploy-output");
21
- const module_boundary_validator_1 = require("../server/module-boundary-validator");
22
- const client_manifest_1 = require("../build/rsc/client-manifest");
23
- const _debug = !!process.env.VISTA_DEBUG;
24
- // Helper to run PostCSS
25
- function runPostCSS(cwd, vistaDir) {
26
- const globalsCss = path_1.default.join(cwd, 'app/globals.css');
27
- if (fs_1.default.existsSync(globalsCss)) {
28
- if (_debug)
29
- console.log('Building CSS with PostCSS...');
30
- const { execSync } = require('child_process');
31
- try {
32
- const cssOut = path_1.default.join(vistaDir, 'client.css');
33
- execSync(`npx postcss app/globals.css -o "${cssOut}"`, {
34
- stdio: _debug ? 'inherit' : 'pipe',
35
- cwd,
36
- });
37
- if (_debug)
38
- console.log('CSS Built Successfully!');
39
- }
40
- catch (cssErr) {
41
- console.error('CSS Build failed (PostCSS error).');
42
- }
43
- }
44
- }
45
- function collectRouteArtifactEntries(node, segments = [], entries = []) {
46
- const nextSegments = [...segments];
47
- if (node.segment) {
48
- if (node.kind === 'dynamic') {
49
- nextSegments.push(`:${node.segment}`);
50
- }
51
- else if (node.kind === 'catch-all') {
52
- nextSegments.push(`:${node.segment}*`);
53
- }
54
- else if (node.kind !== 'group') {
55
- nextSegments.push(node.segment);
56
- }
57
- }
58
- if (node.indexPath) {
59
- const pattern = nextSegments.length === 0 ? '/' : `/${nextSegments.join('/')}`;
60
- const type = pattern.includes('*')
61
- ? 'catch-all'
62
- : pattern.includes(':')
63
- ? 'dynamic'
64
- : 'static';
65
- entries.push({
66
- pattern,
67
- pagePath: String(node.indexPath),
68
- type,
69
- });
70
- }
71
- if (Array.isArray(node.children)) {
72
- node.children.forEach((child) => collectRouteArtifactEntries(child, nextSegments, entries));
73
- }
74
- return entries;
75
- }
76
- // Generate Client Entry File - TRUE RSC
77
- // Only imports components with 'use client' directive
78
- function generateClientEntry(cwd, vistaDir, clientComponents, isDev = false) {
79
- const devToolsBootId = `legacy-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
80
- const appDir = path_1.default.join(cwd, 'app');
81
- // Generate imports ONLY for client components
82
- const clientImports = [];
83
- const clientRegistrations = [];
84
- clientComponents.forEach((comp, index) => {
85
- const relativePath = './' + path_1.default.relative(vistaDir, comp.absolutePath).replace(/\\/g, '/');
86
- const componentName = `ClientComponent_${index}`;
87
- const componentId = comp.relativePath.replace(/\\/g, '/').replace(/\.(tsx|ts|jsx|js)$/, '');
88
- // Extract just the component name (e.g., "Navbar" from "components/Navbar")
89
- const baseName = path_1.default.basename(comp.relativePath).replace(/\.(tsx|ts|jsx|js)$/, '');
90
- const lowercaseName = baseName.toLowerCase();
91
- clientImports.push(`import ${componentName} from "${relativePath}";`);
92
- // Register by full path (for standard RSC)
93
- clientRegistrations.push(` "${componentId}": ${componentName},`);
94
- // Also register by lowercase name (for <Client> wrapper compatibility)
95
- clientRegistrations.push(` "${lowercaseName}": ${componentName},`);
96
- });
97
- // Get Route Tree from Rust (but DON'T bundle server components)
98
- const { getRouteTree } = require('./file-scanner');
99
- let routeTree;
100
- try {
101
- routeTree = getRouteTree(appDir);
102
- }
103
- catch (e) {
104
- console.error('Failed to generate route tree:', e);
105
- process.exit(1);
106
- }
107
- // For RSC, we only serialize the STRUCTURE, not the components
108
- // Components are loaded separately
109
- function serializeRouteStructure(node) {
110
- const props = [];
111
- props.push(`segment: "${node.segment}"`);
112
- props.push(`kind: "${node.kind}"`);
113
- // Store paths as strings, NOT require() - server renders these
114
- if (node.indexPath) {
115
- const componentId = path_1.default
116
- .relative(appDir, node.indexPath)
117
- .replace(/\\/g, '/')
118
- .replace(/\.(tsx|ts|jsx|js)$/, '');
119
- props.push(`indexId: "${componentId}"`);
120
- }
121
- if (node.layoutPath) {
122
- const componentId = path_1.default
123
- .relative(appDir, node.layoutPath)
124
- .replace(/\\/g, '/')
125
- .replace(/\.(tsx|ts|jsx|js)$/, '');
126
- props.push(`layoutId: "${componentId}"`);
127
- }
128
- if (node.loadingPath) {
129
- const componentId = path_1.default
130
- .relative(appDir, node.loadingPath)
131
- .replace(/\\/g, '/')
132
- .replace(/\.(tsx|ts|jsx|js)$/, '');
133
- props.push(`loadingId: "${componentId}"`);
134
- }
135
- if (node.children && node.children.length > 0) {
136
- const childrenStr = node.children
137
- .map((child) => serializeRouteStructure(child))
138
- .join(',\n');
139
- props.push(`children: [\n${childrenStr}\n]`);
140
- }
141
- else {
142
- props.push(`children: []`);
143
- }
144
- return `{\n${props.join(',\n')}\n}`;
145
- }
146
- const routeStructure = serializeRouteStructure(routeTree);
147
- // TRUE RSC CLIENT ENTRY
148
- // Only client components are imported here
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.compiler = void 0;
7
+ exports.buildClient = buildClient;
8
+ const path_1 = __importDefault(require("path"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const webpack_1 = __importDefault(require("webpack"));
11
+ const webpack_config_1 = require("./webpack.config");
12
+ const file_scanner_1 = require("./file-scanner");
13
+ const manifest_1 = require("../build/manifest");
14
+ const config_1 = require("../config");
15
+ const constants_1 = require("../constants");
16
+ const structure_validator_1 = require("../server/structure-validator");
17
+ const structure_log_1 = require("../server/structure-log");
18
+ const devtools_indicator_snippet_1 = require("./devtools-indicator-snippet");
19
+ const dev_error_overlay_snippet_1 = require("./dev-error-overlay-snippet");
20
+ const deploy_output_1 = require("./deploy-output");
21
+ const module_boundary_validator_1 = require("../server/module-boundary-validator");
22
+ const client_manifest_1 = require("../build/rsc/client-manifest");
23
+ const app_dir_1 = require("../server/app-dir");
24
+ const _debug = !!process.env.VISTA_DEBUG;
25
+ // Helper to run PostCSS
26
+ function runPostCSS(cwd, vistaDir) {
27
+ const globalsCss = path_1.default.join((0, app_dir_1.resolveAppDir)(cwd), 'globals.css');
28
+ if (fs_1.default.existsSync(globalsCss)) {
29
+ if (_debug)
30
+ console.log('Building CSS with PostCSS...');
31
+ const { execSync } = require('child_process');
32
+ try {
33
+ const cssOut = path_1.default.join(vistaDir, 'client.css');
34
+ const globalsCssRelative = path_1.default.relative(cwd, globalsCss).replace(/\\/g, '/');
35
+ execSync(`npx postcss "${globalsCssRelative}" -o "${cssOut}"`, {
36
+ stdio: _debug ? 'inherit' : 'pipe',
37
+ cwd,
38
+ });
39
+ if (_debug)
40
+ console.log('CSS Built Successfully!');
41
+ }
42
+ catch (cssErr) {
43
+ console.error('CSS Build failed (PostCSS error).');
44
+ }
45
+ }
46
+ }
47
+ function collectRouteArtifactEntries(node, segments = [], entries = []) {
48
+ const nextSegments = [...segments];
49
+ if (node.segment) {
50
+ if (node.kind === 'dynamic') {
51
+ nextSegments.push(`:${node.segment}`);
52
+ }
53
+ else if (node.kind === 'catch-all') {
54
+ nextSegments.push(`:${node.segment}*`);
55
+ }
56
+ else if (node.kind !== 'group') {
57
+ nextSegments.push(node.segment);
58
+ }
59
+ }
60
+ if (node.indexPath) {
61
+ const pattern = nextSegments.length === 0 ? '/' : `/${nextSegments.join('/')}`;
62
+ const type = pattern.includes('*')
63
+ ? 'catch-all'
64
+ : pattern.includes(':')
65
+ ? 'dynamic'
66
+ : 'static';
67
+ entries.push({
68
+ pattern,
69
+ pagePath: String(node.indexPath),
70
+ type,
71
+ });
72
+ }
73
+ if (Array.isArray(node.children)) {
74
+ node.children.forEach((child) => collectRouteArtifactEntries(child, nextSegments, entries));
75
+ }
76
+ return entries;
77
+ }
78
+ // Generate Client Entry File - TRUE RSC
79
+ // Only imports components with 'use client' directive
80
+ function generateClientEntry(cwd, vistaDir, clientComponents, isDev = false) {
81
+ const devToolsBootId = `legacy-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
82
+ const appDir = (0, app_dir_1.resolveAppDir)(cwd);
83
+ // Generate imports ONLY for client components
84
+ const clientImports = [];
85
+ const clientRegistrations = [];
86
+ clientComponents.forEach((comp, index) => {
87
+ const relativePath = './' + path_1.default.relative(vistaDir, comp.absolutePath).replace(/\\/g, '/');
88
+ const componentName = `ClientComponent_${index}`;
89
+ const componentId = comp.relativePath.replace(/\\/g, '/').replace(/\.(tsx|ts|jsx|js)$/, '');
90
+ // Extract just the component name (e.g., "Navbar" from "components/Navbar")
91
+ const baseName = path_1.default.basename(comp.relativePath).replace(/\.(tsx|ts|jsx|js)$/, '');
92
+ const lowercaseName = baseName.toLowerCase();
93
+ clientImports.push(`import ${componentName} from "${relativePath}";`);
94
+ // Register by full path (for standard RSC)
95
+ clientRegistrations.push(` "${componentId}": ${componentName},`);
96
+ // Also register by lowercase name (for <Client> wrapper compatibility)
97
+ clientRegistrations.push(` "${lowercaseName}": ${componentName},`);
98
+ });
99
+ // Get Route Tree from Rust (but DON'T bundle server components)
100
+ const { getRouteTree } = require('./file-scanner');
101
+ let routeTree;
102
+ try {
103
+ routeTree = getRouteTree(appDir);
104
+ }
105
+ catch (e) {
106
+ console.error('Failed to generate route tree:', e);
107
+ process.exit(1);
108
+ }
109
+ // For RSC, we only serialize the STRUCTURE, not the components
110
+ // Components are loaded separately
111
+ function serializeRouteStructure(node) {
112
+ const props = [];
113
+ props.push(`segment: "${node.segment}"`);
114
+ props.push(`kind: "${node.kind}"`);
115
+ // Store paths as strings, NOT require() - server renders these
116
+ if (node.indexPath) {
117
+ const componentId = path_1.default
118
+ .relative(appDir, node.indexPath)
119
+ .replace(/\\/g, '/')
120
+ .replace(/\.(tsx|ts|jsx|js)$/, '');
121
+ props.push(`indexId: "${componentId}"`);
122
+ }
123
+ if (node.layoutPath) {
124
+ const componentId = path_1.default
125
+ .relative(appDir, node.layoutPath)
126
+ .replace(/\\/g, '/')
127
+ .replace(/\.(tsx|ts|jsx|js)$/, '');
128
+ props.push(`layoutId: "${componentId}"`);
129
+ }
130
+ if (node.loadingPath) {
131
+ const componentId = path_1.default
132
+ .relative(appDir, node.loadingPath)
133
+ .replace(/\\/g, '/')
134
+ .replace(/\.(tsx|ts|jsx|js)$/, '');
135
+ props.push(`loadingId: "${componentId}"`);
136
+ }
137
+ if (node.children && node.children.length > 0) {
138
+ const childrenStr = node.children
139
+ .map((child) => serializeRouteStructure(child))
140
+ .join(',\n');
141
+ props.push(`children: [\n${childrenStr}\n]`);
142
+ }
143
+ else {
144
+ props.push(`children: []`);
145
+ }
146
+ return `{\n${props.join(',\n')}\n}`;
147
+ }
148
+ const routeStructure = serializeRouteStructure(routeTree);
149
+ // TRUE RSC CLIENT ENTRY
150
+ // Only client components are imported here
149
151
  const clientEntryContent = `
150
152
  // Vista Client Entry - TRUE RSC
151
153
  // Only client components are bundled here
@@ -207,7 +209,7 @@ if ((module as any).hot) {
207
209
  }
208
210
 
209
211
  // Server-Side Live Reload (for server component changes)
210
- ${isDev
212
+ ${isDev
211
213
  ? `
212
214
  ${(0, devtools_indicator_snippet_1.getDevToolsIndicatorBootstrapSource)(devToolsBootId)}
213
215
  ${(0, dev_error_overlay_snippet_1.getDevErrorOverlayBootstrapSource)()}
@@ -249,211 +251,211 @@ sse.onmessage = (event) => {
249
251
  sse.onerror = (e) => {
250
252
  console.log('[Vista] SSE connection lost');
251
253
  };
252
- `
254
+ `
253
255
  : '// SSE reload disabled in production'}
254
256
 
255
257
  // Export for debugging
256
258
  (window as any).${constants_1.CLIENT_COMPONENTS_FLAG} = CLIENT_COMPONENTS;
257
- `;
258
- fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'client.tsx'), clientEntryContent);
259
- if (_debug) {
260
- console.log(`[Vista JS RSC] Generated client entry with ${clientComponents.length} client component(s)`);
261
- }
262
- }
263
- // Webpack Compiler Instance (reused for watch mode)
264
- let compiler = null;
265
- exports.compiler = compiler;
266
- async function buildClient(watch = false, onRebuild) {
267
- const cwd = process.cwd();
268
- const vistaDirs = (0, manifest_1.createVistaDirectories)(cwd);
269
- const vistaDir = vistaDirs.root;
270
- const buildId = (0, manifest_1.getBuildId)(vistaDir, !watch);
271
- if (_debug)
272
- console.log(`Building Client (Watch Mode: ${watch}, Bundler: Webpack + SWC)...`);
273
- // ========================================================================
274
- // Pre-build Structure Validation
275
- // ========================================================================
276
- const vistaConfig = (0, config_1.loadConfig)(cwd);
277
- const engineVariant = (0, config_1.resolveAndApplyEngineVariant)(vistaConfig);
278
- const structureConfig = (0, config_1.resolveStructureValidationConfig)(vistaConfig);
279
- const cacheComponentsConfig = (0, config_1.resolveCacheComponentsConfig)(vistaConfig);
280
- if (_debug)
281
- console.log(`[vista:build] Engine variant: ${engineVariant}`);
282
- if (structureConfig.enabled) {
283
- const result = (0, structure_validator_1.validateAppStructure)({ cwd });
284
- (0, structure_log_1.logValidationResult)(result, structureConfig.logLevel);
285
- if (result.state === 'error' && structureConfig.mode === 'strict') {
286
- console.error((0, structure_log_1.formatBuildFailTable)(result));
287
- process.exit(1);
288
- }
289
- // Warnings: continue build, already logged above.
290
- }
291
- // Scan app directory using Rust bindings to get client components
292
- const appDir = path_1.default.join(cwd, 'app');
293
- const additionalClientRoots = (0, client_manifest_1.discoverProjectClientRoots)(cwd).filter((root) => path_1.default.resolve(root.dir) !== path_1.default.resolve(appDir));
294
- let clientComponents = [];
295
- if (fs_1.default.existsSync(appDir)) {
296
- if (_debug) {
297
- console.log(`[Vista JS] Using ${(0, file_scanner_1.isNativeAvailable)() ? 'Rust native' : 'JS fallback'} scanner (v${(0, file_scanner_1.getVersion)()})`);
298
- }
299
- const scanResult = (0, file_scanner_1.scanAppDirectory)(appDir);
300
- if (_debug) {
301
- console.log(`[Vista JS] Found ${scanResult.clientComponents.length} client components, ${scanResult.serverComponents.length} server components in app/`);
302
- }
303
- // Store client components for entry generation
304
- clientComponents = scanResult.clientComponents.map((c) => ({
305
- relativePath: c.relativePath,
306
- absolutePath: c.absolutePath,
307
- }));
308
- // Log client components
309
- if (scanResult.clientComponents.length > 0 && _debug) {
310
- console.log(`[Vista JS] Client components ('use client') from app/:`);
311
- scanResult.clientComponents.forEach((c) => {
312
- console.log(` - ${c.relativePath}`);
313
- });
314
- }
315
- const moduleBoundaryIssues = (0, module_boundary_validator_1.validateModuleBoundaries)({
316
- appDir,
317
- extraRoots: additionalClientRoots.map((root) => root.dir),
318
- cacheComponentsEnabled: cacheComponentsConfig.enabled,
319
- }).issues;
320
- if (moduleBoundaryIssues.length > 0) {
321
- console.log('');
322
- console.log('\x1b[41m\x1b[37m ERROR \x1b[0m \x1b[31mServer/Segment Validation Error\x1b[0m');
323
- console.log('');
324
- for (const issue of moduleBoundaryIssues) {
325
- console.log(`\x1b[31m✗\x1b[0m ${path_1.default.relative(cwd, issue.filePath)}`);
326
- console.log(` ${issue.message}`);
327
- console.log('');
328
- if (issue.fix) {
329
- console.log(` \x1b[36mTo fix:\x1b[0m ${issue.fix}`);
330
- console.log('');
331
- }
332
- }
333
- if (!watch) {
334
- console.log('\x1b[31mBuild failed due to server/segment violations.\x1b[0m');
335
- process.exit(1);
336
- }
337
- }
338
- }
339
- for (const root of additionalClientRoots) {
340
- if (_debug)
341
- console.log(`[Vista JS] Scanning ${root.prefix} directory...`);
342
- const extraScan = (0, file_scanner_1.scanAppDirectory)(root.dir);
343
- clientComponents = [
344
- ...clientComponents,
345
- ...extraScan.clientComponents.map((c) => ({
346
- relativePath: `${root.prefix}${c.relativePath}`,
347
- absolutePath: c.absolutePath,
348
- })),
349
- ];
350
- if (extraScan.clientComponents.length > 0 && _debug) {
351
- console.log(`[Vista JS] Client components ('use client') from ${root.prefix}:`);
352
- extraScan.clientComponents.forEach((c) => {
353
- console.log(` - ${root.prefix}${c.relativePath}`);
354
- });
355
- }
356
- }
357
- if (_debug)
358
- console.log(`[Vista JS] Total client components: ${clientComponents.length}`);
359
- // Write canonical artifact manifests for legacy mode.
360
- try {
361
- const { getRouteTree } = require('./file-scanner');
362
- const routeTree = getRouteTree(appDir);
363
- const routes = collectRouteArtifactEntries(routeTree);
364
- (0, manifest_1.writeCanonicalVistaArtifacts)(cwd, vistaDir, buildId, routes);
365
- }
366
- catch (error) {
367
- // Keep build behavior resilient in environments where route scan fails.
368
- (0, manifest_1.writeCanonicalVistaArtifacts)(cwd, vistaDir, buildId, []);
369
- console.warn(`[vista:build] Failed to derive route artifacts: ${error.message}`);
370
- }
371
- (0, manifest_1.writeReservedVistaArtifacts)(vistaDir, {
372
- buildId,
373
- engineVariant,
374
- imagesConfig: vistaConfig.images,
375
- });
376
- // Generate client entry - TRUE RSC: only client components
377
- generateClientEntry(cwd, vistaDir, clientComponents, watch);
378
- // Create Webpack config
379
- const config = (0, webpack_config_1.createWebpackConfig)({
380
- cwd,
381
- isDev: watch,
382
- engineVariant,
383
- cacheComponentsEnabled: cacheComponentsConfig.enabled,
384
- });
385
- // Create Webpack compiler
386
- exports.compiler = compiler = (0, webpack_1.default)(config);
387
- if (watch) {
388
- // In watch mode, we return the compiler for use with dev middleware
389
- // Initial CSS build
390
- runPostCSS(cwd, vistaDir);
391
- // Watch CSS + source files that may affect Tailwind output.
392
- const chokidar = require('chokidar');
393
- try {
394
- const styleWatchRoots = ['app', 'components', 'content', 'lib', 'ctx', 'data']
395
- .map((entry) => path_1.default.join(cwd, entry))
396
- .filter((entry) => fs_1.default.existsSync(entry));
397
- let cssTimer = null;
398
- const scheduleCSSBuild = () => {
399
- if (cssTimer)
400
- clearTimeout(cssTimer);
401
- cssTimer = setTimeout(() => {
402
- if (_debug)
403
- console.log('Style source changed, rebuilding CSS...');
404
- runPostCSS(cwd, vistaDir);
405
- }, 120);
406
- };
407
- chokidar
408
- .watch(styleWatchRoots, {
409
- ignoreInitial: true,
410
- ignored: (watchedPath) => watchedPath.includes(`${path_1.default.sep}node_modules${path_1.default.sep}`) ||
411
- watchedPath.includes(`${path_1.default.sep}.git${path_1.default.sep}`) ||
412
- watchedPath.includes(`${path_1.default.sep}.vista${path_1.default.sep}`),
413
- })
414
- .on('all', (_event, changedPath) => {
415
- if (/\.(?:css|[cm]?[jt]sx?|md|mdx)$/i.test(changedPath)) {
416
- scheduleCSSBuild();
417
- }
418
- });
419
- }
420
- catch (e) {
421
- // chokidar not installed, skip CSS watch
422
- }
423
- if (_debug)
424
- console.log('Webpack compiler ready for dev middleware.');
425
- return compiler;
426
- }
427
- else {
428
- // Production build
429
- return new Promise((resolve, reject) => {
430
- compiler.run((err, stats) => {
431
- if (err) {
432
- console.error('Webpack build error:', err);
433
- reject(err);
434
- return;
435
- }
436
- if (stats?.hasErrors()) {
437
- console.error('Webpack compilation errors:', stats.toString('errors-only'));
438
- reject(new Error('Compilation failed'));
439
- return;
440
- }
441
- console.log('Webpack build complete!');
442
- console.log(stats?.toString('minimal'));
443
- // Build CSS
444
- runPostCSS(cwd, vistaDir);
445
- (0, deploy_output_1.generateDeploymentOutputs)({
446
- cwd,
447
- vistaDir,
448
- debug: _debug,
449
- });
450
- (0, manifest_1.pruneEmptyVistaDirectories)(vistaDir);
451
- compiler.close((closeErr) => {
452
- if (closeErr)
453
- console.error('Error closing compiler:', closeErr);
454
- resolve(null);
455
- });
456
- });
457
- });
458
- }
459
- }
259
+ `;
260
+ fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'client.tsx'), clientEntryContent);
261
+ if (_debug) {
262
+ console.log(`[Vista JS RSC] Generated client entry with ${clientComponents.length} client component(s)`);
263
+ }
264
+ }
265
+ // Webpack Compiler Instance (reused for watch mode)
266
+ let compiler = null;
267
+ exports.compiler = compiler;
268
+ async function buildClient(watch = false, onRebuild) {
269
+ const cwd = process.cwd();
270
+ const vistaDirs = (0, manifest_1.createVistaDirectories)(cwd);
271
+ const vistaDir = vistaDirs.root;
272
+ const buildId = (0, manifest_1.getBuildId)(vistaDir, !watch);
273
+ if (_debug)
274
+ console.log(`Building Client (Watch Mode: ${watch}, Bundler: Webpack + SWC)...`);
275
+ // ========================================================================
276
+ // Pre-build Structure Validation
277
+ // ========================================================================
278
+ const vistaConfig = (0, config_1.loadConfig)(cwd);
279
+ const engineVariant = (0, config_1.resolveAndApplyEngineVariant)(vistaConfig);
280
+ const structureConfig = (0, config_1.resolveStructureValidationConfig)(vistaConfig);
281
+ const cacheComponentsConfig = (0, config_1.resolveCacheComponentsConfig)(vistaConfig);
282
+ if (_debug)
283
+ console.log(`[vista:build] Engine variant: ${engineVariant}`);
284
+ if (structureConfig.enabled) {
285
+ const result = (0, structure_validator_1.validateAppStructure)({ cwd });
286
+ (0, structure_log_1.logValidationResult)(result, structureConfig.logLevel);
287
+ if (result.state === 'error' && structureConfig.mode === 'strict') {
288
+ console.error((0, structure_log_1.formatBuildFailTable)(result));
289
+ process.exit(1);
290
+ }
291
+ // Warnings: continue build, already logged above.
292
+ }
293
+ // Scan app directory using Rust bindings to get client components
294
+ const appDir = (0, app_dir_1.resolveAppDir)(cwd);
295
+ const additionalClientRoots = (0, client_manifest_1.discoverProjectClientRoots)(cwd).filter((root) => path_1.default.resolve(root.dir) !== path_1.default.resolve(appDir));
296
+ let clientComponents = [];
297
+ if (fs_1.default.existsSync(appDir)) {
298
+ if (_debug) {
299
+ console.log(`[Vista JS] Using ${(0, file_scanner_1.isNativeAvailable)() ? 'Rust native' : 'JS fallback'} scanner (v${(0, file_scanner_1.getVersion)()})`);
300
+ }
301
+ const scanResult = (0, file_scanner_1.scanAppDirectory)(appDir);
302
+ if (_debug) {
303
+ console.log(`[Vista JS] Found ${scanResult.clientComponents.length} client components, ${scanResult.serverComponents.length} server components in app/`);
304
+ }
305
+ // Store client components for entry generation
306
+ clientComponents = scanResult.clientComponents.map((c) => ({
307
+ relativePath: c.relativePath,
308
+ absolutePath: c.absolutePath,
309
+ }));
310
+ // Log client components
311
+ if (scanResult.clientComponents.length > 0 && _debug) {
312
+ console.log(`[Vista JS] Client components ('use client') from app/:`);
313
+ scanResult.clientComponents.forEach((c) => {
314
+ console.log(` - ${c.relativePath}`);
315
+ });
316
+ }
317
+ const moduleBoundaryIssues = (0, module_boundary_validator_1.validateModuleBoundaries)({
318
+ appDir,
319
+ extraRoots: additionalClientRoots.map((root) => root.dir),
320
+ cacheComponentsEnabled: cacheComponentsConfig.enabled,
321
+ }).issues;
322
+ if (moduleBoundaryIssues.length > 0) {
323
+ console.log('');
324
+ console.log('\x1b[41m\x1b[37m ERROR \x1b[0m \x1b[31mServer/Segment Validation Error\x1b[0m');
325
+ console.log('');
326
+ for (const issue of moduleBoundaryIssues) {
327
+ console.log(`\x1b[31m✗\x1b[0m ${path_1.default.relative(cwd, issue.filePath)}`);
328
+ console.log(` ${issue.message}`);
329
+ console.log('');
330
+ if (issue.fix) {
331
+ console.log(` \x1b[36mTo fix:\x1b[0m ${issue.fix}`);
332
+ console.log('');
333
+ }
334
+ }
335
+ if (!watch) {
336
+ console.log('\x1b[31mBuild failed due to server/segment violations.\x1b[0m');
337
+ process.exit(1);
338
+ }
339
+ }
340
+ }
341
+ for (const root of additionalClientRoots) {
342
+ if (_debug)
343
+ console.log(`[Vista JS] Scanning ${root.prefix} directory...`);
344
+ const extraScan = (0, file_scanner_1.scanAppDirectory)(root.dir);
345
+ clientComponents = [
346
+ ...clientComponents,
347
+ ...extraScan.clientComponents.map((c) => ({
348
+ relativePath: `${root.prefix}${c.relativePath}`,
349
+ absolutePath: c.absolutePath,
350
+ })),
351
+ ];
352
+ if (extraScan.clientComponents.length > 0 && _debug) {
353
+ console.log(`[Vista JS] Client components ('use client') from ${root.prefix}:`);
354
+ extraScan.clientComponents.forEach((c) => {
355
+ console.log(` - ${root.prefix}${c.relativePath}`);
356
+ });
357
+ }
358
+ }
359
+ if (_debug)
360
+ console.log(`[Vista JS] Total client components: ${clientComponents.length}`);
361
+ // Write canonical artifact manifests for legacy mode.
362
+ try {
363
+ const { getRouteTree } = require('./file-scanner');
364
+ const routeTree = getRouteTree(appDir);
365
+ const routes = collectRouteArtifactEntries(routeTree);
366
+ (0, manifest_1.writeCanonicalVistaArtifacts)(cwd, vistaDir, buildId, routes);
367
+ }
368
+ catch (error) {
369
+ // Keep build behavior resilient in environments where route scan fails.
370
+ (0, manifest_1.writeCanonicalVistaArtifacts)(cwd, vistaDir, buildId, []);
371
+ console.warn(`[vista:build] Failed to derive route artifacts: ${error.message}`);
372
+ }
373
+ (0, manifest_1.writeReservedVistaArtifacts)(vistaDir, {
374
+ buildId,
375
+ engineVariant,
376
+ imagesConfig: vistaConfig.images,
377
+ });
378
+ // Generate client entry - TRUE RSC: only client components
379
+ generateClientEntry(cwd, vistaDir, clientComponents, watch);
380
+ // Create Webpack config
381
+ const config = (0, webpack_config_1.createWebpackConfig)({
382
+ cwd,
383
+ isDev: watch,
384
+ engineVariant,
385
+ cacheComponentsEnabled: cacheComponentsConfig.enabled,
386
+ });
387
+ // Create Webpack compiler
388
+ exports.compiler = compiler = (0, webpack_1.default)(config);
389
+ if (watch) {
390
+ // In watch mode, we return the compiler for use with dev middleware
391
+ // Initial CSS build
392
+ runPostCSS(cwd, vistaDir);
393
+ // Watch CSS + source files that may affect Tailwind output.
394
+ const chokidar = require('chokidar');
395
+ try {
396
+ const styleWatchRoots = ['app', 'components', 'content', 'lib', 'ctx', 'data', 'src']
397
+ .map((entry) => path_1.default.join(cwd, entry))
398
+ .filter((entry) => fs_1.default.existsSync(entry));
399
+ let cssTimer = null;
400
+ const scheduleCSSBuild = () => {
401
+ if (cssTimer)
402
+ clearTimeout(cssTimer);
403
+ cssTimer = setTimeout(() => {
404
+ if (_debug)
405
+ console.log('Style source changed, rebuilding CSS...');
406
+ runPostCSS(cwd, vistaDir);
407
+ }, 120);
408
+ };
409
+ chokidar
410
+ .watch(styleWatchRoots, {
411
+ ignoreInitial: true,
412
+ ignored: (watchedPath) => watchedPath.includes(`${path_1.default.sep}node_modules${path_1.default.sep}`) ||
413
+ watchedPath.includes(`${path_1.default.sep}.git${path_1.default.sep}`) ||
414
+ watchedPath.includes(`${path_1.default.sep}.vista${path_1.default.sep}`),
415
+ })
416
+ .on('all', (_event, changedPath) => {
417
+ if (/\.(?:css|[cm]?[jt]sx?|md|mdx)$/i.test(changedPath)) {
418
+ scheduleCSSBuild();
419
+ }
420
+ });
421
+ }
422
+ catch (e) {
423
+ // chokidar not installed, skip CSS watch
424
+ }
425
+ if (_debug)
426
+ console.log('Webpack compiler ready for dev middleware.');
427
+ return compiler;
428
+ }
429
+ else {
430
+ // Production build
431
+ return new Promise((resolve, reject) => {
432
+ compiler.run((err, stats) => {
433
+ if (err) {
434
+ console.error('Webpack build error:', err);
435
+ reject(err);
436
+ return;
437
+ }
438
+ if (stats?.hasErrors()) {
439
+ console.error('Webpack compilation errors:', stats.toString('errors-only'));
440
+ reject(new Error('Compilation failed'));
441
+ return;
442
+ }
443
+ console.log('Webpack build complete!');
444
+ console.log(stats?.toString('minimal'));
445
+ // Build CSS
446
+ runPostCSS(cwd, vistaDir);
447
+ (0, deploy_output_1.generateDeploymentOutputs)({
448
+ cwd,
449
+ vistaDir,
450
+ debug: _debug,
451
+ });
452
+ (0, manifest_1.pruneEmptyVistaDirectories)(vistaDir);
453
+ compiler.close((closeErr) => {
454
+ if (closeErr)
455
+ console.error('Error closing compiler:', closeErr);
456
+ resolve(null);
457
+ });
458
+ });
459
+ });
460
+ }
461
+ }