vite-plugin-react-server 1.1.12 → 1.1.13
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/dist/package.json +10 -8
- package/dist/plugin/components/css-collector-elements.d.ts +4 -2
- package/dist/plugin/components/css-collector-elements.d.ts.map +1 -1
- package/dist/plugin/components/css-collector-elements.js +21 -7
- package/dist/plugin/components/css-collector-elements.js.map +1 -1
- package/dist/plugin/components/css-collector.d.ts +4 -5
- package/dist/plugin/components/css-collector.d.ts.map +1 -1
- package/dist/plugin/components/css-collector.js +5 -9
- package/dist/plugin/components/css-collector.js.map +1 -1
- package/dist/plugin/components/html.d.ts +1 -1
- package/dist/plugin/components/html.d.ts.map +1 -1
- package/dist/plugin/components/html.js +14 -3
- package/dist/plugin/components/html.js.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts +4 -4
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js +14 -9
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -1
- package/dist/plugin/config/defaults.d.ts +66 -12
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +69 -15
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts +5 -0
- package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts.map +1 -0
- package/dist/plugin/config/resolveAutoDiscoverMatcher.js +25 -0
- package/dist/plugin/config/resolveAutoDiscoverMatcher.js.map +1 -0
- package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
- package/dist/plugin/config/resolveEnv.js +16 -5
- package/dist/plugin/config/resolveEnv.js.map +1 -1
- package/dist/plugin/config/resolveOptions.d.ts +3 -3
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +59 -87
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts +4 -4
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +8 -1
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/error/toError.d.ts +3 -0
- package/dist/plugin/error/toError.d.ts.map +1 -1
- package/dist/plugin/error/toError.js +33 -4
- package/dist/plugin/error/toError.js.map +1 -1
- package/dist/plugin/helpers/cleanObject.d.ts.map +1 -1
- package/dist/plugin/helpers/cleanObject.js +19 -5
- package/dist/plugin/helpers/cleanObject.js.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +3 -3
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts +4 -3
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
- package/dist/plugin/helpers/createCssProps.js +7 -2
- package/dist/plugin/helpers/createCssProps.js.map +1 -1
- package/dist/plugin/helpers/createHandler.d.ts +4 -3
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createHandler.js +1 -1
- package/dist/plugin/helpers/createHandler.js.map +1 -1
- package/dist/plugin/helpers/createRscStream.d.ts +2 -2
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
- package/dist/plugin/helpers/createRscStream.js +15 -5
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/index.d.ts +2 -2
- package/dist/plugin/helpers/index.d.ts.map +1 -1
- package/dist/plugin/helpers/index.js +2 -2
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +4 -1
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/moduleResolver.d.ts +3 -0
- package/dist/plugin/helpers/moduleResolver.d.ts.map +1 -0
- package/dist/plugin/helpers/moduleResolver.js +25 -0
- package/dist/plugin/helpers/requestInfo.d.ts +18 -3
- package/dist/plugin/helpers/requestInfo.d.ts.map +1 -1
- package/dist/plugin/helpers/requestInfo.js +75 -11
- package/dist/plugin/helpers/requestInfo.js.map +1 -1
- package/dist/plugin/helpers/resolvePage.d.ts.map +1 -1
- package/dist/plugin/helpers/resolvePage.js +2 -3
- package/dist/plugin/helpers/resolvePage.js.map +1 -1
- package/dist/plugin/helpers/resolvePageAndProps.d.ts +4 -3
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -1
- package/dist/plugin/helpers/serializeUserOptions.d.ts +3 -2
- package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -1
- package/dist/plugin/helpers/serializeUserOptions.js +13 -1
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
- package/dist/plugin/helpers/sourceMap.d.ts +8 -0
- package/dist/plugin/helpers/sourceMap.d.ts.map +1 -0
- package/dist/plugin/helpers/sourceMap.js +136 -0
- package/dist/plugin/helpers.js +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +7 -22
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +79 -65
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/createDefaultLoader.d.ts +13 -0
- package/dist/plugin/loader/createDefaultLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createDefaultLoader.js +47 -0
- package/dist/plugin/loader/css-loader.development.d.ts +1 -0
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.development.js +1 -1
- package/dist/plugin/loader/css-loader.development.js.map +1 -1
- package/dist/plugin/loader/handleExports.d.ts +33 -0
- package/dist/plugin/loader/handleExports.d.ts.map +1 -0
- package/dist/plugin/loader/handleExports.js +174 -0
- package/dist/plugin/loader/handleExports.js.map +1 -0
- package/dist/plugin/loader/index.d.ts +1 -1
- package/dist/plugin/loader/index.d.ts.map +1 -1
- package/dist/plugin/loader/index.js +4 -1
- package/dist/plugin/loader/parse.d.ts +6 -0
- package/dist/plugin/loader/parse.d.ts.map +1 -0
- package/dist/plugin/loader/parse.js +23 -0
- package/dist/plugin/loader/parse.js.map +1 -0
- package/dist/plugin/loader/react-loader.client.d.ts +2 -0
- package/dist/plugin/loader/react-loader.client.d.ts.map +1 -0
- package/dist/plugin/loader/react-loader.client.js +2 -0
- package/dist/plugin/loader/react-loader.d.ts +1 -12
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +5 -687
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/loader/react-loader.server.d.ts +21 -0
- package/dist/plugin/loader/react-loader.server.d.ts.map +1 -0
- package/dist/plugin/loader/react-loader.server.js +69 -0
- package/dist/plugin/loader/sourceMap.d.ts +35 -0
- package/dist/plugin/loader/sourceMap.d.ts.map +1 -0
- package/dist/plugin/loader/sourceMap.js +105 -0
- package/dist/plugin/loader/temporaryReferences.d.ts +1 -1
- package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.d.ts +2 -0
- package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -0
- package/dist/plugin/loader/transformModuleIfNeeded.js +27 -0
- package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -0
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts +27 -0
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts.map +1 -0
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.js +52 -0
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.js.map +1 -0
- package/dist/plugin/loader/types.d.ts +8 -0
- package/dist/plugin/loader/types.d.ts.map +1 -0
- package/dist/plugin/loader/types.js +1 -0
- package/dist/plugin/plugin.client.d.ts +2 -2
- package/dist/plugin/plugin.client.d.ts.map +1 -1
- package/dist/plugin/plugin.client.js +2 -3
- package/dist/plugin/plugin.client.js.map +1 -1
- package/dist/plugin/plugin.server.d.ts +2 -2
- package/dist/plugin/plugin.server.d.ts.map +1 -1
- package/dist/plugin/plugin.server.js +2 -2
- package/dist/plugin/plugin.server.js.map +1 -1
- package/dist/plugin/preserver/plugin.d.ts +2 -2
- package/dist/plugin/preserver/plugin.d.ts.map +1 -1
- package/dist/plugin/preserver/plugin.js +6 -2
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/{server.d.ts → configureWorkerRequestHandler.d.ts} +4 -4
- package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -0
- package/dist/plugin/react-client/{server.js → configureWorkerRequestHandler.js} +11 -8
- package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -0
- package/dist/plugin/react-client/createMessageHandlers.d.ts +1 -1
- package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
- package/dist/plugin/react-client/createMessageHandlers.js +18 -11
- package/dist/plugin/react-client/createMessageHandlers.js.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.d.ts +5 -3
- package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.js +61 -27
- package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.js +14 -4
- package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -1
- package/dist/plugin/react-client/plugin.d.ts +2 -2
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +7 -8
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/restartWorker.d.ts +1 -1
- package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
- package/dist/plugin/react-client/restartWorker.js +9 -3
- package/dist/plugin/react-client/restartWorker.js.map +1 -1
- package/dist/plugin/react-server/configureReactServer.d.ts +9 -0
- package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -0
- package/dist/plugin/react-server/{server.js → configureReactServer.js} +26 -8
- package/dist/plugin/react-server/configureReactServer.js.map +1 -0
- package/dist/plugin/react-server/handleServerAction.d.ts +5 -0
- package/dist/plugin/react-server/handleServerAction.d.ts.map +1 -0
- package/dist/plugin/react-server/handleServerAction.js +145 -0
- package/dist/plugin/react-server/handleServerAction.js.map +1 -0
- package/dist/plugin/react-server/plugin.d.ts +2 -2
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +1 -1
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +2 -2
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
- package/dist/plugin/react-static/collectRscContent.d.ts +2 -2
- package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -1
- package/dist/plugin/react-static/collectRscContent.js.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.d.ts +3 -3
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js +18 -7
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
- package/dist/plugin/react-static/plugin.d.ts +2 -2
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +28 -12
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPage.d.ts +2 -2
- package/dist/plugin/react-static/renderPage.d.ts.map +1 -1
- package/dist/plugin/react-static/renderPage.js.map +1 -1
- package/dist/plugin/react-static/renderPages.d.ts +2 -2
- package/dist/plugin/react-static/renderPages.d.ts.map +1 -1
- package/dist/plugin/react-static/renderPages.js.map +1 -1
- package/dist/plugin/react-static/renderStreams.d.ts +2 -2
- package/dist/plugin/react-static/renderStreams.d.ts.map +1 -1
- package/dist/plugin/react-static/renderStreams.js +4 -4
- package/dist/plugin/react-static/renderStreams.js.map +1 -1
- package/dist/plugin/source-map/createMappingsSerializer.d.ts +2 -0
- package/dist/plugin/source-map/createMappingsSerializer.d.ts.map +1 -0
- package/dist/plugin/source-map/createMappingsSerializer.js +159 -0
- package/dist/plugin/source-map/readMappings.d.ts +2 -0
- package/dist/plugin/source-map/readMappings.d.ts.map +1 -0
- package/dist/plugin/source-map/readMappings.js +201 -0
- package/dist/plugin/transformer/index.d.ts +0 -1
- package/dist/plugin/transformer/index.d.ts.map +1 -1
- package/dist/plugin/transformer/index.js +0 -1
- package/dist/plugin/transformer/plugin.client.d.ts +1 -3
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.client.js +1 -84
- package/dist/plugin/transformer/plugin.server.d.ts +2 -2
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.server.js +52 -20
- package/dist/plugin/transformer/plugin.server.js.map +1 -1
- package/dist/plugin/types.d.ts +89 -119
- package/dist/plugin/types.d.ts.map +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/createCallServer.d.ts +1 -1
- package/dist/plugin/utils/createCallServer.d.ts.map +1 -1
- package/dist/plugin/utils/createCallServer.js +13 -4
- package/dist/plugin/utils/createCallServer.js.map +1 -1
- package/dist/plugin/utils/index.d.ts +1 -0
- package/dist/plugin/utils/index.d.ts.map +1 -1
- package/dist/plugin/utils/index.js +1 -0
- package/dist/plugin/utils.js +1 -0
- package/dist/plugin/utils.js.map +1 -1
- package/dist/plugin/vendor/vendor.client.d.ts +2 -1
- package/dist/plugin/vendor/vendor.client.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.client.js +2 -1
- package/dist/plugin/vendor/vendor.client.js.map +1 -1
- package/dist/plugin/vendor/vendor.server.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.server.js +1 -1
- package/dist/plugin/vendor/vendor.server.js.map +1 -1
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +17 -22
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +25 -4
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js +15 -13
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +2 -12
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +2 -2
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts +2 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.js +8 -8
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +166 -107
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +112 -52
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts +5 -64
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js +5 -1
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/sendMessage.d.ts +2 -0
- package/dist/plugin/worker/sendMessage.d.ts.map +1 -1
- package/dist/plugin/worker/sendMessage.js +2 -1
- package/dist/plugin/worker/sendMessage.js.map +1 -1
- package/dist/plugin/worker/types.d.ts +52 -53
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -8
- package/plugin/components/css-collector-elements.tsx +30 -9
- package/plugin/components/css-collector.tsx +13 -22
- package/plugin/components/html.tsx +12 -5
- package/plugin/config/autoDiscover/resolveAutoDiscover.ts +31 -13
- package/plugin/config/defaults.tsx +72 -16
- package/plugin/config/resolveAutoDiscoverMatcher.ts +23 -0
- package/plugin/config/resolveEnv.ts +20 -12
- package/plugin/config/resolveOptions.ts +152 -155
- package/plugin/config/resolveUserConfig.ts +20 -5
- package/plugin/error/toError.ts +35 -1
- package/plugin/helpers/cleanObject.ts +79 -15
- package/plugin/helpers/collectViteModuleGraphCss.ts +4 -3
- package/plugin/helpers/createCssProps.tsx +26 -9
- package/plugin/helpers/createHandler.ts +7 -4
- package/plugin/helpers/createRscStream.tsx +20 -14
- package/plugin/helpers/index.ts +2 -2
- package/plugin/helpers/inputNormalizer.ts +4 -2
- package/plugin/helpers/moduleResolver.ts +36 -0
- package/plugin/helpers/requestInfo.ts +117 -23
- package/plugin/helpers/resolvePage.ts +2 -3
- package/plugin/helpers/resolvePageAndProps.ts +7 -6
- package/plugin/helpers/serializeUserOptions.ts +20 -2
- package/plugin/helpers/sourceMap.ts +182 -0
- package/plugin/loader/createBuildLoader.ts +124 -104
- package/plugin/loader/createDefaultLoader.ts +62 -0
- package/plugin/loader/css-loader.development.ts +3 -2
- package/plugin/loader/handleExports.ts +276 -0
- package/plugin/loader/index.ts +6 -1
- package/plugin/loader/parse.ts +22 -0
- package/plugin/loader/react-loader.client.ts +1 -0
- package/plugin/loader/react-loader.server.ts +107 -0
- package/plugin/loader/react-loader.ts +4 -1002
- package/plugin/loader/sourceMap.ts +118 -0
- package/plugin/loader/transformModuleIfNeeded.ts +33 -0
- package/plugin/loader/transformModuleWithPreservedFunctions.ts +119 -0
- package/plugin/loader/types.ts +10 -0
- package/plugin/plugin.client.ts +18 -11
- package/plugin/plugin.server.ts +6 -3
- package/plugin/preserver/plugin.ts +37 -17
- package/plugin/react-client/{server.ts → configureWorkerRequestHandler.ts} +22 -12
- package/plugin/react-client/createMessageHandlers.ts +21 -13
- package/plugin/react-client/createWorkerStream.ts +71 -33
- package/plugin/react-client/handleWorkerRscStream.ts +15 -5
- package/plugin/react-client/plugin.ts +18 -13
- package/plugin/react-client/restartWorker.ts +17 -5
- package/plugin/react-server/{server.ts → configureReactServer.ts} +40 -9
- package/plugin/react-server/handleServerAction.ts +177 -0
- package/plugin/react-server/plugin.ts +8 -3
- package/plugin/react-static/collectHtmlWorkerContent.ts +11 -3
- package/plugin/react-static/collectRscContent.ts +17 -9
- package/plugin/react-static/configurePreviewServer.ts +37 -17
- package/plugin/react-static/plugin.ts +45 -22
- package/plugin/react-static/renderPage.ts +12 -6
- package/plugin/react-static/renderPages.ts +15 -4
- package/plugin/react-static/renderStreams.ts +13 -12
- package/plugin/source-map/createMappingsSerializer.ts +182 -0
- package/plugin/source-map/readMappings.ts +195 -0
- package/plugin/transformer/README.md +295 -29
- package/plugin/transformer/index.ts +0 -1
- package/plugin/transformer/plugin.client.ts +0 -111
- package/plugin/transformer/plugin.server.ts +94 -25
- package/plugin/types/react-server-dom-esm.d.ts +183 -24
- package/plugin/types/sourceMap.d.ts +2 -0
- package/plugin/types/webpack-sources.d.ts +24 -0
- package/plugin/types.ts +169 -132
- package/plugin/utils/createCallServer.ts +21 -6
- package/plugin/utils/index.ts +2 -1
- package/plugin/vendor/vendor.client.ts +2 -1
- package/plugin/vendor/vendor.server.ts +1 -1
- package/plugin/worker/createWorker.ts +21 -24
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +31 -7
- package/plugin/worker/html/html-worker.development.tsx +16 -16
- package/plugin/worker/html/html-worker.production.tsx +3 -19
- package/plugin/worker/html/messageHandler.tsx +2 -4
- package/plugin/worker/rsc/handleRender.ts +15 -12
- package/plugin/worker/rsc/messageHandler.tsx +191 -120
- package/plugin/worker/rsc/rsc-worker.development.ts +148 -77
- package/plugin/worker/rsc/rsc-worker.production.ts +1 -1
- package/plugin/worker/rsc/state.ts +10 -0
- package/plugin/worker/sendMessage.ts +32 -14
- package/plugin/worker/types.ts +99 -64
- package/dist/plugin/react-client/server.d.ts.map +0 -1
- package/dist/plugin/react-client/server.js.map +0 -1
- package/dist/plugin/react-server/server.d.ts +0 -9
- package/dist/plugin/react-server/server.d.ts.map +0 -1
- package/dist/plugin/react-server/server.js.map +0 -1
- package/dist/plugin/transformer/plugin.client.js.map +0 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +0 -2
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +0 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.js +0 -40
- package/dist/plugin/worker/loader.d.ts +0 -5
- package/dist/plugin/worker/loader.d.ts.map +0 -1
- package/dist/plugin/worker/loader.js +0 -11
- package/dist/plugin/worker/loader.js.map +0 -1
- package/plugin/transformer/upgradeCssModuleCode.ts +0 -42
- package/plugin/worker/loader.ts +0 -7
|
@@ -4,124 +4,183 @@
|
|
|
4
4
|
* MIT License
|
|
5
5
|
*/
|
|
6
6
|
import { parentPort, workerData } from 'node:worker_threads';
|
|
7
|
-
import { activeStreams, addCssFileContent, hmrState } from './state.js';
|
|
7
|
+
import { activeStreams, addModuleId, addCssFileContent, hmrState } from './state.js';
|
|
8
8
|
import { handleRender } from './handleRender.js';
|
|
9
|
-
import {
|
|
9
|
+
import { sendRscWorkerMessage } from '../sendMessage.js';
|
|
10
|
+
import { toError } from '../../error/toError.js';
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const isTestEnv = process.env["VITEST"] || process.env["NODE_ENV"] === "test";
|
|
13
|
+
const isDevEnv = process.env["NODE_ENV"] !== "production";
|
|
14
|
+
const handlers = {
|
|
15
|
+
onError: (id, error, errorInfo) => {
|
|
16
|
+
sendRscWorkerMessage({
|
|
17
|
+
type: "ERROR",
|
|
18
|
+
id,
|
|
19
|
+
errorInfo,
|
|
20
|
+
error: toError(error)
|
|
21
|
+
});
|
|
22
|
+
sendRscWorkerMessage({
|
|
23
|
+
type: "RSC_END",
|
|
24
|
+
id
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
onData: (id, data) => {
|
|
28
|
+
sendRscWorkerMessage({
|
|
29
|
+
type: "RSC_CHUNK",
|
|
30
|
+
id,
|
|
31
|
+
chunk: data
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
onEnd: (id) => {
|
|
35
|
+
sendRscWorkerMessage({
|
|
36
|
+
type: "RSC_END",
|
|
37
|
+
id
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
onMetrics: (id, metrics) => {
|
|
41
|
+
sendRscWorkerMessage({
|
|
42
|
+
type: "RSC_METRICS",
|
|
43
|
+
id,
|
|
44
|
+
metrics
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
onHmrAccept: (id, routes) => {
|
|
48
|
+
sendRscWorkerMessage({
|
|
49
|
+
type: "HMR_ACCEPT",
|
|
50
|
+
id,
|
|
51
|
+
routes
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
onHmrUpdate: (id, routes) => {
|
|
55
|
+
sendRscWorkerMessage({
|
|
56
|
+
type: "HMR_UPDATE",
|
|
57
|
+
id,
|
|
58
|
+
routes
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
onServerModule: (id, url, source) => {
|
|
62
|
+
sendRscWorkerMessage({
|
|
63
|
+
type: "SERVER_MODULE",
|
|
64
|
+
id,
|
|
65
|
+
url,
|
|
66
|
+
source
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
onServerActionResponse: (id, result, error) => {
|
|
70
|
+
sendRscWorkerMessage({
|
|
71
|
+
type: "SERVER_ACTION_RESPONSE",
|
|
72
|
+
id,
|
|
73
|
+
result,
|
|
74
|
+
error
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
onServerAction: async (id, args) => {
|
|
78
|
+
try {
|
|
79
|
+
const serverAction = workerData.serverActions?.[id];
|
|
80
|
+
if (!serverAction) {
|
|
81
|
+
throw new Error(`Server action ${id} not found`);
|
|
19
82
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
message: error.message,
|
|
26
|
-
stack: error.stack,
|
|
27
|
-
name: error.name,
|
|
28
|
-
cause: error.cause
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
port.postMessage({
|
|
32
|
-
type: "RSC_END",
|
|
33
|
-
id: msg.id
|
|
83
|
+
const result = await serverAction(...args);
|
|
84
|
+
sendRscWorkerMessage({
|
|
85
|
+
type: "SERVER_ACTION_RESPONSE",
|
|
86
|
+
id,
|
|
87
|
+
result
|
|
34
88
|
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
chunk: data
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
onEnd: () => {
|
|
44
|
-
port.postMessage({
|
|
45
|
-
type: "RSC_END",
|
|
46
|
-
id: msg.id
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
onMetrics: (metrics) => {
|
|
50
|
-
port.postMessage({
|
|
51
|
-
type: "RSC_METRICS",
|
|
52
|
-
id: msg.id,
|
|
53
|
-
metrics
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
onHmrAccept: (routes) => {
|
|
57
|
-
port.postMessage({
|
|
58
|
-
type: "HMR_ACCEPT",
|
|
59
|
-
id: msg.id,
|
|
60
|
-
routes
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
onHmrUpdate: (routes) => {
|
|
64
|
-
port.postMessage({
|
|
65
|
-
type: "HMR_UPDATE",
|
|
66
|
-
id: msg.id,
|
|
67
|
-
routes
|
|
89
|
+
} catch (error) {
|
|
90
|
+
sendRscWorkerMessage({
|
|
91
|
+
type: "SERVER_ACTION_RESPONSE",
|
|
92
|
+
id,
|
|
93
|
+
error: error instanceof Error ? error.message : String(error)
|
|
68
94
|
});
|
|
69
95
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
moduleBaseURL: workerData.userOptions.moduleBaseURL || "/",
|
|
100
|
-
moduleBasePath: workerData.userOptions.moduleBasePath || "/",
|
|
101
|
-
moduleRootPath: workerData.userOptions.moduleRootPath,
|
|
102
|
-
css: cssOptions
|
|
96
|
+
},
|
|
97
|
+
onShutdown: (id) => {
|
|
98
|
+
sendRscWorkerMessage({
|
|
99
|
+
type: "SHUTDOWN_COMPLETE",
|
|
100
|
+
id
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
async function messageHandler(msg, port = parentPort) {
|
|
105
|
+
try {
|
|
106
|
+
if (!port) {
|
|
107
|
+
throw new Error("No port found");
|
|
108
|
+
}
|
|
109
|
+
switch (msg.type) {
|
|
110
|
+
case "RSC_RENDER":
|
|
111
|
+
return await handleRender(msg, handlers);
|
|
112
|
+
case "SERVER_ACTION":
|
|
113
|
+
return handlers.onServerAction(msg.id, msg.args);
|
|
114
|
+
case "INITIALIZED_REACT_LOADER":
|
|
115
|
+
return;
|
|
116
|
+
case "INITIALIZED_CSS_LOADER":
|
|
117
|
+
return;
|
|
118
|
+
case "INITIALIZED_ENV_LOADER":
|
|
119
|
+
return;
|
|
120
|
+
case "HMR_UPDATE":
|
|
121
|
+
hmrState.set(msg.id, {
|
|
122
|
+
timestamp: msg.timestamp || Date.now(),
|
|
123
|
+
invalidated: true,
|
|
124
|
+
routes: msg.routes || []
|
|
103
125
|
});
|
|
126
|
+
handlers.onHmrUpdate(msg.id, msg.routes || []);
|
|
127
|
+
return;
|
|
128
|
+
case "HMR_CLEANUP":
|
|
129
|
+
hmrState.delete(msg.id);
|
|
130
|
+
handlers.onHmrAccept(msg.id, msg.routes || []);
|
|
131
|
+
return;
|
|
132
|
+
case "CSS_FILE":
|
|
133
|
+
if (msg.id) {
|
|
134
|
+
const cssOptions = workerData.userOptions.css || {
|
|
135
|
+
inlineThreshold: 1e3
|
|
136
|
+
};
|
|
137
|
+
addCssFileContent(msg.id, msg.content, {
|
|
138
|
+
projectRoot: workerData.userOptions.projectRoot || process.cwd(),
|
|
139
|
+
moduleBaseURL: workerData.userOptions.moduleBaseURL || "/",
|
|
140
|
+
moduleBasePath: workerData.userOptions.moduleBasePath || "/",
|
|
141
|
+
moduleRootPath: workerData.userOptions.moduleRootPath,
|
|
142
|
+
css: cssOptions
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
case "SERVER_MODULE":
|
|
147
|
+
if (msg.id && msg.url) {
|
|
148
|
+
addModuleId(msg.id, msg.url);
|
|
149
|
+
}
|
|
150
|
+
handlers.onServerModule(msg.id, msg.url, msg.source);
|
|
151
|
+
return;
|
|
152
|
+
case "SHUTDOWN": {
|
|
153
|
+
if (msg.id === "*") {
|
|
154
|
+
activeStreams.forEach((stream, renderId) => {
|
|
155
|
+
stream.end();
|
|
156
|
+
activeStreams.delete(renderId);
|
|
157
|
+
});
|
|
158
|
+
parentPort?.removeAllListeners();
|
|
159
|
+
} else {
|
|
160
|
+
activeStreams.delete(msg.id);
|
|
161
|
+
}
|
|
162
|
+
handlers.onShutdown(msg.id);
|
|
163
|
+
return;
|
|
104
164
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
activeStreams.forEach((stream, renderId) => {
|
|
109
|
-
stream.end();
|
|
110
|
-
activeStreams.delete(renderId);
|
|
111
|
-
});
|
|
112
|
-
parentPort?.removeAllListeners();
|
|
113
|
-
} else {
|
|
114
|
-
activeStreams.delete(msg.id);
|
|
165
|
+
default: {
|
|
166
|
+
console.log("Unknown message", msg);
|
|
167
|
+
return;
|
|
115
168
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
169
|
+
}
|
|
170
|
+
} catch (error) {
|
|
171
|
+
const err = toError(error);
|
|
172
|
+
if (isDevEnv) {
|
|
173
|
+
console.error(err);
|
|
174
|
+
}
|
|
175
|
+
if (parentPort) {
|
|
176
|
+
port?.postMessage({
|
|
177
|
+
type: "ERROR",
|
|
178
|
+
id: "rsc-worker",
|
|
179
|
+
error: err
|
|
119
180
|
});
|
|
120
|
-
return;
|
|
121
181
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return;
|
|
182
|
+
if (!isDevEnv || isTestEnv) {
|
|
183
|
+
throw err;
|
|
125
184
|
}
|
|
126
185
|
}
|
|
127
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageHandler.js","sources":["../../../../plugin/worker/rsc/messageHandler.tsx"],"sourcesContent":["import { parentPort, workerData } from \"node:worker_threads\";\nimport { activeStreams, addCssFileContent, hmrState } from \"./state.js\";\nimport { handleRender } from \"./handleRender.js\";\nimport type {\n HmrAcceptMessage,\n RscWorkerInputMessage,\n RscWorkerOutputMessage,\n StreamHandlers,\n} from \"../types.js\";\nimport { sendMessage } from \"../sendMessage.js\";\n\nexport async function messageHandler(\n msg: RscWorkerInputMessage,\n port = parentPort\n) {\n if (!port) {\n throw new Error(\"No port found\");\n }\n const handlers: StreamHandlers = {\n onError: (error: any, errorInfo?: any) => {\n if (!(error instanceof Error)) {\n error = new Error(String(error));\n }\n port.postMessage({\n type: \"ERROR\",\n id: msg.id,\n errorInfo,\n error: {\n message: error.message,\n stack: error.stack,\n name: error.name,\n cause: error.cause,\n },\n } satisfies RscWorkerOutputMessage);\n port.postMessage({\n type: \"RSC_END\",\n id: msg.id,\n } satisfies RscWorkerOutputMessage);\n },\n onData: (data: any) => {\n port.postMessage({\n type: \"RSC_CHUNK\",\n id: msg.id,\n chunk: data,\n } satisfies RscWorkerOutputMessage);\n },\n onEnd: () => {\n port.postMessage({\n type: \"RSC_END\",\n id: msg.id,\n } satisfies RscWorkerOutputMessage);\n },\n onMetrics: (metrics: any) => {\n port.postMessage({\n type: \"RSC_METRICS\",\n id: msg.id,\n metrics,\n } satisfies RscWorkerOutputMessage);\n },\n onHmrAccept: (routes: string[]) => {\n port.postMessage({\n type: \"HMR_ACCEPT\",\n id: (msg as HmrAcceptMessage).id,\n routes: routes,\n });\n },\n onHmrUpdate: (routes: string[]) => {\n port.postMessage({\n type: \"HMR_UPDATE\",\n id: msg.id,\n routes: routes,\n });\n },\n };\n switch (msg.type) {\n case \"RSC_RENDER\":\n return await handleRender(msg, handlers);\n case \"INITIALIZED_REACT_LOADER\":\n return;\n case \"INITIALIZED_CSS_LOADER\":\n return;\n case \"INITIALIZED_ENV_LOADER\":\n return;\n case \"HMR_UPDATE\":\n // Mark the module as invalidated\n hmrState.set(msg.id, {\n timestamp: msg.timestamp || Date.now(),\n invalidated: true,\n routes: msg.routes || [],\n });\n // Notify the main thread that we've processed the update\n handlers.onHmrUpdate(msg.routes || []);\n return;\n case \"HMR_CLEANUP\":\n // Clear the invalidation state\n hmrState.delete(msg.id);\n // Notify the main thread that we've processed the cleanup\n handlers.onHmrAccept(msg.routes || []);\n return;\n case \"CSS_FILE\":\n if (msg.id) {\n const cssOptions = workerData.userOptions.css || {\n inlineThreshold: 1000,\n };\n\n addCssFileContent(msg.id, msg.content, {\n projectRoot: workerData.userOptions.projectRoot || process.cwd(),\n moduleBaseURL: workerData.userOptions.moduleBaseURL || \"/\",\n moduleBasePath: workerData.userOptions.moduleBasePath || \"/\",\n moduleRootPath: workerData.userOptions.moduleRootPath,\n css: cssOptions,\n });\n }\n return;\n case \"SHUTDOWN\": {\n // If id is \"*\", clean up all render states\n if (msg.id === \"*\") {\n activeStreams.forEach((stream, renderId) => {\n stream.end();\n activeStreams.delete(renderId);\n });\n parentPort?.removeAllListeners();\n } else {\n activeStreams.delete(msg.id);\n }\n // Send SHUTDOWN_COMPLETE message to signal that shutdown is complete\n sendMessage({\n type: \"SHUTDOWN_COMPLETE\",\n id: msg.id,\n } satisfies RscWorkerOutputMessage);\n return;\n }\n default: {\n console.log(\"Unknown message\", msg);\n return;\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAWA,eAAsB,cAAA,CACpB,GACA,EAAA,IAAA,GAAO,UACP,EAAA;AACA,EAAA,IAAI,CAAC,IAAM,EAAA;AACT,IAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AAAA;AAEjC,EAAA,MAAM,QAA2B,GAAA;AAAA,IAC/B,OAAA,EAAS,CAAC,KAAA,EAAY,SAAoB,KAAA;AACxC,MAAI,IAAA,EAAE,iBAAiB,KAAQ,CAAA,EAAA;AAC7B,QAAA,KAAA,GAAQ,IAAI,KAAA,CAAM,MAAO,CAAA,KAAK,CAAC,CAAA;AAAA;AAEjC,MAAA,IAAA,CAAK,WAAY,CAAA;AAAA,QACf,IAAM,EAAA,OAAA;AAAA,QACN,IAAI,GAAI,CAAA,EAAA;AAAA,QACR,SAAA;AAAA,QACA,KAAO,EAAA;AAAA,UACL,SAAS,KAAM,CAAA,OAAA;AAAA,UACf,OAAO,KAAM,CAAA,KAAA;AAAA,UACb,MAAM,KAAM,CAAA,IAAA;AAAA,UACZ,OAAO,KAAM,CAAA;AAAA;AACf,OACgC,CAAA;AAClC,MAAA,IAAA,CAAK,WAAY,CAAA;AAAA,QACf,IAAM,EAAA,SAAA;AAAA,QACN,IAAI,GAAI,C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AY,kBAAmB,EAAA;AAAA,OAC1B,MAAA;AACL,QAAc,aAAA,CAAA,MAAA,CAAO,IAAI,EAAE,CAAA;AAAA;AAG7B,MAAY,WAAA,CAAA;AAAA,QACV,IAAM,EAAA,mBAAA;AAAA,QACN,IAAI,GAAI,CAAA;AAAA,OACwB,CAAA;AAClC,MAAA;AAAA;AACF,IACA,SAAS;AACP,MAAQ,OAAA,CAAA,GAAA,CAAI,mBAAmB,GAAG,CAAA;AAClC,MAAA;AAAA;AACF;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"messageHandler.js","sources":["../../../../plugin/worker/rsc/messageHandler.tsx"],"sourcesContent":["import { parentPort, workerData } from \"node:worker_threads\";\nimport {\n activeStreams,\n addCssFileContent,\n hmrState,\n addModuleId,\n} from \"./state.js\";\nimport { handleRender } from \"./handleRender.js\";\nimport type {\n RscWorkerInputMessage,\n StreamHandlers,\n} from \"../types.js\";\nimport { sendRscWorkerMessage } from \"../sendMessage.js\";\nimport { toError } from \"../../error/toError.js\";\n\n// In test mode, we want errors to propagate up immediately\nconst isTestEnv = process.env[\"VITEST\"] || process.env[\"NODE_ENV\"] === \"test\";\nconst isDevEnv = process.env[\"NODE_ENV\"] !== \"production\";\n\nconst handlers: Required<StreamHandlers> = {\n onError: (id, error, errorInfo) => {\n sendRscWorkerMessage({\n type: \"ERROR\",\n id: id,\n errorInfo,\n error: toError(error),\n });\n sendRscWorkerMessage({\n type: \"RSC_END\",\n id: id,\n });\n },\n onData: (id, data: any) => {\n sendRscWorkerMessage({\n type: \"RSC_CHUNK\",\n id: id,\n chunk: data,\n });\n },\n onEnd: (id: string) => {\n sendRscWorkerMessage({\n type: \"RSC_END\",\n id: id,\n });\n },\n onMetrics: (id: string, metrics: any) => {\n sendRscWorkerMessage({\n type: \"RSC_METRICS\",\n id: id,\n metrics,\n });\n },\n onHmrAccept: (id, routes) => {\n sendRscWorkerMessage({\n type: \"HMR_ACCEPT\",\n id: id,\n routes: routes,\n });\n },\n onHmrUpdate: (id, routes) => {\n sendRscWorkerMessage({\n type: \"HMR_UPDATE\",\n id: id,\n routes: routes,\n });\n },\n onServerModule: (id, url, source) => {\n sendRscWorkerMessage({\n type: \"SERVER_MODULE\",\n id,\n url,\n source,\n });\n },\n onServerActionResponse: (id, result, error) => {\n sendRscWorkerMessage({\n type: \"SERVER_ACTION_RESPONSE\",\n id,\n result,\n error,\n });\n },\n onServerAction: async (id, args) => {\n try {\n // Get the server action function from the worker data\n const serverAction = workerData.serverActions?.[id];\n if (!serverAction) {\n throw new Error(`Server action ${id} not found`);\n }\n // Execute the server action\n const result = await serverAction(...args);\n // Send the result back\n sendRscWorkerMessage({\n type: \"SERVER_ACTION_RESPONSE\",\n id,\n result,\n });\n } catch (error) {\n // Send error back\n sendRscWorkerMessage({\n type: \"SERVER_ACTION_RESPONSE\",\n id,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n },\n onShutdown: (id: string) => {\n // Send SHUTDOWN_COMPLETE message to signal that shutdown is complete\n sendRscWorkerMessage({\n type: \"SHUTDOWN_COMPLETE\",\n id: id,\n });\n },\n};\n\nexport async function messageHandler(\n msg: RscWorkerInputMessage,\n port = parentPort\n) {\n try {\n if (!port) {\n throw new Error(\"No port found\");\n }\n switch (msg.type) {\n case \"RSC_RENDER\":\n return await handleRender(msg, handlers);\n case \"SERVER_ACTION\":\n return handlers.onServerAction(msg.id, msg.args);\n case \"INITIALIZED_REACT_LOADER\":\n return;\n case \"INITIALIZED_CSS_LOADER\":\n return;\n case \"INITIALIZED_ENV_LOADER\":\n return;\n case \"HMR_UPDATE\":\n // Mark the module as invalidated\n hmrState.set(msg.id, {\n timestamp: msg.timestamp || Date.now(),\n invalidated: true,\n routes: msg.routes || [],\n });\n // Notify the main thread that we've processed the update\n handlers.onHmrUpdate(msg.id, msg.routes || []);\n return;\n case \"HMR_CLEANUP\":\n // Clear the invalidation state\n hmrState.delete(msg.id);\n // Notify the main thread that we've processed the cleanup\n handlers.onHmrAccept(msg.id, msg.routes || []);\n return;\n case \"CSS_FILE\":\n if (msg.id) {\n const cssOptions = workerData.userOptions.css || {\n inlineThreshold: 1000,\n };\n\n addCssFileContent(msg.id, msg.content, {\n projectRoot: workerData.userOptions.projectRoot || process.cwd(),\n moduleBaseURL: workerData.userOptions.moduleBaseURL || \"/\",\n moduleBasePath: workerData.userOptions.moduleBasePath || \"/\",\n moduleRootPath: workerData.userOptions.moduleRootPath,\n css: cssOptions,\n });\n }\n return;\n case \"SERVER_MODULE\":\n if (msg.id && msg.url) {\n addModuleId(msg.id, msg.url);\n }\n handlers.onServerModule(msg.id, msg.url, msg.source);\n return;\n case \"SHUTDOWN\": {\n // If id is \"*\", clean up all render states\n if (msg.id === \"*\") {\n activeStreams.forEach((stream, renderId) => {\n stream.end();\n activeStreams.delete(renderId);\n });\n parentPort?.removeAllListeners();\n } else {\n activeStreams.delete(msg.id);\n }\n handlers.onShutdown(msg.id);\n return;\n }\n default: {\n console.log(\"Unknown message\", msg);\n return;\n }\n }\n } catch (error) {\n const err = toError(error);\n if (isDevEnv) {\n console.error(err);\n }\n // In dev mode, try to send error message before exiting\n if (parentPort) {\n port?.postMessage({\n type: \"ERROR\",\n id: \"rsc-worker\",\n error: err,\n });\n }\n if (!isDevEnv || isTestEnv) {\n // In test mode or production mode, just throw the error to fail fast\n throw err;\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAgBA,MAAM,SAAA,GAAY,QAAQ,GAAI,CAAA,QAAQ,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAM,KAAA,MAAA;AACvE,MAAM,QAAW,GAAA,OAAA,CAAQ,GAAI,CAAA,UAAU,CAAM,KAAA,YAAA;AAE7C,MAAM,QAAqC,GAAA;AAAA,EACzC,OAAS,EAAA,CAAC,EAAI,EAAA,KAAA,EAAO,SAAc,KAAA;AACjC,IAAqB,oBAAA,CAAA;AAAA,MACnB,IAAM,EAAA,OAAA;AAAA,MACN,EAAA;AAAA,MACA,SAAA;AAAA,MACA,KAAA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}
|
|
@@ -10,65 +10,125 @@ import { register as register$1 } from 'tsx/esm/api';
|
|
|
10
10
|
import { join } from 'node:path';
|
|
11
11
|
import { pluginRoot } from '../../root.js';
|
|
12
12
|
import { deserializeRegExp } from '../../helpers/serializeUserOptions.js';
|
|
13
|
+
import { toError } from '../../error/toError.js';
|
|
13
14
|
|
|
14
15
|
if (!parentPort) {
|
|
15
16
|
throw new Error("This module must be run as a worker");
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.development.js");
|
|
28
|
-
const envLoaderPath = "file://" + join(pluginRoot, "loader/env-loader.development.js");
|
|
29
|
-
register(loaderPath, {
|
|
30
|
-
parentURL: pluginRoot,
|
|
31
|
-
data: { port: reactLoaderChannel.port1 },
|
|
32
|
-
transferList: [reactLoaderChannel.port1]
|
|
33
|
-
});
|
|
34
|
-
register(cssLoaderPath, {
|
|
35
|
-
parentURL: pluginRoot,
|
|
36
|
-
data: { port: cssLoaderChannel.port1, resolvedConfig: workerData.resolvedConfig },
|
|
37
|
-
transferList: [cssLoaderChannel.port1]
|
|
38
|
-
});
|
|
39
|
-
register$1();
|
|
40
|
-
register(envLoaderPath, {
|
|
41
|
-
parentURL: pluginRoot,
|
|
42
|
-
data: { port: envLoaderChannel.port1, resolvedConfig: workerData.resolvedConfig },
|
|
43
|
-
transferList: [envLoaderChannel.port1]
|
|
44
|
-
});
|
|
45
|
-
parentPort.on("message", messageHandler);
|
|
46
|
-
const { hmrPort } = workerData;
|
|
47
|
-
if (hmrPort) {
|
|
48
|
-
hmrPort.start();
|
|
49
|
-
hmrPort.on("message", (message) => {
|
|
50
|
-
if (message.type === "HMR_UPDATE") {
|
|
51
|
-
parentPort.postMessage({
|
|
52
|
-
type: "HMR_UPDATE",
|
|
53
|
-
id: message.id,
|
|
54
|
-
routes: message.routes
|
|
55
|
-
});
|
|
18
|
+
const isTestEnv = process.env["VITEST"] || process.env["NODE_ENV"] === "test";
|
|
19
|
+
const isDevEnv = process.env["NODE_ENV"] !== "production";
|
|
20
|
+
const verbose = workerData.verbose;
|
|
21
|
+
const developmentMessageHandler = (msg) => {
|
|
22
|
+
if (verbose) {
|
|
23
|
+
if ("chunk" in msg) {
|
|
24
|
+
let preview = Buffer.from(msg.chunk).toString("utf-8");
|
|
25
|
+
console.log(`[rsc-worker:${msg.type}] ${preview}`);
|
|
26
|
+
} else {
|
|
27
|
+
console.log(`[rsc-worker:${msg.type}] ${JSON.stringify(msg)}`);
|
|
56
28
|
}
|
|
29
|
+
}
|
|
30
|
+
messageHandler(msg);
|
|
31
|
+
};
|
|
32
|
+
const developmentCssLoaderMessageHandler = (msg) => {
|
|
33
|
+
if (verbose) {
|
|
34
|
+
console.log(`[css-loader:${msg.type}] ${JSON.stringify(msg)}`);
|
|
35
|
+
}
|
|
36
|
+
messageHandler(msg);
|
|
37
|
+
};
|
|
38
|
+
const developmentEnvLoaderMessageHandler = (msg) => {
|
|
39
|
+
if (verbose) {
|
|
40
|
+
console.log(`[env-loader:${msg.type}] ${JSON.stringify(msg)}`);
|
|
41
|
+
}
|
|
42
|
+
messageHandler(msg);
|
|
43
|
+
};
|
|
44
|
+
const developmentReactLoaderMessageHandler = (msg) => {
|
|
45
|
+
if (verbose) {
|
|
46
|
+
console.log(`[react-loader:${msg.type}] ${JSON.stringify(msg)}`);
|
|
47
|
+
}
|
|
48
|
+
messageHandler(msg);
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
if (workerData) {
|
|
52
|
+
workerData.userOptions = deserializeRegExp(workerData.userOptions);
|
|
53
|
+
}
|
|
54
|
+
const reactLoaderChannel = new MessageChannel();
|
|
55
|
+
const cssLoaderChannel = new MessageChannel();
|
|
56
|
+
const envLoaderChannel = new MessageChannel();
|
|
57
|
+
reactLoaderChannel.port1.on("message", developmentReactLoaderMessageHandler);
|
|
58
|
+
cssLoaderChannel.port1.on("message", developmentCssLoaderMessageHandler);
|
|
59
|
+
envLoaderChannel.port1.on("message", developmentEnvLoaderMessageHandler);
|
|
60
|
+
const reactLoaderPath = "file://" + join(pluginRoot, "loader/react-loader.server.js");
|
|
61
|
+
const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.development.js");
|
|
62
|
+
const envLoaderPath = "file://" + join(pluginRoot, "loader/env-loader.development.js");
|
|
63
|
+
register(reactLoaderPath, {
|
|
64
|
+
parentURL: pluginRoot,
|
|
65
|
+
data: {
|
|
66
|
+
id: "react-loader",
|
|
67
|
+
port: reactLoaderChannel.port1,
|
|
68
|
+
userOptions: workerData.userOptions
|
|
69
|
+
},
|
|
70
|
+
transferList: [reactLoaderChannel.port1]
|
|
71
|
+
});
|
|
72
|
+
register(cssLoaderPath, {
|
|
73
|
+
parentURL: pluginRoot,
|
|
74
|
+
data: {
|
|
75
|
+
id: "css-loader",
|
|
76
|
+
port: cssLoaderChannel.port1,
|
|
77
|
+
resolvedConfig: workerData.resolvedConfig
|
|
78
|
+
},
|
|
79
|
+
transferList: [cssLoaderChannel.port1]
|
|
80
|
+
});
|
|
81
|
+
register$1();
|
|
82
|
+
register(envLoaderPath, {
|
|
83
|
+
parentURL: pluginRoot,
|
|
84
|
+
data: {
|
|
85
|
+
port: envLoaderChannel.port1,
|
|
86
|
+
resolvedConfig: workerData.resolvedConfig
|
|
87
|
+
},
|
|
88
|
+
transferList: [envLoaderChannel.port1]
|
|
57
89
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
90
|
+
parentPort.on("message", developmentMessageHandler);
|
|
91
|
+
const { hmrPort } = workerData;
|
|
92
|
+
if (hmrPort) {
|
|
93
|
+
hmrPort.start();
|
|
94
|
+
hmrPort.on("message", (message) => {
|
|
95
|
+
if (message.type === "HMR_UPDATE") {
|
|
96
|
+
parentPort.postMessage({
|
|
97
|
+
type: "HMR_UPDATE",
|
|
98
|
+
id: message.id,
|
|
99
|
+
routes: message.routes
|
|
100
|
+
});
|
|
101
|
+
} else if (message.type === "HMR_ACCEPT") {
|
|
102
|
+
parentPort.postMessage({
|
|
103
|
+
type: "HMR_ACCEPT",
|
|
104
|
+
id: message.id,
|
|
105
|
+
routes: message.routes
|
|
106
|
+
});
|
|
107
|
+
}
|
|
63
108
|
});
|
|
109
|
+
}
|
|
110
|
+
parentPort.postMessage({
|
|
111
|
+
type: "READY",
|
|
112
|
+
env: process.env["NODE_ENV"],
|
|
113
|
+
pid: process.pid,
|
|
114
|
+
id: "rsc-worker"
|
|
64
115
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
116
|
+
if (process.env["NODE_ENV"] === "production") {
|
|
117
|
+
throw new Error("This module should not run in production mode.");
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (isDevEnv) {
|
|
121
|
+
console.error(error);
|
|
122
|
+
}
|
|
123
|
+
if (parentPort) {
|
|
124
|
+
parentPort?.postMessage({
|
|
125
|
+
type: "ERROR",
|
|
126
|
+
id: "rsc-worker",
|
|
127
|
+
error: toError(error)
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (!isDevEnv || isTestEnv) {
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
73
133
|
}
|
|
74
134
|
//# sourceMappingURL=rsc-worker.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc-worker.development.js","sources":["../../../../plugin/worker/rsc/rsc-worker.development.ts"],"sourcesContent":["import { parentPort, MessageChannel, workerData } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\nimport { register } from \"node:module\";\nimport { register as registerTsx } from \"tsx/esm/api\";\nimport { join } from \"node:path\";\nimport { pluginRoot } from \"../../root.js\";\nimport { deserializeRegExp } from \"../../helpers/serializeUserOptions.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"rsc-worker.development.js","sources":["../../../../plugin/worker/rsc/rsc-worker.development.ts"],"sourcesContent":["import { parentPort, MessageChannel, workerData } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\nimport { register } from \"node:module\";\nimport { register as registerTsx } from \"tsx/esm/api\";\nimport { join } from \"node:path\";\nimport { pluginRoot } from \"../../root.js\";\nimport { deserializeRegExp } from \"../../helpers/serializeUserOptions.js\";\nimport type {\n HmrAcceptMessage,\n HmrUpdateMessage,\n ReadyMessage,\n} from \"../types.js\";\nimport { toError } from \"../../error/toError.js\";\n// Initialize worker\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// In test mode, we want errors to propagate up immediately\nconst isTestEnv = process.env[\"VITEST\"] || process.env[\"NODE_ENV\"] === \"test\";\nconst isDevEnv = process.env[\"NODE_ENV\"] !== \"production\";\nconst verbose = workerData.verbose;\n\nconst developmentMessageHandler = (msg: any) => {\n if (verbose) {\n if (\"chunk\" in msg) {\n let preview = Buffer.from(msg.chunk).toString(\"utf-8\");\n console.log(`[rsc-worker:${msg.type}] ${preview}`);\n } else {\n console.log(`[rsc-worker:${msg.type}] ${JSON.stringify(msg)}`);\n }\n }\n messageHandler(msg);\n};\n\nconst developmentCssLoaderMessageHandler = (msg: any) => {\n if (verbose) {\n console.log(`[css-loader:${msg.type}] ${JSON.stringify(msg)}`);\n }\n messageHandler(msg);\n};\n\nconst developmentEnvLoaderMessageHandler = (msg: any) => {\n if (verbose) {\n console.log(`[env-loader:${msg.type}] ${JSON.stringify(msg)}`);\n }\n messageHandler(msg);\n};\n\nconst developmentReactLoaderMessageHandler = (msg: any) => {\n if (verbose) {\n console.log(`[react-loader:${msg.type}] ${JSON.stringify(msg)}`);\n }\n messageHandler(msg);\n};\n\ntry {\n // Deserialize workerData to restore RegExp objects\n if (workerData) {\n workerData.userOptions = deserializeRegExp(workerData.userOptions);\n }\n\n // Create channels for each loader\n const reactLoaderChannel = new MessageChannel();\n const cssLoaderChannel = new MessageChannel();\n const envLoaderChannel = new MessageChannel();\n\n // Set up message handlers before transferring ports\n reactLoaderChannel.port1.on(\"message\", developmentReactLoaderMessageHandler);\n cssLoaderChannel.port1.on(\"message\", developmentCssLoaderMessageHandler);\n envLoaderChannel.port1.on(\"message\", developmentEnvLoaderMessageHandler);\n\n const reactLoaderPath =\n \"file://\" + join(pluginRoot, \"loader/react-loader.server.js\");\n const cssLoaderPath =\n \"file://\" + join(pluginRoot, \"loader/css-loader.development.js\");\n const envLoaderPath =\n \"file://\" + join(pluginRoot, \"loader/env-loader.development.js\");\n\n // Register loaders with their ports\n register(reactLoaderPath, {\n parentURL: pluginRoot,\n data: {\n id: \"react-loader\",\n port: reactLoaderChannel.port1,\n userOptions: workerData.userOptions,\n },\n transferList: [reactLoaderChannel.port1],\n });\n register(cssLoaderPath, {\n parentURL: pluginRoot,\n data: {\n id: \"css-loader\",\n port: cssLoaderChannel.port1,\n resolvedConfig: workerData.resolvedConfig,\n },\n transferList: [cssLoaderChannel.port1],\n });\n\n // Register loaders\n registerTsx();\n\n // Register env-loader (ensure this the last)\n register(envLoaderPath, {\n parentURL: pluginRoot,\n data: {\n port: envLoaderChannel.port1,\n resolvedConfig: workerData.resolvedConfig,\n },\n transferList: [envLoaderChannel.port1],\n });\n\n // Set up message handling\n parentPort!.on(\"message\", developmentMessageHandler);\n\n const { hmrPort } = workerData;\n if (hmrPort) {\n // Start the message port\n hmrPort.start();\n\n // Listen for HMR messages\n hmrPort.on(\"message\", (message: any) => {\n if (message.type === \"HMR_UPDATE\") {\n // Invalidate the module in the worker\n parentPort!.postMessage({\n type: \"HMR_UPDATE\",\n id: message.id,\n routes: message.routes,\n } satisfies HmrUpdateMessage);\n } else if (message.type === \"HMR_ACCEPT\") {\n // Handle the update\n parentPort!.postMessage({\n type: \"HMR_ACCEPT\",\n id: message.id,\n routes: message.routes,\n } satisfies HmrAcceptMessage);\n }\n });\n }\n\n // Notify parent that we're ready\n parentPort!.postMessage({\n type: \"READY\",\n env: process.env[\"NODE_ENV\"],\n pid: process.pid,\n id: \"rsc-worker\",\n } satisfies ReadyMessage);\n\n if (process.env[\"NODE_ENV\"] === \"production\") {\n throw new Error(\"This module should not run in production mode.\");\n }\n} catch (error) {\n if (isDevEnv) {\n console.error(error);\n }\n // In dev mode, try to send error message before exiting\n if (parentPort) {\n parentPort?.postMessage({\n type: \"ERROR\",\n id: \"rsc-worker\",\n error: toError(error),\n });\n }\n if (!isDevEnv || isTestEnv) {\n // In test mode or production mode, just throw the error to fail fast\n throw error;\n }\n}\n"],"names":["registerTsx"],"mappings":";;;;;;;;;;;;;;AAcA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,MAAM,SAAA,GAAY,QAAQ,GAAI,CAAA,QAAQ,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAM,KAAA,MAAA;AACvE,MAAM,QAAW,GAAA,OAAA,CAAQ,GAAI,CAAA,UAAU,CAAM,KAAA,YAAA;AAC7C,MAAM,UAAU,UAAW,CAAA,OAAA;AAE3B,MAAM,yBAAA,GAA4B,CAAC,GAAa,KAAA;AAC9C,EAAA,IAAI,OAAS,EAAA;AACX,IAAA,IAAI,WAAW,GAAK,EAAA;AAClB,MAAA,IAAI,UAAU,MAAO,CAAA,IAAA,CAAK,IAAI,KAAK,CAAA,CAAE,SAAS,OAAO,CAAA;AACrD,MAAA,OAAA,CAAQ,IAAI,CAAe,YAAA,EAAA,GAAA,CAAI,IAAI,CAAA,EAAA,EAAK,OAAO,CAAE,CAAA,CAAA;AAAA,KAC5C,MAAA;AACL,MAAQ,OAAA,CAAA,GAAA,CAAI,eAAe,GAAI,CAAA,IAAI,KAAK,IAAK,CAAA,SAAA,CAAU,GAAG,CAAC,CAAE,CAAA,CAAA;AAAA;AAC/D;AAEF,EAAA,cAAA,CAAe,GAAG,CAAA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,MAAA,KAAA;AAAA;AAEV"}
|
|
@@ -24,5 +24,5 @@ reactLoaderChannel.port2.on("message", messageHandler);
|
|
|
24
24
|
cssLoaderChannel.port2.on("message", messageHandler);
|
|
25
25
|
envLoaderChannel.port2.on("message", messageHandler);
|
|
26
26
|
parentPort.on("message", messageHandler);
|
|
27
|
-
parentPort.postMessage({ type: "READY", env: process.env["NODE_ENV"], pid: process.pid });
|
|
27
|
+
parentPort.postMessage({ type: "READY", id: "rsc-worker", env: process.env["NODE_ENV"], pid: process.pid });
|
|
28
28
|
//# sourceMappingURL=rsc-worker.production.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc-worker.production.js","sources":["../../../../plugin/worker/rsc/rsc-worker.production.ts"],"sourcesContent":["import { parentPort, MessageChannel } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\nimport { register } from \"node:module\";\nimport { join } from \"node:path\";\nimport { pluginRoot } from \"../../root.js\";\nimport type { ReadyMessage } from \"../types.js\";\n\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// Create channels for each loader\nconst reactLoaderChannel = new MessageChannel();\nconst cssLoaderChannel = new MessageChannel();\nconst envLoaderChannel = new MessageChannel();\n\n// Register loaders\nregister(join(pluginRoot, \"worker/env-loader.js\"), {\n parentURL: import.meta.url,\n data: { port: envLoaderChannel.port2 },\n transferList: [envLoaderChannel.port2],\n});\n\n// Listen for messages from loaders\nreactLoaderChannel.port2.on(\"message\", messageHandler);\ncssLoaderChannel.port2.on(\"message\", messageHandler);\nenvLoaderChannel.port2.on(\"message\", messageHandler);\n\n// Handle incoming messages\nparentPort.on(\"message\", messageHandler);\n\n// Signal ready\nparentPort.postMessage({ type: \"READY\", env: process.env[\"NODE_ENV\"], pid: process.pid } satisfies ReadyMessage);\n"],"names":[],"mappings":";;;;;;;;;;;AAOA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,MAAM,kBAAA,GAAqB,IAAI,cAAe,EAAA;AAC9C,MAAM,gBAAA,GAAmB,IAAI,cAAe,EAAA;AAC5C,MAAM,gBAAA,GAAmB,IAAI,cAAe,EAAA;AAG5C,QAAS,CAAA,IAAA,CAAK,UAAY,EAAA,sBAAsB,CAAG,EAAA;AAAA,EACjD,WAAW,MAAY,CAAA,IAAA,CAAA,GAAA;AAAA,EACvB,IAAM,EAAA,EAAE,IAAM,EAAA,gBAAA,CAAiB,KAAM,EAAA;AAAA,EACrC,YAAA,EAAc,CAAC,gBAAA,CAAiB,KAAK;AACvC,CAAC,CAAA;AAGD,kBAAmB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AACrD,gBAAiB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AACnD,gBAAiB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AAGnD,UAAW,CAAA,EAAA,CAAG,WAAW,cAAc,CAAA;AAGvC,UAAA,CAAW,WAAY,CAAA,EAAE,IAAM,EAAA,OAAA,EAAS,
|
|
1
|
+
{"version":3,"file":"rsc-worker.production.js","sources":["../../../../plugin/worker/rsc/rsc-worker.production.ts"],"sourcesContent":["import { parentPort, MessageChannel } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\nimport { register } from \"node:module\";\nimport { join } from \"node:path\";\nimport { pluginRoot } from \"../../root.js\";\nimport type { ReadyMessage } from \"../types.js\";\n\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// Create channels for each loader\nconst reactLoaderChannel = new MessageChannel();\nconst cssLoaderChannel = new MessageChannel();\nconst envLoaderChannel = new MessageChannel();\n\n// Register loaders\nregister(join(pluginRoot, \"worker/env-loader.js\"), {\n parentURL: import.meta.url,\n data: { port: envLoaderChannel.port2 },\n transferList: [envLoaderChannel.port2],\n});\n\n// Listen for messages from loaders\nreactLoaderChannel.port2.on(\"message\", messageHandler);\ncssLoaderChannel.port2.on(\"message\", messageHandler);\nenvLoaderChannel.port2.on(\"message\", messageHandler);\n\n// Handle incoming messages\nparentPort.on(\"message\", messageHandler);\n\n// Signal ready\nparentPort.postMessage({ type: \"READY\", id: \"rsc-worker\", env: process.env[\"NODE_ENV\"], pid: process.pid } satisfies ReadyMessage);\n"],"names":[],"mappings":";;;;;;;;;;;AAOA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,MAAM,kBAAA,GAAqB,IAAI,cAAe,EAAA;AAC9C,MAAM,gBAAA,GAAmB,IAAI,cAAe,EAAA;AAC5C,MAAM,gBAAA,GAAmB,IAAI,cAAe,EAAA;AAG5C,QAAS,CAAA,IAAA,CAAK,UAAY,EAAA,sBAAsB,CAAG,EAAA;AAAA,EACjD,WAAW,MAAY,CAAA,IAAA,CAAA,GAAA;AAAA,EACvB,IAAM,EAAA,EAAE,IAAM,EAAA,gBAAA,CAAiB,KAAM,EAAA;AAAA,EACrC,YAAA,EAAc,CAAC,gBAAA,CAAiB,KAAK;AACvC,CAAC,CAAA;AAGD,kBAAmB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AACrD,gBAAiB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AACnD,gBAAiB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AAGnD,UAAW,CAAA,EAAA,CAAG,WAAW,cAAc,CAAA;AAGvC,UAAA,CAAW,WAAY,CAAA,EAAE,IAAM,EAAA,OAAA,EAAS,IAAI,YAAc,EAAA,GAAA,EAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,EAAG,GAAK,EAAA,OAAA,CAAQ,KAA4B,CAAA"}
|