vite-plugin-react-server 0.3.11 → 0.3.12
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/dist/package.json +15 -11
- package/dist/plugin/checkFilesExist.d.ts +2 -2
- package/dist/plugin/checkFilesExist.d.ts.map +1 -1
- package/dist/plugin/checkFilesExist.js +39 -57
- package/dist/plugin/checkFilesExist.js.map +1 -1
- package/dist/plugin/collect-css-manifest.d.ts.map +1 -1
- package/dist/plugin/collect-css-manifest.js +5 -0
- package/dist/plugin/collect-css-manifest.js.map +1 -1
- package/dist/plugin/components.js +10 -15
- package/dist/plugin/config/createModuleIdGenerator.js +1 -1
- package/dist/plugin/config/createModuleIdGenerator.js.map +1 -1
- package/dist/plugin/config/defaults.d.ts +5 -14
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +12 -12
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getPaths.js +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +73 -52
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +53 -65
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts +6 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +48 -19
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts +1 -2
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +52 -46
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +29 -26
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.d.ts +16 -0
- package/dist/plugin/loader/css-loader.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.js +70 -0
- package/dist/plugin/loader/css-loader.js.map +1 -0
- package/dist/plugin/loader/react-loader.d.ts +17 -0
- package/dist/plugin/loader/react-loader.d.ts.map +1 -0
- package/dist/plugin/loader/react-loader.js +647 -0
- package/dist/plugin/loader/react-loader.js.map +1 -0
- package/dist/plugin/loader/rsc/messageHandler.d.ts +2 -0
- package/dist/plugin/loader/rsc/messageHandler.d.ts.map +1 -0
- package/dist/plugin/loader/rsc/messageHandler.js +1 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +2 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +1 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.js +1 -0
- package/dist/plugin/react-client/index.js +2 -2
- package/dist/plugin/react-client/index.js.map +1 -1
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +202 -25
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createHandler.js +10 -4
- package/dist/plugin/react-server/createHandler.js.map +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts +15 -3
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
- package/dist/plugin/react-server/createRscStream.js +52 -49
- package/dist/plugin/react-server/createRscStream.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +24 -20
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +65 -52
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/types.d.ts +5 -0
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/utils/logger.d.ts +9 -0
- package/dist/plugin/utils/logger.d.ts.map +1 -0
- package/dist/plugin/utils/logger.js +68 -0
- package/dist/plugin/utils/logger.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +1 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +23 -36
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +5 -1
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +10 -19
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/renderPages.d.ts +2 -2
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +130 -131
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/rsc/index.d.ts +1 -3
- package/dist/plugin/worker/rsc/index.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/index.js +1 -9
- package/dist/plugin/worker/rsc/index.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts +3 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.js +107 -0
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -0
- package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/plugin.js +74 -80
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +32 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js +43 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.js +4 -106
- package/dist/plugin/worker/rsc/rsc-worker.production.d.ts +2 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.js +14 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -0
- package/dist/plugin/worker/rsc/state.d.ts +11 -0
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/state.js +12 -0
- package/dist/plugin/worker/rsc/state.js.map +1 -0
- package/dist/plugin/worker/types.d.ts +60 -46
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -11
- package/plugin/checkFilesExist.ts +42 -62
- package/plugin/collect-css-manifest.ts +5 -1
- package/plugin/config/createModuleIdGenerator.ts +1 -1
- package/plugin/config/defaults.ts +13 -15
- package/plugin/config/resolveOptions.ts +134 -76
- package/plugin/config/resolveUserConfig.ts +75 -76
- package/plugin/helpers/getBundleManifest.ts +69 -31
- package/plugin/helpers/inputNormalizer.ts +82 -70
- package/plugin/helpers/tryManifest.ts +1 -1
- package/plugin/loader/createBuildLoader.ts +38 -41
- package/plugin/loader/css-loader.ts +96 -0
- package/plugin/loader/react-loader.ts +945 -0
- package/plugin/loader/rsc/messageHandler.tsx +1 -0
- package/plugin/loader/rsc/rsc-worker.development.ts +1 -0
- package/plugin/react-client/index.ts +1 -1
- package/plugin/react-client/plugin.ts +266 -41
- package/plugin/react-server/createHandler.ts +9 -5
- package/plugin/react-server/createRscStream.ts +75 -54
- package/plugin/react-server/plugin.ts +26 -21
- package/plugin/transformer/plugin.ts +67 -76
- package/plugin/types/global.d.ts +8 -0
- package/plugin/types.ts +2 -0
- package/plugin/utils/logger.ts +52 -0
- package/plugin/worker/createWorker.ts +43 -44
- package/plugin/worker/html/html-worker.production.tsx +7 -2
- package/plugin/worker/html/messageHandler.ts +13 -21
- package/plugin/worker/html/renderPages.ts +146 -179
- package/plugin/worker/rsc/index.ts +4 -13
- package/plugin/worker/rsc/messageHandler.tsx +143 -0
- package/plugin/worker/rsc/plugin.ts +38 -37
- package/plugin/worker/rsc/rsc-worker.development.ts +107 -0
- package/plugin/worker/rsc/rsc-worker.production.ts +13 -0
- package/plugin/worker/rsc/rsc-worker.tsx +5 -128
- package/plugin/worker/rsc/state.ts +37 -0
- package/plugin/worker/types.ts +79 -55
- package/scripts/check-react-version.mjs +17 -7
- package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +143 -4170
- package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +14271 -90079
- package/dist/plugin/components.js.map +0 -1
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts +0 -8
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createClientInputNormalizer.js +0 -35
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts +0 -9
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createServerInputNormalizer.js +0 -37
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +0 -7
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createStaticInputNormalizer.js +0 -18
- package/dist/plugin/helpers/getModuleManifest.d.ts +0 -17
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +0 -1
- package/dist/plugin/helpers/getModuleManifest.js +0 -23
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +0 -12
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.js +0 -33
- package/dist/plugin/helpers/normalizedRelativePath.d.ts +0 -11
- package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +0 -1
- package/dist/plugin/helpers/normalizedRelativePath.js +0 -36
- package/dist/plugin/helpers/resolveFilePath.d.ts +0 -13
- package/dist/plugin/helpers/resolveFilePath.d.ts.map +0 -1
- package/dist/plugin/helpers/resolveFilePath.js +0 -74
- package/dist/plugin/helpers/resolveWorkerModule.d.ts +0 -6
- package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +0 -1
- package/dist/plugin/helpers/resolveWorkerModule.js +0 -24
- package/dist/plugin/helpers/validateModuleBase.d.ts +0 -3
- package/dist/plugin/helpers/validateModuleBase.d.ts.map +0 -1
- package/dist/plugin/helpers/validateModuleBase.js +0 -16
- package/dist/plugin/helpers/validateResolvedConfig.d.ts +0 -3
- package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +0 -1
- package/dist/plugin/helpers/validateResolvedConfig.js +0 -17
- package/dist/plugin/transformer/transformer-client-components.d.ts +0 -30
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-client-components.js +0 -122
- package/dist/plugin/transformer/transformer-client-components.js.map +0 -1
- package/dist/plugin/transformer/transformer-server-actions.d.ts +0 -29
- package/dist/plugin/transformer/transformer-server-actions.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-server-actions.js +0 -90
- package/dist/plugin/worker/rsc/createRscStream.d.ts +0 -5
- package/dist/plugin/worker/rsc/createRscStream.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/createRscStream.js +0 -39
- package/dist/plugin/worker/rsc/createRscStream.js.map +0 -1
- package/dist/plugin/worker/rsc/development.d.ts +0 -5
- package/dist/plugin/worker/rsc/development.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/development.js +0 -13
- package/dist/plugin/worker/rsc/development.js.map +0 -1
- package/dist/plugin/worker/rsc/plugin.js.map +0 -1
- package/dist/plugin/worker/rsc/production.d.ts +0 -5
- package/dist/plugin/worker/rsc/production.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/production.js +0 -13
- package/dist/plugin/worker/rsc/production.js.map +0 -1
- package/plugin/helpers/createClientInputNormalizer.ts +0 -48
- package/plugin/helpers/createServerInputNormalizer.ts +0 -52
- package/plugin/helpers/createStaticInputNormalizer.ts +0 -26
- package/plugin/helpers/getModuleManifest.ts +0 -36
- package/plugin/helpers/inputNormalizerWorker.ts +0 -52
- package/plugin/helpers/normalizedRelativePath.ts +0 -59
- package/plugin/helpers/resolveFilePath.ts +0 -108
- package/plugin/helpers/resolveWorkerModule.ts +0 -41
- package/plugin/helpers/validateModuleBase.ts +0 -30
- package/plugin/helpers/validateResolvedConfig.ts +0 -21
- package/plugin/transformer/transformer-client-components.ts +0 -168
- package/plugin/transformer/transformer-server-actions.ts +0 -125
- package/plugin/worker/rsc/createRscStream.ts +0 -42
- package/plugin/worker/rsc/development.ts +0 -6
- package/plugin/worker/rsc/production.ts +0 -6
- package/scripts/react-server-dom-esm+0.0.1.patch +0 -24775
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { join, basename } from "node:path";
|
|
2
|
-
import { access, realpath } from "node:fs/promises";
|
|
3
|
-
import { normalizePath } from "vite";
|
|
4
|
-
import { getDistDir, getMode, getNodePath, getPluginRoot } from "../config/getPaths.js";
|
|
5
|
-
import pkg from "../../package.json" with { type: 'json' };
|
|
6
|
-
|
|
7
|
-
type ResolveOptions = {
|
|
8
|
-
projectRoot?: string;
|
|
9
|
-
nodePath?: string;
|
|
10
|
-
pluginRoot?: string;
|
|
11
|
-
filePath: string;
|
|
12
|
-
subDir?: string;
|
|
13
|
-
normalize?: boolean;
|
|
14
|
-
distDir?: string;
|
|
15
|
-
mode?: "production" | "development" | "test";
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export async function resolveFilePath({
|
|
19
|
-
projectRoot = process.cwd(),
|
|
20
|
-
nodePath = getNodePath(projectRoot),
|
|
21
|
-
mode = getMode(),
|
|
22
|
-
pluginRoot = getPluginRoot(),
|
|
23
|
-
distDir = getDistDir(mode),
|
|
24
|
-
filePath,
|
|
25
|
-
subDir,
|
|
26
|
-
normalize = false,
|
|
27
|
-
}: ResolveOptions) {
|
|
28
|
-
try {
|
|
29
|
-
let resolvedPath: string | undefined;
|
|
30
|
-
|
|
31
|
-
// Helper to check if file exists
|
|
32
|
-
const exists = async (path: string) => {
|
|
33
|
-
try {
|
|
34
|
-
await access(path);
|
|
35
|
-
return true;
|
|
36
|
-
} catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// If it's a plugin export (like '/rsc-worker'), use exports map
|
|
42
|
-
if (filePath.startsWith('/') && filePath.slice(1) in pkg.exports) {
|
|
43
|
-
const exportPath = filePath.slice(1);
|
|
44
|
-
const pluginPath = pkg.exports[exportPath as keyof typeof pkg.exports];
|
|
45
|
-
return join(process.cwd(), pluginRoot, pluginPath); // Make absolute
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// In test mode, preserve relative paths
|
|
49
|
-
if (mode === 'test' && !filePath.startsWith('/')) {
|
|
50
|
-
return filePath;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// For all other paths, try relative to project root first
|
|
54
|
-
const projectPath = join(projectRoot, filePath);
|
|
55
|
-
if (await exists(projectPath)) {
|
|
56
|
-
return normalize ? normalizePath(projectPath) : projectPath;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 1. Try dist folder
|
|
60
|
-
const distPath = join(distDir, subDir ?? '', basename(filePath));
|
|
61
|
-
if (await exists(distPath)) {
|
|
62
|
-
resolvedPath = await realpath(distPath);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// 2. Try node_modules path
|
|
66
|
-
if (!resolvedPath && filePath.startsWith('/node_modules/')) {
|
|
67
|
-
const npmPath = join(nodePath, filePath.slice('/node_modules/'.length));
|
|
68
|
-
if (await exists(npmPath)) {
|
|
69
|
-
resolvedPath = await realpath(npmPath);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// 3. Try direct path
|
|
74
|
-
if (!resolvedPath && await exists(filePath)) {
|
|
75
|
-
resolvedPath = await realpath(filePath);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 4. Try relative to project root
|
|
79
|
-
if (!resolvedPath) {
|
|
80
|
-
const projectPath = join(projectRoot, filePath);
|
|
81
|
-
if (await exists(projectPath)) {
|
|
82
|
-
resolvedPath = await realpath(projectPath);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (!resolvedPath) {
|
|
87
|
-
throw new Error(
|
|
88
|
-
`Could not resolve path. Tried:\n` +
|
|
89
|
-
`- ${distPath}\n` +
|
|
90
|
-
`- ${join(nodePath, filePath.slice('/node_modules/'.length))}\n` +
|
|
91
|
-
`- ${filePath}\n` +
|
|
92
|
-
`- ${join(projectRoot, filePath)}`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return normalize ? normalizePath(
|
|
97
|
-
resolvedPath
|
|
98
|
-
.replace(pluginRoot, "/node_modules/vite-plugin-react-server")
|
|
99
|
-
.replace(projectRoot, "/")
|
|
100
|
-
.replace(nodePath, "/node_modules")
|
|
101
|
-
.replace(/^(?!\/)/, '/')
|
|
102
|
-
) : resolvedPath;
|
|
103
|
-
|
|
104
|
-
} catch (error) {
|
|
105
|
-
// If realpath fails, return normalized input path
|
|
106
|
-
return normalize ? normalizePath(filePath) : filePath;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { tryManifest } from "./tryManifest.js";
|
|
2
|
-
|
|
3
|
-
export async function resolveWorkerModule(
|
|
4
|
-
moduleGraph: Set<string> | string[],
|
|
5
|
-
options: {
|
|
6
|
-
root: string,
|
|
7
|
-
outDir: string,
|
|
8
|
-
workerPath: string
|
|
9
|
-
}
|
|
10
|
-
) {
|
|
11
|
-
console.log('Resolving worker module:', {
|
|
12
|
-
moduleGraph: Array.from(moduleGraph),
|
|
13
|
-
options
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// Try module graph first
|
|
17
|
-
const workerModule = Array.from(moduleGraph).find(id =>
|
|
18
|
-
id.includes(options.workerPath)
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
console.log('Found in module graph:', workerModule);
|
|
22
|
-
|
|
23
|
-
if (workerModule) {
|
|
24
|
-
return workerModule;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Fallback to manifest
|
|
28
|
-
const resolvedManifest = tryManifest({
|
|
29
|
-
root: options.root,
|
|
30
|
-
outDir: options.outDir,
|
|
31
|
-
ssrManifest: false
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
console.log('Manifest result:', resolvedManifest);
|
|
35
|
-
|
|
36
|
-
if (resolvedManifest.type === "error") {
|
|
37
|
-
throw new Error(`Could not find worker path in module graph or manifest: ${options.workerPath}`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return resolvedManifest.manifest[options.workerPath]?.file;
|
|
41
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { InputOption } from "rollup";
|
|
2
|
-
|
|
3
|
-
export function validateModuleBase(
|
|
4
|
-
input: InputOption,
|
|
5
|
-
moduleBase: string,
|
|
6
|
-
moduleBaseExceptions: string[]
|
|
7
|
-
) {
|
|
8
|
-
for (const [key, value] of Object.entries(input)) {
|
|
9
|
-
const isException =
|
|
10
|
-
moduleBaseExceptions.includes(key) || ["/index", "index"].includes(key);
|
|
11
|
-
if (!key.includes("/")) return;
|
|
12
|
-
if (value.startsWith("//")) {
|
|
13
|
-
throw new Error(`Path shouldn't start with //`);
|
|
14
|
-
}
|
|
15
|
-
if (!key.startsWith(moduleBase) && !isException) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
`Invalid input: ${key} does not start with ${moduleBase}. If this is a valid key, add it to moduleBaseExceptions otherwise put the file in the ${moduleBase} directory. Exception: ${moduleBaseExceptions.join(
|
|
18
|
-
", "
|
|
19
|
-
)}`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
if (!value.startsWith("/" + moduleBase) && !isException) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
`Invalid value: ${value} does not start with ${moduleBase}. If this is a valid path, add it to moduleBaseExceptions otherwise put the file in the ${moduleBase} directory. Exception: ${moduleBaseExceptions.join(
|
|
25
|
-
", "
|
|
26
|
-
)}`
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ResolvedConfig } from "vite";
|
|
2
|
-
|
|
3
|
-
export function validateResolvedConfig(config: ResolvedConfig): asserts config is ResolvedConfig {
|
|
4
|
-
if (
|
|
5
|
-
typeof config === "object" &&
|
|
6
|
-
config != null &&
|
|
7
|
-
"build" in config &&
|
|
8
|
-
typeof config.build === "object" &&
|
|
9
|
-
config.build != null &&
|
|
10
|
-
"rollupOptions" in config.build &&
|
|
11
|
-
typeof config.build.rollupOptions === "object" &&
|
|
12
|
-
config.build.rollupOptions != null &&
|
|
13
|
-
"input" in config.build.rollupOptions &&
|
|
14
|
-
typeof config.build.rollupOptions.input === "object" &&
|
|
15
|
-
config.build.rollupOptions.input != null
|
|
16
|
-
) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
throw new Error("Invalid config");
|
|
20
|
-
};
|
|
21
|
-
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import type { PluginContext } from "rollup";
|
|
2
|
-
import type { TransformerOptions } from "./types.js";
|
|
3
|
-
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
4
|
-
import { createInputNormalizer } from "../helpers/inputNormalizer.js";
|
|
5
|
-
import type { ResolvedUserConfig, ResolvedUserOptions } from "../types.js";
|
|
6
|
-
import type { ConfigEnv } from "vite";
|
|
7
|
-
import { join } from "path";
|
|
8
|
-
import { tryManifest } from "../helpers/tryManifest.js";
|
|
9
|
-
|
|
10
|
-
export function createClientComponentTransformer(
|
|
11
|
-
{
|
|
12
|
-
moduleBase = DEFAULT_CONFIG.MODULE_BASE,
|
|
13
|
-
projectRoot,
|
|
14
|
-
moduleId,
|
|
15
|
-
build,
|
|
16
|
-
}: ResolvedUserOptions,
|
|
17
|
-
config: ResolvedUserConfig,
|
|
18
|
-
configEnv: ConfigEnv
|
|
19
|
-
) {
|
|
20
|
-
let moduleIdFn = moduleId;
|
|
21
|
-
const normalizer = createInputNormalizer({
|
|
22
|
-
root: projectRoot,
|
|
23
|
-
preserveModulesRoot: moduleBase,
|
|
24
|
-
removeExtension: true,
|
|
25
|
-
});
|
|
26
|
-
const isClient = config.build.outDir?.endsWith(build.client);
|
|
27
|
-
const isServer = config.build.outDir?.endsWith(build.server);
|
|
28
|
-
const references = isServer
|
|
29
|
-
? tryManifest({
|
|
30
|
-
root: projectRoot,
|
|
31
|
-
outDir: join(build.outDir, build.client),
|
|
32
|
-
ssrManifest: false,
|
|
33
|
-
}).manifest
|
|
34
|
-
: null;
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
name: "vite-plugin-react-server:client-components-transformer",
|
|
38
|
-
|
|
39
|
-
async transform(
|
|
40
|
-
this: PluginContext,
|
|
41
|
-
code: string,
|
|
42
|
-
id: string,
|
|
43
|
-
options?: { ssr?: boolean }
|
|
44
|
-
) {
|
|
45
|
-
try {
|
|
46
|
-
// Skip node_modules and vite internal files
|
|
47
|
-
if (id.includes("node_modules") || id.includes("vite/dist")) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Check if this is a client component from metadata or directive
|
|
52
|
-
let rest = id.split("/");
|
|
53
|
-
let fileName = rest.pop() as string;
|
|
54
|
-
let dir = rest.join("/");
|
|
55
|
-
if (dir.startsWith(projectRoot)) {
|
|
56
|
-
dir = dir.replace(projectRoot, "");
|
|
57
|
-
}
|
|
58
|
-
const index = dir.indexOf(moduleBase);
|
|
59
|
-
if (index !== -1) {
|
|
60
|
-
if (configEnv.command === "build") {
|
|
61
|
-
if (isServer) {
|
|
62
|
-
dir = join(build.assetsDir, dir.slice(index + moduleBase.length));
|
|
63
|
-
} else {
|
|
64
|
-
dir = new URL(
|
|
65
|
-
dir,
|
|
66
|
-
`file://${config?.server?.host ?? "localhost"}:${
|
|
67
|
-
config?.server?.port ?? configEnv.isPreview ? 4173 : 5173
|
|
68
|
-
}`
|
|
69
|
-
).pathname;
|
|
70
|
-
}
|
|
71
|
-
} else if (configEnv.command === "serve") {
|
|
72
|
-
dir = "";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (!fileName) fileName = id;
|
|
76
|
-
const info = this?.getModuleInfo(id);
|
|
77
|
-
const hasDirective = code.match(/^["']use client["'];?/);
|
|
78
|
-
const isClientComponent =
|
|
79
|
-
hasDirective || info?.meta?.["directives"]?.includes("use client");
|
|
80
|
-
|
|
81
|
-
if (!isClientComponent) {
|
|
82
|
-
return null; // Not a client component, skip
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
let transformedCode = code;
|
|
86
|
-
const moduleId = moduleIdFn!(id, configEnv.isSsrBuild ?? false);
|
|
87
|
-
const [key, value] = normalizer([moduleId, id]);
|
|
88
|
-
// Find all named exports
|
|
89
|
-
const exportMatches = Array.from(
|
|
90
|
-
code.matchAll(/export\s+(?:const|let|var|function|class)\s+(\w+)/g)
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
if (!exportMatches.length) {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Transform each export
|
|
98
|
-
for (const [fullMatch, exportName] of exportMatches) {
|
|
99
|
-
if (!exportName) continue;
|
|
100
|
-
console.log("exportName", dir, fileName, exportName);
|
|
101
|
-
const isClass = fullMatch.includes("class");
|
|
102
|
-
// Remove export keyword
|
|
103
|
-
transformedCode = transformedCode.replace(
|
|
104
|
-
fullMatch,
|
|
105
|
-
fullMatch.replace("export ", "")
|
|
106
|
-
);
|
|
107
|
-
let path = `import.meta.url`;
|
|
108
|
-
// path from moduleBase to value
|
|
109
|
-
const { manifest, error } = tryManifest({
|
|
110
|
-
root: projectRoot,
|
|
111
|
-
outDir: join(build.outDir, build.client),
|
|
112
|
-
ssrManifest: false,
|
|
113
|
-
});
|
|
114
|
-
if (error) {
|
|
115
|
-
console.error(`[RSC] Error getting manifest: ${error}`);
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
const fileFromManifest = manifest[join(moduleBase, value)]?.file;
|
|
119
|
-
if (fileFromManifest) {
|
|
120
|
-
path = JSON.stringify(fileFromManifest);
|
|
121
|
-
} else {
|
|
122
|
-
console.error(`[RSC] File not found in manifest: ${value}`);
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
transformedCode += `const ${exportName}Ref = Object.defineProperties(${
|
|
127
|
-
isClass
|
|
128
|
-
? `class extends ${exportName} {
|
|
129
|
-
constructor(...args) { super(...args); }
|
|
130
|
-
}`
|
|
131
|
-
: `function(...args) { return ${exportName}.apply(null, args); }`
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
135
|
-
$$id: { value: \`\${${path}}${"#" + exportName}\` }
|
|
136
|
-
}
|
|
137
|
-
);
|
|
138
|
-
export { ${exportName}Ref as ${exportName} };`;
|
|
139
|
-
}
|
|
140
|
-
return { code: transformedCode, map: null };
|
|
141
|
-
} catch (error) {
|
|
142
|
-
console.error(
|
|
143
|
-
`[RSC] Error transforming client component: ${id}`,
|
|
144
|
-
error
|
|
145
|
-
);
|
|
146
|
-
throw error;
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
} as const;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* transformedCode += `
|
|
154
|
-
const ${exportName}Ref = Object.defineProperties(
|
|
155
|
-
${
|
|
156
|
-
isClass
|
|
157
|
-
? `class extends ${exportName} {
|
|
158
|
-
constructor(...args) { super(...args); }
|
|
159
|
-
}`
|
|
160
|
-
: `function(...args) { return ${exportName}.apply(null, args); }`
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
164
|
-
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} }
|
|
165
|
-
}
|
|
166
|
-
);
|
|
167
|
-
export { ${exportName}Ref as ${exportName} };`;
|
|
168
|
-
*/
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { SourceMapGenerator } from "source-map";
|
|
2
|
-
import type { TransformerOptions } from "./types.js";
|
|
3
|
-
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
4
|
-
import type { ResolvedUserOptions, ResolvedUserConfig } from "../types.js";
|
|
5
|
-
import type { ConfigEnv } from "vite";
|
|
6
|
-
import { createInputNormalizer } from "../helpers/inputNormalizer.js";
|
|
7
|
-
|
|
8
|
-
export function createServerActionTransformer({
|
|
9
|
-
moduleBase = DEFAULT_CONFIG.MODULE_BASE,
|
|
10
|
-
projectRoot,
|
|
11
|
-
moduleId,
|
|
12
|
-
}: ResolvedUserOptions, config: ResolvedUserConfig, configEnv: ConfigEnv) {
|
|
13
|
-
let moduleIdFn = moduleId;
|
|
14
|
-
const normalizer = createInputNormalizer({
|
|
15
|
-
root: projectRoot,
|
|
16
|
-
preserveModulesRoot: moduleBase,
|
|
17
|
-
removeExtension: DEFAULT_CONFIG.FILE_REGEX,
|
|
18
|
-
});
|
|
19
|
-
return {
|
|
20
|
-
name: "vite-plugin-react-server:server-actions-transformer",
|
|
21
|
-
|
|
22
|
-
async transform(
|
|
23
|
-
code: string,
|
|
24
|
-
path: string,
|
|
25
|
-
{ ssr }: { ssr: boolean } = { ssr: false }
|
|
26
|
-
) {
|
|
27
|
-
try {
|
|
28
|
-
let transformedCode = code;
|
|
29
|
-
const directiveMatch = code.match(/^["']use server["'];?/);
|
|
30
|
-
const moduleId = moduleIdFn(path, ssr);
|
|
31
|
-
const [key,value] = normalizer(moduleId);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// Log the path transformation
|
|
35
|
-
console.log("[RSC Transform] Module path transformation:", {
|
|
36
|
-
original: path,
|
|
37
|
-
transformed: moduleId,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Find all named exports
|
|
41
|
-
const exportMatches = Array.from(
|
|
42
|
-
code.matchAll(/export\s+(?:const|let|var|function|class)\s+(\w+)/g)
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (!exportMatches.length) {
|
|
46
|
-
console.warn(
|
|
47
|
-
`[RSC] No exports found in server action module: ${path}`
|
|
48
|
-
);
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Transform each export
|
|
53
|
-
for (const [fullMatch, exportName] of exportMatches) {
|
|
54
|
-
if (!exportName) {
|
|
55
|
-
console.warn(
|
|
56
|
-
`[RSC] Invalid export in server action module: ${path}`
|
|
57
|
-
);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const isClass = fullMatch.includes("class");
|
|
62
|
-
|
|
63
|
-
// Remove export keyword
|
|
64
|
-
transformedCode = transformedCode.replace(
|
|
65
|
-
fullMatch,
|
|
66
|
-
fullMatch.replace("export ", "")
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
if (!directiveMatch || directiveMatch.index !== 0) {
|
|
70
|
-
// Server action
|
|
71
|
-
} else {
|
|
72
|
-
// Client component
|
|
73
|
-
transformedCode += `
|
|
74
|
-
const ${exportName}Ref = Object.defineProperties(
|
|
75
|
-
${
|
|
76
|
-
isClass
|
|
77
|
-
? `class extends ${exportName} {
|
|
78
|
-
constructor(...args) { super(...args); }
|
|
79
|
-
}`
|
|
80
|
-
: `function(...args) { return ${exportName}.apply(null, args); }`
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
$$typeof: { value: Symbol.for("react.server.reference") },
|
|
84
|
-
$$src: { value: ${JSON.stringify(value)} },
|
|
85
|
-
$$id: { value: import.meta.url.slice(import.meta.url.indexOf("/${key}")}) + ${JSON.stringify("#" + exportName)} },
|
|
86
|
-
$$async: { value: true }
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
export { ${exportName}Ref as ${exportName} };
|
|
90
|
-
`;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
code: transformedCode,
|
|
96
|
-
map: new SourceMapGenerator({ file: path }).toString(),
|
|
97
|
-
};
|
|
98
|
-
} catch (error) {
|
|
99
|
-
console.error(
|
|
100
|
-
`[RSC] Error transforming client component: ${path}`,
|
|
101
|
-
error
|
|
102
|
-
);
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* transformedCode += `
|
|
111
|
-
const ${exportName}Ref = Object.defineProperties(
|
|
112
|
-
${
|
|
113
|
-
isClass
|
|
114
|
-
? `class extends ${exportName} {
|
|
115
|
-
constructor(...args) { super(...args); }
|
|
116
|
-
}`
|
|
117
|
-
: `function(...args) { return ${exportName}.apply(null, args); }`
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
121
|
-
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} }
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
export { ${exportName}Ref as ${exportName} };`;
|
|
125
|
-
*/
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { renderToPipeableStream
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
} from "react-server-dom-esm/server.node";
|
|
4
|
-
import type { Writable } from "node:stream";
|
|
5
|
-
import type { MessagePort } from "node:worker_threads";
|
|
6
|
-
import type { RscRenderState } from "../types.js";
|
|
7
|
-
|
|
8
|
-
export function createRscStream(
|
|
9
|
-
renderState: RscRenderState,
|
|
10
|
-
writeStream: Writable,
|
|
11
|
-
parentPort: MessagePort | null
|
|
12
|
-
) {
|
|
13
|
-
console.log("[createRscStream] Creating stream for:", renderState.id);
|
|
14
|
-
|
|
15
|
-
const stream = renderToPipeableStream(renderState.componentImport, {
|
|
16
|
-
onShellReady() {
|
|
17
|
-
console.log("[createRscStream] onShellReady called for:", renderState.id);
|
|
18
|
-
stream.pipe(writeStream);
|
|
19
|
-
},
|
|
20
|
-
onAllReady() {
|
|
21
|
-
console.log("[createRscStream] onAllReady called for:", renderState.id);
|
|
22
|
-
writeStream.on("finish", () => {
|
|
23
|
-
parentPort?.postMessage({
|
|
24
|
-
type: "WROTE_FILE",
|
|
25
|
-
id: renderState.id,
|
|
26
|
-
outputPath: renderState.rscOutputPath
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
onError(error: unknown) {
|
|
31
|
-
console.error("[createRscStream] Render error:", error);
|
|
32
|
-
parentPort?.postMessage({
|
|
33
|
-
type: "ERROR",
|
|
34
|
-
error: error instanceof Error ? error.message : String(error),
|
|
35
|
-
id: renderState.id
|
|
36
|
-
});
|
|
37
|
-
stream.abort();
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return stream;
|
|
42
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { createRscStream as devCreateRscStream } from './createRscStream.js';
|
|
2
|
-
import { createWorker as devCreateWorker } from '../createWorker.js';
|
|
3
|
-
|
|
4
|
-
// Development-specific implementations
|
|
5
|
-
export const createRscStream = devCreateRscStream;
|
|
6
|
-
export const createWorker = devCreateWorker;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { createRscStream as prodCreateRscStream } from './createRscStream.js';
|
|
2
|
-
import { createWorker as prodCreateWorker } from '../createWorker.js';
|
|
3
|
-
|
|
4
|
-
// Production-specific optimizations could go here
|
|
5
|
-
export const createRscStream = prodCreateRscStream;
|
|
6
|
-
export const createWorker = prodCreateWorker;
|