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