@seasb/metafab 0.0.1 → 2.0.0-next.1

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 (414) hide show
  1. package/README.md +46 -1
  2. package/dist/cli.d.ts +11 -0
  3. package/dist/cli.js +419 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/commands/build.d.ts +31 -0
  6. package/dist/commands/build.js +156 -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 +52 -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 +75 -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/env.d.ts +4 -0
  21. package/dist/commands/env.js +362 -0
  22. package/dist/commands/env.js.map +1 -0
  23. package/dist/commands/import.d.ts +2 -0
  24. package/dist/commands/import.js +107 -0
  25. package/dist/commands/import.js.map +1 -0
  26. package/dist/commands/init.d.ts +2 -0
  27. package/dist/commands/init.js +77 -0
  28. package/dist/commands/init.js.map +1 -0
  29. package/dist/commands/map.d.ts +2 -0
  30. package/dist/commands/map.js +42 -0
  31. package/dist/commands/map.js.map +1 -0
  32. package/dist/commands/pipeline-add.d.ts +2 -0
  33. package/dist/commands/pipeline-add.js +68 -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 +45 -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 +153 -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 +26 -0
  51. package/dist/core/build/agents.js +67 -0
  52. package/dist/core/build/agents.js.map +1 -0
  53. package/dist/core/build/index.d.ts +5 -0
  54. package/dist/core/build/index.js +6 -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 +82 -0
  60. package/dist/core/build/plan.js +912 -0
  61. package/dist/core/build/plan.js.map +1 -0
  62. package/dist/core/build/preview.d.ts +39 -0
  63. package/dist/core/build/preview.js +344 -0
  64. package/dist/core/build/preview.js.map +1 -0
  65. package/dist/core/build/skill.d.ts +99 -0
  66. package/dist/core/build/skill.js +354 -0
  67. package/dist/core/build/skill.js.map +1 -0
  68. package/dist/core/check/drift.d.ts +13 -0
  69. package/dist/core/check/drift.js +205 -0
  70. package/dist/core/check/drift.js.map +1 -0
  71. package/dist/core/check/index.d.ts +16 -0
  72. package/dist/core/check/index.js +84 -0
  73. package/dist/core/check/index.js.map +1 -0
  74. package/dist/core/check/markers.d.ts +9 -0
  75. package/dist/core/check/markers.js +220 -0
  76. package/dist/core/check/markers.js.map +1 -0
  77. package/dist/core/config/destinations.d.ts +5 -0
  78. package/dist/core/config/destinations.js +20 -0
  79. package/dist/core/config/destinations.js.map +1 -0
  80. package/dist/core/config/load.d.ts +4 -0
  81. package/dist/core/config/load.js +41 -0
  82. package/dist/core/config/load.js.map +1 -0
  83. package/dist/core/config/parse.d.ts +8 -0
  84. package/dist/core/config/parse.js +201 -0
  85. package/dist/core/config/parse.js.map +1 -0
  86. package/dist/core/config/source.d.ts +25 -0
  87. package/dist/core/config/source.js +67 -0
  88. package/dist/core/config/source.js.map +1 -0
  89. package/dist/core/config/types.d.ts +48 -0
  90. package/dist/core/config/types.js +2 -0
  91. package/dist/core/config/types.js.map +1 -0
  92. package/dist/core/config/validate.d.ts +11 -0
  93. package/dist/core/config/validate.js +389 -0
  94. package/dist/core/config/validate.js.map +1 -0
  95. package/dist/core/config/writers.d.ts +14 -0
  96. package/dist/core/config/writers.js +269 -0
  97. package/dist/core/config/writers.js.map +1 -0
  98. package/dist/core/config.d.ts +7 -0
  99. package/dist/core/config.js +8 -0
  100. package/dist/core/config.js.map +1 -0
  101. package/dist/core/discovery.d.ts +34 -0
  102. package/dist/core/discovery.js +272 -0
  103. package/dist/core/discovery.js.map +1 -0
  104. package/dist/core/edit/create.d.ts +18 -0
  105. package/dist/core/edit/create.js +190 -0
  106. package/dist/core/edit/create.js.map +1 -0
  107. package/dist/core/edit/document.d.ts +4 -0
  108. package/dist/core/edit/document.js +16 -0
  109. package/dist/core/edit/document.js.map +1 -0
  110. package/dist/core/edit/factory-yaml.d.ts +17 -0
  111. package/dist/core/edit/factory-yaml.js +213 -0
  112. package/dist/core/edit/factory-yaml.js.map +1 -0
  113. package/dist/core/edit/files.d.ts +6 -0
  114. package/dist/core/edit/files.js +47 -0
  115. package/dist/core/edit/files.js.map +1 -0
  116. package/dist/core/edit/index.d.ts +9 -0
  117. package/dist/core/edit/index.js +10 -0
  118. package/dist/core/edit/index.js.map +1 -0
  119. package/dist/core/edit/map.d.ts +24 -0
  120. package/dist/core/edit/map.js +82 -0
  121. package/dist/core/edit/map.js.map +1 -0
  122. package/dist/core/edit/names.d.ts +2 -0
  123. package/dist/core/edit/names.js +17 -0
  124. package/dist/core/edit/names.js.map +1 -0
  125. package/dist/core/edit/paths.d.ts +8 -0
  126. package/dist/core/edit/paths.js +81 -0
  127. package/dist/core/edit/paths.js.map +1 -0
  128. package/dist/core/edit/pipeline.d.ts +19 -0
  129. package/dist/core/edit/pipeline.js +152 -0
  130. package/dist/core/edit/pipeline.js.map +1 -0
  131. package/dist/core/edit/skill.d.ts +1 -0
  132. package/dist/core/edit/skill.js +10 -0
  133. package/dist/core/edit/skill.js.map +1 -0
  134. package/dist/core/env/condition.d.ts +40 -0
  135. package/dist/core/env/condition.js +283 -0
  136. package/dist/core/env/condition.js.map +1 -0
  137. package/dist/core/env/declarations.d.ts +16 -0
  138. package/dist/core/env/declarations.js +328 -0
  139. package/dist/core/env/declarations.js.map +1 -0
  140. package/dist/core/env/directives.d.ts +75 -0
  141. package/dist/core/env/directives.js +429 -0
  142. package/dist/core/env/directives.js.map +1 -0
  143. package/dist/core/env/git-config.d.ts +15 -0
  144. package/dist/core/env/git-config.js +110 -0
  145. package/dist/core/env/git-config.js.map +1 -0
  146. package/dist/core/env/imports.d.ts +60 -0
  147. package/dist/core/env/imports.js +217 -0
  148. package/dist/core/env/imports.js.map +1 -0
  149. package/dist/core/env/index.d.ts +6 -0
  150. package/dist/core/env/index.js +7 -0
  151. package/dist/core/env/index.js.map +1 -0
  152. package/dist/core/env/markdown.d.ts +22 -0
  153. package/dist/core/env/markdown.js +33 -0
  154. package/dist/core/env/markdown.js.map +1 -0
  155. package/dist/core/env/render.d.ts +13 -0
  156. package/dist/core/env/render.js +65 -0
  157. package/dist/core/env/render.js.map +1 -0
  158. package/dist/core/env/report.d.ts +29 -0
  159. package/dist/core/env/report.js +39 -0
  160. package/dist/core/env/report.js.map +1 -0
  161. package/dist/core/env/scenarios.d.ts +40 -0
  162. package/dist/core/env/scenarios.js +124 -0
  163. package/dist/core/env/scenarios.js.map +1 -0
  164. package/dist/core/env/select.d.ts +30 -0
  165. package/dist/core/env/select.js +191 -0
  166. package/dist/core/env/select.js.map +1 -0
  167. package/dist/core/env/types.d.ts +38 -0
  168. package/dist/core/env/types.js +2 -0
  169. package/dist/core/env/types.js.map +1 -0
  170. package/dist/core/env/validate.d.ts +25 -0
  171. package/dist/core/env/validate.js +212 -0
  172. package/dist/core/env/validate.js.map +1 -0
  173. package/dist/core/factory/discovery.d.ts +9 -0
  174. package/dist/core/factory/discovery.js +139 -0
  175. package/dist/core/factory/discovery.js.map +1 -0
  176. package/dist/core/factory/factory-yaml.d.ts +29 -0
  177. package/dist/core/factory/factory-yaml.js +538 -0
  178. package/dist/core/factory/factory-yaml.js.map +1 -0
  179. package/dist/core/factory/index.d.ts +5 -0
  180. package/dist/core/factory/index.js +6 -0
  181. package/dist/core/factory/index.js.map +1 -0
  182. package/dist/core/factory/lines.d.ts +8 -0
  183. package/dist/core/factory/lines.js +11 -0
  184. package/dist/core/factory/lines.js.map +1 -0
  185. package/dist/core/factory/load.d.ts +4 -0
  186. package/dist/core/factory/load.js +83 -0
  187. package/dist/core/factory/load.js.map +1 -0
  188. package/dist/core/factory/requires.d.ts +9 -0
  189. package/dist/core/factory/requires.js +123 -0
  190. package/dist/core/factory/requires.js.map +1 -0
  191. package/dist/core/factory/types.d.ts +58 -0
  192. package/dist/core/factory/types.js +2 -0
  193. package/dist/core/factory/types.js.map +1 -0
  194. package/dist/core/factory/validate.d.ts +44 -0
  195. package/dist/core/factory/validate.js +460 -0
  196. package/dist/core/factory/validate.js.map +1 -0
  197. package/dist/core/hooks/index.d.ts +8 -0
  198. package/dist/core/hooks/index.js +15 -0
  199. package/dist/core/hooks/index.js.map +1 -0
  200. package/dist/core/hooks/script.d.ts +21 -0
  201. package/dist/core/hooks/script.js +34 -0
  202. package/dist/core/hooks/script.js.map +1 -0
  203. package/dist/core/hooks/sync.d.ts +17 -0
  204. package/dist/core/hooks/sync.js +262 -0
  205. package/dist/core/hooks/sync.js.map +1 -0
  206. package/dist/core/import/conflicts.d.ts +82 -0
  207. package/dist/core/import/conflicts.js +256 -0
  208. package/dist/core/import/conflicts.js.map +1 -0
  209. package/dist/core/import/copy.d.ts +10 -0
  210. package/dist/core/import/copy.js +76 -0
  211. package/dist/core/import/copy.js.map +1 -0
  212. package/dist/core/import/file-tree.d.ts +43 -0
  213. package/dist/core/import/file-tree.js +107 -0
  214. package/dist/core/import/file-tree.js.map +1 -0
  215. package/dist/core/import/index.d.ts +5 -0
  216. package/dist/core/import/index.js +6 -0
  217. package/dist/core/import/index.js.map +1 -0
  218. package/dist/core/import/pipeline-changes.d.ts +8 -0
  219. package/dist/core/import/pipeline-changes.js +89 -0
  220. package/dist/core/import/pipeline-changes.js.map +1 -0
  221. package/dist/core/import/run.d.ts +76 -0
  222. package/dist/core/import/run.js +275 -0
  223. package/dist/core/import/run.js.map +1 -0
  224. package/dist/core/init/gitattributes.d.ts +20 -0
  225. package/dist/core/init/gitattributes.js +89 -0
  226. package/dist/core/init/gitattributes.js.map +1 -0
  227. package/dist/core/init/index.d.ts +4 -0
  228. package/dist/core/init/index.js +5 -0
  229. package/dist/core/init/index.js.map +1 -0
  230. package/dist/core/init/name.d.ts +1 -0
  231. package/dist/core/init/name.js +4 -0
  232. package/dist/core/init/name.js.map +1 -0
  233. package/dist/core/init/run.d.ts +51 -0
  234. package/dist/core/init/run.js +261 -0
  235. package/dist/core/init/run.js.map +1 -0
  236. package/dist/core/init/targets.d.ts +17 -0
  237. package/dist/core/init/targets.js +87 -0
  238. package/dist/core/init/targets.js.map +1 -0
  239. package/dist/core/merge.d.ts +88 -0
  240. package/dist/core/merge.js +239 -0
  241. package/dist/core/merge.js.map +1 -0
  242. package/dist/core/publish/exclude.d.ts +9 -0
  243. package/dist/core/publish/exclude.js +32 -0
  244. package/dist/core/publish/exclude.js.map +1 -0
  245. package/dist/core/publish/git-target.d.ts +32 -0
  246. package/dist/core/publish/git-target.js +460 -0
  247. package/dist/core/publish/git-target.js.map +1 -0
  248. package/dist/core/publish/index.d.ts +10 -0
  249. package/dist/core/publish/index.js +11 -0
  250. package/dist/core/publish/index.js.map +1 -0
  251. package/dist/core/publish/npm-target.d.ts +15 -0
  252. package/dist/core/publish/npm-target.js +177 -0
  253. package/dist/core/publish/npm-target.js.map +1 -0
  254. package/dist/core/publish/package-json.d.ts +31 -0
  255. package/dist/core/publish/package-json.js +74 -0
  256. package/dist/core/publish/package-json.js.map +1 -0
  257. package/dist/core/publish/prepare.d.ts +35 -0
  258. package/dist/core/publish/prepare.js +102 -0
  259. package/dist/core/publish/prepare.js.map +1 -0
  260. package/dist/core/publish/provenance.d.ts +1 -0
  261. package/dist/core/publish/provenance.js +20 -0
  262. package/dist/core/publish/provenance.js.map +1 -0
  263. package/dist/core/publish/publish.d.ts +13 -0
  264. package/dist/core/publish/publish.js +143 -0
  265. package/dist/core/publish/publish.js.map +1 -0
  266. package/dist/core/publish/readme.d.ts +22 -0
  267. package/dist/core/publish/readme.js +109 -0
  268. package/dist/core/publish/readme.js.map +1 -0
  269. package/dist/core/publish/stage.d.ts +19 -0
  270. package/dist/core/publish/stage.js +333 -0
  271. package/dist/core/publish/stage.js.map +1 -0
  272. package/dist/core/publish/types.d.ts +71 -0
  273. package/dist/core/publish/types.js +2 -0
  274. package/dist/core/publish/types.js.map +1 -0
  275. package/dist/core/requires/check.d.ts +15 -0
  276. package/dist/core/requires/check.js +83 -0
  277. package/dist/core/requires/check.js.map +1 -0
  278. package/dist/core/requires/index.d.ts +4 -0
  279. package/dist/core/requires/index.js +5 -0
  280. package/dist/core/requires/index.js.map +1 -0
  281. package/dist/core/requires/inspect.d.ts +44 -0
  282. package/dist/core/requires/inspect.js +114 -0
  283. package/dist/core/requires/inspect.js.map +1 -0
  284. package/dist/core/requires/paths.d.ts +29 -0
  285. package/dist/core/requires/paths.js +83 -0
  286. package/dist/core/requires/paths.js.map +1 -0
  287. package/dist/core/requires/setup.d.ts +37 -0
  288. package/dist/core/requires/setup.js +147 -0
  289. package/dist/core/requires/setup.js.map +1 -0
  290. package/dist/core/setup.d.ts +27 -0
  291. package/dist/core/setup.js +84 -0
  292. package/dist/core/setup.js.map +1 -0
  293. package/dist/core/sources/cache.d.ts +38 -0
  294. package/dist/core/sources/cache.js +264 -0
  295. package/dist/core/sources/cache.js.map +1 -0
  296. package/dist/core/sources/containment.d.ts +21 -0
  297. package/dist/core/sources/containment.js +50 -0
  298. package/dist/core/sources/containment.js.map +1 -0
  299. package/dist/core/sources/env.d.ts +12 -0
  300. package/dist/core/sources/env.js +28 -0
  301. package/dist/core/sources/env.js.map +1 -0
  302. package/dist/core/sources/extract.d.ts +25 -0
  303. package/dist/core/sources/extract.js +639 -0
  304. package/dist/core/sources/extract.js.map +1 -0
  305. package/dist/core/sources/git-process.d.ts +26 -0
  306. package/dist/core/sources/git-process.js +51 -0
  307. package/dist/core/sources/git-process.js.map +1 -0
  308. package/dist/core/sources/git.d.ts +41 -0
  309. package/dist/core/sources/git.js +525 -0
  310. package/dist/core/sources/git.js.map +1 -0
  311. package/dist/core/sources/https.d.ts +21 -0
  312. package/dist/core/sources/https.js +218 -0
  313. package/dist/core/sources/https.js.map +1 -0
  314. package/dist/core/sources/index.d.ts +13 -0
  315. package/dist/core/sources/index.js +14 -0
  316. package/dist/core/sources/index.js.map +1 -0
  317. package/dist/core/sources/npm-cli.d.ts +19 -0
  318. package/dist/core/sources/npm-cli.js +51 -0
  319. package/dist/core/sources/npm-cli.js.map +1 -0
  320. package/dist/core/sources/npm.d.ts +29 -0
  321. package/dist/core/sources/npm.js +411 -0
  322. package/dist/core/sources/npm.js.map +1 -0
  323. package/dist/core/sources/parse.d.ts +46 -0
  324. package/dist/core/sources/parse.js +446 -0
  325. package/dist/core/sources/parse.js.map +1 -0
  326. package/dist/core/sources/path.d.ts +10 -0
  327. package/dist/core/sources/path.js +331 -0
  328. package/dist/core/sources/path.js.map +1 -0
  329. package/dist/core/sources/problems.d.ts +29 -0
  330. package/dist/core/sources/problems.js +36 -0
  331. package/dist/core/sources/problems.js.map +1 -0
  332. package/dist/core/sources/redact.d.ts +2 -0
  333. package/dist/core/sources/redact.js +70 -0
  334. package/dist/core/sources/redact.js.map +1 -0
  335. package/dist/core/sources/resolve.d.ts +9 -0
  336. package/dist/core/sources/resolve.js +29 -0
  337. package/dist/core/sources/resolve.js.map +1 -0
  338. package/dist/core/sources/types.d.ts +86 -0
  339. package/dist/core/sources/types.js +2 -0
  340. package/dist/core/sources/types.js.map +1 -0
  341. package/dist/core/sources/validate.d.ts +9 -0
  342. package/dist/core/sources/validate.js +116 -0
  343. package/dist/core/sources/validate.js.map +1 -0
  344. package/dist/core/summary.d.ts +79 -0
  345. package/dist/core/summary.js +411 -0
  346. package/dist/core/summary.js.map +1 -0
  347. package/dist/core/update/clashes.d.ts +63 -0
  348. package/dist/core/update/clashes.js +192 -0
  349. package/dist/core/update/clashes.js.map +1 -0
  350. package/dist/core/update/detach.d.ts +21 -0
  351. package/dist/core/update/detach.js +38 -0
  352. package/dist/core/update/detach.js.map +1 -0
  353. package/dist/core/update/diff.d.ts +58 -0
  354. package/dist/core/update/diff.js +180 -0
  355. package/dist/core/update/diff.js.map +1 -0
  356. package/dist/core/update/fetch.d.ts +34 -0
  357. package/dist/core/update/fetch.js +73 -0
  358. package/dist/core/update/fetch.js.map +1 -0
  359. package/dist/core/update/index.d.ts +6 -0
  360. package/dist/core/update/index.js +7 -0
  361. package/dist/core/update/index.js.map +1 -0
  362. package/dist/core/update/restore.d.ts +20 -0
  363. package/dist/core/update/restore.js +195 -0
  364. package/dist/core/update/restore.js.map +1 -0
  365. package/dist/core/update/run.d.ts +113 -0
  366. package/dist/core/update/run.js +1135 -0
  367. package/dist/core/update/run.js.map +1 -0
  368. package/dist/core/update/select.d.ts +39 -0
  369. package/dist/core/update/select.js +157 -0
  370. package/dist/core/update/select.js.map +1 -0
  371. package/dist/core/update/spelling.d.ts +51 -0
  372. package/dist/core/update/spelling.js +185 -0
  373. package/dist/core/update/spelling.js.map +1 -0
  374. package/dist/core/update/trees.d.ts +24 -0
  375. package/dist/core/update/trees.js +72 -0
  376. package/dist/core/update/trees.js.map +1 -0
  377. package/dist/errors.d.ts +39 -0
  378. package/dist/errors.js +24 -0
  379. package/dist/errors.js.map +1 -0
  380. package/dist/help.d.ts +51 -0
  381. package/dist/help.js +117 -0
  382. package/dist/help.js.map +1 -0
  383. package/dist/input.d.ts +25 -0
  384. package/dist/input.js +174 -0
  385. package/dist/input.js.map +1 -0
  386. package/dist/output.d.ts +21 -0
  387. package/dist/output.js +37 -0
  388. package/dist/output.js.map +1 -0
  389. package/dist/util/frontmatter.d.ts +12 -0
  390. package/dist/util/frontmatter.js +58 -0
  391. package/dist/util/frontmatter.js.map +1 -0
  392. package/dist/util/fs.d.ts +38 -0
  393. package/dist/util/fs.js +135 -0
  394. package/dist/util/fs.js.map +1 -0
  395. package/dist/util/git-names.d.ts +8 -0
  396. package/dist/util/git-names.js +25 -0
  397. package/dist/util/git-names.js.map +1 -0
  398. package/dist/util/git.d.ts +12 -0
  399. package/dist/util/git.js +33 -0
  400. package/dist/util/git.js.map +1 -0
  401. package/dist/util/suggest.d.ts +6 -0
  402. package/dist/util/suggest.js +48 -0
  403. package/dist/util/suggest.js.map +1 -0
  404. package/dist/util/text.d.ts +8 -0
  405. package/dist/util/text.js +19 -0
  406. package/dist/util/text.js.map +1 -0
  407. package/dist/util/version.d.ts +7 -0
  408. package/dist/util/version.js +13 -0
  409. package/dist/util/version.js.map +1 -0
  410. package/dist/util/yaml.d.ts +30 -0
  411. package/dist/util/yaml.js +201 -0
  412. package/dist/util/yaml.js.map +1 -0
  413. package/package.json +51 -3
  414. package/resources/metafab-skill/SKILL.md +173 -0
