vite-plugin-react-server 1.1.9 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -27
- package/dist/index.js.map +1 -1
- package/dist/package.json +34 -14
- package/dist/plugin/{css-collector-elements.d.ts → components/css-collector-elements.d.ts} +1 -1
- package/dist/plugin/components/css-collector-elements.d.ts.map +1 -0
- package/dist/plugin/components/css-collector-elements.js.map +1 -0
- package/dist/plugin/{css-collector.d.ts → components/css-collector.d.ts} +1 -1
- package/dist/plugin/components/css-collector.d.ts.map +1 -0
- package/dist/plugin/components/css-collector.js.map +1 -0
- package/dist/plugin/components/html.d.ts +4 -0
- package/dist/plugin/components/html.d.ts.map +1 -0
- package/dist/plugin/components/html.js +17 -0
- package/dist/plugin/components/html.js.map +1 -0
- package/dist/plugin/components/index.d.ts +5 -0
- package/dist/plugin/components/index.d.ts.map +1 -0
- package/dist/plugin/components.js +9 -3
- package/dist/plugin/components.js.map +1 -0
- package/dist/plugin/config/autoDiscover/index.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/index.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/index.js +8 -0
- package/dist/plugin/config/{resolveAutoDiscover.d.ts → autoDiscover/resolveAutoDiscover.d.ts} +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/{resolveAutoDiscover.js → autoDiscover/resolveAutoDiscover.js} +10 -9
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +10 -10
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -1
- package/dist/plugin/config/defaults.d.ts +6 -4
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +8 -4
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/index.d.ts +1 -0
- package/dist/plugin/config/index.d.ts.map +1 -1
- package/dist/plugin/config/index.js +1 -0
- package/dist/plugin/config/resolveDevServerConfig.d.ts +2 -0
- package/dist/plugin/config/resolveDevServerConfig.d.ts.map +1 -0
- package/dist/plugin/config/resolveEnv.d.ts +13 -0
- package/dist/plugin/config/resolveEnv.d.ts.map +1 -0
- package/dist/plugin/config/resolveEnv.js +120 -0
- package/dist/plugin/config/resolveEnv.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +34 -11
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -1
- package/dist/plugin/config/resolveUrlOption.js +1 -2
- package/dist/plugin/config/resolveUrlOption.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +80 -69
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/config.js +17 -0
- package/dist/plugin/config.js.map +1 -0
- package/dist/plugin/env/index.d.ts +2 -0
- package/dist/plugin/env/index.d.ts.map +1 -0
- package/dist/plugin/env/index.js +1 -0
- package/dist/plugin/env/plugin.d.ts +30 -0
- package/dist/plugin/env/plugin.d.ts.map +1 -0
- package/dist/plugin/env/plugin.js +64 -0
- package/dist/plugin/env.js +45 -0
- package/dist/plugin/env.js.map +1 -0
- package/dist/plugin/error/toError.d.ts +6 -0
- package/dist/plugin/error/toError.d.ts.map +1 -0
- package/dist/plugin/error/toError.js +19 -0
- package/dist/plugin/error/toError.js.map +1 -0
- package/dist/plugin/file-preserver/plugin.d.ts +19 -0
- package/dist/plugin/file-preserver/plugin.d.ts.map +1 -0
- package/dist/plugin/file-preserver/plugin.js +108 -0
- package/dist/plugin/file-preserver.js +96 -0
- package/dist/plugin/file-preserver.js.map +1 -0
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
- package/dist/plugin/helpers/createCssProps.js +10 -2
- package/dist/plugin/helpers/createCssProps.js.map +1 -1
- package/dist/plugin/helpers/createEventHandler.d.ts +1 -1
- package/dist/plugin/helpers/createRscStream.js +1 -1
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/formatMetrics.d.ts +3 -1
- package/dist/plugin/helpers/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/helpers/formatMetrics.js +22 -7
- package/dist/plugin/helpers/formatMetrics.js.map +1 -0
- package/dist/plugin/helpers/getRouteFiles.d.ts +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.js +2 -0
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -1
- package/dist/plugin/helpers/index.d.ts +24 -0
- package/dist/plugin/helpers/index.d.ts.map +1 -0
- package/dist/plugin/helpers/index.js +31 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts +2 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +34 -9
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/metrics.js +26 -2
- package/dist/plugin/helpers/metrics.js.map +1 -1
- package/dist/plugin/helpers/moduleRefs.d.ts.map +1 -0
- package/dist/plugin/helpers/moduleRefs.js.map +1 -0
- package/dist/plugin/helpers/requestInfo.d.ts +26 -0
- package/dist/plugin/helpers/requestInfo.d.ts.map +1 -0
- package/dist/plugin/helpers/requestInfo.js +66 -0
- package/dist/plugin/helpers/requestInfo.js.map +1 -0
- package/dist/plugin/helpers/requestToRoute.js.map +1 -1
- package/dist/plugin/helpers/resolvePage.d.ts.map +1 -0
- package/dist/plugin/{resolvePage.js → helpers/resolvePage.js} +19 -3
- package/dist/plugin/helpers/resolvePage.js.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
- package/dist/plugin/helpers/resolvePageAndProps.js +7 -4
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -1
- package/dist/plugin/helpers/resolveProps.d.ts.map +1 -0
- package/dist/plugin/{resolveProps.js → helpers/resolveProps.js} +9 -6
- package/dist/plugin/helpers/resolveProps.js.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.js +1 -1
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
- package/dist/plugin/helpers/stashReturnValue.js +19 -13
- package/dist/plugin/helpers/stashReturnValue.js.map +1 -0
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +0 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/helpers.js +27 -0
- package/dist/plugin/helpers.js.map +1 -0
- package/dist/plugin/loader/createBuildLoader.js +1 -1
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.development.js +1 -7
- package/dist/plugin/loader/css-loader.development.js.map +1 -1
- package/dist/plugin/loader/css-loader.production.js.map +1 -1
- package/dist/plugin/loader/env-loader.development.d.ts +12 -0
- package/dist/plugin/loader/env-loader.development.d.ts.map +1 -0
- package/dist/plugin/loader/env-loader.development.js +60 -0
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +1 -8
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/metrics/formatMetrics.d.ts +6 -1
- package/dist/plugin/metrics/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/metrics/formatMetrics.js +21 -3
- package/dist/plugin/metrics/formatMetrics.js.map +1 -1
- package/dist/plugin/metrics.js +1 -1
- package/dist/plugin/plugin.client.d.ts.map +1 -1
- package/dist/plugin/plugin.client.js +2 -0
- package/dist/plugin/plugin.client.js.map +1 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +1 -2
- package/dist/plugin/plugin.server.d.ts.map +1 -1
- package/dist/plugin/plugin.server.js +3 -0
- package/dist/plugin/plugin.server.js.map +1 -1
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/process-env.d.ts +14 -0
- package/dist/plugin/process-env.d.ts.map +1 -0
- package/dist/plugin/process-env.js +1 -0
- package/dist/plugin/react-client/createMessageHandlers.d.ts +11 -0
- package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -0
- package/dist/plugin/react-client/createMessageHandlers.js +47 -0
- package/dist/plugin/react-client/createMessageHandlers.js.map +1 -0
- package/dist/plugin/react-client/createWorkerStream.d.ts +9 -3
- package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.js +102 -70
- package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts +19 -0
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -0
- package/dist/plugin/react-client/handleWorkerRscStream.js +47 -0
- package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -0
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +19 -5
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/restartWorker.d.ts +6 -1
- package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
- package/dist/plugin/react-client/restartWorker.js +13 -5
- package/dist/plugin/react-client/restartWorker.js.map +1 -1
- package/dist/plugin/react-client/server.d.ts +2 -13
- package/dist/plugin/react-client/server.d.ts.map +1 -1
- package/dist/plugin/react-client/server.js +123 -121
- package/dist/plugin/react-client/server.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +18 -8
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-server/server.d.ts.map +1 -1
- package/dist/plugin/react-server/server.js +37 -23
- package/dist/plugin/react-server/server.js.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.js +9 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
- package/dist/plugin/react-static/collectRscContent.js.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js +58 -54
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
- package/dist/plugin/react-static/fileWriter.d.ts +1 -1
- package/dist/plugin/react-static/fileWriter.d.ts.map +1 -1
- package/dist/plugin/react-static/fileWriter.js.map +1 -1
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +21 -23
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPages.js.map +1 -1
- package/dist/plugin/root.d.ts +1 -0
- package/dist/plugin/root.d.ts.map +1 -1
- package/dist/plugin/root.js +3 -2
- package/dist/plugin/root.js.map +1 -1
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.client.js +3 -12
- package/dist/plugin/transformer/plugin.client.js.map +1 -1
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.server.js +17 -24
- package/dist/plugin/transformer/plugin.server.js.map +1 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +1 -10
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.js +40 -38
- package/dist/plugin/types.d.ts +60 -15
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/types.js +1 -1
- package/dist/plugin/utils/callServer.d.ts +1 -1
- package/dist/plugin/utils/callServer.d.ts.map +1 -1
- package/dist/plugin/utils/callServer.js +3 -17
- package/dist/plugin/utils/callServer.js.map +1 -1
- package/dist/plugin/utils/createCallServer.d.ts +2 -0
- package/dist/plugin/utils/createCallServer.d.ts.map +1 -0
- package/dist/plugin/utils/createCallServer.js +28 -0
- package/dist/plugin/utils/createCallServer.js.map +1 -0
- package/dist/plugin/utils/createReactFetcher.d.ts +3 -1
- package/dist/plugin/utils/createReactFetcher.d.ts.map +1 -1
- package/dist/plugin/utils/createReactFetcher.js +11 -11
- package/dist/plugin/utils/createReactFetcher.js.map +1 -1
- package/dist/plugin/utils/env.d.ts +2 -0
- package/dist/plugin/utils/env.d.ts.map +1 -0
- package/dist/plugin/utils/env.js +9 -0
- package/dist/plugin/utils/env.js.map +1 -0
- package/dist/plugin/utils/envUrls.d.ts +9 -0
- package/dist/plugin/utils/envUrls.d.ts.map +1 -0
- package/dist/plugin/utils/envUrls.js +7 -0
- package/dist/plugin/utils/envUrls.node.d.ts +7 -0
- package/dist/plugin/utils/envUrls.node.d.ts.map +1 -0
- package/dist/plugin/utils/envUrls.node.js +11 -0
- package/dist/plugin/utils/envUrls.node.js.map +1 -0
- package/dist/plugin/utils/index.d.ts +2 -1
- package/dist/plugin/utils/index.d.ts.map +1 -1
- package/dist/plugin/utils/index.js +2 -1
- package/dist/plugin/utils/moduleBaseURL.d.ts +3 -0
- package/dist/plugin/utils/moduleBaseURL.d.ts.map +1 -0
- package/dist/plugin/utils/moduleBaseURL.js +4 -0
- package/dist/plugin/utils/urls.d.ts +130 -0
- package/dist/plugin/utils/urls.d.ts.map +1 -0
- package/dist/plugin/utils/urls.js +87 -0
- package/dist/plugin/utils/urls.js.map +1 -0
- package/dist/plugin/utils.js +2 -1
- package/dist/plugin/utils.js.map +1 -1
- package/dist/plugin/vendor/index.d.ts +2 -0
- package/dist/plugin/vendor/index.d.ts.map +1 -0
- package/dist/plugin/vendor/index.js +1 -0
- package/dist/plugin/vendor/vendor.client.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.client.js.map +1 -0
- package/dist/plugin/vendor/vendor.d.ts +2 -0
- package/dist/plugin/vendor/vendor.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.js +15 -0
- package/dist/plugin/vendor/vendor.js.map +1 -0
- package/dist/plugin/vendor/vendor.server.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.server.js.map +1 -0
- package/dist/plugin/vendor.js +7 -0
- package/dist/plugin/vendor.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +3 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +37 -23
- 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 +4 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts +2 -7
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.js +4 -4
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +42 -16
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +16 -5
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +16 -5
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/sendMessage.js +45 -43
- package/dist/plugin/worker/sendMessage.js.map +1 -0
- package/dist/plugin/worker/types.d.ts +32 -4
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -14
- package/plugin/{css-collector-elements.tsx → components/css-collector-elements.tsx} +1 -1
- package/plugin/{css-collector.tsx → components/css-collector.tsx} +1 -1
- package/plugin/{html.tsx → components/html.tsx} +1 -3
- package/{dist/plugin/components.d.ts → plugin/components/index.ts} +1 -1
- package/plugin/config/autoDiscover/index.ts +10 -0
- package/plugin/config/{resolveAutoDiscover.ts → autoDiscover/resolveAutoDiscover.ts} +16 -12
- package/plugin/config/autoDiscover/resolveBuildPages.ts +10 -11
- package/plugin/config/defaults.tsx +6 -4
- package/plugin/config/index.ts +1 -1
- package/plugin/config/resolveEnv.ts +187 -0
- package/plugin/config/resolveOptions.ts +60 -27
- package/plugin/config/resolveUrlOption.ts +2 -7
- package/plugin/config/resolveUserConfig.ts +145 -98
- package/plugin/env/index.ts +1 -0
- package/plugin/env/plugin.ts +78 -0
- package/plugin/error/toError.ts +19 -0
- package/plugin/file-preserver/plugin.ts +117 -0
- package/plugin/helpers/createCssProps.tsx +14 -6
- package/plugin/helpers/createRscStream.tsx +1 -1
- package/plugin/helpers/formatMetrics.ts +2 -2
- package/plugin/helpers/getRouteFiles.ts +3 -1
- package/plugin/helpers/index.ts +38 -0
- package/plugin/helpers/inputNormalizer.ts +66 -17
- package/plugin/helpers/requestInfo.ts +91 -0
- package/plugin/{resolvePage.ts → helpers/resolvePage.ts} +19 -4
- package/plugin/helpers/resolvePageAndProps.ts +7 -4
- package/plugin/{resolveProps.ts → helpers/resolveProps.ts} +8 -6
- package/plugin/helpers/serializeUserOptions.ts +1 -1
- package/plugin/helpers/tryManifest.ts +0 -1
- package/plugin/loader/createBuildLoader.ts +1 -1
- package/plugin/loader/css-loader.development.ts +2 -8
- package/plugin/loader/env-loader.development.ts +84 -0
- package/plugin/loader/react-loader.ts +1 -10
- package/plugin/metrics/formatMetrics.ts +29 -4
- package/plugin/plugin.client.ts +2 -0
- package/plugin/plugin.server.ts +3 -0
- package/plugin/plugin.ts +1 -3
- package/plugin/preserver/plugin.ts +1 -0
- package/plugin/process-env.ts +13 -0
- package/plugin/react-client/createMessageHandlers.ts +49 -0
- package/plugin/react-client/createWorkerStream.ts +130 -83
- package/plugin/react-client/handleWorkerRscStream.ts +57 -0
- package/plugin/react-client/plugin.ts +30 -17
- package/plugin/react-client/restartWorker.ts +15 -7
- package/plugin/react-client/server.ts +129 -164
- package/plugin/react-server/plugin.ts +26 -13
- package/plugin/react-server/server.ts +40 -35
- package/plugin/react-static/collectHtmlWorkerContent.ts +13 -1
- package/plugin/react-static/configurePreviewServer.ts +75 -62
- package/plugin/react-static/fileWriter.ts +1 -1
- package/plugin/react-static/plugin.ts +23 -30
- package/plugin/root.ts +7 -1
- package/plugin/transformer/plugin.client.ts +4 -12
- package/plugin/transformer/plugin.server.ts +18 -25
- package/plugin/transformer/upgradeCssModuleCode.ts +39 -39
- package/plugin/types/env.d.ts +7 -0
- package/plugin/types.ts +80 -29
- package/plugin/utils/callServer.ts +3 -24
- package/plugin/utils/createCallServer.ts +26 -0
- package/plugin/utils/createReactFetcher.ts +14 -12
- package/plugin/utils/env.ts +1 -0
- package/plugin/utils/envUrls.node.ts +19 -0
- package/plugin/utils/envUrls.ts +8 -0
- package/plugin/utils/index.ts +2 -1
- package/plugin/utils/moduleBaseURL.ts +7 -0
- package/plugin/utils/urls.ts +217 -0
- package/plugin/vendor/index.ts +1 -0
- package/plugin/vendor/vendor.ts +6 -0
- package/plugin/worker/createWorker.ts +41 -30
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +4 -1
- package/plugin/worker/html/html-worker.development.tsx +2 -1
- package/plugin/worker/html/html-worker.production.tsx +2 -1
- package/plugin/worker/rsc/handleRender.ts +6 -12
- package/plugin/worker/rsc/messageHandler.tsx +53 -20
- package/plugin/worker/rsc/rsc-worker.development.ts +23 -9
- package/plugin/worker/rsc/rsc-worker.production.ts +23 -7
- package/plugin/worker/types.ts +35 -4
- package/dist/plugin/components.d.ts.map +0 -1
- package/dist/plugin/config/resolveAutoDiscover.d.ts.map +0 -1
- package/dist/plugin/config/resolveAutoDiscover.js.map +0 -1
- package/dist/plugin/copy.d.ts +0 -7
- package/dist/plugin/copy.d.ts.map +0 -1
- package/dist/plugin/copy.js +0 -30
- package/dist/plugin/css-collector-elements.d.ts.map +0 -1
- package/dist/plugin/css-collector-elements.js.map +0 -1
- package/dist/plugin/css-collector.d.ts.map +0 -1
- package/dist/plugin/css-collector.js.map +0 -1
- package/dist/plugin/getCondition.d.ts +0 -2
- package/dist/plugin/getCondition.d.ts.map +0 -1
- package/dist/plugin/html.d.ts +0 -4
- package/dist/plugin/html.d.ts.map +0 -1
- package/dist/plugin/html.js +0 -18
- package/dist/plugin/html.js.map +0 -1
- package/dist/plugin/manifest.d.ts +0 -6
- package/dist/plugin/manifest.d.ts.map +0 -1
- package/dist/plugin/manifest.js +0 -13
- package/dist/plugin/moduleRefs.d.ts.map +0 -1
- package/dist/plugin/moduleRefs.js.map +0 -1
- package/dist/plugin/resolvePage.d.ts.map +0 -1
- package/dist/plugin/resolvePage.js.map +0 -1
- package/dist/plugin/resolveProps.d.ts.map +0 -1
- package/dist/plugin/resolveProps.js.map +0 -1
- package/dist/plugin/utils/pageURL.d.ts +0 -2
- package/dist/plugin/utils/pageURL.d.ts.map +0 -1
- package/dist/plugin/utils/pageURL.js +0 -21
- package/dist/plugin/utils/pageURL.js.map +0 -1
- package/dist/plugin/vendor.client.d.ts.map +0 -1
- package/dist/plugin/vendor.client.js.map +0 -1
- package/dist/plugin/vendor.server.d.ts.map +0 -1
- package/dist/plugin/vendor.server.js.map +0 -1
- package/plugin/copy.ts +0 -39
- package/plugin/manifest.ts +0 -24
- package/plugin/utils/pageURL.ts +0 -28
- /package/dist/plugin/{css-collector-elements.js → components/css-collector-elements.js} +0 -0
- /package/dist/plugin/{css-collector.js → components/css-collector.js} +0 -0
- /package/{plugin/components.ts → dist/plugin/components/index.js} +0 -0
- /package/dist/plugin/{getCondition.js → config/resolveDevServerConfig.js} +0 -0
- /package/dist/plugin/{moduleRefs.d.ts → helpers/moduleRefs.d.ts} +0 -0
- /package/dist/plugin/{moduleRefs.js → helpers/moduleRefs.js} +0 -0
- /package/dist/plugin/{resolvePage.d.ts → helpers/resolvePage.d.ts} +0 -0
- /package/dist/plugin/{resolveProps.d.ts → helpers/resolveProps.d.ts} +0 -0
- /package/dist/plugin/{vendor.client.d.ts → vendor/vendor.client.d.ts} +0 -0
- /package/dist/plugin/{vendor.client.js → vendor/vendor.client.js} +0 -0
- /package/dist/plugin/{vendor.server.d.ts → vendor/vendor.server.d.ts} +0 -0
- /package/dist/plugin/{vendor.server.js → vendor/vendor.server.js} +0 -0
- /package/plugin/{getCondition.ts → config/resolveDevServerConfig.tsx} +0 -0
- /package/plugin/{moduleRefs.ts → helpers/moduleRefs.ts} +0 -0
- /package/plugin/{vendor.client.ts → vendor/vendor.client.ts} +0 -0
- /package/plugin/{vendor.server.ts → vendor/vendor.server.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { normalizePath } from "vite";
|
|
2
2
|
import type { InputNormalizer, NormalizerInput } from "../types.js";
|
|
3
|
-
import path, { join } from "path";
|
|
3
|
+
import path, { join, sep } from "path";
|
|
4
4
|
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
5
5
|
|
|
6
6
|
let stashedNormalizer: InputNormalizer | null = null;
|
|
@@ -9,6 +9,7 @@ type CreateInputNormalizerProps = {
|
|
|
9
9
|
root: string;
|
|
10
10
|
preserveModulesRoot?: string | undefined;
|
|
11
11
|
removeExtension?: boolean | RegExp | string | ((path: string) => boolean);
|
|
12
|
+
moduleBasePath?: string | undefined;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
const resolveExtensionOptions = (
|
|
@@ -55,7 +56,10 @@ const resolveRootOption = (
|
|
|
55
56
|
return normalizedPreserveModulesRoot.slice(root.length + 1);
|
|
56
57
|
}
|
|
57
58
|
return "";
|
|
58
|
-
} else if (
|
|
59
|
+
} else if (
|
|
60
|
+
typeof preserveModulesRoot === "string" &&
|
|
61
|
+
typeof root !== "string"
|
|
62
|
+
) {
|
|
59
63
|
return normalizePath(preserveModulesRoot);
|
|
60
64
|
}
|
|
61
65
|
return "";
|
|
@@ -65,23 +69,43 @@ const createKeyNormalizer =
|
|
|
65
69
|
root: normalizedRoot,
|
|
66
70
|
preserveModulesRoot,
|
|
67
71
|
handleExtension,
|
|
72
|
+
moduleBasePath,
|
|
68
73
|
}: {
|
|
69
74
|
root: string;
|
|
70
75
|
preserveModulesRoot: string | undefined;
|
|
71
76
|
handleExtension: (path: string) => string;
|
|
77
|
+
moduleBasePath: string | undefined;
|
|
72
78
|
}) =>
|
|
73
79
|
(key: string) => {
|
|
80
|
+
if (key.includes("?")) {
|
|
81
|
+
key = key.split("?")[0];
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
// Handle virtual modules first
|
|
75
|
-
const virtualPrefix = key.match(/^\0+/)
|
|
76
|
-
const actualKey = key.slice(virtualPrefix.length);
|
|
77
|
-
|
|
85
|
+
const virtualPrefix = key.match(/^\0+/) ?? "";
|
|
86
|
+
const actualKey = virtualPrefix ? key.slice(virtualPrefix[0].length) : key;
|
|
87
|
+
|
|
78
88
|
let moduleId = normalizePath(actualKey);
|
|
79
|
-
|
|
89
|
+
|
|
80
90
|
// Normalize root path to handle both absolute and relative paths
|
|
81
91
|
const normalizedRootPath = normalizePath(normalizedRoot);
|
|
82
92
|
if (moduleId.startsWith(normalizedRootPath)) {
|
|
83
93
|
moduleId = moduleId.slice(normalizedRootPath.length);
|
|
84
94
|
}
|
|
95
|
+
if (
|
|
96
|
+
typeof moduleBasePath === "string" &&
|
|
97
|
+
moduleBasePath !== "" &&
|
|
98
|
+
moduleBasePath !== "/"
|
|
99
|
+
) {
|
|
100
|
+
moduleId = moduleId.startsWith(
|
|
101
|
+
moduleBasePath.endsWith(sep) ? moduleBasePath : moduleBasePath + sep
|
|
102
|
+
)
|
|
103
|
+
? moduleId.slice(
|
|
104
|
+
moduleBasePath.length +
|
|
105
|
+
(moduleBasePath.endsWith(sep) ? 0 : sep.length)
|
|
106
|
+
)
|
|
107
|
+
: moduleId;
|
|
108
|
+
}
|
|
85
109
|
|
|
86
110
|
moduleId = handleExtension(moduleId);
|
|
87
111
|
while (moduleId.startsWith("/") || moduleId.startsWith(".")) {
|
|
@@ -95,7 +119,7 @@ const createKeyNormalizer =
|
|
|
95
119
|
? moduleId.slice(preserveModulesRoot.length + path.sep.length)
|
|
96
120
|
: moduleId;
|
|
97
121
|
}
|
|
98
|
-
|
|
122
|
+
|
|
99
123
|
// Add virtual prefix back
|
|
100
124
|
return virtualPrefix + moduleId;
|
|
101
125
|
};
|
|
@@ -104,18 +128,37 @@ const createPathNormalizer =
|
|
|
104
128
|
({
|
|
105
129
|
root,
|
|
106
130
|
preserveModulesRoot,
|
|
131
|
+
moduleBasePath,
|
|
107
132
|
}: {
|
|
108
133
|
root: string;
|
|
109
134
|
preserveModulesRoot: string | undefined;
|
|
135
|
+
moduleBasePath: string | undefined;
|
|
110
136
|
}) =>
|
|
111
137
|
(path: string) => {
|
|
112
138
|
if (typeof path !== "string") {
|
|
113
139
|
throw new Error(`Invalid path: ${JSON.stringify(path)}`);
|
|
114
140
|
}
|
|
141
|
+
if (path.includes("?")) {
|
|
142
|
+
path = path.split("?")[0];
|
|
143
|
+
}
|
|
115
144
|
let normalPath = normalizePath(path);
|
|
116
|
-
if(normalPath.startsWith(root)) {
|
|
145
|
+
if (normalPath.startsWith(root)) {
|
|
117
146
|
normalPath = normalPath.slice(root.length);
|
|
118
147
|
}
|
|
148
|
+
if (
|
|
149
|
+
typeof moduleBasePath === "string" &&
|
|
150
|
+
moduleBasePath !== "" &&
|
|
151
|
+
moduleBasePath !== "/"
|
|
152
|
+
) {
|
|
153
|
+
normalPath = normalPath.startsWith(
|
|
154
|
+
moduleBasePath.endsWith(sep) ? moduleBasePath : moduleBasePath + sep
|
|
155
|
+
)
|
|
156
|
+
? normalPath.slice(
|
|
157
|
+
moduleBasePath.length +
|
|
158
|
+
(moduleBasePath.endsWith(sep) ? 0 : sep.length)
|
|
159
|
+
)
|
|
160
|
+
: normalPath;
|
|
161
|
+
}
|
|
119
162
|
if (typeof preserveModulesRoot === "string" && preserveModulesRoot !== "") {
|
|
120
163
|
normalPath = normalPath.startsWith(preserveModulesRoot)
|
|
121
164
|
? normalPath.slice(preserveModulesRoot.length)
|
|
@@ -135,10 +178,11 @@ const createPathNormalizer =
|
|
|
135
178
|
*/
|
|
136
179
|
export function createInputNormalizer({
|
|
137
180
|
root,
|
|
181
|
+
moduleBasePath,
|
|
138
182
|
preserveModulesRoot = undefined,
|
|
139
183
|
removeExtension = DEFAULT_CONFIG.MODULE_EXTENSION,
|
|
140
184
|
}: CreateInputNormalizerProps): InputNormalizer {
|
|
141
|
-
if(stashedNormalizer) {
|
|
185
|
+
if (stashedNormalizer) {
|
|
142
186
|
return stashedNormalizer;
|
|
143
187
|
}
|
|
144
188
|
const relativeRoot = resolveRootOption(root, preserveModulesRoot);
|
|
@@ -147,10 +191,12 @@ export function createInputNormalizer({
|
|
|
147
191
|
root: root,
|
|
148
192
|
preserveModulesRoot: preserveModulesRoot,
|
|
149
193
|
handleExtension,
|
|
194
|
+
moduleBasePath,
|
|
150
195
|
});
|
|
151
196
|
const normalizeEntryPath = createPathNormalizer({
|
|
152
197
|
root: root,
|
|
153
198
|
preserveModulesRoot: relativeRoot,
|
|
199
|
+
moduleBasePath,
|
|
154
200
|
});
|
|
155
201
|
function normalizeInput(id: NormalizerInput): [string, string] {
|
|
156
202
|
// Normalize both paths to use POSIX separators
|
|
@@ -185,19 +231,22 @@ export function createInputNormalizer({
|
|
|
185
231
|
return normalized;
|
|
186
232
|
}
|
|
187
233
|
throw new Error(`Invalid input type: ${typeof id}`);
|
|
188
|
-
}
|
|
234
|
+
}
|
|
189
235
|
|
|
190
236
|
stashedNormalizer = (input: NormalizerInput): [string, string] => {
|
|
191
237
|
const [key, path] = normalizeInput(input);
|
|
192
238
|
// Apply the same normalization to both key and path
|
|
193
|
-
const normalizedPath = path.startsWith(
|
|
194
|
-
const virtualPrefix = key.match(/^\0+/)
|
|
195
|
-
|
|
239
|
+
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
240
|
+
const virtualPrefix = key.match(/^\0+/) ?? "";
|
|
196
241
|
// If key has virtual prefix, ensure path has it too
|
|
197
|
-
const finalPath = virtualPrefix
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
242
|
+
const finalPath = virtualPrefix
|
|
243
|
+
? virtualPrefix.length && normalizedPath.startsWith(virtualPrefix[0])
|
|
244
|
+
? normalizedPath
|
|
245
|
+
: virtualPrefix.length
|
|
246
|
+
? virtualPrefix[0] + normalizedPath
|
|
247
|
+
: normalizedPath
|
|
248
|
+
: normalizedPath;
|
|
249
|
+
|
|
201
250
|
return [key, finalPath];
|
|
202
251
|
};
|
|
203
252
|
return stashedNormalizer;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import type { ResolvedUserOptions } from "../types.js";
|
|
3
|
+
import type { Connect } from "vite";
|
|
4
|
+
import { MIME_TYPES } from "../config/mimeTypes.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* # Request info
|
|
8
|
+
*
|
|
9
|
+
* Does the initial work to check if the request is for html, rsc, css, or something else not handled by this plugin.
|
|
10
|
+
*
|
|
11
|
+
* @param req
|
|
12
|
+
* @param userOptions
|
|
13
|
+
* @param hostDir
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export function requestInfo(
|
|
17
|
+
req: Connect.IncomingMessage,
|
|
18
|
+
userOptions: Pick<ResolvedUserOptions, "normalizer" | "build" | "autoDiscover">,
|
|
19
|
+
hostDir: string
|
|
20
|
+
) {
|
|
21
|
+
const [, value] = userOptions.normalizer(req.url);
|
|
22
|
+
const dotIndex = value.lastIndexOf(".");
|
|
23
|
+
const ext = dotIndex === -1 ? "" : value.slice(dotIndex);
|
|
24
|
+
// handle index.html
|
|
25
|
+
const isHtml = userOptions.autoDiscover.htmlPattern(value);
|
|
26
|
+
const hasHtmlHeader = req.headers.accept?.includes("text/html");
|
|
27
|
+
const isRsc = userOptions.autoDiscover.rscPattern(value);
|
|
28
|
+
const hasRscHeader = req.headers.accept?.includes("text/x-component");
|
|
29
|
+
const isFolder = !ext;
|
|
30
|
+
const isHtmlRequest =
|
|
31
|
+
isHtml || hasHtmlHeader || (isFolder && !hasRscHeader && !isRsc);
|
|
32
|
+
const isRscRequest = !isHtmlRequest && (isRsc || hasRscHeader);
|
|
33
|
+
const isCss = userOptions.autoDiscover.cssPattern(value);
|
|
34
|
+
const isCssRequest =
|
|
35
|
+
!isHtmlRequest &&
|
|
36
|
+
!isRscRequest &&
|
|
37
|
+
(isCss || req.headers.accept?.includes("text/css"));
|
|
38
|
+
let filePath = join(hostDir, value);
|
|
39
|
+
let contentType;
|
|
40
|
+
if (isHtmlRequest) {
|
|
41
|
+
if (!isHtml) {
|
|
42
|
+
filePath = join(hostDir, value, userOptions.build.htmlOutputPath);
|
|
43
|
+
}
|
|
44
|
+
contentType = "text/html; charset=utf-8";
|
|
45
|
+
} else if (isRscRequest) {
|
|
46
|
+
if (!isRsc) {
|
|
47
|
+
filePath = join(hostDir, value, userOptions.build.rscOutputPath);
|
|
48
|
+
}
|
|
49
|
+
contentType = "text/x-component; charset=utf-8";
|
|
50
|
+
} else if (isCssRequest) {
|
|
51
|
+
if (!isCss) {
|
|
52
|
+
filePath = join(hostDir, value);
|
|
53
|
+
}
|
|
54
|
+
contentType = "text/css; charset=utf-8";
|
|
55
|
+
} else {
|
|
56
|
+
const mimeType = MIME_TYPES[ext];
|
|
57
|
+
if (mimeType) {
|
|
58
|
+
contentType = mimeType;
|
|
59
|
+
} else {
|
|
60
|
+
contentType = "application/octet-stream";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const route = value
|
|
64
|
+
.replace(userOptions.build.rscOutputPath, "")
|
|
65
|
+
.replace(userOptions.build.htmlOutputPath, "");
|
|
66
|
+
|
|
67
|
+
const routeWithoutTrailingSlash =
|
|
68
|
+
route === "" || route === "/"
|
|
69
|
+
? "/"
|
|
70
|
+
: route.endsWith("/")
|
|
71
|
+
? route.slice(0, -1)
|
|
72
|
+
: route;
|
|
73
|
+
const routeWithLeadingSlash =
|
|
74
|
+
routeWithoutTrailingSlash.startsWith("/")
|
|
75
|
+
? routeWithoutTrailingSlash
|
|
76
|
+
: `/${routeWithoutTrailingSlash}`;
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
route: routeWithLeadingSlash,
|
|
80
|
+
ext,
|
|
81
|
+
isHtmlRequest,
|
|
82
|
+
isRscRequest,
|
|
83
|
+
isCssRequest,
|
|
84
|
+
isCss,
|
|
85
|
+
isHtml,
|
|
86
|
+
isRsc,
|
|
87
|
+
isFolder,
|
|
88
|
+
contentType,
|
|
89
|
+
filePath,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toError } from "../error/toError.js";
|
|
1
2
|
|
|
2
3
|
type ResolvePageOptions<N extends string> = {
|
|
3
4
|
id: string;
|
|
@@ -16,7 +17,7 @@ type ResolvePageResult<T, N extends string> =
|
|
|
16
17
|
* During development (ssrLoadModule):
|
|
17
18
|
* - Real modules have exports available directly on the module object
|
|
18
19
|
* - Virtual modules have exports stored in temporaryReferences
|
|
19
|
-
*
|
|
20
|
+
*
|
|
20
21
|
* @param options.id - The module ID to resolve
|
|
21
22
|
* @param options.exportName - The name of the export to resolve (e.g. 'Page')
|
|
22
23
|
* @param options.loader - The loader function to use for loading the module
|
|
@@ -58,17 +59,31 @@ export const resolvePage = async <T, N extends string>({
|
|
|
58
59
|
if (module instanceof Error) {
|
|
59
60
|
return {
|
|
60
61
|
type: "error",
|
|
61
|
-
error:
|
|
62
|
+
error: {
|
|
63
|
+
name: module.name,
|
|
64
|
+
message: module.message,
|
|
65
|
+
stack: module.stack,
|
|
66
|
+
},
|
|
62
67
|
};
|
|
63
68
|
} else if (!(exportName in module)) {
|
|
69
|
+
if ("error" in module) {
|
|
70
|
+
return {
|
|
71
|
+
type: "error",
|
|
72
|
+
error: toError(module.error),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
64
75
|
return {
|
|
65
76
|
type: "error",
|
|
66
|
-
error: new Error(
|
|
77
|
+
error: new Error(
|
|
78
|
+
`Export "${exportName}" not found in module ${id}.`
|
|
79
|
+
),
|
|
67
80
|
};
|
|
68
81
|
} else if (!Page) {
|
|
69
82
|
return {
|
|
70
83
|
type: "error",
|
|
71
|
-
error: new Error(
|
|
84
|
+
error: new Error(
|
|
85
|
+
`Export "${exportName}" is null or undefined in module ${id}.`
|
|
86
|
+
),
|
|
72
87
|
};
|
|
73
88
|
} else if (Page instanceof Error) {
|
|
74
89
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolvePage } from "
|
|
2
|
-
import { resolveProps } from "
|
|
1
|
+
import { resolvePage } from "./resolvePage.js";
|
|
2
|
+
import { resolveProps } from "./resolveProps.js";
|
|
3
3
|
|
|
4
4
|
type ResolvePageAndPropsOptions<N1 extends string, N2 extends string> = {
|
|
5
5
|
pagePath: string;
|
|
@@ -52,8 +52,11 @@ export async function resolvePageAndProps<
|
|
|
52
52
|
? handlerOptions.loader
|
|
53
53
|
: async () => {
|
|
54
54
|
const resolvePageResult = await resolvePagePromise;
|
|
55
|
-
if (resolvePageResult.type
|
|
56
|
-
return resolvePageResult
|
|
55
|
+
if (resolvePageResult.type === "error") {
|
|
56
|
+
return resolvePageResult.error
|
|
57
|
+
}
|
|
58
|
+
if (resolvePageResult.type === "skip") {
|
|
59
|
+
return null;
|
|
57
60
|
}
|
|
58
61
|
return resolvePageResult.module;
|
|
59
62
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toError } from "../error/toError.js";
|
|
1
2
|
|
|
2
3
|
type ResolvePropsOptions<N extends string> = {
|
|
3
4
|
id: string;
|
|
@@ -53,15 +54,16 @@ export const resolveProps = async <T, N extends string>({
|
|
|
53
54
|
| { type: "error"; error: Error; module?: never }
|
|
54
55
|
> => {
|
|
55
56
|
try {
|
|
57
|
+
const result = await loader(id);
|
|
56
58
|
return {
|
|
57
59
|
type: "success",
|
|
58
60
|
key: id,
|
|
59
|
-
module:
|
|
61
|
+
module: result,
|
|
60
62
|
};
|
|
61
63
|
} catch (error) {
|
|
62
64
|
return {
|
|
63
65
|
type: "error",
|
|
64
|
-
error:
|
|
66
|
+
error: toError(error),
|
|
65
67
|
};
|
|
66
68
|
}
|
|
67
69
|
})();
|
|
@@ -117,7 +119,7 @@ export const resolveProps = async <T, N extends string>({
|
|
|
117
119
|
} catch (error) {
|
|
118
120
|
return {
|
|
119
121
|
type: "error",
|
|
120
|
-
error:
|
|
122
|
+
error: toError(error),
|
|
121
123
|
};
|
|
122
124
|
}
|
|
123
125
|
} else if (props instanceof Promise) {
|
|
@@ -132,7 +134,7 @@ export const resolveProps = async <T, N extends string>({
|
|
|
132
134
|
} catch (error) {
|
|
133
135
|
return {
|
|
134
136
|
type: "error",
|
|
135
|
-
error:
|
|
137
|
+
error: toError(error),
|
|
136
138
|
};
|
|
137
139
|
}
|
|
138
140
|
} else if (Array.isArray(props)) {
|
|
@@ -149,7 +151,7 @@ export const resolveProps = async <T, N extends string>({
|
|
|
149
151
|
} catch (error) {
|
|
150
152
|
return {
|
|
151
153
|
type: "error",
|
|
152
|
-
error:
|
|
154
|
+
error: toError(error),
|
|
153
155
|
};
|
|
154
156
|
}
|
|
155
157
|
} else if (typeof props === "string") {
|
|
@@ -162,7 +164,7 @@ export const resolveProps = async <T, N extends string>({
|
|
|
162
164
|
} catch (error) {
|
|
163
165
|
return {
|
|
164
166
|
type: "error",
|
|
165
|
-
error:
|
|
167
|
+
error: toError(error),
|
|
166
168
|
};
|
|
167
169
|
}
|
|
168
170
|
}
|
|
@@ -190,7 +190,7 @@ export const serializedOptions = <T extends ResolvedUserOptions>(
|
|
|
190
190
|
autoDiscover,
|
|
191
191
|
...handlerOptions
|
|
192
192
|
} = userOptions;
|
|
193
|
-
const { entryFile, chunkFile, assetFile, pages, ...buildOptions } = build;
|
|
193
|
+
const { entryFile, chunkFile, assetFile, pages, ...buildOptions } = build ?? {};
|
|
194
194
|
const result = {
|
|
195
195
|
...handlerOptions,
|
|
196
196
|
build: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import type { ResolvedUserConfig, ResolvedUserOptions } from "../../server.js";
|
|
3
3
|
import type { Manifest } from "vite";
|
|
4
|
-
import { getModuleRef } from "../moduleRefs.js";
|
|
4
|
+
import { getModuleRef } from "../helpers/moduleRefs.js";
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
|
6
6
|
import type { OutputBundle } from "rollup";
|
|
7
7
|
import { temporaryReferences } from "./temporaryReferences.js";
|
|
@@ -6,6 +6,7 @@ import { preprocessCSS } from "vite";
|
|
|
6
6
|
import type { ResolvedConfig } from "vite";
|
|
7
7
|
import { readFile } from "node:fs/promises";
|
|
8
8
|
import { join } from "node:path";
|
|
9
|
+
import { env } from "../utils/env.js";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Global port for communication between the main thread and the CSS loader.
|
|
@@ -21,14 +22,7 @@ const cssFilesByPage = new Map<string, Set<string>>();
|
|
|
21
22
|
|
|
22
23
|
let currentPage: string | null = null;
|
|
23
24
|
let resolvedConfig: ResolvedConfig | undefined;
|
|
24
|
-
|
|
25
|
-
const env = import.meta?.env || {
|
|
26
|
-
BASE_URL: '/',
|
|
27
|
-
DEV: true,
|
|
28
|
-
MODE: 'development',
|
|
29
|
-
PROD: false,
|
|
30
|
-
SSR: true
|
|
31
|
-
};
|
|
25
|
+
|
|
32
26
|
|
|
33
27
|
/**
|
|
34
28
|
* Initializes the CSS loader with the necessary communication channels.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { LoadHookContext } from "node:module";
|
|
2
|
+
import type { LoaderContext } from "../types.js";
|
|
3
|
+
import type { MessagePort } from "node:worker_threads";
|
|
4
|
+
import type { ResolvedConfig } from "vite";
|
|
5
|
+
|
|
6
|
+
export let loaderPort: MessagePort | undefined;
|
|
7
|
+
let resolvedConfig: ResolvedConfig | undefined;
|
|
8
|
+
|
|
9
|
+
// Initialize hook
|
|
10
|
+
export async function initialize(data: { port: MessagePort, resolvedConfig: ResolvedConfig }) {
|
|
11
|
+
loaderPort = data.port;
|
|
12
|
+
resolvedConfig = data.resolvedConfig;
|
|
13
|
+
data.port.postMessage({ type: "INITIALIZED_ENV_LOADER" });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Load hook
|
|
17
|
+
export async function load(
|
|
18
|
+
url: string,
|
|
19
|
+
context: LoadHookContext & LoaderContext,
|
|
20
|
+
nextLoad: any
|
|
21
|
+
) {
|
|
22
|
+
const result = await nextLoad(url, context);
|
|
23
|
+
|
|
24
|
+
// Skip if not a module
|
|
25
|
+
if (result.format !== "module") {
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Skip node internals and hidden files
|
|
30
|
+
if (url.startsWith('node:') || url.includes('/.')) {
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Convert source to string if it's a Buffer or Uint8Array
|
|
35
|
+
let sourceStr: string;
|
|
36
|
+
if (typeof result.source === "string") {
|
|
37
|
+
sourceStr = result.source;
|
|
38
|
+
} else if (result.source instanceof Uint8Array || Buffer.isBuffer(result.source)) {
|
|
39
|
+
sourceStr = result.source.toString("utf-8");
|
|
40
|
+
} else {
|
|
41
|
+
console.warn(`[env-loader] Unexpected source type: ${typeof result.source}`);
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Get define object from resolved config
|
|
46
|
+
const define = resolvedConfig?.define || {};
|
|
47
|
+
|
|
48
|
+
// Create the env object with Vite's default environment variables
|
|
49
|
+
const envObject = {
|
|
50
|
+
MODE: resolvedConfig?.mode || 'development',
|
|
51
|
+
BASE_URL: resolvedConfig?.base || '/',
|
|
52
|
+
PROD: resolvedConfig?.isProduction ? true : false,
|
|
53
|
+
DEV: resolvedConfig?.isProduction ? false : true,
|
|
54
|
+
SSR: true,
|
|
55
|
+
...Object.fromEntries(
|
|
56
|
+
Object.entries(define)
|
|
57
|
+
.filter(([key]) => key.startsWith('import.meta.env.'))
|
|
58
|
+
.map(([key, value]) => [key.replace('import.meta.env.', ''), JSON.parse(value as string)])
|
|
59
|
+
)
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Replace environment variable references in the source
|
|
63
|
+
let newSource = sourceStr;
|
|
64
|
+
|
|
65
|
+
// Check if we need to handle import.meta.env
|
|
66
|
+
if (newSource.includes('import.meta.env')) {
|
|
67
|
+
newSource = `Object.defineProperty(import.meta, "env", { value: ${JSON.stringify(envObject)}, writable: false, configurable: false });\n${newSource}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
...result,
|
|
72
|
+
source: newSource
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Transform hook
|
|
77
|
+
export async function transformSource(
|
|
78
|
+
source: string,
|
|
79
|
+
context: any,
|
|
80
|
+
defaultTransformSource: any
|
|
81
|
+
) {
|
|
82
|
+
const transformed = await defaultTransformSource(source, context, defaultTransformSource);
|
|
83
|
+
return transformed;
|
|
84
|
+
}
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
type LoadHookContext,
|
|
9
9
|
type ResolveHookContext,
|
|
10
10
|
} from "node:module";
|
|
11
|
-
import { workerData } from "node:worker_threads";
|
|
12
11
|
import type { MessagePort } from "node:worker_threads";
|
|
13
12
|
import type { LoaderContext } from "../types.js";
|
|
13
|
+
import { env } from '../utils/env.js';
|
|
14
14
|
|
|
15
15
|
let stashedGetSource: any = null;
|
|
16
16
|
let stashedResolve: any = null;
|
|
@@ -21,15 +21,6 @@ setSourceMapsSupport(true, {
|
|
|
21
21
|
generatedCode: true, // Enable for generated code
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
// Get environment variables from workerData or import.meta
|
|
25
|
-
const env = workerData?.importMeta?.env ||
|
|
26
|
-
import.meta?.env || {
|
|
27
|
-
BASE_URL: "/",
|
|
28
|
-
DEV: false,
|
|
29
|
-
MODE: "production",
|
|
30
|
-
PROD: true,
|
|
31
|
-
SSR: true,
|
|
32
|
-
};
|
|
33
24
|
|
|
34
25
|
// Store port globally for use in load hook
|
|
35
26
|
export let loaderPort: MessagePort | undefined;
|
|
@@ -12,7 +12,8 @@ export function formatMetrics(metrics: RenderMetrics): string {
|
|
|
12
12
|
} = metrics;
|
|
13
13
|
|
|
14
14
|
// Format memory usage in MB
|
|
15
|
-
const formatMemory = (bytes: number) =>
|
|
15
|
+
const formatMemory = (bytes: number) =>
|
|
16
|
+
`${(bytes / 1024 / 1024).toFixed(2)}MB`;
|
|
16
17
|
|
|
17
18
|
return `
|
|
18
19
|
Route: ${route}
|
|
@@ -32,6 +33,30 @@ Stream:
|
|
|
32
33
|
`.trim();
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
export function
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
export function metricWatcher({
|
|
37
|
+
maxTime = 200,
|
|
38
|
+
warnOnly = false,
|
|
39
|
+
warn = console.warn,
|
|
40
|
+
info = console.info,
|
|
41
|
+
}: {
|
|
42
|
+
maxTime?: number;
|
|
43
|
+
warnOnly?: boolean;
|
|
44
|
+
warn?: (...args: any[]) => void;
|
|
45
|
+
info?: (...args: any[]) => void;
|
|
46
|
+
}) {
|
|
47
|
+
return (metrics: RenderMetrics) => {
|
|
48
|
+
if (metrics.processingTime > maxTime) {
|
|
49
|
+
warn(`It took over ${maxTime}ms to render ${metrics.route}`);
|
|
50
|
+
warn(formatMetrics(metrics));
|
|
51
|
+
} else if (!warnOnly) {
|
|
52
|
+
const rounded = Math.round(metrics.processingTime);
|
|
53
|
+
if (rounded === 0) {
|
|
54
|
+
// smaller unit of time
|
|
55
|
+
const rounded = Math.round(metrics.processingTime * 1000);
|
|
56
|
+
info(`${metrics.route} (${rounded}μs)`);
|
|
57
|
+
} else {
|
|
58
|
+
info(`${metrics.route} (${rounded}ms)`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
package/plugin/plugin.client.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { reactPreservePlugin } from "./preserver/plugin.js";
|
|
|
2
2
|
import { reactTransformPlugin } from "./transformer/plugin.client.js";
|
|
3
3
|
import type { StreamPluginOptions } from "../types.js";
|
|
4
4
|
import { reactClientPlugin } from "./react-client/plugin.js";
|
|
5
|
+
import { envPlugin } from "./env/plugin.js";
|
|
5
6
|
|
|
6
7
|
export function vitePluginReactServer(options = {} as StreamPluginOptions): import("vite").Plugin[] {
|
|
7
8
|
return [
|
|
9
|
+
envPlugin(),
|
|
8
10
|
reactClientPlugin(options),
|
|
9
11
|
reactTransformPlugin(options),
|
|
10
12
|
reactPreservePlugin(options),
|
package/plugin/plugin.server.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { reactStaticPlugin } from "./react-static/plugin.js";
|
|
|
3
3
|
import { reactTransformPlugin } from "./transformer/plugin.server.js";
|
|
4
4
|
import type { StreamPluginOptions } from "./types.js";
|
|
5
5
|
import { reactServerPlugin } from "./react-server/plugin.js";
|
|
6
|
+
import { envPlugin } from "./env/plugin.js";
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
export function vitePluginReactServer(
|
|
@@ -11,12 +12,14 @@ export function vitePluginReactServer(
|
|
|
11
12
|
if(!options.build?.pages || (Array.isArray(options.build.pages) && options.build.pages.length === 0)) {
|
|
12
13
|
// in this case we do not need the static plugin at all
|
|
13
14
|
return [
|
|
15
|
+
envPlugin(),
|
|
14
16
|
reactTransformPlugin(options),
|
|
15
17
|
reactServerPlugin(options),
|
|
16
18
|
reactPreservePlugin(options),
|
|
17
19
|
];
|
|
18
20
|
}
|
|
19
21
|
return [
|
|
22
|
+
envPlugin(),
|
|
20
23
|
reactTransformPlugin(options),
|
|
21
24
|
reactServerPlugin(options),
|
|
22
25
|
reactStaticPlugin(options),
|
package/plugin/plugin.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { getCondition } from './config/getCondition.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
export const { vitePluginReactServer } = await import(`./plugin.${condition}.js`);
|
|
3
|
+
export const { vitePluginReactServer } = await import(`./plugin.${getCondition('')}.js`);
|