@vistagenic/vista 0.2.12 → 0.2.13

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 (77) hide show
  1. package/bin/vista.js +171 -35
  2. package/dist/bin/build-rsc-flashpack.d.ts +4 -0
  3. package/dist/bin/build-rsc-flashpack.js +29 -0
  4. package/dist/bin/build-rsc.js +47 -16
  5. package/dist/bin/build.js +36 -13
  6. package/dist/bin/devtools-indicator-snippet.js +30 -0
  7. package/dist/bin/file-scanner.d.ts +1 -1
  8. package/dist/bin/file-scanner.js +8 -0
  9. package/dist/bin/flashpack-runner.d.ts +1 -0
  10. package/dist/bin/flashpack-runner.js +61 -0
  11. package/dist/bin/server-component-plugin.d.ts +6 -4
  12. package/dist/bin/server-component-plugin.js +22 -69
  13. package/dist/bin/webpack.config.d.ts +3 -0
  14. package/dist/bin/webpack.config.js +12 -3
  15. package/dist/build/manifest.d.ts +17 -3
  16. package/dist/build/manifest.js +99 -23
  17. package/dist/build/rsc/compiler.d.ts +2 -0
  18. package/dist/build/rsc/compiler.js +25 -5
  19. package/dist/build/rsc/react-client-reference-manifest.d.ts +22 -0
  20. package/dist/build/rsc/react-client-reference-manifest.js +219 -0
  21. package/dist/build/rsc/server-manifest.d.ts +23 -2
  22. package/dist/build/rsc/server-manifest.js +162 -24
  23. package/dist/build/standalone.d.ts +31 -0
  24. package/dist/build/standalone.js +334 -0
  25. package/dist/client/rsc-router.d.ts +31 -0
  26. package/dist/client/rsc-router.js +89 -0
  27. package/dist/config.d.ts +23 -0
  28. package/dist/config.js +106 -5
  29. package/dist/constants.d.ts +2 -0
  30. package/dist/constants.js +3 -1
  31. package/dist/flashpack/command.d.ts +8 -0
  32. package/dist/flashpack/command.js +134 -0
  33. package/dist/flashpack/runtime.d.ts +39 -0
  34. package/dist/flashpack/runtime.js +249 -0
  35. package/dist/server/app-router-runtime.d.ts +26 -0
  36. package/dist/server/app-router-runtime.js +321 -0
  37. package/dist/server/artifact-validator.js +21 -1
  38. package/dist/server/cache.d.ts +10 -0
  39. package/dist/server/cache.js +270 -0
  40. package/dist/server/client-boundary.js +20 -2
  41. package/dist/server/engine.js +236 -159
  42. package/dist/server/fetch-policy.d.ts +2 -0
  43. package/dist/server/fetch-policy.js +123 -0
  44. package/dist/server/index.d.ts +7 -0
  45. package/dist/server/index.js +131 -22
  46. package/dist/server/module-boundary-validator.d.ts +15 -0
  47. package/dist/server/module-boundary-validator.js +262 -0
  48. package/dist/server/module-compile-hook.d.ts +7 -0
  49. package/dist/server/module-compile-hook.js +662 -0
  50. package/dist/server/ppr.d.ts +18 -0
  51. package/dist/server/ppr.js +59 -0
  52. package/dist/server/request-context.d.ts +31 -0
  53. package/dist/server/request-context.js +95 -0
  54. package/dist/server/rsc-engine-flashpack.d.ts +4 -0
  55. package/dist/server/rsc-engine-flashpack.js +27 -0
  56. package/dist/server/rsc-engine.d.ts +2 -0
  57. package/dist/server/rsc-engine.js +589 -317
  58. package/dist/server/rsc-upstream.js +539 -233
  59. package/dist/server/runtime-actions.d.ts +5 -0
  60. package/dist/server/runtime-actions.js +80 -0
  61. package/dist/server/runtime-artifacts.d.ts +11 -0
  62. package/dist/server/runtime-artifacts.js +35 -0
  63. package/dist/server/segment-config.d.ts +37 -0
  64. package/dist/server/segment-config.js +205 -0
  65. package/dist/server/spawn-permissions.d.ts +2 -0
  66. package/dist/server/spawn-permissions.js +21 -0
  67. package/dist/server/static-cache.d.ts +15 -1
  68. package/dist/server/static-cache.js +83 -3
  69. package/dist/server/static-generator.js +254 -100
  70. package/dist/server/structure-validator.d.ts +1 -1
  71. package/dist/server/structure-validator.js +26 -5
  72. package/dist/server/structure-watch.js +1 -1
  73. package/dist/server/typed-api-runtime.d.ts +1 -0
  74. package/dist/server/typed-api-runtime.js +145 -25
  75. package/dist/server/vista-import-map.d.ts +1 -0
  76. package/dist/server/vista-import-map.js +123 -0
  77. package/package.json +13 -1
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAppPPREnabled = isAppPPREnabled;
4
+ exports.isRoutePPREligible = isRoutePPREligible;
5
+ exports.getPprShellArtifactPath = getPprShellArtifactPath;
6
+ exports.createPartialPrerenderInfo = createPartialPrerenderInfo;
7
+ exports.resolvePprRequestMode = resolvePprRequestMode;
8
+ exports.injectPprResumeBootstrap = injectPprResumeBootstrap;
9
+ const config_1 = require("../config");
10
+ function isAppPPREnabled(config) {
11
+ return (0, config_1.resolveCacheComponentsConfig)(config).enabled;
12
+ }
13
+ function isRoutePPREligible(route, appPprEnabled) {
14
+ if (!appPprEnabled) {
15
+ return false;
16
+ }
17
+ if (!route.loadingPath) {
18
+ return false;
19
+ }
20
+ return route.renderMode === 'static' || route.renderMode === 'isr';
21
+ }
22
+ function getPprShellArtifactPath(urlPath) {
23
+ const normalized = urlPath === '/' ? '/index' : urlPath;
24
+ return `static/pages${normalized}.shell.html`;
25
+ }
26
+ function createPartialPrerenderInfo(urlPath) {
27
+ return {
28
+ enabled: true,
29
+ strategy: 'loading-boundary',
30
+ shellArtifact: getPprShellArtifactPath(urlPath),
31
+ resumePath: urlPath,
32
+ };
33
+ }
34
+ function resolvePprRequestMode(input) {
35
+ const headerValue = String(input.headerValue || '').trim().toLowerCase();
36
+ const queryValue = String(input.queryValue || '').trim().toLowerCase();
37
+ const value = headerValue || queryValue;
38
+ if (value === 'shell') {
39
+ return 'shell';
40
+ }
41
+ if (value === 'resume') {
42
+ return 'resume';
43
+ }
44
+ return 'default';
45
+ }
46
+ function injectPprResumeBootstrap(shellHtml, urlPath) {
47
+ const payload = JSON.stringify({
48
+ url: urlPath,
49
+ headerName: 'x-vista-prerender',
50
+ headerValue: 'resume',
51
+ queryKey: '__vista_prerender',
52
+ queryValue: 'resume',
53
+ });
54
+ const script = `<script>window.__VISTA_PPR_RESUME__=${payload};(function(){var c=window.__VISTA_PPR_RESUME__;if(!c)return;var root=document.getElementById('root');if(!root)return;var finished=false;function ensureTraceStore(){var existing=window.__VISTA_RUNTIME_TRACE__;if(existing&&typeof existing.pushEvent==='function'&&Array.isArray(existing.events)){return existing;}var store={events:[],lastEvent:null,pushEvent:function(type,detail){var entry={type:type,detail:detail||{},at:Date.now()};store.events.push(entry);if(store.events.length>60){store.events.shift();}store.lastEvent=entry;return entry;}};window.__VISTA_RUNTIME_TRACE__=store;return store;}function trace(type,detail){var store=ensureTraceStore();return store.pushEvent(type,detail||{});}function mark(mode){document.documentElement.setAttribute('data-vista-ppr',mode);}function emit(name,detail){document.dispatchEvent(new CustomEvent(name,{detail:detail}));}trace('ppr-shell-rendered',{url:c.url});mark('shell');emit('vista:ppr-shell',{url:c.url});function complete(detail){trace('ppr-resume-complete',detail);emit('vista:ppr-complete',detail);}function fail(detail,error){trace('ppr-resume-error',{url:detail&&detail.url||c.url,mode:detail&&detail.mode||'unknown',message:(error&&error.message)||String(error||'Unknown PPR resume error')});emit('vista:ppr-error',{url:detail&&detail.url||c.url,mode:detail&&detail.mode||'unknown',message:(error&&error.message)||String(error||'Unknown PPR resume error')});mark('error');console.error('[vista:ppr] resume failed',error);}function fallbackHtmlResume(){var resumeUrl=new URL(c.url,window.location.href);resumeUrl.searchParams.set(c.queryKey,c.queryValue);trace('ppr-resume-start',{url:resumeUrl.toString(),mode:'html'});emit('vista:ppr-resume',{url:resumeUrl.toString(),mode:'html'});fetch(resumeUrl.toString(),{headers:{[c.headerName]:c.headerValue},credentials:'same-origin',cache:'no-store'}).then(function(res){return res.text().then(function(html){return{res:res,html:html,url:resumeUrl.toString()};});}).then(function(result){if(!result.res.ok){throw new Error('Resume request failed with status '+result.res.status);}var parsed=new DOMParser().parseFromString(result.html,'text/html');var nextRoot=parsed.getElementById('root');if(nextRoot){root.innerHTML=nextRoot.innerHTML;}var nextTitle=parsed.querySelector('title');if(nextTitle&&nextTitle.textContent){document.title=nextTitle.textContent;}finished=true;mark('resumed');complete({url:result.url,mode:'html'});}).catch(function(error){fail({url:resumeUrl.toString(),mode:'html'},error);});}function tryFlightResume(){var router=window.__VISTA_RSC_ROUTER__;if(!router||typeof router.resume!=='function'){return false;}finished=true;trace('ppr-resume-start',{url:c.url,mode:'flight'});mark('flight-resume');emit('vista:ppr-resume',{url:c.url,mode:'flight'});router.resume(c.url);return true;}function onFlightComplete(event){var detail=event&&event.detail&&typeof event.detail==='object'?event.detail:{url:c.url};complete({url:detail.url||c.url,mode:'flight'});mark('resumed');}function onFlightError(event){var detail=event&&event.detail&&typeof event.detail==='object'?event.detail:{url:c.url};fail({url:detail.url||c.url,mode:'flight'},new Error(detail.message||'Flight resume failed'));}document.addEventListener('vista:rsc-resume-complete',onFlightComplete,{once:true});document.addEventListener('vista:rsc-resume-error',onFlightError,{once:true});var attempts=0;var maxAttempts=20;function attemptResume(){if(finished)return;if(tryFlightResume())return;attempts++;if(attempts>=maxAttempts){fallbackHtmlResume();return;}setTimeout(attemptResume,100);}document.addEventListener('vista:rsc-router-ready',attemptResume,{once:true});attemptResume();})();</script>`;
55
+ if (/<\/body>/i.test(shellHtml)) {
56
+ return shellHtml.replace(/<\/body>/i, `${script}\n</body>`);
57
+ }
58
+ return `${shellHtml}\n${script}`;
59
+ }
@@ -0,0 +1,31 @@
1
+ import type express from 'express';
2
+ import type { ResolvedSegmentConfig } from './segment-config';
3
+ export interface RequestContext {
4
+ req?: express.Request;
5
+ res?: express.Response;
6
+ cwd?: string;
7
+ vistaDirRoot?: string;
8
+ urlPath?: string;
9
+ segmentConfig?: ResolvedSegmentConfig;
10
+ usedTags: Set<string>;
11
+ revalidatedTags: Set<string>;
12
+ revalidatedPaths: Set<string>;
13
+ }
14
+ export interface RequestContextSeed {
15
+ req?: express.Request;
16
+ res?: express.Response;
17
+ cwd?: string;
18
+ vistaDirRoot?: string;
19
+ urlPath?: string;
20
+ segmentConfig?: ResolvedSegmentConfig;
21
+ }
22
+ export declare function runWithRequestContext<T>(seed: RequestContextSeed, callback: () => T): T;
23
+ export declare function getRequestContext(): RequestContext | undefined;
24
+ export declare function setCurrentSegmentConfig(segmentConfig: ResolvedSegmentConfig | undefined): void;
25
+ export declare function getCurrentSegmentConfig(): ResolvedSegmentConfig | undefined;
26
+ export declare function trackCacheTags(tags: Iterable<string> | undefined): void;
27
+ export declare function consumeTrackedTags(): string[];
28
+ export declare function consumeRevalidatedTags(): string[];
29
+ export declare function consumeRevalidatedPaths(): string[];
30
+ export declare function recordRevalidatedTag(tag: string): void;
31
+ export declare function recordRevalidatedPath(urlPath: string): void;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runWithRequestContext = runWithRequestContext;
4
+ exports.getRequestContext = getRequestContext;
5
+ exports.setCurrentSegmentConfig = setCurrentSegmentConfig;
6
+ exports.getCurrentSegmentConfig = getCurrentSegmentConfig;
7
+ exports.trackCacheTags = trackCacheTags;
8
+ exports.consumeTrackedTags = consumeTrackedTags;
9
+ exports.consumeRevalidatedTags = consumeRevalidatedTags;
10
+ exports.consumeRevalidatedPaths = consumeRevalidatedPaths;
11
+ exports.recordRevalidatedTag = recordRevalidatedTag;
12
+ exports.recordRevalidatedPath = recordRevalidatedPath;
13
+ const node_async_hooks_1 = require("node:async_hooks");
14
+ const requestContextStorage = new node_async_hooks_1.AsyncLocalStorage();
15
+ function createRequestContext(seed = {}) {
16
+ return {
17
+ req: seed.req,
18
+ res: seed.res,
19
+ cwd: seed.cwd,
20
+ vistaDirRoot: seed.vistaDirRoot,
21
+ urlPath: seed.urlPath,
22
+ segmentConfig: seed.segmentConfig,
23
+ usedTags: new Set(),
24
+ revalidatedTags: new Set(),
25
+ revalidatedPaths: new Set(),
26
+ };
27
+ }
28
+ function runWithRequestContext(seed, callback) {
29
+ return requestContextStorage.run(createRequestContext(seed), callback);
30
+ }
31
+ function getRequestContext() {
32
+ return requestContextStorage.getStore();
33
+ }
34
+ function setCurrentSegmentConfig(segmentConfig) {
35
+ const context = getRequestContext();
36
+ if (context) {
37
+ context.segmentConfig = segmentConfig;
38
+ }
39
+ }
40
+ function getCurrentSegmentConfig() {
41
+ return getRequestContext()?.segmentConfig;
42
+ }
43
+ function trackCacheTags(tags) {
44
+ const context = getRequestContext();
45
+ if (!context || !tags) {
46
+ return;
47
+ }
48
+ for (const tag of tags) {
49
+ const normalized = String(tag || '').trim();
50
+ if (normalized) {
51
+ context.usedTags.add(normalized);
52
+ }
53
+ }
54
+ }
55
+ function consumeTrackedTags() {
56
+ const context = getRequestContext();
57
+ if (!context || context.usedTags.size === 0) {
58
+ return [];
59
+ }
60
+ const tags = Array.from(context.usedTags);
61
+ context.usedTags.clear();
62
+ return tags;
63
+ }
64
+ function consumeRevalidatedTags() {
65
+ const context = getRequestContext();
66
+ if (!context || context.revalidatedTags.size === 0) {
67
+ return [];
68
+ }
69
+ const tags = Array.from(context.revalidatedTags);
70
+ context.revalidatedTags.clear();
71
+ return tags;
72
+ }
73
+ function consumeRevalidatedPaths() {
74
+ const context = getRequestContext();
75
+ if (!context || context.revalidatedPaths.size === 0) {
76
+ return [];
77
+ }
78
+ const paths = Array.from(context.revalidatedPaths);
79
+ context.revalidatedPaths.clear();
80
+ return paths;
81
+ }
82
+ function recordRevalidatedTag(tag) {
83
+ const context = getRequestContext();
84
+ const normalized = String(tag || '').trim();
85
+ if (context && normalized) {
86
+ context.revalidatedTags.add(normalized);
87
+ }
88
+ }
89
+ function recordRevalidatedPath(urlPath) {
90
+ const context = getRequestContext();
91
+ const normalized = String(urlPath || '').trim();
92
+ if (context && normalized) {
93
+ context.revalidatedPaths.add(normalized);
94
+ }
95
+ }
@@ -0,0 +1,4 @@
1
+ import { type RSCEngineOptions } from './rsc-engine';
2
+ export declare function startFlashpackRSCServer(options?: RSCEngineOptions): void;
3
+ export declare const startRSCServer: typeof startFlashpackRSCServer;
4
+ export { startFlashpackRSCServer as default };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startRSCServer = void 0;
4
+ exports.startFlashpackRSCServer = startFlashpackRSCServer;
5
+ exports.default = startFlashpackRSCServer;
6
+ const runtime_1 = require("../flashpack/runtime");
7
+ const rsc_engine_1 = require("./rsc-engine");
8
+ function resolveMode() {
9
+ return process.env.NODE_ENV === 'development' ? 'development' : 'production';
10
+ }
11
+ function startFlashpackRSCServer(options = {}) {
12
+ const cwd = process.cwd();
13
+ const mode = resolveMode();
14
+ const phase = mode === 'development' ? 'dev' : 'start';
15
+ const strict = process.env.VISTA_FLASHPACK_STRICT !== 'false';
16
+ const prepared = (0, runtime_1.prepareFlashpackRuntime)({
17
+ cwd,
18
+ phase,
19
+ mode,
20
+ allowFallback: !strict,
21
+ });
22
+ if (process.env.VISTA_DEBUG) {
23
+ console.log(`[flashpack] server runtime prepared (rust=${prepared.rustPipelineUsed ? 'on' : 'fallback'}) at ${prepared.flashDir}`);
24
+ }
25
+ (0, rsc_engine_1.startRSCServer)(options);
26
+ }
27
+ exports.startRSCServer = startFlashpackRSCServer;
@@ -11,6 +11,8 @@ import webpack from 'webpack';
11
11
  export interface RSCEngineOptions {
12
12
  port?: number;
13
13
  compiler?: webpack.Compiler | null;
14
+ projectRoot?: string;
15
+ runtimeRoot?: string;
14
16
  }
15
17
  export declare function startRSCServer(options?: RSCEngineOptions): void;
16
18
  export { startRSCServer as default };