vite-plugin-react-server 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -222
- package/bin/patch.mjs +84 -0
- package/dist/_virtual/sourcemap-codec.umd.js +11 -0
- package/dist/_virtual/sourcemap-codec.umd.js.map +1 -0
- package/dist/_virtual/sourcemap-codec.umd2.js +9 -0
- package/dist/_virtual/sourcemap-codec.umd2.js.map +1 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +7 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -3
- package/dist/index.js.map +1 -1
- package/dist/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js +457 -0
- package/dist/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js.map +1 -0
- package/dist/node_modules/magic-string/dist/magic-string.es.js +1283 -0
- package/dist/node_modules/magic-string/dist/magic-string.es.js.map +1 -0
- package/dist/package.json +131 -0
- package/dist/plugin/assertServerCondition.d.ts.map +1 -0
- package/dist/plugin/assertServerCondition.js +15 -0
- package/dist/plugin/build/createClientBuildConfig.d.ts +3 -0
- package/dist/plugin/build/createClientBuildConfig.d.ts.map +1 -0
- package/dist/plugin/build/createClientBuildConfig.js +14 -0
- package/dist/plugin/build/createServerBuildConfig.d.ts +12 -0
- package/dist/plugin/build/createServerBuildConfig.d.ts.map +1 -0
- package/dist/plugin/build/createServerBuildConfig.js +40 -0
- package/dist/plugin/build/createSharedBuildConfig.d.ts +5 -0
- package/dist/plugin/build/createSharedBuildConfig.d.ts.map +1 -0
- package/dist/plugin/build/createSharedBuildConfig.js +28 -0
- package/dist/plugin/build/mergeInputs.d.ts +9 -0
- package/dist/plugin/build/mergeInputs.d.ts.map +1 -0
- package/dist/plugin/build/mergeInputs.js +56 -0
- package/dist/plugin/checkFilesExist.d.ts +3 -0
- package/dist/plugin/checkFilesExist.d.ts.map +1 -0
- package/dist/plugin/checkFilesExist.js +78 -0
- package/dist/plugin/checkFilesExist.js.map +1 -0
- package/dist/{collect-css-manifest.d.ts → plugin/collect-css-manifest.d.ts} +2 -2
- package/dist/plugin/collect-css-manifest.d.ts.map +1 -0
- package/dist/{src → plugin}/collect-css-manifest.js +8 -5
- package/dist/plugin/collect-css-manifest.js.map +1 -0
- package/dist/plugin/components.d.ts.map +1 -0
- package/dist/{src → plugin}/components.js +9 -4
- package/dist/plugin/components.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +51 -0
- package/dist/plugin/config/defaults.d.ts.map +1 -0
- package/dist/plugin/config/defaults.js +52 -0
- package/dist/plugin/config/defaults.js.map +1 -0
- package/dist/plugin/config/getCondition.d.ts +2 -0
- package/dist/plugin/config/getCondition.d.ts.map +1 -0
- package/dist/plugin/config/getCondition.js +11 -0
- package/dist/plugin/config/getCondition.js.map +1 -0
- package/dist/plugin/config/getPaths.d.ts +5 -0
- package/dist/plugin/config/getPaths.d.ts.map +1 -0
- package/dist/plugin/config/getPaths.js +21 -0
- package/dist/plugin/config/getPaths.js.map +1 -0
- package/dist/plugin/config/getWorkerPath.d.ts +2 -0
- package/dist/plugin/config/getWorkerPath.d.ts.map +1 -0
- package/dist/plugin/config/getWorkerPath.js +4 -0
- package/dist/plugin/config/index.d.ts +8 -0
- package/dist/plugin/config/index.d.ts.map +1 -0
- package/dist/plugin/config/index.js +7 -0
- package/dist/plugin/config/moduleIdDefault.d.ts +8 -0
- package/dist/plugin/config/moduleIdDefault.d.ts.map +1 -0
- package/dist/plugin/config/moduleIdDefault.js +23 -0
- package/dist/plugin/config/moduleIdDefault.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts +9 -0
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -0
- package/dist/plugin/config/resolveOptions.js +56 -0
- package/dist/plugin/config/resolveOptions.js.map +1 -0
- package/dist/plugin/config/resolvePages.d.ts +9 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -0
- package/dist/plugin/config/resolvePages.js +38 -0
- package/dist/plugin/config/resolvePages.js.map +1 -0
- package/dist/plugin/config/resolveUserConfig.d.ts +18 -0
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -0
- package/dist/plugin/config/resolveUserConfig.js +84 -0
- package/dist/plugin/config/resolveUserConfig.js.map +1 -0
- package/dist/plugin/copy-dir.d.ts.map +1 -0
- package/dist/plugin/copy-dir.js +20 -0
- package/dist/plugin/getCondition.d.ts +2 -0
- package/dist/plugin/getCondition.d.ts.map +1 -0
- package/dist/plugin/getCondition.js +1 -0
- package/dist/plugin/getEnv.d.ts.map +1 -0
- package/dist/plugin/getEnv.js +107 -0
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts +8 -0
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/createClientInputNormalizer.js +35 -0
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts +9 -0
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/createServerInputNormalizer.js +37 -0
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +7 -0
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/createStaticInputNormalizer.js +18 -0
- package/dist/plugin/helpers/getModuleManifest.d.ts +12 -0
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +1 -0
- package/dist/plugin/helpers/getModuleManifest.js +24 -0
- package/dist/plugin/helpers/getModuleManifest.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts +3 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.js +35 -0
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +11 -0
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +1 -0
- package/dist/plugin/helpers/inputNormalizerWorker.js +30 -0
- package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +1 -0
- package/dist/plugin/helpers/normalizedRelativePath.js +36 -0
- package/dist/plugin/helpers/resolveFilePath.d.ts +13 -0
- package/dist/plugin/helpers/resolveFilePath.d.ts.map +1 -0
- package/dist/plugin/helpers/resolveFilePath.js +74 -0
- package/dist/plugin/helpers/resolveWorkerModule.d.ts +6 -0
- package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +1 -0
- package/dist/plugin/helpers/resolveWorkerModule.js +24 -0
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -0
- package/dist/{src → plugin}/helpers/tryManifest.js +11 -6
- package/dist/plugin/helpers/tryManifest.js.map +1 -0
- package/dist/plugin/helpers/validateModuleBase.d.ts +3 -0
- package/dist/plugin/helpers/validateModuleBase.d.ts.map +1 -0
- package/dist/plugin/helpers/validateModuleBase.js +16 -0
- package/dist/plugin/helpers/validateResolvedConfig.d.ts +3 -0
- package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +1 -0
- package/dist/plugin/helpers/validateResolvedConfig.js +17 -0
- package/dist/plugin/index.d.ts +3 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +1 -0
- package/dist/plugin/loader/createBuildLoader.d.ts +9 -0
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createBuildLoader.js +52 -0
- package/dist/plugin/loader/createBuildLoader.js.map +1 -0
- package/dist/plugin/loader/createCssLoader.d.ts +30 -0
- package/dist/plugin/loader/createCssLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createCssLoader.js +35 -0
- package/dist/{html → plugin/loader}/createPageLoader.d.ts +2 -4
- package/dist/plugin/loader/createPageLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createPageLoader.js +57 -0
- package/dist/plugin/manifest.d.ts.map +1 -0
- package/dist/plugin/manifest.js +13 -0
- package/dist/plugin/module-graph.d.ts.map +1 -0
- package/dist/plugin/module-graph.js +35 -0
- package/dist/plugin/plugin.d.ts +7 -0
- package/dist/plugin/plugin.d.ts.map +1 -0
- package/dist/plugin/plugin.js +8 -0
- package/dist/plugin/preserver/index.d.ts +2 -0
- package/dist/plugin/preserver/index.d.ts.map +1 -0
- package/dist/plugin/preserver/index.js +1 -0
- package/dist/plugin/preserver/plugin.d.ts +4 -0
- package/dist/plugin/preserver/plugin.d.ts.map +1 -0
- package/dist/plugin/preserver/plugin.js +90 -0
- package/dist/plugin/preserver/plugin.js.map +1 -0
- package/dist/plugin/react-client/index.d.ts +2 -0
- package/dist/plugin/react-client/index.d.ts.map +1 -0
- package/dist/plugin/react-client/index.js +1 -0
- package/dist/plugin/react-client/plugin.d.ts +4 -0
- package/dist/plugin/react-client/plugin.d.ts.map +1 -0
- package/dist/plugin/react-client/plugin.js +34 -0
- package/dist/plugin/react-client/plugin.js.map +1 -0
- package/dist/plugin/react-server/createDevMiddleware.d.ts.map +1 -0
- package/dist/plugin/react-server/createDevMiddleware.js +68 -0
- package/dist/plugin/react-server/createDevServer.d.ts.map +1 -0
- package/dist/plugin/react-server/createDevServer.js +4 -0
- package/dist/plugin/react-server/createHandler.d.ts +17 -0
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -0
- package/dist/{src → plugin}/react-server/createHandler.js +28 -17
- package/dist/plugin/react-server/createHandler.js.map +1 -0
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +1 -0
- package/dist/plugin/react-server/createReactNodeStreamer.js +7 -0
- package/dist/{react-server → plugin/react-server}/createRscStream.d.ts +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -0
- package/dist/{src → plugin}/react-server/createRscStream.js +14 -13
- package/dist/plugin/react-server/createRscStream.js.map +1 -0
- package/dist/{react-server → plugin/react-server}/createSsrHandler.d.ts +1 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -0
- package/dist/plugin/react-server/createSsrHandler.js +102 -0
- package/dist/plugin/react-server/index.d.ts +4 -0
- package/dist/plugin/react-server/index.d.ts.map +1 -0
- package/dist/plugin/react-server/index.js +10 -0
- package/dist/{react-server → plugin/react-server}/plugin.d.ts +2 -2
- package/dist/plugin/react-server/plugin.d.ts.map +1 -0
- package/dist/plugin/react-server/plugin.js +375 -0
- package/dist/plugin/react-server/plugin.js.map +1 -0
- package/dist/plugin/resolvePage.d.ts.map +1 -0
- package/dist/{src → plugin}/resolvePage.js +8 -4
- package/dist/plugin/resolvePage.js.map +1 -0
- package/dist/plugin/resolveProps.d.ts.map +1 -0
- package/dist/{src → plugin}/resolveProps.js +21 -8
- package/dist/plugin/resolveProps.js.map +1 -0
- package/dist/plugin/server.d.ts +2 -0
- package/dist/plugin/server.d.ts.map +1 -0
- package/dist/plugin/server.js +1 -0
- package/dist/plugin/transformer/index.d.ts +2 -0
- package/dist/plugin/transformer/index.d.ts.map +1 -0
- package/dist/plugin/transformer/index.js +1 -0
- package/dist/{transformer/index.d.ts → plugin/transformer/plugin.d.ts} +3 -3
- package/dist/plugin/transformer/plugin.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.js +86 -0
- package/dist/plugin/transformer/plugin.js.map +1 -0
- package/dist/plugin/transformer/transformer-client-components.d.ts +21 -0
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +1 -0
- package/dist/plugin/transformer/transformer-client-components.js +61 -0
- package/dist/plugin/transformer/transformer-client-components.js.map +1 -0
- package/dist/{transformer/transformer.d.ts → plugin/transformer/transformer-server-actions.d.ts} +3 -4
- package/dist/plugin/transformer/transformer-server-actions.d.ts.map +1 -0
- package/dist/plugin/transformer/transformer-server-actions.js +76 -0
- package/dist/plugin/transformer/transformer-server-actions.js.map +1 -0
- package/dist/plugin/transformer/types.d.ts.map +1 -0
- package/dist/plugin/transformer/types.js +1 -0
- package/dist/plugin/types.d.ts +225 -0
- package/dist/plugin/types.d.ts.map +1 -0
- package/dist/plugin/types.js +1 -0
- package/dist/plugin/worker/createWorker.d.ts +15 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -0
- package/dist/plugin/worker/createWorker.js +71 -0
- package/dist/plugin/worker/createWorker.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.d.ts +2 -0
- package/dist/plugin/worker/html/html-worker.d.ts.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts +2 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.js +12 -0
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.js +4 -0
- package/dist/plugin/worker/html/html-worker.production.d.ts +2 -0
- package/dist/plugin/worker/html/html-worker.production.d.ts.map +1 -0
- package/dist/plugin/worker/html/html-worker.production.js +12 -0
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -0
- package/dist/plugin/worker/html/index.d.ts +2 -0
- package/dist/plugin/worker/html/index.d.ts.map +1 -0
- package/dist/plugin/worker/html/index.js +7 -0
- package/dist/plugin/worker/html/index.js.map +1 -0
- package/dist/plugin/worker/html/messageHandler.d.ts +3 -0
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -0
- package/dist/plugin/worker/html/messageHandler.js +98 -0
- package/dist/plugin/worker/html/messageHandler.js.map +1 -0
- package/dist/plugin/worker/html/plugin.d.ts +4 -0
- package/dist/plugin/worker/html/plugin.d.ts.map +1 -0
- package/dist/plugin/worker/html/plugin.js +89 -0
- package/dist/plugin/worker/html/renderPages.d.ts +38 -0
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -0
- package/dist/plugin/worker/html/renderPages.js +121 -0
- package/dist/plugin/worker/html/renderPages.js.map +1 -0
- package/dist/plugin/worker/loader.d.ts.map +1 -0
- package/dist/plugin/worker/loader.js +11 -0
- package/dist/plugin/worker/loader.js.map +1 -0
- package/dist/plugin/worker/plugin.d.ts +10 -0
- package/dist/plugin/worker/plugin.d.ts.map +1 -0
- package/dist/plugin/worker/plugin.js +14 -0
- package/dist/plugin/worker/rsc/createRscStream.d.ts +5 -0
- package/dist/plugin/worker/rsc/createRscStream.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/createRscStream.js +39 -0
- package/dist/plugin/worker/rsc/createRscStream.js.map +1 -0
- package/dist/plugin/worker/rsc/development.d.ts +5 -0
- package/dist/plugin/worker/rsc/development.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/development.js +13 -0
- package/dist/plugin/worker/rsc/development.js.map +1 -0
- package/dist/plugin/worker/rsc/index.d.ts +4 -0
- package/dist/plugin/worker/rsc/index.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/index.js +15 -0
- package/dist/plugin/worker/rsc/index.js.map +1 -0
- package/dist/plugin/worker/rsc/plugin.d.ts +4 -0
- package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/plugin.js +82 -0
- package/dist/plugin/worker/rsc/plugin.js.map +1 -0
- package/dist/plugin/worker/rsc/production.d.ts +5 -0
- package/dist/plugin/worker/rsc/production.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/production.js +13 -0
- package/dist/plugin/worker/rsc/production.js.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.d.ts +2 -0
- package/dist/plugin/worker/rsc/rsc-worker.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.js +106 -0
- package/dist/plugin/worker/types.d.ts +99 -0
- package/dist/plugin/worker/types.d.ts.map +1 -0
- package/dist/plugin/worker/types.js +1 -0
- package/dist/server.d.ts +4 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +9 -0
- package/dist/server.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +1 -201
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +44 -25
- package/plugin/build/createClientBuildConfig.ts +21 -0
- package/plugin/build/createServerBuildConfig.ts +66 -0
- package/plugin/build/createSharedBuildConfig.ts +35 -0
- package/plugin/build/mergeInputs.ts +58 -0
- package/plugin/checkFilesExist.ts +82 -0
- package/{src → plugin}/collect-css-manifest.ts +4 -2
- package/plugin/config/defaults.ts +44 -0
- package/plugin/config/getCondition.ts +3 -0
- package/plugin/config/getPaths.ts +25 -0
- package/plugin/config/getWorkerPath.ts +5 -0
- package/plugin/config/index.ts +8 -0
- package/plugin/config/moduleIdDefault.ts +23 -0
- package/plugin/config/resolveOptions.ts +53 -0
- package/plugin/config/resolvePages.ts +43 -0
- package/plugin/config/resolveUserConfig.ts +97 -0
- package/{src → plugin}/getEnv.ts +1 -1
- package/plugin/helpers/createClientInputNormalizer.ts +48 -0
- package/plugin/helpers/createServerInputNormalizer.ts +52 -0
- package/plugin/helpers/createStaticInputNormalizer.ts +26 -0
- package/plugin/helpers/getModuleManifest.ts +31 -0
- package/plugin/helpers/inputNormalizer.ts +39 -0
- package/plugin/helpers/inputNormalizerWorker.ts +47 -0
- package/plugin/helpers/resolveFilePath.ts +108 -0
- package/plugin/helpers/resolveWorkerModule.ts +41 -0
- package/plugin/helpers/validateModuleBase.ts +30 -0
- package/plugin/helpers/validateResolvedConfig.ts +21 -0
- package/plugin/index.ts +2 -0
- package/plugin/loader/createBuildLoader.ts +60 -0
- package/plugin/loader/createCssLoader.ts +73 -0
- package/{src/html → plugin/loader}/createPageLoader.ts +35 -27
- package/plugin/plugin.ts +8 -0
- package/plugin/preserver/index.ts +1 -0
- package/plugin/preserver/plugin.ts +110 -0
- package/plugin/react-client/index.ts +1 -0
- package/plugin/react-client/plugin.ts +33 -0
- package/{src → plugin}/react-server/createDevMiddleware.ts +17 -1
- package/{src → plugin}/react-server/createDevServer.ts +0 -1
- package/{src → plugin}/react-server/createHandler.ts +31 -10
- package/{src → plugin}/react-server/createReactNodeStreamer.ts +1 -0
- package/{src → plugin}/react-server/createRscStream.ts +8 -12
- package/{src → plugin}/react-server/createSsrHandler.ts +16 -19
- package/plugin/react-server/index.ts +13 -0
- package/plugin/react-server/plugin.ts +465 -0
- package/{src → plugin}/resolvePage.ts +1 -1
- package/{src → plugin}/resolveProps.ts +15 -6
- package/plugin/server.tsx +0 -0
- package/plugin/transformer/index.ts +1 -0
- package/plugin/transformer/plugin.ts +131 -0
- package/plugin/transformer/transformer-client-components.ts +94 -0
- package/{src/transformer/transformer.ts → plugin/transformer/transformer-server-actions.ts} +14 -27
- package/{src → plugin}/types.ts +97 -55
- package/plugin/worker/createWorker.ts +84 -0
- package/plugin/worker/html/html-worker.development.tsx +8 -0
- package/plugin/worker/html/html-worker.production.tsx +8 -0
- package/plugin/worker/html/html-worker.ts +5 -0
- package/plugin/worker/html/index.ts +5 -0
- package/plugin/worker/html/messageHandler.ts +116 -0
- package/plugin/worker/html/plugin.ts +97 -0
- package/plugin/worker/html/renderPages.ts +187 -0
- package/plugin/worker/plugin.ts +17 -0
- package/plugin/worker/rsc/createRscStream.ts +42 -0
- package/plugin/worker/rsc/development.ts +6 -0
- package/plugin/worker/rsc/index.ts +14 -0
- package/plugin/worker/rsc/plugin.ts +83 -0
- package/plugin/worker/rsc/production.ts +6 -0
- package/plugin/worker/rsc/rsc-worker.tsx +128 -0
- package/plugin/worker/types.ts +124 -0
- package/scripts/bump-version.mjs +68 -0
- package/scripts/check-react-version.mjs +66 -0
- package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +4291 -0
- package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +108798 -0
- package/scripts/react-server-dom-esm+0.0.0-experimental-b3a95caf-20250113.patch +24775 -0
- package/{patches → scripts}/react-server-dom-esm+0.0.1.patch +10259 -3
- package/tsconfig.json +15 -13
- package/dist/assertServerCondition.d.ts.map +0 -1
- package/dist/bin/patch.js +0 -51
- package/dist/bin/patch.js.map +0 -1
- package/dist/build/createBuildConfig.d.ts +0 -13
- package/dist/build/createBuildConfig.d.ts.map +0 -1
- package/dist/build/mergeInputs.d.ts +0 -5
- package/dist/build/mergeInputs.d.ts.map +0 -1
- package/dist/checkFilesExist.d.ts +0 -8
- package/dist/checkFilesExist.d.ts.map +0 -1
- package/dist/collect-css-manifest.d.ts.map +0 -1
- package/dist/components.d.ts.map +0 -1
- package/dist/copy-dir.d.ts.map +0 -1
- package/dist/getEnv.d.ts.map +0 -1
- package/dist/helpers/inputNormalizer.d.ts +0 -6
- package/dist/helpers/inputNormalizer.d.ts.map +0 -1
- package/dist/helpers/normalizedRelativePath.d.ts.map +0 -1
- package/dist/helpers/tryManifest.d.ts.map +0 -1
- package/dist/html/createPageLoader.d.ts.map +0 -1
- package/dist/manifest.d.ts.map +0 -1
- package/dist/module-graph.d.ts.map +0 -1
- package/dist/options.d.ts +0 -91
- package/dist/options.d.ts.map +0 -1
- package/dist/plugin.d.ts +0 -3
- package/dist/plugin.d.ts.map +0 -1
- package/dist/react-client/plugin.d.ts +0 -4
- package/dist/react-client/plugin.d.ts.map +0 -1
- package/dist/react-client/plugin.js +0 -28
- package/dist/react-client/plugin.js.map +0 -1
- package/dist/react-server/createDevMiddleware.d.ts.map +0 -1
- package/dist/react-server/createDevServer.d.ts.map +0 -1
- package/dist/react-server/createHandler.d.ts +0 -23
- package/dist/react-server/createHandler.d.ts.map +0 -1
- package/dist/react-server/createReactNodeStreamer.d.ts.map +0 -1
- package/dist/react-server/createRscStream.d.ts.map +0 -1
- package/dist/react-server/createSsrHandler.d.ts.map +0 -1
- package/dist/react-server/plugin.d.ts.map +0 -1
- package/dist/react-server/plugin.js +0 -345
- package/dist/react-server/plugin.js.map +0 -1
- package/dist/resolvePage.d.ts.map +0 -1
- package/dist/resolveProps.d.ts.map +0 -1
- package/dist/src/build/createBuildConfig.js +0 -44
- package/dist/src/build/createBuildConfig.js.map +0 -1
- package/dist/src/build/mergeInputs.js +0 -16
- package/dist/src/build/mergeInputs.js.map +0 -1
- package/dist/src/checkFilesExist.js +0 -61
- package/dist/src/checkFilesExist.js.map +0 -1
- package/dist/src/collect-css-manifest.js.map +0 -1
- package/dist/src/components.js.map +0 -1
- package/dist/src/getEnv.js +0 -76
- package/dist/src/getEnv.js.map +0 -1
- package/dist/src/helpers/inputNormalizer.js +0 -11
- package/dist/src/helpers/inputNormalizer.js.map +0 -1
- package/dist/src/helpers/normalizedRelativePath.js +0 -34
- package/dist/src/helpers/normalizedRelativePath.js.map +0 -1
- package/dist/src/helpers/tryManifest.js.map +0 -1
- package/dist/src/html/createPageLoader.js +0 -72
- package/dist/src/html/createPageLoader.js.map +0 -1
- package/dist/src/options.js +0 -307
- package/dist/src/options.js.map +0 -1
- package/dist/src/react-server/createHandler.js.map +0 -1
- package/dist/src/react-server/createRscStream.js.map +0 -1
- package/dist/src/resolvePage.js.map +0 -1
- package/dist/src/resolveProps.js.map +0 -1
- package/dist/src/worker/createHtmlStream.js +0 -62
- package/dist/src/worker/createHtmlStream.js.map +0 -1
- package/dist/src/worker/createWorker.js +0 -34
- package/dist/src/worker/createWorker.js.map +0 -1
- package/dist/src/worker/renderPages.js +0 -99
- package/dist/src/worker/renderPages.js.map +0 -1
- package/dist/transformer/index.d.ts.map +0 -1
- package/dist/transformer/preserveDirectives.d.ts +0 -4
- package/dist/transformer/preserveDirectives.d.ts.map +0 -1
- package/dist/transformer/preserver.d.ts +0 -2
- package/dist/transformer/preserver.d.ts.map +0 -1
- package/dist/transformer/transformer.d.ts.map +0 -1
- package/dist/transformer/types.d.ts.map +0 -1
- package/dist/worker/createHtmlStream.d.ts +0 -7
- package/dist/worker/createHtmlStream.d.ts.map +0 -1
- package/dist/worker/createWorker.d.ts +0 -10
- package/dist/worker/createWorker.d.ts.map +0 -1
- package/dist/worker/loader.d.ts.map +0 -1
- package/dist/worker/loader.js +0 -7
- package/dist/worker/loader.js.map +0 -1
- package/dist/worker/renderPages.d.ts +0 -18
- package/dist/worker/renderPages.d.ts.map +0 -1
- package/dist/worker/types.d.ts +0 -31
- package/dist/worker/types.d.ts.map +0 -1
- package/dist/worker/worker.d.ts +0 -7
- package/dist/worker/worker.d.ts.map +0 -1
- package/dist/worker/worker.js +0 -112
- package/dist/worker/worker.js.map +0 -1
- package/src/build/createBuildConfig.ts +0 -57
- package/src/build/mergeInputs.ts +0 -42
- package/src/checkFilesExist.ts +0 -67
- package/src/helpers/inputNormalizer.ts +0 -22
- package/src/index.ts +0 -4
- package/src/options.ts +0 -423
- package/src/plugin.ts +0 -5
- package/src/react-client/plugin.ts +0 -34
- package/src/react-server/plugin.ts +0 -409
- package/src/transformer/index.ts +0 -112
- package/src/transformer/preserveDirectives.ts +0 -100
- package/src/transformer/preserver.ts +0 -47
- package/src/worker/createHtmlStream.ts +0 -76
- package/src/worker/createWorker.ts +0 -44
- package/src/worker/renderPages.ts +0 -144
- package/src/worker/types.ts +0 -38
- package/src/worker/worker.tsx +0 -136
- /package/dist/{assertServerCondition.d.ts → plugin/assertServerCondition.d.ts} +0 -0
- /package/dist/{components.d.ts → plugin/components.d.ts} +0 -0
- /package/dist/{copy-dir.d.ts → plugin/copy-dir.d.ts} +0 -0
- /package/dist/{getEnv.d.ts → plugin/getEnv.d.ts} +0 -0
- /package/dist/{helpers → plugin/helpers}/normalizedRelativePath.d.ts +0 -0
- /package/dist/{helpers → plugin/helpers}/tryManifest.d.ts +0 -0
- /package/dist/{manifest.d.ts → plugin/manifest.d.ts} +0 -0
- /package/dist/{module-graph.d.ts → plugin/module-graph.d.ts} +0 -0
- /package/dist/{react-server → plugin/react-server}/createDevMiddleware.d.ts +0 -0
- /package/dist/{react-server → plugin/react-server}/createDevServer.d.ts +0 -0
- /package/dist/{react-server → plugin/react-server}/createReactNodeStreamer.d.ts +0 -0
- /package/dist/{resolvePage.d.ts → plugin/resolvePage.d.ts} +0 -0
- /package/dist/{resolveProps.d.ts → plugin/resolveProps.d.ts} +0 -0
- /package/dist/{transformer → plugin/transformer}/types.d.ts +0 -0
- /package/dist/{worker → plugin/worker}/loader.d.ts +0 -0
- /package/{src → plugin}/assertServerCondition.ts +0 -0
- /package/{src → plugin}/components.tsx +0 -0
- /package/{src → plugin}/copy-dir.ts +0 -0
- /package/{src/server.tsx → plugin/getCondition.ts} +0 -0
- /package/{src → plugin}/helpers/normalizedRelativePath.ts +0 -0
- /package/{src → plugin}/helpers/tryManifest.ts +0 -0
- /package/{src → plugin}/manifest.ts +0 -0
- /package/{src → plugin}/module-graph.ts +0 -0
- /package/{src → plugin}/transformer/README.md +0 -0
- /package/{src → plugin}/transformer/types.ts +0 -0
- /package/{src → plugin}/worker/loader.ts +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { tryManifest } from "./tryManifest.js";
|
|
2
|
+
|
|
3
|
+
export async function resolveWorkerModule(
|
|
4
|
+
moduleGraph: Set<string> | string[],
|
|
5
|
+
options: {
|
|
6
|
+
root: string,
|
|
7
|
+
outDir: string,
|
|
8
|
+
workerPath: string
|
|
9
|
+
}
|
|
10
|
+
) {
|
|
11
|
+
console.log('Resolving worker module:', {
|
|
12
|
+
moduleGraph: Array.from(moduleGraph),
|
|
13
|
+
options
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// Try module graph first
|
|
17
|
+
const workerModule = Array.from(moduleGraph).find(id =>
|
|
18
|
+
id.includes(options.workerPath)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
console.log('Found in module graph:', workerModule);
|
|
22
|
+
|
|
23
|
+
if (workerModule) {
|
|
24
|
+
return workerModule;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Fallback to manifest
|
|
28
|
+
const resolvedManifest = tryManifest({
|
|
29
|
+
root: options.root,
|
|
30
|
+
outDir: options.outDir,
|
|
31
|
+
ssrManifest: false
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log('Manifest result:', resolvedManifest);
|
|
35
|
+
|
|
36
|
+
if (resolvedManifest.type === "error") {
|
|
37
|
+
throw new Error(`Could not find worker path in module graph or manifest: ${options.workerPath}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return resolvedManifest.manifest[options.workerPath]?.file;
|
|
41
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { InputOption } from "rollup";
|
|
2
|
+
|
|
3
|
+
export function validateModuleBase(
|
|
4
|
+
input: InputOption,
|
|
5
|
+
moduleBase: string,
|
|
6
|
+
moduleBaseExceptions: string[]
|
|
7
|
+
) {
|
|
8
|
+
for (const [key, value] of Object.entries(input)) {
|
|
9
|
+
const isException =
|
|
10
|
+
moduleBaseExceptions.includes(key) || ["/index", "index"].includes(key);
|
|
11
|
+
if (!key.includes("/")) return;
|
|
12
|
+
if (value.startsWith("//")) {
|
|
13
|
+
throw new Error(`Path shouldn't start with //`);
|
|
14
|
+
}
|
|
15
|
+
if (!key.startsWith(moduleBase) && !isException) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`Invalid input: ${key} does not start with ${moduleBase}. If this is a valid key, add it to moduleBaseExceptions otherwise put the file in the ${moduleBase} directory. Exception: ${moduleBaseExceptions.join(
|
|
18
|
+
", "
|
|
19
|
+
)}`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
if (!value.startsWith("/" + moduleBase) && !isException) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Invalid value: ${value} does not start with ${moduleBase}. If this is a valid path, add it to moduleBaseExceptions otherwise put the file in the ${moduleBase} directory. Exception: ${moduleBaseExceptions.join(
|
|
25
|
+
", "
|
|
26
|
+
)}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ResolvedConfig } from "vite";
|
|
2
|
+
|
|
3
|
+
export function validateResolvedConfig(config: ResolvedConfig): asserts config is ResolvedConfig {
|
|
4
|
+
if (
|
|
5
|
+
typeof config === "object" &&
|
|
6
|
+
config != null &&
|
|
7
|
+
"build" in config &&
|
|
8
|
+
typeof config.build === "object" &&
|
|
9
|
+
config.build != null &&
|
|
10
|
+
"rollupOptions" in config.build &&
|
|
11
|
+
typeof config.build.rollupOptions === "object" &&
|
|
12
|
+
config.build.rollupOptions != null &&
|
|
13
|
+
"input" in config.build.rollupOptions &&
|
|
14
|
+
typeof config.build.rollupOptions.input === "object" &&
|
|
15
|
+
config.build.rollupOptions.input != null
|
|
16
|
+
) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
throw new Error("Invalid config");
|
|
20
|
+
};
|
|
21
|
+
|
package/plugin/index.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { join, relative } from "path";
|
|
2
|
+
import type { PluginContext } from "rollup";
|
|
3
|
+
import type { ResolvedUserConfig } from "../../server.js";
|
|
4
|
+
import { createInputNormalizer } from "../helpers/inputNormalizer.js";
|
|
5
|
+
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
6
|
+
import { mkdir, stat, writeFile } from "node:fs/promises";
|
|
7
|
+
|
|
8
|
+
export interface BuildLoaderOptions {
|
|
9
|
+
root: string;
|
|
10
|
+
pluginContext: PluginContext;
|
|
11
|
+
userConfig: ResolvedUserConfig;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createBuildLoader({
|
|
15
|
+
root,
|
|
16
|
+
pluginContext,
|
|
17
|
+
userConfig,
|
|
18
|
+
}: BuildLoaderOptions) {
|
|
19
|
+
const normalizer = createInputNormalizer(root);
|
|
20
|
+
return async (id: string) => {
|
|
21
|
+
console.log("[createBuildLoader] Loading module:", id);
|
|
22
|
+
const moduleId = join(root, id);
|
|
23
|
+
|
|
24
|
+
// Load the module source
|
|
25
|
+
const result = await pluginContext.load({ id: moduleId });
|
|
26
|
+
if (!result) {
|
|
27
|
+
throw new Error(`Failed to load module: ${id}`);
|
|
28
|
+
}
|
|
29
|
+
let destination = id.replace(DEFAULT_CONFIG.FILE_REGEX, "") + ".js";
|
|
30
|
+
let fullDestination = join(root, userConfig.build.outDir, destination);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// Import and evaluate the module
|
|
34
|
+
try {
|
|
35
|
+
let emitIfNotExists = await stat(fullDestination).then(stats => stats.isFile());
|
|
36
|
+
if (emitIfNotExists) {
|
|
37
|
+
console.log(
|
|
38
|
+
"[createBuildLoader] Emitting file:",
|
|
39
|
+
id,
|
|
40
|
+
pluginContext.getModuleInfo(id),
|
|
41
|
+
pluginContext.getWatchFiles(),
|
|
42
|
+
destination,
|
|
43
|
+
emitIfNotExists
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return await import(fullDestination);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.log(
|
|
49
|
+
"[createBuildLoader] A file wasn't emitted, emitting now",
|
|
50
|
+
error
|
|
51
|
+
);
|
|
52
|
+
console.log("[createBuildLoader] Module doesn't exist, emitting it", fullDestination, result.code);
|
|
53
|
+
await mkdir(join(root, userConfig.build.outDir), { recursive: true });
|
|
54
|
+
|
|
55
|
+
await writeFile(fullDestination, result.code ?? "");
|
|
56
|
+
console.log("[createBuildLoader] Emitted file:", fullDestination);
|
|
57
|
+
return await import(fullDestination);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ModuleGraph, type Manifest } from "vite";
|
|
2
|
+
import {
|
|
3
|
+
collectManifestCss,
|
|
4
|
+
collectModuleGraphCss,
|
|
5
|
+
} from "../collect-css-manifest.js";
|
|
6
|
+
|
|
7
|
+
type BaseCssLoaderOptions = {
|
|
8
|
+
/** callback to add css files to the stream */
|
|
9
|
+
onCssFile: (css: string) => void;
|
|
10
|
+
/** loader to load the module */
|
|
11
|
+
loader: (id: string) => Promise<Record<string, any>>;
|
|
12
|
+
/** url of the page */
|
|
13
|
+
url: string;
|
|
14
|
+
/** manually provided css files to add */
|
|
15
|
+
cssFiles: string[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type CreateCssLoaderOptions =
|
|
19
|
+
| (BaseCssLoaderOptions & {
|
|
20
|
+
/** manifest to collect css from */
|
|
21
|
+
manifest: Manifest;
|
|
22
|
+
/** when manifest is given, moduleGraph is not needed */
|
|
23
|
+
moduleGraph?: never;
|
|
24
|
+
})
|
|
25
|
+
| (BaseCssLoaderOptions & {
|
|
26
|
+
/** when moduleGraph is given, manifest is not needed, manual cssFiles can still be provided */
|
|
27
|
+
manifest?: never;
|
|
28
|
+
/** when moduleGraph is given, manifest is not needed, manual cssFiles can still be provided */
|
|
29
|
+
moduleGraph: ModuleGraph;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* create a loader that can be used to load css files from a manifest or a moduleGraph
|
|
34
|
+
* @param options
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export async function createCssLoader(options: CreateCssLoaderOptions) {
|
|
38
|
+
const root = process.cwd();
|
|
39
|
+
|
|
40
|
+
const cssModules = new Set<string>();
|
|
41
|
+
|
|
42
|
+
if (!(options.manifest || options.moduleGraph))
|
|
43
|
+
throw new Error("Missing manifest or moduleGraph, pass it to options.");
|
|
44
|
+
|
|
45
|
+
const getCss = options.manifest
|
|
46
|
+
? (id: string) =>
|
|
47
|
+
collectManifestCss(
|
|
48
|
+
options.manifest,
|
|
49
|
+
root,
|
|
50
|
+
id,
|
|
51
|
+
options.onCssFile
|
|
52
|
+
)
|
|
53
|
+
: (id: string) => collectModuleGraphCss(options.moduleGraph!, id, options.onCssFile);
|
|
54
|
+
|
|
55
|
+
const loadWithCss = async (id: string) => {
|
|
56
|
+
if (!id) return {};
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const mod = await options.loader(id);
|
|
60
|
+
const pageCss = await Promise.resolve(getCss(id));
|
|
61
|
+
Array.from(pageCss.keys()).forEach((css) => cssModules.add(css));
|
|
62
|
+
return mod as Record<string, any>;
|
|
63
|
+
} catch (e: any) {
|
|
64
|
+
if (e.message?.includes("module runner has been closed")) {
|
|
65
|
+
return { type: "skip" } as Record<string, any>;
|
|
66
|
+
} else {
|
|
67
|
+
return { type: "error", error: e } as Record<string, any>;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return loadWithCss;
|
|
73
|
+
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { resolve as resolvePath } from "node:path";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
load
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
} from "react-server-dom-esm/node-loader";
|
|
7
|
+
|
|
3
8
|
import {
|
|
4
9
|
registerClientReference,
|
|
5
10
|
registerServerReference,
|
|
11
|
+
// @ts-ignore
|
|
6
12
|
} from "react-server-dom-esm/server.node";
|
|
7
|
-
import { createNormalizedRelativePath } from "../helpers/normalizedRelativePath.js";
|
|
8
13
|
|
|
9
14
|
type CreatePageLoaderOptions = {
|
|
10
|
-
manifest: Record<string, { file: string }>;
|
|
15
|
+
manifest: Record<string, { file: string; src?: string }>;
|
|
11
16
|
root: string;
|
|
12
17
|
outDir: string;
|
|
13
18
|
moduleBase: string;
|
|
@@ -52,41 +57,44 @@ export const createDefaultLoader = ({
|
|
|
52
57
|
return [key, value];
|
|
53
58
|
}
|
|
54
59
|
};
|
|
55
|
-
return async (url: string) =>
|
|
56
|
-
|
|
60
|
+
return async (url: string) => {
|
|
61
|
+
console.log("[createDefaultLoader] Loading:", url);
|
|
62
|
+
const result = await import(url);
|
|
63
|
+
console.log("[createDefaultLoader] Result:", result);
|
|
64
|
+
return Object.fromEntries(Object.entries(result).map(mapper));
|
|
65
|
+
};
|
|
57
66
|
};
|
|
58
67
|
|
|
59
|
-
export
|
|
68
|
+
export function createPageLoader({
|
|
60
69
|
manifest,
|
|
61
70
|
root,
|
|
62
71
|
outDir,
|
|
63
72
|
moduleBase,
|
|
64
|
-
registerServer,
|
|
65
|
-
registerClient,
|
|
66
73
|
alwaysRegisterServer,
|
|
67
74
|
alwaysRegisterClient,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (!
|
|
75
|
+
registerServer,
|
|
76
|
+
registerClient,
|
|
77
|
+
}: CreatePageLoaderOptions) {
|
|
78
|
+
return async function loader(id: string) {
|
|
79
|
+
console.log("[pageLoader] Loading:", {
|
|
80
|
+
id,
|
|
81
|
+
manifest: Object.keys(manifest),
|
|
82
|
+
outDir,
|
|
83
|
+
moduleBase
|
|
84
|
+
});
|
|
85
|
+
console.log("[pageLoader] Manifest:", manifest);
|
|
86
|
+
// Try to find the entry directly or by source file
|
|
87
|
+
const manifestEntry = manifest[id] ||
|
|
88
|
+
Object.values(manifest).find(entry => entry.src === id);
|
|
89
|
+
|
|
90
|
+
if (!manifestEntry) {
|
|
84
91
|
throw new Error(
|
|
85
|
-
`Could not find manifest entry for ${id}
|
|
92
|
+
`Could not find manifest entry for ${id} from ${root}. Available entries: ${Object.keys(manifest).join(', ')}`
|
|
86
93
|
);
|
|
87
94
|
}
|
|
95
|
+
|
|
88
96
|
const loaderResult = await load(
|
|
89
|
-
resolvePath(root, outDir,
|
|
97
|
+
resolvePath(root, outDir, manifestEntry.file),
|
|
90
98
|
{ format: "module" },
|
|
91
99
|
createDefaultLoader({
|
|
92
100
|
id,
|
|
@@ -98,4 +106,4 @@ export const createPageLoader = ({
|
|
|
98
106
|
);
|
|
99
107
|
return loaderResult;
|
|
100
108
|
};
|
|
101
|
-
}
|
|
109
|
+
}
|
package/plugin/plugin.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "./assertServerCondition.js";
|
|
2
|
+
export { reactServerPlugin } from "./react-server/plugin.js";
|
|
3
|
+
export { reactClientPlugin } from "./react-client/plugin.js";
|
|
4
|
+
export { reactTransformPlugin } from "./transformer/plugin.js";
|
|
5
|
+
export { reactPreservePlugin } from "./preserver/plugin.js";
|
|
6
|
+
export { vitePluginReactServer } from "./react-server/index.js";
|
|
7
|
+
// the main plugin is version is the server version, if you want the client version, use the `vite-plugin-react-server/client` import
|
|
8
|
+
// this is because the workflow assumes main thread = react server condition
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { reactPreservePlugin } from "./plugin.js";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Node } from "estree";
|
|
2
|
+
import type { Plugin } from "vite";
|
|
3
|
+
import MagicString from "magic-string";
|
|
4
|
+
import type { StreamPluginOptions } from "../types.js";
|
|
5
|
+
|
|
6
|
+
const REACT_DIRECTIVES = new Set(["use client", "use server"]);
|
|
7
|
+
|
|
8
|
+
export function reactPreservePlugin(_options: StreamPluginOptions): Plugin {
|
|
9
|
+
const meta: Record<string, Set<string>> = {};
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
name: "vite-plugin-react-server:preserve-directives",
|
|
13
|
+
enforce: 'post',
|
|
14
|
+
|
|
15
|
+
transform: {
|
|
16
|
+
order: 'post', // Ensure this runs last in transform phase
|
|
17
|
+
handler(code: string, id: string) {
|
|
18
|
+
// Skip node_modules and vite files
|
|
19
|
+
if (id.includes('node_modules') || id.includes('vite/dist')) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let ast: Node;
|
|
24
|
+
try {
|
|
25
|
+
ast = this.parse(code, {
|
|
26
|
+
allowReturnOutsideFunction: true,
|
|
27
|
+
jsx: true
|
|
28
|
+
}) as Node;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
console.warn(`[PreservePlugin] Failed to parse ${id}`, e);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (ast.type !== 'Program') {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const magicString = new MagicString(code);
|
|
39
|
+
let hasChanged = false;
|
|
40
|
+
|
|
41
|
+
// Only look at top-level directives
|
|
42
|
+
for (const node of ast.body) {
|
|
43
|
+
if (node.type !== 'ExpressionStatement') {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let directive: string | null = null;
|
|
48
|
+
if ('directive' in node) {
|
|
49
|
+
directive = node.directive;
|
|
50
|
+
} else if (
|
|
51
|
+
node.expression.type === 'Literal' &&
|
|
52
|
+
typeof node.expression.value === 'string' &&
|
|
53
|
+
REACT_DIRECTIVES.has(node.expression.value)
|
|
54
|
+
) {
|
|
55
|
+
directive = node.expression.value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (directive) {
|
|
59
|
+
meta[id] ||= new Set<string>();
|
|
60
|
+
meta[id].add(directive);
|
|
61
|
+
|
|
62
|
+
if ('start' in node && 'end' in node) {
|
|
63
|
+
magicString.remove(node.start as number, node.end as number);
|
|
64
|
+
hasChanged = true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!hasChanged) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
code: magicString.toString(),
|
|
75
|
+
map: magicString.generateMap({ hires: true }),
|
|
76
|
+
meta: {
|
|
77
|
+
directives: Array.from(meta[id] || [])
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
renderChunk(code, chunk) {
|
|
84
|
+
const chunkDirectives = new Set<string>();
|
|
85
|
+
|
|
86
|
+
// Collect directives from all modules in chunk
|
|
87
|
+
for (const id of chunk.moduleIds) {
|
|
88
|
+
if (meta[id]) {
|
|
89
|
+
meta[id].forEach(d => chunkDirectives.add(d));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (chunkDirectives.size) {
|
|
94
|
+
const magicString = new MagicString(code);
|
|
95
|
+
magicString.prepend(
|
|
96
|
+
Array.from(chunkDirectives)
|
|
97
|
+
.map(d => `"${d}";`)
|
|
98
|
+
.join('\n') + '\n'
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
code: magicString.toString(),
|
|
103
|
+
map: magicString.generateMap({ hires: true })
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { reactClientPlugin } from "./plugin.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Plugin as VitePlugin, UserConfig } from "vite";
|
|
2
|
+
|
|
3
|
+
import type { ResolvedUserOptions, StreamPluginOptions } from "../types.js";
|
|
4
|
+
import { resolveOptions } from "../config/resolveOptions.js";
|
|
5
|
+
import { resolveUserConfig } from "../config/resolveUserConfig.js";
|
|
6
|
+
|
|
7
|
+
let userOptions: ResolvedUserOptions;
|
|
8
|
+
|
|
9
|
+
export function reactClientPlugin(options: StreamPluginOptions): VitePlugin {
|
|
10
|
+
const resolvedOptions = resolveOptions(options);
|
|
11
|
+
if (resolvedOptions.type === "error") {
|
|
12
|
+
throw resolvedOptions.error;
|
|
13
|
+
}
|
|
14
|
+
userOptions = resolvedOptions.userOptions;
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
name: "vite:react-stream-client",
|
|
18
|
+
async config(config): Promise<UserConfig> {
|
|
19
|
+
const resolvedConfig = resolveUserConfig({
|
|
20
|
+
condition: "react-client",
|
|
21
|
+
config,
|
|
22
|
+
configEnv: { command: "build", mode: "production" },
|
|
23
|
+
userOptions,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if (resolvedConfig.type === "error") {
|
|
27
|
+
throw resolvedConfig.error;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return resolvedConfig.userConfig;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -18,6 +18,14 @@ export function createDevMiddleware(
|
|
|
18
18
|
server: ViteDevServer,
|
|
19
19
|
options: DevMiddlewareOptions
|
|
20
20
|
): RequestHandler {
|
|
21
|
+
// Add HMR support
|
|
22
|
+
const hmr = server.hot;
|
|
23
|
+
|
|
24
|
+
hmr?.on('vite:beforeUpdate', () => {
|
|
25
|
+
// Clear module cache before updates
|
|
26
|
+
server.moduleGraph.invalidateAll();
|
|
27
|
+
});
|
|
28
|
+
|
|
21
29
|
return async (req: IncomingMessage, res: ServerResponse, next: any) => {
|
|
22
30
|
// Skip non-page requests
|
|
23
31
|
if (
|
|
@@ -34,7 +42,15 @@ export function createDevMiddleware(
|
|
|
34
42
|
console.log("[stream] Handling RSC stream");
|
|
35
43
|
|
|
36
44
|
const result = await createHandler(url, options, {
|
|
37
|
-
loader:
|
|
45
|
+
loader: (id)=>{
|
|
46
|
+
const mod = server.ssrLoadModule(id);
|
|
47
|
+
if(!mod) {
|
|
48
|
+
throw new Error(`[RSC] Module not found: ${id}`);
|
|
49
|
+
} else {
|
|
50
|
+
console.log('[RSC] Loaded module:', id);
|
|
51
|
+
}
|
|
52
|
+
return mod;
|
|
53
|
+
},
|
|
38
54
|
moduleGraph: server.moduleGraph,
|
|
39
55
|
});
|
|
40
56
|
|
|
@@ -3,11 +3,22 @@ import {
|
|
|
3
3
|
collectManifestCss,
|
|
4
4
|
collectModuleGraphCss,
|
|
5
5
|
} from "../collect-css-manifest.js";
|
|
6
|
-
import { DEFAULT_CONFIG } from "../
|
|
6
|
+
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
7
7
|
import { resolvePage } from "../resolvePage.js";
|
|
8
8
|
import { resolveProps } from "../resolveProps.js";
|
|
9
9
|
import type { CreateHandlerOptions, StreamPluginOptions } from "../types.js";
|
|
10
10
|
import { createRscStream } from "./createRscStream.js";
|
|
11
|
+
import type { PipeableStream } from "react-dom/server";
|
|
12
|
+
|
|
13
|
+
type CreateHandlerResult =
|
|
14
|
+
| { type: "success"; controller: AbortController; stream: PipeableStream; assets: any; clientPath: string }
|
|
15
|
+
| { type: "error"; error: Error }
|
|
16
|
+
| { type: "skip" };
|
|
17
|
+
|
|
18
|
+
interface HandlerAssets {
|
|
19
|
+
css: Set<string>;
|
|
20
|
+
clientPath: string;
|
|
21
|
+
}
|
|
11
22
|
|
|
12
23
|
export async function createHandler<T>(
|
|
13
24
|
url: string,
|
|
@@ -19,7 +30,7 @@ export async function createHandler<T>(
|
|
|
19
30
|
Pick<StreamPluginOptions, "moduleBase" | "moduleBasePath" | "projectRoot">
|
|
20
31
|
>,
|
|
21
32
|
streamOptions: CreateHandlerOptions<T>
|
|
22
|
-
) {
|
|
33
|
+
): Promise<CreateHandlerResult> {
|
|
23
34
|
const root = pluginOptions.projectRoot ?? process.cwd();
|
|
24
35
|
|
|
25
36
|
const Html = pluginOptions.Html ?? DEFAULT_CONFIG.HTML;
|
|
@@ -55,8 +66,7 @@ export async function createHandler<T>(
|
|
|
55
66
|
: (id: string) => collectModuleGraphCss(streamOptions.moduleGraph!, id);
|
|
56
67
|
|
|
57
68
|
const loadWithCss = async (id: string) => {
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
console.log('[RSC] Loading module:', id);
|
|
60
70
|
try {
|
|
61
71
|
const mod = await streamOptions.loader(id);
|
|
62
72
|
const pageCss = await Promise.resolve(getCss(id));
|
|
@@ -110,35 +120,46 @@ export async function createHandler<T>(
|
|
|
110
120
|
error: new Error("Invalid props: " + propsPath, {
|
|
111
121
|
cause: props,
|
|
112
122
|
}),
|
|
113
|
-
}
|
|
123
|
+
}
|
|
114
124
|
}
|
|
115
125
|
|
|
116
126
|
// Add any additional CSS files
|
|
117
127
|
if (streamOptions.cssFiles) {
|
|
118
128
|
streamOptions.cssFiles.forEach((css) => cssModules.add(css));
|
|
119
129
|
}
|
|
130
|
+
|
|
120
131
|
const stream = createRscStream({
|
|
121
132
|
Html: Html,
|
|
122
133
|
Page: Page,
|
|
123
134
|
props: props,
|
|
124
|
-
moduleBasePath: pluginOptions.moduleBasePath,
|
|
135
|
+
moduleBasePath: pluginOptions.moduleBasePath,
|
|
125
136
|
logger: streamOptions.logger ?? createLogger(),
|
|
126
137
|
cssFiles: Array.from(cssModules),
|
|
127
138
|
route: url,
|
|
128
139
|
url,
|
|
129
140
|
pipableStreamOptions: streamOptions.pipableStreamOptions,
|
|
141
|
+
htmlProps: {
|
|
142
|
+
pageProps: props,
|
|
143
|
+
route: url,
|
|
144
|
+
url: url,
|
|
145
|
+
},
|
|
130
146
|
});
|
|
131
147
|
|
|
132
148
|
if (!stream) {
|
|
149
|
+
console.log("[createHandler] No stream created for route:", url);
|
|
133
150
|
return { type: "skip" as const };
|
|
134
151
|
}
|
|
135
152
|
|
|
153
|
+
const assets: HandlerAssets = {
|
|
154
|
+
css: new Set(cssFiles ?? []),
|
|
155
|
+
clientPath: pagePath ?? ''
|
|
156
|
+
};
|
|
157
|
+
|
|
136
158
|
return {
|
|
137
|
-
type: "success"
|
|
159
|
+
type: "success",
|
|
138
160
|
controller,
|
|
139
161
|
stream,
|
|
140
|
-
assets
|
|
141
|
-
|
|
142
|
-
},
|
|
162
|
+
assets,
|
|
163
|
+
clientPath: assets.clientPath,
|
|
143
164
|
};
|
|
144
165
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type PipeableStream,
|
|
5
|
-
} from "react-server-dom-esm/server.node";
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { renderToPipeableStream } from "react-server-dom-esm/server.node";
|
|
6
4
|
import { CssCollector } from "../components.js";
|
|
7
5
|
import type { RscStreamOptions } from "../types.js";
|
|
6
|
+
import type { PipeableStream } from "react-dom/server";
|
|
8
7
|
|
|
9
8
|
export function createRscStream(
|
|
10
9
|
streamOptions: RscStreamOptions
|
|
@@ -15,11 +14,11 @@ export function createRscStream(
|
|
|
15
14
|
props,
|
|
16
15
|
logger,
|
|
17
16
|
cssFiles,
|
|
18
|
-
route,
|
|
19
|
-
url,
|
|
20
17
|
moduleBasePath,
|
|
21
18
|
pipableStreamOptions,
|
|
19
|
+
htmlProps,
|
|
22
20
|
} = streamOptions;
|
|
21
|
+
|
|
23
22
|
const css = Array.isArray(cssFiles)
|
|
24
23
|
? cssFiles.map((css, index) =>
|
|
25
24
|
React.createElement(CssCollector, {
|
|
@@ -33,10 +32,7 @@ export function createRscStream(
|
|
|
33
32
|
Html,
|
|
34
33
|
{
|
|
35
34
|
key: "html",
|
|
36
|
-
|
|
37
|
-
moduleBasePath: moduleBasePath,
|
|
38
|
-
route,
|
|
39
|
-
url,
|
|
35
|
+
...htmlProps
|
|
40
36
|
},
|
|
41
37
|
React.createElement(Page, { key: "page", ...props }),
|
|
42
38
|
...css
|
|
@@ -46,7 +42,7 @@ export function createRscStream(
|
|
|
46
42
|
onError: logger?.error ?? console.error,
|
|
47
43
|
onPostpone: logger?.info ?? console.info,
|
|
48
44
|
environmentName: "Server",
|
|
49
|
-
...pipableStreamOptions
|
|
45
|
+
...pipableStreamOptions
|
|
50
46
|
}
|
|
51
47
|
);
|
|
52
48
|
}
|