@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
@@ -1,367 +1,423 @@
1
- "use strict";
2
- /**
3
- * Vista Build Utilities
4
- *
5
- * Generates build manifests, BUILD_ID, and manages .vista output structure.
6
- */
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.generateBuildId = generateBuildId;
12
- exports.getBuildId = getBuildId;
13
- exports.createVistaDirectories = createVistaDirectories;
14
- exports.generateBuildManifest = generateBuildManifest;
15
- exports.generateAppPathRoutesManifest = generateAppPathRoutesManifest;
16
- exports.generatePrerenderManifest = generatePrerenderManifest;
17
- exports.generateRequiredServerFilesManifest = generateRequiredServerFilesManifest;
18
- exports.ensureJsonFile = ensureJsonFile;
19
- exports.writeArtifactManifest = writeArtifactManifest;
20
- exports.writeCanonicalVistaArtifacts = writeCanonicalVistaArtifacts;
21
- exports.writeReservedVistaArtifacts = writeReservedVistaArtifacts;
22
- exports.generateRoutesManifest = generateRoutesManifest;
23
- exports.generateClientComponentsManifest = generateClientComponentsManifest;
24
- exports.generateServerComponentsManifest = generateServerComponentsManifest;
25
- exports.getWebpackCacheConfig = getWebpackCacheConfig;
26
- exports.cleanOldCache = cleanOldCache;
27
- exports.pruneEmptyVistaDirectories = pruneEmptyVistaDirectories;
28
- const fs_1 = __importDefault(require("fs"));
29
- const path_1 = __importDefault(require("path"));
30
- const crypto_1 = __importDefault(require("crypto"));
31
- const constants_1 = require("../constants");
32
- const integrity_1 = require("../integrity");
33
- // ============================================================================
34
- // BUILD_ID Generation
35
- // ============================================================================
36
- /**
37
- * Generate a unique build ID based on timestamp and random bytes.
38
- */
39
- function generateBuildId() {
40
- const timestamp = Date.now().toString(36);
41
- const random = crypto_1.default.randomBytes(4).toString('hex');
42
- return `${timestamp}-${random}`;
43
- }
44
- /**
45
- * Read existing BUILD_ID or generate a new one.
46
- */
47
- function getBuildId(vistaDir, forceNew = false) {
48
- const buildIdPath = path_1.default.join(vistaDir, 'BUILD_ID');
49
- if (!forceNew && fs_1.default.existsSync(buildIdPath)) {
50
- return fs_1.default.readFileSync(buildIdPath, 'utf-8').trim();
51
- }
52
- const buildId = generateBuildId();
53
- fs_1.default.mkdirSync(vistaDir, { recursive: true });
54
- fs_1.default.writeFileSync(buildIdPath, buildId);
55
- return buildId;
56
- }
57
- /**
58
- * Create the .vista directory structure.
59
- * In legacy mode, only creates root (no empty server/static dirs).
60
- * In RSC mode, creates the full structure for server/client bundles.
61
- */
62
- function createVistaDirectories(cwd, mode = 'legacy') {
63
- const root = path_1.default.join(cwd, constants_1.BUILD_DIR);
64
- const dirs = {
65
- root,
66
- cache: path_1.default.join(root, 'cache'),
67
- imageCache: path_1.default.join(root, 'cache', 'images'),
68
- server: path_1.default.join(root, 'server'),
69
- static: path_1.default.join(root, 'static'),
70
- chunks: path_1.default.join(root, 'static', 'chunks'),
71
- css: path_1.default.join(root, 'static', 'css'),
72
- media: path_1.default.join(root, 'static', 'media'),
73
- };
74
- // Always create root
75
- fs_1.default.mkdirSync(root, { recursive: true });
76
- if (mode === 'rsc') {
77
- [dirs.root, dirs.cache, dirs.imageCache, dirs.server, dirs.static, dirs.chunks, dirs.media].forEach((dir) => {
78
- fs_1.default.mkdirSync(dir, { recursive: true });
79
- });
80
- }
81
- // Legacy mode: only root dir is created — webpack outputs directly into .vista/
82
- return dirs;
83
- }
84
- /**
85
- * Generate build-manifest.json
86
- */
87
- function generateBuildManifest(vistaDir, buildId, pages = {}) {
88
- const manifest = {
89
- buildId,
90
- polyfillFiles: [],
91
- devFiles: [],
92
- lowPriorityFiles: [],
93
- rootMainFiles: [`${constants_1.STATIC_CHUNKS_PATH}webpack.js`, `${constants_1.STATIC_CHUNKS_PATH}main.js`],
94
- pages,
95
- };
96
- const manifestPath = path_1.default.join(vistaDir, 'build-manifest.json');
97
- fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
98
- return manifest;
99
- }
100
- function toRegexFromPattern(pattern) {
101
- if (pattern === '/') {
102
- return '^/$';
103
- }
104
- const normalized = pattern.startsWith('/') ? pattern.slice(1) : pattern;
105
- const parts = normalized.split('/').filter(Boolean);
106
- const regexParts = parts.map((part) => {
107
- if (!part.startsWith(':')) {
108
- return part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
109
- }
110
- const dynamicMatch = /^:([a-zA-Z0-9_]+)(\*)?(\?)?$/.exec(part);
111
- if (!dynamicMatch) {
112
- return part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
113
- }
114
- const [, paramName, isCatchAll, isOptional] = dynamicMatch;
115
- if (isCatchAll && isOptional) {
116
- return `(?<${paramName}>.*)`;
117
- }
118
- if (isCatchAll) {
119
- return `(?<${paramName}>.+)`;
120
- }
121
- return `(?<${paramName}>[^/]+)`;
122
- });
123
- return `^/${regexParts.join('/')}$`;
124
- }
125
- function toRouteInfo(route) {
126
- return {
127
- page: route.pagePath,
128
- regex: toRegexFromPattern(route.pattern),
129
- routeKeys: {},
130
- namedRegex: toRegexFromPattern(route.pattern),
131
- };
132
- }
133
- function generateAppPathRoutesManifest(vistaDir, routes = []) {
134
- const manifest = {};
135
- routes.forEach((route) => {
136
- manifest[route.pattern] = route.pagePath;
137
- });
138
- fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'app-path-routes-manifest.json'), JSON.stringify(manifest, null, 2));
139
- return manifest;
140
- }
141
- function generatePrerenderManifest(vistaDir) {
142
- const manifest = {
143
- version: 1,
144
- routes: {},
145
- dynamicRoutes: {},
146
- notFoundRoutes: [],
147
- preview: {
148
- previewModeId: '',
149
- previewModeSigningKey: '',
150
- previewModeEncryptionKey: '',
151
- },
152
- };
153
- fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'prerender-manifest.json'), JSON.stringify(manifest, null, 2));
154
- }
155
- function generateRequiredServerFilesManifest(cwd, vistaDir, extraFiles = [], appDir = cwd) {
156
- const files = Array.from(new Set([
157
- `${constants_1.BUILD_DIR}/BUILD_ID`,
158
- `${constants_1.BUILD_DIR}/build-manifest.json`,
159
- `${constants_1.BUILD_DIR}/routes-manifest.json`,
160
- `${constants_1.BUILD_DIR}/app-path-routes-manifest.json`,
161
- `${constants_1.BUILD_DIR}/server/server-manifest.json`,
162
- ...extraFiles,
163
- ]));
164
- const manifest = {
165
- version: 1,
166
- config: {},
167
- appDir,
168
- relativeAppDir: path_1.default.relative(cwd, appDir) || '.',
169
- files,
170
- };
171
- fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'required-server-files.json'), JSON.stringify(manifest, null, 2));
172
- }
173
- function ensureJsonFile(vistaDir, relativePath, fallback = {}) {
174
- const absolutePath = path_1.default.join(vistaDir, relativePath);
175
- if (!fs_1.default.existsSync(absolutePath)) {
176
- fs_1.default.writeFileSync(absolutePath, JSON.stringify(fallback, null, 2));
177
- }
178
- }
179
- function writeArtifactManifest(vistaDir, buildId, extraManifestEntries = {}) {
180
- const artifactManifest = {
181
- schemaVersion: 1,
182
- buildId,
183
- generatedAt: new Date().toISOString(),
184
- __integrity: (0, integrity_1.generateBuildWatermark)(),
185
- manifests: {
186
- buildManifest: 'build-manifest.json',
187
- routesManifest: 'routes-manifest.json',
188
- appPathRoutesManifest: 'app-path-routes-manifest.json',
189
- prerenderManifest: 'prerender-manifest.json',
190
- requiredServerFiles: 'required-server-files.json',
191
- reactClientManifest: 'react-client-manifest.json',
192
- reactServerManifest: 'react-server-manifest.json',
193
- ...extraManifestEntries,
194
- },
195
- };
196
- fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'artifact-manifest.json'), JSON.stringify(artifactManifest, null, 2));
197
- return artifactManifest;
198
- }
199
- function writeCanonicalVistaArtifacts(cwd, vistaDir, buildId, routes = []) {
200
- const staticRoutes = routes.filter((route) => route.type === 'static').map(toRouteInfo);
201
- const dynamicRoutes = routes.filter((route) => route.type !== 'static').map(toRouteInfo);
202
- generateBuildManifest(vistaDir, buildId);
203
- generateRoutesManifest(vistaDir, staticRoutes, dynamicRoutes);
204
- generateAppPathRoutesManifest(vistaDir, routes);
205
- generatePrerenderManifest(vistaDir);
206
- generateRequiredServerFilesManifest(cwd, vistaDir);
207
- // Keep canonical React manifest filenames present for validation consistency.
208
- ensureJsonFile(vistaDir, 'react-client-manifest.json', {});
209
- ensureJsonFile(vistaDir, 'react-server-manifest.json', {});
210
- return writeArtifactManifest(vistaDir, buildId);
211
- }
212
- function writeReservedVistaArtifacts(vistaDir, options) {
213
- const engineVariant = options.engineVariant || 'default';
214
- const generatedAt = new Date().toISOString();
215
- const cacheDir = path_1.default.join(vistaDir, 'cache');
216
- const imageCacheDir = path_1.default.join(cacheDir, 'images');
217
- const mediaDir = path_1.default.join(vistaDir, 'static', 'media');
218
- fs_1.default.mkdirSync(cacheDir, { recursive: true });
219
- fs_1.default.mkdirSync(imageCacheDir, { recursive: true });
220
- fs_1.default.mkdirSync(mediaDir, { recursive: true });
221
- fs_1.default.writeFileSync(path_1.default.join(cacheDir, 'cache-manifest.json'), JSON.stringify({
222
- schemaVersion: 1,
223
- buildId: options.buildId,
224
- generatedAt,
225
- engine: engineVariant,
226
- activeCacheRoot: engineVariant === 'flashpack' ? '.flash/cache' : '.vista/cache/webpack',
227
- directories: {
228
- localCache: '.vista/cache',
229
- webpack: engineVariant === 'flashpack' ? '.flash/cache/webpack' : '.vista/cache/webpack',
230
- images: '.vista/cache/images',
231
- },
232
- notes: [
233
- engineVariant === 'flashpack'
234
- ? 'Flashpack stores its hot build cache in .flash while .vista/cache keeps framework metadata.'
235
- : 'Default engine stores framework metadata here and may add webpack cache artifacts during rebuilds.',
236
- ],
237
- }, null, 2));
238
- fs_1.default.writeFileSync(path_1.default.join(imageCacheDir, 'manifest.json'), JSON.stringify({
239
- schemaVersion: 1,
240
- buildId: options.buildId,
241
- generatedAt,
242
- endpoint: constants_1.IMAGE_ENDPOINT,
243
- cacheDirectory: '.vista/cache/images',
244
- config: options.imagesConfig || {},
245
- behavior: {
246
- optimization: 'on-demand',
247
- staticImportsEmitInto: '.vista/static/media',
248
- publicReferencesStayIn: 'public/',
249
- },
250
- }, null, 2));
251
- const emittedMedia = fs_1.default
252
- .readdirSync(mediaDir, { withFileTypes: true })
253
- .filter((entry) => entry.isFile() && entry.name !== 'media-manifest.json')
254
- .map((entry) => entry.name)
255
- .sort();
256
- fs_1.default.writeFileSync(path_1.default.join(mediaDir, 'media-manifest.json'), JSON.stringify({
257
- schemaVersion: 1,
258
- buildId: options.buildId,
259
- generatedAt,
260
- mediaDirectory: '.vista/static/media',
261
- emittedFiles: emittedMedia,
262
- note: 'This directory is reserved for emitted media assets. Public file references are served from public/ and may leave this list empty.',
263
- }, null, 2));
264
- }
265
- /**
266
- * Generate routes-manifest.json from route tree.
267
- */
268
- function generateRoutesManifest(vistaDir, staticRoutes = [], dynamicRoutes = []) {
269
- const manifest = {
270
- version: 1,
271
- basePath: '',
272
- redirects: [],
273
- rewrites: [],
274
- headers: [],
275
- staticRoutes,
276
- dynamicRoutes,
277
- };
278
- const manifestPath = path_1.default.join(vistaDir, 'routes-manifest.json');
279
- fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
280
- return manifest;
281
- }
282
- /**
283
- * Generate manifest of client components (files with 'use client').
284
- */
285
- function generateClientComponentsManifest(vistaDir, buildId, clientModules = {}) {
286
- const manifest = {
287
- buildId,
288
- clientModules,
289
- };
290
- const manifestPath = path_1.default.join(vistaDir, 'client-components-manifest.json');
291
- fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
292
- return manifest;
293
- }
294
- /**
295
- * Generate manifest of server components.
296
- */
297
- function generateServerComponentsManifest(vistaDir, serverModules = {}) {
298
- const manifest = {
299
- serverModules,
300
- };
301
- const manifestPath = path_1.default.join(vistaDir, 'server', 'server-components-manifest.json');
302
- fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
303
- }
304
- // ============================================================================
305
- // Cache Utilities
306
- // ============================================================================
307
- /**
308
- * Get Webpack cache configuration for persistent caching.
309
- */
310
- function getWebpackCacheConfig(vistaDir, buildId, name, engineVariant = 'default', cwd = process.cwd()) {
311
- const cacheDirectory = engineVariant === 'flashpack'
312
- ? path_1.default.join(cwd, constants_1.FLASH_DIR, 'cache', 'webpack')
313
- : path_1.default.join(vistaDir, 'cache', 'webpack');
314
- return {
315
- type: 'filesystem',
316
- version: buildId,
317
- cacheDirectory,
318
- name: name,
319
- buildDependencies: {
320
- config: [__filename],
321
- },
322
- };
323
- }
324
- /**
325
- * Clean old cache entries (keeps last N builds).
326
- */
327
- function cleanOldCache(vistaDir, keepBuilds = 5) {
328
- const cacheDir = path_1.default.join(vistaDir, 'cache', 'webpack');
329
- if (!fs_1.default.existsSync(cacheDir))
330
- return;
331
- const entries = fs_1.default
332
- .readdirSync(cacheDir)
333
- .map((name) => ({
334
- name,
335
- path: path_1.default.join(cacheDir, name),
336
- stat: fs_1.default.statSync(path_1.default.join(cacheDir, name)),
337
- }))
338
- .filter((e) => e.stat.isDirectory())
339
- .sort((a, b) => b.stat.mtimeMs - a.stat.mtimeMs);
340
- // Remove old cache directories
341
- entries.slice(keepBuilds).forEach((entry) => {
342
- fs_1.default.rmSync(entry.path, { recursive: true, force: true });
343
- });
344
- }
345
- function pruneEmptyVistaDirectories(vistaDir) {
346
- if (!fs_1.default.existsSync(vistaDir))
347
- return;
348
- const prune = (absolutePath) => {
349
- const entries = fs_1.default.readdirSync(absolutePath, { withFileTypes: true });
350
- for (const entry of entries) {
351
- if (!entry.isDirectory())
352
- continue;
353
- const childPath = path_1.default.join(absolutePath, entry.name);
354
- prune(childPath);
355
- }
356
- // Never remove the root .vista directory itself.
357
- if (absolutePath === vistaDir)
358
- return false;
359
- const remaining = fs_1.default.readdirSync(absolutePath);
360
- if (remaining.length === 0) {
361
- fs_1.default.rmdirSync(absolutePath);
362
- return true;
363
- }
364
- return false;
365
- };
366
- prune(vistaDir);
367
- }
1
+ "use strict";
2
+ /**
3
+ * Vista Build Utilities
4
+ *
5
+ * Generates build manifests, BUILD_ID, and manages .vista output structure.
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.generateBuildId = generateBuildId;
12
+ exports.getBuildId = getBuildId;
13
+ exports.createVistaDirectories = createVistaDirectories;
14
+ exports.generateBuildManifest = generateBuildManifest;
15
+ exports.generateAppPathRoutesManifest = generateAppPathRoutesManifest;
16
+ exports.writeVistaTypes = writeVistaTypes;
17
+ exports.writeVistaTrace = writeVistaTrace;
18
+ exports.generatePrerenderManifest = generatePrerenderManifest;
19
+ exports.generateRequiredServerFilesManifest = generateRequiredServerFilesManifest;
20
+ exports.ensureJsonFile = ensureJsonFile;
21
+ exports.writeArtifactManifest = writeArtifactManifest;
22
+ exports.writeCanonicalVistaArtifacts = writeCanonicalVistaArtifacts;
23
+ exports.writeReservedVistaArtifacts = writeReservedVistaArtifacts;
24
+ exports.generateRoutesManifest = generateRoutesManifest;
25
+ exports.generateClientComponentsManifest = generateClientComponentsManifest;
26
+ exports.generateServerComponentsManifest = generateServerComponentsManifest;
27
+ exports.getWebpackCacheConfig = getWebpackCacheConfig;
28
+ exports.cleanOldCache = cleanOldCache;
29
+ exports.pruneEmptyVistaDirectories = pruneEmptyVistaDirectories;
30
+ const fs_1 = __importDefault(require("fs"));
31
+ const path_1 = __importDefault(require("path"));
32
+ const crypto_1 = __importDefault(require("crypto"));
33
+ const constants_1 = require("../constants");
34
+ const integrity_1 = require("../integrity");
35
+ // ============================================================================
36
+ // BUILD_ID Generation
37
+ // ============================================================================
38
+ /**
39
+ * Generate a unique build ID based on timestamp and random bytes.
40
+ */
41
+ function generateBuildId() {
42
+ const timestamp = Date.now().toString(36);
43
+ const random = crypto_1.default.randomBytes(4).toString('hex');
44
+ return `${timestamp}-${random}`;
45
+ }
46
+ /**
47
+ * Read existing BUILD_ID or generate a new one.
48
+ */
49
+ function getBuildId(vistaDir, forceNew = false) {
50
+ const buildIdPath = path_1.default.join(vistaDir, 'BUILD_ID');
51
+ if (!forceNew && fs_1.default.existsSync(buildIdPath)) {
52
+ return fs_1.default.readFileSync(buildIdPath, 'utf-8').trim();
53
+ }
54
+ const buildId = generateBuildId();
55
+ fs_1.default.mkdirSync(vistaDir, { recursive: true });
56
+ fs_1.default.writeFileSync(buildIdPath, buildId);
57
+ return buildId;
58
+ }
59
+ /**
60
+ * Create the .vista directory structure.
61
+ * In legacy mode, only creates root (no empty server/static dirs).
62
+ * In RSC mode, creates the full structure for server/client bundles.
63
+ */
64
+ function createVistaDirectories(cwd, mode = 'legacy') {
65
+ const root = path_1.default.join(cwd, constants_1.BUILD_DIR);
66
+ const dirs = {
67
+ root,
68
+ cache: path_1.default.join(root, 'cache'),
69
+ imageCache: path_1.default.join(root, 'cache', 'images'),
70
+ server: path_1.default.join(root, 'server'),
71
+ static: path_1.default.join(root, 'static'),
72
+ chunks: path_1.default.join(root, 'static', 'chunks'),
73
+ css: path_1.default.join(root, 'static', 'css'),
74
+ media: path_1.default.join(root, 'static', 'media'),
75
+ types: path_1.default.join(root, 'types'),
76
+ };
77
+ // Always create root
78
+ fs_1.default.mkdirSync(root, { recursive: true });
79
+ if (mode === 'rsc') {
80
+ [dirs.root, dirs.cache, dirs.imageCache, dirs.server, dirs.static, dirs.chunks, dirs.media, dirs.types].forEach((dir) => {
81
+ fs_1.default.mkdirSync(dir, { recursive: true });
82
+ });
83
+ }
84
+ // Legacy mode: only root dir is created — webpack outputs directly into .vista/
85
+ return dirs;
86
+ }
87
+ /**
88
+ * Generate build-manifest.json
89
+ */
90
+ function generateBuildManifest(vistaDir, buildId, pages = {}) {
91
+ const manifest = {
92
+ buildId,
93
+ polyfillFiles: [],
94
+ devFiles: [],
95
+ lowPriorityFiles: [],
96
+ rootMainFiles: [`${constants_1.STATIC_CHUNKS_PATH}webpack.js`, `${constants_1.STATIC_CHUNKS_PATH}main.js`],
97
+ pages,
98
+ };
99
+ const manifestPath = path_1.default.join(vistaDir, 'build-manifest.json');
100
+ fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
101
+ return manifest;
102
+ }
103
+ function toRegexFromPattern(pattern) {
104
+ if (pattern === '/') {
105
+ return '^/$';
106
+ }
107
+ const normalized = pattern.startsWith('/') ? pattern.slice(1) : pattern;
108
+ const parts = normalized.split('/').filter(Boolean);
109
+ const regexParts = parts.map((part) => {
110
+ if (!part.startsWith(':')) {
111
+ return part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
112
+ }
113
+ const dynamicMatch = /^:([a-zA-Z0-9_]+)(\*)?(\?)?$/.exec(part);
114
+ if (!dynamicMatch) {
115
+ return part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
116
+ }
117
+ const [, paramName, isCatchAll, isOptional] = dynamicMatch;
118
+ if (isCatchAll && isOptional) {
119
+ return `(?<${paramName}>.*)`;
120
+ }
121
+ if (isCatchAll) {
122
+ return `(?<${paramName}>.+)`;
123
+ }
124
+ return `(?<${paramName}>[^/]+)`;
125
+ });
126
+ return `^/${regexParts.join('/')}$`;
127
+ }
128
+ function toRouteHandlerInfo(handler) {
129
+ return {
130
+ page: handler.filePath,
131
+ regex: toRegexFromPattern(handler.pattern),
132
+ namedRegex: toRegexFromPattern(handler.pattern),
133
+ routeKeys: {},
134
+ methods: handler.methods || [],
135
+ ...(handler.runtime ? { runtime: handler.runtime } : {}),
136
+ };
137
+ }
138
+ function toRouteInfo(route) {
139
+ return {
140
+ page: route.pagePath,
141
+ regex: toRegexFromPattern(route.pattern),
142
+ routeKeys: {},
143
+ namedRegex: toRegexFromPattern(route.pattern),
144
+ };
145
+ }
146
+ function generateAppPathRoutesManifest(vistaDir, routes = [], routeHandlers = []) {
147
+ const manifest = {};
148
+ routes.forEach((route) => {
149
+ manifest[route.pattern] = route.pagePath;
150
+ });
151
+ // A page and a route handler cannot both own a URL. Pages win, so a stray
152
+ // `route.ts` next to a `page.tsx` cannot silently take over the route.
153
+ routeHandlers.forEach((handler) => {
154
+ if (!(handler.pattern in manifest)) {
155
+ manifest[handler.pattern] = handler.filePath;
156
+ }
157
+ });
158
+ fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'app-path-routes-manifest.json'), JSON.stringify(manifest, null, 2));
159
+ return manifest;
160
+ }
161
+ function quoteRouteLiteral(route) {
162
+ return `'${route.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
163
+ }
164
+ function writeVistaTypes(vistaDir, routes = []) {
165
+ const typesDir = path_1.default.join(vistaDir, 'types');
166
+ fs_1.default.mkdirSync(typesDir, { recursive: true });
167
+ const uniqueRoutes = [...new Set(routes.filter(Boolean))].sort();
168
+ const union = uniqueRoutes.length
169
+ ? uniqueRoutes.map((route) => ` | ${quoteRouteLiteral(route)}`).join('\n')
170
+ : ' | never';
171
+ const source = [
172
+ '// Generated by `vista build`. Do not edit.',
173
+ '// Mirrors Next.js `.next/types` route unions for editor tooling.',
174
+ '',
175
+ 'export type VistaAppRoute =',
176
+ union,
177
+ '',
178
+ 'export type VistaRoutePath = VistaAppRoute;',
179
+ '',
180
+ ].join('\n');
181
+ fs_1.default.writeFileSync(path_1.default.join(typesDir, 'routes.d.ts'), source);
182
+ fs_1.default.writeFileSync(path_1.default.join(typesDir, 'package.json'), JSON.stringify({ type: 'module' }, null, 2));
183
+ }
184
+ function writeVistaTrace(vistaDir, fileTrace = {}) {
185
+ const payload = {
186
+ schemaVersion: 1,
187
+ source: 'server/file-trace.json',
188
+ generatedAt: fileTrace.generatedAt || new Date().toISOString(),
189
+ copiedFiles: Array.isArray(fileTrace.copiedFiles) ? fileTrace.copiedFiles.length : 0,
190
+ };
191
+ fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'trace'), JSON.stringify(payload, null, 2));
192
+ }
193
+ function generatePrerenderManifest(vistaDir) {
194
+ const manifest = {
195
+ version: 1,
196
+ routes: {},
197
+ dynamicRoutes: {},
198
+ notFoundRoutes: [],
199
+ preview: {
200
+ previewModeId: '',
201
+ previewModeSigningKey: '',
202
+ previewModeEncryptionKey: '',
203
+ },
204
+ };
205
+ fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'prerender-manifest.json'), JSON.stringify(manifest, null, 2));
206
+ }
207
+ function generateRequiredServerFilesManifest(cwd, vistaDir, extraFiles = [], appDir = cwd) {
208
+ const files = Array.from(new Set([
209
+ `${constants_1.BUILD_DIR}/BUILD_ID`,
210
+ `${constants_1.BUILD_DIR}/build-manifest.json`,
211
+ `${constants_1.BUILD_DIR}/routes-manifest.json`,
212
+ `${constants_1.BUILD_DIR}/app-path-routes-manifest.json`,
213
+ `${constants_1.BUILD_DIR}/server/server-manifest.json`,
214
+ ...extraFiles,
215
+ ]));
216
+ const manifest = {
217
+ version: 1,
218
+ config: {},
219
+ appDir,
220
+ relativeAppDir: path_1.default.relative(cwd, appDir) || '.',
221
+ files,
222
+ };
223
+ fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'required-server-files.json'), JSON.stringify(manifest, null, 2));
224
+ }
225
+ function ensureJsonFile(vistaDir, relativePath, fallback = {}) {
226
+ const absolutePath = path_1.default.join(vistaDir, relativePath);
227
+ if (!fs_1.default.existsSync(absolutePath)) {
228
+ fs_1.default.writeFileSync(absolutePath, JSON.stringify(fallback, null, 2));
229
+ }
230
+ }
231
+ function writeArtifactManifest(vistaDir, buildId, extraManifestEntries = {}) {
232
+ const artifactManifest = {
233
+ schemaVersion: 1,
234
+ buildId,
235
+ generatedAt: new Date().toISOString(),
236
+ __integrity: (0, integrity_1.generateBuildWatermark)(),
237
+ manifests: {
238
+ buildManifest: 'build-manifest.json',
239
+ routesManifest: 'routes-manifest.json',
240
+ appPathRoutesManifest: 'app-path-routes-manifest.json',
241
+ prerenderManifest: 'prerender-manifest.json',
242
+ requiredServerFiles: 'required-server-files.json',
243
+ reactClientManifest: 'react-client-manifest.json',
244
+ reactServerManifest: 'react-server-manifest.json',
245
+ ...extraManifestEntries,
246
+ },
247
+ };
248
+ fs_1.default.writeFileSync(path_1.default.join(vistaDir, 'artifact-manifest.json'), JSON.stringify(artifactManifest, null, 2));
249
+ return artifactManifest;
250
+ }
251
+ function writeCanonicalVistaArtifacts(cwd, vistaDir, buildId, routes = [], routeHandlers = []) {
252
+ const staticRoutes = routes.filter((route) => route.type === 'static').map(toRouteInfo);
253
+ const dynamicRoutes = routes.filter((route) => route.type !== 'static').map(toRouteInfo);
254
+ generateBuildManifest(vistaDir, buildId);
255
+ generateRoutesManifest(vistaDir, staticRoutes, dynamicRoutes, routeHandlers);
256
+ const appPaths = generateAppPathRoutesManifest(vistaDir, routes, routeHandlers);
257
+ generatePrerenderManifest(vistaDir);
258
+ generateRequiredServerFilesManifest(cwd, vistaDir);
259
+ writeVistaTypes(vistaDir, Object.keys(appPaths));
260
+ // Keep canonical React manifest filenames present for validation consistency.
261
+ ensureJsonFile(vistaDir, 'react-client-manifest.json', {});
262
+ ensureJsonFile(vistaDir, 'react-server-manifest.json', {});
263
+ return writeArtifactManifest(vistaDir, buildId, {
264
+ types: 'types/routes.d.ts',
265
+ });
266
+ }
267
+ function writeReservedVistaArtifacts(vistaDir, options) {
268
+ const engineVariant = options.engineVariant || 'default';
269
+ const generatedAt = new Date().toISOString();
270
+ const cacheDir = path_1.default.join(vistaDir, 'cache');
271
+ const imageCacheDir = path_1.default.join(cacheDir, 'images');
272
+ const mediaDir = path_1.default.join(vistaDir, 'static', 'media');
273
+ fs_1.default.mkdirSync(cacheDir, { recursive: true });
274
+ fs_1.default.mkdirSync(imageCacheDir, { recursive: true });
275
+ fs_1.default.mkdirSync(mediaDir, { recursive: true });
276
+ fs_1.default.writeFileSync(path_1.default.join(cacheDir, 'cache-manifest.json'), JSON.stringify({
277
+ schemaVersion: 1,
278
+ buildId: options.buildId,
279
+ generatedAt,
280
+ engine: engineVariant,
281
+ activeCacheRoot: engineVariant === 'flashpack' ? '.flash/cache' : '.vista/cache/webpack',
282
+ directories: {
283
+ localCache: '.vista/cache',
284
+ webpack: engineVariant === 'flashpack' ? '.flash/cache/webpack' : '.vista/cache/webpack',
285
+ images: '.vista/cache/images',
286
+ },
287
+ notes: [
288
+ engineVariant === 'flashpack'
289
+ ? 'Flashpack stores its hot build cache in .flash while .vista/cache keeps framework metadata.'
290
+ : 'Default engine stores framework metadata here and may add webpack cache artifacts during rebuilds.',
291
+ ],
292
+ }, null, 2));
293
+ fs_1.default.writeFileSync(path_1.default.join(imageCacheDir, 'manifest.json'), JSON.stringify({
294
+ schemaVersion: 1,
295
+ buildId: options.buildId,
296
+ generatedAt,
297
+ endpoint: constants_1.IMAGE_ENDPOINT,
298
+ cacheDirectory: '.vista/cache/images',
299
+ config: options.imagesConfig || {},
300
+ behavior: {
301
+ optimization: 'on-demand',
302
+ staticImportsEmitInto: '.vista/static/media',
303
+ publicReferencesStayIn: 'public/',
304
+ },
305
+ }, null, 2));
306
+ const emittedMedia = fs_1.default
307
+ .readdirSync(mediaDir, { withFileTypes: true })
308
+ .filter((entry) => entry.isFile() && entry.name !== 'media-manifest.json')
309
+ .map((entry) => entry.name)
310
+ .sort();
311
+ fs_1.default.writeFileSync(path_1.default.join(mediaDir, 'media-manifest.json'), JSON.stringify({
312
+ schemaVersion: 1,
313
+ buildId: options.buildId,
314
+ generatedAt,
315
+ mediaDirectory: '.vista/static/media',
316
+ emittedFiles: emittedMedia,
317
+ note: 'This directory is reserved for emitted media assets. Public file references are served from public/ and may leave this list empty.',
318
+ }, null, 2));
319
+ }
320
+ /**
321
+ * Generate routes-manifest.json from route tree.
322
+ */
323
+ function generateRoutesManifest(vistaDir, staticRoutes = [], dynamicRoutes = [], routeHandlers = []) {
324
+ const manifest = {
325
+ version: 1,
326
+ basePath: '',
327
+ redirects: [],
328
+ rewrites: [],
329
+ headers: [],
330
+ staticRoutes,
331
+ dynamicRoutes,
332
+ routeHandlers: routeHandlers.map(toRouteHandlerInfo),
333
+ };
334
+ const manifestPath = path_1.default.join(vistaDir, 'routes-manifest.json');
335
+ fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
336
+ return manifest;
337
+ }
338
+ /**
339
+ * Generate manifest of client components (files with 'use client').
340
+ */
341
+ function generateClientComponentsManifest(vistaDir, buildId, clientModules = {}) {
342
+ const manifest = {
343
+ buildId,
344
+ clientModules,
345
+ };
346
+ const manifestPath = path_1.default.join(vistaDir, 'client-components-manifest.json');
347
+ fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
348
+ return manifest;
349
+ }
350
+ /**
351
+ * Generate manifest of server components.
352
+ */
353
+ function generateServerComponentsManifest(vistaDir, serverModules = {}) {
354
+ const manifest = {
355
+ serverModules,
356
+ };
357
+ const manifestPath = path_1.default.join(vistaDir, 'server', 'server-components-manifest.json');
358
+ fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
359
+ }
360
+ // ============================================================================
361
+ // Cache Utilities
362
+ // ============================================================================
363
+ /**
364
+ * Get Webpack cache configuration for persistent caching.
365
+ */
366
+ function getWebpackCacheConfig(vistaDir, buildId, name, engineVariant = 'default', cwd = process.cwd()) {
367
+ const cacheDirectory = engineVariant === 'flashpack'
368
+ ? path_1.default.join(cwd, constants_1.FLASH_DIR, 'cache', 'webpack')
369
+ : path_1.default.join(vistaDir, 'cache', 'webpack');
370
+ return {
371
+ type: 'filesystem',
372
+ version: buildId,
373
+ cacheDirectory,
374
+ name: name,
375
+ buildDependencies: {
376
+ config: [__filename],
377
+ },
378
+ };
379
+ }
380
+ /**
381
+ * Clean old cache entries (keeps last N builds).
382
+ */
383
+ function cleanOldCache(vistaDir, keepBuilds = 5) {
384
+ const cacheDir = path_1.default.join(vistaDir, 'cache', 'webpack');
385
+ if (!fs_1.default.existsSync(cacheDir))
386
+ return;
387
+ const entries = fs_1.default
388
+ .readdirSync(cacheDir)
389
+ .map((name) => ({
390
+ name,
391
+ path: path_1.default.join(cacheDir, name),
392
+ stat: fs_1.default.statSync(path_1.default.join(cacheDir, name)),
393
+ }))
394
+ .filter((e) => e.stat.isDirectory())
395
+ .sort((a, b) => b.stat.mtimeMs - a.stat.mtimeMs);
396
+ // Remove old cache directories
397
+ entries.slice(keepBuilds).forEach((entry) => {
398
+ fs_1.default.rmSync(entry.path, { recursive: true, force: true });
399
+ });
400
+ }
401
+ function pruneEmptyVistaDirectories(vistaDir) {
402
+ if (!fs_1.default.existsSync(vistaDir))
403
+ return;
404
+ const prune = (absolutePath) => {
405
+ const entries = fs_1.default.readdirSync(absolutePath, { withFileTypes: true });
406
+ for (const entry of entries) {
407
+ if (!entry.isDirectory())
408
+ continue;
409
+ const childPath = path_1.default.join(absolutePath, entry.name);
410
+ prune(childPath);
411
+ }
412
+ // Never remove the root .vista directory itself.
413
+ if (absolutePath === vistaDir)
414
+ return false;
415
+ const remaining = fs_1.default.readdirSync(absolutePath);
416
+ if (remaining.length === 0) {
417
+ fs_1.default.rmdirSync(absolutePath);
418
+ return true;
419
+ }
420
+ return false;
421
+ };
422
+ prune(vistaDir);
423
+ }