@seasb/metafab 0.0.0-stage → 1.0.0

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 (369) hide show
  1. package/README.md +47 -2
  2. package/dist/cli.d.ts +11 -0
  3. package/dist/cli.js +317 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/commands/build.d.ts +2 -0
  6. package/dist/commands/build.js +70 -0
  7. package/dist/commands/build.js.map +1 -0
  8. package/dist/commands/check.d.ts +2 -0
  9. package/dist/commands/check.js +41 -0
  10. package/dist/commands/check.js.map +1 -0
  11. package/dist/commands/create.d.ts +2 -0
  12. package/dist/commands/create.js +74 -0
  13. package/dist/commands/create.js.map +1 -0
  14. package/dist/commands/detach.d.ts +2 -0
  15. package/dist/commands/detach.js +24 -0
  16. package/dist/commands/detach.js.map +1 -0
  17. package/dist/commands/diff.d.ts +2 -0
  18. package/dist/commands/diff.js +35 -0
  19. package/dist/commands/diff.js.map +1 -0
  20. package/dist/commands/import.d.ts +2 -0
  21. package/dist/commands/import.js +107 -0
  22. package/dist/commands/import.js.map +1 -0
  23. package/dist/commands/init.d.ts +2 -0
  24. package/dist/commands/init.js +77 -0
  25. package/dist/commands/init.js.map +1 -0
  26. package/dist/commands/map.d.ts +2 -0
  27. package/dist/commands/map.js +43 -0
  28. package/dist/commands/map.js.map +1 -0
  29. package/dist/commands/not-implemented.d.ts +2 -0
  30. package/dist/commands/not-implemented.js +19 -0
  31. package/dist/commands/not-implemented.js.map +1 -0
  32. package/dist/commands/pipeline-add.d.ts +2 -0
  33. package/dist/commands/pipeline-add.js +67 -0
  34. package/dist/commands/pipeline-add.js.map +1 -0
  35. package/dist/commands/pipeline-remove.d.ts +2 -0
  36. package/dist/commands/pipeline-remove.js +44 -0
  37. package/dist/commands/pipeline-remove.js.map +1 -0
  38. package/dist/commands/publish.d.ts +2 -0
  39. package/dist/commands/publish.js +147 -0
  40. package/dist/commands/publish.js.map +1 -0
  41. package/dist/commands/types.d.ts +45 -0
  42. package/dist/commands/types.js +2 -0
  43. package/dist/commands/types.js.map +1 -0
  44. package/dist/commands/update.d.ts +2 -0
  45. package/dist/commands/update.js +97 -0
  46. package/dist/commands/update.js.map +1 -0
  47. package/dist/core/adopt.d.ts +53 -0
  48. package/dist/core/adopt.js +676 -0
  49. package/dist/core/adopt.js.map +1 -0
  50. package/dist/core/build/agents.d.ts +23 -0
  51. package/dist/core/build/agents.js +60 -0
  52. package/dist/core/build/agents.js.map +1 -0
  53. package/dist/core/build/index.d.ts +4 -0
  54. package/dist/core/build/index.js +5 -0
  55. package/dist/core/build/index.js.map +1 -0
  56. package/dist/core/build/markers.d.ts +34 -0
  57. package/dist/core/build/markers.js +97 -0
  58. package/dist/core/build/markers.js.map +1 -0
  59. package/dist/core/build/plan.d.ts +48 -0
  60. package/dist/core/build/plan.js +792 -0
  61. package/dist/core/build/plan.js.map +1 -0
  62. package/dist/core/build/skill.d.ts +60 -0
  63. package/dist/core/build/skill.js +275 -0
  64. package/dist/core/build/skill.js.map +1 -0
  65. package/dist/core/check/drift.d.ts +13 -0
  66. package/dist/core/check/drift.js +205 -0
  67. package/dist/core/check/drift.js.map +1 -0
  68. package/dist/core/check/index.d.ts +12 -0
  69. package/dist/core/check/index.js +78 -0
  70. package/dist/core/check/index.js.map +1 -0
  71. package/dist/core/check/markers.d.ts +9 -0
  72. package/dist/core/check/markers.js +220 -0
  73. package/dist/core/check/markers.js.map +1 -0
  74. package/dist/core/config/destinations.d.ts +5 -0
  75. package/dist/core/config/destinations.js +20 -0
  76. package/dist/core/config/destinations.js.map +1 -0
  77. package/dist/core/config/load.d.ts +4 -0
  78. package/dist/core/config/load.js +41 -0
  79. package/dist/core/config/load.js.map +1 -0
  80. package/dist/core/config/parse.d.ts +8 -0
  81. package/dist/core/config/parse.js +198 -0
  82. package/dist/core/config/parse.js.map +1 -0
  83. package/dist/core/config/source.d.ts +14 -0
  84. package/dist/core/config/source.js +44 -0
  85. package/dist/core/config/source.js.map +1 -0
  86. package/dist/core/config/types.d.ts +48 -0
  87. package/dist/core/config/types.js +2 -0
  88. package/dist/core/config/types.js.map +1 -0
  89. package/dist/core/config/validate.d.ts +11 -0
  90. package/dist/core/config/validate.js +351 -0
  91. package/dist/core/config/validate.js.map +1 -0
  92. package/dist/core/config/writers.d.ts +14 -0
  93. package/dist/core/config/writers.js +261 -0
  94. package/dist/core/config/writers.js.map +1 -0
  95. package/dist/core/config.d.ts +7 -0
  96. package/dist/core/config.js +8 -0
  97. package/dist/core/config.js.map +1 -0
  98. package/dist/core/discovery.d.ts +34 -0
  99. package/dist/core/discovery.js +272 -0
  100. package/dist/core/discovery.js.map +1 -0
  101. package/dist/core/edit/create.d.ts +18 -0
  102. package/dist/core/edit/create.js +190 -0
  103. package/dist/core/edit/create.js.map +1 -0
  104. package/dist/core/edit/document.d.ts +4 -0
  105. package/dist/core/edit/document.js +16 -0
  106. package/dist/core/edit/document.js.map +1 -0
  107. package/dist/core/edit/factory-yaml.d.ts +17 -0
  108. package/dist/core/edit/factory-yaml.js +211 -0
  109. package/dist/core/edit/factory-yaml.js.map +1 -0
  110. package/dist/core/edit/files.d.ts +6 -0
  111. package/dist/core/edit/files.js +47 -0
  112. package/dist/core/edit/files.js.map +1 -0
  113. package/dist/core/edit/index.d.ts +9 -0
  114. package/dist/core/edit/index.js +10 -0
  115. package/dist/core/edit/index.js.map +1 -0
  116. package/dist/core/edit/map.d.ts +24 -0
  117. package/dist/core/edit/map.js +82 -0
  118. package/dist/core/edit/map.js.map +1 -0
  119. package/dist/core/edit/names.d.ts +2 -0
  120. package/dist/core/edit/names.js +17 -0
  121. package/dist/core/edit/names.js.map +1 -0
  122. package/dist/core/edit/paths.d.ts +8 -0
  123. package/dist/core/edit/paths.js +76 -0
  124. package/dist/core/edit/paths.js.map +1 -0
  125. package/dist/core/edit/pipeline.d.ts +19 -0
  126. package/dist/core/edit/pipeline.js +146 -0
  127. package/dist/core/edit/pipeline.js.map +1 -0
  128. package/dist/core/edit/skill.d.ts +1 -0
  129. package/dist/core/edit/skill.js +10 -0
  130. package/dist/core/edit/skill.js.map +1 -0
  131. package/dist/core/factory/discovery.d.ts +9 -0
  132. package/dist/core/factory/discovery.js +139 -0
  133. package/dist/core/factory/discovery.js.map +1 -0
  134. package/dist/core/factory/factory-yaml.d.ts +16 -0
  135. package/dist/core/factory/factory-yaml.js +375 -0
  136. package/dist/core/factory/factory-yaml.js.map +1 -0
  137. package/dist/core/factory/index.d.ts +5 -0
  138. package/dist/core/factory/index.js +6 -0
  139. package/dist/core/factory/index.js.map +1 -0
  140. package/dist/core/factory/lines.d.ts +8 -0
  141. package/dist/core/factory/lines.js +11 -0
  142. package/dist/core/factory/lines.js.map +1 -0
  143. package/dist/core/factory/load.d.ts +4 -0
  144. package/dist/core/factory/load.js +81 -0
  145. package/dist/core/factory/load.js.map +1 -0
  146. package/dist/core/factory/requires.d.ts +9 -0
  147. package/dist/core/factory/requires.js +123 -0
  148. package/dist/core/factory/requires.js.map +1 -0
  149. package/dist/core/factory/types.d.ts +45 -0
  150. package/dist/core/factory/types.js +2 -0
  151. package/dist/core/factory/types.js.map +1 -0
  152. package/dist/core/factory/validate.d.ts +41 -0
  153. package/dist/core/factory/validate.js +441 -0
  154. package/dist/core/factory/validate.js.map +1 -0
  155. package/dist/core/hooks/index.d.ts +8 -0
  156. package/dist/core/hooks/index.js +15 -0
  157. package/dist/core/hooks/index.js.map +1 -0
  158. package/dist/core/hooks/script.d.ts +21 -0
  159. package/dist/core/hooks/script.js +34 -0
  160. package/dist/core/hooks/script.js.map +1 -0
  161. package/dist/core/hooks/sync.d.ts +17 -0
  162. package/dist/core/hooks/sync.js +262 -0
  163. package/dist/core/hooks/sync.js.map +1 -0
  164. package/dist/core/import/conflicts.d.ts +82 -0
  165. package/dist/core/import/conflicts.js +256 -0
  166. package/dist/core/import/conflicts.js.map +1 -0
  167. package/dist/core/import/copy.d.ts +10 -0
  168. package/dist/core/import/copy.js +76 -0
  169. package/dist/core/import/copy.js.map +1 -0
  170. package/dist/core/import/file-tree.d.ts +43 -0
  171. package/dist/core/import/file-tree.js +107 -0
  172. package/dist/core/import/file-tree.js.map +1 -0
  173. package/dist/core/import/index.d.ts +5 -0
  174. package/dist/core/import/index.js +6 -0
  175. package/dist/core/import/index.js.map +1 -0
  176. package/dist/core/import/pipeline-changes.d.ts +8 -0
  177. package/dist/core/import/pipeline-changes.js +89 -0
  178. package/dist/core/import/pipeline-changes.js.map +1 -0
  179. package/dist/core/import/run.d.ts +76 -0
  180. package/dist/core/import/run.js +258 -0
  181. package/dist/core/import/run.js.map +1 -0
  182. package/dist/core/init/gitattributes.d.ts +20 -0
  183. package/dist/core/init/gitattributes.js +89 -0
  184. package/dist/core/init/gitattributes.js.map +1 -0
  185. package/dist/core/init/index.d.ts +4 -0
  186. package/dist/core/init/index.js +5 -0
  187. package/dist/core/init/index.js.map +1 -0
  188. package/dist/core/init/name.d.ts +1 -0
  189. package/dist/core/init/name.js +4 -0
  190. package/dist/core/init/name.js.map +1 -0
  191. package/dist/core/init/run.d.ts +51 -0
  192. package/dist/core/init/run.js +261 -0
  193. package/dist/core/init/run.js.map +1 -0
  194. package/dist/core/init/targets.d.ts +17 -0
  195. package/dist/core/init/targets.js +87 -0
  196. package/dist/core/init/targets.js.map +1 -0
  197. package/dist/core/merge.d.ts +88 -0
  198. package/dist/core/merge.js +239 -0
  199. package/dist/core/merge.js.map +1 -0
  200. package/dist/core/publish/exclude.d.ts +9 -0
  201. package/dist/core/publish/exclude.js +32 -0
  202. package/dist/core/publish/exclude.js.map +1 -0
  203. package/dist/core/publish/git-target.d.ts +32 -0
  204. package/dist/core/publish/git-target.js +447 -0
  205. package/dist/core/publish/git-target.js.map +1 -0
  206. package/dist/core/publish/index.d.ts +10 -0
  207. package/dist/core/publish/index.js +11 -0
  208. package/dist/core/publish/index.js.map +1 -0
  209. package/dist/core/publish/npm-target.d.ts +15 -0
  210. package/dist/core/publish/npm-target.js +170 -0
  211. package/dist/core/publish/npm-target.js.map +1 -0
  212. package/dist/core/publish/package-json.d.ts +31 -0
  213. package/dist/core/publish/package-json.js +74 -0
  214. package/dist/core/publish/package-json.js.map +1 -0
  215. package/dist/core/publish/prepare.d.ts +24 -0
  216. package/dist/core/publish/prepare.js +93 -0
  217. package/dist/core/publish/prepare.js.map +1 -0
  218. package/dist/core/publish/provenance.d.ts +1 -0
  219. package/dist/core/publish/provenance.js +20 -0
  220. package/dist/core/publish/provenance.js.map +1 -0
  221. package/dist/core/publish/publish.d.ts +13 -0
  222. package/dist/core/publish/publish.js +130 -0
  223. package/dist/core/publish/publish.js.map +1 -0
  224. package/dist/core/publish/readme.d.ts +22 -0
  225. package/dist/core/publish/readme.js +112 -0
  226. package/dist/core/publish/readme.js.map +1 -0
  227. package/dist/core/publish/stage.d.ts +19 -0
  228. package/dist/core/publish/stage.js +333 -0
  229. package/dist/core/publish/stage.js.map +1 -0
  230. package/dist/core/publish/types.d.ts +71 -0
  231. package/dist/core/publish/types.js +2 -0
  232. package/dist/core/publish/types.js.map +1 -0
  233. package/dist/core/requires/check.d.ts +15 -0
  234. package/dist/core/requires/check.js +83 -0
  235. package/dist/core/requires/check.js.map +1 -0
  236. package/dist/core/requires/index.d.ts +4 -0
  237. package/dist/core/requires/index.js +5 -0
  238. package/dist/core/requires/index.js.map +1 -0
  239. package/dist/core/requires/inspect.d.ts +44 -0
  240. package/dist/core/requires/inspect.js +114 -0
  241. package/dist/core/requires/inspect.js.map +1 -0
  242. package/dist/core/requires/paths.d.ts +29 -0
  243. package/dist/core/requires/paths.js +83 -0
  244. package/dist/core/requires/paths.js.map +1 -0
  245. package/dist/core/requires/setup.d.ts +37 -0
  246. package/dist/core/requires/setup.js +147 -0
  247. package/dist/core/requires/setup.js.map +1 -0
  248. package/dist/core/setup.d.ts +27 -0
  249. package/dist/core/setup.js +84 -0
  250. package/dist/core/setup.js.map +1 -0
  251. package/dist/core/sources/cache.d.ts +38 -0
  252. package/dist/core/sources/cache.js +200 -0
  253. package/dist/core/sources/cache.js.map +1 -0
  254. package/dist/core/sources/containment.d.ts +21 -0
  255. package/dist/core/sources/containment.js +50 -0
  256. package/dist/core/sources/containment.js.map +1 -0
  257. package/dist/core/sources/env.d.ts +12 -0
  258. package/dist/core/sources/env.js +28 -0
  259. package/dist/core/sources/env.js.map +1 -0
  260. package/dist/core/sources/extract.d.ts +25 -0
  261. package/dist/core/sources/extract.js +676 -0
  262. package/dist/core/sources/extract.js.map +1 -0
  263. package/dist/core/sources/git-process.d.ts +26 -0
  264. package/dist/core/sources/git-process.js +51 -0
  265. package/dist/core/sources/git-process.js.map +1 -0
  266. package/dist/core/sources/git.d.ts +41 -0
  267. package/dist/core/sources/git.js +511 -0
  268. package/dist/core/sources/git.js.map +1 -0
  269. package/dist/core/sources/https.d.ts +21 -0
  270. package/dist/core/sources/https.js +208 -0
  271. package/dist/core/sources/https.js.map +1 -0
  272. package/dist/core/sources/index.d.ts +13 -0
  273. package/dist/core/sources/index.js +14 -0
  274. package/dist/core/sources/index.js.map +1 -0
  275. package/dist/core/sources/npm-cli.d.ts +19 -0
  276. package/dist/core/sources/npm-cli.js +43 -0
  277. package/dist/core/sources/npm-cli.js.map +1 -0
  278. package/dist/core/sources/npm.d.ts +29 -0
  279. package/dist/core/sources/npm.js +386 -0
  280. package/dist/core/sources/npm.js.map +1 -0
  281. package/dist/core/sources/parse.d.ts +32 -0
  282. package/dist/core/sources/parse.js +389 -0
  283. package/dist/core/sources/parse.js.map +1 -0
  284. package/dist/core/sources/path.d.ts +10 -0
  285. package/dist/core/sources/path.js +316 -0
  286. package/dist/core/sources/path.js.map +1 -0
  287. package/dist/core/sources/redact.d.ts +2 -0
  288. package/dist/core/sources/redact.js +70 -0
  289. package/dist/core/sources/redact.js.map +1 -0
  290. package/dist/core/sources/resolve.d.ts +9 -0
  291. package/dist/core/sources/resolve.js +29 -0
  292. package/dist/core/sources/resolve.js.map +1 -0
  293. package/dist/core/sources/types.d.ts +86 -0
  294. package/dist/core/sources/types.js +2 -0
  295. package/dist/core/sources/types.js.map +1 -0
  296. package/dist/core/sources/validate.d.ts +9 -0
  297. package/dist/core/sources/validate.js +111 -0
  298. package/dist/core/sources/validate.js.map +1 -0
  299. package/dist/core/summary.d.ts +77 -0
  300. package/dist/core/summary.js +405 -0
  301. package/dist/core/summary.js.map +1 -0
  302. package/dist/core/update/clashes.d.ts +63 -0
  303. package/dist/core/update/clashes.js +192 -0
  304. package/dist/core/update/clashes.js.map +1 -0
  305. package/dist/core/update/detach.d.ts +21 -0
  306. package/dist/core/update/detach.js +38 -0
  307. package/dist/core/update/detach.js.map +1 -0
  308. package/dist/core/update/diff.d.ts +58 -0
  309. package/dist/core/update/diff.js +180 -0
  310. package/dist/core/update/diff.js.map +1 -0
  311. package/dist/core/update/fetch.d.ts +34 -0
  312. package/dist/core/update/fetch.js +73 -0
  313. package/dist/core/update/fetch.js.map +1 -0
  314. package/dist/core/update/index.d.ts +6 -0
  315. package/dist/core/update/index.js +7 -0
  316. package/dist/core/update/index.js.map +1 -0
  317. package/dist/core/update/restore.d.ts +20 -0
  318. package/dist/core/update/restore.js +195 -0
  319. package/dist/core/update/restore.js.map +1 -0
  320. package/dist/core/update/run.d.ts +113 -0
  321. package/dist/core/update/run.js +1132 -0
  322. package/dist/core/update/run.js.map +1 -0
  323. package/dist/core/update/select.d.ts +39 -0
  324. package/dist/core/update/select.js +157 -0
  325. package/dist/core/update/select.js.map +1 -0
  326. package/dist/core/update/spelling.d.ts +51 -0
  327. package/dist/core/update/spelling.js +185 -0
  328. package/dist/core/update/spelling.js.map +1 -0
  329. package/dist/core/update/trees.d.ts +24 -0
  330. package/dist/core/update/trees.js +72 -0
  331. package/dist/core/update/trees.js.map +1 -0
  332. package/dist/errors.d.ts +29 -0
  333. package/dist/errors.js +24 -0
  334. package/dist/errors.js.map +1 -0
  335. package/dist/help.d.ts +46 -0
  336. package/dist/help.js +103 -0
  337. package/dist/help.js.map +1 -0
  338. package/dist/input.d.ts +25 -0
  339. package/dist/input.js +173 -0
  340. package/dist/input.js.map +1 -0
  341. package/dist/output.d.ts +21 -0
  342. package/dist/output.js +37 -0
  343. package/dist/output.js.map +1 -0
  344. package/dist/util/frontmatter.d.ts +12 -0
  345. package/dist/util/frontmatter.js +58 -0
  346. package/dist/util/frontmatter.js.map +1 -0
  347. package/dist/util/fs.d.ts +32 -0
  348. package/dist/util/fs.js +126 -0
  349. package/dist/util/fs.js.map +1 -0
  350. package/dist/util/git-names.d.ts +8 -0
  351. package/dist/util/git-names.js +25 -0
  352. package/dist/util/git-names.js.map +1 -0
  353. package/dist/util/git.d.ts +12 -0
  354. package/dist/util/git.js +33 -0
  355. package/dist/util/git.js.map +1 -0
  356. package/dist/util/suggest.d.ts +6 -0
  357. package/dist/util/suggest.js +48 -0
  358. package/dist/util/suggest.js.map +1 -0
  359. package/dist/util/text.d.ts +8 -0
  360. package/dist/util/text.js +19 -0
  361. package/dist/util/text.js.map +1 -0
  362. package/dist/util/version.d.ts +7 -0
  363. package/dist/util/version.js +13 -0
  364. package/dist/util/version.js.map +1 -0
  365. package/dist/util/yaml.d.ts +30 -0
  366. package/dist/util/yaml.js +201 -0
  367. package/dist/util/yaml.js.map +1 -0
  368. package/package.json +51 -4
  369. package/resources/metafab-skill/SKILL.md +99 -0
