one 1.25.12 → 1.25.15
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 +37 -186
- package/dist/cjs/cli/build.native.js +270 -423
- package/dist/cjs/cli/build.native.js.map +1 -1
- package/dist/cjs/cli/buildPage.cjs +7 -7
- package/dist/cjs/cli/buildPage.native.js +7 -7
- package/dist/cjs/cli/buildPage.native.js.map +1 -1
- package/dist/cjs/cli/buildPageWorker.cjs +1 -1
- package/dist/cjs/cli/buildPageWorker.native.js +1 -1
- package/dist/cjs/cli/buildPageWorker.native.js.map +1 -1
- package/dist/cjs/cli/serverRouteModules.cjs +47 -0
- package/dist/cjs/cli/serverRouteModules.native.js +52 -0
- package/dist/cjs/cli/serverRouteModules.native.js.map +1 -0
- package/dist/cjs/cli/workerPool.native.js.map +1 -1
- package/dist/cjs/createApp.cjs +3 -0
- package/dist/cjs/createDevHandleRequest.cjs +151 -0
- package/dist/cjs/createDevHandleRequest.native.js +194 -0
- package/dist/cjs/createDevHandleRequest.native.js.map +1 -0
- package/dist/cjs/createHandleRequest.cjs +1 -123
- package/dist/cjs/createHandleRequest.native.js +1 -163
- package/dist/cjs/createHandleRequest.native.js.map +1 -1
- package/dist/cjs/createHandleRequest.test.cjs +25 -25
- package/dist/cjs/createHandleRequest.test.native.js +25 -25
- package/dist/cjs/createHandleRequest.test.native.js.map +1 -1
- package/dist/cjs/headless-server.native.js.map +1 -1
- package/dist/cjs/headless.cjs +4 -0
- package/dist/cjs/headless.native.js +4 -0
- package/dist/cjs/headless.native.js.map +1 -1
- package/dist/cjs/layouts/Drawer.cjs +0 -2
- package/dist/cjs/layouts/Drawer.native.js.map +1 -1
- package/dist/cjs/layouts/Tabs.cjs +0 -2
- package/dist/cjs/layouts/Tabs.native.js.map +1 -1
- package/dist/cjs/router/diagnoseRouteLoadFailure.native.js.map +1 -1
- package/dist/cjs/router/useViteRoutes.cjs +9 -1
- package/dist/cjs/router/useViteRoutes.native.js +9 -1
- package/dist/cjs/router/useViteRoutes.native.js.map +1 -1
- package/dist/cjs/router/web/WebStackView.cjs +0 -2
- package/dist/cjs/router/web/WebStackView.native.js +0 -2
- package/dist/cjs/router/web/WebStackView.native.js.map +1 -1
- package/dist/cjs/serve-worker.cjs +3 -2
- package/dist/cjs/serve-worker.native.js +3 -2
- package/dist/cjs/serve-worker.native.js.map +1 -1
- package/dist/cjs/server/oneServe.cjs +23 -4
- package/dist/cjs/server/oneServe.native.js +25 -6
- package/dist/cjs/server/oneServe.native.js.map +1 -1
- package/dist/cjs/server/routeExportsFromEntry.cjs +47 -0
- package/dist/cjs/server/routeExportsFromEntry.native.js +52 -0
- package/dist/cjs/server/routeExportsFromEntry.native.js.map +1 -0
- package/dist/cjs/server/workerHandler.cjs +30 -12
- package/dist/cjs/server/workerHandler.native.js +32 -13
- package/dist/cjs/server/workerHandler.native.js.map +1 -1
- package/dist/cjs/server/workerHandler.test.cjs +43 -10
- package/dist/cjs/server/workerHandler.test.native.js +46 -10
- package/dist/cjs/server/workerHandler.test.native.js.map +1 -1
- package/dist/cjs/views/ScrollBehavior.native.js.map +1 -1
- package/dist/cjs/vite/cloudflareWranglerConfig.cjs +247 -0
- package/dist/cjs/vite/cloudflareWranglerConfig.native.js +392 -0
- package/dist/cjs/vite/cloudflareWranglerConfig.native.js.map +1 -0
- package/dist/cjs/vite/cloudflareWranglerConfig.test.cjs +116 -0
- package/dist/cjs/vite/cloudflareWranglerConfig.test.native.js +120 -0
- package/dist/cjs/vite/cloudflareWranglerConfig.test.native.js.map +1 -0
- package/dist/cjs/vite/one.cjs +4 -2
- package/dist/cjs/vite/one.native.js +8 -6
- package/dist/cjs/vite/one.native.js.map +1 -1
- package/dist/cjs/vite/plugins/SSRCSSPlugin.cjs +10 -1
- package/dist/cjs/vite/plugins/SSRCSSPlugin.native.js +52 -3
- package/dist/cjs/vite/plugins/SSRCSSPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/environmentGuardPlugin.cjs +1 -1
- package/dist/cjs/vite/plugins/environmentGuardPlugin.native.js +1 -1
- package/dist/cjs/vite/plugins/environmentGuardPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/environmentGuardPlugin.test.cjs +4 -0
- package/dist/cjs/vite/plugins/environmentGuardPlugin.test.native.js +4 -0
- package/dist/cjs/vite/plugins/environmentGuardPlugin.test.native.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +14 -5
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +15 -5
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.test.cjs +47 -0
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.test.native.js +47 -0
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.test.native.js.map +1 -1
- package/dist/cjs/vite/plugins/virtualEntryPlugin.cjs +9 -7
- package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js +11 -7
- package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/virtualEntryPlugin.test.cjs +12 -0
- package/dist/cjs/vite/plugins/virtualEntryPlugin.test.native.js +12 -0
- package/dist/cjs/vite/plugins/virtualEntryPlugin.test.native.js.map +1 -1
- package/dist/cjs/vite/plugins/workerdDevPlugin.cjs +364 -0
- package/dist/cjs/vite/plugins/workerdDevPlugin.native.js +461 -0
- package/dist/cjs/vite/plugins/workerdDevPlugin.native.js.map +1 -0
- package/dist/cjs/vite/plugins/workerdDevPlugin.test.cjs +42 -0
- package/dist/cjs/vite/plugins/workerdDevPlugin.test.native.js +45 -0
- package/dist/cjs/vite/plugins/workerdDevPlugin.test.native.js.map +1 -0
- package/dist/cjs/vite/replaceLoader.cjs +6 -3
- package/dist/cjs/vite/replaceLoader.native.js +8 -3
- package/dist/cjs/vite/replaceLoader.native.js.map +1 -1
- package/dist/esm/cli/build.mjs +31 -180
- package/dist/esm/cli/build.mjs.map +1 -1
- package/dist/esm/cli/build.native.js +264 -417
- package/dist/esm/cli/build.native.js.map +1 -1
- package/dist/esm/cli/buildPage.mjs +7 -7
- package/dist/esm/cli/buildPage.mjs.map +1 -1
- package/dist/esm/cli/buildPage.native.js +7 -7
- package/dist/esm/cli/buildPage.native.js.map +1 -1
- package/dist/esm/cli/buildPageWorker.mjs +1 -1
- package/dist/esm/cli/buildPageWorker.mjs.map +1 -1
- package/dist/esm/cli/buildPageWorker.native.js +1 -1
- package/dist/esm/cli/buildPageWorker.native.js.map +1 -1
- package/dist/esm/cli/serverRouteModules.mjs +22 -0
- package/dist/esm/cli/serverRouteModules.mjs.map +1 -0
- package/dist/esm/cli/serverRouteModules.native.js +24 -0
- package/dist/esm/cli/serverRouteModules.native.js.map +1 -0
- package/dist/esm/cli/workerPool.mjs.map +1 -1
- package/dist/esm/cli/workerPool.native.js.map +1 -1
- package/dist/esm/createApp.mjs +4 -1
- package/dist/esm/createApp.mjs.map +1 -1
- package/dist/esm/createDevHandleRequest.mjs +126 -0
- package/dist/esm/createDevHandleRequest.mjs.map +1 -0
- package/dist/esm/createDevHandleRequest.native.js +166 -0
- package/dist/esm/createDevHandleRequest.native.js.map +1 -0
- package/dist/esm/createHandleRequest.mjs +1 -123
- package/dist/esm/createHandleRequest.mjs.map +1 -1
- package/dist/esm/createHandleRequest.native.js +1 -163
- package/dist/esm/createHandleRequest.native.js.map +1 -1
- package/dist/esm/createHandleRequest.test.mjs +1 -1
- package/dist/esm/createHandleRequest.test.native.js +1 -1
- package/dist/esm/headless-server.mjs.map +1 -1
- package/dist/esm/headless-server.native.js.map +1 -1
- package/dist/esm/headless.mjs +4 -0
- package/dist/esm/headless.mjs.map +1 -1
- package/dist/esm/headless.native.js +4 -0
- package/dist/esm/headless.native.js.map +1 -1
- package/dist/esm/layouts/Drawer.mjs +0 -2
- package/dist/esm/layouts/Drawer.mjs.map +1 -1
- package/dist/esm/layouts/Drawer.native.js.map +1 -1
- package/dist/esm/layouts/Tabs.mjs +0 -2
- package/dist/esm/layouts/Tabs.mjs.map +1 -1
- package/dist/esm/layouts/Tabs.native.js.map +1 -1
- package/dist/esm/router/diagnoseRouteLoadFailure.mjs.map +1 -1
- package/dist/esm/router/diagnoseRouteLoadFailure.native.js.map +1 -1
- package/dist/esm/router/useViteRoutes.mjs +9 -1
- package/dist/esm/router/useViteRoutes.mjs.map +1 -1
- package/dist/esm/router/useViteRoutes.native.js +9 -1
- package/dist/esm/router/useViteRoutes.native.js.map +1 -1
- package/dist/esm/router/web/WebStackView.mjs +0 -2
- package/dist/esm/router/web/WebStackView.mjs.map +1 -1
- package/dist/esm/router/web/WebStackView.native.js +0 -2
- package/dist/esm/router/web/WebStackView.native.js.map +1 -1
- package/dist/esm/serve-worker.mjs +3 -2
- package/dist/esm/serve-worker.mjs.map +1 -1
- package/dist/esm/serve-worker.native.js +3 -2
- package/dist/esm/serve-worker.native.js.map +1 -1
- package/dist/esm/server/oneServe.mjs +23 -4
- package/dist/esm/server/oneServe.mjs.map +1 -1
- package/dist/esm/server/oneServe.native.js +25 -6
- package/dist/esm/server/oneServe.native.js.map +1 -1
- package/dist/esm/server/routeExportsFromEntry.mjs +21 -0
- package/dist/esm/server/routeExportsFromEntry.mjs.map +1 -0
- package/dist/esm/server/routeExportsFromEntry.native.js +23 -0
- package/dist/esm/server/routeExportsFromEntry.native.js.map +1 -0
- package/dist/esm/server/workerHandler.mjs +30 -12
- package/dist/esm/server/workerHandler.mjs.map +1 -1
- package/dist/esm/server/workerHandler.native.js +32 -13
- package/dist/esm/server/workerHandler.native.js.map +1 -1
- package/dist/esm/server/workerHandler.test.mjs +43 -10
- package/dist/esm/server/workerHandler.test.mjs.map +1 -1
- package/dist/esm/server/workerHandler.test.native.js +46 -10
- package/dist/esm/server/workerHandler.test.native.js.map +1 -1
- package/dist/esm/views/ScrollBehavior.mjs.map +1 -1
- package/dist/esm/views/ScrollBehavior.native.js.map +1 -1
- package/dist/esm/vite/cloudflareWranglerConfig.mjs +202 -0
- package/dist/esm/vite/cloudflareWranglerConfig.mjs.map +1 -0
- package/dist/esm/vite/cloudflareWranglerConfig.native.js +344 -0
- package/dist/esm/vite/cloudflareWranglerConfig.native.js.map +1 -0
- package/dist/esm/vite/cloudflareWranglerConfig.test.mjs +117 -0
- package/dist/esm/vite/cloudflareWranglerConfig.test.mjs.map +1 -0
- package/dist/esm/vite/cloudflareWranglerConfig.test.native.js +118 -0
- package/dist/esm/vite/cloudflareWranglerConfig.test.native.js.map +1 -0
- package/dist/esm/vite/one.mjs +4 -2
- package/dist/esm/vite/one.mjs.map +1 -1
- package/dist/esm/vite/one.native.js +8 -6
- package/dist/esm/vite/one.native.js.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.mjs +10 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.native.js +52 -3
- package/dist/esm/vite/plugins/SSRCSSPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/environmentGuardPlugin.mjs +1 -1
- package/dist/esm/vite/plugins/environmentGuardPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/environmentGuardPlugin.native.js +1 -1
- package/dist/esm/vite/plugins/environmentGuardPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/environmentGuardPlugin.test.mjs +4 -0
- package/dist/esm/vite/plugins/environmentGuardPlugin.test.mjs.map +1 -1
- package/dist/esm/vite/plugins/environmentGuardPlugin.test.native.js +4 -0
- package/dist/esm/vite/plugins/environmentGuardPlugin.test.native.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +13 -4
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +14 -4
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.mjs +47 -0
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.native.js +47 -0
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.native.js.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.mjs +9 -7
- package/dist/esm/vite/plugins/virtualEntryPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.native.js +11 -7
- package/dist/esm/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.test.mjs +12 -0
- package/dist/esm/vite/plugins/virtualEntryPlugin.test.mjs.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.test.native.js +12 -0
- package/dist/esm/vite/plugins/virtualEntryPlugin.test.native.js.map +1 -1
- package/dist/esm/vite/plugins/workerdDevPlugin.mjs +336 -0
- package/dist/esm/vite/plugins/workerdDevPlugin.mjs.map +1 -0
- package/dist/esm/vite/plugins/workerdDevPlugin.native.js +430 -0
- package/dist/esm/vite/plugins/workerdDevPlugin.native.js.map +1 -0
- package/dist/esm/vite/plugins/workerdDevPlugin.test.mjs +43 -0
- package/dist/esm/vite/plugins/workerdDevPlugin.test.mjs.map +1 -0
- package/dist/esm/vite/plugins/workerdDevPlugin.test.native.js +43 -0
- package/dist/esm/vite/plugins/workerdDevPlugin.test.native.js.map +1 -0
- package/dist/esm/vite/replaceLoader.mjs +6 -3
- package/dist/esm/vite/replaceLoader.mjs.map +1 -1
- package/dist/esm/vite/replaceLoader.native.js +8 -3
- package/dist/esm/vite/replaceLoader.native.js.map +1 -1
- package/package.json +9 -9
- package/src/cli/build.ts +48 -224
- package/src/cli/buildPage.ts +9 -7
- package/src/cli/buildPageWorker.ts +1 -0
- package/src/cli/serverRouteModules.ts +33 -0
- package/src/cli/workerPool.ts +1 -0
- package/src/createApp.tsx +5 -1
- package/src/createDevHandleRequest.ts +186 -0
- package/src/createHandleRequest.test.ts +1 -1
- package/src/createHandleRequest.ts +2 -172
- package/src/headless-server.ts +0 -1
- package/src/headless.tsx +5 -0
- package/src/layouts/Drawer.web.tsx +0 -3
- package/src/layouts/Tabs.web.tsx +0 -2
- package/src/router/diagnoseRouteLoadFailure.ts +3 -1
- package/src/router/useViteRoutes.tsx +9 -1
- package/src/router/web/WebStackView.tsx +0 -3
- package/src/serve-worker.ts +6 -1
- package/src/server/oneServe.ts +40 -16
- package/src/server/routeExportsFromEntry.ts +59 -0
- package/src/server/workerHandler.test.ts +37 -9
- package/src/server/workerHandler.ts +39 -13
- package/src/views/ScrollBehavior.tsx +5 -1
- package/src/vite/cloudflareWranglerConfig.test.ts +101 -0
- package/src/vite/cloudflareWranglerConfig.ts +252 -0
- package/src/vite/one.ts +14 -1
- package/src/vite/plugins/SSRCSSPlugin.ts +17 -2
- package/src/vite/plugins/environmentGuardPlugin.test.ts +5 -0
- package/src/vite/plugins/environmentGuardPlugin.ts +2 -2
- package/src/vite/plugins/fileSystemRouterPlugin.test.ts +44 -0
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +20 -8
- package/src/vite/plugins/virtualEntryPlugin.test.ts +13 -0
- package/src/vite/plugins/virtualEntryPlugin.ts +13 -9
- package/src/vite/plugins/workerdDevPlugin.test.ts +44 -0
- package/src/vite/plugins/workerdDevPlugin.ts +398 -0
- package/src/vite/replaceLoader.ts +10 -2
- package/types/cli/build.d.ts.map +1 -1
- package/types/cli/buildPage.d.ts +1 -1
- package/types/cli/buildPage.d.ts.map +1 -1
- package/types/cli/serverRouteModules.d.ts +2 -0
- package/types/cli/serverRouteModules.d.ts.map +1 -0
- package/types/cli/workerPool.d.ts +1 -0
- package/types/cli/workerPool.d.ts.map +1 -1
- package/types/createApp.d.ts.map +1 -1
- package/types/createDevHandleRequest.d.ts +10 -0
- package/types/createDevHandleRequest.d.ts.map +1 -0
- package/types/createHandleRequest.d.ts +2 -9
- package/types/createHandleRequest.d.ts.map +1 -1
- package/types/headless-server.d.ts +0 -1
- package/types/headless-server.d.ts.map +1 -1
- package/types/headless.d.ts.map +1 -1
- package/types/layouts/Drawer.web.d.ts.map +1 -1
- package/types/layouts/Tabs.web.d.ts.map +1 -1
- package/types/router/diagnoseRouteLoadFailure.d.ts.map +1 -1
- package/types/router/useViteRoutes.d.ts.map +1 -1
- package/types/router/web/WebStackView.d.ts.map +1 -1
- package/types/serve-worker.d.ts +3 -1
- package/types/serve-worker.d.ts.map +1 -1
- package/types/server/oneServe.d.ts +1 -1
- package/types/server/oneServe.d.ts.map +1 -1
- package/types/server/routeExportsFromEntry.d.ts +29 -0
- package/types/server/routeExportsFromEntry.d.ts.map +1 -0
- package/types/server/workerHandler.d.ts +2 -1
- package/types/server/workerHandler.d.ts.map +1 -1
- package/types/views/ScrollBehavior.d.ts.map +1 -1
- package/types/vite/cloudflareWranglerConfig.d.ts +21 -0
- package/types/vite/cloudflareWranglerConfig.d.ts.map +1 -0
- package/types/vite/cloudflareWranglerConfig.test.d.ts +2 -0
- package/types/vite/cloudflareWranglerConfig.test.d.ts.map +1 -0
- package/types/vite/one.d.ts.map +1 -1
- package/types/vite/plugins/SSRCSSPlugin.d.ts.map +1 -1
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
- package/types/vite/plugins/virtualEntryPlugin.d.ts.map +1 -1
- package/types/vite/plugins/workerdDevPlugin.d.ts +15 -0
- package/types/vite/plugins/workerdDevPlugin.d.ts.map +1 -0
- package/types/vite/plugins/workerdDevPlugin.test.d.ts +2 -0
- package/types/vite/plugins/workerdDevPlugin.test.d.ts.map +1 -0
- package/types/vite/replaceLoader.d.ts +2 -1
- package/types/vite/replaceLoader.d.ts.map +1 -1
- package/dist/cjs/headless/devHeadlessNote.cjs +0 -34
- package/dist/cjs/headless/devHeadlessNote.native.js +0 -37
- package/dist/cjs/headless/devHeadlessNote.native.js.map +0 -1
- package/dist/esm/headless/devHeadlessNote.mjs +0 -9
- package/dist/esm/headless/devHeadlessNote.mjs.map +0 -1
- package/dist/esm/headless/devHeadlessNote.native.js +0 -9
- package/dist/esm/headless/devHeadlessNote.native.js.map +0 -1
- package/src/headless/devHeadlessNote.ts +0 -13
- package/types/headless/devHeadlessNote.d.ts +0 -2
- package/types/headless/devHeadlessNote.d.ts.map +0 -1
|
@@ -7,7 +7,7 @@ import type { Connect, Plugin, ViteDevServer } from 'vite'
|
|
|
7
7
|
import { createServerModuleRunner, normalizePath } from 'vite'
|
|
8
8
|
import type { ModuleRunner } from 'vite/module-runner'
|
|
9
9
|
import { getSpaHeaderElements } from '../../constants'
|
|
10
|
-
import { createHandleRequest } from '../../
|
|
10
|
+
import { createHandleRequest } from '../../createDevHandleRequest'
|
|
11
11
|
import type { RouteNode } from '../../router/Route' // used for type in runLoaderWithTracking
|
|
12
12
|
import type { RenderAppProps } from '../../types'
|
|
13
13
|
import { getPageExport } from '../../utils/getPageExport'
|
|
@@ -42,9 +42,6 @@ const routeTypeColors: Record<string, (s: string) => string> = {
|
|
|
42
42
|
api: colors.magenta,
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
// server needs better dep optimization
|
|
46
|
-
const USE_SERVER_ENV = false //!!process.env.USE_SERVER_ENV
|
|
47
|
-
|
|
48
45
|
export function createFileSystemRouterPlugin(
|
|
49
46
|
options: One.PluginOptions,
|
|
50
47
|
routeIndex: RouteIndex
|
|
@@ -615,6 +612,11 @@ export function createFileSystemRouterPlugin(
|
|
|
615
612
|
handleRequest = createRequestHandler()
|
|
616
613
|
ssgHtmlCache.clear()
|
|
617
614
|
needsRouteRefresh = true
|
|
615
|
+
const workerGraph = server?.environments.worker?.moduleGraph
|
|
616
|
+
const workerEntry = workerGraph?.getModuleById('\0virtual:one-workerd-dev-entry')
|
|
617
|
+
if (workerGraph && workerEntry) {
|
|
618
|
+
workerGraph.invalidateModule(workerEntry)
|
|
619
|
+
}
|
|
618
620
|
} catch (error) {
|
|
619
621
|
console.warn(`[one] Failed to rebuild routes after ${changedPath} changed.`, error)
|
|
620
622
|
}
|
|
@@ -708,10 +710,14 @@ export function createFileSystemRouterPlugin(
|
|
|
708
710
|
preloads = ['/bundledDevClient.mjs', '/assets/_virtual_one-entry.js']
|
|
709
711
|
}
|
|
710
712
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
)
|
|
713
|
+
const workerDev = !!server.environments.worker
|
|
714
|
+
|
|
715
|
+
// workerd-backed worker env handles web requests via @cloudflare/vite-plugin
|
|
716
|
+
// middleware (node req/res <-> fetch). the node module runner is only for
|
|
717
|
+
// the default (flag off) path.
|
|
718
|
+
if (!workerDev) {
|
|
719
|
+
runner = createServerModuleRunner(server.environments.ssr)
|
|
720
|
+
}
|
|
715
721
|
|
|
716
722
|
const appDir = path.resolve(process.cwd(), getRouterRootFromOneOptions(options))
|
|
717
723
|
|
|
@@ -762,6 +768,12 @@ export function createFileSystemRouterPlugin(
|
|
|
762
768
|
// Vite's transform middleware so that we can focus on handling the requests
|
|
763
769
|
// we're interested in.
|
|
764
770
|
return () => {
|
|
771
|
+
if (workerDev) {
|
|
772
|
+
// @cloudflare/vite-plugin already dispatches the request into workerd.
|
|
773
|
+
// do not run the node handler alongside it.
|
|
774
|
+
return
|
|
775
|
+
}
|
|
776
|
+
|
|
765
777
|
// packager status fallback — runs after one's routing so user-defined
|
|
766
778
|
// /status routes, +api handlers, and custom middleware take priority.
|
|
767
779
|
// only fires if nothing else handled the request.
|
|
@@ -194,6 +194,19 @@ export const registerPreloadedRoute = () => {}`
|
|
|
194
194
|
expect(code).not.toContain('__oneGetSetupPromise')
|
|
195
195
|
})
|
|
196
196
|
|
|
197
|
+
it('worker environment uses the server setupFile like ssr', () => {
|
|
198
|
+
const plugin = createVirtualEntry({
|
|
199
|
+
...base,
|
|
200
|
+
setupFile: {
|
|
201
|
+
client: './src/setupClient.ts',
|
|
202
|
+
server: './src/setupServer.ts',
|
|
203
|
+
},
|
|
204
|
+
})
|
|
205
|
+
const code = loadEntry(plugin, 'worker', 'serve')
|
|
206
|
+
expect(code).toContain('import "./src/setupServer.ts"')
|
|
207
|
+
expect(code).not.toContain('__oneGetSetupPromise')
|
|
208
|
+
})
|
|
209
|
+
|
|
197
210
|
it('no setupFile produces no import', () => {
|
|
198
211
|
const plugin = createVirtualEntry(base)
|
|
199
212
|
const code = loadEntry(plugin, 'ssr')
|
|
@@ -88,6 +88,7 @@ function getSetupFileImport(
|
|
|
88
88
|
const envMap: Record<string, keyof NormalizedSetupFiles> = {
|
|
89
89
|
client: 'client',
|
|
90
90
|
ssr: 'server',
|
|
91
|
+
worker: 'server',
|
|
91
92
|
ios: 'ios',
|
|
92
93
|
android: 'android',
|
|
93
94
|
}
|
|
@@ -170,7 +171,8 @@ export function createVirtualEntry(options: {
|
|
|
170
171
|
handler(id) {
|
|
171
172
|
if (id === resolvedVirtualEntryId) {
|
|
172
173
|
const isNative = isNativeEnvironment(this.environment)
|
|
173
|
-
const isSSR =
|
|
174
|
+
const isSSR =
|
|
175
|
+
this.environment.name === 'ssr' || this.environment.name === 'worker'
|
|
174
176
|
const serverSpaRouteFiles = isSSR
|
|
175
177
|
? options.routeIndex
|
|
176
178
|
.getPaths()
|
|
@@ -209,12 +211,12 @@ export function createVirtualEntry(options: {
|
|
|
209
211
|
const serverSpaBuildGlobs = serverSpaRouteFiles.map(
|
|
210
212
|
(file) => `/${options.root}/${file}`
|
|
211
213
|
)
|
|
214
|
+
const serverSpaExportGlob = (name: string) =>
|
|
215
|
+
` ${name}: import.meta.glob(${JSON.stringify(serverSpaBuildGlobs)}, { exhaustive: true, import: '${name}', query: '?one-spa-build' })`
|
|
212
216
|
const serverSpaBuildRoutes = serverSpaBuildGlobs.length
|
|
213
|
-
? `{
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
sitemap: import.meta.glob(${JSON.stringify(serverSpaBuildGlobs)}, { exhaustive: true, import: 'sitemap', query: '?one-spa-build' })
|
|
217
|
-
}`
|
|
217
|
+
? `{\n${['loader', 'loaderCache', 'generateStaticParams', 'sitemap']
|
|
218
|
+
.map(serverSpaExportGlob)
|
|
219
|
+
.join(',\n')}\n}`
|
|
218
220
|
: '{}'
|
|
219
221
|
const webRouteGlobs = [
|
|
220
222
|
...routeGlobs,
|
|
@@ -299,9 +301,11 @@ if (typeof window !== 'undefined') {
|
|
|
299
301
|
window.__oneRegisterPreloadedRoute = registerPreloadedRoute
|
|
300
302
|
}
|
|
301
303
|
|
|
302
|
-
//
|
|
303
|
-
//
|
|
304
|
-
export
|
|
304
|
+
// a route that declares spa by filename or parent directory is stubbed out of
|
|
305
|
+
// the route map below so the server never holds its page component. its
|
|
306
|
+
// server-side exports come from here instead, one glob per export so the page
|
|
307
|
+
// never comes with them.
|
|
308
|
+
export const oneServerSpaRouteExports = ${serverSpaBuildRoutes}
|
|
305
309
|
|
|
306
310
|
// globbing ${JSON.stringify(webRouteGlobs)}
|
|
307
311
|
export default createApp({
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
5
|
+
import { generateWorkerdDevEntryModule } from './workerdDevPlugin'
|
|
6
|
+
|
|
7
|
+
let testDir: string | undefined
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
if (testDir) {
|
|
11
|
+
rmSync(testDir, { recursive: true, force: true })
|
|
12
|
+
testDir = undefined
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
describe('generateWorkerdDevEntryModule', () => {
|
|
17
|
+
it('emits createWorkerHandler wiring and lazy imports for pages and api routes', () => {
|
|
18
|
+
testDir = mkdtempSync(join(tmpdir(), 'one-workerd-entry-'))
|
|
19
|
+
const appDir = join(testDir, 'app')
|
|
20
|
+
mkdirSync(join(appDir, 'api'), { recursive: true })
|
|
21
|
+
writeFileSync(
|
|
22
|
+
join(appDir, 'ssr-page+ssr.tsx'),
|
|
23
|
+
'export default function Page() { return null }\n'
|
|
24
|
+
)
|
|
25
|
+
writeFileSync(
|
|
26
|
+
join(appDir, 'api', 'hello+api.ts'),
|
|
27
|
+
'export function GET() { return new Response("ok") }\n'
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const code = generateWorkerdDevEntryModule({
|
|
31
|
+
root: testDir,
|
|
32
|
+
options: { web: { defaultRenderMode: 'ssr' } },
|
|
33
|
+
routerRoot: 'app',
|
|
34
|
+
routePaths: ['./ssr-page+ssr.tsx', './api/hello+api.ts'],
|
|
35
|
+
preloads: ['/@vite/client'],
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
expect(code).toContain("from 'one/serve-worker'")
|
|
39
|
+
expect(code).toContain('disableModuleCache: true')
|
|
40
|
+
expect(code).toContain('serverEntry: () => import("virtual:one-entry")')
|
|
41
|
+
expect(code).toContain('/api/hello')
|
|
42
|
+
expect(code).toContain('ssr-page+ssr.tsx')
|
|
43
|
+
})
|
|
44
|
+
})
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { join, resolve } from 'node:path'
|
|
3
|
+
import { pathToFileURL } from 'node:url'
|
|
4
|
+
import { resolvePath } from '@vxrn/resolve'
|
|
5
|
+
import { cloudflare } from '@cloudflare/vite-plugin'
|
|
6
|
+
import { getPlatformEnvDefine } from '@vxrn/vite-plugin-metro'
|
|
7
|
+
import { exactRegex } from 'rolldown/filter'
|
|
8
|
+
import { type Plugin, type PluginOption } from 'vite'
|
|
9
|
+
import { CACHE_KEY } from '../../constants'
|
|
10
|
+
import { virtalEntryIdClient, virtualEntryId } from './virtualEntryConstants'
|
|
11
|
+
import { getManifest } from '../getManifest'
|
|
12
|
+
import { getRouterRootFromOneOptions } from '../../utils/getRouterRootFromOneOptions'
|
|
13
|
+
import type { RouteIndex } from '../../utils/routeIndex'
|
|
14
|
+
import type { One, RouteInfo } from '../types'
|
|
15
|
+
import {
|
|
16
|
+
createCloudflareWranglerConfig,
|
|
17
|
+
getCloudflareProjectNameSync,
|
|
18
|
+
loadUserWranglerConfigSync,
|
|
19
|
+
shouldEnableWorkerdDev,
|
|
20
|
+
} from '../cloudflareWranglerConfig'
|
|
21
|
+
|
|
22
|
+
export { shouldEnableWorkerdDev }
|
|
23
|
+
|
|
24
|
+
export const workerdDevEntryId = 'virtual:one-workerd-dev-entry'
|
|
25
|
+
const resolvedWorkerdDevEntryId = `\0${workerdDevEntryId}`
|
|
26
|
+
|
|
27
|
+
const WORKERD_DEV_DIR = 'node_modules/.one-workerd-dev'
|
|
28
|
+
|
|
29
|
+
function serveOnly(plugin: Plugin): Plugin {
|
|
30
|
+
const existing = plugin.apply
|
|
31
|
+
return {
|
|
32
|
+
...plugin,
|
|
33
|
+
apply(config, env) {
|
|
34
|
+
if (env.command !== 'serve') return false
|
|
35
|
+
if (typeof existing === 'function') return existing(config, env)
|
|
36
|
+
if (existing === 'build') return false
|
|
37
|
+
return true
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function toImportHref(root: string, routerRoot: string, routeFile: string): string {
|
|
43
|
+
const rel = routeFile.replace(/^\.\//, '')
|
|
44
|
+
return pathToFileURL(resolve(root, routerRoot, rel)).href
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function serializeImportMap(entries: Array<[string, string]>): string {
|
|
48
|
+
return entries
|
|
49
|
+
.map(
|
|
50
|
+
([key, href]) => ` ${JSON.stringify(key)}: () => import(${JSON.stringify(href)})`
|
|
51
|
+
)
|
|
52
|
+
.join(',\n')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function stripRouteForWorker(route: RouteInfo): RouteInfo {
|
|
56
|
+
const { layouts, middlewares, ...rest } = route
|
|
57
|
+
return {
|
|
58
|
+
...rest,
|
|
59
|
+
// live-render SSG in dev the same way the node middleware does
|
|
60
|
+
type: route.type === 'ssg' ? 'ssr' : route.type,
|
|
61
|
+
layouts: layouts?.map((layout) => ({
|
|
62
|
+
contextKey: layout.contextKey,
|
|
63
|
+
})) as RouteInfo['layouts'],
|
|
64
|
+
middlewares: middlewares?.map((middleware) => ({
|
|
65
|
+
contextKey: middleware.contextKey,
|
|
66
|
+
})) as RouteInfo['middlewares'],
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function stubRouteBuildInfo(
|
|
71
|
+
route: RouteInfo,
|
|
72
|
+
preloads: string[]
|
|
73
|
+
): One.BuildInfo['routeToBuildInfo'][string] {
|
|
74
|
+
const pageType = route.type === 'ssg' ? 'ssr' : route.type
|
|
75
|
+
return {
|
|
76
|
+
type: pageType,
|
|
77
|
+
path: route.page,
|
|
78
|
+
routeFile: route.file,
|
|
79
|
+
middlewares: route.middlewares?.map((middleware) => middleware.contextKey) ?? [],
|
|
80
|
+
preloadPath: '',
|
|
81
|
+
cssPreloadPath: '',
|
|
82
|
+
loaderPath: '',
|
|
83
|
+
cleanPath: route.urlCleanPath || route.page,
|
|
84
|
+
htmlPath: '',
|
|
85
|
+
clientJsPath: '',
|
|
86
|
+
serverJsPath: '',
|
|
87
|
+
params: {},
|
|
88
|
+
preloads,
|
|
89
|
+
css: [],
|
|
90
|
+
layoutCSS: [],
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function generateWorkerdDevEntryModule(args: {
|
|
95
|
+
root: string
|
|
96
|
+
options: One.PluginOptions
|
|
97
|
+
routerRoot: string
|
|
98
|
+
routePaths: string[]
|
|
99
|
+
preloads: string[]
|
|
100
|
+
}): string {
|
|
101
|
+
const { root, options, routerRoot, routePaths, preloads } = args
|
|
102
|
+
const manifest = getManifest({
|
|
103
|
+
routerRoot: resolve(root, routerRoot),
|
|
104
|
+
ignoredRouteFiles: options.router?.ignoredRouteFiles,
|
|
105
|
+
routePaths,
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
if (!manifest) {
|
|
109
|
+
throw new Error('[one] workerd dev: no routes manifest')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const apiImports = new Map<string, string>()
|
|
113
|
+
const middlewareImports = new Map<string, string>()
|
|
114
|
+
const routeToBuildInfo: One.BuildInfo['routeToBuildInfo'] = {}
|
|
115
|
+
|
|
116
|
+
for (const route of manifest.pageRoutes) {
|
|
117
|
+
for (const middleware of route.middlewares || []) {
|
|
118
|
+
if (!middleware.contextKey || middlewareImports.has(middleware.contextKey)) continue
|
|
119
|
+
middlewareImports.set(
|
|
120
|
+
middleware.contextKey,
|
|
121
|
+
toImportHref(root, routerRoot, middleware.contextKey)
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
if (route.file) {
|
|
125
|
+
routeToBuildInfo[route.file] = stubRouteBuildInfo(route, preloads)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (const route of manifest.apiRoutes) {
|
|
130
|
+
if (route.file) {
|
|
131
|
+
apiImports.set(route.page, toImportHref(root, routerRoot, route.file))
|
|
132
|
+
}
|
|
133
|
+
for (const middleware of route.middlewares || []) {
|
|
134
|
+
if (!middleware.contextKey || middlewareImports.has(middleware.contextKey)) continue
|
|
135
|
+
middlewareImports.set(
|
|
136
|
+
middleware.contextKey,
|
|
137
|
+
toImportHref(root, routerRoot, middleware.contextKey)
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const pageRoutes = manifest.pageRoutes.map(stripRouteForWorker)
|
|
143
|
+
const apiRoutes = manifest.apiRoutes.map(stripRouteForWorker)
|
|
144
|
+
|
|
145
|
+
const buildInfo: One.BuildInfo = {
|
|
146
|
+
constants: { CACHE_KEY },
|
|
147
|
+
oneOptions: options,
|
|
148
|
+
routeToBuildInfo,
|
|
149
|
+
pathToRoute: {},
|
|
150
|
+
routeMap: {},
|
|
151
|
+
manifest: {
|
|
152
|
+
pageRoutes,
|
|
153
|
+
apiRoutes,
|
|
154
|
+
allRoutes: [...pageRoutes, ...apiRoutes],
|
|
155
|
+
},
|
|
156
|
+
preloads: Object.fromEntries(preloads.map((preload) => [preload, true])),
|
|
157
|
+
cssPreloads: {},
|
|
158
|
+
loaders: {},
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const spaPreloadScripts = preloads
|
|
162
|
+
.map((preload) => `<script type="module" src="${preload}"></script>`)
|
|
163
|
+
.join('')
|
|
164
|
+
|
|
165
|
+
return `if (typeof MessageChannel === 'undefined') {
|
|
166
|
+
globalThis.MessageChannel = class MessageChannel {
|
|
167
|
+
constructor() {
|
|
168
|
+
this.port1 = { postMessage: () => {}, onmessage: null, close: () => {} }
|
|
169
|
+
this.port2 = { postMessage: () => {}, onmessage: null, close: () => {} }
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
import { serve, setFetchStaticHtml } from 'one/serve-worker'
|
|
175
|
+
|
|
176
|
+
const lazyRoutes = {
|
|
177
|
+
serverEntry: () => import(${JSON.stringify(virtualEntryId)}),
|
|
178
|
+
api: {
|
|
179
|
+
${serializeImportMap([...apiImports])}
|
|
180
|
+
},
|
|
181
|
+
middlewares: {
|
|
182
|
+
${serializeImportMap([...middlewareImports])}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const buildInfo = ${JSON.stringify(buildInfo)}
|
|
187
|
+
|
|
188
|
+
let server
|
|
189
|
+
|
|
190
|
+
export default {
|
|
191
|
+
async fetch(request, env, ctx) {
|
|
192
|
+
const url = new URL(request.url)
|
|
193
|
+
const pathname = url.pathname
|
|
194
|
+
|
|
195
|
+
if (pathname === '/status' || pathname.startsWith('/status?')) {
|
|
196
|
+
return new Response('packager-status:running', {
|
|
197
|
+
headers: { 'content-type': 'text/plain' },
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!server) {
|
|
202
|
+
server = await serve(buildInfo, lazyRoutes, { disableModuleCache: true })
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (env && env.ASSETS) {
|
|
206
|
+
setFetchStaticHtml(async (path) => {
|
|
207
|
+
try {
|
|
208
|
+
const assetUrl = new URL(request.url)
|
|
209
|
+
assetUrl.pathname = path
|
|
210
|
+
const assetResponse = await env.ASSETS.fetch(new Request(assetUrl))
|
|
211
|
+
if (assetResponse && assetResponse.ok) {
|
|
212
|
+
return await assetResponse.text()
|
|
213
|
+
}
|
|
214
|
+
} catch {}
|
|
215
|
+
return null
|
|
216
|
+
})
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
const response = await server.fetch(request, env, ctx)
|
|
221
|
+
|
|
222
|
+
if (!response || response.status === 404) {
|
|
223
|
+
if (env && env.ASSETS) {
|
|
224
|
+
try {
|
|
225
|
+
const assetResponse = await env.ASSETS.fetch(request)
|
|
226
|
+
if (assetResponse && assetResponse.status !== 404) {
|
|
227
|
+
return assetResponse
|
|
228
|
+
}
|
|
229
|
+
} catch {}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!response) {
|
|
234
|
+
if (request.method === 'GET' || request.method === 'HEAD') {
|
|
235
|
+
return new Response(
|
|
236
|
+
'<!DOCTYPE html><html><head>' +
|
|
237
|
+
${JSON.stringify(spaPreloadScripts)} +
|
|
238
|
+
'</head></html>',
|
|
239
|
+
{ headers: { 'content-type': 'text/html' } }
|
|
240
|
+
)
|
|
241
|
+
}
|
|
242
|
+
return new Response('Not Found', { status: 404 })
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return response
|
|
246
|
+
} finally {
|
|
247
|
+
setFetchStaticHtml(null)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
`
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function createWorkerdDevPlugins(
|
|
255
|
+
options: One.PluginOptions,
|
|
256
|
+
root: string,
|
|
257
|
+
routeIndex: RouteIndex
|
|
258
|
+
): PluginOption[] {
|
|
259
|
+
if (!shouldEnableWorkerdDev(options.web?.deploy, root)) {
|
|
260
|
+
return []
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const cacheDir = join(root, WORKERD_DEV_DIR)
|
|
264
|
+
const wranglerInputPath = join(cacheDir, '_wrangler.input.jsonc')
|
|
265
|
+
const workerEntryPath = join(cacheDir, 'worker-entry.js')
|
|
266
|
+
|
|
267
|
+
mkdirSync(cacheDir, { recursive: true })
|
|
268
|
+
writeFileSync(
|
|
269
|
+
workerEntryPath,
|
|
270
|
+
`export { default } from ${JSON.stringify(workerdDevEntryId)}\n`
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
const userWranglerConfig = loadUserWranglerConfigSync(root)
|
|
274
|
+
const projectName = getCloudflareProjectNameSync(root)
|
|
275
|
+
const wranglerInputConfig = createCloudflareWranglerConfig(
|
|
276
|
+
projectName,
|
|
277
|
+
userWranglerConfig?.config
|
|
278
|
+
)
|
|
279
|
+
// wrangler resolves `main` relative to the config file, which lives in cacheDir
|
|
280
|
+
wranglerInputConfig.main = 'worker-entry.js'
|
|
281
|
+
writeFileSync(wranglerInputPath, `${JSON.stringify(wranglerInputConfig, null, 2)}\n`)
|
|
282
|
+
|
|
283
|
+
const preloads = options.web?.experimentalBundledDev
|
|
284
|
+
? ['/bundledDevClient.mjs', '/assets/_virtual_one-entry.js']
|
|
285
|
+
: ['/@vite/client', virtalEntryIdClient]
|
|
286
|
+
|
|
287
|
+
const empty = resolvePath('@vxrn/vite-plugin-metro/empty', root)
|
|
288
|
+
const rnWebPkg = resolvePath('react-native-web/package.json', root)
|
|
289
|
+
const rnWeb = resolvePath('react-native-web', root)
|
|
290
|
+
const safeArea = resolvePath('@vxrn/safe-area', root)
|
|
291
|
+
|
|
292
|
+
const preparePlugin: Plugin = {
|
|
293
|
+
name: 'one:workerd-dev-prepare',
|
|
294
|
+
apply: 'serve',
|
|
295
|
+
enforce: 'pre',
|
|
296
|
+
|
|
297
|
+
config() {
|
|
298
|
+
return {
|
|
299
|
+
environments: {
|
|
300
|
+
worker: {
|
|
301
|
+
define: {
|
|
302
|
+
...getPlatformEnvDefine('ssr'),
|
|
303
|
+
'process.env.TAMAGUI_IS_SERVER': JSON.stringify('1'),
|
|
304
|
+
'process.env.TAMAGUI_KEEP_THEMES': JSON.stringify('1'),
|
|
305
|
+
'process.env.ONE_CACHE_KEY': JSON.stringify(CACHE_KEY),
|
|
306
|
+
},
|
|
307
|
+
optimizeDeps: {
|
|
308
|
+
include: [
|
|
309
|
+
'react',
|
|
310
|
+
'react-dom',
|
|
311
|
+
'react-dom/client',
|
|
312
|
+
'react-dom/server.browser',
|
|
313
|
+
'react/jsx-runtime',
|
|
314
|
+
'react/jsx-dev-runtime',
|
|
315
|
+
],
|
|
316
|
+
},
|
|
317
|
+
build: {
|
|
318
|
+
rolldownOptions: {
|
|
319
|
+
shimMissingExports: true,
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
// environment resolve options have no alias field; match the production
|
|
328
|
+
// worker aliases with a worker-only resolveId (rolldown cannot parse RN Flow)
|
|
329
|
+
resolveId: {
|
|
330
|
+
filter: {
|
|
331
|
+
id: /^(react-native(\/|$)|react-native-safe-area-context$)/,
|
|
332
|
+
},
|
|
333
|
+
handler(source) {
|
|
334
|
+
if (this.environment.name !== 'worker') return
|
|
335
|
+
if (/^react-native\/Libraries\//.test(source)) return empty
|
|
336
|
+
if (source === 'react-native/package.json') return rnWebPkg
|
|
337
|
+
if (source === 'react-native') return rnWeb
|
|
338
|
+
if (source === 'react-native-safe-area-context') return safeArea
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
configureServer(server) {
|
|
343
|
+
if (!server.environments.worker) {
|
|
344
|
+
throw new Error(
|
|
345
|
+
'[one] ONE_EXPERIMENTAL_WORKER_DEV=1 is set but @cloudflare/vite-plugin did not register a "worker" environment. ' +
|
|
346
|
+
`Expected wrangler config at ${wranglerInputPath}.`
|
|
347
|
+
)
|
|
348
|
+
}
|
|
349
|
+
console.info(
|
|
350
|
+
'[one] experimental workerd dev enabled (ONE_EXPERIMENTAL_WORKER_DEV=1)'
|
|
351
|
+
)
|
|
352
|
+
},
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const virtualPlugin: Plugin = {
|
|
356
|
+
name: 'one:workerd-dev-entry',
|
|
357
|
+
apply: 'serve',
|
|
358
|
+
|
|
359
|
+
resolveId: {
|
|
360
|
+
filter: { id: exactRegex(workerdDevEntryId) },
|
|
361
|
+
handler(id) {
|
|
362
|
+
if (this.environment.name !== 'worker') return
|
|
363
|
+
if (id === workerdDevEntryId) return resolvedWorkerdDevEntryId
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
|
|
367
|
+
load: {
|
|
368
|
+
filter: { id: exactRegex(resolvedWorkerdDevEntryId) },
|
|
369
|
+
handler() {
|
|
370
|
+
if (this.environment.name !== 'worker') return
|
|
371
|
+
return generateWorkerdDevEntryModule({
|
|
372
|
+
root,
|
|
373
|
+
options,
|
|
374
|
+
routerRoot: getRouterRootFromOneOptions(options),
|
|
375
|
+
routePaths: routeIndex.getPaths(),
|
|
376
|
+
preloads,
|
|
377
|
+
})
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
hotUpdate({ file }) {
|
|
382
|
+
if (this.environment.name !== 'worker') return
|
|
383
|
+
const graph = this.environment.moduleGraph
|
|
384
|
+
const entry = graph.getModuleById(resolvedWorkerdDevEntryId)
|
|
385
|
+
if (!entry) return
|
|
386
|
+
const modules = graph.getModulesByFile(file)
|
|
387
|
+
if (!modules?.size) return
|
|
388
|
+
graph.invalidateModule(entry)
|
|
389
|
+
},
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const cloudflarePlugins = cloudflare({
|
|
393
|
+
configPath: wranglerInputPath,
|
|
394
|
+
viteEnvironment: { name: 'worker' },
|
|
395
|
+
}).map(serveOnly)
|
|
396
|
+
|
|
397
|
+
return [preparePlugin, virtualPlugin, ...cloudflarePlugins]
|
|
398
|
+
}
|
|
@@ -4,12 +4,19 @@
|
|
|
4
4
|
// minified (rolldown): return`./loader-refetch/index.tsx`
|
|
5
5
|
const routeIdReturnRegex = /return\s*["'`]\.\/[^"'`]+["'`]/
|
|
6
6
|
|
|
7
|
+
// a chunk can hold more than one route's stub once the bundler merges routes,
|
|
8
|
+
// so target this route's own id when we know it rather than the first stub
|
|
9
|
+
const routeIdReturnRegexFor = (routeId: string) =>
|
|
10
|
+
new RegExp(`return\\s*["'\`]${routeId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}["'\`]`)
|
|
11
|
+
|
|
7
12
|
export function replaceLoader({
|
|
8
13
|
code,
|
|
9
14
|
loaderData,
|
|
15
|
+
routeId,
|
|
10
16
|
}: {
|
|
11
17
|
code: string
|
|
12
18
|
loaderData: object
|
|
19
|
+
routeId?: string
|
|
13
20
|
}) {
|
|
14
21
|
const stringifiedData = JSON.stringify(loaderData)
|
|
15
22
|
const safeData = stringifiedData.replace(/\$/g, '$$$$')
|
|
@@ -28,8 +35,9 @@ export function replaceLoader({
|
|
|
28
35
|
|
|
29
36
|
// new-style routeId stub from clientTreeShakePlugin
|
|
30
37
|
// works with both minified (return"./path") and non-minified (return "./path") code
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
const stubRegex = routeId ? routeIdReturnRegexFor(routeId) : routeIdReturnRegex
|
|
39
|
+
if (stubRegex.test(code)) {
|
|
40
|
+
return code.replace(stubRegex, 'return ' + safeData)
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
return code + `\nexport const loader = () => (${stringifiedData})`
|
package/types/cli/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AA2LA,wBAAsB,KAAK,CAAC,IAAI,EAAE;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAA;IACpC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,iBAkzCA"}
|
package/types/cli/buildPage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { One, RouteInfo } from '../vite/types';
|
|
2
2
|
export declare function printBuildTimings(): void;
|
|
3
|
-
export declare function buildPage(serverEntry: string, path: string, relativeId: string, params: any, foundRoute: RouteInfo<string>, clientManifestEntry: any, staticDir: string, clientDir: string, builtMiddlewares: Record<string, string>, serverJsPath: string, preloads: string[], allCSS: string[], layoutCSS: string[], routePreloads: Record<string, string>, allCSSContents?: string[], criticalPreloads?: string[], deferredPreloads?: string[], useAfterLCP?: boolean, useAfterLCPAggressive?: boolean): Promise<One.RouteBuildInfo>;
|
|
3
|
+
export declare function buildPage(serverEntry: string, routerRoot: string, path: string, relativeId: string, params: any, foundRoute: RouteInfo<string>, clientManifestEntry: any, staticDir: string, clientDir: string, builtMiddlewares: Record<string, string>, serverJsPath: string, preloads: string[], allCSS: string[], layoutCSS: string[], routePreloads: Record<string, string>, allCSSContents?: string[], criticalPreloads?: string[], deferredPreloads?: string[], useAfterLCP?: boolean, useAfterLCPAggressive?: boolean): Promise<One.RouteBuildInfo>;
|
|
4
4
|
//# sourceMappingURL=buildPage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildPage.d.ts","sourceRoot":"","sources":["../../src/cli/buildPage.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"buildPage.d.ts","sourceRoot":"","sources":["../../src/cli/buildPage.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAmBnD,wBAAgB,iBAAiB,SAUhC;AAED,wBAAsB,SAAS,CAC7B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,GAAG,EACX,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,EAC7B,mBAAmB,EAAE,GAAG,EACxB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACxC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAAE,EAClB,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,EAAE,MAAM,EAAE,EACnB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACrC,cAAc,CAAC,EAAE,MAAM,EAAE,EACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAC3B,WAAW,CAAC,EAAE,OAAO,EACrB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAkb7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverRouteModules.d.ts","sourceRoot":"","sources":["../../src/cli/serverRouteModules.ts"],"names":[],"mappings":"AAeA,wBAAsB,eAAe,CACnC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAa9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerPool.d.ts","sourceRoot":"","sources":["../../src/cli/workerPool.ts"],"names":[],"mappings":"AAiBA,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,SAAS,CAAgD;IACjE,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,UAAU,CAAI;IACtB,OAAO,CAAC,SAAS,CAAI;IACrB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,mBAAmB,CAAa;IACxC,OAAO,CAAC,WAAW,CAAQ;gBAEf,IAAI,SAAiC;IAkDjD,IAAI,IAAI,WAEP;IAGK,UAAU,CAAC,UAAU,CAAC,EAAE,GAAG;IAUjC,OAAO,CAAC,QAAQ;IASV,SAAS,CAAC,IAAI,EAAE;QACpB,WAAW,EAAE,MAAM,CAAA;QACnB,IAAI,EAAE,MAAM,CAAA;QACZ,UAAU,EAAE,MAAM,CAAA;QAClB,MAAM,EAAE,GAAG,CAAA;QACX,UAAU,EAAE,GAAG,CAAA;QACf,mBAAmB,EAAE,GAAG,CAAA;QACxB,SAAS,EAAE,MAAM,CAAA;QACjB,SAAS,EAAE,MAAM,CAAA;QACjB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACxC,YAAY,EAAE,MAAM,CAAA;QACpB,QAAQ,EAAE,MAAM,EAAE,CAAA;QAClB,MAAM,EAAE,MAAM,EAAE,CAAA;QAChB,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACrC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;QACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;QAC3B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;QAC3B,WAAW,CAAC,EAAE,OAAO,CAAA;QACrB,qBAAqB,CAAC,EAAE,OAAO,CAAA;KAChC,GAAG,OAAO,CAAC,GAAG,CAAC;IAuCV,SAAS;CAMhB;AAKD,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CAK5D;AAED,wBAAsB,mBAAmB,kBAKxC"}
|
|
1
|
+
{"version":3,"file":"workerPool.d.ts","sourceRoot":"","sources":["../../src/cli/workerPool.ts"],"names":[],"mappings":"AAiBA,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,SAAS,CAAgD;IACjE,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,UAAU,CAAI;IACtB,OAAO,CAAC,SAAS,CAAI;IACrB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,mBAAmB,CAAa;IACxC,OAAO,CAAC,WAAW,CAAQ;gBAEf,IAAI,SAAiC;IAkDjD,IAAI,IAAI,WAEP;IAGK,UAAU,CAAC,UAAU,CAAC,EAAE,GAAG;IAUjC,OAAO,CAAC,QAAQ;IASV,SAAS,CAAC,IAAI,EAAE;QACpB,WAAW,EAAE,MAAM,CAAA;QACnB,UAAU,EAAE,MAAM,CAAA;QAClB,IAAI,EAAE,MAAM,CAAA;QACZ,UAAU,EAAE,MAAM,CAAA;QAClB,MAAM,EAAE,GAAG,CAAA;QACX,UAAU,EAAE,GAAG,CAAA;QACf,mBAAmB,EAAE,GAAG,CAAA;QACxB,SAAS,EAAE,MAAM,CAAA;QACjB,SAAS,EAAE,MAAM,CAAA;QACjB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACxC,YAAY,EAAE,MAAM,CAAA;QACpB,QAAQ,EAAE,MAAM,EAAE,CAAA;QAClB,MAAM,EAAE,MAAM,EAAE,CAAA;QAChB,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACrC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;QACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;QAC3B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;QAC3B,WAAW,CAAC,EAAE,OAAO,CAAA;QACrB,qBAAqB,CAAC,EAAE,OAAO,CAAA;KAChC,GAAG,OAAO,CAAC,GAAG,CAAC;IAuCV,SAAS;CAMhB;AAKD,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CAK5D;AAED,wBAAsB,mBAAmB,kBAKxC"}
|
package/types/createApp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApp.d.ts","sourceRoot":"","sources":["../src/createApp.tsx"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAA;AAWhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAMzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAEvC,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;IAC9C,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,GAAG,CAAC,KAAK,CAAA;IACjB,OAAO,CAAC,EAAE,gBAAgB,CAAA;IAC1B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;CACzC,CAAA;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,cAAc;;oBAUrB,cAAc;0BAwGR,cAAc,KAAG,OAAO,CAAC,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"createApp.d.ts","sourceRoot":"","sources":["../src/createApp.tsx"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAA;AAWhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAMzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAEvC,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;IAC9C,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,GAAG,CAAC,KAAK,CAAA;IACjB,OAAO,CAAC,EAAE,gBAAgB,CAAA;IAC1B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;CACzC,CAAA;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,cAAc;;oBAUrB,cAAc;0BAwGR,cAAc,KAAG,OAAO,CAAC,cAAc,CAAC;EAyJzE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RequestHandlerResponse, type RequestHandlers } from './createHandleRequest';
|
|
2
|
+
export declare function createHandleRequest(handlers: RequestHandlers, { routerRoot, ignoredRouteFiles, routePaths, }: {
|
|
3
|
+
routerRoot: string;
|
|
4
|
+
ignoredRouteFiles?: string[];
|
|
5
|
+
routePaths?: string[];
|
|
6
|
+
}): {
|
|
7
|
+
manifest: import("./server/createRoutesManifest").RoutesManifest<string>;
|
|
8
|
+
handler: (request: Request) => Promise<RequestHandlerResponse>;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=createDevHandleRequest.d.ts.map
|