vite-plugin-react-server 1.1.19 → 1.2.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -395
- package/dist/_virtual/dynamic-import-helper.js +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +5 -2
- package/dist/index.js +1 -1
- package/dist/package.json +58 -25
- package/dist/plugin/components/{css-collector-elements.d.ts → css.d.ts} +2 -2
- package/dist/plugin/components/css.d.ts.map +1 -0
- package/dist/plugin/components/css.js +33 -0
- 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 +5 -5
- package/dist/plugin/components/index.d.ts +3 -3
- package/dist/plugin/components/index.d.ts.map +1 -1
- package/dist/plugin/components/index.js +9 -3
- package/dist/plugin/components/root.d.ts +7 -0
- package/dist/plugin/components/root.d.ts.map +1 -0
- package/dist/plugin/components/root.js +18 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js +1 -1
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js +1 -1
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts +5 -4
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js +26 -7
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts +25 -2
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +84 -5
- package/dist/plugin/config/createModuleID.d.ts +3 -6
- package/dist/plugin/config/createModuleID.d.ts.map +1 -1
- package/dist/plugin/config/createModuleID.js +42 -32
- package/dist/plugin/config/defaults.d.ts +199 -121
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +155 -89
- package/dist/plugin/config/extMap.d.ts +6 -2
- package/dist/plugin/config/extMap.d.ts.map +1 -1
- package/dist/plugin/config/extMap.js +38 -48
- package/dist/plugin/config/flightBindings.d.ts +4 -0
- package/dist/plugin/config/flightBindings.d.ts.map +1 -0
- package/dist/plugin/config/flightBindings.js +215 -0
- package/dist/plugin/config/getCondition.d.ts +2 -0
- package/dist/plugin/config/getCondition.d.ts.map +1 -1
- package/dist/plugin/config/getCondition.js +4 -2
- package/dist/plugin/config/getPaths.js +1 -1
- package/dist/plugin/config/index.d.ts +17 -4
- package/dist/plugin/config/index.d.ts.map +1 -1
- package/dist/plugin/config/index.js +29 -7
- package/dist/plugin/config/interpolatePattern.d.ts +13 -0
- package/dist/plugin/config/interpolatePattern.d.ts.map +1 -0
- package/dist/plugin/config/interpolatePattern.js +13 -0
- package/dist/plugin/config/mimeTypes.js +1 -1
- package/dist/plugin/config/parsePattern.d.ts +25 -0
- package/dist/plugin/config/parsePattern.d.ts.map +1 -0
- package/dist/plugin/config/parsePattern.js +30 -0
- package/dist/plugin/config/resolveAllowedDirectives.d.ts +26 -0
- package/dist/plugin/config/resolveAllowedDirectives.d.ts.map +1 -0
- package/dist/plugin/config/resolveAllowedDirectives.js +35 -0
- package/dist/plugin/config/resolveDirectiveMatcher.d.ts +25 -0
- package/dist/plugin/config/resolveDirectiveMatcher.d.ts.map +1 -0
- package/dist/plugin/config/resolveDirectiveMatcher.js +33 -0
- package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
- package/dist/plugin/config/resolveEnv.js +14 -4
- package/dist/plugin/config/resolveOptions.d.ts +13 -3
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +228 -206
- package/dist/plugin/config/resolvePages.js +1 -1
- package/dist/plugin/config/resolvePatternWithValues.d.ts +39 -0
- package/dist/plugin/config/resolvePatternWithValues.d.ts.map +1 -0
- package/dist/plugin/config/resolvePatternWithValues.js +36 -0
- package/dist/plugin/config/resolveRegExp.d.ts +29 -0
- package/dist/plugin/config/resolveRegExp.d.ts.map +1 -0
- package/dist/plugin/config/resolveRegExp.js +39 -0
- package/dist/plugin/config/resolveUrlOption.d.ts +37 -6
- package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -1
- package/dist/plugin/config/resolveUrlOption.js +42 -12
- package/dist/plugin/config/resolveUserConfig.d.ts +5 -4
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +86 -40
- package/dist/plugin/env/plugin.d.ts +6 -0
- package/dist/plugin/env/plugin.d.ts.map +1 -1
- package/dist/plugin/env/plugin.js +111 -93
- package/dist/plugin/error/directiveError.d.ts +13 -0
- package/dist/plugin/error/directiveError.d.ts.map +1 -0
- package/dist/plugin/error/directiveError.js +21 -0
- package/dist/plugin/error/enhanceError.d.ts +14 -0
- package/dist/plugin/error/enhanceError.d.ts.map +1 -0
- package/dist/plugin/error/enhanceError.js +24 -0
- package/dist/plugin/error/index.d.ts +4 -0
- package/dist/plugin/error/index.d.ts.map +1 -0
- package/dist/plugin/error/index.js +9 -0
- package/dist/plugin/error/logError.d.ts +3 -0
- package/dist/plugin/error/logError.d.ts.map +1 -0
- package/dist/plugin/error/logError.js +47 -0
- package/dist/plugin/error/serializeError.d.ts +7 -0
- package/dist/plugin/error/serializeError.d.ts.map +1 -0
- package/dist/plugin/error/serializeError.js +37 -0
- package/dist/plugin/error/toError.d.ts +1 -8
- package/dist/plugin/error/toError.d.ts.map +1 -1
- package/dist/plugin/error/toError.js +62 -34
- package/dist/plugin/file-preserver/plugin.js +93 -105
- package/dist/plugin/getNodeEnv.d.ts +11 -0
- package/dist/plugin/getNodeEnv.d.ts.map +1 -0
- package/dist/plugin/getNodeEnv.js +17 -0
- package/dist/plugin/helpers/cleanObject.d.ts.map +1 -1
- package/dist/plugin/helpers/cleanObject.js +2 -1
- package/dist/plugin/helpers/collectManifestCss.js +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +6 -4
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.js +15 -9
- package/dist/plugin/helpers/createCssProps.d.ts +3 -4
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
- package/dist/plugin/helpers/createCssProps.js +16 -4
- package/dist/plugin/helpers/createEventHandler.d.ts +2 -2
- package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createEventHandler.js +1 -1
- package/dist/plugin/helpers/createHandler.d.ts +10 -8
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createHandler.js +11 -5
- package/dist/plugin/helpers/createRscStream.d.ts +18 -5
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
- package/dist/plugin/helpers/createRscStream.js +48 -14
- package/dist/plugin/helpers/formatMetrics.d.ts +1 -5
- package/dist/plugin/helpers/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/helpers/formatMetrics.js +2 -39
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +9 -2
- package/dist/plugin/helpers/getRouteFiles.d.ts +30 -2
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.js +70 -7
- package/dist/plugin/helpers/handleServerAction.d.ts +8 -7
- package/dist/plugin/helpers/handleServerAction.d.ts.map +1 -1
- package/dist/plugin/helpers/handleServerAction.js +5 -2
- package/dist/plugin/helpers/hydrateUserOptions.d.ts +9 -0
- package/dist/plugin/helpers/hydrateUserOptions.d.ts.map +1 -0
- package/dist/plugin/helpers/hydrateUserOptions.js +22 -0
- package/dist/plugin/helpers/index.d.ts +2 -0
- package/dist/plugin/helpers/index.d.ts.map +1 -1
- package/dist/plugin/helpers/index.js +31 -31
- package/dist/plugin/helpers/inputNormalizer.d.ts +1 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +33 -20
- package/dist/plugin/helpers/metrics.d.ts +4 -10
- package/dist/plugin/helpers/metrics.d.ts.map +1 -1
- package/dist/plugin/helpers/metrics.js +3 -59
- package/dist/plugin/helpers/moduleRefs.js +1 -1
- package/dist/plugin/helpers/moduleResolver.d.ts +24 -2
- package/dist/plugin/helpers/moduleResolver.d.ts.map +1 -1
- package/dist/plugin/helpers/moduleResolver.js +61 -22
- package/dist/plugin/helpers/requestInfo.d.ts +28 -1
- package/dist/plugin/helpers/requestInfo.d.ts.map +1 -1
- package/dist/plugin/helpers/requestInfo.js +43 -30
- package/dist/plugin/helpers/requestToRoute.d.ts +1 -1
- package/dist/plugin/helpers/requestToRoute.d.ts.map +1 -1
- package/dist/plugin/helpers/requestToRoute.js +17 -9
- package/dist/plugin/helpers/resolveComponent.d.ts +57 -0
- package/dist/plugin/helpers/resolveComponent.d.ts.map +1 -0
- package/dist/plugin/helpers/resolveComponent.js +71 -0
- package/dist/plugin/helpers/resolveComponents.d.ts +27 -0
- package/dist/plugin/helpers/resolveComponents.d.ts.map +1 -0
- package/dist/plugin/helpers/resolveComponents.js +137 -0
- package/dist/plugin/helpers/resolvePage.d.ts +15 -11
- package/dist/plugin/helpers/resolvePage.d.ts.map +1 -1
- package/dist/plugin/helpers/resolvePage.js +11 -7
- package/dist/plugin/helpers/resolvePageAndProps.d.ts +3 -10
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
- package/dist/plugin/helpers/resolvePageAndProps.js +28 -18
- package/dist/plugin/helpers/resolveProps.d.ts +13 -7
- package/dist/plugin/helpers/resolveProps.d.ts.map +1 -1
- package/dist/plugin/helpers/resolveProps.js +55 -25
- package/dist/plugin/helpers/resolveUserComponents.d.ts +33 -0
- package/dist/plugin/helpers/resolveUserComponents.d.ts.map +1 -0
- package/dist/plugin/helpers/resolveUserComponents.js +163 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts +7 -7
- package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -1
- package/dist/plugin/helpers/serializeUserOptions.js +127 -42
- package/dist/plugin/helpers/stashReturnValue.d.ts +2 -1
- package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -1
- package/dist/plugin/helpers/stashReturnValue.js +6 -3
- package/dist/plugin/helpers/tryManifest.d.ts +1 -2
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +1 -1
- package/dist/plugin/loader/createDefaultLoader.d.ts +19 -8
- package/dist/plugin/loader/createDefaultLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createDefaultLoader.js +69 -107
- package/dist/plugin/loader/createTransformer.d.ts +6 -0
- package/dist/plugin/loader/createTransformer.d.ts.map +1 -0
- package/dist/plugin/loader/createTransformer.js +97 -0
- package/dist/plugin/loader/{css-loader.development.d.ts → css-loader.d.ts} +6 -8
- package/dist/plugin/loader/css-loader.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.js +134 -0
- package/dist/plugin/loader/directives/addLocalExportedNames.d.ts +4 -0
- package/dist/plugin/loader/directives/addLocalExportedNames.d.ts.map +1 -0
- package/dist/plugin/loader/directives/addLocalExportedNames.js +57 -0
- package/dist/plugin/loader/directives/analyzeDirectives.d.ts +9 -0
- package/dist/plugin/loader/directives/analyzeDirectives.d.ts.map +1 -0
- package/dist/plugin/loader/directives/analyzeDirectives.js +221 -0
- package/dist/plugin/loader/directives/analyzeModule.d.ts +11 -0
- package/dist/plugin/loader/directives/analyzeModule.d.ts.map +1 -0
- package/dist/plugin/loader/directives/analyzeModule.js +34 -0
- package/dist/plugin/loader/directives/collectExports.d.ts +13 -0
- package/dist/plugin/loader/directives/collectExports.d.ts.map +1 -0
- package/dist/plugin/loader/directives/collectExports.js +116 -0
- package/dist/plugin/loader/directives/collectExportsFromModule.d.ts +6 -0
- package/dist/plugin/loader/directives/collectExportsFromModule.d.ts.map +1 -0
- package/dist/plugin/loader/directives/collectExportsFromModule.js +24 -0
- package/dist/plugin/loader/directives/findDirectiveMatches.d.ts +3 -0
- package/dist/plugin/loader/directives/findDirectiveMatches.d.ts.map +1 -0
- package/dist/plugin/loader/directives/findDirectiveMatches.js +46 -0
- package/dist/plugin/loader/directives/getExportedName.d.ts +3 -0
- package/dist/plugin/loader/directives/getExportedName.d.ts.map +1 -0
- package/dist/plugin/loader/directives/getExportedName.js +59 -0
- package/dist/plugin/loader/directives/getExports.d.ts +7 -0
- package/dist/plugin/loader/directives/getExports.d.ts.map +1 -0
- package/dist/plugin/loader/directives/getExports.js +28 -0
- package/dist/plugin/loader/directives/getFunctionBody.d.ts +3 -0
- package/dist/plugin/loader/directives/getFunctionBody.d.ts.map +1 -0
- package/dist/plugin/loader/directives/getFunctionBody.js +31 -0
- package/dist/plugin/loader/directives/getFunctionName.d.ts +10 -0
- package/dist/plugin/loader/directives/getFunctionName.d.ts.map +1 -0
- package/dist/plugin/loader/directives/getFunctionName.js +42 -0
- package/dist/plugin/loader/directives/getQualifiedName.d.ts +3 -0
- package/dist/plugin/loader/directives/getQualifiedName.d.ts.map +1 -0
- package/dist/plugin/loader/directives/getQualifiedName.js +65 -0
- package/dist/plugin/loader/directives/index.d.ts +14 -0
- package/dist/plugin/loader/directives/index.d.ts.map +1 -0
- package/dist/plugin/loader/directives/index.js +18 -0
- package/dist/plugin/loader/directives/processFunctionNode.d.ts +4 -0
- package/dist/plugin/loader/directives/processFunctionNode.d.ts.map +1 -0
- package/dist/plugin/loader/directives/processFunctionNode.js +86 -0
- package/dist/plugin/loader/directives/typeGuards.d.ts +37 -0
- package/dist/plugin/loader/directives/typeGuards.d.ts.map +1 -0
- package/dist/plugin/loader/directives/typeGuards.js +100 -0
- package/dist/plugin/loader/directives/types.d.ts +154 -0
- package/dist/plugin/loader/directives/types.d.ts.map +1 -0
- package/dist/plugin/loader/directives/utils.d.ts +14 -0
- package/dist/plugin/loader/directives/utils.d.ts.map +1 -0
- package/dist/plugin/loader/directives/utils.js +21 -0
- package/dist/plugin/loader/env-loader.d.ts +11 -0
- package/dist/plugin/loader/env-loader.d.ts.map +1 -0
- package/dist/plugin/loader/env-loader.js +65 -0
- package/dist/plugin/loader/index.d.ts +8 -1
- package/dist/plugin/loader/index.d.ts.map +1 -1
- package/dist/plugin/loader/index.js +13 -4
- package/dist/plugin/loader/parse.d.ts +11 -2
- package/dist/plugin/loader/parse.d.ts.map +1 -1
- package/dist/plugin/loader/parse.js +29 -6
- package/dist/plugin/loader/react-loader.d.ts +22 -1
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +169 -6
- package/dist/plugin/loader/removeDirectives.d.ts +5 -0
- package/dist/plugin/loader/removeDirectives.d.ts.map +1 -0
- package/dist/plugin/loader/removeDirectives.js +17 -0
- package/dist/plugin/loader/removeRanges.d.ts +5 -0
- package/dist/plugin/loader/removeRanges.d.ts.map +1 -0
- package/dist/plugin/loader/removeRanges.js +20 -0
- package/dist/plugin/loader/sourceMap.d.ts +16 -24
- package/dist/plugin/loader/sourceMap.d.ts.map +1 -1
- package/dist/plugin/loader/sourceMap.js +125 -97
- package/dist/plugin/loader/transformClientModule.d.ts +10 -0
- package/dist/plugin/loader/transformClientModule.d.ts.map +1 -0
- package/dist/plugin/loader/transformClientModule.js +46 -0
- package/dist/plugin/loader/transformModule.d.ts +6 -0
- package/dist/plugin/loader/transformModule.d.ts.map +1 -0
- package/dist/plugin/loader/transformModule.js +33 -0
- package/dist/plugin/loader/transformModuleIfNeeded.d.ts +12 -1
- package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.js +9 -20
- package/dist/plugin/loader/transformServerModule.d.ts +11 -0
- package/dist/plugin/loader/transformServerModule.d.ts.map +1 -0
- package/dist/plugin/loader/transformServerModule.js +84 -0
- package/dist/plugin/loader/transformWithAcornLoose.d.ts +12 -0
- package/dist/plugin/loader/transformWithAcornLoose.d.ts.map +1 -0
- package/dist/plugin/loader/transformWithAcornLoose.js +18 -0
- package/dist/plugin/loader/types.d.ts +59 -12
- package/dist/plugin/loader/types.d.ts.map +1 -1
- package/dist/plugin/metrics/collectStreamMetrics.d.ts +9 -0
- package/dist/plugin/metrics/collectStreamMetrics.d.ts.map +1 -0
- package/dist/plugin/metrics/collectStreamMetrics.js +35 -0
- package/dist/plugin/metrics/createRenderMetrics.d.ts +3 -0
- package/dist/plugin/metrics/createRenderMetrics.d.ts.map +1 -0
- package/dist/plugin/metrics/createRenderMetrics.js +24 -0
- package/dist/plugin/metrics/createStreamMetrics.d.ts +3 -0
- package/dist/plugin/metrics/createStreamMetrics.d.ts.map +1 -0
- package/dist/plugin/metrics/createStreamMetrics.js +19 -0
- package/dist/plugin/metrics/formatMetrics.d.ts +6 -3
- package/dist/plugin/metrics/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/metrics/formatMetrics.js +5 -2
- package/dist/plugin/metrics/index.d.ts +3 -1
- package/dist/plugin/metrics/index.d.ts.map +1 -1
- package/dist/plugin/metrics/index.js +9 -1
- package/dist/plugin/metrics/types.d.ts +23 -0
- package/dist/plugin/metrics/types.d.ts.map +1 -0
- package/dist/plugin/metrics/types.js +1 -0
- package/dist/plugin/plugin.client.d.ts +23 -2
- package/dist/plugin/plugin.client.d.ts.map +1 -1
- package/dist/plugin/plugin.client.js +30 -17
- package/dist/plugin/plugin.server.d.ts +13 -2
- package/dist/plugin/plugin.server.d.ts.map +1 -1
- package/dist/plugin/plugin.server.js +7 -4
- 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 +33 -29
- package/dist/plugin/react-client/cleanupWorkerServerAction.d.ts +11 -0
- package/dist/plugin/react-client/cleanupWorkerServerAction.d.ts.map +1 -0
- package/dist/plugin/react-client/cleanupWorkerServerAction.js +18 -0
- package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts +9 -9
- package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -1
- package/dist/plugin/react-client/configureWorkerRequestHandler.js +25 -14
- 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 +15 -3
- package/dist/plugin/react-client/createWorkerStream.d.ts +12 -10
- package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.js +27 -29
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts +13 -8
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.js +59 -24
- package/dist/plugin/react-client/handleWorkerServerAction.d.ts +2 -1
- package/dist/plugin/react-client/handleWorkerServerAction.d.ts.map +1 -1
- package/dist/plugin/react-client/handleWorkerServerAction.js +43 -28
- package/dist/plugin/react-client/index.d.ts +4 -1
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +10 -1
- package/dist/plugin/react-client/plugin.d.ts +5 -3
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +9 -11
- package/dist/plugin/react-client/restartWorker.d.ts +5 -4
- package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
- package/dist/plugin/react-client/restartWorker.js +12 -10
- package/dist/plugin/react-server/configureReactServer.d.ts +5 -4
- package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -1
- package/dist/plugin/react-server/configureReactServer.js +98 -43
- package/dist/plugin/react-server/handleServerAction.d.ts +3 -2
- package/dist/plugin/react-server/handleServerAction.d.ts.map +1 -1
- package/dist/plugin/react-server/handleServerAction.js +14 -20
- package/dist/plugin/react-server/plugin.d.ts +3 -4
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +14 -17
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +8 -6
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.js +4 -4
- package/dist/plugin/react-static/collectRscContent.d.ts +8 -6
- package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -1
- package/dist/plugin/react-static/collectRscContent.js +4 -4
- package/dist/plugin/react-static/configurePreviewServer.d.ts +6 -4
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js +38 -31
- package/dist/plugin/react-static/createBuildLoader.d.ts +5 -5
- package/dist/plugin/react-static/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/react-static/createBuildLoader.js +122 -30
- package/dist/plugin/react-static/fileWriter.js +1 -1
- package/dist/plugin/react-static/plugin.d.ts +3 -4
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +62 -47
- package/dist/plugin/react-static/renderPage.d.ts +4 -2
- package/dist/plugin/react-static/renderPage.d.ts.map +1 -1
- package/dist/plugin/react-static/renderPage.js +33 -17
- package/dist/plugin/react-static/renderPages.d.ts +4 -2
- package/dist/plugin/react-static/renderPages.d.ts.map +1 -1
- package/dist/plugin/react-static/renderPages.js +7 -6
- package/dist/plugin/react-static/renderStreams.d.ts +5 -22
- package/dist/plugin/react-static/renderStreams.d.ts.map +1 -1
- package/dist/plugin/react-static/renderStreams.js +6 -6
- package/dist/plugin/react-static/rscToHtmlStream.d.ts.map +1 -1
- package/dist/plugin/react-static/rscToHtmlStream.js +1 -1
- package/dist/plugin/react-static/temporaryReferences.js +1 -1
- package/dist/plugin/react-static/types.d.ts +0 -1
- package/dist/plugin/react-static/types.d.ts.map +1 -1
- package/dist/plugin/root.js +1 -1
- package/dist/plugin/transformer/plugin.js +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts +5 -3
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.server.js +43 -44
- package/dist/plugin/types/css-tracking.d.ts +2 -2
- package/dist/plugin/types/css-tracking.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +452 -192
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/types.js +2 -1
- package/dist/plugin/utils/callServer.js +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 +1 -1
- package/dist/plugin/utils/createReactFetcher.d.ts +2 -3
- package/dist/plugin/utils/createReactFetcher.d.ts.map +1 -1
- package/dist/plugin/utils/createReactFetcher.js +1 -1
- package/dist/plugin/utils/env.js +1 -1
- package/dist/plugin/utils/envUrls.node.js +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 +12 -5
- package/dist/plugin/utils/routeToURL.d.ts +12 -0
- package/dist/plugin/utils/routeToURL.d.ts.map +1 -0
- package/dist/plugin/utils/routeToURL.js +26 -0
- package/dist/plugin/utils/urls.d.ts.map +1 -1
- package/dist/plugin/utils/urls.js +5 -3
- package/dist/plugin/vendor/index.js +7 -1
- package/dist/plugin/vendor/vendor.client.js +1 -1
- package/dist/plugin/vendor/vendor.js +1 -1
- package/dist/plugin/vendor/vendor.server.js +1 -1
- package/dist/plugin/worker/createWorker.d.ts +31 -17
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +18 -12
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts +2 -2
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +5 -2
- package/dist/plugin/worker/html/html-worker.development.js +3 -3
- package/dist/plugin/worker/html/html-worker.production.js +1 -1
- package/dist/plugin/worker/html/index.d.ts +1 -1
- package/dist/plugin/worker/html/index.d.ts.map +1 -1
- package/dist/plugin/worker/html/index.js +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +9 -11
- package/dist/plugin/worker/html/sendHtmlWorkerMessage.d.ts +3 -0
- package/dist/plugin/worker/html/sendHtmlWorkerMessage.d.ts.map +1 -0
- package/dist/plugin/worker/html/sendHtmlWorkerMessage.js +2 -0
- package/dist/plugin/worker/html/types.d.ts +20 -2
- package/dist/plugin/worker/html/types.d.ts.map +1 -1
- package/dist/plugin/worker/index.d.ts +3 -0
- package/dist/plugin/worker/index.d.ts.map +1 -0
- package/dist/plugin/worker/index.js +7 -0
- package/dist/plugin/worker/registerLoaders.js +2 -2
- package/dist/plugin/worker/rsc/handleRender.d.ts +4 -3
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.js +54 -32
- package/dist/plugin/worker/rsc/handlers.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handlers.js +19 -15
- package/dist/plugin/worker/rsc/index.d.ts +1 -1
- package/dist/plugin/worker/rsc/index.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/index.js +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +16 -4
- package/dist/plugin/worker/rsc/rsc-worker.development.js +77 -11
- package/dist/plugin/worker/rsc/rsc-worker.production.js +1 -1
- package/dist/plugin/worker/rsc/sendRscWorkerMessage.d.ts +3 -0
- package/dist/plugin/worker/rsc/sendRscWorkerMessage.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/sendRscWorkerMessage.js +11 -0
- package/dist/plugin/worker/rsc/state.js +1 -1
- package/dist/plugin/worker/rsc/types.d.ts +95 -0
- package/dist/plugin/worker/rsc/types.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/types.js +1 -0
- package/dist/plugin/worker/rsc/userOptions.d.ts +1 -1
- package/dist/plugin/worker/rsc/userOptions.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/userOptions.js +3 -4
- package/dist/plugin/worker/sendMessage.d.ts +3 -4
- package/dist/plugin/worker/sendMessage.d.ts.map +1 -1
- package/dist/plugin/worker/sendMessage.js +15 -5
- package/dist/plugin/worker/types.d.ts +109 -260
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +58 -25
- package/plugin/components/{css-collector-elements.tsx → css.tsx} +3 -3
- package/plugin/components/html.tsx +4 -4
- package/plugin/components/index.ts +3 -3
- package/plugin/components/root.tsx +20 -0
- package/plugin/config/autoDiscover/resolveAutoDiscover.ts +173 -134
- package/plugin/config/autoDiscover/resolveBuildPages.ts +120 -7
- package/plugin/config/createModuleID.ts +60 -39
- package/plugin/config/defaults.tsx +184 -95
- package/plugin/config/extMap.ts +51 -56
- package/plugin/config/flightBindings.ts +221 -0
- package/plugin/config/getCondition.ts +6 -0
- package/plugin/config/index.ts +17 -4
- package/plugin/config/interpolatePattern.ts +19 -0
- package/plugin/config/parsePattern.ts +81 -0
- package/plugin/config/resolveAllowedDirectives.ts +59 -0
- package/plugin/config/resolveDirectiveMatcher.ts +57 -0
- package/plugin/config/resolveEnv.ts +5 -10
- package/plugin/config/resolveOptions.ts +415 -299
- package/plugin/config/resolvePatternWithValues.ts +70 -0
- package/plugin/config/resolveRegExp.ts +89 -0
- package/plugin/config/resolveUrlOption.ts +92 -20
- package/plugin/config/resolveUserConfig.ts +417 -351
- package/plugin/env/plugin.ts +71 -7
- package/plugin/error/directiveError.ts +29 -0
- package/plugin/error/enhanceError.ts +41 -0
- package/plugin/error/index.ts +3 -0
- package/plugin/error/logError.ts +45 -0
- package/plugin/error/serializeError.ts +34 -0
- package/plugin/error/toError.ts +75 -45
- package/plugin/file-preserver/plugin.ts +3 -3
- package/plugin/getNodeEnv.ts +24 -0
- package/plugin/helpers/cleanObject.ts +2 -1
- package/plugin/helpers/collectViteModuleGraphCss.ts +138 -118
- package/plugin/helpers/createCssProps.tsx +41 -20
- package/plugin/helpers/createEventHandler.ts +1 -1
- package/plugin/helpers/createHandler.ts +40 -12
- package/plugin/helpers/createRscStream.tsx +97 -35
- package/plugin/helpers/formatMetrics.ts +2 -37
- package/plugin/helpers/getBundleManifest.ts +10 -1
- package/plugin/helpers/getRouteFiles.ts +112 -8
- package/plugin/helpers/handleServerAction.ts +10 -6
- package/plugin/helpers/hydrateUserOptions.ts +23 -0
- package/plugin/helpers/index.ts +4 -0
- package/plugin/helpers/inputNormalizer.ts +44 -24
- package/plugin/helpers/metrics.ts +4 -64
- package/plugin/helpers/moduleResolver.ts +74 -19
- package/plugin/helpers/requestInfo.ts +72 -52
- package/plugin/helpers/requestToRoute.ts +38 -12
- package/plugin/helpers/resolveComponent.ts +173 -0
- package/plugin/helpers/resolveComponents.ts +185 -0
- package/plugin/helpers/resolvePage.ts +35 -29
- package/plugin/helpers/resolvePageAndProps.ts +82 -61
- package/plugin/helpers/resolveProps.ts +100 -37
- package/plugin/helpers/resolveUserComponents.ts +190 -0
- package/plugin/helpers/serializeUserOptions.ts +190 -69
- package/plugin/helpers/stashReturnValue.ts +7 -4
- package/plugin/helpers/tryManifest.ts +1 -1
- package/plugin/loader/createDefaultLoader.ts +119 -119
- package/plugin/loader/createTransformer.ts +118 -0
- package/plugin/loader/css-loader.ts +206 -0
- package/plugin/loader/directives/addLocalExportedNames.ts +78 -0
- package/plugin/loader/directives/analyzeDirectives.ts +298 -0
- package/plugin/loader/directives/analyzeModule.ts +39 -0
- package/plugin/loader/directives/collectExports.ts +181 -0
- package/plugin/loader/directives/collectExportsFromModule.ts +25 -0
- package/plugin/loader/directives/findDirectiveMatches.ts +58 -0
- package/plugin/loader/directives/getExportedName.ts +73 -0
- package/plugin/loader/directives/getExports.ts +27 -0
- package/plugin/loader/directives/getFunctionBody.ts +32 -0
- package/plugin/loader/directives/getFunctionName.ts +70 -0
- package/plugin/loader/directives/getQualifiedName.ts +76 -0
- package/plugin/loader/directives/index.ts +13 -0
- package/plugin/loader/directives/processFunctionNode.ts +97 -0
- package/plugin/loader/directives/typeGuards.ts +160 -0
- package/plugin/loader/directives/types.ts +174 -0
- package/plugin/loader/directives/utils.ts +35 -0
- package/plugin/loader/{env-loader.development.ts → env-loader.ts} +8 -22
- package/plugin/loader/index.ts +8 -6
- package/plugin/loader/parse.ts +42 -12
- package/plugin/loader/react-loader.ts +255 -4
- package/plugin/loader/removeDirectives.ts +14 -0
- package/plugin/loader/removeRanges.ts +21 -0
- package/plugin/loader/sourceMap.ts +174 -84
- package/plugin/loader/transformClientModule.ts +64 -0
- package/plugin/loader/transformModule.ts +54 -0
- package/plugin/loader/transformModuleIfNeeded.ts +40 -40
- package/plugin/loader/transformServerModule.ts +136 -0
- package/plugin/loader/transformWithAcornLoose.ts +27 -0
- package/plugin/loader/types.ts +65 -13
- package/plugin/metrics/collectStreamMetrics.ts +38 -0
- package/plugin/metrics/createRenderMetrics.ts +17 -0
- package/plugin/metrics/createStreamMetrics.ts +14 -0
- package/plugin/metrics/formatMetrics.ts +7 -3
- package/plugin/metrics/index.ts +3 -1
- package/plugin/metrics/types.ts +24 -0
- package/plugin/plugin.client.ts +39 -15
- package/plugin/plugin.server.ts +39 -18
- package/plugin/preserver/plugin.ts +42 -42
- package/plugin/react-client/cleanupWorkerServerAction.ts +33 -0
- package/plugin/react-client/configureWorkerRequestHandler.ts +212 -201
- package/plugin/react-client/createMessageHandlers.ts +17 -3
- package/plugin/react-client/createWorkerStream.ts +55 -51
- package/plugin/react-client/handleWorkerRscStream.ts +141 -61
- package/plugin/react-client/handleWorkerServerAction.ts +59 -37
- package/plugin/react-client/index.ts +4 -1
- package/plugin/react-client/plugin.ts +17 -18
- package/plugin/react-client/restartWorker.ts +75 -70
- package/plugin/react-server/configureReactServer.ts +200 -142
- package/plugin/react-server/handleServerAction.ts +156 -160
- package/plugin/react-server/plugin.ts +18 -25
- package/plugin/react-static/collectHtmlWorkerContent.ts +109 -102
- package/plugin/react-static/collectRscContent.ts +55 -51
- package/plugin/react-static/configurePreviewServer.ts +110 -100
- package/plugin/react-static/createBuildLoader.ts +157 -48
- package/plugin/react-static/plugin.ts +368 -357
- package/plugin/react-static/renderPage.ts +43 -24
- package/plugin/react-static/renderPages.ts +21 -14
- package/plugin/react-static/renderStreams.ts +13 -15
- package/plugin/react-static/rscToHtmlStream.ts +4 -6
- package/plugin/react-static/types.ts +0 -3
- package/plugin/transformer/README.md +82 -8
- package/plugin/transformer/plugin.server.ts +55 -82
- package/plugin/types/css-tracking.ts +1 -1
- package/plugin/types/global.d.ts +2 -2
- package/plugin/types/react-server-dom-esm.d.ts +12 -13
- package/plugin/types.ts +685 -309
- package/plugin/utils/createCallServer.ts +5 -5
- package/plugin/utils/createReactFetcher.ts +4 -6
- package/plugin/utils/index.ts +2 -1
- package/plugin/utils/routeToURL.ts +34 -0
- package/plugin/utils/urls.ts +9 -6
- package/plugin/worker/createWorker.ts +67 -34
- package/plugin/worker/html/README.md +10 -0
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +7 -4
- package/plugin/worker/html/html-worker.development.tsx +4 -3
- package/plugin/worker/html/index.ts +3 -1
- package/plugin/worker/html/messageHandler.tsx +10 -16
- package/plugin/worker/html/sendHtmlWorkerMessage.ts +8 -0
- package/plugin/worker/html/types.ts +67 -1
- package/plugin/worker/index.ts +2 -0
- package/plugin/worker/registerLoaders.ts +3 -3
- package/plugin/worker/rsc/README.md +203 -1
- package/plugin/worker/rsc/handleRender.ts +76 -39
- package/plugin/worker/rsc/handlers.ts +30 -22
- package/plugin/worker/rsc/index.ts +2 -0
- package/plugin/worker/rsc/messageHandler.tsx +17 -10
- package/plugin/worker/rsc/rsc-worker.development.ts +104 -17
- package/plugin/worker/rsc/sendRscWorkerMessage.ts +7 -0
- package/plugin/worker/rsc/state.ts +1 -1
- package/plugin/worker/rsc/types.ts +185 -0
- package/plugin/worker/rsc/userOptions.ts +2 -3
- package/plugin/worker/sendMessage.ts +23 -14
- package/plugin/worker/types.ts +131 -386
- package/scripts/check-react-version.mjs +3 -3
- package/scripts/fix-unused-imports.mjs +77 -0
- package/tsconfig.json +1 -1
- package/dist/_virtual/dynamic-import-helper.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/plugin/components/css-collector-elements.d.ts.map +0 -1
- package/dist/plugin/components/css-collector-elements.js +0 -33
- package/dist/plugin/components/css-collector-elements.js.map +0 -1
- package/dist/plugin/components/css-collector.d.ts +0 -7
- package/dist/plugin/components/css-collector.d.ts.map +0 -1
- package/dist/plugin/components/css-collector.js +0 -18
- package/dist/plugin/components/css-collector.js.map +0 -1
- package/dist/plugin/components/html.js.map +0 -1
- package/dist/plugin/components.js +0 -9
- package/dist/plugin/components.js.map +0 -1
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js.map +0 -1
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js.map +0 -1
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js.map +0 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +0 -1
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +0 -1
- package/dist/plugin/config/defaults.js.map +0 -1
- package/dist/plugin/config/extMap.js.map +0 -1
- package/dist/plugin/config/getCondition.js.map +0 -1
- package/dist/plugin/config/getPaths.js.map +0 -1
- package/dist/plugin/config/mimeTypes.js.map +0 -1
- package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts +0 -5
- package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts.map +0 -1
- package/dist/plugin/config/resolveAutoDiscoverMatcher.js +0 -25
- package/dist/plugin/config/resolveAutoDiscoverMatcher.js.map +0 -1
- package/dist/plugin/config/resolveEnv.js.map +0 -1
- package/dist/plugin/config/resolveOptions.js.map +0 -1
- package/dist/plugin/config/resolvePages.js.map +0 -1
- package/dist/plugin/config/resolveUrlOption.js.map +0 -1
- package/dist/plugin/config/resolveUserConfig.js.map +0 -1
- package/dist/plugin/config.js +0 -17
- package/dist/plugin/config.js.map +0 -1
- package/dist/plugin/env.js +0 -79
- package/dist/plugin/env.js.map +0 -1
- package/dist/plugin/error/toError.js.map +0 -1
- package/dist/plugin/file-preserver.js +0 -96
- package/dist/plugin/file-preserver.js.map +0 -1
- package/dist/plugin/helpers/cleanObject.js.map +0 -1
- package/dist/plugin/helpers/collectManifestCss.js.map +0 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +0 -1
- package/dist/plugin/helpers/createCssProps.js.map +0 -1
- package/dist/plugin/helpers/createEventHandler.js.map +0 -1
- package/dist/plugin/helpers/createHandler.js.map +0 -1
- package/dist/plugin/helpers/createRscStream.js.map +0 -1
- package/dist/plugin/helpers/formatMetrics.js.map +0 -1
- package/dist/plugin/helpers/getBundleManifest.js.map +0 -1
- package/dist/plugin/helpers/getRouteFiles.js.map +0 -1
- package/dist/plugin/helpers/handleServerAction.js.map +0 -1
- package/dist/plugin/helpers/inputNormalizer.js.map +0 -1
- package/dist/plugin/helpers/metrics.js.map +0 -1
- package/dist/plugin/helpers/moduleRefs.js.map +0 -1
- package/dist/plugin/helpers/requestInfo.js.map +0 -1
- package/dist/plugin/helpers/requestToRoute.js.map +0 -1
- package/dist/plugin/helpers/resolvePage.js.map +0 -1
- package/dist/plugin/helpers/resolvePageAndProps.js.map +0 -1
- package/dist/plugin/helpers/resolveProps.js.map +0 -1
- package/dist/plugin/helpers/serializeUserOptions.js.map +0 -1
- package/dist/plugin/helpers/sourceMap.d.ts +0 -8
- package/dist/plugin/helpers/sourceMap.d.ts.map +0 -1
- package/dist/plugin/helpers/sourceMap.js +0 -136
- package/dist/plugin/helpers/stashReturnValue.js.map +0 -1
- package/dist/plugin/helpers/tryManifest.js.map +0 -1
- package/dist/plugin/helpers.js +0 -27
- package/dist/plugin/helpers.js.map +0 -1
- package/dist/plugin/loader/css-loader.development.d.ts.map +0 -1
- package/dist/plugin/loader/css-loader.development.js +0 -76
- package/dist/plugin/loader/css-loader.development.js.map +0 -1
- package/dist/plugin/loader/css-loader.production.d.ts +0 -31
- package/dist/plugin/loader/css-loader.production.d.ts.map +0 -1
- package/dist/plugin/loader/css-loader.production.js +0 -45
- package/dist/plugin/loader/css-loader.production.js.map +0 -1
- package/dist/plugin/loader/env-loader.development.d.ts +0 -13
- package/dist/plugin/loader/env-loader.development.d.ts.map +0 -1
- package/dist/plugin/loader/env-loader.development.js +0 -68
- package/dist/plugin/loader/handleExports.d.ts +0 -40
- package/dist/plugin/loader/handleExports.d.ts.map +0 -1
- package/dist/plugin/loader/handleExports.js +0 -209
- package/dist/plugin/loader/handleExports.js.map +0 -1
- package/dist/plugin/loader/parse.js.map +0 -1
- package/dist/plugin/loader/react-loader.client.d.ts +0 -2
- package/dist/plugin/loader/react-loader.client.d.ts.map +0 -1
- package/dist/plugin/loader/react-loader.client.js +0 -2
- package/dist/plugin/loader/react-loader.js.map +0 -1
- package/dist/plugin/loader/react-loader.server.d.ts +0 -21
- package/dist/plugin/loader/react-loader.server.d.ts.map +0 -1
- package/dist/plugin/loader/react-loader.server.js +0 -131
- package/dist/plugin/loader/transformModuleIfNeeded.js.map +0 -1
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts +0 -48
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts.map +0 -1
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.js +0 -431
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.js.map +0 -1
- package/dist/plugin/metrics/formatMetrics.js.map +0 -1
- package/dist/plugin/metrics.js +0 -7
- package/dist/plugin/metrics.js.map +0 -1
- package/dist/plugin/plugin.client.js.map +0 -1
- package/dist/plugin/plugin.server.js.map +0 -1
- package/dist/plugin/preserver/plugin.js.map +0 -1
- package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +0 -1
- package/dist/plugin/react-client/createMessageHandlers.js.map +0 -1
- package/dist/plugin/react-client/createWorkerStream.js.map +0 -1
- package/dist/plugin/react-client/handleWorkerRscStream.js.map +0 -1
- package/dist/plugin/react-client/handleWorkerServerAction.js.map +0 -1
- package/dist/plugin/react-client/plugin.js.map +0 -1
- package/dist/plugin/react-client/restartWorker.js.map +0 -1
- package/dist/plugin/react-server/configureReactServer.js.map +0 -1
- package/dist/plugin/react-server/handleServerAction.js.map +0 -1
- package/dist/plugin/react-server/plugin.js.map +0 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +0 -1
- package/dist/plugin/react-static/collectRscContent.js.map +0 -1
- package/dist/plugin/react-static/configurePreviewServer.js.map +0 -1
- package/dist/plugin/react-static/createBuildLoader.js.map +0 -1
- package/dist/plugin/react-static/fileWriter.js.map +0 -1
- package/dist/plugin/react-static/plugin.js.map +0 -1
- package/dist/plugin/react-static/renderPage.js.map +0 -1
- package/dist/plugin/react-static/renderPages.js.map +0 -1
- package/dist/plugin/react-static/renderStreams.js.map +0 -1
- package/dist/plugin/react-static/rscToHtmlStream.js.map +0 -1
- package/dist/plugin/react-static/temporaryReferences.js.map +0 -1
- package/dist/plugin/root.js.map +0 -1
- package/dist/plugin/source-map/createMappingsSerializer.d.ts +0 -2
- package/dist/plugin/source-map/createMappingsSerializer.d.ts.map +0 -1
- package/dist/plugin/source-map/createMappingsSerializer.js +0 -129
- package/dist/plugin/source-map/createMappingsSerializer.js.map +0 -1
- package/dist/plugin/source-map/readMappings.d.ts +0 -2
- package/dist/plugin/source-map/readMappings.d.ts.map +0 -1
- package/dist/plugin/source-map/readMappings.js +0 -200
- package/dist/plugin/transformer/plugin.client.d.ts +0 -2
- package/dist/plugin/transformer/plugin.client.d.ts.map +0 -1
- package/dist/plugin/transformer/plugin.js.map +0 -1
- package/dist/plugin/transformer/plugin.server.js.map +0 -1
- package/dist/plugin/utils/callServer.js.map +0 -1
- package/dist/plugin/utils/createCallServer.js.map +0 -1
- package/dist/plugin/utils/createReactFetcher.js.map +0 -1
- package/dist/plugin/utils/env.js.map +0 -1
- package/dist/plugin/utils/envUrls.node.js.map +0 -1
- package/dist/plugin/utils/urls.js.map +0 -1
- package/dist/plugin/utils.js +0 -11
- package/dist/plugin/utils.js.map +0 -1
- package/dist/plugin/vendor/vendor.client.js.map +0 -1
- package/dist/plugin/vendor/vendor.js.map +0 -1
- package/dist/plugin/vendor/vendor.server.js.map +0 -1
- package/dist/plugin/vendor.js +0 -7
- package/dist/plugin/vendor.js.map +0 -1
- package/dist/plugin/worker/createWorker.js.map +0 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +0 -1
- package/dist/plugin/worker/html/html-worker.development.js.map +0 -1
- package/dist/plugin/worker/html/html-worker.production.js.map +0 -1
- package/dist/plugin/worker/html/index.js.map +0 -1
- package/dist/plugin/worker/html/messageHandler.js.map +0 -1
- package/dist/plugin/worker/rsc/handleRender.js.map +0 -1
- package/dist/plugin/worker/rsc/handlers.js.map +0 -1
- package/dist/plugin/worker/rsc/index.js.map +0 -1
- package/dist/plugin/worker/rsc/messageHandler.js.map +0 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +0 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +0 -1
- package/dist/plugin/worker/rsc/state.js.map +0 -1
- package/dist/plugin/worker/rsc/userOptions.js.map +0 -1
- package/dist/plugin/worker/sendMessage.js.map +0 -1
- package/dist/server.js.map +0 -1
- package/plugin/components/css-collector.tsx +0 -20
- package/plugin/config/resolveAutoDiscoverMatcher.ts +0 -23
- package/plugin/helpers/sourceMap.ts +0 -182
- package/plugin/loader/css-loader.development.ts +0 -135
- package/plugin/loader/css-loader.production.ts +0 -84
- package/plugin/loader/handleExports.ts +0 -309
- package/plugin/loader/react-loader.client.ts +0 -1
- package/plugin/loader/react-loader.server.ts +0 -185
- package/plugin/loader/transformModuleWithPreservedFunctions.ts +0 -596
- package/plugin/source-map/createMappingsSerializer.ts +0 -181
- package/plugin/source-map/readMappings.ts +0 -194
- package/plugin/transformer/plugin.client.ts +0 -0
- /package/dist/plugin/{transformer/plugin.client.js → loader/directives/types.js} +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { transformModule } from "./transformModule.js";
|
|
2
|
+
import { isReactServerCondition } from "../config/getCondition.js";
|
|
3
|
+
import { parse } from "./parse.js";
|
|
4
|
+
import { analyzeModule } from "./directives/analyzeModule.js";
|
|
5
|
+
import { findDirectiveMatches } from "./directives/findDirectiveMatches.js";
|
|
6
|
+
import type { DirectiveMatch } from "./directives/types.js";
|
|
7
|
+
import type { TransformerFactory, TransformResult } from "./types.js";
|
|
8
|
+
import { getNodeEnv } from "../getNodeEnv.js";
|
|
9
|
+
import { DEFAULT_LOADER_CONFIG } from "../config/defaults.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a transformer that handles React Server Components (RSC) boundaries.
|
|
13
|
+
*/
|
|
14
|
+
export const createTransformer: TransformerFactory = ({
|
|
15
|
+
parseFn = parse,
|
|
16
|
+
options,
|
|
17
|
+
forceServerFunction = undefined,
|
|
18
|
+
forceClientComponent = undefined,
|
|
19
|
+
isServerEnvironment = isReactServerCondition(),
|
|
20
|
+
}) => {
|
|
21
|
+
return async (source: string, moduleId: string): Promise<TransformResult> => {
|
|
22
|
+
if (options.verbose) {
|
|
23
|
+
console.log(`[createTransformer] Loading: ${moduleId}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Fast-path: skip parsing and transformation if no directives are present
|
|
27
|
+
const matches = findDirectiveMatches(source);
|
|
28
|
+
const hasServerDirective = matches.matches.some(
|
|
29
|
+
(m: DirectiveMatch) => m.type === "server"
|
|
30
|
+
);
|
|
31
|
+
const hasClientDirective = matches.matches.some(
|
|
32
|
+
(m: DirectiveMatch) => m.type === "client"
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (hasClientDirective === false && hasServerDirective === false) {
|
|
36
|
+
return { code: source, map: null };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (isServerEnvironment === false && hasServerDirective) {
|
|
40
|
+
console.warn(
|
|
41
|
+
"You likely don't want to use createTransformer in the client environment."
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Use analyzeModule to get the full parse result, passing the custom parseFn
|
|
46
|
+
const parseResult = await analyzeModule(source, {
|
|
47
|
+
...options,
|
|
48
|
+
loader: options.loader ?? DEFAULT_LOADER_CONFIG,
|
|
49
|
+
}, parseFn);
|
|
50
|
+
if (
|
|
51
|
+
parseResult.directiveInfo &&
|
|
52
|
+
parseResult.directiveInfo.warnings.length > 0
|
|
53
|
+
) {
|
|
54
|
+
const isProduction = getNodeEnv() === "production";
|
|
55
|
+
|
|
56
|
+
// Handle directive errors (can be downgraded to warnings based on panicThreshold)
|
|
57
|
+
for (const warning of parseResult.directiveInfo.warnings) {
|
|
58
|
+
const shouldDowngradeToWarning = !isProduction && options.panicThreshold === 'none';
|
|
59
|
+
|
|
60
|
+
if (shouldDowngradeToWarning) {
|
|
61
|
+
// Downgrade error to warning in development when panicThreshold is 'none'
|
|
62
|
+
const [start, end] = warning.range;
|
|
63
|
+
const lines = source.split('\n');
|
|
64
|
+
const startLine = source.slice(0, start).split('\n').length;
|
|
65
|
+
|
|
66
|
+
console.warn(`Warning: ${warning.message}`);
|
|
67
|
+
|
|
68
|
+
// Show document preview with line numbers
|
|
69
|
+
const contextLines = 2; // Show 2 lines before and after
|
|
70
|
+
const minLine = Math.max(1, startLine - contextLines);
|
|
71
|
+
const maxLine = Math.min(lines.length, startLine + contextLines);
|
|
72
|
+
|
|
73
|
+
console.warn('');
|
|
74
|
+
for (let i = minLine; i <= maxLine; i++) {
|
|
75
|
+
const lineNum = i.toString().padStart(3, ' ');
|
|
76
|
+
const isErrorLine = i === startLine;
|
|
77
|
+
const prefix = isErrorLine ? '>' : ' ';
|
|
78
|
+
const line = lines[i - 1] || '';
|
|
79
|
+
|
|
80
|
+
if (isErrorLine) {
|
|
81
|
+
console.warn(`${prefix} ${lineNum} | ${line}`);
|
|
82
|
+
// Show pointer to the directive
|
|
83
|
+
const lineStart = source.lastIndexOf('\n', start - 1) + 1;
|
|
84
|
+
const columnPos = Math.max(0, start - lineStart);
|
|
85
|
+
const directiveLength = Math.max(1, end - start);
|
|
86
|
+
const pointer = ' '.repeat(7 + columnPos) + '^'.repeat(directiveLength);
|
|
87
|
+
console.warn(` ${pointer}`);
|
|
88
|
+
} else {
|
|
89
|
+
console.warn(` ${lineNum} | ${line}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
console.warn('');
|
|
93
|
+
|
|
94
|
+
if (options.verbose) {
|
|
95
|
+
console.warn(` range: [${start}, ${end}]`);
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
// Treat as error (default behavior) - panic and stop compilation
|
|
99
|
+
throw new Error(warning.message);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (parseResult.type !== "success") {
|
|
104
|
+
return { code: source, map: null };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Transform the module
|
|
108
|
+
return await transformModule(source, moduleId, parseResult, {
|
|
109
|
+
forceServerFunction: forceServerFunction ?? hasServerDirective,
|
|
110
|
+
forceClientComponent: forceClientComponent ?? hasClientDirective,
|
|
111
|
+
isServerEnvironment,
|
|
112
|
+
loader: options.loader,
|
|
113
|
+
directiveWarnings: parseResult.directiveInfo.warnings,
|
|
114
|
+
verbose: options.verbose || false,
|
|
115
|
+
panicThreshold: options.panicThreshold || 'none',
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { type MessagePort } from "node:worker_threads";
|
|
2
|
+
import type { LoadHook, ResolveHook, ModuleFormat } from "node:module";
|
|
3
|
+
import type {
|
|
4
|
+
ResolvedUserOptions,
|
|
5
|
+
SerializedResolvedConfig,
|
|
6
|
+
SerializedUserOptions,
|
|
7
|
+
} from "../types.js";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { preprocessCSS, resolveConfig } from "vite";
|
|
10
|
+
import { readFile } from "node:fs/promises";
|
|
11
|
+
import { env } from "../utils/env.js";
|
|
12
|
+
import type {
|
|
13
|
+
CssFileMessage,
|
|
14
|
+
InitializedCssLoaderMessage,
|
|
15
|
+
} from "../worker/rsc/types.js";
|
|
16
|
+
import { hydrateUserOptions } from "../helpers/hydrateUserOptions.js";
|
|
17
|
+
import { toError } from "../error/toError.js";
|
|
18
|
+
import { sendMessage } from "../worker/sendMessage.js";
|
|
19
|
+
import type { ErrorMessage } from "../worker/types.js";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Global port for communication between the main thread and the CSS loader.
|
|
23
|
+
* This port is used to send CSS file requests and receive responses.
|
|
24
|
+
*/
|
|
25
|
+
export let loaderPort: MessagePort | undefined;
|
|
26
|
+
|
|
27
|
+
let resolvedConfig: SerializedResolvedConfig | null;
|
|
28
|
+
let userOptions: ResolvedUserOptions | undefined;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initializes the CSS loader with the necessary communication channels.
|
|
32
|
+
* Sets up message handlers for CSS file requests and responses.
|
|
33
|
+
*
|
|
34
|
+
* @param data - Configuration data for the CSS loader
|
|
35
|
+
* @param data.port - The message port for communication
|
|
36
|
+
*/
|
|
37
|
+
export async function initialize(data: {
|
|
38
|
+
id: string;
|
|
39
|
+
port: MessagePort;
|
|
40
|
+
resolvedConfig: SerializedResolvedConfig;
|
|
41
|
+
userOptions: SerializedUserOptions;
|
|
42
|
+
}) {
|
|
43
|
+
loaderPort = data.port;
|
|
44
|
+
resolvedConfig = data.resolvedConfig;
|
|
45
|
+
const resolvedUserOptions = hydrateUserOptions(data.userOptions);
|
|
46
|
+
if (resolvedUserOptions.type === "error") {
|
|
47
|
+
if (loaderPort) {
|
|
48
|
+
sendMessage(
|
|
49
|
+
{
|
|
50
|
+
type: "ERROR",
|
|
51
|
+
id: "css-loader",
|
|
52
|
+
error: resolvedUserOptions.error,
|
|
53
|
+
} satisfies ErrorMessage,
|
|
54
|
+
loaderPort
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
throw resolvedUserOptions.error;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Use the hydrated user options directly (includes recreated functions)
|
|
61
|
+
userOptions = resolvedUserOptions.userOptions;
|
|
62
|
+
|
|
63
|
+
if (loaderPort) {
|
|
64
|
+
sendMessage(
|
|
65
|
+
{
|
|
66
|
+
type: "INITIALIZED_CSS_LOADER",
|
|
67
|
+
id: data.id,
|
|
68
|
+
} satisfies InitializedCssLoaderMessage,
|
|
69
|
+
loaderPort
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Processes a CSS file request.
|
|
76
|
+
* Sends a request to the main thread and waits for the processed CSS.
|
|
77
|
+
*
|
|
78
|
+
* @param filePath - The file system path of the CSS file
|
|
79
|
+
* @param config - The Vite config
|
|
80
|
+
* @returns A promise that resolves to the processed CSS content
|
|
81
|
+
*/
|
|
82
|
+
async function processCssFile(
|
|
83
|
+
filePath: string,
|
|
84
|
+
inline: boolean
|
|
85
|
+
): Promise<{ format: ModuleFormat; source: string; shortCircuit: boolean }> {
|
|
86
|
+
try {
|
|
87
|
+
// Convert file URL to path if needed
|
|
88
|
+
const path = filePath.startsWith("file://")
|
|
89
|
+
? fileURLToPath(filePath)
|
|
90
|
+
: filePath;
|
|
91
|
+
|
|
92
|
+
// Process CSS using Vite's preprocessCSS
|
|
93
|
+
const source = await readFile(path, "utf-8");
|
|
94
|
+
let moduleID = path;
|
|
95
|
+
if (userOptions?.normalizer) {
|
|
96
|
+
const [, value] = userOptions.normalizer(path);
|
|
97
|
+
moduleID = userOptions.moduleID?.(value || path) || path;
|
|
98
|
+
}
|
|
99
|
+
// Try to process CSS with preprocessCSS, fall back to raw CSS if config is incomplete
|
|
100
|
+
let processed: { code: string; modules?: any };
|
|
101
|
+
try {
|
|
102
|
+
// Create a minimal config with environments that preprocessCSS expects
|
|
103
|
+
const viteConfig = await resolveConfig(
|
|
104
|
+
{
|
|
105
|
+
...resolvedConfig,
|
|
106
|
+
env: env,
|
|
107
|
+
// do-not re-resolve the config file as it would import the plugin again which we do not need.
|
|
108
|
+
configFile: false,
|
|
109
|
+
},
|
|
110
|
+
"serve"
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
processed = await preprocessCSS(source, path, viteConfig);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
// If preprocessCSS fails, fall back to raw CSS
|
|
116
|
+
if (loaderPort) {
|
|
117
|
+
sendMessage(
|
|
118
|
+
{
|
|
119
|
+
type: "ERROR",
|
|
120
|
+
id: moduleID,
|
|
121
|
+
error: toError(error),
|
|
122
|
+
} satisfies ErrorMessage,
|
|
123
|
+
loaderPort
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
processed = { code: source, modules: {} };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// If we're processing CSS for a specific page, notify the message handler
|
|
130
|
+
if (loaderPort) {
|
|
131
|
+
sendMessage(
|
|
132
|
+
{
|
|
133
|
+
type: "CSS_FILE",
|
|
134
|
+
id: moduleID,
|
|
135
|
+
content: processed.code,
|
|
136
|
+
} satisfies CssFileMessage,
|
|
137
|
+
loaderPort
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Return a module that can be used by React components
|
|
142
|
+
if (inline) {
|
|
143
|
+
return {
|
|
144
|
+
format: "module",
|
|
145
|
+
source: processed.code,
|
|
146
|
+
shortCircuit: true,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
format: "module",
|
|
151
|
+
source: `export default ${JSON.stringify(processed.modules || {})};`,
|
|
152
|
+
shortCircuit: true,
|
|
153
|
+
};
|
|
154
|
+
} catch (error) {
|
|
155
|
+
const err = toError(error);
|
|
156
|
+
if (loaderPort) {
|
|
157
|
+
sendMessage(
|
|
158
|
+
{
|
|
159
|
+
type: "ERROR",
|
|
160
|
+
id: "css-loader",
|
|
161
|
+
error: err,
|
|
162
|
+
} satisfies ErrorMessage,
|
|
163
|
+
loaderPort
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Vite's load hook implementation for CSS files.
|
|
172
|
+
* Handles CSS file loading requests and returns a placeholder module.
|
|
173
|
+
* The actual CSS content is processed in the main thread.
|
|
174
|
+
*
|
|
175
|
+
* @param url - The URL of the module to load
|
|
176
|
+
* @param context - The load hook context
|
|
177
|
+
* @param defaultLoad - The default load function
|
|
178
|
+
* @returns A promise that resolves to the module content
|
|
179
|
+
*/
|
|
180
|
+
export const load: LoadHook = async (url, context, defaultLoad) => {
|
|
181
|
+
const [name, query] = url.split("?");
|
|
182
|
+
if (name.endsWith(".css")) {
|
|
183
|
+
let isInline = query?.startsWith("inline") || query?.includes("&inline");
|
|
184
|
+
if (isInline && query.includes('inline=')) {
|
|
185
|
+
// handle = true/false
|
|
186
|
+
const match = query.match(/inline=(1|true|0|false)/)?.[1];
|
|
187
|
+
isInline = match === '1' || match === 'true';
|
|
188
|
+
}
|
|
189
|
+
return processCssFile(url, isInline);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return defaultLoad(url, context);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Vite's resolve hook implementation.
|
|
197
|
+
* Handles module resolution during development.
|
|
198
|
+
*
|
|
199
|
+
* @param specifier - The module specifier to resolve
|
|
200
|
+
* @param context - The resolve hook context
|
|
201
|
+
* @param defaultResolve - The default resolve function
|
|
202
|
+
* @returns A promise that resolves to the resolved module
|
|
203
|
+
*/
|
|
204
|
+
export const resolve: ResolveHook = (specifier, context, defaultResolve) => {
|
|
205
|
+
return defaultResolve(specifier, context);
|
|
206
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ExportInfo } from "./types.js";
|
|
2
|
+
import type {
|
|
3
|
+
Identifier,
|
|
4
|
+
ClassDeclaration,
|
|
5
|
+
ObjectPattern,
|
|
6
|
+
ArrayPattern,
|
|
7
|
+
Property,
|
|
8
|
+
AssignmentPattern,
|
|
9
|
+
RestElement,
|
|
10
|
+
ParenthesizedExpression,
|
|
11
|
+
Expression,
|
|
12
|
+
AssignmentProperty,
|
|
13
|
+
} from "acorn";
|
|
14
|
+
|
|
15
|
+
// Helper: recursively collect exportable names from patterns and classes
|
|
16
|
+
export function addLocalExportedNames(
|
|
17
|
+
exports: ExportInfo[],
|
|
18
|
+
node:
|
|
19
|
+
| Identifier
|
|
20
|
+
| ClassDeclaration
|
|
21
|
+
| ObjectPattern
|
|
22
|
+
| ArrayPattern
|
|
23
|
+
| Property
|
|
24
|
+
| AssignmentPattern
|
|
25
|
+
| RestElement
|
|
26
|
+
| ParenthesizedExpression
|
|
27
|
+
| Expression
|
|
28
|
+
| AssignmentProperty,
|
|
29
|
+
parentRange: [number, number]
|
|
30
|
+
) {
|
|
31
|
+
if (!node) return;
|
|
32
|
+
switch (node.type) {
|
|
33
|
+
case "Identifier":
|
|
34
|
+
exports.push({
|
|
35
|
+
localName: node.name,
|
|
36
|
+
exportName: node.name,
|
|
37
|
+
type: null,
|
|
38
|
+
range: parentRange,
|
|
39
|
+
});
|
|
40
|
+
break;
|
|
41
|
+
case "ClassDeclaration":
|
|
42
|
+
if (node.id) {
|
|
43
|
+
exports.push({
|
|
44
|
+
localName: node.id.name,
|
|
45
|
+
exportName: node.id.name,
|
|
46
|
+
type: "class",
|
|
47
|
+
range: parentRange,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case "ObjectPattern":
|
|
52
|
+
for (const prop of node.properties) {
|
|
53
|
+
if(prop.type === "RestElement") {
|
|
54
|
+
addLocalExportedNames(exports, prop.argument, parentRange);
|
|
55
|
+
} else {
|
|
56
|
+
addLocalExportedNames(exports, prop.value, parentRange);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
case "ArrayPattern":
|
|
61
|
+
for (const element of node.elements) {
|
|
62
|
+
if (element) addLocalExportedNames(exports, element, parentRange);
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
case "Property":
|
|
66
|
+
addLocalExportedNames(exports, node.value, parentRange);
|
|
67
|
+
break;
|
|
68
|
+
case "AssignmentPattern":
|
|
69
|
+
addLocalExportedNames(exports, node.left, parentRange);
|
|
70
|
+
break;
|
|
71
|
+
case "RestElement":
|
|
72
|
+
addLocalExportedNames(exports, node.argument, parentRange);
|
|
73
|
+
break;
|
|
74
|
+
case "ParenthesizedExpression":
|
|
75
|
+
addLocalExportedNames(exports, node.expression, parentRange);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { findDirectiveMatches } from "./findDirectiveMatches.js";
|
|
2
|
+
import { isFunctionNode } from "./typeGuards.js";
|
|
3
|
+
import { getFunctionBody } from "./getFunctionBody.js";
|
|
4
|
+
import { getFunctionName } from "./getFunctionName.js";
|
|
5
|
+
import { getExportedName } from "./getExportedName.js";
|
|
6
|
+
import { processFunctionNode } from "./processFunctionNode.js";
|
|
7
|
+
import { isDirectiveAtStart, getDirectiveValue, matchOverlapsDirective } from "./utils.js";
|
|
8
|
+
import type { DirectiveInfo, DirectiveMatch, DirectiveMatches } from "./types.js";
|
|
9
|
+
import type { Node, Program } from "acorn";
|
|
10
|
+
import type { DirectiveOptions } from "../../types.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Analyzes directives in the given source and AST, returning directiveInfo.
|
|
14
|
+
*/
|
|
15
|
+
export function analyzeDirectives(
|
|
16
|
+
ast: Program,
|
|
17
|
+
source: string,
|
|
18
|
+
matches?: DirectiveMatches,
|
|
19
|
+
): DirectiveInfo;
|
|
20
|
+
export function analyzeDirectives(
|
|
21
|
+
ast: Program,
|
|
22
|
+
source: string,
|
|
23
|
+
options?: DirectiveOptions,
|
|
24
|
+
): DirectiveInfo;
|
|
25
|
+
export function analyzeDirectives(
|
|
26
|
+
ast: Program,
|
|
27
|
+
source: string,
|
|
28
|
+
optionsOrMatches?: DirectiveMatches | DirectiveOptions,
|
|
29
|
+
): DirectiveInfo {
|
|
30
|
+
const hasOptions = optionsOrMatches != null && typeof optionsOrMatches === 'object';
|
|
31
|
+
const directiveMatches = hasOptions && 'matches' in optionsOrMatches
|
|
32
|
+
? optionsOrMatches
|
|
33
|
+
: findDirectiveMatches(source);
|
|
34
|
+
|
|
35
|
+
const directiveInfo: DirectiveInfo = {
|
|
36
|
+
fileLevel: null,
|
|
37
|
+
functionLevel: [],
|
|
38
|
+
warnings: []
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Find file-level directives by checking AST
|
|
42
|
+
let foundNonDirective = false;
|
|
43
|
+
let firstDirective: DirectiveMatch | null = null;
|
|
44
|
+
let verbose = hasOptions && 'verbose' in optionsOrMatches && optionsOrMatches.verbose;
|
|
45
|
+
for (const node of ast.body) {
|
|
46
|
+
// Debug logging
|
|
47
|
+
if (verbose) {
|
|
48
|
+
console.log('[analyzeDirectives] Processing node:', {
|
|
49
|
+
type: node.type,
|
|
50
|
+
start: node.start,
|
|
51
|
+
end: node.end,
|
|
52
|
+
directive: 'directive' in node ? node.directive : undefined,
|
|
53
|
+
beforeNode: node.start! > 0 ? JSON.stringify(source.slice(0, node.start!)) : 'none',
|
|
54
|
+
foundNonDirective
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Only check for directives in expression statements
|
|
59
|
+
if (node.type === "ExpressionStatement") {
|
|
60
|
+
let directive: string | null = null;
|
|
61
|
+
if ("directive" in node && typeof node.directive === "string") {
|
|
62
|
+
directive = node.directive;
|
|
63
|
+
} else if (
|
|
64
|
+
node.expression.type === "Literal" &&
|
|
65
|
+
typeof node.expression.value === "string" &&
|
|
66
|
+
(node.expression.value === "use server" || node.expression.value === "use client")
|
|
67
|
+
) {
|
|
68
|
+
directive = node.expression.value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (directive) {
|
|
72
|
+
const getDirectiveType = optionsOrMatches != null && 'loader' in optionsOrMatches ? optionsOrMatches.loader?.getDirectiveType : undefined;
|
|
73
|
+
const type = getDirectiveType?.(directive) ??
|
|
74
|
+
(directive === "use server" ? "server" : "client");
|
|
75
|
+
if (!firstDirective) {
|
|
76
|
+
firstDirective = { type, range: [node.start!, node.end!] };
|
|
77
|
+
if (verbose) {
|
|
78
|
+
console.log('[analyzeDirectives] Found first directive:', directive, 'at range:', [node.start!, node.end!]);
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
directiveInfo.warnings.push({
|
|
82
|
+
message: "Cannot have both 'use client' and 'use server' directives in the same file",
|
|
83
|
+
range: [0, 0],
|
|
84
|
+
type: "server"
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
// This expression statement is not a directive, so mark as non-directive
|
|
89
|
+
// if we haven't found the first directive yet
|
|
90
|
+
if (!firstDirective) {
|
|
91
|
+
foundNonDirective = true;
|
|
92
|
+
if (optionsOrMatches != null && 'verbose' in optionsOrMatches && optionsOrMatches?.verbose) {
|
|
93
|
+
console.log('[analyzeDirectives] Found non-directive expression before first directive, setting foundNonDirective=true');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} else if (node.type !== "ImportDeclaration" && node.type !== "ExportNamedDeclaration" && node.type !== "ExportDefaultDeclaration") {
|
|
98
|
+
// Only mark actual code (not imports/exports) as non-directive
|
|
99
|
+
// if we haven't found the first directive yet
|
|
100
|
+
if (!firstDirective) {
|
|
101
|
+
foundNonDirective = true;
|
|
102
|
+
if (verbose) {
|
|
103
|
+
console.log('[analyzeDirectives] Found non-directive node before first directive:', node.type, 'setting foundNonDirective=true');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Check if this node is after any comments or non-whitespace content
|
|
109
|
+
// Only matters if we haven't found the first directive yet
|
|
110
|
+
if (!firstDirective && node.start! > 0) {
|
|
111
|
+
const beforeNode = source.slice(0, node.start!).trim();
|
|
112
|
+
if (beforeNode.length > 0) {
|
|
113
|
+
foundNonDirective = true;
|
|
114
|
+
if (verbose) {
|
|
115
|
+
console.log('[analyzeDirectives] Found content before first directive:', JSON.stringify(beforeNode), 'setting foundNonDirective=true');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Set the first directive as file-level if found
|
|
122
|
+
if (firstDirective) {
|
|
123
|
+
directiveInfo.fileLevel = firstDirective;
|
|
124
|
+
|
|
125
|
+
// Check if there was content (including comments) before the directive
|
|
126
|
+
if (!foundNonDirective && firstDirective.range[0] > 0) {
|
|
127
|
+
const beforeDirective = source.slice(0, firstDirective.range[0]).trim();
|
|
128
|
+
if (beforeDirective.length > 0) {
|
|
129
|
+
foundNonDirective = true;
|
|
130
|
+
if (verbose) {
|
|
131
|
+
console.log('[analyzeDirectives] Found content before directive:', JSON.stringify(beforeDirective), 'setting foundNonDirective=true for directive');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (foundNonDirective) {
|
|
137
|
+
directiveInfo.warnings.push({
|
|
138
|
+
message: "File-level directives must be at the top of the file, before any other code",
|
|
139
|
+
range: [firstDirective.range[0], firstDirective.range[1]],
|
|
140
|
+
type: firstDirective.type
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Process function-level directives
|
|
146
|
+
const functionLevelMatches = directiveMatches.matches.filter((match: DirectiveMatch) => {
|
|
147
|
+
// Skip if this match is already used as a file-level directive
|
|
148
|
+
if (directiveInfo.fileLevel &&
|
|
149
|
+
match.range[0] === directiveInfo.fileLevel.range[0] &&
|
|
150
|
+
match.range[1] === directiveInfo.fileLevel.range[1]) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const processedFunctions = new Set<string>();
|
|
157
|
+
|
|
158
|
+
// First pass: collect all function nodes with their directives
|
|
159
|
+
const functionNodes: Array<{node: Node, match: DirectiveMatch, context: string}> = [];
|
|
160
|
+
|
|
161
|
+
// Track context during traversal
|
|
162
|
+
function traverseWithContext(node: Node, context: { inFunction: boolean, inClass: boolean }) {
|
|
163
|
+
if (isFunctionNode(node)) {
|
|
164
|
+
const body = getFunctionBody(node);
|
|
165
|
+
if (body) {
|
|
166
|
+
// Check if directive is at the start of the function body
|
|
167
|
+
for (const match of functionLevelMatches) {
|
|
168
|
+
const directiveValue = getDirectiveValue(match.type);
|
|
169
|
+
|
|
170
|
+
if (isDirectiveAtStart(node, directiveValue)) {
|
|
171
|
+
// Check if the match range corresponds to this specific directive position
|
|
172
|
+
const directiveNode = body.body[0];
|
|
173
|
+
const directiveStart = directiveNode.start!;
|
|
174
|
+
const directiveEnd = directiveNode.end!;
|
|
175
|
+
|
|
176
|
+
// Match based on position - the match should overlap with the directive node
|
|
177
|
+
const matchOverlaps = matchOverlapsDirective(match.range, directiveStart, directiveEnd);
|
|
178
|
+
|
|
179
|
+
if (matchOverlaps) {
|
|
180
|
+
const functionName = getFunctionName(node) || "anonymous";
|
|
181
|
+
|
|
182
|
+
// Check for invalid contexts based on traversal context
|
|
183
|
+
if (context.inFunction) {
|
|
184
|
+
const nameDesc = functionName === "anonymous" ? "" : ` '${functionName}'`;
|
|
185
|
+
directiveInfo.warnings.push({
|
|
186
|
+
message: `Function${nameDesc} with '${directiveValue}' directive cannot be nested inside another function. Directives are only allowed in top-level functions.`,
|
|
187
|
+
range: match.range,
|
|
188
|
+
type: match.type
|
|
189
|
+
});
|
|
190
|
+
return; // Skip this function entirely
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (context.inClass) {
|
|
194
|
+
const nameDesc = functionName === "anonymous" ? "" : ` '${functionName}'`;
|
|
195
|
+
directiveInfo.warnings.push({
|
|
196
|
+
message: `Class method${nameDesc} with '${directiveValue}' directive is not supported. Directives are only allowed in top-level functions.`,
|
|
197
|
+
range: match.range,
|
|
198
|
+
type: match.type
|
|
199
|
+
});
|
|
200
|
+
return; // Skip this function entirely
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Only allow server directives in function-level contexts
|
|
204
|
+
if (match.type === "server") {
|
|
205
|
+
functionNodes.push({ node, match, context: context.inFunction ? "nested" : context.inClass ? "class" : "top-level" });
|
|
206
|
+
} else {
|
|
207
|
+
// Generate warning for client directives in functions
|
|
208
|
+
directiveInfo.warnings.push({
|
|
209
|
+
message: "Function-level 'use client' isn't allowed",
|
|
210
|
+
range: match.range,
|
|
211
|
+
type: "client"
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Continue traversal with updated context (now inside a function)
|
|
221
|
+
traverseChildren(node, { inFunction: true, inClass: context.inClass });
|
|
222
|
+
} else if (node.type === "ClassDeclaration" || node.type === "ClassExpression") {
|
|
223
|
+
// Continue traversal with updated context (now inside a class)
|
|
224
|
+
traverseChildren(node, { inFunction: context.inFunction, inClass: true });
|
|
225
|
+
} else if (node.type === "MethodDefinition") {
|
|
226
|
+
// Method definitions are inside classes
|
|
227
|
+
traverseChildren(node, { inFunction: context.inFunction, inClass: true });
|
|
228
|
+
} else {
|
|
229
|
+
// Continue with same context
|
|
230
|
+
traverseChildren(node, context);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function traverseChildren(node: Node, context: { inFunction: boolean, inClass: boolean }) {
|
|
235
|
+
const nodeWithChildren = node as any;
|
|
236
|
+
for (const key in nodeWithChildren) {
|
|
237
|
+
if (key === 'parent' || key === 'start' || key === 'end' || key === 'loc' || key === 'range') {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const value = nodeWithChildren[key];
|
|
242
|
+
if (value && typeof value === 'object') {
|
|
243
|
+
if (Array.isArray(value)) {
|
|
244
|
+
for (const child of value) {
|
|
245
|
+
if (child && typeof child === 'object' && child.type) {
|
|
246
|
+
traverseWithContext(child, context);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} else if (value.type) {
|
|
250
|
+
traverseWithContext(value, context);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Start traversal at top level (not in function or class)
|
|
257
|
+
traverseWithContext(ast, { inFunction: false, inClass: false });
|
|
258
|
+
|
|
259
|
+
// Second pass: process functions in order
|
|
260
|
+
for (const { node, match } of functionNodes) {
|
|
261
|
+
const name = getFunctionName(node) || "anonymous";
|
|
262
|
+
const exportName = getExportedName(node);
|
|
263
|
+
const functionKey = `${name}-${exportName || ''}-${match.range[0]}`;
|
|
264
|
+
|
|
265
|
+
// Skip if we've already processed this function
|
|
266
|
+
if (processedFunctions.has(functionKey)) continue;
|
|
267
|
+
processedFunctions.add(functionKey);
|
|
268
|
+
|
|
269
|
+
processFunctionNode(node, name, exportName, match, directiveInfo);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Add warnings for mixed server/client directives
|
|
273
|
+
if (directiveInfo.fileLevel && directiveInfo.functionLevel.length > 0) {
|
|
274
|
+
for (const func of directiveInfo.functionLevel) {
|
|
275
|
+
if (directiveInfo.fileLevel.type !== func.type) {
|
|
276
|
+
directiveInfo.warnings.push({
|
|
277
|
+
message: `Cannot have both 'use ${directiveInfo.fileLevel.type}' and 'use ${func.type}' directives in the same file`,
|
|
278
|
+
range: func.range,
|
|
279
|
+
type: "server"
|
|
280
|
+
});
|
|
281
|
+
} else if (func.type !== "server") {
|
|
282
|
+
directiveInfo.warnings.push({
|
|
283
|
+
message: `Function-level directives should be 'use server', but got 'use ${func.type}'`,
|
|
284
|
+
range: func.range,
|
|
285
|
+
type: "client"
|
|
286
|
+
});
|
|
287
|
+
} else {
|
|
288
|
+
directiveInfo.warnings.push({
|
|
289
|
+
message: `'use server' is already defined at the top of the file, this directive should be removed.`,
|
|
290
|
+
range: func.range,
|
|
291
|
+
type: "server"
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return directiveInfo;
|
|
298
|
+
}
|