@@ -0,0 +1,177 @@
1
+ import { execFile } from "node:child_process";
2
+ import { ExitCode, MetafabError } from "../../errors.js";
3
+ import { npmInvocation } from "../sources/npm-cli.js";
4
+ import { redact } from "../sources/redact.js";
5
+ import { PUBLISH_RETRY_FIX, publishProblem } from "./prepare.js";
6
+ import { provenanceEnabled } from "./provenance.js";
7
+ const MAX_OUTPUT = 32 * 1024 * 1024;
8
+ function npmMessage(failure) {
9
+ const raw = (failure.stderr ?? "").trim() || (failure.stdout ?? "").trim() || failure.message || "";
10
+ const lines = raw
11
+ .split("\n")
12
+ .map((line) => line.replace(/^npm (?:error|notice) /i, "").trimEnd())
13
+ .filter((line) => line !== "" && !line.startsWith("A complete log of this run can be found"));
14
+ return lines.join("\n") || "npm failed";
15
+ }
16
+ function publishError(message, code, exitCode, cause, fix = PUBLISH_RETRY_FIX) {
17
+ const text = redact(message);
18
+ return new MetafabError(text, {
19
+ exitCode,
20
+ code,
21
+ cause,
22
+ problems: [publishProblem(text, fix)],
23
+ });
24
+ }
25
+ function notFound(result) {
26
+ const output = `${result.stderr}\n${result.stdout}`;
27
+ return /\bE404\b|404 Not Found/i.test(output);
28
+ }
29
+ async function tryNpm(args, env) {
30
+ const npm = await npmInvocation({ env });
31
+ try {
32
+ const { stdout, stderr } = await new Promise((resolve, reject) => {
33
+ execFile(npm.command, [...npm.args, ...args], { env, encoding: "utf8", maxBuffer: MAX_OUTPUT, windowsHide: true }, (error, stdout, stderr) => {
34
+ if (error === null)
35
+ resolve({ stdout, stderr });
36
+ else
37
+ reject(Object.assign(error, { stdout, stderr }));
38
+ });
39
+ });
40
+ return { ok: true, stdout, stderr };
41
+ }
42
+ catch (error) {
43
+ const failure = error;
44
+ return {
45
+ ok: false,
46
+ stdout: failure.stdout ?? "",
47
+ stderr: failure.stderr ?? failure.message ?? "",
48
+ };
49
+ }
50
+ }
51
+ function isRecord(value) {
52
+ return typeof value === "object" && value !== null && !Array.isArray(value);
53
+ }
54
+ function parseJson(value, context) {
55
+ try {
56
+ return JSON.parse(value);
57
+ }
58
+ catch (error) {
59
+ throw publishError(`${context}: npm returned invalid JSON`, "publish-npm-invalid-json", ExitCode.Failed, error);
60
+ }
61
+ }
62
+ function manifestHashes(dist) {
63
+ return {
64
+ ...(typeof dist.integrity === "string" && dist.integrity !== ""
65
+ ? { integrity: dist.integrity }
66
+ : {}),
67
+ ...(typeof dist.shasum === "string" && dist.shasum !== "" ? { shasum: dist.shasum } : {}),
68
+ };
69
+ }
70
+ async function packedHashes(root, env) {
71
+ const context = "Cannot pack the fab for the npm target";
72
+ const result = await tryNpm(["pack", root, "--dry-run", "--json", "--ignore-scripts"], env);
73
+ if (!result.ok) {
74
+ throw publishError(`${context}: ${npmMessage(result)}`, "publish-npm-failed", ExitCode.Failed);
75
+ }
76
+ const parsed = parseJson(result.stdout, context);
77
+ const manifest = Array.isArray(parsed) ? parsed[0] : undefined;
78
+ if (!isRecord(manifest)) {
79
+ throw publishError(`${context}: npm pack returned no package`, "publish-npm-failed", ExitCode.Failed);
80
+ }
81
+ return {
82
+ ...(typeof manifest.integrity === "string" ? { integrity: manifest.integrity } : {}),
83
+ ...(typeof manifest.shasum === "string" ? { shasum: manifest.shasum } : {}),
84
+ };
85
+ }
86
+ async function publishedHashes(name, version, env) {
87
+ const context = `Cannot read npm package "${name}@${version}"`;
88
+ const result = await tryNpm(["view", `${name}@${version}`, "--json"], env);
89
+ if (!result.ok) {
90
+ throw publishError(`${context}: ${npmMessage(result)}`, "publish-npm-failed", ExitCode.FetchFailed);
91
+ }
92
+ const parsed = parseJson(result.stdout, context);
93
+ if (!isRecord(parsed) || !isRecord(parsed.dist)) {
94
+ throw publishError(`${context}: npm returned an unexpected response`, "publish-npm-failed", ExitCode.Failed);
95
+ }
96
+ return manifestHashes(parsed.dist);
97
+ }
98
+ function sameContent(published, packed) {
99
+ // Integrity covers the tarball bytes that the registry stores. A registry
100
+ // that reports only a SHA-1 shasum is compared on that instead.
101
+ if (published.integrity !== undefined)
102
+ return published.integrity === packed.integrity;
103
+ if (published.shasum !== undefined)
104
+ return published.shasum === packed.shasum;
105
+ // Nothing to compare with: an existing version can never be proven identical.
106
+ return false;
107
+ }
108
+ /**
109
+ * Whether `name@version` is on the registry, and if so whether it carries the
110
+ * same tarball as the staged fab would. A 404 means the version is new.
111
+ */
112
+ export async function npmVersionState(publish, version, root, options = {}) {
113
+ if (publish.name === undefined) {
114
+ throw publishError("The npm target requires publish.name.", "publish-missing-setting", ExitCode.Failed, undefined, 'Add "name" to "publish"');
115
+ }
116
+ const env = options.env ?? process.env;
117
+ const context = `Cannot check npm package "${publish.name}@${version}"`;
118
+ const viewed = await tryNpm(["view", `${publish.name}@${version}`, "version", "--json"], env);
119
+ if (!viewed.ok) {
120
+ if (notFound(viewed))
121
+ return { exists: false, identical: false };
122
+ throw publishError(`${context}: ${npmMessage(viewed)}`, "publish-npm-failed", ExitCode.FetchFailed);
123
+ }
124
+ const [published, packed] = await Promise.all([
125
+ publishedHashes(publish.name, version, env),
126
+ packedHashes(root, env),
127
+ ]);
128
+ return { exists: true, identical: sameContent(published, packed) };
129
+ }
130
+ function forward(stream, onText, collect) {
131
+ stream?.on("data", (chunk) => {
132
+ const text = chunk.toString();
133
+ collect(text);
134
+ onText(text);
135
+ });
136
+ }
137
+ async function publishNpm(args, env, onText) {
138
+ const npm = await npmInvocation({ env });
139
+ let stdout = "";
140
+ let stderr = "";
141
+ await new Promise((resolve, reject) => {
142
+ const child = execFile(npm.command, [...npm.args, ...args], { env, encoding: "utf8", maxBuffer: MAX_OUTPUT, windowsHide: true }, (error) => {
143
+ if (error === null)
144
+ resolve();
145
+ else
146
+ reject(Object.assign(error, { stdout, stderr }));
147
+ });
148
+ forward(child.stdout, onText, (text) => {
149
+ stdout += text;
150
+ });
151
+ forward(child.stderr, onText, (text) => {
152
+ stderr += text;
153
+ });
154
+ });
155
+ }
156
+ /** `npm publish` in the staging directory, streaming its output to the report's stderr. */
157
+ export async function publishNpmFab(publish, version, root, options = {}) {
158
+ if (publish.name === undefined) {
159
+ throw publishError("The npm target requires publish.name.", "publish-missing-setting", ExitCode.Failed, undefined, 'Add "name" to "publish"');
160
+ }
161
+ const env = options.env ?? process.env;
162
+ const onText = options.stderr ?? ((text) => process.stderr.write(text));
163
+ const args = ["publish", root, "--access", publish.access ?? "public", "--ignore-scripts"];
164
+ if (options.tag !== undefined)
165
+ args.push("--tag", options.tag);
166
+ if (provenanceEnabled(env))
167
+ args.push("--provenance");
168
+ try {
169
+ await publishNpm(args, env, onText);
170
+ }
171
+ catch (error) {
172
+ const detail = npmMessage(error);
173
+ throw publishError(`Cannot publish ${publish.name}@${version}: ${detail}`, "publish-npm-failed", ExitCode.Failed, error);
174
+ }
175
+ return `Published ${publish.name}@${version} to npm${options.tag === undefined ? "" : ` with tag ${options.tag}`}.`;
176
+ }
177
+ //# sourceMappingURL=npm-target.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-target.js","sourceRoot":"","sources":["../../../src/core/publish/npm-target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAepD,MAAM,UAAU,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEpC,SAAS,UAAU,CAAC,OAAmB;IACrC,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;IACpG,MAAM,KAAK,GAAG,GAAG;SACd,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,yBAAyB,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;SACpE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,yCAAyC,CAAC,CAAC,CAAC;IAChG,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC;AAC1C,CAAC;AAED,SAAS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= "metafab";
4
+ export declare const FAB_FILES: readonly [".factory", "README.md"];
5
+ export interface FabPackageJson {
6
+ name: string;
7
+ version: string;
8
+ description?: string;
9
+ keywords: string[];
10
+ files: string[];
11
+ /** Named by a provenance bundle, when CI supplies it. */
12
+ repository?: string;
13
+ metafab: {
14
+ format: 1 | 2;
15
+ };
16
+ license?: string;
17
+ }
18
+ /**
19
+ * The repository a provenance bundle names. npm requires `repository` in the
20
+ * `package.json` to match the bundle, so when CI can attest provenance the
21
+ * repository comes from the same environment. Version 1 has no
22
+ * `publish.repository` setting, so detection is the only source.
23
+ */
24
+ export declare function provenanceRepository(env?: NodeJS.ProcessEnv): string | undefined;
25
+ /** `metafab` first, then `publish.keywords`, without empty values or duplicates. */
26
+ export declare function keywordsFor(publish: PublishConfig): string[];
27
+ /**
28
+ * The npm `package.json` for a fab. `files` and `metafab.format` are fixed by
29
+ * the fab layout, so they are not configurable.
30
+ */
31
+ export declare function buildPackageJson(factory: Factory, publish: PublishConfig, env?: NodeJS.ProcessEnv): FabPackageJson;
@@ -0,0 +1,74 @@
1
+ import { ExitCode, MetafabError } from "../../errors.js";
2
+ import { provenanceEnabled } from "./provenance.js";
3
+ export const FAB_KEYWORD = "metafab";
4
+ export const FAB_FILES = [".factory", "README.md"];
5
+ function nonEmpty(value) {
6
+ const trimmed = value?.trim();
7
+ return trimmed === undefined || trimmed === "" ? undefined : trimmed;
8
+ }
9
+ /**
10
+ * The repository a provenance bundle names. npm requires `repository` in the
11
+ * `package.json` to match the bundle, so when CI can attest provenance the
12
+ * repository comes from the same environment. Version 1 has no
13
+ * `publish.repository` setting, so detection is the only source.
14
+ */
15
+ export function provenanceRepository(env = process.env) {
16
+ if (!provenanceEnabled(env))
17
+ return undefined;
18
+ const slug = nonEmpty(env.GITHUB_REPOSITORY);
19
+ if (slug !== undefined) {
20
+ const server = nonEmpty(env.GITHUB_SERVER_URL)?.replace(/\/+$/, "") ?? "https://github.com";
21
+ return `${server}/${slug}`;
22
+ }
23
+ return nonEmpty(env.CI_PROJECT_URL)?.replace(/\/+$/, "");
24
+ }
25
+ function missingSetting(key) {
26
+ return new MetafabError(`The npm target requires "${key}".`, {
27
+ exitCode: ExitCode.Failed,
28
+ code: "publish-missing-setting",
29
+ problems: [
30
+ {
31
+ level: "error",
32
+ file: ".factory/metafab.yaml",
33
+ message: `The npm target requires "${key}".`,
34
+ fix: `Add "${key}" to the publish section`,
35
+ },
36
+ ],
37
+ });
38
+ }
39
+ /** `metafab` first, then `publish.keywords`, without empty values or duplicates. */
40
+ export function keywordsFor(publish) {
41
+ const seen = new Set();
42
+ const keywords = [];
43
+ for (const keyword of [FAB_KEYWORD, ...(publish.keywords ?? [])]) {
44
+ const value = keyword.trim();
45
+ if (value === "" || seen.has(value))
46
+ continue;
47
+ seen.add(value);
48
+ keywords.push(value);
49
+ }
50
+ return keywords;
51
+ }
52
+ /**
53
+ * The npm `package.json` for a fab. `files` and `metafab.format` are fixed by
54
+ * the fab layout, so they are not configurable.
55
+ */
56
+ export function buildPackageJson(factory, publish, env = process.env) {
57
+ if (publish.name === undefined)
58
+ throw missingSetting("publish.name");
59
+ if (publish.version === undefined)
60
+ throw missingSetting("publish.version");
61
+ const description = publish.description ?? factory.factoryYaml?.description;
62
+ const repository = provenanceRepository(env);
63
+ return {
64
+ name: publish.name,
65
+ version: publish.version,
66
+ ...(description === undefined ? {} : { description }),
67
+ keywords: keywordsFor(publish),
68
+ files: [...FAB_FILES],
69
+ ...(repository === undefined ? {} : { repository }),
70
+ metafab: { format: factory.factoryYaml?.format ?? 1 },
71
+ ...(publish.license === undefined ? {} : { license: publish.license }),
72
+ };
73
+ }
74
+ //# sourceMappingURL=package-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-json.js","sourceRoot":"","sources":["../../../src/core/publish/package-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGzD,OAAO,EAAE,iBAAiB,EAAE,MA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E,CAAC,GAAG,SAAS,CAAC;QACrB,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC;QACnD,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE,MAAM,IAAI,CAAC,EAAE;QACrD,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;KACvE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { ErrorProblem } from "../../errors.js";
2
+ import type { Config, PublishConfig } from "../config/types.js";
3
+ import type { Factory } from "../factory/index.js";
4
+ import type { PreparedFab, PublishTargetName } from "./types.js";
5
+ /**
6
+ * The fix for a failed publish target, from the Sharing spec's publish steps:
7
+ * fix the failure and run the command again, where a target that already
8
+ * carries these bytes is skipped. It lives beside `publishProblem` rather than
9
+ * in `publish.ts` so both targets import it without a cycle: `publish.ts`
10
+ * imports the targets.
11
+ */
12
+ export declare const PUBLISH_RETRY_FIX = "Fix the failure, then run metafab publish again; a target that already has this version is skipped";
13
+ /** A `publish` section that has a version and at least one target. */
14
+ export type ValidPublishConfig = PublishConfig & {
15
+ version: string;
16
+ };
17
+ /** A problem about the `publish` section, whose file is the configuration the person edits. */
18
+ export declare function publishProblem(message: string, fix: string): ErrorProblem;
19
+ /** The targets a `publish` section enables: `name` adds npm, `git` adds Git. */
20
+ export declare function publishTargets(publish: PublishConfig): PublishTargetName[];
21
+ /**
22
+ * The `publish` section a publish needs, or the problems to report instead.
23
+ * The command checks it before it runs anything else, and `prepareFab` uses the
24
+ * same function, so both report the same problems.
25
+ */
26
+ export declare function requirePublishConfig(config: Config): ValidPublishConfig;
27
+ /**
28
+ * Builds the complete fab in a temporary directory: the staged `.factory/`,
29
+ * the README at the root and, for the npm target, `package.json`. It publishes
30
+ * nothing, so `--dry-run` and the real run report from the same data.
31
+ *
32
+ * `files` and `size` describe what the npm package holds when npm is a target
33
+ * (`package.json` included) and what the Git fab holds otherwise.
34
+ */
35
+ export declare function prepareFab(factory: Factory, config: Config): Promise<PreparedFab>;
@@ -0,0 +1,102 @@
1
+ import { stat, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { ExitCode, MetafabError } from "../../errors.js";
4
+ import { listFiles } from "../../util/fs.js";
5
+ import { CONFIG_FILE } from "../config/parse.js";
6
+ import { buildPackageJson } from "./package-json.js";
7
+ import { resolveReadme } from "./readme.js";
8
+ import { stageFab } from "./stage.js";
9
+ /**
10
+ * The fix for a failed publish target, from the Sharing spec's publish steps:
11
+ * fix the failure and run the command again, where a target that already
12
+ * carries these bytes is skipped. It lives beside `publishProblem` rather than
13
+ * in `publish.ts` so both targets import it without a cycle: `publish.ts`
14
+ * imports the targets.
15
+ */
16
+ export const PUBLISH_RETRY_FIX = "Fix the failure, then run metafab publish again; a target that already has this version is skipped";
17
+ /** A problem about the `publish` section, whose file is the configuration the person edits. */
18
+ export function publishProblem(message, fix) {
19
+ return {
20
+ level: "error",
21
+ file: CONFIG_FILE,
22
+ message,
23
+ fix,
24
+ };
25
+ }
26
+ /** The targets a `publish` section enables: `name` adds npm, `git` adds Git. */
27
+ export function publishTargets(publish) {
28
+ const targets = [];
29
+ if (publish.name !== undefined)
30
+ targets.push("npm");
31
+ if (publish.git !== undefined)
32
+ targets.push("git");
33
+ return targets;
34
+ }
35
+ async function fabFileSize(root, file) {
36
+ return (await stat(path.join(root, ...file.split("/")))).size;
37
+ }
38
+ /**
39
+ * The `publish` section a publish needs, or the problems to report instead.
40
+ * The command checks it before it runs anything else, and `prepareFab` uses the
41
+ * same function, so both report the same problems.
42
+ */
43
+ export function requirePublishConfig(config) {
44
+ const publish = config.publish;
45
+ if (publish === undefined) {
46
+ throw new MetafabError('"publish" is not configured.', {
47
+ exitCode: ExitCode.Failed,
48
+ code: "publish-not-configured",
49
+ problems: [
50
+ publishProblem('The configuration has no "publish" section.', 'Add a "publish" section with "version" and "name" or "git"'),
51
+ ],
52
+ });
53
+ }
54
+ if (publishTargets(publish).length === 0) {
55
+ throw new MetafabError('"publish" names no target.', {
56
+ exitCode: ExitCode.Failed,
57
+ code: "publish-no-target",
58
+ problems: [
59
+ publishProblem('"publish" requires "name" or "git".', 'Add "name" for npm or "git" for a fab repository'),
60
+ ],
61
+ });
62
+ }
63
+ if (publish.version === undefined) {
64
+ throw new MetafabError('"publish.version" is required.', {
65
+ exitCode: ExitCode.Failed,
66
+ code: "publish-missing-setting",
67
+ problems: [publishProblem('"publish.version" is required.', 'Add "version" to "publish"')],
68
+ });
69
+ }
70
+ return publish;
71
+ }
72
+ /**
73
+ * Builds the complete fab in a temporary directory: the staged `.factory/`,
74
+ * the README at the root and, for the npm target, `package.json`. It publishes
75
+ * nothing, so `--dry-run` and the real run report from the same data.
76
+ *
77
+ * `files` and `size` describe what the npm package holds when npm is a target
78
+ * (`package.json` included) and what the Git fab holds otherwise.
79
+ */
80
+ export async function prepareFab(factory, config) {
81
+ const publish = requirePublishConfig(config);
82
+ const targets = publishTargets(publish);
83
+ const staged = await stageFab(factory, { exclude: publish.exclude, targets });
84
+ try {
85
+ const readme = await resolveReadme(factory.root, factory, publish, staged.factory);
86
+ await writeFile(path.join(staged.root, "README.md"), readme, "utf8");
87
+ if (targets.includes("npm")) {
88
+ const packageJson = `${JSON.stringify(buildPackageJson(factory, publish), null, 2)}\n`;
89
+ await writeFile(path.join(staged.root, "package.json"), packageJson, "utf8");
90
+ }
91
+ const files = await listFiles(staged.root);
92
+ let size = 0;
93
+ for (const file of files)
94
+ size += await fabFileSize(staged.root, file);
95
+ return { ...staged, files, size, targets };
96
+ }
97
+ catch (error) {
98
+ await staged.cleanup();
99
+ throw error;
100
+ }
101
+ }
102
+ //# sourceMappingURL=prepare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.js","sourceRoot":"","sources":["../../../src/core/publish/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AC;QACH,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACnF,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAErE,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,WAAW,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;YACvF,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC/E,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,IAAI,IAAI,MAAM,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAEvE,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function provenanceEnabled(env?: NodeJS.ProcessEnv): boolean;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * npm can attach provenance only where the CI system hands it an OIDC token:
3
+ * GitHub Actions through `ACTIONS_ID_TOKEN_REQUEST_URL`, GitLab CI through
4
+ * `SIGSTORE_ID_TOKEN`. v1 detects the bundle and never overrides it with a flag
5
+ * (plan 1.011, open question 2).
6
+ */
7
+ function enabled(value) {
8
+ if (value === undefined)
9
+ return false;
10
+ const normalized = value.trim().toLowerCase();
11
+ return normalized !== "" && normalized !== "false" && normalized !== "0";
12
+ }
13
+ export function provenanceEnabled(env = process.env) {
14
+ if (enabled(env.GITHUB_ACTIONS) && enabled(env.ACTIONS_ID_TOKEN_REQUEST_URL))
15
+ return true;
16
+ if (enabled(env.GITLAB_CI) && enabled(env.SIGSTORE_ID_TOKEN))
17
+ return true;
18
+ return false;
19
+ }
20
+ //# sourceMappingURL=provenance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provenance.js","sourceRoot":"","sources":["../../../src/core/publish/provenance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,SAAS,OAAO,CAAC,KAAyB;IACxC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC9C,OAAO,UAAU,KAAK,EAAE,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,GAAG,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG;IACpE,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1F,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1E,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { PublishConfig } from "../config/types.js";
2
+ import type { PreparedFab, PublishOptions, PublishResult } from "./types.js";
3
+ /**
4
+ * Publishes one prepared fab to every configured target.
5
+ *
6
+ * The version preflight runs for every target before anything is published: a
7
+ * version that exists with different content refuses the whole publish, while a
8
+ * version that exists with identical content is skipped. A target failure is
9
+ * reported in its result and the remaining targets are not attempted; a failure
10
+ * that names problems, or asks for an exit code other than 1, carries both back
11
+ * so the command reports them.
12
+ */
13
+ export declare function publishFab(prepared: PreparedFab, publish: PublishConfig, options?: PublishOptions): Promise<PublishResult>;
@@ -0,0 +1,143 @@
1
+ import { ExitCode, MetafabError } from "../../errors.js";
2
+ import { CONFIG_FILE } from "../config/parse.js";
3
+ import { gitVersionState, publishGitFab } from "./git-target.js";
4
+ import { npmVersionState, publishNpmFab } from "./npm-target.js";
5
+ import { PUBLISH_RETRY_FIX, publishProblem } from "./prepare.js";
6
+ /**
7
+ * Publish order. Git goes first because its push is atomic and its preflight is
8
+ * the strongest, so a half-published release can be finished by a re-run that
9
+ * skips the target already carrying these bytes (plan 1.011, open question 1).
10
+ */
11
+ const PUBLISH_ORDER = ["git", "npm"];
12
+ function versionConflict(target, version) {
13
+ const label = target === "npm" ? "npm" : "Git fab repository";
14
+ return new MetafabError(`Version ${version} is already published to ${label} with different content.`, {
15
+ exitCode: ExitCode.Failed,
16
+ code: "publish-version-exists",
17
+ problems: [
18
+ {
19
+ level: "error",
20
+ file: ".factory/metafab.yaml",
21
+ message: `The ${label} already has ${version} with different content.`,
22
+ fix: "Bump publish.version; a published version cannot change",
23
+ },
24
+ ],
25
+ });
26
+ }
27
+ function skippedDetail(target, version) {
28
+ return target === "npm"
29
+ ? `${version} is already on npm with identical content.`
30
+ : `v${version} is already in the fab repository with identical content.`;
31
+ }
32
+ /** How many of a failure's paths its target detail names; the problems carry all. */
33
+ const DETAIL_PATHS = 3;
34
+ function failureDetail(error) {
35
+ const message = error instanceof Error && error.message.trim() !== "" ? error.message.trim() : String(error);
36
+ if (!(error instanceof MetafabError))
37
+ return message;
38
+ // A publish problem names the configuration the person edits rather than a
39
+ // path the target printed, so the detail keeps naming only the target's paths.
40
+ const files = [...new Set((error.problems ?? []).map((problem) => problem.file))].filter((file) => file !== CONFIG_FILE);
41
+ if (files.length === 0)
42
+ return message;
43
+ if (files.length === 1)
44
+ return `${message} (${files[0]})`;
45
+ // A failed list may name thousands of paths; the reported problems carry
46
+ // every one, so the detail only counts them and shows the first few.
47
+ const shown = files.slice(0, DETAIL_PATHS).join(", ");
48
+ const more = files.length > DETAIL_PATHS ? ` and ${files.length - DETAIL_PATHS} more` : "";
49
+ return `${message} (${files.length} paths: ${shown}${more})`;
50
+ }
51
+ /**
52
+ * Publishes one prepared fab to every configured target.
53
+ *
54
+ * The version preflight runs for every target before anything is published: a
55
+ * version that exists with different content refuses the whole publish, while a
56
+ * version that exists with identical content is skipped. A target failure is
57
+ * reported in its result and the remaining targets are not attempted; a failure
58
+ * that names problems, or asks for an exit code other than 1, carries both back
59
+ * so the command reports them.
60
+ */
61
+ export async function publishFab(prepared, publish, options = {}) {
62
+ const version = publish.version;
63
+ if (version === undefined) {
64
+ throw new MetafabError('"publish.version" is required.', {
65
+ exitCode: ExitCode.Failed,
66
+ code: "publish-missing-setting",
67
+ problems: [publishProblem('"publish.version" is required.', 'Add "version" to "publish"')],
68
+ });
69
+ }
70
+ const context = {
71
+ ...options,
72
+ interactive: options.interactive ?? (process.stdin.isTTY === true && options.json !== true),
73
+ };
74
+ const targets = PUBLISH_ORDER.filter((target) => prepared.targets.includes(target));
75
+ const existing = new Map();
76
+ for (const target of targets) {
77
+ if (target === "git") {
78
+ const state = await gitVersionState(publish, version, prepared.root, context);
79
+ if (state.tagExists && !state.identical)
80
+ throw versionConflict("git", version);
81
+ existing.set(target, state.tagExists ? "identical" : "new");
82
+ }
83
+ else {
84
+ const state = await npmVersionState(publish, version, prepared.root, context);
85
+ if (state.exists && !state.identical)
86
+ throw versionConflict("npm", version);
87
+ existing.set(target, state.exists ? "identical" : "new");
88
+ }
89
+ }
90
+ const results = new Map();
91
+ let failed;
92
+ const problems = [];
93
+ let exitCode;
94
+ for (const target of targets) {
95
+ if (existing.get(target) === "identical") {
96
+ results.set(target, { target, status: "skipped", detail: skippedDetail(target, version) });
97
+ continue;
98
+ }
99
+ if (failed !== undefined) {
100
+ results.set(target, {
101
+ target,
102
+ status: "skipped",
103
+ detail: `Not attempted: the ${failed} target failed.`,
104
+ });
105
+ continue;
106
+ }
107
+ try {
108
+ const detail = target === "git"
109
+ ? await publishGitFab(publish, version, prepared.root, context)
110
+ : await publishNpmFab(publish, version, prepared.root, context);
111
+ results.set(target, { target, status: "published", detail });
112
+ }
113
+ catch (error) {
114
+ // Head protection is a refusal the command must report with its own exit
115
+ // code, and it happens before this target changes anything.
116
+ if (error instanceof MetafabError && error.exitCode === ExitCode.NotOwned)
117
+ throw error;
118
+ const detail = failureDetail(error);
119
+ // A target that names its problems, such as the files Git lost, keeps
120
+ // them: the command reports them and exits with the target's code.
121
+ if (error instanceof MetafabError) {
122
+ problems.push(...(error.problems ?? []));
123
+ exitCode = error.exitCode;
124
+ }
125
+ else {
126
+ // A raw failure, such as a filesystem error while the Git target writes
127
+ // its repository, names no problem of its own. The person still needs a
128
+ // next step, and the command still exits 1.
129
+ problems.push(publishProblem(`The ${target} target failed: ${detail}`, PUBLISH_RETRY_FIX));
130
+ exitCode = ExitCode.Failed;
131
+ }
132
+ results.set(target, { target, status: "failed", detail });
133
+ failed = target;
134
+ }
135
+ }
136
+ return {
137
+ version,
138
+ targets: prepared.targets.map((target) => results.get(target)),
139
+ ...(problems.length === 0 ? {} : { problems }),
140
+ ...(exitCode === undefined ? {} : { exitCode }),
141
+ };
142
+ }
143
+ //# sourceMappingURL=publish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish.js","sourceRoot":"","sources":["../../../src/core/publish/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,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