devflare 1.0.0-next.5 → 1.0.0-next.50
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/LICENSE +21 -0
- package/LLM.md +17312 -2139
- package/README.md +394 -605
- package/bin/devflare.js +30 -14
- package/dist/_chunks/account-BI3WZMDy.js +462 -0
- package/dist/_chunks/account-resources-CsmVowJp.js +159 -0
- package/dist/_chunks/ai-CBEuLdoP.js +322 -0
- package/dist/_chunks/api-TzdliH-6.js +568 -0
- package/dist/_chunks/build-artifacts-DU5V0J0Z.js +483 -0
- package/dist/_chunks/build-e0KR38-4.js +24 -0
- package/dist/_chunks/cli-DuUz10Mn.js +1163 -0
- package/dist/_chunks/cloudflare-BaloqI3H.js +157 -0
- package/dist/_chunks/colors-DiK6wPJ5.js +13 -0
- package/dist/_chunks/command-utils-DA0Qx9_K.js +45 -0
- package/dist/_chunks/compiler-Zw16C9Pi.js +489 -0
- package/dist/_chunks/config-Brju62xy.js +78 -0
- package/dist/_chunks/config-path-DaL1ylZ_.js +42 -0
- package/dist/_chunks/context-CX50Y2Kb.js +2250 -0
- package/dist/_chunks/decorators-QmV57ixr.js +19 -0
- package/dist/_chunks/dependencies-C2oxFjU_.js +57 -0
- package/dist/_chunks/deploy-B-Kku1Vk.js +1032 -0
- package/dist/_chunks/dev-D4e_RRZn.js +3471 -0
- package/dist/_chunks/doctor-jm_K4dxL.js +219 -0
- package/dist/_chunks/durable-object-DMtH0XYX.js +234 -0
- package/dist/_chunks/env-S0_nMVz1.js +125 -0
- package/dist/_chunks/family-_9-mGSfO.js +143 -0
- package/dist/_chunks/generated-artifacts-dMJY4KAt.js +32 -0
- package/dist/_chunks/glob-CmQOvunB.js +56 -0
- package/dist/_chunks/init-DnkJOmpW.js +165 -0
- package/dist/_chunks/loader-Cr0_OWPy.js +1288 -0
- package/dist/_chunks/local-dev-vars-CTSa-wvF.js +81 -0
- package/dist/_chunks/local-hyperdrive-CJ90j46O.js +119 -0
- package/dist/_chunks/local-media-bindings-DsAW4AMF.js +335 -0
- package/dist/_chunks/local-secrets-DMPkmOn3.js +123 -0
- package/dist/_chunks/local-workflow-entrypoints-Cq_WJajd.js +90 -0
- package/dist/_chunks/login-FjTAAQbi.js +51 -0
- package/dist/_chunks/package-metadata-DjHBLB-z.js +39 -0
- package/dist/_chunks/preferences-BKp_7XJx.js +241 -0
- package/dist/_chunks/preview-C3Cdr8an.js +462 -0
- package/dist/_chunks/preview-registry-ClAbLTHH.js +1186 -0
- package/dist/_chunks/preview-resources-CGMBjsYB.js +359 -0
- package/dist/_chunks/previews-C7hs9-BT.js +1134 -0
- package/dist/_chunks/productions-T9Als4fE.js +411 -0
- package/dist/_chunks/ref-CYJNAAe_.js +178 -0
- package/dist/_chunks/remote-CZnP-HLJ.js +79 -0
- package/dist/_chunks/remote-config-D39BY9ji.js +132 -0
- package/dist/_chunks/resolve-package-qizBfCIm.js +152 -0
- package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
- package/dist/_chunks/routes-BFYCqHb-.js +833 -0
- package/dist/_chunks/runtime-DL-Nz3k8.js +550 -0
- package/dist/_chunks/schema-normalization-BCwTLTGp.js +660 -0
- package/dist/_chunks/secrets-DIpJGe6C.js +95 -0
- package/dist/_chunks/tail-IY-ijYmv.js +239 -0
- package/dist/_chunks/token-Dmi0KXyX.js +333 -0
- package/dist/_chunks/tokens-iVcgNXi-.js +221 -0
- package/dist/_chunks/types-DoKsMYfm.js +484 -0
- package/dist/_chunks/ui-BUoZApvE.js +103 -0
- package/dist/_chunks/usage-BBTGzjon.js +272 -0
- package/dist/_chunks/vite-CGtVNf5E.js +1267 -0
- package/dist/_chunks/vite-utils-OVLMV605.js +183 -0
- package/dist/_chunks/worker-BEZI4od1.js +410 -0
- package/dist/_chunks/worker-bundler-dTTnYU3n.js +458 -0
- package/dist/_chunks/worker-entrypoint-CQW77lG8.js +247 -0
- package/dist/_chunks/workerName-CFJsLZA-.js +23 -0
- package/dist/bridge/client.d.ts +49 -7
- package/dist/bridge/client.d.ts.map +1 -1
- package/dist/bridge/gateway-runtime.d.ts +8 -0
- package/dist/bridge/gateway-runtime.d.ts.map +1 -0
- package/dist/bridge/index.d.ts +6 -6
- package/dist/bridge/index.d.ts.map +1 -1
- package/dist/bridge/log.d.ts +5 -0
- package/dist/bridge/log.d.ts.map +1 -0
- package/dist/bridge/miniflare.d.ts +82 -2
- package/dist/bridge/miniflare.d.ts.map +1 -1
- package/dist/bridge/proxy.d.ts +12 -11
- package/dist/bridge/proxy.d.ts.map +1 -1
- package/dist/bridge/server.d.ts +2 -1
- package/dist/bridge/server.d.ts.map +1 -1
- package/dist/bridge/v2/body-streams.d.ts +53 -0
- package/dist/bridge/v2/body-streams.d.ts.map +1 -0
- package/dist/bridge/v2/codec.d.ts +106 -0
- package/dist/bridge/v2/codec.d.ts.map +1 -0
- package/dist/bridge/v2/control-messages.d.ts +46 -0
- package/dist/bridge/v2/control-messages.d.ts.map +1 -0
- package/dist/bridge/v2/frames.d.ts +109 -0
- package/dist/bridge/v2/frames.d.ts.map +1 -0
- package/dist/bridge/v2/index.d.ts +11 -0
- package/dist/bridge/v2/index.d.ts.map +1 -0
- package/dist/bridge/v2/serialization.d.ts +48 -0
- package/dist/bridge/v2/serialization.d.ts.map +1 -0
- package/dist/bridge/v2/transport.d.ts +31 -0
- package/dist/bridge/v2/transport.d.ts.map +1 -0
- package/dist/bridge/v2/value-codec.d.ts +61 -0
- package/dist/bridge/v2/value-codec.d.ts.map +1 -0
- package/dist/bridge/{serialization.d.ts → v2/value-serialization.d.ts} +40 -18
- package/dist/bridge/v2/value-serialization.d.ts.map +1 -0
- package/dist/bridge/{protocol.d.ts → v2/wire.d.ts} +32 -8
- package/dist/bridge/v2/wire.d.ts.map +1 -0
- package/dist/bridge/v2/ws-relay.d.ts +53 -0
- package/dist/bridge/v2/ws-relay.d.ts.map +1 -0
- package/dist/browser-shim/handler.d.ts +2 -2
- package/dist/browser-shim/handler.d.ts.map +1 -1
- package/dist/browser-shim/index.d.ts +2 -2
- package/dist/browser-shim/server.d.ts +63 -0
- package/dist/browser-shim/server.d.ts.map +1 -1
- package/dist/browser.d.ts +5411 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +80 -0
- package/dist/bundler/defaults.d.ts +23 -0
- package/dist/bundler/defaults.d.ts.map +1 -0
- package/dist/bundler/do-bundler.d.ts +7 -0
- package/dist/bundler/do-bundler.d.ts.map +1 -1
- package/dist/bundler/index.d.ts +3 -1
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/rolldown-shared.d.ts +53 -0
- package/dist/bundler/rolldown-shared.d.ts.map +1 -0
- package/dist/bundler/worker-bundler.d.ts +13 -0
- package/dist/bundler/worker-bundler.d.ts.map +1 -0
- package/dist/bundler/worker-compat.d.ts +4 -0
- package/dist/bundler/worker-compat.d.ts.map +1 -0
- package/dist/cli/build-manifest.d.ts +66 -0
- package/dist/cli/build-manifest.d.ts.map +1 -0
- package/dist/cli/command-utils.d.ts +18 -0
- package/dist/cli/command-utils.d.ts.map +1 -0
- package/dist/cli/commands/account.d.ts +2 -2
- package/dist/cli/commands/account.d.ts.map +1 -1
- package/dist/cli/commands/ai.d.ts +1 -1
- package/dist/cli/commands/ai.d.ts.map +1 -1
- package/dist/cli/commands/build-artifacts.d.ts +40 -0
- package/dist/cli/commands/build-artifacts.d.ts.map +1 -0
- package/dist/cli/commands/build.d.ts +2 -2
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/config.d.ts +4 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/deploy/metadata.d.ts +18 -0
- package/dist/cli/commands/deploy/metadata.d.ts.map +1 -0
- package/dist/cli/commands/deploy/prepare.d.ts +23 -0
- package/dist/cli/commands/deploy/prepare.d.ts.map +1 -0
- package/dist/cli/commands/deploy/runtime.d.ts +4 -0
- package/dist/cli/commands/deploy/runtime.d.ts.map +1 -0
- package/dist/cli/commands/deploy/verification.d.ts +36 -0
- package/dist/cli/commands/deploy/verification.d.ts.map +1 -0
- package/dist/cli/commands/deploy.d.ts +2 -2
- package/dist/cli/commands/deploy.d.ts.map +1 -1
- package/dist/cli/commands/dev.d.ts +9 -1
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/doctor.d.ts +2 -2
- package/dist/cli/commands/doctor.d.ts.map +1 -1
- package/dist/cli/commands/init.d.ts +2 -2
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/login.d.ts +4 -0
- package/dist/cli/commands/login.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/cleanup.d.ts +9 -0
- package/dist/cli/commands/previews-support/cleanup.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/family.d.ts +10 -0
- package/dist/cli/commands/previews-support/family.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/render.d.ts +8 -0
- package/dist/cli/commands/previews-support/render.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/theme.d.ts +10 -0
- package/dist/cli/commands/previews-support/theme.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/types.d.ts +70 -0
- package/dist/cli/commands/previews-support/types.d.ts.map +1 -0
- package/dist/cli/commands/previews.d.ts +4 -0
- package/dist/cli/commands/previews.d.ts.map +1 -0
- package/dist/cli/commands/productions.d.ts +4 -0
- package/dist/cli/commands/productions.d.ts.map +1 -0
- package/dist/cli/commands/remote.d.ts +1 -1
- package/dist/cli/commands/remote.d.ts.map +1 -1
- package/dist/cli/commands/secrets.d.ts +4 -0
- package/dist/cli/commands/secrets.d.ts.map +1 -0
- package/dist/cli/commands/tail.d.ts +44 -0
- package/dist/cli/commands/tail.d.ts.map +1 -0
- package/dist/cli/commands/token.d.ts +4 -0
- package/dist/cli/commands/token.d.ts.map +1 -0
- package/dist/cli/commands/type-generation/discovery.d.ts +7 -0
- package/dist/cli/commands/type-generation/discovery.d.ts.map +1 -0
- package/dist/cli/commands/type-generation/generator.d.ts +121 -0
- package/dist/cli/commands/type-generation/generator.d.ts.map +1 -0
- package/dist/cli/commands/type-generation/models.d.ts +27 -0
- package/dist/cli/commands/type-generation/models.d.ts.map +1 -0
- package/dist/cli/commands/types.d.ts +2 -2
- package/dist/cli/commands/types.d.ts.map +1 -1
- package/dist/cli/commands/worker.d.ts +4 -0
- package/dist/cli/commands/worker.d.ts.map +1 -0
- package/dist/cli/config-path.d.ts +6 -0
- package/dist/cli/config-path.d.ts.map +1 -0
- package/dist/cli/dependencies.d.ts +2 -1
- package/dist/cli/dependencies.d.ts.map +1 -1
- package/dist/cli/deploy-strategy.d.ts +17 -0
- package/dist/cli/deploy-strategy.d.ts.map +1 -0
- package/dist/cli/deploy-target.d.ts +17 -0
- package/dist/cli/deploy-target.d.ts.map +1 -0
- package/dist/cli/generated-artifacts.d.ts +12 -0
- package/dist/cli/generated-artifacts.d.ts.map +1 -0
- package/dist/cli/gradual-deploy.d.ts +49 -0
- package/dist/cli/gradual-deploy.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/account.d.ts +3 -0
- package/dist/cli/help-pages/pages/account.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/core.d.ts +4 -0
- package/dist/cli/help-pages/pages/core.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/index.d.ts +3 -0
- package/dist/cli/help-pages/pages/index.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/misc.d.ts +3 -0
- package/dist/cli/help-pages/pages/misc.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/previews.d.ts +3 -0
- package/dist/cli/help-pages/pages/previews.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/productions.d.ts +3 -0
- package/dist/cli/help-pages/pages/productions.d.ts.map +1 -0
- package/dist/cli/help-pages/render.d.ts +12 -0
- package/dist/cli/help-pages/render.d.ts.map +1 -0
- package/dist/cli/help-pages/shared.d.ts +15 -0
- package/dist/cli/help-pages/shared.d.ts.map +1 -0
- package/dist/cli/help-pages/types.d.ts +23 -0
- package/dist/cli/help-pages/types.d.ts.map +1 -0
- package/dist/cli/help.d.ts +6 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/package-metadata.d.ts +16 -0
- package/dist/cli/package-metadata.d.ts.map +1 -0
- package/dist/cli/preview-bindings.d.ts +49 -0
- package/dist/cli/preview-bindings.d.ts.map +1 -0
- package/dist/cli/preview.d.ts +10 -0
- package/dist/cli/preview.d.ts.map +1 -0
- package/dist/cli/ui.d.ts +37 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/workspace-build-guard.d.ts +14 -0
- package/dist/cli/workspace-build-guard.d.ts.map +1 -0
- package/dist/cli/wrangler-auth.d.ts +1 -1
- package/dist/cloudflare/account-core.d.ts +6 -0
- package/dist/cloudflare/account-core.d.ts.map +1 -0
- package/dist/cloudflare/account-resources.d.ts +40 -0
- package/dist/cloudflare/account-resources.d.ts.map +1 -0
- package/dist/cloudflare/account-status.d.ts +11 -0
- package/dist/cloudflare/account-status.d.ts.map +1 -0
- package/dist/cloudflare/account-workers.d.ts +14 -0
- package/dist/cloudflare/account-workers.d.ts.map +1 -0
- package/dist/cloudflare/account.d.ts +7 -64
- package/dist/cloudflare/account.d.ts.map +1 -1
- package/dist/cloudflare/api.d.ts +71 -3
- package/dist/cloudflare/api.d.ts.map +1 -1
- package/dist/cloudflare/auth.d.ts +1 -1
- package/dist/cloudflare/auth.d.ts.map +1 -1
- package/dist/cloudflare/index.d.ts +61 -6
- package/dist/cloudflare/index.d.ts.map +1 -1
- package/dist/cloudflare/index.js +4 -13
- package/dist/cloudflare/known-permission-group-ids.generated.d.ts +10 -0
- package/dist/cloudflare/known-permission-group-ids.generated.d.ts.map +1 -0
- package/dist/cloudflare/kv-namespace.d.ts +4 -0
- package/dist/cloudflare/kv-namespace.d.ts.map +1 -0
- package/dist/cloudflare/preferences.d.ts +7 -0
- package/dist/cloudflare/preferences.d.ts.map +1 -1
- package/dist/cloudflare/preview-registry-cache.d.ts +6 -0
- package/dist/cloudflare/preview-registry-cache.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-inference.d.ts +14 -0
- package/dist/cloudflare/preview-registry-inference.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-records.d.ts +4 -0
- package/dist/cloudflare/preview-registry-records.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-shape.d.ts +47 -0
- package/dist/cloudflare/preview-registry-shape.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-store.d.ts +14 -0
- package/dist/cloudflare/preview-registry-store.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-transport.d.ts +4 -0
- package/dist/cloudflare/preview-registry-transport.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-types.d.ts +103 -0
- package/dist/cloudflare/preview-registry-types.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry.d.ts +42 -0
- package/dist/cloudflare/preview-registry.d.ts.map +1 -0
- package/dist/cloudflare/preview-urls.d.ts +3 -0
- package/dist/cloudflare/preview-urls.d.ts.map +1 -0
- package/dist/cloudflare/registry-schema.d.ts +253 -0
- package/dist/cloudflare/registry-schema.d.ts.map +1 -0
- package/dist/cloudflare/remote-config.d.ts.map +1 -1
- package/dist/cloudflare/tokens.d.ts +44 -0
- package/dist/cloudflare/tokens.d.ts.map +1 -0
- package/dist/cloudflare/types.d.ts +124 -7
- package/dist/cloudflare/types.d.ts.map +1 -1
- package/dist/cloudflare/usage.d.ts +31 -3
- package/dist/cloudflare/usage.d.ts.map +1 -1
- package/dist/config/binding-resolution-helpers.d.ts +41 -0
- package/dist/config/binding-resolution-helpers.d.ts.map +1 -0
- package/dist/config/compatibility.d.ts +3 -0
- package/dist/config/compatibility.d.ts.map +1 -0
- package/dist/config/compiler/bindings.d.ts +14 -0
- package/dist/config/compiler/bindings.d.ts.map +1 -0
- package/dist/config/compiler/core-helpers.d.ts +6 -0
- package/dist/config/compiler/core-helpers.d.ts.map +1 -0
- package/dist/config/compiler/do-workers.d.ts +34 -0
- package/dist/config/compiler/do-workers.d.ts.map +1 -0
- package/dist/config/compiler/paths.d.ts +18 -0
- package/dist/config/compiler/paths.d.ts.map +1 -0
- package/dist/config/compiler/types.d.ts +298 -0
- package/dist/config/compiler/types.d.ts.map +1 -0
- package/dist/config/compiler.d.ts +22 -134
- package/dist/config/compiler.d.ts.map +1 -1
- package/dist/config/cron.d.ts +19 -0
- package/dist/config/cron.d.ts.map +1 -0
- package/dist/config/define.d.ts +8 -5
- package/dist/config/define.d.ts.map +1 -1
- package/dist/config/deploy-resources.d.ts +58 -0
- package/dist/config/deploy-resources.d.ts.map +1 -0
- package/dist/config/env-vars.d.ts +309 -0
- package/dist/config/env-vars.d.ts.map +1 -0
- package/dist/config/framework-providers.d.ts +9 -0
- package/dist/config/framework-providers.d.ts.map +1 -0
- package/dist/config/index.d.ts +12 -5
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/loader.d.ts +2 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/local-dev-vars.d.ts +15 -0
- package/dist/config/local-dev-vars.d.ts.map +1 -0
- package/dist/config/preview-resources.d.ts +83 -0
- package/dist/config/preview-resources.d.ts.map +1 -0
- package/dist/config/preview.d.ts +29 -0
- package/dist/config/preview.d.ts.map +1 -0
- package/dist/config/ref.d.ts +16 -25
- package/dist/config/ref.d.ts.map +1 -1
- package/dist/config/resolve-phased.d.ts +72 -0
- package/dist/config/resolve-phased.d.ts.map +1 -0
- package/dist/config/resolve.d.ts +11 -0
- package/dist/config/resolve.d.ts.map +1 -0
- package/dist/config/resource-resolution.d.ts +80 -0
- package/dist/config/resource-resolution.d.ts.map +1 -0
- package/dist/config/schema-bindings.d.ts +2025 -0
- package/dist/config/schema-bindings.d.ts.map +1 -0
- package/dist/config/schema-build.d.ts +67 -0
- package/dist/config/schema-build.d.ts.map +1 -0
- package/dist/config/schema-env.d.ts +3579 -0
- package/dist/config/schema-env.d.ts.map +1 -0
- package/dist/config/schema-normalization.d.ts +265 -0
- package/dist/config/schema-normalization.d.ts.map +1 -0
- package/dist/config/schema-runtime.d.ts +508 -0
- package/dist/config/schema-runtime.d.ts.map +1 -0
- package/dist/config/schema-types-bindings-platform.d.ts +508 -0
- package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
- package/dist/config/schema-types-bindings-resources.d.ts +767 -0
- package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
- package/dist/config/schema-types-bindings.d.ts +293 -0
- package/dist/config/schema-types-bindings.d.ts.map +1 -0
- package/dist/config/schema-types-build.d.ts +86 -0
- package/dist/config/schema-types-build.d.ts.map +1 -0
- package/dist/config/schema-types-runtime.d.ts +917 -0
- package/dist/config/schema-types-runtime.d.ts.map +1 -0
- package/dist/config/schema-types.d.ts +424 -0
- package/dist/config/schema-types.d.ts.map +1 -0
- package/dist/config/schema.d.ts +5324 -2011
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/service-bindings-validation.d.ts +36 -0
- package/dist/config/service-bindings-validation.d.ts.map +1 -0
- package/dist/config-entry.d.ts +7 -0
- package/dist/config-entry.d.ts.map +1 -0
- package/dist/config-entry.js +3 -0
- package/dist/decorators/durable-object.d.ts.map +1 -1
- package/dist/decorators/index.d.ts +2 -2
- package/dist/decorators/index.js +2 -9
- package/dist/dev-server/d1-migrations.d.ts +36 -0
- package/dist/dev-server/d1-migrations.d.ts.map +1 -0
- package/dist/dev-server/dev-server-state.d.ts +59 -0
- package/dist/dev-server/dev-server-state.d.ts.map +1 -0
- package/dist/dev-server/gateway-script.d.ts +21 -0
- package/dist/dev-server/gateway-script.d.ts.map +1 -0
- package/dist/dev-server/index.d.ts +1 -1
- package/dist/dev-server/miniflare-bindings.d.ts +81 -0
- package/dist/dev-server/miniflare-bindings.d.ts.map +1 -0
- package/dist/dev-server/miniflare-dev-config.d.ts +36 -0
- package/dist/dev-server/miniflare-dev-config.d.ts.map +1 -0
- package/dist/dev-server/miniflare-log.d.ts +20 -0
- package/dist/dev-server/miniflare-log.d.ts.map +1 -0
- package/dist/dev-server/miniflare-worker-config.d.ts +82 -0
- package/dist/dev-server/miniflare-worker-config.d.ts.map +1 -0
- package/dist/dev-server/reload-queue.d.ts +13 -0
- package/dist/dev-server/reload-queue.d.ts.map +1 -0
- package/dist/dev-server/runtime-stdio.d.ts +8 -0
- package/dist/dev-server/runtime-stdio.d.ts.map +1 -0
- package/dist/dev-server/server-startup-helpers.d.ts +84 -0
- package/dist/dev-server/server-startup-helpers.d.ts.map +1 -0
- package/dist/dev-server/server.d.ts +2 -0
- package/dist/dev-server/server.d.ts.map +1 -1
- package/dist/dev-server/vite-process.d.ts +15 -0
- package/dist/dev-server/vite-process.d.ts.map +1 -0
- package/dist/dev-server/vite-utils.d.ts +19 -1
- package/dist/dev-server/vite-utils.d.ts.map +1 -1
- package/dist/dev-server/worker-source-watcher.d.ts +17 -0
- package/dist/dev-server/worker-source-watcher.d.ts.map +1 -0
- package/dist/dev-server/worker-surface-paths.d.ts +6 -0
- package/dist/dev-server/worker-surface-paths.d.ts.map +1 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/index.d.ts +8 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -298
- package/dist/runtime/context-events.d.ts +13 -0
- package/dist/runtime/context-events.d.ts.map +1 -0
- package/dist/runtime/context-types.d.ts +82 -0
- package/dist/runtime/context-types.d.ts.map +1 -0
- package/dist/runtime/context.d.ts +20 -44
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/exports.d.ts +70 -55
- package/dist/runtime/exports.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +10 -3
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +5 -111
- package/dist/runtime/middleware.d.ts +119 -67
- package/dist/runtime/middleware.d.ts.map +1 -1
- package/dist/runtime/router/index.d.ts +7 -0
- package/dist/runtime/router/index.d.ts.map +1 -0
- package/dist/runtime/router/types.d.ts +24 -0
- package/dist/runtime/router/types.d.ts.map +1 -0
- package/dist/runtime/validation.d.ts +18 -4
- package/dist/runtime/validation.d.ts.map +1 -1
- package/dist/secrets/local-secrets.d.ts +46 -0
- package/dist/secrets/local-secrets.d.ts.map +1 -0
- package/dist/shims/local-hyperdrive.d.ts +12 -0
- package/dist/shims/local-hyperdrive.d.ts.map +1 -0
- package/dist/shims/local-media-bindings.d.ts +19 -0
- package/dist/shims/local-media-bindings.d.ts.map +1 -0
- package/dist/shims/local-worker-loader.d.ts +3 -0
- package/dist/shims/local-worker-loader.d.ts.map +1 -0
- package/dist/sveltekit/index.d.ts +1 -1
- package/dist/sveltekit/index.d.ts.map +1 -1
- package/dist/sveltekit/index.js +313 -167
- package/dist/sveltekit/local-bindings.d.ts +4 -0
- package/dist/sveltekit/local-bindings.d.ts.map +1 -0
- package/dist/sveltekit/platform.d.ts +20 -2
- package/dist/sveltekit/platform.d.ts.map +1 -1
- package/dist/test/ai-search.d.ts +39 -0
- package/dist/test/ai-search.d.ts.map +1 -0
- package/dist/test/alarm.d.ts +55 -0
- package/dist/test/alarm.d.ts.map +1 -0
- package/dist/test/binding-hints.d.ts +10 -0
- package/dist/test/binding-hints.d.ts.map +1 -0
- package/dist/test/cf.d.ts +71 -35
- package/dist/test/cf.d.ts.map +1 -1
- package/dist/test/containers.d.ts +87 -0
- package/dist/test/containers.d.ts.map +1 -0
- package/dist/test/email.d.ts +16 -7
- package/dist/test/email.d.ts.map +1 -1
- package/dist/test/index.d.ts +20 -21
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +4971 -70
- package/dist/test/offline-bindings.d.ts +115 -0
- package/dist/test/offline-bindings.d.ts.map +1 -0
- package/dist/test/queue.d.ts.map +1 -1
- package/dist/test/remote-ai.d.ts.map +1 -1
- package/dist/test/remote-cloudflare.d.ts +13 -0
- package/dist/test/remote-cloudflare.d.ts.map +1 -0
- package/dist/test/remote-vectorize.d.ts.map +1 -1
- package/dist/test/resolve-service-bindings.d.ts +64 -4
- package/dist/test/resolve-service-bindings.d.ts.map +1 -1
- package/dist/test/scheduled.d.ts.map +1 -1
- package/dist/test/should-skip.d.ts +14 -18
- package/dist/test/should-skip.d.ts.map +1 -1
- package/dist/test/simple-context-bindings.d.ts +13 -0
- package/dist/test/simple-context-bindings.d.ts.map +1 -0
- package/dist/test/simple-context-durable-objects.d.ts +6 -0
- package/dist/test/simple-context-durable-objects.d.ts.map +1 -0
- package/dist/test/simple-context-env.d.ts +35 -0
- package/dist/test/simple-context-env.d.ts.map +1 -0
- package/dist/test/simple-context-gateway-script.d.ts +2 -0
- package/dist/test/simple-context-gateway-script.d.ts.map +1 -0
- package/dist/test/simple-context-handlers.d.ts +12 -0
- package/dist/test/simple-context-handlers.d.ts.map +1 -0
- package/dist/test/simple-context-lifecycle.d.ts +32 -0
- package/dist/test/simple-context-lifecycle.d.ts.map +1 -0
- package/dist/test/simple-context-mfconfig.d.ts +10 -0
- package/dist/test/simple-context-mfconfig.d.ts.map +1 -0
- package/dist/test/simple-context-multi-worker.d.ts +16 -0
- package/dist/test/simple-context-multi-worker.d.ts.map +1 -0
- package/dist/test/simple-context-paths.d.ts +40 -0
- package/dist/test/simple-context-paths.d.ts.map +1 -0
- package/dist/test/simple-context-runtime.d.ts +19 -0
- package/dist/test/simple-context-runtime.d.ts.map +1 -0
- package/dist/test/simple-context-startup.d.ts +11 -0
- package/dist/test/simple-context-startup.d.ts.map +1 -0
- package/dist/test/simple-context-transport.d.ts +14 -0
- package/dist/test/simple-context-transport.d.ts.map +1 -0
- package/dist/test/simple-context.d.ts +8 -27
- package/dist/test/simple-context.d.ts.map +1 -1
- package/dist/test/tail.d.ts +3 -2
- package/dist/test/tail.d.ts.map +1 -1
- package/dist/test/utilities/analytics-engine.d.ts +22 -0
- package/dist/test/utilities/analytics-engine.d.ts.map +1 -0
- package/dist/test/utilities/artifacts.d.ts +11 -0
- package/dist/test/utilities/artifacts.d.ts.map +1 -0
- package/dist/test/utilities/context.d.ts +39 -0
- package/dist/test/utilities/context.d.ts.map +1 -0
- package/dist/test/utilities/d1.d.ts +21 -0
- package/dist/test/utilities/d1.d.ts.map +1 -0
- package/dist/test/utilities/env.d.ts +43 -0
- package/dist/test/utilities/env.d.ts.map +1 -0
- package/dist/test/utilities/kv.d.ts +11 -0
- package/dist/test/utilities/kv.d.ts.map +1 -0
- package/dist/test/utilities/media.d.ts +16 -0
- package/dist/test/utilities/media.d.ts.map +1 -0
- package/dist/test/utilities/platform.d.ts +41 -0
- package/dist/test/utilities/platform.d.ts.map +1 -0
- package/dist/test/utilities/queue.d.ts +5 -0
- package/dist/test/utilities/queue.d.ts.map +1 -0
- package/dist/test/utilities/r2.d.ts +2 -0
- package/dist/test/utilities/r2.d.ts.map +1 -0
- package/dist/test/utilities/stream-flagship.d.ts +27 -0
- package/dist/test/utilities/stream-flagship.d.ts.map +1 -0
- package/dist/test/utilities/vectorize.d.ts +38 -0
- package/dist/test/utilities/vectorize.d.ts.map +1 -0
- package/dist/test/utilities/workflows.d.ts +26 -0
- package/dist/test/utilities/workflows.d.ts.map +1 -0
- package/dist/test/utilities.d.ts +13 -98
- package/dist/test/utilities.d.ts.map +1 -1
- package/dist/test/worker.d.ts +6 -0
- package/dist/test/worker.d.ts.map +1 -1
- package/dist/transform/durable-object.d.ts.map +1 -1
- package/dist/transform/index.d.ts +2 -2
- package/dist/transform/worker-entrypoint.d.ts +5 -0
- package/dist/transform/worker-entrypoint.d.ts.map +1 -1
- package/dist/utils/entrypoint-discovery.d.ts +6 -3
- package/dist/utils/entrypoint-discovery.d.ts.map +1 -1
- package/dist/utils/glob.d.ts.map +1 -1
- package/dist/utils/resolve-package.d.ts.map +1 -1
- package/dist/utils/send-email.d.ts +15 -0
- package/dist/utils/send-email.d.ts.map +1 -0
- package/dist/utils/send-email.js +163 -0
- package/dist/vite/config-file.d.ts +25 -0
- package/dist/vite/config-file.d.ts.map +1 -0
- package/dist/vite/index.d.ts +3 -2
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +2 -339
- package/dist/vite/plugin-config-hook.d.ts +28 -0
- package/dist/vite/plugin-config-hook.d.ts.map +1 -0
- package/dist/vite/plugin-context.d.ts +27 -0
- package/dist/vite/plugin-context.d.ts.map +1 -0
- package/dist/vite/plugin-durable-objects.d.ts +18 -0
- package/dist/vite/plugin-durable-objects.d.ts.map +1 -0
- package/dist/vite/plugin-programmatic.d.ts +44 -0
- package/dist/vite/plugin-programmatic.d.ts.map +1 -0
- package/dist/vite/plugin-service-bindings.d.ts +13 -0
- package/dist/vite/plugin-service-bindings.d.ts.map +1 -0
- package/dist/vite/plugin-transform.d.ts +41 -0
- package/dist/vite/plugin-transform.d.ts.map +1 -0
- package/dist/vite/plugin.d.ts +10 -41
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/worker-entry/composed-worker.d.ts +7 -0
- package/dist/worker-entry/composed-worker.d.ts.map +1 -0
- package/dist/worker-entry/durable-object-discovery.d.ts +20 -0
- package/dist/worker-entry/durable-object-discovery.d.ts.map +1 -0
- package/dist/worker-entry/extensions.d.ts +5 -0
- package/dist/worker-entry/extensions.d.ts.map +1 -0
- package/dist/worker-entry/routes.d.ts +22 -0
- package/dist/worker-entry/routes.d.ts.map +1 -0
- package/dist/worker-entry/surface-paths.d.ts +26 -0
- package/dist/worker-entry/surface-paths.d.ts.map +1 -0
- package/dist/worker-entry/validate-fetch-style.d.ts +12 -0
- package/dist/worker-entry/validate-fetch-style.d.ts.map +1 -0
- package/dist/workflows/local-workflow-entrypoints.d.ts +7 -0
- package/dist/workflows/local-workflow-entrypoints.d.ts.map +1 -0
- package/package.json +159 -116
- package/R2.md +0 -170
- package/dist/account-rvrj687w.js +0 -397
- package/dist/ai-dx4fr9jh.js +0 -107
- package/dist/bridge/protocol.d.ts.map +0 -1
- package/dist/bridge/serialization.d.ts.map +0 -1
- package/dist/browser-shim/worker.d.ts +0 -14
- package/dist/browser-shim/worker.d.ts.map +0 -1
- package/dist/build-mnf6v8gd.js +0 -53
- package/dist/deploy-nhceck39.js +0 -70
- package/dist/dev-b9dmrj7b.js +0 -2417
- package/dist/doctor-fmgb3d28.js +0 -190
- package/dist/durable-object-t4kbb0yt.js +0 -13
- package/dist/index-07q6yxyc.js +0 -168
- package/dist/index-18hvb6gb.js +0 -194
- package/dist/index-1xpj0m4r.js +0 -57
- package/dist/index-37x76zdn.js +0 -4
- package/dist/index-3t6rypgc.js +0 -13
- package/dist/index-67qcae0f.js +0 -183
- package/dist/index-a855bdsx.js +0 -18
- package/dist/index-d8bdkx2h.js +0 -109
- package/dist/index-ep3445yc.js +0 -2225
- package/dist/index-gz1gndna.js +0 -307
- package/dist/index-hcex3rgh.js +0 -266
- package/dist/index-m2q41jwa.js +0 -462
- package/dist/index-n7rs26ft.js +0 -77
- package/dist/index-pf5s73n9.js +0 -1413
- package/dist/index-rbht7m9r.js +0 -36
- package/dist/index-tfyxa77h.js +0 -850
- package/dist/index-tk6ej9dj.js +0 -94
- package/dist/index-z14anrqp.js +0 -226
- package/dist/init-f9mgmew3.js +0 -186
- package/dist/remote-q59qk463.js +0 -97
- package/dist/test/bridge-context.d.ts +0 -76
- package/dist/test/bridge-context.d.ts.map +0 -1
- package/dist/test/multi-worker-context.d.ts +0 -114
- package/dist/test/multi-worker-context.d.ts.map +0 -1
- package/dist/types-5nyrz1sz.js +0 -454
- package/dist/worker-entrypoint-m9th0rg0.js +0 -13
|
@@ -0,0 +1,1267 @@
|
|
|
1
|
+
import { d as resolveConfigEnvVars } from "./preview-C3Cdr8an.js";
|
|
2
|
+
import { i as resolveConfigPath, o as loadResolvedConfig, r as loadConfig, s as resolveResources, u as resolveConfigForEnvironment } from "./loader-Cr0_OWPy.js";
|
|
3
|
+
import { o as normalizeDOBinding } from "./schema-normalization-BCwTLTGp.js";
|
|
4
|
+
import { c as writeWranglerConfig, i as isolateViteBuildOutputPaths, n as compileConfig, o as rebaseWranglerConfigPaths, r as compileToProgrammaticConfig, t as compileBuildConfig } from "./compiler-Zw16C9Pi.js";
|
|
5
|
+
import { h as resolveFetchHandler, i as assertExplicit2ArgStyle } from "./runtime-DL-Nz3k8.js";
|
|
6
|
+
import { s as resolveServiceBindings, t as discoverRoutes } from "./routes-BFYCqHb-.js";
|
|
7
|
+
import { n as findDurableObjectClasses } from "./durable-object-DMtH0XYX.js";
|
|
8
|
+
import { r as SUPPORTED_WORKER_EXTENSIONS } from "./worker-entrypoint-CQW77lG8.js";
|
|
9
|
+
import { i as findFiles, t as DEFAULT_DO_PATTERN } from "./glob-CmQOvunB.js";
|
|
10
|
+
import { dirname, isAbsolute, relative, resolve } from "pathe";
|
|
11
|
+
//#region src/worker-entry/durable-object-discovery.ts
|
|
12
|
+
/**
|
|
13
|
+
* Walk the glob `pattern` under `cwd` and return a map of file path →
|
|
14
|
+
* Durable Object class names declared in that file. Files that fail to read
|
|
15
|
+
* or contain no DO classes are omitted. Respects `.gitignore` automatically
|
|
16
|
+
* (via `findFiles`).
|
|
17
|
+
*/
|
|
18
|
+
async function discoverDurableObjectFiles(cwd, pattern) {
|
|
19
|
+
const result = /* @__PURE__ */ new Map();
|
|
20
|
+
const matchedFiles = await findFiles(pattern, { cwd });
|
|
21
|
+
const fs = await import("node:fs/promises");
|
|
22
|
+
for (const filePath of matchedFiles) try {
|
|
23
|
+
const classNames = findDurableObjectClasses(await fs.readFile(filePath, "utf-8"));
|
|
24
|
+
if (classNames.length > 0) result.set(filePath, classNames);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.warn(`[devflare] Failed to read DO file: ${filePath}`, error);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Vite-plugin-shaped wrapper around `discoverDurableObjectFiles`. Returns a
|
|
32
|
+
* `DODiscoveryResult` carrying the discovered file map plus the auxiliary
|
|
33
|
+
* worker name.
|
|
34
|
+
*/
|
|
35
|
+
async function discoverDurableObjects(projectRoot, pattern, workerName) {
|
|
36
|
+
return {
|
|
37
|
+
files: await discoverDurableObjectFiles(projectRoot, pattern),
|
|
38
|
+
workerName
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/vite/plugin-config-hook.ts
|
|
43
|
+
/**
|
|
44
|
+
* Try to load the devflare config without throwing. Returns `null` if the
|
|
45
|
+
* config does not exist (the plugin still works without one).
|
|
46
|
+
*/
|
|
47
|
+
async function tryLoadDevflareConfig(cwd, configPath, command) {
|
|
48
|
+
try {
|
|
49
|
+
return await loadConfig({
|
|
50
|
+
cwd,
|
|
51
|
+
configFile: configPath
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (command === "build") console.warn("[devflare] Could not load config:", error);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Build the `define` map injecting `__DEVFLARE_WORKER_NAME__` as a build-time
|
|
60
|
+
* constant. Caller is responsible for merging this into any existing `define`.
|
|
61
|
+
*/
|
|
62
|
+
function buildWorkerNameDefine(lfConfig, existing) {
|
|
63
|
+
const workerNameValue = lfConfig.name ?? "unknown";
|
|
64
|
+
return {
|
|
65
|
+
...existing,
|
|
66
|
+
__DEVFLARE_WORKER_NAME__: JSON.stringify(workerNameValue)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Build the `server.proxy` config that forwards WebSocket upgrades to the
|
|
71
|
+
* Miniflare bridge. Returns `null` when no patterns are configured.
|
|
72
|
+
*/
|
|
73
|
+
function buildWebSocketProxyConfig(lfConfig, bridgePort, wsProxyPatterns) {
|
|
74
|
+
const patterns = [...wsProxyPatterns];
|
|
75
|
+
if (lfConfig.wsRoutes && lfConfig.wsRoutes.length > 0) {
|
|
76
|
+
for (const route of lfConfig.wsRoutes) if (!patterns.includes(route.pattern)) patterns.push(route.pattern);
|
|
77
|
+
}
|
|
78
|
+
if (patterns.length === 0) return null;
|
|
79
|
+
const proxyConfig = {};
|
|
80
|
+
for (const pattern of patterns) proxyConfig[pattern] = {
|
|
81
|
+
target: `http://127.0.0.1:${bridgePort}`,
|
|
82
|
+
changeOrigin: true,
|
|
83
|
+
ws: true,
|
|
84
|
+
configure: (proxy) => {
|
|
85
|
+
proxy.on("error", (err) => {
|
|
86
|
+
console.error(`[devflare] Proxy error: ${err.message}`);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
if (Object.keys(proxyConfig).length === 0) return null;
|
|
91
|
+
console.log(`[devflare] WebSocket proxy configured for: ${patterns.join(", ")}`);
|
|
92
|
+
return proxyConfig;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Build the additional Vite config returned by the plugin's `config()` hook.
|
|
96
|
+
* Loads the devflare config, derives `define` and (in dev under
|
|
97
|
+
* `DEVFLARE_DEV`) `server.proxy`. Returns `undefined` when there is nothing
|
|
98
|
+
* to merge.
|
|
99
|
+
*/
|
|
100
|
+
async function buildPluginConfigHookResult(cwd, options, command, existingDefine) {
|
|
101
|
+
const lfConfig = await tryLoadDevflareConfig(cwd, options.configPath, command);
|
|
102
|
+
const returnConfig = {};
|
|
103
|
+
if (lfConfig) returnConfig.define = buildWorkerNameDefine(lfConfig, existingDefine);
|
|
104
|
+
if (command === "serve" && process.env.DEVFLARE_DEV && lfConfig) {
|
|
105
|
+
const proxyConfig = buildWebSocketProxyConfig(lfConfig, options.bridgePort ?? 8787, options.wsProxyPatterns);
|
|
106
|
+
if (proxyConfig) returnConfig.server = { proxy: proxyConfig };
|
|
107
|
+
}
|
|
108
|
+
return Object.keys(returnConfig).length > 0 ? returnConfig : void 0;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/worker-entry/surface-paths.ts
|
|
112
|
+
const defaultEntriesFor = (surface) => SUPPORTED_WORKER_EXTENSIONS.map((ext) => `src/${surface}${ext}`);
|
|
113
|
+
const DEFAULT_FETCH_ENTRY_FILES = defaultEntriesFor("fetch");
|
|
114
|
+
const DEFAULT_QUEUE_ENTRY_FILES = defaultEntriesFor("queue");
|
|
115
|
+
const DEFAULT_SCHEDULED_ENTRY_FILES = defaultEntriesFor("scheduled");
|
|
116
|
+
const DEFAULT_EMAIL_ENTRY_FILES = defaultEntriesFor("email");
|
|
117
|
+
const DEFAULT_TAIL_ENTRY_FILES = defaultEntriesFor("tail");
|
|
118
|
+
/**
|
|
119
|
+
* Path prefixes that are known framework / bundler build outputs.
|
|
120
|
+
* A handler path that lives under one of these will not exist on disk
|
|
121
|
+
* until the framework's own build (e.g. `vite build`, `svelte-kit build`)
|
|
122
|
+
* has run, which happens AFTER devflare resolves surface paths.
|
|
123
|
+
*/
|
|
124
|
+
const BUILD_OUTPUT_PATH_PREFIXES = [
|
|
125
|
+
".svelte-kit/",
|
|
126
|
+
".adapter-cloudflare/",
|
|
127
|
+
".next/",
|
|
128
|
+
".nuxt/",
|
|
129
|
+
".output/",
|
|
130
|
+
".vercel/",
|
|
131
|
+
"dist/",
|
|
132
|
+
"build/",
|
|
133
|
+
".vinxi/",
|
|
134
|
+
".solid/"
|
|
135
|
+
];
|
|
136
|
+
/** Returns true when the path looks like a framework build output. */
|
|
137
|
+
function looksLikeBuildArtifactPath(configuredPath) {
|
|
138
|
+
const normalised = configuredPath.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
139
|
+
return BUILD_OUTPUT_PATH_PREFIXES.some((prefix) => normalised.startsWith(prefix));
|
|
140
|
+
}
|
|
141
|
+
async function resolveWorkerHandlerPath(cwd, configuredPath, defaultEntries, surfaceName = "worker") {
|
|
142
|
+
if (configuredPath === false) return null;
|
|
143
|
+
const fs = await import("node:fs/promises");
|
|
144
|
+
if (typeof configuredPath === "string" && configuredPath) {
|
|
145
|
+
const absolutePath = resolve(cwd, configuredPath);
|
|
146
|
+
try {
|
|
147
|
+
await fs.access(absolutePath);
|
|
148
|
+
return absolutePath;
|
|
149
|
+
} catch {
|
|
150
|
+
if (looksLikeBuildArtifactPath(configuredPath)) throw new Error(`Configured ${surfaceName} handler "${configuredPath}" was not found.\n\nThis path looks like a framework build output (e.g. SvelteKit / Vite / Next).\nDevflare resolves handler paths BEFORE your framework runs its build, so the file\ndoes not exist yet at this stage.\n\nRecommended fix — point devflare at the build artifact via wrangler passthrough\ninstead of files.${surfaceName}, so devflare skips composition and lets your\nframework write the worker entry that wrangler/vite then picks up:\n\n files: { ${surfaceName}: false },\n wrangler: {\n passthrough: { main: '${configuredPath}' }\n }\n\nAlternatively, run your framework build (e.g. \`vite build\`) before \`devflare build\`,\nor move the handler to a source file that exists at config time.`);
|
|
151
|
+
throw new Error(`Configured ${surfaceName} handler "${configuredPath}" was not found`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
for (const defaultEntry of defaultEntries) {
|
|
155
|
+
const absolutePath = resolve(cwd, defaultEntry);
|
|
156
|
+
try {
|
|
157
|
+
await fs.access(absolutePath);
|
|
158
|
+
return absolutePath;
|
|
159
|
+
} catch {}
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
async function resolveWorkerSurfacePaths(cwd, config) {
|
|
164
|
+
return {
|
|
165
|
+
fetch: await resolveWorkerHandlerPath(cwd, config.files?.fetch, DEFAULT_FETCH_ENTRY_FILES, "fetch"),
|
|
166
|
+
queue: await resolveWorkerHandlerPath(cwd, config.files?.queue, DEFAULT_QUEUE_ENTRY_FILES, "queue"),
|
|
167
|
+
scheduled: await resolveWorkerHandlerPath(cwd, config.files?.scheduled, DEFAULT_SCHEDULED_ENTRY_FILES, "scheduled"),
|
|
168
|
+
email: await resolveWorkerHandlerPath(cwd, config.files?.email, DEFAULT_EMAIL_ENTRY_FILES, "email"),
|
|
169
|
+
tail: await resolveWorkerHandlerPath(cwd, config.files?.tail, DEFAULT_TAIL_ENTRY_FILES, "tail")
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function hasWorkerSurfacePaths(surfacePaths) {
|
|
173
|
+
return Object.values(surfacePaths).some((surfacePath) => typeof surfacePath === "string" && surfacePath.length > 0);
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/worker-entry/validate-fetch-style.ts
|
|
177
|
+
/**
|
|
178
|
+
* Validate the resolved fetch surface module's calling-convention style.
|
|
179
|
+
*
|
|
180
|
+
* `fetchSurfacePath` is the absolute, on-disk path devflare resolved for the
|
|
181
|
+
* fetch surface (`WorkerSurfacePaths.fetch`). When it is `null` there is no
|
|
182
|
+
* fetch surface to check.
|
|
183
|
+
*
|
|
184
|
+
* Throws the same `[devflare] Ambiguous 2-argument fetch handler …` error as
|
|
185
|
+
* the request-time check when the export is an unmarked 2-arg handler.
|
|
186
|
+
*/
|
|
187
|
+
async function validateFetchHandlerStyle(fetchSurfacePath) {
|
|
188
|
+
if (!fetchSurfacePath) return;
|
|
189
|
+
if (looksLikeBuildArtifactPath(fetchSurfacePath)) return;
|
|
190
|
+
let surfaceModule;
|
|
191
|
+
try {
|
|
192
|
+
surfaceModule = await import(fetchSurfacePath);
|
|
193
|
+
} catch {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
let handler;
|
|
197
|
+
try {
|
|
198
|
+
handler = resolveFetchHandler(surfaceModule);
|
|
199
|
+
} catch {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (!handler) return;
|
|
203
|
+
assertExplicit2ArgStyle(handler);
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/worker-entry/composed-worker.ts
|
|
207
|
+
/**
|
|
208
|
+
* Minimal structured codegen helper used to emit the composed worker module.
|
|
209
|
+
* Each method appends a discrete "section" to the output; sections are joined
|
|
210
|
+
* by a single newline when rendered, which matches the shape previously
|
|
211
|
+
* produced by the hand-written template literal.
|
|
212
|
+
*/
|
|
213
|
+
var CodeBuilder = class {
|
|
214
|
+
sections = [];
|
|
215
|
+
importStatement(specifiers, from) {
|
|
216
|
+
this.sections.push(`import { ${specifiers.join(", ")} } from '${from}'`);
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
importNamespace(identifier, from) {
|
|
220
|
+
this.sections.push(`import * as ${identifier} from '${from}'`);
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
reExport(names, from) {
|
|
224
|
+
this.sections.push(`export { ${names.join(", ")} } from '${from}'`);
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
constDeclaration(name, value) {
|
|
228
|
+
this.sections.push(`const ${name} = ${value}`);
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
classDeclaration(body) {
|
|
232
|
+
this.sections.push(body);
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
exportDefault(body) {
|
|
236
|
+
this.sections.push(`export default ${body}`);
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
raw(text) {
|
|
240
|
+
this.sections.push(text);
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
blank() {
|
|
244
|
+
this.sections.push("");
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
toString() {
|
|
248
|
+
return this.sections.join("\n");
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
const DEV_ONLY_EMAIL_HOOKS_SOURCE = `
|
|
252
|
+
function __devflareCreateEmailHeaders(rawBody) {
|
|
253
|
+
const headers = new Headers()
|
|
254
|
+
const lines = rawBody.split(/\\r?\\n/)
|
|
255
|
+
|
|
256
|
+
for (const line of lines) {
|
|
257
|
+
if (line.trim() === '') {
|
|
258
|
+
break
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const colonIndex = line.indexOf(':')
|
|
262
|
+
if (colonIndex <= 0) {
|
|
263
|
+
continue
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
headers.append(line.slice(0, colonIndex).trim(), line.slice(colonIndex + 1).trim())
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return headers
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function __devflareCreateEmailRawStream(rawBody) {
|
|
273
|
+
return new ReadableStream({
|
|
274
|
+
start(controller) {
|
|
275
|
+
controller.enqueue(new TextEncoder().encode(rawBody))
|
|
276
|
+
controller.close()
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async function __devflareHandleInternalEmail(request, env, ctx) {
|
|
282
|
+
if (!__devflareEmailHandler) {
|
|
283
|
+
return new Response('Email handler not configured', { status: 501 })
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const from = request.headers.get('x-devflare-email-from') || 'unknown@example.com'
|
|
287
|
+
const to = request.headers.get('x-devflare-email-to') || 'worker@example.com'
|
|
288
|
+
const rawBody = await request.text()
|
|
289
|
+
const emailMessage = {
|
|
290
|
+
from,
|
|
291
|
+
to,
|
|
292
|
+
headers: __devflareCreateEmailHeaders(rawBody),
|
|
293
|
+
raw: __devflareCreateEmailRawStream(rawBody),
|
|
294
|
+
rawSize: rawBody.length,
|
|
295
|
+
setReject(reason) {
|
|
296
|
+
console.warn('[Devflare email rejected]', reason)
|
|
297
|
+
},
|
|
298
|
+
async forward(rcptTo) {
|
|
299
|
+
console.log('[Devflare email forwarded]', rcptTo)
|
|
300
|
+
return Promise.resolve()
|
|
301
|
+
},
|
|
302
|
+
async reply(message) {
|
|
303
|
+
console.log('[Devflare email reply sent]', message?.from)
|
|
304
|
+
return Promise.resolve()
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const __devflareEvent = createEmailEvent(emailMessage, env, ctx)
|
|
309
|
+
|
|
310
|
+
await runWithEventContext(
|
|
311
|
+
__devflareEvent,
|
|
312
|
+
() => __devflareEmailHandler(__devflareEvent, env, ctx)
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
return new Response(JSON.stringify({ ok: true, from, to }), {
|
|
316
|
+
headers: { 'Content-Type': 'application/json' }
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
`;
|
|
320
|
+
function emitDevOnlyEmailHooks(builder, options) {
|
|
321
|
+
if (!options.enabled) return;
|
|
322
|
+
builder.raw(DEV_ONLY_EMAIL_HOOKS_SOURCE);
|
|
323
|
+
}
|
|
324
|
+
const RESOLVE_HANDLER_DECLARATION = `const __devflareResolveHandler = (module, namedExport) => {
|
|
325
|
+
const defaultExport = module.default
|
|
326
|
+
|
|
327
|
+
if (typeof defaultExport === 'function') {
|
|
328
|
+
return defaultExport
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (defaultExport && typeof defaultExport[namedExport] === 'function') {
|
|
332
|
+
return defaultExport[namedExport].bind(defaultExport)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (typeof module[namedExport] === 'function') {
|
|
336
|
+
return module[namedExport]
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return null
|
|
340
|
+
}`;
|
|
341
|
+
function buildDefaultExportBody(options) {
|
|
342
|
+
const devOnlyEmailEntry = options.includeDevOnlyHooks ? `const url = new URL(request.url)
|
|
343
|
+
|
|
344
|
+
if (
|
|
345
|
+
request.headers.get('x-devflare-event') === 'email'
|
|
346
|
+
&& url.pathname === '/_devflare/internal/email'
|
|
347
|
+
) {
|
|
348
|
+
return __devflareHandleInternalEmail(request, env, ctx)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
` : "";
|
|
352
|
+
return `{
|
|
353
|
+
...(${options.hasFetchDispatch ? "true" : "false"}
|
|
354
|
+
? {
|
|
355
|
+
async fetch(request, env, ctx) {
|
|
356
|
+
${devOnlyEmailEntry}const __devflareInitialRouteMatch = __devflareHasRoutes ? matchFetchRoute(__devflareRoutes, request) : null
|
|
357
|
+
const __devflareEvent = createFetchEvent(request, env, ctx, {
|
|
358
|
+
params: __devflareInitialRouteMatch?.params ?? {}
|
|
359
|
+
})
|
|
360
|
+
return runWithEventContext(
|
|
361
|
+
__devflareEvent,
|
|
362
|
+
() => invokeFetchModule(
|
|
363
|
+
__devflareFetchModule,
|
|
364
|
+
__devflareEvent,
|
|
365
|
+
__devflareHasRoutes
|
|
366
|
+
? createRouteResolve(__devflareRoutes, __devflareEvent)
|
|
367
|
+
: undefined
|
|
368
|
+
)
|
|
369
|
+
)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
: {}),
|
|
373
|
+
...(__devflareQueueHandler
|
|
374
|
+
? {
|
|
375
|
+
async queue(batch, env, ctx) {
|
|
376
|
+
assertExplicitQueueHandlerStyle(__devflareQueueHandler)
|
|
377
|
+
const __devflareEvent = createQueueEvent(batch, env, ctx)
|
|
378
|
+
return runWithEventContext(
|
|
379
|
+
__devflareEvent,
|
|
380
|
+
() => __devflareQueueHandler(__devflareEvent, env, ctx)
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
: {}),
|
|
385
|
+
...(__devflareScheduledHandler
|
|
386
|
+
? {
|
|
387
|
+
async scheduled(controller, env, ctx) {
|
|
388
|
+
assertExplicitScheduledHandlerStyle(__devflareScheduledHandler)
|
|
389
|
+
const __devflareEvent = createScheduledEvent(controller, env, ctx)
|
|
390
|
+
return runWithEventContext(
|
|
391
|
+
__devflareEvent,
|
|
392
|
+
() => __devflareScheduledHandler(__devflareEvent, env, ctx)
|
|
393
|
+
)
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
: {}),
|
|
397
|
+
...(__devflareEmailHandler
|
|
398
|
+
? {
|
|
399
|
+
async email(message, env, ctx) {
|
|
400
|
+
const __devflareEvent = createEmailEvent(message, env, ctx)
|
|
401
|
+
return runWithEventContext(
|
|
402
|
+
__devflareEvent,
|
|
403
|
+
() => __devflareEmailHandler(__devflareEvent, env, ctx)
|
|
404
|
+
)
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
: {}),
|
|
408
|
+
...(__devflareTailHandler
|
|
409
|
+
? {
|
|
410
|
+
async tail(events, env, ctx) {
|
|
411
|
+
const __devflareEvent = createTailEvent(events, env, ctx)
|
|
412
|
+
return runWithEventContext(
|
|
413
|
+
__devflareEvent,
|
|
414
|
+
() => __devflareTailHandler.length >= 2
|
|
415
|
+
? __devflareTailHandler(events, env, ctx)
|
|
416
|
+
: __devflareTailHandler(__devflareEvent, env, ctx)
|
|
417
|
+
)
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
: {})
|
|
421
|
+
}`;
|
|
422
|
+
}
|
|
423
|
+
function getComposedWorkerEntrypointSource(surfaceImportPaths, configuredLocalSendEmailBindings = {}, durableObjectExports = [], routeImports = [], options = {}) {
|
|
424
|
+
const includeDevOnlyHooks = options.includeDevOnlyHooks ?? options.devInternalEmail === true;
|
|
425
|
+
const importsBuilder = new CodeBuilder();
|
|
426
|
+
importsBuilder.importStatement([
|
|
427
|
+
"assertExplicitQueueHandlerStyle",
|
|
428
|
+
"assertExplicitScheduledHandlerStyle",
|
|
429
|
+
"createEmailEvent",
|
|
430
|
+
"createFetchEvent",
|
|
431
|
+
"createQueueEvent",
|
|
432
|
+
"createRouteResolve",
|
|
433
|
+
"createScheduledEvent",
|
|
434
|
+
"createTailEvent",
|
|
435
|
+
"invokeFetchModule",
|
|
436
|
+
"matchFetchRoute",
|
|
437
|
+
"runWithEventContext",
|
|
438
|
+
"setLocalSendEmailBindings"
|
|
439
|
+
], "devflare/runtime");
|
|
440
|
+
const fallbackModules = [
|
|
441
|
+
{
|
|
442
|
+
identifier: "__devflareFetchModule",
|
|
443
|
+
importPath: surfaceImportPaths.fetch
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
identifier: "__devflareQueueModule",
|
|
447
|
+
importPath: surfaceImportPaths.queue
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
identifier: "__devflareScheduledModule",
|
|
451
|
+
importPath: surfaceImportPaths.scheduled
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
identifier: "__devflareEmailModule",
|
|
455
|
+
importPath: surfaceImportPaths.email
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
identifier: "__devflareTailModule",
|
|
459
|
+
importPath: surfaceImportPaths.tail
|
|
460
|
+
}
|
|
461
|
+
];
|
|
462
|
+
const fallbacksBuilder = new CodeBuilder();
|
|
463
|
+
for (const { identifier, importPath } of fallbackModules) if (importPath) importsBuilder.importNamespace(identifier, importPath);
|
|
464
|
+
else fallbacksBuilder.constDeclaration(identifier, "{}");
|
|
465
|
+
for (const routeImport of routeImports) importsBuilder.importNamespace(routeImport.identifier, routeImport.importPath);
|
|
466
|
+
const reExportsBuilder = new CodeBuilder();
|
|
467
|
+
for (const { classNames, importPath } of durableObjectExports) reExportsBuilder.reExport(classNames, importPath);
|
|
468
|
+
const routeManifestEntries = routeImports.map(({ identifier, filePath, routePath, segmentsJson }) => {
|
|
469
|
+
return `\t{ filePath: ${JSON.stringify(filePath)}, routePath: ${JSON.stringify(routePath)}, segments: ${segmentsJson}, module: ${identifier} }`;
|
|
470
|
+
});
|
|
471
|
+
const builder = new CodeBuilder();
|
|
472
|
+
builder.raw(importsBuilder.toString());
|
|
473
|
+
builder.raw(fallbacksBuilder.toString());
|
|
474
|
+
builder.raw(reExportsBuilder.toString());
|
|
475
|
+
builder.blank();
|
|
476
|
+
builder.raw(`setLocalSendEmailBindings(${JSON.stringify(configuredLocalSendEmailBindings)})`);
|
|
477
|
+
builder.blank();
|
|
478
|
+
builder.constDeclaration("__devflareHasFetchModule", surfaceImportPaths.fetch ? "true" : "false");
|
|
479
|
+
builder.raw(`const __devflareRoutes = [\n${routeManifestEntries.join(",\n")}\n]`);
|
|
480
|
+
builder.constDeclaration("__devflareHasRoutes", "__devflareRoutes.length > 0");
|
|
481
|
+
builder.blank();
|
|
482
|
+
builder.raw(RESOLVE_HANDLER_DECLARATION);
|
|
483
|
+
builder.blank();
|
|
484
|
+
builder.constDeclaration("__devflareQueueHandler", "__devflareResolveHandler(__devflareQueueModule, 'queue')");
|
|
485
|
+
builder.constDeclaration("__devflareScheduledHandler", "__devflareResolveHandler(__devflareScheduledModule, 'scheduled')");
|
|
486
|
+
builder.constDeclaration("__devflareEmailHandler", "__devflareResolveHandler(__devflareEmailModule, 'email')");
|
|
487
|
+
builder.constDeclaration("__devflareTailHandler", "__devflareResolveHandler(__devflareTailModule, 'tail')");
|
|
488
|
+
emitDevOnlyEmailHooks(builder, { enabled: includeDevOnlyHooks });
|
|
489
|
+
builder.blank();
|
|
490
|
+
builder.exportDefault(buildDefaultExportBody({
|
|
491
|
+
hasFetchDispatch: Boolean(surfaceImportPaths.fetch) || routeImports.length > 0 || includeDevOnlyHooks,
|
|
492
|
+
includeDevOnlyHooks
|
|
493
|
+
}));
|
|
494
|
+
builder.raw("");
|
|
495
|
+
return builder.toString();
|
|
496
|
+
}
|
|
497
|
+
function toImportSpecifier(fromFilePath, toFilePath) {
|
|
498
|
+
const specifier = relative(dirname(fromFilePath), toFilePath).replace(/\\/g, "/");
|
|
499
|
+
return specifier.startsWith(".") ? specifier : `./${specifier}`;
|
|
500
|
+
}
|
|
501
|
+
function createGeneratedRouteModuleImports(entryPath, routeDiscovery) {
|
|
502
|
+
if (!routeDiscovery) return [];
|
|
503
|
+
return routeDiscovery.routes.map((route, index) => ({
|
|
504
|
+
identifier: `__devflareRouteModule${index}`,
|
|
505
|
+
importPath: toImportSpecifier(entryPath, route.absolutePath),
|
|
506
|
+
filePath: route.filePath,
|
|
507
|
+
routePath: route.routePath,
|
|
508
|
+
segmentsJson: JSON.stringify(route.segments)
|
|
509
|
+
}));
|
|
510
|
+
}
|
|
511
|
+
async function createGeneratedDurableObjectExports(entryPath, cwd, config) {
|
|
512
|
+
if (config.files?.durableObjects === false || !config.bindings?.durableObjects) return [];
|
|
513
|
+
const localClassNames = new Set(Object.values(config.bindings.durableObjects).map((binding) => normalizeDOBinding(binding)).filter((binding) => binding.kind === "local").map((binding) => binding.className));
|
|
514
|
+
if (localClassNames.size === 0) return [];
|
|
515
|
+
const discoveredFiles = await discoverDurableObjectFiles(cwd, typeof config.files?.durableObjects === "string" ? config.files.durableObjects : DEFAULT_DO_PATTERN);
|
|
516
|
+
const exports = [];
|
|
517
|
+
const discoveredClassNames = /* @__PURE__ */ new Set();
|
|
518
|
+
for (const [filePath, allClassNames] of discoveredFiles) {
|
|
519
|
+
const classNames = allClassNames.filter((className) => localClassNames.has(className));
|
|
520
|
+
if (classNames.length === 0) continue;
|
|
521
|
+
for (const className of classNames) discoveredClassNames.add(className);
|
|
522
|
+
exports.push({
|
|
523
|
+
importPath: toImportSpecifier(entryPath, filePath),
|
|
524
|
+
filePath,
|
|
525
|
+
classNames
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
const missingClassNames = Array.from(localClassNames).filter((className) => !discoveredClassNames.has(className));
|
|
529
|
+
if (missingClassNames.length > 0) throw new Error(`Failed to discover local Durable Object class${missingClassNames.length === 1 ? "" : "es"} ${missingClassNames.join(", ")} for worker composition. Ensure files.durableObjects matches the source file pattern for your do.* files.`);
|
|
530
|
+
return exports;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Returns true when the resolved config has any composition signal other than
|
|
534
|
+
* `files.fetch` (queue / scheduled / email handler files, durable-object
|
|
535
|
+
* bindings, sendEmail bindings, or routes). Used to decide whether a missing
|
|
536
|
+
* build-artifact fetch path can be safely deferred to wrangler/vite.
|
|
537
|
+
*/
|
|
538
|
+
function mayRequireCompositionBesidesFetch(config) {
|
|
539
|
+
const files = config.files ?? {};
|
|
540
|
+
if (typeof files.queue === "string" && files.queue) return true;
|
|
541
|
+
if (typeof files.scheduled === "string" && files.scheduled) return true;
|
|
542
|
+
if (typeof files.email === "string" && files.email) return true;
|
|
543
|
+
if (typeof files.tail === "string" && files.tail) return true;
|
|
544
|
+
if (files.durableObjects) return true;
|
|
545
|
+
if (files.routes) return true;
|
|
546
|
+
const bindings = config.bindings ?? {};
|
|
547
|
+
const doBindings = bindings.durableObjects;
|
|
548
|
+
if (doBindings && Object.keys(doBindings).length > 0) return true;
|
|
549
|
+
const sendEmail = bindings.sendEmail;
|
|
550
|
+
if (sendEmail && Object.keys(sendEmail).length > 0) return true;
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
function needsComposedWorkerEntrypoint(cwd, surfacePaths, config, routeDiscovery) {
|
|
554
|
+
if (Boolean(surfacePaths.queue || surfacePaths.scheduled || surfacePaths.email || surfacePaths.tail || routeDiscovery?.routes.length)) return true;
|
|
555
|
+
if (!surfacePaths.fetch) return false;
|
|
556
|
+
const assetsDirectory = config.assets?.directory;
|
|
557
|
+
if (assetsDirectory) {
|
|
558
|
+
const generatedAssetsWorkerPath = resolve(cwd, assetsDirectory, "_worker.js");
|
|
559
|
+
if (surfacePaths.fetch === generatedAssetsWorkerPath) return false;
|
|
560
|
+
}
|
|
561
|
+
return Boolean(surfacePaths.fetch);
|
|
562
|
+
}
|
|
563
|
+
async function prepareComposedWorkerEntrypoint(cwd, config, environment, options = {}) {
|
|
564
|
+
const resolvedConfig = resolveConfigForEnvironment(config, environment);
|
|
565
|
+
if (resolvedConfig.wrangler?.passthrough && Object.prototype.hasOwnProperty.call(resolvedConfig.wrangler.passthrough, "main")) return null;
|
|
566
|
+
const configuredFetch = resolvedConfig.files?.fetch;
|
|
567
|
+
if (typeof configuredFetch === "string" && looksLikeBuildArtifactPath(configuredFetch)) {
|
|
568
|
+
const fs = await import("node:fs/promises");
|
|
569
|
+
const fetchAbsolute = resolve(cwd, configuredFetch);
|
|
570
|
+
let fetchExists = true;
|
|
571
|
+
try {
|
|
572
|
+
await fs.access(fetchAbsolute);
|
|
573
|
+
} catch {
|
|
574
|
+
fetchExists = false;
|
|
575
|
+
}
|
|
576
|
+
if (!fetchExists && !mayRequireCompositionBesidesFetch(resolvedConfig)) return null;
|
|
577
|
+
}
|
|
578
|
+
const surfacePaths = await resolveWorkerSurfacePaths(cwd, resolvedConfig);
|
|
579
|
+
const routeDiscovery = await discoverRoutes(cwd, resolvedConfig);
|
|
580
|
+
if (!needsComposedWorkerEntrypoint(cwd, surfacePaths, resolvedConfig, routeDiscovery)) return null;
|
|
581
|
+
await validateFetchHandlerStyle(surfacePaths.fetch);
|
|
582
|
+
const fs = await import("node:fs/promises");
|
|
583
|
+
const entryDir = resolve(cwd, ".devflare", "worker-entrypoints");
|
|
584
|
+
const entryPath = resolve(entryDir, "main.ts");
|
|
585
|
+
await fs.mkdir(entryDir, { recursive: true });
|
|
586
|
+
const surfaceImportPaths = {
|
|
587
|
+
fetch: surfacePaths.fetch ? toImportSpecifier(entryPath, surfacePaths.fetch) : null,
|
|
588
|
+
queue: surfacePaths.queue ? toImportSpecifier(entryPath, surfacePaths.queue) : null,
|
|
589
|
+
scheduled: surfacePaths.scheduled ? toImportSpecifier(entryPath, surfacePaths.scheduled) : null,
|
|
590
|
+
email: surfacePaths.email ? toImportSpecifier(entryPath, surfacePaths.email) : null,
|
|
591
|
+
tail: surfacePaths.tail ? toImportSpecifier(entryPath, surfacePaths.tail) : null
|
|
592
|
+
};
|
|
593
|
+
const durableObjectExports = await createGeneratedDurableObjectExports(entryPath, cwd, resolvedConfig);
|
|
594
|
+
const routeImports = createGeneratedRouteModuleImports(entryPath, routeDiscovery);
|
|
595
|
+
await fs.writeFile(entryPath, getComposedWorkerEntrypointSource(surfaceImportPaths, resolvedConfig.bindings?.sendEmail ?? {}, durableObjectExports, routeImports, options));
|
|
596
|
+
return entryPath;
|
|
597
|
+
}
|
|
598
|
+
//#endregion
|
|
599
|
+
//#region src/vite/plugin-durable-objects.ts
|
|
600
|
+
const VIRTUAL_DO_ENTRY = "virtual:devflare-do-entry";
|
|
601
|
+
const RESOLVED_VIRTUAL_DO_ENTRY = "\0" + VIRTUAL_DO_ENTRY;
|
|
602
|
+
/**
|
|
603
|
+
* Generate virtual DO entry module code
|
|
604
|
+
*/
|
|
605
|
+
function generateVirtualDOEntry(discovery) {
|
|
606
|
+
const lines = [
|
|
607
|
+
"// Auto-generated by devflare — DO entry module",
|
|
608
|
+
"// Re-exports all Durable Object classes discovered from files.durableObjects pattern",
|
|
609
|
+
""
|
|
610
|
+
];
|
|
611
|
+
for (const [filePath, classNames] of discovery.files) {
|
|
612
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
613
|
+
lines.push(`export { ${classNames.join(", ")} } from '${normalizedPath}'`);
|
|
614
|
+
}
|
|
615
|
+
lines.push("");
|
|
616
|
+
lines.push("// Default fetch handler for DO worker");
|
|
617
|
+
lines.push("export default {");
|
|
618
|
+
lines.push(" async fetch(request: Request): Promise<Response> {");
|
|
619
|
+
lines.push(" return new Response(\"Devflare DO Worker\", { status: 200 })");
|
|
620
|
+
lines.push(" }");
|
|
621
|
+
lines.push("}");
|
|
622
|
+
return lines.join("\n");
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Create auxiliary worker config for Durable Objects
|
|
626
|
+
*/
|
|
627
|
+
function createAuxiliaryWorkerConfig(wranglerConfig, discovery) {
|
|
628
|
+
const doBindings = wranglerConfig.durable_objects?.bindings?.map((binding) => ({
|
|
629
|
+
name: binding.name,
|
|
630
|
+
class_name: binding.class_name
|
|
631
|
+
})) ?? [];
|
|
632
|
+
return { config: {
|
|
633
|
+
name: discovery.workerName,
|
|
634
|
+
main: VIRTUAL_DO_ENTRY,
|
|
635
|
+
compatibility_date: wranglerConfig.compatibility_date,
|
|
636
|
+
compatibility_flags: wranglerConfig.compatibility_flags,
|
|
637
|
+
durable_objects: { bindings: doBindings },
|
|
638
|
+
migrations: wranglerConfig.migrations,
|
|
639
|
+
kv_namespaces: wranglerConfig.kv_namespaces,
|
|
640
|
+
d1_databases: wranglerConfig.d1_databases,
|
|
641
|
+
r2_buckets: wranglerConfig.r2_buckets,
|
|
642
|
+
browser: wranglerConfig.browser
|
|
643
|
+
} };
|
|
644
|
+
}
|
|
645
|
+
function logDiscoveredDurableObjects(projectRoot, discovery) {
|
|
646
|
+
if (!discovery || discovery.files.size === 0) return;
|
|
647
|
+
console.log(`[devflare] Discovered ${discovery.files.size} DO file(s):`);
|
|
648
|
+
for (const [filePath, classes] of discovery.files) console.log(` • ${filePath.replace(projectRoot, ".")} → ${classes.join(", ")}`);
|
|
649
|
+
}
|
|
650
|
+
//#endregion
|
|
651
|
+
//#region src/vite/plugin-service-bindings.ts
|
|
652
|
+
const VIRTUAL_SERVICE_WORKER_PREFIX = "virtual:devflare-service-worker/";
|
|
653
|
+
const RESOLVED_VIRTUAL_SERVICE_WORKER_PREFIX = "\0" + VIRTUAL_SERVICE_WORKER_PREFIX;
|
|
654
|
+
function virtualServiceWorkerId(workerName) {
|
|
655
|
+
return `${VIRTUAL_SERVICE_WORKER_PREFIX}${encodeURIComponent(workerName)}`;
|
|
656
|
+
}
|
|
657
|
+
function resolvedVirtualServiceWorkerId(workerName) {
|
|
658
|
+
return `${RESOLVED_VIRTUAL_SERVICE_WORKER_PREFIX}${encodeURIComponent(workerName)}`;
|
|
659
|
+
}
|
|
660
|
+
function objectEntries(record) {
|
|
661
|
+
return record ? Object.entries(record) : [];
|
|
662
|
+
}
|
|
663
|
+
function toWranglerDurableObjectBinding(name, value) {
|
|
664
|
+
if (typeof value === "string") return {
|
|
665
|
+
name,
|
|
666
|
+
class_name: value
|
|
667
|
+
};
|
|
668
|
+
return {
|
|
669
|
+
name,
|
|
670
|
+
class_name: value.className,
|
|
671
|
+
script_name: value.scriptName
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
function toWranglerWorkerConfig(worker) {
|
|
675
|
+
const queueProducers = worker.queueProducers ? objectEntries(worker.queueProducers).map(([binding, producer]) => ({
|
|
676
|
+
binding,
|
|
677
|
+
queue: producer.queueName
|
|
678
|
+
})) : void 0;
|
|
679
|
+
const queueConsumers = worker.queueConsumers ? objectEntries(worker.queueConsumers).map(([queue, consumer]) => ({
|
|
680
|
+
queue,
|
|
681
|
+
...consumer.maxBatchSize !== void 0 && { max_batch_size: consumer.maxBatchSize },
|
|
682
|
+
...consumer.maxBatchTimeout !== void 0 && { max_batch_timeout: consumer.maxBatchTimeout },
|
|
683
|
+
...consumer.maxRetries !== void 0 && { max_retries: consumer.maxRetries },
|
|
684
|
+
...typeof consumer.deadLetterQueue === "string" && { dead_letter_queue: consumer.deadLetterQueue },
|
|
685
|
+
...consumer.maxConcurrency !== void 0 && { max_concurrency: consumer.maxConcurrency },
|
|
686
|
+
...consumer.retryDelay !== void 0 && { retry_delay: consumer.retryDelay }
|
|
687
|
+
})) : void 0;
|
|
688
|
+
const queues = queueProducers || queueConsumers ? {
|
|
689
|
+
...queueProducers && { producers: queueProducers },
|
|
690
|
+
...queueConsumers && { consumers: queueConsumers }
|
|
691
|
+
} : void 0;
|
|
692
|
+
const durableObjectBindings = worker.durableObjects ? objectEntries(worker.durableObjects).map(([name, value]) => toWranglerDurableObjectBinding(name, value)) : [];
|
|
693
|
+
const serviceBindings = worker.serviceBindings ? objectEntries(worker.serviceBindings).map(([binding, target]) => ({
|
|
694
|
+
binding,
|
|
695
|
+
service: target.name,
|
|
696
|
+
...target.entrypoint && { entrypoint: target.entrypoint }
|
|
697
|
+
})) : [];
|
|
698
|
+
return {
|
|
699
|
+
name: worker.name,
|
|
700
|
+
main: virtualServiceWorkerId(worker.name),
|
|
701
|
+
compatibility_date: worker.compatibilityDate,
|
|
702
|
+
...worker.compatibilityFlags && { compatibility_flags: worker.compatibilityFlags },
|
|
703
|
+
...worker.bindings && { vars: worker.bindings },
|
|
704
|
+
...worker.kvNamespaces && { kv_namespaces: objectEntries(worker.kvNamespaces).map(([binding, id]) => ({
|
|
705
|
+
binding,
|
|
706
|
+
id
|
|
707
|
+
})) },
|
|
708
|
+
...worker.r2Buckets && { r2_buckets: objectEntries(worker.r2Buckets).map(([binding, bucket_name]) => ({
|
|
709
|
+
binding,
|
|
710
|
+
bucket_name
|
|
711
|
+
})) },
|
|
712
|
+
...worker.d1Databases && { d1_databases: objectEntries(worker.d1Databases).map(([binding, database_id]) => ({
|
|
713
|
+
binding,
|
|
714
|
+
database_id,
|
|
715
|
+
database_name: database_id
|
|
716
|
+
})) },
|
|
717
|
+
...durableObjectBindings.length > 0 && { durable_objects: { bindings: durableObjectBindings } },
|
|
718
|
+
...serviceBindings.length > 0 && { services: serviceBindings },
|
|
719
|
+
...queues && { queues }
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
function createAuxiliaryServiceWorkerConfigs(resolution) {
|
|
723
|
+
if (!resolution || resolution.workers.length === 0) return {
|
|
724
|
+
auxiliaryWorkers: [],
|
|
725
|
+
virtualModules: /* @__PURE__ */ new Map()
|
|
726
|
+
};
|
|
727
|
+
const virtualModules = /* @__PURE__ */ new Map();
|
|
728
|
+
return {
|
|
729
|
+
auxiliaryWorkers: resolution.workers.map((worker) => {
|
|
730
|
+
virtualModules.set(resolvedVirtualServiceWorkerId(worker.name), worker.script);
|
|
731
|
+
return { config: toWranglerWorkerConfig(worker) };
|
|
732
|
+
}),
|
|
733
|
+
virtualModules
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
//#endregion
|
|
737
|
+
//#region src/vite/plugin-context.ts
|
|
738
|
+
const CONFIG_DIR$2 = ".devflare";
|
|
739
|
+
function removeDevflareHandledServeBindings(config) {
|
|
740
|
+
const next = { ...config };
|
|
741
|
+
delete next.workflows;
|
|
742
|
+
delete next.media;
|
|
743
|
+
return next;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Compile a DevflareConfig into the bundle of artefacts the Vite plugin
|
|
747
|
+
* exposes to consumers (wrangler config, cloudflare-plugin programmatic
|
|
748
|
+
* config, auxiliary DO worker, discovered DOs).
|
|
749
|
+
*
|
|
750
|
+
* Mode discriminator:
|
|
751
|
+
* - `'serve'` — materialize names into stable local identifiers
|
|
752
|
+
* (miniflare-friendly).
|
|
753
|
+
* - `'build'` — preserve names in the emitted Wrangler artefact so deploy
|
|
754
|
+
* can later resolve them against the real Cloudflare account.
|
|
755
|
+
*/
|
|
756
|
+
async function buildPluginContextState(projectRoot, devflareConfig, environment, mode = "serve", configDir = projectRoot) {
|
|
757
|
+
const effectiveConfig = await resolveConfigEnvVars(mode === "build" ? await resolveResources(devflareConfig, {
|
|
758
|
+
phase: "build",
|
|
759
|
+
environment
|
|
760
|
+
}) : await resolveResources(devflareConfig, {
|
|
761
|
+
phase: "local",
|
|
762
|
+
environment
|
|
763
|
+
}), {
|
|
764
|
+
cwd: configDir,
|
|
765
|
+
mode: mode === "build" ? "build" : "dev"
|
|
766
|
+
});
|
|
767
|
+
const compiledWranglerConfig = mode === "build" ? compileBuildConfig(effectiveConfig) : compileConfig(effectiveConfig);
|
|
768
|
+
const wranglerConfig = mode === "build" ? isolateViteBuildOutputPaths(projectRoot, compiledWranglerConfig) : removeDevflareHandledServeBindings(compiledWranglerConfig);
|
|
769
|
+
const cloudflareConfig = { ...mode === "build" ? isolateViteBuildOutputPaths(projectRoot, compileToProgrammaticConfig(effectiveConfig, environment, { preserveNamedBindings: true })) : removeDevflareHandledServeBindings(compileToProgrammaticConfig(effectiveConfig, environment)) };
|
|
770
|
+
const composedMainEntry = mode === "build" ? null : await prepareComposedWorkerEntrypoint(projectRoot, effectiveConfig, environment);
|
|
771
|
+
if (composedMainEntry) {
|
|
772
|
+
const relativeMain = relative(projectRoot, composedMainEntry);
|
|
773
|
+
wranglerConfig.main = relativeMain;
|
|
774
|
+
cloudflareConfig.main = relativeMain;
|
|
775
|
+
}
|
|
776
|
+
let durableObjects = null;
|
|
777
|
+
let auxiliaryWorkerConfig = null;
|
|
778
|
+
let serviceWorkerVirtualModules = /* @__PURE__ */ new Map();
|
|
779
|
+
let serviceAuxiliaryWorkerConfigs = [];
|
|
780
|
+
const doPatternConfig = effectiveConfig.files?.durableObjects;
|
|
781
|
+
const doPattern = typeof doPatternConfig === "string" ? doPatternConfig : DEFAULT_DO_PATTERN;
|
|
782
|
+
if (doPatternConfig !== false) {
|
|
783
|
+
const doWorkerName = `${wranglerConfig.name}-do`;
|
|
784
|
+
const discovery = await discoverDurableObjects(projectRoot, doPattern, doWorkerName);
|
|
785
|
+
if (discovery.files.size > 0) {
|
|
786
|
+
durableObjects = discovery;
|
|
787
|
+
if (wranglerConfig.durable_objects?.bindings) for (const binding of wranglerConfig.durable_objects.bindings) binding.script_name = doWorkerName;
|
|
788
|
+
if (cloudflareConfig.durable_objects) {
|
|
789
|
+
const doConfig = cloudflareConfig.durable_objects;
|
|
790
|
+
for (const binding of doConfig.bindings) binding.script_name = doWorkerName;
|
|
791
|
+
}
|
|
792
|
+
auxiliaryWorkerConfig = createAuxiliaryWorkerConfig(wranglerConfig, discovery);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
if (mode === "serve" && effectiveConfig.bindings?.services) {
|
|
796
|
+
const serviceWorkers = createAuxiliaryServiceWorkerConfigs(await resolveServiceBindings(effectiveConfig, configDir));
|
|
797
|
+
serviceAuxiliaryWorkerConfigs = serviceWorkers.auxiliaryWorkers;
|
|
798
|
+
serviceWorkerVirtualModules = serviceWorkers.virtualModules;
|
|
799
|
+
}
|
|
800
|
+
return {
|
|
801
|
+
wranglerConfig,
|
|
802
|
+
cloudflareConfig,
|
|
803
|
+
auxiliaryWorkerConfigs: [...auxiliaryWorkerConfig ? [auxiliaryWorkerConfig] : [], ...serviceAuxiliaryWorkerConfigs],
|
|
804
|
+
serviceWorkerVirtualModules,
|
|
805
|
+
durableObjects,
|
|
806
|
+
auxiliaryWorkerConfig
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
async function ensureGeneratedConfigDir$1(projectRoot) {
|
|
810
|
+
const configDir = resolve(projectRoot, CONFIG_DIR$2);
|
|
811
|
+
const fs = await import("node:fs/promises");
|
|
812
|
+
await fs.mkdir(configDir, { recursive: true });
|
|
813
|
+
const gitignorePath = resolve(configDir, ".gitignore");
|
|
814
|
+
try {
|
|
815
|
+
await fs.access(gitignorePath);
|
|
816
|
+
} catch {
|
|
817
|
+
await fs.writeFile(gitignorePath, "*\n", "utf-8");
|
|
818
|
+
}
|
|
819
|
+
return configDir;
|
|
820
|
+
}
|
|
821
|
+
async function writeGeneratedWranglerConfig(projectRoot, wranglerConfig) {
|
|
822
|
+
const configDir = await ensureGeneratedConfigDir$1(projectRoot);
|
|
823
|
+
await writeWranglerConfig(configDir, rebaseWranglerConfigPaths(projectRoot, configDir, wranglerConfig), "wrangler.jsonc");
|
|
824
|
+
}
|
|
825
|
+
async function resolvePluginConfigPath(projectRoot, configPath) {
|
|
826
|
+
if (configPath) return isAbsolute(configPath) ? configPath : resolve(projectRoot, configPath);
|
|
827
|
+
return await resolveConfigPath(projectRoot) ?? null;
|
|
828
|
+
}
|
|
829
|
+
//#endregion
|
|
830
|
+
//#region src/vite/plugin-transform.ts
|
|
831
|
+
const TRANSFORMABLE_EXTENSIONS = [
|
|
832
|
+
".ts",
|
|
833
|
+
".tsx",
|
|
834
|
+
".js"
|
|
835
|
+
];
|
|
836
|
+
/**
|
|
837
|
+
* Returns `true` when devflare may rewrite the given module. Skips
|
|
838
|
+
* `node_modules` and any file that isn't a `.ts`/`.tsx`/`.js`.
|
|
839
|
+
*/
|
|
840
|
+
function isTransformCandidate(id) {
|
|
841
|
+
if (id.includes("node_modules")) return false;
|
|
842
|
+
return TRANSFORMABLE_EXTENSIONS.some((ext) => id.endsWith(ext));
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Worker-entrypoint instrumentation step.
|
|
846
|
+
*
|
|
847
|
+
* Only handles `worker.ts` / `worker.js` files and only when
|
|
848
|
+
* `shouldTransformWorker` accepts them. Returns `null` when this step does
|
|
849
|
+
* not apply, so the caller can fall through to other transforms.
|
|
850
|
+
*/
|
|
851
|
+
async function runWorkerEntryTransform(code, id) {
|
|
852
|
+
if (!id.endsWith("worker.ts") && !id.endsWith("worker.js")) return null;
|
|
853
|
+
const { shouldTransformWorker, transformWorkerEntrypoint } = await import("./worker-entrypoint-CQW77lG8.js").then((n) => n.n);
|
|
854
|
+
if (!shouldTransformWorker(code, id)) return null;
|
|
855
|
+
const result = transformWorkerEntrypoint(code, id);
|
|
856
|
+
if (!result) return null;
|
|
857
|
+
return {
|
|
858
|
+
code: result.code,
|
|
859
|
+
map: result.map
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Durable Object class transform step.
|
|
864
|
+
*
|
|
865
|
+
* Only runs when the user opted in via `doTransforms` and the source mentions
|
|
866
|
+
* `DurableObject` or the `@durableObject` decorator. Returns `null` when this
|
|
867
|
+
* step does not apply.
|
|
868
|
+
*/
|
|
869
|
+
async function runDurableObjectTransform(code, id, options) {
|
|
870
|
+
if (!options.doTransforms) return null;
|
|
871
|
+
if (!code.includes("DurableObject") && !code.includes("@durableObject")) return null;
|
|
872
|
+
const { transformDurableObject } = await import("./durable-object-DMtH0XYX.js").then((n) => n.t);
|
|
873
|
+
return transformDurableObject(code, id);
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Apply devflare's source-level transforms to a single module.
|
|
877
|
+
*
|
|
878
|
+
* Order:
|
|
879
|
+
* 1. Worker-entrypoint instrumentation (`runWorkerEntryTransform`)
|
|
880
|
+
* 2. Durable Object class transform (`runDurableObjectTransform`)
|
|
881
|
+
*
|
|
882
|
+
* Returns `null` when no transform applies, mirroring Vite's transform-hook
|
|
883
|
+
* contract.
|
|
884
|
+
*/
|
|
885
|
+
async function runDevflareTransform(code, id, options) {
|
|
886
|
+
if (!isTransformCandidate(id)) return null;
|
|
887
|
+
const workerResult = await runWorkerEntryTransform(code, id);
|
|
888
|
+
if (workerResult) return workerResult;
|
|
889
|
+
return await runDurableObjectTransform(code, id, options);
|
|
890
|
+
}
|
|
891
|
+
//#endregion
|
|
892
|
+
//#region src/vite/plugin-programmatic.ts
|
|
893
|
+
async function loadProgrammaticDevflareConfig(options) {
|
|
894
|
+
const cwd = options.cwd ?? process.cwd();
|
|
895
|
+
const strategy = options.resolve ?? "offline-local";
|
|
896
|
+
return {
|
|
897
|
+
cwd,
|
|
898
|
+
devflareConfig: await resolveConfigEnvVars(strategy === "remote" ? await loadResolvedConfig({
|
|
899
|
+
cwd,
|
|
900
|
+
configFile: options.configPath,
|
|
901
|
+
environment: options.environment
|
|
902
|
+
}) : await resolveResources(await loadConfig({
|
|
903
|
+
cwd,
|
|
904
|
+
configFile: options.configPath
|
|
905
|
+
}), {
|
|
906
|
+
phase: "local",
|
|
907
|
+
environment: options.environment
|
|
908
|
+
}), {
|
|
909
|
+
cwd,
|
|
910
|
+
configPath: options.configPath,
|
|
911
|
+
mode: strategy === "remote" ? "build" : "dev"
|
|
912
|
+
})
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Single canonical builder for programmatic config artifacts.
|
|
917
|
+
*
|
|
918
|
+
* Both public helpers (`getCloudflareConfig`, `getDevflareConfigs`) project
|
|
919
|
+
* out of this. The function loads the devflare config, prepares the composed
|
|
920
|
+
* worker entrypoint, compiles the wrangler config, derives the matching
|
|
921
|
+
* cloudflare-vite-plugin config (with optional `programmatic` projection),
|
|
922
|
+
* and discovers auxiliary DO workers when applicable.
|
|
923
|
+
*/
|
|
924
|
+
async function buildProgrammaticArtifacts(options, mode) {
|
|
925
|
+
const { cwd, devflareConfig } = await loadProgrammaticDevflareConfig(options);
|
|
926
|
+
const composedMainEntry = await prepareComposedWorkerEntrypoint(cwd, devflareConfig);
|
|
927
|
+
const wranglerConfig = compileConfig(devflareConfig);
|
|
928
|
+
const cloudflareConfig = mode === "programmatic" ? compileToProgrammaticConfig(devflareConfig) : { ...wranglerConfig };
|
|
929
|
+
if (composedMainEntry) {
|
|
930
|
+
const relativeMain = relative(cwd, composedMainEntry);
|
|
931
|
+
wranglerConfig.main = relativeMain;
|
|
932
|
+
cloudflareConfig.main = relativeMain;
|
|
933
|
+
}
|
|
934
|
+
const auxiliaryWorkers = [];
|
|
935
|
+
const doPatternConfig = devflareConfig.files?.durableObjects;
|
|
936
|
+
const doPattern = typeof doPatternConfig === "string" ? doPatternConfig : DEFAULT_DO_PATTERN;
|
|
937
|
+
if (doPatternConfig !== false) {
|
|
938
|
+
const doWorkerName = `${wranglerConfig.name}-do`;
|
|
939
|
+
const discovery = await discoverDurableObjects(cwd, doPattern, doWorkerName);
|
|
940
|
+
if (discovery.files.size > 0) {
|
|
941
|
+
if (cloudflareConfig.durable_objects) {
|
|
942
|
+
const doConfig = cloudflareConfig.durable_objects;
|
|
943
|
+
for (const binding of doConfig.bindings) binding.script_name = doWorkerName;
|
|
944
|
+
}
|
|
945
|
+
auxiliaryWorkers.push(createAuxiliaryWorkerConfig(wranglerConfig, discovery));
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
if (devflareConfig.bindings?.services) {
|
|
949
|
+
const serviceBindingResolution = await resolveServiceBindings(devflareConfig, cwd);
|
|
950
|
+
auxiliaryWorkers.push(...createAuxiliaryServiceWorkerConfigs(serviceBindingResolution).auxiliaryWorkers);
|
|
951
|
+
}
|
|
952
|
+
return {
|
|
953
|
+
cwd,
|
|
954
|
+
devflareConfig,
|
|
955
|
+
composedMainEntry,
|
|
956
|
+
wranglerConfig,
|
|
957
|
+
cloudflareConfig,
|
|
958
|
+
auxiliaryWorkers
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Get cloudflare config for programmatic use with @cloudflare/vite-plugin.
|
|
963
|
+
* Call this in vite.config.ts before setting up plugins.
|
|
964
|
+
*
|
|
965
|
+
* By default the config is resolved **offline** using local stable
|
|
966
|
+
* identifiers (no Cloudflare credentials required — matches the Miniflare /
|
|
967
|
+
* workerd behaviour of `vite dev`). Pass `{ resolve: 'remote' }` to restore
|
|
968
|
+
* the legacy behaviour that talks to the Cloudflare API and fails without
|
|
969
|
+
* credentials (e.g. when you want the programmatic config to reflect real
|
|
970
|
+
* production IDs during an automation script).
|
|
971
|
+
*/
|
|
972
|
+
async function getCloudflareConfig(options = {}) {
|
|
973
|
+
const { cloudflareConfig } = await buildProgrammaticArtifacts(options, "programmatic");
|
|
974
|
+
return cloudflareConfig;
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Get auxiliary worker configs for Durable Objects
|
|
978
|
+
* Use this when configuring @cloudflare/vite-plugin's auxiliaryWorkers option
|
|
979
|
+
*
|
|
980
|
+
* @example
|
|
981
|
+
* ```ts
|
|
982
|
+
* const { cloudflareConfig, auxiliaryWorkers } = await getDevflareConfigs()
|
|
983
|
+
*
|
|
984
|
+
* cloudflare({
|
|
985
|
+
* config: cloudflareConfig,
|
|
986
|
+
* auxiliaryWorkers
|
|
987
|
+
* })
|
|
988
|
+
* ```
|
|
989
|
+
*/
|
|
990
|
+
async function getDevflareConfigs(options = {}) {
|
|
991
|
+
const { cloudflareConfig, auxiliaryWorkers } = await buildProgrammaticArtifacts(options, "wrangler");
|
|
992
|
+
return {
|
|
993
|
+
cloudflareConfig,
|
|
994
|
+
auxiliaryWorkers
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
//#endregion
|
|
998
|
+
//#region src/vite/plugin.ts
|
|
999
|
+
const CONFIG_DIR$1 = ".devflare";
|
|
1000
|
+
function createPluginState() {
|
|
1001
|
+
return {
|
|
1002
|
+
context: {
|
|
1003
|
+
wranglerConfig: null,
|
|
1004
|
+
cloudflareConfig: null,
|
|
1005
|
+
projectRoot: process.cwd(),
|
|
1006
|
+
auxiliaryWorkerConfig: null,
|
|
1007
|
+
auxiliaryWorkerConfigs: [],
|
|
1008
|
+
serviceWorkerVirtualModules: /* @__PURE__ */ new Map(),
|
|
1009
|
+
durableObjects: null
|
|
1010
|
+
},
|
|
1011
|
+
projectRoot: process.cwd(),
|
|
1012
|
+
devflareConfig: null,
|
|
1013
|
+
resolvedPluginConfigPath: null
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Reload `devflare.config.ts`, rebuild the plugin context state, mutate the
|
|
1018
|
+
* shared plugin state in-place, and write the generated wrangler config to
|
|
1019
|
+
* disk. Used by both `configResolved` (initial load) and the `configureServer`
|
|
1020
|
+
* watcher (HMR reload).
|
|
1021
|
+
*/
|
|
1022
|
+
async function loadAndApplyConfig(state, options, mode, onContextUpdated) {
|
|
1023
|
+
state.devflareConfig = await loadConfig({
|
|
1024
|
+
cwd: state.projectRoot,
|
|
1025
|
+
configFile: options.configPath
|
|
1026
|
+
});
|
|
1027
|
+
const pluginState = await buildPluginContextState(state.projectRoot, state.devflareConfig, options.environment, mode, state.resolvedPluginConfigPath ? dirname(state.resolvedPluginConfigPath) : state.projectRoot);
|
|
1028
|
+
Object.assign(state.context, {
|
|
1029
|
+
projectRoot: state.projectRoot,
|
|
1030
|
+
...pluginState
|
|
1031
|
+
});
|
|
1032
|
+
onContextUpdated(state.context);
|
|
1033
|
+
logDiscoveredDurableObjects(state.projectRoot, pluginState.durableObjects);
|
|
1034
|
+
await writeGeneratedWranglerConfig(state.projectRoot, pluginState.wranglerConfig);
|
|
1035
|
+
}
|
|
1036
|
+
let lastPluginContext = createPluginState().context;
|
|
1037
|
+
/**
|
|
1038
|
+
* Get the compiled config context
|
|
1039
|
+
* Can be used by other plugins or CLI commands
|
|
1040
|
+
*/
|
|
1041
|
+
function getPluginContext() {
|
|
1042
|
+
return lastPluginContext;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Devflare Vite Plugin
|
|
1046
|
+
*
|
|
1047
|
+
* @example
|
|
1048
|
+
* ```ts
|
|
1049
|
+
* // vite.config.ts
|
|
1050
|
+
* import { defineConfig } from 'vite'
|
|
1051
|
+
* import { sveltekit } from '@sveltejs/kit/vite'
|
|
1052
|
+
* import { devflarePlugin, getPluginContext } from 'devflare/vite'
|
|
1053
|
+
* import { cloudflare } from '@cloudflare/vite-plugin'
|
|
1054
|
+
*
|
|
1055
|
+
* export default defineConfig(async () => {
|
|
1056
|
+
* // First, run devflare to get context
|
|
1057
|
+
* const lfPlugin = devflarePlugin()
|
|
1058
|
+
*
|
|
1059
|
+
* return {
|
|
1060
|
+
* plugins: [
|
|
1061
|
+
* lfPlugin,
|
|
1062
|
+
* sveltekit(),
|
|
1063
|
+
* // Access context after configResolved
|
|
1064
|
+
* cloudflare({
|
|
1065
|
+
* config: getPluginContext().cloudflareConfig,
|
|
1066
|
+
* auxiliaryWorkers: getPluginContext().auxiliaryWorkerConfigs.length > 0
|
|
1067
|
+
* ? getPluginContext().auxiliaryWorkerConfigs
|
|
1068
|
+
* : undefined
|
|
1069
|
+
* })
|
|
1070
|
+
* ]
|
|
1071
|
+
* }
|
|
1072
|
+
* })
|
|
1073
|
+
* ```
|
|
1074
|
+
*/
|
|
1075
|
+
function devflarePlugin(options = {}) {
|
|
1076
|
+
const { configPath, environment, doTransforms = true, watchConfig = true, bridgePort = process.env.DEVFLARE_BRIDGE_PORT ? Number.parseInt(process.env.DEVFLARE_BRIDGE_PORT, 10) : void 0, wsProxyPatterns = [] } = options;
|
|
1077
|
+
const state = createPluginState();
|
|
1078
|
+
return {
|
|
1079
|
+
name: "devflare",
|
|
1080
|
+
enforce: "pre",
|
|
1081
|
+
async config(config, { command }) {
|
|
1082
|
+
return buildPluginConfigHookResult(config.root ?? process.cwd(), {
|
|
1083
|
+
configPath,
|
|
1084
|
+
bridgePort,
|
|
1085
|
+
wsProxyPatterns
|
|
1086
|
+
}, command, config.define ?? {});
|
|
1087
|
+
},
|
|
1088
|
+
resolveId(id) {
|
|
1089
|
+
if (id === "virtual:devflare-do-entry") return RESOLVED_VIRTUAL_DO_ENTRY;
|
|
1090
|
+
if (id.startsWith("virtual:devflare-service-worker/")) return "\0" + id;
|
|
1091
|
+
return null;
|
|
1092
|
+
},
|
|
1093
|
+
async load(id) {
|
|
1094
|
+
if (id === "\0virtual:devflare-do-entry") {
|
|
1095
|
+
if (!state.context.durableObjects) return "// No Durable Objects configured\nexport default { fetch: () => new Response(\"No DOs\") }";
|
|
1096
|
+
return generateVirtualDOEntry(state.context.durableObjects);
|
|
1097
|
+
}
|
|
1098
|
+
if (id.startsWith("\0virtual:devflare-service-worker/")) return state.context.serviceWorkerVirtualModules.get(id) ?? null;
|
|
1099
|
+
return null;
|
|
1100
|
+
},
|
|
1101
|
+
async configResolved(config) {
|
|
1102
|
+
state.projectRoot = config.root;
|
|
1103
|
+
state.context.projectRoot = state.projectRoot;
|
|
1104
|
+
state.resolvedPluginConfigPath = await resolvePluginConfigPath(state.projectRoot, configPath);
|
|
1105
|
+
try {
|
|
1106
|
+
await loadAndApplyConfig(state, {
|
|
1107
|
+
configPath,
|
|
1108
|
+
environment
|
|
1109
|
+
}, config.command === "build" ? "build" : "serve", (ctx) => {
|
|
1110
|
+
lastPluginContext = ctx;
|
|
1111
|
+
});
|
|
1112
|
+
if (config.command === "serve") {
|
|
1113
|
+
console.log("[devflare] Config generated to .devflare/wrangler.jsonc");
|
|
1114
|
+
if (state.context.auxiliaryWorkerConfig) console.log("[devflare] ✓ Auxiliary DO worker configured");
|
|
1115
|
+
}
|
|
1116
|
+
if (config.command === "build") console.log(`[devflare] Generated ${CONFIG_DIR$1}/wrangler.jsonc`);
|
|
1117
|
+
} catch (error) {
|
|
1118
|
+
if (error instanceof Error) console.error("[devflare] Config error:", error.message);
|
|
1119
|
+
throw error;
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
configureServer(server) {
|
|
1123
|
+
if (!watchConfig) return;
|
|
1124
|
+
const fullConfigPath = state.resolvedPluginConfigPath ?? resolve(state.projectRoot, configPath || "devflare.config.ts");
|
|
1125
|
+
server.watcher.add(fullConfigPath);
|
|
1126
|
+
server.watcher.on("change", async (changedPath) => {
|
|
1127
|
+
if (changedPath === fullConfigPath) {
|
|
1128
|
+
console.log("[devflare] Config changed, reloading...");
|
|
1129
|
+
try {
|
|
1130
|
+
await loadAndApplyConfig(state, {
|
|
1131
|
+
configPath,
|
|
1132
|
+
environment
|
|
1133
|
+
}, "serve", (ctx) => {
|
|
1134
|
+
lastPluginContext = ctx;
|
|
1135
|
+
});
|
|
1136
|
+
console.log("[devflare] Config reloaded");
|
|
1137
|
+
server.ws.send({
|
|
1138
|
+
type: "full-reload",
|
|
1139
|
+
path: "*"
|
|
1140
|
+
});
|
|
1141
|
+
} catch (error) {
|
|
1142
|
+
console.error("[devflare] Failed to reload config:", error);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
},
|
|
1147
|
+
async transform(code, id) {
|
|
1148
|
+
return runDevflareTransform(code, id, { doTransforms });
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
//#endregion
|
|
1153
|
+
//#region src/vite/config-file.ts
|
|
1154
|
+
const CONFIG_DIR = ".devflare";
|
|
1155
|
+
const GENERATED_VITE_CONFIG_FILENAME = "vite.config.mjs";
|
|
1156
|
+
function hasInlineViteConfig(viteConfig) {
|
|
1157
|
+
return Boolean(viteConfig && Object.keys(viteConfig).length > 0);
|
|
1158
|
+
}
|
|
1159
|
+
function resolveEffectiveViteProject(detection, config, environment) {
|
|
1160
|
+
const hasDevflareConfig = hasInlineViteConfig(resolveConfigForEnvironment(config, environment).vite);
|
|
1161
|
+
return {
|
|
1162
|
+
...detection,
|
|
1163
|
+
hasDevflareViteConfig: hasDevflareConfig,
|
|
1164
|
+
shouldStartVite: detection.shouldStartVite || hasDevflareConfig,
|
|
1165
|
+
wantsViteIntegration: detection.wantsViteIntegration || hasDevflareConfig
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
function isPromiseLike(value) {
|
|
1169
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
1170
|
+
}
|
|
1171
|
+
function normalizePluginOptions(pluginOption) {
|
|
1172
|
+
if (typeof pluginOption === "undefined") return [];
|
|
1173
|
+
return Array.isArray(pluginOption) ? pluginOption : [pluginOption];
|
|
1174
|
+
}
|
|
1175
|
+
function removePluginByName(pluginOption, pluginName) {
|
|
1176
|
+
if (Array.isArray(pluginOption)) {
|
|
1177
|
+
const filteredPlugins = pluginOption.map((nestedPlugin) => removePluginByName(nestedPlugin, pluginName)).filter((nestedPlugin) => typeof nestedPlugin !== "undefined");
|
|
1178
|
+
return filteredPlugins.length > 0 ? filteredPlugins : void 0;
|
|
1179
|
+
}
|
|
1180
|
+
if (!pluginOption || typeof pluginOption === "boolean" || isPromiseLike(pluginOption)) return pluginOption;
|
|
1181
|
+
return pluginOption.name === pluginName ? void 0 : pluginOption;
|
|
1182
|
+
}
|
|
1183
|
+
function withInjectedDevflarePlugin(config, pluginOptions) {
|
|
1184
|
+
const existingPlugins = normalizePluginOptions(config.plugins).map((pluginOption) => removePluginByName(pluginOption, "devflare")).filter((pluginOption) => typeof pluginOption !== "undefined");
|
|
1185
|
+
return {
|
|
1186
|
+
...config,
|
|
1187
|
+
plugins: [devflarePlugin(pluginOptions), ...existingPlugins]
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
async function resolveViteUserConfig(configEnv, options = {}) {
|
|
1191
|
+
const { loadConfigFromFile, mergeConfig } = await import("vite");
|
|
1192
|
+
const cwd = options.cwd ?? process.cwd();
|
|
1193
|
+
const inlineViteConfig = resolveConfigForEnvironment(await loadConfig({
|
|
1194
|
+
cwd,
|
|
1195
|
+
configFile: options.configPath
|
|
1196
|
+
}), options.environment).vite ?? {};
|
|
1197
|
+
const mergedConfig = mergeConfig(options.localConfigPath ? (await loadConfigFromFile(configEnv, options.localConfigPath, cwd))?.config ?? {} : {}, inlineViteConfig);
|
|
1198
|
+
return withInjectedDevflarePlugin(mergedConfig.root ? mergedConfig : {
|
|
1199
|
+
...mergedConfig,
|
|
1200
|
+
root: cwd
|
|
1201
|
+
}, {
|
|
1202
|
+
configPath: options.configPath,
|
|
1203
|
+
environment: options.environment,
|
|
1204
|
+
bridgePort: options.bridgePort
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
async function ensureGeneratedConfigDir(cwd) {
|
|
1208
|
+
const fs = await import("node:fs/promises");
|
|
1209
|
+
const { resolve } = await import("pathe");
|
|
1210
|
+
const configDir = resolve(cwd, CONFIG_DIR);
|
|
1211
|
+
await fs.mkdir(configDir, { recursive: true });
|
|
1212
|
+
const gitignorePath = resolve(configDir, ".gitignore");
|
|
1213
|
+
try {
|
|
1214
|
+
await fs.access(gitignorePath);
|
|
1215
|
+
} catch {
|
|
1216
|
+
await fs.writeFile(gitignorePath, "*\n", "utf-8");
|
|
1217
|
+
}
|
|
1218
|
+
return configDir;
|
|
1219
|
+
}
|
|
1220
|
+
async function resolveDevflarePackageRoot(currentFilePath) {
|
|
1221
|
+
const fs = await import("node:fs/promises");
|
|
1222
|
+
const { dirname, resolve } = await import("pathe");
|
|
1223
|
+
let currentDir = dirname(currentFilePath);
|
|
1224
|
+
while (true) {
|
|
1225
|
+
const packageJsonPath = resolve(currentDir, "package.json");
|
|
1226
|
+
try {
|
|
1227
|
+
if (JSON.parse(await fs.readFile(packageJsonPath, "utf-8")).name === "devflare") return currentDir;
|
|
1228
|
+
} catch {}
|
|
1229
|
+
const parentDir = dirname(currentDir);
|
|
1230
|
+
if (parentDir === currentDir) break;
|
|
1231
|
+
currentDir = parentDir;
|
|
1232
|
+
}
|
|
1233
|
+
throw new Error("Could not resolve the devflare package root for generated Vite config imports.");
|
|
1234
|
+
}
|
|
1235
|
+
async function resolveGeneratedViteImportPath(configDir) {
|
|
1236
|
+
const { fileURLToPath } = await import("node:url");
|
|
1237
|
+
const { extname, normalize, relative, resolve } = await import("pathe");
|
|
1238
|
+
const currentFilePath = normalize(fileURLToPath(import.meta.url));
|
|
1239
|
+
const currentExtension = extname(currentFilePath);
|
|
1240
|
+
const packageRoot = await resolveDevflarePackageRoot(currentFilePath);
|
|
1241
|
+
const relativeImportPath = relative(configDir, currentFilePath.includes("/dist/") ? resolve(packageRoot, "dist/vite/index.js") : resolve(packageRoot, `src/vite/index${currentExtension}`));
|
|
1242
|
+
return relativeImportPath.startsWith(".") ? relativeImportPath : `./${relativeImportPath}`;
|
|
1243
|
+
}
|
|
1244
|
+
async function writeGeneratedViteConfig(options) {
|
|
1245
|
+
const fs = await import("node:fs/promises");
|
|
1246
|
+
const { resolve } = await import("pathe");
|
|
1247
|
+
const configDir = await ensureGeneratedConfigDir(options.cwd);
|
|
1248
|
+
const generatedConfigPath = resolve(configDir, GENERATED_VITE_CONFIG_FILENAME);
|
|
1249
|
+
const viteImportPath = await resolveGeneratedViteImportPath(configDir);
|
|
1250
|
+
const content = `import { defineConfig } from 'vite'
|
|
1251
|
+
import { resolveViteUserConfig } from ${JSON.stringify(viteImportPath)}
|
|
1252
|
+
|
|
1253
|
+
export default defineConfig(async (env) => {
|
|
1254
|
+
return await resolveViteUserConfig(env, {
|
|
1255
|
+
cwd: ${JSON.stringify(options.cwd)},
|
|
1256
|
+
configPath: ${JSON.stringify(options.configPath)},
|
|
1257
|
+
environment: ${JSON.stringify(options.environment)},
|
|
1258
|
+
localConfigPath: ${JSON.stringify(options.localConfigPath)},
|
|
1259
|
+
bridgePort: ${JSON.stringify(options.bridgePort)}
|
|
1260
|
+
})
|
|
1261
|
+
})
|
|
1262
|
+
`;
|
|
1263
|
+
await fs.writeFile(generatedConfigPath, content, "utf-8");
|
|
1264
|
+
return generatedConfigPath;
|
|
1265
|
+
}
|
|
1266
|
+
//#endregion
|
|
1267
|
+
export { devflarePlugin as a, getDevflareConfigs as c, DEFAULT_FETCH_ENTRY_FILES as d, DEFAULT_QUEUE_ENTRY_FILES as f, discoverDurableObjectFiles as g, resolveWorkerSurfacePaths as h, writeGeneratedViteConfig as i, prepareComposedWorkerEntrypoint as l, hasWorkerSurfacePaths as m, resolveEffectiveViteProject as n, getPluginContext as o, DEFAULT_SCHEDULED_ENTRY_FILES as p, resolveViteUserConfig as r, getCloudflareConfig as s, hasInlineViteConfig as t, DEFAULT_EMAIL_ENTRY_FILES as u };
|