vite-plugin-react-server 1.1.10 → 1.1.12
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 +208 -27
- package/dist/package.json +34 -14
- package/dist/plugin/{css-collector-elements.d.ts → components/css-collector-elements.d.ts} +1 -1
- package/dist/plugin/components/css-collector-elements.d.ts.map +1 -0
- package/dist/plugin/components/css-collector-elements.js.map +1 -0
- package/dist/plugin/{css-collector.d.ts → components/css-collector.d.ts} +1 -1
- package/dist/plugin/components/css-collector.d.ts.map +1 -0
- package/dist/plugin/components/css-collector.js.map +1 -0
- package/dist/plugin/components/html.d.ts +4 -0
- package/dist/plugin/components/html.d.ts.map +1 -0
- package/dist/plugin/components/html.js +17 -0
- package/dist/plugin/components/html.js.map +1 -0
- package/dist/plugin/components/index.d.ts +5 -0
- package/dist/plugin/components/index.d.ts.map +1 -0
- package/dist/plugin/components.js +9 -3
- package/dist/plugin/components.js.map +1 -0
- package/dist/plugin/config/autoDiscover/index.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/index.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/index.js +8 -0
- package/dist/plugin/config/{resolveAutoDiscover.d.ts → autoDiscover/resolveAutoDiscover.d.ts} +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/{resolveAutoDiscover.js → autoDiscover/resolveAutoDiscover.js} +10 -9
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +10 -10
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -1
- package/dist/plugin/config/defaults.d.ts +4 -3
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +5 -3
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/index.d.ts +1 -0
- package/dist/plugin/config/index.d.ts.map +1 -1
- package/dist/plugin/config/index.js +1 -0
- package/dist/plugin/config/resolveEnv.d.ts +11 -1
- package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
- package/dist/plugin/config/resolveEnv.js +104 -5
- package/dist/plugin/config/resolveEnv.js.map +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +11 -4
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -1
- package/dist/plugin/config/resolveUrlOption.js +1 -2
- package/dist/plugin/config/resolveUrlOption.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +43 -18
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/config.js +17 -0
- package/dist/plugin/config.js.map +1 -0
- package/dist/plugin/env/index.d.ts +2 -0
- package/dist/plugin/env/index.d.ts.map +1 -0
- package/dist/plugin/env/index.js +1 -0
- package/dist/plugin/env/plugin.d.ts +30 -0
- package/dist/plugin/env/plugin.d.ts.map +1 -0
- package/dist/plugin/env/plugin.js +64 -0
- package/dist/plugin/env.js +45 -0
- package/dist/plugin/env.js.map +1 -0
- package/dist/plugin/error/toError.d.ts +6 -0
- package/dist/plugin/error/toError.d.ts.map +1 -0
- package/dist/plugin/error/toError.js +19 -0
- package/dist/plugin/error/toError.js.map +1 -0
- package/dist/plugin/file-preserver/plugin.d.ts +19 -0
- package/dist/plugin/file-preserver/plugin.d.ts.map +1 -0
- package/dist/plugin/file-preserver/plugin.js +108 -0
- package/dist/plugin/file-preserver.js +96 -0
- package/dist/plugin/file-preserver.js.map +1 -0
- package/dist/plugin/helpers/createEventHandler.d.ts +1 -1
- package/dist/plugin/helpers/createRscStream.js +1 -1
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/formatMetrics.d.ts +3 -1
- package/dist/plugin/helpers/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/helpers/formatMetrics.js +22 -7
- package/dist/plugin/helpers/formatMetrics.js.map +1 -0
- package/dist/plugin/helpers/getRouteFiles.d.ts +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.js +37 -18
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -0
- package/dist/plugin/helpers/index.d.ts +24 -0
- package/dist/plugin/helpers/index.d.ts.map +1 -0
- package/dist/plugin/helpers/index.js +31 -0
- package/dist/plugin/helpers/metrics.js +26 -2
- package/dist/plugin/helpers/metrics.js.map +1 -1
- package/dist/plugin/helpers/moduleRefs.d.ts.map +1 -0
- package/dist/plugin/helpers/moduleRefs.js.map +1 -0
- package/dist/plugin/helpers/requestInfo.d.ts +10 -0
- package/dist/plugin/helpers/requestInfo.d.ts.map +1 -1
- package/dist/plugin/helpers/requestInfo.js.map +1 -1
- package/dist/plugin/helpers/requestToRoute.js +22 -14
- package/dist/plugin/helpers/requestToRoute.js.map +1 -0
- package/dist/plugin/helpers/resolvePage.d.ts.map +1 -0
- package/dist/plugin/{resolvePage.js → helpers/resolvePage.js} +19 -3
- package/dist/plugin/helpers/resolvePage.js.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
- package/dist/plugin/helpers/resolvePageAndProps.js +7 -4
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -1
- package/dist/plugin/helpers/resolveProps.d.ts.map +1 -0
- package/dist/plugin/{resolveProps.js → helpers/resolveProps.js} +9 -6
- package/dist/plugin/helpers/resolveProps.js.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.js +1 -1
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
- package/dist/plugin/helpers/stashReturnValue.js +19 -13
- package/dist/plugin/helpers/stashReturnValue.js.map +1 -0
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +0 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/helpers.js +27 -0
- package/dist/plugin/helpers.js.map +1 -0
- package/dist/plugin/loader/createBuildLoader.js +1 -1
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/env-loader.development.d.ts +12 -0
- package/dist/plugin/loader/env-loader.development.d.ts.map +1 -0
- package/dist/plugin/loader/env-loader.development.js +60 -0
- package/dist/plugin/plugin.client.d.ts.map +1 -1
- package/dist/plugin/plugin.client.js +2 -0
- package/dist/plugin/plugin.client.js.map +1 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +1 -2
- package/dist/plugin/plugin.server.d.ts.map +1 -1
- package/dist/plugin/plugin.server.js +3 -0
- package/dist/plugin/plugin.server.js.map +1 -1
- package/dist/plugin/process-env.d.ts +14 -0
- package/dist/plugin/process-env.d.ts.map +1 -0
- package/dist/plugin/react-client/createMessageHandlers.d.ts +2 -1
- package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
- package/dist/plugin/react-client/createMessageHandlers.js +13 -2
- package/dist/plugin/react-client/createMessageHandlers.js.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.d.ts +8 -2
- package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.js +49 -8
- package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts +19 -0
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -0
- package/dist/plugin/react-client/handleWorkerRscStream.js +47 -0
- package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -0
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +18 -2
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/restartWorker.d.ts +6 -1
- package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
- package/dist/plugin/react-client/restartWorker.js +13 -5
- package/dist/plugin/react-client/restartWorker.js.map +1 -1
- package/dist/plugin/react-client/server.d.ts +2 -13
- package/dist/plugin/react-client/server.d.ts.map +1 -1
- package/dist/plugin/react-client/server.js +112 -99
- package/dist/plugin/react-client/server.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +18 -8
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-server/server.d.ts.map +1 -1
- package/dist/plugin/react-server/server.js +28 -12
- package/dist/plugin/react-server/server.js.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.js +9 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
- package/dist/plugin/react-static/fileWriter.d.ts +1 -1
- package/dist/plugin/react-static/fileWriter.d.ts.map +1 -1
- package/dist/plugin/react-static/fileWriter.js.map +1 -1
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +19 -27
- package/dist/plugin/react-static/plugin.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 +3 -2
- package/dist/plugin/root.js.map +1 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +1 -10
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.js +40 -38
- package/dist/plugin/types.d.ts +57 -15
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/types.js +1 -1
- package/dist/plugin/utils/callServer.d.ts +1 -1
- package/dist/plugin/utils/callServer.d.ts.map +1 -1
- package/dist/plugin/utils/callServer.js +2 -16
- package/dist/plugin/utils/callServer.js.map +1 -1
- package/dist/plugin/utils/createCallServer.d.ts +2 -0
- package/dist/plugin/utils/createCallServer.d.ts.map +1 -0
- package/dist/plugin/utils/createCallServer.js +28 -0
- package/dist/plugin/utils/createCallServer.js.map +1 -0
- package/dist/plugin/utils/createReactFetcher.d.ts +3 -1
- package/dist/plugin/utils/createReactFetcher.d.ts.map +1 -1
- package/dist/plugin/utils/createReactFetcher.js +7 -5
- package/dist/plugin/utils/createReactFetcher.js.map +1 -1
- package/dist/plugin/utils/env.js.map +1 -1
- package/dist/plugin/utils/envUrls.d.ts +9 -0
- package/dist/plugin/utils/envUrls.d.ts.map +1 -0
- package/dist/plugin/utils/envUrls.js +7 -0
- package/dist/plugin/utils/envUrls.node.d.ts +7 -0
- package/dist/plugin/utils/envUrls.node.d.ts.map +1 -0
- package/dist/plugin/utils/envUrls.node.js +11 -0
- package/dist/plugin/utils/envUrls.node.js.map +1 -0
- package/dist/plugin/utils/index.d.ts +1 -1
- package/dist/plugin/utils/index.d.ts.map +1 -1
- package/dist/plugin/utils/index.js +1 -1
- package/dist/plugin/utils/moduleBaseURL.d.ts +3 -0
- package/dist/plugin/utils/moduleBaseURL.d.ts.map +1 -0
- package/dist/plugin/utils/moduleBaseURL.js +4 -0
- package/dist/plugin/utils/urls.d.ts +130 -0
- package/dist/plugin/utils/urls.d.ts.map +1 -0
- package/dist/plugin/utils/urls.js +87 -0
- package/dist/plugin/utils/urls.js.map +1 -0
- package/dist/plugin/utils.js +1 -1
- package/dist/plugin/vendor/index.d.ts +2 -0
- package/dist/plugin/vendor/index.d.ts.map +1 -0
- package/dist/plugin/vendor/index.js +1 -0
- package/dist/plugin/vendor/vendor.client.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.client.js.map +1 -0
- package/dist/plugin/vendor/vendor.d.ts +2 -0
- package/dist/plugin/vendor/vendor.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.js +15 -0
- package/dist/plugin/vendor/vendor.js.map +1 -0
- package/dist/plugin/vendor/vendor.server.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.server.js.map +1 -0
- package/dist/plugin/vendor.js +7 -0
- package/dist/plugin/vendor.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +3 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +33 -20
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.js +4 -4
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +41 -15
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +16 -5
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +16 -5
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/sendMessage.js +45 -43
- package/dist/plugin/worker/sendMessage.js.map +1 -0
- package/dist/plugin/worker/types.d.ts +26 -4
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -14
- package/plugin/{css-collector-elements.tsx → components/css-collector-elements.tsx} +1 -1
- package/plugin/{css-collector.tsx → components/css-collector.tsx} +1 -1
- package/plugin/{html.tsx → components/html.tsx} +1 -3
- package/{dist/plugin/components.d.ts → plugin/components/index.ts} +1 -1
- package/plugin/config/autoDiscover/index.ts +10 -0
- package/plugin/config/{resolveAutoDiscover.ts → autoDiscover/resolveAutoDiscover.ts} +16 -12
- package/plugin/config/autoDiscover/resolveBuildPages.ts +10 -11
- package/plugin/config/defaults.tsx +4 -3
- package/plugin/config/index.ts +1 -1
- package/plugin/config/resolveEnv.ts +156 -6
- package/plugin/config/resolveOptions.ts +13 -5
- package/plugin/config/resolveUrlOption.ts +2 -7
- package/plugin/config/resolveUserConfig.ts +87 -36
- package/plugin/env/index.ts +1 -0
- package/plugin/env/plugin.ts +78 -0
- package/plugin/error/toError.ts +19 -0
- package/plugin/file-preserver/plugin.ts +117 -0
- package/plugin/helpers/createRscStream.tsx +1 -1
- package/plugin/helpers/formatMetrics.ts +2 -2
- package/plugin/helpers/getRouteFiles.ts +3 -1
- package/plugin/helpers/index.ts +38 -0
- package/plugin/helpers/requestInfo.ts +10 -0
- package/plugin/{resolvePage.ts → helpers/resolvePage.ts} +19 -4
- package/plugin/helpers/resolvePageAndProps.ts +7 -4
- package/plugin/{resolveProps.ts → helpers/resolveProps.ts} +8 -6
- package/plugin/helpers/serializeUserOptions.ts +1 -1
- package/plugin/helpers/tryManifest.ts +0 -1
- package/plugin/loader/createBuildLoader.ts +1 -1
- package/plugin/loader/env-loader.development.ts +84 -0
- package/plugin/plugin.client.ts +2 -0
- package/plugin/plugin.server.ts +3 -0
- package/plugin/plugin.ts +1 -3
- package/plugin/process-env.ts +13 -0
- package/plugin/react-client/createMessageHandlers.ts +13 -1
- package/plugin/react-client/createWorkerStream.ts +69 -15
- package/plugin/react-client/handleWorkerRscStream.ts +57 -0
- package/plugin/react-client/plugin.ts +29 -13
- package/plugin/react-client/restartWorker.ts +15 -7
- package/plugin/react-client/server.ts +115 -124
- package/plugin/react-server/plugin.ts +26 -13
- package/plugin/react-server/server.ts +33 -15
- package/plugin/react-static/collectHtmlWorkerContent.ts +13 -1
- package/plugin/react-static/fileWriter.ts +1 -1
- package/plugin/react-static/plugin.ts +21 -34
- package/plugin/root.ts +7 -1
- package/plugin/transformer/upgradeCssModuleCode.ts +39 -39
- package/plugin/types/env.d.ts +7 -0
- package/plugin/types.ts +68 -20
- package/plugin/utils/callServer.ts +2 -24
- package/plugin/utils/createCallServer.ts +26 -0
- package/plugin/utils/createReactFetcher.ts +10 -6
- package/plugin/utils/envUrls.node.ts +19 -0
- package/plugin/utils/envUrls.ts +8 -0
- package/plugin/utils/index.ts +1 -1
- package/plugin/utils/moduleBaseURL.ts +7 -0
- package/plugin/utils/urls.ts +217 -0
- package/plugin/vendor/index.ts +1 -0
- package/plugin/vendor/vendor.ts +6 -0
- package/plugin/worker/createWorker.ts +38 -22
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +1 -1
- package/plugin/worker/html/html-worker.development.tsx +2 -1
- package/plugin/worker/html/html-worker.production.tsx +2 -1
- package/plugin/worker/rsc/handleRender.ts +4 -5
- package/plugin/worker/rsc/messageHandler.tsx +53 -17
- package/plugin/worker/rsc/rsc-worker.development.ts +22 -8
- package/plugin/worker/rsc/rsc-worker.production.ts +23 -7
- package/plugin/worker/types.ts +28 -4
- package/dist/plugin/components.d.ts.map +0 -1
- package/dist/plugin/config/resolveAutoDiscover.d.ts.map +0 -1
- package/dist/plugin/config/resolveAutoDiscover.js.map +0 -1
- package/dist/plugin/copy.d.ts +0 -7
- package/dist/plugin/copy.d.ts.map +0 -1
- package/dist/plugin/copy.js +0 -30
- package/dist/plugin/css-collector-elements.d.ts.map +0 -1
- package/dist/plugin/css-collector-elements.js.map +0 -1
- package/dist/plugin/css-collector.d.ts.map +0 -1
- package/dist/plugin/css-collector.js.map +0 -1
- package/dist/plugin/getCondition.d.ts +0 -2
- package/dist/plugin/getCondition.d.ts.map +0 -1
- package/dist/plugin/html.d.ts +0 -4
- package/dist/plugin/html.d.ts.map +0 -1
- package/dist/plugin/html.js +0 -18
- package/dist/plugin/html.js.map +0 -1
- package/dist/plugin/manifest.d.ts +0 -6
- package/dist/plugin/manifest.d.ts.map +0 -1
- package/dist/plugin/manifest.js +0 -13
- package/dist/plugin/moduleRefs.d.ts.map +0 -1
- package/dist/plugin/moduleRefs.js.map +0 -1
- package/dist/plugin/resolvePage.d.ts.map +0 -1
- package/dist/plugin/resolvePage.js.map +0 -1
- package/dist/plugin/resolveProps.d.ts.map +0 -1
- package/dist/plugin/resolveProps.js.map +0 -1
- package/dist/plugin/utils/pageURL.d.ts +0 -5
- package/dist/plugin/utils/pageURL.d.ts.map +0 -1
- package/dist/plugin/utils/pageURL.js +0 -33
- package/dist/plugin/utils/pageURL.js.map +0 -1
- package/dist/plugin/vendor.client.d.ts.map +0 -1
- package/dist/plugin/vendor.client.js.map +0 -1
- package/dist/plugin/vendor.server.d.ts.map +0 -1
- package/dist/plugin/vendor.server.js.map +0 -1
- package/plugin/copy.ts +0 -39
- package/plugin/getCondition.ts +0 -0
- package/plugin/manifest.ts +0 -24
- package/plugin/utils/pageURL.ts +0 -33
- /package/dist/plugin/{css-collector-elements.js → components/css-collector-elements.js} +0 -0
- /package/dist/plugin/{css-collector.js → components/css-collector.js} +0 -0
- /package/{plugin/components.ts → dist/plugin/components/index.js} +0 -0
- /package/dist/plugin/{moduleRefs.d.ts → helpers/moduleRefs.d.ts} +0 -0
- /package/dist/plugin/{moduleRefs.js → helpers/moduleRefs.js} +0 -0
- /package/dist/plugin/{resolvePage.d.ts → helpers/resolvePage.d.ts} +0 -0
- /package/dist/plugin/{resolveProps.d.ts → helpers/resolveProps.d.ts} +0 -0
- /package/dist/plugin/{getCondition.js → process-env.js} +0 -0
- /package/dist/plugin/{vendor.client.d.ts → vendor/vendor.client.d.ts} +0 -0
- /package/dist/plugin/{vendor.client.js → vendor/vendor.client.js} +0 -0
- /package/dist/plugin/{vendor.server.d.ts → vendor/vendor.server.d.ts} +0 -0
- /package/dist/plugin/{vendor.server.js → vendor/vendor.server.js} +0 -0
- /package/plugin/{moduleRefs.ts → helpers/moduleRefs.ts} +0 -0
- /package/plugin/{vendor.client.ts → vendor/vendor.client.ts} +0 -0
- /package/plugin/{vendor.server.ts → vendor/vendor.server.ts} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createFromFetch,
|
|
3
|
+
encodeReply,
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
} from "react-server-dom-esm/client.browser";
|
|
6
|
+
|
|
7
|
+
type ServerResponse = { returnValue: unknown };
|
|
8
|
+
|
|
9
|
+
export const createCallServer = (moduleBaseURL: string) => {
|
|
10
|
+
const callServer = async (_id: string, args: unknown[]): Promise<unknown> => {
|
|
11
|
+
const response = await createFromFetch(
|
|
12
|
+
fetch(moduleBaseURL, {
|
|
13
|
+
method: "POST",
|
|
14
|
+
body: await encodeReply(args),
|
|
15
|
+
headers: {
|
|
16
|
+
Accept: "application/json",
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
{ callServer, moduleBaseURL }
|
|
21
|
+
);
|
|
22
|
+
const returnValue = (response as ServerResponse).returnValue;
|
|
23
|
+
return returnValue;
|
|
24
|
+
};
|
|
25
|
+
return callServer;
|
|
26
|
+
};
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
// @ts-ignore
|
|
3
3
|
import { createFromFetch } from "react-server-dom-esm/client.browser";
|
|
4
|
-
import {
|
|
5
|
-
import { pageURL } from "./pageURL.js";
|
|
4
|
+
import { createCallServer } from "./createCallServer.js";
|
|
6
5
|
import { env } from "./env.js";
|
|
6
|
+
import { createPageURL } from "./urls.js";
|
|
7
7
|
|
|
8
8
|
export function createReactFetcher({
|
|
9
9
|
moduleBaseURL = env.BASE_URL,
|
|
10
|
-
|
|
10
|
+
publicOrigin = env.PUBLIC_ORIGIN,
|
|
11
|
+
url = window.location.pathname,
|
|
12
|
+
indexRSC = "index.rsc",
|
|
11
13
|
headers = {
|
|
12
14
|
Accept: "text/x-component",
|
|
13
15
|
},
|
|
14
16
|
}: {
|
|
15
17
|
url?: string;
|
|
16
18
|
moduleBaseURL?: string;
|
|
19
|
+
publicOrigin?: string;
|
|
20
|
+
indexRSC?: string;
|
|
17
21
|
headers?: HeadersInit;
|
|
18
22
|
} = {}): Promise<ReactNode> {
|
|
19
|
-
const parsedURL =
|
|
23
|
+
const parsedURL = createPageURL(moduleBaseURL, publicOrigin, env.DEV)(url, indexRSC);
|
|
20
24
|
return createFromFetch(
|
|
21
25
|
fetch(parsedURL.indexRSC, {
|
|
22
26
|
headers: headers,
|
|
23
27
|
}),
|
|
24
28
|
{
|
|
25
|
-
callServer:
|
|
29
|
+
callServer: createCallServer(parsedURL.moduleBaseURL),
|
|
26
30
|
moduleBaseURL: parsedURL.moduleBaseURL,
|
|
27
31
|
}
|
|
28
|
-
)
|
|
32
|
+
);
|
|
29
33
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createAbsoluteURL, createBaseURL, createPageURL } from "./urls.js";
|
|
2
|
+
|
|
3
|
+
export const absoluteURL = (path: string) =>
|
|
4
|
+
createAbsoluteURL(
|
|
5
|
+
process.env.VITE_BASE_URL ?? "/",
|
|
6
|
+
process.env.VITE_PUBLIC_ORIGIN ?? ""
|
|
7
|
+
)(path);
|
|
8
|
+
|
|
9
|
+
export const baseURL = (path: string) =>
|
|
10
|
+
createBaseURL(process.env.VITE_BASE_URL ?? "/")(path);
|
|
11
|
+
|
|
12
|
+
export const pageURL = (path: string) =>
|
|
13
|
+
createPageURL(
|
|
14
|
+
process.env.VITE_BASE_URL ?? "/",
|
|
15
|
+
process.env.VITE_PUBLIC_ORIGIN ?? "",
|
|
16
|
+
typeof process.env.VITE_DEV === "string"
|
|
17
|
+
? process.env.VITE_DEV === "true" || process.env.VITE_DEV === "1"
|
|
18
|
+
: process.env["NODE_ENV"] === "development"
|
|
19
|
+
)(path);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { env } from "./env.js";
|
|
2
|
+
import { createAbsoluteURL, createBaseURL, createPageURL } from "./urls.js";
|
|
3
|
+
|
|
4
|
+
export const absoluteURL = createAbsoluteURL(env.BASE_URL, env.PUBLIC_ORIGIN);
|
|
5
|
+
export const baseURL = createBaseURL(env.BASE_URL);
|
|
6
|
+
export const pageURL = createPageURL(env.BASE_URL, env.PUBLIC_ORIGIN, env.DEV);
|
|
7
|
+
export const { indexRSC: rootIndexRSC, moduleBaseURL } = pageURL("/");
|
|
8
|
+
export const { BASE_URL, PUBLIC_ORIGIN } = env;
|
package/plugin/utils/index.ts
CHANGED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* # createAbsoluteUrl
|
|
4
|
+
*
|
|
5
|
+
* This function takes a baseURL and a public origin and returns a function that takes a path and returns the path with the baseURL attached to it.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const absoluteURL = createAbsoluteURL("/mmc", "https://bidoof.com")
|
|
10
|
+
* console.log(absoluteURL("/test")) // "https://bidoof.com/mmc/test"
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const absoluteURL = createAbsoluteURL("/mmc", "https://bidoof.com")
|
|
16
|
+
* console.log(absoluteURL("/test")) // "https://bidoof.com/mmc/test"
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* This can replace code like `${process.env.VITE_PUBLIC_ORIGIN}/test` with `absoluteUrl('/test')`, and you can be sure that it will work after
|
|
20
|
+
* changing the plugin settings.
|
|
21
|
+
*/
|
|
22
|
+
export const createAbsoluteURL = (
|
|
23
|
+
withBaseURL: string,
|
|
24
|
+
withPublicOrigin: string
|
|
25
|
+
) => {
|
|
26
|
+
const baseURL = createBaseURL(withBaseURL);
|
|
27
|
+
if (withPublicOrigin === "" || typeof withPublicOrigin !== "string")
|
|
28
|
+
return baseURL;
|
|
29
|
+
return (path: string) => {
|
|
30
|
+
const pathWithBaseURL = baseURL(path);
|
|
31
|
+
try {
|
|
32
|
+
return new URL(pathWithBaseURL, withPublicOrigin).toString();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return withPublicOrigin + pathWithBaseURL;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* # createBaseURL
|
|
41
|
+
*
|
|
42
|
+
* This function takes a baseURL and returns a function that takes a path and returns the path with the baseURL attached to it.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const baseURL = createBaseURL("/mmc")
|
|
47
|
+
* console.log(baseURL("/test")) // "/mmc/test"
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const baseURL = createBaseURL("/mmc/")
|
|
53
|
+
* console.log(baseURL("/test")) // "/mmc/test"
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* This can replace code like `${import.meta.env.test` with `baseURL(path)`, and you can be sure that it will work after
|
|
57
|
+
* changing the plugin settings.
|
|
58
|
+
*
|
|
59
|
+
* Path handling logic:
|
|
60
|
+
* 1. For baseURL ending with "/":
|
|
61
|
+
* - If path starts with "/", slice off the leading slash to avoid double slashes
|
|
62
|
+
* - If path doesn't start with "/", keep it as is
|
|
63
|
+
*
|
|
64
|
+
* 2. For baseURL not ending with "/":
|
|
65
|
+
* - If path starts with "/", directly concatenate with baseURL
|
|
66
|
+
* - If path doesn't start with "/", add a slash between baseURL and path
|
|
67
|
+
*
|
|
68
|
+
* baseURL "src" + path "src/test" -> should not concatenate to src/src/test
|
|
69
|
+
* baseURL "/" + path "https://bidoof.com" -> should not concatenate to /https://bidoof.com"
|
|
70
|
+
*/
|
|
71
|
+
export const createBaseURL = (withBaseURL: string) => {
|
|
72
|
+
if (withBaseURL.endsWith("/")) {
|
|
73
|
+
return (path: string) => {
|
|
74
|
+
if (path === "") return withBaseURL;
|
|
75
|
+
if (path.startsWith(withBaseURL) || isAbsoluteURL(path)) return path;
|
|
76
|
+
return `${withBaseURL}${removeLeadingSlash(path)}`;
|
|
77
|
+
};
|
|
78
|
+
} else {
|
|
79
|
+
return (path: string) => {
|
|
80
|
+
if (path === "") return withBaseURL;
|
|
81
|
+
if (isAbsoluteURL(path)) return path;
|
|
82
|
+
if (path.startsWith("/")) return withBaseURL + path;
|
|
83
|
+
if (path.startsWith(withBaseURL)) return path;
|
|
84
|
+
return `${withBaseURL}/${path}`;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** Remove a single trailing slash from the URL if it ends with one */
|
|
90
|
+
export const removeTrailingSlash = (url: string) =>
|
|
91
|
+
url.endsWith("/") ? url.slice(0, -1) : url;
|
|
92
|
+
|
|
93
|
+
/** Add a single trailing slash to the URL if it doesn't end with one */
|
|
94
|
+
export const addTrailingSlash = (url: string) =>
|
|
95
|
+
url.endsWith("/") ? url : `${url}/`;
|
|
96
|
+
|
|
97
|
+
export const removeLeadingSlash = (url: string) =>
|
|
98
|
+
url.startsWith("/") ? url.slice(1) : url;
|
|
99
|
+
|
|
100
|
+
export const addLeadingSlash = (url: string) =>
|
|
101
|
+
url.startsWith("/") ? url : `/${url}`;
|
|
102
|
+
|
|
103
|
+
export const isBlankRegex = /^(?:[a-zA-Z][a-zA-Z0-9+.-]*:)?\/\//;
|
|
104
|
+
export const isAbsoluteURL = (url: string) =>
|
|
105
|
+
isBlankRegex.test(url) || url.startsWith("//");
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
export const folderName = (path: string, withBaseURL: string) => {
|
|
109
|
+
const baseURL = createBaseURL(withBaseURL);
|
|
110
|
+
return baseURL(path.replace(/\[index.(html?|rsc|HTML?)]$/, ""));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* # createPageURL
|
|
115
|
+
*
|
|
116
|
+
* This function takes a baseURL, public origin and a optional normalizer function that mirrors the baseURL's format.
|
|
117
|
+
* If baseURL ends with a slash, we continue it using the URL itself (must end with a slash)
|
|
118
|
+
*
|
|
119
|
+
* - `indexRSC`: The path to the index.rsc file
|
|
120
|
+
* - `moduleBaseURL`: The baseURL to use for the module
|
|
121
|
+
*
|
|
122
|
+
* These can be passed in directly to the createReactFetcher and also determine the defaults when no input are provided.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { createFromFetch } from "react-server-dom-esm/client.browser";
|
|
127
|
+
* const parsedURL = pageURL(window.location.pathname ?? "/");
|
|
128
|
+
* const data = createFromFetch(
|
|
129
|
+
* fetch(parsedURL.indexRSC, {
|
|
130
|
+
* headers: {
|
|
131
|
+
* Accept: "text/x-component",
|
|
132
|
+
* }
|
|
133
|
+
* }),
|
|
134
|
+
* {
|
|
135
|
+
* callServer: callServer,
|
|
136
|
+
* moduleBaseURL: parsedURL.moduleBaseURL,
|
|
137
|
+
* }
|
|
138
|
+
* );
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* The moduleBasePath being set at the config level as "/",
|
|
142
|
+
* then we pass it to create a stream `renderToPipeableStream(elements, moduleBasePath)`, and we see
|
|
143
|
+
* ```text
|
|
144
|
+
* 2:I["src/components/Clickable.client-Dx9diOqr.js","ClientClickable"]
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
*/
|
|
148
|
+
export const createPageURL = (
|
|
149
|
+
withBaseURL: string,
|
|
150
|
+
withPublicOrigin: string,
|
|
151
|
+
isDev = false,
|
|
152
|
+
normalizer = !withBaseURL.endsWith("/")
|
|
153
|
+
? removeTrailingSlash
|
|
154
|
+
: addTrailingSlash,
|
|
155
|
+
) => {
|
|
156
|
+
return (to: string, fileName: string = "index.rsc") => {
|
|
157
|
+
try {
|
|
158
|
+
// Create the base URL first
|
|
159
|
+
const folderName = addTrailingSlash(
|
|
160
|
+
to.replace(/\[index.(html?|rsc|HTML?)]$/, "")
|
|
161
|
+
);
|
|
162
|
+
const baseURL = createBaseURL(withBaseURL);
|
|
163
|
+
const rscPath = baseURL(folderName) + fileName;
|
|
164
|
+
// Create moduleBaseURL and normalize it to match input format
|
|
165
|
+
const moduleBaseURL = parseURL(withBaseURL, withPublicOrigin);
|
|
166
|
+
if (moduleBaseURL.type === "error") {
|
|
167
|
+
throw moduleBaseURL.error;
|
|
168
|
+
}
|
|
169
|
+
const indexRSC = parseURL(rscPath, withPublicOrigin);
|
|
170
|
+
if (indexRSC.type === "error") {
|
|
171
|
+
throw indexRSC.error;
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
indexRSC: indexRSC.url.toString(),
|
|
175
|
+
moduleBaseURL: normalizer(moduleBaseURL.url.toString()),
|
|
176
|
+
};
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (isDev) console.error("Error parsing pageURL", error);
|
|
179
|
+
return {
|
|
180
|
+
indexRSC: withBaseURL + "index.rsc",
|
|
181
|
+
moduleBaseURL: withBaseURL,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* # moduleBaseURL
|
|
189
|
+
*
|
|
190
|
+
* This function takes a baseURL, public origin and a optional normalizer function that mirrors the baseURL's format.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* const moduleBaseURL = parseURL("/mmc", "https://bidoof.com")
|
|
195
|
+
* if(moduleBaseURL.type === "error") {
|
|
196
|
+
* console.error(moduleBaseURL.error)
|
|
197
|
+
* } else {
|
|
198
|
+
* console.log(moduleBaseURL.url)
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
**/
|
|
203
|
+
export const parseURL = (
|
|
204
|
+
url: string,
|
|
205
|
+
base: string
|
|
206
|
+
):
|
|
207
|
+
| { type: "success"; url: URL; error?: never; base?: never }
|
|
208
|
+
| { type: "error"; url: string; base: string; error: Error } => {
|
|
209
|
+
try {
|
|
210
|
+
return {
|
|
211
|
+
type: "success",
|
|
212
|
+
url: new URL(url, base),
|
|
213
|
+
};
|
|
214
|
+
} catch (error) {
|
|
215
|
+
return { type: "error", url: url, base: base, error: error as Error };
|
|
216
|
+
}
|
|
217
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './vendor.js';
|
|
@@ -9,6 +9,9 @@ import { join } from "node:path";
|
|
|
9
9
|
import { pluginRoot } from "../root.js";
|
|
10
10
|
import * as React from "react";
|
|
11
11
|
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
12
|
+
import { createLogger, type Logger } from "vite";
|
|
13
|
+
import type { HtmlWorkerOutputMessage } from "./types.js";
|
|
14
|
+
import type { RscWorkerOutputMessage } from "./types.js";
|
|
12
15
|
|
|
13
16
|
export type CreateWorkerOptions = {
|
|
14
17
|
projectRoot?: string;
|
|
@@ -25,6 +28,8 @@ export type CreateWorkerOptions = {
|
|
|
25
28
|
htmlChunkSize?: number; // Size of HTML chunks in bytes
|
|
26
29
|
workerData?: any;
|
|
27
30
|
transferList?: TransferListItem[];
|
|
31
|
+
logger?: Logger;
|
|
32
|
+
verbose?: boolean;
|
|
28
33
|
};
|
|
29
34
|
|
|
30
35
|
type CreateWorkerSuccess = {
|
|
@@ -65,6 +70,8 @@ export async function createWorker(
|
|
|
65
70
|
},
|
|
66
71
|
htmlChunkSize = 8 * 1024,
|
|
67
72
|
transferList = [],
|
|
73
|
+
logger = createLogger(),
|
|
74
|
+
verbose = false,
|
|
68
75
|
} = options;
|
|
69
76
|
let workerPathWithDefault =
|
|
70
77
|
typeof workerPath === "string" ? workerPath : undefined;
|
|
@@ -96,7 +103,8 @@ export async function createWorker(
|
|
|
96
103
|
[envPrefix + "PROD"]: mode === "production" ? "1" : "0",
|
|
97
104
|
[envPrefix + "SSR"]: "true",
|
|
98
105
|
[envPrefix + "BASE_URL"]: options.workerData.userOptions.moduleBaseURL,
|
|
99
|
-
[envPrefix + "PUBLIC_ORIGIN"]:
|
|
106
|
+
[envPrefix + "PUBLIC_ORIGIN"]:
|
|
107
|
+
options.workerData.userOptions.publicOrigin,
|
|
100
108
|
NODE_ENV: nodeEnv,
|
|
101
109
|
NODE_PATH: nodePath,
|
|
102
110
|
NODE_OPTIONS: process.env["NODE_OPTIONS"]?.includes(reverseCondition)
|
|
@@ -128,11 +136,35 @@ export async function createWorker(
|
|
|
128
136
|
const timeout = setTimeout(() => {
|
|
129
137
|
reject({ type: "error", error: new Error("Worker ready timeout") });
|
|
130
138
|
}, 5000);
|
|
131
|
-
|
|
132
|
-
|
|
139
|
+
const exitHandler = (code: number) => {
|
|
140
|
+
clearTimeout(timeout);
|
|
141
|
+
worker.removeListener("message", messageHandler);
|
|
142
|
+
worker.removeListener("exit", exitHandler);
|
|
143
|
+
if (code === 0) {
|
|
144
|
+
resolve({
|
|
145
|
+
type: "skip",
|
|
146
|
+
reason: "Worker exited with code 0",
|
|
147
|
+
workerPath: workerPathWithDefault,
|
|
148
|
+
} satisfies CreateWorkerSkip);
|
|
149
|
+
} else {
|
|
150
|
+
const error = new Error(`Worker exited with code ${code}`);
|
|
151
|
+
logger.error(`worker exited with code ${code}`, { error });
|
|
152
|
+
reject({
|
|
153
|
+
type: "error",
|
|
154
|
+
error,
|
|
155
|
+
workerPath: workerPathWithDefault,
|
|
156
|
+
} satisfies CreateWorkerError);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const messageHandler = (msg: HtmlWorkerOutputMessage | RscWorkerOutputMessage) => {
|
|
160
|
+
if (verbose) logger.info(`Initial worker message ${msg.type}`);
|
|
133
161
|
if (msg.type === "READY") {
|
|
162
|
+
if (verbose) logger.info(`Worker running for ${msg.env}`);
|
|
134
163
|
clearTimeout(timeout);
|
|
164
|
+
worker.removeListener("message", messageHandler);
|
|
165
|
+
worker.removeListener("exit", exitHandler);
|
|
135
166
|
if (msg.env !== nodeEnv) {
|
|
167
|
+
if (verbose) logger.info(`Worker environment mismatch.`);
|
|
136
168
|
reject({
|
|
137
169
|
type: "error",
|
|
138
170
|
error: new Error(
|
|
@@ -147,25 +179,9 @@ export async function createWorker(
|
|
|
147
179
|
workerPath: workerPathWithDefault,
|
|
148
180
|
} satisfies CreateWorkerSuccess);
|
|
149
181
|
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
worker.once("exit",
|
|
153
|
-
clearTimeout(timeout);
|
|
154
|
-
worker.removeAllListeners();
|
|
155
|
-
if (code === 0) {
|
|
156
|
-
resolve({
|
|
157
|
-
type: "skip",
|
|
158
|
-
reason: "Worker exited with code 0",
|
|
159
|
-
workerPath: workerPathWithDefault,
|
|
160
|
-
} satisfies CreateWorkerSkip);
|
|
161
|
-
} else {
|
|
162
|
-
reject({
|
|
163
|
-
type: "error",
|
|
164
|
-
error: new Error(`Worker exited with code ${code}`),
|
|
165
|
-
workerPath: workerPathWithDefault,
|
|
166
|
-
} satisfies CreateWorkerError);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
182
|
+
}
|
|
183
|
+
worker.once("message", messageHandler);
|
|
184
|
+
worker.once("exit", exitHandler);
|
|
169
185
|
}
|
|
170
186
|
);
|
|
171
187
|
} catch (error) {
|
|
@@ -8,7 +8,7 @@ import { Transform } from "node:stream";
|
|
|
8
8
|
import type { HtmlWorkerOutputMessage } from "../types.js";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import type { StreamMetrics } from "../../types.js";
|
|
11
|
-
import { ReactDOMServer } from "../../vendor.client.js";
|
|
11
|
+
import { ReactDOMServer } from "../../vendor/vendor.client.js";
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
const createMetrics = (): StreamMetrics => {
|
|
@@ -3,6 +3,7 @@ import { messageHandler } from "./messageHandler.js";
|
|
|
3
3
|
import { MessageChannel, parentPort } from "node:worker_threads";
|
|
4
4
|
import { pluginRoot } from "../../root.js";
|
|
5
5
|
import { register } from "node:module";
|
|
6
|
+
import type { ReadyMessage } from "../types.js";
|
|
6
7
|
|
|
7
8
|
// Create channels for each loader
|
|
8
9
|
const cssLoaderChannel = new MessageChannel();
|
|
@@ -22,4 +23,4 @@ parentPort?.postMessage({
|
|
|
22
23
|
type: "READY",
|
|
23
24
|
env: process.env["NODE_ENV"],
|
|
24
25
|
pid: process.pid,
|
|
25
|
-
});
|
|
26
|
+
} satisfies ReadyMessage);
|
|
@@ -3,6 +3,7 @@ import { messageHandler } from "./messageHandler.js";
|
|
|
3
3
|
import { MessageChannel, parentPort } from "node:worker_threads";
|
|
4
4
|
import { pluginRoot } from "../../root.js";
|
|
5
5
|
import { register } from "node:module";
|
|
6
|
+
import type { ReadyMessage } from "../types.js";
|
|
6
7
|
|
|
7
8
|
// Create channels for each loader
|
|
8
9
|
const cssLoaderChannel = new MessageChannel();
|
|
@@ -24,4 +25,4 @@ parentPort?.postMessage({
|
|
|
24
25
|
type: "READY",
|
|
25
26
|
env: process.env["NODE_ENV"],
|
|
26
27
|
pid: process.pid,
|
|
27
|
-
});
|
|
28
|
+
} satisfies ReadyMessage);
|
|
@@ -2,11 +2,11 @@ import { resolvePageAndProps } from "../../helpers/resolvePageAndProps.js";
|
|
|
2
2
|
import type { RscRenderMessage, StreamHandlers } from "../types.js";
|
|
3
3
|
import { activeStreams, cssFiles } from "./state.js";
|
|
4
4
|
import { createRscStream } from "../../helpers/createRscStream.js";
|
|
5
|
-
import { CssCollector } from "../../css-collector.js";
|
|
5
|
+
import { CssCollector } from "../../components/css-collector.js";
|
|
6
6
|
import { PassThrough } from "node:stream";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { workerData } from "node:worker_threads";
|
|
9
|
-
import { React } from "../../vendor.server.js";
|
|
9
|
+
import { React } from "../../vendor/vendor.server.js";
|
|
10
10
|
import { hmrState } from "./state.js";
|
|
11
11
|
import { performance } from "node:perf_hooks";
|
|
12
12
|
|
|
@@ -23,14 +23,13 @@ export async function handleRender(
|
|
|
23
23
|
propsExportName = workerData.userOptions.propsExportName,
|
|
24
24
|
projectRoot = workerData.userOptions.projectRoot,
|
|
25
25
|
moduleRootPath = workerData.userOptions.moduleRootPath,
|
|
26
|
-
moduleBaseURL = workerData.userOptions.moduleBaseURL,
|
|
27
|
-
moduleBasePath = workerData.userOptions.moduleBasePath,
|
|
26
|
+
moduleBaseURL = workerData.userOptions.moduleBaseURL ?? "/",
|
|
27
|
+
moduleBasePath = workerData.userOptions.moduleBasePath ?? "/",
|
|
28
28
|
moduleBase = workerData.userOptions.moduleBase,
|
|
29
29
|
pipeableStreamOptions = workerData.userOptions.pipeableStreamOptions,
|
|
30
30
|
cssFiles: messageCssFiles,
|
|
31
31
|
globalCss = workerData.globalCss,
|
|
32
32
|
} = msg;
|
|
33
|
-
|
|
34
33
|
try {
|
|
35
34
|
// Load modules
|
|
36
35
|
const pageAndPropsResult = await resolvePageAndProps({
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { parentPort, workerData } from "node:worker_threads";
|
|
2
|
-
import { addCssFileContent, hmrState } from "./state.js";
|
|
2
|
+
import { activeStreams, addCssFileContent, hmrState } from "./state.js";
|
|
3
3
|
import { handleRender } from "./handleRender.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
HmrAcceptMessage,
|
|
6
|
+
RscWorkerInputMessage,
|
|
7
|
+
RscWorkerOutputMessage,
|
|
8
|
+
StreamHandlers,
|
|
9
|
+
} from "../types.js";
|
|
10
|
+
import { sendMessage } from "../sendMessage.js";
|
|
5
11
|
|
|
6
|
-
export async function messageHandler(
|
|
12
|
+
export async function messageHandler(
|
|
13
|
+
msg: RscWorkerInputMessage,
|
|
14
|
+
port = parentPort
|
|
15
|
+
) {
|
|
7
16
|
if (!port) {
|
|
8
17
|
throw new Error("No port found");
|
|
9
18
|
}
|
|
@@ -48,6 +57,20 @@ export async function messageHandler(msg: any, port = parentPort) {
|
|
|
48
57
|
metrics,
|
|
49
58
|
} satisfies RscWorkerOutputMessage);
|
|
50
59
|
},
|
|
60
|
+
onHmrAccept: (routes: string[]) => {
|
|
61
|
+
port.postMessage({
|
|
62
|
+
type: "HMR_ACCEPT",
|
|
63
|
+
id: (msg as HmrAcceptMessage).id,
|
|
64
|
+
routes: routes,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
onHmrUpdate: (routes: string[]) => {
|
|
68
|
+
port.postMessage({
|
|
69
|
+
type: "HMR_UPDATE",
|
|
70
|
+
id: msg.id,
|
|
71
|
+
routes: routes,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
51
74
|
};
|
|
52
75
|
switch (msg.type) {
|
|
53
76
|
case "RSC_RENDER":
|
|
@@ -56,28 +79,23 @@ export async function messageHandler(msg: any, port = parentPort) {
|
|
|
56
79
|
return;
|
|
57
80
|
case "INITIALIZED_CSS_LOADER":
|
|
58
81
|
return;
|
|
82
|
+
case "INITIALIZED_ENV_LOADER":
|
|
83
|
+
return;
|
|
59
84
|
case "HMR_UPDATE":
|
|
60
85
|
// Mark the module as invalidated
|
|
61
|
-
hmrState.set(msg.
|
|
86
|
+
hmrState.set(msg.id, {
|
|
62
87
|
timestamp: msg.timestamp || Date.now(),
|
|
63
88
|
invalidated: true,
|
|
64
89
|
routes: msg.routes || [],
|
|
65
90
|
});
|
|
66
91
|
// Notify the main thread that we've processed the update
|
|
67
|
-
|
|
68
|
-
type: "HMR_ACCEPT",
|
|
69
|
-
path: msg.path,
|
|
70
|
-
routes: msg.routes,
|
|
71
|
-
});
|
|
92
|
+
handlers.onHmrUpdate(msg.routes || []);
|
|
72
93
|
return;
|
|
73
94
|
case "HMR_CLEANUP":
|
|
74
95
|
// Clear the invalidation state
|
|
75
|
-
hmrState.delete(msg.
|
|
96
|
+
hmrState.delete(msg.id);
|
|
76
97
|
// Notify the main thread that we've processed the cleanup
|
|
77
|
-
|
|
78
|
-
type: "HMR_ACCEPT",
|
|
79
|
-
path: msg.path,
|
|
80
|
-
});
|
|
98
|
+
handlers.onHmrAccept(msg.routes || []);
|
|
81
99
|
return;
|
|
82
100
|
case "CSS_FILE":
|
|
83
101
|
if (msg.id) {
|
|
@@ -87,13 +105,31 @@ export async function messageHandler(msg: any, port = parentPort) {
|
|
|
87
105
|
|
|
88
106
|
addCssFileContent(msg.id, msg.content, {
|
|
89
107
|
projectRoot: workerData.userOptions.projectRoot || process.cwd(),
|
|
90
|
-
moduleBaseURL: workerData.userOptions.moduleBaseURL || "",
|
|
91
|
-
moduleBasePath: workerData.userOptions.moduleBasePath || "",
|
|
92
|
-
moduleRootPath: workerData.userOptions.moduleRootPath
|
|
108
|
+
moduleBaseURL: workerData.userOptions.moduleBaseURL || "/",
|
|
109
|
+
moduleBasePath: workerData.userOptions.moduleBasePath || "/",
|
|
110
|
+
moduleRootPath: workerData.userOptions.moduleRootPath,
|
|
93
111
|
css: cssOptions,
|
|
94
112
|
});
|
|
95
113
|
}
|
|
96
114
|
return;
|
|
115
|
+
case "SHUTDOWN": {
|
|
116
|
+
// If id is "*", clean up all render states
|
|
117
|
+
if (msg.id === "*") {
|
|
118
|
+
activeStreams.forEach((stream, renderId) => {
|
|
119
|
+
stream.end();
|
|
120
|
+
activeStreams.delete(renderId);
|
|
121
|
+
});
|
|
122
|
+
parentPort?.removeAllListeners();
|
|
123
|
+
} else {
|
|
124
|
+
activeStreams.delete(msg.id);
|
|
125
|
+
}
|
|
126
|
+
// Send SHUTDOWN_COMPLETE message to signal that shutdown is complete
|
|
127
|
+
sendMessage({
|
|
128
|
+
type: "SHUTDOWN_COMPLETE",
|
|
129
|
+
id: msg.id,
|
|
130
|
+
} satisfies RscWorkerOutputMessage);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
97
133
|
default: {
|
|
98
134
|
console.log("Unknown message", msg);
|
|
99
135
|
return;
|