@seasb/metafab 0.0.1 → 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 +46 -1
  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 +50 -3
  369. package/resources/metafab-skill/SKILL.md +99 -0
@@ -0,0 +1,112 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { ExitCode, MetafabError } from "../../errors.js";
4
+ import { importSourceForGitUrl, sourceWithoutCredentials } from "../sources/parse.js";
5
+ const IMPORT_COMMAND = "npx @seasb/metafab import";
6
+ function isAbsentError(error) {
7
+ const code = error?.code;
8
+ return code === "ENOENT" || code === "ENOTDIR";
9
+ }
10
+ function readError(file, fix) {
11
+ return new MetafabError(`Cannot read file ${file}`, {
12
+ exitCode: ExitCode.Failed,
13
+ code: "publish-readme-unreadable",
14
+ problems: [
15
+ {
16
+ level: "error",
17
+ file,
18
+ line: 1,
19
+ message: `Cannot read file ${file}`,
20
+ fix,
21
+ },
22
+ ],
23
+ });
24
+ }
25
+ async function readReadme(target, file) {
26
+ try {
27
+ return await readFile(target, "utf8");
28
+ }
29
+ catch (error) {
30
+ if (isAbsentError(error))
31
+ throw readError(file, "Create the file or remove publish.readme");
32
+ throw readError(file, "Check its permissions");
33
+ }
34
+ }
35
+ function skillSummary(skill) {
36
+ const description = skill.frontmatter["description"];
37
+ if (typeof description === "string" && description.trim() !== "")
38
+ return description.trim();
39
+ return skill.title;
40
+ }
41
+ function skillLine(skill) {
42
+ const summary = skillSummary(skill);
43
+ return summary === undefined ? `- \`${skill.name}\`` : `- \`${skill.name}\` — ${summary}`;
44
+ }
45
+ /**
46
+ * The source an importer names: the npm package when there is one, else the Git
47
+ * URL without credentials, in the form `import` accepts (`https://` and
48
+ * `file://` gain `git+`). The README is published, so a token in `publish.git`
49
+ * must never reach it.
50
+ */
51
+ export function publishSource(publish) {
52
+ if (publish.name !== undefined)
53
+ return publish.name;
54
+ if (publish.git === undefined)
55
+ return undefined;
56
+ return importSourceForGitUrl(sourceWithoutCredentials(publish.git));
57
+ }
58
+ /**
59
+ * The README written when a project has neither `publish.readme` nor
60
+ * `.factory/README.md`: what the factory is, how it runs and how to import it.
61
+ */
62
+ export function generateReadme(factory, publish) {
63
+ const name = factory.factoryYaml?.name ?? publish.name ?? "factory";
64
+ const description = factory.factoryYaml?.description ?? publish.description;
65
+ const lines = [`# ${name}`, ""];
66
+ if (description !== undefined)
67
+ lines.push(description, "");
68
+ const pipeline = factory.factoryYaml?.pipeline ?? [];
69
+ if (pipeline.length > 0) {
70
+ lines.push("## Pipeline", "");
71
+ pipeline.forEach((entry, index) => {
72
+ const stop = entry.stop === undefined ? "" : ` — stop: ${entry.stop}`;
73
+ lines.push(`${index + 1}. \`${entry.workflow}\`${stop}`);
74
+ });
75
+ lines.push("");
76
+ }
77
+ const workflows = factory.skills.filter((skill) => skill.isWorkflow);
78
+ if (workflows.length > 0) {
79
+ lines.push("## Workflows", "", ...workflows.map(skillLine), "");
80
+ }
81
+ const skills = factory.skills.filter((skill) => !skill.isWorkflow);
82
+ if (skills.length > 0) {
83
+ lines.push("## Skills", "", ...skills.map(skillLine), "");
84
+ }
85
+ lines.push("## Install", "", "Install this factory with Metafab:", "", "```sh", `${IMPORT_COMMAND} ${publishSource(publish) ?? "<source>"}`, "```", "");
86
+ return lines.join("\n");
87
+ }
88
+ /**
89
+ * The README at the fab root: `publish.readme`, else `.factory/README.md`, else
90
+ * a generated one. `.factory/README.md` is never copied into the fab itself.
91
+ *
92
+ * The generated README describes `published`, the staged factory, so a name or
93
+ * description that `publish.exclude` removes is not published.
94
+ */
95
+ export async function resolveReadme(repositoryRoot, factory, publish, published = factory) {
96
+ if (publish.readme !== undefined) {
97
+ const target = path.isAbsolute(publish.readme)
98
+ ? publish.readme
99
+ : path.join(repositoryRoot, publish.readme);
100
+ return readReadme(target, publish.readme);
101
+ }
102
+ const factoryReadme = path.join(factory.dir, "README.md");
103
+ try {
104
+ return await readFile(factoryReadme, "utf8");
105
+ }
106
+ catch (error) {
107
+ if (isAbsentError(error))
108
+ return generateReadme(published, publish);
109
+ throw readError(".factory/README.md", "Check its permissions");
110
+ }
111
+ }
112
+ //# sourceMappingURL=readme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readme.js","sourceRoot":"","sources":["../../../src/core/publish/readme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGzD,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEtF,MAAM,cAAc,GAAG,2BAA2B,CAAC;AAEnD,SAAS,aAAa,CAAC,KAAc;IACnC,MAAM,IAAI,GAAI,KAA2C,EAAE,IAAI,CAAC;IAChE,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,CAAC;AACjD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AC,CAAC;QAC9C,OAAO,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IAC1D,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,aAAa,CAAC,KAAK,CAAC;YAAE,OAAO,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACpE,MAAM,SAAS,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,CAAC;IACjE,CAAC;AACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Factory } from "../factory/index.js";
2
+ import type { StageOptions, StagedFab } from "./types.js";
3
+ /**
4
+ * Copies `.factory/` into a temporary directory for publishing, keeping file
5
+ * modes, without `metafab.yaml`, without `.factory/README.md`, without every
6
+ * `publish.exclude` glob and, when npm is a target, without the names `npm pack`
7
+ * never carries (each one is reported as a warning).
8
+ *
9
+ * The copy follows the fab rules `import` applies, so a fab that would be
10
+ * rejected on the way back in is never published: 1 MB per file, 64 MiB and
11
+ * 10 000 entries in total, and no link that leaves `.factory/`. The staged
12
+ * factory is then validated again, because an exclude can break a reference.
13
+ *
14
+ * A link is checked even when npm would leave its name out, and a publish to the
15
+ * Git target refuses a path Git reads as `.git`, which a fab repository cannot
16
+ * store. Without `targets`, both rules apply, so a caller cannot stage a fab
17
+ * that only one target could carry by accident.
18
+ */
19
+ export declare function stageFab(factory: Factory, options?: StageOptions): Promise<StagedFab>;
@@ -0,0 +1,333 @@
1
+ import { lstat, mkdir, mkdtemp, readdir, realpath, rm, stat } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import path from "node:path";
4
+ import { ExitCode, MetafabError } from "../../errors.js";
5
+ import { copyFileWithMode } from "../../util/fs.js";
6
+ import { isDotGitName } from "../../util/git-names.js";
7
+ import { loadFactory } from "../factory/index.js";
8
+ import { isInsideAbsolute } from "../sources/containment.js";
9
+ import { MAX_FAB_ENTRIES, MAX_FAB_FILE_SIZE, MAX_FAB_TOTAL_SIZE } from "../sources/extract.js";
10
+ import { exclusionMatcher } from "./exclude.js";
11
+ /** Files the fab format forbids inside `.factory/`; see Sharing: Fab layout. */
12
+ const ALWAYS_EXCLUDED = new Set(["metafab.yaml", "README.md"]);
13
+ /**
14
+ * Names npm never packs, even when `files` names the directory they are in:
15
+ * `npm-packlist` applies these rules at every depth. They are left out only
16
+ * when npm is a target, so a two-target publish carries the same files on both
17
+ * and a Git-only publish keeps them; each path left out is reported.
18
+ */
19
+ const NPM_IGNORED_NAMES = new Set([
20
+ ".DS_Store",
21
+ ".gitignore",
22
+ ".lock-wscript",
23
+ ".npmignore",
24
+ ".npmrc",
25
+ "npm-debug.log",
26
+ ]);
27
+ /** Directories npm ignores with everything below them. */
28
+ const NPM_IGNORED_DIRECTORIES = new Set([".git", ".hg", ".svn", "archived-packages", "CVS"]);
29
+ /**
30
+ * The `.git` name `npm pack` already leaves out. npm matches its ignore rules
31
+ * without regard to case, so `.git`, `.GIT` and `.Git` all never reach the
32
+ * tarball. The spellings NTFS and HFS fold to `.git`, and the 8.3 short name,
33
+ * do reach it.
34
+ */
35
+ function npmDropsDotGit(name) {
36
+ return name.toLowerCase() === ".git";
37
+ }
38
+ /**
39
+ * Whether `npm pack` would leave `name` out. The patterns are npm's defaults,
40
+ * matched the way its per-directory walk matches them. `npm-packlist` also
41
+ * ignores `node_modules`, `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`
42
+ * and `bun.lockb`, but only at the package root; staging writes nothing there
43
+ * except `README.md` and `package.json`, so those rules never apply to a fab.
44
+ */
45
+ function npmIgnores(name, parent) {
46
+ if (NPM_IGNORED_NAMES.has(name) || NPM_IGNORED_DIRECTORIES.has(name))
47
+ return true;
48
+ if (name.startsWith("._") || name.startsWith(".wafpickle-"))
49
+ return true;
50
+ if (name.startsWith(".") && name.endsWith(".swp"))
51
+ return true;
52
+ if (name.endsWith(".orig"))
53
+ return true;
54
+ // `/build/config.gypi` is anchored to each directory, as npm's walkers are.
55
+ return parent === "build" && name === "config.gypi";
56
+ }
57
+ function stagingError(message, code, problems, exitCode = ExitCode.Failed) {
58
+ return new MetafabError(message, {
59
+ exitCode,
60
+ code,
61
+ problems,
62
+ });
63
+ }
64
+ function fabProblem(relativePath, message, fix) {
65
+ return {
66
+ level: "error",
67
+ file: relativePath === "" ? ".factory" : `.factory/${relativePath}`,
68
+ line: 1,
69
+ message,
70
+ fix,
71
+ };
72
+ }
73
+ /**
74
+ * npm cannot publish a name it never packs, so staging leaves the path out of
75
+ * the fab instead of failing, and says so: the person asked for the fab, not
76
+ * for that file to disappear.
77
+ */
78
+ function npmIgnoredProblem(relativePath) {
79
+ return {
80
+ level: "warning",
81
+ file: `.factory/${relativePath}`,
82
+ line: 1,
83
+ message: `npm never packs .factory/${relativePath}, so it is left out of the fab`,
84
+ fix: "Rename the path or remove it from .factory/; the name cannot be published",
85
+ };
86
+ }
87
+ /**
88
+ * A workflow that `publish.exclude` removes while the pipeline still names it
89
+ * leaves a fab whose `factory.yaml` points at nothing, so staging stops before
90
+ * it copies a file.
91
+ */
92
+ function excludedWorkflowProblems(factory, isExcluded) {
93
+ const problems = [];
94
+ for (const entry of factory.factoryYaml?.pipeline ?? []) {
95
+ const workflow = factory.skills.find((skill) => skill.isWorkflow && skill.name === entry.workflow);
96
+ if (workflow === undefined)
97
+ continue;
98
+ if (!isExcluded(`${workflow.relDir}/SKILL.md`))
99
+ continue;
100
+ problems.push({
101
+ level: "error",
102
+ file: ".factory/factory.yaml",
103
+ line: entry.line,
104
+ message: `Pipeline names excluded workflow "${entry.workflow}"`,
105
+ fix: `Remove "${workflow.relDir}" from publish.exclude or the workflow from the pipeline`,
106
+ });
107
+ }
108
+ return problems;
109
+ }
110
+ /** Every file, directory and link is one entry, as in an archive import reads. */
111
+ function countEntry(state, relativePath) {
112
+ state.entries += 1;
113
+ if (state.entries <= MAX_FAB_ENTRIES)
114
+ return true;
115
+ state.problems.push(fabProblem(relativePath, `fabs with more than ${MAX_FAB_ENTRIES} files, directories and links are not allowed`, "Add project-only paths to publish.exclude"));
116
+ state.stopped = true;
117
+ return false;
118
+ }
119
+ function fileAllowed(state, relativePath, size) {
120
+ if (size > MAX_FAB_FILE_SIZE) {
121
+ state.problems.push(fabProblem(relativePath, `files larger than ${MAX_FAB_FILE_SIZE} bytes are not allowed in a fab`, "Add the file to publish.exclude, or keep fab files under 1 MB"));
122
+ return false;
123
+ }
124
+ state.totalSize += size;
125
+ if (state.totalSize > MAX_FAB_TOTAL_SIZE) {
126
+ state.problems.push(fabProblem(relativePath, `files larger than ${MAX_FAB_TOTAL_SIZE} bytes in total are not allowed in a fab`, "Add project-only paths to publish.exclude"));
127
+ state.stopped = true;
128
+ return false;
129
+ }
130
+ return true;
131
+ }
132
+ function destinationFor(context, relativePath) {
133
+ return path.join(context.destinationFactory, ...relativePath.split("/"));
134
+ }
135
+ /**
136
+ * Resolves a link, reporting by name the ways a link can leave the fab: it is
137
+ * broken, it points outside `.factory/`, or its target is not a file or
138
+ * directory. Every link is checked this way before staging decides to copy it,
139
+ * so a link npm would drop still cannot pass unnoticed.
140
+ */
141
+ async function resolveLink(linkPath, relativePath, context) {
142
+ let resolved;
143
+ try {
144
+ resolved = await realpath(linkPath);
145
+ }
146
+ catch {
147
+ context.state.problems.push(fabProblem(relativePath, `Symlink .factory/${relativePath} is broken`, "Replace it with a regular file inside .factory/, or remove the symlink"));
148
+ return undefined;
149
+ }
150
+ if (!isInsideAbsolute(context.rootReal, resolved)) {
151
+ context.state.problems.push(fabProblem(relativePath, `Symlink .factory/${relativePath} points outside .factory/`, "Point it inside .factory/, or remove the symlink"));
152
+ return undefined;
153
+ }
154
+ const info = await stat(resolved).catch(() => undefined);
155
+ if (info === undefined) {
156
+ context.state.problems.push(fabProblem(relativePath, `Cannot read the target of symlink .factory/${relativePath}`, "Replace it with a regular file inside .factory/"));
157
+ return undefined;
158
+ }
159
+ if (!info.isFile() && !info.isDirectory()) {
160
+ context.state.problems.push(fabProblem(relativePath, `Symlink .factory/${relativePath} does not point to a file or directory`, "Replace it with a regular file inside .factory/"));
161
+ return undefined;
162
+ }
163
+ return { resolved, info };
164
+ }
165
+ /**
166
+ * A link is published as the content of its target, the same decision `build`
167
+ * makes for a skill. A link that leaves `.factory/` or loops stops the publish
168
+ * by name instead of disappearing from the fab.
169
+ */
170
+ async function copyLink(link, relativePath, context, ancestry) {
171
+ const { resolved, info } = link;
172
+ if (info.isDirectory()) {
173
+ if (ancestry.has(resolved)) {
174
+ context.state.problems.push(fabProblem(relativePath, `Symlink .factory/${relativePath} creates a loop`, "Remove the symlink"));
175
+ return;
176
+ }
177
+ await walkFactory(resolved, relativePath, context, ancestry);
178
+ return;
179
+ }
180
+ if (!fileAllowed(context.state, relativePath, info.size))
181
+ return;
182
+ await copyFileWithMode(resolved, destinationFor(context, relativePath));
183
+ }
184
+ async function walkFactory(directory, prefix, context, ancestry) {
185
+ if (context.state.stopped)
186
+ return;
187
+ let names;
188
+ try {
189
+ names = (await readdir(directory)).sort();
190
+ }
191
+ catch {
192
+ context.state.problems.push(fabProblem(prefix, `Cannot read .factory/${prefix}`, "Check its permissions"));
193
+ return;
194
+ }
195
+ let descendants = ancestry;
196
+ try {
197
+ descendants = new Set([...ancestry, await realpath(directory)]);
198
+ }
199
+ catch {
200
+ // Keep the ancestors we have; the entries below still report their own problems.
201
+ }
202
+ for (const name of names) {
203
+ if (context.state.stopped)
204
+ return;
205
+ const absolute = path.join(directory, name);
206
+ const relativePath = prefix === "" ? name : `${prefix}/${name}`;
207
+ if (context.isExcluded(relativePath))
208
+ continue;
209
+ // Both rules come before the link branch: a link named `README.md` at the
210
+ // factory root leaves the fab too, and `.factory/README.md` may point
211
+ // outside `.factory/` because it is read as the fab README, never copied.
212
+ if (ALWAYS_EXCLUDED.has(relativePath))
213
+ continue;
214
+ const npmDropped = context.npmFilter && (npmIgnores(name, path.basename(prefix)) || npmDropsDotGit(name));
215
+ // Git reads a directory named `.git` as another repository and never adds
216
+ // the files below it. A publish to the Git target refuses such a path by
217
+ // name. An npm-only publish keeps npm's own rule where npm drops the name;
218
+ // every spelling npm would pack but Git would read as `.git` is refused
219
+ // too, so a fab never carries one.
220
+ if (isDotGitName(name) && !(npmDropped && !context.gitTarget)) {
221
+ context.state.problems.push(fabProblem(relativePath, `Git cannot store .factory/${relativePath} in a fab`, "Rename the path or add it to publish.exclude"));
222
+ continue;
223
+ }
224
+ const info = await lstat(absolute).catch(() => undefined);
225
+ if (info === undefined) {
226
+ context.state.problems.push(fabProblem(relativePath, `Cannot read .factory/${relativePath}`, "Check its permissions"));
227
+ continue;
228
+ }
229
+ if (info.isSymbolicLink()) {
230
+ // The link is checked before the npm drop: a broken or escaping link
231
+ // stops the publish even when its name is one npm never packs.
232
+ const link = await resolveLink(absolute, relativePath, context);
233
+ if (link === undefined)
234
+ continue;
235
+ if (npmDropped) {
236
+ context.state.warnings.push(npmIgnoredProblem(relativePath));
237
+ continue;
238
+ }
239
+ if (!countEntry(context.state, relativePath))
240
+ return;
241
+ await copyLink(link, relativePath, context, descendants);
242
+ continue;
243
+ }
244
+ if (npmDropped) {
245
+ context.state.warnings.push(npmIgnoredProblem(relativePath));
246
+ continue;
247
+ }
248
+ if (info.isDirectory()) {
249
+ if (!countEntry(context.state, relativePath))
250
+ return;
251
+ await walkFactory(absolute, relativePath, context, descendants);
252
+ continue;
253
+ }
254
+ if (info.isFile()) {
255
+ if (!countEntry(context.state, relativePath))
256
+ return;
257
+ if (!fileAllowed(context.state, relativePath, info.size))
258
+ return;
259
+ await copyFileWithMode(absolute, destinationFor(context, relativePath));
260
+ continue;
261
+ }
262
+ context.state.problems.push(fabProblem(relativePath, `device files and FIFOs are not allowed in a fab`, "Remove it from .factory/"));
263
+ }
264
+ }
265
+ /**
266
+ * Copies `.factory/` into a temporary directory for publishing, keeping file
267
+ * modes, without `metafab.yaml`, without `.factory/README.md`, without every
268
+ * `publish.exclude` glob and, when npm is a target, without the names `npm pack`
269
+ * never carries (each one is reported as a warning).
270
+ *
271
+ * The copy follows the fab rules `import` applies, so a fab that would be
272
+ * rejected on the way back in is never published: 1 MB per file, 64 MiB and
273
+ * 10 000 entries in total, and no link that leaves `.factory/`. The staged
274
+ * factory is then validated again, because an exclude can break a reference.
275
+ *
276
+ * A link is checked even when npm would leave its name out, and a publish to the
277
+ * Git target refuses a path Git reads as `.git`, which a fab repository cannot
278
+ * store. Without `targets`, both rules apply, so a caller cannot stage a fab
279
+ * that only one target could carry by accident.
280
+ */
281
+ export async function stageFab(factory, options = {}) {
282
+ const isExcluded = exclusionMatcher(options.exclude ?? []);
283
+ const targets = options.targets ?? ["npm", "git"];
284
+ const npmFilter = targets.includes("npm");
285
+ const gitTarget = targets.includes("git");
286
+ const problems = excludedWorkflowProblems(factory, isExcluded);
287
+ if (problems.length > 0) {
288
+ throw stagingError("The fab would lose a workflow that the pipeline names.", "publish-excluded-workflow", problems);
289
+ }
290
+ const root = await mkdtemp(path.join(tmpdir(), "metafab-publish-"));
291
+ const factoryDir = path.join(root, ".factory");
292
+ try {
293
+ await mkdir(factoryDir, { recursive: true });
294
+ const rootReal = await realpath(factory.dir).catch(() => undefined);
295
+ if (rootReal === undefined) {
296
+ throw stagingError("Cannot read the factory directory.", "publish-invalid-fab", [
297
+ fabProblem("", "Cannot resolve the .factory directory", "Restore the .factory directory"),
298
+ ], ExitCode.InvalidFab);
299
+ }
300
+ const state = {
301
+ problems: [],
302
+ warnings: [],
303
+ entries: 0,
304
+ totalSize: 0,
305
+ stopped: false,
306
+ };
307
+ await walkFactory(factory.dir, "", { isExcluded, npmFilter, gitTarget, destinationFactory: factoryDir, rootReal, state }, new Set([rootReal]));
308
+ // An exclude can empty `.factory/` or break a reference; import would
309
+ // reject such a fab, so publish refuses to build it.
310
+ if ((await readdir(factoryDir)).length === 0) {
311
+ state.problems.push(fabProblem("", "The fab has no files in .factory/", "Remove the publish.exclude entries that leave .factory/ empty"));
312
+ }
313
+ const staged = await loadFactory(root);
314
+ const errors = [...state.problems, ...staged.problems].filter((problem) => problem.level === "error");
315
+ if (errors.length > 0) {
316
+ // A staged fab that breaks the fab rules is an invalid fab, as import
317
+ // reports it (exit 4), not a validation failure of the repository.
318
+ throw stagingError("The fab does not follow the fab rules.", "publish-invalid-fab", errors, ExitCode.InvalidFab);
319
+ }
320
+ return {
321
+ root,
322
+ factoryDir,
323
+ factory: staged,
324
+ warnings: state.warnings,
325
+ cleanup: () => rm(root, { recursive: true, force: true }),
326
+ };
327
+ }
328
+ catch (error) {
329
+ await rm(root, { recursive: true, force: true });
330
+ throw error;
331
+ }
332
+ }
333
+ //# sourceMappingURL=stage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stage.js","sourceRoot":"","sources":["../../../src/core/publish/stage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEtF,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC/F,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,gFAAgF;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C;YACtB,sEAAsE;YACtE,mEAAmE;YACnE,MAAM,YAAY,CAChB,wCAAwC,EACxC,qBAAqB,EACrB,MAAM,EACN,QAAQ,CAAC,UAAU,CACpB,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI;YACJ,UAAU;YACV,OAAO,EAAE,MAAM;YACf,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;SAC1D,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { ExitCode } from "../../errors.js";
2
+ import type { Problem } from "../../errors.js";
3
+ import type { Factory } from "../factory/index.js";
4
+ /** A configured `publish` target: an npm package or a Git fab repository. */
5
+ export type PublishTargetName = "npm" | "git";
6
+ /** What a publish reports before it publishes: the fab files, their size and the targets. */
7
+ export interface PublishReport {
8
+ /** Every fab file, relative to the fab root, in sorted order. */
9
+ files: string[];
10
+ /** Total size of `files` in bytes. */
11
+ size: number;
12
+ targets: PublishTargetName[];
13
+ }
14
+ /** A `.factory/` copied into a temporary fab directory. */
15
+ export interface StagedFab {
16
+ /** The temporary fab root. Remove it with `cleanup`. */
17
+ root: string;
18
+ /** `<root>/.factory`, the factory the fab carries. */
19
+ factoryDir: string;
20
+ /** The staged factory, which is what the fab publishes. */
21
+ factory: Factory;
22
+ /** Paths staging left out that the person did not ask it to, as warnings. */
23
+ warnings: Problem[];
24
+ cleanup(): Promise<void>;
25
+ }
26
+ /** A staged fab that is ready to publish: README, `package.json` and the report data. */
27
+ export interface PreparedFab extends StagedFab, PublishReport {
28
+ }
29
+ export interface StageOptions {
30
+ /** `publish.exclude` globs, relative to `.factory/`. */
31
+ exclude?: readonly string[];
32
+ /**
33
+ * The targets being published. The names npm never packs are left out only
34
+ * when npm is one of them, so a Git-only fab keeps those files. A publish to
35
+ * the Git target also refuses a path Git reads as `.git`, which a fab
36
+ * repository cannot store. Defaults to both targets, the safest pair of rules.
37
+ */
38
+ targets?: readonly PublishTargetName[];
39
+ }
40
+ /** How one target ended: published now, already published with the same content, or failed. */
41
+ export type PublishStatus = "published" | "skipped" | "failed";
42
+ export interface PublishTargetResult {
43
+ target: PublishTargetName;
44
+ status: PublishStatus;
45
+ /** One line for the report; a failure detail is never a stack trace. */
46
+ detail: string;
47
+ }
48
+ export interface PublishResult {
49
+ version: string;
50
+ /** One entry per configured target, in `PreparedFab.targets` order. */
51
+ targets: PublishTargetResult[];
52
+ /** Problems the failed target reported by name, such as the paths Git lost. */
53
+ problems?: Problem[];
54
+ /** The exit code the failed target asked for, which the command reports. */
55
+ exitCode?: ExitCode;
56
+ }
57
+ export interface PublishOptions {
58
+ /** npm dist-tag from `--tag`. The Git target ignores it. */
59
+ tag?: string;
60
+ /** `--json` is present. It never enables a Git credential prompt. */
61
+ json?: boolean;
62
+ /** Defaults to `process.env`. */
63
+ env?: NodeJS.ProcessEnv;
64
+ /** Receives npm's output as it is produced. Defaults to `process.stderr`. */
65
+ stderr?: (text: string) => void;
66
+ /**
67
+ * Whether Git may prompt for a credential. Defaults to a terminal standard
68
+ * input with no `--json`, as `import` does.
69
+ */
70
+ interactive?: boolean;
71
+ }
@@ -0,0 +1,2 @@
1
+ import { ExitCode } from "../../errors.js";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/publish/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Problem } from "../../errors.js";
2
+ import type { Factory } from "../factory/types.js";
3
+ /**
4
+ * Warnings for the repository files a factory requires. A missing file is the
5
+ * person's to create, and an entry in the way is theirs to move, so neither is
6
+ * an error: the factory itself is valid, and a repository may choose not to
7
+ * create a file. A present file says nothing, with or without a template;
8
+ * whether it holds what the fab needs is the person's call.
9
+ *
10
+ * An entry that rule 12 or 13 already rejected is skipped: rule 12's path
11
+ * shape, rule 12's uniqueness and nesting (the later repeat or nested entry),
12
+ * and rule 13's template checks are errors with their own fix, and a warning
13
+ * telling the person to create the file would contradict them.
14
+ */
15
+ export declare function requirementWarnings(factory: Factory): Promise<Problem[]>;