veryfront 0.1.215 → 0.1.217

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 (305) hide show
  1. package/README.md +1 -1
  2. package/esm/cli/commands/extension/command-help.d.ts +3 -0
  3. package/esm/cli/commands/extension/command-help.d.ts.map +1 -0
  4. package/esm/cli/commands/extension/command-help.js +16 -0
  5. package/esm/cli/commands/extension/handler.d.ts +3 -0
  6. package/esm/cli/commands/extension/handler.d.ts.map +1 -0
  7. package/esm/cli/commands/extension/handler.js +36 -0
  8. package/esm/cli/commands/extension/init-command.d.ts +19 -0
  9. package/esm/cli/commands/extension/init-command.d.ts.map +1 -0
  10. package/esm/cli/commands/extension/init-command.js +122 -0
  11. package/esm/cli/commands/extension/validate-command.d.ts +13 -0
  12. package/esm/cli/commands/extension/validate-command.d.ts.map +1 -0
  13. package/esm/cli/commands/extension/validate-command.js +62 -0
  14. package/esm/cli/commands/generate/integration-generator-helpers.d.ts +35 -0
  15. package/esm/cli/commands/generate/integration-generator-helpers.d.ts.map +1 -0
  16. package/esm/cli/commands/generate/integration-generator-helpers.js +123 -0
  17. package/esm/cli/commands/generate/integration-generator.d.ts +1 -2
  18. package/esm/cli/commands/generate/integration-generator.d.ts.map +1 -1
  19. package/esm/cli/commands/generate/integration-generator.js +1 -123
  20. package/esm/cli/commands/knowledge/command-helpers.d.ts +48 -0
  21. package/esm/cli/commands/knowledge/command-helpers.d.ts.map +1 -0
  22. package/esm/cli/commands/knowledge/command-helpers.js +216 -0
  23. package/esm/cli/commands/knowledge/command.d.ts +12 -17
  24. package/esm/cli/commands/knowledge/command.d.ts.map +1 -1
  25. package/esm/cli/commands/knowledge/command.js +26 -214
  26. package/esm/cli/help/command-definitions.d.ts.map +1 -1
  27. package/esm/cli/help/command-definitions.js +2 -0
  28. package/esm/cli/mcp/remote-file-tool-helpers.d.ts +5 -0
  29. package/esm/cli/mcp/remote-file-tool-helpers.d.ts.map +1 -0
  30. package/esm/cli/mcp/remote-file-tool-helpers.js +22 -0
  31. package/esm/cli/mcp/remote-file-tools.d.ts.map +1 -1
  32. package/esm/cli/mcp/remote-file-tools.js +1 -22
  33. package/esm/cli/router.d.ts.map +1 -1
  34. package/esm/cli/router.js +2 -0
  35. package/esm/cli/templates/integration-loader-helpers.d.ts +8 -0
  36. package/esm/cli/templates/integration-loader-helpers.d.ts.map +1 -0
  37. package/esm/cli/templates/integration-loader-helpers.js +29 -0
  38. package/esm/cli/templates/integration-loader.d.ts.map +1 -1
  39. package/esm/cli/templates/integration-loader.js +5 -21
  40. package/esm/cli/templates/manifest.d.ts +1 -0
  41. package/esm/cli/templates/manifest.js +2 -1
  42. package/esm/deno.d.ts +3 -0
  43. package/esm/deno.js +5 -2
  44. package/esm/src/agent/runtime/index.d.ts.map +1 -1
  45. package/esm/src/agent/runtime/index.js +48 -90
  46. package/esm/src/chat/ag-ui-helpers.d.ts +17 -0
  47. package/esm/src/chat/ag-ui-helpers.d.ts.map +1 -0
  48. package/esm/src/chat/ag-ui-helpers.js +111 -0
  49. package/esm/src/chat/ag-ui.d.ts.map +1 -1
  50. package/esm/src/chat/ag-ui.js +1 -111
  51. package/esm/src/config/schemas/config.schema.d.ts +1 -0
  52. package/esm/src/config/schemas/config.schema.d.ts.map +1 -1
  53. package/esm/src/config/schemas/config.schema.js +11 -0
  54. package/esm/src/config/schemas/index.d.ts +11 -1
  55. package/esm/src/config/schemas/index.d.ts.map +1 -1
  56. package/esm/src/errors/error-registry-helpers.d.ts +6 -0
  57. package/esm/src/errors/error-registry-helpers.d.ts.map +1 -0
  58. package/esm/src/errors/error-registry-helpers.js +9 -0
  59. package/esm/src/errors/error-registry.d.ts.map +1 -1
  60. package/esm/src/errors/error-registry.js +4 -3
  61. package/esm/src/extensions/capabilities.d.ts +20 -0
  62. package/esm/src/extensions/capabilities.d.ts.map +1 -0
  63. package/esm/src/extensions/capabilities.js +77 -0
  64. package/esm/src/extensions/contracts.d.ts +10 -0
  65. package/esm/src/extensions/contracts.d.ts.map +1 -0
  66. package/esm/src/extensions/contracts.js +28 -0
  67. package/esm/src/extensions/discovery.d.ts +48 -0
  68. package/esm/src/extensions/discovery.d.ts.map +1 -0
  69. package/esm/src/extensions/discovery.js +179 -0
  70. package/esm/src/extensions/errors.d.ts +10 -0
  71. package/esm/src/extensions/errors.d.ts.map +1 -0
  72. package/esm/src/extensions/errors.js +34 -0
  73. package/esm/src/extensions/factory-loader.d.ts +29 -0
  74. package/esm/src/extensions/factory-loader.d.ts.map +1 -0
  75. package/esm/src/extensions/factory-loader.js +63 -0
  76. package/esm/src/extensions/index.d.ts +37 -0
  77. package/esm/src/extensions/index.d.ts.map +1 -0
  78. package/esm/src/extensions/index.js +41 -0
  79. package/esm/src/extensions/interfaces/ai-model-provider.d.ts +94 -0
  80. package/esm/src/extensions/interfaces/ai-model-provider.d.ts.map +1 -0
  81. package/esm/src/extensions/interfaces/ai-model-provider.js +8 -0
  82. package/esm/src/extensions/interfaces/auth-provider.d.ts +49 -0
  83. package/esm/src/extensions/interfaces/auth-provider.d.ts.map +1 -0
  84. package/esm/src/extensions/interfaces/auth-provider.js +8 -0
  85. package/esm/src/extensions/interfaces/bundler.d.ts +118 -0
  86. package/esm/src/extensions/interfaces/bundler.d.ts.map +1 -0
  87. package/esm/src/extensions/interfaces/bundler.js +8 -0
  88. package/esm/src/extensions/interfaces/cache-store.d.ts +27 -0
  89. package/esm/src/extensions/interfaces/cache-store.d.ts.map +1 -0
  90. package/esm/src/extensions/interfaces/cache-store.js +8 -0
  91. package/esm/src/extensions/interfaces/code-parser.d.ts +76 -0
  92. package/esm/src/extensions/interfaces/code-parser.d.ts.map +1 -0
  93. package/esm/src/extensions/interfaces/code-parser.js +8 -0
  94. package/esm/src/extensions/interfaces/content-transformer.d.ts +40 -0
  95. package/esm/src/extensions/interfaces/content-transformer.d.ts.map +1 -0
  96. package/esm/src/extensions/interfaces/content-transformer.js +8 -0
  97. package/esm/src/extensions/interfaces/css-processor.d.ts +38 -0
  98. package/esm/src/extensions/interfaces/css-processor.d.ts.map +1 -0
  99. package/esm/src/extensions/interfaces/css-processor.js +8 -0
  100. package/esm/src/extensions/interfaces/database-client.d.ts +31 -0
  101. package/esm/src/extensions/interfaces/database-client.d.ts.map +1 -0
  102. package/esm/src/extensions/interfaces/database-client.js +8 -0
  103. package/esm/src/extensions/interfaces/embedding-provider.d.ts +37 -0
  104. package/esm/src/extensions/interfaces/embedding-provider.d.ts.map +1 -0
  105. package/esm/src/extensions/interfaces/embedding-provider.js +8 -0
  106. package/esm/src/extensions/interfaces/index.d.ts +21 -0
  107. package/esm/src/extensions/interfaces/index.d.ts.map +1 -0
  108. package/esm/src/extensions/interfaces/index.js +9 -0
  109. package/esm/src/extensions/interfaces/node-compat.d.ts +25 -0
  110. package/esm/src/extensions/interfaces/node-compat.d.ts.map +1 -0
  111. package/esm/src/extensions/interfaces/node-compat.js +8 -0
  112. package/esm/src/extensions/interfaces/schema-validator.d.ts +46 -0
  113. package/esm/src/extensions/interfaces/schema-validator.d.ts.map +1 -0
  114. package/esm/src/extensions/interfaces/schema-validator.js +8 -0
  115. package/esm/src/extensions/interfaces/tracing-exporter.d.ts +44 -0
  116. package/esm/src/extensions/interfaces/tracing-exporter.d.ts.map +1 -0
  117. package/esm/src/extensions/interfaces/tracing-exporter.js +8 -0
  118. package/esm/src/extensions/loader.d.ts +33 -0
  119. package/esm/src/extensions/loader.d.ts.map +1 -0
  120. package/esm/src/extensions/loader.js +209 -0
  121. package/esm/src/extensions/orchestrate.d.ts +54 -0
  122. package/esm/src/extensions/orchestrate.d.ts.map +1 -0
  123. package/esm/src/extensions/orchestrate.js +116 -0
  124. package/esm/src/extensions/recommendations.d.ts +7 -0
  125. package/esm/src/extensions/recommendations.d.ts.map +1 -0
  126. package/esm/src/extensions/recommendations.js +22 -0
  127. package/esm/src/extensions/types.d.ts +47 -0
  128. package/esm/src/extensions/types.d.ts.map +1 -0
  129. package/esm/src/extensions/types.js +6 -0
  130. package/esm/src/extensions/validation.d.ts +44 -0
  131. package/esm/src/extensions/validation.d.ts.map +1 -0
  132. package/esm/src/extensions/validation.js +115 -0
  133. package/esm/src/html/styles-builder/plugin-loader.d.ts.map +1 -1
  134. package/esm/src/html/styles-builder/plugin-loader.js +23 -0
  135. package/esm/src/html/styles-builder/tailwind-plugin-allowlist.d.ts +29 -0
  136. package/esm/src/html/styles-builder/tailwind-plugin-allowlist.d.ts.map +1 -0
  137. package/esm/src/html/styles-builder/tailwind-plugin-allowlist.js +48 -0
  138. package/esm/src/modules/react-loader/ssr-module-loader/loader-helpers.d.ts +15 -0
  139. package/esm/src/modules/react-loader/ssr-module-loader/loader-helpers.d.ts.map +1 -0
  140. package/esm/src/modules/react-loader/ssr-module-loader/loader-helpers.js +22 -0
  141. package/esm/src/modules/react-loader/ssr-module-loader/loader.d.ts +0 -2
  142. package/esm/src/modules/react-loader/ssr-module-loader/loader.d.ts.map +1 -1
  143. package/esm/src/modules/react-loader/ssr-module-loader/loader.js +4 -24
  144. package/esm/src/platform/adapters/fs/veryfront/adapter-helpers.d.ts +19 -0
  145. package/esm/src/platform/adapters/fs/veryfront/adapter-helpers.d.ts.map +1 -0
  146. package/esm/src/platform/adapters/fs/veryfront/adapter-helpers.js +26 -0
  147. package/esm/src/platform/adapters/fs/veryfront/adapter.d.ts.map +1 -1
  148. package/esm/src/platform/adapters/fs/veryfront/adapter.js +4 -20
  149. package/esm/src/platform/adapters/fs/veryfront/read-operations-helpers.d.ts +1 -0
  150. package/esm/src/platform/adapters/fs/veryfront/read-operations-helpers.d.ts.map +1 -1
  151. package/esm/src/platform/adapters/fs/veryfront/read-operations-helpers.js +3 -0
  152. package/esm/src/platform/adapters/fs/veryfront/read-operations.d.ts.map +1 -1
  153. package/esm/src/platform/adapters/fs/veryfront/read-operations.js +4 -7
  154. package/esm/src/platform/adapters/fs/veryfront/websocket-manager-helpers.d.ts +28 -0
  155. package/esm/src/platform/adapters/fs/veryfront/websocket-manager-helpers.d.ts.map +1 -0
  156. package/esm/src/platform/adapters/fs/veryfront/websocket-manager-helpers.js +41 -0
  157. package/esm/src/platform/adapters/fs/veryfront/websocket-manager.d.ts +1 -4
  158. package/esm/src/platform/adapters/fs/veryfront/websocket-manager.d.ts.map +1 -1
  159. package/esm/src/platform/adapters/fs/veryfront/websocket-manager.js +7 -40
  160. package/esm/src/platform/compat/process/command.d.ts +31 -0
  161. package/esm/src/platform/compat/process/command.d.ts.map +1 -0
  162. package/esm/src/platform/compat/process/command.js +193 -0
  163. package/esm/src/platform/compat/process/env.d.ts +31 -0
  164. package/esm/src/platform/compat/process/env.d.ts.map +1 -0
  165. package/esm/src/platform/compat/process/env.js +175 -0
  166. package/esm/src/platform/compat/process/lifecycle.d.ts +98 -0
  167. package/esm/src/platform/compat/process/lifecycle.d.ts.map +1 -0
  168. package/esm/src/platform/compat/process/lifecycle.js +305 -0
  169. package/esm/src/platform/compat/process/runtime-process.d.ts +10 -0
  170. package/esm/src/platform/compat/process/runtime-process.d.ts.map +1 -0
  171. package/esm/src/platform/compat/process/runtime-process.js +24 -0
  172. package/esm/src/platform/compat/process.d.ts +4 -165
  173. package/esm/src/platform/compat/process.d.ts.map +1 -1
  174. package/esm/src/platform/compat/process.js +4 -682
  175. package/esm/src/platform/index.d.ts +1 -1
  176. package/esm/src/platform/index.d.ts.map +1 -1
  177. package/esm/src/provider/runtime-loader/provider-endpoints.d.ts +8 -0
  178. package/esm/src/provider/runtime-loader/provider-endpoints.d.ts.map +1 -0
  179. package/esm/src/provider/runtime-loader/provider-endpoints.js +27 -0
  180. package/esm/src/provider/runtime-loader/provider-request-init.d.ts +32 -0
  181. package/esm/src/provider/runtime-loader/provider-request-init.d.ts.map +1 -0
  182. package/esm/src/provider/runtime-loader/provider-request-init.js +67 -0
  183. package/esm/src/provider/runtime-loader/tool-input-status.d.ts +17 -0
  184. package/esm/src/provider/runtime-loader/tool-input-status.d.ts.map +1 -0
  185. package/esm/src/provider/runtime-loader/tool-input-status.js +155 -0
  186. package/esm/src/provider/runtime-loader.d.ts +2 -3
  187. package/esm/src/provider/runtime-loader.d.ts.map +1 -1
  188. package/esm/src/provider/runtime-loader.js +92 -291
  189. package/esm/src/proxy/handler.d.ts.map +1 -1
  190. package/esm/src/proxy/handler.js +14 -0
  191. package/esm/src/rendering/orchestrator/pipeline-helpers.d.ts +8 -0
  192. package/esm/src/rendering/orchestrator/pipeline-helpers.d.ts.map +1 -0
  193. package/esm/src/rendering/orchestrator/pipeline-helpers.js +20 -0
  194. package/esm/src/rendering/orchestrator/pipeline.d.ts +0 -3
  195. package/esm/src/rendering/orchestrator/pipeline.d.ts.map +1 -1
  196. package/esm/src/rendering/orchestrator/pipeline.js +4 -22
  197. package/esm/src/routing/api/module-loader/loader-helpers.d.ts +10 -0
  198. package/esm/src/routing/api/module-loader/loader-helpers.d.ts.map +1 -0
  199. package/esm/src/routing/api/module-loader/loader-helpers.js +62 -0
  200. package/esm/src/routing/api/module-loader/loader.d.ts +1 -1
  201. package/esm/src/routing/api/module-loader/loader.d.ts.map +1 -1
  202. package/esm/src/routing/api/module-loader/loader.js +2 -60
  203. package/esm/src/server/bootstrap.d.ts +22 -2
  204. package/esm/src/server/bootstrap.d.ts.map +1 -1
  205. package/esm/src/server/bootstrap.js +67 -5
  206. package/esm/src/server/dev-ui/manifest.d.ts +2 -0
  207. package/esm/src/server/dev-ui/manifest.js +3 -1
  208. package/esm/src/server/handlers/request/api/project-discovery.d.ts.map +1 -1
  209. package/esm/src/server/handlers/request/api/project-discovery.js +14 -8
  210. package/esm/src/server/production-server.js +1 -1
  211. package/esm/src/server/services/rsc/endpoints/rsc-bundles.generated.d.ts.map +1 -1
  212. package/esm/src/server/services/rsc/endpoints/rsc-bundles.generated.js +2 -2
  213. package/esm/src/server/utils/domain-parser.d.ts.map +1 -1
  214. package/esm/src/server/utils/domain-parser.js +4 -0
  215. package/esm/src/studio/bridge/bridge-bundle.generated.d.ts.map +1 -1
  216. package/esm/src/studio/bridge/bridge-bundle.generated.js +1 -1
  217. package/esm/src/tool/index.d.ts +1 -1
  218. package/esm/src/tool/index.d.ts.map +1 -1
  219. package/esm/src/tool/types.d.ts +20 -0
  220. package/esm/src/tool/types.d.ts.map +1 -1
  221. package/esm/src/utils/version-constant.d.ts +1 -1
  222. package/esm/src/utils/version-constant.js +1 -1
  223. package/package.json +7 -1
  224. package/src/cli/commands/extension/command-help.ts +18 -0
  225. package/src/cli/commands/extension/handler.ts +41 -0
  226. package/src/cli/commands/extension/init-command.ts +140 -0
  227. package/src/cli/commands/extension/validate-command.ts +78 -0
  228. package/src/cli/commands/generate/integration-generator-helpers.ts +185 -0
  229. package/src/cli/commands/generate/integration-generator.ts +12 -168
  230. package/src/cli/commands/knowledge/command-helpers.ts +295 -0
  231. package/src/cli/commands/knowledge/command.ts +34 -261
  232. package/src/cli/help/command-definitions.ts +2 -0
  233. package/src/cli/mcp/remote-file-tool-helpers.ts +27 -0
  234. package/src/cli/mcp/remote-file-tools.ts +6 -28
  235. package/src/cli/router.ts +2 -0
  236. package/src/cli/templates/integration-loader-helpers.ts +49 -0
  237. package/src/cli/templates/integration-loader.ts +10 -28
  238. package/src/cli/templates/manifest.js +2 -1
  239. package/src/deno.js +5 -2
  240. package/src/src/agent/runtime/index.ts +77 -94
  241. package/src/src/chat/ag-ui-helpers.ts +139 -0
  242. package/src/src/chat/ag-ui.ts +11 -139
  243. package/src/src/config/schemas/config.schema.ts +11 -0
  244. package/src/src/config/schemas/index.ts +15 -1
  245. package/src/src/errors/error-registry-helpers.ts +23 -0
  246. package/src/src/errors/error-registry.ts +8 -3
  247. package/src/src/extensions/capabilities.ts +97 -0
  248. package/src/src/extensions/contracts.ts +36 -0
  249. package/src/src/extensions/discovery.ts +221 -0
  250. package/src/src/extensions/errors.ts +39 -0
  251. package/src/src/extensions/factory-loader.ts +76 -0
  252. package/src/src/extensions/index.ts +79 -0
  253. package/src/src/extensions/interfaces/ai-model-provider.ts +100 -0
  254. package/src/src/extensions/interfaces/auth-provider.ts +52 -0
  255. package/src/src/extensions/interfaces/bundler.ts +116 -0
  256. package/src/src/extensions/interfaces/cache-store.ts +27 -0
  257. package/src/src/extensions/interfaces/code-parser.ts +84 -0
  258. package/src/src/extensions/interfaces/content-transformer.ts +38 -0
  259. package/src/src/extensions/interfaces/css-processor.ts +40 -0
  260. package/src/src/extensions/interfaces/database-client.ts +35 -0
  261. package/src/src/extensions/interfaces/embedding-provider.ts +39 -0
  262. package/src/src/extensions/interfaces/index.ts +81 -0
  263. package/src/src/extensions/interfaces/node-compat.ts +25 -0
  264. package/src/src/extensions/interfaces/schema-validator.ts +51 -0
  265. package/src/src/extensions/interfaces/tracing-exporter.ts +42 -0
  266. package/src/src/extensions/loader.ts +245 -0
  267. package/src/src/extensions/orchestrate.ts +184 -0
  268. package/src/src/extensions/recommendations.ts +24 -0
  269. package/src/src/extensions/types.ts +57 -0
  270. package/src/src/extensions/validation.ts +147 -0
  271. package/src/src/html/styles-builder/plugin-loader.ts +32 -0
  272. package/src/src/html/styles-builder/tailwind-plugin-allowlist.ts +51 -0
  273. package/src/src/modules/react-loader/ssr-module-loader/loader-helpers.ts +37 -0
  274. package/src/src/modules/react-loader/ssr-module-loader/loader.ts +8 -39
  275. package/src/src/platform/adapters/fs/veryfront/adapter-helpers.ts +43 -0
  276. package/src/src/platform/adapters/fs/veryfront/adapter.ts +8 -22
  277. package/src/src/platform/adapters/fs/veryfront/read-operations-helpers.ts +4 -0
  278. package/src/src/platform/adapters/fs/veryfront/read-operations.ts +4 -7
  279. package/src/src/platform/adapters/fs/veryfront/websocket-manager-helpers.ts +73 -0
  280. package/src/src/platform/adapters/fs/veryfront/websocket-manager.ts +29 -44
  281. package/src/src/platform/compat/process/command.ts +297 -0
  282. package/src/src/platform/compat/process/env.ts +227 -0
  283. package/src/src/platform/compat/process/lifecycle.ts +330 -0
  284. package/src/src/platform/compat/process/runtime-process.ts +27 -0
  285. package/src/src/platform/compat/process.ts +37 -870
  286. package/src/src/platform/index.ts +1 -0
  287. package/src/src/provider/runtime-loader/provider-endpoints.ts +50 -0
  288. package/src/src/provider/runtime-loader/provider-request-init.ts +101 -0
  289. package/src/src/provider/runtime-loader/tool-input-status.ts +210 -0
  290. package/src/src/provider/runtime-loader.ts +113 -368
  291. package/src/src/proxy/handler.ts +16 -0
  292. package/src/src/rendering/orchestrator/pipeline-helpers.ts +35 -0
  293. package/src/src/rendering/orchestrator/pipeline.ts +8 -35
  294. package/src/src/routing/api/module-loader/loader-helpers.ts +68 -0
  295. package/src/src/routing/api/module-loader/loader.ts +8 -65
  296. package/src/src/server/bootstrap.ts +88 -7
  297. package/src/src/server/dev-ui/manifest.js +3 -1
  298. package/src/src/server/handlers/request/api/project-discovery.ts +19 -8
  299. package/src/src/server/production-server.ts +1 -1
  300. package/src/src/server/services/rsc/endpoints/rsc-bundles.generated.ts +2 -2
  301. package/src/src/server/utils/domain-parser.ts +4 -0
  302. package/src/src/studio/bridge/bridge-bundle.generated.ts +1 -1
  303. package/src/src/tool/index.ts +1 -0
  304. package/src/src/tool/types.ts +21 -0
  305. package/src/src/utils/version-constant.ts +1 -1
