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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../plugin/components.tsx"],"sourcesContent":["import { createElement } from 'react';\n\n/**\n * A component that emits <link> tags for CSS files during streaming.\n * The high precedence ensures they bubble up to the document head.\n */\nexport function CssCollector({ url, moduleBasePath }: { url: string, moduleBasePath: string }) {\n return createElement('link', {\n key: url,\n rel: 'stylesheet',\n href: url,\n precedence: 'high'\n });\n} "],"names":[],"mappings":";;;;;;;AAMO,SAAS,YAAa,CAAA,EAAE,GAAK,EAAA,cAAA,EAA2D,EAAA;AAC7F,EAAA,OAAO,cAAc,MAAQ,EAAA;AAAA,IAC3B,GAAK,EAAA,GAAA;AAAA,IACL,GAAK,EAAA,YAAA;AAAA,IACL,IAAM,EAAA,GAAA;AAAA,IACN,UAAY,EAAA;AAAA,GACb,CAAA;AACH;;;;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Worker } from 'worker_threads';
|
|
2
|
-
import type { InputNormalizerWorker } from '../types.js';
|
|
3
|
-
type ClientNormalizerOptions = {
|
|
4
|
-
rscWorker: Worker;
|
|
5
|
-
};
|
|
6
|
-
export declare const createClientInputNormalizer: ({ rscWorker }: ClientNormalizerOptions) => InputNormalizerWorker;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=createClientInputNormalizer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createClientInputNormalizer.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/createClientInputNormalizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,KAAK,uBAAuB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,2BAA2B,kBAErC,uBAAuB,KAAG,qBAsC5B,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export const createClientInputNormalizer = ({ rscWorker }) => {
|
|
2
|
-
return async (input) => {
|
|
3
|
-
// Handle string
|
|
4
|
-
if (typeof input === "string") {
|
|
5
|
-
return [input, input];
|
|
6
|
-
}
|
|
7
|
-
// Handle React component
|
|
8
|
-
if (typeof input === "function") {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
const handler = (message) => {
|
|
11
|
-
if (message.type === "CLIENT_REFERENCE") {
|
|
12
|
-
rscWorker.off('message', handler);
|
|
13
|
-
resolve([message.ref.$$id, message.ref.$$location]);
|
|
14
|
-
}
|
|
15
|
-
if (message.type === "ERROR") {
|
|
16
|
-
rscWorker.off('message', handler);
|
|
17
|
-
reject(new Error(message.error));
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
rscWorker.on('message', handler);
|
|
21
|
-
rscWorker.postMessage({
|
|
22
|
-
type: "CLIENT_REFERENCE",
|
|
23
|
-
id: input.name || 'AnonymousComponent',
|
|
24
|
-
location: input.toString(),
|
|
25
|
-
key: input.name
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
// Handle arrays
|
|
30
|
-
if (Array.isArray(input)) {
|
|
31
|
-
return [input[0], input[0]];
|
|
32
|
-
}
|
|
33
|
-
throw new Error('Invalid client input type');
|
|
34
|
-
};
|
|
35
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Worker } from "node:worker_threads";
|
|
2
|
-
import type { InputNormalizerWorker } from "../types.js";
|
|
3
|
-
interface ServerNormalizerOptions {
|
|
4
|
-
root: string;
|
|
5
|
-
htmlWorker: Worker;
|
|
6
|
-
}
|
|
7
|
-
export declare function createServerInputNormalizer({ root, htmlWorker }: ServerNormalizerOptions): InputNormalizerWorker;
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=createServerInputNormalizer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createServerInputNormalizer.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/createServerInputNormalizer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,UAAU,uBAAuB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,2BAA2B,CAAC,EAC1C,IAAI,EACJ,UAAU,EACX,EAAE,uBAAuB,GAAG,qBAAqB,CAuCjD"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
export function createServerInputNormalizer({ root, htmlWorker }) {
|
|
3
|
-
return async (input) => {
|
|
4
|
-
// Handle React components with worker
|
|
5
|
-
if (typeof input === "function") {
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
-
const handler = (message) => {
|
|
8
|
-
if (message.type === "CLIENT_REFERENCE") {
|
|
9
|
-
htmlWorker.off('message', handler);
|
|
10
|
-
resolve([message.ref.$$id, message.ref.$$location]);
|
|
11
|
-
}
|
|
12
|
-
if (message.type === "ERROR") {
|
|
13
|
-
htmlWorker.off('message', handler);
|
|
14
|
-
reject(new Error(message.error));
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
htmlWorker.on('message', handler);
|
|
18
|
-
htmlWorker.postMessage({
|
|
19
|
-
type: "CLIENT_REFERENCE",
|
|
20
|
-
id: input.name || 'AnonymousComponent',
|
|
21
|
-
location: input.toString(),
|
|
22
|
-
key: input.name
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
// Handle tuple input [key, path]
|
|
27
|
-
if (Array.isArray(input)) {
|
|
28
|
-
const [key, path] = input;
|
|
29
|
-
return [key, join(root, path)];
|
|
30
|
-
}
|
|
31
|
-
// Handle string input
|
|
32
|
-
if (typeof input === "string") {
|
|
33
|
-
return [input, join(root, input)];
|
|
34
|
-
}
|
|
35
|
-
throw new Error(`Invalid input type: ${typeof input}`);
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { InputNormalizer } from "../types.js";
|
|
2
|
-
interface StaticNormalizerOptions {
|
|
3
|
-
root: string;
|
|
4
|
-
}
|
|
5
|
-
export declare function createStaticInputNormalizer({ root }: StaticNormalizerOptions): InputNormalizer;
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=createStaticInputNormalizer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createStaticInputNormalizer.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/createStaticInputNormalizer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,UAAU,uBAAuB;IAC/B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,2BAA2B,CAAC,EAAE,IAAI,EAAE,EAAE,uBAAuB,GAAG,eAAe,CAkB9F"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
export function createStaticInputNormalizer({ root }) {
|
|
3
|
-
return (input) => {
|
|
4
|
-
// Handle tuple input [key, path]
|
|
5
|
-
if (Array.isArray(input)) {
|
|
6
|
-
const [key, path] = input;
|
|
7
|
-
// Keep the key as-is for Rollup entry point naming
|
|
8
|
-
// Just resolve the path relative to root
|
|
9
|
-
return [key, join(root, path)];
|
|
10
|
-
}
|
|
11
|
-
// Handle string input
|
|
12
|
-
if (typeof input === "string") {
|
|
13
|
-
// For single string inputs, let Rollup handle the naming
|
|
14
|
-
return [input, join(root, input)];
|
|
15
|
-
}
|
|
16
|
-
throw new Error(`Invalid input type: ${typeof input}`);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { PluginContext } from 'rollup';
|
|
2
|
-
interface ModuleManifestEntry {
|
|
3
|
-
file: string;
|
|
4
|
-
name: string;
|
|
5
|
-
src?: string;
|
|
6
|
-
isEntry?: boolean;
|
|
7
|
-
imports?: string[];
|
|
8
|
-
dynamicImports?: string[];
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Get the module manifest from the plugin context, will only work during development
|
|
12
|
-
* @param this - The plugin context
|
|
13
|
-
* @returns The module manifest
|
|
14
|
-
*/
|
|
15
|
-
export declare function getModuleManifest(this: PluginContext): Record<string, ModuleManifestEntry>;
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=getModuleManifest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getModuleManifest.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/getModuleManifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,aAAa,EAAE,MAAM,QAAQ,CAAC;AAExD,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAmB1F"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the module manifest from the plugin context, will only work during development
|
|
3
|
-
* @param this - The plugin context
|
|
4
|
-
* @returns The module manifest
|
|
5
|
-
*/
|
|
6
|
-
export function getModuleManifest() {
|
|
7
|
-
const manifest = {};
|
|
8
|
-
// Build module graph from plugin context
|
|
9
|
-
for (const id of this.getModuleIds()) {
|
|
10
|
-
const info = this.getModuleInfo(id);
|
|
11
|
-
if (!info)
|
|
12
|
-
continue;
|
|
13
|
-
manifest[id] = {
|
|
14
|
-
file: info.id,
|
|
15
|
-
src: info.id,
|
|
16
|
-
name: id,
|
|
17
|
-
isEntry: info.isEntry,
|
|
18
|
-
imports: Array.from(info.importedIds),
|
|
19
|
-
dynamicImports: Array.from(info.dynamicallyImportedIds)
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return manifest;
|
|
23
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Worker } from "node:worker_threads";
|
|
2
|
-
import type { InputNormalizerWorker } from "../types.js";
|
|
3
|
-
interface WorkerNormalizerOptions {
|
|
4
|
-
root: string;
|
|
5
|
-
moduleBase: string;
|
|
6
|
-
worker: Worker;
|
|
7
|
-
moduleBaseExceptions?: string[];
|
|
8
|
-
preserveModulesRoot: boolean | undefined;
|
|
9
|
-
}
|
|
10
|
-
export declare function createInputNormalizerWorker({ root, moduleBase, worker, preserveModulesRoot, }: WorkerNormalizerOptions): InputNormalizerWorker;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=inputNormalizerWorker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inputNormalizerWorker.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/inputNormalizerWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAmB,MAAM,aAAa,CAAC;AAG1E,UAAU,uBAAuB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,mBAAmB,EAAE,OAAO,GAAG,SAAS,CAAC;CAC1C;AAED,wBAAgB,2BAA2B,CAAC,EAC1C,IAAI,EACJ,UAAU,EACV,MAAM,EACN,mBAAmB,GACpB,EAAE,uBAAuB,GAAG,qBAAqB,CAkCjD"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createInputNormalizer } from "./inputNormalizer.js";
|
|
2
|
-
export function createInputNormalizerWorker({ root, moduleBase, worker, preserveModulesRoot, }) {
|
|
3
|
-
const baseNormalizer = createInputNormalizer({
|
|
4
|
-
root,
|
|
5
|
-
preserveModulesRoot: preserveModulesRoot === true ? moduleBase : undefined,
|
|
6
|
-
});
|
|
7
|
-
return async (input) => {
|
|
8
|
-
// Handle React components specially with worker
|
|
9
|
-
if (typeof input === "function") {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
const handler = (message) => {
|
|
12
|
-
if (message.type === "CLIENT_REFERENCE") {
|
|
13
|
-
worker.off("message", handler);
|
|
14
|
-
resolve([message.ref.$$id, message.ref.$$location]);
|
|
15
|
-
}
|
|
16
|
-
if (message.type === "ERROR") {
|
|
17
|
-
worker.off("message", handler);
|
|
18
|
-
reject(new Error(message.error));
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
worker.on("message", handler);
|
|
22
|
-
worker.postMessage({
|
|
23
|
-
type: "CLIENT_REFERENCE",
|
|
24
|
-
id: input.name || "AnonymousComponent",
|
|
25
|
-
location: input.toString(),
|
|
26
|
-
key: input.name,
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
// For all other types, use the base normalizer
|
|
31
|
-
return baseNormalizer(input);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type NormalizedRelativePathOptions = {
|
|
2
|
-
root: string;
|
|
3
|
-
outDir: string;
|
|
4
|
-
moduleBase: string;
|
|
5
|
-
noLeadingSlash: boolean;
|
|
6
|
-
noTrailingSlash: boolean;
|
|
7
|
-
moduleBaseExceptions: string[];
|
|
8
|
-
};
|
|
9
|
-
export declare const createNormalizedRelativePath: (options?: NormalizedRelativePathOptions) => (path: string) => string;
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=normalizedRelativePath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normalizedRelativePath.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/normalizedRelativePath.ts"],"names":[],"mappings":"AAEA,KAAK,6BAA6B,GAAG;IAEnC,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IAEnB,cAAc,EAAE,OAAO,CAAC;IAExB,eAAe,EAAE,OAAO,CAAC;IAEzB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,4BAA4B,aAC9B,6BAA6B,YAuCxB,MAAM,WACrB,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { normalizePath } from "vite";
|
|
2
|
-
export const createNormalizedRelativePath = (options = {
|
|
3
|
-
root: process.cwd(),
|
|
4
|
-
outDir: "dist",
|
|
5
|
-
moduleBase: "src",
|
|
6
|
-
noLeadingSlash: false,
|
|
7
|
-
noTrailingSlash: false,
|
|
8
|
-
moduleBaseExceptions: [],
|
|
9
|
-
}) => {
|
|
10
|
-
let base = options.noLeadingSlash && options.moduleBase.startsWith("/")
|
|
11
|
-
? options.moduleBase.slice(1)
|
|
12
|
-
: options.moduleBase;
|
|
13
|
-
if (options.noTrailingSlash && base.endsWith("/")) {
|
|
14
|
-
base = base.slice(0, -1);
|
|
15
|
-
}
|
|
16
|
-
const removeOutDir = (path) => options.outDir === path
|
|
17
|
-
? path.slice(options.outDir.length)
|
|
18
|
-
: path;
|
|
19
|
-
const removeRoot = (path) => {
|
|
20
|
-
const relative = path.startsWith(options.root)
|
|
21
|
-
? path.slice(options.root.length)
|
|
22
|
-
: path;
|
|
23
|
-
return relative;
|
|
24
|
-
};
|
|
25
|
-
const ensureModuleBase = (path) => {
|
|
26
|
-
let transformed = path;
|
|
27
|
-
if (options.noLeadingSlash && path.startsWith("/")) {
|
|
28
|
-
transformed = path.slice(1);
|
|
29
|
-
}
|
|
30
|
-
if (options.noTrailingSlash && transformed.endsWith("/")) {
|
|
31
|
-
transformed = transformed.slice(0, -1);
|
|
32
|
-
}
|
|
33
|
-
return transformed;
|
|
34
|
-
};
|
|
35
|
-
return (path) => ensureModuleBase(removeOutDir(removeRoot(normalizePath(path))));
|
|
36
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type ResolveOptions = {
|
|
2
|
-
projectRoot?: string;
|
|
3
|
-
nodePath?: string;
|
|
4
|
-
pluginRoot?: string;
|
|
5
|
-
filePath: string;
|
|
6
|
-
subDir?: string;
|
|
7
|
-
normalize?: boolean;
|
|
8
|
-
distDir?: string;
|
|
9
|
-
mode?: "production" | "development" | "test";
|
|
10
|
-
};
|
|
11
|
-
export declare function resolveFilePath({ projectRoot, nodePath, mode, pluginRoot, distDir, filePath, subDir, normalize, }: ResolveOptions): Promise<string>;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=resolveFilePath.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolveFilePath.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/resolveFilePath.ts"],"names":[],"mappings":"AAMA,KAAK,cAAc,GAAG;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,CAAC;CAC9C,CAAC;AAEF,wBAAsB,eAAe,CAAC,EACpC,WAA2B,EAC3B,QAAmC,EACnC,IAAgB,EAChB,UAA4B,EAC5B,OAA0B,EAC1B,QAAQ,EACR,MAAM,EACN,SAAiB,GAClB,EAAE,cAAc,mBAiFhB"}
|
|
@@ -1,74 +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
|
-
export async function resolveFilePath({ projectRoot = process.cwd(), nodePath = getNodePath(projectRoot), mode = getMode(), pluginRoot = getPluginRoot(), distDir = getDistDir(mode), filePath, subDir, normalize = false, }) {
|
|
7
|
-
try {
|
|
8
|
-
let resolvedPath;
|
|
9
|
-
// Helper to check if file exists
|
|
10
|
-
const exists = async (path) => {
|
|
11
|
-
try {
|
|
12
|
-
await access(path);
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
// If it's a plugin export (like '/rsc-worker'), use exports map
|
|
20
|
-
if (filePath.startsWith('/') && filePath.slice(1) in pkg.exports) {
|
|
21
|
-
const exportPath = filePath.slice(1);
|
|
22
|
-
const pluginPath = pkg.exports[exportPath];
|
|
23
|
-
return join(process.cwd(), pluginRoot, pluginPath); // Make absolute
|
|
24
|
-
}
|
|
25
|
-
// In test mode, preserve relative paths
|
|
26
|
-
if (mode === 'test' && !filePath.startsWith('/')) {
|
|
27
|
-
return filePath;
|
|
28
|
-
}
|
|
29
|
-
// For all other paths, try relative to project root first
|
|
30
|
-
const projectPath = join(projectRoot, filePath);
|
|
31
|
-
if (await exists(projectPath)) {
|
|
32
|
-
return normalize ? normalizePath(projectPath) : projectPath;
|
|
33
|
-
}
|
|
34
|
-
// 1. Try dist folder
|
|
35
|
-
const distPath = join(distDir, subDir ?? '', basename(filePath));
|
|
36
|
-
if (await exists(distPath)) {
|
|
37
|
-
resolvedPath = await realpath(distPath);
|
|
38
|
-
}
|
|
39
|
-
// 2. Try node_modules path
|
|
40
|
-
if (!resolvedPath && filePath.startsWith('/node_modules/')) {
|
|
41
|
-
const npmPath = join(nodePath, filePath.slice('/node_modules/'.length));
|
|
42
|
-
if (await exists(npmPath)) {
|
|
43
|
-
resolvedPath = await realpath(npmPath);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// 3. Try direct path
|
|
47
|
-
if (!resolvedPath && await exists(filePath)) {
|
|
48
|
-
resolvedPath = await realpath(filePath);
|
|
49
|
-
}
|
|
50
|
-
// 4. Try relative to project root
|
|
51
|
-
if (!resolvedPath) {
|
|
52
|
-
const projectPath = join(projectRoot, filePath);
|
|
53
|
-
if (await exists(projectPath)) {
|
|
54
|
-
resolvedPath = await realpath(projectPath);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (!resolvedPath) {
|
|
58
|
-
throw new Error(`Could not resolve path. Tried:\n` +
|
|
59
|
-
`- ${distPath}\n` +
|
|
60
|
-
`- ${join(nodePath, filePath.slice('/node_modules/'.length))}\n` +
|
|
61
|
-
`- ${filePath}\n` +
|
|
62
|
-
`- ${join(projectRoot, filePath)}`);
|
|
63
|
-
}
|
|
64
|
-
return normalize ? normalizePath(resolvedPath
|
|
65
|
-
.replace(pluginRoot, "/node_modules/vite-plugin-react-server")
|
|
66
|
-
.replace(projectRoot, "/")
|
|
67
|
-
.replace(nodePath, "/node_modules")
|
|
68
|
-
.replace(/^(?!\/)/, '/')) : resolvedPath;
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
// If realpath fails, return normalized input path
|
|
72
|
-
return normalize ? normalizePath(filePath) : filePath;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolveWorkerModule.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/resolveWorkerModule.ts"],"names":[],"mappings":"AAEA,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,EACnC,OAAO,EAAE;IACP,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAA;CACnB,mBAgCF"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { tryManifest } from "./tryManifest.js";
|
|
2
|
-
export async function resolveWorkerModule(moduleGraph, options) {
|
|
3
|
-
console.log('Resolving worker module:', {
|
|
4
|
-
moduleGraph: Array.from(moduleGraph),
|
|
5
|
-
options
|
|
6
|
-
});
|
|
7
|
-
// Try module graph first
|
|
8
|
-
const workerModule = Array.from(moduleGraph).find(id => id.includes(options.workerPath));
|
|
9
|
-
console.log('Found in module graph:', workerModule);
|
|
10
|
-
if (workerModule) {
|
|
11
|
-
return workerModule;
|
|
12
|
-
}
|
|
13
|
-
// Fallback to manifest
|
|
14
|
-
const resolvedManifest = tryManifest({
|
|
15
|
-
root: options.root,
|
|
16
|
-
outDir: options.outDir,
|
|
17
|
-
ssrManifest: false
|
|
18
|
-
});
|
|
19
|
-
console.log('Manifest result:', resolvedManifest);
|
|
20
|
-
if (resolvedManifest.type === "error") {
|
|
21
|
-
throw new Error(`Could not find worker path in module graph or manifest: ${options.workerPath}`);
|
|
22
|
-
}
|
|
23
|
-
return resolvedManifest.manifest[options.workerPath]?.file;
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateModuleBase.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/validateModuleBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,MAAM,EAClB,oBAAoB,EAAE,MAAM,EAAE,QAwB/B"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export function validateModuleBase(input, moduleBase, moduleBaseExceptions) {
|
|
2
|
-
for (const [key, value] of Object.entries(input)) {
|
|
3
|
-
const isException = moduleBaseExceptions.includes(key) || ["/index", "index"].includes(key);
|
|
4
|
-
if (!key.includes("/"))
|
|
5
|
-
return;
|
|
6
|
-
if (value.startsWith("//")) {
|
|
7
|
-
throw new Error(`Path shouldn't start with //`);
|
|
8
|
-
}
|
|
9
|
-
if (!key.startsWith(moduleBase) && !isException) {
|
|
10
|
-
throw new Error(`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(", ")}`);
|
|
11
|
-
}
|
|
12
|
-
if (!value.startsWith("/" + moduleBase) && !isException) {
|
|
13
|
-
throw new Error(`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(", ")}`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateResolvedConfig.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/validateResolvedConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE3C,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,IAAI,cAAc,CAiB7F"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function validateResolvedConfig(config) {
|
|
2
|
-
if (typeof config === "object" &&
|
|
3
|
-
config != null &&
|
|
4
|
-
"build" in config &&
|
|
5
|
-
typeof config.build === "object" &&
|
|
6
|
-
config.build != null &&
|
|
7
|
-
"rollupOptions" in config.build &&
|
|
8
|
-
typeof config.build.rollupOptions === "object" &&
|
|
9
|
-
config.build.rollupOptions != null &&
|
|
10
|
-
"input" in config.build.rollupOptions &&
|
|
11
|
-
typeof config.build.rollupOptions.input === "object" &&
|
|
12
|
-
config.build.rollupOptions.input != null) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
throw new Error("Invalid config");
|
|
16
|
-
}
|
|
17
|
-
;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { PluginContext } from "rollup";
|
|
2
|
-
import type { ResolvedUserConfig, ResolvedUserOptions } from "../types.js";
|
|
3
|
-
import type { ConfigEnv } from "vite";
|
|
4
|
-
export declare function createClientComponentTransformer({ moduleBase, projectRoot, moduleId, build, }: ResolvedUserOptions, config: ResolvedUserConfig, configEnv: ConfigEnv): {
|
|
5
|
-
readonly name: "vite-plugin-react-server:client-components-transformer";
|
|
6
|
-
readonly transform: (this: PluginContext, code: string, id: string, options?: {
|
|
7
|
-
ssr?: boolean;
|
|
8
|
-
}) => Promise<{
|
|
9
|
-
code: string;
|
|
10
|
-
map: null;
|
|
11
|
-
} | null>;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* transformedCode += `
|
|
15
|
-
const ${exportName}Ref = Object.defineProperties(
|
|
16
|
-
${
|
|
17
|
-
isClass
|
|
18
|
-
? `class extends ${exportName} {
|
|
19
|
-
constructor(...args) { super(...args); }
|
|
20
|
-
}`
|
|
21
|
-
: `function(...args) { return ${exportName}.apply(null, args); }`
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
25
|
-
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} }
|
|
26
|
-
}
|
|
27
|
-
);
|
|
28
|
-
export { ${exportName}Ref as ${exportName} };`;
|
|
29
|
-
*/
|
|
30
|
-
//# sourceMappingURL=transformer-client-components.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transformer-client-components.d.ts","sourceRoot":"","sources":["../../../plugin/transformer/transformer-client-components.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAI5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAItC,wBAAgB,gCAAgC,CAC9C,EACE,UAAuC,EACvC,WAAW,EACX,QAAQ,EACR,KAAK,GACN,EAAE,mBAAmB,EACtB,MAAM,EAAE,kBAAkB,EAC1B,SAAS,EAAE,SAAS;;+BAsBV,aAAa,QACb,MAAM,MACR,MAAM,YACA;QAAE,GAAG,CAAC,EAAE,OAAO,CAAA;KAAE;;;;EA2GhC;AAED;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vite-plugin-react-server
|
|
3
|
-
* Copyright (c) Nico Brinkkemper
|
|
4
|
-
* MIT License
|
|
5
|
-
*/
|
|
6
|
-
import { DEFAULT_CONFIG } from '../config/defaults.js';
|
|
7
|
-
import { createInputNormalizer } from '../helpers/inputNormalizer.js';
|
|
8
|
-
import { join } from 'path';
|
|
9
|
-
import { tryManifest } from '../helpers/tryManifest.js';
|
|
10
|
-
|
|
11
|
-
function createClientComponentTransformer({
|
|
12
|
-
moduleBase = DEFAULT_CONFIG.MODULE_BASE,
|
|
13
|
-
projectRoot,
|
|
14
|
-
moduleId,
|
|
15
|
-
build
|
|
16
|
-
}, config, configEnv) {
|
|
17
|
-
let moduleIdFn = moduleId;
|
|
18
|
-
const normalizer = createInputNormalizer({
|
|
19
|
-
root: projectRoot,
|
|
20
|
-
preserveModulesRoot: moduleBase,
|
|
21
|
-
removeExtension: true
|
|
22
|
-
});
|
|
23
|
-
config.build.outDir?.endsWith(build.client);
|
|
24
|
-
const isServer = config.build.outDir?.endsWith(build.server);
|
|
25
|
-
isServer ? tryManifest({
|
|
26
|
-
root: projectRoot,
|
|
27
|
-
outDir: join(build.outDir, build.client),
|
|
28
|
-
ssrManifest: false
|
|
29
|
-
}).manifest : null;
|
|
30
|
-
return {
|
|
31
|
-
name: "vite-plugin-react-server:client-components-transformer",
|
|
32
|
-
async transform(code, id, options) {
|
|
33
|
-
try {
|
|
34
|
-
if (id.includes("node_modules") || id.includes("vite/dist")) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
let rest = id.split("/");
|
|
38
|
-
let fileName = rest.pop();
|
|
39
|
-
let dir = rest.join("/");
|
|
40
|
-
if (dir.startsWith(projectRoot)) {
|
|
41
|
-
dir = dir.replace(projectRoot, "");
|
|
42
|
-
}
|
|
43
|
-
const index = dir.indexOf(moduleBase);
|
|
44
|
-
if (index !== -1) {
|
|
45
|
-
if (configEnv.command === "build") {
|
|
46
|
-
if (isServer) {
|
|
47
|
-
dir = join(build.assetsDir, dir.slice(index + moduleBase.length));
|
|
48
|
-
} else {
|
|
49
|
-
dir = new URL(
|
|
50
|
-
dir,
|
|
51
|
-
`file://${config?.server?.host ?? "localhost"}:${config?.server?.port ?? configEnv.isPreview ? 4173 : 5173}`
|
|
52
|
-
).pathname;
|
|
53
|
-
}
|
|
54
|
-
} else if (configEnv.command === "serve") {
|
|
55
|
-
dir = "";
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (!fileName) fileName = id;
|
|
59
|
-
const info = this?.getModuleInfo(id);
|
|
60
|
-
const hasDirective = code.match(/^["']use client["'];?/);
|
|
61
|
-
const isClientComponent = hasDirective || info?.meta?.["directives"]?.includes("use client");
|
|
62
|
-
if (!isClientComponent) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
let transformedCode = code;
|
|
66
|
-
const moduleId2 = moduleIdFn(id, configEnv.isSsrBuild ?? false);
|
|
67
|
-
const [key, value] = normalizer([moduleId2, id]);
|
|
68
|
-
const exportMatches = Array.from(
|
|
69
|
-
code.matchAll(/export\s+(?:const|let|var|function|class)\s+(\w+)/g)
|
|
70
|
-
);
|
|
71
|
-
if (!exportMatches.length) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
for (const [fullMatch, exportName] of exportMatches) {
|
|
75
|
-
if (!exportName) continue;
|
|
76
|
-
console.log("exportName", dir, fileName, exportName);
|
|
77
|
-
const isClass = fullMatch.includes("class");
|
|
78
|
-
transformedCode = transformedCode.replace(
|
|
79
|
-
fullMatch,
|
|
80
|
-
fullMatch.replace("export ", "")
|
|
81
|
-
);
|
|
82
|
-
let path = `import.meta.url`;
|
|
83
|
-
const { manifest, error } = tryManifest({
|
|
84
|
-
root: projectRoot,
|
|
85
|
-
outDir: join(build.outDir, build.client),
|
|
86
|
-
ssrManifest: false
|
|
87
|
-
});
|
|
88
|
-
if (error) {
|
|
89
|
-
console.error(`[RSC] Error getting manifest: ${error}`);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
const fileFromManifest = manifest[join(moduleBase, value)]?.file;
|
|
93
|
-
if (fileFromManifest) {
|
|
94
|
-
path = JSON.stringify(fileFromManifest);
|
|
95
|
-
} else {
|
|
96
|
-
console.error(`[RSC] File not found in manifest: ${value}`);
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
transformedCode += `const ${exportName}Ref = Object.defineProperties(${isClass ? `class extends ${exportName} {
|
|
100
|
-
constructor(...args) { super(...args); }
|
|
101
|
-
}` : `function(...args) { return ${exportName}.apply(null, args); }`},
|
|
102
|
-
{
|
|
103
|
-
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
104
|
-
$$id: { value: \`\${${path}}${"#" + exportName}\` }
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
export { ${exportName}Ref as ${exportName} };`;
|
|
108
|
-
}
|
|
109
|
-
return { code: transformedCode, map: null };
|
|
110
|
-
} catch (error) {
|
|
111
|
-
console.error(
|
|
112
|
-
`[RSC] Error transforming client component: ${id}`,
|
|
113
|
-
error
|
|
114
|
-
);
|
|
115
|
-
throw error;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export { createClientComponentTransformer };
|
|
122
|
-
//# sourceMappingURL=transformer-client-components.js.map
|