@bolt-foundry/gambit 0.8.3 → 0.8.5-rc.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 (289) hide show
  1. package/CHANGELOG.md +38 -2
  2. package/README.md +79 -16
  3. package/esm/_dnt.polyfills.d.ts +17 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -1
  5. package/esm/_dnt.polyfills.js +122 -0
  6. package/esm/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts +322 -0
  7. package/esm/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts.map +1 -0
  8. package/esm/deps/jsr.io/@std/collections/1.1.5/deep_merge.js +105 -0
  9. package/esm/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts +14 -0
  10. package/esm/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.js +34 -0
  12. package/esm/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts +13 -0
  13. package/esm/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts.map +1 -0
  14. package/esm/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.js +18 -0
  15. package/esm/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts +10 -0
  16. package/esm/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts.map +1 -0
  17. package/esm/deps/jsr.io/@std/fs/1.0.22/_is_same_path.js +17 -0
  18. package/esm/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts +12 -0
  19. package/esm/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts.map +1 -0
  20. package/esm/deps/jsr.io/@std/fs/1.0.22/_is_subdir.js +25 -0
  21. package/esm/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts +9 -0
  22. package/esm/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts.map +1 -0
  23. package/esm/deps/jsr.io/@std/fs/1.0.22/_to_path_string.js +13 -0
  24. package/esm/deps/jsr.io/@std/fs/1.0.22/copy.d.ts +117 -0
  25. package/esm/deps/jsr.io/@std/fs/1.0.22/copy.d.ts.map +1 -0
  26. package/esm/deps/jsr.io/@std/fs/1.0.22/copy.js +313 -0
  27. package/esm/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts +48 -0
  28. package/esm/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts.map +1 -0
  29. package/esm/deps/jsr.io/@std/fs/1.0.22/empty_dir.js +87 -0
  30. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts +49 -0
  31. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts.map +1 -0
  32. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_dir.js +102 -0
  33. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts +47 -0
  34. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts.map +1 -0
  35. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_file.js +90 -0
  36. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts +49 -0
  37. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts.map +1 -0
  38. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_link.js +61 -0
  39. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts +70 -0
  40. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts.map +1 -0
  41. package/esm/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.js +156 -0
  42. package/esm/deps/jsr.io/@std/fs/1.0.22/eol.d.ts +52 -0
  43. package/esm/deps/jsr.io/@std/fs/1.0.22/eol.d.ts.map +1 -0
  44. package/esm/deps/jsr.io/@std/fs/1.0.22/eol.js +67 -0
  45. package/esm/deps/jsr.io/@std/fs/1.0.22/exists.d.ts +218 -0
  46. package/esm/deps/jsr.io/@std/fs/1.0.22/exists.d.ts.map +1 -0
  47. package/esm/deps/jsr.io/@std/fs/1.0.22/exists.js +271 -0
  48. package/esm/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts +267 -0
  49. package/esm/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts.map +1 -0
  50. package/esm/deps/jsr.io/@std/fs/1.0.22/expand_glob.js +442 -0
  51. package/esm/deps/jsr.io/@std/fs/1.0.22/mod.d.ts +29 -0
  52. package/esm/deps/jsr.io/@std/fs/1.0.22/mod.d.ts.map +1 -0
  53. package/esm/deps/jsr.io/@std/fs/1.0.22/mod.js +29 -0
  54. package/esm/deps/jsr.io/@std/fs/1.0.22/move.d.ts +86 -0
  55. package/esm/deps/jsr.io/@std/fs/1.0.22/move.d.ts.map +1 -0
  56. package/esm/deps/jsr.io/@std/fs/1.0.22/move.js +142 -0
  57. package/esm/deps/jsr.io/@std/fs/1.0.22/walk.d.ts +777 -0
  58. package/esm/deps/jsr.io/@std/fs/1.0.22/walk.d.ts.map +1 -0
  59. package/esm/deps/jsr.io/@std/fs/1.0.22/walk.js +846 -0
  60. package/esm/deps/jsr.io/@std/json/1.0.2/types.d.ts +5 -0
  61. package/esm/deps/jsr.io/@std/json/1.0.2/types.d.ts.map +1 -0
  62. package/esm/deps/jsr.io/@std/json/1.0.2/types.js +3 -0
  63. package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts +20 -0
  64. package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts.map +1 -0
  65. package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.js +21 -0
  66. package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts +21 -0
  67. package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts.map +1 -0
  68. package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.js +320 -0
  69. package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts +93 -0
  70. package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts.map +1 -0
  71. package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.js +753 -0
  72. package/esm/deps/jsr.io/@std/toml/1.0.11/mod.d.ts +109 -0
  73. package/esm/deps/jsr.io/@std/toml/1.0.11/mod.d.ts.map +1 -0
  74. package/esm/deps/jsr.io/@std/toml/1.0.11/mod.js +110 -0
  75. package/esm/deps/jsr.io/@std/toml/1.0.11/parse.d.ts +21 -0
  76. package/esm/deps/jsr.io/@std/toml/1.0.11/parse.d.ts.map +1 -0
  77. package/esm/deps/jsr.io/@std/toml/1.0.11/parse.js +25 -0
  78. package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts +35 -0
  79. package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts.map +1 -0
  80. package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.js +283 -0
  81. package/esm/gambit/simulator-ui/dist/bundle.js +10639 -4629
  82. package/esm/gambit/simulator-ui/dist/bundle.js.map +4 -4
  83. package/esm/mod.d.ts +13 -3
  84. package/esm/mod.d.ts.map +1 -1
  85. package/esm/mod.js +8 -2
  86. package/esm/src/cli_utils.d.ts +1 -0
  87. package/esm/src/cli_utils.d.ts.map +1 -1
  88. package/esm/src/cli_utils.js +13 -1
  89. package/esm/src/default_runtime.d.ts +46 -0
  90. package/esm/src/default_runtime.d.ts.map +1 -0
  91. package/esm/src/default_runtime.js +415 -0
  92. package/esm/src/durable_streams.js +26 -1
  93. package/esm/src/model_matchers.d.ts +10 -0
  94. package/esm/src/model_matchers.d.ts.map +1 -0
  95. package/esm/src/model_matchers.js +26 -0
  96. package/esm/src/openai_compat.d.ts +12 -1
  97. package/esm/src/openai_compat.d.ts.map +1 -1
  98. package/esm/src/openai_compat.js +53 -1
  99. package/esm/src/project_config.d.ts +47 -0
  100. package/esm/src/project_config.d.ts.map +1 -0
  101. package/esm/src/project_config.js +134 -0
  102. package/esm/src/providers/codex.d.ts +37 -0
  103. package/esm/src/providers/codex.d.ts.map +1 -0
  104. package/esm/src/providers/codex.js +810 -0
  105. package/esm/src/providers/google.d.ts +3 -1
  106. package/esm/src/providers/google.d.ts.map +1 -1
  107. package/esm/src/providers/google.js +82 -6
  108. package/esm/src/providers/ollama.d.ts +3 -1
  109. package/esm/src/providers/ollama.d.ts.map +1 -1
  110. package/esm/src/providers/ollama.js +238 -15
  111. package/esm/src/providers/openrouter.d.ts +6 -2
  112. package/esm/src/providers/openrouter.d.ts.map +1 -1
  113. package/esm/src/providers/openrouter.js +260 -23
  114. package/esm/src/providers/router.d.ts +19 -0
  115. package/esm/src/providers/router.d.ts.map +1 -0
  116. package/esm/src/providers/router.js +93 -0
  117. package/esm/src/server.d.ts +9 -0
  118. package/esm/src/server.d.ts.map +1 -1
  119. package/esm/src/server.js +3186 -652
  120. package/esm/src/server_feedback_grading_routes.d.ts +32 -0
  121. package/esm/src/server_feedback_grading_routes.d.ts.map +1 -0
  122. package/esm/src/server_feedback_grading_routes.js +305 -0
  123. package/esm/src/server_helpers.d.ts +4 -0
  124. package/esm/src/server_helpers.d.ts.map +1 -0
  125. package/esm/src/server_helpers.js +46 -0
  126. package/esm/src/server_session_store.d.ts +87 -0
  127. package/esm/src/server_session_store.d.ts.map +1 -0
  128. package/esm/src/server_session_store.js +873 -0
  129. package/esm/src/server_types.d.ts +110 -0
  130. package/esm/src/server_types.d.ts.map +1 -0
  131. package/esm/src/server_types.js +1 -0
  132. package/esm/src/server_ui_routes.d.ts +33 -0
  133. package/esm/src/server_ui_routes.d.ts.map +1 -0
  134. package/esm/src/server_ui_routes.js +135 -0
  135. package/esm/src/session_artifacts.d.ts +22 -0
  136. package/esm/src/session_artifacts.d.ts.map +1 -0
  137. package/esm/src/session_artifacts.js +243 -0
  138. package/esm/src/trace.d.ts.map +1 -1
  139. package/esm/src/trace.js +6 -3
  140. package/esm/src/workspace.d.ts +19 -0
  141. package/esm/src/workspace.d.ts.map +1 -0
  142. package/esm/src/workspace.js +164 -0
  143. package/esm/src/workspace_contract.d.ts +76 -0
  144. package/esm/src/workspace_contract.d.ts.map +1 -0
  145. package/esm/src/workspace_contract.js +74 -0
  146. package/package.json +2 -2
  147. package/script/_dnt.polyfills.d.ts +17 -0
  148. package/script/_dnt.polyfills.d.ts.map +1 -1
  149. package/script/_dnt.polyfills.js +122 -0
  150. package/script/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts +322 -0
  151. package/script/deps/jsr.io/@std/collections/1.1.5/deep_merge.d.ts.map +1 -0
  152. package/script/deps/jsr.io/@std/collections/1.1.5/deep_merge.js +108 -0
  153. package/script/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts +14 -0
  154. package/script/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.d.ts.map +1 -0
  155. package/script/deps/jsr.io/@std/fs/1.0.22/_create_walk_entry.js +71 -0
  156. package/script/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts +13 -0
  157. package/script/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.d.ts.map +1 -0
  158. package/script/deps/jsr.io/@std/fs/1.0.22/_get_file_info_type.js +21 -0
  159. package/script/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts +10 -0
  160. package/script/deps/jsr.io/@std/fs/1.0.22/_is_same_path.d.ts.map +1 -0
  161. package/script/deps/jsr.io/@std/fs/1.0.22/_is_same_path.js +20 -0
  162. package/script/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts +12 -0
  163. package/script/deps/jsr.io/@std/fs/1.0.22/_is_subdir.d.ts.map +1 -0
  164. package/script/deps/jsr.io/@std/fs/1.0.22/_is_subdir.js +28 -0
  165. package/script/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts +9 -0
  166. package/script/deps/jsr.io/@std/fs/1.0.22/_to_path_string.d.ts.map +1 -0
  167. package/script/deps/jsr.io/@std/fs/1.0.22/_to_path_string.js +16 -0
  168. package/script/deps/jsr.io/@std/fs/1.0.22/copy.d.ts +117 -0
  169. package/script/deps/jsr.io/@std/fs/1.0.22/copy.d.ts.map +1 -0
  170. package/script/deps/jsr.io/@std/fs/1.0.22/copy.js +350 -0
  171. package/script/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts +48 -0
  172. package/script/deps/jsr.io/@std/fs/1.0.22/empty_dir.d.ts.map +1 -0
  173. package/script/deps/jsr.io/@std/fs/1.0.22/empty_dir.js +124 -0
  174. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts +49 -0
  175. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_dir.d.ts.map +1 -0
  176. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_dir.js +139 -0
  177. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts +47 -0
  178. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_file.d.ts.map +1 -0
  179. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_file.js +127 -0
  180. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts +49 -0
  181. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_link.d.ts.map +1 -0
  182. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_link.js +98 -0
  183. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts +70 -0
  184. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.d.ts.map +1 -0
  185. package/script/deps/jsr.io/@std/fs/1.0.22/ensure_symlink.js +193 -0
  186. package/script/deps/jsr.io/@std/fs/1.0.22/eol.d.ts +52 -0
  187. package/script/deps/jsr.io/@std/fs/1.0.22/eol.d.ts.map +1 -0
  188. package/script/deps/jsr.io/@std/fs/1.0.22/eol.js +105 -0
  189. package/script/deps/jsr.io/@std/fs/1.0.22/exists.d.ts +218 -0
  190. package/script/deps/jsr.io/@std/fs/1.0.22/exists.d.ts.map +1 -0
  191. package/script/deps/jsr.io/@std/fs/1.0.22/exists.js +308 -0
  192. package/script/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts +267 -0
  193. package/script/deps/jsr.io/@std/fs/1.0.22/expand_glob.d.ts.map +1 -0
  194. package/script/deps/jsr.io/@std/fs/1.0.22/expand_glob.js +479 -0
  195. package/script/deps/jsr.io/@std/fs/1.0.22/mod.d.ts +29 -0
  196. package/script/deps/jsr.io/@std/fs/1.0.22/mod.d.ts.map +1 -0
  197. package/script/deps/jsr.io/@std/fs/1.0.22/mod.js +45 -0
  198. package/script/deps/jsr.io/@std/fs/1.0.22/move.d.ts +86 -0
  199. package/script/deps/jsr.io/@std/fs/1.0.22/move.d.ts.map +1 -0
  200. package/script/deps/jsr.io/@std/fs/1.0.22/move.js +179 -0
  201. package/script/deps/jsr.io/@std/fs/1.0.22/walk.d.ts +777 -0
  202. package/script/deps/jsr.io/@std/fs/1.0.22/walk.d.ts.map +1 -0
  203. package/script/deps/jsr.io/@std/fs/1.0.22/walk.js +883 -0
  204. package/script/deps/jsr.io/@std/json/1.0.2/types.d.ts +5 -0
  205. package/script/deps/jsr.io/@std/json/1.0.2/types.d.ts.map +1 -0
  206. package/script/deps/jsr.io/@std/json/1.0.2/types.js +4 -0
  207. package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts +20 -0
  208. package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts.map +1 -0
  209. package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.js +37 -0
  210. package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts +21 -0
  211. package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts.map +1 -0
  212. package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.js +323 -0
  213. package/script/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts +93 -0
  214. package/script/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts.map +1 -0
  215. package/script/deps/jsr.io/@std/toml/1.0.11/_parser.js +781 -0
  216. package/script/deps/jsr.io/@std/toml/1.0.11/mod.d.ts +109 -0
  217. package/script/deps/jsr.io/@std/toml/1.0.11/mod.d.ts.map +1 -0
  218. package/script/deps/jsr.io/@std/toml/1.0.11/mod.js +126 -0
  219. package/script/deps/jsr.io/@std/toml/1.0.11/parse.d.ts +21 -0
  220. package/script/deps/jsr.io/@std/toml/1.0.11/parse.d.ts.map +1 -0
  221. package/script/deps/jsr.io/@std/toml/1.0.11/parse.js +28 -0
  222. package/script/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts +35 -0
  223. package/script/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts.map +1 -0
  224. package/script/deps/jsr.io/@std/toml/1.0.11/stringify.js +286 -0
  225. package/script/gambit/simulator-ui/dist/bundle.js +10639 -4629
  226. package/script/gambit/simulator-ui/dist/bundle.js.map +4 -4
  227. package/script/mod.d.ts +13 -3
  228. package/script/mod.d.ts.map +1 -1
  229. package/script/mod.js +14 -5
  230. package/script/src/cli_utils.d.ts +1 -0
  231. package/script/src/cli_utils.d.ts.map +1 -1
  232. package/script/src/cli_utils.js +14 -1
  233. package/script/src/default_runtime.d.ts +46 -0
  234. package/script/src/default_runtime.d.ts.map +1 -0
  235. package/script/src/default_runtime.js +452 -0
  236. package/script/src/durable_streams.js +26 -1
  237. package/script/src/model_matchers.d.ts +10 -0
  238. package/script/src/model_matchers.d.ts.map +1 -0
  239. package/script/src/model_matchers.js +29 -0
  240. package/script/src/openai_compat.d.ts +12 -1
  241. package/script/src/openai_compat.d.ts.map +1 -1
  242. package/script/src/openai_compat.js +85 -0
  243. package/script/src/project_config.d.ts +47 -0
  244. package/script/src/project_config.d.ts.map +1 -0
  245. package/script/src/project_config.js +173 -0
  246. package/script/src/providers/codex.d.ts +37 -0
  247. package/script/src/providers/codex.d.ts.map +1 -0
  248. package/script/src/providers/codex.js +850 -0
  249. package/script/src/providers/google.d.ts +3 -1
  250. package/script/src/providers/google.d.ts.map +1 -1
  251. package/script/src/providers/google.js +82 -6
  252. package/script/src/providers/ollama.d.ts +3 -1
  253. package/script/src/providers/ollama.d.ts.map +1 -1
  254. package/script/src/providers/ollama.js +238 -15
  255. package/script/src/providers/openrouter.d.ts +6 -2
  256. package/script/src/providers/openrouter.d.ts.map +1 -1
  257. package/script/src/providers/openrouter.js +260 -23
  258. package/script/src/providers/router.d.ts +19 -0
  259. package/script/src/providers/router.d.ts.map +1 -0
  260. package/script/src/providers/router.js +96 -0
  261. package/script/src/server.d.ts +9 -0
  262. package/script/src/server.d.ts.map +1 -1
  263. package/script/src/server.js +3193 -659
  264. package/script/src/server_feedback_grading_routes.d.ts +32 -0
  265. package/script/src/server_feedback_grading_routes.d.ts.map +1 -0
  266. package/script/src/server_feedback_grading_routes.js +343 -0
  267. package/script/src/server_helpers.d.ts +4 -0
  268. package/script/src/server_helpers.d.ts.map +1 -0
  269. package/script/src/server_helpers.js +84 -0
  270. package/script/src/server_session_store.d.ts +87 -0
  271. package/script/src/server_session_store.d.ts.map +1 -0
  272. package/script/src/server_session_store.js +910 -0
  273. package/script/src/server_types.d.ts +110 -0
  274. package/script/src/server_types.d.ts.map +1 -0
  275. package/script/src/server_types.js +2 -0
  276. package/script/src/server_ui_routes.d.ts +33 -0
  277. package/script/src/server_ui_routes.d.ts.map +1 -0
  278. package/script/src/server_ui_routes.js +172 -0
  279. package/script/src/session_artifacts.d.ts +22 -0
  280. package/script/src/session_artifacts.d.ts.map +1 -0
  281. package/script/src/session_artifacts.js +279 -0
  282. package/script/src/trace.d.ts.map +1 -1
  283. package/script/src/trace.js +6 -3
  284. package/script/src/workspace.d.ts +19 -0
  285. package/script/src/workspace.d.ts.map +1 -0
  286. package/script/src/workspace.js +201 -0
  287. package/script/src/workspace_contract.d.ts +76 -0
  288. package/script/src/workspace_contract.d.ts.map +1 -0
  289. package/script/src/workspace_contract.js +82 -0
