vite-plugin-react-server 0.3.3 → 0.3.5
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/README.md +113 -222
- package/bin/patch.mjs +84 -0
- package/dist/_virtual/sourcemap-codec.umd.js +11 -0
- package/dist/_virtual/sourcemap-codec.umd.js.map +1 -0
- package/dist/_virtual/sourcemap-codec.umd2.js +9 -0
- package/dist/_virtual/sourcemap-codec.umd2.js.map +1 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +7 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -3
- package/dist/index.js.map +1 -1
- package/dist/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js +457 -0
- package/dist/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js.map +1 -0
- package/dist/node_modules/magic-string/dist/magic-string.es.js +1283 -0
- package/dist/node_modules/magic-string/dist/magic-string.es.js.map +1 -0
- package/dist/package.json +131 -0
- package/dist/plugin/assertServerCondition.d.ts.map +1 -0
- package/dist/plugin/assertServerCondition.js +15 -0
- package/dist/plugin/build/createClientBuildConfig.d.ts +3 -0
- package/dist/plugin/build/createClientBuildConfig.d.ts.map +1 -0
- package/dist/plugin/build/createClientBuildConfig.js +14 -0
- package/dist/plugin/build/createServerBuildConfig.d.ts +12 -0
- package/dist/plugin/build/createServerBuildConfig.d.ts.map +1 -0
- package/dist/plugin/build/createServerBuildConfig.js +40 -0
- package/dist/plugin/build/createSharedBuildConfig.d.ts +5 -0
- package/dist/plugin/build/createSharedBuildConfig.d.ts.map +1 -0
- package/dist/plugin/build/createSharedBuildConfig.js +28 -0
- package/dist/plugin/build/mergeInputs.d.ts +9 -0
- package/dist/plugin/build/mergeInputs.d.ts.map +1 -0
- package/dist/plugin/build/mergeInputs.js +56 -0
- package/dist/plugin/checkFilesExist.d.ts +3 -0
- package/dist/plugin/checkFilesExist.d.ts.map +1 -0
- package/dist/plugin/checkFilesExist.js +78 -0
- package/dist/plugin/checkFilesExist.js.map +1 -0
- package/dist/{collect-css-manifest.d.ts → plugin/collect-css-manifest.d.ts} +2 -2
- package/dist/plugin/collect-css-manifest.d.ts.map +1 -0
- package/dist/{src → plugin}/collect-css-manifest.js +8 -5
- package/dist/plugin/collect-css-manifest.js.map +1 -0
- package/dist/plugin/components.d.ts.map +1 -0
- package/dist/{src → plugin}/components.js +9 -4
- package/dist/plugin/components.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +51 -0
- package/dist/plugin/config/defaults.d.ts.map +1 -0
- package/dist/plugin/config/defaults.js +52 -0
- package/dist/plugin/config/defaults.js.map +1 -0
- package/dist/plugin/config/getCondition.d.ts +2 -0
- package/dist/plugin/config/getCondition.d.ts.map +1 -0
- package/dist/plugin/config/getCondition.js +11 -0
- package/dist/plugin/config/getCondition.js.map +1 -0
- package/dist/plugin/config/getPaths.d.ts +5 -0
- package/dist/plugin/config/getPaths.d.ts.map +1 -0
- package/dist/plugin/config/getPaths.js +21 -0
- package/dist/plugin/config/getPaths.js.map +1 -0
- package/dist/plugin/config/getWorkerPath.d.ts +2 -0
- package/dist/plugin/config/getWorkerPath.d.ts.map +1 -0
- package/dist/plugin/config/getWorkerPath.js +4 -0
- package/dist/plugin/config/index.d.ts +8 -0
- package/dist/plugin/config/index.d.ts.map +1 -0
- package/dist/plugin/config/index.js +7 -0
- package/dist/plugin/config/moduleIdDefault.d.ts +8 -0
- package/dist/plugin/config/moduleIdDefault.d.ts.map +1 -0
- package/dist/plugin/config/moduleIdDefault.js +23 -0
- package/dist/plugin/config/moduleIdDefault.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts +9 -0
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -0
- package/dist/plugin/config/resolveOptions.js +56 -0
- package/dist/plugin/config/resolveOptions.js.map +1 -0
- package/dist/plugin/config/resolvePages.d.ts +9 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -0
- package/dist/plugin/config/resolvePages.js +38 -0
- package/dist/plugin/config/resolvePages.js.map +1 -0
- package/dist/plugin/config/resolveUserConfig.d.ts +18 -0
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -0
- package/dist/plugin/config/resolveUserConfig.js +84 -0
- package/dist/plugin/config/resolveUserConfig.js.map +1 -0
- package/dist/plugin/copy-dir.d.ts.map +1 -0
- package/dist/plugin/copy-dir.js +20 -0
- package/dist/plugin/getCondition.d.ts +2 -0
- package/dist/plugin/getCondition.d.ts.map +1 -0
- package/dist/plugin/getCondition.js +1 -0
- package/dist/plugin/getEnv.d.ts.map +1 -0
- package/dist/plugin/getEnv.js +107 -0
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts +8 -0
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/createClientInputNormalizer.js +35 -0
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts +9 -0
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/createServerInputNormalizer.js +37 -0
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +7 -0
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/createStaticInputNormalizer.js +18 -0
- package/dist/plugin/helpers/getModuleManifest.d.ts +12 -0
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +1 -0
- package/dist/plugin/helpers/getModuleManifest.js +24 -0
- package/dist/plugin/helpers/getModuleManifest.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts +3 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.js +35 -0
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +11 -0
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +1 -0
- package/dist/plugin/helpers/inputNormalizerWorker.js +30 -0
- package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +1 -0
- package/dist/plugin/helpers/normalizedRelativePath.js +36 -0
- package/dist/plugin/helpers/resolveFilePath.d.ts +13 -0
- package/dist/plugin/helpers/resolveFilePath.d.ts.map +1 -0
- package/dist/plugin/helpers/resolveFilePath.js +74 -0
- package/dist/plugin/helpers/resolveWorkerModule.d.ts +6 -0
- package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +1 -0
- package/dist/plugin/helpers/resolveWorkerModule.js +24 -0
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -0
- package/dist/{src → plugin}/helpers/tryManifest.js +11 -6
- package/dist/plugin/helpers/tryManifest.js.map +1 -0
- package/dist/plugin/helpers/validateModuleBase.d.ts +3 -0
- package/dist/plugin/helpers/validateModuleBase.d.ts.map +1 -0
- package/dist/plugin/helpers/validateModuleBase.js +16 -0
- package/dist/plugin/helpers/validateResolvedConfig.d.ts +3 -0
- package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +1 -0
- package/dist/plugin/helpers/validateResolvedConfig.js +17 -0
- package/dist/plugin/index.d.ts +3 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +1 -0
- package/dist/plugin/loader/createBuildLoader.d.ts +9 -0
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createBuildLoader.js +52 -0
- package/dist/plugin/loader/createBuildLoader.js.map +1 -0
- package/dist/plugin/loader/createCssLoader.d.ts +30 -0
- package/dist/plugin/loader/createCssLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createCssLoader.js +35 -0
- package/dist/{html → plugin/loader}/createPageLoader.d.ts +2 -4
- package/dist/plugin/loader/createPageLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createPageLoader.js +57 -0
- package/dist/plugin/manifest.d.ts.map +1 -0
- package/dist/plugin/manifest.js +13 -0
- package/dist/plugin/module-graph.d.ts.map +1 -0
- package/dist/plugin/module-graph.js +35 -0
- package/dist/plugin/plugin.d.ts +7 -0
- package/dist/plugin/plugin.d.ts.map +1 -0
- package/dist/plugin/plugin.js +8 -0
- package/dist/plugin/preserver/index.d.ts +2 -0
- package/dist/plugin/preserver/index.d.ts.map +1 -0
- package/dist/plugin/preserver/index.js +1 -0
- package/dist/plugin/preserver/plugin.d.ts +4 -0
- package/dist/plugin/preserver/plugin.d.ts.map +1 -0
- package/dist/plugin/preserver/plugin.js +90 -0
- package/dist/plugin/preserver/plugin.js.map +1 -0
- package/dist/plugin/react-client/index.d.ts +2 -0
- package/dist/plugin/react-client/index.d.ts.map +1 -0
- package/dist/plugin/react-client/index.js +1 -0
- package/dist/plugin/react-client/plugin.d.ts +4 -0
- package/dist/plugin/react-client/plugin.d.ts.map +1 -0
- package/dist/plugin/react-client/plugin.js +34 -0
- package/dist/plugin/react-client/plugin.js.map +1 -0
- package/dist/plugin/react-server/createDevMiddleware.d.ts.map +1 -0
- package/dist/plugin/react-server/createDevMiddleware.js +68 -0
- package/dist/plugin/react-server/createDevServer.d.ts.map +1 -0
- package/dist/plugin/react-server/createDevServer.js +4 -0
- package/dist/plugin/react-server/createHandler.d.ts +17 -0
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -0
- package/dist/{src → plugin}/react-server/createHandler.js +28 -17
- package/dist/plugin/react-server/createHandler.js.map +1 -0
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +1 -0
- package/dist/plugin/react-server/createReactNodeStreamer.js +7 -0
- package/dist/{react-server → plugin/react-server}/createRscStream.d.ts +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -0
- package/dist/{src → plugin}/react-server/createRscStream.js +14 -13
- package/dist/plugin/react-server/createRscStream.js.map +1 -0
- package/dist/{react-server → plugin/react-server}/createSsrHandler.d.ts +1 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -0
- package/dist/plugin/react-server/createSsrHandler.js +102 -0
- package/dist/plugin/react-server/index.d.ts +4 -0
- package/dist/plugin/react-server/index.d.ts.map +1 -0
- package/dist/plugin/react-server/index.js +10 -0
- package/dist/{react-server → plugin/react-server}/plugin.d.ts +2 -2
- package/dist/plugin/react-server/plugin.d.ts.map +1 -0
- package/dist/plugin/react-server/plugin.js +375 -0
- package/dist/plugin/react-server/plugin.js.map +1 -0
- package/dist/plugin/resolvePage.d.ts.map +1 -0
- package/dist/{src → plugin}/resolvePage.js +8 -4
- package/dist/plugin/resolvePage.js.map +1 -0
- package/dist/plugin/resolveProps.d.ts.map +1 -0
- package/dist/{src → plugin}/resolveProps.js +21 -8
- package/dist/plugin/resolveProps.js.map +1 -0
- package/dist/plugin/server.d.ts +2 -0
- package/dist/plugin/server.d.ts.map +1 -0
- package/dist/plugin/server.js +1 -0
- package/dist/plugin/transformer/index.d.ts +2 -0
- package/dist/plugin/transformer/index.d.ts.map +1 -0
- package/dist/plugin/transformer/index.js +1 -0
- package/dist/{transformer/index.d.ts → plugin/transformer/plugin.d.ts} +3 -3
- package/dist/plugin/transformer/plugin.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.js +86 -0
- package/dist/plugin/transformer/plugin.js.map +1 -0
- package/dist/plugin/transformer/transformer-client-components.d.ts +21 -0
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +1 -0
- package/dist/plugin/transformer/transformer-client-components.js +61 -0
- package/dist/plugin/transformer/transformer-client-components.js.map +1 -0
- package/dist/{transformer/transformer.d.ts → plugin/transformer/transformer-server-actions.d.ts} +3 -4
- package/dist/plugin/transformer/transformer-server-actions.d.ts.map +1 -0
- package/dist/plugin/transformer/transformer-server-actions.js +76 -0
- package/dist/plugin/transformer/transformer-server-actions.js.map +1 -0
- package/dist/plugin/transformer/types.d.ts.map +1 -0
- package/dist/plugin/transformer/types.js +1 -0
- package/dist/plugin/types.d.ts +225 -0
- package/dist/plugin/types.d.ts.map +1 -0
- package/dist/plugin/types.js +1 -0
- package/dist/plugin/worker/createWorker.d.ts +15 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -0
- package/dist/plugin/worker/createWorker.js +71 -0
- package/dist/plugin/worker/createWorker.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.d.ts +2 -0
- package/dist/plugin/worker/html/html-worker.d.ts.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts +2 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.js +12 -0
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.js +4 -0
- package/dist/plugin/worker/html/html-worker.production.d.ts +2 -0
- package/dist/plugin/worker/html/html-worker.production.d.ts.map +1 -0
- package/dist/plugin/worker/html/html-worker.production.js +12 -0
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -0
- package/dist/plugin/worker/html/index.d.ts +2 -0
- package/dist/plugin/worker/html/index.d.ts.map +1 -0
- package/dist/plugin/worker/html/index.js +7 -0
- package/dist/plugin/worker/html/index.js.map +1 -0
- package/dist/plugin/worker/html/messageHandler.d.ts +3 -0
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -0
- package/dist/plugin/worker/html/messageHandler.js +98 -0
- package/dist/plugin/worker/html/messageHandler.js.map +1 -0
- package/dist/plugin/worker/html/plugin.d.ts +4 -0
- package/dist/plugin/worker/html/plugin.d.ts.map +1 -0
- package/dist/plugin/worker/html/plugin.js +89 -0
- package/dist/plugin/worker/html/renderPages.d.ts +38 -0
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -0
- package/dist/plugin/worker/html/renderPages.js +121 -0
- package/dist/plugin/worker/html/renderPages.js.map +1 -0
- package/dist/plugin/worker/loader.d.ts.map +1 -0
- package/dist/plugin/worker/loader.js +11 -0
- package/dist/plugin/worker/loader.js.map +1 -0
- package/dist/plugin/worker/plugin.d.ts +10 -0
- package/dist/plugin/worker/plugin.d.ts.map +1 -0
- package/dist/plugin/worker/plugin.js +14 -0
- package/dist/plugin/worker/rsc/createRscStream.d.ts +5 -0
- package/dist/plugin/worker/rsc/createRscStream.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/createRscStream.js +39 -0
- package/dist/plugin/worker/rsc/createRscStream.js.map +1 -0
- package/dist/plugin/worker/rsc/development.d.ts +5 -0
- package/dist/plugin/worker/rsc/development.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/development.js +13 -0
- package/dist/plugin/worker/rsc/development.js.map +1 -0
- package/dist/plugin/worker/rsc/index.d.ts +4 -0
- package/dist/plugin/worker/rsc/index.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/index.js +15 -0
- package/dist/plugin/worker/rsc/index.js.map +1 -0
- package/dist/plugin/worker/rsc/plugin.d.ts +4 -0
- package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/plugin.js +82 -0
- package/dist/plugin/worker/rsc/plugin.js.map +1 -0
- package/dist/plugin/worker/rsc/production.d.ts +5 -0
- package/dist/plugin/worker/rsc/production.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/production.js +13 -0
- package/dist/plugin/worker/rsc/production.js.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.d.ts +2 -0
- package/dist/plugin/worker/rsc/rsc-worker.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.js +106 -0
- package/dist/plugin/worker/types.d.ts +99 -0
- package/dist/plugin/worker/types.d.ts.map +1 -0
- package/dist/plugin/worker/types.js +1 -0
- package/dist/server.d.ts +4 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +9 -0
- package/dist/server.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +1 -201
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +44 -25
- package/plugin/build/createClientBuildConfig.ts +21 -0
- package/plugin/build/createServerBuildConfig.ts +66 -0
- package/plugin/build/createSharedBuildConfig.ts +35 -0
- package/plugin/build/mergeInputs.ts +58 -0
- package/plugin/checkFilesExist.ts +82 -0
- package/{src → plugin}/collect-css-manifest.ts +4 -2
- package/plugin/config/defaults.ts +44 -0
- package/plugin/config/getCondition.ts +3 -0
- package/plugin/config/getPaths.ts +25 -0
- package/plugin/config/getWorkerPath.ts +5 -0
- package/plugin/config/index.ts +8 -0
- package/plugin/config/moduleIdDefault.ts +23 -0
- package/plugin/config/resolveOptions.ts +53 -0
- package/plugin/config/resolvePages.ts +43 -0
- package/plugin/config/resolveUserConfig.ts +97 -0
- package/{src → plugin}/getEnv.ts +1 -1
- package/plugin/helpers/createClientInputNormalizer.ts +48 -0
- package/plugin/helpers/createServerInputNormalizer.ts +52 -0
- package/plugin/helpers/createStaticInputNormalizer.ts +26 -0
- package/plugin/helpers/getModuleManifest.ts +31 -0
- package/plugin/helpers/inputNormalizer.ts +39 -0
- package/plugin/helpers/inputNormalizerWorker.ts +47 -0
- package/plugin/helpers/resolveFilePath.ts +108 -0
- package/plugin/helpers/resolveWorkerModule.ts +41 -0
- package/plugin/helpers/validateModuleBase.ts +30 -0
- package/plugin/helpers/validateResolvedConfig.ts +21 -0
- package/plugin/index.ts +2 -0
- package/plugin/loader/createBuildLoader.ts +60 -0
- package/plugin/loader/createCssLoader.ts +73 -0
- package/{src/html → plugin/loader}/createPageLoader.ts +35 -27
- package/plugin/plugin.ts +8 -0
- package/plugin/preserver/index.ts +1 -0
- package/plugin/preserver/plugin.ts +110 -0
- package/plugin/react-client/index.ts +1 -0
- package/plugin/react-client/plugin.ts +33 -0
- package/{src → plugin}/react-server/createDevMiddleware.ts +17 -1
- package/{src → plugin}/react-server/createDevServer.ts +0 -1
- package/{src → plugin}/react-server/createHandler.ts +31 -10
- package/{src → plugin}/react-server/createReactNodeStreamer.ts +1 -0
- package/{src → plugin}/react-server/createRscStream.ts +8 -12
- package/{src → plugin}/react-server/createSsrHandler.ts +16 -19
- package/plugin/react-server/index.ts +13 -0
- package/plugin/react-server/plugin.ts +465 -0
- package/{src → plugin}/resolvePage.ts +1 -1
- package/{src → plugin}/resolveProps.ts +15 -6
- package/plugin/server.tsx +0 -0
- package/plugin/transformer/index.ts +1 -0
- package/plugin/transformer/plugin.ts +131 -0
- package/plugin/transformer/transformer-client-components.ts +94 -0
- package/{src/transformer/transformer.ts → plugin/transformer/transformer-server-actions.ts} +14 -27
- package/{src → plugin}/types.ts +97 -55
- package/plugin/worker/createWorker.ts +84 -0
- package/plugin/worker/html/html-worker.development.tsx +8 -0
- package/plugin/worker/html/html-worker.production.tsx +8 -0
- package/plugin/worker/html/html-worker.ts +5 -0
- package/plugin/worker/html/index.ts +5 -0
- package/plugin/worker/html/messageHandler.ts +116 -0
- package/plugin/worker/html/plugin.ts +97 -0
- package/plugin/worker/html/renderPages.ts +187 -0
- package/plugin/worker/plugin.ts +17 -0
- package/plugin/worker/rsc/createRscStream.ts +42 -0
- package/plugin/worker/rsc/development.ts +6 -0
- package/plugin/worker/rsc/index.ts +14 -0
- package/plugin/worker/rsc/plugin.ts +83 -0
- package/plugin/worker/rsc/production.ts +6 -0
- package/plugin/worker/rsc/rsc-worker.tsx +128 -0
- package/plugin/worker/types.ts +124 -0
- package/scripts/bump-version.mjs +68 -0
- package/scripts/check-react-version.mjs +66 -0
- package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +4291 -0
- package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +108798 -0
- package/scripts/react-server-dom-esm+0.0.0-experimental-b3a95caf-20250113.patch +24775 -0
- package/{patches → scripts}/react-server-dom-esm+0.0.1.patch +10259 -3
- package/tsconfig.json +15 -13
- package/dist/assertServerCondition.d.ts.map +0 -1
- package/dist/bin/patch.js +0 -51
- package/dist/bin/patch.js.map +0 -1
- package/dist/build/createBuildConfig.d.ts +0 -13
- package/dist/build/createBuildConfig.d.ts.map +0 -1
- package/dist/build/mergeInputs.d.ts +0 -5
- package/dist/build/mergeInputs.d.ts.map +0 -1
- package/dist/checkFilesExist.d.ts +0 -8
- package/dist/checkFilesExist.d.ts.map +0 -1
- package/dist/collect-css-manifest.d.ts.map +0 -1
- package/dist/components.d.ts.map +0 -1
- package/dist/copy-dir.d.ts.map +0 -1
- package/dist/getEnv.d.ts.map +0 -1
- package/dist/helpers/inputNormalizer.d.ts +0 -6
- package/dist/helpers/inputNormalizer.d.ts.map +0 -1
- package/dist/helpers/normalizedRelativePath.d.ts.map +0 -1
- package/dist/helpers/tryManifest.d.ts.map +0 -1
- package/dist/html/createPageLoader.d.ts.map +0 -1
- package/dist/manifest.d.ts.map +0 -1
- package/dist/module-graph.d.ts.map +0 -1
- package/dist/options.d.ts +0 -91
- package/dist/options.d.ts.map +0 -1
- package/dist/plugin.d.ts +0 -3
- package/dist/plugin.d.ts.map +0 -1
- package/dist/react-client/plugin.d.ts +0 -4
- package/dist/react-client/plugin.d.ts.map +0 -1
- package/dist/react-client/plugin.js +0 -28
- package/dist/react-client/plugin.js.map +0 -1
- package/dist/react-server/createDevMiddleware.d.ts.map +0 -1
- package/dist/react-server/createDevServer.d.ts.map +0 -1
- package/dist/react-server/createHandler.d.ts +0 -23
- package/dist/react-server/createHandler.d.ts.map +0 -1
- package/dist/react-server/createReactNodeStreamer.d.ts.map +0 -1
- package/dist/react-server/createRscStream.d.ts.map +0 -1
- package/dist/react-server/createSsrHandler.d.ts.map +0 -1
- package/dist/react-server/plugin.d.ts.map +0 -1
- package/dist/react-server/plugin.js +0 -345
- package/dist/react-server/plugin.js.map +0 -1
- package/dist/resolvePage.d.ts.map +0 -1
- package/dist/resolveProps.d.ts.map +0 -1
- package/dist/src/build/createBuildConfig.js +0 -44
- package/dist/src/build/createBuildConfig.js.map +0 -1
- package/dist/src/build/mergeInputs.js +0 -16
- package/dist/src/build/mergeInputs.js.map +0 -1
- package/dist/src/checkFilesExist.js +0 -61
- package/dist/src/checkFilesExist.js.map +0 -1
- package/dist/src/collect-css-manifest.js.map +0 -1
- package/dist/src/components.js.map +0 -1
- package/dist/src/getEnv.js +0 -76
- package/dist/src/getEnv.js.map +0 -1
- package/dist/src/helpers/inputNormalizer.js +0 -11
- package/dist/src/helpers/inputNormalizer.js.map +0 -1
- package/dist/src/helpers/normalizedRelativePath.js +0 -34
- package/dist/src/helpers/normalizedRelativePath.js.map +0 -1
- package/dist/src/helpers/tryManifest.js.map +0 -1
- package/dist/src/html/createPageLoader.js +0 -72
- package/dist/src/html/createPageLoader.js.map +0 -1
- package/dist/src/options.js +0 -307
- package/dist/src/options.js.map +0 -1
- package/dist/src/react-server/createHandler.js.map +0 -1
- package/dist/src/react-server/createRscStream.js.map +0 -1
- package/dist/src/resolvePage.js.map +0 -1
- package/dist/src/resolveProps.js.map +0 -1
- package/dist/src/worker/createHtmlStream.js +0 -62
- package/dist/src/worker/createHtmlStream.js.map +0 -1
- package/dist/src/worker/createWorker.js +0 -34
- package/dist/src/worker/createWorker.js.map +0 -1
- package/dist/src/worker/renderPages.js +0 -99
- package/dist/src/worker/renderPages.js.map +0 -1
- package/dist/transformer/index.d.ts.map +0 -1
- package/dist/transformer/preserveDirectives.d.ts +0 -4
- package/dist/transformer/preserveDirectives.d.ts.map +0 -1
- package/dist/transformer/preserver.d.ts +0 -2
- package/dist/transformer/preserver.d.ts.map +0 -1
- package/dist/transformer/transformer.d.ts.map +0 -1
- package/dist/transformer/types.d.ts.map +0 -1
- package/dist/worker/createHtmlStream.d.ts +0 -7
- package/dist/worker/createHtmlStream.d.ts.map +0 -1
- package/dist/worker/createWorker.d.ts +0 -10
- package/dist/worker/createWorker.d.ts.map +0 -1
- package/dist/worker/loader.d.ts.map +0 -1
- package/dist/worker/loader.js +0 -7
- package/dist/worker/loader.js.map +0 -1
- package/dist/worker/renderPages.d.ts +0 -18
- package/dist/worker/renderPages.d.ts.map +0 -1
- package/dist/worker/types.d.ts +0 -31
- package/dist/worker/types.d.ts.map +0 -1
- package/dist/worker/worker.d.ts +0 -7
- package/dist/worker/worker.d.ts.map +0 -1
- package/dist/worker/worker.js +0 -112
- package/dist/worker/worker.js.map +0 -1
- package/src/build/createBuildConfig.ts +0 -57
- package/src/build/mergeInputs.ts +0 -42
- package/src/checkFilesExist.ts +0 -67
- package/src/helpers/inputNormalizer.ts +0 -22
- package/src/index.ts +0 -4
- package/src/options.ts +0 -423
- package/src/plugin.ts +0 -5
- package/src/react-client/plugin.ts +0 -34
- package/src/react-server/plugin.ts +0 -409
- package/src/transformer/index.ts +0 -112
- package/src/transformer/preserveDirectives.ts +0 -100
- package/src/transformer/preserver.ts +0 -47
- package/src/worker/createHtmlStream.ts +0 -76
- package/src/worker/createWorker.ts +0 -44
- package/src/worker/renderPages.ts +0 -144
- package/src/worker/types.ts +0 -38
- package/src/worker/worker.tsx +0 -136
- /package/dist/{assertServerCondition.d.ts → plugin/assertServerCondition.d.ts} +0 -0
- /package/dist/{components.d.ts → plugin/components.d.ts} +0 -0
- /package/dist/{copy-dir.d.ts → plugin/copy-dir.d.ts} +0 -0
- /package/dist/{getEnv.d.ts → plugin/getEnv.d.ts} +0 -0
- /package/dist/{helpers → plugin/helpers}/normalizedRelativePath.d.ts +0 -0
- /package/dist/{helpers → plugin/helpers}/tryManifest.d.ts +0 -0
- /package/dist/{manifest.d.ts → plugin/manifest.d.ts} +0 -0
- /package/dist/{module-graph.d.ts → plugin/module-graph.d.ts} +0 -0
- /package/dist/{react-server → plugin/react-server}/createDevMiddleware.d.ts +0 -0
- /package/dist/{react-server → plugin/react-server}/createDevServer.d.ts +0 -0
- /package/dist/{react-server → plugin/react-server}/createReactNodeStreamer.d.ts +0 -0
- /package/dist/{resolvePage.d.ts → plugin/resolvePage.d.ts} +0 -0
- /package/dist/{resolveProps.d.ts → plugin/resolveProps.d.ts} +0 -0
- /package/dist/{transformer → plugin/transformer}/types.d.ts +0 -0
- /package/dist/{worker → plugin/worker}/loader.d.ts +0 -0
- /package/{src → plugin}/assertServerCondition.ts +0 -0
- /package/{src → plugin}/components.tsx +0 -0
- /package/{src → plugin}/copy-dir.ts +0 -0
- /package/{src/server.tsx → plugin/getCondition.ts} +0 -0
- /package/{src → plugin}/helpers/normalizedRelativePath.ts +0 -0
- /package/{src → plugin}/helpers/tryManifest.ts +0 -0
- /package/{src → plugin}/manifest.ts +0 -0
- /package/{src → plugin}/module-graph.ts +0 -0
- /package/{src → plugin}/transformer/README.md +0 -0
- /package/{src → plugin}/transformer/types.ts +0 -0
- /package/{src → plugin}/worker/loader.ts +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
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 { createClientComponentTransformer } from './transformer-client-components.js';
|
|
8
|
+
import { createServerActionTransformer } from './transformer-server-actions.js';
|
|
9
|
+
|
|
10
|
+
function reactTransformPlugin(options) {
|
|
11
|
+
if (process.env["NODE_OPTIONS"]?.match(/--conditions[= ]react-server/)) {
|
|
12
|
+
console.log("react-server");
|
|
13
|
+
} else {
|
|
14
|
+
console.log(process.env["NODE_OPTIONS"]);
|
|
15
|
+
throw new Error('react-server condition not found, set NODE_OPTIONS="--conditions react-server"');
|
|
16
|
+
}
|
|
17
|
+
const projectRoot = options?.projectRoot || process.cwd();
|
|
18
|
+
let transformClientComponent;
|
|
19
|
+
let transformServerAction;
|
|
20
|
+
const clientComponents = /* @__PURE__ */ new Set();
|
|
21
|
+
return {
|
|
22
|
+
name: "vite:react-stream-transformer",
|
|
23
|
+
enforce: "post",
|
|
24
|
+
configResolved(config) {
|
|
25
|
+
transformClientComponent = createClientComponentTransformer({
|
|
26
|
+
moduleId: options?.moduleId || DEFAULT_CONFIG.MODULE_ID({
|
|
27
|
+
projectRoot,
|
|
28
|
+
output: {
|
|
29
|
+
dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server
|
|
30
|
+
},
|
|
31
|
+
isProduction: config.isProduction
|
|
32
|
+
})
|
|
33
|
+
}).transform;
|
|
34
|
+
transformServerAction = createServerActionTransformer({
|
|
35
|
+
moduleId: options?.moduleId || DEFAULT_CONFIG.MODULE_ID({
|
|
36
|
+
projectRoot,
|
|
37
|
+
output: {
|
|
38
|
+
dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server
|
|
39
|
+
},
|
|
40
|
+
isProduction: config.isProduction
|
|
41
|
+
})
|
|
42
|
+
}).transform;
|
|
43
|
+
},
|
|
44
|
+
config(config) {
|
|
45
|
+
const existingInput = config.build?.rollupOptions?.input || {};
|
|
46
|
+
const currentInputs = typeof existingInput === "string" ? { default: existingInput } : existingInput;
|
|
47
|
+
const entries = Array.from(clientComponents).reduce((acc, path) => ({
|
|
48
|
+
...acc,
|
|
49
|
+
[path.replace(DEFAULT_CONFIG.FILE_REGEX, "")]: path
|
|
50
|
+
}), {});
|
|
51
|
+
return {
|
|
52
|
+
build: {
|
|
53
|
+
rollupOptions: {
|
|
54
|
+
input: {
|
|
55
|
+
...currentInputs,
|
|
56
|
+
...entries
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
buildStart() {
|
|
63
|
+
clientComponents.clear();
|
|
64
|
+
},
|
|
65
|
+
async transform(code, id, options2) {
|
|
66
|
+
const hasClientDirective = code.match(/^["']use client["'];?/);
|
|
67
|
+
if (!hasClientDirective) {
|
|
68
|
+
const hasServerDirective = code.match(/^["']use server["'];?/);
|
|
69
|
+
if (!hasServerDirective) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return transformServerAction.bind(this)(code, id, options2);
|
|
73
|
+
}
|
|
74
|
+
clientComponents.add(id);
|
|
75
|
+
console.log("[TransformerPlugin] Found client component:", id);
|
|
76
|
+
return transformClientComponent.bind(this)(code, id, options2);
|
|
77
|
+
},
|
|
78
|
+
// Log final client components list
|
|
79
|
+
buildEnd() {
|
|
80
|
+
console.log("[TransformerPlugin] Final client components:", Array.from(clientComponents));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { reactTransformPlugin };
|
|
86
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../../plugin/transformer/plugin.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { DEFAULT_CONFIG } from \"../config/defaults.js\";\nimport { createClientComponentTransformer } from \"./transformer-client-components.js\";\nimport type { StreamPluginOptions } from \"../types.js\";\nimport { createServerActionTransformer } from \"./transformer-server-actions.js\";\n\n\n/**\n * Plugin for transforming React Client Components.\n *\n * Core responsibilities:\n * 1. Detects \"use client\" directives\n * 2. Transforms client components for RSC boundaries\n * 3. Adds client reference metadata for RSC\n *\n * When a component is marked with \"use client\", it:\n * - Gets transformed into a client reference\n * - Maintains module ID for RSC boundaries\n * - Preserves class/function behavior\n *\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [\n * viteReactClientTransformPlugin({\n * projectRoot: process.cwd(),\n * })\n * ]\n * });\n * ```\n */\n\nexport function reactTransformPlugin(\n options?: StreamPluginOptions\n): Plugin {\n if(process.env['NODE_OPTIONS']?.match(/--conditions[= ]react-server/)) {\n console.log('react-server')\n } else {\n console.log(process.env['NODE_OPTIONS'])\n throw new Error('react-server condition not found, set NODE_OPTIONS=\"--conditions react-server\"')\n }\n const projectRoot = options?.projectRoot || process.cwd();\n // const includeClient = options?.autoDiscover?.clientComponents || DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents;\n // const includeServerFunctions = options?.autoDiscover?.serverFunctions || DEFAULT_CONFIG.AUTO_DISCOVER.serverFunctions;\n let transformClientComponent: any;\n let transformServerAction: any;\n // get the file we are imported from (parent)\n\n // Track client components\n const clientComponents = new Set<string>();\n\n return {\n name: \"vite:react-stream-transformer\",\n enforce: 'post',\n\n configResolved(config) {\n transformClientComponent = createClientComponentTransformer({\n moduleId:\n options?.moduleId ||\n DEFAULT_CONFIG.MODULE_ID({\n projectRoot: projectRoot,\n output: {\n dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server,\n },\n isProduction: config.isProduction,\n }),\n }).transform;\n transformServerAction = createServerActionTransformer({\n moduleId:\n options?.moduleId ||\n DEFAULT_CONFIG.MODULE_ID({\n projectRoot: projectRoot,\n output: {\n dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server,\n },\n isProduction: config.isProduction,\n }),\n }).transform;\n },\n\n config(config) {\n // Get existing inputs\n const existingInput = config.build?.rollupOptions?.input || {};\n const currentInputs = typeof existingInput === 'string' ? { default: existingInput } : existingInput;\n\n // Add client components\n const entries = Array.from(clientComponents).reduce((acc, path) => ({\n ...acc,\n [path.replace(DEFAULT_CONFIG.FILE_REGEX, '')]: path\n }), {});\n\n return {\n build: {\n rollupOptions: {\n input: {\n ...currentInputs,\n ...entries\n }\n }\n }\n };\n },\n\n buildStart() {\n // Reset client components at start of each build\n clientComponents.clear();\n },\n\n async transform(code: string, id: string, options?: { ssr?: boolean }) {\n // Check for directives\n const hasClientDirective = code.match(/^[\"']use client[\"'];?/);\n if (!hasClientDirective) {\n const hasServerDirective = code.match(/^[\"']use server[\"'];?/);\n if (!hasServerDirective) {\n return null;\n }\n return transformServerAction.bind(this)(code, id, options);\n }\n\n // Track client component and transform\n clientComponents.add(id);\n console.log('[TransformerPlugin] Found client component:', id);\n return transformClientComponent.bind(this)(code, id, options);\n },\n\n // Log final client components list\n buildEnd() {\n console.log('[TransformerPlugin] Final client components:', Array.from(clientComponents));\n }\n };\n}\n"],"names":["options"],"mappings":";;;;;;;;;AAgCO,SAAS,qBACd,OACQ,EAAA;AACR,EAAA,IAAG,QAAQ,GAAI,CAAA,cAAc,CAAG,EAAA,KAAA,CAAM,8BAA8B,CAAG,EAAA;AACrE,IAAA,OAAA,CAAQ,IAAI,cAAc,CAAA;AAAA,GACrB,MAAA;AACL,IAAA,OAAA,CAAQ,GAAI,CAAA,OAAA,CAAQ,GAAI,CAAA,cAAc,CAAC,CAAA;AACvC,IAAM,MAAA,IAAI,MAAM,gF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|
+
import type { TransformerOptions } from "./types.js";
|
|
3
|
+
export declare function createClientComponentTransformer({ moduleId: userModuleId, }: TransformerOptions): RollupPlugin;
|
|
4
|
+
/**
|
|
5
|
+
* transformedCode += `
|
|
6
|
+
const ${exportName}Ref = Object.defineProperties(
|
|
7
|
+
${
|
|
8
|
+
isClass
|
|
9
|
+
? `class extends ${exportName} {
|
|
10
|
+
constructor(...args) { super(...args); }
|
|
11
|
+
}`
|
|
12
|
+
: `function(...args) { return ${exportName}.apply(null, args); }`
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
16
|
+
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} }
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
export { ${exportName}Ref as ${exportName} };`;
|
|
20
|
+
*/
|
|
21
|
+
//# sourceMappingURL=transformer-client-components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer-client-components.d.ts","sourceRoot":"","sources":["../../../plugin/transformer/transformer-client-components.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,gCAAgC,CAAC,EAC/C,QAAQ,EAAE,YAAY,GACvB,EAAE,kBAAkB,GAAG,YAAY,CAsEnC;AAED;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
function createClientComponentTransformer({
|
|
7
|
+
moduleId: userModuleId
|
|
8
|
+
}) {
|
|
9
|
+
let moduleIdFn = userModuleId;
|
|
10
|
+
return {
|
|
11
|
+
name: "vite-plugin-react-server:client-components-transformer",
|
|
12
|
+
async transform(code, id, options) {
|
|
13
|
+
try {
|
|
14
|
+
if (id.includes("node_modules") || id.includes("vite/dist")) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const info = this?.getModuleInfo(id);
|
|
18
|
+
const hasDirective = code.match(/^["']use client["'];?/);
|
|
19
|
+
const isClientComponent = hasDirective || info?.meta?.["directives"]?.includes("use client");
|
|
20
|
+
if (!isClientComponent) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
let transformedCode = code;
|
|
24
|
+
const moduleId = moduleIdFn(id, options?.ssr ?? false);
|
|
25
|
+
const exportMatches = Array.from(
|
|
26
|
+
code.matchAll(/export\s+(?:const|let|var|function|class)\s+(\w+)/g)
|
|
27
|
+
);
|
|
28
|
+
if (!exportMatches.length) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
for (const [fullMatch, exportName] of exportMatches) {
|
|
32
|
+
if (!exportName) continue;
|
|
33
|
+
const isClass = fullMatch.includes("class");
|
|
34
|
+
transformedCode = transformedCode.replace(
|
|
35
|
+
fullMatch,
|
|
36
|
+
fullMatch.replace("export ", "")
|
|
37
|
+
);
|
|
38
|
+
transformedCode += `
|
|
39
|
+
const ${exportName}Ref = Object.defineProperties(
|
|
40
|
+
${isClass ? `class extends ${exportName} {
|
|
41
|
+
constructor(...args) { super(...args); }
|
|
42
|
+
}` : `function(...args) { return ${exportName}.apply(null, args); }`},
|
|
43
|
+
{
|
|
44
|
+
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
45
|
+
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} },
|
|
46
|
+
$$filepath: { value: ${JSON.stringify(id)} }
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
export { ${exportName}Ref as ${exportName} };`;
|
|
50
|
+
}
|
|
51
|
+
return { code: transformedCode, map: null };
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error(`[RSC] Error transforming client component: ${id}`, error);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { createClientComponentTransformer };
|
|
61
|
+
//# sourceMappingURL=transformer-client-components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer-client-components.js","sources":["../../../plugin/transformer/transformer-client-components.ts"],"sourcesContent":["import type { Plugin as RollupPlugin } from \"rollup\";\nimport type { TransformerOptions } from \"./types.js\";\n\nexport function createClientComponentTransformer({\n moduleId: userModuleId,\n}: TransformerOptions): RollupPlugin {\n let moduleIdFn = userModuleId;\n\n return {\n name: \"vite-plugin-react-server:client-components-transformer\",\n\n async transform(code: string, id: string, options?: { ssr?: boolean }) {\n try {\n // Skip node_modules and vite internal files\n if (id.includes('node_modules') || id.includes('vite/dist')) {\n return null;\n }\n\n // Check if this is a client component from metadata or directive\n const info = this?.getModuleInfo(id);\n const hasDirective = code.match(/^[\"']use client[\"'];?/);\n const isClientComponent = hasDirective || info?.meta?.['directives']?.includes('use client');\n\n if (!isClientComponent) {\n return null; // Not a client component, skip\n }\n\n let transformedCode = code;\n const moduleId = moduleIdFn!(id, options?.ssr ?? false);\n\n // Find all named exports\n const exportMatches = Array.from(\n code.matchAll(/export\\s+(?:const|let|var|function|class)\\s+(\\w+)/g)\n );\n\n if (!exportMatches.length) {\n return null;\n }\n\n // Transform each export\n for (const [fullMatch, exportName] of exportMatches) {\n if (!exportName) continue;\n\n const isClass = fullMatch.includes(\"class\");\n\n // Remove export keyword\n transformedCode = transformedCode.replace(\n fullMatch,\n fullMatch.replace(\"export \", \"\")\n );\n\n transformedCode += `\nconst ${exportName}Ref = Object.defineProperties(\n ${isClass \n ? `class extends ${exportName} {\n constructor(...args) { super(...args); }\n }`\n : `function(...args) { return ${exportName}.apply(null, args); }`\n },\n {\n $$typeof: { value: Symbol.for(\"react.client.reference\") },\n $$id: { value: ${JSON.stringify(moduleId + \"#\" + exportName)} },\n $$filepath: { value: ${JSON.stringify(id)} }\n }\n);\nexport { ${exportName}Ref as ${exportName} };`;\n }\n\n return { code: transformedCode, map: null };\n } catch (error) {\n console.error(`[RSC] Error transforming client component: ${id}`, error);\n throw error;\n }\n },\n };\n}\n\n/**\n * transformedCode += `\nconst ${exportName}Ref = Object.defineProperties(\n ${\n isClass\n ? `class extends ${exportName} {\n constructor(...args) { super(...args); }\n }`\n : `function(...args) { return ${exportName}.apply(null, args); }`\n },\n {\n $$typeof: { value: Symbol.for(\"react.client.reference\") },\n $$id: { value: ${JSON.stringify(moduleId + \"#\" + exportName)} }\n }\n);\nexport { ${exportName}Ref as ${exportName} };`;\n */\n"],"names":[],"mappings":";;;;;AAGO,SAAS,gCAAiC,CAAA;AAAA,EAC/C,QAAU,EAAA;AACZ,CAAqC,EAAA;AACnC,EAAA,IAAI,UAAa,GAAA,YAAA;AAEjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,wDAAA;AAAA,IAEN,MAAM,SAAA,CAAU,IAAc,EAAA,EAAA,EAAY,OAA6B,EAAA;AACrE,MAAI,IAAA;AAEF,QAAA,IAAI,GAAG,QAAS,CAAA,cAAc,KAAK,EAAG,CAAA,QAAA,CAAS,WAAW,CAAG,EAAA;AAC3D,UAAO,OAAA,IAAA;AAAA;AAIT,QAAM,MAAA,IAAA,GAAO,IAAM,EAAA,aAAA,CAAc,EAAE,CAAA;AACnC,QAAM,MAAA,YAAA,GAAe,IAAK,CAAA,KAAA,CAAM,uBAAuB,CAAA;AACvD,QAAA,MAAM,oBAAoB,YAAgB,IAAA,IAAA,EAAM,OAAO,YAAY,CAAA,EAAG,SAAS,YAAY,CAAA;AAE3F,QAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,UAAO,OAAA,IAAA;AAAA;AAGT,QAAA,IAAI,eAAkB,GAAA,IAAA;AACtB,QAAA,MAAM,QAAW,GAAA,UAAA,CAAY,EAAI,EAAA,OAAA,EAAS,OAAO,KAAK,CAAA;AAGtD,QAAA,MAAM,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ptions } from "./types.js";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function createServerActionTransformer(options: TransformerOptions): {
|
|
3
3
|
name: string;
|
|
4
4
|
enforce: "post";
|
|
5
|
-
transform(code: string, path: string, { ssr }
|
|
6
|
-
inMap: null | string;
|
|
5
|
+
transform(code: string, path: string, { ssr }?: {
|
|
7
6
|
ssr: boolean;
|
|
8
7
|
}): Promise<{
|
|
9
8
|
code: string;
|
|
@@ -27,4 +26,4 @@ const ${exportName}Ref = Object.defineProperties(
|
|
|
27
26
|
);
|
|
28
27
|
export { ${exportName}Ref as ${exportName} };`;
|
|
29
28
|
*/
|
|
30
|
-
//# sourceMappingURL=transformer.d.ts.map
|
|
29
|
+
//# sourceMappingURL=transformer-server-actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer-server-actions.d.ts","sourceRoot":"","sources":["../../../plugin/transformer/transformer-server-actions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,kBAAkB;;;oBAM7D,MAAM,QACN,MAAM,YACH;QAAE,GAAG,EAAE,OAAO,CAAA;KAAE;;;;EAgF9B;AAED;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { SourceMapGenerator } from 'source-map';
|
|
7
|
+
|
|
8
|
+
function createServerActionTransformer(options) {
|
|
9
|
+
return {
|
|
10
|
+
name: "vite-plugin-react-server:server-actions-transformer",
|
|
11
|
+
enforce: "post",
|
|
12
|
+
async transform(code, path, { ssr } = { ssr: false }) {
|
|
13
|
+
try {
|
|
14
|
+
let transformedCode = code;
|
|
15
|
+
const directiveMatch = code.match(/^["']use server["'];?/);
|
|
16
|
+
const moduleId = options.moduleId(path, ssr);
|
|
17
|
+
console.log("[RSC Transform] Module path transformation:", {
|
|
18
|
+
original: path,
|
|
19
|
+
transformed: moduleId
|
|
20
|
+
});
|
|
21
|
+
const exportMatches = Array.from(
|
|
22
|
+
code.matchAll(/export\s+(?:const|let|var|function|class)\s+(\w+)/g)
|
|
23
|
+
);
|
|
24
|
+
if (!exportMatches.length) {
|
|
25
|
+
console.warn(
|
|
26
|
+
`[RSC] No exports found in server action module: ${path}`
|
|
27
|
+
);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
for (const [fullMatch, exportName] of exportMatches) {
|
|
31
|
+
if (!exportName) {
|
|
32
|
+
console.warn(
|
|
33
|
+
`[RSC] Invalid export in server action module: ${path}`
|
|
34
|
+
);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const isClass = fullMatch.includes("class");
|
|
38
|
+
transformedCode = transformedCode.replace(
|
|
39
|
+
fullMatch,
|
|
40
|
+
fullMatch.replace("export ", "")
|
|
41
|
+
);
|
|
42
|
+
if (!directiveMatch || directiveMatch.index !== 0) {
|
|
43
|
+
} else {
|
|
44
|
+
transformedCode += `
|
|
45
|
+
const ${exportName}Ref = Object.defineProperties(
|
|
46
|
+
${isClass ? `class extends ${exportName} {
|
|
47
|
+
constructor(...args) { super(...args); }
|
|
48
|
+
}` : `function(...args) { return ${exportName}.apply(null, args); }`},
|
|
49
|
+
{
|
|
50
|
+
$$typeof: { value: Symbol.for("react.server.reference") },
|
|
51
|
+
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} },
|
|
52
|
+
$$filepath: { value: ${JSON.stringify(path)} },
|
|
53
|
+
$$async: { value: true }
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
export { ${exportName}Ref as ${exportName} };
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
code: transformedCode,
|
|
62
|
+
map: new SourceMapGenerator({ file: path }).toString()
|
|
63
|
+
};
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(
|
|
66
|
+
`[RSC] Error transforming client component: ${path}`,
|
|
67
|
+
error
|
|
68
|
+
);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { createServerActionTransformer };
|
|
76
|
+
//# sourceMappingURL=transformer-server-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer-server-actions.js","sources":["../../../plugin/transformer/transformer-server-actions.ts"],"sourcesContent":["import { SourceMapGenerator } from \"source-map\";\nimport type { TransformerOptions } from \"./types.js\";\n\nexport function createServerActionTransformer(options: TransformerOptions) {\n return {\n name: \"vite-plugin-react-server:server-actions-transformer\",\n enforce: \"post\" as const,\n\n async transform(\n code: string,\n path: string,\n { ssr }: { ssr: boolean } = { ssr: false }\n ) {\n try {\n let transformedCode = code;\n const directiveMatch = code.match(/^[\"']use server[\"'];?/);\n const moduleId = options.moduleId(path, ssr);\n\n // Log the path transformation\n console.log(\"[RSC Transform] Module path transformation:\", {\n original: path,\n transformed: moduleId,\n });\n\n // Find all named exports\n const exportMatches = Array.from(\n code.matchAll(/export\\s+(?:const|let|var|function|class)\\s+(\\w+)/g)\n );\n\n if (!exportMatches.length) {\n console.warn(\n `[RSC] No exports found in server action module: ${path}`\n );\n return null;\n }\n\n // Transform each export\n for (const [fullMatch, exportName] of exportMatches) {\n if (!exportName) {\n console.warn(\n `[RSC] Invalid export in server action module: ${path}`\n );\n continue;\n }\n\n const isClass = fullMatch.includes(\"class\");\n\n // Remove export keyword\n transformedCode = transformedCode.replace(\n fullMatch,\n fullMatch.replace(\"export \", \"\")\n );\n\n if (!directiveMatch || directiveMatch.index !== 0) {\n // Server action\n } else {\n // Client component\n transformedCode += `\nconst ${exportName}Ref = Object.defineProperties(\n ${\n isClass\n ? `class extends ${exportName} {\n constructor(...args) { super(...args); }\n }`\n : `function(...args) { return ${exportName}.apply(null, args); }`\n },\n {\n $$typeof: { value: Symbol.for(\"react.server.reference\") },\n $$id: { value: ${JSON.stringify(moduleId + \"#\" + exportName)} },\n $$filepath: { value: ${JSON.stringify(path)} },\n $$async: { value: true }\n }\n);\nexport { ${exportName}Ref as ${exportName} };\n `;\n }\n }\n\n return {\n code: transformedCode,\n map: new SourceMapGenerator({ file: path }).toString(),\n };\n } catch (error) {\n console.error(\n `[RSC] Error transforming client component: ${path}`,\n error\n );\n throw error;\n }\n },\n };\n}\n\n/**\n * transformedCode += `\nconst ${exportName}Ref = Object.defineProperties(\n ${\n isClass\n ? `class extends ${exportName} {\n constructor(...args) { super(...args); }\n }`\n : `function(...args) { return ${exportName}.apply(null, args); }`\n },\n {\n $$typeof: { value: Symbol.for(\"react.client.reference\") },\n $$id: { value: ${JSON.stringify(moduleId + \"#\" + exportName)} }\n }\n);\nexport { ${exportName}Ref as ${exportName} };`;\n */\n"],"names":[],"mappings":";;;;;;;AAGO,SAAS,8BAA8B,OAA6B,EAAA;AACzE,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,qDAAA;AAAA,IACN,OAAS,EAAA,MAAA;AAAA,IAET,MAAM,SACJ,CAAA,IAAA,EACA,IACA,EAAA,EAAE,KAA0B,GAAA,EAAE,GAAK,EAAA,KAAA,EACnC,EAAA;AACA,MAAI,IAAA;AACF,QAAA,IAAI,eAAkB,GAAA,IAAA;AACtB,QAAM,MAAA,cAAA,GAAiB,IAAK,CAAA,KAAA,CAAM,uBAAuB,CAAA;AACzD,QAAA,MAAM,QAAW,GAAA,OAAA,CAAQ,QAAS,CAAA,IAAA,EAAM,GAAG,CAAA;AAG3C,QAAA,OAAA,CAAQ,IAAI,6CAA+C,EAAA;AAAA,UACzD,QAAU,EAAA,IAAA;AAAA,UACV,WAAa,EAAA;AAAA,SACd,CAAA;AAGD,QAAA,MAAM,gBAAgB,KAAM,CAAA,IAAA;AAAA,UAC1B,IAAA,CAAK,SAAS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vD;AAAA,eACO,KAAO,EAAA;AACd,QAAQ,OAAA,CAAA,KAAA;AAAA,UACN,8CAA8C,IAAI,CAAA,CAAA;AAAA,UAClD;AAAA,SACF;AACA,QAAM,MAAA,KAAA;AAAA;AACR;AACF,GACF;AACF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../plugin/transformer/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,+BAA+B;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;IAClD,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IACjD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CACjD;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;IACjD;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CAClD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { UserConfig, BuildOptions, InlineConfig, AliasOptions, Connect } from 'vite';
|
|
3
|
+
export type NormalizerInput = string | ComponentType<any> | [string, string] | string[];
|
|
4
|
+
export type InputNormalizer = (input: NormalizerInput) => [string, string];
|
|
5
|
+
export type InputNormalizerWorker = (input: NormalizerInput) => Promise<[string, string]>;
|
|
6
|
+
export type ResolvedUserConfig = Required<Pick<UserConfig, "root" | "mode" | "build">> & Omit<UserConfig, "root" | "mode" | "build"> & {
|
|
7
|
+
build: NonNullable<Required<Pick<BuildOptions, "target" | "outDir" | "assetsDir" | "ssr" | "ssrEmitAssets" | "ssrManifest" | "manifest" | "rollupOptions">>> & Omit<BuildOptions, "target" | "outDir" | "assetsDir" | "ssr" | "ssrEmitAssets" | "ssrManifest" | "manifest">;
|
|
8
|
+
};
|
|
9
|
+
export interface StreamPluginOptionsClient {
|
|
10
|
+
outDir?: string;
|
|
11
|
+
build?: BuildConfig;
|
|
12
|
+
assetsDir?: string;
|
|
13
|
+
projectRoot?: string;
|
|
14
|
+
moduleBase?: string;
|
|
15
|
+
moduleBasePath?: string;
|
|
16
|
+
moduleBaseURL?: string;
|
|
17
|
+
clientComponents?: AliasOptions;
|
|
18
|
+
cssFiles?: AliasOptions;
|
|
19
|
+
}
|
|
20
|
+
export type ResolvedUserOptions = Required<Pick<StreamPluginOptions, "moduleBase" | "moduleBasePath" | "moduleBaseURL" | "projectRoot" | "build" | "Page" | "props" | "Html" | "pageExportName" | "propsExportName" | "collectCss" | "collectAssets" | "assetsDir" | "htmlWorkerPath" | "rscWorkerPath" | "loaderPath" | "clientEntry" | "serverEntry" | "moduleBaseExceptions">> & {
|
|
21
|
+
build: NonNullable<Required<StreamPluginOptions["build"]>>;
|
|
22
|
+
autoDiscover: NonNullable<Required<StreamPluginOptions["autoDiscover"]>>;
|
|
23
|
+
};
|
|
24
|
+
export type createBuildConfigFn<C extends "react-client" | "react-server"> = (input: {
|
|
25
|
+
condition: C;
|
|
26
|
+
userOptions: ResolvedUserOptions;
|
|
27
|
+
userConfig: ResolvedUserConfig;
|
|
28
|
+
mode: "production" | "development" | "test";
|
|
29
|
+
inputNormalizer: C extends "react-server" ? InputNormalizerWorker : InputNormalizerWorker;
|
|
30
|
+
}) => C extends "react-server" ? Promise<InlineConfig> : Promise<InlineConfig>;
|
|
31
|
+
export interface StreamPluginOptions {
|
|
32
|
+
projectRoot?: string;
|
|
33
|
+
assetsDir?: string;
|
|
34
|
+
moduleBase: string;
|
|
35
|
+
moduleBasePath?: string;
|
|
36
|
+
moduleBaseURL?: string;
|
|
37
|
+
clientEntry?: string;
|
|
38
|
+
serverEntry?: string;
|
|
39
|
+
autoDiscover?: {
|
|
40
|
+
pagePattern?: RegExp;
|
|
41
|
+
propsPattern?: RegExp;
|
|
42
|
+
clientComponents?: RegExp;
|
|
43
|
+
serverFunctions?: RegExp;
|
|
44
|
+
} | undefined;
|
|
45
|
+
Page: string | ((url: string) => string);
|
|
46
|
+
props?: undefined | string | ((url: string) => string);
|
|
47
|
+
htmlWorkerPath?: string;
|
|
48
|
+
rscWorkerPath?: string;
|
|
49
|
+
loaderPath?: string;
|
|
50
|
+
pageExportName?: string;
|
|
51
|
+
propsExportName?: string;
|
|
52
|
+
Html?: React.FC<{
|
|
53
|
+
manifest: import("vite").Manifest;
|
|
54
|
+
pageProps: any;
|
|
55
|
+
route: string;
|
|
56
|
+
url: string;
|
|
57
|
+
children: React.ReactNode;
|
|
58
|
+
}>;
|
|
59
|
+
collectCss?: boolean;
|
|
60
|
+
collectAssets?: boolean;
|
|
61
|
+
build?: BuildConfig;
|
|
62
|
+
moduleBaseExceptions?: string[];
|
|
63
|
+
moduleId?: (id: string) => string;
|
|
64
|
+
}
|
|
65
|
+
export interface CreateHandlerOptions<T = any> {
|
|
66
|
+
loader: (id: string) => Promise<T>;
|
|
67
|
+
manifest?: import("vite").Manifest;
|
|
68
|
+
moduleGraph?: import("vite").ModuleGraph;
|
|
69
|
+
cssFiles?: string[];
|
|
70
|
+
onCssFile?: (path: string) => void;
|
|
71
|
+
logger?: import("vite").Logger;
|
|
72
|
+
pipableStreamOptions?: any;
|
|
73
|
+
}
|
|
74
|
+
export type ModuleLoader = (url: string, context?: any, defaultLoad?: any) => Promise<Record<string, any>>;
|
|
75
|
+
export interface BaseProps {
|
|
76
|
+
manifest: import("vite").Manifest;
|
|
77
|
+
children?: React.ReactNode;
|
|
78
|
+
assets?: {
|
|
79
|
+
css?: string[];
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export type StreamResult = {
|
|
83
|
+
type: "success";
|
|
84
|
+
stream: any;
|
|
85
|
+
assets?: {
|
|
86
|
+
css?: string[];
|
|
87
|
+
};
|
|
88
|
+
} | {
|
|
89
|
+
type: "error";
|
|
90
|
+
error: unknown;
|
|
91
|
+
} | {
|
|
92
|
+
type: "skip";
|
|
93
|
+
};
|
|
94
|
+
export interface RscStreamOptions {
|
|
95
|
+
Page: React.ComponentType;
|
|
96
|
+
props: any;
|
|
97
|
+
Html: any;
|
|
98
|
+
logger?: Console | import("vite").Logger;
|
|
99
|
+
cssFiles?: string[];
|
|
100
|
+
htmlProps: any;
|
|
101
|
+
route: string;
|
|
102
|
+
url: string;
|
|
103
|
+
pipableStreamOptions?: any;
|
|
104
|
+
moduleBasePath: string;
|
|
105
|
+
}
|
|
106
|
+
export interface RouteConfig {
|
|
107
|
+
path: string;
|
|
108
|
+
pattern?: {
|
|
109
|
+
page?: string;
|
|
110
|
+
props?: string;
|
|
111
|
+
};
|
|
112
|
+
paths?: {
|
|
113
|
+
page: string;
|
|
114
|
+
props: string;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export interface BuildOutput {
|
|
118
|
+
dir?: string;
|
|
119
|
+
rsc?: string;
|
|
120
|
+
ext?: string;
|
|
121
|
+
}
|
|
122
|
+
export interface BuildConfig {
|
|
123
|
+
pages: string[] | (() => Promise<string[]> | string[]);
|
|
124
|
+
client?: string;
|
|
125
|
+
server?: string;
|
|
126
|
+
static?: string;
|
|
127
|
+
}
|
|
128
|
+
export interface RscResolver {
|
|
129
|
+
/**
|
|
130
|
+
* Get RSC data for static generation
|
|
131
|
+
* @param path - Route path (e.g. "/", "/about")
|
|
132
|
+
*/
|
|
133
|
+
getRscData: (path: string) => Promise<{
|
|
134
|
+
Page: React.ComponentType;
|
|
135
|
+
props: any;
|
|
136
|
+
}>;
|
|
137
|
+
}
|
|
138
|
+
export type RequestHandler = Connect.NextHandleFunction;
|
|
139
|
+
export interface SsrStreamOptions {
|
|
140
|
+
url: string;
|
|
141
|
+
controller: AbortController;
|
|
142
|
+
loader: (id: string) => Promise<any>;
|
|
143
|
+
Html: any;
|
|
144
|
+
options: StreamPluginOptions;
|
|
145
|
+
pageExportName: string;
|
|
146
|
+
propsExportName: string;
|
|
147
|
+
moduleGraph: any;
|
|
148
|
+
bootstrapModules?: string[];
|
|
149
|
+
importMap?: Record<string, string[]>;
|
|
150
|
+
clientComponents?: boolean;
|
|
151
|
+
onlyClientComponents?: boolean;
|
|
152
|
+
}
|
|
153
|
+
export type RscServerConfig = {
|
|
154
|
+
/** How to get RSC data (e.g. HTTP, direct import, etc) */
|
|
155
|
+
getRscComponent: (url: string) => React.Usable<React.ReactNode>;
|
|
156
|
+
/** Base URL for client assets */
|
|
157
|
+
clientBase?: string;
|
|
158
|
+
/** SSR stream rendering options */
|
|
159
|
+
ssrOptions?: SsrStreamOptions;
|
|
160
|
+
};
|
|
161
|
+
export interface RscServerModule {
|
|
162
|
+
/**
|
|
163
|
+
* Get RSC data for a route
|
|
164
|
+
* @param path - Route path (e.g. "/", "/about")
|
|
165
|
+
* @returns Page component and props
|
|
166
|
+
*/
|
|
167
|
+
getRscData: (path: string) => Promise<{
|
|
168
|
+
/** Page component to render */
|
|
169
|
+
Page: React.ComponentType;
|
|
170
|
+
/** Props to pass to the page */
|
|
171
|
+
props: any;
|
|
172
|
+
}>;
|
|
173
|
+
}
|
|
174
|
+
export interface RegisterComponentMessage {
|
|
175
|
+
type: "REGISTER_COMPONENT";
|
|
176
|
+
id: string;
|
|
177
|
+
code: string;
|
|
178
|
+
}
|
|
179
|
+
export type RscBuildResult = string[];
|
|
180
|
+
export interface ReactStreamPluginMeta {
|
|
181
|
+
timing: BuildTiming;
|
|
182
|
+
}
|
|
183
|
+
export interface BuildTiming {
|
|
184
|
+
start: number;
|
|
185
|
+
configResolved?: number;
|
|
186
|
+
buildStart?: number;
|
|
187
|
+
buildEnd?: number;
|
|
188
|
+
renderStart?: number;
|
|
189
|
+
renderEnd?: number;
|
|
190
|
+
total?: number;
|
|
191
|
+
}
|
|
192
|
+
export type CheckFilesExistReturn = {
|
|
193
|
+
propsMap: Map<string, string>;
|
|
194
|
+
propsSet: Set<string>;
|
|
195
|
+
pageMap: Map<string, string>;
|
|
196
|
+
pageSet: Set<string>;
|
|
197
|
+
};
|
|
198
|
+
export type WorkerMessage = {
|
|
199
|
+
type: 'READY';
|
|
200
|
+
} | {
|
|
201
|
+
type: 'ERROR';
|
|
202
|
+
error: string | Error;
|
|
203
|
+
} | {
|
|
204
|
+
type: 'RSC_CHUNK';
|
|
205
|
+
id: string;
|
|
206
|
+
chunk: Buffer;
|
|
207
|
+
} | {
|
|
208
|
+
type: 'RSC_END';
|
|
209
|
+
id: string;
|
|
210
|
+
} | {
|
|
211
|
+
type: 'SHUTDOWN';
|
|
212
|
+
};
|
|
213
|
+
export type ModuleId = string & {
|
|
214
|
+
readonly __brand: unique symbol;
|
|
215
|
+
};
|
|
216
|
+
export type PagePath = string & {
|
|
217
|
+
readonly __brand: unique symbol;
|
|
218
|
+
};
|
|
219
|
+
export type HtmlProps = {
|
|
220
|
+
pageProps: any;
|
|
221
|
+
route: string;
|
|
222
|
+
url: string;
|
|
223
|
+
cssFiles: string[];
|
|
224
|
+
};
|
|
225
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../plugin/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,OAAO,EACR,MAAM,MAAM,CAAC;AAGd,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,MAA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OAAO,EAAE,GAAG,CAAC,MAAM,EAAC,MAAM,CAAC,CAAC;IAC5B,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACrB,CAAA;AAGD,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAGzB,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AACpE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AAGpE,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,GAAG,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Worker, type ResourceLimits } from "node:worker_threads";
|
|
2
|
+
type CreateWorkerOptions = {
|
|
3
|
+
projectRoot?: string;
|
|
4
|
+
condition?: "react-server" | "react-client";
|
|
5
|
+
nodePath?: string;
|
|
6
|
+
nodeOptions?: string;
|
|
7
|
+
mode?: "production" | "development";
|
|
8
|
+
reverseCondition?: boolean;
|
|
9
|
+
maxListeners?: number;
|
|
10
|
+
workerPath: string;
|
|
11
|
+
resourceLimits?: ResourceLimits;
|
|
12
|
+
};
|
|
13
|
+
export declare function createWorker(options: CreateWorkerOptions): Promise<Worker>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=createWorker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createWorker.d.ts","sourceRoot":"","sources":["../../../plugin/worker/createWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIlE,KAAK,mBAAmB,GAAG;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,cAAc,GAAG,cAAc,CAAC;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,YAAY,GAAG,aAAa,CAAC;IACpC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF,wBAAsB,YAAY,CAAC,OAAO,EAAE,mBAAmB,mBAmE9D"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { Worker } from 'node:worker_threads';
|
|
7
|
+
import { getNodePath, getMode } from '../config/getPaths.js';
|
|
8
|
+
import { getCondition } from '../config/getCondition.js';
|
|
9
|
+
|
|
10
|
+
async function createWorker(options) {
|
|
11
|
+
const {
|
|
12
|
+
projectRoot = process.cwd(),
|
|
13
|
+
nodePath = getNodePath(projectRoot),
|
|
14
|
+
condition = getCondition(),
|
|
15
|
+
reverseCondition = true,
|
|
16
|
+
maxListeners = 100,
|
|
17
|
+
mode = getMode(),
|
|
18
|
+
workerPath,
|
|
19
|
+
resourceLimits = {
|
|
20
|
+
maxOldGenerationSizeMb: 512,
|
|
21
|
+
maxYoungGenerationSizeMb: 128
|
|
22
|
+
}
|
|
23
|
+
} = options;
|
|
24
|
+
const isTestEnv = process.env["VITEST"] || process.env["NODE_ENV"] === "test";
|
|
25
|
+
const nodeEnv = isTestEnv ? "development" : mode;
|
|
26
|
+
const env = {
|
|
27
|
+
...process.env,
|
|
28
|
+
NODE_ENV: nodeEnv,
|
|
29
|
+
NODE_PATH: nodePath,
|
|
30
|
+
// Clear any inherited conditions for worker
|
|
31
|
+
NODE_OPTIONS: reverseCondition ? condition === "react-server" ? "--conditions=react-client" : "--conditions=react-server" : process.env["NODE_OPTIONS"]
|
|
32
|
+
};
|
|
33
|
+
const maxRetries = 3;
|
|
34
|
+
for (let tries = 0; tries < maxRetries; tries++) {
|
|
35
|
+
try {
|
|
36
|
+
const worker = new Worker(workerPath, {
|
|
37
|
+
env,
|
|
38
|
+
// Increase resource limits for stream handling
|
|
39
|
+
resourceLimits
|
|
40
|
+
});
|
|
41
|
+
worker.setMaxListeners(maxListeners);
|
|
42
|
+
const ready = await Promise.race([
|
|
43
|
+
new Promise((_, reject) => {
|
|
44
|
+
setTimeout(() => reject(new Error(`Worker startup timeout: ${workerPath}`)), 5e3);
|
|
45
|
+
}),
|
|
46
|
+
new Promise((resolve, reject) => {
|
|
47
|
+
worker.once("message", (msg) => {
|
|
48
|
+
if (msg.type === "READY") {
|
|
49
|
+
if (msg.env === nodeEnv) {
|
|
50
|
+
resolve(true);
|
|
51
|
+
} else {
|
|
52
|
+
reject(new Error(`Worker environment mismatch: expected ${nodeEnv}, got ${msg.env}`));
|
|
53
|
+
}
|
|
54
|
+
} else if (msg.type === "ERROR") {
|
|
55
|
+
reject(new Error(msg.error));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
worker.once("error", reject);
|
|
59
|
+
})
|
|
60
|
+
]);
|
|
61
|
+
if (ready) return worker;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.warn(`Worker startup attempt ${tries + 1} failed:`, error);
|
|
64
|
+
if (tries === maxRetries - 1) throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error("Failed to start worker after retries");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { createWorker };
|
|
71
|
+
//# sourceMappingURL=createWorker.js.map
|