@@ -1,870 +1,37 @@
1
- import * as dntShim from "../../../_dnt.shims.js";
2
- import { isBun as IS_BUN, isDeno as IS_DENO } from "./runtime.js";
3
- import { dynamicImport } from "./dynamic-import.js";
4
-
5
- const nodeProcess = (dntShim.dntGlobalThis as { process?: typeof import("node:process") }).process;
6
- type RuntimeProcess = typeof import("node:process");
7
-
8
- /**
9
- * Detect a real Node/Bun process object.
10
- * Browser bundles may inject `window.process = { env: {} }`, which is not enough
11
- * to safely call process APIs like cwd(), exit(), or on().
12
- */
13
- export function testHasRuntimeProcess(processLike: unknown): processLike is RuntimeProcess {
14
- if (!processLike || typeof processLike !== "object") return false;
15
- const versions = (processLike as { versions?: { node?: string } }).versions;
16
- return typeof versions?.node === "string" && versions.node.length > 0;
17
- }
18
-
19
- const runtimeProcess = testHasRuntimeProcess(nodeProcess) ? nodeProcess : null;
20
-
21
- function isWindowsPlatform(): boolean {
22
- if (IS_DENO) return dntShim.Deno.build.os === "windows";
23
- const platform = runtimeProcess?.platform ??
24
- (dntShim.dntGlobalThis as { process?: { platform?: string } }).process?.platform;
25
- return platform === "win32";
26
- }
27
-
28
- /** Get command-line arguments (cross-runtime: Deno.args or process.argv). */
29
- export function getArgs(): string[] {
30
- if (IS_DENO) return dntShim.Deno.args;
31
- if (runtimeProcess) return runtimeProcess.argv.slice(2);
32
- return [];
33
- }
34
-
35
- /** Exit the process with an optional code (cross-runtime: Deno.exit or process.exit). */
36
- export function exit(code?: number): never {
37
- if (IS_DENO) dntShim.Deno.exit(code);
38
- if (runtimeProcess) runtimeProcess.exit(code);
39
- throw new Error("exit() is not supported in this runtime");
40
- }
41
-
42
- export function cwd(): string {
43
- if (IS_DENO) return dntShim.Deno.cwd();
44
- if (runtimeProcess) return runtimeProcess.cwd();
45
- throw new Error("cwd() is not supported in this runtime");
46
- }
47
-
48
- export function chdir(directory: string): void {
49
- if (IS_DENO) {
50
- dntShim.Deno.chdir(directory);
51
- return;
52
- }
53
- if (runtimeProcess) {
54
- runtimeProcess.chdir(directory);
55
- return;
56
- }
57
- throw new Error("chdir() is not supported in this runtime");
58
- }
59
-
60
- type EnvOverlayValue = string | null;
61
- type EnvOverlayStore = Map<string, EnvOverlayValue>;
62
-
63
- function getEnvOverlayStore(): EnvOverlayStore | null {
64
- const storage = getEnvOverlayStorage();
65
- const store = storage?.getStore();
66
- return store instanceof Map ? store as EnvOverlayStore : null;
67
- }
68
-
69
- function getOverlayEnvValue(
70
- store: EnvOverlayStore | null,
71
- key: string,
72
- ): { hasValue: boolean; value: string | undefined } {
73
- if (!store?.has(key)) {
74
- return { hasValue: false, value: undefined };
75
- }
76
-
77
- const value = store.get(key);
78
- return { hasValue: true, value: value ?? undefined };
79
- }
80
-
81
- export function env(): Record<string, string> {
82
- const base = IS_DENO
83
- ? dntShim.Deno.env.toObject()
84
- : runtimeProcess
85
- ? { ...runtimeProcess.env } as Record<string, string>
86
- : {};
87
-
88
- const overlay = getEnvOverlayStore();
89
- if (!overlay) return base;
90
-
91
- for (const [key, value] of overlay.entries()) {
92
- if (value === null) {
93
- delete base[key];
94
- continue;
95
- }
96
- base[key] = value;
97
- }
98
-
99
- return base;
100
- }
101
-
102
- /**
103
- * Read a host-level environment variable without consulting any project env overlay.
104
- * Use this for framework-owned runtime configuration that should not be shadowed by tenant env.
105
- */
106
- export function getHostEnv(key: string): string | undefined {
107
- const overlayResult = getOverlayEnvValue(getEnvOverlayStore(), key);
108
- if (overlayResult.hasValue) {
109
- return overlayResult.value;
110
- }
111
-
112
- if (IS_DENO) return dntShim.Deno.env.get(key);
113
- if (runtimeProcess) return runtimeProcess.env[key];
114
- return undefined;
115
- }
116
-
117
- // Lazy-loaded references to project-env/storage.ts functions.
118
- // Uses globalThis to avoid circular imports (process.ts is low-level, project-env is high-level).
119
- // IMPORTANT: Only cache when the real getter is found. If storage.ts hasn't loaded yet,
120
- // re-check globalThis on every call to avoid permanently caching the fallback.
121
- let _getProjectEnv: ((key: string) => string | undefined) | null = null;
122
- let _isProjectEnvActive: (() => boolean) | null = null;
123
-
124
- function getProjectEnvSafe(key: string): string | undefined {
125
- if (_getProjectEnv === null) {
126
- const mod = (dntShim.dntGlobalThis as Record<string, unknown>).__vfProjectEnvGetter as
127
- | ((key: string) => string | undefined)
128
- | undefined;
129
- if (mod) {
130
- _getProjectEnv = mod;
131
- } else {
132
- return undefined;
133
- }
134
- }
135
- return _getProjectEnv(key);
136
- }
137
-
138
- function isProjectEnvActiveSafe(): boolean {
139
- if (_isProjectEnvActive === null) {
140
- const mod = (dntShim.dntGlobalThis as Record<string, unknown>).__vfProjectEnvActiveChecker as
141
- | (() => boolean)
142
- | undefined;
143
- if (mod) {
144
- _isProjectEnvActive = mod;
145
- } else {
146
- return false;
147
- }
148
- }
149
- return _isProjectEnvActive();
150
- }
151
-
152
- export function getEnv(key: string): string | undefined {
153
- // Check per-request project env overlay first (AsyncLocalStorage)
154
- const projectValue = getProjectEnvSafe(key);
155
- if (projectValue !== undefined) return projectValue;
156
-
157
- // When a project env overlay is active (remote project request), do NOT
158
- // fall through to host process env. This prevents remote projects from
159
- // reading host-level secrets like AWS_SECRET_ACCESS_KEY, DATABASE_URL, etc.
160
- if (isProjectEnvActiveSafe()) return undefined;
161
-
162
- return getHostEnv(key);
163
- }
164
-
165
- const DEFAULT_ENV_TRUE_VALUES = ["1", "true", "yes"] as const;
166
- const DEFAULT_ENV_FALSE_VALUES = ["0", "false", "no"] as const;
167
-
168
- export interface EnvBooleanOptions {
169
- trueValues?: readonly string[];
170
- falseValues?: readonly string[];
171
- trim?: boolean;
172
- caseSensitive?: boolean;
173
- }
174
-
175
- function normalizeEnvToken(
176
- value: string,
177
- options: { trim: boolean; caseSensitive: boolean },
178
- ): string {
179
- const normalized = options.trim ? value.trim() : value;
180
- return options.caseSensitive ? normalized : normalized.toLowerCase();
181
- }
182
-
183
- export function getEnvString(key: string): string | undefined;
184
- export function getEnvString(key: string, fallback: string): string;
185
- export function getEnvString(key: string, fallback?: string): string | undefined {
186
- const value = getEnv(key);
187
- if (value === undefined) return fallback;
188
- return value;
189
- }
190
-
191
- export function getEnvNumber(key: string): number | undefined;
192
- export function getEnvNumber(key: string, fallback: number): number;
193
- export function getEnvNumber(key: string, fallback?: number): number | undefined {
194
- const value = getEnvString(key);
195
- if (value === undefined) return fallback;
196
-
197
- const parsed = Number.parseInt(value, 10);
198
- if (Number.isNaN(parsed)) return fallback ?? Number.NaN;
199
- return parsed;
200
- }
201
-
202
- export function getEnvBoolean(
203
- key: string,
204
- fallback = false,
205
- options: EnvBooleanOptions = {},
206
- ): boolean {
207
- const value = getEnvString(key);
208
- if (value === undefined) return fallback;
209
-
210
- const trim = options.trim ?? true;
211
- const caseSensitive = options.caseSensitive ?? false;
212
- const normalized = normalizeEnvToken(value, { trim, caseSensitive });
213
-
214
- const trueValues = options.trueValues ?? DEFAULT_ENV_TRUE_VALUES;
215
- for (const trueValue of trueValues) {
216
- if (normalized === normalizeEnvToken(trueValue, { trim, caseSensitive })) return true;
217
- }
218
-
219
- const falseValues = options.falseValues ?? DEFAULT_ENV_FALSE_VALUES;
220
- for (const falseValue of falseValues) {
221
- if (normalized === normalizeEnvToken(falseValue, { trim, caseSensitive })) return false;
222
- }
223
-
224
- return fallback;
225
- }
226
-
227
- export function setEnv(key: string, value: string): void {
228
- const overlay = getEnvOverlayStore();
229
- if (overlay) {
230
- overlay.set(key, value);
231
- return;
232
- }
233
-
234
- if (IS_DENO) {
235
- dntShim.Deno.env.set(key, value);
236
- return;
237
- }
238
- if (runtimeProcess) {
239
- runtimeProcess.env[key] = value;
240
- return;
241
- }
242
- throw new Error("setEnv() is not supported in this runtime");
243
- }
244
-
245
- export function deleteEnv(key: string): void {
246
- const overlay = getEnvOverlayStore();
247
- if (overlay) {
248
- overlay.set(key, null);
249
- return;
250
- }
251
-
252
- if (IS_DENO) {
253
- dntShim.Deno.env.delete(key);
254
- return;
255
- }
256
- if (runtimeProcess) {
257
- delete runtimeProcess.env[key];
258
- return;
259
- }
260
- throw new Error("deleteEnv() is not supported in this runtime");
261
- }
262
-
263
- type EnvOverlayStorage = {
264
- getStore: () => unknown;
265
- run?: <T>(store: unknown, fn: () => T) => T;
266
- enterWith?: (store: unknown) => void;
267
- };
268
-
269
- /**
270
- * Get an AsyncLocalStorage-based env overlay storage if installed.
271
- * This enables per-async-context env isolation (e.g., in tests).
272
- */
273
- export function getEnvOverlayStorage(): EnvOverlayStorage | null {
274
- const globalAny = dntShim.dntGlobalThis as Record<string, unknown>;
275
- const overlay =
276
- (globalAny["__vfTestDenoEnvOverlay"] as { storage?: EnvOverlayStorage } | undefined) ??
277
- (globalAny["__vfTestEnvOverlay"] as { storage?: EnvOverlayStorage } | undefined);
278
-
279
- const storage = overlay?.storage;
280
- if (!storage || typeof storage.getStore !== "function") return null;
281
- return storage;
282
- }
283
-
284
- export function pid(): number {
285
- if (IS_DENO) return dntShim.Deno.pid;
286
- if (runtimeProcess) return runtimeProcess.pid;
287
- return 0;
288
- }
289
-
290
- export function memoryUsage(): {
291
- rss: number;
292
- heapTotal: number;
293
- heapUsed: number;
294
- external: number;
295
- } {
296
- if (IS_DENO) {
297
- const { rss, heapTotal, heapUsed, external } = dntShim.Deno.memoryUsage();
298
- return { rss, heapTotal, heapUsed, external };
299
- }
300
-
301
- if (!runtimeProcess) {
302
- throw new Error("memoryUsage() is not supported in this runtime");
303
- }
304
-
305
- const { rss, heapTotal, heapUsed, external } = runtimeProcess.memoryUsage();
306
- return { rss, heapTotal, heapUsed, external: external || 0 };
307
- }
308
-
309
- /**
310
- * Check if stdin is a TTY (terminal)
311
- */
312
- export function isInteractive(): boolean {
313
- if (IS_DENO) return dntShim.Deno.stdin.isTerminal();
314
- if (runtimeProcess) return runtimeProcess.stdin.isTTY ?? false;
315
- return false;
316
- }
317
-
318
- /**
319
- * Check if stdout is a TTY (terminal)
320
- */
321
- export function isStdoutTTY(): boolean {
322
- if (IS_DENO) return dntShim.Deno.stdout.isTerminal();
323
- if (runtimeProcess) return runtimeProcess.stdout.isTTY ?? false;
324
- return false;
325
- }
326
-
327
- /**
328
- * Get terminal size (columns and rows)
329
- * Returns default fallback values if terminal size cannot be determined
330
- */
331
- export function getTerminalSize(): { columns: number; rows: number } {
332
- const defaultSize = { columns: 80, rows: 24 };
333
-
334
- if (IS_DENO) {
335
- try {
336
- const { columns, rows } = dntShim.Deno.consoleSize();
337
- return { columns, rows };
338
- } catch (_) {
339
- /* expected: Deno.consoleSize() fails when not attached to a terminal */
340
- return defaultSize;
341
- }
342
- }
343
-
344
- if (!runtimeProcess) return defaultSize;
345
-
346
- const columns = runtimeProcess.stdout?.columns;
347
- const rows = runtimeProcess.stdout?.rows;
348
- if (columns && rows) return { columns, rows };
349
-
350
- return defaultSize;
351
- }
352
-
353
- /**
354
- * Get runtime version string
355
- */
356
- export function getRuntimeVersion(): string {
357
- if (IS_DENO) return `Deno ${dntShim.Deno.version.deno}`;
358
- if ("Bun" in dntShim.dntGlobalThis) {
359
- return `Bun ${(dntShim.dntGlobalThis as unknown as { Bun: { version: string } }).Bun.version}`;
360
- }
361
- if (runtimeProcess) return `Node.js ${runtimeProcess.version}`;
362
- return "unknown";
363
- }
364
-
365
- /**
366
- * Get the operating system type
367
- * Returns: "darwin" (macOS), "linux", "windows", or the raw platform string
368
- */
369
- export function getOsType(): string {
370
- if (IS_DENO) return dntShim.Deno.build.os;
371
- if (runtimeProcess) {
372
- // Node/Bun uses process.platform which returns "win32" for Windows
373
- const platform = runtimeProcess.platform;
374
- return platform === "win32" ? "windows" : platform;
375
- }
376
- return "unknown";
377
- }
378
-
379
- /**
380
- * Register a signal handler (SIGINT, SIGTERM) for graceful shutdown
381
- */
382
- export function onSignal(
383
- signal: "SIGINT" | "SIGTERM",
384
- handler: () => void,
385
- ): void {
386
- if (IS_DENO) {
387
- dntShim.Deno.addSignalListener(signal, handler);
388
- return;
389
- }
390
- if (runtimeProcess) runtimeProcess.on(signal, handler);
391
- }
392
-
393
- /**
394
- * Register global error handlers for uncaught exceptions and unhandled promise rejections.
395
- * These handlers prevent the process from crashing due to application code errors.
396
- *
397
- * IMPORTANT: These handlers should be registered early in the application lifecycle
398
- * to catch errors that escape try/catch blocks.
399
- *
400
- * @param onError - Callback invoked with the error. Return true to prevent process exit.
401
- */
402
- export function onGlobalError(
403
- onError: (error: Error, type: "uncaughtException" | "unhandledRejection") => boolean | void,
404
- ): void {
405
- if (IS_DENO) {
406
- // Intentionally permanent: process-level handlers must persist for the entire runtime
407
- globalThis.addEventListener("error", (event) => {
408
- const error = event.error instanceof Error ? event.error : new Error(String(event.error));
409
- if (onError(error, "uncaughtException")) event.preventDefault();
410
- });
411
-
412
- globalThis.addEventListener("unhandledrejection", (event) => {
413
- const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
414
- if (onError(error, "unhandledRejection")) event.preventDefault();
415
- });
416
-
417
- return;
418
- }
419
-
420
- if (!runtimeProcess) return;
421
-
422
- const handleNodeGlobalError = (
423
- error: Error,
424
- type: "uncaughtException" | "unhandledRejection",
425
- ): void => {
426
- let shouldPreventExit = false;
427
- try {
428
- shouldPreventExit = onError(error, type) === true;
429
- } catch (handlerError) {
430
- const handlerException = handlerError instanceof Error
431
- ? handlerError
432
- : new Error(String(handlerError));
433
- console.error("Global error handler threw while processing", type, handlerException);
434
- }
435
-
436
- if (shouldPreventExit) return;
437
-
438
- // Node/Bun suppress default fatal behavior when a listener is registered.
439
- // If the callback did not explicitly handle the error, exit to preserve
440
- // expected fatal semantics for uncaught exceptions and unhandled rejections.
441
- runtimeProcess.exit(1);
442
- };
443
-
444
- runtimeProcess.on("uncaughtException", (error: Error) => {
445
- handleNodeGlobalError(error, "uncaughtException");
446
- });
447
-
448
- runtimeProcess.on("unhandledRejection", (reason: unknown) => {
449
- const error = reason instanceof Error ? reason : new Error(String(reason));
450
- handleNodeGlobalError(error, "unhandledRejection");
451
- });
452
- }
453
-
454
- /**
455
- * Unreference a timer to prevent it from keeping the process alive
456
- */
457
- export function unrefTimer(timerId: ReturnType<typeof dntShim.setInterval>): void {
458
- if (IS_DENO && typeof dntShim.Deno.unrefTimer === "function") {
459
- dntShim.Deno.unrefTimer(timerId as number);
460
- return;
461
- }
462
-
463
- if (timerId && typeof timerId === "object" && "unref" in timerId) {
464
- (timerId as { unref: () => void }).unref();
465
- }
466
- }
467
-
468
- /**
469
- * Get the executable path of the current runtime
470
- */
471
- export function execPath(): string {
472
- if (IS_DENO) return dntShim.Deno.execPath();
473
- if (runtimeProcess) return runtimeProcess.execPath;
474
- return "";
475
- }
476
-
477
- /**
478
- * Get process uptime in seconds
479
- * Returns OS uptime on Deno, process uptime on Node.js
480
- */
481
- export function uptime(): number {
482
- if (IS_DENO) {
483
- // Deno.osUptime() returns system uptime in seconds
484
- return dntShim.Deno.osUptime?.() ?? 0;
485
- }
486
- if (runtimeProcess) {
487
- // process.uptime() returns process uptime in seconds
488
- return runtimeProcess.uptime?.() ?? 0;
489
- }
490
- return 0;
491
- }
492
-
493
- /**
494
- * Get stdout stream for writing
495
- * Returns null if not available (e.g., in browser/workers)
496
- */
497
- export function getStdout(): { write: (data: string) => void } | null {
498
- if (IS_DENO) {
499
- const encoder = new TextEncoder();
500
- return { write: (data: string) => dntShim.Deno.stdout.writeSync(encoder.encode(data)) };
501
- }
502
- if (runtimeProcess?.stdout) {
503
- return { write: (data: string) => runtimeProcess.stdout.write(data) };
504
- }
505
- return null;
506
- }
507
-
508
- /**
509
- * Write text directly to stdout (sync)
510
- * No-op if stdout is not available
511
- */
512
- export function writeStdout(text: string): void {
513
- getStdout()?.write(text);
514
- }
515
-
516
- /**
517
- * Write data to stdout asynchronously
518
- * Returns a promise that resolves when the write is complete
519
- */
520
- export async function writeStdoutAsync(data: Uint8Array): Promise<number> {
521
- if (IS_DENO) return await dntShim.Deno.stdout.write(data);
522
-
523
- if (runtimeProcess?.stdout) {
524
- return await new Promise((resolve, reject) => {
525
- runtimeProcess.stdout.write(data, (error) => {
526
- if (error) reject(error);
527
- else resolve(data.length);
528
- });
529
- });
530
- }
531
-
532
- return 0;
533
- }
534
-
535
- /**
536
- * Synchronous prompt function that works across Deno and Bun.
537
- * Displays a message and reads user input from stdin.
538
- *
539
- * Note: This relies on globalThis.prompt which is available in Deno and Bun.
540
- * Returns null in environments where prompt is not available (e.g., Node.js ESM).
541
- */
542
- export function promptSync(message?: string): string | null {
543
- if (typeof globalThis.prompt !== "function") return null;
544
- return globalThis.prompt(message ?? "") ?? null;
545
- }
546
-
547
- /**
548
- * Read a single byte from stdin synchronously.
549
- * Requires raw mode to be enabled for character-by-character reading.
550
- * Returns null on EOF or if stdin is not available.
551
- */
552
- export function readStdinByteSync(): number | null {
553
- const buf = new Uint8Array(1);
554
-
555
- if (IS_DENO) {
556
- const n = dntShim.Deno.stdin.readSync(buf);
557
- return n ? buf[0] ?? null : null;
558
- }
559
-
560
- if (IS_BUN) {
561
- // Bun: read one byte from the file descriptor directly
562
- const BunGlobal =
563
- (dntShim.dntGlobalThis as { Bun?: { stdin?: { read?: (n: number) => Uint8Array | null } } })
564
- .Bun;
565
- const chunk = BunGlobal?.stdin?.read?.(1);
566
- if (chunk && chunk.length > 0) {
567
- const first = chunk.at(0);
568
- return first ?? null;
569
- }
570
- return null;
571
- }
572
-
573
- return null;
574
- }
575
-
576
- // ============================================================================
577
- // Command Execution
578
- // ============================================================================
579
-
580
- export interface CommandResult {
581
- success: boolean;
582
- code: number;
583
- stdout?: string;
584
- stderr?: string;
585
- }
586
-
587
- export interface CommandOptions {
588
- args?: string[];
589
- cwd?: string;
590
- env?: Record<string, string>;
591
- /** Capture stdout/stderr to return in result */
592
- capture?: boolean;
593
- /** Inherit stdio from parent process (shows output in terminal) */
594
- inherit?: boolean;
595
- /** Use shell to run the command (needed for .cmd files on Windows) */
596
- shell?: boolean;
597
- /** Kill the command if it exceeds this duration (milliseconds) */
598
- timeoutMs?: number;
599
- }
600
-
601
- const COMMAND_TIMEOUT_EXIT_CODE = 124;
602
- const FORCE_KILL_GRACE_MS = 250;
603
-
604
- function createTimeoutResult(
605
- timeoutMs: number,
606
- stdout?: string,
607
- stderr?: string,
608
- ): CommandResult {
609
- return {
610
- success: false,
611
- code: COMMAND_TIMEOUT_EXIT_CODE,
612
- stdout,
613
- stderr: `${stderr ?? ""}\nCommand timed out after ${timeoutMs}ms`.trim(),
614
- };
615
- }
616
-
617
- function createProcessTimeout(
618
- timeoutMs: number | undefined,
619
- terminate: () => void,
620
- forceTerminate: () => void,
621
- ): { hasTimedOut: () => boolean; clear: () => void } {
622
- let timedOut = false;
623
- let timeoutId: ReturnType<typeof dntShim.setTimeout> | undefined;
624
- let forceKillId: ReturnType<typeof dntShim.setTimeout> | undefined;
625
-
626
- if (timeoutMs && timeoutMs > 0) {
627
- timeoutId = dntShim.setTimeout(() => {
628
- timedOut = true;
629
- try {
630
- terminate();
631
- } catch (_) {
632
- /* expected: best-effort terminate may fail if process already exited */
633
- }
634
-
635
- forceKillId = dntShim.setTimeout(() => {
636
- try {
637
- forceTerminate();
638
- } catch (_) {
639
- /* expected: best-effort force terminate may fail if process already exited */
640
- }
641
- }, FORCE_KILL_GRACE_MS);
642
- }, timeoutMs);
643
- }
644
-
645
- return {
646
- hasTimedOut: () => timedOut,
647
- clear: () => {
648
- if (timeoutId) clearTimeout(timeoutId);
649
- if (forceKillId) clearTimeout(forceKillId);
650
- },
651
- };
652
- }
653
-
654
- async function readStreamToString(stream: ReadableStream<Uint8Array>): Promise<string> {
655
- const reader = stream.getReader();
656
- const chunks: Uint8Array[] = [];
657
-
658
- while (true) {
659
- const { done, value } = await reader.read();
660
- if (done) break;
661
- if (value) chunks.push(value);
662
- }
663
-
664
- const total = chunks.reduce((acc, c) => acc + c.length, 0);
665
- const merged = new Uint8Array(total);
666
- let offset = 0;
667
-
668
- for (const chunk of chunks) {
669
- merged.set(chunk, offset);
670
- offset += chunk.length;
671
- }
672
-
673
- return new TextDecoder().decode(merged);
674
- }
675
-
676
- /**
677
- * Run a command and return the result.
678
- * Works across Deno, Node.js, and Bun.
679
- *
680
- * @param cmd - Command to run
681
- * @param options - Command options
682
- * @param options.capture - Capture stdout/stderr to return in result
683
- * @param options.inherit - Inherit stdio from parent (shows output in terminal)
684
- * @param options.shell - Use shell to run command (needed for .cmd on Windows)
685
- */
686
- export async function runCommand(
687
- cmd: string,
688
- options: CommandOptions = {},
689
- ): Promise<CommandResult> {
690
- const {
691
- args = [],
692
- cwd: cmdCwd,
693
- env: cmdEnv,
694
- capture = false,
695
- inherit = false,
696
- shell = false,
697
- timeoutMs,
698
- } = options;
699
- const effectiveTimeoutMs = timeoutMs && timeoutMs > 0 ? Math.floor(timeoutMs) : undefined;
700
-
701
- // Determine stdio mode: inherit > capture > null
702
- const stdioMode = inherit ? "inherit" : capture ? "piped" : "null";
703
-
704
- if (IS_DENO) {
705
- const command = new dntShim.Deno.Command(cmd, {
706
- args,
707
- cwd: cmdCwd,
708
- env: cmdEnv,
709
- stdin: inherit ? "inherit" : "null",
710
- stdout: stdioMode,
711
- stderr: stdioMode,
712
- });
713
-
714
- const child = command.spawn();
715
- const timeout = createProcessTimeout(
716
- effectiveTimeoutMs,
717
- () => child.kill("SIGTERM"),
718
- () => child.kill("SIGKILL"),
719
- );
720
-
721
- try {
722
- const [status, stdout, stderr] = await Promise.all([
723
- child.status,
724
- capture && child.stdout ? readStreamToString(child.stdout) : Promise.resolve(undefined),
725
- capture && child.stderr ? readStreamToString(child.stderr) : Promise.resolve(undefined),
726
- ]);
727
-
728
- if (timeout.hasTimedOut()) {
729
- return createTimeoutResult(effectiveTimeoutMs ?? 0, stdout, stderr);
730
- }
731
-
732
- return {
733
- success: status.success,
734
- code: status.code,
735
- stdout,
736
- stderr,
737
- };
738
- } finally {
739
- timeout.clear();
740
- }
741
- }
742
-
743
- if (IS_BUN) {
744
- const bunGlobal = dntShim.dntGlobalThis as unknown as {
745
- Bun: {
746
- spawn: (options: {
747
- cmd: string[];
748
- cwd?: string;
749
- env?: Record<string, string>;
750
- stdout?: "pipe" | "inherit" | "ignore";
751
- stderr?: "pipe" | "inherit" | "ignore";
752
- }) => {
753
- exited: Promise<number>;
754
- stdout: ReadableStream<Uint8Array> | null;
755
- stderr: ReadableStream<Uint8Array> | null;
756
- kill?: (signal?: string | number) => void;
757
- };
758
- };
759
- };
760
-
761
- const bunStdio = inherit ? "inherit" : capture ? "pipe" : "ignore";
762
-
763
- const isWindows = isWindowsPlatform();
764
- const bunCmd = shell
765
- ? args.length === 0
766
- ? isWindows ? ["cmd", "/c", cmd] : ["sh", "-c", cmd]
767
- : isWindows
768
- ? ["cmd", "/c", cmd, ...args]
769
- : ["sh", "-c", 'exec "$@"', "sh", cmd, ...args]
770
- : [cmd, ...args];
771
-
772
- const proc = bunGlobal.Bun.spawn({
773
- cmd: bunCmd,
774
- cwd: cmdCwd,
775
- env: cmdEnv,
776
- stdout: bunStdio,
777
- stderr: bunStdio,
778
- });
779
-
780
- const timeout = createProcessTimeout(
781
- effectiveTimeoutMs,
782
- () => proc.kill?.("SIGTERM"),
783
- () => proc.kill?.("SIGKILL"),
784
- );
785
-
786
- try {
787
- const [code, stdout, stderr] = await Promise.all([
788
- proc.exited,
789
- capture && proc.stdout ? readStreamToString(proc.stdout) : Promise.resolve(undefined),
790
- capture && proc.stderr ? readStreamToString(proc.stderr) : Promise.resolve(undefined),
791
- ]);
792
-
793
- if (timeout.hasTimedOut()) {
794
- return createTimeoutResult(effectiveTimeoutMs ?? 0, stdout, stderr);
795
- }
796
-
797
- return { success: code === 0, code, stdout, stderr };
798
- } finally {
799
- timeout.clear();
800
- }
801
- }
802
-
803
- if (!runtimeProcess) return { success: false, code: 1 };
804
-
805
- const { spawn } = await dynamicImport<typeof import("node:child_process")>("node:child_process");
806
-
807
- const nodeStdio: [
808
- "ignore" | "inherit" | "pipe",
809
- "ignore" | "inherit" | "pipe",
810
- "ignore" | "inherit" | "pipe",
811
- ] = inherit
812
- ? ["inherit", "inherit", "inherit"]
813
- : capture
814
- ? ["ignore", "pipe", "pipe"]
815
- : ["ignore", "ignore", "ignore"];
816
-
817
- return await new Promise((resolve) => {
818
- const child = spawn(cmd, args, {
819
- cwd: cmdCwd,
820
- env: cmdEnv ? { ...runtimeProcess.env, ...cmdEnv } : undefined,
821
- stdio: nodeStdio,
822
- shell,
823
- });
824
-
825
- let stdout = "";
826
- let stderr = "";
827
- const decoder = new TextDecoder();
828
- const timeout = createProcessTimeout(
829
- effectiveTimeoutMs,
830
- () => child.kill("SIGTERM"),
831
- () => child.kill("SIGKILL"),
832
- );
833
-
834
- if (capture) {
835
- child.stdout?.on("data", (data: Uint8Array) => {
836
- stdout += decoder.decode(data);
837
- });
838
- child.stderr?.on("data", (data: Uint8Array) => {
839
- stderr += decoder.decode(data);
840
- });
841
- }
842
-
843
- child.on("close", (code) => {
844
- timeout.clear();
845
-
846
- if (timeout.hasTimedOut()) {
847
- resolve(
848
- createTimeoutResult(
849
- effectiveTimeoutMs ?? 0,
850
- capture ? stdout : undefined,
851
- capture ? stderr : undefined,
852
- ),
853
- );
854
- return;
855
- }
856
-
857
- resolve({
858
- success: code === 0,
859
- code: code ?? 1,
860
- stdout: capture ? stdout : undefined,
861
- stderr: capture ? stderr : undefined,
862
- });
863
- });
864
-
865
- child.on("error", () => {
866
- timeout.clear();
867
- resolve({ success: false, code: 1 });
868
- });
869
- });
870
- }
1
+ export {
2
+ deleteEnv,
3
+ env,
4
+ type EnvBooleanOptions,
5
+ getEnv,
6
+ getEnvBoolean,
7
+ getEnvNumber,
8
+ getEnvOverlayStorage,
9
+ getEnvString,
10
+ getHostEnv,
11
+ setEnv,
12
+ } from "./process/env.js";
13
+ export {
14
+ chdir,
15
+ cwd,
16
+ execPath,
17
+ exit,
18
+ getArgs,
19
+ getOsType,
20
+ getRuntimeVersion,
21
+ getStdout,
22
+ getTerminalSize,
23
+ isInteractive,
24
+ isStdoutTTY,
25
+ memoryUsage,
26
+ onGlobalError,
27
+ onSignal,
28
+ pid,
29
+ promptSync,
30
+ readStdinByteSync,
31
+ unrefTimer,
32
+ uptime,
33
+ writeStdout,
34
+ writeStdoutAsync,
35
+ } from "./process/lifecycle.js";
36
+ export { testHasRuntimeProcess } from "./process/runtime-process.js";
37
+ export { type CommandOptions, type CommandResult, runCommand } from "./process/command.js";