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,57 @@
|
|
|
1
|
+
import { type MessagePort } from "node:worker_threads";
|
|
2
|
+
import type { LoadHookContext } from "node:module";
|
|
3
|
+
import type { LoaderContext, SerializedUserConfig } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Global port for communication between the main thread and the CSS loader.
|
|
6
|
+
* This port is used to send CSS file requests and receive responses.
|
|
7
|
+
*/
|
|
8
|
+
export declare let loaderPort: MessagePort | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Initializes the CSS loader with the necessary communication channels.
|
|
11
|
+
* Sets up message handlers for CSS file requests and responses.
|
|
12
|
+
*
|
|
13
|
+
* @param data - Configuration data for the CSS loader
|
|
14
|
+
* @param data.port - The message port for communication
|
|
15
|
+
*/
|
|
16
|
+
export declare function initialize(data: {
|
|
17
|
+
port: MessagePort;
|
|
18
|
+
resolvedConfig: SerializedUserConfig;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Sets the current page being processed.
|
|
22
|
+
* Used to track which CSS files are associated with which pages.
|
|
23
|
+
*
|
|
24
|
+
* @param page - The URL of the current page, or null if no page is active
|
|
25
|
+
*/
|
|
26
|
+
export declare function setCurrentPage(page: string | null): void;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves all CSS files associated with a specific page.
|
|
29
|
+
*
|
|
30
|
+
* @param page - The URL of the page
|
|
31
|
+
* @returns An array of CSS file paths used by the page
|
|
32
|
+
*/
|
|
33
|
+
export declare function getCssFilesForPage(page: string): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Vite's load hook implementation for CSS files.
|
|
36
|
+
* Handles CSS file loading requests and returns a placeholder module.
|
|
37
|
+
* The actual CSS content is processed in the main thread.
|
|
38
|
+
*
|
|
39
|
+
* @param url - The URL of the module to load
|
|
40
|
+
* @param context - The load hook context
|
|
41
|
+
* @param defaultLoad - The default load function
|
|
42
|
+
* @returns A promise that resolves to the module content
|
|
43
|
+
*/
|
|
44
|
+
export declare function load(url: string, context: LoadHookContext & LoaderContext & {
|
|
45
|
+
resolvedConfig: SerializedUserConfig;
|
|
46
|
+
}, defaultLoad: any): Promise<any>;
|
|
47
|
+
/**
|
|
48
|
+
* Vite's resolve hook implementation.
|
|
49
|
+
* Handles module resolution during development.
|
|
50
|
+
*
|
|
51
|
+
* @param specifier - The module specifier to resolve
|
|
52
|
+
* @param context - The resolve hook context
|
|
53
|
+
* @param defaultResolve - The default resolve function
|
|
54
|
+
* @returns A promise that resolves to the resolved module
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolve(specifier: string, context: any, defaultResolve: any): any;
|
|
57
|
+
//# sourceMappingURL=css-loader.development.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-loader.development.d.ts","sourceRoot":"","sources":["../../../plugin/loader/css-loader.development.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAOvE;;;GAGG;AACH,eAAO,IAAI,UAAU,EAAE,WAAW,GAAG,SAAS,CAAC;AAmB/C;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,cAAc,EAAE,oBAAoB,CAAA;CAAE,iBAIjG;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,QAEjD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAEzD;AA2DD;;;;;;;;;GASG;AACH,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,eAAe,GAAG,aAAa,GAAG;IAAE,cAAc,EAAE,oBAAoB,CAAA;CAAE,EACnF,WAAW,EAAE,GAAG,gBAQjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,OAE3E"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import 'node:worker_threads';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { preprocessCSS } from 'vite';
|
|
9
|
+
import { readFile } from 'node:fs/promises';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
|
|
12
|
+
let loaderPort;
|
|
13
|
+
const cssFilesByPage = /* @__PURE__ */ new Map();
|
|
14
|
+
let currentPage = null;
|
|
15
|
+
let resolvedConfig;
|
|
16
|
+
const env = import.meta?.env || {
|
|
17
|
+
BASE_URL: "/",
|
|
18
|
+
DEV: true,
|
|
19
|
+
MODE: "development",
|
|
20
|
+
PROD: false,
|
|
21
|
+
SSR: true
|
|
22
|
+
};
|
|
23
|
+
async function initialize(data) {
|
|
24
|
+
loaderPort = data.port;
|
|
25
|
+
resolvedConfig = data.resolvedConfig;
|
|
26
|
+
data.port.postMessage({ type: "INITIALIZED_CSS_LOADER" });
|
|
27
|
+
}
|
|
28
|
+
function setCurrentPage(page) {
|
|
29
|
+
currentPage = page;
|
|
30
|
+
}
|
|
31
|
+
function getCssFilesForPage(page) {
|
|
32
|
+
return Array.from(cssFilesByPage.get(page) || []);
|
|
33
|
+
}
|
|
34
|
+
async function processCssFile(filePath, config, inline) {
|
|
35
|
+
try {
|
|
36
|
+
const path = filePath.startsWith("file://") ? fileURLToPath(filePath) : filePath;
|
|
37
|
+
const source = await readFile(path, "utf-8");
|
|
38
|
+
const processed = await preprocessCSS(source, path, {
|
|
39
|
+
...config,
|
|
40
|
+
env
|
|
41
|
+
});
|
|
42
|
+
if (loaderPort) {
|
|
43
|
+
loaderPort.postMessage({
|
|
44
|
+
type: "CSS_FILE",
|
|
45
|
+
id: currentPage ? join(path, "?page=" + currentPage) : path,
|
|
46
|
+
path,
|
|
47
|
+
content: processed.code,
|
|
48
|
+
modules: processed.modules || {},
|
|
49
|
+
inline
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (inline) {
|
|
53
|
+
return {
|
|
54
|
+
format: "module",
|
|
55
|
+
source: processed.code,
|
|
56
|
+
shortCircuit: true
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
format: "module",
|
|
61
|
+
source: `export default ${JSON.stringify(processed.modules || {})};`,
|
|
62
|
+
shortCircuit: true
|
|
63
|
+
};
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(`[css-loader] Error processing CSS file: ${error}`);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function load(url, context, defaultLoad) {
|
|
70
|
+
const [name, query] = url.split("?");
|
|
71
|
+
if (name.endsWith(".css")) {
|
|
72
|
+
return processCssFile(url, resolvedConfig, query === "inline");
|
|
73
|
+
}
|
|
74
|
+
return defaultLoad(url, context, defaultLoad);
|
|
75
|
+
}
|
|
76
|
+
function resolve(specifier, context, defaultResolve) {
|
|
77
|
+
return defaultResolve(specifier, context, defaultResolve);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { getCssFilesForPage, initialize, load, loaderPort, resolve, setCurrentPage };
|
|
81
|
+
//# sourceMappingURL=css-loader.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-loader.development.js","sources":["../../../plugin/loader/css-loader.development.ts"],"sourcesContent":["import { type MessagePort } from \"node:worker_threads\";\nimport type { LoadHookContext } from \"node:module\";\nimport type { LoaderContext, SerializedUserConfig } from \"../types.js\";\nimport { fileURLToPath } from \"node:url\";\nimport { preprocessCSS } from \"vite\";\nimport type { ResolvedConfig } from \"vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\n/**\n * Global port for communication between the main thread and the CSS loader.\n * This port is used to send CSS file requests and receive responses.\n */\nexport let loaderPort: MessagePort | undefined;\n\n/**\n * Tracks CSS files used by each page.\n * Maps page URLs to sets of CSS file paths that are used by that page.\n */\nconst cssFilesByPage = new Map<string, Set<string>>();\n\nlet currentPage: string | null = null;\nlet resolvedConfig: ResolvedConfig | undefined;\n// Get environment variables\nconst env = import.meta?.env || {\n BASE_URL: '/',\n DEV: true,\n MODE: 'development',\n PROD: false,\n SSR: true\n};\n\n/**\n * Initializes the CSS loader with the necessary communication channels.\n * Sets up message handlers for CSS file requests and responses.\n *\n * @param data - Configuration data for the CSS loader\n * @param data.port - The message port for communication\n */\nexport async function initialize(data: { port: MessagePort, resolvedConfig: SerializedUserConfig }) {\n loaderPort = data.port;\n resolvedConfig = data.resolvedConfig;\n data.port.postMessage({ type: \"INITIALIZED_CSS_LOADER\" });\n}\n\n/**\n * Sets the current page being processed.\n * Used to track which CSS files are associated with which pages.\n *\n * @param page - The URL of the current page, or null if no page is active\n */\nexport function setCurrentPage(page: string | null) {\n currentPage = page;\n}\n\n/**\n * Retrieves all CSS files associated with a specific page.\n *\n * @param page - The URL of the page\n * @returns An array of CSS file paths used by the page\n */\nexport function getCssFilesForPage(page: string): string[] {\n return Array.from(cssFilesByPage.get(page) || []);\n}\n\n/**\n * Processes a CSS file request.\n * Sends a request to the main thread and waits for the processed CSS.\n *\n * @param filePath - The file system path of the CSS file\n * @param config - The Vite config\n * @returns A promise that resolves to the processed CSS content\n */\nasync function processCssFile(\n filePath: string,\n config: ResolvedConfig,\n inline: boolean\n): Promise<{ format: string; source: string; shortCircuit: boolean }> {\n try {\n // Convert file URL to path if needed\n const path = filePath.startsWith(\"file://\")\n ? fileURLToPath(filePath)\n : filePath;\n\n // Process CSS using Vite's preprocessCSS\n const source = await readFile(path, \"utf-8\");\n const processed = await preprocessCSS(source, path, {\n ...config,\n env: env\n });\n\n // If we're processing CSS for a specific page, notify the message handler\n if (loaderPort) {\n loaderPort.postMessage({\n type: \"CSS_FILE\",\n id: currentPage ? join(path, \"?page=\" + currentPage) : path,\n path: path,\n content: processed.code,\n modules: processed.modules || {},\n inline,\n });\n }\n\n // Return a module that can be used by React components\n if (inline) {\n return {\n format: \"module\",\n source: processed.code,\n shortCircuit: true,\n };\n }\n return {\n format: \"module\",\n source: `export default ${JSON.stringify(processed.modules || {})};`,\n shortCircuit: true,\n };\n } catch (error) {\n console.error(`[css-loader] Error processing CSS file: ${error}`);\n throw error;\n }\n}\n\n/**\n * Vite's load hook implementation for CSS files.\n * Handles CSS file loading requests and returns a placeholder module.\n * The actual CSS content is processed in the main thread.\n *\n * @param url - The URL of the module to load\n * @param context - The load hook context\n * @param defaultLoad - The default load function\n * @returns A promise that resolves to the module content\n */\nexport async function load(\n url: string,\n context: LoadHookContext & LoaderContext & { resolvedConfig: SerializedUserConfig },\n defaultLoad: any\n) {\n const [name, query] = url.split(\"?\");\n if (name.endsWith(\".css\")) {\n return processCssFile(url, resolvedConfig as ResolvedConfig, query === \"inline\");\n }\n\n return defaultLoad(url, context, defaultLoad);\n}\n\n/**\n * Vite's resolve hook implementation.\n * Handles module resolution during development.\n *\n * @param specifier - The module specifier to resolve\n * @param context - The resolve hook context\n * @param defaultResolve - The default resolve function\n * @returns A promise that resolves to the resolved module\n */\nexport function resolve(specifier: string, context: any, defaultResolve: any) {\n return defaultResolve(specifier, context, defaultResolve);\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAaW,IAAA;AAMX,MAAM,cAAA,uBAAqB,GAAyB,EAAA;AAEpD,IAAI,WAA6B,GAAA,IAAA;AACjC,IAAI,cAAA;AAEJ,MAAM,GAAA,GAAM,aAAa,GAAO,IAAA;AAAA,EAC9B,QAAU,EAAA,GAAA;AAAA,EACV,GAAK,EAAA,IAAA;AAAA,EACL,IAAM,EAAA,aAAA;AAAA,EACN,IAAM,EAAA,KAAA;AAAA,EACN,GAAK,EAAA;AACP,CAAA;AASA,eAAsB,WAAW,IAAmE,EAAA;AAClG,EAAA,UAAA,GAAa,IAAK,CAAA,IAAA;AAClB,EAAA,cAAA,GAAiB,IAAK,CAAA,cAAA;AACtB,EAAA,IAAA,CAAK,IAAK,CAAA,WAAA,CAAY,EAAE,IAAA,EAAM,0BAA0B,CAAA;AAC1D;AAQO,SAAS,eAAe,IAAqB,EAAA;AAClD,EAAc,WAAA,GAAA,IAAA;AAChB;AAQO,SAAS,mBAAmB,IAAwB,EAAA;AACzD,EAAA,OAAO,MAAM,IAAK,CAAA,cAAA,CAAe,IAAI,IAAI,CAAA,IAAK,EAAE,CAAA;AAClD;AAUA,eAAe,cAAA,CACb,QACA,EAAA,MAAA,EACA,MACoE,EAAA;AACpE,EAAI,IAAA;AAEF,IAAA,MAAM,OAAO,QAAS,CAAA,UAAA,CAAW,SAAS,CACtC,GAAA,aAAA,CAAc,QAAQ,CACtB,GAAA,QAAA;AAGJ,IAAA,MAAM,MAAS,GAAA,MAAM,QAAS,CAAA,IAAA,EAAM,OAAO,CAAA;AAC3C,IAAA,MAAM,SAAY,GAAA,MAAM,aAAc,CAAA,MAAA,EAAQ,IAAM,EAAA;AAAA,MAClD,GAAG,MAAA;AAAA,MACH;AAAA,KACD,CAAA;AAGD,IAAA,IAAI,UAAY,EAAA;AACd,MAAA,UAAA,CAAW,WAAY,CAAA;AAAA,QACrB,IAAM,EAAA,UAAA;AAAA,QACN,IAAI,WAAc,GAAA,IAAA,CAAK,IAAM,EAAA,QAAA,GAAW,WAAW,CAAI,GAAA,IAAA;AAAA,QACvD,IAAA;AAAA,QACA,SAAS,SAAU,CAAA,IAAA;AAAA,QACnB,OAAA,EAAS,SAAU,CAAA,OAAA,IAAW,EAAC;AAAA,QAC/B;AAAA,OACD,CAAA;AAAA;AAIH,IAAA,IAAI,MAAQ,EAAA;AACV,MAAO,OAAA;AAAA,QACL,MAAQ,EAAA,QAAA;AAAA,QACR,QAAQ,SAAU,CAAA,IAAA;AAAA,QAClB,YAAc,EAAA;AAAA,OAChB;AAAA;AAEF,IAAO,OAAA;AAAA,MACL,MAAQ,EAAA,QAAA;AAAA,MACR,MAAA,EAAQ,kBAAkB,IAAK,CAAA,SAAA,CAAU,UAAU,OAAW,IAAA,EAAE,CAAC,CAAA,CAAA,CAAA;AAAA,MACjE,YAAc,EAAA;AAAA,KAChB;AAAA,WACO,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,CAA2C,wCAAA,EAAA,KAAK,CAAE,CAAA,CAAA;AAChE,IAAM,MAAA,KAAA;AAAA;AAEV;AAYsB,eAAA,IAAA,CACpB,GACA,EAAA,OAAA,EACA,WACA,EAAA;AACA,EAAA,MAAM,CAAC,IAAM,EAAA,KAAK,CAAI,GAAA,GAAA,CAAI,MAAM,GAAG,CAAA;AACnC,EAAI,IAAA,IAAA,CAAK,QAAS,CAAA,MAAM,CAAG,EAAA;AACzB,IAAA,OAAO,cAAe,CAAA,GAAA,EAAK,cAAkC,EAAA,KAAA,KAAU,QAAQ,CAAA;AAAA;AAGjF,EAAO,OAAA,WAAA,CAAY,GAAK,EAAA,OAAA,EAAS,WAAW,CAAA;AAC9C;AAWgB,SAAA,OAAA,CAAQ,SAAmB,EAAA,OAAA,EAAc,cAAqB,EAAA;AAC5E,EAAO,OAAA,cAAA,CAAe,SAAW,EAAA,OAAA,EAAS,cAAc,CAAA;AAC1D;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MessagePort } from "node:worker_threads";
|
|
2
|
+
import type { LoadHookContext } from "node:module";
|
|
3
|
+
import type { LoaderContext } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Global port for communication between the main thread and the CSS loader.
|
|
6
|
+
* This port is used to send CSS file requests and receive responses.
|
|
7
|
+
*/
|
|
8
|
+
export declare let loaderPort: MessagePort | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Initializes the CSS loader with the necessary communication channels.
|
|
11
|
+
* Sets up message handlers for CSS file requests and responses.
|
|
12
|
+
*
|
|
13
|
+
* @param data - Configuration data for the CSS loader
|
|
14
|
+
* @param data.port - The message port for communication
|
|
15
|
+
* @param data.server - The Vite dev server instance
|
|
16
|
+
*/
|
|
17
|
+
export declare function initialize(data: {
|
|
18
|
+
port: MessagePort;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Vite's load hook implementation for CSS files.
|
|
22
|
+
* Handles CSS file loading requests and returns a placeholder module.
|
|
23
|
+
* The actual CSS content is processed in the main thread.
|
|
24
|
+
*
|
|
25
|
+
* @param url - The URL of the module to load
|
|
26
|
+
* @param context - The load hook context
|
|
27
|
+
* @param defaultLoad - The default load function
|
|
28
|
+
* @returns A promise that resolves to the module content
|
|
29
|
+
*/
|
|
30
|
+
export declare function load(url: string, context: LoadHookContext & LoaderContext, defaultLoad: any): Promise<any>;
|
|
31
|
+
//# sourceMappingURL=css-loader.production.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-loader.production.d.ts","sourceRoot":"","sources":["../../../plugin/loader/css-loader.production.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD;;;GAGG;AACH,eAAO,IAAI,UAAU,EAAE,WAAW,GAAG,SAAS,CAAC;AAI/C;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,iBAG3D;AAsCD;;;;;;;;;GASG;AACH,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,eAAe,GAAG,aAAa,EACxC,WAAW,EAAE,GAAG,gBASjB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { readFile } from 'node:fs/promises';
|
|
8
|
+
|
|
9
|
+
let loaderPort;
|
|
10
|
+
let stashedCssFiles = /* @__PURE__ */ new Map();
|
|
11
|
+
async function initialize(data) {
|
|
12
|
+
loaderPort = data.port;
|
|
13
|
+
data.port.postMessage({ type: "INITIALIZED_CSS_LOADER" });
|
|
14
|
+
}
|
|
15
|
+
async function processCssFile(filePath) {
|
|
16
|
+
try {
|
|
17
|
+
const path = filePath.startsWith("file://") ? fileURLToPath(filePath) : filePath;
|
|
18
|
+
if (stashedCssFiles.has(filePath)) {
|
|
19
|
+
return {
|
|
20
|
+
format: "module",
|
|
21
|
+
source: stashedCssFiles.get(filePath),
|
|
22
|
+
shortCircuit: true
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const source = await readFile(path, "utf-8");
|
|
26
|
+
stashedCssFiles.set(path, source);
|
|
27
|
+
return {
|
|
28
|
+
format: "module",
|
|
29
|
+
source,
|
|
30
|
+
shortCircuit: true
|
|
31
|
+
};
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function load(url, context, defaultLoad) {
|
|
37
|
+
const [name] = url.split("?");
|
|
38
|
+
if (name.endsWith(".css")) {
|
|
39
|
+
return processCssFile(url);
|
|
40
|
+
}
|
|
41
|
+
return defaultLoad(url, context, defaultLoad);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { initialize, load, loaderPort };
|
|
45
|
+
//# sourceMappingURL=css-loader.production.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-loader.production.js","sources":["../../../plugin/loader/css-loader.production.ts"],"sourcesContent":["import type { MessagePort } from \"node:worker_threads\";\nimport type { LoadHookContext } from \"node:module\";\nimport type { LoaderContext } from \"../types.js\";\nimport { fileURLToPath } from \"node:url\";\nimport { readFile } from \"node:fs/promises\";\n\n/**\n * Global port for communication between the main thread and the CSS loader.\n * This port is used to send CSS file requests and receive responses.\n */\nexport let loaderPort: MessagePort | undefined;\n\nlet stashedCssFiles = new Map();\n\n/**\n * Initializes the CSS loader with the necessary communication channels.\n * Sets up message handlers for CSS file requests and responses.\n *\n * @param data - Configuration data for the CSS loader\n * @param data.port - The message port for communication\n * @param data.server - The Vite dev server instance\n */\nexport async function initialize(data: { port: MessagePort }) {\n loaderPort = data.port;\n data.port.postMessage({ type: \"INITIALIZED_CSS_LOADER\" });\n}\n\n/**\n * Processes a CSS file request.\n * Sends a request to the main thread and waits for the processed CSS.\n *\n * @param filePath - The file system path of the CSS file\n * @param config - The Vite config\n * @returns A promise that resolves to the processed CSS content\n */\nasync function processCssFile(\n filePath: string\n): Promise<{ format: string; source: string; shortCircuit: boolean }> {\n try {\n // Convert file URL to path if needed\n const path = filePath.startsWith(\"file://\")\n ? fileURLToPath(filePath)\n : filePath;\n if (stashedCssFiles.has(filePath)) {\n return {\n format: \"module\",\n source: stashedCssFiles.get(filePath),\n shortCircuit: true,\n };\n }\n // Process CSS using Vite's preprocessCSS\n const source = await readFile(path, \"utf-8\");\n stashedCssFiles.set(path, source);\n return {\n format: \"module\",\n source: source,\n shortCircuit: true,\n };\n } catch (error) {\n throw error;\n }\n}\n\n/**\n * Vite's load hook implementation for CSS files.\n * Handles CSS file loading requests and returns a placeholder module.\n * The actual CSS content is processed in the main thread.\n *\n * @param url - The URL of the module to load\n * @param context - The load hook context\n * @param defaultLoad - The default load function\n * @returns A promise that resolves to the module content\n */\nexport async function load(\n url: string,\n context: LoadHookContext & LoaderContext,\n defaultLoad: any\n) {\n // Handle CSS files\n const [name] = url.split(\"?\");\n if (name.endsWith(\".css\")) {\n return processCssFile(url);\n }\n\n return defaultLoad(url, context, defaultLoad);\n}\n"],"names":[],"mappings":";;;;;;;;AAUW,IAAA;AAEX,IAAI,eAAA,uBAAsB,GAAI,EAAA;AAU9B,eAAsB,WAAW,IAA6B,EAAA;AAC5D,EAAA,UAAA,GAAa,IAAK,CAAA,IAAA;AAClB,EAAA,IAAA,CAAK,IAAK,CAAA,WAAA,CAAY,EAAE,IAAA,EAAM,0BAA0B,CAAA;AAC1D;AAUA,eAAe,eACb,QACoE,EAAA;AACpE,EAAI,IAAA;AAEF,IAAA,MAAM,OAAO,QAAS,CAAA,UAAA,CAAW,SAAS,CACtC,GAAA,aAAA,CAAc,QAAQ,CACtB,GAAA,QAAA;AACJ,IAAI,IAAA,eAAA,CAAgB,GAAI,CAAA,QAAQ,CAAG,EAAA;AACjC,MAAO,OAAA;AAAA,QACL,MAAQ,EAAA,QAAA;AAAA,QACR,MAAA,EAAQ,eAAgB,CAAA,GAAA,CAAI,QAAQ,CAAA;AAAA,QACpC,YAAc,EAAA;AAAA,OAChB;AAAA;AAGF,IAAA,MAAM,MAAS,GAAA,MAAM,QAAS,CAAA,IAAA,EAAM,OAAO,CAAA;AAC3C,IAAgB,eAAA,CAAA,GAAA,CAAI,MAAM,MAAM,CAAA;AAChC,IAAO,OAAA;AAAA,MACL,MAAQ,EAAA,QAAA;AAAA,MACR,MAAA;AAAA,MACA,YAAc,EAAA;AAAA,KAChB;AAAA,WACO,KAAO,EAAA;AACd,IAAM,MAAA,KAAA;AAAA;AAEV;AAYsB,eAAA,IAAA,CACpB,GACA,EAAA,OAAA,EACA,WACA,EAAA;AAEA,EAAA,MAAM,CAAC,IAAI,CAAI,GAAA,GAAA,CAAI,MAAM,GAAG,CAAA;AAC5B,EAAI,IAAA,IAAA,CAAK,QAAS,CAAA,MAAM,CAAG,EAAA;AACzB,IAAA,OAAO,eAAe,GAAG,CAAA;AAAA;AAG3B,EAAO,OAAA,WAAA,CAAY,GAAK,EAAA,OAAA,EAAS,WAAW,CAAA;AAC9C;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../plugin/loader/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { reactLoaderPlugin } from "./plugin.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StreamPluginOptions } from "../types.js";
|
|
2
|
+
import type { Plugin } from "vite";
|
|
3
|
+
/**
|
|
4
|
+
* Plugin for loading various front-end react files like css-loader, react-loader, etc.
|
|
5
|
+
*
|
|
6
|
+
* Core responsibilities:
|
|
7
|
+
* 1. Use the load hook to use the appropriate loader for the file type
|
|
8
|
+
* 2. When used, we can assume that such files work the same as when used as node loader
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* plugins: [
|
|
14
|
+
* reactLoaderPlugin({
|
|
15
|
+
* projectRoot: process.cwd(),
|
|
16
|
+
* })
|
|
17
|
+
* ]
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function reactLoaderPlugin(options: StreamPluginOptions): Plugin;
|
|
22
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../plugin/loader/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAOtE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { resolveOptions } from "../config/resolveOptions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Plugin for loading various front-end react files like css-loader, react-loader, etc.
|
|
4
|
+
*
|
|
5
|
+
* Core responsibilities:
|
|
6
|
+
* 1. Use the load hook to use the appropriate loader for the file type
|
|
7
|
+
* 2. When used, we can assume that such files work the same as when used as node loader
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* export default defineConfig({
|
|
12
|
+
* plugins: [
|
|
13
|
+
* reactLoaderPlugin({
|
|
14
|
+
* projectRoot: process.cwd(),
|
|
15
|
+
* })
|
|
16
|
+
* ]
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function reactLoaderPlugin(options) {
|
|
21
|
+
const resolvedOptionsResult = resolveOptions(options);
|
|
22
|
+
if (resolvedOptionsResult.type === "error")
|
|
23
|
+
throw resolvedOptionsResult.error;
|
|
24
|
+
return {
|
|
25
|
+
name: "vite:react-loader",
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { type LoadHookContext, type ResolveHookContext } from "node:module";
|
|
2
2
|
import type { MessagePort } from "node:worker_threads";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
port: MessagePort;
|
|
6
|
-
};
|
|
7
|
-
}
|
|
3
|
+
import type { LoaderContext } from "../types.js";
|
|
4
|
+
export declare let loaderPort: MessagePort | undefined;
|
|
8
5
|
export declare function getSource(url: string, context: any, defaultGetSource: any): Promise<any>;
|
|
9
|
-
export declare function transformModuleIfNeeded(source: string, url: string, loader: any, port?: MessagePort): Promise<string>;
|
|
6
|
+
export declare function transformModuleIfNeeded(source: string, url: string, loader: any, port?: MessagePort): Promise<string | null>;
|
|
10
7
|
export declare function initialize(data: {
|
|
11
8
|
port: MessagePort;
|
|
12
9
|
}): Promise<void>;
|
|
13
10
|
export declare function resolve(specifier: string, context: ResolveHookContext, nextResolve: any): Promise<any>;
|
|
14
11
|
export declare function load(url: string, context: LoadHookContext & LoaderContext, nextLoad: any): Promise<any>;
|
|
15
12
|
export declare function transformSource(source: string, context: any, defaultTransformSource: any): Promise<any>;
|
|
16
|
-
export {};
|
|
17
13
|
//# sourceMappingURL=react-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-loader.d.ts","sourceRoot":"","sources":["../../../plugin/loader/react-loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"react-loader.d.ts","sourceRoot":"","sources":["../../../plugin/loader/react-loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAsBjD,eAAO,IAAI,UAAU,EAAE,WAAW,GAAG,SAAS,CAAC;AAI/C,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,GAAG,EACZ,gBAAgB,EAAE,GAAG,gBAKtB;AA0mBD,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EACX,IAAI,CAAC,EAAE,WAAW,0BAuDnB;AA4KD,wBAAsB,UAAU,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,iBAI3D;AAGD,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,EAC3B,WAAW,EAAE,GAAG,gBAGjB;AAGD,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,eAAe,GAAG,aAAa,EACxC,QAAQ,EAAE,GAAG,gBA0Dd;AAGD,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,GAAG,EACZ,sBAAsB,EAAE,GAAG,gBAkC5B"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import * as acorn from 'acorn-loose';
|
|
7
7
|
import { basename } from 'path';
|
|
8
8
|
import { setSourceMapsSupport, SourceMap } from 'node:module';
|
|
9
|
+
import { workerData } from 'node:worker_threads';
|
|
9
10
|
|
|
10
11
|
let stashedGetSource = null;
|
|
11
12
|
setSourceMapsSupport(true, {
|
|
@@ -14,7 +15,15 @@ setSourceMapsSupport(true, {
|
|
|
14
15
|
generatedCode: true
|
|
15
16
|
// Enable for generated code
|
|
16
17
|
});
|
|
18
|
+
const env = workerData?.importMeta?.env || import.meta?.env || {
|
|
19
|
+
BASE_URL: "/",
|
|
20
|
+
DEV: false,
|
|
21
|
+
MODE: "production",
|
|
22
|
+
PROD: true,
|
|
23
|
+
SSR: true
|
|
24
|
+
};
|
|
17
25
|
let loaderPort;
|
|
26
|
+
let isDev = process.env["NODE_ENV"] === "development";
|
|
18
27
|
async function getSource(url, context, defaultGetSource) {
|
|
19
28
|
stashedGetSource = defaultGetSource;
|
|
20
29
|
return defaultGetSource(url, context, defaultGetSource);
|
|
@@ -238,8 +247,12 @@ function transformServerModule(source, program, url, sourceMap, _loader, port) {
|
|
|
238
247
|
entry.originalColumn = 0;
|
|
239
248
|
}
|
|
240
249
|
}
|
|
241
|
-
newSrc
|
|
242
|
-
newSrc +=
|
|
250
|
+
newSrc = "";
|
|
251
|
+
newSrc += `import ReactDOMServerESM from "react-server-dom-esm/server${isDev ? ".node" : ""}";
|
|
252
|
+
`;
|
|
253
|
+
newSrc += `if(ReactDOMServerESM instanceof Error){ throw ReactDOMServerESM; }`;
|
|
254
|
+
newSrc += `export const registerServerReference = ReactDOMServerESM.registerServerReference;
|
|
255
|
+
`;
|
|
243
256
|
if (mappings) {
|
|
244
257
|
mappings += ";;";
|
|
245
258
|
}
|
|
@@ -386,10 +399,13 @@ async function transformClientModule(program, url, sourceMap, loader) {
|
|
|
386
399
|
const names = [];
|
|
387
400
|
await parseExportNamesInto(body, names, url, loader);
|
|
388
401
|
if (names.length === 0) {
|
|
389
|
-
|
|
390
|
-
return "";
|
|
402
|
+
return null;
|
|
391
403
|
}
|
|
392
|
-
let newSrc =
|
|
404
|
+
let newSrc = `import ReactDOMServerESM from "react-server-dom-esm/server${isDev ? ".node" : ""}";
|
|
405
|
+
`;
|
|
406
|
+
newSrc += `if(ReactDOMServerESM instanceof Error){ throw new Error(ReactDOMServerESM); }`;
|
|
407
|
+
newSrc += `export const registerClientReference = ReactDOMServerESM.registerClientReference;
|
|
408
|
+
`;
|
|
393
409
|
for (let i = 0; i < names.length; i++) {
|
|
394
410
|
const name = names[i];
|
|
395
411
|
const errorMessage = name === "default" ? `Attempted to call the default export of ${url} from the server but it's on the client` : `Attempted to call ${name}() from the server but ${name} is on the client`;
|
|
@@ -460,13 +476,6 @@ async function transformModuleIfNeeded(source, url, loader, port) {
|
|
|
460
476
|
if (node.type !== "ExpressionStatement" || !node.directive) continue;
|
|
461
477
|
if (node.directive === "use client") {
|
|
462
478
|
useClient = true;
|
|
463
|
-
if (port) {
|
|
464
|
-
port.postMessage({
|
|
465
|
-
type: "CLIENT_COMPONENT",
|
|
466
|
-
url,
|
|
467
|
-
source
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
479
|
break;
|
|
471
480
|
}
|
|
472
481
|
if (node.directive === "use server") {
|
|
@@ -474,12 +483,18 @@ async function transformModuleIfNeeded(source, url, loader, port) {
|
|
|
474
483
|
break;
|
|
475
484
|
}
|
|
476
485
|
}
|
|
486
|
+
if (useClient && useServer) {
|
|
487
|
+
throw new Error(
|
|
488
|
+
"Cannot use both use client and use server directives in the same module"
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
if (!useClient && !useServer) {
|
|
492
|
+
return source;
|
|
493
|
+
}
|
|
477
494
|
if (useClient) {
|
|
478
495
|
return transformClientModule(program, url, undefined, loader);
|
|
479
|
-
} else if (useServer) {
|
|
480
|
-
return transformServerModule(source, program, url, undefined, loader, port);
|
|
481
496
|
}
|
|
482
|
-
return source;
|
|
497
|
+
return transformServerModule(source, program, url, undefined, loader, port);
|
|
483
498
|
}
|
|
484
499
|
function readMappings(mappings, callback) {
|
|
485
500
|
let line = 1;
|
|
@@ -602,24 +617,57 @@ function decodeVLQ(str) {
|
|
|
602
617
|
}
|
|
603
618
|
async function initialize(data) {
|
|
604
619
|
loaderPort = data.port;
|
|
605
|
-
data.port.postMessage({ type: "
|
|
620
|
+
data.port.postMessage({ type: "INITIALIZED_REACT_LOADER" });
|
|
606
621
|
data.port.unref();
|
|
607
622
|
}
|
|
608
623
|
async function resolve(specifier, context, nextResolve) {
|
|
609
624
|
return nextResolve(specifier, context);
|
|
610
625
|
}
|
|
611
626
|
async function load(url, context, nextLoad) {
|
|
612
|
-
const result = await nextLoad(url,
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
627
|
+
const result = await nextLoad(url, {
|
|
628
|
+
...context,
|
|
629
|
+
env
|
|
630
|
+
});
|
|
631
|
+
if (result.format !== "module") {
|
|
632
|
+
return result;
|
|
633
|
+
}
|
|
634
|
+
let sourceStr;
|
|
635
|
+
if (typeof result.source === "string") {
|
|
636
|
+
sourceStr = result.source;
|
|
637
|
+
} else if (result.source instanceof Uint8Array || Buffer.isBuffer(result.source)) {
|
|
638
|
+
sourceStr = result.source.toString("utf-8");
|
|
639
|
+
} else {
|
|
640
|
+
console.warn(
|
|
641
|
+
`[react-loader] Unexpected source type: ${typeof result.source}`
|
|
642
|
+
);
|
|
643
|
+
return result;
|
|
644
|
+
}
|
|
645
|
+
const transformResult = await transformModuleIfNeeded(
|
|
646
|
+
sourceStr,
|
|
647
|
+
url,
|
|
648
|
+
nextLoad,
|
|
649
|
+
loaderPort ?? undefined
|
|
650
|
+
);
|
|
651
|
+
if (transformResult === null) {
|
|
652
|
+
return result;
|
|
653
|
+
} else if (typeof transformResult === "string") {
|
|
654
|
+
return { ...result, source: transformResult };
|
|
655
|
+
} else if (typeof transformResult === "object") {
|
|
656
|
+
const typedResult = transformResult;
|
|
657
|
+
if (!("code" in typedResult)) {
|
|
658
|
+
throw new Error("Failed to transform module");
|
|
659
|
+
}
|
|
660
|
+
return {
|
|
661
|
+
...result,
|
|
662
|
+
source: typedResult.code,
|
|
663
|
+
map: typedResult.map || result.map
|
|
664
|
+
};
|
|
665
|
+
} else {
|
|
666
|
+
console.warn(
|
|
667
|
+
`[react-loader] Unexpected transform result type: ${typeof transformResult}`
|
|
619
668
|
);
|
|
620
|
-
return
|
|
669
|
+
return result;
|
|
621
670
|
}
|
|
622
|
-
return result;
|
|
623
671
|
}
|
|
624
672
|
async function transformSource(source, context, defaultTransformSource) {
|
|
625
673
|
const transformed = await defaultTransformSource(
|
|
@@ -628,12 +676,19 @@ async function transformSource(source, context, defaultTransformSource) {
|
|
|
628
676
|
defaultTransformSource
|
|
629
677
|
);
|
|
630
678
|
if (context.format === "module") {
|
|
631
|
-
|
|
632
|
-
if (typeof
|
|
633
|
-
|
|
679
|
+
let transformedSourceStr;
|
|
680
|
+
if (typeof transformed.source === "string") {
|
|
681
|
+
transformedSourceStr = transformed.source;
|
|
682
|
+
} else if (transformed.source instanceof Uint8Array || Buffer.isBuffer(transformed.source)) {
|
|
683
|
+
transformedSourceStr = transformed.source.toString("utf-8");
|
|
684
|
+
} else {
|
|
685
|
+
console.warn(
|
|
686
|
+
`[react-loader] Unexpected transformed source type: ${typeof transformed.source}`
|
|
687
|
+
);
|
|
688
|
+
return transformed;
|
|
634
689
|
}
|
|
635
690
|
const newSrc = await transformModuleIfNeeded(
|
|
636
|
-
|
|
691
|
+
transformedSourceStr,
|
|
637
692
|
context.url,
|
|
638
693
|
(url) => loadClientImport(url, defaultTransformSource),
|
|
639
694
|
context.data?.port
|
|
@@ -643,5 +698,5 @@ async function transformSource(source, context, defaultTransformSource) {
|
|
|
643
698
|
return transformed;
|
|
644
699
|
}
|
|
645
700
|
|
|
646
|
-
export { getSource, initialize, load, resolve, transformModuleIfNeeded, transformSource };
|
|
701
|
+
export { getSource, initialize, load, loaderPort, resolve, transformModuleIfNeeded, transformSource };
|
|
647
702
|
//# sourceMappingURL=react-loader.js.map
|