eve 0.29.3 → 0.29.5

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.
Files changed (326) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/src/acp/adapter.d.ts +43 -0
  3. package/dist/src/acp/adapter.js +1 -0
  4. package/dist/src/acp/line-limit.d.ts +3 -0
  5. package/dist/src/acp/line-limit.js +1 -0
  6. package/dist/src/acp/server.d.ts +24 -0
  7. package/dist/src/acp/server.js +1 -0
  8. package/dist/src/channel/clear-session.d.ts +4 -0
  9. package/dist/src/channel/clear-session.js +1 -0
  10. package/dist/src/channel/compact-session.d.ts +4 -0
  11. package/dist/src/channel/compact-session.js +1 -0
  12. package/dist/src/channel/routes.d.ts +34 -6
  13. package/dist/src/channel/types.d.ts +61 -9
  14. package/dist/src/chunks/{use-eve-agent-DaH3cf8K.js → use-eve-agent-BXMIf5fR.js} +130 -11
  15. package/dist/src/chunks/{use-eve-agent-CyDt3Lny.js → use-eve-agent-k-XHfrJT.js} +130 -11
  16. package/dist/src/cli/acp/command.d.ts +22 -0
  17. package/dist/src/cli/acp/command.js +4 -0
  18. package/dist/src/cli/commands/agent-prompt/build-and-verify.md +4 -0
  19. package/dist/src/cli/commands/extension-init.js +1 -1
  20. package/dist/src/cli/commands/init-git.js +1 -1
  21. package/dist/src/cli/commands/init-repl.js +1 -1
  22. package/dist/src/cli/commands/init.js +1 -1
  23. package/dist/src/cli/commands/logs.js +2 -2
  24. package/dist/src/cli/commands/register-integration-commands.js +1 -1
  25. package/dist/src/cli/commands/register-registry-commands.js +1 -1
  26. package/dist/src/cli/commands/registry-project.js +1 -1
  27. package/dist/src/cli/commands/registry-setup-command.js +1 -1
  28. package/dist/src/cli/commands/registry.d.ts +14 -2
  29. package/dist/src/cli/commands/registry.js +1 -1
  30. package/dist/src/cli/commands/trace.d.ts +2 -2
  31. package/dist/src/cli/dev/command-options.d.ts +22 -0
  32. package/dist/src/cli/dev/command-options.js +1 -0
  33. package/dist/src/cli/dev/diagnostic-dump.js +1 -1
  34. package/dist/src/cli/dev/diagnostic-sink.js +1 -1
  35. package/dist/src/cli/dev/local-server-cleanup.js +1 -1
  36. package/dist/src/cli/dev/local-server-process.js +1 -1
  37. package/dist/src/cli/dev/tui/command-typeahead.js +1 -1
  38. package/dist/src/cli/dev/tui/message-queue.d.ts +9 -13
  39. package/dist/src/cli/dev/tui/message-queue.js +1 -1
  40. package/dist/src/cli/dev/tui/prompt-commands.d.ts +13 -5
  41. package/dist/src/cli/dev/tui/prompt-commands.js +1 -1
  42. package/dist/src/cli/dev/tui/remote-auth.d.ts +6 -3
  43. package/dist/src/cli/dev/tui/remote-connection-probe.js +1 -1
  44. package/dist/src/cli/dev/tui/runner.d.ts +7 -7
  45. package/dist/src/cli/dev/tui/runner.js +1 -1
  46. package/dist/src/cli/dev/tui/stream-format.d.ts +14 -0
  47. package/dist/src/cli/dev/tui/stream-format.js +2 -2
  48. package/dist/src/cli/dev/tui/subagent-pump.d.ts +5 -5
  49. package/dist/src/cli/dev/tui/terminal-background.d.ts +23 -0
  50. package/dist/src/cli/dev/tui/terminal-background.js +1 -0
  51. package/dist/src/cli/dev/tui/terminal-renderer.js +12 -12
  52. package/dist/src/cli/dev/tui/traces/trace-content.d.ts +7 -0
  53. package/dist/src/cli/dev/tui/traces/trace-content.js +2 -2
  54. package/dist/src/cli/dev/tui/traces/trace-conversation.d.ts +10 -5
  55. package/dist/src/cli/dev/tui/traces/trace-conversation.js +1 -1
  56. package/dist/src/cli/dev/tui/traces/trace-store.js +1 -1
  57. package/dist/src/cli/dev/tui/traces/trace-surfaces.d.ts +40 -0
  58. package/dist/src/cli/dev/tui/traces/trace-surfaces.js +1 -0
  59. package/dist/src/cli/dev/tui/traces/trace-view.d.ts +8 -1
  60. package/dist/src/cli/dev/tui/traces/trace-view.js +2 -2
  61. package/dist/src/cli/dev/tui/traces/trace-viewer-session.d.ts +13 -0
  62. package/dist/src/cli/dev/tui/traces/trace-viewer-session.js +1 -1
  63. package/dist/src/cli/dev/tui/traces/trace-viewer-state.js +1 -1
  64. package/dist/src/cli/dev/tui/tui.js +1 -1
  65. package/dist/src/cli/invoke/invoke.js +1 -1
  66. package/dist/src/cli/invoke/result.js +1 -1
  67. package/dist/src/cli/run.d.ts +3 -0
  68. package/dist/src/cli/run.js +3 -3
  69. package/dist/src/cli/ui/terminal-text.d.ts +0 -3
  70. package/dist/src/cli/ui/terminal-text.js +1 -1
  71. package/dist/src/client/agent-info-schema.d.ts +2 -2
  72. package/dist/src/client/agent-info-schema.js +1 -1
  73. package/dist/src/client/index.d.ts +1 -1
  74. package/dist/src/client/open-stream.js +1 -1
  75. package/dist/src/client/session.d.ts +29 -1
  76. package/dist/src/client/session.js +1 -1
  77. package/dist/src/client/types.d.ts +29 -0
  78. package/dist/src/compiled/.vendor-stamp.json +2 -1
  79. package/dist/src/compiled/@agentclientprotocol/sdk/LICENSE +191 -0
  80. package/dist/src/compiled/@agentclientprotocol/sdk/index.d.ts +1835 -0
  81. package/dist/src/compiled/@agentclientprotocol/sdk/index.js +65 -0
  82. package/dist/src/compiled/@agentclientprotocol/sdk/jsonrpc.d.ts +603 -0
  83. package/dist/src/compiled/@agentclientprotocol/sdk/schema/guards.gen.d.ts +199 -0
  84. package/dist/src/compiled/@agentclientprotocol/sdk/schema/index.d.ts +51 -0
  85. package/dist/src/compiled/@agentclientprotocol/sdk/schema/types.gen.d.ts +6118 -0
  86. package/dist/src/compiled/@agentclientprotocol/sdk/stream.d.ts +35 -0
  87. package/dist/src/compiler/artifacts.js +1 -1
  88. package/dist/src/compiler/extension-compatibility.d.ts +8 -8
  89. package/dist/src/compiler/extension-compatibility.js +1 -1
  90. package/dist/src/compiler/manifest.d.ts +11 -22
  91. package/dist/src/compiler/manifest.js +1 -1
  92. package/dist/src/compiler/model-catalog.js +1 -1
  93. package/dist/src/compiler/normalize-agent-config.d.ts +3 -1
  94. package/dist/src/compiler/normalize-agent-config.js +1 -1
  95. package/dist/src/compiler/normalize-manifest.js +1 -1
  96. package/dist/src/compiler/normalize-sandbox.js +1 -1
  97. package/dist/src/compiler/normalize-subagent.d.ts +1 -0
  98. package/dist/src/compiler/normalize-subagent.js +1 -1
  99. package/dist/src/compiler/remote-agent-node.d.ts +3 -0
  100. package/dist/src/compiler/workspace-resources.js +1 -1
  101. package/dist/src/context/dynamic-subagent-lifecycle.d.ts +22 -0
  102. package/dist/src/context/dynamic-subagent-lifecycle.js +1 -0
  103. package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
  104. package/dist/src/context/keys.d.ts +13 -2
  105. package/dist/src/context/keys.js +1 -1
  106. package/dist/src/context/run-step.js +1 -1
  107. package/dist/src/discover/project-source.js +1 -1
  108. package/dist/src/evals/cli/eval.js +2 -2
  109. package/dist/src/evals/loaders/json.js +1 -1
  110. package/dist/src/evals/loaders/yaml.js +1 -1
  111. package/dist/src/evals/runner/artifacts.js +1 -1
  112. package/dist/src/evals/runner/discover.js +1 -1
  113. package/dist/src/evals/runner/reporters/junit.js +1 -1
  114. package/dist/src/evals/session.js +1 -1
  115. package/dist/src/execution/create-session-step.d.ts +2 -0
  116. package/dist/src/execution/create-session-step.js +1 -1
  117. package/dist/src/execution/delegation-tool.d.ts +3 -0
  118. package/dist/src/execution/delegation-tool.js +1 -0
  119. package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
  120. package/dist/src/execution/dispatch-workflow-runtime-actions-step.js +1 -1
  121. package/dist/src/execution/effective-agent-config.d.ts +12 -0
  122. package/dist/src/execution/effective-agent-config.js +1 -0
  123. package/dist/src/execution/node-step.d.ts +4 -0
  124. package/dist/src/execution/node-step.js +1 -1
  125. package/dist/src/execution/runtime-context.d.ts +2 -0
  126. package/dist/src/execution/runtime-context.js +1 -1
  127. package/dist/src/execution/sandbox/bindings/docker-cli.js +1 -1
  128. package/dist/src/execution/sandbox/bindings/docker-templates.js +1 -1
  129. package/dist/src/execution/sandbox/bindings/just-bash-runtime.js +1 -1
  130. package/dist/src/execution/sandbox/bindings/just-bash.js +1 -1
  131. package/dist/src/execution/sandbox/bindings/local-backend-utils.js +1 -1
  132. package/dist/src/execution/sandbox/bindings/microsandbox-lifecycle.js +1 -1
  133. package/dist/src/execution/sandbox/bindings/microsandbox-metadata.js +1 -1
  134. package/dist/src/execution/sandbox/bindings/microsandbox-platform.js +1 -1
  135. package/dist/src/execution/sandbox/bindings/microsandbox-runtime.js +1 -1
  136. package/dist/src/execution/sandbox/bindings/microsandbox-templates.js +1 -1
  137. package/dist/src/execution/sandbox/development-cleanup.js +1 -1
  138. package/dist/src/execution/sandbox/template-prewarm-lock.js +1 -1
  139. package/dist/src/execution/session-callback-request.d.ts +5 -0
  140. package/dist/src/execution/session-callback-request.js +1 -0
  141. package/dist/src/execution/session-delivery-hook.d.ts +1 -0
  142. package/dist/src/execution/session-delivery-hook.js +1 -1
  143. package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
  144. package/dist/src/execution/subagent-event-proxy-step.js +1 -1
  145. package/dist/src/execution/workflow-entry.js +1 -1
  146. package/dist/src/execution/workflow-runtime.d.ts +2 -0
  147. package/dist/src/execution/workflow-runtime.js +1 -1
  148. package/dist/src/execution/workflow-steps.js +1 -1
  149. package/dist/src/harness/agent-handles.d.ts +238 -0
  150. package/dist/src/harness/agent-handles.js +2 -0
  151. package/dist/src/harness/attachment-staging.js +1 -1
  152. package/dist/src/harness/compaction.d.ts +1 -1
  153. package/dist/src/harness/compaction.js +1 -1
  154. package/dist/src/harness/tool-loop.js +2 -2
  155. package/dist/src/harness/types.d.ts +16 -0
  156. package/dist/src/internal/application/build-profile.js +1 -1
  157. package/dist/src/internal/application/build-workspace.js +1 -1
  158. package/dist/src/internal/application/cache-metadata.js +1 -1
  159. package/dist/src/internal/application/compiled-artifacts.js +8 -8
  160. package/dist/src/internal/application/optional-package-install.js +2 -2
  161. package/dist/src/internal/application/output-publication-artifacts.js +1 -1
  162. package/dist/src/internal/application/output-publication-journal.js +1 -1
  163. package/dist/src/internal/application/output-publication-lock.js +1 -1
  164. package/dist/src/internal/application/output-publication.js +1 -1
  165. package/dist/src/internal/application/package.js +1 -1
  166. package/dist/src/internal/application/paths.js +1 -1
  167. package/dist/src/internal/application/production-compiler-artifacts.js +1 -1
  168. package/dist/src/internal/application/tsconfig-dependencies.js +1 -1
  169. package/dist/src/internal/authored-asset-import-plugin.js +1 -1
  170. package/dist/src/internal/authored-definition/core.js +1 -1
  171. package/dist/src/internal/authored-module-loader.js +3 -3
  172. package/dist/src/internal/authored-package-tsconfig-paths.js +1 -1
  173. package/dist/src/internal/materialized-authored-modules.js +1 -1
  174. package/dist/src/internal/nitro/dev-runtime-artifacts-retention.js +1 -1
  175. package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
  176. package/dist/src/internal/nitro/dev-runtime-source-snapshot-copy.js +1 -1
  177. package/dist/src/internal/nitro/dev-runtime-source-snapshot.js +1 -1
  178. package/dist/src/internal/nitro/host/build-application.js +1 -1
  179. package/dist/src/internal/nitro/host/build-extension.js +1 -1
  180. package/dist/src/internal/nitro/host/build-vercel-agent-summary.js +1 -1
  181. package/dist/src/internal/nitro/host/configure-nitro-routes.js +3 -3
  182. package/dist/src/internal/nitro/host/copy-host-middleware.js +1 -1
  183. package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
  184. package/dist/src/internal/nitro/host/cron-handler-route.js +1 -1
  185. package/dist/src/internal/nitro/host/dev-authored-rebuild-coordinator.js +1 -1
  186. package/dist/src/internal/nitro/host/dev-authored-source-watcher.js +1 -1
  187. package/dist/src/internal/nitro/host/dev-host-fingerprint.js +1 -1
  188. package/dist/src/internal/nitro/host/dev-host-workspace.js +1 -1
  189. package/dist/src/internal/nitro/host/dev-server-http.js +1 -1
  190. package/dist/src/internal/nitro/host/dev-server-state.js +1 -1
  191. package/dist/src/internal/nitro/host/dev-workspace-extensions.js +1 -1
  192. package/dist/src/internal/nitro/host/extension-build-config.js +1 -1
  193. package/dist/src/internal/nitro/host/extension-declarations.js +2 -2
  194. package/dist/src/internal/nitro/host/extension-distribution.js +3 -3
  195. package/dist/src/internal/nitro/host/extension-state-usage.js +1 -1
  196. package/dist/src/internal/nitro/host/normalize-vercel-service-crons.js +1 -1
  197. package/dist/src/internal/nitro/host/start-development-server.js +2 -2
  198. package/dist/src/internal/nitro/host/start-production-server.js +2 -2
  199. package/dist/src/internal/nitro/host/types.d.ts +2 -0
  200. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response-from-manifest.js +1 -1
  201. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.d.ts +1 -1
  202. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.js +1 -1
  203. package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
  204. package/dist/src/internal/vercel/project-link.js +1 -1
  205. package/dist/src/internal/vercel-agent-summary.d.ts +1 -1
  206. package/dist/src/internal/workflow/development-world-client.js +1 -1
  207. package/dist/src/internal/workflow-bundle/builder-support.js +6 -6
  208. package/dist/src/internal/workflow-bundle/builder.js +3 -3
  209. package/dist/src/internal/workflow-bundle/nitro-step-entry.js +2 -2
  210. package/dist/src/internal/workflow-bundle/vercel-workflow-output.js +1 -1
  211. package/dist/src/internal/workflow-bundle/workflow-builders.js +1 -1
  212. package/dist/src/protocol/clear-session.d.ts +14 -0
  213. package/dist/src/protocol/clear-session.js +1 -0
  214. package/dist/src/protocol/compact-session.d.ts +14 -0
  215. package/dist/src/protocol/compact-session.js +1 -0
  216. package/dist/src/protocol/message.d.ts +19 -1
  217. package/dist/src/protocol/message.js +1 -1
  218. package/dist/src/protocol/routes.d.ts +10 -0
  219. package/dist/src/protocol/routes.js +1 -1
  220. package/dist/src/public/channels/discord/discordChannel.js +1 -1
  221. package/dist/src/public/channels/discord/verify.js +1 -1
  222. package/dist/src/public/channels/eve.js +1 -1
  223. package/dist/src/public/channels/github/auth.js +2 -2
  224. package/dist/src/public/channels/github/githubChannel.js +1 -1
  225. package/dist/src/public/channels/github/verify.js +1 -1
  226. package/dist/src/public/channels/index.d.ts +1 -1
  227. package/dist/src/public/channels/linear/inbound.js +2 -2
  228. package/dist/src/public/channels/linear/linearChannel.js +1 -1
  229. package/dist/src/public/channels/linear/verify.js +1 -1
  230. package/dist/src/public/channels/teams/teamsChannel.js +1 -1
  231. package/dist/src/public/channels/telegram/verify.js +1 -1
  232. package/dist/src/public/channels/twilio/twilioChannel.js +1 -1
  233. package/dist/src/public/definitions/agent.d.ts +32 -1
  234. package/dist/src/public/definitions/agent.js +1 -1
  235. package/dist/src/public/definitions/channel.d.ts +5 -2
  236. package/dist/src/public/definitions/channel.js +1 -1
  237. package/dist/src/public/definitions/hook.d.ts +1 -0
  238. package/dist/src/public/definitions/tool.d.ts +4 -1
  239. package/dist/src/public/index.d.ts +1 -2
  240. package/dist/src/public/index.js +1 -1
  241. package/dist/src/public/models/openai/chatgpt/auth.js +1 -1
  242. package/dist/src/public/next/server.js +2 -2
  243. package/dist/src/public/next/vercel-output-config.js +1 -1
  244. package/dist/src/public/nuxt/dev-server.js +1 -1
  245. package/dist/src/public/nuxt/vercel-services.js +1 -1
  246. package/dist/src/public/sveltekit/dev-server.js +1 -1
  247. package/dist/src/public/sveltekit/vercel-json.js +1 -1
  248. package/dist/src/runtime/framework-tools/connection-search-dynamic.d.ts +2 -18
  249. package/dist/src/runtime/framework-tools/connection-search-dynamic.js +2 -2
  250. package/dist/src/runtime/framework-tools/file-state.js +1 -1
  251. package/dist/src/runtime/framework-tools/index.d.ts +7 -2
  252. package/dist/src/runtime/framework-tools/index.js +1 -1
  253. package/dist/src/runtime/resolve-agent-graph.js +1 -1
  254. package/dist/src/runtime/resolve-agent.js +1 -1
  255. package/dist/src/runtime/resolve-dynamic-subagent.d.ts +12 -0
  256. package/dist/src/runtime/resolve-dynamic-subagent.js +1 -0
  257. package/dist/src/runtime/resolve-dynamic-tool.d.ts +15 -0
  258. package/dist/src/runtime/resolve-dynamic-tool.js +1 -1
  259. package/dist/src/runtime/sandbox/keys.js +1 -1
  260. package/dist/src/runtime/subagents/dynamic-agent-config.d.ts +22 -0
  261. package/dist/src/runtime/subagents/dynamic-agent-config.js +1 -0
  262. package/dist/src/runtime/subagents/registry.d.ts +10 -2
  263. package/dist/src/runtime/subagents/registry.js +1 -1
  264. package/dist/src/runtime/types.d.ts +11 -2
  265. package/dist/src/runtime/workspace/seed-files.js +1 -1
  266. package/dist/src/setup/boxes/detect-ai-gateway.js +1 -1
  267. package/dist/src/setup/flows/registry.js +1 -1
  268. package/dist/src/setup/index.d.ts +1 -0
  269. package/dist/src/setup/index.js +1 -1
  270. package/dist/src/setup/integrations/discord/api.d.ts +15 -0
  271. package/dist/src/setup/integrations/discord/api.js +1 -0
  272. package/dist/src/setup/integrations/discord/connect.d.ts +24 -0
  273. package/dist/src/setup/integrations/discord/connect.js +1 -0
  274. package/dist/src/setup/integrations/discord/setup.d.ts +19 -0
  275. package/dist/src/setup/integrations/discord/setup.js +8 -0
  276. package/dist/src/setup/integrations/registry.js +1 -1
  277. package/dist/src/setup/package-manager.js +1 -1
  278. package/dist/src/setup/primitives/pm/pnpm.js +3 -3
  279. package/dist/src/setup/project-resolution.js +1 -1
  280. package/dist/src/setup/prompter.js +1 -1
  281. package/dist/src/setup/registry-setup-client.d.ts +6 -2
  282. package/dist/src/setup/registry-setup-client.js +1 -1
  283. package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
  284. package/dist/src/setup/scaffold/create/extension.js +1 -1
  285. package/dist/src/setup/scaffold/create/project.js +2 -9
  286. package/dist/src/setup/scaffold/files.js +1 -1
  287. package/dist/src/setup/scaffold/update/channels.js +2 -2
  288. package/dist/src/setup/scaffold/update/connections.js +1 -1
  289. package/dist/src/setup/scaffold/workspace-root.js +1 -1
  290. package/dist/src/setup/slack-connect-lifecycle.js +1 -1
  291. package/dist/src/setup/vercel-project-framework.js +1 -1
  292. package/dist/src/shared/agent-definition.d.ts +7 -0
  293. package/dist/src/shared/agent-turn-outcome.d.ts +47 -0
  294. package/dist/src/shared/agent-turn-outcome.js +1 -0
  295. package/dist/src/shared/dynamic-tool-definition.d.ts +1 -5
  296. package/dist/src/shared/dynamic-tool-definition.js +1 -1
  297. package/dist/src/shared/guards.d.ts +2 -0
  298. package/dist/src/shared/guards.js +1 -1
  299. package/dist/src/shared/skill-package.js +1 -1
  300. package/dist/src/shared/skill-paths.d.ts +4 -4
  301. package/dist/src/shared/skill-paths.js +2 -2
  302. package/dist/src/shared/vercel-output-directory.js +1 -1
  303. package/dist/src/source-change/static-source-change.js +1 -1
  304. package/dist/src/svelte/index.js +1 -1
  305. package/dist/src/svelte/use-eve-agent.js +1 -1
  306. package/dist/src/tracing/local-instrumentation-runtime.js +1 -1
  307. package/dist/src/tracing/local-trace-reader.d.ts +22 -5
  308. package/dist/src/tracing/local-trace-reader.js +1 -1
  309. package/dist/src/tracing/local-trace-retention.js +1 -1
  310. package/dist/src/tracing/local-trace-span-processor.js +1 -1
  311. package/dist/src/vue/index.js +1 -1
  312. package/dist/src/vue/use-eve-agent.js +1 -1
  313. package/docs/channels/custom.mdx +41 -1
  314. package/docs/channels/discord.mdx +30 -14
  315. package/docs/channels/eve.mdx +26 -1
  316. package/docs/concepts/default-harness.md +4 -0
  317. package/docs/guides/acp.md +91 -0
  318. package/docs/guides/client/streaming.mdx +38 -0
  319. package/docs/guides/dev-tui.md +10 -7
  320. package/docs/guides/dynamic-capabilities.md +49 -6
  321. package/docs/guides/meta.json +1 -0
  322. package/docs/reference/cli.md +3 -0
  323. package/docs/reference/project-layout.md +1 -1
  324. package/docs/reference/typescript-api.md +48 -48
  325. package/docs/subagents.mdx +32 -2
  326. package/package.json +3 -2
