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
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import type { ServerResponse } from "node:http";
|
|
3
|
-
import { join, relative, resolve, resolve as resolvePath } from "node:path";
|
|
4
|
-
import { performance } from "node:perf_hooks";
|
|
5
|
-
import { Worker } from "node:worker_threads";
|
|
6
|
-
import type { Plugin as RollupPlugin } from "rollup";
|
|
7
|
-
import type { Manifest, Plugin as VitePlugin } from "vite";
|
|
8
|
-
import {
|
|
9
|
-
createLogger,
|
|
10
|
-
type ResolvedConfig,
|
|
11
|
-
type UserConfig,
|
|
12
|
-
type ViteDevServer,
|
|
13
|
-
} from "vite";
|
|
14
|
-
import { createBuildConfig } from "../build/createBuildConfig.js";
|
|
15
|
-
import { checkFilesExist } from "../checkFilesExist.js";
|
|
16
|
-
import { getEnv } from "../getEnv.js";
|
|
17
|
-
import { createPageLoader } from "../html/createPageLoader.js";
|
|
18
|
-
import { renderPages } from "../worker/renderPages.js";
|
|
19
|
-
import { resolveOptions, resolvePages, resolveUserConfig } from "../options.js";
|
|
20
|
-
import type { BuildTiming, ReactStreamPluginMeta } from "../types.js";
|
|
21
|
-
import { type StreamPluginOptions } from "../types.js";
|
|
22
|
-
import { createWorker } from "../worker/createWorker.js";
|
|
23
|
-
import { createHandler } from "./createHandler.js";
|
|
24
|
-
import { tryManifest } from "../helpers/tryManifest.js";
|
|
25
|
-
import { createNormalizedRelativePath } from "../helpers/normalizedRelativePath.js";
|
|
26
|
-
|
|
27
|
-
let files: Awaited<ReturnType<typeof checkFilesExist>>;
|
|
28
|
-
let env: Awaited<ReturnType<typeof getEnv>>;
|
|
29
|
-
let worker: Worker;
|
|
30
|
-
let config: ResolvedConfig;
|
|
31
|
-
let cssModules = new Set<string>();
|
|
32
|
-
let clientComponents = new Map<string, string>();
|
|
33
|
-
let define: Record<string, string>;
|
|
34
|
-
let buildCssFiles = new Set<string>();
|
|
35
|
-
let root: string = process.cwd();
|
|
36
|
-
|
|
37
|
-
interface BuildStats {
|
|
38
|
-
htmlFiles: number;
|
|
39
|
-
clientComponents: number;
|
|
40
|
-
cssFiles: number;
|
|
41
|
-
totalRoutes: number;
|
|
42
|
-
timing: {
|
|
43
|
-
config: number;
|
|
44
|
-
build: number;
|
|
45
|
-
render: number;
|
|
46
|
-
total: number;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function reactStreamPlugin(
|
|
51
|
-
options: StreamPluginOptions = {} as StreamPluginOptions
|
|
52
|
-
): Promise<VitePlugin & RollupPlugin & { meta: ReactStreamPluginMeta }> {
|
|
53
|
-
const timing: BuildTiming = {
|
|
54
|
-
start: performance.now(),
|
|
55
|
-
};
|
|
56
|
-
const resolvedOptions = resolveOptions(options);
|
|
57
|
-
if (resolvedOptions.type === "error") {
|
|
58
|
-
console.error(
|
|
59
|
-
"[vite-react-stream:server] Error resolving userOptions. Please check your userOptions."
|
|
60
|
-
);
|
|
61
|
-
throw resolvedOptions.error;
|
|
62
|
-
}
|
|
63
|
-
const { userOptions } = resolvedOptions;
|
|
64
|
-
return {
|
|
65
|
-
name: "vite:react-stream",
|
|
66
|
-
meta: {
|
|
67
|
-
timing,
|
|
68
|
-
} as ReactStreamPluginMeta,
|
|
69
|
-
api: {
|
|
70
|
-
addCssFile(path: string) {
|
|
71
|
-
buildCssFiles.add(path);
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
configResolved(resolvedConfig) {
|
|
75
|
-
if (resolvedConfig.command === "build") {
|
|
76
|
-
timing.configResolved = performance.now();
|
|
77
|
-
console.log("[vite-react-stream] Starting build...");
|
|
78
|
-
}
|
|
79
|
-
config = resolvedConfig;
|
|
80
|
-
},
|
|
81
|
-
async configureServer(server: ViteDevServer) {
|
|
82
|
-
if (server.config.root) {
|
|
83
|
-
console.log(
|
|
84
|
-
"[vite-react-stream] Root dir changed",
|
|
85
|
-
server.config.root,
|
|
86
|
-
server.config.root
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const activeStreams = new Set<ServerResponse>();
|
|
91
|
-
|
|
92
|
-
// Handle Vite server restarts
|
|
93
|
-
server.ws.on("restart", (path) => {
|
|
94
|
-
console.log(
|
|
95
|
-
"[vite-react-stream] 🔧 Plugin changed, preparing for restart:",
|
|
96
|
-
path
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
// Close streams with restart message
|
|
100
|
-
for (const res of activeStreams) {
|
|
101
|
-
res.writeHead(503, {
|
|
102
|
-
"Content-Type": "text/x-component",
|
|
103
|
-
"Retry-After": "1",
|
|
104
|
-
});
|
|
105
|
-
res.end('{"error":"Server restarting..."}');
|
|
106
|
-
}
|
|
107
|
-
activeStreams.clear();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
server.ws.on("connection", (socket, req) => {
|
|
111
|
-
console.log("[vite-react-stream] hooking up ws connection");
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
server.ws.on("listening", () => {
|
|
115
|
-
console.log("[vite-react-stream] hooking up ws listening");
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
server.middlewares.use(async (req, res, next) => {
|
|
119
|
-
if (req.headers.accept !== "text/x-component") return next();
|
|
120
|
-
console.log("[vite-react-stream] middleware called");
|
|
121
|
-
try {
|
|
122
|
-
const handler = await createHandler(
|
|
123
|
-
req.url ?? "",
|
|
124
|
-
{
|
|
125
|
-
Page: userOptions.Page,
|
|
126
|
-
props: userOptions.props,
|
|
127
|
-
build: userOptions.build,
|
|
128
|
-
Html: ({ children }) => children,
|
|
129
|
-
pageExportName: userOptions.pageExportName,
|
|
130
|
-
propsExportName: userOptions.propsExportName,
|
|
131
|
-
moduleBase: userOptions.moduleBase,
|
|
132
|
-
moduleBasePath: userOptions.moduleBasePath,
|
|
133
|
-
projectRoot: server.config.root ?? userOptions.projectRoot,
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
cssFiles: Array.from(cssModules),
|
|
137
|
-
logger: createLogger(),
|
|
138
|
-
loader: server.ssrLoadModule,
|
|
139
|
-
moduleGraph: server.moduleGraph,
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
handler?.stream?.pipe(res);
|
|
143
|
-
} finally {
|
|
144
|
-
res.on("close", () => {
|
|
145
|
-
console.log("[vite-react-stream] ➖ Stream closed for:", req.url);
|
|
146
|
-
activeStreams.delete(res);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
async config(config, configEnv): Promise<UserConfig> {
|
|
153
|
-
const resolvedPages = await resolvePages(userOptions.build.pages);
|
|
154
|
-
if (resolvedPages.type === "error") {
|
|
155
|
-
throw resolvedPages.error;
|
|
156
|
-
}
|
|
157
|
-
const { pages } = resolvedPages;
|
|
158
|
-
env = getEnv(config, configEnv);
|
|
159
|
-
define = env.define;
|
|
160
|
-
files = await checkFilesExist(
|
|
161
|
-
pages,
|
|
162
|
-
userOptions,
|
|
163
|
-
config.root ?? userOptions.projectRoot
|
|
164
|
-
);
|
|
165
|
-
root = config.root ?? userOptions.projectRoot;
|
|
166
|
-
const resolvedConfig = resolveUserConfig(
|
|
167
|
-
"react-server",
|
|
168
|
-
[...pages, userOptions.workerPath, userOptions.loaderPath],
|
|
169
|
-
config,
|
|
170
|
-
configEnv,
|
|
171
|
-
userOptions
|
|
172
|
-
);
|
|
173
|
-
if (resolvedConfig.type === "error") {
|
|
174
|
-
throw resolvedConfig.error;
|
|
175
|
-
}
|
|
176
|
-
const { userConfig } = resolvedConfig;
|
|
177
|
-
console.log({
|
|
178
|
-
worker: userOptions.workerPath,
|
|
179
|
-
loader: userOptions.loaderPath,
|
|
180
|
-
});
|
|
181
|
-
const entriesClient = Object.fromEntries([
|
|
182
|
-
...Array.from(files.pageMap.entries()).map(([key, value]) => [
|
|
183
|
-
key,
|
|
184
|
-
relative(root, value),
|
|
185
|
-
]),
|
|
186
|
-
...Array.from(files.propsMap.entries()).map(([key, value]) => [
|
|
187
|
-
key,
|
|
188
|
-
relative(root, value),
|
|
189
|
-
]),
|
|
190
|
-
]);
|
|
191
|
-
const entriesResolved = Object.fromEntries(
|
|
192
|
-
(Object.entries(entriesClient) as [string, string][]).map(
|
|
193
|
-
([key, entry]) => {
|
|
194
|
-
if (typeof entry !== "string") {
|
|
195
|
-
return [key, entry];
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return [key, entry];
|
|
199
|
-
}
|
|
200
|
-
)
|
|
201
|
-
);
|
|
202
|
-
const serverEntries = {
|
|
203
|
-
...entriesResolved,
|
|
204
|
-
["worker/worker"]: userOptions.workerPath,
|
|
205
|
-
["worker/loader"]: userOptions.loaderPath,
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const buildConfig = createBuildConfig({
|
|
209
|
-
input: serverEntries,
|
|
210
|
-
userConfig: userConfig,
|
|
211
|
-
userOptions: userOptions,
|
|
212
|
-
root,
|
|
213
|
-
moduleBaseExceptions: [
|
|
214
|
-
userOptions.workerPath,
|
|
215
|
-
userOptions.loaderPath,
|
|
216
|
-
...userOptions.moduleBaseExceptions,
|
|
217
|
-
],
|
|
218
|
-
});
|
|
219
|
-
return {
|
|
220
|
-
...buildConfig,
|
|
221
|
-
define,
|
|
222
|
-
plugins: config.plugins,
|
|
223
|
-
};
|
|
224
|
-
},
|
|
225
|
-
async buildStart() {
|
|
226
|
-
timing.buildStart = performance.now();
|
|
227
|
-
},
|
|
228
|
-
async closeBundle() {
|
|
229
|
-
if (!config) return;
|
|
230
|
-
console.log("RSC CLOSE BUNDLE CALLED");
|
|
231
|
-
if (!files.pageSet.size) return;
|
|
232
|
-
timing.renderStart = performance.now();
|
|
233
|
-
|
|
234
|
-
try {
|
|
235
|
-
const resolvedServerManifest = tryManifest({
|
|
236
|
-
root,
|
|
237
|
-
outDir: userOptions.build.server,
|
|
238
|
-
ssrManifest: false,
|
|
239
|
-
});
|
|
240
|
-
if (resolvedServerManifest.type === "error") {
|
|
241
|
-
console.error(
|
|
242
|
-
"[vite-react-stream] Server Build failed, can not build without a server manifest. Please set `manifest: true` in your vite config.",
|
|
243
|
-
resolvedServerManifest.error
|
|
244
|
-
);
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const { manifest: serverManifest } = resolvedServerManifest;
|
|
248
|
-
|
|
249
|
-
// get worker path from server manifest
|
|
250
|
-
const workerPath =
|
|
251
|
-
serverManifest[userOptions.workerPath]?.file ??
|
|
252
|
-
serverManifest[relative(root, userOptions.workerPath)]?.file ??
|
|
253
|
-
serverManifest[
|
|
254
|
-
relative(
|
|
255
|
-
join(root, userOptions.build.server),
|
|
256
|
-
userOptions.workerPath
|
|
257
|
-
)
|
|
258
|
-
]?.file;
|
|
259
|
-
if (!workerPath) {
|
|
260
|
-
console.log(serverManifest, userOptions.build.server);
|
|
261
|
-
throw new Error(
|
|
262
|
-
`Worker path not found in server manifest, tried: ${userOptions.workerPath}, ${relative(root, userOptions.workerPath)}, ${join(root, userOptions.build.server, userOptions.workerPath)}`
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
console.log("workerPath", workerPath);
|
|
266
|
-
// client
|
|
267
|
-
const resolvedClientManifest = tryManifest({
|
|
268
|
-
root,
|
|
269
|
-
outDir: userOptions.build.client,
|
|
270
|
-
ssrManifest: false,
|
|
271
|
-
});
|
|
272
|
-
if (resolvedClientManifest.type === "error") {
|
|
273
|
-
console.error(
|
|
274
|
-
"[vite-react-stream] Server Build failed, can not build without a client manifest. Make sure to run the client build before the server build and set `manifest: true` in your vite config.",
|
|
275
|
-
resolvedClientManifest.error
|
|
276
|
-
);
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
const { manifest: clientManifest } = resolvedClientManifest;
|
|
280
|
-
|
|
281
|
-
// Create a single worker for all routes
|
|
282
|
-
if (!worker)
|
|
283
|
-
worker = await createWorker({
|
|
284
|
-
workerPath: join(root, userOptions.build.server, workerPath),
|
|
285
|
-
nodePath: process.env["NODE_PATH"] ?? resolve(root, "node_modules"),
|
|
286
|
-
mode:
|
|
287
|
-
process.env["NODE_ENV"] === "development"
|
|
288
|
-
? "development"
|
|
289
|
-
: "production",
|
|
290
|
-
});
|
|
291
|
-
// this is based on the user config - the routes should lead to a page and props but the rendering is agnostic of that
|
|
292
|
-
const routes = Array.from(files.pageMap.keys());
|
|
293
|
-
const indexEntry = clientManifest["index.html"];
|
|
294
|
-
if (!indexEntry) {
|
|
295
|
-
throw new Error("root /index.html not found");
|
|
296
|
-
}
|
|
297
|
-
await renderPages(routes, {
|
|
298
|
-
pipableStreamOptions: {
|
|
299
|
-
bootstrapModules: ["/" + indexEntry.file],
|
|
300
|
-
},
|
|
301
|
-
outDir: config.build.outDir,
|
|
302
|
-
clientCss: indexEntry.css?.map((css) => "/" + css) ?? [],
|
|
303
|
-
pluginOptions: {
|
|
304
|
-
Page: userOptions.Page,
|
|
305
|
-
props: userOptions.props,
|
|
306
|
-
build: userOptions.build,
|
|
307
|
-
Html: userOptions.Html,
|
|
308
|
-
pageExportName: userOptions.pageExportName,
|
|
309
|
-
propsExportName: userOptions.propsExportName,
|
|
310
|
-
moduleBase: userOptions.moduleBase,
|
|
311
|
-
moduleBasePath: userOptions.moduleBasePath,
|
|
312
|
-
moduleBaseURL: userOptions.moduleBaseURL,
|
|
313
|
-
projectRoot: root,
|
|
314
|
-
},
|
|
315
|
-
worker: worker,
|
|
316
|
-
manifest: clientManifest,
|
|
317
|
-
loader: createPageLoader({
|
|
318
|
-
manifest: clientManifest,
|
|
319
|
-
root: config.root,
|
|
320
|
-
outDir: config.build.outDir,
|
|
321
|
-
moduleBase: userOptions.moduleBase,
|
|
322
|
-
alwaysRegisterServer: false,
|
|
323
|
-
alwaysRegisterClient: false,
|
|
324
|
-
registerServer: [],
|
|
325
|
-
registerClient: Object.keys(resolvedClientManifest).filter(
|
|
326
|
-
(key) =>
|
|
327
|
-
key.endsWith(".client.tsx") && clientManifest[key].isEntry
|
|
328
|
-
),
|
|
329
|
-
}),
|
|
330
|
-
onCssFile: (path) => buildCssFiles.add(path),
|
|
331
|
-
});
|
|
332
|
-
console.log("[vite-react-stream] Render complete");
|
|
333
|
-
console.log("[vite-react-stream] Terminating worker");
|
|
334
|
-
if (worker) await worker.terminate();
|
|
335
|
-
|
|
336
|
-
timing.renderEnd = performance.now();
|
|
337
|
-
timing.total = (timing.renderEnd - timing.start) / 1000;
|
|
338
|
-
|
|
339
|
-
// Collect stats
|
|
340
|
-
const stats: BuildStats = {
|
|
341
|
-
htmlFiles: routes.length,
|
|
342
|
-
clientComponents: clientComponents.size,
|
|
343
|
-
cssFiles: cssModules.size,
|
|
344
|
-
totalRoutes: routes.length,
|
|
345
|
-
timing: {
|
|
346
|
-
config: ((timing.configResolved ?? 0) - timing.start) / 1000,
|
|
347
|
-
build:
|
|
348
|
-
((timing.buildStart ?? 0) - (timing.configResolved ?? 0)) / 1000,
|
|
349
|
-
render:
|
|
350
|
-
((timing.renderEnd ?? 0) - (timing.renderStart ?? 0)) / 1000,
|
|
351
|
-
total: (timing.renderEnd ?? 0 - timing.start) / 1000,
|
|
352
|
-
},
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
// Format duration helper
|
|
356
|
-
const formatDuration = (seconds: number) => {
|
|
357
|
-
if (seconds < 0.001) {
|
|
358
|
-
return `${(seconds * 1000000).toFixed(0)}μs`;
|
|
359
|
-
}
|
|
360
|
-
if (seconds < 1) {
|
|
361
|
-
return `${(seconds * 1000).toFixed(0)}ms`;
|
|
362
|
-
}
|
|
363
|
-
return `${seconds.toFixed(2)}s`;
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
console.log("\n[vite-react-stream] Build Summary:");
|
|
367
|
-
console.log("─".repeat(50));
|
|
368
|
-
console.log(`📄 Generated ${stats.htmlFiles} HTML files`);
|
|
369
|
-
console.log(`🎯 Processed ${stats.clientComponents} client components`);
|
|
370
|
-
console.log(`🎨 Included ${stats.cssFiles} CSS files`);
|
|
371
|
-
console.log(`🛣️ Total routes: ${stats.totalRoutes}`);
|
|
372
|
-
console.log("─".repeat(50));
|
|
373
|
-
console.log("⏱️ Timing:");
|
|
374
|
-
console.log(` Config: ${formatDuration(stats.timing.config)}`);
|
|
375
|
-
console.log(` Build: ${formatDuration(stats.timing.build)}`);
|
|
376
|
-
console.log(` Render: ${formatDuration(stats.timing.render)}`);
|
|
377
|
-
console.log(" ".repeat(12));
|
|
378
|
-
console.log(` Total: ${formatDuration(stats.timing.total)}`);
|
|
379
|
-
console.log("─".repeat(50));
|
|
380
|
-
} catch (error) {
|
|
381
|
-
console.error("[vite-react-stream] Build failed:", error);
|
|
382
|
-
throw error;
|
|
383
|
-
}
|
|
384
|
-
},
|
|
385
|
-
async buildEnd(error) {
|
|
386
|
-
if (error) {
|
|
387
|
-
console.error("[vite-react-stream] Build error:", error);
|
|
388
|
-
}
|
|
389
|
-
if (worker) await worker.terminate();
|
|
390
|
-
},
|
|
391
|
-
handleHotUpdate({ file }) {
|
|
392
|
-
if (file.endsWith(".css")) {
|
|
393
|
-
cssModules.add(file);
|
|
394
|
-
}
|
|
395
|
-
},
|
|
396
|
-
transform(code: string, id: string) {
|
|
397
|
-
if (
|
|
398
|
-
(id.includes(".client") ||
|
|
399
|
-
code.startsWith('"use client"') ||
|
|
400
|
-
code.startsWith("use client")) &&
|
|
401
|
-
!id.includes("node_modules")
|
|
402
|
-
) {
|
|
403
|
-
console.log("[vite-react-stream] Client component added", id);
|
|
404
|
-
clientComponents.set(id, code);
|
|
405
|
-
}
|
|
406
|
-
return { code };
|
|
407
|
-
},
|
|
408
|
-
};
|
|
409
|
-
}
|
package/src/transformer/index.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from "vite";
|
|
2
|
-
import { normalizePath } from "vite";
|
|
3
|
-
import { DEFAULT_CONFIG } from "../options.js";
|
|
4
|
-
import { createRscTransformer } from "./transformer.js";
|
|
5
|
-
import type { ViteReactClientTransformOptions } from "./types.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 viteReactClientTransformPlugin(
|
|
34
|
-
options?: ViteReactClientTransformOptions
|
|
35
|
-
): Plugin {
|
|
36
|
-
if(process.env['NODE_OPTIONS']?.match(/--conditions=react-server/)) {
|
|
37
|
-
console.log('react-server')
|
|
38
|
-
} else {
|
|
39
|
-
throw new Error('react-server condition not found, set NODE_OPTIONS="--conditions react-server"')
|
|
40
|
-
}
|
|
41
|
-
const projectRoot = options?.projectRoot || process.cwd();
|
|
42
|
-
const include = options?.include || DEFAULT_CONFIG.FILE_REGEX;
|
|
43
|
-
const exclude = options?.exclude;
|
|
44
|
-
let transform: any;
|
|
45
|
-
// get the file we are imported from (parent)
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
name: "vite:react-stream-transformer",
|
|
49
|
-
enforce: "pre",
|
|
50
|
-
|
|
51
|
-
configResolved(config) {
|
|
52
|
-
transform = createRscTransformer({
|
|
53
|
-
moduleId:
|
|
54
|
-
options?.moduleId ||
|
|
55
|
-
moduleIdDefault({
|
|
56
|
-
projectRoot: projectRoot,
|
|
57
|
-
output: {
|
|
58
|
-
dir: config.build?.outDir ?? DEFAULT_CONFIG.BUILD.server,
|
|
59
|
-
},
|
|
60
|
-
isProduction: config.isProduction,
|
|
61
|
-
}),
|
|
62
|
-
}).transform;
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
transform(code: string, id: string, opts) {
|
|
66
|
-
// Skip if file doesn't match patterns
|
|
67
|
-
if (
|
|
68
|
-
!matchPattern(id, include) ||
|
|
69
|
-
(exclude && matchPattern(id, exclude))
|
|
70
|
-
) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Look for use client directive at start of file (no exceptions)
|
|
75
|
-
const directiveMatch =
|
|
76
|
-
code.startsWith('"use client"') || code.startsWith("'use client'");
|
|
77
|
-
if (!directiveMatch) return null;
|
|
78
|
-
|
|
79
|
-
// Transform client components
|
|
80
|
-
return transform(code, id, opts);
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const moduleIdDefault =
|
|
86
|
-
({
|
|
87
|
-
projectRoot,
|
|
88
|
-
output: _,
|
|
89
|
-
isProduction,
|
|
90
|
-
}: {
|
|
91
|
-
isProduction: boolean;
|
|
92
|
-
projectRoot: string;
|
|
93
|
-
output: { dir: string };
|
|
94
|
-
}) =>
|
|
95
|
-
(moduleId: string) => {
|
|
96
|
-
const normalized = normalizePath(moduleId);
|
|
97
|
-
const noRoot = normalized.startsWith(projectRoot)
|
|
98
|
-
? normalized.slice(projectRoot.length)
|
|
99
|
-
: normalized;
|
|
100
|
-
if (!isProduction) {
|
|
101
|
-
return noRoot;
|
|
102
|
-
}
|
|
103
|
-
return noRoot.replace(DEFAULT_CONFIG.FILE_REGEX, ".js");
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const matchPattern = (
|
|
107
|
-
file: string,
|
|
108
|
-
pattern: string | RegExp | (string | RegExp)[]
|
|
109
|
-
) =>
|
|
110
|
-
Array.isArray(pattern)
|
|
111
|
-
? pattern.some((p) => file.match(p as RegExp))
|
|
112
|
-
: file.match(pattern as RegExp);
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { Node } from "estree";
|
|
2
|
-
import type { Plugin } from "rollup";
|
|
3
|
-
import { SourceMapGenerator } from "source-map";
|
|
4
|
-
import { DEFAULT_CONFIG } from "../options.js";
|
|
5
|
-
import type { Options } from "../types.js";
|
|
6
|
-
|
|
7
|
-
const REACT_DIRECTIVES = new Set(["use client", "use server", "use no-memo"]);
|
|
8
|
-
|
|
9
|
-
interface PreserveDirectiveMeta {
|
|
10
|
-
directives: Record<string, Set<string>>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function preserveDirectives(options?: Pick<Options, "include">): Plugin {
|
|
14
|
-
const meta: PreserveDirectiveMeta = {
|
|
15
|
-
directives: {},
|
|
16
|
-
};
|
|
17
|
-
const fileRegex = options?.include ?? DEFAULT_CONFIG.FILE_REGEX;
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
name: "react-preserve-directives",
|
|
21
|
-
transform: {
|
|
22
|
-
order: "post",
|
|
23
|
-
handler(code, id) {
|
|
24
|
-
if (!fileRegex.test(id)) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const ast = this.parse(code) as Node;
|
|
29
|
-
if (ast.type !== "Program") {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let hasDirectives = false;
|
|
34
|
-
const directives = new Set<string>();
|
|
35
|
-
|
|
36
|
-
// Look for directives at start of file
|
|
37
|
-
for (const node of ast.body) {
|
|
38
|
-
if (node.type !== "ExpressionStatement") {
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
node.expression.type === "Literal" &&
|
|
44
|
-
typeof node.expression.value === "string" &&
|
|
45
|
-
REACT_DIRECTIVES.has(node.expression.value)
|
|
46
|
-
) {
|
|
47
|
-
directives.add(node.expression.value);
|
|
48
|
-
hasDirectives = true;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!hasDirectives) return null;
|
|
53
|
-
|
|
54
|
-
meta.directives[id] = directives;
|
|
55
|
-
|
|
56
|
-
// Generate source map
|
|
57
|
-
const map = new SourceMapGenerator({
|
|
58
|
-
file: id,
|
|
59
|
-
sourceRoot: "",
|
|
60
|
-
});
|
|
61
|
-
map.setSourceContent(id, code);
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
code,
|
|
65
|
-
map: map.toString(),
|
|
66
|
-
meta: { directives: Array.from(directives) },
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
renderChunk(code, chunk) {
|
|
72
|
-
const moduleIds = chunk.moduleIds;
|
|
73
|
-
const chunkDirectives = moduleIds
|
|
74
|
-
.map((id) => meta.directives[id])
|
|
75
|
-
.filter((dirs): dirs is Set<string> => !!dirs)
|
|
76
|
-
.reduce((acc, dirs) => {
|
|
77
|
-
dirs.forEach((d) => acc.add(d));
|
|
78
|
-
return acc;
|
|
79
|
-
}, new Set<string>());
|
|
80
|
-
|
|
81
|
-
if (chunkDirectives.size) {
|
|
82
|
-
const directiveCode = Array.from(chunkDirectives)
|
|
83
|
-
.map((d) => `"${d}";`)
|
|
84
|
-
.join("\n");
|
|
85
|
-
return {
|
|
86
|
-
code: `${directiveCode}\n${code}`,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return null;
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
onLog(level, log) {
|
|
94
|
-
if (log.code === "MODULE_LEVEL_DIRECTIVE" && level === "warn") {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
return this.warn(log);
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
interface RSCChunk {
|
|
2
|
-
id: number;
|
|
3
|
-
type?: string;
|
|
4
|
-
content: any;
|
|
5
|
-
timing?: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function preserveRSC(chunk: string): string {
|
|
9
|
-
// Try to parse RSC format: <id>:<content>
|
|
10
|
-
const match = chunk.match(/^(\d+):(.+)$/);
|
|
11
|
-
if (!match) return chunk;
|
|
12
|
-
|
|
13
|
-
const [_, id, content] = match;
|
|
14
|
-
|
|
15
|
-
// Handle different chunk types
|
|
16
|
-
if (content.startsWith('"$S')) {
|
|
17
|
-
// Fragment type
|
|
18
|
-
return chunk;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (content.startsWith("I[")) {
|
|
22
|
-
// Import type
|
|
23
|
-
return chunk;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
// Try to parse as array/object
|
|
28
|
-
const parsed = JSON.parse(content);
|
|
29
|
-
|
|
30
|
-
// Check if this is a component chunk
|
|
31
|
-
if (Array.isArray(parsed) && parsed[2] === "html") {
|
|
32
|
-
const componentChunk = {
|
|
33
|
-
name: "Page",
|
|
34
|
-
env: "Server",
|
|
35
|
-
key: "page",
|
|
36
|
-
owner: null,
|
|
37
|
-
stack: [],
|
|
38
|
-
props: parsed[3],
|
|
39
|
-
};
|
|
40
|
-
return `${id}:${JSON.stringify(componentChunk)}\n:N${Date.now()}`;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return chunk;
|
|
44
|
-
} catch {
|
|
45
|
-
return chunk;
|
|
46
|
-
}
|
|
47
|
-
}
|