vite-plugin-react-server 0.3.10 → 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/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/package.json +16 -14
- package/dist/plugin/assertServerCondition.d.ts +5 -1
- package/dist/plugin/assertServerCondition.d.ts.map +1 -1
- package/dist/plugin/assertServerCondition.js +1 -3
- package/dist/plugin/checkFilesExist.d.ts +2 -2
- package/dist/plugin/checkFilesExist.d.ts.map +1 -1
- package/dist/plugin/checkFilesExist.js +43 -58
- 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.d.ts +11 -0
- package/dist/plugin/config/createModuleIdGenerator.d.ts.map +1 -0
- package/dist/plugin/config/createModuleIdGenerator.js +44 -0
- package/dist/plugin/config/createModuleIdGenerator.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +27 -24
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +26 -31
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getPaths.js +1 -1
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +223 -16
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +2 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts +2 -2
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +149 -50
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts +25 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -0
- package/dist/plugin/helpers/getBundleManifest.js +72 -0
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts +14 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +128 -16
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts +3 -1
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +1 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +6 -2
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +37 -9
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/createPageLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createPageLoader.js +0 -7
- 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/plugin.d.ts +0 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +2 -1
- package/dist/plugin/preserver/plugin.d.ts.map +1 -1
- package/dist/plugin/preserver/plugin.js +3 -2
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/index.d.ts +2 -1
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +19 -1
- package/dist/plugin/react-client/index.js.map +1 -0
- package/dist/plugin/react-client/plugin.d.ts +2 -2
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +283 -10
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/createHandler.d.ts +2 -2
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createHandler.js +15 -9
- 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 +53 -36
- package/dist/plugin/react-server/createRscStream.js.map +1 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts +2 -2
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createSsrHandler.js +5 -12
- package/dist/plugin/react-server/index.js +18 -9
- package/dist/plugin/react-server/index.js.map +1 -0
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +147 -137
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.d.ts +2 -1
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +68 -75
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/types.d.ts +4 -0
- package/dist/plugin/transformer/types.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +56 -20
- 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 +33 -28
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/html/plugin.js +10 -5
- package/dist/plugin/worker/html/renderPages.d.ts +7 -6
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +147 -93
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/loader.d.ts +1 -11
- package/dist/plugin/worker/loader.d.ts.map +1 -1
- package/dist/plugin/worker/loader.js +2 -2
- package/dist/plugin/worker/loader.js.map +1 -1
- package/dist/plugin/worker/plugin.d.ts +10 -1
- package/dist/plugin/worker/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/plugin.js +10 -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 +62 -35
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.d.ts +1 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -3
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -14
- package/plugin/assertServerCondition.ts +2 -3
- package/plugin/checkFilesExist.ts +46 -66
- package/plugin/collect-css-manifest.ts +5 -1
- package/plugin/config/createModuleIdGenerator.ts +52 -0
- package/plugin/config/defaults.ts +27 -20
- package/plugin/config/resolveOptions.ts +311 -25
- package/plugin/config/resolvePages.ts +1 -1
- package/plugin/config/resolveUserConfig.ts +195 -61
- package/plugin/helpers/getBundleManifest.ts +113 -0
- package/plugin/helpers/inputNormalizer.ts +186 -25
- package/plugin/helpers/tryManifest.ts +3 -1
- package/plugin/loader/createBuildLoader.ts +50 -9
- package/plugin/loader/createPageLoader.ts +1 -7
- 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/plugin.ts +2 -1
- package/plugin/preserver/plugin.ts +2 -1
- package/plugin/react-client/index.ts +12 -1
- package/plugin/react-client/plugin.ts +351 -11
- package/plugin/react-server/createHandler.ts +16 -18
- package/plugin/react-server/createRscStream.ts +75 -42
- package/plugin/react-server/createSsrHandler.ts +7 -26
- package/plugin/react-server/plugin.ts +192 -155
- package/plugin/transformer/plugin.ts +70 -104
- package/plugin/transformer/types.ts +4 -0
- package/plugin/types/global.d.ts +8 -0
- package/plugin/types.ts +120 -64
- 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 +42 -35
- package/plugin/worker/html/plugin.ts +15 -11
- package/plugin/worker/html/renderPages.ts +177 -123
- package/plugin/worker/loader.ts +4 -13
- package/plugin/worker/plugin.ts +10 -1
- 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 +83 -38
- 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/node_modules/magic-string/dist/magic-string.es.js +0 -1283
- package/dist/node_modules/magic-string/dist/magic-string.es.js.map +0 -1
- package/dist/plugin/build/createClientBuildConfig.d.ts +0 -3
- package/dist/plugin/build/createClientBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createClientBuildConfig.js +0 -14
- package/dist/plugin/build/createServerBuildConfig.d.ts +0 -12
- package/dist/plugin/build/createServerBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createServerBuildConfig.js +0 -40
- package/dist/plugin/build/createSharedBuildConfig.d.ts +0 -5
- package/dist/plugin/build/createSharedBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createSharedBuildConfig.js +0 -28
- package/dist/plugin/build/mergeInputs.d.ts +0 -9
- package/dist/plugin/build/mergeInputs.d.ts.map +0 -1
- package/dist/plugin/build/mergeInputs.js +0 -56
- package/dist/plugin/components.js.map +0 -1
- package/dist/plugin/config/moduleIdDefault.d.ts +0 -8
- package/dist/plugin/config/moduleIdDefault.d.ts.map +0 -1
- package/dist/plugin/config/moduleIdDefault.js +0 -23
- package/dist/plugin/config/moduleIdDefault.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 -12
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +0 -1
- package/dist/plugin/helpers/getModuleManifest.js +0 -24
- package/dist/plugin/helpers/getModuleManifest.js.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +0 -11
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.js +0 -30
- 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/react-server/createDevMiddleware.d.ts +0 -8
- package/dist/plugin/react-server/createDevMiddleware.d.ts.map +0 -1
- package/dist/plugin/react-server/createDevMiddleware.js +0 -68
- package/dist/plugin/react-server/createDevServer.d.ts +0 -4
- package/dist/plugin/react-server/createDevServer.d.ts.map +0 -1
- package/dist/plugin/react-server/createDevServer.js +0 -4
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts +0 -10
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +0 -1
- package/dist/plugin/react-server/createReactNodeStreamer.js +0 -7
- package/dist/plugin/transformer/transformer-client-components.d.ts +0 -21
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-client-components.js +0 -61
- 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 -76
- package/dist/plugin/transformer/transformer-server-actions.js.map +0 -1
- 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/build/createClientBuildConfig.ts +0 -21
- package/plugin/build/createServerBuildConfig.ts +0 -66
- package/plugin/build/createSharedBuildConfig.ts +0 -35
- package/plugin/build/mergeInputs.ts +0 -58
- package/plugin/config/moduleIdDefault.ts +0 -23
- 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 -31
- package/plugin/helpers/inputNormalizerWorker.ts +0 -47
- 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/react-server/createDevMiddleware.ts +0 -91
- package/plugin/react-server/createDevServer.ts +0 -9
- package/plugin/react-server/createReactNodeStreamer.ts +0 -26
- package/plugin/transformer/transformer-client-components.ts +0 -94
- package/plugin/transformer/transformer-server-actions.ts +0 -110
- 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,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveOptions } from "../config/resolveOptions.js";
|
|
2
2
|
import type { StreamPluginOptions } from "../types.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { type Plugin } from "vite";
|
|
4
|
+
import { transformModuleIfNeeded } from "../loader/react-loader.js";
|
|
5
|
+
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
6
|
+
import { createInputNormalizer } from "../helpers/inputNormalizer.js";
|
|
7
|
+
import { tryManifest } from "../helpers/tryManifest.js";
|
|
8
|
+
import { join } from "node:path";
|
|
7
9
|
/**
|
|
8
10
|
* Plugin for transforming React Client Components.
|
|
9
11
|
*
|
|
@@ -29,113 +31,77 @@ import { createServerActionTransformer } from "./transformer-server-actions.js";
|
|
|
29
31
|
* ```
|
|
30
32
|
*/
|
|
31
33
|
|
|
32
|
-
export function reactTransformPlugin(
|
|
33
|
-
options
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
const projectRoot = options?.projectRoot || process.cwd();
|
|
44
|
-
// const includeClient = options?.autoDiscover?.clientComponents || DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents;
|
|
45
|
-
// const includeServerFunctions = options?.autoDiscover?.serverFunctions || DEFAULT_CONFIG.AUTO_DISCOVER.serverFunctions;
|
|
46
|
-
let transformClientComponent: any;
|
|
47
|
-
let transformServerAction: any;
|
|
48
|
-
// get the file we are imported from (parent)
|
|
34
|
+
export function reactTransformPlugin(options: StreamPluginOptions): Plugin {
|
|
35
|
+
const resolvedOptions = resolveOptions(options);
|
|
36
|
+
let isDev = false;
|
|
37
|
+
if (resolvedOptions.type === "error") throw resolvedOptions.error;
|
|
38
|
+
const normalizer = createInputNormalizer({
|
|
39
|
+
root: resolvedOptions.userOptions.projectRoot,
|
|
40
|
+
preserveModulesRoot: undefined,
|
|
41
|
+
removeExtension: false,
|
|
42
|
+
});
|
|
49
43
|
|
|
50
|
-
//
|
|
51
|
-
const
|
|
44
|
+
// Get the client manifest
|
|
45
|
+
const clientManifestResult = tryManifest({
|
|
46
|
+
root: resolvedOptions.userOptions.projectRoot,
|
|
47
|
+
outDir: join(
|
|
48
|
+
resolvedOptions.userOptions.build.outDir,
|
|
49
|
+
resolvedOptions.userOptions.build.client
|
|
50
|
+
),
|
|
51
|
+
ssrManifest: false,
|
|
52
|
+
});
|
|
52
53
|
|
|
53
54
|
return {
|
|
54
|
-
name: "vite:react-
|
|
55
|
-
enforce: "
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
transformClientComponent = createClientComponentTransformer({
|
|
59
|
-
moduleId:
|
|
60
|
-
options?.moduleId ||
|
|
61
|
-
DEFAULT_CONFIG.MODULE_ID({
|
|
62
|
-
projectRoot: projectRoot,
|
|
63
|
-
output: {
|
|
64
|
-
dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server,
|
|
65
|
-
},
|
|
66
|
-
isProduction: config.isProduction,
|
|
67
|
-
}),
|
|
68
|
-
}).transform;
|
|
69
|
-
transformServerAction = createServerActionTransformer({
|
|
70
|
-
moduleId:
|
|
71
|
-
options?.moduleId ||
|
|
72
|
-
DEFAULT_CONFIG.MODULE_ID({
|
|
73
|
-
projectRoot: projectRoot,
|
|
74
|
-
output: {
|
|
75
|
-
dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server,
|
|
76
|
-
},
|
|
77
|
-
isProduction: config.isProduction,
|
|
78
|
-
}),
|
|
79
|
-
}).transform;
|
|
55
|
+
name: "vite:react-transform",
|
|
56
|
+
enforce: "pre", // Run before Vite's transforms
|
|
57
|
+
config(config, configEnv) {
|
|
58
|
+
isDev = configEnv.mode === "development" && configEnv.command === "serve";
|
|
80
59
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
...acc,
|
|
94
|
-
[path.replace(DEFAULT_CONFIG.FILE_REGEX, "")]: path,
|
|
95
|
-
}),
|
|
96
|
-
{}
|
|
60
|
+
async transform(code, id, options) {
|
|
61
|
+
const ssr = options?.ssr ?? false;
|
|
62
|
+
if (!ssr) return null;
|
|
63
|
+
if (!id.match(DEFAULT_CONFIG.FILE_REGEX)) return null;
|
|
64
|
+
if (!code.match('"use client"'))
|
|
65
|
+
return null;
|
|
66
|
+
const [key, value] = normalizer(id);
|
|
67
|
+
const transformed = await transformModuleIfNeeded(
|
|
68
|
+
code,
|
|
69
|
+
id,
|
|
70
|
+
// Pass null for nextLoad since we don't need module loading in the plugin
|
|
71
|
+
null
|
|
97
72
|
);
|
|
73
|
+
if (!transformed) return null;
|
|
74
|
+
if (isDev) {
|
|
75
|
+
return {
|
|
76
|
+
code: transformed,
|
|
77
|
+
map: null,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const moduleIdIndex = transformed.indexOf(value);
|
|
81
|
+
if (moduleIdIndex === -1) {
|
|
82
|
+
console.warn(
|
|
83
|
+
`[vite-plugin-react-server] Could not find module id in transformed code. Ignoring.`,
|
|
84
|
+
{
|
|
85
|
+
code,
|
|
86
|
+
id,
|
|
87
|
+
transformed,
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
if (clientManifestResult.type === "error") {
|
|
93
|
+
throw clientManifestResult.error;
|
|
94
|
+
}
|
|
95
|
+
const clientPath = clientManifestResult.manifest[key]?.file;
|
|
98
96
|
|
|
97
|
+
if (!clientPath) {
|
|
98
|
+
console.warn(`[vite-plugin-react-server] Could not find client path for ${value}. Ignoring.`)
|
|
99
|
+
return null
|
|
100
|
+
}
|
|
99
101
|
return {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
input: {
|
|
103
|
-
...currentInputs,
|
|
104
|
-
...entries,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
102
|
+
code: transformed.replace(key, join(resolvedOptions.userOptions.build.client, clientPath)),
|
|
103
|
+
map: null,
|
|
108
104
|
};
|
|
109
105
|
},
|
|
110
|
-
|
|
111
|
-
buildStart() {
|
|
112
|
-
// Reset client components at start of each build
|
|
113
|
-
clientComponents.clear();
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
async transform(code: string, id: string, options?: { ssr?: boolean }) {
|
|
117
|
-
// Check for directives
|
|
118
|
-
const hasClientDirective = code.match(/^["']use client["'];?/);
|
|
119
|
-
if (!hasClientDirective) {
|
|
120
|
-
const hasServerDirective = code.match(/^["']use server["'];?/);
|
|
121
|
-
if (!hasServerDirective) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
return transformServerAction.bind(this)(code, id, options);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Track client component and transform
|
|
128
|
-
clientComponents.add(id);
|
|
129
|
-
console.log("[TransformerPlugin] Found client component:", id);
|
|
130
|
-
return transformClientComponent.bind(this)(code, id, options);
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
// Log final client components list
|
|
134
|
-
buildEnd() {
|
|
135
|
-
console.log(
|
|
136
|
-
"[TransformerPlugin] Final client components:",
|
|
137
|
-
Array.from(clientComponents)
|
|
138
|
-
);
|
|
139
|
-
},
|
|
140
106
|
};
|
|
141
107
|
}
|
package/plugin/types.ts
CHANGED
|
@@ -1,40 +1,57 @@
|
|
|
1
|
-
import type { ComponentType } from
|
|
2
|
-
import type {
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
import type { RenderToPipeableStreamOptions } from "react-dom/server";
|
|
3
|
+
import type { PreRenderedChunk } from "rollup";
|
|
4
|
+
import type { PreRenderedAsset } from "rollup";
|
|
5
|
+
import type {
|
|
3
6
|
UserConfig,
|
|
4
7
|
BuildOptions,
|
|
5
8
|
InlineConfig,
|
|
6
9
|
AliasOptions,
|
|
7
10
|
Connect,
|
|
8
|
-
|
|
11
|
+
ResolveOptions,
|
|
12
|
+
} from "vite";
|
|
13
|
+
import type { PipeableStreamOptions } from "./worker/types.js";
|
|
9
14
|
|
|
10
15
|
// Input can be a string path, React component, tuple, or array
|
|
11
|
-
export type NormalizerInput =
|
|
16
|
+
export type NormalizerInput = unknown;
|
|
12
17
|
|
|
13
18
|
export type InputNormalizer = (input: NormalizerInput) => [string, string];
|
|
14
19
|
|
|
15
|
-
export type InputNormalizerWorker = (
|
|
20
|
+
export type InputNormalizerWorker = (
|
|
21
|
+
input: NormalizerInput
|
|
22
|
+
) => Promise<[string, string]>;
|
|
16
23
|
|
|
17
|
-
export type ResolvedUserConfig = Required<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
>
|
|
24
|
+
export type ResolvedUserConfig = Required<
|
|
25
|
+
Pick<UserConfig, "root" | "mode" | "build" | "resolve">
|
|
26
|
+
> &
|
|
27
|
+
Omit<UserConfig, "root" | "mode" | "build" | "resolve"> & {
|
|
28
|
+
resolve: {alias:AliasOptions} & ResolveOptions;
|
|
29
|
+
} & {
|
|
30
|
+
build: NonNullable<
|
|
31
|
+
Required<
|
|
32
|
+
Pick<
|
|
33
|
+
BuildOptions,
|
|
34
|
+
| "target"
|
|
35
|
+
| "outDir"
|
|
36
|
+
| "assetsDir"
|
|
37
|
+
| "ssr"
|
|
38
|
+
| "ssrEmitAssets"
|
|
39
|
+
| "ssrManifest"
|
|
40
|
+
| "manifest"
|
|
41
|
+
| "rollupOptions"
|
|
42
|
+
>
|
|
43
|
+
>
|
|
44
|
+
> &
|
|
45
|
+
Omit<
|
|
46
|
+
BuildOptions,
|
|
47
|
+
| "target"
|
|
48
|
+
| "outDir"
|
|
49
|
+
| "assetsDir"
|
|
50
|
+
| "ssr"
|
|
51
|
+
| "ssrEmitAssets"
|
|
52
|
+
| "ssrManifest"
|
|
53
|
+
| "manifest"
|
|
54
|
+
>;
|
|
38
55
|
};
|
|
39
56
|
|
|
40
57
|
// Client plugin options
|
|
@@ -65,46 +82,75 @@ export type ResolvedUserOptions = Required<
|
|
|
65
82
|
| "propsExportName"
|
|
66
83
|
| "collectCss"
|
|
67
84
|
| "collectAssets"
|
|
68
|
-
| "assetsDir"
|
|
69
85
|
| "htmlWorkerPath"
|
|
70
86
|
| "rscWorkerPath"
|
|
71
87
|
| "loaderPath"
|
|
72
88
|
| "clientEntry"
|
|
73
89
|
| "serverEntry"
|
|
74
90
|
| "moduleBaseExceptions"
|
|
91
|
+
| "pipableStreamOptions"
|
|
92
|
+
| "moduleId"
|
|
75
93
|
>
|
|
76
94
|
> & {
|
|
77
95
|
build: NonNullable<Required<StreamPluginOptions["build"]>>;
|
|
78
|
-
autoDiscover:
|
|
96
|
+
autoDiscover: {
|
|
97
|
+
modulePattern: (path: string) => boolean;
|
|
98
|
+
cssPattern: (path: string) => boolean;
|
|
99
|
+
jsonPattern: (path: string) => boolean;
|
|
100
|
+
clientComponents: (path: string) => boolean;
|
|
101
|
+
propsPattern: (path: string) => boolean;
|
|
102
|
+
pagePattern: (path: string) => boolean;
|
|
103
|
+
serverFunctions: (path: string) => boolean;
|
|
104
|
+
cssModulePattern: (path: string) => boolean;
|
|
105
|
+
vendorPattern: (path: string) => boolean;
|
|
106
|
+
};
|
|
79
107
|
};
|
|
80
108
|
|
|
81
|
-
export type createBuildConfigFn<C extends "react-client" | "react-server"> =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
109
|
+
export type createBuildConfigFn<C extends "react-client" | "react-server"> =
|
|
110
|
+
(input: {
|
|
111
|
+
condition: C;
|
|
112
|
+
userOptions: ResolvedUserOptions;
|
|
113
|
+
userConfig: ResolvedUserConfig;
|
|
114
|
+
mode: "production" | "development" | "test";
|
|
115
|
+
inputNormalizer: C extends "react-server"
|
|
116
|
+
? InputNormalizerWorker
|
|
117
|
+
: InputNormalizerWorker;
|
|
118
|
+
}) => C extends "react-server"
|
|
119
|
+
? Promise<InlineConfig>
|
|
120
|
+
: Promise<InlineConfig>;
|
|
88
121
|
|
|
89
122
|
export interface StreamPluginOptions {
|
|
90
123
|
projectRoot?: string;
|
|
91
|
-
assetsDir?: string;
|
|
92
124
|
moduleBase: string;
|
|
93
125
|
moduleBasePath?: string;
|
|
94
126
|
moduleBaseURL?: string;
|
|
95
127
|
clientEntry?: string;
|
|
96
128
|
serverEntry?: string;
|
|
97
129
|
// Auto-discovery (zero-config)
|
|
98
|
-
autoDiscover?:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
130
|
+
autoDiscover?:
|
|
131
|
+
| {
|
|
132
|
+
// default: /\.(m|c)?(j|t)sx?$/
|
|
133
|
+
modulePattern?: string | RegExp | ((path: string) => boolean);
|
|
134
|
+
// default: [Pp]age.tsx
|
|
135
|
+
pagePattern?: string | RegExp | ((path: string) => boolean);
|
|
136
|
+
// default: [Pp]rops.ts
|
|
137
|
+
propsPattern?: string | RegExp | ((path: string) => boolean);
|
|
138
|
+
// default: "use client" and .client./\.(m|c)?(j|t)sx?$/
|
|
139
|
+
clientComponents?: string | RegExp | ((path: string) => boolean);
|
|
140
|
+
// default: "use server" and .server./\.(m|c)?(j|t)sx?$/
|
|
141
|
+
serverFunctions?: string | RegExp | ((path: string) => boolean);
|
|
142
|
+
// default: /\.css$/
|
|
143
|
+
cssPattern?: string | RegExp | ((path: string) => boolean);
|
|
144
|
+
// default: /\.json$/
|
|
145
|
+
jsonPattern?: string | RegExp | ((path: string) => boolean);
|
|
146
|
+
// default: /\.html$/
|
|
147
|
+
htmlPattern?: string | RegExp | ((path: string) => boolean);
|
|
148
|
+
// default: /\.css\.js/
|
|
149
|
+
cssModulePattern?: string | RegExp | ((path: string) => boolean);
|
|
150
|
+
// default: /node_modules|(_virtual)/
|
|
151
|
+
vendorPattern?: string | RegExp | ((path: string) => boolean);
|
|
152
|
+
}
|
|
153
|
+
| undefined;
|
|
108
154
|
// Manual configuration
|
|
109
155
|
Page: string | ((url: string) => string);
|
|
110
156
|
props?: undefined | string | ((url: string) => string);
|
|
@@ -125,17 +171,19 @@ export interface StreamPluginOptions {
|
|
|
125
171
|
collectAssets?: boolean;
|
|
126
172
|
build?: BuildConfig;
|
|
127
173
|
moduleBaseExceptions?: string[];
|
|
128
|
-
|
|
174
|
+
pipableStreamOptions?: PipeableStreamOptions;
|
|
175
|
+
moduleId?: (id: string, ssr: boolean) => string;
|
|
129
176
|
}
|
|
130
177
|
|
|
131
178
|
export interface CreateHandlerOptions<T = any> {
|
|
132
179
|
loader: (id: string) => Promise<T>;
|
|
133
|
-
|
|
180
|
+
clientManifest?: import("vite").Manifest;
|
|
181
|
+
serverManifest?: import("vite").Manifest;
|
|
134
182
|
moduleGraph?: import("vite").ModuleGraph;
|
|
135
183
|
cssFiles?: string[];
|
|
136
184
|
onCssFile?: (path: string) => void;
|
|
137
185
|
logger?: import("vite").Logger;
|
|
138
|
-
pipableStreamOptions?:
|
|
186
|
+
pipableStreamOptions?: PipeableStreamOptions;
|
|
139
187
|
}
|
|
140
188
|
|
|
141
189
|
export type ModuleLoader = (
|
|
@@ -172,7 +220,7 @@ export interface RscStreamOptions {
|
|
|
172
220
|
htmlProps: any;
|
|
173
221
|
route: string;
|
|
174
222
|
url: string;
|
|
175
|
-
pipableStreamOptions?:
|
|
223
|
+
pipableStreamOptions?: PipeableStreamOptions;
|
|
176
224
|
moduleBasePath: string;
|
|
177
225
|
}
|
|
178
226
|
|
|
@@ -198,9 +246,17 @@ export interface BuildOutput {
|
|
|
198
246
|
|
|
199
247
|
export interface BuildConfig {
|
|
200
248
|
pages: string[] | (() => Promise<string[]> | string[]);
|
|
249
|
+
assetsDir?: string;
|
|
201
250
|
client?: string; // Output directory for client files
|
|
202
251
|
server?: string; // Output directory for server files
|
|
203
252
|
static?: string; // Output directory for static environment - works in both
|
|
253
|
+
api?: string; // Output directory for API files
|
|
254
|
+
outDir?: string;
|
|
255
|
+
hash?: string;
|
|
256
|
+
preserveModulesRoot?: boolean;
|
|
257
|
+
entryFile?: (n: PreRenderedChunk) => string;
|
|
258
|
+
chunkFile?: (n: PreRenderedChunk) => string;
|
|
259
|
+
assetFile?: (n: PreRenderedAsset) => string;
|
|
204
260
|
}
|
|
205
261
|
|
|
206
262
|
export interface RscResolver {
|
|
@@ -276,30 +332,30 @@ export interface BuildTiming {
|
|
|
276
332
|
total?: number;
|
|
277
333
|
}
|
|
278
334
|
|
|
279
|
-
|
|
280
335
|
export type CheckFilesExistReturn = {
|
|
281
|
-
propsMap: Map<string,string
|
|
282
|
-
propsSet: Set<string
|
|
283
|
-
pageMap: Map<string,string
|
|
284
|
-
pageSet: Set<string
|
|
285
|
-
}
|
|
336
|
+
propsMap: Map<string, string>;
|
|
337
|
+
propsSet: Set<string>;
|
|
338
|
+
pageMap: Map<string, string>;
|
|
339
|
+
pageSet: Set<string>;
|
|
340
|
+
urlMap: Map<string, {props: string, page: string}>;
|
|
341
|
+
errors: string[];
|
|
342
|
+
};
|
|
286
343
|
|
|
287
344
|
// Add strict type checking for worker messages
|
|
288
|
-
export type WorkerMessage =
|
|
289
|
-
| { type:
|
|
290
|
-
| { type:
|
|
291
|
-
| { type:
|
|
292
|
-
| { type:
|
|
293
|
-
| { type:
|
|
345
|
+
export type WorkerMessage =
|
|
346
|
+
| { type: "READY" }
|
|
347
|
+
| { type: "ERROR"; error: string | Error }
|
|
348
|
+
| { type: "RSC_CHUNK"; id: string; chunk: Buffer }
|
|
349
|
+
| { type: "RSC_END"; id: string }
|
|
350
|
+
| { type: "SHUTDOWN" };
|
|
294
351
|
|
|
295
352
|
// Add branded types for safety
|
|
296
353
|
export type ModuleId = string & { readonly __brand: unique symbol };
|
|
297
354
|
export type PagePath = string & { readonly __brand: unique symbol };
|
|
298
355
|
|
|
299
|
-
|
|
300
356
|
export type HtmlProps = {
|
|
301
357
|
pageProps: any;
|
|
302
358
|
route: string;
|
|
303
359
|
url: string;
|
|
304
360
|
cssFiles: string[];
|
|
305
|
-
}
|
|
361
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createLogger as createViteLogger, type LogLevel } from 'vite';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const isPrimitive = (value: any) => {
|
|
5
|
+
return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'symbol';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const buildMessage = (prefix: string, msg: string, ...args: any[]) => {
|
|
9
|
+
let buildMsg = `[${prefix}] ${msg}`
|
|
10
|
+
for(const arg of args) {
|
|
11
|
+
if(isPrimitive(arg)) {
|
|
12
|
+
buildMsg += `\n[${prefix}] ${String(arg)}`;
|
|
13
|
+
} else if(arg instanceof Error) {
|
|
14
|
+
buildMsg += `\n[${prefix}] ${arg.name}`
|
|
15
|
+
buildMsg += `\n[${prefix}] ${arg.message}`
|
|
16
|
+
buildMsg += `\n[${prefix}] ${arg.stack}`
|
|
17
|
+
buildMsg += `\n[${prefix}] ${arg.cause}`
|
|
18
|
+
} else {
|
|
19
|
+
buildMsg += `\n[${prefix}] ${JSON.stringify(arg)}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return buildMsg;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const createLogger = (process.env['NODE_ENV'] === 'development') ? (prefix: string, logLevel: LogLevel = 'info') => {
|
|
26
|
+
const logger = createViteLogger(logLevel, {
|
|
27
|
+
allowClearScreen: true
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
clear: () => logger.clearScreen('info'),
|
|
31
|
+
info: (msg: string, ...args: any[]) => {
|
|
32
|
+
console.log(buildMessage(prefix, msg, ...args))
|
|
33
|
+
},
|
|
34
|
+
warn: (msg: string, ...args: any[]) => {
|
|
35
|
+
console.warn(buildMessage(prefix, msg, ...args))
|
|
36
|
+
},
|
|
37
|
+
error: (msg: string, ...args: any[]) => {
|
|
38
|
+
console.error(buildMessage(prefix, msg, ...args))
|
|
39
|
+
},
|
|
40
|
+
debug: (msg: string, ...args: any[]) => {
|
|
41
|
+
console.debug(buildMessage(prefix, msg, ...args))
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
} : () => {
|
|
45
|
+
return {
|
|
46
|
+
clear: () => {},
|
|
47
|
+
info: () => {},
|
|
48
|
+
warn: () => {},
|
|
49
|
+
error: () => {},
|
|
50
|
+
debug: () => {},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -12,6 +12,7 @@ type CreateWorkerOptions = {
|
|
|
12
12
|
maxListeners?: number;
|
|
13
13
|
workerPath: string;
|
|
14
14
|
resourceLimits?: ResourceLimits;
|
|
15
|
+
typescript?: boolean;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
export async function createWorker(options: CreateWorkerOptions) {
|
|
@@ -26,59 +27,57 @@ export async function createWorker(options: CreateWorkerOptions) {
|
|
|
26
27
|
resourceLimits = {
|
|
27
28
|
maxOldGenerationSizeMb: 512,
|
|
28
29
|
maxYoungGenerationSizeMb: 128,
|
|
29
|
-
}
|
|
30
|
+
},
|
|
30
31
|
} = options;
|
|
31
32
|
|
|
32
33
|
// Ensure consistent NODE_ENV between main thread and worker
|
|
33
|
-
const isTestEnv = process.env[
|
|
34
|
-
const nodeEnv = isTestEnv ?
|
|
34
|
+
const isTestEnv = process.env["VITEST"] || process.env["NODE_ENV"] === "test";
|
|
35
|
+
const nodeEnv = isTestEnv ? "development" : mode;
|
|
35
36
|
|
|
36
37
|
const env = {
|
|
37
38
|
...process.env,
|
|
38
39
|
NODE_ENV: nodeEnv,
|
|
39
40
|
NODE_PATH: nodePath,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
NODE_OPTIONS: `${
|
|
42
|
+
reverseCondition
|
|
43
|
+
? condition === "react-server"
|
|
44
|
+
? process.env["NODE_OPTIONS"]?.includes("react-server")
|
|
45
|
+
? process.env["NODE_OPTIONS"]?.replace("react-server", "react-client")
|
|
46
|
+
: `${process.env["NODE_OPTIONS"] ?? ''} --conditions=react-client`
|
|
47
|
+
: process.env["NODE_OPTIONS"]?.includes("react-client")
|
|
48
|
+
? process.env["NODE_OPTIONS"]?.replace("react-client", "react-server")
|
|
49
|
+
: `${process.env["NODE_OPTIONS"] ?? ''} --conditions=react-server`
|
|
50
|
+
: process.env["NODE_OPTIONS"]
|
|
51
|
+
}`,
|
|
44
52
|
};
|
|
45
|
-
const maxRetries = 3;
|
|
46
|
-
for (let tries = 0; tries < maxRetries; tries++) {
|
|
47
|
-
try {
|
|
48
|
-
const worker = new Worker(workerPath.startsWith('/') ? workerPath : join(projectRoot, workerPath), {
|
|
49
|
-
env,
|
|
50
|
-
// Increase resource limits for stream handling
|
|
51
|
-
resourceLimits: resourceLimits
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
worker.setMaxListeners(maxListeners);
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
worker.once('message', (msg) => {
|
|
63
|
-
if (msg.type === 'READY') {
|
|
64
|
-
if(msg.env === nodeEnv) {
|
|
65
|
-
resolve(true);
|
|
66
|
-
} else {
|
|
67
|
-
reject(new Error(`Worker environment mismatch: expected ${nodeEnv}, got ${msg.env}`));
|
|
68
|
-
}
|
|
69
|
-
} else if (msg.type === 'ERROR') {
|
|
70
|
-
reject(new Error(msg.error));
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
worker.once('error', reject);
|
|
74
|
-
})
|
|
75
|
-
]);
|
|
76
|
-
|
|
77
|
-
if (ready) return worker;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.warn(`Worker startup attempt ${tries + 1} failed:`, error);
|
|
80
|
-
if (tries === maxRetries - 1) throw error;
|
|
54
|
+
// Create worker with proper environment
|
|
55
|
+
const worker = new Worker(
|
|
56
|
+
workerPath.startsWith("/") ? workerPath : join(projectRoot, workerPath),
|
|
57
|
+
{
|
|
58
|
+
env,
|
|
59
|
+
resourceLimits,
|
|
81
60
|
}
|
|
82
|
-
|
|
83
|
-
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
worker.setMaxListeners(maxListeners);
|
|
64
|
+
|
|
65
|
+
// Wait for worker to be ready
|
|
66
|
+
return await new Promise<Worker>((resolve, reject) => {
|
|
67
|
+
const timeout = setTimeout(() => {
|
|
68
|
+
reject(new Error('Worker ready timeout'));
|
|
69
|
+
}, 5000);
|
|
70
|
+
|
|
71
|
+
worker.once("message", (msg) => {
|
|
72
|
+
if (msg.type === "READY" && msg.env === nodeEnv) {
|
|
73
|
+
clearTimeout(timeout);
|
|
74
|
+
resolve(worker);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
worker.once("error", (error) => {
|
|
79
|
+
clearTimeout(timeout);
|
|
80
|
+
reject(error);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
84
83
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { messageHandler } from "./messageHandler.js";
|
|
2
2
|
import { parentPort } from "node:worker_threads";
|
|
3
3
|
|
|
4
|
+
let ready = false;
|
|
4
5
|
if (!parentPort) throw new Error("This module must be run as a worker");
|
|
5
|
-
parentPort?.on("message", messageHandler);
|
|
6
6
|
|
|
7
7
|
// Signal ready with environment
|
|
8
|
-
parentPort?.
|
|
8
|
+
parentPort?.on("message", messageHandler);
|
|
9
|
+
parentPort?.postMessage({
|
|
10
|
+
type: "READY",
|
|
11
|
+
env: process.env["NODE_ENV"],
|
|
12
|
+
pid: process.pid
|
|
13
|
+
});
|