@vistagenic/vista 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/vista.js +98 -0
- package/dist/auth/index.d.ts +8 -0
- package/dist/auth/index.js +16 -0
- package/dist/bin/build-rsc.d.ts +17 -0
- package/dist/bin/build-rsc.js +320 -0
- package/dist/bin/build.d.ts +4 -0
- package/dist/bin/build.js +336 -0
- package/dist/bin/file-scanner.d.ts +66 -0
- package/dist/bin/file-scanner.js +399 -0
- package/dist/bin/server-component-plugin.d.ts +17 -0
- package/dist/bin/server-component-plugin.js +133 -0
- package/dist/bin/webpack.config.d.ts +6 -0
- package/dist/bin/webpack.config.js +138 -0
- package/dist/build/manifest.d.ts +95 -0
- package/dist/build/manifest.js +168 -0
- package/dist/build/rsc/client-manifest.d.ts +48 -0
- package/dist/build/rsc/client-manifest.js +191 -0
- package/dist/build/rsc/client-reference-plugin.d.ts +37 -0
- package/dist/build/rsc/client-reference-plugin.js +185 -0
- package/dist/build/rsc/compiler.d.ts +36 -0
- package/dist/build/rsc/compiler.js +311 -0
- package/dist/build/rsc/index.d.ts +16 -0
- package/dist/build/rsc/index.js +32 -0
- package/dist/build/rsc/native-scanner.d.ts +123 -0
- package/dist/build/rsc/native-scanner.js +165 -0
- package/dist/build/rsc/rsc-renderer.d.ts +99 -0
- package/dist/build/rsc/rsc-renderer.js +269 -0
- package/dist/build/rsc/server-component-loader.d.ts +19 -0
- package/dist/build/rsc/server-component-loader.js +147 -0
- package/dist/build/rsc/server-manifest.d.ts +63 -0
- package/dist/build/rsc/server-manifest.js +268 -0
- package/dist/build/webpack/loaders/vista-flight-loader.d.ts +17 -0
- package/dist/build/webpack/loaders/vista-flight-loader.js +93 -0
- package/dist/build/webpack/plugins/vista-flight-plugin.d.ts +36 -0
- package/dist/build/webpack/plugins/vista-flight-plugin.js +133 -0
- package/dist/client/dynamic.d.ts +25 -0
- package/dist/client/dynamic.js +68 -0
- package/dist/client/font.d.ts +98 -0
- package/dist/client/font.js +109 -0
- package/dist/client/head.d.ts +79 -0
- package/dist/client/head.js +261 -0
- package/dist/client/hydration.d.ts +45 -0
- package/dist/client/hydration.js +291 -0
- package/dist/client/link.d.ts +30 -0
- package/dist/client/link.js +188 -0
- package/dist/client/navigation.d.ts +28 -0
- package/dist/client/navigation.js +116 -0
- package/dist/client/router.d.ts +41 -0
- package/dist/client/router.js +190 -0
- package/dist/client/script.d.ts +51 -0
- package/dist/client/script.js +118 -0
- package/dist/components/client-island.d.ts +34 -0
- package/dist/components/client-island.js +75 -0
- package/dist/components/client.d.ts +29 -0
- package/dist/components/client.js +102 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +8 -0
- package/dist/components/link.d.ts +6 -0
- package/dist/components/link.js +13 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.js +31 -0
- package/dist/dev-error.d.ts +35 -0
- package/dist/dev-error.js +310 -0
- package/dist/image/get-img-props.d.ts +28 -0
- package/dist/image/get-img-props.js +49 -0
- package/dist/image/image-config.d.ts +20 -0
- package/dist/image/image-config.js +20 -0
- package/dist/image/image-loader.d.ts +7 -0
- package/dist/image/image-loader.js +14 -0
- package/dist/image/index.d.ts +6 -0
- package/dist/image/index.js +110 -0
- package/dist/image.d.ts +10 -0
- package/dist/image.js +7 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +53 -0
- package/dist/metadata/generate.d.ts +22 -0
- package/dist/metadata/generate.js +324 -0
- package/dist/metadata/index.d.ts +7 -0
- package/dist/metadata/index.js +26 -0
- package/dist/metadata/types.d.ts +325 -0
- package/dist/metadata/types.js +15 -0
- package/dist/router/context.d.ts +8 -0
- package/dist/router/context.js +13 -0
- package/dist/router/index.d.ts +2 -0
- package/dist/router/index.js +18 -0
- package/dist/router/provider.d.ts +5 -0
- package/dist/router/provider.js +31 -0
- package/dist/server/client-boundary.d.ts +48 -0
- package/dist/server/client-boundary.js +133 -0
- package/dist/server/engine.d.ts +4 -0
- package/dist/server/engine.js +651 -0
- package/dist/server/index.d.ts +95 -0
- package/dist/server/index.js +177 -0
- package/dist/server/rsc-engine.d.ts +20 -0
- package/dist/server/rsc-engine.js +588 -0
- package/dist/server/rsc-module-system.d.ts +33 -0
- package/dist/server/rsc-module-system.js +119 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +2 -0
- package/package.json +103 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Vista Client Reference Plugin
|
|
4
|
+
*
|
|
5
|
+
* Webpack plugin that transforms server component imports in the client bundle.
|
|
6
|
+
*
|
|
7
|
+
* When a client bundle imports a server component, this plugin:
|
|
8
|
+
* 1. Replaces the import with a client reference proxy
|
|
9
|
+
* 2. The proxy throws an error if used on the client (server components can't run on client)
|
|
10
|
+
* 3. For valid patterns (passing server component as children), the reference works
|
|
11
|
+
*
|
|
12
|
+
* This ensures:
|
|
13
|
+
* - Server code never leaks to the client bundle
|
|
14
|
+
* - Server components contribute 0kb to client JavaScript
|
|
15
|
+
* - Clear error messages when misusing server components
|
|
16
|
+
*/
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.ClientReferencePlugin = void 0;
|
|
22
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
23
|
+
const path_1 = __importDefault(require("path"));
|
|
24
|
+
const fs_1 = __importDefault(require("fs"));
|
|
25
|
+
/**
|
|
26
|
+
* Virtual module that provides server component proxies
|
|
27
|
+
* These proxies throw helpful errors when server components are incorrectly used client-side
|
|
28
|
+
*/
|
|
29
|
+
const SERVER_COMPONENT_PROXY = `
|
|
30
|
+
// Vista Server Component Proxy
|
|
31
|
+
// This module is injected when a client bundle tries to import a server component
|
|
32
|
+
|
|
33
|
+
export function createServerComponentProxy(id, name) {
|
|
34
|
+
const proxy = function ServerComponentProxy(props) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
\`[Vista] Cannot render server component "\${name}" on the client.\n\` +
|
|
37
|
+
\`Server components can only be rendered on the server.\n\n\` +
|
|
38
|
+
\`To fix this:\n\` +
|
|
39
|
+
\`1. If you need interactivity, add 'client load' at the top of the component file\n\` +
|
|
40
|
+
\`2. If passing as children, ensure the parent is a client component\n\` +
|
|
41
|
+
\`\nComponent ID: \${id}\`
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
proxy.$$typeof = Symbol.for('vista.server.reference');
|
|
46
|
+
proxy.$$id = id;
|
|
47
|
+
proxy.$$name = name;
|
|
48
|
+
|
|
49
|
+
return proxy;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default createServerComponentProxy;
|
|
53
|
+
`;
|
|
54
|
+
/**
|
|
55
|
+
* Check if a file is a client component by reading 'client load' directive
|
|
56
|
+
*/
|
|
57
|
+
function isClientComponent(filePath) {
|
|
58
|
+
try {
|
|
59
|
+
const content = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
60
|
+
const trimmed = content.trim();
|
|
61
|
+
return trimmed.startsWith("'client load'") || trimmed.startsWith('"client load"');
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Client Reference Plugin
|
|
69
|
+
*
|
|
70
|
+
* Transforms imports of server components in the client bundle
|
|
71
|
+
*/
|
|
72
|
+
class ClientReferencePlugin {
|
|
73
|
+
appDir;
|
|
74
|
+
clientManifestPath;
|
|
75
|
+
clientManifest = null;
|
|
76
|
+
constructor(options) {
|
|
77
|
+
this.appDir = options.appDir;
|
|
78
|
+
this.clientManifestPath = options.clientManifestPath;
|
|
79
|
+
}
|
|
80
|
+
apply(compiler) {
|
|
81
|
+
const pluginName = 'VistaClientReferencePlugin';
|
|
82
|
+
// Load client manifest
|
|
83
|
+
compiler.hooks.beforeCompile.tap(pluginName, () => {
|
|
84
|
+
this.loadManifest();
|
|
85
|
+
});
|
|
86
|
+
// Provide virtual module for server component proxies
|
|
87
|
+
compiler.hooks.normalModuleFactory.tap(pluginName, (nmf) => {
|
|
88
|
+
nmf.hooks.beforeResolve.tap(pluginName, (resolveData) => {
|
|
89
|
+
if (!resolveData)
|
|
90
|
+
return;
|
|
91
|
+
// Check if this is importing a server component from client code
|
|
92
|
+
const request = resolveData.request;
|
|
93
|
+
if (request === 'vista/server-component-proxy') {
|
|
94
|
+
// Virtual module - allow it to continue
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
nmf.hooks.afterResolve.tap(pluginName, (resolveData) => {
|
|
99
|
+
if (!resolveData || !resolveData.createData)
|
|
100
|
+
return;
|
|
101
|
+
const resourcePath = resolveData.createData.resource;
|
|
102
|
+
if (!resourcePath)
|
|
103
|
+
return;
|
|
104
|
+
// Check if this is a file in the app directory
|
|
105
|
+
if (!resourcePath.startsWith(this.appDir))
|
|
106
|
+
return;
|
|
107
|
+
// Check if this is a TypeScript/JavaScript file
|
|
108
|
+
if (!/\.[jt]sx?$/.test(resourcePath))
|
|
109
|
+
return;
|
|
110
|
+
// Check if this is a server component (NOT a client component)
|
|
111
|
+
if (!isClientComponent(resourcePath)) {
|
|
112
|
+
// This is a server component being imported in client bundle
|
|
113
|
+
// We need to replace it with a proxy
|
|
114
|
+
// Mark it for replacement (use any to add custom properties)
|
|
115
|
+
resolveData.createData.vistaServerComponent = true;
|
|
116
|
+
resolveData.createData.vistaComponentId = this.getComponentId(resourcePath);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
// Transform the module content for server components
|
|
121
|
+
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
122
|
+
// Add the server component proxy to the beginning of affected modules
|
|
123
|
+
compilation.hooks.succeedModule.tap(pluginName, (module) => {
|
|
124
|
+
if (module.vistaServerComponent) {
|
|
125
|
+
// This module is a server component - it should be replaced with a proxy
|
|
126
|
+
// In practice, we handle this via the loader
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
// Add a loader to handle server component replacement
|
|
131
|
+
compiler.options.module?.rules?.push({
|
|
132
|
+
test: /\.[jt]sx?$/,
|
|
133
|
+
include: this.appDir,
|
|
134
|
+
enforce: 'pre',
|
|
135
|
+
use: [
|
|
136
|
+
{
|
|
137
|
+
loader: require.resolve('./server-component-loader'),
|
|
138
|
+
options: {
|
|
139
|
+
appDir: this.appDir,
|
|
140
|
+
clientManifestPath: this.clientManifestPath,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
});
|
|
145
|
+
// Generate client reference manifest for runtime
|
|
146
|
+
compiler.hooks.emit.tap(pluginName, (compilation) => {
|
|
147
|
+
if (this.clientManifest) {
|
|
148
|
+
const runtimeManifest = this.generateRuntimeManifest();
|
|
149
|
+
const manifestSource = JSON.stringify(runtimeManifest, null, 2);
|
|
150
|
+
compilation.emitAsset('client-reference-manifest.json', new webpack_1.default.sources.RawSource(manifestSource));
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
loadManifest() {
|
|
155
|
+
try {
|
|
156
|
+
if (fs_1.default.existsSync(this.clientManifestPath)) {
|
|
157
|
+
const content = fs_1.default.readFileSync(this.clientManifestPath, 'utf-8');
|
|
158
|
+
this.clientManifest = JSON.parse(content);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
console.warn('[Vista] Failed to load client manifest:', e);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
getComponentId(filePath) {
|
|
166
|
+
const relative = path_1.default.relative(this.appDir, filePath);
|
|
167
|
+
return `server:${relative.replace(/\\/g, '/').replace(/\.[jt]sx?$/, '')}`;
|
|
168
|
+
}
|
|
169
|
+
generateRuntimeManifest() {
|
|
170
|
+
if (!this.clientManifest)
|
|
171
|
+
return {};
|
|
172
|
+
return {
|
|
173
|
+
clientModules: Object.keys(this.clientManifest.clientModules).reduce((acc, key) => {
|
|
174
|
+
const entry = this.clientManifest.clientModules[key];
|
|
175
|
+
acc[key] = {
|
|
176
|
+
id: entry.id,
|
|
177
|
+
chunks: [entry.chunkName],
|
|
178
|
+
name: entry.exports[0] || 'default',
|
|
179
|
+
};
|
|
180
|
+
return acc;
|
|
181
|
+
}, {}),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.ClientReferencePlugin = ClientReferencePlugin;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RSC Webpack Compiler
|
|
3
|
+
*
|
|
4
|
+
* Creates separate webpack configurations for:
|
|
5
|
+
* 1. Server Bundle (.vista/server/) - All app code for SSR
|
|
6
|
+
* 2. Client Bundle (.vista/static/) - Only 'client load' components
|
|
7
|
+
*/
|
|
8
|
+
import webpack from 'webpack';
|
|
9
|
+
import { VistaDirs } from '../manifest';
|
|
10
|
+
export interface RSCCompilerOptions {
|
|
11
|
+
cwd: string;
|
|
12
|
+
isDev: boolean;
|
|
13
|
+
vistaDirs: VistaDirs;
|
|
14
|
+
buildId: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create Server-Side Webpack Configuration
|
|
18
|
+
*
|
|
19
|
+
* Builds ALL components for server-side rendering.
|
|
20
|
+
* Output goes to .vista/server/ and is NEVER sent to the client.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createServerWebpackConfig(options: RSCCompilerOptions): webpack.Configuration;
|
|
23
|
+
/**
|
|
24
|
+
* Create Client-Side Webpack Configuration (RSC-aware)
|
|
25
|
+
*
|
|
26
|
+
* ONLY bundles components marked with 'client load'.
|
|
27
|
+
* Server components are replaced with client references.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createClientWebpackConfig(options: RSCCompilerOptions): webpack.Configuration;
|
|
30
|
+
/**
|
|
31
|
+
* Run both server and client builds
|
|
32
|
+
*/
|
|
33
|
+
export declare function runRSCBuild(cwd: string, isDev: boolean): Promise<{
|
|
34
|
+
serverCompiler: webpack.Compiler;
|
|
35
|
+
clientCompiler: webpack.Compiler;
|
|
36
|
+
}>;
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* RSC Webpack Compiler
|
|
4
|
+
*
|
|
5
|
+
* Creates separate webpack configurations for:
|
|
6
|
+
* 1. Server Bundle (.vista/server/) - All app code for SSR
|
|
7
|
+
* 2. Client Bundle (.vista/static/) - Only 'client load' components
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.createServerWebpackConfig = createServerWebpackConfig;
|
|
47
|
+
exports.createClientWebpackConfig = createClientWebpackConfig;
|
|
48
|
+
exports.runRSCBuild = runRSCBuild;
|
|
49
|
+
const path_1 = __importDefault(require("path"));
|
|
50
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
51
|
+
const fs_1 = __importDefault(require("fs"));
|
|
52
|
+
const manifest_1 = require("../manifest");
|
|
53
|
+
const client_reference_plugin_1 = require("./client-reference-plugin");
|
|
54
|
+
const client_manifest_1 = require("./client-manifest");
|
|
55
|
+
const server_manifest_1 = require("./server-manifest");
|
|
56
|
+
// Find module path (handles monorepo hoisting)
|
|
57
|
+
const findModulePath = (moduleName, cwd) => {
|
|
58
|
+
const localPath = path_1.default.resolve(cwd, 'node_modules', moduleName);
|
|
59
|
+
if (fs_1.default.existsSync(localPath)) {
|
|
60
|
+
return localPath;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
return path_1.default.dirname(require.resolve(`${moduleName}/package.json`, { paths: [cwd] }));
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return path_1.default.dirname(require.resolve(`${moduleName}/package.json`));
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Create Server-Side Webpack Configuration
|
|
71
|
+
*
|
|
72
|
+
* Builds ALL components for server-side rendering.
|
|
73
|
+
* Output goes to .vista/server/ and is NEVER sent to the client.
|
|
74
|
+
*/
|
|
75
|
+
function createServerWebpackConfig(options) {
|
|
76
|
+
const { cwd, isDev, vistaDirs, buildId } = options;
|
|
77
|
+
// Generate server manifest first
|
|
78
|
+
const serverManifest = (0, server_manifest_1.generateServerManifest)(cwd, path_1.default.join(cwd, 'app'));
|
|
79
|
+
fs_1.default.writeFileSync(path_1.default.join(vistaDirs.server, 'server-manifest.json'), JSON.stringify(serverManifest, null, 2));
|
|
80
|
+
return {
|
|
81
|
+
mode: isDev ? 'development' : 'production',
|
|
82
|
+
name: 'server',
|
|
83
|
+
target: 'node',
|
|
84
|
+
// Entry: All pages and layouts for SSR
|
|
85
|
+
entry: () => {
|
|
86
|
+
const entries = {};
|
|
87
|
+
const appDir = path_1.default.join(cwd, 'app');
|
|
88
|
+
// Scan for all page.tsx, layout.tsx files
|
|
89
|
+
function scanDir(dir, prefix = '') {
|
|
90
|
+
if (!fs_1.default.existsSync(dir))
|
|
91
|
+
return;
|
|
92
|
+
const items = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
93
|
+
for (const item of items) {
|
|
94
|
+
if (item.isDirectory()) {
|
|
95
|
+
if (!item.name.startsWith('.') && item.name !== 'node_modules') {
|
|
96
|
+
scanDir(path_1.default.join(dir, item.name), prefix + item.name + '/');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (item.isFile()) {
|
|
100
|
+
const ext = path_1.default.extname(item.name);
|
|
101
|
+
const base = path_1.default.basename(item.name, ext);
|
|
102
|
+
if (['.tsx', '.ts', '.jsx', '.js'].includes(ext)) {
|
|
103
|
+
if (['page', 'layout', 'loading', 'error', 'not-found', 'root', 'index'].includes(base)) {
|
|
104
|
+
const entryName = (prefix + base).replace(/\//g, '_') || 'root';
|
|
105
|
+
entries[entryName] = path_1.default.join(dir, item.name);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
scanDir(appDir);
|
|
112
|
+
return entries;
|
|
113
|
+
},
|
|
114
|
+
output: {
|
|
115
|
+
path: path_1.default.join(vistaDirs.server, 'app'),
|
|
116
|
+
filename: '[name].js',
|
|
117
|
+
libraryTarget: 'commonjs2',
|
|
118
|
+
clean: !isDev,
|
|
119
|
+
},
|
|
120
|
+
externals: [
|
|
121
|
+
// Don't bundle node_modules on server
|
|
122
|
+
({ request }, callback) => {
|
|
123
|
+
if (request &&
|
|
124
|
+
!request.startsWith('.') &&
|
|
125
|
+
!request.startsWith('/') &&
|
|
126
|
+
!path_1.default.isAbsolute(request)) {
|
|
127
|
+
// External - don't bundle
|
|
128
|
+
return callback(null, 'commonjs ' + request);
|
|
129
|
+
}
|
|
130
|
+
callback();
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
cache: isDev ? (0, manifest_1.getWebpackCacheConfig)(vistaDirs.root, buildId, 'server-development') : false,
|
|
134
|
+
resolve: {
|
|
135
|
+
extensions: ['.tsx', '.ts', '.jsx', '.js'],
|
|
136
|
+
modules: [path_1.default.resolve(cwd, 'node_modules'), 'node_modules'],
|
|
137
|
+
},
|
|
138
|
+
module: {
|
|
139
|
+
rules: [
|
|
140
|
+
{
|
|
141
|
+
test: /\.[jt]sx?$/,
|
|
142
|
+
exclude: /node_modules/,
|
|
143
|
+
use: {
|
|
144
|
+
loader: 'swc-loader',
|
|
145
|
+
options: {
|
|
146
|
+
jsc: {
|
|
147
|
+
parser: {
|
|
148
|
+
syntax: 'typescript',
|
|
149
|
+
tsx: true,
|
|
150
|
+
},
|
|
151
|
+
transform: {
|
|
152
|
+
react: {
|
|
153
|
+
runtime: 'automatic',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
target: 'es2020',
|
|
157
|
+
},
|
|
158
|
+
module: {
|
|
159
|
+
type: 'commonjs',
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
test: /\.css$/,
|
|
166
|
+
use: 'null-loader', // CSS handled separately
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
plugins: [
|
|
171
|
+
new webpack_1.default.DefinePlugin({
|
|
172
|
+
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
|
|
173
|
+
__VISTA_BUILD_ID__: JSON.stringify(buildId),
|
|
174
|
+
__VISTA_SERVER__: 'true',
|
|
175
|
+
}),
|
|
176
|
+
],
|
|
177
|
+
devtool: isDev ? 'source-map' : false,
|
|
178
|
+
stats: 'minimal',
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Create Client-Side Webpack Configuration (RSC-aware)
|
|
183
|
+
*
|
|
184
|
+
* ONLY bundles components marked with 'client load'.
|
|
185
|
+
* Server components are replaced with client references.
|
|
186
|
+
*/
|
|
187
|
+
function createClientWebpackConfig(options) {
|
|
188
|
+
const { cwd, isDev, vistaDirs, buildId } = options;
|
|
189
|
+
// Generate client manifest
|
|
190
|
+
const clientManifest = (0, client_manifest_1.generateClientManifest)(cwd, path_1.default.join(cwd, 'app'));
|
|
191
|
+
fs_1.default.writeFileSync(path_1.default.join(vistaDirs.root, 'client-manifest.json'), JSON.stringify(clientManifest, null, 2));
|
|
192
|
+
const reactPath = findModulePath('react', cwd);
|
|
193
|
+
const reactDomPath = findModulePath('react-dom', cwd);
|
|
194
|
+
// Entry: Only client components
|
|
195
|
+
const clientEntry = path_1.default.join(vistaDirs.root, 'rsc-client.tsx');
|
|
196
|
+
return {
|
|
197
|
+
mode: isDev ? 'development' : 'production',
|
|
198
|
+
name: 'client',
|
|
199
|
+
target: 'web',
|
|
200
|
+
entry: isDev
|
|
201
|
+
? ['webpack-hot-middleware/client?reload=true&overlay=true', clientEntry]
|
|
202
|
+
: clientEntry,
|
|
203
|
+
output: {
|
|
204
|
+
path: vistaDirs.chunks,
|
|
205
|
+
filename: isDev ? 'main.js' : 'main-[contenthash:8].js',
|
|
206
|
+
chunkFilename: isDev ? '[name].js' : '[name]-[contenthash:8].js',
|
|
207
|
+
publicPath: '/_vista/static/chunks/',
|
|
208
|
+
clean: !isDev,
|
|
209
|
+
},
|
|
210
|
+
cache: isDev ? (0, manifest_1.getWebpackCacheConfig)(vistaDirs.root, buildId, 'client-rsc-development') : false,
|
|
211
|
+
resolve: {
|
|
212
|
+
extensions: ['.tsx', '.ts', '.jsx', '.js'],
|
|
213
|
+
alias: {
|
|
214
|
+
react: reactPath,
|
|
215
|
+
'react-dom': reactDomPath,
|
|
216
|
+
'react/jsx-runtime': path_1.default.join(reactPath, 'jsx-runtime'),
|
|
217
|
+
'react/jsx-dev-runtime': path_1.default.join(reactPath, 'jsx-dev-runtime'),
|
|
218
|
+
},
|
|
219
|
+
modules: [path_1.default.resolve(cwd, 'node_modules'), 'node_modules'],
|
|
220
|
+
},
|
|
221
|
+
optimization: {
|
|
222
|
+
splitChunks: {
|
|
223
|
+
chunks: 'all',
|
|
224
|
+
cacheGroups: {
|
|
225
|
+
framework: {
|
|
226
|
+
name: 'framework',
|
|
227
|
+
test: /[\\/]node_modules[\\/](react|react-dom|scheduler)[\\/]/,
|
|
228
|
+
priority: 40,
|
|
229
|
+
chunks: 'all',
|
|
230
|
+
enforce: true,
|
|
231
|
+
},
|
|
232
|
+
vendor: {
|
|
233
|
+
name: 'vendor',
|
|
234
|
+
test: /[\\/]node_modules[\\/]/,
|
|
235
|
+
priority: 30,
|
|
236
|
+
chunks: 'all',
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
runtimeChunk: {
|
|
241
|
+
name: 'webpack',
|
|
242
|
+
},
|
|
243
|
+
moduleIds: isDev ? 'named' : 'deterministic',
|
|
244
|
+
chunkIds: isDev ? 'named' : 'deterministic',
|
|
245
|
+
},
|
|
246
|
+
module: {
|
|
247
|
+
rules: [
|
|
248
|
+
{
|
|
249
|
+
test: /\.[jt]sx?$/,
|
|
250
|
+
exclude: /node_modules/,
|
|
251
|
+
use: {
|
|
252
|
+
loader: 'swc-loader',
|
|
253
|
+
options: {
|
|
254
|
+
jsc: {
|
|
255
|
+
parser: {
|
|
256
|
+
syntax: 'typescript',
|
|
257
|
+
tsx: true,
|
|
258
|
+
dynamicImport: true,
|
|
259
|
+
},
|
|
260
|
+
transform: {
|
|
261
|
+
react: {
|
|
262
|
+
runtime: 'automatic',
|
|
263
|
+
development: isDev,
|
|
264
|
+
refresh: isDev,
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
target: 'es2020',
|
|
268
|
+
},
|
|
269
|
+
module: {
|
|
270
|
+
type: 'es6',
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
test: /\.css$/,
|
|
277
|
+
use: 'null-loader',
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
},
|
|
281
|
+
plugins: [
|
|
282
|
+
// Replace server component imports with client references
|
|
283
|
+
new client_reference_plugin_1.ClientReferencePlugin({
|
|
284
|
+
appDir: path_1.default.join(cwd, 'app'),
|
|
285
|
+
clientManifestPath: path_1.default.join(vistaDirs.root, 'client-manifest.json'),
|
|
286
|
+
}),
|
|
287
|
+
new webpack_1.default.DefinePlugin({
|
|
288
|
+
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
|
|
289
|
+
__VISTA_BUILD_ID__: JSON.stringify(buildId),
|
|
290
|
+
__VISTA_SERVER__: 'false',
|
|
291
|
+
}),
|
|
292
|
+
...(isDev ? [new webpack_1.default.HotModuleReplacementPlugin()] : []),
|
|
293
|
+
],
|
|
294
|
+
devtool: isDev ? 'eval-cheap-module-source-map' : 'source-map',
|
|
295
|
+
stats: 'minimal',
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Run both server and client builds
|
|
300
|
+
*/
|
|
301
|
+
async function runRSCBuild(cwd, isDev) {
|
|
302
|
+
const { createVistaDirectories, getBuildId } = await Promise.resolve().then(() => __importStar(require('../manifest')));
|
|
303
|
+
const vistaDirs = createVistaDirectories(cwd);
|
|
304
|
+
const buildId = getBuildId(vistaDirs.root, !isDev);
|
|
305
|
+
const options = { cwd, isDev, vistaDirs, buildId };
|
|
306
|
+
const serverConfig = createServerWebpackConfig(options);
|
|
307
|
+
const clientConfig = createClientWebpackConfig(options);
|
|
308
|
+
const serverCompiler = (0, webpack_1.default)(serverConfig);
|
|
309
|
+
const clientCompiler = (0, webpack_1.default)(clientConfig);
|
|
310
|
+
return { serverCompiler, clientCompiler };
|
|
311
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vista RSC (React Server Components) Build System
|
|
3
|
+
*
|
|
4
|
+
* This module implements the True RSC Architecture:
|
|
5
|
+
* 1. Server components render on the server and contribute 0kb to client bundle
|
|
6
|
+
* 2. Client components are marked with 'client load' and hydrate on the browser
|
|
7
|
+
* 3. Strict separation ensures server secrets never leak to client
|
|
8
|
+
*
|
|
9
|
+
* Performance: Uses Rust-powered native scanning when available
|
|
10
|
+
*/
|
|
11
|
+
export * from './compiler';
|
|
12
|
+
export * from './client-manifest';
|
|
13
|
+
export * from './server-manifest';
|
|
14
|
+
export * from './rsc-renderer';
|
|
15
|
+
export * from './client-reference-plugin';
|
|
16
|
+
export * from './native-scanner';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Vista RSC (React Server Components) Build System
|
|
4
|
+
*
|
|
5
|
+
* This module implements the True RSC Architecture:
|
|
6
|
+
* 1. Server components render on the server and contribute 0kb to client bundle
|
|
7
|
+
* 2. Client components are marked with 'client load' and hydrate on the browser
|
|
8
|
+
* 3. Strict separation ensures server secrets never leak to client
|
|
9
|
+
*
|
|
10
|
+
* Performance: Uses Rust-powered native scanning when available
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
24
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
__exportStar(require("./compiler"), exports);
|
|
28
|
+
__exportStar(require("./client-manifest"), exports);
|
|
29
|
+
__exportStar(require("./server-manifest"), exports);
|
|
30
|
+
__exportStar(require("./rsc-renderer"), exports);
|
|
31
|
+
__exportStar(require("./client-reference-plugin"), exports);
|
|
32
|
+
__exportStar(require("./native-scanner"), exports);
|