@teyik0/furin 0.7.0-alpha.2 → 0.8.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 +1 -1
- package/dist/adapter/build.d.ts +9 -0
- package/dist/adapter/bun/server.d.ts +1 -0
- package/dist/adapter/bun.d.ts +7 -3
- package/dist/adapter/package.d.ts +1 -0
- package/dist/adapter/prerender.d.ts +21 -0
- package/dist/adapter/runtime-build.d.ts +24 -10
- package/dist/adapter/server-bundle.d.ts +20 -0
- package/dist/adapter/static.d.ts +2 -2
- package/dist/adapter/types.d.ts +81 -0
- package/dist/adapter/vercel/bootstrap.d.ts +5 -0
- package/dist/adapter/vercel/data.d.ts +23 -0
- package/dist/adapter/vercel/handler.d.ts +10 -0
- package/dist/adapter/vercel.d.ts +13 -3
- package/dist/adapter/vercel.js +516 -0
- package/dist/build/bun-build.d.ts +4 -0
- package/dist/build/compile-entry.ts +1 -0
- package/dist/build/discover-mounts-process.d.ts +1 -0
- package/dist/build/discover-mounts.d.ts +6 -0
- package/dist/build/elysia-aot-worker.d.ts +4 -0
- package/dist/build/elysia-aot.d.ts +7 -1
- package/dist/build/entry-template.d.ts +14 -7
- package/dist/build/entry-template.ts +33 -18
- package/dist/build/hydrate.d.ts +15 -2
- package/dist/build/index.d.ts +7 -3
- package/dist/build/index.js +8845 -15398
- package/dist/build/private-server-sourcemaps.d.ts +2 -0
- package/dist/build/route-types.d.ts +8 -2
- package/dist/build/server-app-entry.d.ts +2 -2
- package/dist/build/shared.d.ts +3 -5
- package/dist/build/types.d.ts +16 -16
- package/dist/cache.js +117 -32
- package/dist/cli/config.d.ts +2 -2
- package/dist/cli/index.js +8956 -15272
- package/dist/client/chunks/client-brdfd773.js +852 -0
- package/dist/client/chunks/client-k29262a4.js +59 -0
- package/dist/client/chunks/client-k88668k7.js +159 -0
- package/dist/client/chunks/client-xy6g38kx.js +317 -0
- package/dist/client/default-screens.d.ts +0 -11
- package/dist/client/define-route.d.ts +2 -1
- package/dist/client/hmr.d.ts +1 -1
- package/dist/client/internal/runtime-types.d.ts +7 -1
- package/dist/client/link.d.ts +1 -0
- package/dist/client/link.js +1790 -4190
- package/dist/client/mutation.d.ts +5 -0
- package/dist/client/query-store.d.ts +17 -7
- package/dist/client/query.d.ts +6 -8
- package/dist/client/request-id.d.ts +1 -0
- package/dist/client/route-api.d.ts +4 -4
- package/dist/client/route-element.d.ts +51 -0
- package/dist/client/router/boundary-tree.d.ts +1 -9
- package/dist/client/router/cache-generation.d.ts +15 -0
- package/dist/client/router/context.d.ts +13 -2
- package/dist/client/router/fetch-observers.d.ts +9 -0
- package/dist/client/router/hmr-refresh.d.ts +12 -0
- package/dist/client/router/index.d.ts +5 -7
- package/dist/client/router/link-utils.d.ts +0 -2
- package/dist/client/router/navigation-controller.d.ts +76 -0
- package/dist/client/router/navigation.d.ts +1 -0
- package/dist/client/router/page-fetch.d.ts +38 -0
- package/dist/client/router/provider.d.ts +2 -3
- package/dist/client/router/search/index.d.ts +11 -4
- package/dist/client/router/search/index.js +60 -0
- package/dist/client/router/spa-response.d.ts +9 -26
- package/dist/client/router/sync-catch-up.d.ts +3 -2
- package/dist/client/router/transport.d.ts +4 -0
- package/dist/client/router/types.d.ts +120 -46
- package/dist/client/router/use-fetch-interception.d.ts +12 -0
- package/dist/client/router/use-history-sync.d.ts +7 -0
- package/dist/client/router/use-hmr-refresh.d.ts +8 -0
- package/dist/client/router/use-sync-stream.d.ts +16 -0
- package/dist/client/server-error.d.ts +4 -7
- package/dist/client/sync.d.ts +43 -30
- package/dist/client.d.ts +2 -1
- package/dist/client.js +279 -829
- package/dist/config.d.ts +11 -12
- package/dist/config.js +0 -30
- package/dist/define-route.d.ts +262 -517
- package/dist/devtools/protocol.d.ts +4 -3
- package/dist/furin.d.ts +41 -31
- package/dist/furin.js +20561 -18971
- package/dist/plugin/binding-scope.d.ts +15 -2
- package/dist/plugin/client-plugin.d.ts +19 -0
- package/dist/plugin/dead-code-elimination.d.ts +14 -3
- package/dist/plugin/dev-routes.d.ts +22 -0
- package/dist/plugin/hmr-data-signature.d.ts +3 -0
- package/dist/plugin/hmr-hook-signature.d.ts +9 -0
- package/dist/plugin/index.d.ts +1 -6
- package/dist/plugin/index.js +1753 -1214
- package/dist/plugin/module-bindings.d.ts +11 -0
- package/dist/plugin/module-transform.d.ts +29 -0
- package/dist/plugin/preflight.d.ts +8 -0
- package/dist/plugin/route-chains.d.ts +35 -0
- package/dist/plugin/route-config.d.ts +28 -0
- package/dist/plugin/route-modules.d.ts +35 -0
- package/dist/plugin/route-registry.d.ts +12 -0
- package/dist/plugin/route-tree.d.ts +43 -0
- package/dist/plugin/strip-server-stages.d.ts +10 -0
- package/dist/plugin/strip-server.d.ts +10 -0
- package/dist/plugin/transform-client-module.d.ts +3 -0
- package/dist/plugin/transform-client.d.ts +0 -2
- package/dist/plugin/transform-isomorphic.d.ts +3 -2
- package/dist/routes.d.ts +15 -5
- package/dist/rsc/build/client-references.d.ts +8 -0
- package/dist/rsc/build/discover.d.ts +7 -0
- package/dist/rsc/build/flight-loader.d.ts +1 -0
- package/dist/rsc/build/index.d.ts +4 -1
- package/dist/rsc/build/paths.d.ts +2 -0
- package/dist/rsc/bundled-client-codec.d.ts +1 -0
- package/dist/rsc/client-codec.d.ts +3 -0
- package/dist/rsc/client-references.d.ts +22 -0
- package/dist/rsc/server-client-codec.d.ts +1 -0
- package/dist/rsc/server-codec.js +3889 -2
- package/dist/rsc/slot-proxy.d.ts +11 -0
- package/dist/rsc/transport-benchmark.d.ts +2 -1
- package/dist/rsc-client.js +16 -164
- package/dist/rsc-server.d.ts +1 -5
- package/dist/rsc.d.ts +1 -5
- package/dist/rsc.js +233 -73
- package/dist/server/assets/client-dir.d.ts +1 -0
- package/dist/server/auto-invalidate/index.d.ts +2 -2
- package/dist/server/auto-invalidate/plugin.d.ts +21 -15
- package/dist/server/auto-invalidate/types.d.ts +0 -2
- package/dist/server/bounded-body.d.ts +6 -0
- package/dist/server/browser-events/plugin.d.ts +4 -1
- package/dist/server/browser-events/shutdown.d.ts +1 -1
- package/dist/server/cache/dev-loader.d.ts +6 -1
- package/dist/server/cache/index.d.ts +4 -9
- package/dist/server/cache/invalidation.d.ts +7 -2
- package/dist/server/cache/isr-ssg.d.ts +6 -1
- package/dist/server/cache/page-cache.d.ts +5 -0
- package/dist/server/cache/purger.d.ts +14 -4
- package/dist/server/cache/redis/index.d.ts +1 -34
- package/dist/server/cache/redis/index.js +51 -25
- package/dist/server/cache/redis/scripts.d.ts +1 -1
- package/dist/server/cache/route-cache.d.ts +18 -2
- package/dist/server/cache/runtime-cache.d.ts +7 -0
- package/dist/server/context-logger.d.ts +6 -1
- package/dist/server/dev/graph.d.ts +4 -3
- package/dist/server/dev/runtime.d.ts +4 -0
- package/dist/server/dev/runtime.production.d.ts +1 -0
- package/dist/server/dev/stack-location.d.ts +9 -0
- package/dist/server/dev-page-imports.d.ts +42 -0
- package/dist/server/dev-page-plugin.d.ts +2 -49
- package/dist/server/devtools/instrumentation.d.ts +1 -3
- package/dist/server/devtools/instrumentation.production.d.ts +0 -2
- package/dist/server/devtools/request-context.d.ts +7 -0
- package/dist/server/evlog.d.ts +18 -6
- package/dist/server/instance.d.ts +52 -44
- package/dist/server/internal.d.ts +51 -14
- package/dist/server/internal.js +9749 -2095
- package/dist/server/lang-detect.d.ts +4 -4
- package/dist/server/logger.d.ts +6 -0
- package/dist/server/logging/ingest-plugin.d.ts +32 -0
- package/dist/server/mode.d.ts +17 -0
- package/dist/server/prerender.d.ts +32 -0
- package/dist/server/prod/runtime.d.ts +5 -0
- package/dist/server/production-server.js +992 -726
- package/dist/server/registrations.d.ts +14 -0
- package/dist/server/render/assemble.d.ts +0 -22
- package/dist/server/render/buffered-render.d.ts +20 -0
- package/dist/server/render/document-stream.d.ts +45 -0
- package/dist/server/render/document.d.ts +1 -1
- package/dist/server/render/element.d.ts +2 -5
- package/dist/server/render/index.d.ts +4 -5
- package/dist/server/render/index.ts +4 -21
- package/dist/server/render/isr-revalidation.d.ts +5 -0
- package/dist/server/render/isr-shared-cache.d.ts +23 -0
- package/dist/server/render/isr.d.ts +19 -1
- package/dist/server/render/loader-errors.d.ts +33 -0
- package/dist/server/render/loader-segments.d.ts +40 -0
- package/dist/server/render/loaders.d.ts +16 -32
- package/dist/server/render/mixed-cache.d.ts +2 -2
- package/dist/server/render/navigation-head.d.ts +13 -0
- package/dist/server/render/not-found-plugin.d.ts +18 -0
- package/dist/server/render/observe-loader.d.ts +1 -0
- package/dist/server/render/ppr-document.d.ts +1 -1
- package/dist/server/render/ppr-request.d.ts +0 -2
- package/dist/server/render/ppr-route.d.ts +13 -2
- package/dist/server/render/prepare-render.d.ts +57 -0
- package/dist/server/render/request-loaders.d.ts +19 -0
- package/dist/server/render/route-frame-transport.d.ts +7 -1
- package/dist/server/render/shell.d.ts +1 -1
- package/dist/server/render/shell.ts +1 -1
- package/dist/server/render/ssr-transport.d.ts +11 -0
- package/dist/server/render/ssr.d.ts +1 -116
- package/dist/server/render/static-params.d.ts +15 -0
- package/dist/server/router/discovery.d.ts +1 -0
- package/dist/server/router/dispatch.d.ts +96 -0
- package/dist/server/router/hmr.d.ts +14 -24
- package/dist/server/router/patterns.d.ts +15 -20
- package/dist/server/router/plugin.d.ts +26 -24
- package/dist/server/router/schemas.d.ts +6 -24
- package/dist/server/router/types.d.ts +0 -2
- package/dist/server/runtime-env.d.ts +6 -1
- package/dist/server/static-export.d.ts +38 -0
- package/dist/server/static-export.js +10667 -0
- package/dist/server/sync/adapter.d.ts +11 -0
- package/dist/server/sync/atomic.d.ts +0 -2
- package/dist/server/sync/config.d.ts +0 -1
- package/dist/server/sync/drizzle/index.js +112 -68
- package/dist/server/sync/fingerprint.d.ts +0 -1
- package/dist/server/sync/index.d.ts +2 -6
- package/dist/server/sync/index.js +1690 -1365
- package/dist/server/sync/invalidate-sync.d.ts +10 -0
- package/dist/server/sync/plugin.d.ts +18 -55
- package/dist/server/sync/postgres/execute.d.ts +2 -2
- package/dist/server/sync/postgres/index.d.ts +3 -1
- package/dist/server/sync/postgres/index.js +68 -37
- package/dist/server/sync/postgres/migration.sql +2 -0
- package/dist/server/sync/principal-journal.d.ts +11 -0
- package/dist/server/sync/prisma/index.js +74 -39
- package/dist/server/sync/queries.d.ts +57 -16
- package/dist/server/sync/redis/index.d.ts +2 -1
- package/dist/server/sync/redis/index.js +49 -5
- package/dist/server/sync/redis/scripts.d.ts +2 -1
- package/dist/server/sync/response.d.ts +3 -0
- package/dist/server/sync/runtime.d.ts +5 -1
- package/dist/server/sync/sqlite/index.d.ts +3 -1
- package/dist/server/sync/sqlite/index.js +58 -27
- package/dist/server/sync/stream.d.ts +32 -7
- package/dist/server/weak-registry.d.ts +9 -0
- package/dist/shared/await.d.ts +2 -1
- package/dist/shared/compact-json.d.ts +1 -0
- package/dist/shared/defer.d.ts +1 -1
- package/dist/shared/deferred-ndjson.d.ts +3 -2
- package/dist/shared/elysia-contract.d.ts +2 -0
- package/dist/shared/in-memory-apps.d.ts +7 -0
- package/dist/shared/invalidation-header.d.ts +13 -0
- package/dist/shared/navigation-data.d.ts +7 -0
- package/dist/shared/prefix.d.ts +11 -5
- package/dist/shared/route-frame.d.ts +3 -0
- package/dist/shared/route-map.d.ts +7 -0
- package/dist/shared/route-matches.d.ts +41 -0
- package/dist/shared/route-specificity.d.ts +2 -0
- package/dist/shared/search-params.d.ts +2 -3
- package/dist/shared/sync-query.d.ts +6 -13
- package/dist/shared/utils/ast-walk.d.ts +3 -11
- package/package.json +32 -21
- package/src/adapter/README.md +37 -16
- package/src/adapter/build.ts +269 -0
- package/src/adapter/bun/server.ts +14 -0
- package/src/adapter/bun.ts +89 -265
- package/src/adapter/furin-app.d.ts +14 -0
- package/src/adapter/package.ts +31 -27
- package/src/adapter/prerender.ts +97 -0
- package/src/adapter/runtime-build.ts +83 -93
- package/src/adapter/server-bundle.ts +110 -0
- package/src/adapter/static.ts +259 -247
- package/src/adapter/types.ts +89 -0
- package/src/adapter/vercel/bootstrap.ts +85 -0
- package/src/adapter/vercel/data.ts +21 -0
- package/src/adapter/vercel/handler.ts +132 -0
- package/src/adapter/vercel.ts +333 -667
- package/src/build/bun-build.ts +3 -0
- package/src/build/client.ts +22 -60
- package/src/build/compile-entry.ts +1 -0
- package/src/build/discover-mounts-process.ts +13 -0
- package/src/build/discover-mounts.ts +40 -0
- package/src/build/elysia-aot-worker.ts +84 -2
- package/src/build/elysia-aot.ts +61 -2
- package/src/build/entry-template.ts +33 -18
- package/src/build/hydrate.ts +122 -44
- package/src/build/index.ts +156 -108
- package/src/build/private-server-sourcemaps.ts +5 -0
- package/src/build/production-instrumentation.ts +22 -19
- package/src/build/route-types.ts +93 -11
- package/src/build/server-app-entry.ts +4 -21
- package/src/build/shared.ts +9 -41
- package/src/build/types.ts +14 -20
- package/src/build/virtual-entry.ts +2 -4
- package/src/cli/config.ts +133 -6
- package/src/cli/index.ts +59 -21
- package/src/cli/preview.ts +2 -1
- package/src/client/boundaries.tsx +5 -14
- package/src/client/default-screens.tsx +2 -2
- package/src/client/define-route.ts +3 -2
- package/src/client/hmr.ts +1 -1
- package/src/client/internal/runtime-types.ts +7 -1
- package/src/client/link.tsx +80 -43
- package/src/client/mutation.ts +98 -3
- package/src/client/query-store.ts +160 -29
- package/src/client/query.tsx +12 -29
- package/src/client/request-id.ts +10 -0
- package/src/client/route-api.tsx +6 -6
- package/src/client/route-element.tsx +155 -0
- package/src/client/router/boundary-tree.tsx +2 -93
- package/src/client/router/cache-generation.ts +37 -0
- package/src/client/router/context.ts +40 -4
- package/src/client/router/fetch-observers.ts +46 -0
- package/src/client/router/hmr-refresh.ts +50 -0
- package/src/client/router/index.ts +7 -29
- package/src/client/router/link-utils.ts +19 -31
- package/src/client/router/navigation-controller.ts +547 -0
- package/src/client/router/navigation.ts +3 -2
- package/src/client/router/optimistic.ts +2 -3
- package/src/client/router/page-fetch.ts +272 -0
- package/src/client/router/provider.tsx +223 -1079
- package/src/client/router/search/index.ts +38 -14
- package/src/client/router/spa-response.ts +19 -70
- package/src/client/router/sync-catch-up.ts +65 -7
- package/src/client/router/transport.ts +23 -0
- package/src/client/router/types.ts +203 -61
- package/src/client/router/use-fetch-interception.ts +52 -0
- package/src/client/router/use-history-sync.ts +56 -0
- package/src/client/router/use-hmr-refresh.ts +51 -0
- package/src/client/router/use-sync-stream.ts +129 -0
- package/src/client/server-error.ts +2 -40
- package/src/client/sync.ts +268 -378
- package/src/client.ts +2 -7
- package/src/config.ts +23 -45
- package/src/define-route.ts +487 -882
- package/src/devtools/devtools-element.js +10 -3
- package/src/devtools/protocol.ts +3 -3
- package/src/furin.ts +253 -1086
- package/src/plugin/binding-scope.ts +219 -94
- package/src/plugin/client-plugin.ts +145 -0
- package/src/plugin/dead-code-elimination.ts +390 -111
- package/src/plugin/dev-routes.ts +453 -0
- package/src/plugin/hmr-data-signature.ts +161 -0
- package/src/plugin/hmr-dependencies.ts +2 -4
- package/src/plugin/hmr-hook-signature.ts +252 -0
- package/src/plugin/index.ts +3 -96
- package/src/plugin/module-bindings.ts +216 -0
- package/src/plugin/module-transform.ts +63 -0
- package/src/plugin/preflight.ts +66 -0
- package/src/plugin/route-chains.ts +309 -0
- package/src/plugin/route-config.ts +451 -0
- package/src/plugin/route-modules.ts +209 -0
- package/src/plugin/route-registry.ts +316 -0
- package/src/plugin/route-tree.ts +248 -0
- package/src/plugin/strip-server-stages.ts +197 -0
- package/src/plugin/strip-server.ts +22 -0
- package/src/plugin/transform-client-module.ts +36 -31
- package/src/plugin/transform-client.ts +33 -1114
- package/src/plugin/transform-dev-page.ts +84 -92
- package/src/plugin/transform-isomorphic.ts +396 -185
- package/src/routes.ts +15 -5
- package/src/rsc/build/client-references.ts +267 -0
- package/src/rsc/build/discover.ts +226 -0
- package/src/rsc/build/flight-loader.ts +69 -0
- package/src/rsc/build/index.ts +53 -31
- package/src/rsc/build/paths.ts +7 -0
- package/src/rsc/bundled-client-codec.ts +4 -0
- package/src/rsc/client-codec.ts +12 -3
- package/src/rsc/client-references.ts +138 -0
- package/src/rsc/codec.ts +30 -21
- package/src/rsc/flight-drain.ts +6 -29
- package/src/rsc/react-server-dom-webpack.d.ts +1 -1
- package/src/rsc/server-client-codec.ts +14 -0
- package/src/rsc/server-codec.ts +5 -8
- package/src/rsc/slot-proxy.ts +34 -0
- package/src/rsc/transport-benchmark.ts +1 -1
- package/src/rsc-server.tsx +5 -23
- package/src/rsc.tsx +5 -29
- package/src/server/assets/client-dir.ts +110 -0
- package/src/server/assets/production.ts +1 -1
- package/src/server/auto-invalidate/index.ts +2 -7
- package/src/server/auto-invalidate/plugin.ts +43 -15
- package/src/server/auto-invalidate/registry.ts +6 -6
- package/src/server/auto-invalidate/runtime.ts +16 -98
- package/src/server/auto-invalidate/types.ts +0 -6
- package/src/server/bounded-body.ts +38 -0
- package/src/server/browser-events/plugin.ts +109 -22
- package/src/server/browser-events/shutdown.ts +28 -9
- package/src/server/cache/dev-loader.ts +30 -16
- package/src/server/cache/index.ts +2 -15
- package/src/server/cache/invalidation.ts +27 -46
- package/src/server/cache/isr-ssg.ts +6 -1
- package/src/server/cache/isr.ts +11 -11
- package/src/server/cache/page-cache-state.ts +2 -2
- package/src/server/cache/page-cache.ts +13 -9
- package/src/server/cache/purger.ts +64 -8
- package/src/server/cache/redis/index.ts +17 -27
- package/src/server/cache/redis/scripts.ts +21 -4
- package/src/server/cache/registry.ts +3 -3
- package/src/server/cache/route-cache.ts +47 -13
- package/src/server/cache/runtime-cache.ts +144 -24
- package/src/server/cache/ssg.ts +7 -5
- package/src/server/context-logger.ts +46 -8
- package/src/server/dev/diagnostics.ts +6 -56
- package/src/server/dev/error.ts +3 -34
- package/src/server/dev/graph.ts +35 -22
- package/src/server/dev/rewrite-module-specifiers.ts +15 -19
- package/src/server/dev/runtime.production.ts +4 -0
- package/src/server/dev/runtime.ts +404 -0
- package/src/server/dev/stack-location.ts +46 -0
- package/src/server/dev-page-imports.ts +183 -0
- package/src/server/dev-page-plugin.ts +39 -302
- package/src/server/devtools/hub.ts +3 -3
- package/src/server/devtools/instrumentation.production.ts +0 -8
- package/src/server/devtools/instrumentation.ts +6 -8
- package/src/server/devtools/plugin.ts +2 -1
- package/src/server/devtools/request-context.ts +67 -16
- package/src/server/evlog.ts +119 -55
- package/src/server/instance.ts +187 -138
- package/src/server/internal.ts +66 -62
- package/src/server/lang-detect.ts +31 -22
- package/src/server/logger.ts +20 -7
- package/src/server/logging/ingest-plugin.ts +123 -0
- package/src/server/mode.ts +19 -0
- package/src/server/prerender.ts +122 -0
- package/src/server/prod/runtime.ts +181 -0
- package/src/server/production-server.ts +43 -17
- package/src/server/registrations.ts +38 -0
- package/src/server/render/assemble.ts +5 -8
- package/src/server/render/buffered-render.ts +171 -0
- package/src/server/render/document-stream.ts +188 -0
- package/src/server/render/document.tsx +5 -3
- package/src/server/render/element.tsx +6 -73
- package/src/server/render/index.ts +4 -21
- package/src/server/render/isr-revalidation.ts +246 -0
- package/src/server/render/isr-shared-cache.ts +141 -0
- package/src/server/render/isr.ts +212 -516
- package/src/server/render/loader-errors.ts +183 -0
- package/src/server/render/loader-segments.ts +149 -0
- package/src/server/render/loaders.ts +126 -547
- package/src/server/render/mixed-cache.ts +28 -27
- package/src/server/render/navigation-head.ts +33 -0
- package/src/server/render/not-found-plugin.ts +31 -0
- package/src/server/render/not-found.ts +32 -8
- package/src/server/render/observe-loader.ts +46 -0
- package/src/server/render/ppr-document.ts +36 -14
- package/src/server/render/ppr-request.ts +2 -2
- package/src/server/render/ppr-route.ts +79 -18
- package/src/server/render/prepare-render.ts +251 -0
- package/src/server/render/request-loaders.ts +216 -0
- package/src/server/render/route-frame-transport.ts +41 -4
- package/src/server/render/shell.ts +1 -1
- package/src/server/render/ssg.ts +9 -20
- package/src/server/render/ssr-transport.ts +221 -0
- package/src/server/render/ssr.ts +95 -956
- package/src/server/render/static-params.ts +32 -0
- package/src/server/render/template.ts +7 -7
- package/src/server/router/discovery.ts +82 -159
- package/src/server/router/dispatch.ts +337 -0
- package/src/server/router/hmr.ts +177 -190
- package/src/server/router/patterns.ts +39 -65
- package/src/server/router/plugin.ts +234 -359
- package/src/server/router/schemas.ts +6 -39
- package/src/server/router/source-version.ts +5 -4
- package/src/server/router/types.ts +0 -2
- package/src/server/runtime-env.ts +6 -1
- package/src/server/static-export.ts +143 -0
- package/src/server/sync/adapter.ts +11 -0
- package/src/server/sync/atomic.ts +16 -36
- package/src/server/sync/config.ts +6 -14
- package/src/server/sync/drizzle/index.ts +12 -20
- package/src/server/sync/fingerprint.ts +1 -1
- package/src/server/sync/index.ts +2 -10
- package/src/server/sync/invalidate-sync.ts +31 -0
- package/src/server/sync/mutation-handler.ts +12 -1
- package/src/server/sync/plugin.ts +171 -129
- package/src/server/sync/postgres/execute.ts +9 -1
- package/src/server/sync/postgres/index.ts +71 -39
- package/src/server/sync/postgres/migration.sql +2 -0
- package/src/server/sync/principal-journal.ts +78 -0
- package/src/server/sync/prisma/index.ts +1 -0
- package/src/server/sync/queries.ts +133 -40
- package/src/server/sync/query-context.ts +38 -5
- package/src/server/sync/redis/index.ts +34 -6
- package/src/server/sync/redis/scripts.ts +10 -1
- package/src/server/sync/response.ts +47 -67
- package/src/server/sync/runtime.ts +24 -7
- package/src/server/sync/sqlite/index.ts +92 -61
- package/src/server/sync/sqlite/migration.sql +1 -0
- package/src/server/sync/stream.ts +47 -26
- package/src/server/sync/validation.ts +1 -1
- package/src/server/weak-registry.ts +37 -0
- package/src/shared/await.tsx +2 -1
- package/src/shared/compact-json.ts +1 -1
- package/src/shared/defer.ts +1 -1
- package/src/shared/deferred-ndjson.ts +142 -120
- package/src/shared/elysia-contract.ts +7 -0
- package/src/shared/error.ts +1 -4
- package/src/shared/in-memory-apps.ts +24 -0
- package/src/shared/invalidation-header.ts +38 -0
- package/src/shared/navigation-data.ts +29 -0
- package/src/shared/prefix.ts +42 -6
- package/src/shared/route-frame.ts +82 -26
- package/src/shared/route-map.ts +23 -39
- package/src/shared/route-matches.ts +59 -0
- package/src/shared/route-specificity.ts +28 -0
- package/src/shared/search-params.ts +6 -35
- package/src/shared/sync-query.ts +30 -23
- package/src/shared/utils/ast-walk.ts +9 -25
- package/src/shared/utils/index.ts +1 -1
- package/dist/build/scan-server.d.ts +0 -14
- package/dist/build/ssg-cache.d.ts +0 -17
- package/dist/plugin/route-config-autofix.d.ts +0 -31
- package/dist/plugin/routes.d.ts +0 -34
- package/dist/server/router/hmr.production.d.ts +0 -7
- package/src/build/scan-server.ts +0 -112
- package/src/build/ssg-cache.ts +0 -124
- package/src/plugin/route-config-autofix.ts +0 -1149
- package/src/plugin/routes.ts +0 -1140
- package/src/server/router/hmr.production.ts +0 -18
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import rewriting for development modules served from a virtual namespace:
|
|
3
|
+
* pins React packages and the JSX runtime to one on-disk instance and resolves
|
|
4
|
+
* relative and bare specifiers from the source file. Each edit stays on its
|
|
5
|
+
* line, so Bun's own transpiler reports source line numbers in stack traces.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
9
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
10
|
+
import MagicString from "magic-string";
|
|
11
|
+
import { parseSource } from "../shared/parser.ts";
|
|
12
|
+
import { walkAST } from "../shared/utils/ast-walk.ts";
|
|
13
|
+
import { rewriteModuleSpecifiers } from "./dev/rewrite-module-specifiers.ts";
|
|
14
|
+
import { routeModuleSourceVersion } from "./router/source-version.ts";
|
|
15
|
+
|
|
16
|
+
export const WORKSPACE_SOURCE_FILTER =
|
|
17
|
+
/^(?!.*(?:[\\/]node_modules[\\/]|[\\/]\.bun[\\/]))(?!.*\.(?:test|spec)\.(?:[cm]?[jt]s|[jt]sx)$).*\.(?:m?[jt]s|[jt]sx)$/;
|
|
18
|
+
|
|
19
|
+
export type SourceLoader = "js" | "jsx" | "ts" | "tsx";
|
|
20
|
+
|
|
21
|
+
// ── Singleton package resolution ───────────────────────────────────────────────
|
|
22
|
+
//
|
|
23
|
+
// React (and react-dom) must be singletons: every module in the render graph
|
|
24
|
+
// must import the EXACT same object instance so that ReactSharedInternals.H
|
|
25
|
+
// (the hooks dispatcher) is shared between react-dom/server and the page.
|
|
26
|
+
//
|
|
27
|
+
// We resolve the absolute on-disk path once at module-evaluation time and
|
|
28
|
+
// rewrite every explicit import in the source to use that path. The JSX
|
|
29
|
+
// runtime import that Bun's transpiler adds is pinned by pinJsxRuntime below.
|
|
30
|
+
|
|
31
|
+
/** React packages that must share a single instance across the module graph. */
|
|
32
|
+
const SINGLETON_PKGS = [
|
|
33
|
+
"react",
|
|
34
|
+
"react/jsx-runtime",
|
|
35
|
+
"react/jsx-dev-runtime",
|
|
36
|
+
"react-dom",
|
|
37
|
+
"react-dom/server",
|
|
38
|
+
"react-dom/client",
|
|
39
|
+
] as const;
|
|
40
|
+
|
|
41
|
+
/** package specifier → absolute file path, resolved once at plugin registration time. */
|
|
42
|
+
const SINGLETON_PATHS = new Map<string, string>();
|
|
43
|
+
for (const pkg of SINGLETON_PKGS) {
|
|
44
|
+
try {
|
|
45
|
+
SINGLETON_PATHS.set(pkg, toImportSpecifier(fileURLToPath(import.meta.resolve(pkg))));
|
|
46
|
+
} catch {
|
|
47
|
+
// Package not installed — skip (e.g. react-dom/client in a server-only env)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Converts a native absolute path to Bun's cross-platform import format. */
|
|
52
|
+
export function toImportSpecifier(filePath: string): string {
|
|
53
|
+
return filePath.replaceAll("\\", "/");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Rewrites bare React/react-dom singleton imports in source text to their
|
|
58
|
+
* absolute resolved paths. Handles explicit static import / re-export forms:
|
|
59
|
+
*
|
|
60
|
+
* import { useState } from "react" → import { useState } from "/abs/…"
|
|
61
|
+
* import type { FC } from "react"
|
|
62
|
+
* export { x } from "react"
|
|
63
|
+
* import "react/jsx-dev-runtime"
|
|
64
|
+
*
|
|
65
|
+
* Does NOT touch dynamic `import("react")` or `require("react")`.
|
|
66
|
+
*
|
|
67
|
+
* @internal exported for testing
|
|
68
|
+
*/
|
|
69
|
+
export function rewriteSingletonImports(source: string, loader: SourceLoader): string {
|
|
70
|
+
const result = new MagicString(source);
|
|
71
|
+
for (const statement of parseSource(source, loader).program.body) {
|
|
72
|
+
if (
|
|
73
|
+
statement.type !== "ImportDeclaration" &&
|
|
74
|
+
statement.type !== "ExportNamedDeclaration" &&
|
|
75
|
+
statement.type !== "ExportAllDeclaration"
|
|
76
|
+
) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const specifier = statement.source;
|
|
80
|
+
if (!specifier) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const path = SINGLETON_PATHS.get(specifier.value);
|
|
84
|
+
if (path) {
|
|
85
|
+
result.overwrite(specifier.start, specifier.end, JSON.stringify(path));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return result.toString();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Bun's transpiler imports the JSX runtime by its bare specifier, which a
|
|
93
|
+
* virtual-namespace module resolves from the process CWD rather than from the
|
|
94
|
+
* page. A leading `@jsxImportSource` pragma pins it to the React instance of
|
|
95
|
+
* `react-dom/server`. The pragma is a file URL because it ends at whitespace,
|
|
96
|
+
* and it shares the first line so every source line keeps its number.
|
|
97
|
+
*/
|
|
98
|
+
export function pinJsxRuntime(source: string, loader: SourceLoader): string {
|
|
99
|
+
const runtime = SINGLETON_PATHS.get("react/jsx-dev-runtime");
|
|
100
|
+
if (!runtime || loader === "ts") {
|
|
101
|
+
return source;
|
|
102
|
+
}
|
|
103
|
+
const pragma = `/** @jsxImportSource ${pathToFileURL(dirname(runtime)).href} */ `;
|
|
104
|
+
// A shebang must stay first: pin on line 2 so no source line moves.
|
|
105
|
+
const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
106
|
+
return shebangEnd > 0
|
|
107
|
+
? `${source.slice(0, shebangEnd)}${pragma}${source.slice(shebangEnd)}`
|
|
108
|
+
: `${pragma}${source}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @internal exported for testing */
|
|
112
|
+
export function rewriteRelativeImports(source: string, dir: string): string {
|
|
113
|
+
return rewriteModuleSpecifiers({
|
|
114
|
+
code: source,
|
|
115
|
+
filePath: resolve(dir, "__furin_entry.tsx"),
|
|
116
|
+
versioned: false,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function rewriteRelativeImportsWithVersion(
|
|
121
|
+
source: string,
|
|
122
|
+
filePath: string,
|
|
123
|
+
versioned: boolean
|
|
124
|
+
): string {
|
|
125
|
+
return rewriteModuleSpecifiers({
|
|
126
|
+
code: source,
|
|
127
|
+
filePath,
|
|
128
|
+
versioned,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Resolves static imports, re-exports, and literal dynamic imports from the
|
|
134
|
+
* page file's directory, including tsconfig aliases in virtual modules.
|
|
135
|
+
*
|
|
136
|
+
* @internal exported for testing
|
|
137
|
+
*/
|
|
138
|
+
export function rewriteBareImports(source: string, dir: string, loader: SourceLoader): string {
|
|
139
|
+
const output = new MagicString(source);
|
|
140
|
+
walkAST(parseSource(source, loader).program, (node) => {
|
|
141
|
+
if (
|
|
142
|
+
node.type !== "ImportDeclaration" &&
|
|
143
|
+
node.type !== "ExportNamedDeclaration" &&
|
|
144
|
+
node.type !== "ExportAllDeclaration" &&
|
|
145
|
+
node.type !== "ImportExpression"
|
|
146
|
+
) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const literal = node.source;
|
|
150
|
+
if (literal?.type !== "Literal") {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const specifier = literal.value;
|
|
154
|
+
if (
|
|
155
|
+
typeof specifier !== "string" ||
|
|
156
|
+
specifier.startsWith(".") ||
|
|
157
|
+
isAbsolute(specifier) ||
|
|
158
|
+
specifier.startsWith("file:") ||
|
|
159
|
+
SINGLETON_PATHS.has(specifier)
|
|
160
|
+
) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let resolved: string;
|
|
165
|
+
try {
|
|
166
|
+
resolved = toImportSpecifier(Bun.resolveSync(specifier, dir));
|
|
167
|
+
} catch {
|
|
168
|
+
// Leave unresolved imports to Bun's native resolution and diagnostics.
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (
|
|
172
|
+
WORKSPACE_SOURCE_FILTER.test(resolved) &&
|
|
173
|
+
specifier !== "furin" &&
|
|
174
|
+
!specifier.startsWith("furin/") &&
|
|
175
|
+
specifier !== "@teyik0/furin" &&
|
|
176
|
+
!specifier.startsWith("@teyik0/furin/")
|
|
177
|
+
) {
|
|
178
|
+
resolved = `${resolved}?furin-server&t=${routeModuleSourceVersion(resolved)}`;
|
|
179
|
+
}
|
|
180
|
+
output.update(literal.start, literal.end, JSON.stringify(resolved));
|
|
181
|
+
});
|
|
182
|
+
return output.toString();
|
|
183
|
+
}
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
*
|
|
32
32
|
* ## Bare specifier rewriting
|
|
33
33
|
*
|
|
34
|
-
*
|
|
34
|
+
* In a virtual namespace, Bun resolves bare specifiers
|
|
35
35
|
* (e.g. `@teyik0/furin/link`, `shiki`) from the process CWD — not from the
|
|
36
36
|
* page file's directory. On a cold start the CWD and the file's directory
|
|
37
37
|
* often agree, but after `bun --hot` re-evaluates the server the module
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
* one already cached by `react-dom/server`. The result is the classic
|
|
41
41
|
* "two React copies" crash: `dispatcher.useState === null`.
|
|
42
42
|
*
|
|
43
|
-
* Fix:
|
|
43
|
+
* Fix: before returning the source, resolve every bare specifier from the page
|
|
44
44
|
* file's directory via `Bun.resolveSync` and replace it with the
|
|
45
45
|
* canonical on-disk path. This pins each import to exactly the same
|
|
46
46
|
* file-system location that Bun's native module resolver would choose,
|
|
@@ -52,303 +52,45 @@
|
|
|
52
52
|
*/
|
|
53
53
|
|
|
54
54
|
import { statSync } from "node:fs";
|
|
55
|
-
import { dirname, isAbsolute
|
|
56
|
-
import { fileURLToPath } from "node:url";
|
|
57
|
-
import MagicString from "magic-string";
|
|
55
|
+
import { dirname, isAbsolute } from "node:path";
|
|
58
56
|
import { splitDevPage } from "../plugin/transform-dev-page.ts";
|
|
59
57
|
import { transformIsomorphicFunctions } from "../plugin/transform-isomorphic.ts";
|
|
60
|
-
import { parseSource } from "../shared/parser.ts";
|
|
61
|
-
import type { AstNode } from "../shared/utils/ast-walk.ts";
|
|
62
|
-
import { walkAST } from "../shared/utils/ast-walk.ts";
|
|
63
58
|
import { invalidateDevLoaderCacheBySource } from "./cache/dev-loader.ts";
|
|
64
59
|
import { publishDevError } from "./dev/error.ts";
|
|
65
60
|
import { developmentGraphs, resolveDevSourceImports } from "./dev/graph.ts";
|
|
66
|
-
import { rewriteModuleSpecifiers } from "./dev/rewrite-module-specifiers.ts";
|
|
67
61
|
import { DevTransformFailure } from "./dev/transform-failure.ts";
|
|
62
|
+
import {
|
|
63
|
+
pinJsxRuntime,
|
|
64
|
+
rewriteBareImports,
|
|
65
|
+
rewriteRelativeImportsWithVersion,
|
|
66
|
+
rewriteSingletonImports,
|
|
67
|
+
type SourceLoader,
|
|
68
|
+
toImportSpecifier,
|
|
69
|
+
WORKSPACE_SOURCE_FILTER,
|
|
70
|
+
} from "./dev-page-imports.ts";
|
|
71
|
+
import { detectLoaderFromPath, SCRIPT_FILE_FILTER } from "./lang-detect.ts";
|
|
68
72
|
import { routeModuleSourceVersion } from "./router/source-version.ts";
|
|
69
73
|
|
|
70
74
|
// Matches ?furin-server with an optional &t=<ms> cache-buster.
|
|
71
75
|
const FURIN_SERVER_FILTER = /\?furin-server(?:&t=\d+)?$/;
|
|
72
76
|
const FURIN_RENDER_FILTER = /\?furin-render&t=\d+$/;
|
|
77
|
+
const COMMONJS_FILE_RE = /\.c[jt]s$/;
|
|
73
78
|
const ANY_FILTER = /.*/;
|
|
74
|
-
export const WORKSPACE_SOURCE_FILTER =
|
|
75
|
-
/^(?!.*(?:[\\/]node_modules[\\/]|[\\/]\.bun[\\/]))(?!.*\.(?:test|spec)\.[jt]sx?$).*\.[jt]sx?$/;
|
|
76
79
|
const T_PARAM_RE = /&t=(\d+)/;
|
|
77
80
|
const STRIP_FURIN_SERVER_RE = /\?furin-server.*$/;
|
|
78
81
|
const STRIP_T_PARAM_RE = /\?t=\d+$/;
|
|
79
|
-
const IMPORT_ATTRIBUTES_RE = /\b(?:with|assert)\s*\{/;
|
|
80
82
|
const DELETED_DEV_PAGE_CONTENTS = "export const route = undefined;";
|
|
81
83
|
|
|
82
84
|
let _pluginRegistered = false;
|
|
83
85
|
const pluginSourceStamps = new Map<string, string>();
|
|
84
86
|
|
|
85
|
-
type SourceLoader = "js" | "jsx" | "ts" | "tsx";
|
|
86
|
-
|
|
87
87
|
interface CachedDevPageContents {
|
|
88
88
|
contents: string;
|
|
89
89
|
moduleIdentity: string;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
// ── Singleton package resolution ───────────────────────────────────────────────
|
|
93
|
-
//
|
|
94
|
-
// React (and react-dom) must be singletons: every module in the render graph
|
|
95
|
-
// must import the EXACT same object instance so that ReactSharedInternals.H
|
|
96
|
-
// (the hooks dispatcher) is shared between react-dom/server and the page.
|
|
97
|
-
//
|
|
98
|
-
// We resolve the absolute on-disk path once at module-evaluation time and
|
|
99
|
-
// rewrite every explicit import in the transpiled source to use that path.
|
|
100
|
-
// The auto-injected jsx-dev-runtime import (added by Bun.Transpiler AFTER the
|
|
101
|
-
// source is transformed) is handled by injectJsxHelperImports below.
|
|
102
|
-
|
|
103
|
-
/** React packages that must share a single instance across the module graph. */
|
|
104
|
-
const SINGLETON_PKGS = [
|
|
105
|
-
"react",
|
|
106
|
-
"react/jsx-runtime",
|
|
107
|
-
"react/jsx-dev-runtime",
|
|
108
|
-
"react-dom",
|
|
109
|
-
"react-dom/server",
|
|
110
|
-
"react-dom/client",
|
|
111
|
-
] as const;
|
|
112
|
-
|
|
113
|
-
/** package specifier → absolute file path, resolved once at plugin registration time. */
|
|
114
|
-
const SINGLETON_PATHS = new Map<string, string>();
|
|
115
|
-
for (const pkg of SINGLETON_PKGS) {
|
|
116
|
-
try {
|
|
117
|
-
SINGLETON_PATHS.set(pkg, toImportSpecifier(fileURLToPath(import.meta.resolve(pkg))));
|
|
118
|
-
} catch {
|
|
119
|
-
// Package not installed — skip (e.g. react-dom/client in a server-only env)
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Converts a native absolute path to Bun's cross-platform import format. */
|
|
124
|
-
export function toImportSpecifier(filePath: string): string {
|
|
125
|
-
return filePath.replaceAll("\\", "/");
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function escapeRegExp(s: string): string {
|
|
129
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Rewrites bare React/react-dom singleton imports in source text to their
|
|
134
|
-
* absolute resolved paths. Handles explicit static import / re-export forms:
|
|
135
|
-
*
|
|
136
|
-
* import { useState } from "react" → import { useState } from "/abs/…"
|
|
137
|
-
* import type { FC } from "react"
|
|
138
|
-
* export { x } from "react"
|
|
139
|
-
* import "react/jsx-dev-runtime"
|
|
140
|
-
*
|
|
141
|
-
* Does NOT touch dynamic `import("react")` or `require("react")`.
|
|
142
|
-
*
|
|
143
|
-
* @internal exported for testing
|
|
144
|
-
*/
|
|
145
|
-
export function rewriteSingletonImports(source: string): string {
|
|
146
|
-
let result = source;
|
|
147
|
-
for (const [pkg, absPath] of SINGLETON_PATHS) {
|
|
148
|
-
// react-doctor-disable-next-line react-doctor/js-hoist-regexp
|
|
149
|
-
const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(pkg)}["']`, "g");
|
|
150
|
-
result = result.replace(re, (_, g1: string) => `${g1}${JSON.stringify(absPath)}`);
|
|
151
|
-
}
|
|
152
|
-
return result;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* `Bun.Transpiler.transformSync` converts JSX syntax to function calls using
|
|
157
|
-
* mangled helper names (e.g. `jsxDEV_7x81h0kn`, `Fragment_8vg9x3sq`) but does
|
|
158
|
-
* NOT emit the corresponding import statement — it expects Bun's full bundler
|
|
159
|
-
* pipeline to inject it later.
|
|
160
|
-
*
|
|
161
|
-
* When we return pre-transpiled JS from `onLoad`, that pipeline step never
|
|
162
|
-
* runs, leaving the helpers as undefined free variables. This function scans
|
|
163
|
-
* the transpiled source, detects which mangled helper names are used, and
|
|
164
|
-
* prepends the correct import statements using absolute on-disk paths from
|
|
165
|
-
* `SINGLETON_PATHS`.
|
|
166
|
-
*
|
|
167
|
-
* Helper → package mapping:
|
|
168
|
-
* jsxDEV_* → `{ jsxDEV as … }` from react/jsx-dev-runtime
|
|
169
|
-
* Fragment_* → `{ Fragment as … }` from react/jsx-dev-runtime
|
|
170
|
-
* jsx_* → `{ jsx as … }` from react/jsx-runtime (prod only)
|
|
171
|
-
* jsxs_* → `{ jsxs as … }` from react/jsx-runtime (prod only)
|
|
172
|
-
*
|
|
173
|
-
* @internal exported for testing
|
|
174
|
-
*/
|
|
175
|
-
export function injectJsxHelperImports(transpiled: string): string {
|
|
176
|
-
// Match mangled JSX helper names. Alternation order matters: try longer
|
|
177
|
-
// prefixes first so "jsxDEV_xxx" isn't partially matched as "jsx_xxx".
|
|
178
|
-
const JSX_HELPER_RE = /\b(jsxDEV|jsxs|jsx|Fragment)_([0-9a-z]{8})\b/g;
|
|
179
|
-
|
|
180
|
-
// Package → Map<varName, exportName>
|
|
181
|
-
const devRuntime = new Map<string, string>(); // react/jsx-dev-runtime
|
|
182
|
-
const prodRuntime = new Map<string, string>(); // react/jsx-runtime
|
|
183
|
-
|
|
184
|
-
for (const [, base, hash] of transpiled.matchAll(JSX_HELPER_RE)) {
|
|
185
|
-
if (!(base && hash)) {
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
const varName = `${base}_${hash}`;
|
|
189
|
-
if (base === "jsxDEV" || base === "Fragment") {
|
|
190
|
-
devRuntime.set(varName, base);
|
|
191
|
-
} else {
|
|
192
|
-
prodRuntime.set(varName, base);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const lines: string[] = [];
|
|
197
|
-
|
|
198
|
-
if (devRuntime.size > 0) {
|
|
199
|
-
const absPath = SINGLETON_PATHS.get("react/jsx-dev-runtime");
|
|
200
|
-
if (absPath) {
|
|
201
|
-
const specifiers = [...devRuntime.entries()]
|
|
202
|
-
.map(([varName, exportName]) => `${exportName} as ${varName}`)
|
|
203
|
-
.join(", ");
|
|
204
|
-
lines.push(`import { ${specifiers} } from ${JSON.stringify(absPath)};`);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (prodRuntime.size > 0) {
|
|
209
|
-
const absPath = SINGLETON_PATHS.get("react/jsx-runtime");
|
|
210
|
-
if (absPath) {
|
|
211
|
-
const specifiers = [...prodRuntime.entries()]
|
|
212
|
-
.map(([varName, exportName]) => `${exportName} as ${varName}`)
|
|
213
|
-
.join(", ");
|
|
214
|
-
lines.push(`import { ${specifiers} } from ${JSON.stringify(absPath)};`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (lines.length === 0) {
|
|
219
|
-
return transpiled;
|
|
220
|
-
}
|
|
221
|
-
return `${lines.join("\n")}\n${transpiled}`;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/** @internal exported for testing */
|
|
225
|
-
export function rewriteRelativeImports(source: string, dir: string): string {
|
|
226
|
-
return rewriteModuleSpecifiers({
|
|
227
|
-
code: source,
|
|
228
|
-
filePath: resolve(dir, "__furin_entry.tsx"),
|
|
229
|
-
versioned: false,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function rewriteRelativeImportsWithVersion(
|
|
234
|
-
source: string,
|
|
235
|
-
filePath: string,
|
|
236
|
-
versioned: boolean
|
|
237
|
-
): string {
|
|
238
|
-
return rewriteModuleSpecifiers({
|
|
239
|
-
code: source,
|
|
240
|
-
filePath,
|
|
241
|
-
versioned,
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Resolves static imports, re-exports, and literal dynamic imports from the
|
|
247
|
-
* page file's directory, including tsconfig aliases in virtual modules.
|
|
248
|
-
*
|
|
249
|
-
* @internal exported for testing
|
|
250
|
-
*/
|
|
251
|
-
export function rewriteBareImports(transpiled: string, dir: string): string {
|
|
252
|
-
const output = new MagicString(transpiled);
|
|
253
|
-
walkAST(parseSource(transpiled, "js").program, (node) => {
|
|
254
|
-
if (
|
|
255
|
-
node.type !== "ImportDeclaration" &&
|
|
256
|
-
node.type !== "ExportNamedDeclaration" &&
|
|
257
|
-
node.type !== "ExportAllDeclaration" &&
|
|
258
|
-
node.type !== "ImportExpression"
|
|
259
|
-
) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
const literal = node.source as AstNode | undefined;
|
|
263
|
-
const specifier = literal?.value;
|
|
264
|
-
if (
|
|
265
|
-
literal?.type !== "Literal" ||
|
|
266
|
-
typeof specifier !== "string" ||
|
|
267
|
-
specifier.startsWith(".") ||
|
|
268
|
-
isAbsolute(specifier) ||
|
|
269
|
-
specifier.startsWith("file:") ||
|
|
270
|
-
SINGLETON_PATHS.has(specifier)
|
|
271
|
-
) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
let resolved: string;
|
|
276
|
-
try {
|
|
277
|
-
resolved = toImportSpecifier(Bun.resolveSync(specifier, dir));
|
|
278
|
-
} catch {
|
|
279
|
-
// Leave unresolved imports to Bun's native resolution and diagnostics.
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
output.update(literal.start, literal.end, JSON.stringify(resolved));
|
|
283
|
-
});
|
|
284
|
-
return output.toString();
|
|
285
|
-
}
|
|
286
|
-
|
|
287
92
|
function getSourceLoader(filePath: string): SourceLoader | null {
|
|
288
|
-
|
|
289
|
-
return "tsx";
|
|
290
|
-
}
|
|
291
|
-
if (filePath.endsWith(".ts")) {
|
|
292
|
-
return "ts";
|
|
293
|
-
}
|
|
294
|
-
if (filePath.endsWith(".jsx")) {
|
|
295
|
-
return "jsx";
|
|
296
|
-
}
|
|
297
|
-
if (filePath.endsWith(".js")) {
|
|
298
|
-
return "js";
|
|
299
|
-
}
|
|
300
|
-
return null;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Bun.Transpiler drops static import attributes, turning text imports into file paths.
|
|
304
|
-
function restoreImportAttributes(source: string, transpiled: string, loader: SourceLoader): string {
|
|
305
|
-
if (!IMPORT_ATTRIBUTES_RE.test(source)) {
|
|
306
|
-
return transpiled;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const declarations = parseSource(source, loader).program.body as AstNode[];
|
|
310
|
-
const output = new MagicString(transpiled);
|
|
311
|
-
const emitted = parseSource(transpiled, "js").program.body as AstNode[];
|
|
312
|
-
const matched = new Set<AstNode>();
|
|
313
|
-
for (const declaration of declarations) {
|
|
314
|
-
if (declaration.importKind === "type" || declaration.exportKind === "type") {
|
|
315
|
-
continue;
|
|
316
|
-
}
|
|
317
|
-
const specifiers = declaration.specifiers as AstNode[] | undefined;
|
|
318
|
-
if (
|
|
319
|
-
specifiers?.length &&
|
|
320
|
-
specifiers.every(
|
|
321
|
-
(specifier) => specifier.importKind === "type" || specifier.exportKind === "type"
|
|
322
|
-
)
|
|
323
|
-
) {
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
const sourcePath = (declaration.source as { value?: unknown } | undefined)?.value;
|
|
327
|
-
if (typeof sourcePath !== "string") {
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
const target = emitted.find(
|
|
331
|
-
(node) =>
|
|
332
|
-
!matched.has(node) &&
|
|
333
|
-
node.type === declaration.type &&
|
|
334
|
-
(node.source as { value?: unknown } | undefined)?.value === sourcePath
|
|
335
|
-
);
|
|
336
|
-
if (!target) {
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
matched.add(target);
|
|
340
|
-
const attributes = declaration.attributes as AstNode[] | undefined;
|
|
341
|
-
if (!attributes?.length || (target.attributes as AstNode[] | undefined)?.length) {
|
|
342
|
-
continue;
|
|
343
|
-
}
|
|
344
|
-
const [first] = attributes;
|
|
345
|
-
const last = attributes.at(-1);
|
|
346
|
-
const imported = target.source as AstNode | undefined;
|
|
347
|
-
if (first && last && imported) {
|
|
348
|
-
output.appendLeft(imported.end, ` with { ${source.slice(first.start, last.end)} }`);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return output.toString();
|
|
93
|
+
return SCRIPT_FILE_FILTER.test(filePath) ? detectLoaderFromPath(filePath) : null;
|
|
352
94
|
}
|
|
353
95
|
|
|
354
96
|
function shouldSkipWorkspaceTransform(filePath: string): boolean {
|
|
@@ -448,23 +190,15 @@ export function transformDevSource(
|
|
|
448
190
|
`${filePath}?furin-render&t=${routeModuleSourceVersion(filePath)}`
|
|
449
191
|
);
|
|
450
192
|
const serverSource = split?.contract ?? isomorphicSource;
|
|
451
|
-
|
|
193
|
+
let result = options.rewriteRelativeImports
|
|
452
194
|
? rewriteRelativeImportsWithVersion(serverSource, filePath, true)
|
|
453
195
|
: serverSource;
|
|
454
|
-
const transpiler = new Bun.Transpiler({ loader });
|
|
455
|
-
const transpiled = restoreImportAttributes(
|
|
456
|
-
sourceForTranspile,
|
|
457
|
-
transpiler.transformSync(sourceForTranspile, loader),
|
|
458
|
-
loader
|
|
459
|
-
);
|
|
460
|
-
|
|
461
|
-
let result = transpiled;
|
|
462
196
|
if (options.rewriteBareImports) {
|
|
463
|
-
result = rewriteBareImports(result, dirname(filePath));
|
|
197
|
+
result = rewriteBareImports(result, dirname(filePath), loader);
|
|
464
198
|
}
|
|
465
199
|
|
|
466
|
-
result = rewriteSingletonImports(result);
|
|
467
|
-
return
|
|
200
|
+
result = rewriteSingletonImports(result, loader);
|
|
201
|
+
return pinJsxRuntime(result, loader);
|
|
468
202
|
} catch (error) {
|
|
469
203
|
return rethrowWithSourcePath(error, filePath);
|
|
470
204
|
}
|
|
@@ -538,7 +272,7 @@ export function registerDevPagePlugin(): void {
|
|
|
538
272
|
rewriteBareImports: true,
|
|
539
273
|
rewriteRelativeImports: true,
|
|
540
274
|
}),
|
|
541
|
-
loader:
|
|
275
|
+
loader: detectLoaderFromPath(filePath),
|
|
542
276
|
};
|
|
543
277
|
});
|
|
544
278
|
// Keep an already-loaded module generation usable if its source is
|
|
@@ -555,20 +289,23 @@ export function registerDevPagePlugin(): void {
|
|
|
555
289
|
const filePath = args.path.replace(STRIP_FURIN_SERVER_RE, "");
|
|
556
290
|
// biome-ignore lint/suspicious/noUnnecessaryConditions: the timestamp query is optional.
|
|
557
291
|
const resolvedPath = tMatch ? `${filePath}?t=${tMatch[1]}` : filePath;
|
|
558
|
-
return {
|
|
292
|
+
return {
|
|
293
|
+
namespace: COMMONJS_FILE_RE.test(filePath) ? "file" : "furin-dev-page",
|
|
294
|
+
path: resolvedPath,
|
|
295
|
+
};
|
|
559
296
|
});
|
|
560
297
|
|
|
561
298
|
/**
|
|
562
|
-
* Workspace source files
|
|
299
|
+
* Workspace source files imported by plain path (local components, core
|
|
563
300
|
* packages, etc.) still load through Bun's normal file namespace in dev.
|
|
564
301
|
*
|
|
565
302
|
* After bun --hot re-evaluates part of that graph, those modules can
|
|
566
303
|
* re-import React through a different logical path than react-dom/server,
|
|
567
304
|
* which recreates the classic "dispatcher is null" invalid hook crash.
|
|
568
305
|
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
306
|
+
* Rewrite only the React singleton imports and the JSX runtime so every
|
|
307
|
+
* SSR module observes the exact same React instance, while still keeping
|
|
308
|
+
* the files in Bun's watched graph.
|
|
572
309
|
*/
|
|
573
310
|
build.onLoad({ filter: WORKSPACE_SOURCE_FILTER }, async (args) => {
|
|
574
311
|
const raw = await Bun.file(args.path).text();
|
|
@@ -602,7 +339,7 @@ export function registerDevPagePlugin(): void {
|
|
|
602
339
|
|
|
603
340
|
return {
|
|
604
341
|
contents,
|
|
605
|
-
loader
|
|
342
|
+
loader,
|
|
606
343
|
};
|
|
607
344
|
});
|
|
608
345
|
|
|
@@ -611,7 +348,7 @@ export function registerDevPagePlugin(): void {
|
|
|
611
348
|
* this handler is called for each edited source version; strip it before
|
|
612
349
|
* file I/O.
|
|
613
350
|
*
|
|
614
|
-
* ## Why
|
|
351
|
+
* ## Why specifiers are rewritten in the source
|
|
615
352
|
*
|
|
616
353
|
* Bun's runtime plugin system (used by `bun --hot`) does NOT route
|
|
617
354
|
* sub-imports from virtual-namespace modules through `onResolve` hooks —
|
|
@@ -622,14 +359,14 @@ export function registerDevPagePlugin(): void {
|
|
|
622
359
|
*
|
|
623
360
|
* 1. **Relative imports** (`./root`, `../utils`) — no real directory
|
|
624
361
|
* context in the virtual namespace → Bun fails to resolve them.
|
|
625
|
-
* 2. **Auto-injected JSX runtime** — `import {
|
|
362
|
+
* 2. **Auto-injected JSX runtime** — `import { jsxDEV } from
|
|
626
363
|
* "react/jsx-dev-runtime"` added by Bun's TSX transpiler AFTER
|
|
627
|
-
* `onLoad` returns
|
|
364
|
+
* `onLoad` returns, resolved from the process CWD.
|
|
628
365
|
*
|
|
629
|
-
* Solution:
|
|
630
|
-
*
|
|
631
|
-
* it
|
|
632
|
-
*
|
|
366
|
+
* Solution: rewrite the specifiers in the TS/TSX source and return it
|
|
367
|
+
* with its own loader. Bun transpiles it and maps stack frames to the
|
|
368
|
+
* returned text (it ignores an `onLoad` sourcemap), so every rewrite
|
|
369
|
+
* stays on its line:
|
|
633
370
|
*
|
|
634
371
|
* • `rewriteRelativeImports` → converts `./root` to `/abs/path/root`
|
|
635
372
|
* • `rewriteBareImports` → resolves ALL bare specifiers (including
|
|
@@ -638,8 +375,8 @@ export function registerDevPagePlugin(): void {
|
|
|
638
375
|
* bun --hot re-evaluation.
|
|
639
376
|
* • `rewriteSingletonImports` → belt-and-suspenders for react singletons
|
|
640
377
|
* (covered by rewriteBareImports but kept for safety).
|
|
641
|
-
* • `
|
|
642
|
-
*
|
|
378
|
+
* • `pinJsxRuntime` → points the auto-injected JSX runtime import at the
|
|
379
|
+
* same React package with an `@jsxImportSource` pragma.
|
|
643
380
|
*/
|
|
644
381
|
build.onLoad({ filter: ANY_FILTER, namespace: "furin-dev-page" }, async (args) => {
|
|
645
382
|
const filePath = args.path.replace(STRIP_T_PARAM_RE, "");
|
|
@@ -647,7 +384,7 @@ export function registerDevPagePlugin(): void {
|
|
|
647
384
|
|
|
648
385
|
return {
|
|
649
386
|
contents,
|
|
650
|
-
loader:
|
|
387
|
+
loader: detectLoaderFromPath(filePath),
|
|
651
388
|
};
|
|
652
389
|
});
|
|
653
390
|
},
|
|
@@ -26,7 +26,7 @@ export function devtoolsEventsSnapshot(instance?: FurinInstance): {
|
|
|
26
26
|
events: DevtoolsServerEvent[];
|
|
27
27
|
lastEventId: number;
|
|
28
28
|
} {
|
|
29
|
-
const hub = instanceDevtoolsHub(instance);
|
|
29
|
+
const hub = instanceDevtoolsHub(instance ?? currentInstance());
|
|
30
30
|
return { events: [...hub.events], lastEventId: hub.sequence };
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -35,7 +35,7 @@ export function subscribeDevtoolsEventsAfter(
|
|
|
35
35
|
listener: (event: DevtoolsServerEvent) => void,
|
|
36
36
|
instance?: FurinInstance
|
|
37
37
|
): { replay: DevtoolsServerEvent[]; unsubscribe: () => void } {
|
|
38
|
-
const hub = instanceDevtoolsHub(instance);
|
|
38
|
+
const hub = instanceDevtoolsHub(instance ?? currentInstance());
|
|
39
39
|
hub.listeners.add(listener);
|
|
40
40
|
return {
|
|
41
41
|
replay: hub.events.filter((event) => event.id > cursor),
|
|
@@ -46,7 +46,7 @@ export function subscribeDevtoolsEventsAfter(
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export function appendDevtoolsEvent(event: DevtoolsServerEventInput): DevtoolsServerEvent {
|
|
49
|
-
const hub = instanceDevtoolsHub();
|
|
49
|
+
const hub = instanceDevtoolsHub(currentInstance());
|
|
50
50
|
hub.sequence += 1;
|
|
51
51
|
const complete = {
|
|
52
52
|
...event,
|
|
@@ -56,14 +56,6 @@ export function currentInstrumentationRequest(): void {
|
|
|
56
56
|
// Production instrumentation has no request-local state.
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export function runWithRequestInstrumentation<T>(_request: Request, fn: () => T): T {
|
|
60
|
-
return fn();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function shouldInstrumentRequest(_pathname: string, _prefix: string): boolean {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
59
|
export function instrumentationLoggerExclusions(_prefix: string): string[] {
|
|
68
60
|
return [];
|
|
69
61
|
}
|