vite-plugin-react-server 1.0.2 → 1.1.0
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 +49 -76
- package/bin/patch.mjs +27 -20
- package/dist/_virtual/dynamic-import-helper.js +24 -0
- package/dist/_virtual/dynamic-import-helper.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -26
- package/dist/index.js.map +1 -1
- package/dist/package.json +24 -14
- package/dist/plugin/components.d.ts +1 -1
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +1 -1
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js +30 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js.map +1 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts +13 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js +24 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js.map +1 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts +11 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js +29 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +83 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +18 -14
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +42 -21
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getCondition.d.ts +1 -1
- package/dist/plugin/config/getCondition.d.ts.map +1 -1
- package/dist/plugin/config/getCondition.js +2 -2
- package/dist/plugin/config/getCondition.js.map +1 -1
- package/dist/plugin/config/getPaths.d.ts +0 -1
- package/dist/plugin/config/getPaths.d.ts.map +1 -1
- package/dist/plugin/config/getPaths.js.map +1 -1
- package/dist/plugin/config/index.d.ts +0 -1
- package/dist/plugin/config/index.d.ts.map +1 -1
- package/dist/plugin/config/index.js +0 -1
- package/dist/plugin/config/resolveAutoDiscover.d.ts +20 -0
- package/dist/plugin/config/resolveAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/resolveAutoDiscover.js +128 -0
- package/dist/plugin/config/resolveAutoDiscover.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +109 -77
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +0 -1
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js +6 -8
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts +16 -0
- package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -0
- package/dist/plugin/config/resolveUrlOption.js +37 -0
- package/dist/plugin/config/resolveUrlOption.js.map +1 -0
- package/dist/plugin/config/resolveUserConfig.d.ts +4 -5
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +80 -132
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/copy.d.ts +7 -0
- package/dist/plugin/copy.d.ts.map +1 -0
- package/dist/plugin/copy.js +30 -0
- package/dist/plugin/css-collector-elements.d.ts +4 -0
- package/dist/plugin/css-collector-elements.d.ts.map +1 -0
- package/dist/plugin/css-collector-elements.js +19 -0
- package/dist/plugin/css-collector-elements.js.map +1 -0
- package/dist/plugin/css-collector.d.ts +2 -8
- package/dist/plugin/css-collector.d.ts.map +1 -1
- package/dist/plugin/css-collector.js +9 -36
- package/dist/plugin/css-collector.js.map +1 -1
- package/dist/plugin/helpers/cleanObject.d.ts +3 -0
- package/dist/plugin/helpers/cleanObject.d.ts.map +1 -0
- package/dist/plugin/helpers/cleanObject.js +47 -0
- package/dist/plugin/helpers/cleanObject.js.map +1 -0
- package/dist/plugin/helpers/collectBundleManifestCss.d.ts +8 -0
- package/dist/plugin/helpers/collectBundleManifestCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectBundleManifestCss.js +110 -0
- package/dist/plugin/helpers/collectManifestCss.d.ts +7 -0
- package/dist/plugin/helpers/collectManifestCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectManifestCss.js +44 -0
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +31 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.js +104 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -0
- package/dist/plugin/helpers/createCssProps.d.ts +25 -0
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -0
- package/dist/plugin/helpers/createCssProps.js +57 -0
- package/dist/plugin/helpers/createCssProps.js.map +1 -0
- package/dist/plugin/helpers/createEventHandler.d.ts +22 -0
- package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -0
- package/dist/plugin/helpers/createEventHandler.js +36 -0
- package/dist/plugin/helpers/createEventHandler.js.map +1 -0
- package/dist/plugin/helpers/createHandler.d.ts +7 -13
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createHandler.js +54 -96
- package/dist/plugin/helpers/createHandler.js.map +1 -1
- package/dist/plugin/helpers/createRscStream.d.ts +12 -26
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
- package/dist/plugin/helpers/createRscStream.js +105 -51
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/defaultFileWriter.d.ts +2 -0
- package/dist/plugin/helpers/defaultFileWriter.d.ts.map +1 -0
- package/dist/plugin/helpers/defaultFileWriter.js +1 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts +10 -16
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +30 -22
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts +14 -0
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -0
- package/dist/plugin/helpers/getRouteFiles.js +36 -0
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +38 -32
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/metrics.d.ts +11 -0
- package/dist/plugin/helpers/metrics.d.ts.map +1 -0
- package/dist/plugin/helpers/metrics.js +35 -0
- package/dist/plugin/helpers/metrics.js.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts +27 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.js +51 -0
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts +8 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.js +182 -0
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -0
- package/dist/plugin/helpers/stashReturnValue.d.ts +2 -0
- package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -0
- package/dist/plugin/helpers/stashReturnValue.js +14 -0
- package/dist/plugin/helpers/tryManifest.d.ts +5 -3
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +16 -7
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/html.d.ts +2 -3
- package/dist/plugin/html.d.ts.map +1 -1
- package/dist/plugin/html.js +7 -1
- package/dist/plugin/html.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +3 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +26 -4
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +98 -33
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.development.d.ts +57 -0
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.development.js +81 -0
- package/dist/plugin/loader/css-loader.development.js.map +1 -0
- package/dist/plugin/loader/css-loader.production.d.ts +31 -0
- package/dist/plugin/loader/css-loader.production.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.production.js +45 -0
- package/dist/plugin/loader/css-loader.production.js.map +1 -0
- package/dist/plugin/loader/index.d.ts +2 -0
- package/dist/plugin/loader/index.d.ts.map +1 -0
- package/dist/plugin/loader/index.js +1 -0
- package/dist/plugin/loader/plugin.d.ts +22 -0
- package/dist/plugin/loader/plugin.d.ts.map +1 -0
- package/dist/plugin/loader/plugin.js +27 -0
- package/dist/plugin/loader/react-loader.d.ts +3 -7
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +85 -30
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/loader/temporaryReferences.d.ts +2 -0
- package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -0
- package/dist/plugin/loader/temporaryReferences.js +11 -0
- package/dist/plugin/loader/temporaryReferences.js.map +1 -0
- package/dist/plugin/moduleRefs.d.ts +7 -0
- package/dist/plugin/moduleRefs.d.ts.map +1 -0
- package/dist/plugin/moduleRefs.js +17 -0
- package/dist/plugin/moduleRefs.js.map +1 -0
- package/dist/plugin/plugin.client.d.ts +3 -0
- package/dist/plugin/plugin.client.d.ts.map +1 -0
- package/dist/plugin/plugin.client.js +19 -0
- package/dist/plugin/plugin.client.js.map +1 -0
- package/dist/plugin/plugin.d.ts +1 -5
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +3 -9
- package/dist/plugin/plugin.server.d.ts +3 -0
- package/dist/plugin/plugin.server.d.ts.map +1 -0
- package/dist/plugin/plugin.server.js +28 -0
- package/dist/plugin/plugin.server.js.map +1 -0
- package/dist/plugin/preserver/plugin.js +1 -1
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/index.d.ts +1 -2
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +1 -19
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +60 -219
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/server.d.ts +27 -0
- package/dist/plugin/react-client/server.d.ts.map +1 -0
- package/dist/plugin/react-client/server.js +197 -0
- package/dist/plugin/react-client/server.js.map +1 -0
- package/dist/plugin/react-server/index.d.ts +1 -2
- package/dist/plugin/react-server/index.d.ts.map +1 -1
- package/dist/plugin/react-server/index.js +1 -21
- package/dist/plugin/react-server/plugin.d.ts +0 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +60 -186
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-server/server.d.ts +9 -0
- package/dist/plugin/react-server/server.d.ts.map +1 -0
- package/dist/plugin/react-server/server.js +120 -0
- package/dist/plugin/react-server/server.js.map +1 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +23 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js +85 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -0
- package/dist/plugin/react-static/collectRscContent.d.ts +24 -0
- package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -0
- package/dist/plugin/react-static/collectRscContent.js +49 -0
- package/dist/plugin/react-static/collectRscContent.js.map +1 -0
- package/dist/plugin/react-static/configurePreviewServer.d.ts +7 -0
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -0
- package/dist/plugin/react-static/configurePreviewServer.js +67 -0
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -0
- package/dist/plugin/react-static/fileWriter.d.ts +23 -0
- package/dist/plugin/react-static/fileWriter.d.ts.map +1 -0
- package/dist/plugin/react-static/fileWriter.js +65 -0
- package/dist/plugin/react-static/fileWriter.js.map +1 -0
- package/dist/plugin/react-static/plugin.d.ts +15 -0
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +248 -149
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPage.d.ts +3 -0
- package/dist/plugin/react-static/renderPage.d.ts.map +1 -0
- package/dist/plugin/react-static/renderPage.js +116 -0
- package/dist/plugin/react-static/renderPage.js.map +1 -0
- package/dist/plugin/react-static/renderPages.d.ts +3 -0
- package/dist/plugin/react-static/renderPages.d.ts.map +1 -0
- package/dist/plugin/react-static/renderPages.js +125 -0
- package/dist/plugin/react-static/renderPages.js.map +1 -0
- package/dist/plugin/react-static/renderStreams.d.ts +26 -0
- package/dist/plugin/react-static/renderStreams.d.ts.map +1 -0
- package/dist/plugin/react-static/renderStreams.js +27 -0
- package/dist/plugin/react-static/renderStreams.js.map +1 -0
- package/dist/plugin/react-static/rscToHtmlStream.d.ts +22 -0
- package/dist/plugin/react-static/rscToHtmlStream.d.ts.map +1 -0
- package/dist/plugin/react-static/rscToHtmlStream.js +54 -0
- package/dist/plugin/react-static/rscToHtmlStream.js.map +1 -0
- package/dist/plugin/react-static/streamHandler.d.ts +2 -0
- package/dist/plugin/react-static/streamHandler.d.ts.map +1 -0
- package/dist/plugin/react-static/streamHandler.js +1 -0
- package/dist/plugin/react-static/types.d.ts +11 -0
- package/dist/plugin/react-static/types.d.ts.map +1 -1
- package/dist/plugin/resolvePage.d.ts +26 -9
- package/dist/plugin/resolvePage.d.ts.map +1 -1
- package/dist/plugin/resolvePage.js +41 -39
- package/dist/plugin/resolvePage.js.map +1 -1
- package/dist/plugin/resolveProps.d.ts +40 -7
- package/dist/plugin/resolveProps.d.ts.map +1 -1
- package/dist/plugin/resolveProps.js +100 -75
- package/dist/plugin/resolveProps.js.map +1 -1
- package/dist/plugin/root.d.ts +1 -0
- package/dist/plugin/root.d.ts.map +1 -1
- package/dist/plugin/root.js +1 -0
- package/dist/plugin/root.js.map +1 -1
- package/dist/plugin/transformer/index.d.ts +2 -1
- package/dist/plugin/transformer/index.d.ts.map +1 -1
- package/dist/plugin/transformer/index.js +2 -1
- package/dist/plugin/transformer/plugin.client.d.ts +4 -0
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.client.js +83 -0
- package/dist/plugin/transformer/plugin.client.js.map +1 -0
- package/dist/plugin/transformer/plugin.d.ts +1 -27
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +3 -87
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts +4 -0
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.server.js +76 -0
- package/dist/plugin/transformer/plugin.server.js.map +1 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +11 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.js +38 -0
- package/dist/plugin/types/css-tracking.d.ts +6 -0
- package/dist/plugin/types/css-tracking.d.ts.map +1 -0
- package/dist/plugin/types/css-tracking.js +1 -0
- package/dist/plugin/types.d.ts +372 -86
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/types.js +1 -1
- package/dist/plugin/vendor.client.d.ts +4 -0
- package/dist/plugin/vendor.client.d.ts.map +1 -0
- package/dist/plugin/vendor.client.js +16 -0
- package/dist/plugin/vendor.client.js.map +1 -0
- package/dist/plugin/vendor.server.d.ts +4 -0
- package/dist/plugin/vendor.server.d.ts.map +1 -0
- package/dist/plugin/vendor.server.js +16 -0
- package/dist/plugin/vendor.server.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +25 -7
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +108 -33
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts +12 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +103 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts +0 -30
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js +3 -17
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +12 -5
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts +2 -2
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +87 -84
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/types.d.ts +18 -0
- package/dist/plugin/worker/html/types.d.ts.map +1 -0
- package/dist/plugin/worker/html/types.js +1 -0
- package/dist/plugin/worker/registerLoaders.d.ts +9 -0
- package/dist/plugin/worker/registerLoaders.d.ts.map +1 -0
- package/dist/plugin/worker/registerLoaders.js +45 -0
- package/dist/plugin/worker/rsc/handleRender.d.ts +4 -0
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/handleRender.js +147 -0
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -2
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +47 -112
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +0 -30
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +29 -4
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +3 -3
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts +73 -2
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js +40 -3
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/sendMessage.d.ts +3 -0
- package/dist/plugin/worker/sendMessage.d.ts.map +1 -0
- package/dist/plugin/worker/sendMessage.js +48 -0
- package/dist/plugin/worker/types.d.ts +218 -76
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -1
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -14
- package/plugin/components.ts +1 -1
- package/plugin/config/autoDiscover/createGlobAutoDiscover.ts +29 -0
- package/plugin/config/autoDiscover/customWorkerFiles.ts +27 -0
- package/plugin/config/autoDiscover/pageAndPropFiles.ts +36 -0
- package/plugin/config/autoDiscover/resolveBuildPages.ts +98 -0
- package/plugin/config/defaults.tsx +38 -29
- package/plugin/config/getCondition.ts +7 -3
- package/plugin/config/getPaths.ts +1 -7
- package/plugin/config/index.ts +0 -1
- package/plugin/config/resolveAutoDiscover.ts +177 -0
- package/plugin/config/resolveOptions.ts +220 -118
- package/plugin/config/resolvePages.ts +5 -7
- package/plugin/config/resolveUrlOption.ts +43 -0
- package/plugin/config/resolveUserConfig.ts +116 -166
- package/plugin/copy.ts +39 -0
- package/plugin/css-collector-elements.tsx +21 -0
- package/plugin/css-collector.tsx +20 -53
- package/plugin/helpers/cleanObject.ts +50 -0
- package/plugin/helpers/collectBundleManifestCss.ts +160 -0
- package/plugin/helpers/collectManifestCss.ts +61 -0
- package/plugin/helpers/collectViteModuleGraphCss.ts +158 -0
- package/plugin/helpers/createCssProps.tsx +85 -0
- package/plugin/helpers/createEventHandler.ts +44 -0
- package/plugin/helpers/createHandler.ts +57 -126
- package/plugin/helpers/createRscStream.tsx +156 -0
- package/plugin/helpers/defaultFileWriter.ts +0 -0
- package/plugin/helpers/getBundleManifest.ts +42 -37
- package/plugin/helpers/getRouteFiles.ts +47 -0
- package/plugin/helpers/inputNormalizer.ts +16 -10
- package/plugin/helpers/metrics.ts +64 -0
- package/plugin/helpers/resolvePageAndProps.ts +81 -0
- package/plugin/helpers/serializeUserOptions.ts +209 -0
- package/plugin/helpers/stashReturnValue.ts +16 -0
- package/plugin/helpers/tryManifest.ts +35 -18
- package/plugin/html.tsx +14 -3
- package/plugin/index.ts +5 -2
- package/plugin/loader/createBuildLoader.ts +152 -47
- package/plugin/loader/css-loader.development.ts +157 -0
- package/plugin/loader/css-loader.production.ts +86 -0
- package/plugin/loader/index.ts +1 -0
- package/plugin/loader/plugin.ts +33 -0
- package/plugin/loader/react-loader.ts +109 -41
- package/plugin/loader/temporaryReferences.ts +3 -0
- package/plugin/moduleRefs.ts +11 -0
- package/plugin/plugin.client.ts +12 -0
- package/plugin/plugin.server.ts +25 -0
- package/plugin/plugin.ts +5 -9
- package/plugin/preserver/plugin.ts +1 -1
- package/plugin/react-client/index.ts +1 -12
- package/plugin/react-client/plugin.ts +70 -259
- package/plugin/react-client/server.ts +276 -0
- package/plugin/react-server/index.ts +1 -14
- package/plugin/react-server/plugin.ts +69 -220
- package/plugin/react-server/server.ts +128 -0
- package/plugin/react-static/collectHtmlWorkerContent.ts +120 -0
- package/plugin/react-static/collectRscContent.ts +77 -0
- package/plugin/react-static/configurePreviewServer.ts +68 -0
- package/plugin/react-static/fileWriter.ts +103 -0
- package/plugin/react-static/plugin.ts +308 -181
- package/plugin/react-static/renderPage.ts +151 -0
- package/plugin/react-static/renderPages.ts +154 -0
- package/plugin/react-static/renderStreams.ts +48 -0
- package/plugin/react-static/rscToHtmlStream.ts +85 -0
- package/plugin/react-static/streamHandler.ts +0 -0
- package/plugin/react-static/types.ts +10 -0
- package/plugin/resolvePage.ts +67 -57
- package/plugin/resolveProps.ts +148 -104
- package/plugin/root.ts +1 -1
- package/plugin/transformer/index.ts +2 -1
- package/plugin/transformer/plugin.client.ts +109 -0
- package/plugin/transformer/plugin.server.ts +98 -0
- package/plugin/transformer/plugin.ts +2 -115
- package/plugin/transformer/upgradeCssModuleCode.ts +42 -0
- package/plugin/types/css-tracking.ts +5 -0
- package/plugin/types/react-server-dom-esm.d.ts +54 -0
- package/plugin/types.ts +508 -97
- package/plugin/vendor.client.ts +12 -0
- package/plugin/vendor.server.ts +12 -0
- package/plugin/worker/createWorker.ts +158 -53
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +112 -0
- package/plugin/worker/html/html-worker.development.tsx +5 -75
- package/plugin/worker/html/html-worker.production.tsx +18 -7
- package/plugin/worker/html/messageHandler.tsx +126 -0
- package/plugin/worker/html/types.ts +19 -0
- package/plugin/worker/registerLoaders.ts +54 -0
- package/plugin/worker/rsc/handleRender.ts +180 -0
- package/plugin/worker/rsc/messageHandler.tsx +58 -132
- package/plugin/worker/rsc/rsc-worker.development.ts +49 -63
- package/plugin/worker/rsc/rsc-worker.production.ts +5 -5
- package/plugin/worker/rsc/state.ts +79 -2
- package/plugin/worker/sendMessage.ts +49 -0
- package/plugin/worker/types.ts +299 -100
- package/scripts/check-react-version.mjs +60 -48
- package/scripts/react+0.0.0-experimental-0ca8420f-20250504.patch +57 -0
- package/scripts/react-dom+0.0.0-experimental-0ca8420f-20250504.patch +819 -0
- package/scripts/{react-server-dom-esm+0.0.0-experimental-eda36a1c-20250228.patch → react-server-dom-esm+0.0.0-experimental-0ca8420f-20250504.patch} +1702 -2820
- package/tsconfig.json +7 -2
- package/dist/plugin/assertServerCondition.d.ts +0 -6
- package/dist/plugin/assertServerCondition.d.ts.map +0 -1
- package/dist/plugin/assertServerCondition.js +0 -13
- package/dist/plugin/checkFilesExist.d.ts +0 -3
- package/dist/plugin/checkFilesExist.d.ts.map +0 -1
- package/dist/plugin/checkFilesExist.js +0 -67
- package/dist/plugin/checkFilesExist.js.map +0 -1
- package/dist/plugin/collect-manifest-client-files.d.ts +0 -23
- package/dist/plugin/collect-manifest-client-files.d.ts.map +0 -1
- package/dist/plugin/collect-manifest-client-files.js +0 -131
- package/dist/plugin/collect-manifest-client-files.js.map +0 -1
- package/dist/plugin/config/getWorkerPath.d.ts +0 -2
- package/dist/plugin/config/getWorkerPath.d.ts.map +0 -1
- package/dist/plugin/config/getWorkerPath.js +0 -4
- package/dist/plugin/copy-dir.d.ts +0 -4
- package/dist/plugin/copy-dir.d.ts.map +0 -1
- package/dist/plugin/copy-dir.js +0 -25
- package/dist/plugin/copy-dir.js.map +0 -1
- package/dist/plugin/css-collector-inline.d.ts +0 -10
- package/dist/plugin/css-collector-inline.d.ts.map +0 -1
- package/dist/plugin/css-collector-inline.js +0 -55
- package/dist/plugin/css-collector-inline.js.map +0 -1
- package/dist/plugin/loader/css-loader.d.ts +0 -16
- package/dist/plugin/loader/css-loader.d.ts.map +0 -1
- package/dist/plugin/loader/css-loader.js +0 -70
- package/dist/plugin/loader/css-loader.js.map +0 -1
- package/dist/plugin/react-client/index.js.map +0 -1
- package/dist/plugin/react-server/index.js.map +0 -1
- package/dist/plugin/worker/html/renderPages.d.ts +0 -26
- package/dist/plugin/worker/html/renderPages.d.ts.map +0 -1
- package/dist/plugin/worker/html/renderPages.js +0 -241
- package/dist/plugin/worker/html/renderPages.js.map +0 -1
- package/plugin/assertServerCondition.ts +0 -12
- package/plugin/checkFilesExist.ts +0 -66
- package/plugin/collect-manifest-client-files.ts +0 -167
- package/plugin/config/getWorkerPath.ts +0 -5
- package/plugin/copy-dir.ts +0 -27
- package/plugin/css-collector-inline.tsx +0 -60
- package/plugin/helpers/createRscStream.ts +0 -109
- package/plugin/loader/css-loader.ts +0 -94
- package/plugin/worker/html/messageHandler.ts +0 -130
- package/plugin/worker/html/renderPages.ts +0 -293
- package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +0 -159
- package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +0 -12508
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { Transform } from 'node:stream';
|
|
7
|
+
import { createStreamMetrics } from '../helpers/metrics.js';
|
|
8
|
+
import { createRscToHtmlStream } from './rscToHtmlStream.js';
|
|
9
|
+
import { fileWriter } from './fileWriter.js';
|
|
10
|
+
|
|
11
|
+
async function collectHtmlWorkerContent(rscStream, handlerOptions) {
|
|
12
|
+
const metrics = createStreamMetrics();
|
|
13
|
+
const startTime = performance.now();
|
|
14
|
+
const rscToHtmlStream = createRscToHtmlStream({
|
|
15
|
+
worker: handlerOptions.worker,
|
|
16
|
+
route: handlerOptions.route,
|
|
17
|
+
moduleRootPath: handlerOptions.moduleRootPath,
|
|
18
|
+
moduleBaseURL: handlerOptions.moduleBaseURL,
|
|
19
|
+
pipeableStreamOptions: handlerOptions.pipeableStreamOptions,
|
|
20
|
+
build: handlerOptions.build,
|
|
21
|
+
cssFiles: handlerOptions.cssFiles,
|
|
22
|
+
projectRoot: handlerOptions.projectRoot
|
|
23
|
+
});
|
|
24
|
+
const htmlTransform = new Transform({
|
|
25
|
+
transform(chunk, _encoding, callback) {
|
|
26
|
+
metrics.chunks++;
|
|
27
|
+
callback(null, chunk);
|
|
28
|
+
},
|
|
29
|
+
flush(callback) {
|
|
30
|
+
metrics.duration = Date.now() - startTime;
|
|
31
|
+
callback();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
let isComplete = false;
|
|
35
|
+
const routeComplete = new Promise((resolve, reject) => {
|
|
36
|
+
const messageHandler = (msg) => {
|
|
37
|
+
switch (msg.type) {
|
|
38
|
+
case "HTML_CHUNK":
|
|
39
|
+
if (!isComplete) {
|
|
40
|
+
htmlTransform.write(msg.chunk);
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
case "HTML_COMPLETE":
|
|
44
|
+
isComplete = true;
|
|
45
|
+
htmlTransform.end();
|
|
46
|
+
handlerOptions.worker.postMessage({
|
|
47
|
+
type: "CLEANUP",
|
|
48
|
+
id: handlerOptions.route
|
|
49
|
+
});
|
|
50
|
+
break;
|
|
51
|
+
case "CLEANUP_COMPLETE":
|
|
52
|
+
resolve();
|
|
53
|
+
break;
|
|
54
|
+
case "ERROR":
|
|
55
|
+
handlerOptions.worker.removeListener("message", messageHandler);
|
|
56
|
+
reject(msg.error);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
handlerOptions.worker.on("message", messageHandler);
|
|
61
|
+
});
|
|
62
|
+
try {
|
|
63
|
+
if (handlerOptions.onEvent) {
|
|
64
|
+
const originalOnEvent = handlerOptions.onEvent;
|
|
65
|
+
handlerOptions.onEvent = (event) => {
|
|
66
|
+
if (event.type === "file.write.done" && event.data.fileType === "html") {
|
|
67
|
+
metrics.bytes = event.data.content.length;
|
|
68
|
+
}
|
|
69
|
+
originalOnEvent(event);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
rscStream.pipe(rscToHtmlStream);
|
|
73
|
+
const writePromise = fileWriter(htmlTransform, "html", handlerOptions);
|
|
74
|
+
await routeComplete;
|
|
75
|
+
await writePromise;
|
|
76
|
+
rscToHtmlStream.destroy();
|
|
77
|
+
return { stream: rscStream, metrics };
|
|
78
|
+
} catch (error) {
|
|
79
|
+
rscToHtmlStream.destroy();
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { collectHtmlWorkerContent };
|
|
85
|
+
//# sourceMappingURL=collectHtmlWorkerContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectHtmlWorkerContent.js","sources":["../../../plugin/react-static/collectHtmlWorkerContent.ts"],"sourcesContent":["/**\n * rscHandler.ts\n *\n * PURPOSE: Handles collecting HTML content from the htmlCompact stream\n *\n * This module:\n * 1. Collects HTML content from the rscFull stream (which includes <html> and <body> tags)\n * 2. Returns the complete HTML content when the stream is done\n * 3. Provides a clean interface for HTML handling\n */\n\nimport { PassThrough, Transform } from \"node:stream\";\nimport type { CreateHandlerOptions, StreamMetrics } from \"../types.js\";\nimport { createStreamMetrics } from \"../helpers/metrics.js\";\nimport { createRscToHtmlStream } from \"./rscToHtmlStream.js\";\nimport { fileWriter } from \"./fileWriter.js\";\n\n/**\n * Collects RSC content from the rscFull stream\n *\n * @param rscFull The stream containing the RSC content\n * @returns A promise that resolves with the complete RSC content\n */\nexport async function collectHtmlWorkerContent(\n rscStream: PassThrough,\n handlerOptions: CreateHandlerOptions\n): Promise<{ stream: PassThrough; metrics: StreamMetrics }> {\n const metrics = createStreamMetrics();\n const startTime = performance.now();\n\n // Create RSC to HTML transform stream\n const rscToHtmlStream = createRscToHtmlStream({\n worker: handlerOptions.worker,\n route: handlerOptions.route,\n moduleRootPath: handlerOptions.moduleRootPath,\n moduleBaseURL: handlerOptions.moduleBaseURL,\n pipeableStreamOptions: handlerOptions.pipeableStreamOptions,\n build: handlerOptions.build,\n cssFiles: handlerOptions.cssFiles,\n projectRoot: handlerOptions.projectRoot,\n });\n\n // Create transform stream to handle HTML chunks and file writing\n const htmlTransform = new Transform({\n transform(chunk, _encoding, callback) {\n metrics.chunks++;\n callback(null, chunk);\n },\n flush(callback) {\n metrics.duration = Date.now() - startTime;\n callback();\n },\n });\n\n let isComplete = false;\n\n // Create a promise that resolves when the route is complete\n const routeComplete = new Promise<void>((resolve, reject) => {\n const messageHandler = (msg: any) => {\n switch (msg.type) {\n case \"HTML_CHUNK\":\n if (!isComplete) {\n htmlTransform.write(msg.chunk);\n }\n break;\n case \"HTML_COMPLETE\":\n isComplete = true;\n // End the transform stream\n htmlTransform.end();\n // Send cleanup message to worker\n handlerOptions.worker.postMessage({\n type: \"CLEANUP\",\n id: handlerOptions.route,\n });\n break;\n case \"CLEANUP_COMPLETE\":\n resolve();\n break;\n case \"ERROR\":\n handlerOptions.worker.removeListener(\"message\", messageHandler);\n reject(msg.error);\n break;\n }\n };\n handlerOptions.worker.on(\"message\", messageHandler);\n });\n\n try {\n // Set up event handler to capture content length\n if (handlerOptions.onEvent) {\n const originalOnEvent = handlerOptions.onEvent;\n handlerOptions.onEvent = (event) => {\n if (event.type === \"file.write.done\" && event.data.fileType === \"html\") {\n metrics.bytes = event.data.content.length;\n }\n originalOnEvent(event);\n };\n }\n\n // Pipe RSC through transform to HTML\n rscStream.pipe(rscToHtmlStream);\n\n // Set up file writing using fileWriter\n const writePromise = fileWriter(htmlTransform, \"html\", handlerOptions);\n\n // Wait for route to complete\n await routeComplete;\n\n // Wait for file writing to complete\n await writePromise;\n\n rscToHtmlStream.destroy();\n\n return { stream: rscStream, metrics };\n } catch (error) {\n // Clean up streams on error\n rscToHtmlStream.destroy();\n throw error;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAuBsB,eAAA,wBAAA,CACpB,WACA,cAC0D,EAAA;AAC1D,EAAA,MAAM,UAAU,mBAAoB,EAAA;AACpC,EAAM,MAAA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collecting RSC content from the rscHeadless stream
|
|
5
|
+
*
|
|
6
|
+
* This module:
|
|
7
|
+
* 1. Collects RSC content from the rscHeadless stream
|
|
8
|
+
* 2. Returns the complete RSC content when the stream is done
|
|
9
|
+
* 3. Provides a clean interface for RSC handling
|
|
10
|
+
*/
|
|
11
|
+
import { PassThrough } from "node:stream";
|
|
12
|
+
import type { CreateHandlerOptions, StreamMetrics } from "../types.js";
|
|
13
|
+
/**
|
|
14
|
+
* Collects RSC content from the rscHeadless stream
|
|
15
|
+
*
|
|
16
|
+
* @param rscStream The stream containing the RSC content
|
|
17
|
+
* @param handlerOptions The options for the handler
|
|
18
|
+
* @returns A promise that resolves with the complete RSC content and metrics
|
|
19
|
+
*/
|
|
20
|
+
export declare function collectRscContent(rscStream: PassThrough, handlerOptions: CreateHandlerOptions): Promise<{
|
|
21
|
+
stream: PassThrough;
|
|
22
|
+
metrics: StreamMetrics;
|
|
23
|
+
}>;
|
|
24
|
+
//# sourceMappingURL=collectRscContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectRscContent.d.ts","sourceRoot":"","sources":["../../../plugin/react-static/collectRscContent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAa,MAAM,aAAa,CAAC;AAGrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIvE;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,WAAW,EACtB,cAAc,EAAE,oBAAoB,GACnC,OAAO,CAAC;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,aAAa,CAAA;CAAE,CAAC,CAgD1D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { Transform } from 'node:stream';
|
|
7
|
+
import { join, dirname } from 'node:path';
|
|
8
|
+
import { mkdir } from 'node:fs/promises';
|
|
9
|
+
import { createStreamMetrics } from '../helpers/metrics.js';
|
|
10
|
+
import { fileWriter } from './fileWriter.js';
|
|
11
|
+
|
|
12
|
+
async function collectRscContent(rscStream, handlerOptions) {
|
|
13
|
+
const metrics = createStreamMetrics();
|
|
14
|
+
const startTime = performance.now();
|
|
15
|
+
const outputPath = join(
|
|
16
|
+
handlerOptions.build.outDir,
|
|
17
|
+
handlerOptions.build.static,
|
|
18
|
+
handlerOptions.route,
|
|
19
|
+
handlerOptions.build.rscOutputPath
|
|
20
|
+
);
|
|
21
|
+
const dir = dirname(outputPath);
|
|
22
|
+
await mkdir(join(handlerOptions.projectRoot, dir), { recursive: true });
|
|
23
|
+
const metricsTransform = new Transform({
|
|
24
|
+
transform(chunk, _encoding, callback) {
|
|
25
|
+
metrics.chunks++;
|
|
26
|
+
metrics.bytes += chunk.length;
|
|
27
|
+
callback(null, chunk);
|
|
28
|
+
},
|
|
29
|
+
flush(callback) {
|
|
30
|
+
metrics.duration = Date.now() - startTime;
|
|
31
|
+
callback();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
rscStream.pipe(metricsTransform);
|
|
36
|
+
const writePromise = fileWriter(metricsTransform, "rsc", handlerOptions);
|
|
37
|
+
await new Promise((resolve) => {
|
|
38
|
+
metricsTransform.on("end", resolve);
|
|
39
|
+
});
|
|
40
|
+
await writePromise;
|
|
41
|
+
return { stream: rscStream, metrics };
|
|
42
|
+
} catch (error) {
|
|
43
|
+
metricsTransform.destroy();
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { collectRscContent };
|
|
49
|
+
//# sourceMappingURL=collectRscContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectRscContent.js","sources":["../../../plugin/react-static/collectRscContent.ts"],"sourcesContent":["/**\n * rscHandler.ts\n * \n * PURPOSE: Handles collecting RSC content from the rscHeadless stream\n * \n * This module:\n * 1. Collects RSC content from the rscHeadless stream\n * 2. Returns the complete RSC content when the stream is done\n * 3. Provides a clean interface for RSC handling\n */\n\nimport { PassThrough, Transform } from \"node:stream\";\nimport { dirname, join } from \"node:path\";\nimport { mkdir } from \"node:fs/promises\";\nimport type { CreateHandlerOptions, StreamMetrics } from \"../types.js\";\nimport { createStreamMetrics } from \"../helpers/metrics.js\";\nimport { fileWriter } from \"./fileWriter.js\";\n\n/**\n * Collects RSC content from the rscHeadless stream\n * \n * @param rscStream The stream containing the RSC content\n * @param handlerOptions The options for the handler\n * @returns A promise that resolves with the complete RSC content and metrics\n */\nexport async function collectRscContent(\n rscStream: PassThrough,\n handlerOptions: CreateHandlerOptions\n): Promise<{ stream: PassThrough; metrics: StreamMetrics }> {\n const metrics = createStreamMetrics();\n const startTime = performance.now()\n\n const outputPath = join(\n handlerOptions.build.outDir,\n handlerOptions.build.static,\n handlerOptions.route,\n handlerOptions.build.rscOutputPath\n );\n\n const dir = dirname(outputPath);\n // Ensure directory exists\n await mkdir(join(handlerOptions.projectRoot, dir), { recursive: true });\n\n // Create transform to track metrics\n const metricsTransform = new Transform({\n transform(chunk, _encoding, callback) {\n metrics.chunks++;\n metrics.bytes += chunk.length;\n callback(null, chunk);\n },\n flush(callback) {\n metrics.duration = Date.now() - startTime;\n callback();\n }\n });\n\n try {\n // Pipe RSC stream through metrics tracking\n rscStream.pipe(metricsTransform);\n\n // Set up file writing using fileWriter\n const writePromise = fileWriter(metricsTransform, \"rsc\", handlerOptions);\n\n // Wait for stream to complete\n await new Promise<void>((resolve) => {\n metricsTransform.on('end', resolve);\n });\n\n // Wait for file writing to complete\n await writePromise;\n\n return { stream: rscStream, metrics };\n } catch (error) {\n metricsTransform.destroy();\n throw error;\n }\n} "],"names":[],"mappings":";;;;;;;;;;;AAyBsB,eAAA,iBAAA,CACpB,WACA,cAC0D,EAAA;AAC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AAiB,OAAQ,EAAA;AACzB,IAAM,MAAA,KAAA;AAAA;AAEV;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PreviewServer } from "vite";
|
|
2
|
+
import type { ResolvedUserOptions } from "../types.js";
|
|
3
|
+
export declare function configurePreviewServer({ server, userOptions, }: {
|
|
4
|
+
server: PreviewServer;
|
|
5
|
+
userOptions: ResolvedUserOptions;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=configurePreviewServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configurePreviewServer.d.ts","sourceRoot":"","sources":["../../../plugin/react-static/configurePreviewServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAMvD,wBAAsB,sBAAsB,CAAC,EAC3C,MAAM,EACN,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,WAAW,EAAE,mBAAmB,CAAC;CAClC,iBAqDA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { MIME_TYPES } from '../config/mimeTypes.js';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { createReadStream } from 'node:fs';
|
|
9
|
+
import { stat } from 'node:fs/promises';
|
|
10
|
+
import { pipeline } from 'node:stream/promises';
|
|
11
|
+
|
|
12
|
+
async function configurePreviewServer({
|
|
13
|
+
server,
|
|
14
|
+
userOptions
|
|
15
|
+
}) {
|
|
16
|
+
const staticHostDir = join(userOptions.projectRoot, userOptions.build.outDir, userOptions.build.static);
|
|
17
|
+
server.middlewares.use(async (req, res, next) => {
|
|
18
|
+
if (!req.url) {
|
|
19
|
+
return next();
|
|
20
|
+
}
|
|
21
|
+
const [, value] = userOptions.normalizer(req.url);
|
|
22
|
+
const isHtml = userOptions.autoDiscover.htmlPattern(value);
|
|
23
|
+
if (isHtml || req.headers.accept?.includes("text/html")) {
|
|
24
|
+
const indexHtml = isHtml ? join(staticHostDir, value) : join(staticHostDir, value, userOptions.build.htmlOutputPath);
|
|
25
|
+
try {
|
|
26
|
+
const stats = await stat(indexHtml);
|
|
27
|
+
if (stats.isFile()) {
|
|
28
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
29
|
+
await pipeline(createReadStream(indexHtml), res);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const isRsc = userOptions.autoDiscover.rscPattern(value);
|
|
36
|
+
if (isRsc || req.headers.accept?.includes("text/x-component")) {
|
|
37
|
+
const rsc = isRsc ? join(staticHostDir, value) : join(staticHostDir, value, userOptions.build.rscOutputPath);
|
|
38
|
+
try {
|
|
39
|
+
const stats = await stat(rsc);
|
|
40
|
+
if (stats.isFile()) {
|
|
41
|
+
res.setHeader("Content-Type", "text/x-component; charset=utf-8");
|
|
42
|
+
await pipeline(createReadStream(rsc), res);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const ext = value.slice(value.lastIndexOf("."));
|
|
49
|
+
if (ext) {
|
|
50
|
+
const filePath = join(staticHostDir, value);
|
|
51
|
+
try {
|
|
52
|
+
const stats = await stat(filePath);
|
|
53
|
+
if (stats.isFile()) {
|
|
54
|
+
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
|
55
|
+
res.setHeader("Content-Type", `${contentType}; charset=utf-8`);
|
|
56
|
+
await pipeline(createReadStream(filePath), res);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
next();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { configurePreviewServer };
|
|
67
|
+
//# sourceMappingURL=configurePreviewServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configurePreviewServer.js","sources":["../../../plugin/react-static/configurePreviewServer.ts"],"sourcesContent":["import type { PreviewServer } from \"vite\";\nimport { MIME_TYPES } from \"../config/mimeTypes.js\";\nimport type { ResolvedUserOptions } from \"../types.js\";\nimport { join } from \"node:path\";\nimport { createReadStream } from \"node:fs\";\nimport { stat } from \"node:fs/promises\";\nimport { pipeline } from \"node:stream/promises\";\n\nexport async function configurePreviewServer({\n server,\n userOptions,\n}: {\n server: PreviewServer;\n userOptions: ResolvedUserOptions;\n}) {\n const staticHostDir = join(userOptions.projectRoot, userOptions.build.outDir, userOptions.build.static);\n server.middlewares.use(async (req, res, next) => {\n if(!req.url) {\n return next();\n }\n const [, value] = userOptions.normalizer(req.url);\n // handle index.html\n const isHtml = userOptions.autoDiscover.htmlPattern(value)\n if (isHtml || req.headers.accept?.includes(\"text/html\")) {\n const indexHtml = isHtml ? join(staticHostDir, value) : join(staticHostDir, value, userOptions.build.htmlOutputPath);\n try {\n const stats = await stat(indexHtml);\n if (stats.isFile()) {\n res.setHeader(\"Content-Type\", \"text/html; charset=utf-8\");\n await pipeline(createReadStream(indexHtml), res);\n return;\n }\n } catch {\n // File doesn't exist, continue to next middleware\n }\n } \n const isRsc = userOptions.autoDiscover.rscPattern(value)\n if (isRsc || req.headers.accept?.includes(\"text/x-component\")) {\n const rsc = isRsc ? join(staticHostDir, value) : join(staticHostDir, value, userOptions.build.rscOutputPath);\n try {\n const stats = await stat(rsc);\n if (stats.isFile()) {\n res.setHeader(\"Content-Type\", \"text/x-component; charset=utf-8\");\n await pipeline(createReadStream(rsc), res);\n return;\n }\n } catch {\n // File doesn't exist, continue to next middleware\n }\n }\n const ext = value.slice(value.lastIndexOf(\".\"));\n if (ext) {\n const filePath = join(staticHostDir, value);\n try {\n const stats = await stat(filePath);\n if (stats.isFile()) {\n const contentType = MIME_TYPES[ext] || \"application/octet-stream\";\n res.setHeader(\"Content-Type\", `${contentType}; charset=utf-8`);\n await pipeline(createReadStream(filePath), res);\n return;\n }\n } catch {\n // File doesn't exist, continue to next middleware\n }\n }\n next();\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAQA,eAAsB,sBAAuB,CAAA;AAAA,EAC3C,MAAA;AAAA,EACA;AACF,CAGG,EAAA;AACD,EAAM,MAAA,aAAA,GAAgB,KAAK,WAAY,CAAA,WAAA,EAAa,YAAY,KAAM,CAAA,MAAA,EAAQ,WAAY,CAAA,KAAA,CAAM,MAAM,CAAA;AACtG,EAAA,MAAA,CAAO,WAAY,CAAA,GAAA,CAAI,OAAO,GAAA,EAAK,KAAK,IAAS,KAAA;AAC/C,IAAG,IAAA,CAAC,IAAI,GAAK,EAAA;AACX,MAAA,OAAO,IAAK,EAAA;AAAA;AAEd,IAAA,MAAM,GAAG,KAAK,IAAI,WAAY,CAAA,UAAA,CAAW,IAAI,GAAG,CAAA;AAEhD,IAAA,MAAM,MAAS,GAAA,WAAA,CAAY,YAAa,CAAA,WAAA,CAAY,KAAK,CAAA;AACzD,IAAA,IAAI,UAAU,GAAI,CAAA,OAAA,CAAQ,MAAQ,EAAA,QAAA,CAAS,WAAW,CAAG,EAAA;AACvD,MAAM,MAAA,SAAA,GAAY,MAAS,GAAA,IAAA,CAAK,aAAe,EAAA,KAAK,CAAI,GAAA,IAAA,CAAK,aAAe,EAAA,KAAA,EAAO,WAAY,CAAA,KAAA,CAAM,cAAc,CAAA;AACnH,MAAI,IAAA;AACF,QAAM,MAAA,KAAA,GAAQ,MAAM,IAAA,CAAK,SAAS,CAAA;AAClC,QAAI,IAAA,KAAA,CAAM,QAAU,EAAA;AAClB,UAAI,GAAA,CAAA,SAAA,CAAU,gBAAgB,0BAA0B,CAAA;AACxD,UAAA,MAAM,QAAS,CAAA,gBAAA,CAAiB,SAAS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,QAAQ,CAAA,EAAG,GAAG,CAAA;AAC9C,UAAA;AAAA;AACF,OACM,CAAA,MAAA;AAAA;AAER;AAEF,IAAK,IAAA,EAAA;AAAA,GACN,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fileWriter.ts
|
|
3
|
+
*
|
|
4
|
+
* PURPOSE: Handles file writing operations for React Server Components (RSC) rendering
|
|
5
|
+
*
|
|
6
|
+
* This module:
|
|
7
|
+
* 1. Writes HTML and RSC files to the filesystem using streams
|
|
8
|
+
* 2. Creates necessary directories
|
|
9
|
+
* 3. Handles file path construction
|
|
10
|
+
* 4. Provides a clean interface for file operations
|
|
11
|
+
*/
|
|
12
|
+
import type { FileWriterOptions } from "../types.js";
|
|
13
|
+
import { Readable } from "node:stream";
|
|
14
|
+
/**
|
|
15
|
+
* Writes HTML and RSC files for a route using streams
|
|
16
|
+
*
|
|
17
|
+
* @param stream The readable stream containing the content
|
|
18
|
+
* @param fileType The type of file being written ("html" or "rsc")
|
|
19
|
+
* @param options The file writer options
|
|
20
|
+
* @returns A promise that resolves when the file is written
|
|
21
|
+
*/
|
|
22
|
+
export declare function fileWriter(stream: Readable, fileType: "html" | "rsc", options: FileWriterOptions): Promise<void>;
|
|
23
|
+
//# sourceMappingURL=fileWriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileWriter.d.ts","sourceRoot":"","sources":["../../../plugin/react-static/fileWriter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIrD,OAAO,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAC;AAElD;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,MAAM,GAAG,KAAK,EACxB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAyEf"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { createWriteStream } from 'node:fs';
|
|
8
|
+
import { mkdir } from 'node:fs/promises';
|
|
9
|
+
import { Transform } from 'node:stream';
|
|
10
|
+
|
|
11
|
+
async function fileWriter(stream, fileType, options) {
|
|
12
|
+
const { onEvent } = options;
|
|
13
|
+
if (!stream) {
|
|
14
|
+
throw new Error(`Missing stream for route: ${options.route}`);
|
|
15
|
+
}
|
|
16
|
+
const outputPath = join(
|
|
17
|
+
options.build.outDir,
|
|
18
|
+
options.build.static,
|
|
19
|
+
options.route,
|
|
20
|
+
fileType === "html" ? options.build.htmlOutputPath : options.build.rscOutputPath
|
|
21
|
+
);
|
|
22
|
+
await mkdir(join(options.build.outDir, options.build.static, options.route), { recursive: true });
|
|
23
|
+
const writeStream = createWriteStream(outputPath);
|
|
24
|
+
const contentCapture = new Transform({
|
|
25
|
+
transform(chunk, _encoding, callback) {
|
|
26
|
+
callback(null, chunk);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const chunks = [];
|
|
30
|
+
contentCapture.on("data", (chunk) => {
|
|
31
|
+
chunks.push(Buffer.from(chunk));
|
|
32
|
+
});
|
|
33
|
+
if (onEvent) {
|
|
34
|
+
onEvent({
|
|
35
|
+
type: "file.write",
|
|
36
|
+
data: {
|
|
37
|
+
fileType,
|
|
38
|
+
route: options.route,
|
|
39
|
+
stream,
|
|
40
|
+
path: outputPath,
|
|
41
|
+
onComplete: async () => {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
stream.pipe(contentCapture).pipe(writeStream).on("finish", () => {
|
|
48
|
+
const content = Buffer.concat(chunks).toString("utf-8");
|
|
49
|
+
if (onEvent) {
|
|
50
|
+
onEvent({
|
|
51
|
+
type: "file.write.done",
|
|
52
|
+
data: {
|
|
53
|
+
fileType,
|
|
54
|
+
route: options.route,
|
|
55
|
+
content
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
resolve();
|
|
60
|
+
}).on("error", reject);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { fileWriter };
|
|
65
|
+
//# sourceMappingURL=fileWriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileWriter.js","sources":["../../../plugin/react-static/fileWriter.ts"],"sourcesContent":["/**\n * fileWriter.ts\n *\n * PURPOSE: Handles file writing operations for React Server Components (RSC) rendering\n *\n * This module:\n * 1. Writes HTML and RSC files to the filesystem using streams\n * 2. Creates necessary directories\n * 3. Handles file path construction\n * 4. Provides a clean interface for file operations\n */\nimport type { FileWriterOptions } from \"../types.js\";\nimport { join } from \"node:path\";\nimport { createWriteStream } from \"node:fs\";\nimport { mkdir } from \"node:fs/promises\";\nimport { Readable, Transform } from \"node:stream\";\n\n/**\n * Writes HTML and RSC files for a route using streams\n *\n * @param stream The readable stream containing the content\n * @param fileType The type of file being written (\"html\" or \"rsc\")\n * @param options The file writer options\n * @returns A promise that resolves when the file is written\n */\nexport async function fileWriter(\n stream: Readable,\n fileType: \"html\" | \"rsc\",\n options: FileWriterOptions\n): Promise<void> {\n const { onEvent } = options;\n\n // Validate stream\n if (!stream) {\n throw new Error(`Missing stream for route: ${options.route}`);\n }\n\n const outputPath = join(\n options.build.outDir,\n options.build.static,\n options.route,\n fileType === \"html\" ? options.build.htmlOutputPath : options.build.rscOutputPath\n );\n\n // Ensure directory exists\n await mkdir(join(options.build.outDir, options.build.static, options.route), { recursive: true });\n\n // Create write stream\n const writeStream = createWriteStream(outputPath);\n\n // Create transform stream to capture content\n const contentCapture = new Transform({\n transform(chunk, _encoding, callback) {\n // Pass through the chunk\n callback(null, chunk);\n }\n });\n\n // Collect chunks for content\n const chunks: Buffer[] = [];\n contentCapture.on('data', (chunk) => {\n chunks.push(Buffer.from(chunk));\n });\n\n // Emit file.write events if onEvent is provided\n if (onEvent) {\n onEvent({\n type: \"file.write\",\n data: {\n fileType: fileType,\n route: options.route,\n stream: stream,\n path: outputPath,\n onComplete: async () => {},\n },\n });\n }\n\n // Pipe the stream through content capture to file\n return new Promise((resolve, reject) => {\n stream\n .pipe(contentCapture)\n .pipe(writeStream)\n .on(\"finish\", () => {\n // Combine chunks into content\n const content = Buffer.concat(chunks).toString('utf-8');\n \n // Emit file.write.done event with content\n if (onEvent) {\n onEvent({\n type: \"file.write.done\",\n data: {\n fileType: fileType,\n route: options.route,\n content: content\n },\n });\n }\n resolve();\n })\n .on(\"error\", reject);\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;AAyBsB,eAAA,UAAA,CACpB,MACA,EAAA,QAAA,EACA,OACe,EAAA;AACf,EAAM,MAAA,EAAE,SAAY,GAAA,OAAA;AAGpB,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,CAA6B,0BAAA,EAAA,OAAA,CAAQ,KAAK,CAAE,CAAA,CAAA;AAAA;AAG9D,EAAA,MAAM,UAAa,GAAA,IAAA;AAAA,IACjB,QAAQ,KAAM,CAAA,MAAA;AAAA,IACd,QAAQ,KAAM,CAAA,MAAA;AAAA,IACd,OAAQ,CAAA,KAAA;AAAA,IACR,aAAa,MAAS,GAAA,OAAA,CAAQ,KAAM,CAAA,cAAA,GAAiB,QAAQ,KAAM,CAAA;AAAA,GACrE;AAGA,EAAA,MAAM,KAAM,CAAA,IAAA,CAAK,OAAQ,CAAA,KAAA,CAAM,QAAQ,OAAQ,CAAA,KAAA,CAAM,MAAQ,EAAA,OAAA,CAAQ,KAAK,CAAA,EAAG,EAAE,SAAA,EAAW,MAAM,CAAA;AAGhG,EAAM,MAAA,WAAA,GAAc,kBAAkB,U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1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* plugin.ts
|
|
3
|
+
*
|
|
4
|
+
* PURPOSE: Main Vite plugin for React Server Components (RSC) static site generation
|
|
5
|
+
*
|
|
6
|
+
* This module:
|
|
7
|
+
* 1. Orchestrates the entire static site generation process
|
|
8
|
+
* 2. Manages the lifecycle of the RSC rendering process
|
|
9
|
+
* 3. Handles file writing for both initial page loads and client-side navigation
|
|
10
|
+
* - Writes .html files for initial page loads (complete HTML document)
|
|
11
|
+
* - Writes .rsc files for client-side navigation (RSC content only)
|
|
12
|
+
* 4. Provides hooks for Vite to integrate with the build process
|
|
13
|
+
* 5. Manages worker threads for parallel rendering
|
|
14
|
+
* 6. Handles error reporting and metrics collection
|
|
15
|
+
*/
|
|
1
16
|
import { type Plugin as VitePlugin } from "vite";
|
|
2
17
|
import type { ReactStreamPluginMeta } from "../types.js";
|
|
3
18
|
import { type StreamPluginOptions } from "../types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../plugin/react-static/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../plugin/react-static/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAGL,KAAK,MAAM,IAAI,UAAU,EAE1B,MAAM,MAAM,CAAC;AAId,OAAO,KAAK,EAEV,qBAAqB,EAOtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AA6BvD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,UAAU,CAAC;IAC1E,IAAI,EAAE,qBAAqB,CAAC;CAC7B,CAAC,CA0TD"}
|