one 1.2.57 → 1.2.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/build.cjs +3 -1
- package/dist/cjs/cli/build.js +1 -1
- package/dist/cjs/cli/build.js.map +1 -1
- package/dist/cjs/cli/build.native.js +13 -12
- package/dist/cjs/cli/build.native.js.map +1 -1
- package/dist/cjs/cli/buildPage.cjs +1 -1
- package/dist/cjs/cli/buildPage.js +1 -1
- package/dist/cjs/cli/buildPage.native.js +2 -2
- package/dist/cjs/cli/buildPage.native.js.map +1 -1
- package/dist/cjs/cli/dev.cjs +4 -4
- package/dist/cjs/cli/dev.js +4 -4
- package/dist/cjs/cli/dev.js.map +1 -1
- package/dist/cjs/cli/dev.native.js +4 -4
- package/dist/cjs/cli/dev.native.js.map +1 -1
- package/dist/cjs/cli/generateRoutes.cjs +1 -1
- package/dist/cjs/cli/generateRoutes.js +1 -1
- package/dist/cjs/cli/generateRoutes.native.js +1 -1
- package/dist/cjs/cli/generateRoutes.native.js.map +1 -1
- package/dist/cjs/cli/generateSitemap.native.js +7 -7
- package/dist/cjs/cli/generateSitemap.native.js.map +1 -1
- package/dist/cjs/config.native.js +2 -2
- package/dist/cjs/config.native.js.map +1 -1
- package/dist/cjs/constants.native.js +1 -1
- package/dist/cjs/constants.native.js.map +1 -1
- package/dist/cjs/createApp.cjs +2 -1
- package/dist/cjs/createApp.js +2 -2
- package/dist/cjs/createApp.js.map +1 -1
- package/dist/cjs/createHandleRequest.test.js +3 -1
- package/dist/cjs/createHandleRequest.test.js.map +1 -1
- package/dist/cjs/createHandleRequest.test.native.js.map +1 -1
- package/dist/cjs/devtools/registry.cjs +30 -0
- package/dist/cjs/devtools/registry.js +25 -0
- package/dist/cjs/devtools/registry.js.map +6 -0
- package/dist/cjs/devtools/registry.native.js +33 -0
- package/dist/cjs/devtools/registry.native.js.map +1 -0
- package/dist/cjs/fork/NavigationContainer.native.js +5 -5
- package/dist/cjs/fork/NavigationContainer.native.js.map +1 -1
- package/dist/cjs/fork/createMemoryHistory.cjs +20 -9
- package/dist/cjs/fork/createMemoryHistory.js +22 -4
- package/dist/cjs/fork/createMemoryHistory.js.map +1 -1
- package/dist/cjs/fork/createMemoryHistory.native.js +22 -11
- package/dist/cjs/fork/createMemoryHistory.native.js.map +1 -1
- package/dist/cjs/fork/extractPathFromURL.native.js +8 -8
- package/dist/cjs/fork/extractPathFromURL.native.js.map +1 -1
- package/dist/cjs/fork/findFocusedRoute.native.js +2 -3
- package/dist/cjs/fork/findFocusedRoute.native.js.map +1 -1
- package/dist/cjs/fork/getPathFromState-mods.native.js +2 -3
- package/dist/cjs/fork/getPathFromState-mods.native.js.map +1 -1
- package/dist/cjs/fork/getStateFromPath-mods.native.js +3 -3
- package/dist/cjs/fork/getStateFromPath-mods.native.js.map +1 -1
- package/dist/cjs/fork/useLinking.cjs +11 -5
- package/dist/cjs/fork/useLinking.js +6 -6
- package/dist/cjs/fork/useLinking.js.map +1 -1
- package/dist/cjs/fork/useLinking.native.js.map +1 -1
- package/dist/cjs/head/url.native.js +2 -3
- package/dist/cjs/head/url.native.js.map +1 -1
- package/dist/cjs/hooks.js.map +1 -1
- package/dist/cjs/hooks.native.js.map +1 -1
- package/dist/cjs/index.cjs +17 -1
- package/dist/cjs/index.js +12 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +17 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/layouts/withLayoutContext.cjs +34 -15
- package/dist/cjs/layouts/withLayoutContext.js +29 -13
- package/dist/cjs/layouts/withLayoutContext.js.map +1 -1
- package/dist/cjs/layouts/withLayoutContext.native.js +42 -19
- package/dist/cjs/layouts/withLayoutContext.native.js.map +1 -1
- package/dist/cjs/link/Link.cjs +5 -2
- package/dist/cjs/link/Link.js +3 -2
- package/dist/cjs/link/Link.js.map +1 -1
- package/dist/cjs/link/Link.native.js +6 -1
- package/dist/cjs/link/Link.native.js.map +1 -1
- package/dist/cjs/link/href.native.js +2 -2
- package/dist/cjs/link/href.native.js.map +1 -1
- package/dist/cjs/link/useLinkTo.cjs +11 -3
- package/dist/cjs/link/useLinkTo.js +6 -3
- package/dist/cjs/link/useLinkTo.js.map +1 -1
- package/dist/cjs/link/useLinkTo.native.js +11 -3
- package/dist/cjs/link/useLinkTo.native.js.map +1 -1
- package/dist/cjs/router/Route.js.map +1 -1
- package/dist/cjs/router/Route.native.js.map +1 -1
- package/dist/cjs/router/findRouteNode.cjs +70 -0
- package/dist/cjs/router/findRouteNode.js +72 -0
- package/dist/cjs/router/findRouteNode.js.map +6 -0
- package/dist/cjs/router/findRouteNode.native.js +104 -0
- package/dist/cjs/router/findRouteNode.native.js.map +1 -0
- package/dist/cjs/router/getRoutes.native.js +3 -3
- package/dist/cjs/router/getRoutes.native.js.map +1 -1
- package/dist/cjs/router/router.cjs +160 -11
- package/dist/cjs/router/router.js +142 -7
- package/dist/cjs/router/router.js.map +2 -2
- package/dist/cjs/router/router.native.js +247 -67
- package/dist/cjs/router/router.native.js.map +1 -1
- package/dist/cjs/router/useNavigation.js.map +1 -1
- package/dist/cjs/router/useNavigation.native.js.map +1 -1
- package/dist/cjs/router/useScreens.cjs +1 -1
- package/dist/cjs/router/useScreens.js +1 -1
- package/dist/cjs/router/useScreens.js.map +1 -1
- package/dist/cjs/router/useScreens.native.js +6 -3
- package/dist/cjs/router/useScreens.native.js.map +1 -1
- package/dist/cjs/router/utils/getNavigateAction.native.js +2 -4
- package/dist/cjs/router/utils/getNavigateAction.native.js.map +1 -1
- package/dist/cjs/server/oneServe.js.map +1 -1
- package/dist/cjs/server/oneServe.native.js +4 -4
- package/dist/cjs/server/oneServe.native.js.map +1 -1
- package/dist/cjs/server/setupBuildOptions.native.js +1 -1
- package/dist/cjs/server/setupBuildOptions.native.js.map +1 -1
- package/dist/cjs/ui/common.native.js +6 -5
- package/dist/cjs/ui/common.native.js.map +1 -1
- package/dist/cjs/useBlocker.cjs +158 -0
- package/dist/cjs/useBlocker.js +145 -0
- package/dist/cjs/useBlocker.js.map +6 -0
- package/dist/cjs/useBlocker.native.js +89 -0
- package/dist/cjs/useBlocker.native.js.map +1 -0
- package/dist/cjs/useFocusEffect.cjs +2 -2
- package/dist/cjs/useFocusEffect.js +2 -2
- package/dist/cjs/useFocusEffect.js.map +1 -1
- package/dist/cjs/useFocusEffect.native.js +2 -2
- package/dist/cjs/useFocusEffect.native.js.map +1 -1
- package/dist/cjs/useLoader.cjs +69 -3
- package/dist/cjs/useLoader.js +57 -4
- package/dist/cjs/useLoader.js.map +2 -2
- package/dist/cjs/useLoader.native.js +90 -6
- package/dist/cjs/useLoader.native.js.map +1 -1
- package/dist/cjs/useScrollGroup.cjs +37 -0
- package/dist/cjs/useScrollGroup.js +30 -0
- package/dist/cjs/useScrollGroup.js.map +6 -0
- package/dist/cjs/useScrollGroup.native.js +29 -0
- package/dist/cjs/useScrollGroup.native.js.map +1 -0
- package/dist/cjs/validateParams.cjs +80 -0
- package/dist/cjs/validateParams.js +84 -0
- package/dist/cjs/validateParams.js.map +6 -0
- package/dist/cjs/validateParams.native.js +180 -0
- package/dist/cjs/validateParams.native.js.map +1 -0
- package/dist/cjs/validateSearch.cjs +104 -0
- package/dist/cjs/validateSearch.js +99 -0
- package/dist/cjs/validateSearch.js.map +6 -0
- package/dist/cjs/validateSearch.native.js +202 -0
- package/dist/cjs/validateSearch.native.js.map +1 -0
- package/dist/cjs/vercel/build/buildVercelOutputDirectory.native.js +2 -2
- package/dist/cjs/vercel/build/buildVercelOutputDirectory.native.js.map +1 -1
- package/dist/cjs/views/ErrorBoundary.cjs +293 -10
- package/dist/cjs/views/ErrorBoundary.js +328 -8
- package/dist/cjs/views/ErrorBoundary.js.map +2 -2
- package/dist/cjs/views/ErrorBoundary.native.js +159 -4
- package/dist/cjs/views/ErrorBoundary.native.js.map +1 -1
- package/dist/cjs/views/Navigator.cjs +10 -3
- package/dist/cjs/views/Navigator.js +11 -3
- package/dist/cjs/views/Navigator.js.map +1 -1
- package/dist/cjs/views/Navigator.native.js +15 -6
- package/dist/cjs/views/Navigator.native.js.map +1 -1
- package/dist/cjs/views/Protected.cjs +36 -0
- package/dist/cjs/views/Protected.js +27 -0
- package/dist/cjs/views/Protected.js.map +6 -0
- package/dist/cjs/views/Protected.native.js +44 -0
- package/dist/cjs/views/Protected.native.js.map +1 -0
- package/dist/cjs/views/RootErrorBoundary.cjs +193 -8
- package/dist/cjs/views/RootErrorBoundary.js +213 -8
- package/dist/cjs/views/RootErrorBoundary.js.map +1 -1
- package/dist/cjs/views/RootErrorBoundary.native.js +192 -8
- package/dist/cjs/views/RootErrorBoundary.native.js.map +1 -1
- package/dist/cjs/views/ScrollBehavior.cjs +49 -11
- package/dist/cjs/views/ScrollBehavior.js +47 -11
- package/dist/cjs/views/ScrollBehavior.js.map +1 -1
- package/dist/cjs/views/ScrollBehavior.native.js +68 -10
- package/dist/cjs/views/ScrollBehavior.native.js.map +1 -1
- package/dist/cjs/views/SourceInspector.cjs +28 -0
- package/dist/cjs/views/SourceInspector.js +23 -0
- package/dist/cjs/views/SourceInspector.js.map +6 -0
- package/dist/cjs/views/SourceInspector.native.js +32 -0
- package/dist/cjs/views/SourceInspector.native.js.map +1 -0
- package/dist/cjs/views/Try.cjs +40 -7
- package/dist/cjs/views/Try.js +38 -4
- package/dist/cjs/views/Try.js.map +1 -1
- package/dist/cjs/views/Try.native.js +42 -7
- package/dist/cjs/views/Try.native.js.map +1 -1
- package/dist/cjs/vite/DevHead.cjs +797 -43
- package/dist/cjs/vite/DevHead.js +802 -51
- package/dist/cjs/vite/DevHead.js.map +1 -1
- package/dist/cjs/vite/DevHead.native.js +783 -1
- package/dist/cjs/vite/DevHead.native.js.map +1 -1
- package/dist/cjs/vite/one.cjs +7 -1
- package/dist/cjs/vite/one.js +7 -2
- package/dist/cjs/vite/one.js.map +1 -1
- package/dist/cjs/vite/one.native.js +17 -7
- package/dist/cjs/vite/one.native.js.map +1 -1
- package/dist/cjs/vite/plugins/SSRCSSPlugin.cjs +44 -4
- package/dist/cjs/vite/plugins/SSRCSSPlugin.js +48 -4
- package/dist/cjs/vite/plugins/SSRCSSPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/SSRCSSPlugin.native.js +62 -5
- package/dist/cjs/vite/plugins/SSRCSSPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.cjs +34 -15
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.js +24 -3
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.native.js +55 -19
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.test.cjs +129 -0
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.test.js +129 -0
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.test.js.map +6 -0
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.test.native.js +140 -0
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.test.native.js.map +1 -0
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +6 -3
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +3 -3
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.cjs +5 -1
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js +11 -6
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +1 -0
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/sourceInspectorPlugin.cjs +155 -0
- package/dist/cjs/vite/plugins/sourceInspectorPlugin.js +148 -0
- package/dist/cjs/vite/plugins/sourceInspectorPlugin.js.map +6 -0
- package/dist/cjs/vite/plugins/sourceInspectorPlugin.native.js +231 -0
- package/dist/cjs/vite/plugins/sourceInspectorPlugin.native.js.map +1 -0
- package/dist/cjs/vite/plugins/virtualEntryPlugin.cjs +25 -6
- package/dist/cjs/vite/plugins/virtualEntryPlugin.js +16 -6
- package/dist/cjs/vite/plugins/virtualEntryPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js +26 -7
- package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
- package/dist/esm/cli/build.js +1 -1
- package/dist/esm/cli/build.js.map +1 -1
- package/dist/esm/cli/build.mjs +3 -1
- package/dist/esm/cli/build.mjs.map +1 -1
- package/dist/esm/cli/build.native.js +13 -12
- package/dist/esm/cli/build.native.js.map +1 -1
- package/dist/esm/cli/buildPage.js +1 -1
- package/dist/esm/cli/buildPage.mjs +1 -1
- package/dist/esm/cli/buildPage.mjs.map +1 -1
- package/dist/esm/cli/buildPage.native.js +2 -2
- package/dist/esm/cli/buildPage.native.js.map +1 -1
- package/dist/esm/cli/dev.js +4 -4
- package/dist/esm/cli/dev.js.map +1 -1
- package/dist/esm/cli/dev.mjs +4 -4
- package/dist/esm/cli/dev.mjs.map +1 -1
- package/dist/esm/cli/dev.native.js +4 -4
- package/dist/esm/cli/dev.native.js.map +1 -1
- package/dist/esm/cli/generateRoutes.js +1 -1
- package/dist/esm/cli/generateRoutes.mjs +1 -1
- package/dist/esm/cli/generateRoutes.mjs.map +1 -1
- package/dist/esm/cli/generateRoutes.native.js +1 -1
- package/dist/esm/cli/generateRoutes.native.js.map +1 -1
- package/dist/esm/cli/generateSitemap.native.js +7 -7
- package/dist/esm/cli/generateSitemap.native.js.map +1 -1
- package/dist/esm/config.native.js +2 -2
- package/dist/esm/config.native.js.map +1 -1
- package/dist/esm/constants.native.js +2 -2
- package/dist/esm/constants.native.js.map +1 -1
- package/dist/esm/createApp.js +2 -2
- package/dist/esm/createApp.js.map +1 -1
- package/dist/esm/createApp.mjs +2 -1
- package/dist/esm/createApp.mjs.map +1 -1
- package/dist/esm/createHandleRequest.test.js +3 -1
- package/dist/esm/createHandleRequest.test.js.map +1 -1
- package/dist/esm/createHandleRequest.test.mjs.map +1 -1
- package/dist/esm/createHandleRequest.test.native.js.map +1 -1
- package/dist/esm/devtools/registry.js +9 -0
- package/dist/esm/devtools/registry.js.map +6 -0
- package/dist/esm/devtools/registry.mjs +6 -0
- package/dist/esm/devtools/registry.mjs.map +1 -0
- package/dist/esm/devtools/registry.native.js +6 -0
- package/dist/esm/devtools/registry.native.js.map +1 -0
- package/dist/esm/fork/NavigationContainer.native.js +5 -5
- package/dist/esm/fork/NavigationContainer.native.js.map +1 -1
- package/dist/esm/fork/createMemoryHistory.js +22 -4
- package/dist/esm/fork/createMemoryHistory.js.map +1 -1
- package/dist/esm/fork/createMemoryHistory.mjs +20 -9
- package/dist/esm/fork/createMemoryHistory.mjs.map +1 -1
- package/dist/esm/fork/createMemoryHistory.native.js +22 -11
- package/dist/esm/fork/createMemoryHistory.native.js.map +1 -1
- package/dist/esm/fork/extractPathFromURL.native.js +8 -8
- package/dist/esm/fork/extractPathFromURL.native.js.map +1 -1
- package/dist/esm/fork/findFocusedRoute.native.js +2 -3
- package/dist/esm/fork/findFocusedRoute.native.js.map +1 -1
- package/dist/esm/fork/getPathFromState-mods.native.js +2 -3
- package/dist/esm/fork/getPathFromState-mods.native.js.map +1 -1
- package/dist/esm/fork/getStateFromPath-mods.native.js +3 -3
- package/dist/esm/fork/getStateFromPath-mods.native.js.map +1 -1
- package/dist/esm/fork/useLinking.js +6 -5
- package/dist/esm/fork/useLinking.js.map +1 -1
- package/dist/esm/fork/useLinking.mjs +11 -5
- package/dist/esm/fork/useLinking.mjs.map +1 -1
- package/dist/esm/fork/useLinking.native.js.map +1 -1
- package/dist/esm/head/url.native.js +2 -3
- package/dist/esm/head/url.native.js.map +1 -1
- package/dist/esm/hooks.js.map +1 -1
- package/dist/esm/hooks.mjs.map +1 -1
- package/dist/esm/hooks.native.js.map +1 -1
- package/dist/esm/index.js +30 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +8 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +8 -2
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/layouts/withLayoutContext.js +30 -12
- package/dist/esm/layouts/withLayoutContext.js.map +1 -1
- package/dist/esm/layouts/withLayoutContext.mjs +34 -15
- package/dist/esm/layouts/withLayoutContext.mjs.map +1 -1
- package/dist/esm/layouts/withLayoutContext.native.js +42 -19
- package/dist/esm/layouts/withLayoutContext.native.js.map +1 -1
- package/dist/esm/link/Link.js +3 -2
- package/dist/esm/link/Link.js.map +1 -1
- package/dist/esm/link/Link.mjs +5 -2
- package/dist/esm/link/Link.mjs.map +1 -1
- package/dist/esm/link/Link.native.js +6 -1
- package/dist/esm/link/Link.native.js.map +1 -1
- package/dist/esm/link/href.native.js +2 -2
- package/dist/esm/link/href.native.js.map +1 -1
- package/dist/esm/link/useLinkTo.js +6 -3
- package/dist/esm/link/useLinkTo.js.map +1 -1
- package/dist/esm/link/useLinkTo.mjs +11 -3
- package/dist/esm/link/useLinkTo.mjs.map +1 -1
- package/dist/esm/link/useLinkTo.native.js +11 -3
- package/dist/esm/link/useLinkTo.native.js.map +1 -1
- package/dist/esm/router/Route.js.map +1 -1
- package/dist/esm/router/Route.mjs.map +1 -1
- package/dist/esm/router/Route.native.js.map +1 -1
- package/dist/esm/router/findRouteNode.js +56 -0
- package/dist/esm/router/findRouteNode.js.map +6 -0
- package/dist/esm/router/findRouteNode.mjs +44 -0
- package/dist/esm/router/findRouteNode.mjs.map +1 -0
- package/dist/esm/router/findRouteNode.native.js +75 -0
- package/dist/esm/router/findRouteNode.native.js.map +1 -0
- package/dist/esm/router/getRoutes.native.js +3 -3
- package/dist/esm/router/getRoutes.native.js.map +1 -1
- package/dist/esm/router/router.js +154 -6
- package/dist/esm/router/router.js.map +1 -1
- package/dist/esm/router/router.mjs +151 -10
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +238 -66
- package/dist/esm/router/router.native.js.map +1 -1
- package/dist/esm/router/useNavigation.js.map +1 -1
- package/dist/esm/router/useNavigation.mjs.map +1 -1
- package/dist/esm/router/useNavigation.native.js.map +1 -1
- package/dist/esm/router/useScreens.js +1 -1
- package/dist/esm/router/useScreens.js.map +1 -1
- package/dist/esm/router/useScreens.mjs +1 -1
- package/dist/esm/router/useScreens.mjs.map +1 -1
- package/dist/esm/router/useScreens.native.js +6 -3
- package/dist/esm/router/useScreens.native.js.map +1 -1
- package/dist/esm/router/utils/getNavigateAction.native.js +2 -4
- package/dist/esm/router/utils/getNavigateAction.native.js.map +1 -1
- package/dist/esm/server/oneServe.js.map +1 -1
- package/dist/esm/server/oneServe.mjs.map +1 -1
- package/dist/esm/server/oneServe.native.js +4 -4
- package/dist/esm/server/oneServe.native.js.map +1 -1
- package/dist/esm/server/setupBuildOptions.native.js +1 -1
- package/dist/esm/server/setupBuildOptions.native.js.map +1 -1
- package/dist/esm/ui/common.native.js +6 -5
- package/dist/esm/ui/common.native.js.map +1 -1
- package/dist/esm/useBlocker.js +122 -0
- package/dist/esm/useBlocker.js.map +6 -0
- package/dist/esm/useBlocker.mjs +123 -0
- package/dist/esm/useBlocker.mjs.map +1 -0
- package/dist/esm/useBlocker.native.js +51 -0
- package/dist/esm/useBlocker.native.js.map +1 -0
- package/dist/esm/useFocusEffect.js +2 -2
- package/dist/esm/useFocusEffect.js.map +1 -1
- package/dist/esm/useFocusEffect.mjs +2 -2
- package/dist/esm/useFocusEffect.mjs.map +1 -1
- package/dist/esm/useFocusEffect.native.js +2 -2
- package/dist/esm/useFocusEffect.native.js.map +1 -1
- package/dist/esm/useLoader.js +57 -3
- package/dist/esm/useLoader.js.map +2 -2
- package/dist/esm/useLoader.mjs +69 -4
- package/dist/esm/useLoader.mjs.map +1 -1
- package/dist/esm/useLoader.native.js +90 -7
- package/dist/esm/useLoader.native.js.map +1 -1
- package/dist/esm/useScrollGroup.js +16 -0
- package/dist/esm/useScrollGroup.js.map +6 -0
- package/dist/esm/useScrollGroup.mjs +14 -0
- package/dist/esm/useScrollGroup.mjs.map +1 -0
- package/dist/esm/useScrollGroup.native.js +3 -0
- package/dist/esm/useScrollGroup.native.js.map +1 -0
- package/dist/esm/validateParams.js +68 -0
- package/dist/esm/validateParams.js.map +6 -0
- package/dist/esm/validateParams.mjs +54 -0
- package/dist/esm/validateParams.mjs.map +1 -0
- package/dist/esm/validateParams.native.js +151 -0
- package/dist/esm/validateParams.native.js.map +1 -0
- package/dist/esm/validateSearch.js +83 -0
- package/dist/esm/validateSearch.js.map +6 -0
- package/dist/esm/validateSearch.mjs +77 -0
- package/dist/esm/validateSearch.mjs.map +1 -0
- package/dist/esm/validateSearch.native.js +172 -0
- package/dist/esm/validateSearch.native.js.map +1 -0
- package/dist/esm/vercel/build/buildVercelOutputDirectory.native.js +2 -2
- package/dist/esm/vercel/build/buildVercelOutputDirectory.native.js.map +1 -1
- package/dist/esm/views/ErrorBoundary.js +325 -7
- package/dist/esm/views/ErrorBoundary.js.map +2 -2
- package/dist/esm/views/ErrorBoundary.mjs +289 -6
- package/dist/esm/views/ErrorBoundary.mjs.map +1 -1
- package/dist/esm/views/ErrorBoundary.native.js +159 -4
- package/dist/esm/views/ErrorBoundary.native.js.map +1 -1
- package/dist/esm/views/Navigator.js +11 -2
- package/dist/esm/views/Navigator.js.map +1 -1
- package/dist/esm/views/Navigator.mjs +10 -3
- package/dist/esm/views/Navigator.mjs.map +1 -1
- package/dist/esm/views/Navigator.native.js +15 -6
- package/dist/esm/views/Navigator.native.js.map +1 -1
- package/dist/esm/views/Protected.js +14 -0
- package/dist/esm/views/Protected.js.map +6 -0
- package/dist/esm/views/Protected.mjs +11 -0
- package/dist/esm/views/Protected.mjs.map +1 -0
- package/dist/esm/views/Protected.native.js +16 -0
- package/dist/esm/views/Protected.native.js.map +1 -0
- package/dist/esm/views/RootErrorBoundary.js +214 -7
- package/dist/esm/views/RootErrorBoundary.js.map +1 -1
- package/dist/esm/views/RootErrorBoundary.mjs +192 -7
- package/dist/esm/views/RootErrorBoundary.mjs.map +1 -1
- package/dist/esm/views/RootErrorBoundary.native.js +191 -7
- package/dist/esm/views/RootErrorBoundary.native.js.map +1 -1
- package/dist/esm/views/ScrollBehavior.js +47 -11
- package/dist/esm/views/ScrollBehavior.js.map +1 -1
- package/dist/esm/views/ScrollBehavior.mjs +48 -11
- package/dist/esm/views/ScrollBehavior.mjs.map +1 -1
- package/dist/esm/views/ScrollBehavior.native.js +67 -10
- package/dist/esm/views/ScrollBehavior.native.js.map +1 -1
- package/dist/esm/views/SourceInspector.js +7 -0
- package/dist/esm/views/SourceInspector.js.map +6 -0
- package/dist/esm/views/SourceInspector.mjs +5 -0
- package/dist/esm/views/SourceInspector.mjs.map +1 -0
- package/dist/esm/views/SourceInspector.native.js +6 -0
- package/dist/esm/views/SourceInspector.native.js.map +1 -0
- package/dist/esm/views/Try.js +38 -4
- package/dist/esm/views/Try.js.map +1 -1
- package/dist/esm/views/Try.mjs +40 -7
- package/dist/esm/views/Try.mjs.map +1 -1
- package/dist/esm/views/Try.native.js +42 -7
- package/dist/esm/views/Try.native.js.map +1 -1
- package/dist/esm/vite/DevHead.js +802 -51
- package/dist/esm/vite/DevHead.js.map +1 -1
- package/dist/esm/vite/DevHead.mjs +797 -43
- package/dist/esm/vite/DevHead.mjs.map +1 -1
- package/dist/esm/vite/DevHead.native.js +782 -0
- package/dist/esm/vite/DevHead.native.js.map +1 -1
- package/dist/esm/vite/one.js +7 -1
- package/dist/esm/vite/one.js.map +1 -1
- package/dist/esm/vite/one.mjs +7 -1
- package/dist/esm/vite/one.mjs.map +1 -1
- package/dist/esm/vite/one.native.js +17 -7
- package/dist/esm/vite/one.native.js.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.js +48 -4
- package/dist/esm/vite/plugins/SSRCSSPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.mjs +44 -4
- package/dist/esm/vite/plugins/SSRCSSPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.native.js +61 -4
- package/dist/esm/vite/plugins/SSRCSSPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/clientTreeShakePlugin.js +24 -3
- package/dist/esm/vite/plugins/clientTreeShakePlugin.js.map +1 -1
- package/dist/esm/vite/plugins/clientTreeShakePlugin.mjs +34 -15
- package/dist/esm/vite/plugins/clientTreeShakePlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/clientTreeShakePlugin.native.js +55 -19
- package/dist/esm/vite/plugins/clientTreeShakePlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.js +130 -0
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.js.map +6 -0
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.mjs +130 -0
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.mjs.map +1 -0
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.native.js +138 -0
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.native.js.map +1 -0
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +6 -3
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +3 -3
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js +11 -6
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs +5 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +1 -0
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/sourceInspectorPlugin.js +126 -0
- package/dist/esm/vite/plugins/sourceInspectorPlugin.js.map +6 -0
- package/dist/esm/vite/plugins/sourceInspectorPlugin.mjs +121 -0
- package/dist/esm/vite/plugins/sourceInspectorPlugin.mjs.map +1 -0
- package/dist/esm/vite/plugins/sourceInspectorPlugin.native.js +194 -0
- package/dist/esm/vite/plugins/sourceInspectorPlugin.native.js.map +1 -0
- package/dist/esm/vite/plugins/virtualEntryPlugin.js +16 -6
- package/dist/esm/vite/plugins/virtualEntryPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.mjs +25 -6
- package/dist/esm/vite/plugins/virtualEntryPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.native.js +26 -7
- package/dist/esm/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
- package/package.json +16 -14
- package/src/cli/build.ts +1 -1
- package/src/cli/buildPage.ts +1 -1
- package/src/cli/dev.ts +4 -4
- package/src/cli/generateRoutes.ts +1 -1
- package/src/createApp.tsx +11 -1
- package/src/createHandleRequest.test.ts +3 -1
- package/src/devtools/registry.ts +21 -0
- package/src/fork/createMemoryHistory.tsx +43 -11
- package/src/fork/useLinking.ts +14 -4
- package/src/hooks.tsx +71 -21
- package/src/index.ts +34 -1
- package/src/interfaces/router.ts +48 -0
- package/src/layouts/withLayoutContext.tsx +48 -8
- package/src/link/Link.tsx +7 -2
- package/src/link/useLinkTo.tsx +7 -3
- package/src/router/Route.tsx +32 -3
- package/src/router/findRouteNode.ts +127 -0
- package/src/router/router.ts +291 -2
- package/src/router/useNavigation.ts +12 -3
- package/src/router/useScreens.tsx +9 -3
- package/src/useBlocker.native.ts +153 -0
- package/src/useBlocker.ts +340 -0
- package/src/useFocusEffect.ts +18 -5
- package/src/useLoader.ts +193 -2
- package/src/useScrollGroup.native.ts +7 -0
- package/src/useScrollGroup.ts +35 -0
- package/src/validateParams.ts +196 -0
- package/src/validateSearch.ts +241 -0
- package/src/views/ErrorBoundary.tsx +154 -156
- package/src/views/ErrorBoundary.web.tsx +321 -0
- package/src/views/Navigator.tsx +18 -2
- package/src/views/Protected.tsx +62 -0
- package/src/views/RootErrorBoundary.tsx +214 -17
- package/src/views/ScrollBehavior.tsx +82 -3
- package/src/views/SourceInspector.tsx +39 -0
- package/src/views/Try.tsx +81 -12
- package/src/vite/DevHead.tsx +819 -54
- package/src/vite/one.ts +13 -0
- package/src/vite/plugins/SSRCSSPlugin.ts +104 -0
- package/src/vite/plugins/clientTreeShakePlugin.test.ts +174 -0
- package/src/vite/plugins/clientTreeShakePlugin.ts +50 -4
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +11 -8
- package/src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx +4 -0
- package/src/vite/plugins/sourceInspectorPlugin.ts +246 -0
- package/src/vite/plugins/virtualEntryPlugin.ts +36 -10
- package/src/vite/types.ts +28 -0
- package/types/createApp.d.ts +5 -0
- package/types/createApp.d.ts.map +1 -1
- package/types/devtools/registry.d.ts +15 -0
- package/types/devtools/registry.d.ts.map +1 -0
- package/types/fork/createMemoryHistory.d.ts +8 -3
- package/types/fork/createMemoryHistory.d.ts.map +1 -1
- package/types/fork/useLinking.d.ts.map +1 -1
- package/types/hooks.d.ts +71 -20
- package/types/hooks.d.ts.map +1 -1
- package/types/index.d.ts +8 -1
- package/types/index.d.ts.map +1 -1
- package/types/interfaces/router.d.ts +47 -0
- package/types/interfaces/router.d.ts.map +1 -1
- package/types/layouts/Drawer.d.ts +15 -11
- package/types/layouts/Drawer.d.ts.map +1 -1
- package/types/layouts/withLayoutContext.d.ts +2 -1
- package/types/layouts/withLayoutContext.d.ts.map +1 -1
- package/types/link/Link.d.ts.map +1 -1
- package/types/link/useLinkTo.d.ts +1 -0
- package/types/link/useLinkTo.d.ts.map +1 -1
- package/types/router/Route.d.ts +32 -3
- package/types/router/Route.d.ts.map +1 -1
- package/types/router/findRouteNode.d.ts +31 -0
- package/types/router/findRouteNode.d.ts.map +1 -0
- package/types/router/router.d.ts +35 -0
- package/types/router/router.d.ts.map +1 -1
- package/types/router/useNavigation.d.ts +12 -3
- package/types/router/useNavigation.d.ts.map +1 -1
- package/types/router/useScreens.d.ts +2 -0
- package/types/router/useScreens.d.ts.map +1 -1
- package/types/server/oneServe.d.ts.map +1 -1
- package/types/ui/TabContext.d.ts +1 -1
- package/types/ui/TabContext.d.ts.map +1 -1
- package/types/ui/Tabs.d.ts +2 -2
- package/types/ui/Tabs.d.ts.map +1 -1
- package/types/useBlocker.d.ts +72 -0
- package/types/useBlocker.d.ts.map +1 -0
- package/types/useBlocker.native.d.ts +60 -0
- package/types/useBlocker.native.d.ts.map +1 -0
- package/types/useFocusEffect.d.ts +17 -4
- package/types/useFocusEffect.d.ts.map +1 -1
- package/types/useLoader.d.ts +63 -0
- package/types/useLoader.d.ts.map +1 -1
- package/types/useScrollGroup.d.ts +18 -0
- package/types/useScrollGroup.d.ts.map +1 -0
- package/types/useScrollGroup.native.d.ts +6 -0
- package/types/useScrollGroup.native.d.ts.map +1 -0
- package/types/validateParams.d.ts +85 -0
- package/types/validateParams.d.ts.map +1 -0
- package/types/validateSearch.d.ts +107 -0
- package/types/validateSearch.d.ts.map +1 -0
- package/types/views/ErrorBoundary.d.ts +11 -1
- package/types/views/ErrorBoundary.d.ts.map +1 -1
- package/types/views/ErrorBoundary.web.d.ts +13 -0
- package/types/views/ErrorBoundary.web.d.ts.map +1 -0
- package/types/views/Navigator.d.ts.map +1 -1
- package/types/views/Protected.d.ts +39 -0
- package/types/views/Protected.d.ts.map +1 -0
- package/types/views/RootErrorBoundary.d.ts +14 -8
- package/types/views/RootErrorBoundary.d.ts.map +1 -1
- package/types/views/ScrollBehavior.d.ts +8 -0
- package/types/views/ScrollBehavior.d.ts.map +1 -1
- package/types/views/SourceInspector.d.ts +35 -0
- package/types/views/SourceInspector.d.ts.map +1 -0
- package/types/views/Try.d.ts +29 -6
- package/types/views/Try.d.ts.map +1 -1
- package/types/vite/DevHead.d.ts.map +1 -1
- package/types/vite/one.d.ts.map +1 -1
- package/types/vite/plugins/SSRCSSPlugin.d.ts.map +1 -1
- package/types/vite/plugins/clientTreeShakePlugin.d.ts.map +1 -1
- package/types/vite/plugins/clientTreeShakePlugin.test.d.ts +2 -0
- package/types/vite/plugins/clientTreeShakePlugin.test.d.ts.map +1 -0
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
- package/types/vite/plugins/generateFileSystemRouteTypesPlugin.d.ts.map +1 -1
- package/types/vite/plugins/sourceInspectorPlugin.d.ts +3 -0
- package/types/vite/plugins/sourceInspectorPlugin.d.ts.map +1 -0
- package/types/vite/plugins/virtualEntryPlugin.d.ts.map +1 -1
- package/types/vite/types.d.ts +24 -0
- package/types/vite/types.d.ts.map +1 -1
- package/types/env.d.ts +0 -66
- /package/types/vercel/build/generate/{createSSRServerlessFunction.d.ts → createSsrServerlessFunction.d.ts} +0 -0
package/src/vite/one.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { createFileSystemRouterPlugin } from './plugins/fileSystemRouterPlugin'
|
|
|
22
22
|
import { fixDependenciesPlugin } from './plugins/fixDependenciesPlugin'
|
|
23
23
|
import { generateFileSystemRouteTypesPlugin } from './plugins/generateFileSystemRouteTypesPlugin'
|
|
24
24
|
import { imageDataPlugin } from './plugins/imageDataPlugin'
|
|
25
|
+
import { sourceInspectorPlugin } from './plugins/sourceInspectorPlugin'
|
|
25
26
|
import { SSRCSSPlugin } from './plugins/SSRCSSPlugin'
|
|
26
27
|
import { virtualEntryId } from './plugins/virtualEntryConstants'
|
|
27
28
|
import { createVirtualEntry } from './plugins/virtualEntryPlugin'
|
|
@@ -678,5 +679,17 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
|
678
679
|
SSRCSSPlugin({
|
|
679
680
|
entries: [virtualEntryId],
|
|
680
681
|
}),
|
|
682
|
+
|
|
683
|
+
// Source inspector - show source file location on hover with Shift+Ctrl/Cmd
|
|
684
|
+
...(() => {
|
|
685
|
+
// devtools defaults to true
|
|
686
|
+
const devtools = options.devtools ?? true
|
|
687
|
+
if (devtools === false) return []
|
|
688
|
+
|
|
689
|
+
// if devtools is true, enable all tools
|
|
690
|
+
// if devtools is object, check individual settings (default true)
|
|
691
|
+
const inspector = devtools === true || (devtools.inspector ?? true)
|
|
692
|
+
return inspector ? sourceInspectorPlugin() : []
|
|
693
|
+
})(),
|
|
681
694
|
]
|
|
682
695
|
}
|
|
@@ -3,6 +3,11 @@ import { VIRTUAL_SSR_CSS_ENTRY, VIRTUAL_SSR_CSS_HREF } from '../../constants'
|
|
|
3
3
|
|
|
4
4
|
// thanks to hi-ogawa https://github.com/hi-ogawa/vite-plugins/tree/main/packages/ssr-css
|
|
5
5
|
|
|
6
|
+
// Track if we've pre-warmed routes and cached CSS
|
|
7
|
+
let cssCache: { css: string; timestamp: number } | null = null
|
|
8
|
+
let routesPreWarmed = false
|
|
9
|
+
const CSS_CACHE_TTL = 1000 // 1 second cache for dev mode
|
|
10
|
+
|
|
6
11
|
export function SSRCSSPlugin(pluginOpts: { entries: string[] }): Plugin {
|
|
7
12
|
let server: ViteDevServer
|
|
8
13
|
|
|
@@ -12,12 +17,64 @@ export function SSRCSSPlugin(pluginOpts: { entries: string[] }): Plugin {
|
|
|
12
17
|
configureServer(server_) {
|
|
13
18
|
server = server_
|
|
14
19
|
|
|
20
|
+
// Pre-warm route modules on first request to populate the module graph
|
|
21
|
+
// This ensures CSS from all routes is collected even for lazy imports
|
|
22
|
+
const preWarmRoutes = async () => {
|
|
23
|
+
if (routesPreWarmed) return
|
|
24
|
+
routesPreWarmed = true
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
// Transform the virtual entry to get route module paths
|
|
28
|
+
await server.transformRequest(pluginOpts.entries[0])
|
|
29
|
+
|
|
30
|
+
// Get all route files from the module graph
|
|
31
|
+
const routeFiles = await collectRouteFiles(server, pluginOpts.entries)
|
|
32
|
+
|
|
33
|
+
// Transform each route file to warm its CSS dependencies
|
|
34
|
+
await Promise.all(
|
|
35
|
+
routeFiles.map((file) =>
|
|
36
|
+
server.transformRequest(file).catch(() => {
|
|
37
|
+
// Ignore errors - some routes may have issues
|
|
38
|
+
})
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
if (process.env.ONE_DEBUG) {
|
|
43
|
+
console.log(
|
|
44
|
+
`[one] Pre-warmed ${routeFiles.length} route modules for CSS collection`
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error('[one] Error pre-warming routes:', err)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Invalidate CSS cache on HMR
|
|
53
|
+
server.watcher.on('change', () => {
|
|
54
|
+
cssCache = null
|
|
55
|
+
})
|
|
56
|
+
|
|
15
57
|
// invalidate virtual modules for each direct request
|
|
16
58
|
server.middlewares.use(async (req, res, next) => {
|
|
17
59
|
if (req.url?.includes(VIRTUAL_SSR_CSS_HREF)) {
|
|
60
|
+
// Pre-warm routes on first CSS request
|
|
61
|
+
await preWarmRoutes()
|
|
62
|
+
|
|
18
63
|
invalidateModule(server, '\0' + VIRTUAL_SSR_CSS_ENTRY + '?direct')
|
|
19
64
|
|
|
65
|
+
// Use cached CSS if fresh
|
|
66
|
+
const now = Date.now()
|
|
67
|
+
if (cssCache && now - cssCache.timestamp < CSS_CACHE_TTL) {
|
|
68
|
+
res.setHeader('Content-Type', 'text/css')
|
|
69
|
+
res.setHeader('Cache-Control', 'no-store')
|
|
70
|
+
res.setHeader('Vary', '*')
|
|
71
|
+
res.write(cssCache.css)
|
|
72
|
+
res.end()
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
20
76
|
const code = await collectStyle(server, pluginOpts.entries)
|
|
77
|
+
cssCache = { css: code, timestamp: now }
|
|
21
78
|
|
|
22
79
|
res.setHeader('Content-Type', 'text/css')
|
|
23
80
|
res.setHeader('Cache-Control', 'no-store')
|
|
@@ -175,3 +232,50 @@ async function collectStyleUrls(
|
|
|
175
232
|
|
|
176
233
|
// cf. https://github.com/vitejs/vite/blob/d6bde8b03d433778aaed62afc2be0630c8131908/packages/vite/src/node/constants.ts#L49C23-L50
|
|
177
234
|
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/
|
|
235
|
+
|
|
236
|
+
// Match route files from dynamic imports in virtual entry
|
|
237
|
+
// Vite transforms import.meta.glob to:
|
|
238
|
+
// const routes = { "./path/to/file.tsx": () => import("./path/to/file.tsx") }
|
|
239
|
+
const DYNAMIC_IMPORT_RE = /import\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Collect all route file paths from the module graph.
|
|
243
|
+
* This is used to pre-warm route modules so their CSS is included.
|
|
244
|
+
*/
|
|
245
|
+
async function collectRouteFiles(
|
|
246
|
+
server: ViteDevServer,
|
|
247
|
+
entries: string[]
|
|
248
|
+
): Promise<string[]> {
|
|
249
|
+
const routeFiles: string[] = []
|
|
250
|
+
|
|
251
|
+
for (const entry of entries) {
|
|
252
|
+
try {
|
|
253
|
+
// Get the transformed code for the entry
|
|
254
|
+
const result = await server.transformRequest(entry)
|
|
255
|
+
if (!result?.code) continue
|
|
256
|
+
|
|
257
|
+
// Extract dynamic import paths from the transformed code
|
|
258
|
+
let match
|
|
259
|
+
while ((match = DYNAMIC_IMPORT_RE.exec(result.code)) !== null) {
|
|
260
|
+
const importPath = match[1]
|
|
261
|
+
// Only include actual route files, not node_modules or virtual
|
|
262
|
+
if (
|
|
263
|
+
importPath &&
|
|
264
|
+
!importPath.includes('node_modules') &&
|
|
265
|
+
!importPath.startsWith('\0') &&
|
|
266
|
+
!importPath.startsWith('virtual:') &&
|
|
267
|
+
(importPath.endsWith('.tsx') ||
|
|
268
|
+
importPath.endsWith('.ts') ||
|
|
269
|
+
importPath.endsWith('.jsx') ||
|
|
270
|
+
importPath.endsWith('.js'))
|
|
271
|
+
) {
|
|
272
|
+
routeFiles.push(importPath)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
} catch {
|
|
276
|
+
// Ignore errors
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return routeFiles
|
|
281
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { transformTreeShakeClient } from './clientTreeShakePlugin'
|
|
3
|
+
|
|
4
|
+
describe('clientTreeShakePlugin', () => {
|
|
5
|
+
describe('transformTreeShakeClient', () => {
|
|
6
|
+
it('should remove loader export and its imports', async () => {
|
|
7
|
+
const code = `
|
|
8
|
+
import { serverOnlyModule } from 'server-only-pkg'
|
|
9
|
+
import { Text } from 'react-native'
|
|
10
|
+
import { useLoader } from 'one'
|
|
11
|
+
|
|
12
|
+
export function loader() {
|
|
13
|
+
return serverOnlyModule()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default function Page() {
|
|
17
|
+
const data = useLoader(loader)
|
|
18
|
+
return <Text>{data}</Text>
|
|
19
|
+
}
|
|
20
|
+
`
|
|
21
|
+
const result = await transformTreeShakeClient(code, '/app/index.tsx')
|
|
22
|
+
expect(result).toBeDefined()
|
|
23
|
+
// The server-only import should be removed
|
|
24
|
+
expect(result!.code).not.toContain('server-only-pkg')
|
|
25
|
+
// But react-native and one should remain
|
|
26
|
+
expect(result!.code).toContain('react-native')
|
|
27
|
+
expect(result!.code).toContain('one')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('should remove loader export with dynamic import', async () => {
|
|
31
|
+
const code = `
|
|
32
|
+
import { Text } from 'react-native'
|
|
33
|
+
import { useLoader } from 'one'
|
|
34
|
+
|
|
35
|
+
export async function loader() {
|
|
36
|
+
const { serverFn } = await import('server-only-pkg')
|
|
37
|
+
return serverFn()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default function Page() {
|
|
41
|
+
const data = useLoader(loader)
|
|
42
|
+
return <Text>{data}</Text>
|
|
43
|
+
}
|
|
44
|
+
`
|
|
45
|
+
const result = await transformTreeShakeClient(code, '/app/index.tsx')
|
|
46
|
+
expect(result).toBeDefined()
|
|
47
|
+
// Dynamic import should also be removed along with the loader
|
|
48
|
+
expect(result!.code).not.toContain('server-only-pkg')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('should remove loader with const arrow function export', async () => {
|
|
52
|
+
const code = `
|
|
53
|
+
import { serverOnlyModule } from 'server-only-pkg'
|
|
54
|
+
import { Text } from 'react-native'
|
|
55
|
+
import { useLoader } from 'one'
|
|
56
|
+
|
|
57
|
+
export const loader = async () => {
|
|
58
|
+
return serverOnlyModule()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default function Page() {
|
|
62
|
+
const data = useLoader(loader)
|
|
63
|
+
return <Text>{data}</Text>
|
|
64
|
+
}
|
|
65
|
+
`
|
|
66
|
+
const result = await transformTreeShakeClient(code, '/app/index.tsx')
|
|
67
|
+
expect(result).toBeDefined()
|
|
68
|
+
// The server-only import should be removed
|
|
69
|
+
expect(result!.code).not.toContain('server-only-pkg')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('should handle multiple imports where only some are used in loader', async () => {
|
|
73
|
+
const code = `
|
|
74
|
+
import { serverFn } from 'server-only-pkg'
|
|
75
|
+
import { sharedUtil } from 'shared-pkg'
|
|
76
|
+
import { Text } from 'react-native'
|
|
77
|
+
import { useLoader } from 'one'
|
|
78
|
+
|
|
79
|
+
export function loader() {
|
|
80
|
+
return serverFn()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default function Page() {
|
|
84
|
+
const data = useLoader(loader)
|
|
85
|
+
return <Text>{sharedUtil(data)}</Text>
|
|
86
|
+
}
|
|
87
|
+
`
|
|
88
|
+
const result = await transformTreeShakeClient(code, '/app/index.tsx')
|
|
89
|
+
expect(result).toBeDefined()
|
|
90
|
+
// server-only-pkg should be removed (only used in loader)
|
|
91
|
+
expect(result!.code).not.toContain('server-only-pkg')
|
|
92
|
+
// shared-pkg should remain (used in component)
|
|
93
|
+
expect(result!.code).toContain('shared-pkg')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('should remove generateStaticParams and its imports', async () => {
|
|
97
|
+
const code = `
|
|
98
|
+
import { getRoutes } from 'server-only-pkg'
|
|
99
|
+
import { Text } from 'react-native'
|
|
100
|
+
|
|
101
|
+
export function generateStaticParams() {
|
|
102
|
+
return getRoutes()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export default function Page() {
|
|
106
|
+
return <Text>Hello</Text>
|
|
107
|
+
}
|
|
108
|
+
`
|
|
109
|
+
const result = await transformTreeShakeClient(code, '/app/[slug].tsx')
|
|
110
|
+
expect(result).toBeDefined()
|
|
111
|
+
expect(result!.code).not.toContain('server-only-pkg')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('should not transform files without loader or generateStaticParams', async () => {
|
|
115
|
+
const code = `
|
|
116
|
+
import { Text } from 'react-native'
|
|
117
|
+
|
|
118
|
+
export default function Page() {
|
|
119
|
+
return <Text>Hello</Text>
|
|
120
|
+
}
|
|
121
|
+
`
|
|
122
|
+
const result = await transformTreeShakeClient(code, '/app/index.tsx')
|
|
123
|
+
expect(result).toBeUndefined()
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('should preserve type-only imports during tree shaking', async () => {
|
|
127
|
+
const code = `
|
|
128
|
+
import type { SomeType } from 'types-pkg'
|
|
129
|
+
import { serverFn } from 'server-only-pkg'
|
|
130
|
+
import { Text } from 'react-native'
|
|
131
|
+
import { useLoader } from 'one'
|
|
132
|
+
|
|
133
|
+
export function loader(): SomeType {
|
|
134
|
+
return serverFn()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export default function Page() {
|
|
138
|
+
const data = useLoader(loader)
|
|
139
|
+
return <Text>{data}</Text>
|
|
140
|
+
}
|
|
141
|
+
`
|
|
142
|
+
const result = await transformTreeShakeClient(code, '/app/index.tsx')
|
|
143
|
+
expect(result).toBeDefined()
|
|
144
|
+
// Type import should be preserved
|
|
145
|
+
expect(result!.code).toContain('types-pkg')
|
|
146
|
+
// Server-only import should be removed
|
|
147
|
+
expect(result!.code).not.toContain('server-only-pkg')
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('should preserve type imports even when used only in loader', async () => {
|
|
151
|
+
const code = `
|
|
152
|
+
import type { APIGuildMember } from '@discordjs/core'
|
|
153
|
+
import { getClient } from 'discord-client'
|
|
154
|
+
import { Text } from 'react-native'
|
|
155
|
+
import { useLoader } from 'one'
|
|
156
|
+
|
|
157
|
+
export function loader(): APIGuildMember {
|
|
158
|
+
return getClient()
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export default function Page() {
|
|
162
|
+
const data = useLoader(loader)
|
|
163
|
+
return <Text>{JSON.stringify(data)}</Text>
|
|
164
|
+
}
|
|
165
|
+
`
|
|
166
|
+
const result = await transformTreeShakeClient(code, '/app/index.tsx')
|
|
167
|
+
expect(result).toBeDefined()
|
|
168
|
+
// Type import should be preserved (TypeScript erases these at compile time)
|
|
169
|
+
expect(result!.code).toContain('@discordjs/core')
|
|
170
|
+
// Runtime import should be removed
|
|
171
|
+
expect(result!.code).not.toContain('discord-client')
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
})
|
|
@@ -2,6 +2,7 @@ import { extname, relative } from 'node:path'
|
|
|
2
2
|
import BabelGenerate from '@babel/generator'
|
|
3
3
|
import { parse } from '@babel/parser'
|
|
4
4
|
import BabelTraverse from '@babel/traverse'
|
|
5
|
+
import type * as t from '@babel/types'
|
|
5
6
|
import {
|
|
6
7
|
deadCodeElimination,
|
|
7
8
|
findReferencedIdentifiers,
|
|
@@ -9,8 +10,46 @@ import {
|
|
|
9
10
|
import type { Plugin } from 'vite'
|
|
10
11
|
import { EMPTY_LOADER_STRING } from '../constants'
|
|
11
12
|
|
|
12
|
-
const traverse = BabelTraverse['default'] as typeof BabelTraverse
|
|
13
|
-
const generate = BabelGenerate['default']
|
|
13
|
+
const traverse = (BabelTraverse['default'] || BabelTraverse) as typeof BabelTraverse
|
|
14
|
+
const generate = (BabelGenerate['default'] ||
|
|
15
|
+
BabelGenerate) as any as typeof BabelGenerate
|
|
16
|
+
|
|
17
|
+
// Collect type-only imports before dead code elimination runs
|
|
18
|
+
// These should never be removed since TypeScript erases them at compile time
|
|
19
|
+
function collectTypeImports(ast: t.File): t.ImportDeclaration[] {
|
|
20
|
+
const typeImports: t.ImportDeclaration[] = []
|
|
21
|
+
traverse(ast, {
|
|
22
|
+
ImportDeclaration(path) {
|
|
23
|
+
// Check if the entire import is type-only: `import type { X } from '...'`
|
|
24
|
+
if (path.node.importKind === 'type') {
|
|
25
|
+
typeImports.push(path.node)
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
return typeImports
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Restore type-only imports that may have been removed by dead code elimination
|
|
33
|
+
function restoreTypeImports(ast: t.File, typeImports: t.ImportDeclaration[]) {
|
|
34
|
+
if (typeImports.length === 0) return
|
|
35
|
+
|
|
36
|
+
// Get existing import sources to avoid duplicates
|
|
37
|
+
const existingSources = new Set<string>()
|
|
38
|
+
traverse(ast, {
|
|
39
|
+
ImportDeclaration(path) {
|
|
40
|
+
if (path.node.importKind === 'type') {
|
|
41
|
+
existingSources.add(path.node.source.value)
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Add back any type imports that were removed
|
|
47
|
+
for (const typeImport of typeImports) {
|
|
48
|
+
if (!existingSources.has(typeImport.source.value)) {
|
|
49
|
+
ast.program.body.unshift(typeImport)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
14
53
|
|
|
15
54
|
export const clientTreeShakePlugin = (): Plugin => {
|
|
16
55
|
return {
|
|
@@ -108,8 +147,8 @@ export async function transformTreeShakeClient(code: string, id: string) {
|
|
|
108
147
|
declarator.id.name === 'generateStaticParams')
|
|
109
148
|
) {
|
|
110
149
|
const declaration = path.get('declaration.declarations.' + index)
|
|
111
|
-
if (!Array.isArray(declaration)) {
|
|
112
|
-
declaration.remove()
|
|
150
|
+
if (!Array.isArray(declaration) && declaration) {
|
|
151
|
+
;(declaration as any).remove()
|
|
113
152
|
removed[declarator.id.name] = true
|
|
114
153
|
}
|
|
115
154
|
}
|
|
@@ -131,8 +170,15 @@ export async function transformTreeShakeClient(code: string, id: string) {
|
|
|
131
170
|
|
|
132
171
|
if (removedFunctions.length) {
|
|
133
172
|
try {
|
|
173
|
+
// Collect type-only imports before dead code elimination
|
|
174
|
+
// These should be preserved since TypeScript erases them at compile time
|
|
175
|
+
const typeImports = collectTypeImports(ast)
|
|
176
|
+
|
|
134
177
|
deadCodeElimination(ast, referenced)
|
|
135
178
|
|
|
179
|
+
// Restore any type imports that were incorrectly removed
|
|
180
|
+
restoreTypeImports(ast, typeImports)
|
|
181
|
+
|
|
136
182
|
const out = generate(ast)
|
|
137
183
|
|
|
138
184
|
// add back in empty or filled loader and genparams
|
|
@@ -360,15 +360,18 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
|
|
|
360
360
|
const appDir = path.join(process.cwd(), getRouterRootFromOneOptions(options))
|
|
361
361
|
|
|
362
362
|
// on change ./app stuff lets reload this to pick up any route changes
|
|
363
|
-
const fileWatcherChangeListener = debounce(
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
363
|
+
const fileWatcherChangeListener = debounce(
|
|
364
|
+
async (type: string, changedPath: string) => {
|
|
365
|
+
if (type === 'add' || type === 'delete') {
|
|
366
|
+
// resolve to absolute path since watcher may emit relative paths
|
|
367
|
+
const absolutePath = path.resolve(changedPath)
|
|
368
|
+
if (absolutePath.startsWith(appDir)) {
|
|
369
|
+
handleRequest = createRequestHandler()
|
|
370
|
+
}
|
|
369
371
|
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
+
},
|
|
373
|
+
100
|
|
374
|
+
)
|
|
372
375
|
|
|
373
376
|
server.watcher.addListener('all', fileWatcherChangeListener)
|
|
374
377
|
|
|
@@ -25,6 +25,10 @@ export function generateFileSystemRouteTypesPlugin(options: One.PluginOptions):
|
|
|
25
25
|
if (type === 'add' || type === 'delete' || type === 'change') {
|
|
26
26
|
// resolve to absolute path since watcher may emit relative paths
|
|
27
27
|
const absolutePath = resolve(path)
|
|
28
|
+
// skip routes.d.ts itself to avoid infinite loop
|
|
29
|
+
if (absolutePath === outFile) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
28
32
|
if (absolutePath.startsWith(appDir)) {
|
|
29
33
|
// generate
|
|
30
34
|
generateRouteTypes(
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { parseSync } from 'oxc-parser'
|
|
3
|
+
import { normalizePath } from 'vite'
|
|
4
|
+
import type { Plugin, ViteDevServer } from 'vite'
|
|
5
|
+
|
|
6
|
+
interface JsxLocation {
|
|
7
|
+
/** Position right after the tag name where we insert the attribute */
|
|
8
|
+
insertOffset: number
|
|
9
|
+
/** Traversal index - stable ordering that's the same on server and client */
|
|
10
|
+
index: number
|
|
11
|
+
/** Actual line number for editor navigation */
|
|
12
|
+
line: number
|
|
13
|
+
/** Actual column number for editor navigation */
|
|
14
|
+
column: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Parse code with oxc and find all JSX opening elements.
|
|
19
|
+
* Returns insertion points sorted by offset (descending for safe insertion).
|
|
20
|
+
*/
|
|
21
|
+
function findJsxElements(code: string, filename: string): JsxLocation[] {
|
|
22
|
+
const result = parseSync(filename, code)
|
|
23
|
+
|
|
24
|
+
if (result.errors.length > 0) {
|
|
25
|
+
return []
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const locations: JsxLocation[] = []
|
|
29
|
+
let traversalIndex = 0
|
|
30
|
+
|
|
31
|
+
function getJsxName(node: any): string | null {
|
|
32
|
+
if (!node) return null
|
|
33
|
+
if (node.type === 'JSXIdentifier') return node.name
|
|
34
|
+
if (node.type === 'JSXMemberExpression') {
|
|
35
|
+
const obj = getJsxName(node.object)
|
|
36
|
+
return obj ? `${obj}.${node.property?.name}` : null
|
|
37
|
+
}
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getLocation(offset: number): { line: number; column: number } {
|
|
42
|
+
const before = code.slice(0, offset)
|
|
43
|
+
const lines = before.split('\n')
|
|
44
|
+
return {
|
|
45
|
+
line: lines.length,
|
|
46
|
+
column: lines[lines.length - 1]!.length + 1,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function walk(node: any): void {
|
|
51
|
+
if (!node || typeof node !== 'object') return
|
|
52
|
+
|
|
53
|
+
if (node.type === 'JSXOpeningElement' && node.name) {
|
|
54
|
+
const tagName = getJsxName(node.name)
|
|
55
|
+
|
|
56
|
+
// Skip Fragment and already-tagged elements
|
|
57
|
+
if (tagName && tagName !== 'Fragment') {
|
|
58
|
+
// Check if already has data-one-source
|
|
59
|
+
const hasSourceAttr = node.attributes?.some(
|
|
60
|
+
(attr: any) =>
|
|
61
|
+
attr.type === 'JSXAttribute' && attr.name?.name === 'data-one-source'
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
if (!hasSourceAttr) {
|
|
65
|
+
// Insert position is right after the tag name
|
|
66
|
+
const nameEnd = node.name.end
|
|
67
|
+
const loc = getLocation(node.start)
|
|
68
|
+
|
|
69
|
+
locations.push({
|
|
70
|
+
insertOffset: nameEnd,
|
|
71
|
+
index: traversalIndex++,
|
|
72
|
+
line: loc.line,
|
|
73
|
+
column: loc.column,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Walk all child nodes in consistent order
|
|
80
|
+
for (const key of Object.keys(node)) {
|
|
81
|
+
if (key === 'parent') continue
|
|
82
|
+
const value = node[key]
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
for (const child of value) {
|
|
85
|
+
walk(child)
|
|
86
|
+
}
|
|
87
|
+
} else if (value && typeof value === 'object') {
|
|
88
|
+
walk(value)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
walk(result.program)
|
|
94
|
+
|
|
95
|
+
// Sort by offset descending so we can insert from end to start without shifting positions
|
|
96
|
+
return locations.sort((a, b) => b.insertOffset - a.insertOffset)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Transforms JSX to inject data-one-source attributes using oxc-parser.
|
|
101
|
+
* Uses stable traversal indices instead of line numbers to avoid hydration mismatches.
|
|
102
|
+
*/
|
|
103
|
+
function injectSourceToJsx(
|
|
104
|
+
code: string,
|
|
105
|
+
id: string
|
|
106
|
+
): { code: string; map?: null } | undefined {
|
|
107
|
+
const [filePath] = id.split('?')
|
|
108
|
+
if (!filePath) return
|
|
109
|
+
|
|
110
|
+
const location = filePath.replace(normalizePath(process.cwd()), '')
|
|
111
|
+
|
|
112
|
+
// Quick check - skip if no JSX-like content
|
|
113
|
+
if (!code.includes('<') || !code.includes('>')) {
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const jsxLocations = findJsxElements(code, filePath)
|
|
118
|
+
|
|
119
|
+
if (jsxLocations.length === 0) {
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Build source info map for this file
|
|
124
|
+
// Sort by index (ascending) for the map, since jsxLocations is sorted by offset (descending)
|
|
125
|
+
const sourceInfoEntries = [...jsxLocations]
|
|
126
|
+
.sort((a, b) => a.index - b.index)
|
|
127
|
+
.map((jsx) => `${jsx.index}:[${jsx.line},${jsx.column}]`)
|
|
128
|
+
.join(',')
|
|
129
|
+
|
|
130
|
+
// Inject source info registration at the top of the file
|
|
131
|
+
const sourceInfoScript = `globalThis.__oneSourceInfo=globalThis.__oneSourceInfo||{};globalThis.__oneSourceInfo["${location}"]={${sourceInfoEntries}};`
|
|
132
|
+
|
|
133
|
+
let result = code
|
|
134
|
+
|
|
135
|
+
// Insert from end to start to preserve offsets
|
|
136
|
+
for (const jsx of jsxLocations) {
|
|
137
|
+
// Use stable index instead of line:column
|
|
138
|
+
const sourceAttr = ` data-one-source="${location}:${jsx.index}"`
|
|
139
|
+
result =
|
|
140
|
+
result.slice(0, jsx.insertOffset) + sourceAttr + result.slice(jsx.insertOffset)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Add source info at the very beginning of the file
|
|
144
|
+
result = sourceInfoScript + result
|
|
145
|
+
|
|
146
|
+
return { code: result, map: null }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function openInEditor(
|
|
150
|
+
filePath: string,
|
|
151
|
+
line?: string,
|
|
152
|
+
column?: string
|
|
153
|
+
): Promise<void> {
|
|
154
|
+
try {
|
|
155
|
+
const launch = (await import('launch-editor')).default
|
|
156
|
+
const fullPath = path.join(process.cwd(), filePath)
|
|
157
|
+
const location = `${fullPath}${line ? `:${line}` : ''}${column ? `:${column}` : ''}`
|
|
158
|
+
|
|
159
|
+
launch(location, undefined, (filename: string, errorMessage: string | null) => {
|
|
160
|
+
if (errorMessage) {
|
|
161
|
+
console.warn(
|
|
162
|
+
`[one:source-inspector] Failed to open ${filename} in editor:`,
|
|
163
|
+
errorMessage
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
} catch (err) {
|
|
168
|
+
console.warn('[one:source-inspector] Failed to launch editor:', err)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function sourceInspectorPlugin(): Plugin[] {
|
|
173
|
+
return [
|
|
174
|
+
// Transform plugin - injects data-one-source attributes
|
|
175
|
+
{
|
|
176
|
+
name: 'one:source-inspector-transform',
|
|
177
|
+
enforce: 'pre',
|
|
178
|
+
apply: 'serve',
|
|
179
|
+
|
|
180
|
+
transform(code, id) {
|
|
181
|
+
const envName = this.environment?.name
|
|
182
|
+
// Skip native environments only - transform both client and SSR for consistency
|
|
183
|
+
if (envName === 'ios' || envName === 'android') return
|
|
184
|
+
|
|
185
|
+
if (
|
|
186
|
+
id.includes('node_modules') ||
|
|
187
|
+
id.includes('?raw') ||
|
|
188
|
+
id.includes('dist') ||
|
|
189
|
+
id.includes('build')
|
|
190
|
+
) {
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!id.endsWith('.jsx') && !id.endsWith('.tsx')) return
|
|
195
|
+
|
|
196
|
+
return injectSourceToJsx(code, id)
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
// Note: Inspector UI script is now injected via DevHead.tsx for SSR compatibility
|
|
201
|
+
|
|
202
|
+
// Server plugin - handles open-source requests
|
|
203
|
+
{
|
|
204
|
+
name: 'one:source-inspector-server',
|
|
205
|
+
apply: 'serve',
|
|
206
|
+
|
|
207
|
+
configureServer(server: ViteDevServer) {
|
|
208
|
+
server.middlewares.use(async (req, res, next) => {
|
|
209
|
+
if (!req.url?.startsWith('/__one/open-source')) {
|
|
210
|
+
return next()
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
const url = new URL(req.url, 'http://localhost')
|
|
215
|
+
const source = url.searchParams.get('source')
|
|
216
|
+
|
|
217
|
+
if (!source) {
|
|
218
|
+
res.statusCode = 400
|
|
219
|
+
res.end('Missing source parameter')
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Parse the source - now format is "filePath:index"
|
|
224
|
+
const lastColon = source.lastIndexOf(':')
|
|
225
|
+
const filePath = source.slice(0, lastColon)
|
|
226
|
+
const index = source.slice(lastColon + 1)
|
|
227
|
+
|
|
228
|
+
// Look up actual line/column from source info
|
|
229
|
+
// The client will send these if available
|
|
230
|
+
const line = url.searchParams.get('line')
|
|
231
|
+
const column = url.searchParams.get('column')
|
|
232
|
+
|
|
233
|
+
await openInEditor(filePath, line || undefined, column || undefined)
|
|
234
|
+
|
|
235
|
+
res.statusCode = 200
|
|
236
|
+
res.end('OK')
|
|
237
|
+
} catch (err) {
|
|
238
|
+
console.error('[one:source-inspector] Error:', err)
|
|
239
|
+
res.statusCode = 500
|
|
240
|
+
res.end('Internal server error')
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
]
|
|
246
|
+
}
|