@@ -0,0 +1,84 @@
1
+ import { lstat } from "node:fs/promises";
2
+ import { ExitCode, MetafabError } from "../errors.js";
3
+ import { isDirectory } from "../util/fs.js";
4
+ import { cliVersion } from "../util/version.js";
5
+ import { planBuild } from "./build/index.js";
6
+ import { loadConfig, unreadableConfigCode } from "./config/load.js";
7
+ import { CONFIG_FILE, parseConfig } from "./config/parse.js";
8
+ import { TARGETS } from "./config/types.js";
9
+ import { createConfigText } from "./config/writers.js";
10
+ import { loadFactory } from "./factory/load.js";
11
+ export function selectedTargets(selection) {
12
+ return selection === "all" ? [...TARGETS] : [...selection];
13
+ }
14
+ export function unreadableFactory(file, message, fix) {
15
+ return new MetafabError(message, {
16
+ exitCode: ExitCode.Failed,
17
+ code: "factory-unreadable",
18
+ problems: [{ level: "error", file, message, fix }],
19
+ });
20
+ }
21
+ /** Refuses a `.factory` entry that cannot hold a factory before anything reads it. */
22
+ export async function assertFactoryDirectoryUsable(factoryDir, command) {
23
+ let info;
24
+ try {
25
+ info = await lstat(factoryDir);
26
+ }
27
+ catch (error) {
28
+ const code = error.code;
29
+ if (code === "ENOENT")
30
+ return;
31
+ throw unreadableFactory(".factory", "Cannot read the .factory entry", "Check its permissions or restore the directory");
32
+ }
33
+ if (info.isDirectory())
34
+ return;
35
+ if (info.isSymbolicLink() && (await isDirectory(factoryDir)))
36
+ return;
37
+ throw unreadableFactory(".factory", info.isSymbolicLink()
38
+ ? ".factory is a symbolic link that does not point to a directory"
39
+ : ".factory is a file, not a directory", `Move it or replace it with a directory, then run metafab ${command} again`);
40
+ }
41
+ /**
42
+ * The fix line for an unreadable configuration file. Only a permissions error
43
+ * is worth telling the reader to check permissions; every other code means the
44
+ * file is broken, a directory, a loop, or otherwise unreadable.
45
+ */
46
+ export function unreadableConfigFix(code, command) {
47
+ return code === "EACCES" || code === "EPERM"
48
+ ? "Check its permissions or restore the file"
49
+ : `Restore the file, then run metafab ${command} again`;
50
+ }
51
+ /** Loads `metafab.yaml`, refusing a file that exists but cannot be read. */
52
+ export async function readConfig(factoryDir, command) {
53
+ const config = await loadConfig(factoryDir);
54
+ const code = unreadableConfigCode(config);
55
+ if (code !== undefined) {
56
+ throw unreadableFactory(CONFIG_FILE, `Cannot read file ${CONFIG_FILE}`, unreadableConfigFix(code, command));
57
+ }
58
+ return config;
59
+ }
60
+ /** True when `file` lies at or beneath one of the paths an adoption moves. */
61
+ export function isAdoptionSource(file, moves) {
62
+ return moves.some((move) => move.from.some((from) => file === from || file.startsWith(`${from}/`)));
63
+ }
64
+ /**
65
+ * The output conflicts `build` would refuse, checked before `init` or `import`
66
+ * writes anything. Validation errors that are already in the factory are left
67
+ * for the closing build to report, so the setup command still adds the missing
68
+ * entries the specification promises. Conflict problems inside a planned move
69
+ * are ignored: the move removes them.
70
+ */
71
+ export async function preflightBuild(root, config, selection, configExists, moves) {
72
+ const factory = await loadFactory(root);
73
+ const effective = configExists ? config : parseConfig(createConfigText({ agents: selection }));
74
+ const planned = await planBuild(factory, effective, cliVersion());
75
+ const conflicts = planned.conflicts.filter((problem) => !isAdoptionSource(problem.file, moves));
76
+ if (conflicts.length === 0)
77
+ return;
78
+ throw new MetafabError("Build stopped because the repository contains output that Metafab does not own.", {
79
+ exitCode: ExitCode.NotOwned,
80
+ code: "build-conflict",
81
+ problems: [...conflicts, ...planned.errors, ...planned.warnings],
82
+ });
83
+ }
84
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/core/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKhD,MAAM,UAAU,eAAe,CAAC,SAA2B;IACzD,OAAO,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,i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C;IAEhG,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAEnC,MAAM,IAAI,YAAY,CACpB,iFAAiF,EACjF;QACE,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,IAAI,EAAE,gBAAgB;QACtB,QAAQ,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;KACjE,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { MetafabError } from "../../errors.js";
2
+ export interface CacheLayout {
3
+ root: string;
4
+ npmTarball(name: string, version: string): string;
5
+ gitMirror(url: string): string;
6
+ fabDir(key: string): string;
7
+ fabFactoryDir(key: string): string;
8
+ }
9
+ export interface GetOrCreateOptions<T> {
10
+ /** The cache root, so a write failure can name what to make writable. */
11
+ root: string;
12
+ /** Validates the entry in the directory it is given and returns the final path. */
13
+ validate: (dir: string) => Promise<T>;
14
+ /** Builds the entry in the staging directory it is given. */
15
+ create: (staging: string) => Promise<void>;
16
+ }
17
+ export declare function cacheRoot(env?: NodeJS.ProcessEnv): string;
18
+ export declare function fabKey(...parts: string[]): string;
19
+ export declare function cacheLayout(root?: string): CacheLayout;
20
+ /**
21
+ * True when a rename failed because another command put the target in place
22
+ * first. Windows reports a directory rename over an existing one as EPERM or
23
+ * EBUSY, so those count only when the target is there.
24
+ */
25
+ export declare function isLostRaceError(error: unknown, target: string): Promise<boolean>;
26
+ /**
27
+ * Removes `<name>.tmp-*` and `<name>.old-*` siblings older than 24 hours. A
28
+ * concurrent command's clone is never touched: no clone takes a day. Best
29
+ * effort, because a cache it cannot clean is still usable.
30
+ */
31
+ export declare function sweepStale(parent: string, name: string, now?: number): Promise<void>;
32
+ /**
33
+ * One `fetch-failed` problem naming the path: a cache Metafab cannot write
34
+ * stops the command before the repository changes, instead of surfacing a
35
+ * filesystem error as an internal bug.
36
+ */
37
+ export declare function cacheWriteError(target: string, root: string, error: unknown): MetafabError;
38
+ export declare function getOrCreate<T>(target: string, options: GetOrCreateOptions<T>): Promise<T>;
@@ -0,0 +1,200 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { readdir, rename, rm, stat } from "node:fs/promises";
3
+ import { homedir } from "node:os";
4
+ import path from "node:path";
5
+ import { ExitCode, MetafabError } from "../../errors.js";
6
+ import { pathExists, toPosixPath } from "../../util/fs.js";
7
+ import { sourceWithoutCredentials } from "./parse.js";
8
+ const MAX_KEY_LENGTH = 120;
9
+ const STALE_AGE_MS = 24 * 60 * 60 * 1000;
10
+ export function cacheRoot(env = process.env) {
11
+ const override = env.METAFAB_CACHE?.trim();
12
+ if (override !== undefined && override !== "")
13
+ return path.resolve(override);
14
+ return path.join(homedir(), ".metafab", "cache");
15
+ }
16
+ function keySegment(value) {
17
+ const key = value.replace(/[^A-Za-z0-9._@-]+/g, "-").replace(/^\.+$/, "");
18
+ if (key === "")
19
+ throw new Error(`Invalid cache key "${value}"`);
20
+ return key;
21
+ }
22
+ export function fabKey(...parts) {
23
+ const key = keySegment(parts.filter((part) => part !== "").join("-"));
24
+ if (key.length <= MAX_KEY_LENGTH)
25
+ return key;
26
+ // A Git source carries its whole path into the name. Keep the readable head
27
+ // and add a digest of the whole key so a path longer than the filesystem
28
+ // allows still names one stable entry.
29
+ const digest = createHash("sha256").update(key).digest("hex").slice(0, 32);
30
+ return `${key.slice(0, 80)}-${digest}`;
31
+ }
32
+ export function cacheLayout(root = cacheRoot()) {
33
+ return {
34
+ root,
35
+ npmTarball(name, version) {
36
+ return path.join(root, "npm", ...name.split("/"), `${version}.tgz`);
37
+ },
38
+ gitMirror(url) {
39
+ // Key on the URL without credentials so a new token reuses the mirror
40
+ // instead of cloning the same repository again. A `file:` URL carries
41
+ // none, and its path may hold a `@` that is not userinfo.
42
+ const hash = createHash("sha256").update(sourceWithoutCredentials(url)).digest("hex");
43
+ return path.join(root, "git", hash);
44
+ },
45
+ fabDir(key) {
46
+ return path.join(root, "fabs", keySegment(key));
47
+ },
48
+ fabFactoryDir(key) {
49
+ return path.join(root, "fabs", keySegment(key), ".factory");
50
+ },
51
+ };
52
+ }
53
+ function errorCode(error) {
54
+ if (typeof error !== "object" || error === null || !("code" in error))
55
+ return undefined;
56
+ const code = error.code;
57
+ return typeof code === "string" ? code : undefined;
58
+ }
59
+ async function removeQuietly(target) {
60
+ await rm(target, { recursive: true, force: true }).catch(() => undefined);
61
+ }
62
+ /**
63
+ * True when a rename failed because another command put the target in place
64
+ * first. Windows reports a directory rename over an existing one as EPERM or
65
+ * EBUSY, so those count only when the target is there.
66
+ */
67
+ export async function isLostRaceError(error, target) {
68
+ const code = errorCode(error);
69
+ if (code === "EEXIST" || code === "ENOTEMPTY")
70
+ return true;
71
+ if (code === "EPERM" || code === "EBUSY")
72
+ return await pathExists(target);
73
+ return false;
74
+ }
75
+ /**
76
+ * Removes `<name>.tmp-*` and `<name>.old-*` siblings older than 24 hours. A
77
+ * concurrent command's clone is never touched: no clone takes a day. Best
78
+ * effort, because a cache it cannot clean is still usable.
79
+ */
80
+ export async function sweepStale(parent, name, now = Date.now()) {
81
+ let entries;
82
+ try {
83
+ entries = await readdir(parent);
84
+ }
85
+ catch {
86
+ return;
87
+ }
88
+ const prefixes = [`${name}.tmp-`, `${name}.old-`];
89
+ for (const entry of entries) {
90
+ if (!prefixes.some((prefix) => entry.startsWith(prefix)))
91
+ continue;
92
+ const candidate = path.join(parent, entry);
93
+ try {
94
+ const info = await stat(candidate);
95
+ if (now - info.mtimeMs <= STALE_AGE_MS)
96
+ continue;
97
+ }
98
+ catch {
99
+ continue;
100
+ }
101
+ await removeQuietly(candidate);
102
+ }
103
+ }
104
+ /**
105
+ * One `fetch-failed` problem naming the path: a cache Metafab cannot write
106
+ * stops the command before the repository changes, instead of surfacing a
107
+ * filesystem error as an internal bug.
108
+ */
109
+ export function cacheWriteError(target, root, error) {
110
+ const detail = errorCode(error) ?? (error instanceof Error ? error.message : String(error));
111
+ const message = `Cannot write the Metafab cache: ${detail}: ${target}`;
112
+ const problem = {
113
+ level: "error",
114
+ file: toPosixPath(target),
115
+ message,
116
+ fix: `Free disk space or make ${root} writable, or set METAFAB_CACHE to a writable directory, then run the command again`,
117
+ };
118
+ return new MetafabError(message, {
119
+ exitCode: ExitCode.FetchFailed,
120
+ code: "fetch-failed",
121
+ problems: [problem],
122
+ cause: error,
123
+ });
124
+ }
125
+ function isAbsentError(error) {
126
+ const code = errorCode(error);
127
+ return code === "ENOENT" || code === "ENOTDIR";
128
+ }
129
+ /**
130
+ * Moves a complete entry that failed validation out of the way. The rename is
131
+ * atomic, so when two commands find the same corrupt entry only one moves it;
132
+ * the other's rename fails with ENOENT and it carries on to create. A sibling a
133
+ * command leaves behind is swept after 24 hours.
134
+ */
135
+ async function discardEntry(target, root) {
136
+ const discarded = `${target}.old-${randomUUID()}`;
137
+ try {
138
+ await rename(target, discarded);
139
+ }
140
+ catch (error) {
141
+ // Another command moved it first, so it is already gone.
142
+ if (isAbsentError(error))
143
+ return;
144
+ throw cacheWriteError(target, root, error);
145
+ }
146
+ await removeQuietly(discarded);
147
+ }
148
+ export async function getOrCreate(target, options) {
149
+ // A complete entry that fails validation is wrong, not another command's
150
+ // partial work: renames are atomic. Another command may have replaced it
151
+ // since it was read, though, so look again before moving it: moving an entry
152
+ // that just became good would take the path away from its caller.
153
+ if (await pathExists(target)) {
154
+ try {
155
+ return await options.validate(target);
156
+ }
157
+ catch {
158
+ if (await pathExists(target)) {
159
+ try {
160
+ return await options.validate(target);
161
+ }
162
+ catch {
163
+ await discardEntry(target, options.root);
164
+ }
165
+ }
166
+ }
167
+ }
168
+ await sweepStale(path.dirname(target), path.basename(target));
169
+ const staging = `${target}.tmp-${randomUUID()}`;
170
+ try {
171
+ await options.create(staging);
172
+ }
173
+ catch (error) {
174
+ await removeQuietly(staging);
175
+ throw error;
176
+ }
177
+ let result;
178
+ try {
179
+ result = await options.validate(staging);
180
+ }
181
+ catch (error) {
182
+ await removeQuietly(staging);
183
+ throw error;
184
+ }
185
+ try {
186
+ await rename(staging, target);
187
+ }
188
+ catch (error) {
189
+ if (await isLostRaceError(error, target)) {
190
+ // Another command renamed a complete entry into place first. Its entry
191
+ // is the one that won; use it rather than deleting it.
192
+ await removeQuietly(staging);
193
+ return await options.validate(target);
194
+ }
195
+ await removeQuietly(staging);
196
+ throw cacheWriteError(target, options.root, error);
197
+ }
198
+ return result;
199
+ }
200
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/core/sources/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAmBtD,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,YAAY,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEzC,MAAM,UAAU,SAAS,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG;IAC5D,MAAM,QAAQ,GAAG,GAAG,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACnD,CA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AAC;QACD,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;QAC7B,MAAM,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,21 @@
1
+ /** The parts of a `stat()` result that identify a file on disk. */
2
+ export interface FileIdentity {
3
+ readonly dev: bigint;
4
+ readonly ino: bigint;
5
+ }
6
+ /**
7
+ * Whether two `stat(path, { bigint: true })` results are the same file. NTFS
8
+ * file IDs are 64 bits, and a JavaScript number keeps only 53, so comparing
9
+ * `dev` and `ino` as numbers makes different files look like the same one.
10
+ * Pass bigint stats so the exact values are compared.
11
+ */
12
+ export declare function sameFile(left: FileIdentity, right: FileIdentity): boolean;
13
+ /**
14
+ * The directory a link must stay inside. The spelling of the stored path is not
15
+ * what the filesystem matches on: on a case-insensitive filesystem
16
+ * `.FACTORY/leak` lives in the same directory as `.factory/leak`, and a
17
+ * symlinked parent can put a differently spelled path there too. Walk the
18
+ * link's real ancestors and compare their identity with `.factory`.
19
+ */
20
+ export declare function containmentRootAbsolute(absoluteLinkPath: string, destination: string): Promise<string>;
21
+ export declare function isInsideAbsolute(root: string, target: string): boolean;
@@ -0,0 +1,50 @@
1
+ import { realpath, stat } from "node:fs/promises";
2
+ import path from "node:path";
3
+ const FACTORY_DIRECTORY = ".factory";
4
+ /**
5
+ * Whether two `stat(path, { bigint: true })` results are the same file. NTFS
6
+ * file IDs are 64 bits, and a JavaScript number keeps only 53, so comparing
7
+ * `dev` and `ino` as numbers makes different files look like the same one.
8
+ * Pass bigint stats so the exact values are compared.
9
+ */
10
+ export function sameFile(left, right) {
11
+ return left.dev === right.dev && left.ino === right.ino;
12
+ }
13
+ /**
14
+ * The directory a link must stay inside. The spelling of the stored path is not
15
+ * what the filesystem matches on: on a case-insensitive filesystem
16
+ * `.FACTORY/leak` lives in the same directory as `.factory/leak`, and a
17
+ * symlinked parent can put a differently spelled path there too. Walk the
18
+ * link's real ancestors and compare their identity with `.factory`.
19
+ */
20
+ export async function containmentRootAbsolute(absoluteLinkPath, destination) {
21
+ const destinationRoot = await realpath(destination).catch(() => path.resolve(destination));
22
+ const factoryPath = path.join(destination, FACTORY_DIRECTORY);
23
+ const factory = await stat(factoryPath, { bigint: true }).catch(() => undefined);
24
+ if (factory === undefined)
25
+ return destinationRoot;
26
+ let current = path.dirname(absoluteLinkPath);
27
+ for (;;) {
28
+ const ancestor = await stat(current, { bigint: true }).catch(() => undefined);
29
+ if (ancestor !== undefined && sameFile(ancestor, factory)) {
30
+ return realpath(factoryPath).catch(() => factoryPath);
31
+ }
32
+ const parent = path.dirname(current);
33
+ if (parent === current)
34
+ return destinationRoot;
35
+ current = parent;
36
+ }
37
+ }
38
+ export function isInsideAbsolute(root, target) {
39
+ const relative = path.relative(root, target);
40
+ if (relative === "")
41
+ return true;
42
+ if (path.isAbsolute(relative))
43
+ return false;
44
+ if (relative === "..")
45
+ return false;
46
+ // A name may start with two dots (`.factory/..notes.md`); only a `..`
47
+ // segment, whole or followed by a separator, leaves the root.
48
+ return !(relative.startsWith(`..${path.sep}`) || relative.startsWith("../"));
49
+ }
50
+ //# sourceMappingURL=containment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"containment.js","sourceRoot":"","sources":["../../../src/core/sources/containment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAQrC;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAkB,EAAE,KAAmB;IAC9D,OAAO,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,uB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IAAI,CAAC;IACjC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACpC,sEAAsE;IACtE,8DAA8D;IAC9D,OAAO,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Build the environment for a child process.
3
+ *
4
+ * Windows environment variable names are case-insensitive, but spreading
5
+ * `process.env` into a plain object is not: setting `npm_config_cache` next to
6
+ * an inherited `NPM_CONFIG_CACHE` puts two names for one setting in the child's
7
+ * environment block, and which one the child (and npm, which reads every
8
+ * `npm_config_*` name case-insensitively) sees is undefined. Each override
9
+ * therefore replaces every existing name that matches it case-insensitively,
10
+ * so the child has exactly one name per setting.
11
+ */
12
+ export declare function withEnv(baseEnv: NodeJS.ProcessEnv, overrides: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Build the environment for a child process.
3
+ *
4
+ * Windows environment variable names are case-insensitive, but spreading
5
+ * `process.env` into a plain object is not: setting `npm_config_cache` next to
6
+ * an inherited `NPM_CONFIG_CACHE` puts two names for one setting in the child's
7
+ * environment block, and which one the child (and npm, which reads every
8
+ * `npm_config_*` name case-insensitively) sees is undefined. Each override
9
+ * therefore replaces every existing name that matches it case-insensitively,
10
+ * so the child has exactly one name per setting.
11
+ */
12
+ export function withEnv(baseEnv, overrides) {
13
+ const defined = Object.entries(overrides).filter((entry) => entry[1] !== undefined);
14
+ const overridden = new Set(defined.map(([name]) => name.toLowerCase()));
15
+ const env = {};
16
+ for (const [name, value] of Object.entries(baseEnv)) {
17
+ if (value === undefined)
18
+ continue;
19
+ if (overridden.has(name.toLowerCase()))
20
+ continue;
21
+ env[name] = value;
22
+ }
23
+ for (const [name, value] of defined) {
24
+ env[name] = value;
25
+ }
26
+ return env;
27
+ }
28
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/core/sources/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,OAAO,CACrB,OAA0B,EAC1B,SAA4B;IAE5B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAC9C,CAAC,KAAK,EAA6B,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAC7D,CAAC;IACF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACxE,MAAM,GAAG,GAAsB,EAAE,CAAC;IAElC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YAAE,SAAS;QACjD,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACpB,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACpC,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { MetafabError } from "../../errors.js";
2
+ export declare const MAX_FAB_FILE_SIZE: number;
3
+ export declare const MAX_FAB_TOTAL_SIZE: number;
4
+ export declare const MAX_FAB_ENTRIES = 10000;
5
+ export interface ExtractTarballOptions {
6
+ strip?: number;
7
+ stripPrefix?: string;
8
+ flattenSingleDirectory?: boolean;
9
+ maxFileSize?: number;
10
+ maxTotalSize?: number;
11
+ maxEntries?: number;
12
+ /**
13
+ * Turns a failure to write the destination into the caller's own error, such
14
+ * as a cache write failure. Without it, every destination failure is a
15
+ * tarball problem (exit 4), as it always was.
16
+ */
17
+ writeError?: (target: string, error: unknown) => MetafabError;
18
+ }
19
+ /**
20
+ * True when a filesystem failure means the destination could not be written,
21
+ * rather than the archive being bad: permissions, a full disk or a read-only
22
+ * filesystem.
23
+ */
24
+ export declare function isCacheWriteFailure(error: unknown): boolean;
25
+ export declare function extractTarball(tarball: string, destination: string, options?: ExtractTarballOptions): Promise<void>;