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
|
@@ -3,693 +3,11 @@
|
|
|
3
3
|
* Copyright (c) Nico Brinkkemper
|
|
4
4
|
* MIT License
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
7
|
-
import { basename } from 'path';
|
|
8
|
-
import { setSourceMapsSupport, SourceMap } from 'node:module';
|
|
9
|
-
import { env } from '../utils/env.js';
|
|
6
|
+
import { getCondition } from '../config/getCondition.js';
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// Enable for node_modules files
|
|
15
|
-
generatedCode: true
|
|
16
|
-
// Enable for generated code
|
|
17
|
-
});
|
|
18
|
-
let loaderPort;
|
|
19
|
-
let isDev = process.env["NODE_ENV"] === "development";
|
|
20
|
-
async function getSource(url, context, defaultGetSource) {
|
|
21
|
-
stashedGetSource = defaultGetSource;
|
|
22
|
-
return defaultGetSource(url, context, defaultGetSource);
|
|
23
|
-
}
|
|
24
|
-
function addExportedEntry(exportedEntries, localNames, localName, exportedName, type, loc) {
|
|
25
|
-
if (localNames.has(localName)) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
exportedEntries.push({
|
|
29
|
-
localName,
|
|
30
|
-
exportedName,
|
|
31
|
-
type,
|
|
32
|
-
loc,
|
|
33
|
-
originalLine: -1,
|
|
34
|
-
originalColumn: -1,
|
|
35
|
-
originalSource: -1,
|
|
36
|
-
nameIndex: -1
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function addLocalExportedNames(exportedEntries, localNames, node) {
|
|
40
|
-
switch (node.type) {
|
|
41
|
-
case "Identifier":
|
|
42
|
-
addExportedEntry(
|
|
43
|
-
exportedEntries,
|
|
44
|
-
localNames,
|
|
45
|
-
node.name,
|
|
46
|
-
node.name,
|
|
47
|
-
null,
|
|
48
|
-
node.loc
|
|
49
|
-
);
|
|
50
|
-
return;
|
|
51
|
-
case "ObjectPattern":
|
|
52
|
-
for (let i = 0; i < node.properties.length; i++)
|
|
53
|
-
addLocalExportedNames(exportedEntries, localNames, node.properties[i]);
|
|
54
|
-
return;
|
|
55
|
-
case "ArrayPattern":
|
|
56
|
-
for (let i = 0; i < node.elements.length; i++) {
|
|
57
|
-
const element = node.elements[i];
|
|
58
|
-
if (element)
|
|
59
|
-
addLocalExportedNames(exportedEntries, localNames, element);
|
|
60
|
-
}
|
|
61
|
-
return;
|
|
62
|
-
case "Property":
|
|
63
|
-
addLocalExportedNames(exportedEntries, localNames, node.value);
|
|
64
|
-
return;
|
|
65
|
-
case "AssignmentPattern":
|
|
66
|
-
addLocalExportedNames(exportedEntries, localNames, node.left);
|
|
67
|
-
return;
|
|
68
|
-
case "RestElement":
|
|
69
|
-
addLocalExportedNames(exportedEntries, localNames, node.argument);
|
|
70
|
-
return;
|
|
71
|
-
case "ParenthesizedExpression":
|
|
72
|
-
addLocalExportedNames(exportedEntries, localNames, node.expression);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function transformServerModule(source, program, url, sourceMap, _loader, port) {
|
|
77
|
-
const body = program.body;
|
|
78
|
-
const exportedEntries = [];
|
|
79
|
-
const localNames = /* @__PURE__ */ new Set();
|
|
80
|
-
for (let i = 0; i < body.length; i++) {
|
|
81
|
-
const node = body[i];
|
|
82
|
-
switch (node.type) {
|
|
83
|
-
case "ExportAllDeclaration":
|
|
84
|
-
break;
|
|
85
|
-
case "ExportDefaultDeclaration":
|
|
86
|
-
if (node.declaration.type === "Identifier") {
|
|
87
|
-
addExportedEntry(
|
|
88
|
-
exportedEntries,
|
|
89
|
-
localNames,
|
|
90
|
-
node.declaration.name,
|
|
91
|
-
"default",
|
|
92
|
-
null,
|
|
93
|
-
node.declaration.loc
|
|
94
|
-
);
|
|
95
|
-
} else if (node.declaration.type === "FunctionDeclaration") {
|
|
96
|
-
if (node.declaration.id) {
|
|
97
|
-
addExportedEntry(
|
|
98
|
-
exportedEntries,
|
|
99
|
-
localNames,
|
|
100
|
-
node.declaration.id.name,
|
|
101
|
-
"default",
|
|
102
|
-
"function",
|
|
103
|
-
node.declaration.id.loc
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
continue;
|
|
108
|
-
case "ExportNamedDeclaration":
|
|
109
|
-
if (node.declaration) {
|
|
110
|
-
if (node.declaration.type === "VariableDeclaration") {
|
|
111
|
-
const declarations = node.declaration.declarations;
|
|
112
|
-
for (let j = 0; j < declarations.length; j++) {
|
|
113
|
-
addLocalExportedNames(
|
|
114
|
-
exportedEntries,
|
|
115
|
-
localNames,
|
|
116
|
-
declarations[j].id
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
const name = node.declaration.id.name;
|
|
121
|
-
addExportedEntry(
|
|
122
|
-
exportedEntries,
|
|
123
|
-
localNames,
|
|
124
|
-
name,
|
|
125
|
-
name,
|
|
126
|
-
node.declaration.type === "FunctionDeclaration" ? "function" : null,
|
|
127
|
-
node.declaration.id.loc
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (node.specifiers) {
|
|
132
|
-
const specifiers = node.specifiers;
|
|
133
|
-
for (let j = 0; j < specifiers.length; j++) {
|
|
134
|
-
const specifier = specifiers[j];
|
|
135
|
-
addExportedEntry(
|
|
136
|
-
exportedEntries,
|
|
137
|
-
localNames,
|
|
138
|
-
specifier.local.name,
|
|
139
|
-
specifier.exported.name,
|
|
140
|
-
null,
|
|
141
|
-
specifier.local.loc
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
let mappings = sourceMap && typeof sourceMap.mappings === "string" ? sourceMap.mappings : "";
|
|
149
|
-
let newSrc = source;
|
|
150
|
-
if (exportedEntries.length > 0) {
|
|
151
|
-
let lastSourceIndex = 0;
|
|
152
|
-
let lastOriginalLine = 0;
|
|
153
|
-
let lastOriginalColumn = 0;
|
|
154
|
-
let lastNameIndex = 0;
|
|
155
|
-
let sourceLineCount = 0;
|
|
156
|
-
let lastMappedLine = 0;
|
|
157
|
-
if (sourceMap) {
|
|
158
|
-
let nextEntryIdx = 0;
|
|
159
|
-
let nextEntryLine = exportedEntries[nextEntryIdx].loc.start.line;
|
|
160
|
-
let nextEntryColumn = exportedEntries[nextEntryIdx].loc.start.column;
|
|
161
|
-
readMappings(
|
|
162
|
-
mappings,
|
|
163
|
-
(generatedLine2, generatedColumn, sourceIndex, originalLine, originalColumn, nameIndex) => {
|
|
164
|
-
if (generatedLine2 > nextEntryLine || generatedLine2 === nextEntryLine && generatedColumn > nextEntryColumn) {
|
|
165
|
-
if (lastMappedLine === nextEntryLine) {
|
|
166
|
-
exportedEntries[nextEntryIdx].originalLine = lastOriginalLine;
|
|
167
|
-
exportedEntries[nextEntryIdx].originalColumn = lastOriginalColumn;
|
|
168
|
-
exportedEntries[nextEntryIdx].originalSource = lastSourceIndex;
|
|
169
|
-
exportedEntries[nextEntryIdx].nameIndex = lastNameIndex;
|
|
170
|
-
}
|
|
171
|
-
nextEntryIdx++;
|
|
172
|
-
if (nextEntryIdx < exportedEntries.length) {
|
|
173
|
-
nextEntryLine = exportedEntries[nextEntryIdx].loc.start.line;
|
|
174
|
-
nextEntryColumn = exportedEntries[nextEntryIdx].loc.start.column;
|
|
175
|
-
} else {
|
|
176
|
-
nextEntryLine = -1;
|
|
177
|
-
nextEntryColumn = -1;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
lastMappedLine = generatedLine2;
|
|
181
|
-
if (sourceIndex > -1) {
|
|
182
|
-
lastSourceIndex = sourceIndex;
|
|
183
|
-
}
|
|
184
|
-
if (originalLine > -1) {
|
|
185
|
-
lastOriginalLine = originalLine;
|
|
186
|
-
}
|
|
187
|
-
if (originalColumn > -1) {
|
|
188
|
-
lastOriginalColumn = originalColumn;
|
|
189
|
-
}
|
|
190
|
-
if (nameIndex > -1) {
|
|
191
|
-
lastNameIndex = nameIndex;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
if (nextEntryIdx < exportedEntries.length) {
|
|
196
|
-
if (lastMappedLine === nextEntryLine) {
|
|
197
|
-
exportedEntries[nextEntryIdx].originalLine = lastOriginalLine;
|
|
198
|
-
exportedEntries[nextEntryIdx].originalColumn = lastOriginalColumn;
|
|
199
|
-
exportedEntries[nextEntryIdx].originalSource = lastSourceIndex;
|
|
200
|
-
exportedEntries[nextEntryIdx].nameIndex = lastNameIndex;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
for (let lastIdx = mappings.length - 1; lastIdx >= 0 && mappings[lastIdx] === ";"; lastIdx--) {
|
|
204
|
-
lastMappedLine++;
|
|
205
|
-
}
|
|
206
|
-
sourceLineCount = program.loc.end.line;
|
|
207
|
-
if (sourceLineCount < lastMappedLine) {
|
|
208
|
-
throw new Error(
|
|
209
|
-
"The source map has more mappings than there are lines."
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
for (let extraLines = sourceLineCount - lastMappedLine; extraLines > 0; extraLines--) {
|
|
213
|
-
mappings += ";";
|
|
214
|
-
}
|
|
215
|
-
} else {
|
|
216
|
-
sourceLineCount = 1;
|
|
217
|
-
let idx = -1;
|
|
218
|
-
while ((idx = source.indexOf("\n", idx + 1)) !== -1) {
|
|
219
|
-
sourceLineCount++;
|
|
220
|
-
}
|
|
221
|
-
mappings = "AAAA" + ";AACA".repeat(sourceLineCount - 1);
|
|
222
|
-
sourceMap = new SourceMap({
|
|
223
|
-
version: 3,
|
|
224
|
-
file: basename(url),
|
|
225
|
-
sources: [url],
|
|
226
|
-
sourcesContent: [source],
|
|
227
|
-
names: [],
|
|
228
|
-
mappings,
|
|
229
|
-
sourceRoot: ""
|
|
230
|
-
});
|
|
231
|
-
lastSourceIndex = 0;
|
|
232
|
-
lastOriginalLine = sourceLineCount;
|
|
233
|
-
lastOriginalColumn = 0;
|
|
234
|
-
lastNameIndex = -1;
|
|
235
|
-
lastMappedLine = sourceLineCount;
|
|
236
|
-
for (let i = 0; i < exportedEntries.length; i++) {
|
|
237
|
-
const entry = exportedEntries[i];
|
|
238
|
-
entry.originalSource = 0;
|
|
239
|
-
entry.originalLine = entry.loc.start.line;
|
|
240
|
-
entry.originalColumn = 0;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
newSrc = "";
|
|
244
|
-
newSrc += `import ReactDOMServerESM from "react-server-dom-esm/server${isDev ? ".node" : ""}";
|
|
245
|
-
`;
|
|
246
|
-
newSrc += `if(ReactDOMServerESM instanceof Error){ throw ReactDOMServerESM; }`;
|
|
247
|
-
newSrc += `export const registerServerReference = ReactDOMServerESM.registerServerReference;
|
|
248
|
-
`;
|
|
249
|
-
if (mappings) {
|
|
250
|
-
mappings += ";;";
|
|
251
|
-
}
|
|
252
|
-
const createMapping = createMappingsSerializer();
|
|
253
|
-
let generatedLine = 1;
|
|
254
|
-
createMapping(
|
|
255
|
-
generatedLine,
|
|
256
|
-
0,
|
|
257
|
-
lastSourceIndex,
|
|
258
|
-
lastOriginalLine,
|
|
259
|
-
lastOriginalColumn,
|
|
260
|
-
lastNameIndex
|
|
261
|
-
);
|
|
262
|
-
for (let i = 0; i < exportedEntries.length; i++) {
|
|
263
|
-
const entry = exportedEntries[i];
|
|
264
|
-
generatedLine++;
|
|
265
|
-
if (entry.type !== "function") {
|
|
266
|
-
newSrc += "if (typeof " + entry.localName + ' === "function") ';
|
|
267
|
-
}
|
|
268
|
-
newSrc += "registerServerReference(" + entry.localName + ",";
|
|
269
|
-
newSrc += JSON.stringify(url) + ",";
|
|
270
|
-
newSrc += JSON.stringify(entry.exportedName) + ");\n";
|
|
271
|
-
mappings += createMapping(
|
|
272
|
-
generatedLine,
|
|
273
|
-
0,
|
|
274
|
-
entry.originalSource,
|
|
275
|
-
entry.originalLine,
|
|
276
|
-
entry.originalColumn,
|
|
277
|
-
entry.nameIndex
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
if (sourceMap) {
|
|
282
|
-
sourceMap.mappings = mappings;
|
|
283
|
-
newSrc += "//# sourceMappingURL=data:application/json;charset=utf-8;base64," + Buffer.from(JSON.stringify(sourceMap)).toString("base64");
|
|
284
|
-
}
|
|
285
|
-
if (port) {
|
|
286
|
-
port.postMessage({
|
|
287
|
-
type: "SERVER_MODULE",
|
|
288
|
-
url,
|
|
289
|
-
source: newSrc
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
return newSrc;
|
|
293
|
-
}
|
|
294
|
-
function addExportNames(names, node) {
|
|
295
|
-
switch (node.type) {
|
|
296
|
-
case "Identifier":
|
|
297
|
-
names.push(node.name);
|
|
298
|
-
return;
|
|
299
|
-
case "ObjectPattern":
|
|
300
|
-
for (let i = 0; i < node.properties.length; i++)
|
|
301
|
-
addExportNames(names, node.properties[i]);
|
|
302
|
-
return;
|
|
303
|
-
case "ArrayPattern":
|
|
304
|
-
for (let i = 0; i < node.elements.length; i++) {
|
|
305
|
-
const element = node.elements[i];
|
|
306
|
-
if (element) addExportNames(names, element);
|
|
307
|
-
}
|
|
308
|
-
return;
|
|
309
|
-
case "Property":
|
|
310
|
-
addExportNames(names, node.value);
|
|
311
|
-
return;
|
|
312
|
-
case "AssignmentPattern":
|
|
313
|
-
addExportNames(names, node.left);
|
|
314
|
-
return;
|
|
315
|
-
case "RestElement":
|
|
316
|
-
addExportNames(names, node.argument);
|
|
317
|
-
return;
|
|
318
|
-
case "ParenthesizedExpression":
|
|
319
|
-
addExportNames(names, node.expression);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
function resolveClientImport(specifier, parentURL) {
|
|
324
|
-
{
|
|
325
|
-
throw new Error(
|
|
326
|
-
"Expected resolve to have been called before transformSource"
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
async function parseExportNamesInto(body, names, parentURL, loader) {
|
|
331
|
-
for (let i = 0; i < body.length; i++) {
|
|
332
|
-
const node = body[i];
|
|
333
|
-
switch (node.type) {
|
|
334
|
-
case "ExportAllDeclaration":
|
|
335
|
-
if (node.exported) {
|
|
336
|
-
addExportNames(names, node.exported);
|
|
337
|
-
continue;
|
|
338
|
-
} else {
|
|
339
|
-
const _await$resolveClientI = await resolveClientImport(
|
|
340
|
-
node.source.value), url = _await$resolveClientI.url;
|
|
341
|
-
const _await$loader = await loader(
|
|
342
|
-
url,
|
|
343
|
-
{
|
|
344
|
-
format: "module",
|
|
345
|
-
conditions: [],
|
|
346
|
-
importAttributes: {}
|
|
347
|
-
},
|
|
348
|
-
loader
|
|
349
|
-
), source = _await$loader.source;
|
|
350
|
-
if (typeof source !== "string") {
|
|
351
|
-
throw new Error("Expected the transformed source to be a string.");
|
|
352
|
-
}
|
|
353
|
-
let childBody;
|
|
354
|
-
try {
|
|
355
|
-
childBody = acorn.parse(source, {
|
|
356
|
-
ecmaVersion: "2024",
|
|
357
|
-
sourceType: "module"
|
|
358
|
-
}).body;
|
|
359
|
-
} catch (x) {
|
|
360
|
-
console.error("Error parsing %s %s", url, x?.message);
|
|
361
|
-
continue;
|
|
362
|
-
}
|
|
363
|
-
await parseExportNamesInto(childBody, names, url, loader);
|
|
364
|
-
continue;
|
|
365
|
-
}
|
|
366
|
-
case "ExportDefaultDeclaration":
|
|
367
|
-
names.push("default");
|
|
368
|
-
continue;
|
|
369
|
-
case "ExportNamedDeclaration":
|
|
370
|
-
if (node.declaration) {
|
|
371
|
-
if (node.declaration.type === "VariableDeclaration") {
|
|
372
|
-
const declarations = node.declaration.declarations;
|
|
373
|
-
for (let j = 0; j < declarations.length; j++) {
|
|
374
|
-
addExportNames(names, declarations[j].id);
|
|
375
|
-
}
|
|
376
|
-
} else {
|
|
377
|
-
addExportNames(names, node.declaration.id);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
if (node.specifiers) {
|
|
381
|
-
const specifiers = node.specifiers;
|
|
382
|
-
for (let j = 0; j < specifiers.length; j++) {
|
|
383
|
-
addExportNames(names, specifiers[j].exported);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
continue;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
async function transformClientModule(program, url, sourceMap, loader) {
|
|
391
|
-
const body = program.body;
|
|
392
|
-
const names = [];
|
|
393
|
-
await parseExportNamesInto(body, names, url, loader);
|
|
394
|
-
if (names.length === 0) {
|
|
395
|
-
return null;
|
|
396
|
-
}
|
|
397
|
-
let newSrc = `import ReactDOMServerESM from "react-server-dom-esm/server${isDev ? ".node" : ""}";
|
|
398
|
-
`;
|
|
399
|
-
newSrc += `if(ReactDOMServerESM instanceof Error){ throw new Error(ReactDOMServerESM); }`;
|
|
400
|
-
newSrc += `export const registerClientReference = ReactDOMServerESM.registerClientReference;
|
|
401
|
-
`;
|
|
402
|
-
for (let i = 0; i < names.length; i++) {
|
|
403
|
-
const name = names[i];
|
|
404
|
-
const errorMessage = name === "default" ? `Attempted to call the default export of ${url} from the server but it's on the client` : `Attempted to call ${name}() from the server but ${name} is on the client`;
|
|
405
|
-
const fullError = `${errorMessage}. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.`;
|
|
406
|
-
const browserUrl = url.replace("file://", "").replace(process.cwd(), "");
|
|
407
|
-
if (name === "default") {
|
|
408
|
-
newSrc += `export default registerClientReference(function() { throw new Error(${JSON.stringify(
|
|
409
|
-
fullError
|
|
410
|
-
)}); }, ${JSON.stringify(browserUrl)}, ${JSON.stringify(name)});
|
|
411
|
-
`;
|
|
412
|
-
} else {
|
|
413
|
-
newSrc += `export const ${name} = registerClientReference(function() { throw new Error(${JSON.stringify(
|
|
414
|
-
fullError
|
|
415
|
-
)}); }, ${JSON.stringify(browserUrl)}, ${JSON.stringify(name)});
|
|
416
|
-
`;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
return newSrc;
|
|
420
|
-
}
|
|
421
|
-
async function loadClientImport(url, defaultTransformSource) {
|
|
422
|
-
if (stashedGetSource === null) {
|
|
423
|
-
throw new Error(
|
|
424
|
-
"Expected getSource to have been called before transformSource"
|
|
425
|
-
);
|
|
426
|
-
}
|
|
427
|
-
const _await$stashedGetSour = await stashedGetSource(
|
|
428
|
-
url,
|
|
429
|
-
{
|
|
430
|
-
format: "module"
|
|
431
|
-
},
|
|
432
|
-
stashedGetSource
|
|
433
|
-
), source = _await$stashedGetSour.source;
|
|
434
|
-
const result = await defaultTransformSource(
|
|
435
|
-
source,
|
|
436
|
-
{
|
|
437
|
-
format: "module",
|
|
438
|
-
url
|
|
439
|
-
},
|
|
440
|
-
defaultTransformSource
|
|
441
|
-
);
|
|
442
|
-
return {
|
|
443
|
-
format: "module",
|
|
444
|
-
source: result.source
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
async function transformModuleIfNeeded(source, url, loader, port) {
|
|
448
|
-
if (source.indexOf("use client") === -1 && source.indexOf("use server") === -1) {
|
|
449
|
-
return source;
|
|
450
|
-
}
|
|
451
|
-
let program;
|
|
452
|
-
try {
|
|
453
|
-
program = acorn.parse(source, {
|
|
454
|
-
ecmaVersion: "2024",
|
|
455
|
-
sourceType: "module",
|
|
456
|
-
locations: true
|
|
457
|
-
});
|
|
458
|
-
} catch (x) {
|
|
459
|
-
console.error(
|
|
460
|
-
"[react-loader] Error parsing %s: %s",
|
|
461
|
-
url,
|
|
462
|
-
x?.message
|
|
463
|
-
);
|
|
464
|
-
return source;
|
|
465
|
-
}
|
|
466
|
-
let useClient = false;
|
|
467
|
-
let useServer = false;
|
|
468
|
-
for (const node of program.body) {
|
|
469
|
-
if (node.type !== "ExpressionStatement" || !node.directive) continue;
|
|
470
|
-
if (node.directive === "use client") {
|
|
471
|
-
useClient = true;
|
|
472
|
-
break;
|
|
473
|
-
}
|
|
474
|
-
if (node.directive === "use server") {
|
|
475
|
-
useServer = true;
|
|
476
|
-
break;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
if (useClient && useServer) {
|
|
480
|
-
throw new Error(
|
|
481
|
-
"Cannot use both use client and use server directives in the same module"
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
if (!useClient && !useServer) {
|
|
485
|
-
return source;
|
|
486
|
-
}
|
|
487
|
-
if (useClient) {
|
|
488
|
-
return transformClientModule(program, url, undefined, loader);
|
|
489
|
-
}
|
|
490
|
-
return transformServerModule(source, program, url, undefined, loader, port);
|
|
491
|
-
}
|
|
492
|
-
function readMappings(mappings, callback) {
|
|
493
|
-
let line = 1;
|
|
494
|
-
let column = 0;
|
|
495
|
-
let sourceIndex = 0;
|
|
496
|
-
let originalLine = 0;
|
|
497
|
-
let originalColumn = 0;
|
|
498
|
-
let nameIndex = 0;
|
|
499
|
-
let index = 0;
|
|
500
|
-
while (index < mappings.length) {
|
|
501
|
-
if (mappings[index] === ";") {
|
|
502
|
-
line++;
|
|
503
|
-
column = 0;
|
|
504
|
-
index++;
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
507
|
-
if (mappings[index] === ",") {
|
|
508
|
-
index++;
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
let [
|
|
512
|
-
generatedColumnDelta = 0,
|
|
513
|
-
sourceIndexDelta = 0,
|
|
514
|
-
originalLineDelta = 0,
|
|
515
|
-
originalColumnDelta = 0,
|
|
516
|
-
nameIndexDelta = 0
|
|
517
|
-
] = decodeVLQ(mappings.slice(index));
|
|
518
|
-
column += generatedColumnDelta;
|
|
519
|
-
sourceIndex += sourceIndexDelta;
|
|
520
|
-
originalLine += originalLineDelta;
|
|
521
|
-
originalColumn += originalColumnDelta;
|
|
522
|
-
nameIndex += nameIndexDelta;
|
|
523
|
-
while (index < mappings.length && !/[,;]/.test(mappings[index])) {
|
|
524
|
-
index++;
|
|
525
|
-
}
|
|
526
|
-
callback(
|
|
527
|
-
line,
|
|
528
|
-
column,
|
|
529
|
-
sourceIndex,
|
|
530
|
-
originalLine,
|
|
531
|
-
originalColumn,
|
|
532
|
-
nameIndex
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
function createMappingsSerializer() {
|
|
537
|
-
let previousGeneratedLine = 1;
|
|
538
|
-
let previousGeneratedColumn = 0;
|
|
539
|
-
let previousOriginalFile = 0;
|
|
540
|
-
let previousOriginalLine = 0;
|
|
541
|
-
let previousOriginalColumn = 0;
|
|
542
|
-
let previousNameIndex = 0;
|
|
543
|
-
return function(generatedLine, generatedColumn, originalFile, originalLine, originalColumn, nameIndex) {
|
|
544
|
-
if (generatedLine > previousGeneratedLine) {
|
|
545
|
-
previousGeneratedColumn = 0;
|
|
546
|
-
let lines = "";
|
|
547
|
-
for (let i = previousGeneratedLine; i < generatedLine; i++) {
|
|
548
|
-
lines += ";";
|
|
549
|
-
}
|
|
550
|
-
previousGeneratedLine = generatedLine;
|
|
551
|
-
if (lines) return lines;
|
|
552
|
-
}
|
|
553
|
-
const segment = [
|
|
554
|
-
generatedColumn - previousGeneratedColumn,
|
|
555
|
-
originalFile - previousOriginalFile,
|
|
556
|
-
originalLine - previousOriginalLine,
|
|
557
|
-
originalColumn - previousOriginalColumn
|
|
558
|
-
];
|
|
559
|
-
if (nameIndex >= 0) {
|
|
560
|
-
segment.push(nameIndex - previousNameIndex);
|
|
561
|
-
}
|
|
562
|
-
previousGeneratedColumn = generatedColumn;
|
|
563
|
-
previousOriginalFile = originalFile;
|
|
564
|
-
previousOriginalLine = originalLine;
|
|
565
|
-
previousOriginalColumn = originalColumn;
|
|
566
|
-
previousNameIndex = nameIndex;
|
|
567
|
-
return encodeVLQ(segment) + ",";
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
const VLQ_SHIFT = 5;
|
|
571
|
-
const VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
|
|
572
|
-
const VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
|
|
573
|
-
const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
574
|
-
function encodeVLQ(numbers) {
|
|
575
|
-
return numbers.map((num) => {
|
|
576
|
-
const vlq = num < 0 ? -num << 1 | 1 : num << 1;
|
|
577
|
-
let result = "";
|
|
578
|
-
let value = vlq;
|
|
579
|
-
do {
|
|
580
|
-
let digit = value & VLQ_VALUE_MASK;
|
|
581
|
-
value >>>= VLQ_SHIFT;
|
|
582
|
-
if (value > 0) {
|
|
583
|
-
digit |= VLQ_CONTINUATION_BIT;
|
|
584
|
-
}
|
|
585
|
-
result += BASE64_CHARS[digit];
|
|
586
|
-
} while (value > 0);
|
|
587
|
-
return result;
|
|
588
|
-
}).join("");
|
|
589
|
-
}
|
|
590
|
-
function decodeVLQ(str) {
|
|
591
|
-
const numbers = [];
|
|
592
|
-
let value = 0;
|
|
593
|
-
let shift = 0;
|
|
594
|
-
let index = 0;
|
|
595
|
-
while (index < str.length && !/[,;]/.test(str[index])) {
|
|
596
|
-
const digit = BASE64_CHARS.indexOf(str[index]);
|
|
597
|
-
if (digit === -1) break;
|
|
598
|
-
value += (digit & VLQ_VALUE_MASK) << shift;
|
|
599
|
-
if ((digit & VLQ_CONTINUATION_BIT) === 0) {
|
|
600
|
-
const negate = value & 1;
|
|
601
|
-
value >>>= 1;
|
|
602
|
-
numbers.push(negate ? -value : value);
|
|
603
|
-
value = shift = 0;
|
|
604
|
-
} else {
|
|
605
|
-
shift += VLQ_SHIFT;
|
|
606
|
-
}
|
|
607
|
-
index++;
|
|
608
|
-
}
|
|
609
|
-
return numbers;
|
|
610
|
-
}
|
|
611
|
-
async function initialize(data) {
|
|
612
|
-
loaderPort = data.port;
|
|
613
|
-
data.port.postMessage({ type: "INITIALIZED_REACT_LOADER" });
|
|
614
|
-
data.port.unref();
|
|
615
|
-
}
|
|
616
|
-
async function resolve(specifier, context, nextResolve) {
|
|
617
|
-
return nextResolve(specifier, context);
|
|
618
|
-
}
|
|
619
|
-
async function load(url, context, nextLoad) {
|
|
620
|
-
const result = await nextLoad(url, {
|
|
621
|
-
...context,
|
|
622
|
-
env
|
|
623
|
-
});
|
|
624
|
-
if (result.format !== "module") {
|
|
625
|
-
return result;
|
|
626
|
-
}
|
|
627
|
-
let sourceStr;
|
|
628
|
-
if (typeof result.source === "string") {
|
|
629
|
-
sourceStr = result.source;
|
|
630
|
-
} else if (result.source instanceof Uint8Array || Buffer.isBuffer(result.source)) {
|
|
631
|
-
sourceStr = result.source.toString("utf-8");
|
|
632
|
-
} else {
|
|
633
|
-
console.warn(
|
|
634
|
-
`[react-loader] Unexpected source type: ${typeof result.source}`
|
|
635
|
-
);
|
|
636
|
-
return result;
|
|
637
|
-
}
|
|
638
|
-
const transformResult = await transformModuleIfNeeded(
|
|
639
|
-
sourceStr,
|
|
640
|
-
url,
|
|
641
|
-
nextLoad,
|
|
642
|
-
loaderPort ?? undefined
|
|
643
|
-
);
|
|
644
|
-
if (transformResult === null) {
|
|
645
|
-
return result;
|
|
646
|
-
} else if (typeof transformResult === "string") {
|
|
647
|
-
return { ...result, source: transformResult };
|
|
648
|
-
} else if (typeof transformResult === "object") {
|
|
649
|
-
const typedResult = transformResult;
|
|
650
|
-
if (!("code" in typedResult)) {
|
|
651
|
-
throw new Error("Failed to transform module");
|
|
652
|
-
}
|
|
653
|
-
return {
|
|
654
|
-
...result,
|
|
655
|
-
source: typedResult.code,
|
|
656
|
-
map: typedResult.map || result.map
|
|
657
|
-
};
|
|
658
|
-
} else {
|
|
659
|
-
console.warn(
|
|
660
|
-
`[react-loader] Unexpected transform result type: ${typeof transformResult}`
|
|
661
|
-
);
|
|
662
|
-
return result;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
async function transformSource(source, context, defaultTransformSource) {
|
|
666
|
-
const transformed = await defaultTransformSource(
|
|
667
|
-
source,
|
|
668
|
-
context,
|
|
669
|
-
defaultTransformSource
|
|
670
|
-
);
|
|
671
|
-
if (context.format === "module") {
|
|
672
|
-
let transformedSourceStr;
|
|
673
|
-
if (typeof transformed.source === "string") {
|
|
674
|
-
transformedSourceStr = transformed.source;
|
|
675
|
-
} else if (transformed.source instanceof Uint8Array || Buffer.isBuffer(transformed.source)) {
|
|
676
|
-
transformedSourceStr = transformed.source.toString("utf-8");
|
|
677
|
-
} else {
|
|
678
|
-
console.warn(
|
|
679
|
-
`[react-loader] Unexpected transformed source type: ${typeof transformed.source}`
|
|
680
|
-
);
|
|
681
|
-
return transformed;
|
|
682
|
-
}
|
|
683
|
-
const newSrc = await transformModuleIfNeeded(
|
|
684
|
-
transformedSourceStr,
|
|
685
|
-
context.url,
|
|
686
|
-
(url) => loadClientImport(url, defaultTransformSource),
|
|
687
|
-
context.data?.port
|
|
688
|
-
);
|
|
689
|
-
return { source: newSrc };
|
|
690
|
-
}
|
|
691
|
-
return transformed;
|
|
692
|
-
}
|
|
8
|
+
const condition = getCondition("");
|
|
9
|
+
const loader = await import(`react-loader.${condition}.ts`);
|
|
10
|
+
const { load, resolve, transformModuleIfNeeded } = loader;
|
|
693
11
|
|
|
694
|
-
export {
|
|
12
|
+
export { load, resolve, transformModuleIfNeeded };
|
|
695
13
|
//# sourceMappingURL=react-loader.js.map
|