@@ -0,0 +1,313 @@
1
+ // Copyright 2018-2026 the Deno authors. MIT license.
2
+ import * as dntShim from "../../../../../_dnt.shims.js";
3
+ import { basename } from "../../path/1.1.4/basename.js";
4
+ import { join } from "../../path/1.1.4/join.js";
5
+ import { resolve } from "../../path/1.1.4/resolve.js";
6
+ import { ensureDir, ensureDirSync } from "./ensure_dir.js";
7
+ import { getFileInfoType } from "./_get_file_info_type.js";
8
+ import { toPathString } from "./_to_path_string.js";
9
+ import { isSubdir } from "./_is_subdir.js";
10
+ import { isWindows } from "../../internal/1.0.12/os.js";
11
+ function assertIsDate(date, name) {
12
+ if (date === null) {
13
+ throw new Error(`${name} is unavailable`);
14
+ }
15
+ }
16
+ async function ensureValidCopy(src, dest, options) {
17
+ let destStat;
18
+ try {
19
+ destStat = await dntShim.Deno.lstat(dest);
20
+ }
21
+ catch (err) {
22
+ if (err instanceof dntShim.Deno.errors.NotFound) {
23
+ return;
24
+ }
25
+ throw err;
26
+ }
27
+ if (options.isFolder && !destStat.isDirectory) {
28
+ throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'`);
29
+ }
30
+ if (!options.overwrite) {
31
+ throw new dntShim.Deno.errors.AlreadyExists(`'${dest}' already exists.`);
32
+ }
33
+ return destStat;
34
+ }
35
+ function ensureValidCopySync(src, dest, options) {
36
+ let destStat;
37
+ try {
38
+ destStat = dntShim.Deno.lstatSync(dest);
39
+ }
40
+ catch (err) {
41
+ if (err instanceof dntShim.Deno.errors.NotFound) {
42
+ return;
43
+ }
44
+ throw err;
45
+ }
46
+ if (options.isFolder && !destStat.isDirectory) {
47
+ throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'`);
48
+ }
49
+ if (!options.overwrite) {
50
+ throw new dntShim.Deno.errors.AlreadyExists(`'${dest}' already exists`);
51
+ }
52
+ return destStat;
53
+ }
54
+ /* copy file to dest */
55
+ async function copyFile(src, dest, options) {
56
+ await ensureValidCopy(src, dest, options);
57
+ await dntShim.Deno.copyFile(src, dest);
58
+ if (options.preserveTimestamps) {
59
+ const statInfo = await dntShim.Deno.stat(src);
60
+ assertIsDate(statInfo.atime, "statInfo.atime");
61
+ assertIsDate(statInfo.mtime, "statInfo.mtime");
62
+ await dntShim.Deno.utime(dest, statInfo.atime, statInfo.mtime);
63
+ }
64
+ }
65
+ /* copy file to dest synchronously */
66
+ function copyFileSync(src, dest, options) {
67
+ ensureValidCopySync(src, dest, options);
68
+ dntShim.Deno.copyFileSync(src, dest);
69
+ if (options.preserveTimestamps) {
70
+ const statInfo = dntShim.Deno.statSync(src);
71
+ assertIsDate(statInfo.atime, "statInfo.atime");
72
+ assertIsDate(statInfo.mtime, "statInfo.mtime");
73
+ dntShim.Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
74
+ }
75
+ }
76
+ /* copy symlink to dest */
77
+ async function copySymLink(src, dest, options) {
78
+ await ensureValidCopy(src, dest, options);
79
+ const originSrcFilePath = await dntShim.Deno.readLink(src);
80
+ const type = getFileInfoType(await dntShim.Deno.lstat(src));
81
+ if (isWindows) {
82
+ await dntShim.Deno.symlink(originSrcFilePath, dest, {
83
+ type: type === "dir" ? "dir" : "file",
84
+ });
85
+ }
86
+ else {
87
+ await dntShim.Deno.symlink(originSrcFilePath, dest);
88
+ }
89
+ if (options.preserveTimestamps) {
90
+ const statInfo = await dntShim.Deno.lstat(src);
91
+ assertIsDate(statInfo.atime, "statInfo.atime");
92
+ assertIsDate(statInfo.mtime, "statInfo.mtime");
93
+ await dntShim.Deno.utime(dest, statInfo.atime, statInfo.mtime);
94
+ }
95
+ }
96
+ /* copy symlink to dest synchronously */
97
+ function copySymlinkSync(src, dest, options) {
98
+ ensureValidCopySync(src, dest, options);
99
+ const originSrcFilePath = dntShim.Deno.readLinkSync(src);
100
+ const type = getFileInfoType(dntShim.Deno.lstatSync(src));
101
+ if (isWindows) {
102
+ dntShim.Deno.symlinkSync(originSrcFilePath, dest, {
103
+ type: type === "dir" ? "dir" : "file",
104
+ });
105
+ }
106
+ else {
107
+ dntShim.Deno.symlinkSync(originSrcFilePath, dest);
108
+ }
109
+ if (options.preserveTimestamps) {
110
+ const statInfo = dntShim.Deno.lstatSync(src);
111
+ assertIsDate(statInfo.atime, "statInfo.atime");
112
+ assertIsDate(statInfo.mtime, "statInfo.mtime");
113
+ dntShim.Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
114
+ }
115
+ }
116
+ /* copy folder from src to dest. */
117
+ async function copyDir(src, dest, options) {
118
+ const destStat = await ensureValidCopy(src, dest, {
119
+ ...options,
120
+ isFolder: true,
121
+ });
122
+ if (!destStat) {
123
+ await ensureDir(dest);
124
+ }
125
+ if (options.preserveTimestamps) {
126
+ const srcStatInfo = await dntShim.Deno.stat(src);
127
+ assertIsDate(srcStatInfo.atime, "statInfo.atime");
128
+ assertIsDate(srcStatInfo.mtime, "statInfo.mtime");
129
+ await dntShim.Deno.utime(dest, srcStatInfo.atime, srcStatInfo.mtime);
130
+ }
131
+ src = toPathString(src);
132
+ dest = toPathString(dest);
133
+ const promises = [];
134
+ for await (const entry of dntShim.Deno.readDir(src)) {
135
+ const srcPath = join(src, entry.name);
136
+ const destPath = join(dest, basename(srcPath));
137
+ if (entry.isSymlink) {
138
+ promises.push(copySymLink(srcPath, destPath, options));
139
+ }
140
+ else if (entry.isDirectory) {
141
+ promises.push(copyDir(srcPath, destPath, options));
142
+ }
143
+ else if (entry.isFile) {
144
+ promises.push(copyFile(srcPath, destPath, options));
145
+ }
146
+ }
147
+ await Promise.all(promises);
148
+ }
149
+ /* copy folder from src to dest synchronously */
150
+ function copyDirSync(src, dest, options) {
151
+ const destStat = ensureValidCopySync(src, dest, {
152
+ ...options,
153
+ isFolder: true,
154
+ });
155
+ if (!destStat) {
156
+ ensureDirSync(dest);
157
+ }
158
+ if (options.preserveTimestamps) {
159
+ const srcStatInfo = dntShim.Deno.statSync(src);
160
+ assertIsDate(srcStatInfo.atime, "statInfo.atime");
161
+ assertIsDate(srcStatInfo.mtime, "statInfo.mtime");
162
+ dntShim.Deno.utimeSync(dest, srcStatInfo.atime, srcStatInfo.mtime);
163
+ }
164
+ src = toPathString(src);
165
+ dest = toPathString(dest);
166
+ for (const entry of dntShim.Deno.readDirSync(src)) {
167
+ const srcPath = join(src, entry.name);
168
+ const destPath = join(dest, basename(srcPath));
169
+ if (entry.isSymlink) {
170
+ copySymlinkSync(srcPath, destPath, options);
171
+ }
172
+ else if (entry.isDirectory) {
173
+ copyDirSync(srcPath, destPath, options);
174
+ }
175
+ else if (entry.isFile) {
176
+ copyFileSync(srcPath, destPath, options);
177
+ }
178
+ }
179
+ }
180
+ /**
181
+ * Asynchronously copy a file or directory (along with its contents), like
182
+ * {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=c-cp-command#cp__cp_flagr | cp -r}.
183
+ *
184
+ * Both `src` and `dest` must both be a file or directory.
185
+ *
186
+ * Requires `--allow-read` and `--allow-write` permissions.
187
+ *
188
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
189
+ * for more information on Deno's permissions system.
190
+ *
191
+ * @param src The source file/directory path as a string or URL.
192
+ * @param dest The destination file/directory path as a string or URL.
193
+ * @param options Options for copying.
194
+ *
195
+ * @returns A promise that resolves once the copy operation completes.
196
+ *
197
+ * @example Basic usage
198
+ * ```ts ignore
199
+ * import { copy } from "@std/fs/copy";
200
+ *
201
+ * await copy("./foo", "./bar");
202
+ * ```
203
+ *
204
+ * This will copy the file or directory at `./foo` to `./bar` without
205
+ * overwriting.
206
+ *
207
+ * @example Overwriting files/directories
208
+ * ```ts ignore
209
+ * import { copy } from "@std/fs/copy";
210
+ *
211
+ * await copy("./foo", "./bar", { overwrite: true });
212
+ * ```
213
+ *
214
+ * This will copy the file or directory at `./foo` to `./bar` and overwrite
215
+ * any existing files or directories.
216
+ *
217
+ * @example Preserving timestamps
218
+ * ```ts ignore
219
+ * import { copy } from "@std/fs/copy";
220
+ *
221
+ * await copy("./foo", "./bar", { preserveTimestamps: true });
222
+ * ```
223
+ *
224
+ * This will copy the file or directory at `./foo` to `./bar` and set the
225
+ * last modification and access times to the ones of the original source files.
226
+ */
227
+ export async function copy(src, dest, options = {}) {
228
+ src = resolve(toPathString(src));
229
+ dest = resolve(toPathString(dest));
230
+ if (src === dest) {
231
+ throw new Error("Source and destination cannot be the same");
232
+ }
233
+ const srcStat = await dntShim.Deno.lstat(src);
234
+ if (srcStat.isDirectory && isSubdir(src, dest)) {
235
+ throw new Error(`Cannot copy '${src}' to a subdirectory of itself: '${dest}'`);
236
+ }
237
+ if (srcStat.isSymlink) {
238
+ await copySymLink(src, dest, options);
239
+ }
240
+ else if (srcStat.isDirectory) {
241
+ await copyDir(src, dest, options);
242
+ }
243
+ else if (srcStat.isFile) {
244
+ await copyFile(src, dest, options);
245
+ }
246
+ }
247
+ /**
248
+ * Synchronously copy a file or directory (along with its contents), like
249
+ * {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=c-cp-command#cp__cp_flagr | cp -r}.
250
+ *
251
+ * Both `src` and `dest` must both be a file or directory.
252
+ *
253
+ * Requires `--allow-read` and `--allow-write` permissions.
254
+ *
255
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
256
+ * for more information on Deno's permissions system.
257
+ *
258
+ * @param src The source file/directory path as a string or URL.
259
+ * @param dest The destination file/directory path as a string or URL.
260
+ * @param options Options for copying.
261
+ *
262
+ * @returns A void value that returns once the copy operation completes.
263
+ *
264
+ * @example Basic usage
265
+ * ```ts ignore
266
+ * import { copySync } from "@std/fs/copy";
267
+ *
268
+ * copySync("./foo", "./bar");
269
+ * ```
270
+ *
271
+ * This will copy the file or directory at `./foo` to `./bar` without
272
+ * overwriting.
273
+ *
274
+ * @example Overwriting files/directories
275
+ * ```ts ignore
276
+ * import { copySync } from "@std/fs/copy";
277
+ *
278
+ * copySync("./foo", "./bar", { overwrite: true });
279
+ * ```
280
+ *
281
+ * This will copy the file or directory at `./foo` to `./bar` and overwrite
282
+ * any existing files or directories.
283
+ *
284
+ * @example Preserving timestamps
285
+ * ```ts ignore
286
+ * import { copySync } from "@std/fs/copy";
287
+ *
288
+ * copySync("./foo", "./bar", { preserveTimestamps: true });
289
+ * ```
290
+ *
291
+ * This will copy the file or directory at `./foo` to `./bar` and set the
292
+ * last modification and access times to the ones of the original source files.
293
+ */
294
+ export function copySync(src, dest, options = {}) {
295
+ src = resolve(toPathString(src));
296
+ dest = resolve(toPathString(dest));
297
+ if (src === dest) {
298
+ throw new Error("Source and destination cannot be the same");
299
+ }
300
+ const srcStat = dntShim.Deno.lstatSync(src);
301
+ if (srcStat.isDirectory && isSubdir(src, dest)) {
302
+ throw new Error(`Cannot copy '${src}' to a subdirectory of itself: '${dest}'`);
303
+ }
304
+ if (srcStat.isSymlink) {
305
+ copySymlinkSync(src, dest, options);
306
+ }
307
+ else if (srcStat.isDirectory) {
308
+ copyDirSync(src, dest, options);
309
+ }
310
+ else if (srcStat.isFile) {
311
+ copyFileSync(src, dest, options);
312
+ }
313
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Asynchronously ensures that a directory is empty.
3
+ *
4
+ * If the directory does not exist, it is created. The directory itself is not
5
+ * deleted.
6
+ *
7
+ * Requires `--allow-read` and `--allow-write` permissions.
8
+ *
9
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
10
+ * for more information on Deno's permissions system.
11
+ *
12
+ * @param dir The path of the directory to empty, as a string or URL.
13
+ *
14
+ * @returns A void promise that resolves once the directory is empty.
15
+ *
16
+ * @example Usage
17
+ * ```ts ignore
18
+ * import { emptyDir } from "@std/fs/empty-dir";
19
+ *
20
+ * await emptyDir("./foo");
21
+ * ```
22
+ */
23
+ export declare function emptyDir(dir: string | URL): Promise<void>;
24
+ /**
25
+ * Synchronously ensures that a directory is empty deletes the directory
26
+ * contents it is not empty.
27
+ *
28
+ * If the directory does not exist, it is created. The directory itself is not
29
+ * deleted.
30
+ *
31
+ * Requires `--allow-read` and `--allow-write` permissions.
32
+ *
33
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
34
+ * for more information on Deno's permissions system.
35
+ *
36
+ * @param dir The path of the directory to empty, as a string or URL.
37
+ *
38
+ * @returns A void value that returns once the directory is empty.
39
+ *
40
+ * @example Usage
41
+ * ```ts ignore
42
+ * import { emptyDirSync } from "@std/fs/empty-dir";
43
+ *
44
+ * emptyDirSync("./foo");
45
+ * ```
46
+ */
47
+ export declare function emptyDirSync(dir: string | URL): void;
48
+ //# sourceMappingURL=empty_dir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"empty_dir.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/fs/1.0.22/empty_dir.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,iBAkB/C;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,QAmB7C"}
@@ -0,0 +1,87 @@
1
+ // Copyright 2018-2026 the Deno authors. MIT license.
2
+ import * as dntShim from "../../../../../_dnt.shims.js";
3
+ import { join } from "../../path/1.1.4/join.js";
4
+ import { toPathString } from "./_to_path_string.js";
5
+ /**
6
+ * Asynchronously ensures that a directory is empty.
7
+ *
8
+ * If the directory does not exist, it is created. The directory itself is not
9
+ * deleted.
10
+ *
11
+ * Requires `--allow-read` and `--allow-write` permissions.
12
+ *
13
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
14
+ * for more information on Deno's permissions system.
15
+ *
16
+ * @param dir The path of the directory to empty, as a string or URL.
17
+ *
18
+ * @returns A void promise that resolves once the directory is empty.
19
+ *
20
+ * @example Usage
21
+ * ```ts ignore
22
+ * import { emptyDir } from "@std/fs/empty-dir";
23
+ *
24
+ * await emptyDir("./foo");
25
+ * ```
26
+ */
27
+ export async function emptyDir(dir) {
28
+ try {
29
+ const items = await Array.fromAsync(dntShim.Deno.readDir(dir));
30
+ await Promise.all(items.map((item) => {
31
+ if (item && item.name) {
32
+ const filepath = join(toPathString(dir), item.name);
33
+ return dntShim.Deno.remove(filepath, { recursive: true });
34
+ }
35
+ }));
36
+ }
37
+ catch (err) {
38
+ if (!(err instanceof dntShim.Deno.errors.NotFound)) {
39
+ throw err;
40
+ }
41
+ // if not exist. then create it
42
+ await dntShim.Deno.mkdir(dir, { recursive: true });
43
+ }
44
+ }
45
+ /**
46
+ * Synchronously ensures that a directory is empty deletes the directory
47
+ * contents it is not empty.
48
+ *
49
+ * If the directory does not exist, it is created. The directory itself is not
50
+ * deleted.
51
+ *
52
+ * Requires `--allow-read` and `--allow-write` permissions.
53
+ *
54
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
55
+ * for more information on Deno's permissions system.
56
+ *
57
+ * @param dir The path of the directory to empty, as a string or URL.
58
+ *
59
+ * @returns A void value that returns once the directory is empty.
60
+ *
61
+ * @example Usage
62
+ * ```ts ignore
63
+ * import { emptyDirSync } from "@std/fs/empty-dir";
64
+ *
65
+ * emptyDirSync("./foo");
66
+ * ```
67
+ */
68
+ export function emptyDirSync(dir) {
69
+ try {
70
+ const items = [...dntShim.Deno.readDirSync(dir)];
71
+ // If the directory exists, remove all entries inside it.
72
+ while (items.length) {
73
+ const item = items.shift();
74
+ if (item && item.name) {
75
+ const filepath = join(toPathString(dir), item.name);
76
+ dntShim.Deno.removeSync(filepath, { recursive: true });
77
+ }
78
+ }
79
+ }
80
+ catch (err) {
81
+ if (!(err instanceof dntShim.Deno.errors.NotFound)) {
82
+ throw err;
83
+ }
84
+ // if not exist. then create it
85
+ dntShim.Deno.mkdirSync(dir, { recursive: true });
86
+ }
87
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Asynchronously ensures that the directory exists, like
3
+ * {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=m-mkdir-command#mkdir__row-d3e133766 | mkdir -p}.
4
+ *
5
+ * If the directory already exists, this function does nothing. If the directory
6
+ * does not exist, it is created.
7
+ *
8
+ * Requires `--allow-read` and `--allow-write` permissions.
9
+ *
10
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
11
+ * for more information on Deno's permissions system.
12
+ *
13
+ * @param dir The path of the directory to ensure, as a string or URL.
14
+ *
15
+ * @returns A promise that resolves once the directory exists.
16
+ *
17
+ * @example Usage
18
+ * ```ts ignore
19
+ * import { ensureDir } from "@std/fs/ensure-dir";
20
+ *
21
+ * await ensureDir("./bar");
22
+ * ```
23
+ */
24
+ export declare function ensureDir(dir: string | URL): Promise<void>;
25
+ /**
26
+ * Synchronously ensures that the directory exists, like
27
+ * {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=m-mkdir-command#mkdir__row-d3e133766 | mkdir -p}.
28
+ *
29
+ * If the directory already exists, this function does nothing. If the directory
30
+ * does not exist, it is created.
31
+ *
32
+ * Requires `--allow-read` and `--allow-write` permissions.
33
+ *
34
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
35
+ * for more information on Deno's permissions system.
36
+ *
37
+ * @param dir The path of the directory to ensure, as a string or URL.
38
+ *
39
+ * @returns A void value that returns once the directory exists.
40
+ *
41
+ * @example Usage
42
+ * ```ts ignore
43
+ * import { ensureDirSync } from "@std/fs/ensure-dir";
44
+ *
45
+ * ensureDirSync("./bar");
46
+ * ```
47
+ */
48
+ export declare function ensureDirSync(dir: string | URL): void;
49
+ //# sourceMappingURL=ensure_dir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensure_dir.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/fs/1.0.22/ensure_dir.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,iBAuBhD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,QAuB9C"}
@@ -0,0 +1,102 @@
1
+ // Copyright 2018-2026 the Deno authors. MIT license.
2
+ import * as dntShim from "../../../../../_dnt.shims.js";
3
+ import { getFileInfoType } from "./_get_file_info_type.js";
4
+ /**
5
+ * Asynchronously ensures that the directory exists, like
6
+ * {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=m-mkdir-command#mkdir__row-d3e133766 | mkdir -p}.
7
+ *
8
+ * If the directory already exists, this function does nothing. If the directory
9
+ * does not exist, it is created.
10
+ *
11
+ * Requires `--allow-read` and `--allow-write` permissions.
12
+ *
13
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
14
+ * for more information on Deno's permissions system.
15
+ *
16
+ * @param dir The path of the directory to ensure, as a string or URL.
17
+ *
18
+ * @returns A promise that resolves once the directory exists.
19
+ *
20
+ * @example Usage
21
+ * ```ts ignore
22
+ * import { ensureDir } from "@std/fs/ensure-dir";
23
+ *
24
+ * await ensureDir("./bar");
25
+ * ```
26
+ */
27
+ export async function ensureDir(dir) {
28
+ try {
29
+ const fileInfo = await dntShim.Deno.stat(dir);
30
+ throwIfNotDirectory(fileInfo);
31
+ return;
32
+ }
33
+ catch (err) {
34
+ if (!(err instanceof dntShim.Deno.errors.NotFound)) {
35
+ throw err;
36
+ }
37
+ }
38
+ // The dir doesn't exist. Create it.
39
+ // This can be racy. So we catch AlreadyExists and check stat again.
40
+ try {
41
+ await dntShim.Deno.mkdir(dir, { recursive: true });
42
+ }
43
+ catch (err) {
44
+ if (!(err instanceof dntShim.Deno.errors.AlreadyExists)) {
45
+ throw err;
46
+ }
47
+ const fileInfo = await dntShim.Deno.stat(dir);
48
+ throwIfNotDirectory(fileInfo);
49
+ }
50
+ }
51
+ /**
52
+ * Synchronously ensures that the directory exists, like
53
+ * {@linkcode https://www.ibm.com/docs/en/aix/7.3?topic=m-mkdir-command#mkdir__row-d3e133766 | mkdir -p}.
54
+ *
55
+ * If the directory already exists, this function does nothing. If the directory
56
+ * does not exist, it is created.
57
+ *
58
+ * Requires `--allow-read` and `--allow-write` permissions.
59
+ *
60
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
61
+ * for more information on Deno's permissions system.
62
+ *
63
+ * @param dir The path of the directory to ensure, as a string or URL.
64
+ *
65
+ * @returns A void value that returns once the directory exists.
66
+ *
67
+ * @example Usage
68
+ * ```ts ignore
69
+ * import { ensureDirSync } from "@std/fs/ensure-dir";
70
+ *
71
+ * ensureDirSync("./bar");
72
+ * ```
73
+ */
74
+ export function ensureDirSync(dir) {
75
+ try {
76
+ const fileInfo = dntShim.Deno.statSync(dir);
77
+ throwIfNotDirectory(fileInfo);
78
+ return;
79
+ }
80
+ catch (err) {
81
+ if (!(err instanceof dntShim.Deno.errors.NotFound)) {
82
+ throw err;
83
+ }
84
+ }
85
+ // The dir doesn't exist. Create it.
86
+ // This can be racy. So we catch AlreadyExists and check stat again.
87
+ try {
88
+ dntShim.Deno.mkdirSync(dir, { recursive: true });
89
+ }
90
+ catch (err) {
91
+ if (!(err instanceof dntShim.Deno.errors.AlreadyExists)) {
92
+ throw err;
93
+ }
94
+ const fileInfo = dntShim.Deno.statSync(dir);
95
+ throwIfNotDirectory(fileInfo);
96
+ }
97
+ }
98
+ function throwIfNotDirectory(fileInfo) {
99
+ if (!fileInfo.isDirectory) {
100
+ throw new Error(`Failed to ensure directory exists: expected 'dir', got '${getFileInfoType(fileInfo)}'`);
101
+ }
102
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Asynchronously ensures that the file exists.
3
+ *
4
+ * If the file already exists, this function does nothing. If the parent
5
+ * directories for the file do not exist, they are created.
6
+ *
7
+ * Requires `--allow-read` and `--allow-write` permissions.
8
+ *
9
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
10
+ * for more information on Deno's permissions system.
11
+ *
12
+ * @param filePath The path of the file to ensure, as a string or URL.
13
+ *
14
+ * @returns A void promise that resolves once the file exists.
15
+ *
16
+ * @example Usage
17
+ * ```ts ignore
18
+ * import { ensureFile } from "@std/fs/ensure-file";
19
+ *
20
+ * await ensureFile("./folder/targetFile.dat");
21
+ * ```
22
+ */
23
+ export declare function ensureFile(filePath: string | URL): Promise<void>;
24
+ /**
25
+ * Synchronously ensures that the file exists.
26
+ *
27
+ * If the file already exists, this function does nothing. If the parent
28
+ * directories for the file do not exist, they are created.
29
+ *
30
+ * Requires `--allow-read` and `--allow-write` permissions.
31
+ *
32
+ * @see {@link https://docs.deno.com/runtime/manual/basics/permissions#file-system-access}
33
+ * for more information on Deno's permissions system.
34
+ *
35
+ * @param filePath The path of the file to ensure, as a string or URL.
36
+ *
37
+ * @returns A void value that returns once the file exists.
38
+ *
39
+ * @example Usage
40
+ * ```ts ignore
41
+ * import { ensureFileSync } from "@std/fs/ensure-file";
42
+ *
43
+ * ensureFileSync("./folder/targetFile.dat");
44
+ * ```
45
+ */
46
+ export declare function ensureFileSync(filePath: string | URL): void;
47
+ //# sourceMappingURL=ensure_file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensure_file.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/fs/1.0.22/ensure_file.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBtE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,CAsB3D"}