@@ -1,4 +1,4 @@
1
- import{expectObjectRecord}from"#internal/authored-module.js";import{existsSync,mkdirSync,writeFileSync}from"node:fs";import{dirname,join,resolve}from"node:path";import{createHash}from"node:crypto";import{createCompiledModuleMapSource}from"#compiler/module-map.js";import{buildSingleRolldownChunk,buildWithNitroRolldown}from"#internal/bundler/nitro-rolldown.js";import{createAuthoredAssetImportPlugin}from"#internal/authored-asset-import-plugin.js";import{assertNoWorkflowDirectivePrologue}from"#internal/authored-directive-prologue.js";import{createAuthoredModuleBundleError}from"#internal/authored-module-bundle.js";import{createAuthoredModuleEvaluationError}from"#internal/authored-module-evaluation-error.js";import{createAuthoredPackageTsConfigPathsPlugin}from"#internal/authored-package-tsconfig-paths.js";import{createAuthoredRelativeExtensionResolverPlugin}from"#internal/authored-relative-extension-resolver.js";import{createExtensionScopePlugin,createFixedNamespaceScopePlugin}from"#internal/bundler/extension-scope-plugin.js";import{CACHED_CHANNEL_PREFIX,RESOLVE_EXTENSIONS,createDistributionPackageBoundaryPlugin,createGenerationPackageBoundaryPlugin,createRuntimeLoaderPackageBoundaryPlugin,isNodeModulesPath,normalizeExternalDependencies}from"#internal/authored-package-boundary.js";import{createNodeEsmCompatBannerPlugin}from"#internal/node-esm-compat-banner.js";const AUTHORED_BUNDLED_MODULE_EXTENSION=/\.[cm]?[jt]sx?$/,AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH=join(`node_modules`,`.cache`,`eve`,`authored-modules`),CHANNEL_MODULE_CACHE_KEY=`__eveChannelModuleCache__`;function getChannelModuleCache(){return globalThis[CHANNEL_MODULE_CACHE_KEY]}const inFlightModuleLoads=new Map;function loadAuthoredModuleNamespace(e,t={}){let n=createInFlightModuleLoadKey(resolve(e),t),r=inFlightModuleLoads.get(n);if(r!==void 0)return r;let i=(async()=>{try{return await doLoadAuthoredModuleNamespace(e,t)}finally{inFlightModuleLoads.delete(n)}})();return inFlightModuleLoads.set(n,i),i}async function doLoadAuthoredModuleNamespace(t,n){return expectObjectRecord(AUTHORED_BUNDLED_MODULE_EXTENSION.test(t)?await loadBundledAuthoredModule(t,n):await import(createFileImportSpecifier(t)),`Expected "${t}" to export a module namespace object.`)}function createFileImportSpecifier(e){let t=e.replaceAll(`\\`,`/`);return/^[A-Za-z]:\//.test(t)?`file:///${encodeURI(t)}`:t.startsWith(`/`)?`file://${encodeURI(t)}`:t}async function bundleAuthoredModuleCode(e,t={}){return await buildAuthoredModuleBundle(e,t,{channelIdentity:!0,packageBoundaryPlugin:createRuntimeLoaderPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[],sourcemap:`inline`})}async function bundleAuthoredModuleForGeneration(e,t={}){return removeRolldownModuleRegionComments(await buildAuthoredModuleBundle(e,t,{channelIdentity:!1,packageBoundaryPlugin:createGenerationPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[createAuthoredDirectiveGuardPlugin()],sourcemap:!1}))}async function bundleExtensionDistributionGraph(e){let t=[createAuthoredDirectiveGuardPlugin(),createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:e.packageRoot,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),createDistributionPackageBoundaryPlugin({packageRoot:e.packageRoot,runtimeDependencies:e.runtimeDependencies})];try{let n=await buildWithNitroRolldown({cwd:e.packageRoot,input:Object.fromEntries(e.entries.map(e=>[e.name,e.path])),platform:`node`,plugins:t,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:resolveAuthoredTsConfigPath(e.packageRoot),write:!1,output:{chunkFileNames:`_chunks/[name]-[hash].mjs`,codeSplitting:!0,comments:!1,entryFileNames:`[name].mjs`,format:`esm`,sourcemap:!1}}),r=new Map;for(let e of n.output)e.type===`chunk`&&r.set(e.fileName,removeRolldownModuleRegionComments(e.code));return r}catch(t){throw createAuthoredModuleBundleError(e.packageRoot,t)}}async function bundleAuthoredModuleMapForGeneration(e){let t=resolveAuthoredPackageRoot(e.manifest.agentRoot),n=normalizeExternalDependencies([e.manifest,...e.manifest.subagents.map(e=>e.agent)].flatMap(e=>e.config.build?.externalDependencies??[])),r=createCompiledModuleMapSource({manifest:e.manifest,moduleMapPath:e.moduleMapPath}),i=createExtensionScopePlugin(e.manifest.extensionMounts.map(e=>({packageNamespace:e.packageNamespace,sourceRoot:e.sourceRoot}))),a=[createVirtualGenerationModuleMapPlugin({id:e.moduleMapPath,source:r}),createAuthoredDirectiveGuardPlugin(),i,createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:t,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),createGenerationPackageBoundaryPlugin({externalDependencies:n,packageRoot:t})].filter(e=>e!==null);try{return removeRolldownModuleRegionComments((await buildSingleRolldownChunk(`authored module map`,{cwd:t,input:e.moduleMapPath,platform:`node`,plugins:a,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:resolveAuthoredTsConfigPath(t),output:{comments:!1,format:`esm`,sourcemap:!1}})).code)}catch(t){throw createAuthoredModuleBundleError(e.moduleMapPath,t)}}function createVirtualGenerationModuleMapPlugin(e){return{name:`eve-generation-module-map`,resolveId(t){return t===e.id?t:void 0},load(t){return t===e.id?{code:e.source,moduleType:`js`}:void 0}}}async function buildAuthoredModuleBundle(e,t,n){let r=n.channelIdentity?getChannelModuleCache():void 0,i=resolveAuthoredPackageRoot(e),a=resolveAuthoredTsConfigPath(i),s=[r&&r.size>0?{name:`eve-channel-identity`,async resolveId(e,t,n){if(!/channels[/\\]/.test(e)||n.kind!==`import-statement`)return;let i=await this.resolve(e,t,{kind:n.kind,skipSelf:!0});if(i===null||typeof i.id!=`string`)return;let a=resolve(i.id);if(r.has(a))return{id:`${CACHED_CHANNEL_PREFIX}${a}`}},load(e){if(!e.startsWith(CACHED_CHANNEL_PREFIX))return;let t=e.slice(CACHED_CHANNEL_PREFIX.length);return{code:[`const cache = globalThis["${CHANNEL_MODULE_CACHE_KEY}"];`,`export default cache.get(${JSON.stringify(t)});`].join(`
2
- `),moduleType:`js`}}}:null,...n.plugins,t.extensionScopeNamespace===void 0?null:createFixedNamespaceScopePlugin(t.extensionScopeNamespace),createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:i,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),n.packageBoundaryPlugin].filter(e=>e!==null);try{return(await buildSingleRolldownChunk(`authored module for "${e}"`,{cwd:i,input:e,platform:`node`,plugins:s,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:a,output:{comments:!1,format:`esm`,sourcemap:n.sourcemap}})).code}catch(t){throw createAuthoredModuleBundleError(e,t)}}function createAuthoredDirectiveGuardPlugin(){return{name:`eve-authored-directive-guard`,async transform(e,t){!AUTHORED_BUNDLED_MODULE_EXTENSION.test(t)||isNodeModulesPath(t)||await assertNoWorkflowDirectivePrologue({filePath:t,source:e})}}}function removeRolldownModuleRegionComments(e){return e.split(`
1
+ import{createHash}from"node:crypto";import{expectObjectRecord}from"#internal/authored-module.js";import{existsSync,mkdirSync,writeFileSync}from"node:fs";import{dirname,join,resolve}from"node:path";import{createCompiledModuleMapSource}from"#compiler/module-map.js";import{buildSingleRolldownChunk,buildWithNitroRolldown}from"#internal/bundler/nitro-rolldown.js";import{createAuthoredAssetImportPlugin}from"#internal/authored-asset-import-plugin.js";import{assertNoWorkflowDirectivePrologue}from"#internal/authored-directive-prologue.js";import{createAuthoredModuleBundleError}from"#internal/authored-module-bundle.js";import{createAuthoredModuleEvaluationError}from"#internal/authored-module-evaluation-error.js";import{createAuthoredPackageTsConfigPathsPlugin}from"#internal/authored-package-tsconfig-paths.js";import{createAuthoredRelativeExtensionResolverPlugin}from"#internal/authored-relative-extension-resolver.js";import{createExtensionScopePlugin,createFixedNamespaceScopePlugin}from"#internal/bundler/extension-scope-plugin.js";import{CACHED_CHANNEL_PREFIX,RESOLVE_EXTENSIONS,createDistributionPackageBoundaryPlugin,createGenerationPackageBoundaryPlugin,createRuntimeLoaderPackageBoundaryPlugin,isNodeModulesPath,normalizeExternalDependencies}from"#internal/authored-package-boundary.js";import{createNodeEsmCompatBannerPlugin}from"#internal/node-esm-compat-banner.js";const AUTHORED_BUNDLED_MODULE_EXTENSION=/\.[cm]?[jt]sx?$/,AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH=join(`node_modules`,`.cache`,`eve`,`authored-modules`),CHANNEL_MODULE_CACHE_KEY=`__eveChannelModuleCache__`;function getChannelModuleCache(){return globalThis[CHANNEL_MODULE_CACHE_KEY]}const inFlightModuleLoads=new Map;function loadAuthoredModuleNamespace(e,t={}){let n=createInFlightModuleLoadKey(resolve(e),t),r=inFlightModuleLoads.get(n);if(r!==void 0)return r;let i=(async()=>{try{return await doLoadAuthoredModuleNamespace(e,t)}finally{inFlightModuleLoads.delete(n)}})();return inFlightModuleLoads.set(n,i),i}async function doLoadAuthoredModuleNamespace(e,n){return expectObjectRecord(AUTHORED_BUNDLED_MODULE_EXTENSION.test(e)?await loadBundledAuthoredModule(e,n):await import(createFileImportSpecifier(e)),`Expected "${e}" to export a module namespace object.`)}function createFileImportSpecifier(e){let t=e.replaceAll(`\\`,`/`);return/^[A-Za-z]:\//.test(t)?`file:///${encodeURI(t)}`:t.startsWith(`/`)?`file://${encodeURI(t)}`:t}async function bundleAuthoredModuleCode(e,t={}){return await buildAuthoredModuleBundle(e,t,{channelIdentity:!0,packageBoundaryPlugin:createRuntimeLoaderPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[],sourcemap:`inline`})}async function bundleAuthoredModuleForGeneration(e,t={}){return removeRolldownModuleRegionComments(await buildAuthoredModuleBundle(e,t,{channelIdentity:!1,packageBoundaryPlugin:createGenerationPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[createAuthoredDirectiveGuardPlugin()],sourcemap:!1}))}async function bundleExtensionDistributionGraph(e){let t=[createAuthoredDirectiveGuardPlugin(),createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:e.packageRoot,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),createDistributionPackageBoundaryPlugin({packageRoot:e.packageRoot,runtimeDependencies:e.runtimeDependencies})];try{let n=await buildWithNitroRolldown({cwd:e.packageRoot,input:Object.fromEntries(e.entries.map(e=>[e.name,e.path])),platform:`node`,plugins:t,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:resolveAuthoredTsConfigPath(e.packageRoot),write:!1,output:{chunkFileNames:`_chunks/[name]-[hash].mjs`,codeSplitting:!0,comments:!1,entryFileNames:`[name].mjs`,format:`esm`,sourcemap:!1}}),r=new Map;for(let e of n.output)e.type===`chunk`&&r.set(e.fileName,removeRolldownModuleRegionComments(e.code));return r}catch(t){throw createAuthoredModuleBundleError(e.packageRoot,t)}}async function bundleAuthoredModuleMapForGeneration(e){let t=resolveAuthoredPackageRoot(e.manifest.agentRoot),n=normalizeExternalDependencies([e.manifest,...e.manifest.subagents.map(e=>e.agent)].flatMap(e=>e.config.build?.externalDependencies??[])),r=createCompiledModuleMapSource({manifest:e.manifest,moduleMapPath:e.moduleMapPath}),i=createExtensionScopePlugin(e.manifest.extensionMounts.map(e=>({packageNamespace:e.packageNamespace,sourceRoot:e.sourceRoot}))),a=[createVirtualGenerationModuleMapPlugin({id:e.moduleMapPath,source:r}),createAuthoredDirectiveGuardPlugin(),i,createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:t,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),createGenerationPackageBoundaryPlugin({externalDependencies:n,packageRoot:t})].filter(e=>e!==null);try{return removeRolldownModuleRegionComments((await buildSingleRolldownChunk(`authored module map`,{cwd:t,input:e.moduleMapPath,platform:`node`,plugins:a,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:resolveAuthoredTsConfigPath(t),output:{comments:!1,format:`esm`,sourcemap:!1}})).code)}catch(t){throw createAuthoredModuleBundleError(e.moduleMapPath,t)}}function createVirtualGenerationModuleMapPlugin(e){return{name:`eve-generation-module-map`,resolveId(t){return t===e.id?t:void 0},load(t){return t===e.id?{code:e.source,moduleType:`js`}:void 0}}}async function buildAuthoredModuleBundle(e,t,n){let r=n.channelIdentity?getChannelModuleCache():void 0,i=resolveAuthoredPackageRoot(e),a=resolveAuthoredTsConfigPath(i),o=[r&&r.size>0?{name:`eve-channel-identity`,async resolveId(e,t,n){if(!/channels[/\\]/.test(e)||n.kind!==`import-statement`)return;let i=await this.resolve(e,t,{kind:n.kind,skipSelf:!0});if(i===null||typeof i.id!=`string`)return;let a=resolve(i.id);if(r.has(a))return{id:`${CACHED_CHANNEL_PREFIX}${a}`}},load(e){if(!e.startsWith(CACHED_CHANNEL_PREFIX))return;let t=e.slice(CACHED_CHANNEL_PREFIX.length);return{code:[`const cache = globalThis["${CHANNEL_MODULE_CACHE_KEY}"];`,`export default cache.get(${JSON.stringify(t)});`].join(`
2
+ `),moduleType:`js`}}}:null,...n.plugins,t.extensionScopeNamespace===void 0?null:createFixedNamespaceScopePlugin(t.extensionScopeNamespace),createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:i,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),n.packageBoundaryPlugin].filter(e=>e!==null);try{return(await buildSingleRolldownChunk(`authored module for "${e}"`,{cwd:i,input:e,platform:`node`,plugins:o,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:a,output:{comments:!1,format:`esm`,sourcemap:n.sourcemap}})).code}catch(t){throw createAuthoredModuleBundleError(e,t)}}function createAuthoredDirectiveGuardPlugin(){return{name:`eve-authored-directive-guard`,async transform(e,t){!AUTHORED_BUNDLED_MODULE_EXTENSION.test(t)||isNodeModulesPath(t)||await assertNoWorkflowDirectivePrologue({filePath:t,source:e})}}}function removeRolldownModuleRegionComments(e){return e.split(`
3
3
  `).filter(e=>!e.startsWith(`//#region `)&&e!==`//#endregion`).join(`
4
- `)}async function loadBundledAuthoredModule(e,i){let o=await bundleAuthoredModuleCode(e,i),c=normalizeExternalDependencies(i.externalDependencies),l=createHash(`sha1`).update(e).update(`\0`).update(c.join(`\0`)).update(`\0`).update(i.extensionScopeNamespace??``).update(`\0`).update(o).digest(`hex`),u=join(resolveAuthoredPackageRoot(e),AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH),d=join(u,`${l}.mjs`);existsSync(d)||(mkdirSync(u,{recursive:!0}),writeFileSync(d,o));try{return await import(`${createFileImportSpecifier(d)}?v=${l}`)}catch(t){throw createAuthoredModuleEvaluationError(e,t)}}function createInFlightModuleLoadKey(e,t){return`${e}\0${normalizeExternalDependencies(t.externalDependencies).join(`\0`)}\0${t.extensionScopeNamespace??``}`}function resolveAuthoredTsConfigPath(e){for(let n of[`tsconfig.json`,`jsconfig.json`]){let r=join(e,n);if(existsSync(r))return r}return!1}function resolveAuthoredPackageRoot(e){let n=dirname(e);for(;;){if(existsSync(join(n,`package.json`)))return n;let r=dirname(n);if(r===n)throw Error(`Failed to resolve the authored package root for "${e}".`);n=r}}export{bundleAuthoredModuleCode,bundleAuthoredModuleForGeneration,bundleAuthoredModuleMapForGeneration,bundleExtensionDistributionGraph,loadAuthoredModuleNamespace};
4
+ `)}async function loadBundledAuthoredModule(t,a){let s=await bundleAuthoredModuleCode(t,a),c=normalizeExternalDependencies(a.externalDependencies),l=createHash(`sha1`).update(t).update(`\0`).update(c.join(`\0`)).update(`\0`).update(a.extensionScopeNamespace??``).update(`\0`).update(s).digest(`hex`),u=join(resolveAuthoredPackageRoot(t),AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH),d=join(u,`${l}.mjs`);existsSync(d)||(mkdirSync(u,{recursive:!0}),writeFileSync(d,s));try{return await import(`${createFileImportSpecifier(d)}?v=${l}`)}catch(e){throw createAuthoredModuleEvaluationError(t,e)}}function createInFlightModuleLoadKey(e,t){return`${e}\0${normalizeExternalDependencies(t.externalDependencies).join(`\0`)}\0${t.extensionScopeNamespace??``}`}function resolveAuthoredTsConfigPath(e){for(let t of[`tsconfig.json`,`jsconfig.json`]){let r=join(e,t);if(existsSync(r))return r}return!1}function resolveAuthoredPackageRoot(e){let t=dirname(e);for(;;){if(existsSync(join(t,`package.json`)))return t;let r=dirname(t);if(r===t)throw Error(`Failed to resolve the authored package root for "${e}".`);t=r}}export{bundleAuthoredModuleCode,bundleAuthoredModuleForGeneration,bundleAuthoredModuleMapForGeneration,bundleExtensionDistributionGraph,loadAuthoredModuleNamespace};
@@ -1 +1 @@
1
- import{dirname,join,resolve,sep}from"node:path";import{readFile,stat}from"node:fs/promises";import{parse}from"#compiled/jsonc-parser/index.js";const NON_PACKAGE_IMPORT_FILTER=/^(?:\.|\/|[A-Za-z]:[\\/]|node:|data:|file:)/,packageTsConfigPathsCache=new Map,nearestPackageRootCache=new Map;function createAuthoredPackageTsConfigPathsPlugin(e){let t=createCachedStatProbe();return{name:`eve-package-tsconfig-paths`,resolveId:{filter:{id:{exclude:NON_PACKAGE_IMPORT_FILTER}},async handler(r,i,a){if(i===void 0||!isPackageImport(r))return;let o=resolve(i);if(isPathInsideOrEqual(o,e.appPackageRoot))return;let s=await resolveNearestPackageRoot(o,t);if(s===void 0||isPathInsideOrEqual(s,e.appPackageRoot))return;let c=await loadPackageTsConfigPaths(s);if(c!==void 0)for(let n of createTsConfigPathCandidates(r,c)){let r=await this.resolve(n,i,{kind:a.kind,skipSelf:!0});if(r!==null)return r;let o=await resolveExistingPath(n,e.extensions,t);if(o!==void 0)return{id:o}}}}}}function loadPackageTsConfigPaths(e){let t=packageTsConfigPathsCache.get(e);if(t!==void 0)return t;let n=readPackageTsConfigPaths(e);return packageTsConfigPathsCache.set(e,n),n}async function readPackageTsConfigPaths(t){let r=await readPackageConfig(t);if(r===void 0)return;let i=[],a=parse(r.source,i,{allowTrailingComma:!0});if(i.length>0||!isObjectRecord(a))return;let s=a.compilerOptions;if(!isObjectRecord(s)||!isObjectRecord(s.paths))return;let c=dirname(r.path),l=typeof s.baseUrl==`string`?resolve(c,s.baseUrl):c,u=Object.entries(s.paths).flatMap(([e,t])=>!Array.isArray(t)||!t.every(e=>typeof e==`string`)?[]:[{pattern:e,targets:t}]).sort((e,t)=>t.pattern.length-e.pattern.length);if(u.length!==0)return{baseDirectory:l,entries:u}}async function readPackageConfig(e){for(let n of[`tsconfig.json`,`jsconfig.json`]){let r=join(e,n);try{return{path:r,source:await readFile(r,`utf8`)}}catch(e){if(!isPathNotFoundError(e))throw e}}}function createTsConfigPathCandidates(e,t){let r=[];for(let i of t.entries){let a=matchTsConfigPathPattern(e,i.pattern);if(a!==void 0)for(let e of i.targets){let i=e.includes(`*`)?e.replaceAll(`*`,a):e;r.push(resolve(t.baseDirectory,i))}}return r}function matchTsConfigPathPattern(e,t){let n=t.indexOf(`*`);if(n===-1)return e===t?``:void 0;let r=t.slice(0,n),i=t.slice(n+1);if(!(!e.startsWith(r)||!e.endsWith(i)))return e.slice(r.length,e.length-i.length)}async function resolveExistingPath(e,n,r){if(await existsAsFile(e,r))return e;for(let t of n){let n=`${e}${t}`;if(await existsAsFile(n,r))return n}for(let i of n){let n=join(e,`index${i}`);if(await existsAsFile(n,r))return n}}async function existsAsFile(e,t){return(await t(e))?.isFile()??!1}function resolveNearestPackageRoot(t,n){let r=dirname(t),i=nearestPackageRootCache.get(r);if(i!==void 0)return i;let a=findNearestPackageRoot(r,n);return nearestPackageRootCache.set(r,a),a}async function findNearestPackageRoot(n,r){let i=n;for(;;){if(await pathExists(join(i,`package.json`),r))return i;let n=dirname(i);if(n===i)return;i=n}}async function pathExists(e,t){return await t(e)!==void 0}function createCachedStatProbe(){let e=new Map;return t=>{let n=e.get(t);if(n!==void 0)return n;let r=stat(t).catch(()=>void 0);return e.set(t,r),r}}function isPathNotFoundError(e){return typeof e==`object`&&!!e&&`code`in e&&(e.code===`ENOENT`||e.code===`ENOTDIR`)}function isPackageImport(e){return e.startsWith(`.`)||e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)?!1:!/^(?:node|data|file):/.test(e)}function isObjectRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function isPathInsideOrEqual(e,t){let i=resolve(e),a=resolve(t);return i===a||i.startsWith(`${a}${sep}`)}export{createAuthoredPackageTsConfigPathsPlugin};
1
+ import{readFile,stat}from"node:fs/promises";import{dirname,join,resolve,sep}from"node:path";import{parse}from"#compiled/jsonc-parser/index.js";const NON_PACKAGE_IMPORT_FILTER=/^(?:\.|\/|[A-Za-z]:[\\/]|node:|data:|file:)/,packageTsConfigPathsCache=new Map,nearestPackageRootCache=new Map;function createAuthoredPackageTsConfigPathsPlugin(e){let t=createCachedStatProbe();return{name:`eve-package-tsconfig-paths`,resolveId:{filter:{id:{exclude:NON_PACKAGE_IMPORT_FILTER}},async handler(n,r,a){if(r===void 0||!isPackageImport(n))return;let o=resolve(r);if(isPathInsideOrEqual(o,e.appPackageRoot))return;let s=await resolveNearestPackageRoot(o,t);if(s===void 0||isPathInsideOrEqual(s,e.appPackageRoot))return;let c=await loadPackageTsConfigPaths(s);if(c!==void 0)for(let i of createTsConfigPathCandidates(n,c)){let n=await this.resolve(i,r,{kind:a.kind,skipSelf:!0});if(n!==null)return n;let o=await resolveExistingPath(i,e.extensions,t);if(o!==void 0)return{id:o}}}}}}function loadPackageTsConfigPaths(e){let t=packageTsConfigPathsCache.get(e);if(t!==void 0)return t;let n=readPackageTsConfigPaths(e);return packageTsConfigPathsCache.set(e,n),n}async function readPackageTsConfigPaths(e){let t=await readPackageConfig(e);if(t===void 0)return;let r=[],a=parse(t.source,r,{allowTrailingComma:!0});if(r.length>0||!isObjectRecord(a))return;let s=a.compilerOptions;if(!isObjectRecord(s)||!isObjectRecord(s.paths))return;let c=dirname(t.path),l=typeof s.baseUrl==`string`?resolve(c,s.baseUrl):c,u=Object.entries(s.paths).flatMap(([e,t])=>!Array.isArray(t)||!t.every(e=>typeof e==`string`)?[]:[{pattern:e,targets:t}]).sort((e,t)=>t.pattern.length-e.pattern.length);if(u.length!==0)return{baseDirectory:l,entries:u}}async function readPackageConfig(t){for(let n of[`tsconfig.json`,`jsconfig.json`]){let i=join(t,n);try{return{path:i,source:await readFile(i,`utf8`)}}catch(e){if(!isPathNotFoundError(e))throw e}}}function createTsConfigPathCandidates(e,t){let n=[];for(let r of t.entries){let a=matchTsConfigPathPattern(e,r.pattern);if(a!==void 0)for(let e of r.targets){let r=e.includes(`*`)?e.replaceAll(`*`,a):e;n.push(resolve(t.baseDirectory,r))}}return n}function matchTsConfigPathPattern(e,t){let n=t.indexOf(`*`);if(n===-1)return e===t?``:void 0;let r=t.slice(0,n),i=t.slice(n+1);if(!(!e.startsWith(r)||!e.endsWith(i)))return e.slice(r.length,e.length-i.length)}async function resolveExistingPath(e,t,n){if(await existsAsFile(e,n))return e;for(let r of t){let t=`${e}${r}`;if(await existsAsFile(t,n))return t}for(let i of t){let t=join(e,`index${i}`);if(await existsAsFile(t,n))return t}}async function existsAsFile(e,t){return(await t(e))?.isFile()??!1}function resolveNearestPackageRoot(e,t){let r=dirname(e),i=nearestPackageRootCache.get(r);if(i!==void 0)return i;let a=findNearestPackageRoot(r,t);return nearestPackageRootCache.set(r,a),a}async function findNearestPackageRoot(e,t){let i=e;for(;;){if(await pathExists(join(i,`package.json`),t))return i;let e=dirname(i);if(e===i)return;i=e}}async function pathExists(e,t){return await t(e)!==void 0}function createCachedStatProbe(){let e=new Map;return n=>{let r=e.get(n);if(r!==void 0)return r;let i=stat(n).catch(()=>void 0);return e.set(n,i),i}}function isPathNotFoundError(e){return typeof e==`object`&&!!e&&`code`in e&&(e.code===`ENOENT`||e.code===`ENOTDIR`)}function isPackageImport(e){return e.startsWith(`.`)||e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)?!1:!/^(?:node|data|file):/.test(e)}function isObjectRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function isPathInsideOrEqual(e,t){let n=resolve(e),r=resolve(t);return n===r||n.startsWith(`${r}${sep}`)}export{createAuthoredPackageTsConfigPathsPlugin};
@@ -1 +1 @@
1
- import{existsSync}from"node:fs";import{join,relative,sep}from"node:path";import{lstat,mkdir,readFile,readdir,readlink,writeFile}from"node:fs/promises";import{createHash}from"node:crypto";import{COMPILED_AGENT_MANIFEST_KIND,ROOT_COMPILED_AGENT_NODE_ID}from"#compiler/manifest.js";import{bundleAuthoredModuleForGeneration,bundleAuthoredModuleMapForGeneration}from"#internal/authored-module-loader.js";import{serializeCompiledManifestForFingerprint}from"#internal/compiled-manifest-fingerprint.js";const MATERIALIZED_MODULES_DIRECTORY=`authored-modules`,MATERIALIZED_MODULES_INDEX=`authored-modules.json`,INSTRUMENTATION_EXTENSIONS=[`.ts`,`.mts`,`.js`,`.mjs`];async function materializeAuthoredModules(e){let n=join(e.runtimeAppRoot,`.eve`,`compile`),r=await readCompiledManifest(join(n,`compiled-agent-manifest.json`)),i=join(n,MATERIALIZED_MODULES_DIRECTORY),o=createHash(`sha256`);await mkdir(i,{recursive:!0}),o.update(`manifest\0`).update(serializeCompiledManifestForFingerprint({manifest:r,runtimeAppRoot:e.runtimeAppRoot})).update(`\0`);let s=await bundleAuthoredModuleMapForGeneration({manifest:r,moduleMapPath:join(n,`module-map.mjs`)}),c=createMaterializedModuleFileName(ROOT_COMPILED_AGENT_NODE_ID,`module-map`,s),u=join(MATERIALIZED_MODULES_DIRECTORY,c);await writeFile(join(i,c),s),o.update(`module-map\0`).update(s).update(`\0`);let d=resolveInstrumentationModule(r.agentRoot),f;if(d!==void 0){let e=await bundleAuthoredModuleForGeneration(d,{externalDependencies:r.config.build?.externalDependencies??[]}),n=createMaterializedModuleFileName(ROOT_COMPILED_AGENT_NODE_ID,`instrumentation`,e);await writeFile(join(i,n),e),f=join(MATERIALIZED_MODULES_DIRECTORY,n),o.update(`instrumentation\0`).update(e).update(`\0`)}await hashDirectoryIfPresent({fingerprint:o,path:join(n,`workspace-resources`),root:join(n,`workspace-resources`)});let p={fingerprint:o.digest(`hex`),moduleMap:u,version:2};return f!==void 0&&(p.instrumentation=f),await writeFile(join(n,MATERIALIZED_MODULES_INDEX),`${JSON.stringify(p)}\n`),p}async function readMaterializedAuthoredModuleIndex(n){let r=join(n,`.eve`,`compile`,MATERIALIZED_MODULES_INDEX);if(!existsSync(r))return;let i=JSON.parse(await readFile(r,`utf8`));if(i.version!==2||typeof i.fingerprint!=`string`||i.fingerprint.length===0||typeof i.moduleMap!=`string`||i.moduleMap.length===0||i.instrumentation!==void 0&&typeof i.instrumentation!=`string`)throw Error(`Invalid materialized authored module index at "${r}".`);return i}async function readCompiledManifest(e){let t=JSON.parse(await readFile(e,`utf8`));if(t.kind!==COMPILED_AGENT_MANIFEST_KIND)throw Error(`Invalid compiled agent manifest at "${e}".`);return t}function resolveInstrumentationModule(n){for(let r of INSTRUMENTATION_EXTENSIONS){let i=join(n,`instrumentation${r}`);if(existsSync(i))return i}}function createMaterializedModuleFileName(e,t,n){return`${createHash(`sha256`).update(e).update(`\0`).update(t).update(`\0`).update(n).digest(`hex`)}.mjs`}async function hashDirectoryIfPresent(r){if(!existsSync(r.path))return;let a=await lstat(r.path),l=toPortablePath(relative(r.root,r.path));if(a.isSymbolicLink()){r.fingerprint.update(l).update(`\0link\0`).update(await readlink(r.path)).update(`\0`);return}if(a.isDirectory()){for(let e of(await readdir(r.path)).sort())await hashDirectoryIfPresent({...r,path:join(r.path,e)});return}a.isFile()&&r.fingerprint.update(l).update(`\0file\0`).update(await readFile(r.path)).update(`\0`)}function toPortablePath(e){return e.split(sep).join(`/`)}export{materializeAuthoredModules,readMaterializedAuthoredModuleIndex};
1
+ import{createHash}from"node:crypto";import{lstat,mkdir,readFile,readdir,readlink,writeFile}from"node:fs/promises";import{existsSync}from"node:fs";import{join,relative,sep}from"node:path";import{COMPILED_AGENT_MANIFEST_KIND,ROOT_COMPILED_AGENT_NODE_ID}from"#compiler/manifest.js";import{bundleAuthoredModuleForGeneration,bundleAuthoredModuleMapForGeneration}from"#internal/authored-module-loader.js";import{serializeCompiledManifestForFingerprint}from"#internal/compiled-manifest-fingerprint.js";const MATERIALIZED_MODULES_DIRECTORY=`authored-modules`,MATERIALIZED_MODULES_INDEX=`authored-modules.json`,INSTRUMENTATION_EXTENSIONS=[`.ts`,`.mts`,`.js`,`.mjs`];async function materializeAuthoredModules(t){let r=join(t.runtimeAppRoot,`.eve`,`compile`),i=await readCompiledManifest(join(r,`compiled-agent-manifest.json`)),a=join(r,MATERIALIZED_MODULES_DIRECTORY),s=createHash(`sha256`);await mkdir(a,{recursive:!0}),s.update(`manifest\0`).update(serializeCompiledManifestForFingerprint({manifest:i,runtimeAppRoot:t.runtimeAppRoot})).update(`\0`);let c=await bundleAuthoredModuleMapForGeneration({manifest:i,moduleMapPath:join(r,`module-map.mjs`)}),l=createMaterializedModuleFileName(ROOT_COMPILED_AGENT_NODE_ID,`module-map`,c),u=join(MATERIALIZED_MODULES_DIRECTORY,l);await writeFile(join(a,l),c),s.update(`module-map\0`).update(c).update(`\0`);let d=resolveInstrumentationModule(i.agentRoot),f;if(d!==void 0){let e=await bundleAuthoredModuleForGeneration(d,{externalDependencies:i.config.build?.externalDependencies??[]}),t=createMaterializedModuleFileName(ROOT_COMPILED_AGENT_NODE_ID,`instrumentation`,e);await writeFile(join(a,t),e),f=join(MATERIALIZED_MODULES_DIRECTORY,t),s.update(`instrumentation\0`).update(e).update(`\0`)}await hashDirectoryIfPresent({fingerprint:s,path:join(r,`workspace-resources`),root:join(r,`workspace-resources`)});let p={fingerprint:s.digest(`hex`),moduleMap:u,version:2};return f!==void 0&&(p.instrumentation=f),await writeFile(join(r,MATERIALIZED_MODULES_INDEX),`${JSON.stringify(p)}\n`),p}async function readMaterializedAuthoredModuleIndex(e){let t=join(e,`.eve`,`compile`,MATERIALIZED_MODULES_INDEX);if(!existsSync(t))return;let n=JSON.parse(await readFile(t,`utf8`));if(n.version!==2||typeof n.fingerprint!=`string`||n.fingerprint.length===0||typeof n.moduleMap!=`string`||n.moduleMap.length===0||n.instrumentation!==void 0&&typeof n.instrumentation!=`string`)throw Error(`Invalid materialized authored module index at "${t}".`);return n}async function readCompiledManifest(e){let t=JSON.parse(await readFile(e,`utf8`));if(t.kind!==COMPILED_AGENT_MANIFEST_KIND)throw Error(`Invalid compiled agent manifest at "${e}".`);return t}function resolveInstrumentationModule(e){for(let t of INSTRUMENTATION_EXTENSIONS){let n=join(e,`instrumentation${t}`);if(existsSync(n))return n}}function createMaterializedModuleFileName(t,n,r){return`${createHash(`sha256`).update(t).update(`\0`).update(n).update(`\0`).update(r).digest(`hex`)}.mjs`}async function hashDirectoryIfPresent(e){if(!existsSync(e.path))return;let n=await lstat(e.path),o=toPortablePath(relative(e.root,e.path));if(n.isSymbolicLink()){e.fingerprint.update(o).update(`\0link\0`).update(await readlink(e.path)).update(`\0`);return}if(n.isDirectory()){for(let t of(await readdir(e.path)).sort())await hashDirectoryIfPresent({...e,path:join(e.path,t)});return}n.isFile()&&e.fingerprint.update(o).update(`\0file\0`).update(await readFile(e.path)).update(`\0`)}function toPortablePath(e){return e.split(sep).join(`/`)}export{materializeAuthoredModules,readMaterializedAuthoredModuleIndex};
@@ -1 +1 @@
1
- import{existsSync}from"node:fs";import{join,resolve}from"node:path";import{readFile,readdir,rm,stat,writeFile}from"node:fs/promises";const DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER=`activated`,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA=`retired.json`;async function recordRetiredDevelopmentRuntimeArtifactsSnapshot(e,n=Date.now()){await writeFile(join(e,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA),`${JSON.stringify({retiredAt:n})}\n`)}async function pruneDevelopmentRuntimeArtifactsSnapshotDirectory(r){if(r.protectAll)return;let o=r.now??Date.now(),s=Math.max(0,r.gracePeriodMs??18e5),c=Math.max(0,Math.trunc(r.retainCount??5)),l;try{l=await readdir(r.snapshotsDirectory,{withFileTypes:!0})}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let u=r.activeSnapshotRoot===void 0?void 0:resolve(r.activeSnapshotRoot),d=await Promise.all(l.filter(e=>e.isDirectory()).map(async i=>{let a=join(r.snapshotsDirectory,i.name),s=u===resolve(a),c=existsSync(join(a,DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER)),l;if(c&&!s)try{l=await readRetiredAt(a),l===void 0&&(await recordRetiredDevelopmentRuntimeArtifactsSnapshot(a,o),l=o)}catch(e){console.warn(`[eve:dev] failed to read or initialize runtime generation retirement metadata for "${a}": ${String(e)}`)}return{activated:c,active:s,path:a,retiredAt:l,mtimeMs:(await stat(a)).mtimeMs}})),f=new Set(d.flatMap(e=>e.retiredAt===void 0?[]:[{path:e.path,retiredAt:e.retiredAt}]).sort((e,t)=>t.retiredAt-e.retiredAt).slice(0,c).map(e=>e.path)),p=new Set(d.filter(e=>!e.activated).sort((e,t)=>t.mtimeMs-e.mtimeMs).slice(0,c).map(e=>e.path));await Promise.all(d.map(async e=>{e.active||e.activated&&e.retiredAt===void 0||f.has(e.path)||p.has(e.path)||e.retiredAt!==void 0&&o-e.retiredAt<=s||!e.activated&&o-e.mtimeMs<=s||await rm(e.path,{force:!0,recursive:!0})}))}async function readRetiredAt(e){let n;try{n=await readFile(join(e,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA),`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let i;try{i=JSON.parse(n)}catch{return}if(typeof i==`object`&&i&&!Array.isArray(i)&&`retiredAt`in i&&typeof i.retiredAt==`number`&&Number.isFinite(i.retiredAt)&&i.retiredAt>=0)return i.retiredAt}export{DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER,pruneDevelopmentRuntimeArtifactsSnapshotDirectory,recordRetiredDevelopmentRuntimeArtifactsSnapshot};
1
+ import{readFile,readdir,rm,stat,writeFile}from"node:fs/promises";import{existsSync}from"node:fs";import{join,resolve}from"node:path";const DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER=`activated`,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA=`retired.json`;async function recordRetiredDevelopmentRuntimeArtifactsSnapshot(e,t=Date.now()){await writeFile(join(e,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA),`${JSON.stringify({retiredAt:t})}\n`)}async function pruneDevelopmentRuntimeArtifactsSnapshotDirectory(e){if(e.protectAll)return;let i=e.now??Date.now(),a=Math.max(0,e.gracePeriodMs??18e5),o=Math.max(0,Math.trunc(e.retainCount??5)),s;try{s=await readdir(e.snapshotsDirectory,{withFileTypes:!0})}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let c=e.activeSnapshotRoot===void 0?void 0:resolve(e.activeSnapshotRoot),l=await Promise.all(s.filter(e=>e.isDirectory()).map(async t=>{let n=join(e.snapshotsDirectory,t.name),a=c===resolve(n),o=existsSync(join(n,DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER)),s;if(o&&!a)try{s=await readRetiredAt(n),s===void 0&&(await recordRetiredDevelopmentRuntimeArtifactsSnapshot(n,i),s=i)}catch(e){console.warn(`[eve:dev] failed to read or initialize runtime generation retirement metadata for "${n}": ${String(e)}`)}return{activated:o,active:a,path:n,retiredAt:s,mtimeMs:(await stat(n)).mtimeMs}})),u=new Set(l.flatMap(e=>e.retiredAt===void 0?[]:[{path:e.path,retiredAt:e.retiredAt}]).sort((e,t)=>t.retiredAt-e.retiredAt).slice(0,o).map(e=>e.path)),d=new Set(l.filter(e=>!e.activated).sort((e,t)=>t.mtimeMs-e.mtimeMs).slice(0,o).map(e=>e.path));await Promise.all(l.map(async e=>{e.active||e.activated&&e.retiredAt===void 0||u.has(e.path)||d.has(e.path)||e.retiredAt!==void 0&&i-e.retiredAt<=a||!e.activated&&i-e.mtimeMs<=a||await rm(e.path,{force:!0,recursive:!0})}))}async function readRetiredAt(t){let n;try{n=await readFile(join(t,DEVELOPMENT_RUNTIME_ARTIFACTS_RETIRED_METADATA),`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let r;try{r=JSON.parse(n)}catch{return}if(typeof r==`object`&&r&&!Array.isArray(r)&&`retiredAt`in r&&typeof r.retiredAt==`number`&&Number.isFinite(r.retiredAt)&&r.retiredAt>=0)return r.retiredAt}export{DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER,pruneDevelopmentRuntimeArtifactsSnapshotDirectory,recordRetiredDevelopmentRuntimeArtifactsSnapshot};
@@ -1 +1 @@
1
- import{existsSync,readFileSync}from"node:fs";import{dirname,join,relative,resolve,sep}from"node:path";import{cp,mkdir,readFile,rm,writeFile}from"node:fs/promises";import{randomUUID}from"node:crypto";import{renameWithTransientBusyRetry}from"#shared/rename-with-retry.js";import{copyDevelopmentSourceSnapshot}from"#internal/nitro/dev-runtime-source-snapshot-copy.js";import{createDevelopmentSourceSnapshotPlan,toDevelopmentSourceSnapshotPath}from"#internal/nitro/dev-runtime-source-snapshot.js";import{DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER,pruneDevelopmentRuntimeArtifactsSnapshotDirectory,recordRetiredDevelopmentRuntimeArtifactsSnapshot}from"#internal/nitro/dev-runtime-artifacts-retention.js";const DEV_RUNTIME_ARTIFACTS_DIRECTORY=`dev-runtime`;function resolveDevelopmentRuntimeArtifactsPointerPath(e){return join(e,`.eve`,DEV_RUNTIME_ARTIFACTS_DIRECTORY,`current.json`)}function resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e){return join(e,`.eve`,DEV_RUNTIME_ARTIFACTS_DIRECTORY,`snapshots`)}function isDevelopmentRuntimeArtifactsSnapshotRoot(e,t){return dirname(resolve(t))===resolve(resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e))}async function stageDevelopmentRuntimeArtifactsSnapshot(e){let t=join(resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e.project.appRoot),`${Date.now().toString(36)}-${randomUUID()}`),n=await createDevelopmentSourceSnapshotPlan({appRoot:e.project.appRoot,snapshotRoot:t});try{await copyDevelopmentSourceSnapshot(n),await cp(e.paths.compileDirectoryPath,join(n.runtimeAppRoot,`.eve`,`compile`),{recursive:!0}),await rewriteSnapshotCompiledManifest({appRoot:e.project.appRoot,manifestPath:join(n.runtimeAppRoot,`.eve`,`compile`,`compiled-agent-manifest.json`),runtimeAppRoot:n.runtimeAppRoot,snapshotSourceRoot:n.snapshotSourceRoot,sourceRoot:n.sourceRoot}),await validateSnapshotCompiledManifestRoots({manifestPath:join(n.runtimeAppRoot,`.eve`,`compile`,`compiled-agent-manifest.json`),runtimeAppRoot:n.runtimeAppRoot}),await writeFile(join(t,`generation.json`),`${JSON.stringify({runtimeAppRoot:n.runtimeAppRoot})}\n`)}catch(e){throw await rm(t,{force:!0,recursive:!0}).catch(()=>{}),e}return{runtimeAppRoot:n.runtimeAppRoot,snapshotRoot:t,snapshotSourceRoot:n.snapshotSourceRoot,sourceRoot:n.sourceRoot}}async function activateDevelopmentRuntimeArtifactsSnapshot(e){(await activateDevelopmentRuntimeArtifactsSnapshotTransaction(e)).commit()}async function activateDevelopmentRuntimeArtifactsSnapshotTransaction(e){let t=join(e.snapshot.snapshotRoot,DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER),n=resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot),i=readDevelopmentRuntimeArtifactsPointer(n),a=await readOptionalFile(n);try{await writeFile(t,``),await writeDevelopmentRuntimeArtifactsPointer(e),i?.version===2&&i.snapshotRoot!==e.snapshot.snapshotRoot&&isDevelopmentRuntimeArtifactsSnapshotRoot(e.appRoot,i.snapshotRoot)&&await recordRetiredDevelopmentRuntimeArtifactsSnapshot(i.snapshotRoot).catch(e=>{console.warn(`[eve:dev] failed to record retired runtime generation "${i.snapshotRoot}": ${String(e)}`)})}catch(e){throw await rollbackFailedActivation({cause:e,markerPath:t,pointerPath:n,previousPointerSource:a})}let o=!1;return{commit(){o=!0},async rollback(){if(o)return;o=!0;let e=await restoreDevelopmentRuntimeArtifactsActivation({markerPath:t,pointerPath:n,previousPointerSource:a});if(e!==void 0)throw e}}}function readDevelopmentRuntimeArtifactsSnapshotRoot(e){let t=readDevelopmentRuntimeArtifactsPointer(e);if(t!==void 0)return t.version===1?t.appRoot:t.runtimeAppRoot}function readActiveDevelopmentRuntimeArtifactsSnapshot(e){let t=readDevelopmentRuntimeArtifactsPointer(resolveDevelopmentRuntimeArtifactsPointerPath(e));if(!(t===void 0||t.version===1))return{runtimeAppRoot:t.runtimeAppRoot,snapshotRoot:t.snapshotRoot}}function readDevelopmentRuntimeArtifactsRevision(e){return{revision:readDevelopmentRuntimeArtifactsSnapshotRoot(resolveDevelopmentRuntimeArtifactsPointerPath(e))??e}}async function pruneDevelopmentRuntimeArtifactsSnapshots(e){let t=readDevelopmentRuntimeArtifactsPointer(resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot));await pruneDevelopmentRuntimeArtifactsSnapshotDirectory({activeSnapshotRoot:t?.version===2?t.snapshotRoot:void 0,gracePeriodMs:e.gracePeriodMs,now:e.now,protectAll:t?.version===1,retainCount:e.retainCount,snapshotsDirectory:resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e.appRoot)})}function readDevelopmentRuntimeArtifactsPointer(n){if(!(n===void 0||!existsSync(n)))try{let e=JSON.parse(readFileSync(n,`utf8`));return e.kind!==`eve-dev-runtime-artifacts-pointer`||typeof e.version!=`number`?void 0:e.version===1&&typeof e.appRoot==`string`&&e.appRoot.length>0?{appRoot:e.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,version:1}:e.version===2&&typeof e.appRoot==`string`&&typeof e.runtimeAppRoot==`string`&&e.runtimeAppRoot.length>0&&typeof e.snapshotRoot==`string`&&e.snapshotRoot.length>0?{appRoot:e.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,runtimeAppRoot:e.runtimeAppRoot,snapshotRoot:e.snapshotRoot,version:2}:void 0}catch{return}}async function rewriteSnapshotCompiledManifest(e){let t=JSON.parse(await readFile(e.manifestPath,`utf8`)),n=rewriteManifestRoots({appRoot:e.appRoot,runtimeAppRoot:e.runtimeAppRoot,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:t});await writeFile(e.manifestPath,`${JSON.stringify(n,null,2)}\n`)}function rewriteManifestRoots(e){if(Array.isArray(e.value))return e.value.map(t=>rewriteManifestRoots({...e,value:t}));if(e.value===null||typeof e.value!=`object`)return e.value;let t={};for(let[n,r]of Object.entries(e.value)){if(typeof r==`string`&&(n===`appRoot`||n===`agentRoot`)){t[n]=rewritePathWithinAppRoot({appRoot:e.appRoot,path:r,runtimeAppRoot:e.runtimeAppRoot});continue}if(typeof r==`string`&&n===`sourceRoot`){t[n]=rewritePathWithinSourceRoot({path:r,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot});continue}t[n]=rewriteManifestRoots({appRoot:e.appRoot,runtimeAppRoot:e.runtimeAppRoot,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:r})}return t}function rewritePathWithinSourceRoot(e){return isPathInsideOrEqual(e.path,e.sourceRoot)?toDevelopmentSourceSnapshotPath({snapshotSourceRoot:e.snapshotSourceRoot,sourcePath:e.path,sourceRoot:e.sourceRoot}):e.path}function rewritePathWithinAppRoot(e){if(!isPathInsideOrEqual(e.path,e.appRoot))return e.path;let t=relative(e.appRoot,e.path);return t.length===0?e.runtimeAppRoot:join(e.runtimeAppRoot,t)}async function writeDevelopmentRuntimeArtifactsPointer(e){let t=resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot),n={appRoot:e.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,runtimeAppRoot:e.snapshot.runtimeAppRoot,snapshotRoot:e.snapshot.snapshotRoot,version:2};await writeDevelopmentRuntimeArtifactsPointerSource(t,`${JSON.stringify(n,null,2)}\n`)}async function writeDevelopmentRuntimeArtifactsPointerSource(e,t){let r=`${e}.${randomUUID()}.tmp`;await mkdir(dirname(e),{recursive:!0}),await writeFile(r,t);try{await renameWithTransientBusyRetry(r,e)}catch(e){throw await rm(r,{force:!0}).catch(()=>{}),e}}async function readOptionalFile(e){try{return await readFile(e,`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}}async function rollbackFailedActivation(e){let t=await restoreDevelopmentRuntimeArtifactsActivation(e);return t===void 0?e.cause:AggregateError([e.cause,t],`Development runtime activation and rollback failed.`,{cause:e.cause})}async function restoreDevelopmentRuntimeArtifactsActivation(e){let t=(await Promise.allSettled([e.previousPointerSource===void 0?rm(e.pointerPath,{force:!0}):writeDevelopmentRuntimeArtifactsPointerSource(e.pointerPath,e.previousPointerSource),rm(e.markerPath,{force:!0})])).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(t.length!==0)return AggregateError(t,`Failed to restore development runtime activation.`)}async function validateSnapshotCompiledManifestRoots(e){let t=collectManifestRootPaths(JSON.parse(await readFile(e.manifestPath,`utf8`)));for(let n of t)if(!isPathInsideOrEqual(n,e.runtimeAppRoot))throw Error(`Development runtime snapshot manifest root "${n}" is outside runtime app root "${e.runtimeAppRoot}".`)}function collectManifestRootPaths(e){if(Array.isArray(e))return e.flatMap(e=>collectManifestRootPaths(e));if(typeof e!=`object`||!e)return[];let t=[];for(let[n,r]of Object.entries(e)){if((n===`appRoot`||n===`agentRoot`)&&typeof r==`string`){t.push(r);continue}t.push(...collectManifestRootPaths(r))}return t}function isPathInsideOrEqual(e,t){let n=resolve(e),r=resolve(t);return n===r||n.startsWith(`${r}${sep}`)}export{activateDevelopmentRuntimeArtifactsSnapshot,activateDevelopmentRuntimeArtifactsSnapshotTransaction,pruneDevelopmentRuntimeArtifactsSnapshots,readActiveDevelopmentRuntimeArtifactsSnapshot,readDevelopmentRuntimeArtifactsRevision,readDevelopmentRuntimeArtifactsSnapshotRoot,resolveDevelopmentRuntimeArtifactsPointerPath,stageDevelopmentRuntimeArtifactsSnapshot};
1
+ import{randomUUID}from"node:crypto";import{cp,mkdir,readFile,rm,writeFile}from"node:fs/promises";import{existsSync,readFileSync}from"node:fs";import{dirname,join,relative,resolve,sep}from"node:path";import{renameWithTransientBusyRetry}from"#shared/rename-with-retry.js";import{copyDevelopmentSourceSnapshot}from"#internal/nitro/dev-runtime-source-snapshot-copy.js";import{createDevelopmentSourceSnapshotPlan,toDevelopmentSourceSnapshotPath}from"#internal/nitro/dev-runtime-source-snapshot.js";import{DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER,pruneDevelopmentRuntimeArtifactsSnapshotDirectory,recordRetiredDevelopmentRuntimeArtifactsSnapshot}from"#internal/nitro/dev-runtime-artifacts-retention.js";const DEV_RUNTIME_ARTIFACTS_DIRECTORY=`dev-runtime`;function resolveDevelopmentRuntimeArtifactsPointerPath(e){return join(e,`.eve`,DEV_RUNTIME_ARTIFACTS_DIRECTORY,`current.json`)}function resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e){return join(e,`.eve`,DEV_RUNTIME_ARTIFACTS_DIRECTORY,`snapshots`)}function isDevelopmentRuntimeArtifactsSnapshotRoot(e,t){return dirname(resolve(t))===resolve(resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e))}async function stageDevelopmentRuntimeArtifactsSnapshot(n){let r=join(resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(n.project.appRoot),`${Date.now().toString(36)}-${randomUUID()}`),a=await createDevelopmentSourceSnapshotPlan({appRoot:n.project.appRoot,snapshotRoot:r});try{await copyDevelopmentSourceSnapshot(a),await cp(n.paths.compileDirectoryPath,join(a.runtimeAppRoot,`.eve`,`compile`),{recursive:!0}),await rewriteSnapshotCompiledManifest({appRoot:n.project.appRoot,manifestPath:join(a.runtimeAppRoot,`.eve`,`compile`,`compiled-agent-manifest.json`),runtimeAppRoot:a.runtimeAppRoot,snapshotSourceRoot:a.snapshotSourceRoot,sourceRoot:a.sourceRoot}),await validateSnapshotCompiledManifestRoots({manifestPath:join(a.runtimeAppRoot,`.eve`,`compile`,`compiled-agent-manifest.json`),runtimeAppRoot:a.runtimeAppRoot}),await writeFile(join(r,`generation.json`),`${JSON.stringify({runtimeAppRoot:a.runtimeAppRoot})}\n`)}catch(e){throw await rm(r,{force:!0,recursive:!0}).catch(()=>{}),e}return{runtimeAppRoot:a.runtimeAppRoot,snapshotRoot:r,snapshotSourceRoot:a.snapshotSourceRoot,sourceRoot:a.sourceRoot}}async function activateDevelopmentRuntimeArtifactsSnapshot(e){(await activateDevelopmentRuntimeArtifactsSnapshotTransaction(e)).commit()}async function activateDevelopmentRuntimeArtifactsSnapshotTransaction(e){let t=join(e.snapshot.snapshotRoot,DEVELOPMENT_RUNTIME_ARTIFACTS_ACTIVATED_MARKER),n=resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot),r=readDevelopmentRuntimeArtifactsPointer(n),i=await readOptionalFile(n);try{await writeFile(t,``),await writeDevelopmentRuntimeArtifactsPointer(e),r?.version===2&&r.snapshotRoot!==e.snapshot.snapshotRoot&&isDevelopmentRuntimeArtifactsSnapshotRoot(e.appRoot,r.snapshotRoot)&&await recordRetiredDevelopmentRuntimeArtifactsSnapshot(r.snapshotRoot).catch(e=>{console.warn(`[eve:dev] failed to record retired runtime generation "${r.snapshotRoot}": ${String(e)}`)})}catch(e){throw await rollbackFailedActivation({cause:e,markerPath:t,pointerPath:n,previousPointerSource:i})}let a=!1;return{commit(){a=!0},async rollback(){if(a)return;a=!0;let e=await restoreDevelopmentRuntimeArtifactsActivation({markerPath:t,pointerPath:n,previousPointerSource:i});if(e!==void 0)throw e}}}function readDevelopmentRuntimeArtifactsSnapshotRoot(e){let t=readDevelopmentRuntimeArtifactsPointer(e);if(t!==void 0)return t.version===1?t.appRoot:t.runtimeAppRoot}function readActiveDevelopmentRuntimeArtifactsSnapshot(e){let t=readDevelopmentRuntimeArtifactsPointer(resolveDevelopmentRuntimeArtifactsPointerPath(e));if(!(t===void 0||t.version===1))return{runtimeAppRoot:t.runtimeAppRoot,snapshotRoot:t.snapshotRoot}}function readDevelopmentRuntimeArtifactsRevision(e){return{revision:readDevelopmentRuntimeArtifactsSnapshotRoot(resolveDevelopmentRuntimeArtifactsPointerPath(e))??e}}async function pruneDevelopmentRuntimeArtifactsSnapshots(e){let t=readDevelopmentRuntimeArtifactsPointer(resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot));await pruneDevelopmentRuntimeArtifactsSnapshotDirectory({activeSnapshotRoot:t?.version===2?t.snapshotRoot:void 0,gracePeriodMs:e.gracePeriodMs,now:e.now,protectAll:t?.version===1,retainCount:e.retainCount,snapshotsDirectory:resolveDevelopmentRuntimeArtifactsSnapshotsDirectory(e.appRoot)})}function readDevelopmentRuntimeArtifactsPointer(e){if(!(e===void 0||!existsSync(e)))try{let t=JSON.parse(readFileSync(e,`utf8`));return t.kind!==`eve-dev-runtime-artifacts-pointer`||typeof t.version!=`number`?void 0:t.version===1&&typeof t.appRoot==`string`&&t.appRoot.length>0?{appRoot:t.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,version:1}:t.version===2&&typeof t.appRoot==`string`&&typeof t.runtimeAppRoot==`string`&&t.runtimeAppRoot.length>0&&typeof t.snapshotRoot==`string`&&t.snapshotRoot.length>0?{appRoot:t.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,runtimeAppRoot:t.runtimeAppRoot,snapshotRoot:t.snapshotRoot,version:2}:void 0}catch{return}}async function rewriteSnapshotCompiledManifest(e){let t=JSON.parse(await readFile(e.manifestPath,`utf8`)),n=rewriteManifestRoots({appRoot:e.appRoot,runtimeAppRoot:e.runtimeAppRoot,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:t});await writeFile(e.manifestPath,`${JSON.stringify(n,null,2)}\n`)}function rewriteManifestRoots(e){if(Array.isArray(e.value))return e.value.map(t=>rewriteManifestRoots({...e,value:t}));if(e.value===null||typeof e.value!=`object`)return e.value;let t={};for(let[n,r]of Object.entries(e.value)){if(typeof r==`string`&&(n===`appRoot`||n===`agentRoot`)){t[n]=rewritePathWithinAppRoot({appRoot:e.appRoot,path:r,runtimeAppRoot:e.runtimeAppRoot});continue}if(typeof r==`string`&&n===`sourceRoot`){t[n]=rewritePathWithinSourceRoot({path:r,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot});continue}t[n]=rewriteManifestRoots({appRoot:e.appRoot,runtimeAppRoot:e.runtimeAppRoot,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:r})}return t}function rewritePathWithinSourceRoot(e){return isPathInsideOrEqual(e.path,e.sourceRoot)?toDevelopmentSourceSnapshotPath({snapshotSourceRoot:e.snapshotSourceRoot,sourcePath:e.path,sourceRoot:e.sourceRoot}):e.path}function rewritePathWithinAppRoot(e){if(!isPathInsideOrEqual(e.path,e.appRoot))return e.path;let t=relative(e.appRoot,e.path);return t.length===0?e.runtimeAppRoot:join(e.runtimeAppRoot,t)}async function writeDevelopmentRuntimeArtifactsPointer(e){let t=resolveDevelopmentRuntimeArtifactsPointerPath(e.appRoot),n={appRoot:e.appRoot,kind:`eve-dev-runtime-artifacts-pointer`,runtimeAppRoot:e.snapshot.runtimeAppRoot,snapshotRoot:e.snapshot.snapshotRoot,version:2};await writeDevelopmentRuntimeArtifactsPointerSource(t,`${JSON.stringify(n,null,2)}\n`)}async function writeDevelopmentRuntimeArtifactsPointerSource(t,r){let a=`${t}.${randomUUID()}.tmp`;await mkdir(dirname(t),{recursive:!0}),await writeFile(a,r);try{await renameWithTransientBusyRetry(a,t)}catch(e){throw await rm(a,{force:!0}).catch(()=>{}),e}}async function readOptionalFile(e){try{return await readFile(e,`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}}async function rollbackFailedActivation(e){let t=await restoreDevelopmentRuntimeArtifactsActivation(e);return t===void 0?e.cause:AggregateError([e.cause,t],`Development runtime activation and rollback failed.`,{cause:e.cause})}async function restoreDevelopmentRuntimeArtifactsActivation(e){let t=(await Promise.allSettled([e.previousPointerSource===void 0?rm(e.pointerPath,{force:!0}):writeDevelopmentRuntimeArtifactsPointerSource(e.pointerPath,e.previousPointerSource),rm(e.markerPath,{force:!0})])).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(t.length!==0)return AggregateError(t,`Failed to restore development runtime activation.`)}async function validateSnapshotCompiledManifestRoots(e){let t=collectManifestRootPaths(JSON.parse(await readFile(e.manifestPath,`utf8`)));for(let n of t)if(!isPathInsideOrEqual(n,e.runtimeAppRoot))throw Error(`Development runtime snapshot manifest root "${n}" is outside runtime app root "${e.runtimeAppRoot}".`)}function collectManifestRootPaths(e){if(Array.isArray(e))return e.flatMap(e=>collectManifestRootPaths(e));if(typeof e!=`object`||!e)return[];let t=[];for(let[n,r]of Object.entries(e)){if((n===`appRoot`||n===`agentRoot`)&&typeof r==`string`){t.push(r);continue}t.push(...collectManifestRootPaths(r))}return t}function isPathInsideOrEqual(e,t){let n=resolve(e),r=resolve(t);return n===r||n.startsWith(`${r}${sep}`)}export{activateDevelopmentRuntimeArtifactsSnapshot,activateDevelopmentRuntimeArtifactsSnapshotTransaction,pruneDevelopmentRuntimeArtifactsSnapshots,readActiveDevelopmentRuntimeArtifactsSnapshot,readDevelopmentRuntimeArtifactsRevision,readDevelopmentRuntimeArtifactsSnapshotRoot,resolveDevelopmentRuntimeArtifactsPointerPath,stageDevelopmentRuntimeArtifactsSnapshot};
@@ -1 +1 @@
1
- import{constants,existsSync}from"node:fs";import{dirname,join,relative,resolve,sep}from"node:path";import{cp,lstat,mkdir,readFile,readdir,symlink,writeFile}from"node:fs/promises";import{DevelopmentRuntimeSourceSnapshotError,toDevelopmentSourceSnapshotPath}from"#internal/nitro/dev-runtime-source-snapshot.js";import{extractTsConfigExtendsSpecifiers,isTsConfigFilePath,parseTsConfigObject,readTextFileIfExists,resolveFirstExistingTsConfigExtendsTarget,resolveTsConfigExtendsTargetPaths}from"#internal/application/tsconfig-dependencies.js";const SNAPSHOT_SKIP_NAMES=new Set([`.generated`,`.eve`,`.git`,`.next`,`.output`,`.turbo`,`.vercel`,`.workflow-data`,`node_modules`]),SNAPSHOT_APP_ROOT_SKIP_NAMES=new Set([`build`,`dist`]),SNAPSHOT_COPY_MODE=constants.COPYFILE_FICLONE;async function copyDevelopmentSourceSnapshot(e){await mkdir(e.snapshotSourceRoot,{recursive:!0});for(let t of e.copyRoots)await copySnapshotPath({plan:e,sourcePath:t,targetPath:toSnapshotPathForPlan(e,t)});for(let n of e.copyFiles)existsSync(n)&&await copySnapshotPath({plan:e,sourcePath:n,targetPath:toSnapshotPathForPlan(e,n)});await rewriteSnapshotTsConfigAbsoluteExtends(e),await createSnapshotDependencyMounts(e),await ensureRuntimePackageJson(e),await validateDevelopmentSourceSnapshot(e)}async function copySnapshotPath(e){try{if((await lstat(e.sourcePath)).isDirectory()){await copySnapshotDirectory(e);return}await mkdir(dirname(e.targetPath),{recursive:!0}),await cp(e.sourcePath,e.targetPath,{mode:SNAPSHOT_COPY_MODE,recursive:!0})}catch(t){throw new DevelopmentRuntimeSourceSnapshotError(`Failed to copy development runtime source snapshot path "${e.sourcePath}" to "${e.targetPath}": ${formatErrorMessage(t)}`)}}async function copySnapshotDirectory(e){await mkdir(e.targetPath,{recursive:!0});for(let t of await readdir(e.sourcePath,{withFileTypes:!0})){let n=join(e.sourcePath,t.name);shouldSkipSnapshotSource(e.plan,n)||await cp(n,join(e.targetPath,t.name),{filter:t=>!shouldSkipSnapshotSource(e.plan,t),mode:SNAPSHOT_COPY_MODE,recursive:!0})}}function shouldSkipSnapshotSource(e,n){let i=relative(e.sourceRoot,n);return i.length===0?!1:i.split(/[\\/]/).some(e=>SNAPSHOT_SKIP_NAMES.has(e)||e.startsWith(`.env`))||existsSync(join(n,`.git`))?!0:isDirectAppRootSkipPath({appRoot:e.appRoot,sourcePath:n})}function isDirectAppRootSkipPath(e){if(!isPathInsideOrEqual(e.sourcePath,e.appRoot))return!1;let t=relative(e.appRoot,e.sourcePath);if(t.length===0)return!1;let n=t.split(/[\\/]/)[0];return n!==void 0&&SNAPSHOT_APP_ROOT_SKIP_NAMES.has(n)}async function rewriteSnapshotTsConfigAbsoluteExtends(e){for(let t of e.tsconfigPaths){let n=await readTextFileIfExists(t);if(n===void 0)continue;let r=rewriteTsConfigAbsoluteExtends({configPath:t,snapshotConfigPath:toSnapshotPathForPlan(e,t),snapshotSourceRoot:e.snapshotSourceRoot,source:n,sourceRoot:e.sourceRoot});r!==void 0&&await writeFile(toSnapshotPathForPlan(e,t),r)}}function rewriteTsConfigAbsoluteExtends(e){let t=parseTsConfigObject(e.source);if(t===void 0)return;let n=rewriteTsConfigExtendsValue({configPath:e.configPath,snapshotConfigPath:e.snapshotConfigPath,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:t.extends});if(n.changed===!0)return`${JSON.stringify({...t,extends:n.value},null,2)}\n`}function rewriteTsConfigExtendsValue(e){if(typeof e.value==`string`){let t=rewriteTsConfigExtendsSpecifier({configPath:e.configPath,snapshotConfigPath:e.snapshotConfigPath,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:e.value});return t===void 0?{changed:!1,value:e.value}:{changed:!0,value:t}}if(!Array.isArray(e.value))return{changed:!1,value:e.value};let t=!1,n=e.value.map(n=>{if(typeof n!=`string`)return n;let r=rewriteTsConfigExtendsSpecifier({configPath:e.configPath,snapshotConfigPath:e.snapshotConfigPath,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:n});return r===void 0?n:(t=!0,r)});return{changed:t,value:n}}function rewriteTsConfigExtendsSpecifier(e){if(!isTsConfigFilePath(e.value)||!isAbsoluteFilePath(e.value))return;let t=resolveFirstExistingTsConfigExtendsTarget({configPath:e.configPath,extendsSpecifier:e.value});if(!(t===void 0||!isPathInsideOrEqual(t,e.sourceRoot)))return toDevelopmentSourceSnapshotPath({snapshotSourceRoot:e.snapshotSourceRoot,sourcePath:t,sourceRoot:e.sourceRoot})}async function createSnapshotDependencyMounts(e){for(let t of e.dependencyMounts){let r=toSnapshotPathForPlan(e,t.mountPath),i=t.sourceKind===`workspace`?toSnapshotPathForPlan(e,t.sourcePath):t.sourcePath,a=t.sourceKind===`workspace`?relative(dirname(r),i)||`.`:i;await mkdir(dirname(r),{recursive:!0}),await symlink(a,r,`junction`)}}async function ensureRuntimePackageJson(e){let n=join(e.runtimeAppRoot,`package.json`);existsSync(n)||(await mkdir(e.runtimeAppRoot,{recursive:!0}),await writeFile(n,`${JSON.stringify({private:!0,type:`module`},null,2)}\n`))}async function validateDevelopmentSourceSnapshot(e){let n=join(e.runtimeAppRoot,`package.json`);if(!existsSync(n))throw new DevelopmentRuntimeSourceSnapshotError(`Development runtime source snapshot is missing the runtime app package.json at "${n}".`);for(let n of e.tsconfigPaths){let r=toSnapshotPathForPlan(e,n);if(!existsSync(r))throw new DevelopmentRuntimeSourceSnapshotError(`Development runtime source snapshot is missing tsconfig dependency "${r}".`);await validateSnapshotTsConfigExtends(r)}}async function validateSnapshotTsConfigExtends(e){let n=extractTsConfigExtendsSpecifiers(await readFile(e,`utf8`));for(let r of n)if(!(!isTsConfigFilePath(r)||resolveTsConfigExtendsTargetPaths({configPath:e,extendsSpecifier:r}).some(e=>existsSync(e))))throw new DevelopmentRuntimeSourceSnapshotError(`Development runtime source snapshot cannot resolve tsconfig extends "${r}" from "${e}".`)}function toSnapshotPathForPlan(e,t){return toDevelopmentSourceSnapshotPath({snapshotSourceRoot:e.snapshotSourceRoot,sourcePath:t,sourceRoot:e.sourceRoot})}function isPathInsideOrEqual(e,t){let n=resolve(e),r=resolve(t);return n===r||n.startsWith(`${r}${sep}`)}function isAbsoluteFilePath(e){return e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)}function formatErrorMessage(e){return e instanceof Error?e.message:String(e)}export{copyDevelopmentSourceSnapshot};
1
+ import{cp,lstat,mkdir,readFile,readdir,symlink,writeFile}from"node:fs/promises";import{constants,existsSync}from"node:fs";import{dirname,join,relative,resolve,sep}from"node:path";import{DevelopmentRuntimeSourceSnapshotError,toDevelopmentSourceSnapshotPath}from"#internal/nitro/dev-runtime-source-snapshot.js";import{extractTsConfigExtendsSpecifiers,isTsConfigFilePath,parseTsConfigObject,readTextFileIfExists,resolveFirstExistingTsConfigExtendsTarget,resolveTsConfigExtendsTargetPaths}from"#internal/application/tsconfig-dependencies.js";const SNAPSHOT_SKIP_NAMES=new Set([`.generated`,`.eve`,`.git`,`.next`,`.output`,`.turbo`,`.vercel`,`.workflow-data`,`node_modules`]),SNAPSHOT_APP_ROOT_SKIP_NAMES=new Set([`build`,`dist`]),SNAPSHOT_COPY_MODE=constants.COPYFILE_FICLONE;async function copyDevelopmentSourceSnapshot(e){await mkdir(e.snapshotSourceRoot,{recursive:!0});for(let t of e.copyRoots)await copySnapshotPath({plan:e,sourcePath:t,targetPath:toSnapshotPathForPlan(e,t)});for(let t of e.copyFiles)existsSync(t)&&await copySnapshotPath({plan:e,sourcePath:t,targetPath:toSnapshotPathForPlan(e,t)});await rewriteSnapshotTsConfigAbsoluteExtends(e),await createSnapshotDependencyMounts(e),await ensureRuntimePackageJson(e),await validateDevelopmentSourceSnapshot(e)}async function copySnapshotPath(r){try{if((await lstat(r.sourcePath)).isDirectory()){await copySnapshotDirectory(r);return}await mkdir(dirname(r.targetPath),{recursive:!0}),await cp(r.sourcePath,r.targetPath,{mode:SNAPSHOT_COPY_MODE,recursive:!0})}catch(e){throw new DevelopmentRuntimeSourceSnapshotError(`Failed to copy development runtime source snapshot path "${r.sourcePath}" to "${r.targetPath}": ${formatErrorMessage(e)}`)}}async function copySnapshotDirectory(t){await mkdir(t.targetPath,{recursive:!0});for(let n of await readdir(t.sourcePath,{withFileTypes:!0})){let r=join(t.sourcePath,n.name);shouldSkipSnapshotSource(t.plan,r)||await cp(r,join(t.targetPath,n.name),{filter:e=>!shouldSkipSnapshotSource(t.plan,e),mode:SNAPSHOT_COPY_MODE,recursive:!0})}}function shouldSkipSnapshotSource(e,t){let n=relative(e.sourceRoot,t);return n.length===0?!1:n.split(/[\\/]/).some(e=>SNAPSHOT_SKIP_NAMES.has(e)||e.startsWith(`.env`))||existsSync(join(t,`.git`))?!0:isDirectAppRootSkipPath({appRoot:e.appRoot,sourcePath:t})}function isDirectAppRootSkipPath(e){if(!isPathInsideOrEqual(e.sourcePath,e.appRoot))return!1;let t=relative(e.appRoot,e.sourcePath);if(t.length===0)return!1;let n=t.split(/[\\/]/)[0];return n!==void 0&&SNAPSHOT_APP_ROOT_SKIP_NAMES.has(n)}async function rewriteSnapshotTsConfigAbsoluteExtends(e){for(let t of e.tsconfigPaths){let n=await readTextFileIfExists(t);if(n===void 0)continue;let r=rewriteTsConfigAbsoluteExtends({configPath:t,snapshotConfigPath:toSnapshotPathForPlan(e,t),snapshotSourceRoot:e.snapshotSourceRoot,source:n,sourceRoot:e.sourceRoot});r!==void 0&&await writeFile(toSnapshotPathForPlan(e,t),r)}}function rewriteTsConfigAbsoluteExtends(e){let t=parseTsConfigObject(e.source);if(t===void 0)return;let n=rewriteTsConfigExtendsValue({configPath:e.configPath,snapshotConfigPath:e.snapshotConfigPath,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:t.extends});if(n.changed===!0)return`${JSON.stringify({...t,extends:n.value},null,2)}\n`}function rewriteTsConfigExtendsValue(e){if(typeof e.value==`string`){let t=rewriteTsConfigExtendsSpecifier({configPath:e.configPath,snapshotConfigPath:e.snapshotConfigPath,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:e.value});return t===void 0?{changed:!1,value:e.value}:{changed:!0,value:t}}if(!Array.isArray(e.value))return{changed:!1,value:e.value};let t=!1,n=e.value.map(n=>{if(typeof n!=`string`)return n;let r=rewriteTsConfigExtendsSpecifier({configPath:e.configPath,snapshotConfigPath:e.snapshotConfigPath,snapshotSourceRoot:e.snapshotSourceRoot,sourceRoot:e.sourceRoot,value:n});return r===void 0?n:(t=!0,r)});return{changed:t,value:n}}function rewriteTsConfigExtendsSpecifier(e){if(!isTsConfigFilePath(e.value)||!isAbsoluteFilePath(e.value))return;let t=resolveFirstExistingTsConfigExtendsTarget({configPath:e.configPath,extendsSpecifier:e.value});if(!(t===void 0||!isPathInsideOrEqual(t,e.sourceRoot)))return toDevelopmentSourceSnapshotPath({snapshotSourceRoot:e.snapshotSourceRoot,sourcePath:t,sourceRoot:e.sourceRoot})}async function createSnapshotDependencyMounts(e){for(let t of e.dependencyMounts){let r=toSnapshotPathForPlan(e,t.mountPath),i=t.sourceKind===`workspace`?toSnapshotPathForPlan(e,t.sourcePath):t.sourcePath,a=t.sourceKind===`workspace`?relative(dirname(r),i)||`.`:i;await mkdir(dirname(r),{recursive:!0}),await symlink(a,r,`junction`)}}async function ensureRuntimePackageJson(e){let t=join(e.runtimeAppRoot,`package.json`);existsSync(t)||(await mkdir(e.runtimeAppRoot,{recursive:!0}),await writeFile(t,`${JSON.stringify({private:!0,type:`module`},null,2)}\n`))}async function validateDevelopmentSourceSnapshot(e){let t=join(e.runtimeAppRoot,`package.json`);if(!existsSync(t))throw new DevelopmentRuntimeSourceSnapshotError(`Development runtime source snapshot is missing the runtime app package.json at "${t}".`);for(let t of e.tsconfigPaths){let n=toSnapshotPathForPlan(e,t);if(!existsSync(n))throw new DevelopmentRuntimeSourceSnapshotError(`Development runtime source snapshot is missing tsconfig dependency "${n}".`);await validateSnapshotTsConfigExtends(n)}}async function validateSnapshotTsConfigExtends(e){let t=extractTsConfigExtendsSpecifiers(await readFile(e,`utf8`));for(let n of t)if(!(!isTsConfigFilePath(n)||resolveTsConfigExtendsTargetPaths({configPath:e,extendsSpecifier:n}).some(e=>existsSync(e))))throw new DevelopmentRuntimeSourceSnapshotError(`Development runtime source snapshot cannot resolve tsconfig extends "${n}" from "${e}".`)}function toSnapshotPathForPlan(e,t){return toDevelopmentSourceSnapshotPath({snapshotSourceRoot:e.snapshotSourceRoot,sourcePath:t,sourceRoot:e.sourceRoot})}function isPathInsideOrEqual(e,t){let n=resolve(e),r=resolve(t);return n===r||n.startsWith(`${r}${sep}`)}function isAbsoluteFilePath(e){return e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)}function formatErrorMessage(e){return e instanceof Error?e.message:String(e)}export{copyDevelopmentSourceSnapshot};
@@ -1 +1 @@
1
- import{existsSync,readFileSync}from"node:fs";import{dirname,join,relative,resolve,sep}from"node:path";import{lstat,readlink,realpath}from"node:fs/promises";import{parseTsConfigObject,readTextFileIfExists,resolveTsConfigDependencyPaths}from"#internal/application/tsconfig-dependencies.js";const DEV_RUNTIME_SOURCE_DIRECTORY=`source`,SOURCE_ROOT_MARKER_NAMES=[`.git`,`pnpm-workspace.yaml`],WORKSPACE_METADATA_FILE_NAMES=[`package.json`,`pnpm-workspace.yaml`,`pnpm-lock.yaml`,`package-lock.json`,`yarn.lock`,`bun.lock`,`bun.lockb`,`.npmrc`],PACKAGE_DEPENDENCY_FIELDS=[`dependencies`,`devDependencies`,`optionalDependencies`,`peerDependencies`];var DevelopmentRuntimeSourceSnapshotError=class extends Error{constructor(e){super(e),this.name=`DevelopmentRuntimeSourceSnapshotError`}};async function createDevelopmentSourceSnapshotPlan(e){let t=resolve(e.appRoot),n=resolve(e.snapshotRoot),i=resolveDevelopmentSourceRoot(t),o=join(n,DEV_RUNTIME_SOURCE_DIRECTORY),s={appRoot:t,copyFiles:new Set,copyRoots:new Set,dependencyMountsByPath:new Map,localRootsToProcess:[t],processedLocalRoots:new Set,snapshotRoot:n,snapshotSourceRoot:o,sourceRoot:i,tsconfigPaths:new Set};for(addWorkspaceMetadataFiles(s);s.localRootsToProcess.length>0;){let e=s.localRootsToProcess.shift();if(e===void 0)continue;let t=resolve(e);s.processedLocalRoots.has(t)||!isAuthoredSourcePath(t,i)||(s.processedLocalRoots.add(t),s.copyRoots.add(t),await addTsConfigDependenciesForRoot(s,t),await addDependencyMountsForRoot(s,t))}let c=normalizeCopyRoots([...s.copyRoots]),l=[...s.copyFiles].filter(e=>isPathInsideOrEqual(e,i)).sort((e,t)=>e.localeCompare(t)),u=[...s.tsconfigPaths].filter(e=>isPathInsideOrEqual(e,i)).sort((e,t)=>e.localeCompare(t)),d=[...s.dependencyMountsByPath.values()].sort((e,t)=>e.mountPath.localeCompare(t.mountPath)),f=createWatchPaths({appRoot:t,copyFiles:l,copyRoots:c,dependencyMounts:d,sourceRoot:i,tsconfigPaths:u});return{appRoot:t,copyFiles:l,copyRoots:c,dependencyMounts:d,runtimeAppRoot:toSnapshotPath({sourcePath:t,sourceRoot:i,snapshotSourceRoot:o}),snapshotRoot:n,snapshotSourceRoot:o,sourceRoot:i,tsconfigPaths:u,watchPaths:f}}async function resolveDevelopmentSourceSnapshotWatchPaths(e){return[...(await createDevelopmentSourceSnapshotPlan({appRoot:e,snapshotRoot:join(resolve(e),`.eve`,`dev-runtime`,`__watch-plan__`)})).watchPaths]}function toDevelopmentSourceSnapshotPath(e){return toSnapshotPath(e)}function resolveDevelopmentSourceRoot(t){let i=resolve(t);for(;;){if(SOURCE_ROOT_MARKER_NAMES.some(t=>existsSync(join(i,t)))||isWorkspaceManifestRoot(i))return i;let o=dirname(i);if(o===i)return resolve(t);i=o}}function addWorkspaceMetadataFiles(t){for(let n of WORKSPACE_METADATA_FILE_NAMES){let i=join(t.sourceRoot,n);existsSync(i)&&t.copyFiles.add(i)}}async function addTsConfigDependenciesForRoot(e,t){let n=await resolveTsConfigDependencyPaths(t);for(let t of n)if(isPathInsideOrEqual(t,e.sourceRoot)){e.tsconfigPaths.add(t),e.copyFiles.add(t);for(let n of await resolveLocalTsConfigPathTargetRoots({configPath:t,sourceRoot:e.sourceRoot}))enqueueLocalRoot(e,n)}}async function addDependencyMountsForRoot(e,t){let n=await readPackageDependencyNames(resolveDependencyDeclarationRoot(t,e.sourceRoot));for(let r of n)for(let n of listAncestorNodeModulesRoots(t,e.sourceRoot))await addDependencyMount(e,joinNodeModulesPackagePath(n,r))}function resolveDependencyDeclarationRoot(t,i){let o=resolve(t),s=resolve(i);for(;isPathInsideOrEqual(o,s);){if(existsSync(join(o,`package.json`)))return o;let t=dirname(o);if(t===o)break;o=t}return t}function listAncestorNodeModulesRoots(e,t){let r=resolve(t),i=new Set,o=resolve(e);for(;isPathInsideOrEqual(o,r);){i.add(o);let e=dirname(o);if(e===o)break;o=e}return i.add(resolve(e)),i.add(r),[...i]}function isWorkspaceManifestRoot(n){let i=join(n,`package.json`);if(!existsSync(i))return!1;try{let e=JSON.parse(readFileSync(i,`utf8`));return isObjectRecord(e)&&e.workspaces!==void 0}catch{return!1}}async function addDependencyMount(t,n){let r;try{r=await lstat(n)}catch{return}if(!r.isDirectory()&&!r.isSymbolicLink())return;let i=await resolveDependencySourcePathCandidates(n),o=i.find(e=>isAuthoredSourcePath(e,t.sourceRoot));if(o!==void 0){await addWorkspaceDependencyMount({mountPath:n,state:t,sourcePath:o});return}let c=i.find(t=>existsSync(t));c!==void 0&&t.dependencyMountsByPath.set(resolve(n),{mountPath:resolve(n),sourceKind:`installed`,sourcePath:c})}async function addWorkspaceDependencyMount(e){let t=await resolveNearestPackageRoot(e.sourcePath,e.state.sourceRoot);if(t===void 0||!isAuthoredSourcePath(t,e.state.sourceRoot))return;let{state:n}=e;enqueueLocalRoot(n,t),n.dependencyMountsByPath.set(resolve(e.mountPath),{mountPath:resolve(e.mountPath),sourceKind:`workspace`,sourcePath:t})}async function resolveDependencySourcePathCandidates(e){let t=new Set;try{let r=await readlink(e);t.add(resolve(dirname(e),r))}catch{}try{t.add(await realpath(e))}catch{}return[...t]}function enqueueLocalRoot(e,t){let n=resolve(t);e.processedLocalRoots.has(n)||e.localRootsToProcess.includes(n)||!isAuthoredSourcePath(n,e.sourceRoot)||e.localRootsToProcess.push(n)}async function readPackageDependencyNames(e){let t=await readTextFileIfExists(join(e,`package.json`));if(t===void 0)return[];let n;try{n=JSON.parse(t)}catch{return[]}if(!isObjectRecord(n))return[];let i=new Set;for(let e of PACKAGE_DEPENDENCY_FIELDS){let t=n[e];if(isObjectRecord(t))for(let e of Object.keys(t))i.add(e)}return[...i].sort((e,t)=>e.localeCompare(t))}async function resolveLocalTsConfigPathTargetRoots(e){let t=await readTextFileIfExists(e.configPath);if(t===void 0)return[];let r=parseTsConfigObject(t),i=isObjectRecord(r?.compilerOptions)?r.compilerOptions:void 0,o=isObjectRecord(i?.paths)?i.paths:void 0;if(i===void 0||o===void 0)return[];let s=typeof i.baseUrl==`string`?resolve(dirname(e.configPath),i.baseUrl):dirname(e.configPath),c=new Set;for(let t of Object.values(o))if(Array.isArray(t))for(let n of t){if(typeof n!=`string`||n.length===0)continue;let t=await resolveLocalTsConfigPathTargetRoot({baseDirectory:s,sourceRoot:e.sourceRoot,target:n});t!==void 0&&c.add(t)}return[...c].sort((e,t)=>e.localeCompare(t))}async function resolveLocalTsConfigPathTargetRoot(e){let t=e.target.includes(`*`),n=t?e.target.slice(0,e.target.indexOf(`*`)):e.target;if(n.length===0||n===`.`||n===`./`)return;let r=resolve(e.baseDirectory,n);if(!isAuthoredSourcePath(r,e.sourceRoot))return;let i=await resolveExistingPathOrAncestor({path:r,stopDirectory:e.sourceRoot});if(i===void 0)return;let o=await resolveNearestPackageRoot(i,e.sourceRoot);if(o!==void 0&&o!==e.sourceRoot)return o;if(!t)return i===e.sourceRoot?void 0:i}async function resolveExistingPathOrAncestor(t){let r=resolve(t.path);for(;isAuthoredSourcePath(r,t.stopDirectory);){if(existsSync(r))return r;let t=dirname(r);if(t===r)return;r=t}}async function resolveNearestPackageRoot(t,i){let o=resolve(t);try{(await lstat(o)).isDirectory()||(o=dirname(o))}catch{o=dirname(o)}for(;isAuthoredSourcePath(o,i);){if(existsSync(join(o,`package.json`)))return o;let t=dirname(o);if(t===o)return;o=t}}function normalizeCopyRoots(e){let t=[...new Set(e.map(e=>resolve(e)))].sort((e,t)=>{let n=e.length-t.length;return n===0?e.localeCompare(t):n}),n=[];for(let e of t)n.some(t=>isPathInsideOrEqual(e,t))||n.push(e);return n.sort((e,t)=>e.localeCompare(t))}function createWatchPaths(t){let n=new Set([join(t.appRoot,`package.json`),...t.copyFiles,...t.tsconfigPaths]);for(let e of t.copyRoots)e!==t.appRoot&&n.add(e);for(let e of t.dependencyMounts)e.sourceKind===`workspace`&&e.sourcePath!==t.appRoot&&n.add(e.sourcePath);if(t.sourceRoot!==t.appRoot)for(let i of WORKSPACE_METADATA_FILE_NAMES){let a=join(t.sourceRoot,i);existsSync(a)&&n.add(a)}return[...n].sort((e,t)=>e.localeCompare(t))}function joinNodeModulesPackagePath(e,t){return join(e,`node_modules`,...t.split(`/`))}function toSnapshotPath(e){if(!isPathInsideOrEqual(e.sourcePath,e.sourceRoot))throw new DevelopmentRuntimeSourceSnapshotError(`Cannot map source path "${e.sourcePath}" into a development runtime snapshot because it is outside source root "${e.sourceRoot}".`);return join(e.snapshotSourceRoot,relative(e.sourceRoot,e.sourcePath))}function isPathInsideOrEqual(e,t){let n=resolve(e),r=resolve(t);return n===r||n.startsWith(`${r}${sep}`)}function isAuthoredSourcePath(e,t){return isPathInsideOrEqual(e,t)?!relative(t,e).split(/[\\/]/).includes(`node_modules`):!1}function isObjectRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}export{DEV_RUNTIME_SOURCE_DIRECTORY,DevelopmentRuntimeSourceSnapshotError,createDevelopmentSourceSnapshotPlan,isAuthoredSourcePath,resolveDevelopmentSourceRoot,resolveDevelopmentSourceSnapshotWatchPaths,toDevelopmentSourceSnapshotPath};
1
+ import{lstat,readlink,realpath}from"node:fs/promises";import{existsSync,readFileSync}from"node:fs";import{dirname,join,relative,resolve,sep}from"node:path";import{parseTsConfigObject,readTextFileIfExists,resolveTsConfigDependencyPaths}from"#internal/application/tsconfig-dependencies.js";const DEV_RUNTIME_SOURCE_DIRECTORY=`source`,SOURCE_ROOT_MARKER_NAMES=[`.git`,`pnpm-workspace.yaml`],WORKSPACE_METADATA_FILE_NAMES=[`package.json`,`pnpm-workspace.yaml`,`pnpm-lock.yaml`,`package-lock.json`,`yarn.lock`,`bun.lock`,`bun.lockb`,`.npmrc`],PACKAGE_DEPENDENCY_FIELDS=[`dependencies`,`devDependencies`,`optionalDependencies`,`peerDependencies`];var DevelopmentRuntimeSourceSnapshotError=class extends Error{constructor(e){super(e),this.name=`DevelopmentRuntimeSourceSnapshotError`}};async function createDevelopmentSourceSnapshotPlan(e){let t=resolve(e.appRoot),n=resolve(e.snapshotRoot),r=resolveDevelopmentSourceRoot(t),i=join(n,DEV_RUNTIME_SOURCE_DIRECTORY),a={appRoot:t,copyFiles:new Set,copyRoots:new Set,dependencyMountsByPath:new Map,localRootsToProcess:[t],processedLocalRoots:new Set,snapshotRoot:n,snapshotSourceRoot:i,sourceRoot:r,tsconfigPaths:new Set};for(addWorkspaceMetadataFiles(a);a.localRootsToProcess.length>0;){let e=a.localRootsToProcess.shift();if(e===void 0)continue;let t=resolve(e);a.processedLocalRoots.has(t)||!isAuthoredSourcePath(t,r)||(a.processedLocalRoots.add(t),a.copyRoots.add(t),await addTsConfigDependenciesForRoot(a,t),await addDependencyMountsForRoot(a,t))}let s=normalizeCopyRoots([...a.copyRoots]),c=[...a.copyFiles].filter(e=>isPathInsideOrEqual(e,r)).sort((e,t)=>e.localeCompare(t)),l=[...a.tsconfigPaths].filter(e=>isPathInsideOrEqual(e,r)).sort((e,t)=>e.localeCompare(t)),u=[...a.dependencyMountsByPath.values()].sort((e,t)=>e.mountPath.localeCompare(t.mountPath)),d=createWatchPaths({appRoot:t,copyFiles:c,copyRoots:s,dependencyMounts:u,sourceRoot:r,tsconfigPaths:l});return{appRoot:t,copyFiles:c,copyRoots:s,dependencyMounts:u,runtimeAppRoot:toSnapshotPath({sourcePath:t,sourceRoot:r,snapshotSourceRoot:i}),snapshotRoot:n,snapshotSourceRoot:i,sourceRoot:r,tsconfigPaths:l,watchPaths:d}}async function resolveDevelopmentSourceSnapshotWatchPaths(e){return[...(await createDevelopmentSourceSnapshotPlan({appRoot:e,snapshotRoot:join(resolve(e),`.eve`,`dev-runtime`,`__watch-plan__`)})).watchPaths]}function toDevelopmentSourceSnapshotPath(e){return toSnapshotPath(e)}function resolveDevelopmentSourceRoot(e){let t=resolve(e);for(;;){if(SOURCE_ROOT_MARKER_NAMES.some(e=>existsSync(join(t,e)))||isWorkspaceManifestRoot(t))return t;let n=dirname(t);if(n===t)return resolve(e);t=n}}function addWorkspaceMetadataFiles(e){for(let t of WORKSPACE_METADATA_FILE_NAMES){let n=join(e.sourceRoot,t);existsSync(n)&&e.copyFiles.add(n)}}async function addTsConfigDependenciesForRoot(e,t){let n=await resolveTsConfigDependencyPaths(t);for(let t of n)if(isPathInsideOrEqual(t,e.sourceRoot)){e.tsconfigPaths.add(t),e.copyFiles.add(t);for(let n of await resolveLocalTsConfigPathTargetRoots({configPath:t,sourceRoot:e.sourceRoot}))enqueueLocalRoot(e,n)}}async function addDependencyMountsForRoot(e,t){let n=await readPackageDependencyNames(resolveDependencyDeclarationRoot(t,e.sourceRoot));for(let r of n)for(let n of listAncestorNodeModulesRoots(t,e.sourceRoot))await addDependencyMount(e,joinNodeModulesPackagePath(n,r))}function resolveDependencyDeclarationRoot(e,t){let n=resolve(e),i=resolve(t);for(;isPathInsideOrEqual(n,i);){if(existsSync(join(n,`package.json`)))return n;let e=dirname(n);if(e===n)break;n=e}return e}function listAncestorNodeModulesRoots(e,t){let n=resolve(t),r=new Set,i=resolve(e);for(;isPathInsideOrEqual(i,n);){r.add(i);let e=dirname(i);if(e===i)break;i=e}return r.add(resolve(e)),r.add(n),[...r]}function isWorkspaceManifestRoot(e){let t=join(e,`package.json`);if(!existsSync(t))return!1;try{let e=JSON.parse(readFileSync(t,`utf8`));return isObjectRecord(e)&&e.workspaces!==void 0}catch{return!1}}async function addDependencyMount(t,n){let i;try{i=await lstat(n)}catch{return}if(!i.isDirectory()&&!i.isSymbolicLink())return;let a=await resolveDependencySourcePathCandidates(n),o=a.find(e=>isAuthoredSourcePath(e,t.sourceRoot));if(o!==void 0){await addWorkspaceDependencyMount({mountPath:n,state:t,sourcePath:o});return}let s=a.find(e=>existsSync(e));s!==void 0&&t.dependencyMountsByPath.set(resolve(n),{mountPath:resolve(n),sourceKind:`installed`,sourcePath:s})}async function addWorkspaceDependencyMount(e){let t=await resolveNearestPackageRoot(e.sourcePath,e.state.sourceRoot);if(t===void 0||!isAuthoredSourcePath(t,e.state.sourceRoot))return;let{state:n}=e;enqueueLocalRoot(n,t),n.dependencyMountsByPath.set(resolve(e.mountPath),{mountPath:resolve(e.mountPath),sourceKind:`workspace`,sourcePath:t})}async function resolveDependencySourcePathCandidates(e){let r=new Set;try{let n=await readlink(e);r.add(resolve(dirname(e),n))}catch{}try{r.add(await realpath(e))}catch{}return[...r]}function enqueueLocalRoot(e,t){let n=resolve(t);e.processedLocalRoots.has(n)||e.localRootsToProcess.includes(n)||!isAuthoredSourcePath(n,e.sourceRoot)||e.localRootsToProcess.push(n)}async function readPackageDependencyNames(e){let t=await readTextFileIfExists(join(e,`package.json`));if(t===void 0)return[];let n;try{n=JSON.parse(t)}catch{return[]}if(!isObjectRecord(n))return[];let r=new Set;for(let e of PACKAGE_DEPENDENCY_FIELDS){let t=n[e];if(isObjectRecord(t))for(let e of Object.keys(t))r.add(e)}return[...r].sort((e,t)=>e.localeCompare(t))}async function resolveLocalTsConfigPathTargetRoots(e){let t=await readTextFileIfExists(e.configPath);if(t===void 0)return[];let n=parseTsConfigObject(t),r=isObjectRecord(n?.compilerOptions)?n.compilerOptions:void 0,i=isObjectRecord(r?.paths)?r.paths:void 0;if(r===void 0||i===void 0)return[];let o=typeof r.baseUrl==`string`?resolve(dirname(e.configPath),r.baseUrl):dirname(e.configPath),s=new Set;for(let t of Object.values(i))if(Array.isArray(t))for(let n of t){if(typeof n!=`string`||n.length===0)continue;let t=await resolveLocalTsConfigPathTargetRoot({baseDirectory:o,sourceRoot:e.sourceRoot,target:n});t!==void 0&&s.add(t)}return[...s].sort((e,t)=>e.localeCompare(t))}async function resolveLocalTsConfigPathTargetRoot(e){let t=e.target.includes(`*`),n=t?e.target.slice(0,e.target.indexOf(`*`)):e.target;if(n.length===0||n===`.`||n===`./`)return;let r=resolve(e.baseDirectory,n);if(!isAuthoredSourcePath(r,e.sourceRoot))return;let i=await resolveExistingPathOrAncestor({path:r,stopDirectory:e.sourceRoot});if(i===void 0)return;let a=await resolveNearestPackageRoot(i,e.sourceRoot);if(a!==void 0&&a!==e.sourceRoot)return a;if(!t)return i===e.sourceRoot?void 0:i}async function resolveExistingPathOrAncestor(e){let t=resolve(e.path);for(;isAuthoredSourcePath(t,e.stopDirectory);){if(existsSync(t))return t;let e=dirname(t);if(e===t)return;t=e}}async function resolveNearestPackageRoot(t,n){let i=resolve(t);try{(await lstat(i)).isDirectory()||(i=dirname(i))}catch{i=dirname(i)}for(;isAuthoredSourcePath(i,n);){if(existsSync(join(i,`package.json`)))return i;let e=dirname(i);if(e===i)return;i=e}}function normalizeCopyRoots(e){let t=[...new Set(e.map(e=>resolve(e)))].sort((e,t)=>{let n=e.length-t.length;return n===0?e.localeCompare(t):n}),n=[];for(let e of t)n.some(t=>isPathInsideOrEqual(e,t))||n.push(e);return n.sort((e,t)=>e.localeCompare(t))}function createWatchPaths(e){let t=new Set([join(e.appRoot,`package.json`),...e.copyFiles,...e.tsconfigPaths]);for(let n of e.copyRoots)n!==e.appRoot&&t.add(n);for(let n of e.dependencyMounts)n.sourceKind===`workspace`&&n.sourcePath!==e.appRoot&&t.add(n.sourcePath);if(e.sourceRoot!==e.appRoot)for(let n of WORKSPACE_METADATA_FILE_NAMES){let i=join(e.sourceRoot,n);existsSync(i)&&t.add(i)}return[...t].sort((e,t)=>e.localeCompare(t))}function joinNodeModulesPackagePath(e,t){return join(e,`node_modules`,...t.split(`/`))}function toSnapshotPath(e){if(!isPathInsideOrEqual(e.sourcePath,e.sourceRoot))throw new DevelopmentRuntimeSourceSnapshotError(`Cannot map source path "${e.sourcePath}" into a development runtime snapshot because it is outside source root "${e.sourceRoot}".`);return join(e.snapshotSourceRoot,relative(e.sourceRoot,e.sourcePath))}function isPathInsideOrEqual(e,t){let n=resolve(e),r=resolve(t);return n===r||n.startsWith(`${r}${sep}`)}function isAuthoredSourcePath(e,t){return isPathInsideOrEqual(e,t)?!relative(t,e).split(/[\\/]/).includes(`node_modules`):!1}function isObjectRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}export{DEV_RUNTIME_SOURCE_DIRECTORY,DevelopmentRuntimeSourceSnapshotError,createDevelopmentSourceSnapshotPlan,isAuthoredSourcePath,resolveDevelopmentSourceRoot,resolveDevelopmentSourceSnapshotWatchPaths,toDevelopmentSourceSnapshotPath};
@@ -1 +1 @@
1
- import{resolvePackageSourceFilePath}from"#internal/application/package.js";import{dirname,isAbsolute,join,relative,resolve,sep}from"node:path";import{tryReadExtensionBuildConfig}from"#internal/nitro/host/build-extension.js";import{readFile}from"node:fs/promises";import{toErrorMessage}from"#shared/errors.js";import{resolveDiscoveryProject}from"#discover/project.js";import{createDiskRuntimeCompiledArtifactsSource}from"#runtime/compiled-artifacts-source.js";import{build,copyPublicAssets,prepare,prerender}from"nitro/builder";import{prepareEveVersionedCacheDirectory,writeEveVersionedCacheMetadata}from"#internal/application/cache-metadata.js";import{createApplicationBuildWorkspace,removeApplicationBuildWorkspace}from"#internal/application/build-workspace.js";import{ApplicationBuildProfiler,createApplicationBuildProfile,measureApplicationBuildOutput,writeApplicationBuildProfile}from"#internal/application/build-profile.js";import{RecoverablePublicationError,publishApplicationBuildArtifacts}from"#internal/application/output-publication.js";import{stageProductionCompilerArtifacts}from"#internal/application/production-compiler-artifacts.js";import{materializeVercelWorkflowFunctionOutput,normalizeEveVercelFunctionOutput}from"#internal/workflow-bundle/vercel-workflow-output.js";import{createProductionApplicationNitro}from"#internal/nitro/host/create-application-nitro.js";import{emitVercelAgentSummary}from"#internal/nitro/host/build-vercel-agent-summary.js";import{copyHostMiddlewareFunctions}from"#internal/nitro/host/copy-host-middleware.js";import{normalizeVercelServiceCrons}from"#internal/nitro/host/normalize-vercel-service-crons.js";import{prepareProductionApplicationHost}from"#internal/nitro/host/prepare-application-host.js";import{runVercelBuildPrewarm}from"#internal/nitro/host/vercel-build-prewarm.js";import{findClosestVercelOutputDirectory}from"#shared/vercel-output-directory.js";function trimTrailingSlash(e){return e.replace(/[\\/]+$/,``)}async function measureBuildPhase(e,t,n){return e===void 0?n():e.measure(t,n)}function isPathInside(e,t){let r=relative(e,t);return r.length===0||!r.startsWith(`..${sep}`)&&r!==`..`&&!isAbsolute(r)}function assertProfileOutputOutsideBuildOutput(e,t){if(e!==void 0&&isPathInside(t,e))throw Error(`Build profile path ${e} must be outside the published output directory ${t}.`)}async function writeOptionalApplicationBuildProfile(e){try{assertProfileOutputOutsideBuildOutput(e.profileOutputPath,e.outputDirectory);let t=e.profiler.finish(),n=await measureApplicationBuildOutput(e.outputDirectory);await writeApplicationBuildProfile(e.profileOutputPath,createApplicationBuildProfile({output:n,target:process.env.VERCEL?`vercel`:`local`,timing:t}))}catch(t){console.warn(`eve: failed to write optional build profile to ${e.profileOutputPath}; continuing with the published build output: ${toErrorMessage(t)}`)}}function isRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function normalizeEntrypoint(e,t){return typeof t!=`string`||t.trim().length===0?null:resolve(e,t)}function normalizeServiceRoot(e,t){return typeof t.root==`string`&&t.root.trim().length>0?resolve(e,t.root):normalizeEntrypoint(e,t.entrypoint)}function normalizeServicePrefix(e){return typeof e.routePrefix==`string`?e.routePrefix.trim():typeof e.mount==`string`?e.mount.trim():isRecord(e.mount)&&typeof e.mount.path==`string`&&e.mount.path.trim().length>0?e.mount.path.trim():``}function normalizeServiceCollection(e){if(isRecord(e))return Object.values(e).filter(isRecord);if(Array.isArray(e))return e.filter(isRecord)}function resolveCoDeployedEveServicePrefix(e){if(!isRecord(e.config))return;let t=normalizeServiceCollection(e.config.experimentalServices)??normalizeServiceCollection(e.config.experimentalServicesV2)??normalizeServiceCollection(e.config.services);if(t===void 0)return;let n=!1,r;for(let i of t){if(i.framework!==`eve`){n=!0;continue}let t=normalizeServiceRoot(e.configRoot,i),a=normalizeServicePrefix(i);t!==null&&e.appRoots.includes(t)&&a.length>0&&a!==`/`&&(r=a)}return n?r:void 0}async function resolveCoDeployedEveServicePrefixForVercelFunctionOutput(e,n){let i=Array.from(new Set([resolve(e),resolve(n)])),o=await findClosestVercelOutputDirectory(e);if(o!==void 0)try{let e=JSON.parse(await readFile(join(o,`config.json`),`utf8`)),t=resolveCoDeployedEveServicePrefix({appRoots:i,configRoot:await resolveVercelOutputConfigRoot(o),config:e});if(t!==void 0)return t}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}let s=e;for(;;){for(let e of[join(s,`vercel.json`),join(s,`.vercel`,`output`,`config.json`)])try{let n=JSON.parse(await readFile(e,`utf8`)),r=resolveCoDeployedEveServicePrefix({appRoots:i,configRoot:e.endsWith(`vercel.json`)?s:await resolveVercelOutputConfigRoot(dirname(e)),config:n});if(r!==void 0)return r}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}let e=dirname(s);if(e===s)return;s=e}}async function resolveVercelOutputConfigRoot(e){let n=dirname(dirname(e));try{let e=JSON.parse(await readFile(join(n,`.vercel`,`project.json`),`utf8`));if(isRecord(e)&&isRecord(e.settings)&&typeof e.settings.rootDirectory==`string`&&e.settings.rootDirectory.trim().length>0)return resolve(n,e.settings.rootDirectory)}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}return n}async function buildNitroOutput(e,t,n){let r=trimTrailingSlash(e.options.output.dir);return await measureBuildPhase(t,`${n}.cache.prepare`,()=>prepareEveVersionedCacheDirectory(r)),await measureBuildPhase(t,`${n}.prepare`,()=>prepare(e)),await measureBuildPhase(t,`${n}.public-assets`,()=>copyPublicAssets(e)),await measureBuildPhase(t,`${n}.prerender`,()=>prerender(e)),await measureBuildPhase(t,`${n}.bundle`,()=>build(e)),await measureBuildPhase(t,`${n}.cache.write`,()=>writeEveVersionedCacheMetadata(r)),r}async function buildApplication(e,t){let n=t.profileOutputPath===void 0?void 0:resolve(t.profileOutputPath),r=n===void 0?void 0:new ApplicationBuildProfiler,i=await measureBuildPhase(r,`extension.check`,()=>tryReadExtensionBuildConfig(e));if(i!==null)throw Error(`Package "${i.packageName}" is an eve extension. Run \`eve extension build\` instead of \`eve build\`.`);let o=await measureBuildPhase(r,`project.resolve`,()=>resolveDiscoveryProject(e)),c=await measureBuildPhase(r,`workspace.create`,()=>createApplicationBuildWorkspace(o.appRoot,t.vercelServiceOutput?.serviceOutputDirectory)),l=!1,u;try{u=await buildApplicationInWorkspace(c,t,r)}catch(e){throw l=e instanceof RecoverablePublicationError,e}finally{l||await measureBuildPhase(r,`workspace.remove`,()=>removeApplicationBuildWorkspace(c))}return r!==void 0&&n!==void 0&&await writeOptionalApplicationBuildProfile({outputDirectory:u,profileOutputPath:n,profiler:r}),u}async function buildApplicationInWorkspace(t,n,r){let i=await measureBuildPhase(r,`host.prepare`,()=>prepareProductionApplicationHost(t)),a=!!process.env.VERCEL,o=a?await measureBuildPhase(r,`vercel.service-prefix.resolve`,()=>resolveCoDeployedEveServicePrefixForVercelFunctionOutput(i.appRoot,i.compileResult.project.agentRoot)):void 0,s=await measureBuildPhase(r,`nitro.create`,()=>createProductionApplicationNitro(i,{buildDir:t.nitro.buildDir,outputDir:t.publication.output.stagedDir,publicRoutePrefix:n.publicRoutePrefix}));try{a&&!n.skipVercelSandboxPrewarm&&await measureBuildPhase(r,`sandbox.prewarm`,()=>runVercelBuildPrewarm({appRoot:i.appRoot,compiledArtifactsSource:createDiskRuntimeCompiledArtifactsSource(t.compiler.rootDir,{moduleMapLoaderPath:resolvePackageSourceFilePath(`src/internal/authored-module-map-loader.ts`),sandboxAppRoot:i.appRoot}),log(e){console.log(e)}})),await buildNitroOutput(s,r,`nitro`),a&&await measureBuildPhase(r,`vercel.workflow-function.materialize`,()=>materializeVercelWorkflowFunctionOutput(t.publication.output.stagedDir)),o!==void 0&&await measureBuildPhase(r,`vercel.functions.normalize`,()=>normalizeEveVercelFunctionOutput(t.publication.output.stagedDir,{servicePrefix:o}));let c=n.vercelServiceOutput;c!==void 0&&(await measureBuildPhase(r,`vercel.service-crons.normalize`,()=>normalizeVercelServiceCrons({publicRoutePrefix:n.publicRoutePrefix,serviceOutputDirectory:t.publication.output.stagedDir})),await measureBuildPhase(r,`vercel.host-middleware.copy`,()=>copyHostMiddlewareFunctions({hostOutputDirectory:c.hostOutputDirectory,serviceOutputDirectory:t.publication.output.stagedDir}))),await measureBuildPhase(r,`agent-summary.emit`,()=>emitVercelAgentSummary({manifest:i.compileResult.manifest,outputPath:t.publication.summary.stagedPath})),a||await measureBuildPhase(r,`compiler-artifacts.stage`,()=>stageProductionCompilerArtifacts({compilerArtifactsRoot:t.compiler.artifactsDir,outputDir:t.publication.output.stagedDir}))}finally{await measureBuildPhase(r,`nitro.close`,()=>s.close())}return await measureBuildPhase(r,`output.publish`,()=>publishCompletedApplicationBuild(t)),t.publication.output.finalDir}async function publishCompletedApplicationBuild(e){await publishApplicationBuildArtifacts({appRoot:e.appRoot,finalOutputDir:e.publication.output.finalDir,finalSummaryPath:e.publication.summary.finalPath,scratchDir:e.rootDir,stagedOutputDir:e.publication.output.stagedDir,stagedSummaryPath:e.publication.summary.stagedPath})}export{buildApplication};
1
+ import{readFile}from"node:fs/promises";import{resolvePackageSourceFilePath}from"#internal/application/package.js";import{dirname,isAbsolute,join,relative,resolve,sep}from"node:path";import{tryReadExtensionBuildConfig}from"#internal/nitro/host/build-extension.js";import{toErrorMessage}from"#shared/errors.js";import{resolveDiscoveryProject}from"#discover/project.js";import{createDiskRuntimeCompiledArtifactsSource}from"#runtime/compiled-artifacts-source.js";import{build,copyPublicAssets,prepare,prerender}from"nitro/builder";import{prepareEveVersionedCacheDirectory,writeEveVersionedCacheMetadata}from"#internal/application/cache-metadata.js";import{createApplicationBuildWorkspace,removeApplicationBuildWorkspace}from"#internal/application/build-workspace.js";import{ApplicationBuildProfiler,createApplicationBuildProfile,measureApplicationBuildOutput,writeApplicationBuildProfile}from"#internal/application/build-profile.js";import{RecoverablePublicationError,publishApplicationBuildArtifacts}from"#internal/application/output-publication.js";import{stageProductionCompilerArtifacts}from"#internal/application/production-compiler-artifacts.js";import{materializeVercelWorkflowFunctionOutput,normalizeEveVercelFunctionOutput}from"#internal/workflow-bundle/vercel-workflow-output.js";import{createProductionApplicationNitro}from"#internal/nitro/host/create-application-nitro.js";import{emitVercelAgentSummary}from"#internal/nitro/host/build-vercel-agent-summary.js";import{copyHostMiddlewareFunctions}from"#internal/nitro/host/copy-host-middleware.js";import{normalizeVercelServiceCrons}from"#internal/nitro/host/normalize-vercel-service-crons.js";import{prepareProductionApplicationHost}from"#internal/nitro/host/prepare-application-host.js";import{runVercelBuildPrewarm}from"#internal/nitro/host/vercel-build-prewarm.js";import{findClosestVercelOutputDirectory}from"#shared/vercel-output-directory.js";function trimTrailingSlash(e){return e.replace(/[\\/]+$/,``)}async function measureBuildPhase(e,t,n){return e===void 0?n():e.measure(t,n)}function isPathInside(e,t){let n=relative(e,t);return n.length===0||!n.startsWith(`..${sep}`)&&n!==`..`&&!isAbsolute(n)}function assertProfileOutputOutsideBuildOutput(e,t){if(e!==void 0&&isPathInside(t,e))throw Error(`Build profile path ${e} must be outside the published output directory ${t}.`)}async function writeOptionalApplicationBuildProfile(e){try{assertProfileOutputOutsideBuildOutput(e.profileOutputPath,e.outputDirectory);let t=e.profiler.finish(),n=await measureApplicationBuildOutput(e.outputDirectory);await writeApplicationBuildProfile(e.profileOutputPath,createApplicationBuildProfile({output:n,target:process.env.VERCEL?`vercel`:`local`,timing:t}))}catch(t){console.warn(`eve: failed to write optional build profile to ${e.profileOutputPath}; continuing with the published build output: ${toErrorMessage(t)}`)}}function isRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function normalizeEntrypoint(e,t){return typeof t!=`string`||t.trim().length===0?null:resolve(e,t)}function normalizeServiceRoot(e,t){return typeof t.root==`string`&&t.root.trim().length>0?resolve(e,t.root):normalizeEntrypoint(e,t.entrypoint)}function normalizeServicePrefix(e){return typeof e.routePrefix==`string`?e.routePrefix.trim():typeof e.mount==`string`?e.mount.trim():isRecord(e.mount)&&typeof e.mount.path==`string`&&e.mount.path.trim().length>0?e.mount.path.trim():``}function normalizeServiceCollection(e){if(isRecord(e))return Object.values(e).filter(isRecord);if(Array.isArray(e))return e.filter(isRecord)}function resolveCoDeployedEveServicePrefix(e){if(!isRecord(e.config))return;let t=normalizeServiceCollection(e.config.experimentalServices)??normalizeServiceCollection(e.config.experimentalServicesV2)??normalizeServiceCollection(e.config.services);if(t===void 0)return;let n=!1,r;for(let i of t){if(i.framework!==`eve`){n=!0;continue}let t=normalizeServiceRoot(e.configRoot,i),a=normalizeServicePrefix(i);t!==null&&e.appRoots.includes(t)&&a.length>0&&a!==`/`&&(r=a)}return n?r:void 0}async function resolveCoDeployedEveServicePrefixForVercelFunctionOutput(t,r){let a=Array.from(new Set([resolve(t),resolve(r)])),s=await findClosestVercelOutputDirectory(t);if(s!==void 0)try{let t=JSON.parse(await readFile(join(s,`config.json`),`utf8`)),n=resolveCoDeployedEveServicePrefix({appRoots:a,configRoot:await resolveVercelOutputConfigRoot(s),config:t});if(n!==void 0)return n}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}let c=t;for(;;){for(let t of[join(c,`vercel.json`),join(c,`.vercel`,`output`,`config.json`)])try{let r=JSON.parse(await readFile(t,`utf8`)),i=resolveCoDeployedEveServicePrefix({appRoots:a,configRoot:t.endsWith(`vercel.json`)?c:await resolveVercelOutputConfigRoot(dirname(t)),config:r});if(i!==void 0)return i}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}let t=dirname(c);if(t===c)return;c=t}}async function resolveVercelOutputConfigRoot(t){let r=dirname(dirname(t));try{let t=JSON.parse(await readFile(join(r,`.vercel`,`project.json`),`utf8`));if(isRecord(t)&&isRecord(t.settings)&&typeof t.settings.rootDirectory==`string`&&t.settings.rootDirectory.trim().length>0)return resolve(r,t.settings.rootDirectory)}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}return r}async function buildNitroOutput(e,t,n){let r=trimTrailingSlash(e.options.output.dir);return await measureBuildPhase(t,`${n}.cache.prepare`,()=>prepareEveVersionedCacheDirectory(r)),await measureBuildPhase(t,`${n}.prepare`,()=>prepare(e)),await measureBuildPhase(t,`${n}.public-assets`,()=>copyPublicAssets(e)),await measureBuildPhase(t,`${n}.prerender`,()=>prerender(e)),await measureBuildPhase(t,`${n}.bundle`,()=>build(e)),await measureBuildPhase(t,`${n}.cache.write`,()=>writeEveVersionedCacheMetadata(r)),r}async function buildApplication(e,t){let n=t.profileOutputPath===void 0?void 0:resolve(t.profileOutputPath),r=n===void 0?void 0:new ApplicationBuildProfiler,i=await measureBuildPhase(r,`extension.check`,()=>tryReadExtensionBuildConfig(e));if(i!==null)throw Error(`Package "${i.packageName}" is an eve extension. Run \`eve extension build\` instead of \`eve build\`.`);let a=await measureBuildPhase(r,`project.resolve`,()=>resolveDiscoveryProject(e)),s=await measureBuildPhase(r,`workspace.create`,()=>createApplicationBuildWorkspace(a.appRoot,t.vercelServiceOutput?.serviceOutputDirectory)),l=!1,u;try{u=await buildApplicationInWorkspace(s,t,r)}catch(e){throw l=e instanceof RecoverablePublicationError,e}finally{l||await measureBuildPhase(r,`workspace.remove`,()=>removeApplicationBuildWorkspace(s))}return r!==void 0&&n!==void 0&&await writeOptionalApplicationBuildProfile({outputDirectory:u,profileOutputPath:n,profiler:r}),u}async function buildApplicationInWorkspace(e,n,r){let i=await measureBuildPhase(r,`host.prepare`,()=>prepareProductionApplicationHost(e)),a=!!process.env.VERCEL,o=a?await measureBuildPhase(r,`vercel.service-prefix.resolve`,()=>resolveCoDeployedEveServicePrefixForVercelFunctionOutput(i.appRoot,i.compileResult.project.agentRoot)):void 0,s=await measureBuildPhase(r,`nitro.create`,()=>createProductionApplicationNitro(i,{buildDir:e.nitro.buildDir,outputDir:e.publication.output.stagedDir,publicRoutePrefix:n.publicRoutePrefix}));try{a&&!n.skipVercelSandboxPrewarm&&await measureBuildPhase(r,`sandbox.prewarm`,()=>runVercelBuildPrewarm({appRoot:i.appRoot,compiledArtifactsSource:createDiskRuntimeCompiledArtifactsSource(e.compiler.rootDir,{moduleMapLoaderPath:resolvePackageSourceFilePath(`src/internal/authored-module-map-loader.ts`),sandboxAppRoot:i.appRoot}),log(e){console.log(e)}})),await buildNitroOutput(s,r,`nitro`),a&&await measureBuildPhase(r,`vercel.workflow-function.materialize`,()=>materializeVercelWorkflowFunctionOutput(e.publication.output.stagedDir)),o!==void 0&&await measureBuildPhase(r,`vercel.functions.normalize`,()=>normalizeEveVercelFunctionOutput(e.publication.output.stagedDir,{servicePrefix:o}));let c=n.vercelServiceOutput;c!==void 0&&(await measureBuildPhase(r,`vercel.service-crons.normalize`,()=>normalizeVercelServiceCrons({publicRoutePrefix:n.publicRoutePrefix,serviceOutputDirectory:e.publication.output.stagedDir})),await measureBuildPhase(r,`vercel.host-middleware.copy`,()=>copyHostMiddlewareFunctions({hostOutputDirectory:c.hostOutputDirectory,serviceOutputDirectory:e.publication.output.stagedDir}))),await measureBuildPhase(r,`agent-summary.emit`,()=>emitVercelAgentSummary({manifest:i.compileResult.manifest,outputPath:e.publication.summary.stagedPath})),a||await measureBuildPhase(r,`compiler-artifacts.stage`,()=>stageProductionCompilerArtifacts({compilerArtifactsRoot:e.compiler.artifactsDir,outputDir:e.publication.output.stagedDir}))}finally{await measureBuildPhase(r,`nitro.close`,()=>s.close())}return await measureBuildPhase(r,`output.publish`,()=>publishCompletedApplicationBuild(e)),e.publication.output.finalDir}async function publishCompletedApplicationBuild(e){await publishApplicationBuildArtifacts({appRoot:e.appRoot,finalOutputDir:e.publication.output.finalDir,finalSummaryPath:e.publication.summary.finalPath,scratchDir:e.rootDir,stagedOutputDir:e.publication.output.stagedDir,stagedSummaryPath:e.publication.summary.stagedPath})}export{buildApplication};
@@ -1,2 +1,2 @@
1
- import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{join,relative,resolve}from"node:path";import{discoverAgent}from"#discover/discover-agent.js";import{mkdir,mkdtemp,rm}from"node:fs/promises";import{createDiskProjectSource}from"#discover/project-source.js";import{discoverFlatModuleSource,readSortedDirectoryEntries}from"#discover/grammar.js";import{EXTENSION_COMPATIBILITY_MANIFEST_FORMAT_VERSION,EXTENSION_COMPATIBILITY_MANIFEST_KIND,writeExtensionCompatibilityManifest}from"#compiler/extension-compatibility.js";import{ensureExtensionExports,tryReadExtensionBuildConfig}from"#internal/nitro/host/extension-build-config.js";import{deriveExtensionCapabilityRequirements}from"#internal/nitro/host/extension-capability-requirements.js";import{ExtensionOutputRestoreError,emitExtensionDistribution,replaceExtensionBuildOutput}from"#internal/nitro/host/extension-distribution.js";async function buildExtensionPackage(t,n){let r=resolve(t),i=createDiskProjectSource(),{diagnostics:a,manifest:o}=await discoverAgent({agentRoot:n.sourceRoot,appRoot:r,source:i,role:`extension`}),s=a.filter(e=>e.severity===`error`);if(s.length>0)throw Error(`Cannot build extension "${n.packageName}":\n${s.map(e=>` - ${e.message}`).join(`
1
+ import{mkdir,mkdtemp,rm}from"node:fs/promises";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{join,relative,resolve}from"node:path";import{discoverAgent}from"#discover/discover-agent.js";import{createDiskProjectSource}from"#discover/project-source.js";import{discoverFlatModuleSource,readSortedDirectoryEntries}from"#discover/grammar.js";import{EXTENSION_COMPATIBILITY_MANIFEST_FORMAT_VERSION,EXTENSION_COMPATIBILITY_MANIFEST_KIND,writeExtensionCompatibilityManifest}from"#compiler/extension-compatibility.js";import{ensureExtensionExports,tryReadExtensionBuildConfig}from"#internal/nitro/host/extension-build-config.js";import{deriveExtensionCapabilityRequirements}from"#internal/nitro/host/extension-capability-requirements.js";import{ExtensionOutputRestoreError,emitExtensionDistribution,replaceExtensionBuildOutput}from"#internal/nitro/host/extension-distribution.js";async function buildExtensionPackage(t,n){let r=resolve(t),i=createDiskProjectSource(),{diagnostics:a,manifest:o}=await discoverAgent({agentRoot:n.sourceRoot,appRoot:r,source:i,role:`extension`}),s=a.filter(e=>e.severity===`error`);if(s.length>0)throw Error(`Cannot build extension "${n.packageName}":\n${s.map(e=>` - ${e.message}`).join(`
2
2
  `)}`);let c=discoverFlatModuleSource({rootEntries:await readSortedDirectoryEntries(i,n.sourceRoot),rootPath:n.sourceRoot,slotName:`extension`}).module;if(c===void 0)throw Error(`Cannot build extension "${n.packageName}": its source root "${n.sourceRoot}" is missing an "extension.<ext>" declaration. Add \`export default defineExtension(...)\` there (with or without config).`);let l=await mkdtemp(join(r,`.eve-extension-build-`)),u=join(l,`output`),d=join(u,relative(n.outDir,n.distRoot)),f=!1;try{return await mkdir(d,{recursive:!0}),await emitExtensionDistribution({appRoot:r,declarationModule:c,declarationsRoot:join(l,`declarations`),manifest:o,runtimeDependencies:n.runtimeDependencies,shortName:n.shortName,sourceRoot:n.sourceRoot,stagedDistRoot:d,stagedOutDir:u,transactionRoot:l}),await writeExtensionCompatibilityManifest(d,{kind:EXTENSION_COMPATIBILITY_MANIFEST_KIND,formatVersion:EXTENSION_COMPATIBILITY_MANIFEST_FORMAT_VERSION,builtWithEve:resolveInstalledPackageInfo().version,requires:await deriveExtensionCapabilityRequirements({declarationModule:c,manifest:o,runtimeDependencies:n.runtimeDependencies,sourceRoot:n.sourceRoot})}),await ensureExtensionExports(r,n.outDir),await replaceExtensionBuildOutput({outDir:n.outDir,stagedOutDir:u,transactionRoot:l}),n.outDir}catch(e){throw f=e instanceof ExtensionOutputRestoreError,e}finally{f||await rm(l,{force:!0,recursive:!0})}}export{buildExtensionPackage,tryReadExtensionBuildConfig};
@@ -1 +1 @@
1
- import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{dirname}from"node:path";import{mkdir,writeFile}from"node:fs/promises";import{VERCEL_EVE_AGENT_SUMMARY_KIND,VERCEL_EVE_AGENT_SUMMARY_VERSION,normalizeChannelKindForDisplay}from"#internal/vercel-agent-summary.js";function buildVercelAgentSummary(t){let{manifest:n}=t;return{kind:VERCEL_EVE_AGENT_SUMMARY_KIND,schemaVersion:VERCEL_EVE_AGENT_SUMMARY_VERSION,generatorVersion:t.generatorVersion??resolveInstalledPackageInfo().version,agent:{name:n.config.name,description:n.config.description,modelId:n.config.model.id},instructions:n.instructions?toInstructionsEntry(n.instructions):null,schedules:n.schedules.map(toScheduleEntry),tools:n.tools.map(toToolEntry),skills:n.skills.map(toSkillEntry),connections:n.connections.map(toConnectionEntry),channels:n.channels.filter(isActiveChannel).map(toChannelEntry),sandbox:n.sandbox===null?null:{logicalPath:n.sandbox.logicalPath},subagents:n.subagents.map(toSubagentEntry),diagnostics:{errors:n.diagnosticsSummary.errors,warnings:n.diagnosticsSummary.warnings}}}async function emitVercelAgentSummary(e){let r=buildVercelAgentSummary({generatorVersion:e.generatorVersion,manifest:e.manifest});return await mkdir(dirname(e.outputPath),{recursive:!0}),await writeFile(e.outputPath,`${JSON.stringify(r,null,2)}\n`),e.outputPath}function isActiveChannel(e){return e.kind===`channel`}function toInstructionsEntry(e){return{logicalPath:e.logicalPath,sourceKind:e.sourceKind,markdown:e.markdown}}function toScheduleEntry(e){return{name:e.name,cron:e.cron,logicalPath:e.logicalPath}}function toToolEntry(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath}}function toSkillEntry(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath,sourceKind:e.sourceKind}}function toConnectionEntry(e){let t={name:e.connectionName,description:e.description,url:e.url,logicalPath:e.logicalPath,type:e.protocol};return e.vercelConnect===void 0?t:{...t,vercelConnect:{connector:e.vercelConnect.connector}}}function toChannelEntry(e){let t={name:e.name,method:e.method,urlPath:e.urlPath,type:normalizeChannelKindForDisplay(e.adapterKind),logicalPath:e.logicalPath};return e.adapterKind===void 0?t:{...t,adapterKind:e.adapterKind}}function toSubagentEntry(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath}}export{buildVercelAgentSummary,emitVercelAgentSummary};
1
+ import{mkdir,writeFile}from"node:fs/promises";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{dirname}from"node:path";import{VERCEL_EVE_AGENT_SUMMARY_KIND,VERCEL_EVE_AGENT_SUMMARY_VERSION,normalizeChannelKindForDisplay}from"#internal/vercel-agent-summary.js";function buildVercelAgentSummary(e){let{manifest:t}=e;return{kind:VERCEL_EVE_AGENT_SUMMARY_KIND,schemaVersion:VERCEL_EVE_AGENT_SUMMARY_VERSION,generatorVersion:e.generatorVersion??resolveInstalledPackageInfo().version,agent:{name:t.config.name,description:t.config.description,modelId:t.config.model.id},instructions:t.instructions?toInstructionsEntry(t.instructions):null,schedules:t.schedules.map(toScheduleEntry),tools:t.tools.map(toToolEntry),skills:t.skills.map(toSkillEntry),connections:t.connections.map(toConnectionEntry),channels:t.channels.filter(isActiveChannel).map(toChannelEntry),sandbox:t.sandbox===null?null:{logicalPath:t.sandbox.logicalPath},subagents:t.subagents.map(toSubagentEntry),diagnostics:{errors:t.diagnosticsSummary.errors,warnings:t.diagnosticsSummary.warnings}}}async function emitVercelAgentSummary(n){let r=buildVercelAgentSummary({generatorVersion:n.generatorVersion,manifest:n.manifest});return await mkdir(dirname(n.outputPath),{recursive:!0}),await writeFile(n.outputPath,`${JSON.stringify(r,null,2)}\n`),n.outputPath}function isActiveChannel(e){return e.kind===`channel`}function toInstructionsEntry(e){return{logicalPath:e.logicalPath,sourceKind:e.sourceKind,markdown:e.markdown}}function toScheduleEntry(e){return{name:e.name,cron:e.cron,logicalPath:e.logicalPath}}function toToolEntry(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath}}function toSkillEntry(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath,sourceKind:e.sourceKind}}function toConnectionEntry(e){let t={name:e.connectionName,description:e.description,url:e.url,logicalPath:e.logicalPath,type:e.protocol};return e.vercelConnect===void 0?t:{...t,vercelConnect:{connector:e.vercelConnect.connector}}}function toChannelEntry(e){let t={name:e.name,method:e.method,urlPath:e.urlPath,type:normalizeChannelKindForDisplay(e.adapterKind),logicalPath:e.logicalPath};return e.adapterKind===void 0?t:{...t,adapterKind:e.adapterKind}}function toSubagentEntry(e){return{name:e.name,description:e.description,logicalPath:e.logicalPath}}export{buildVercelAgentSummary,emitVercelAgentSummary};
@@ -1,4 +1,4 @@
1
- import{EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN,EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH,EVE_HEALTH_ROUTE_PATH}from"#protocol/routes.js";import{resolvePackageRoot,resolvePackageSourceFilePath,resolveWorkflowModulePath}from"#internal/application/package.js";import{dirname,join,relative}from"node:path";import{mkdir,writeFile}from"node:fs/promises";import{isVercelBuildEnvironment}from"#internal/application/paths.js";import{normalizeEsmImportSpecifier,stringifyEsmImportSpecifier}from"#internal/application/import-specifier.js";import{usesParentDevelopmentWorkflowWorld}from"#internal/workflow/development-world-protocol.js";import{WorkflowBundleBuilder}from"#internal/workflow-bundle/builder.js";import{createDevelopmentNitroArtifactsConfig,createProductionNitroArtifactsConfig}from"#internal/nitro/host/artifacts-config.js";import{deriveEveWorkflowQueuePrefix}from"#internal/workflow/queue-namespace.js";import{computeChannelRouteRegistrations,registerChannelVirtualHandlers}from"#internal/nitro/host/channel-routes.js";import{EVE_WORKFLOW_FLOW_ROUTE_PATH}from"#internal/nitro/host/vercel-build-output-config.js";function registerHandler(e,t){let n=`#eve-route-handler/${t.method??`ALL`} ${t.route}`,r=stringifyEsmImportSpecifier(t.handlerPath);e.options.handlers.push({handler:n,method:t.method,route:t.route}),e.options.virtual[n]=[`import handler from ${r};`,`export default handler;`].join(`
2
- `)}function resolveNitroWorkflowBuildDirectory(e){return join(e.options.buildDir,`workflow`)}function createRelativeImportSpecifier(e,t){let n=relative(e,t).replaceAll(`\\`,`/`);return n.startsWith(`.`)?n:`./${n}`}async function addWorkflowFileHandler(e,t){let n=join(resolveNitroWorkflowBuildDirectory(e),`${t.bundleName}-handler.mjs`),r=dirname(n),i=createRelativeImportSpecifier(r,t.bundlePath),a=t.directHandlers??[],s=a.length>0&&t.workflowWorldPluginPath!==void 0?createRelativeImportSpecifier(r,t.workflowWorldPluginPath):void 0,c=a.map(e=>{let t=createRelativeImportSpecifier(r,e.bundlePath);return{importSpecifier:t,isOwnBundle:t===i,queuePrefix:e.queuePrefix}});await mkdir(r,{recursive:!0}),await writeFile(n,buildWorkflowFileHandlerSource({bundlePath:i,directHandlers:c,runtimeImportSpecifier:t.runtimeImportSpecifier,workflowWorldPluginImportSpecifier:s})),e.options.handlers.push({handler:n,route:t.route})}function buildWorkflowFileHandlerSource(e){let t=[`// Generated by eve. Do not edit by hand.`,`import { POST } from ${JSON.stringify(e.bundlePath)};`];if(e.directHandlers.length>0&&e.runtimeImportSpecifier!==void 0){let n=0,r=e.directHandlers.map(e=>{if(e.isOwnBundle)return{...e,binding:`POST`};let t=`__eveWorkflowDirectHandler${n}`;return n+=1,{...e,binding:t}});for(let e of r)e.isOwnBundle||t.push(`import { POST as ${e.binding} } from ${JSON.stringify(e.importSpecifier)};`);e.workflowWorldPluginImportSpecifier!==void 0&&t.push(`import ${JSON.stringify(e.workflowWorldPluginImportSpecifier)};`),t.push(`import { getWorld as __eveGetWorkflowWorld } from ${JSON.stringify(e.runtimeImportSpecifier)};`,``,`try {`,` const __eveWorkflowWorld = await __eveGetWorkflowWorld();`,` if (typeof __eveWorkflowWorld?.registerHandler === "function") {`);for(let e of r)t.push(` __eveWorkflowWorld.registerHandler(${JSON.stringify(e.queuePrefix)}, ${e.binding});`);t.push(` }`,`} catch (err) {`,` console.warn("[eve] Failed to register direct workflow queue handlers:", err);`,`}`)}return t.push(``,`export default async ({ req }) => {`,` return await POST(req);`,`};`,``),t.join(`
1
+ import{mkdir,writeFile}from"node:fs/promises";import{EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN,EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH,EVE_HEALTH_ROUTE_PATH}from"#protocol/routes.js";import{resolvePackageRoot,resolvePackageSourceFilePath,resolveWorkflowModulePath}from"#internal/application/package.js";import{dirname,join,relative}from"node:path";import{isVercelBuildEnvironment}from"#internal/application/paths.js";import{normalizeEsmImportSpecifier,stringifyEsmImportSpecifier}from"#internal/application/import-specifier.js";import{usesParentDevelopmentWorkflowWorld}from"#internal/workflow/development-world-protocol.js";import{WorkflowBundleBuilder}from"#internal/workflow-bundle/builder.js";import{createDevelopmentNitroArtifactsConfig,createProductionNitroArtifactsConfig}from"#internal/nitro/host/artifacts-config.js";import{deriveEveWorkflowQueuePrefix}from"#internal/workflow/queue-namespace.js";import{computeChannelRouteRegistrations,registerChannelVirtualHandlers}from"#internal/nitro/host/channel-routes.js";import{EVE_WORKFLOW_FLOW_ROUTE_PATH}from"#internal/nitro/host/vercel-build-output-config.js";function registerHandler(e,t){let n=`#eve-route-handler/${t.method??`ALL`} ${t.route}`,r=stringifyEsmImportSpecifier(t.handlerPath);e.options.handlers.push({handler:n,method:t.method,route:t.route}),e.options.virtual[n]=[`import handler from ${r};`,`export default handler;`].join(`
2
+ `)}function resolveNitroWorkflowBuildDirectory(e){return join(e.options.buildDir,`workflow`)}function createRelativeImportSpecifier(e,t){let n=relative(e,t).replaceAll(`\\`,`/`);return n.startsWith(`.`)?n:`./${n}`}async function addWorkflowFileHandler(n,r){let i=join(resolveNitroWorkflowBuildDirectory(n),`${r.bundleName}-handler.mjs`),a=dirname(i),o=createRelativeImportSpecifier(a,r.bundlePath),s=r.directHandlers??[],c=s.length>0&&r.workflowWorldPluginPath!==void 0?createRelativeImportSpecifier(a,r.workflowWorldPluginPath):void 0,l=s.map(e=>{let t=createRelativeImportSpecifier(a,e.bundlePath);return{importSpecifier:t,isOwnBundle:t===o,queuePrefix:e.queuePrefix}});await mkdir(a,{recursive:!0}),await writeFile(i,buildWorkflowFileHandlerSource({bundlePath:o,directHandlers:l,runtimeImportSpecifier:r.runtimeImportSpecifier,workflowWorldPluginImportSpecifier:c})),n.options.handlers.push({handler:i,route:r.route})}function buildWorkflowFileHandlerSource(e){let t=[`// Generated by eve. Do not edit by hand.`,`import { POST } from ${JSON.stringify(e.bundlePath)};`];if(e.directHandlers.length>0&&e.runtimeImportSpecifier!==void 0){let n=0,r=e.directHandlers.map(e=>{if(e.isOwnBundle)return{...e,binding:`POST`};let t=`__eveWorkflowDirectHandler${n}`;return n+=1,{...e,binding:t}});for(let e of r)e.isOwnBundle||t.push(`import { POST as ${e.binding} } from ${JSON.stringify(e.importSpecifier)};`);e.workflowWorldPluginImportSpecifier!==void 0&&t.push(`import ${JSON.stringify(e.workflowWorldPluginImportSpecifier)};`),t.push(`import { getWorld as __eveGetWorkflowWorld } from ${JSON.stringify(e.runtimeImportSpecifier)};`,``,`try {`,` const __eveWorkflowWorld = await __eveGetWorkflowWorld();`,` if (typeof __eveWorkflowWorld?.registerHandler === "function") {`);for(let e of r)t.push(` __eveWorkflowWorld.registerHandler(${JSON.stringify(e.queuePrefix)}, ${e.binding});`);t.push(` }`,`} catch (err) {`,` console.warn("[eve] Failed to register direct workflow queue handlers:", err);`,`}`)}return t.push(``,`export default async ({ req }) => {`,` return await POST(req);`,`};`,``),t.join(`
3
3
  `)}function addFrameworkVirtualHandler(e,t){let n=`#eve-route${t.route}`,r=stringifyEsmImportSpecifier(t.modulePath);e.options.handlers.push({handler:n,method:t.method,route:t.route}),e.options.virtual[n]=[`import { ${t.handlerExport} } from ${r};`,`export default async (event) => ${t.handlerExport}(${t.args}, event.req);`].join(`
4
- `)}async function registerWorkflowArtifactBuildHook(e,t){let n=!0;await t(),e.hooks.hook(`build:before`,async()=>{if(n){n=!1;return}await t()})}function registerApplicationRoutes(e,t,r){addFrameworkVirtualHandler(e,{args:JSON.stringify({agentName:t.compileResult.manifest.config.name}),handlerExport:`handleHomePageRequest`,method:`GET`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/index.ts`),route:`/`});for(let t of[`GET`,`HEAD`])registerHandler(e,{handlerPath:resolvePackageSourceFilePath(`src/internal/nitro/routes/health.ts`),method:t,route:EVE_HEALTH_ROUTE_PATH});registerChannelVirtualHandlers(e,{artifactsConfig:r,registrations:computeChannelRouteRegistrations(t)})}function registerDevelopmentControlRoutes(n,r){addFrameworkVirtualHandler(n,{args:JSON.stringify({appRoot:r.appRoot}),handlerExport:`handleDevRuntimeArtifactsRequest`,method:`GET`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/dev-runtime-artifacts.ts`),route:EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH}),addFrameworkVirtualHandler(n,{args:JSON.stringify(r),handlerExport:`handleDevScheduleDispatchRequest`,method:`POST`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/dev-schedule-dispatch.ts`),route:EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN})}function createWorkflowDirectHandlerEntry(e,t){return{bundlePath:t,queuePrefix:deriveEveWorkflowQueuePrefix(e.compileResult.manifest.config.name)}}async function registerWorkflowRoute(e,t,n,r){await addWorkflowFileHandler(e,{bundleName:`workflows`,bundlePath:n,directHandlers:r,route:EVE_WORKFLOW_FLOW_ROUTE_PATH,runtimeImportSpecifier:r.length===0?void 0:normalizeEsmImportSpecifier(resolveWorkflowModulePath(`workflow/runtime`)),workflowWorldPluginPath:t.compiledArtifacts.workflowWorldPluginPath})}async function configureDevelopmentNitroRoutes(e,t){let n=resolveNitroWorkflowBuildDirectory(e),i=new WorkflowBundleBuilder({agentName:t.compileResult.manifest.config.name,appRoot:t.appRoot,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,outDir:t.workflowBuildDir,rootDir:resolvePackageRoot(),watch:!0});await registerWorkflowArtifactBuildHook(e,async()=>{await i.build({nitroStepOutfile:join(n,`steps.mjs`),nitroWorkflowOutfile:join(n,`workflows.mjs`)})});let a=createDevelopmentNitroArtifactsConfig({appRoot:t.appRoot,configuredWorld:t.compileResult.manifest.config.experimental?.workflow?.world});registerApplicationRoutes(e,t,a),registerDevelopmentControlRoutes(e,a);let o=join(n,`workflows.mjs`),s=[];usesParentDevelopmentWorkflowWorld(t.compileResult.manifest.config.experimental?.workflow?.world)||s.push(createWorkflowDirectHandlerEntry(t,o)),await registerWorkflowRoute(e,t,o,s),e.routing.sync()}async function configureProductionNitroRoutes(e,t){let n=new WorkflowBundleBuilder({agentName:t.compileResult.manifest.config.name,appRoot:t.appRoot,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,outDir:t.workflowBuildDir,rootDir:resolvePackageRoot(),watch:!1});await registerWorkflowArtifactBuildHook(e,async()=>{await n.build({nitroStepOutfile:join(resolveNitroWorkflowBuildDirectory(e),`steps.mjs`)})}),registerApplicationRoutes(e,t,createProductionNitroArtifactsConfig());let i=join(t.workflowBuildDir,`workflows.mjs`),a=t.compileResult.manifest.config.experimental?.workflow?.world!==void 0;await registerWorkflowRoute(e,t,i,!isVercelBuildEnvironment()&&a?[createWorkflowDirectHandlerEntry(t,i)]:[]),e.routing.sync()}export{configureDevelopmentNitroRoutes,configureProductionNitroRoutes};
4
+ `)}async function registerWorkflowArtifactBuildHook(e,t){let n=!0;await t(),e.hooks.hook(`build:before`,async()=>{if(n){n=!1;return}await t()})}function registerApplicationRoutes(e,t,n){addFrameworkVirtualHandler(e,{args:JSON.stringify({agentName:t.compileResult.manifest.config.name}),handlerExport:`handleHomePageRequest`,method:`GET`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/index.ts`),route:`/`});for(let t of[`GET`,`HEAD`])registerHandler(e,{handlerPath:resolvePackageSourceFilePath(`src/internal/nitro/routes/health.ts`),method:t,route:EVE_HEALTH_ROUTE_PATH});registerChannelVirtualHandlers(e,{artifactsConfig:n,registrations:computeChannelRouteRegistrations(t)})}function registerDevelopmentControlRoutes(e,t){addFrameworkVirtualHandler(e,{args:JSON.stringify({appRoot:t.appRoot}),handlerExport:`handleDevRuntimeArtifactsRequest`,method:`GET`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/dev-runtime-artifacts.ts`),route:EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH}),addFrameworkVirtualHandler(e,{args:JSON.stringify(t),handlerExport:`handleDevScheduleDispatchRequest`,method:`POST`,modulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/dev-schedule-dispatch.ts`),route:EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN})}function createWorkflowDirectHandlerEntry(e,t){return{bundlePath:t,queuePrefix:deriveEveWorkflowQueuePrefix(e.compileResult.manifest.config.name)}}async function registerWorkflowRoute(e,t,n,r){await addWorkflowFileHandler(e,{bundleName:`workflows`,bundlePath:n,directHandlers:r,route:EVE_WORKFLOW_FLOW_ROUTE_PATH,runtimeImportSpecifier:r.length===0?void 0:normalizeEsmImportSpecifier(resolveWorkflowModulePath(`workflow/runtime`)),workflowWorldPluginPath:t.compiledArtifacts.workflowWorldPluginPath})}async function configureDevelopmentNitroRoutes(e,t){let n=resolveNitroWorkflowBuildDirectory(e),r=new WorkflowBundleBuilder({agentName:t.compileResult.manifest.config.name,appRoot:t.appRoot,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,outDir:t.workflowBuildDir,rootDir:resolvePackageRoot(),watch:!0});await registerWorkflowArtifactBuildHook(e,async()=>{await r.build({nitroStepOutfile:join(n,`steps.mjs`),nitroWorkflowOutfile:join(n,`workflows.mjs`)})});let i=createDevelopmentNitroArtifactsConfig({appRoot:t.appRoot,configuredWorld:t.compileResult.manifest.config.experimental?.workflow?.world});registerApplicationRoutes(e,t,i),registerDevelopmentControlRoutes(e,i);let o=join(n,`workflows.mjs`),s=[];usesParentDevelopmentWorkflowWorld(t.compileResult.manifest.config.experimental?.workflow?.world)||s.push(createWorkflowDirectHandlerEntry(t,o)),await registerWorkflowRoute(e,t,o,s),e.routing.sync()}async function configureProductionNitroRoutes(e,t){let n=new WorkflowBundleBuilder({agentName:t.compileResult.manifest.config.name,appRoot:t.appRoot,compiledArtifactsBootstrapPath:t.compiledArtifacts.bootstrapPath,outDir:t.workflowBuildDir,rootDir:resolvePackageRoot(),watch:!1});await registerWorkflowArtifactBuildHook(e,async()=>{await n.build({nitroStepOutfile:join(resolveNitroWorkflowBuildDirectory(e),`steps.mjs`)})}),registerApplicationRoutes(e,t,createProductionNitroArtifactsConfig());let r=join(t.workflowBuildDir,`workflows.mjs`),i=t.compileResult.manifest.config.experimental?.workflow?.world!==void 0;await registerWorkflowRoute(e,t,r,!isVercelBuildEnvironment()&&i?[createWorkflowDirectHandlerEntry(t,r)]:[]),e.routing.sync()}export{configureDevelopmentNitroRoutes,configureProductionNitroRoutes};
@@ -1 +1 @@
1
- import{dirname,join,posix,resolve,sep}from"node:path";import{access,cp,mkdir,readFile}from"node:fs/promises";function isRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const NEXT_MIDDLEWARE_PATH=`/_middleware`;function resolveMiddlewareFunctionDirectory(e,t){let a=posix.normalize(t.replace(/^\/+/,``));if(a.length===0||a===`.`||a===`..`||a.startsWith(`../`)||a.includes(`\\`)||a.includes(`\0`))throw Error(`Invalid Vercel middlewarePath: ${JSON.stringify(t)}.`);let o=resolve(e,`functions`),s=resolve(o,`${a}.func`);if(!s.startsWith(`${o}${sep}`))throw Error(`Vercel middlewarePath escapes the functions directory: ${t}.`);return s}async function copyHostMiddlewareFunctions(n){let r;try{r=await readFile(join(n.hostOutputDirectory,`config.json`),`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let i=JSON.parse(r);if(!isRecord(i))return;let c=new Set;if(Array.isArray(i.routes))for(let e of i.routes)isRecord(e)&&typeof e.middlewarePath==`string`&&c.add(e.middlewarePath);let l=resolveMiddlewareFunctionDirectory(n.hostOutputDirectory,NEXT_MIDDLEWARE_PATH);try{await access(l),c.add(NEXT_MIDDLEWARE_PATH)}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}for(let t of c){let r=resolveMiddlewareFunctionDirectory(n.hostOutputDirectory,t),i=resolveMiddlewareFunctionDirectory(n.serviceOutputDirectory,t);await mkdir(dirname(i),{recursive:!0}),await cp(r,i,{force:!0,recursive:!0})}}export{copyHostMiddlewareFunctions};
1
+ import{access,cp,mkdir,readFile}from"node:fs/promises";import{dirname,join,posix,resolve,sep}from"node:path";function isRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const NEXT_MIDDLEWARE_PATH=`/_middleware`;function resolveMiddlewareFunctionDirectory(e,t){let n=posix.normalize(t.replace(/^\/+/,``));if(n.length===0||n===`.`||n===`..`||n.startsWith(`../`)||n.includes(`\\`)||n.includes(`\0`))throw Error(`Invalid Vercel middlewarePath: ${JSON.stringify(t)}.`);let r=resolve(e,`functions`),i=resolve(r,`${n}.func`);if(!i.startsWith(`${r}${sep}`))throw Error(`Vercel middlewarePath escapes the functions directory: ${t}.`);return i}async function copyHostMiddlewareFunctions(o){let s;try{s=await readFile(join(o.hostOutputDirectory,`config.json`),`utf8`)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let c=JSON.parse(s);if(!isRecord(c))return;let l=new Set;if(Array.isArray(c.routes))for(let e of c.routes)isRecord(e)&&typeof e.middlewarePath==`string`&&l.add(e.middlewarePath);let u=resolveMiddlewareFunctionDirectory(o.hostOutputDirectory,NEXT_MIDDLEWARE_PATH);try{await access(u),l.add(NEXT_MIDDLEWARE_PATH)}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ENOENT`))throw e}for(let e of l){let r=resolveMiddlewareFunctionDirectory(o.hostOutputDirectory,e),a=resolveMiddlewareFunctionDirectory(o.serviceOutputDirectory,e);await mkdir(dirname(a),{recursive:!0}),await cp(r,a,{force:!0,recursive:!0})}}export{copyHostMiddlewareFunctions};
@@ -1 +1 @@
1
- import{resolvePackageRoot,resolvePackageSourceDirectoryPath,resolvePackageSourceFilePath,resolveWorkflowModulePath}from"#internal/application/package.js";import{dirname,isAbsolute,join,relative,resolve}from"node:path";import{readFile}from"node:fs/promises";import{fileURLToPath}from"node:url";import{EVE_PACKAGE_NAME}from"#internal/package-name.js";import{createExtensionScopePlugin}from"#internal/bundler/extension-scope-plugin.js";import{createNitro}from"nitro/builder";import{prepareEveVersionedCacheDirectory,writeEveVersionedCacheMetadata}from"#internal/application/cache-metadata.js";import{createProductionNitroArtifactsConfig}from"#internal/nitro/host/artifacts-config.js";import{createEveVercelOptions}from"#internal/nitro/host/vercel-build-output-config.js";import{createCompiledSandboxBackendPrunePlugin}from"#internal/nitro/host/compiled-sandbox-backend-prune-plugin.js";import{configureDevelopmentNitroRoutes,configureProductionNitroRoutes}from"#internal/nitro/host/configure-nitro-routes.js";import{applyEveCronHandlerRoute}from"#internal/nitro/host/cron-handler-route.js";import{createNitroBundlerConfig}from"#internal/nitro/host/nitro-bundler-config.js";import{OPTIONAL_ENGINE_PACKAGES_BY_BACKEND_NAME,createOptionalEngineDependencyPlugin}from"#internal/nitro/host/optional-engine-dependency-plugin.js";import{addNitroRoutingImportSpecifierPlugin}from"#internal/nitro/host/nitro-routing-import-specifier-plugin.js";import{registerScheduleTaskHandlers}from"#internal/nitro/host/schedule-task-routes.js";import{applyWorkflowTransform}from"#internal/workflow-bundle/workflow-builders.js";import{transformDynamicToolExecute}from"#internal/workflow-bundle/dynamic-tool-transform.js";const WORKFLOW_ALIAS_SPECIFIERS=[`workflow`,`workflow/api`,`workflow/errors`,`workflow/internal/builtins`,`workflow/internal/private`,`workflow/runtime`],WORKFLOW_TRANSFORM_PATCHED=Symbol(`eve.workflow-transform-patched`),FRAMEWORK_HOSTED_EXTERNAL_PACKAGES=[`@napi-rs/keyring`],LOCAL_SANDBOX_BACKEND_NAMES=new Set([`docker`,...Object.keys(OPTIONAL_ENGINE_PACKAGES_BY_BACKEND_NAME)]);function resolveWorkflowAliases(){let e={};for(let t of WORKFLOW_ALIAS_SPECIFIERS)e[t]=resolveWorkflowModulePath(t);return e}function resolveProductionNitroPreset(){return process.env.VERCEL?`vercel`:void 0}function manifestEnablesWorkflow(e){return[e,...e.subagents.map(e=>e.agent)].some(e=>e.workflowTool!==void 0)}function manifestHasWebSocketChannel(e){return e.channels.some(e=>e.kind===`channel`&&e.method===`WEBSOCKET`)}function collectHostedTraceDependencies(e,t){let n=[e.compileResult.manifest,...e.compileResult.manifest.subagents.map(e=>e.agent)].flatMap(e=>e.config.build?.externalDependencies??[]);return[...new Set([...FRAMEWORK_HOSTED_EXTERNAL_PACKAGES,...t,...n])].filter(e=>e!==EVE_PACKAGE_NAME)}function collectConfiguredSandboxBackendNames(e){let t=[e,...e.subagents.map(e=>e.agent)];return new Set(t.map(e=>e.sandbox?.backendName).filter(e=>typeof e==`string`))}function shouldPruneLocalSandboxBackends(e){return e.preset===`vercel`&&![...e.configuredBackendNames].some(e=>LOCAL_SANDBOX_BACKEND_NAMES.has(e))}function createDevelopmentWatchOptions(e){return{ignored:[e,join(e,`**`)]}}function normalizePath(e){return e.replaceAll(`\\`,`/`)}function stripPathQueryAndHash(e){let t=e.indexOf(`?`),n=e.indexOf(`#`),r=t===-1?n:n===-1?t:Math.min(t,n);return r===-1?e:e.slice(0,r)}function stripFileSystemPrefix(e){return e.startsWith(`/@fs/`)?e.slice(4):e}function resolveNitroModuleComparisonPath(e,t){return t.startsWith(`file://`)?normalizePath(stripFileSystemPrefix(stripPathQueryAndHash(fileURLToPath(t)))):isAbsolute(t)?normalizePath(stripFileSystemPrefix(stripPathQueryAndHash(t))):normalizePath(stripFileSystemPrefix(stripPathQueryAndHash(resolve(e,t))))}function isWorkflowBundlePath(e,t){let n=normalizePath(e);return n.startsWith(t)||n.includes(`/.eve/workflow-cache/`)}function normalizeStepTransformComparisonPath(e){let t=normalizePath(e);return process.platform===`win32`?t.toLowerCase():t}function parseImportedModuleSpecifiers(e){let t=/^\s*import\s+(?:.+?\s+from\s+)?["']([^"']+)["'];?\s*$/gm,n=[];for(let r of e.matchAll(t)){let e=r[1];e!==void 0&&n.push(e)}return n}function resolveNitroImportPath(e,t,n){return t.startsWith(`workflow`)?resolveWorkflowModulePath(t):t.startsWith(`.`)||t.startsWith(`/`)||t.startsWith(`file://`)?resolveNitroModuleComparisonPath(n===void 0?e:dirname(resolveNitroModuleComparisonPath(e,n)),t):null}async function collectNitroStepTransformTargets(e,t){let n=await readFile(e,`utf8`),r=new Set;for(let i of parseImportedModuleSpecifiers(n)){let n=resolveNitroImportPath(t,i,e);n!==null&&r.add(normalizeStepTransformComparisonPath(n))}return r}async function addNitroStepNoExternals(e,t){if(e.options.noExternals===!0)return;let n;try{n=await collectNitroStepTransformTargets(t,e.options.rootDir)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let r=Array.isArray(e.options.noExternals)?[...e.options.noExternals]:[];e.options.noExternals=[...new Set([...r,...n])]}function createRelativeTransformFilename(e,t){let n=createPackageRelativeTransformFilename(t);if(n!==void 0)return n;let r=normalizePath(e).replace(/\/$/,``),i=normalizePath(t),a=r.toLowerCase(),o=i.toLowerCase();if(o.startsWith(`${a}/`))return i.slice(r.length+1);if(o===a)return`.`;let c=relative(r,i).replaceAll(`\\`,`/`);if(c.startsWith(`../`)&&(c=c.split(`/`).filter(e=>e!==`..`).join(`/`)),c.includes(`:`)||c.startsWith(`/`)){let e=i.split(`/`).pop();return e===void 0||e.length===0?`unknown.ts`:e}return c}function createPackageRelativeTransformFilename(t){let n=normalizePath(resolvePackageRoot()).replace(/\/$/,``),r=normalizePath(t),i=n.toLowerCase(),a=r.toLowerCase(),o=`${n}/src/`,s=`${i}/src/`,c=`${n}/dist/src/`,l=`${i}/dist/src/`;if(a.startsWith(s))return`src/${r.slice(o.length)}`;if(a.startsWith(l))return`src/${r.slice(c.length)}`}function addWorkflowModuleSideEffectsPlugin(e,t){let n=[t,join(e.options.buildDir,`workflow`)].map(t=>resolveNitroModuleComparisonPath(e.options.rootDir,t));e.hooks.hook(`rollup:before`,(t,r)=>{Array.isArray(r.plugins)&&r.plugins.unshift({name:`eve:workflow-module-side-effects`,resolveId(t,r){let i=resolveNitroImportPath(e.options.rootDir,t,r)??resolveNitroModuleComparisonPath(e.options.rootDir,t);return n.some(e=>isWorkflowBundlePath(i,e))?{id:i,moduleSideEffects:`no-treeshake`}:null}})})}function addNitroStepModuleSideEffectsPlugin(e,t){let n=null,getStepTransformTargets=async()=>(n===null&&(n=await collectNitroStepTransformTargets(t.stepEntrypointPath,e.options.rootDir)),n),clearCachedStepTransformTargets=()=>{n=null};return e.hooks.hook(`build:before`,clearCachedStepTransformTargets),e.hooks.hook(`rollup:before`,(t,n)=>{Array.isArray(n.plugins)&&n.plugins.unshift({name:`eve:workflow-step-module-side-effects`,async resolveId(t,n){let r=resolveNitroImportPath(e.options.rootDir,t,n);return r===null||!(await getStepTransformTargets()).has(normalizeStepTransformComparisonPath(r))?null:{id:r,moduleSideEffects:`no-treeshake`}}})}),clearCachedStepTransformTargets}function addNitroStepTransformPlugin(e,t){let n=null,getStepTransformTargets=async()=>(n===null&&(n=await collectNitroStepTransformTargets(t.stepEntrypointPath,e.options.rootDir)),n),clearCachedStepTransformTargets=()=>{n=null};return e.hooks.hook(`build:before`,clearCachedStepTransformTargets),e.hooks.hook(`rollup:before`,(t,n)=>{Array.isArray(n.plugins)&&n.plugins.unshift({async transform(t,n){let r=await getStepTransformTargets(),i=resolveNitroModuleComparisonPath(e.options.rootDir,n);return r.has(normalizeStepTransformComparisonPath(i))?{code:(await applyWorkflowTransform(createRelativeTransformFilename(e.options.rootDir,i),t,`step`,i,e.options.rootDir)).code,map:null}:null},name:`eve:workflow-step-transform`})}),clearCachedStepTransformTargets}function addDynamicToolTransformPlugin(e){e.hooks.hook(`rollup:before`,(e,t)=>{Array.isArray(t.plugins)&&t.plugins.unshift({async transform(e,t){if(!t.includes(`/tools/`))return null;let n=await transformDynamicToolExecute(t,e);return n===null?null:{code:n.code,map:null}},name:`eve:dynamic-tool-transform`})})}function addInstrumentationModuleSideEffectsPlugin(e,t){let n=normalizePath(t);e.hooks.hook(`rollup:before`,(e,t)=>{Array.isArray(t.plugins)&&t.plugins.unshift({name:`eve:instrumentation-module-side-effects`,resolveId(e){return normalizePath(e)===n?{id:e,moduleSideEffects:`no-treeshake`}:null}})})}function patchWorkflowTransformExcludePath(e,t){let n=normalizePath(t);e.hooks.hook(`rollup:before`,(e,t)=>{if(Array.isArray(t.plugins))for(let e of t.plugins){if(typeof e!=`object`||!e)continue;let t=e;if(t.name!==`workflow:transform`||t[WORKFLOW_TRANSFORM_PATCHED]===!0||typeof t.transform!=`function`)continue;let r=t.transform;t.transform=function(e,t,...i){return isWorkflowBundlePath(t,n)?null:r.call(this,e,t,...i)},t[WORKFLOW_TRANSFORM_PATCHED]=!0}})}function createApplicationNitroBundlerConfiguration(e,t){let n=collectConfiguredSandboxBackendNames(e.compileResult.manifest),r=shouldPruneLocalSandboxBackends({configuredBackendNames:n,preset:t})?createCompiledSandboxBackendPrunePlugin():null,i=[],a=[];for(let[e,t]of Object.entries(OPTIONAL_ENGINE_PACKAGES_BY_BACKEND_NAME))(n.has(e)?i:a).push(t);let o=createExtensionScopePlugin((e.compileResult.manifest.extensionMounts??[]).map(e=>({sourceRoot:e.sourceRoot,packageNamespace:e.packageNamespace}))),s=[r,createOptionalEngineDependencyPlugin(a),o].filter(e=>e!==null);return{nitroRolldownConfig:createNitroBundlerConfig(s),nitroRollupConfig:createNitroBundlerConfig(s),tracedAppDependencies:collectHostedTraceDependencies(e,i)}}function createApplicationNitroPlugins(e){let t=[e.compiledArtifacts.bootstrapPath,e.compiledArtifacts.workflowWorldPluginPath];return manifestEnablesWorkflow(e.compileResult.manifest)&&t.push(resolvePackageSourceFilePath(`src/internal/nitro/host/workflow-sandbox-runtime-plugin.ts`)),e.compiledArtifacts.instrumentationPluginPath!==void 0&&t.push(e.compiledArtifacts.instrumentationPluginPath),t}function configureSharedApplicationNitro(e,t){addNitroRoutingImportSpecifierPlugin(e);let n=resolveWorkflowAliases();for(let[t,r]of Object.entries(n))e.options.alias[t]=r;addWorkflowModuleSideEffectsPlugin(e,t.workflowBuildDir),patchWorkflowTransformExcludePath(e,t.workflowBuildDir),addDynamicToolTransformPlugin(e),t.compiledArtifacts.instrumentationSourcePath!==void 0&&addInstrumentationModuleSideEffectsPlugin(e,t.compiledArtifacts.instrumentationSourcePath)}function configureNitroStepPlugins(e,t){return[addNitroStepModuleSideEffectsPlugin(e,{stepEntrypointPath:t}),addNitroStepTransformPlugin(e,{stepEntrypointPath:t})]}function externalizeDevelopmentWorkflowBundle(e,t){let n=new Set([normalizePath(join(t.workflowBuildDir,`workflows.mjs`))]);e.hooks.hook(`rollup:before`,(e,t)=>{let r=t.external;t.external=(e,...t)=>{if(n.has(normalizePath(e)))return!0;if(typeof r==`function`)return r(e,...t)}})}async function createDevelopmentApplicationNitro(e){let r=e.workspace.nitroBuildDir,i=createApplicationNitroBundlerConfiguration(e,void 0),a=createApplicationNitroPlugins(e);e.compiledArtifacts.instrumentationPluginPath===void 0&&a.unshift(resolvePackageSourceFilePath(`src/internal/nitro/host/local-tracing-runtime-plugin.ts`)),await prepareEveVersionedCacheDirectory(r);let s=await createNitro({_cli:{command:`dev`},buildDir:r,dev:!0,features:{websocket:!0},logLevel:1,output:{dir:e.workspace.nitroOutputDir},plugins:a,publicAssets:[],scanDirs:[resolvePackageSourceDirectoryPath(`src/execution`)],rolldownConfig:i.nitroRolldownConfig,rollupConfig:i.nitroRollupConfig,rootDir:e.appRoot,serverDir:!1,traceDeps:i.tracedAppDependencies,vercel:createEveVercelOptions({agentName:e.compileResult.manifest.config.name,enabled:!1}),watchOptions:createDevelopmentWatchOptions(e.appRoot)},{watch:!0});await writeEveVersionedCacheMetadata(r);let c=join(s.options.buildDir,`workflow`,`steps.mjs`);configureSharedApplicationNitro(s,e);let l=configureNitroStepPlugins(s,c);return s.hooks.hook(`dev:reload`,()=>{for(let e of l)e()}),externalizeDevelopmentWorkflowBundle(s,e),await configureDevelopmentNitroRoutes(s,e),await addNitroStepNoExternals(s,c),s}async function createProductionApplicationNitro(e,r){let i=resolveProductionNitroPreset(),a=createApplicationNitroBundlerConfiguration(e,i),s=createApplicationNitroPlugins(e);s.push(resolvePackageSourceFilePath(`src/internal/nitro/host/sandbox-shutdown-plugin.ts`)),await prepareEveVersionedCacheDirectory(r.buildDir);let c=await createNitro({_cli:{command:`build`},buildDir:r.buildDir,dev:!1,features:{websocket:manifestHasWebSocketChannel(e.compileResult.manifest)},output:{dir:r.outputDir},preset:i,plugins:s,publicAssets:[],scanDirs:[resolvePackageSourceDirectoryPath(`src/execution`)],rolldownConfig:a.nitroRolldownConfig,rollupConfig:a.nitroRollupConfig,rootDir:e.appRoot,serverDir:!1,traceDeps:a.tracedAppDependencies,vercel:createEveVercelOptions({agentName:e.compileResult.manifest.config.name,enabled:i===`vercel`,publicRoutePrefix:r.publicRoutePrefix})});return await writeEveVersionedCacheMetadata(r.buildDir),configureSharedApplicationNitro(c,e),configureNitroStepPlugins(c,join(e.workflowBuildDir,`steps.mjs`)),e.scheduleRegistrations.length>0&&(applyEveCronHandlerRoute(c),registerScheduleTaskHandlers(c,{artifactsConfig:createProductionNitroArtifactsConfig(),dispatchModulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/schedule-task.ts`),registrations:e.scheduleRegistrations})),await configureProductionNitroRoutes(c,e),await addNitroStepNoExternals(c,join(e.workflowBuildDir,`steps.mjs`)),c}export{createDevelopmentApplicationNitro,createProductionApplicationNitro,shouldPruneLocalSandboxBackends};
1
+ import{readFile}from"node:fs/promises";import{resolvePackageRoot,resolvePackageSourceDirectoryPath,resolvePackageSourceFilePath,resolveWorkflowModulePath}from"#internal/application/package.js";import{dirname,isAbsolute,join,relative,resolve}from"node:path";import{fileURLToPath}from"node:url";import{EVE_PACKAGE_NAME}from"#internal/package-name.js";import{createExtensionScopePlugin}from"#internal/bundler/extension-scope-plugin.js";import{createNitro}from"nitro/builder";import{prepareEveVersionedCacheDirectory,writeEveVersionedCacheMetadata}from"#internal/application/cache-metadata.js";import{createProductionNitroArtifactsConfig}from"#internal/nitro/host/artifacts-config.js";import{createEveVercelOptions}from"#internal/nitro/host/vercel-build-output-config.js";import{createCompiledSandboxBackendPrunePlugin}from"#internal/nitro/host/compiled-sandbox-backend-prune-plugin.js";import{configureDevelopmentNitroRoutes,configureProductionNitroRoutes}from"#internal/nitro/host/configure-nitro-routes.js";import{applyEveCronHandlerRoute}from"#internal/nitro/host/cron-handler-route.js";import{createNitroBundlerConfig}from"#internal/nitro/host/nitro-bundler-config.js";import{OPTIONAL_ENGINE_PACKAGES_BY_BACKEND_NAME,createOptionalEngineDependencyPlugin}from"#internal/nitro/host/optional-engine-dependency-plugin.js";import{addNitroRoutingImportSpecifierPlugin}from"#internal/nitro/host/nitro-routing-import-specifier-plugin.js";import{registerScheduleTaskHandlers}from"#internal/nitro/host/schedule-task-routes.js";import{applyWorkflowTransform}from"#internal/workflow-bundle/workflow-builders.js";import{transformDynamicToolExecute}from"#internal/workflow-bundle/dynamic-tool-transform.js";const WORKFLOW_ALIAS_SPECIFIERS=[`workflow`,`workflow/api`,`workflow/errors`,`workflow/internal/builtins`,`workflow/internal/private`,`workflow/runtime`],WORKFLOW_TRANSFORM_PATCHED=Symbol(`eve.workflow-transform-patched`),FRAMEWORK_HOSTED_EXTERNAL_PACKAGES=[`@napi-rs/keyring`],LOCAL_SANDBOX_BACKEND_NAMES=new Set([`docker`,...Object.keys(OPTIONAL_ENGINE_PACKAGES_BY_BACKEND_NAME)]);function resolveWorkflowAliases(){let e={};for(let t of WORKFLOW_ALIAS_SPECIFIERS)e[t]=resolveWorkflowModulePath(t);return e}function resolveProductionNitroPreset(){return process.env.VERCEL?`vercel`:void 0}function manifestEnablesWorkflow(e){return[e,...e.subagents.map(e=>e.agent)].some(e=>e.workflowTool!==void 0)}function manifestHasWebSocketChannel(e){return e.channels.some(e=>e.kind===`channel`&&e.method===`WEBSOCKET`)}function collectHostedTraceDependencies(e,t){let n=[e.compileResult.manifest,...e.compileResult.manifest.subagents.map(e=>e.agent)].flatMap(e=>e.config.build?.externalDependencies??[]);return[...new Set([...FRAMEWORK_HOSTED_EXTERNAL_PACKAGES,...t,...n])].filter(e=>e!==EVE_PACKAGE_NAME)}function collectConfiguredSandboxBackendNames(e){let t=[e,...e.subagents.map(e=>e.agent)];return new Set(t.map(e=>e.sandbox?.backendName).filter(e=>typeof e==`string`))}function shouldPruneLocalSandboxBackends(e){return e.preset===`vercel`&&![...e.configuredBackendNames].some(e=>LOCAL_SANDBOX_BACKEND_NAMES.has(e))}function createDevelopmentWatchOptions(e){return{ignored:[e,join(e,`**`)]}}function normalizePath(e){return e.replaceAll(`\\`,`/`)}function stripPathQueryAndHash(e){let t=e.indexOf(`?`),n=e.indexOf(`#`),r=t===-1?n:n===-1?t:Math.min(t,n);return r===-1?e:e.slice(0,r)}function stripFileSystemPrefix(e){return e.startsWith(`/@fs/`)?e.slice(4):e}function resolveNitroModuleComparisonPath(e,t){return t.startsWith(`file://`)?normalizePath(stripFileSystemPrefix(stripPathQueryAndHash(fileURLToPath(t)))):isAbsolute(t)?normalizePath(stripFileSystemPrefix(stripPathQueryAndHash(t))):normalizePath(stripFileSystemPrefix(stripPathQueryAndHash(resolve(e,t))))}function isWorkflowBundlePath(e,t){let n=normalizePath(e);return n.startsWith(t)||n.includes(`/.eve/workflow-cache/`)}function normalizeStepTransformComparisonPath(e){let t=normalizePath(e);return process.platform===`win32`?t.toLowerCase():t}function parseImportedModuleSpecifiers(e){let t=/^\s*import\s+(?:.+?\s+from\s+)?["']([^"']+)["'];?\s*$/gm,n=[];for(let r of e.matchAll(t)){let e=r[1];e!==void 0&&n.push(e)}return n}function resolveNitroImportPath(e,t,n){return t.startsWith(`workflow`)?resolveWorkflowModulePath(t):t.startsWith(`.`)||t.startsWith(`/`)||t.startsWith(`file://`)?resolveNitroModuleComparisonPath(n===void 0?e:dirname(resolveNitroModuleComparisonPath(e,n)),t):null}async function collectNitroStepTransformTargets(t,n){let r=await readFile(t,`utf8`),i=new Set;for(let e of parseImportedModuleSpecifiers(r)){let r=resolveNitroImportPath(n,e,t);r!==null&&i.add(normalizeStepTransformComparisonPath(r))}return i}async function addNitroStepNoExternals(e,t){if(e.options.noExternals===!0)return;let n;try{n=await collectNitroStepTransformTargets(t,e.options.rootDir)}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return;throw e}let r=Array.isArray(e.options.noExternals)?[...e.options.noExternals]:[];e.options.noExternals=[...new Set([...r,...n])]}function createRelativeTransformFilename(e,t){let n=createPackageRelativeTransformFilename(t);if(n!==void 0)return n;let r=normalizePath(e).replace(/\/$/,``),i=normalizePath(t),a=r.toLowerCase(),o=i.toLowerCase();if(o.startsWith(`${a}/`))return i.slice(r.length+1);if(o===a)return`.`;let s=relative(r,i).replaceAll(`\\`,`/`);if(s.startsWith(`../`)&&(s=s.split(`/`).filter(e=>e!==`..`).join(`/`)),s.includes(`:`)||s.startsWith(`/`)){let e=i.split(`/`).pop();return e===void 0||e.length===0?`unknown.ts`:e}return s}function createPackageRelativeTransformFilename(e){let n=normalizePath(resolvePackageRoot()).replace(/\/$/,``),r=normalizePath(e),i=n.toLowerCase(),a=r.toLowerCase(),o=`${n}/src/`,s=`${i}/src/`,c=`${n}/dist/src/`,l=`${i}/dist/src/`;if(a.startsWith(s))return`src/${r.slice(o.length)}`;if(a.startsWith(l))return`src/${r.slice(c.length)}`}function addWorkflowModuleSideEffectsPlugin(e,t){let n=[t,join(e.options.buildDir,`workflow`)].map(t=>resolveNitroModuleComparisonPath(e.options.rootDir,t));e.hooks.hook(`rollup:before`,(t,r)=>{Array.isArray(r.plugins)&&r.plugins.unshift({name:`eve:workflow-module-side-effects`,resolveId(t,r){let i=resolveNitroImportPath(e.options.rootDir,t,r)??resolveNitroModuleComparisonPath(e.options.rootDir,t);return n.some(e=>isWorkflowBundlePath(i,e))?{id:i,moduleSideEffects:`no-treeshake`}:null}})})}function addNitroStepModuleSideEffectsPlugin(e,t){let n=null,getStepTransformTargets=async()=>(n===null&&(n=await collectNitroStepTransformTargets(t.stepEntrypointPath,e.options.rootDir)),n),clearCachedStepTransformTargets=()=>{n=null};return e.hooks.hook(`build:before`,clearCachedStepTransformTargets),e.hooks.hook(`rollup:before`,(t,n)=>{Array.isArray(n.plugins)&&n.plugins.unshift({name:`eve:workflow-step-module-side-effects`,async resolveId(t,n){let r=resolveNitroImportPath(e.options.rootDir,t,n);return r===null||!(await getStepTransformTargets()).has(normalizeStepTransformComparisonPath(r))?null:{id:r,moduleSideEffects:`no-treeshake`}}})}),clearCachedStepTransformTargets}function addNitroStepTransformPlugin(e,t){let n=null,getStepTransformTargets=async()=>(n===null&&(n=await collectNitroStepTransformTargets(t.stepEntrypointPath,e.options.rootDir)),n),clearCachedStepTransformTargets=()=>{n=null};return e.hooks.hook(`build:before`,clearCachedStepTransformTargets),e.hooks.hook(`rollup:before`,(t,n)=>{Array.isArray(n.plugins)&&n.plugins.unshift({async transform(t,n){let r=await getStepTransformTargets(),i=resolveNitroModuleComparisonPath(e.options.rootDir,n);return r.has(normalizeStepTransformComparisonPath(i))?{code:(await applyWorkflowTransform(createRelativeTransformFilename(e.options.rootDir,i),t,`step`,i,e.options.rootDir)).code,map:null}:null},name:`eve:workflow-step-transform`})}),clearCachedStepTransformTargets}function addDynamicToolTransformPlugin(e){e.hooks.hook(`rollup:before`,(e,t)=>{Array.isArray(t.plugins)&&t.plugins.unshift({async transform(e,t){if(!t.includes(`/tools/`))return null;let n=await transformDynamicToolExecute(t,e);return n===null?null:{code:n.code,map:null}},name:`eve:dynamic-tool-transform`})})}function addInstrumentationModuleSideEffectsPlugin(e,t){let n=normalizePath(t);e.hooks.hook(`rollup:before`,(e,t)=>{Array.isArray(t.plugins)&&t.plugins.unshift({name:`eve:instrumentation-module-side-effects`,resolveId(e){return normalizePath(e)===n?{id:e,moduleSideEffects:`no-treeshake`}:null}})})}function patchWorkflowTransformExcludePath(e,t){let n=normalizePath(t);e.hooks.hook(`rollup:before`,(e,t)=>{if(Array.isArray(t.plugins))for(let e of t.plugins){if(typeof e!=`object`||!e)continue;let t=e;if(t.name!==`workflow:transform`||t[WORKFLOW_TRANSFORM_PATCHED]===!0||typeof t.transform!=`function`)continue;let r=t.transform;t.transform=function(e,t,...i){return isWorkflowBundlePath(t,n)?null:r.call(this,e,t,...i)},t[WORKFLOW_TRANSFORM_PATCHED]=!0}})}function createApplicationNitroBundlerConfiguration(e,t){let n=collectConfiguredSandboxBackendNames(e.compileResult.manifest),r=shouldPruneLocalSandboxBackends({configuredBackendNames:n,preset:t})?createCompiledSandboxBackendPrunePlugin():null,i=[],a=[];for(let[e,t]of Object.entries(OPTIONAL_ENGINE_PACKAGES_BY_BACKEND_NAME))(n.has(e)?i:a).push(t);let o=createExtensionScopePlugin((e.compileResult.manifest.extensionMounts??[]).map(e=>({sourceRoot:e.sourceRoot,packageNamespace:e.packageNamespace}))),s=[r,createOptionalEngineDependencyPlugin(a),o].filter(e=>e!==null);return{nitroRolldownConfig:createNitroBundlerConfig(s),nitroRollupConfig:createNitroBundlerConfig(s),tracedAppDependencies:collectHostedTraceDependencies(e,i)}}function createApplicationNitroPlugins(e){let t=[e.compiledArtifacts.bootstrapPath,e.compiledArtifacts.workflowWorldPluginPath];return manifestEnablesWorkflow(e.compileResult.manifest)&&t.push(resolvePackageSourceFilePath(`src/internal/nitro/host/workflow-sandbox-runtime-plugin.ts`)),e.compiledArtifacts.instrumentationPluginPath!==void 0&&t.push(e.compiledArtifacts.instrumentationPluginPath),t}function configureSharedApplicationNitro(e,t){addNitroRoutingImportSpecifierPlugin(e);let n=resolveWorkflowAliases();for(let[t,r]of Object.entries(n))e.options.alias[t]=r;addWorkflowModuleSideEffectsPlugin(e,t.workflowBuildDir),patchWorkflowTransformExcludePath(e,t.workflowBuildDir),addDynamicToolTransformPlugin(e),t.compiledArtifacts.instrumentationSourcePath!==void 0&&addInstrumentationModuleSideEffectsPlugin(e,t.compiledArtifacts.instrumentationSourcePath)}function configureNitroStepPlugins(e,t){return[addNitroStepModuleSideEffectsPlugin(e,{stepEntrypointPath:t}),addNitroStepTransformPlugin(e,{stepEntrypointPath:t})]}function externalizeDevelopmentWorkflowBundle(e,t){let n=new Set([normalizePath(join(t.workflowBuildDir,`workflows.mjs`))]);e.hooks.hook(`rollup:before`,(e,t)=>{let r=t.external;t.external=(e,...t)=>{if(n.has(normalizePath(e)))return!0;if(typeof r==`function`)return r(e,...t)}})}async function createDevelopmentApplicationNitro(e){let t=e.workspace.nitroBuildDir,i=createApplicationNitroBundlerConfiguration(e,void 0),a=createApplicationNitroPlugins(e);e.compiledArtifacts.instrumentationPluginPath===void 0&&a.unshift(resolvePackageSourceFilePath(`src/internal/nitro/host/local-tracing-runtime-plugin.ts`)),await prepareEveVersionedCacheDirectory(t);let o=await createNitro({_cli:{command:`dev`},buildDir:t,dev:!0,features:{websocket:!0},logLevel:1,output:{dir:e.workspace.nitroOutputDir},plugins:a,publicAssets:[],scanDirs:[resolvePackageSourceDirectoryPath(`src/execution`)],rolldownConfig:i.nitroRolldownConfig,rollupConfig:i.nitroRollupConfig,rootDir:e.appRoot,serverDir:!1,traceDeps:i.tracedAppDependencies,vercel:createEveVercelOptions({agentName:e.compileResult.manifest.config.name,enabled:!1}),watchOptions:createDevelopmentWatchOptions(e.appRoot)},{watch:!0});await writeEveVersionedCacheMetadata(t);let c=join(o.options.buildDir,`workflow`,`steps.mjs`);configureSharedApplicationNitro(o,e);let l=configureNitroStepPlugins(o,c);return o.hooks.hook(`dev:reload`,()=>{for(let e of l)e()}),externalizeDevelopmentWorkflowBundle(o,e),await configureDevelopmentNitroRoutes(o,e),await addNitroStepNoExternals(o,c),o}async function createProductionApplicationNitro(e,t){let i=resolveProductionNitroPreset(),a=createApplicationNitroBundlerConfiguration(e,i),o=createApplicationNitroPlugins(e);o.push(resolvePackageSourceFilePath(`src/internal/nitro/host/sandbox-shutdown-plugin.ts`)),await prepareEveVersionedCacheDirectory(t.buildDir);let c=await createNitro({_cli:{command:`build`},buildDir:t.buildDir,dev:!1,features:{websocket:manifestHasWebSocketChannel(e.compileResult.manifest)},output:{dir:t.outputDir},preset:i,plugins:o,publicAssets:[],scanDirs:[resolvePackageSourceDirectoryPath(`src/execution`)],rolldownConfig:a.nitroRolldownConfig,rollupConfig:a.nitroRollupConfig,rootDir:e.appRoot,serverDir:!1,traceDeps:a.tracedAppDependencies,vercel:createEveVercelOptions({agentName:e.compileResult.manifest.config.name,enabled:i===`vercel`,publicRoutePrefix:t.publicRoutePrefix})});return await writeEveVersionedCacheMetadata(t.buildDir),configureSharedApplicationNitro(c,e),configureNitroStepPlugins(c,join(e.workflowBuildDir,`steps.mjs`)),e.scheduleRegistrations.length>0&&(applyEveCronHandlerRoute(c),registerScheduleTaskHandlers(c,{artifactsConfig:createProductionNitroArtifactsConfig(),dispatchModulePath:resolvePackageSourceFilePath(`src/internal/nitro/routes/schedule-task.ts`),registrations:e.scheduleRegistrations})),await configureProductionNitroRoutes(c,e),await addNitroStepNoExternals(c,join(e.workflowBuildDir,`steps.mjs`)),c}export{createDevelopmentApplicationNitro,createProductionApplicationNitro,shouldPruneLocalSandboxBackends};
@@ -1 +1 @@
1
- import{EVE_ROUTE_PREFIX}from"#protocol/routes.js";import{randomBytes}from"node:crypto";function createEveCronHandlerRoute(){return`${EVE_ROUTE_PREFIX}/cron/${randomBytes(32).toString(`base64url`)}`}function applyEveCronHandlerRoute(e){e.options.vercel!==void 0&&(e.options.vercel.cronHandlerRoute=createEveCronHandlerRoute())}export{applyEveCronHandlerRoute,createEveCronHandlerRoute};
1
+ import{randomBytes}from"node:crypto";import{EVE_ROUTE_PREFIX}from"#protocol/routes.js";function createEveCronHandlerRoute(){return`${EVE_ROUTE_PREFIX}/cron/${randomBytes(32).toString(`base64url`)}`}function applyEveCronHandlerRoute(e){e.options.vercel!==void 0&&(e.options.vercel.cronHandlerRoute=createEveCronHandlerRoute())}export{applyEveCronHandlerRoute,createEveCronHandlerRoute};
@@ -1 +1 @@
1
- import{relative,resolve}from"node:path";import{stageDevelopmentEnvironmentFiles}from"#cli/dev/environment.js";import{startDevelopmentSandboxPrewarmInBackground}from"#execution/sandbox/development-prewarm.js";import{usesParentDevelopmentWorkflowWorld}from"#internal/workflow/development-world-protocol.js";import{createDevelopmentApplicationNitro}from"#internal/nitro/host/create-application-nitro.js";import{prepareDevelopmentApplicationHost}from"#internal/nitro/host/prepare-application-host.js";import{createDevelopmentNitroArtifactsConfig}from"#internal/nitro/host/artifacts-config.js";import{buildDevelopmentHostCandidate}from"#internal/nitro/host/dev-host-candidate.js";import{computeDevelopmentHostFingerprint}from"#internal/nitro/host/dev-host-fingerprint.js";import{removeDevelopmentHostWorkspace}from"#internal/nitro/host/dev-host-workspace.js";import"#internal/nitro/host/drained-nitro-dev-server.js";import{activateDevelopmentGeneration,discardDevelopmentGeneration}from"#internal/nitro/development-generation.js";import{resolveNitroCompiledArtifactsSource}from"#internal/nitro/routes/runtime-artifacts.js";var PostCommitDevelopmentRebuildError=class extends Error{constructor(e){super(`The development worker was replaced but its generation failed to activate. The server keeps serving the previous generation; the next rebuild retries activation.`,{cause:e}),this.name=`PostCommitDevelopmentRebuildError`}},DevelopmentWorkflowWorldChangeRequiresRestartError=class extends Error{constructor(){super(`Changing experimental.workflow.world between the parent-owned local World and a custom World requires restarting eve dev.`),this.name=`DevelopmentWorkflowWorldChangeRequiresRestartError`}};async function createDevelopmentAuthoredRebuildCoordinator(e){return new TransactionalDevelopmentAuthoredRebuildCoordinator({currentHostFingerprint:await computeDevelopmentHostFingerprint(e.initialHost),currentRuntimeFingerprint:e.initialHost.generation.fingerprint,devServer:e.devServer,initialHost:e.initialHost})}var TransactionalDevelopmentAuthoredRebuildCoordinator=class{#e;#t;#n;#r;#i;constructor(e){this.#e=e.initialHost,this.#t=e.currentHostFingerprint,this.#n=e.currentRuntimeFingerprint,this.#r=e.devServer,this.#i=usesParentDevelopmentWorkflowWorld(e.initialHost.compileResult.manifest.config.experimental?.workflow?.world)}async rebuild(e){let t=this.#e,r=stageDevelopmentEnvironmentFiles(t.appRoot),a;try{if(a=await prepareDevelopmentApplicationHost(t.appRoot,{changedPaths:e.changedPaths,previousExtensions:t.workspaceExtensions}),usesParentDevelopmentWorkflowWorld(a.compileResult.manifest.config.experimental?.workflow?.world)!==this.#i)throw new DevelopmentWorkflowWorldChangeRequiresRestartError;let n=await computeDevelopmentHostFingerprint(a),o=a.generation.fingerprint,s=n!==this.#t,c=o!==this.#n;if(!s&&!c){let e={...t,workspaceExtensions:a.workspaceExtensions};return await discardPreparedHost(a),a=void 0,this.#o(e,this.#t,this.#n),r.commit(),{host:e,kind:`unchanged`}}if(!s){await removeDevelopmentHostWorkspace(a.workspace);let i=retainActiveHostWorkspace(t,a);return await activateDevelopmentGeneration({appRoot:i.appRoot,generation:i.generation}),this.#o(i,n,o),a=void 0,r.commit(),startSandboxPrewarmAfterCommit(i,e.changedPaths),{host:i,kind:`runtime`}}let l=await this.#a({hasRuntimeChange:c,nextHost:a,nextHostFingerprint:n,nextRuntimeFingerprint:o});return a=void 0,r.commit(),startSandboxPrewarmAfterCommit(l.host,e.changedPaths),l}catch(e){throw e instanceof PostCommitDevelopmentRebuildError?(r.commit(),e):(r.rollback(),a===void 0?e:await discardFailedHost(e,a))}}async#a(e){let t=e.nextHost;e.hasRuntimeChange||(await discardDevelopmentGeneration(e.nextHost.generation),t={...e.nextHost,generation:this.#e.generation});let n=await createDevelopmentApplicationNitro(t),r=await buildDevelopmentHostCandidate({host:t,nitro:n}),i=t.workspace;if(await this.#r.replaceWorker({dispose:async()=>await removeDevelopmentHostWorkspace(i),entry:r.entry,workerData:r.workerData}),e.hasRuntimeChange)try{await activateDevelopmentGeneration({appRoot:t.appRoot,generation:t.generation})}catch(n){throw await discardDevelopmentGeneration(t.generation).catch(()=>void 0),this.#o({...t,generation:this.#e.generation},e.nextHostFingerprint,this.#n),new PostCommitDevelopmentRebuildError(n)}return this.#o(t,e.nextHostFingerprint,e.hasRuntimeChange?e.nextRuntimeFingerprint:this.#n),{host:t,kind:`structural`}}#o(e,t,n){this.#e=e,this.#t=t,this.#n=n}};function retainActiveHostWorkspace(e,t){return{...t,compiledArtifacts:e.compiledArtifacts,workflowBuildDir:e.workflowBuildDir,workspace:e.workspace}}function startSandboxPrewarmAfterCommit(e,t){if(!hasSandboxRelatedChange(e.compileResult.project.agentRoot,t))return;let n=createDevelopmentNitroArtifactsConfig({appRoot:e.appRoot,configuredWorld:e.compileResult.manifest.config.experimental?.workflow?.world});startDevelopmentSandboxPrewarmInBackground({appRoot:e.appRoot,compiledArtifactsSource:resolveNitroCompiledArtifactsSource(n),log:e=>console.log(e)})}function hasSandboxRelatedChange(n,r){return r.some(r=>{let i=relative(resolve(n),resolve(r)),a=i.split(/[\\/]/u);return a[0]===`..`||i===``?!1:a[0]===`sandbox.ts`||a[0]===`sandbox`||a[0]===`workspace`||a[0]===`skills`})}async function discardPreparedHost(e){let t=(await Promise.allSettled([discardDevelopmentGeneration(e.generation),removeDevelopmentHostWorkspace(e.workspace)])).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(t.length>0)throw AggregateError(t,`Failed to discard development host "${e.workspace.rootDir}".`)}async function discardFailedHost(e,t){try{return await discardPreparedHost(t),e}catch(t){return AggregateError([e,t],`Development rebuild rollback failed.`,{cause:e})}}export{DevelopmentWorkflowWorldChangeRequiresRestartError,PostCommitDevelopmentRebuildError,createDevelopmentAuthoredRebuildCoordinator};
1
+ import{stageDevelopmentEnvironmentFiles}from"#cli/dev/environment.js";import{relative,resolve}from"node:path";import{startDevelopmentSandboxPrewarmInBackground}from"#execution/sandbox/development-prewarm.js";import{usesParentDevelopmentWorkflowWorld}from"#internal/workflow/development-world-protocol.js";import{createDevelopmentApplicationNitro}from"#internal/nitro/host/create-application-nitro.js";import{prepareDevelopmentApplicationHost}from"#internal/nitro/host/prepare-application-host.js";import{createDevelopmentNitroArtifactsConfig}from"#internal/nitro/host/artifacts-config.js";import{buildDevelopmentHostCandidate}from"#internal/nitro/host/dev-host-candidate.js";import{computeDevelopmentHostFingerprint}from"#internal/nitro/host/dev-host-fingerprint.js";import{removeDevelopmentHostWorkspace}from"#internal/nitro/host/dev-host-workspace.js";import"#internal/nitro/host/drained-nitro-dev-server.js";import{activateDevelopmentGeneration,discardDevelopmentGeneration}from"#internal/nitro/development-generation.js";import{resolveNitroCompiledArtifactsSource}from"#internal/nitro/routes/runtime-artifacts.js";var PostCommitDevelopmentRebuildError=class extends Error{constructor(e){super(`The development worker was replaced but its generation failed to activate. The server keeps serving the previous generation; the next rebuild retries activation.`,{cause:e}),this.name=`PostCommitDevelopmentRebuildError`}},DevelopmentWorkflowWorldChangeRequiresRestartError=class extends Error{constructor(){super(`Changing experimental.workflow.world between the parent-owned local World and a custom World requires restarting eve dev.`),this.name=`DevelopmentWorkflowWorldChangeRequiresRestartError`}};async function createDevelopmentAuthoredRebuildCoordinator(e){return new TransactionalDevelopmentAuthoredRebuildCoordinator({currentHostFingerprint:await computeDevelopmentHostFingerprint(e.initialHost),currentRuntimeFingerprint:e.initialHost.generation.fingerprint,devServer:e.devServer,initialHost:e.initialHost})}var TransactionalDevelopmentAuthoredRebuildCoordinator=class{#e;#t;#n;#r;#i;constructor(e){this.#e=e.initialHost,this.#t=e.currentHostFingerprint,this.#n=e.currentRuntimeFingerprint,this.#r=e.devServer,this.#i=usesParentDevelopmentWorkflowWorld(e.initialHost.compileResult.manifest.config.experimental?.workflow?.world)}async rebuild(t){let n=this.#e,r=stageDevelopmentEnvironmentFiles(n.appRoot),a;try{if(a=await prepareDevelopmentApplicationHost(n.appRoot,{changedPaths:t.changedPaths,previousExtensions:n.workspaceExtensions}),usesParentDevelopmentWorkflowWorld(a.compileResult.manifest.config.experimental?.workflow?.world)!==this.#i)throw new DevelopmentWorkflowWorldChangeRequiresRestartError;let e=await computeDevelopmentHostFingerprint(a),o=a.generation.fingerprint,s=e!==this.#t,c=o!==this.#n;if(!s&&!c){let e={...n,workspaceExtensions:a.workspaceExtensions};return await discardPreparedHost(a),a=void 0,this.#o(e,this.#t,this.#n),r.commit(),{host:e,kind:`unchanged`}}if(!s){await removeDevelopmentHostWorkspace(a.workspace);let i=retainActiveHostWorkspace(n,a);return await activateDevelopmentGeneration({appRoot:i.appRoot,generation:i.generation}),this.#o(i,e,o),a=void 0,r.commit(),startSandboxPrewarmAfterCommit(i,t.changedPaths),{host:i,kind:`runtime`}}let l=await this.#a({hasRuntimeChange:c,nextHost:a,nextHostFingerprint:e,nextRuntimeFingerprint:o});return a=void 0,r.commit(),startSandboxPrewarmAfterCommit(l.host,t.changedPaths),l}catch(e){throw e instanceof PostCommitDevelopmentRebuildError?(r.commit(),e):(r.rollback(),a===void 0?e:await discardFailedHost(e,a))}}async#a(e){let t=e.nextHost;e.hasRuntimeChange||(await discardDevelopmentGeneration(e.nextHost.generation),t={...e.nextHost,generation:this.#e.generation});let n=await createDevelopmentApplicationNitro(t),r=await buildDevelopmentHostCandidate({host:t,nitro:n}),i=t.workspace;if(await this.#r.replaceWorker({dispose:async()=>await removeDevelopmentHostWorkspace(i),entry:r.entry,workerData:r.workerData}),e.hasRuntimeChange)try{await activateDevelopmentGeneration({appRoot:t.appRoot,generation:t.generation})}catch(n){throw await discardDevelopmentGeneration(t.generation).catch(()=>void 0),this.#o({...t,generation:this.#e.generation},e.nextHostFingerprint,this.#n),new PostCommitDevelopmentRebuildError(n)}return this.#o(t,e.nextHostFingerprint,e.hasRuntimeChange?e.nextRuntimeFingerprint:this.#n),{host:t,kind:`structural`}}#o(e,t,n){this.#e=e,this.#t=t,this.#n=n}};function retainActiveHostWorkspace(e,t){return{...t,compiledArtifacts:e.compiledArtifacts,workflowBuildDir:e.workflowBuildDir,workspace:e.workspace}}function startSandboxPrewarmAfterCommit(e,t){if(!hasSandboxRelatedChange(e.compileResult.project.agentRoot,t))return;let n=createDevelopmentNitroArtifactsConfig({appRoot:e.appRoot,configuredWorld:e.compileResult.manifest.config.experimental?.workflow?.world});startDevelopmentSandboxPrewarmInBackground({appRoot:e.appRoot,compiledArtifactsSource:resolveNitroCompiledArtifactsSource(n),log:e=>console.log(e)})}function hasSandboxRelatedChange(e,r){return r.some(r=>{let i=relative(resolve(e),resolve(r)),a=i.split(/[\\/]/u);return a[0]===`..`||i===``?!1:a[0]===`sandbox.ts`||a[0]===`sandbox`||a[0]===`workspace`||a[0]===`skills`})}async function discardPreparedHost(e){let t=(await Promise.allSettled([discardDevelopmentGeneration(e.generation),removeDevelopmentHostWorkspace(e.workspace)])).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(t.length>0)throw AggregateError(t,`Failed to discard development host "${e.workspace.rootDir}".`)}async function discardFailedHost(e,t){try{return await discardPreparedHost(t),e}catch(t){return AggregateError([e,t],`Development rebuild rollback failed.`,{cause:e})}}export{DevelopmentWorkflowWorldChangeRequiresRestartError,PostCommitDevelopmentRebuildError,createDevelopmentAuthoredRebuildCoordinator};
@@ -1 +1 @@
1
- import{existsSync}from"node:fs";import{dirname,join,normalize,resolve,sep}from"node:path";import{getDevelopmentEnvironmentFilePaths}from"#cli/dev/environment.js";import{toErrorMessage}from"#shared/errors.js";import{AUTHORED_ARTIFACTS_UPDATED_LOG_LINE,STRUCTURAL_RELOAD_LOG_LINE,formatChangeDetectedLogLine}from"#internal/nitro/host/dev-watcher-log.js";import{resolveDevelopmentSourceSnapshotWatchPaths}from"#internal/nitro/dev-runtime-source-snapshot.js";import{resolveTsConfigDependencyPaths}from"#internal/application/tsconfig-dependencies.js";import{watch as watch$1}from"#compiled/chokidar/index.js";const WATCHED_LOCKFILE_NAMES=[`pnpm-lock.yaml`,`package-lock.json`,`yarn.lock`,`bun.lock`,`bun.lockb`],WATCH_ROOT_MARKER_NAMES=[`.git`,`pnpm-workspace.yaml`],WATCHER_IGNORED_DIRECTORY_NAMES=new Set([`.generated`,`.eve`,`.git`,`.next`,`.output`,`.turbo`,`.vercel`,`build`,`dist`,`node_modules`]);async function startAuthoredSourceWatcher(e){let t=e.preparedHost,n=!1,r=Promise.resolve(),i,a=!1,o=0,s=new Map,c=new Set,u=await resolveAuthoredWatchPaths(t),d=createWatchPathMap(u),f=watch$1(u,{awaitWriteFinish:{pollInterval:50,stabilityThreshold:160},followSymlinks:!1,ignoreInitial:!0,ignored:e=>shouldIgnoreWatcherPath(e,t.workspaceExtensions)}),p=waitForWatcherReady(f),rebuild=async(i,a=!1)=>{n||o>0||(r=r.then(async()=>{if(n)return;let r=[...s.values()];if(!i&&r.length===0)return;let o=[...c];s.clear(),c.clear();let l=t;!a&&r.length>0&&console.log(formatChangeDetectedLogLine(l.appRoot,r));try{let n=await e.coordinator.rebuild({changedPaths:o});t=n.host,a||(n.kind===`structural`?console.log(STRUCTURAL_RELOAD_LOG_LINE):console.log(AUTHORED_ARTIFACTS_UPDATED_LOG_LINE)),d=syncWatcherPaths({nextWatchPaths:await resolveAuthoredWatchPaths(t),previousWatchPathsByKey:d,watcher:f})}catch(e){console.error(`[eve:dev] rebuild failed: ${toErrorMessage(e)}`)}}).catch(e=>{console.error(`[eve:dev] rebuild queue error: ${toErrorMessage(e)}`)}),await r)},flush=async()=>{i!==void 0&&(clearTimeout(i),i=void 0),await rebuild(!1)},forceRebuild=async(e=!1)=>{i!==void 0&&(clearTimeout(i),i=void 0),await rebuild(!0,e)};return f.on(`all`,(e,t)=>{n||!a||e===`addDir`||e===`unlinkDir`||(s.set(`${e}:${t}`,{event:e,path:t}),c.add(t),i!==void 0&&clearTimeout(i),i=setTimeout(()=>{i=void 0,flush()},120))}),await p,a=!0,{async close(){n=!0,i!==void 0&&(clearTimeout(i),i=void 0),await f.close(),await r},flush,rebuild:forceRebuild,async suspend(){o+=1,i!==void 0&&(clearTimeout(i),i=void 0),await r},async resume(e){o!==0&&(--o,o===0&&await forceRebuild(e?.silent))}}}async function waitForWatcherReady(e){await new Promise((t,n)=>{e.on(`ready`,()=>{t()}),e.on(`error`,e=>{n(e)})})}async function resolveAuthoredWatchPaths(e){let t=new Set([e.compileResult.project.agentRoot,join(e.appRoot,`package.json`),join(e.appRoot,`jsconfig.json`),join(e.appRoot,`tsconfig.json`),join(e.appRoot,`tsconfig.*.json`)]),r=await resolveTsConfigWatchPaths(e.appRoot),i=await resolveDevelopmentSourceSnapshotWatchPaths(e.appRoot);for(let n of e.workspaceExtensions){t.add(n.config.sourceRoot);for(let e of n.buildConfigPaths)t.add(e)}for(let n of getDevelopmentEnvironmentFilePaths(e.appRoot))t.add(n);for(let e of i)t.add(e);for(let e of r)t.add(e);for(let r of resolveLockfileSearchDirectories(e.appRoot))for(let e of WATCHED_LOCKFILE_NAMES)t.add(join(r,e));return[...t].sort((e,t)=>e.localeCompare(t))}function createWatchPathMap(e){let t=new Map;for(let n of e)t.set(toWatchPathKey(n),n);return t}function syncWatcherPaths(e){let t=createWatchPathMap(e.nextWatchPaths),n=[],r=[];for(let[r,i]of t)e.previousWatchPathsByKey.has(r)||n.push(i);for(let[n,i]of e.previousWatchPathsByKey)t.has(n)||r.push(i);return n.length>0&&e.watcher.add(n),r.length>0&&e.watcher.unwatch(r),t}function toWatchPathKey(e){return normalize(resolve(e))}function resolveLockfileSearchDirectories(e){let n=resolve(e),r=[n],a=n;for(;;){if(hasWatchRootMarker(a))return r;let e=dirname(a);if(e===a)return[n];a=e,r.push(a)}}function hasWatchRootMarker(t){return WATCH_ROOT_MARKER_NAMES.some(r=>existsSync(join(t,r)))}async function resolveTsConfigWatchPaths(e){return await resolveTsConfigDependencyPaths(e)}function shouldIgnoreWatcherPath(e,t){return normalize(e).split(sep).filter(Boolean).some(e=>WATCHER_IGNORED_DIRECTORY_NAMES.has(e))||t.some(t=>isPathInsideOrEqual(e,t.config.outDir))}function isPathInsideOrEqual(e,t){let n=resolve(e),r=resolve(t);return n===r||n.startsWith(`${r}${sep}`)}export{startAuthoredSourceWatcher};
1
+ import{getDevelopmentEnvironmentFilePaths}from"#cli/dev/environment.js";import{existsSync}from"node:fs";import{dirname,join,normalize,resolve,sep}from"node:path";import{toErrorMessage}from"#shared/errors.js";import{AUTHORED_ARTIFACTS_UPDATED_LOG_LINE,STRUCTURAL_RELOAD_LOG_LINE,formatChangeDetectedLogLine}from"#internal/nitro/host/dev-watcher-log.js";import{resolveDevelopmentSourceSnapshotWatchPaths}from"#internal/nitro/dev-runtime-source-snapshot.js";import{resolveTsConfigDependencyPaths}from"#internal/application/tsconfig-dependencies.js";import{watch as watch$1}from"#compiled/chokidar/index.js";const WATCHED_LOCKFILE_NAMES=[`pnpm-lock.yaml`,`package-lock.json`,`yarn.lock`,`bun.lock`,`bun.lockb`],WATCH_ROOT_MARKER_NAMES=[`.git`,`pnpm-workspace.yaml`],WATCHER_IGNORED_DIRECTORY_NAMES=new Set([`.generated`,`.eve`,`.git`,`.next`,`.output`,`.turbo`,`.vercel`,`build`,`dist`,`node_modules`]);async function startAuthoredSourceWatcher(e){let t=e.preparedHost,n=!1,r=Promise.resolve(),i,a=!1,o=0,s=new Map,c=new Set,u=await resolveAuthoredWatchPaths(t),d=createWatchPathMap(u),f=watch$1(u,{awaitWriteFinish:{pollInterval:50,stabilityThreshold:160},followSymlinks:!1,ignoreInitial:!0,ignored:e=>shouldIgnoreWatcherPath(e,t.workspaceExtensions)}),p=waitForWatcherReady(f),rebuild=async(i,a=!1)=>{n||o>0||(r=r.then(async()=>{if(n)return;let r=[...s.values()];if(!i&&r.length===0)return;let o=[...c];s.clear(),c.clear();let l=t;!a&&r.length>0&&console.log(formatChangeDetectedLogLine(l.appRoot,r));try{let n=await e.coordinator.rebuild({changedPaths:o});t=n.host,a||(n.kind===`structural`?console.log(STRUCTURAL_RELOAD_LOG_LINE):console.log(AUTHORED_ARTIFACTS_UPDATED_LOG_LINE)),d=syncWatcherPaths({nextWatchPaths:await resolveAuthoredWatchPaths(t),previousWatchPathsByKey:d,watcher:f})}catch(e){console.error(`[eve:dev] rebuild failed: ${toErrorMessage(e)}`)}}).catch(e=>{console.error(`[eve:dev] rebuild queue error: ${toErrorMessage(e)}`)}),await r)},flush=async()=>{i!==void 0&&(clearTimeout(i),i=void 0),await rebuild(!1)},forceRebuild=async(e=!1)=>{i!==void 0&&(clearTimeout(i),i=void 0),await rebuild(!0,e)};return f.on(`all`,(e,t)=>{n||!a||e===`addDir`||e===`unlinkDir`||(s.set(`${e}:${t}`,{event:e,path:t}),c.add(t),i!==void 0&&clearTimeout(i),i=setTimeout(()=>{i=void 0,flush()},120))}),await p,a=!0,{async close(){n=!0,i!==void 0&&(clearTimeout(i),i=void 0),await f.close(),await r},flush,rebuild:forceRebuild,async suspend(){o+=1,i!==void 0&&(clearTimeout(i),i=void 0),await r},async resume(e){o!==0&&(--o,o===0&&await forceRebuild(e?.silent))}}}async function waitForWatcherReady(e){await new Promise((t,n)=>{e.on(`ready`,()=>{t()}),e.on(`error`,e=>{n(e)})})}async function resolveAuthoredWatchPaths(t){let n=new Set([t.compileResult.project.agentRoot,join(t.appRoot,`package.json`),join(t.appRoot,`jsconfig.json`),join(t.appRoot,`tsconfig.json`),join(t.appRoot,`tsconfig.*.json`)]),i=await resolveTsConfigWatchPaths(t.appRoot),a=await resolveDevelopmentSourceSnapshotWatchPaths(t.appRoot);for(let e of t.workspaceExtensions){n.add(e.config.sourceRoot);for(let t of e.buildConfigPaths)n.add(t)}for(let r of getDevelopmentEnvironmentFilePaths(t.appRoot))n.add(r);for(let e of a)n.add(e);for(let e of i)n.add(e);for(let e of resolveLockfileSearchDirectories(t.appRoot))for(let t of WATCHED_LOCKFILE_NAMES)n.add(join(e,t));return[...n].sort((e,t)=>e.localeCompare(t))}function createWatchPathMap(e){let t=new Map;for(let n of e)t.set(toWatchPathKey(n),n);return t}function syncWatcherPaths(e){let t=createWatchPathMap(e.nextWatchPaths),n=[],r=[];for(let[r,i]of t)e.previousWatchPathsByKey.has(r)||n.push(i);for(let[n,i]of e.previousWatchPathsByKey)t.has(n)||r.push(i);return n.length>0&&e.watcher.add(n),r.length>0&&e.watcher.unwatch(r),t}function toWatchPathKey(e){return normalize(resolve(e))}function resolveLockfileSearchDirectories(e){let t=resolve(e),r=[t],i=t;for(;;){if(hasWatchRootMarker(i))return r;let e=dirname(i);if(e===i)return[t];i=e,r.push(i)}}function hasWatchRootMarker(e){return WATCH_ROOT_MARKER_NAMES.some(n=>existsSync(join(e,n)))}async function resolveTsConfigWatchPaths(e){return await resolveTsConfigDependencyPaths(e)}function shouldIgnoreWatcherPath(e,t){return normalize(e).split(sep).filter(Boolean).some(e=>WATCHER_IGNORED_DIRECTORY_NAMES.has(e))||t.some(t=>isPathInsideOrEqual(e,t.config.outDir))}function isPathInsideOrEqual(e,t){let n=resolve(e),r=resolve(t);return n===r||n.startsWith(`${r}${sep}`)}export{startAuthoredSourceWatcher};
@@ -1 +1 @@
1
- import{readFile}from"node:fs/promises";import{readDevelopmentEnvironmentHostValues}from"#cli/dev/environment.js";import{createHash}from"node:crypto";import{computeChannelRouteRegistrations}from"#internal/nitro/host/channel-routes.js";async function computeDevelopmentHostFingerprint(e){let r=e.compileResult.manifest,i=[r,...r.subagents.map(e=>e.agent)],a={agentName:r.config.name,bundler:{externalDependencies:[...new Set(i.flatMap(e=>e.config.build?.externalDependencies??[]))].sort((e,t)=>e.localeCompare(t)),extensionScopes:(r.extensionMounts??[]).map(e=>({packageNamespace:e.packageNamespace,sourceRoot:e.sourceRoot})).sort((e,t)=>e.sourceRoot.localeCompare(t.sourceRoot)),sandboxBackends:[...new Set(i.map(e=>e.sandbox?.backendName).filter(e=>e!==void 0))].sort((e,t)=>e.localeCompare(t))},channels:computeChannelRouteRegistrations(e),environment:readDevelopmentEnvironmentHostValues(e.appRoot),instrumentation:await readInstrumentationSource(e),workflow:{enabled:i.some(e=>e.workflowTool!==void 0),world:r.config.experimental?.workflow?.world??`local`}};return createHash(`sha256`).update(JSON.stringify(a)).digest(`hex`)}async function readInstrumentationSource(t){let n=t.compiledArtifacts.instrumentationSourcePath;return n===void 0?null:await readFile(n,`utf8`)}export{computeDevelopmentHostFingerprint};
1
+ import{createHash}from"node:crypto";import{readFile}from"node:fs/promises";import{readDevelopmentEnvironmentHostValues}from"#cli/dev/environment.js";import{computeChannelRouteRegistrations}from"#internal/nitro/host/channel-routes.js";async function computeDevelopmentHostFingerprint(t){let r=t.compileResult.manifest,i=[r,...r.subagents.map(e=>e.agent)],a={agentName:r.config.name,bundler:{externalDependencies:[...new Set(i.flatMap(e=>e.config.build?.externalDependencies??[]))].sort((e,t)=>e.localeCompare(t)),extensionScopes:(r.extensionMounts??[]).map(e=>({packageNamespace:e.packageNamespace,sourceRoot:e.sourceRoot})).sort((e,t)=>e.sourceRoot.localeCompare(t.sourceRoot)),sandboxBackends:[...new Set(i.map(e=>e.sandbox?.backendName).filter(e=>e!==void 0))].sort((e,t)=>e.localeCompare(t))},channels:computeChannelRouteRegistrations(t),environment:readDevelopmentEnvironmentHostValues(t.appRoot),instrumentation:await readInstrumentationSource(t),workflow:{enabled:i.some(e=>e.workflowTool!==void 0),world:r.config.experimental?.workflow?.world??`local`}};return createHash(`sha256`).update(JSON.stringify(a)).digest(`hex`)}async function readInstrumentationSource(e){let n=e.compiledArtifacts.instrumentationSourcePath;return n===void 0?null:await readFile(n,`utf8`)}export{computeDevelopmentHostFingerprint};
@@ -1 +1 @@
1
- import{join}from"node:path";import{mkdir,rm}from"node:fs/promises";import{randomUUID}from"node:crypto";async function createDevelopmentHostWorkspace(t){let n=join(t,`.eve`,`dev-hosts`,randomUUID()),r={artifactsDir:join(n,`artifacts`),compilerArtifactsDir:join(n,`compiler`),nitroBuildDir:join(n,`nitro`),nitroOutputDir:join(n,`output`),rootDir:n,workflowBuildDir:join(n,`workflow`)};return await mkdir(n,{recursive:!0}),r}async function removeDevelopmentHostWorkspace(e){await rm(e.rootDir,{force:!0,recursive:!0})}export{createDevelopmentHostWorkspace,removeDevelopmentHostWorkspace};
1
+ import{randomUUID}from"node:crypto";import{mkdir,rm}from"node:fs/promises";import{join}from"node:path";async function createDevelopmentHostWorkspace(t){let n=join(t,`.eve`,`dev-hosts`,randomUUID()),r={artifactsDir:join(n,`artifacts`),compilerArtifactsDir:join(n,`compiler`),nitroBuildDir:join(n,`nitro`),nitroOutputDir:join(n,`output`),rootDir:n,workflowBuildDir:join(n,`workflow`)};return await mkdir(n,{recursive:!0}),r}async function removeDevelopmentHostWorkspace(e){await rm(e.rootDir,{force:!0,recursive:!0})}export{createDevelopmentHostWorkspace,removeDevelopmentHostWorkspace};
@@ -1 +1 @@
1
- import{toErrorMessage}from"#shared/errors.js";import{Readable}from"node:stream";function createPublicRequest(e,n){let r=e.headers.host??`localhost`,i=new URL(e.url??`/`,`http://${r}`),a=new Headers;for(let[t,n]of Object.entries(e.headers))if(Array.isArray(n))for(let e of n)a.append(t,e);else n!==void 0&&a.set(t,n);let o=e.method!==`GET`&&e.method!==`HEAD`;return new Request(i,{body:o?Readable.toWeb(e):void 0,duplex:o?`half`:void 0,headers:a,method:e.method,signal:n})}async function writeResponse(e,n,r){if(e.destroyed){await n.body?.cancel();return}e.statusCode=n.status,e.statusMessage=n.statusText;let i=n.headers.getSetCookie?.call(n.headers)??[];if(n.headers.forEach((t,n)=>{n.toLowerCase()!==`set-cookie`&&e.setHeader(n,t)}),i.length>0&&e.setHeader(`set-cookie`,[...i]),n.body===null){await endResponse(e);return}let a=Readable.fromWeb(n.body),cancelBody=()=>a.destroy(r.reason);r.addEventListener(`abort`,cancelBody,{once:!0});try{await new Promise((t,n)=>{a.once(`error`,n),e.once(`error`,n),e.once(`close`,()=>{e.writableEnded||n(Error(`Development client disconnected.`))}),e.once(`finish`,t),a.pipe(e)})}finally{r.removeEventListener(`abort`,cancelBody),!a.destroyed&&(r.aborted||e.destroyed)&&a.destroy()}}function writeRequestError(t,n){if(t.headersSent){t.destroy();return}t.statusCode=503,t.setHeader(`content-type`,`application/json; charset=utf-8`),!t.writableEnded&&!t.destroyed&&t.end(JSON.stringify({error:toErrorMessage(n)}))}function closeServer(e){if(!e.listening)return Promise.resolve();let t=new Promise((t,n)=>{e.close(e=>{e===void 0?t():n(e)})});return e.closeIdleConnections?.(),t}async function endResponse(e){await new Promise((t,n)=>{e.once(`error`,n),e.end(t)})}export{closeServer,createPublicRequest,writeRequestError,writeResponse};
1
+ import{Readable}from"node:stream";import{toErrorMessage}from"#shared/errors.js";function createPublicRequest(t,n){let r=t.headers.host??`localhost`,i=new URL(t.url??`/`,`http://${r}`),a=new Headers;for(let[e,n]of Object.entries(t.headers))if(Array.isArray(n))for(let t of n)a.append(e,t);else n!==void 0&&a.set(e,n);let o=t.method!==`GET`&&t.method!==`HEAD`;return new Request(i,{body:o?Readable.toWeb(t):void 0,duplex:o?`half`:void 0,headers:a,method:t.method,signal:n})}async function writeResponse(t,n,r){if(t.destroyed){await n.body?.cancel();return}t.statusCode=n.status,t.statusMessage=n.statusText;let i=n.headers.getSetCookie?.call(n.headers)??[];if(n.headers.forEach((e,n)=>{n.toLowerCase()!==`set-cookie`&&t.setHeader(n,e)}),i.length>0&&t.setHeader(`set-cookie`,[...i]),n.body===null){await endResponse(t);return}let a=Readable.fromWeb(n.body),cancelBody=()=>a.destroy(r.reason);r.addEventListener(`abort`,cancelBody,{once:!0});try{await new Promise((e,n)=>{a.once(`error`,n),t.once(`error`,n),t.once(`close`,()=>{t.writableEnded||n(Error(`Development client disconnected.`))}),t.once(`finish`,e),a.pipe(t)})}finally{r.removeEventListener(`abort`,cancelBody),!a.destroyed&&(r.aborted||t.destroyed)&&a.destroy()}}function writeRequestError(e,n){if(e.headersSent){e.destroy();return}e.statusCode=503,e.setHeader(`content-type`,`application/json; charset=utf-8`),!e.writableEnded&&!e.destroyed&&e.end(JSON.stringify({error:toErrorMessage(n)}))}function closeServer(e){if(!e.listening)return Promise.resolve();let t=new Promise((t,n)=>{e.close(e=>{e===void 0?t():n(e)})});return e.closeIdleConnections?.(),t}async function endResponse(e){await new Promise((t,n)=>{e.once(`error`,n),e.end(t)})}export{closeServer,createPublicRequest,writeRequestError,writeResponse};
@@ -1 +1 @@
1
- import{z}from"#compiled/zod/index.js";import{httpServerUrlSchema}from"#shared/network-address.js";import{join}from"node:path";import{mkdir,readFile,rm,writeFile}from"node:fs/promises";const developmentServerStateSchema=z.object({url:httpServerUrlSchema}).strict();var DevelopmentServerState=class{appRoot;#e;#t;constructor(e){this.appRoot=e.appRoot,this.#e=join(this.appRoot,`.eve`),this.#t=join(this.#e,`dev-server-state.v1.json`)}async read(){let e;try{e=await readFile(this.#t,`utf8`)}catch(e){if(isErrnoException(e,`ENOENT`))return;throw e}try{let t=developmentServerStateSchema.safeParse(JSON.parse(e));return t.success?t.data.url:void 0}catch{return}}async write(e){let t=developmentServerStateSchema.parse({url:e});await mkdir(this.#e,{recursive:!0}),await writeFile(this.#t,`${JSON.stringify(t)}\n`,`utf8`)}async remove(){await rm(this.#t,{force:!0})}};function isErrnoException(e,t){return e instanceof Error&&`code`in e&&e.code===t}export{DevelopmentServerState};
1
+ import{mkdir,readFile,rm,writeFile}from"node:fs/promises";import{z}from"#compiled/zod/index.js";import{httpServerUrlSchema}from"#shared/network-address.js";import{join}from"node:path";const developmentServerStateSchema=z.object({url:httpServerUrlSchema}).strict();var DevelopmentServerState=class{appRoot;#e;#t;constructor(e){this.appRoot=e.appRoot,this.#e=join(this.appRoot,`.eve`),this.#t=join(this.#e,`dev-server-state.v1.json`)}async read(){let e;try{e=await readFile(this.#t,`utf8`)}catch(e){if(isErrnoException(e,`ENOENT`))return;throw e}try{let t=developmentServerStateSchema.safeParse(JSON.parse(e));return t.success?t.data.url:void 0}catch{return}}async write(t){let n=developmentServerStateSchema.parse({url:t});await mkdir(this.#e,{recursive:!0}),await writeFile(this.#t,`${JSON.stringify(n)}\n`,`utf8`)}async remove(){await rm(this.#t,{force:!0})}};function isErrnoException(e,t){return e instanceof Error&&`code`in e&&e.code===t}export{DevelopmentServerState};