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,131 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
3
|
+
import { createClientComponentTransformer } from "./transformer-client-components.js";
|
|
4
|
+
import type { StreamPluginOptions } from "../types.js";
|
|
5
|
+
import { createServerActionTransformer } from "./transformer-server-actions.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Plugin for transforming React Client Components.
|
|
10
|
+
*
|
|
11
|
+
* Core responsibilities:
|
|
12
|
+
* 1. Detects "use client" directives
|
|
13
|
+
* 2. Transforms client components for RSC boundaries
|
|
14
|
+
* 3. Adds client reference metadata for RSC
|
|
15
|
+
*
|
|
16
|
+
* When a component is marked with "use client", it:
|
|
17
|
+
* - Gets transformed into a client reference
|
|
18
|
+
* - Maintains module ID for RSC boundaries
|
|
19
|
+
* - Preserves class/function behavior
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* export default defineConfig({
|
|
24
|
+
* plugins: [
|
|
25
|
+
* viteReactClientTransformPlugin({
|
|
26
|
+
* projectRoot: process.cwd(),
|
|
27
|
+
* })
|
|
28
|
+
* ]
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
export function reactTransformPlugin(
|
|
34
|
+
options?: StreamPluginOptions
|
|
35
|
+
): Plugin {
|
|
36
|
+
if(process.env['NODE_OPTIONS']?.match(/--conditions[= ]react-server/)) {
|
|
37
|
+
console.log('react-server')
|
|
38
|
+
} else {
|
|
39
|
+
console.log(process.env['NODE_OPTIONS'])
|
|
40
|
+
throw new Error('react-server condition not found, set NODE_OPTIONS="--conditions react-server"')
|
|
41
|
+
}
|
|
42
|
+
const projectRoot = options?.projectRoot || process.cwd();
|
|
43
|
+
// const includeClient = options?.autoDiscover?.clientComponents || DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents;
|
|
44
|
+
// const includeServerFunctions = options?.autoDiscover?.serverFunctions || DEFAULT_CONFIG.AUTO_DISCOVER.serverFunctions;
|
|
45
|
+
let transformClientComponent: any;
|
|
46
|
+
let transformServerAction: any;
|
|
47
|
+
// get the file we are imported from (parent)
|
|
48
|
+
|
|
49
|
+
// Track client components
|
|
50
|
+
const clientComponents = new Set<string>();
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
name: "vite:react-stream-transformer",
|
|
54
|
+
enforce: 'post',
|
|
55
|
+
|
|
56
|
+
configResolved(config) {
|
|
57
|
+
transformClientComponent = createClientComponentTransformer({
|
|
58
|
+
moduleId:
|
|
59
|
+
options?.moduleId ||
|
|
60
|
+
DEFAULT_CONFIG.MODULE_ID({
|
|
61
|
+
projectRoot: projectRoot,
|
|
62
|
+
output: {
|
|
63
|
+
dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server,
|
|
64
|
+
},
|
|
65
|
+
isProduction: config.isProduction,
|
|
66
|
+
}),
|
|
67
|
+
}).transform;
|
|
68
|
+
transformServerAction = createServerActionTransformer({
|
|
69
|
+
moduleId:
|
|
70
|
+
options?.moduleId ||
|
|
71
|
+
DEFAULT_CONFIG.MODULE_ID({
|
|
72
|
+
projectRoot: projectRoot,
|
|
73
|
+
output: {
|
|
74
|
+
dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server,
|
|
75
|
+
},
|
|
76
|
+
isProduction: config.isProduction,
|
|
77
|
+
}),
|
|
78
|
+
}).transform;
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
config(config) {
|
|
82
|
+
// Get existing inputs
|
|
83
|
+
const existingInput = config.build?.rollupOptions?.input || {};
|
|
84
|
+
const currentInputs = typeof existingInput === 'string' ? { default: existingInput } : existingInput;
|
|
85
|
+
|
|
86
|
+
// Add client components
|
|
87
|
+
const entries = Array.from(clientComponents).reduce((acc, path) => ({
|
|
88
|
+
...acc,
|
|
89
|
+
[path.replace(DEFAULT_CONFIG.FILE_REGEX, '')]: path
|
|
90
|
+
}), {});
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
build: {
|
|
94
|
+
rollupOptions: {
|
|
95
|
+
input: {
|
|
96
|
+
...currentInputs,
|
|
97
|
+
...entries
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
buildStart() {
|
|
105
|
+
// Reset client components at start of each build
|
|
106
|
+
clientComponents.clear();
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
async transform(code: string, id: string, options?: { ssr?: boolean }) {
|
|
110
|
+
// Check for directives
|
|
111
|
+
const hasClientDirective = code.match(/^["']use client["'];?/);
|
|
112
|
+
if (!hasClientDirective) {
|
|
113
|
+
const hasServerDirective = code.match(/^["']use server["'];?/);
|
|
114
|
+
if (!hasServerDirective) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return transformServerAction.bind(this)(code, id, options);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Track client component and transform
|
|
121
|
+
clientComponents.add(id);
|
|
122
|
+
console.log('[TransformerPlugin] Found client component:', id);
|
|
123
|
+
return transformClientComponent.bind(this)(code, id, options);
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
// Log final client components list
|
|
127
|
+
buildEnd() {
|
|
128
|
+
console.log('[TransformerPlugin] Final client components:', Array.from(clientComponents));
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Plugin as RollupPlugin } from "rollup";
|
|
2
|
+
import type { TransformerOptions } from "./types.js";
|
|
3
|
+
|
|
4
|
+
export function createClientComponentTransformer({
|
|
5
|
+
moduleId: userModuleId,
|
|
6
|
+
}: TransformerOptions): RollupPlugin {
|
|
7
|
+
let moduleIdFn = userModuleId;
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
name: "vite-plugin-react-server:client-components-transformer",
|
|
11
|
+
|
|
12
|
+
async transform(code: string, id: string, options?: { ssr?: boolean }) {
|
|
13
|
+
try {
|
|
14
|
+
// Skip node_modules and vite internal files
|
|
15
|
+
if (id.includes('node_modules') || id.includes('vite/dist')) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Check if this is a client component from metadata or directive
|
|
20
|
+
const info = this?.getModuleInfo(id);
|
|
21
|
+
const hasDirective = code.match(/^["']use client["'];?/);
|
|
22
|
+
const isClientComponent = hasDirective || info?.meta?.['directives']?.includes('use client');
|
|
23
|
+
|
|
24
|
+
if (!isClientComponent) {
|
|
25
|
+
return null; // Not a client component, skip
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let transformedCode = code;
|
|
29
|
+
const moduleId = moduleIdFn!(id, options?.ssr ?? false);
|
|
30
|
+
|
|
31
|
+
// Find all named exports
|
|
32
|
+
const exportMatches = Array.from(
|
|
33
|
+
code.matchAll(/export\s+(?:const|let|var|function|class)\s+(\w+)/g)
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (!exportMatches.length) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Transform each export
|
|
41
|
+
for (const [fullMatch, exportName] of exportMatches) {
|
|
42
|
+
if (!exportName) continue;
|
|
43
|
+
|
|
44
|
+
const isClass = fullMatch.includes("class");
|
|
45
|
+
|
|
46
|
+
// Remove export keyword
|
|
47
|
+
transformedCode = transformedCode.replace(
|
|
48
|
+
fullMatch,
|
|
49
|
+
fullMatch.replace("export ", "")
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
transformedCode += `
|
|
53
|
+
const ${exportName}Ref = Object.defineProperties(
|
|
54
|
+
${isClass
|
|
55
|
+
? `class extends ${exportName} {
|
|
56
|
+
constructor(...args) { super(...args); }
|
|
57
|
+
}`
|
|
58
|
+
: `function(...args) { return ${exportName}.apply(null, args); }`
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
62
|
+
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} },
|
|
63
|
+
$$filepath: { value: ${JSON.stringify(id)} }
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
export { ${exportName}Ref as ${exportName} };`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return { code: transformedCode, map: null };
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error(`[RSC] Error transforming client component: ${id}`, error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* transformedCode += `
|
|
80
|
+
const ${exportName}Ref = Object.defineProperties(
|
|
81
|
+
${
|
|
82
|
+
isClass
|
|
83
|
+
? `class extends ${exportName} {
|
|
84
|
+
constructor(...args) { super(...args); }
|
|
85
|
+
}`
|
|
86
|
+
: `function(...args) { return ${exportName}.apply(null, args); }`
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
90
|
+
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} }
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
export { ${exportName}Ref as ${exportName} };`;
|
|
94
|
+
*/
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { SourceMapGenerator } from "source-map";
|
|
2
2
|
import type { TransformerOptions } from "./types.js";
|
|
3
3
|
|
|
4
|
-
export function
|
|
4
|
+
export function createServerActionTransformer(options: TransformerOptions) {
|
|
5
5
|
return {
|
|
6
|
-
name: "vite
|
|
6
|
+
name: "vite-plugin-react-server:server-actions-transformer",
|
|
7
7
|
enforce: "post" as const,
|
|
8
8
|
|
|
9
9
|
async transform(
|
|
10
10
|
code: string,
|
|
11
11
|
path: string,
|
|
12
|
-
{ ssr }: {
|
|
12
|
+
{ ssr }: { ssr: boolean } = { ssr: false }
|
|
13
13
|
) {
|
|
14
14
|
try {
|
|
15
15
|
let transformedCode = code;
|
|
16
|
-
const directiveMatch = code.match(/^["']use
|
|
16
|
+
const directiveMatch = code.match(/^["']use server["'];?/);
|
|
17
17
|
const moduleId = options.moduleId(path, ssr);
|
|
18
18
|
|
|
19
19
|
// Log the path transformation
|
|
@@ -28,14 +28,18 @@ export function createRscTransformer(options: TransformerOptions) {
|
|
|
28
28
|
);
|
|
29
29
|
|
|
30
30
|
if (!exportMatches.length) {
|
|
31
|
-
console.warn(
|
|
31
|
+
console.warn(
|
|
32
|
+
`[RSC] No exports found in server action module: ${path}`
|
|
33
|
+
);
|
|
32
34
|
return null;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
// Transform each export
|
|
36
38
|
for (const [fullMatch, exportName] of exportMatches) {
|
|
37
39
|
if (!exportName) {
|
|
38
|
-
console.warn(
|
|
40
|
+
console.warn(
|
|
41
|
+
`[RSC] Invalid export in server action module: ${path}`
|
|
42
|
+
);
|
|
39
43
|
continue;
|
|
40
44
|
}
|
|
41
45
|
|
|
@@ -48,7 +52,9 @@ export function createRscTransformer(options: TransformerOptions) {
|
|
|
48
52
|
);
|
|
49
53
|
|
|
50
54
|
if (!directiveMatch || directiveMatch.index !== 0) {
|
|
51
|
-
// Server
|
|
55
|
+
// Server action
|
|
56
|
+
} else {
|
|
57
|
+
// Client component
|
|
52
58
|
transformedCode += `
|
|
53
59
|
const ${exportName}Ref = Object.defineProperties(
|
|
54
60
|
${
|
|
@@ -66,26 +72,7 @@ const ${exportName}Ref = Object.defineProperties(
|
|
|
66
72
|
}
|
|
67
73
|
);
|
|
68
74
|
export { ${exportName}Ref as ${exportName} };
|
|
69
|
-
`;
|
|
70
|
-
} else {
|
|
71
|
-
// Client component
|
|
72
|
-
transformedCode += `
|
|
73
|
-
const ${exportName}Ref = Object.defineProperties(
|
|
74
|
-
${
|
|
75
|
-
isClass
|
|
76
|
-
? `class extends ${exportName} {
|
|
77
|
-
constructor(...args) { super(...args); }
|
|
78
|
-
}`
|
|
79
|
-
: `function(...args) { return ${exportName}.apply(null, args); }`
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
$$typeof: { value: Symbol.for("react.client.reference") },
|
|
83
|
-
$$id: { value: ${JSON.stringify(moduleId + "#" + exportName)} },
|
|
84
|
-
$$filepath: { value: ${JSON.stringify(path)} }
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
export { ${exportName}Ref as ${exportName} };
|
|
88
|
-
`;
|
|
75
|
+
`;
|
|
89
76
|
}
|
|
90
77
|
}
|
|
91
78
|
|
package/{src → plugin}/types.ts
RENAMED
|
@@ -1,14 +1,43 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
UserConfig,
|
|
3
4
|
BuildOptions,
|
|
5
|
+
InlineConfig,
|
|
6
|
+
AliasOptions,
|
|
4
7
|
Connect,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
} from 'vite';
|
|
9
|
+
|
|
10
|
+
// Input can be a string path, React component, tuple, or array
|
|
11
|
+
export type NormalizerInput = string | ComponentType<any> | [string, string] | string[];
|
|
12
|
+
|
|
13
|
+
export type InputNormalizer = (input: NormalizerInput) => [string, string];
|
|
14
|
+
|
|
15
|
+
export type InputNormalizerWorker = (input: NormalizerInput) => Promise<[string, string]>;
|
|
16
|
+
|
|
17
|
+
export type ResolvedUserConfig = Required<Pick<UserConfig, "root" | "mode" | "build">> &
|
|
18
|
+
Omit<UserConfig, "root" | "mode" | "build"> & {
|
|
19
|
+
build: NonNullable<Required<Pick<BuildOptions,
|
|
20
|
+
"target" |
|
|
21
|
+
"outDir" |
|
|
22
|
+
"assetsDir" |
|
|
23
|
+
"ssr" |
|
|
24
|
+
"ssrEmitAssets" |
|
|
25
|
+
"ssrManifest" |
|
|
26
|
+
"manifest" |
|
|
27
|
+
"rollupOptions"
|
|
28
|
+
>>> &
|
|
29
|
+
Omit<BuildOptions,
|
|
30
|
+
"target" |
|
|
31
|
+
"outDir" |
|
|
32
|
+
"assetsDir" |
|
|
33
|
+
"ssr" |
|
|
34
|
+
"ssrEmitAssets" |
|
|
35
|
+
"ssrManifest" |
|
|
36
|
+
"manifest"
|
|
37
|
+
>
|
|
38
|
+
};
|
|
11
39
|
|
|
40
|
+
// Client plugin options
|
|
12
41
|
export interface StreamPluginOptionsClient {
|
|
13
42
|
outDir?: string;
|
|
14
43
|
build?: BuildConfig;
|
|
@@ -37,11 +66,11 @@ export type ResolvedUserOptions = Required<
|
|
|
37
66
|
| "collectCss"
|
|
38
67
|
| "collectAssets"
|
|
39
68
|
| "assetsDir"
|
|
40
|
-
| "
|
|
69
|
+
| "htmlWorkerPath"
|
|
70
|
+
| "rscWorkerPath"
|
|
41
71
|
| "loaderPath"
|
|
42
72
|
| "clientEntry"
|
|
43
|
-
| "
|
|
44
|
-
| "clientOutDir"
|
|
73
|
+
| "serverEntry"
|
|
45
74
|
| "moduleBaseExceptions"
|
|
46
75
|
>
|
|
47
76
|
> & {
|
|
@@ -49,36 +78,44 @@ export type ResolvedUserOptions = Required<
|
|
|
49
78
|
autoDiscover: NonNullable<Required<StreamPluginOptions["autoDiscover"]>>;
|
|
50
79
|
};
|
|
51
80
|
|
|
52
|
-
export type
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
81
|
+
export type createBuildConfigFn<C extends "react-client" | "react-server"> = (input: {
|
|
82
|
+
condition: C;
|
|
83
|
+
userOptions: ResolvedUserOptions;
|
|
84
|
+
userConfig: ResolvedUserConfig;
|
|
85
|
+
mode: "production" | "development" | "test";
|
|
86
|
+
inputNormalizer: C extends "react-server" ? InputNormalizerWorker : InputNormalizerWorker;
|
|
87
|
+
}) => C extends "react-server" ? Promise<InlineConfig> : Promise<InlineConfig>;
|
|
57
88
|
|
|
58
89
|
export interface StreamPluginOptions {
|
|
59
90
|
projectRoot?: string;
|
|
60
91
|
assetsDir?: string;
|
|
61
|
-
moduleBase
|
|
92
|
+
moduleBase: string;
|
|
62
93
|
moduleBasePath?: string;
|
|
63
94
|
moduleBaseURL?: string;
|
|
64
95
|
clientEntry?: string;
|
|
65
|
-
|
|
66
|
-
clientOutDir?: string;
|
|
96
|
+
serverEntry?: string;
|
|
67
97
|
// Auto-discovery (zero-config)
|
|
68
98
|
autoDiscover?: {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
99
|
+
// default: [Pp]age.tsx
|
|
100
|
+
pagePattern?: RegExp;
|
|
101
|
+
// default: [Pp]rops.ts
|
|
102
|
+
propsPattern?: RegExp;
|
|
103
|
+
// default: "use client" and .client./\.(m|c)?(j|t)sx?$/
|
|
104
|
+
clientComponents?: RegExp;
|
|
105
|
+
// default: "use server" and .server./\.(m|c)?(j|t)sx?$/
|
|
106
|
+
serverFunctions?: RegExp;
|
|
107
|
+
} | undefined;
|
|
72
108
|
// Manual configuration
|
|
73
109
|
Page: string | ((url: string) => string);
|
|
74
110
|
props?: undefined | string | ((url: string) => string);
|
|
75
111
|
// Escape hatches
|
|
76
|
-
|
|
112
|
+
htmlWorkerPath?: string;
|
|
113
|
+
rscWorkerPath?: string;
|
|
77
114
|
loaderPath?: string;
|
|
78
115
|
pageExportName?: string;
|
|
79
116
|
propsExportName?: string;
|
|
80
117
|
Html?: React.FC<{
|
|
81
|
-
manifest: Manifest;
|
|
118
|
+
manifest: import("vite").Manifest;
|
|
82
119
|
pageProps: any;
|
|
83
120
|
route: string;
|
|
84
121
|
url: string;
|
|
@@ -88,15 +125,16 @@ export interface StreamPluginOptions {
|
|
|
88
125
|
collectAssets?: boolean;
|
|
89
126
|
build?: BuildConfig;
|
|
90
127
|
moduleBaseExceptions?: string[];
|
|
128
|
+
moduleId?: (id: string) => string;
|
|
91
129
|
}
|
|
92
130
|
|
|
93
131
|
export interface CreateHandlerOptions<T = any> {
|
|
94
132
|
loader: (id: string) => Promise<T>;
|
|
95
|
-
manifest?: Manifest;
|
|
96
|
-
moduleGraph?: ModuleGraph;
|
|
133
|
+
manifest?: import("vite").Manifest;
|
|
134
|
+
moduleGraph?: import("vite").ModuleGraph;
|
|
97
135
|
cssFiles?: string[];
|
|
98
136
|
onCssFile?: (path: string) => void;
|
|
99
|
-
logger?: Logger;
|
|
137
|
+
logger?: import("vite").Logger;
|
|
100
138
|
pipableStreamOptions?: any;
|
|
101
139
|
}
|
|
102
140
|
|
|
@@ -107,7 +145,7 @@ export type ModuleLoader = (
|
|
|
107
145
|
) => Promise<Record<string, any>>;
|
|
108
146
|
|
|
109
147
|
export interface BaseProps {
|
|
110
|
-
manifest: Manifest;
|
|
148
|
+
manifest: import("vite").Manifest;
|
|
111
149
|
children?: React.ReactNode;
|
|
112
150
|
assets?: {
|
|
113
151
|
css?: string[];
|
|
@@ -129,8 +167,9 @@ export interface RscStreamOptions {
|
|
|
129
167
|
Page: React.ComponentType;
|
|
130
168
|
props: any;
|
|
131
169
|
Html: any;
|
|
132
|
-
logger?: Console | Logger;
|
|
170
|
+
logger?: Console | import("vite").Logger;
|
|
133
171
|
cssFiles?: string[];
|
|
172
|
+
htmlProps: any;
|
|
134
173
|
route: string;
|
|
135
174
|
url: string;
|
|
136
175
|
pipableStreamOptions?: any;
|
|
@@ -161,6 +200,7 @@ export interface BuildConfig {
|
|
|
161
200
|
pages: string[] | (() => Promise<string[]> | string[]);
|
|
162
201
|
client?: string; // Output directory for client files
|
|
163
202
|
server?: string; // Output directory for server files
|
|
203
|
+
static?: string; // Output directory for static environment - works in both
|
|
164
204
|
}
|
|
165
205
|
|
|
166
206
|
export interface RscResolver {
|
|
@@ -174,32 +214,6 @@ export interface RscResolver {
|
|
|
174
214
|
}>;
|
|
175
215
|
}
|
|
176
216
|
|
|
177
|
-
export interface Options {
|
|
178
|
-
include?: RegExp;
|
|
179
|
-
projectRoot?: string;
|
|
180
|
-
moduleBase: string;
|
|
181
|
-
// can be inferred from moduleBase, will add / to moduleBase by default (if not already present)
|
|
182
|
-
moduleBasePath?: string;
|
|
183
|
-
Html?: React.ComponentType<React.PropsWithChildren<{ manifest: Manifest }>>;
|
|
184
|
-
Page: string | ((url: string) => string);
|
|
185
|
-
props?: string | ((url: string) => string);
|
|
186
|
-
pageExportName?: string;
|
|
187
|
-
propsExportName?: string;
|
|
188
|
-
collectCss?: boolean;
|
|
189
|
-
collectAssets?: boolean;
|
|
190
|
-
emitCss?: boolean;
|
|
191
|
-
moduleLoader?: (server: ViteDevServer) => ModuleLoader;
|
|
192
|
-
build?: BuildConfig;
|
|
193
|
-
outDir?: string; // defaults to 'dist'
|
|
194
|
-
/**
|
|
195
|
-
* Configure static asset copying
|
|
196
|
-
* - true: Copy all assets
|
|
197
|
-
* - false: Don't copy assets
|
|
198
|
-
* - Function: Custom filter for which files to copy
|
|
199
|
-
*/
|
|
200
|
-
copyAssets?: boolean | ((file: string) => boolean);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
217
|
export type RequestHandler = Connect.NextHandleFunction;
|
|
204
218
|
|
|
205
219
|
export interface SsrStreamOptions {
|
|
@@ -261,3 +275,31 @@ export interface BuildTiming {
|
|
|
261
275
|
renderEnd?: number;
|
|
262
276
|
total?: number;
|
|
263
277
|
}
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
export type CheckFilesExistReturn = {
|
|
281
|
+
propsMap: Map<string,string>,
|
|
282
|
+
propsSet: Set<string>
|
|
283
|
+
pageMap: Map<string,string>,
|
|
284
|
+
pageSet: Set<string>
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Add strict type checking for worker messages
|
|
288
|
+
export type WorkerMessage =
|
|
289
|
+
| { type: 'READY' }
|
|
290
|
+
| { type: 'ERROR'; error: string | Error }
|
|
291
|
+
| { type: 'RSC_CHUNK'; id: string; chunk: Buffer }
|
|
292
|
+
| { type: 'RSC_END'; id: string }
|
|
293
|
+
| { type: 'SHUTDOWN' };
|
|
294
|
+
|
|
295
|
+
// Add branded types for safety
|
|
296
|
+
export type ModuleId = string & { readonly __brand: unique symbol };
|
|
297
|
+
export type PagePath = string & { readonly __brand: unique symbol };
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
export type HtmlProps = {
|
|
301
|
+
pageProps: any;
|
|
302
|
+
route: string;
|
|
303
|
+
url: string;
|
|
304
|
+
cssFiles: string[];
|
|
305
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Worker, type ResourceLimits } from "node:worker_threads";
|
|
2
|
+
import { getMode, getNodePath } from "../config/getPaths.js";
|
|
3
|
+
import { getCondition } from "../config/getCondition.js";
|
|
4
|
+
|
|
5
|
+
type CreateWorkerOptions = {
|
|
6
|
+
projectRoot?: string;
|
|
7
|
+
condition?: "react-server" | "react-client";
|
|
8
|
+
nodePath?: string;
|
|
9
|
+
nodeOptions?: string;
|
|
10
|
+
mode?: "production" | "development";
|
|
11
|
+
reverseCondition?: boolean;
|
|
12
|
+
maxListeners?: number;
|
|
13
|
+
workerPath: string;
|
|
14
|
+
resourceLimits?: ResourceLimits;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export async function createWorker(options: CreateWorkerOptions) {
|
|
18
|
+
const {
|
|
19
|
+
projectRoot = process.cwd(),
|
|
20
|
+
nodePath = getNodePath(projectRoot),
|
|
21
|
+
condition = getCondition(),
|
|
22
|
+
reverseCondition = true,
|
|
23
|
+
maxListeners = 100,
|
|
24
|
+
mode = getMode(),
|
|
25
|
+
workerPath,
|
|
26
|
+
resourceLimits = {
|
|
27
|
+
maxOldGenerationSizeMb: 512,
|
|
28
|
+
maxYoungGenerationSizeMb: 128,
|
|
29
|
+
}
|
|
30
|
+
} = options;
|
|
31
|
+
|
|
32
|
+
// Ensure consistent NODE_ENV between main thread and worker
|
|
33
|
+
const isTestEnv = process.env['VITEST'] || process.env['NODE_ENV'] === 'test';
|
|
34
|
+
const nodeEnv = isTestEnv ? 'development' : mode;
|
|
35
|
+
|
|
36
|
+
const env = {
|
|
37
|
+
...process.env,
|
|
38
|
+
NODE_ENV: nodeEnv,
|
|
39
|
+
NODE_PATH: nodePath,
|
|
40
|
+
// Clear any inherited conditions for worker
|
|
41
|
+
NODE_OPTIONS: reverseCondition ?
|
|
42
|
+
(condition === 'react-server' ? '--conditions=react-client' : '--conditions=react-server')
|
|
43
|
+
: process.env['NODE_OPTIONS']
|
|
44
|
+
};
|
|
45
|
+
const maxRetries = 3;
|
|
46
|
+
for (let tries = 0; tries < maxRetries; tries++) {
|
|
47
|
+
try {
|
|
48
|
+
const worker = new Worker(workerPath, {
|
|
49
|
+
env,
|
|
50
|
+
// Increase resource limits for stream handling
|
|
51
|
+
resourceLimits: resourceLimits
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
worker.setMaxListeners(maxListeners);
|
|
55
|
+
|
|
56
|
+
// Wait for worker to be ready and verify environment
|
|
57
|
+
const ready = await Promise.race([
|
|
58
|
+
new Promise((_, reject) => {
|
|
59
|
+
setTimeout(() => reject(new Error(`Worker startup timeout: ${workerPath}`)), 5000);
|
|
60
|
+
}),
|
|
61
|
+
new Promise((resolve, reject) => {
|
|
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;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
throw new Error('Failed to start worker after retries');
|
|
84
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { messageHandler } from "./messageHandler.js";
|
|
2
|
+
import { parentPort } from "node:worker_threads";
|
|
3
|
+
|
|
4
|
+
if (!parentPort) throw new Error("This module must be run as a worker");
|
|
5
|
+
parentPort?.on("message", messageHandler);
|
|
6
|
+
|
|
7
|
+
// Signal ready with environment
|
|
8
|
+
parentPort?.postMessage({ type: "READY", env: process.env["NODE_ENV"] });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { messageHandler } from "./messageHandler.js";
|
|
2
|
+
import { parentPort } from "node:worker_threads";
|
|
3
|
+
|
|
4
|
+
if (!parentPort) throw new Error("This module must be run as a worker");
|
|
5
|
+
parentPort?.on("message", messageHandler);
|
|
6
|
+
|
|
7
|
+
// Signal ready with environment
|
|
8
|
+
parentPort?.postMessage({ type: "READY", env: process.env["NODE_ENV"] });
|