@unbrained/pm-cli 2026.12.1 → 2026.12.3

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 (376) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli/commander-usage.js +4 -4
  3. package/dist/cli/expected-revisions.js +1 -1
  4. package/dist/cli/extension-command-help.js +4 -4
  5. package/dist/cli/main.js +5 -5
  6. package/dist/cli/runtime/invocation-rewrites.js +1 -1
  7. package/dist/cli/runtime-field-commands.js +2 -0
  8. package/dist/cli-bundle/bundle-manifest.json +1 -1
  9. package/dist/cli-bundle/chunks/chunk-3ESBFEQC.js +2 -0
  10. package/dist/cli-bundle/chunks/chunk-46AZP5QW.js +2 -0
  11. package/dist/cli-bundle/chunks/{chunk-OBPO6V7H.js → chunk-5WTBF4M4.js} +2 -2
  12. package/dist/cli-bundle/chunks/{chunk-3KEMIPKG.js → chunk-6TOZQ5BQ.js} +2 -2
  13. package/dist/cli-bundle/chunks/{chunk-4YYFY33T.js → chunk-AHVOEE7F.js} +2 -2
  14. package/dist/cli-bundle/chunks/chunk-CQHB3ZZH.js +2 -0
  15. package/dist/cli-bundle/chunks/chunk-DZPOS3YT.js +2 -0
  16. package/dist/cli-bundle/chunks/{chunk-OKEJ4U2I.js → chunk-E5ADC3HT.js} +65 -65
  17. package/dist/cli-bundle/chunks/{chunk-SY5C3U32.js → chunk-E5HO7HWP.js} +2 -2
  18. package/dist/cli-bundle/chunks/{chunk-3HKPVOAN.js → chunk-EDJ3KR2H.js} +2 -2
  19. package/dist/cli-bundle/chunks/{chunk-XME6GIFQ.js → chunk-FWQNWPIV.js} +2 -2
  20. package/dist/cli-bundle/chunks/{chunk-CWPR234D.js → chunk-H4U3LEOD.js} +2 -2
  21. package/dist/cli-bundle/chunks/{chunk-MZZ4ZJ5Z.js → chunk-HNMED75Y.js} +2 -2
  22. package/dist/cli-bundle/chunks/{chunk-U7RBJGLF.js → chunk-HPCMM74Q.js} +22 -22
  23. package/dist/cli-bundle/chunks/{chunk-WSEIEDEK.js → chunk-ITM4AMVM.js} +2 -2
  24. package/dist/cli-bundle/chunks/{chunk-Q6K7HWZ7.js → chunk-IW4A3I4N.js} +2 -2
  25. package/dist/cli-bundle/chunks/{chunk-4YQMQOUO.js → chunk-JJ73G5UT.js} +52 -52
  26. package/dist/cli-bundle/chunks/chunk-L4HMFRHB.js +2 -0
  27. package/dist/cli-bundle/chunks/{chunk-YSVOXCYH.js → chunk-LTQWPQ7H.js} +2 -2
  28. package/dist/cli-bundle/chunks/{chunk-Q6GLSAJY.js → chunk-MRT3ADO4.js} +2 -2
  29. package/dist/cli-bundle/chunks/{chunk-ZL6J6JYT.js → chunk-PBMLIV74.js} +2 -2
  30. package/dist/cli-bundle/chunks/{chunk-NA6D75V5.js → chunk-PJMGWJKU.js} +2 -2
  31. package/dist/cli-bundle/chunks/chunk-Q2HMDV56.js +9 -0
  32. package/dist/cli-bundle/chunks/{chunk-OXC5KBIQ.js → chunk-RRBNCL63.js} +2 -2
  33. package/dist/cli-bundle/chunks/{chunk-CBUC4X7Q.js → chunk-TDOF7BKO.js} +3 -3
  34. package/dist/cli-bundle/chunks/chunk-UXEZXGAD.js +113 -0
  35. package/dist/cli-bundle/chunks/{chunk-PCDTWL6V.js → chunk-W7HA65EO.js} +2 -2
  36. package/dist/cli-bundle/chunks/{chunk-I4SPJQQI.js → chunk-XGNUDSCG.js} +3 -3
  37. package/dist/cli-bundle/chunks/{chunk-AHV3CSQG.js → chunk-XKJ5NWQ7.js} +2 -2
  38. package/dist/cli-bundle/chunks/{field-option-collisions-BBGTV7AD.js → field-option-collisions-DXKTKW6J.js} +2 -2
  39. package/dist/cli-bundle/chunks/item-revision-DXEF4XBU.js +2 -0
  40. package/dist/cli-bundle/chunks/item-transaction-EANA7V4W.js +2 -0
  41. package/dist/cli-bundle/chunks/{linked-resource-value-list-E2DX52LY.js → linked-resource-value-list-5JRGUDUB.js} +2 -2
  42. package/dist/cli-bundle/chunks/{mutation-actor-NHN33ITJ.js → mutation-actor-S5G7FMNG.js} +2 -2
  43. package/dist/cli-bundle/chunks/{mutation-admission-PGKJTCG6.js → mutation-admission-HQVNPOXV.js} +2 -2
  44. package/dist/cli-bundle/chunks/{register-list-query-7S5QWDTI.js → register-list-query-SQF5PSJ4.js} +2 -2
  45. package/dist/cli-bundle/chunks/{register-mutation-2F6JUBST.js → register-mutation-4AQ4CEBL.js} +2 -2
  46. package/dist/cli-bundle/chunks/{register-operations-ET3UKPYK.js → register-operations-76P7OM4P.js} +2 -2
  47. package/dist/cli-bundle/chunks/{register-setup-I63QTFCU.js → register-setup-T6OEOZK3.js} +2 -2
  48. package/dist/cli-bundle/chunks/{stage-4ZCF74G4.js → stage-KUICZHSF.js} +2 -2
  49. package/dist/cli-bundle/focused-chunks/{chunk-4SCFAWAW.js → chunk-3LHBKFPD.js} +2 -2
  50. package/dist/cli-bundle/focused-chunks/chunk-4DDXERKN.js +2 -0
  51. package/dist/cli-bundle/focused-chunks/{chunk-JPZGC3W4.js → chunk-4YU75CWI.js} +2 -2
  52. package/dist/cli-bundle/focused-chunks/{chunk-TXTPAFHJ.js → chunk-5JQVPQMN.js} +2 -2
  53. package/dist/cli-bundle/focused-chunks/{chunk-KNBGHCIP.js → chunk-5Z4DXYBZ.js} +2 -2
  54. package/dist/cli-bundle/focused-chunks/chunk-7DOP5HEZ.js +44 -0
  55. package/dist/cli-bundle/focused-chunks/{chunk-TR22GU7M.js → chunk-AX4RBJ7B.js} +2 -2
  56. package/dist/cli-bundle/focused-chunks/{chunk-7A6SEZEY.js → chunk-BEHQCHQV.js} +2 -2
  57. package/dist/cli-bundle/focused-chunks/chunk-BUIF6CMZ.js +2 -0
  58. package/dist/cli-bundle/focused-chunks/chunk-E2IWEJL5.js +3 -0
  59. package/dist/cli-bundle/focused-chunks/chunk-GBU7GKNJ.js +2 -0
  60. package/dist/cli-bundle/focused-chunks/{chunk-EQCQTYKO.js → chunk-K35KTBDZ.js} +2 -2
  61. package/dist/cli-bundle/focused-chunks/{chunk-VQIC3UZB.js → chunk-KNST4PGF.js} +2 -2
  62. package/dist/cli-bundle/focused-chunks/{chunk-P2H3GTJK.js → chunk-L2XJB5PK.js} +2 -2
  63. package/dist/cli-bundle/focused-chunks/chunk-L6NOGC4N.js +100 -0
  64. package/dist/cli-bundle/focused-chunks/{chunk-VK3IE3TS.js → chunk-LWIIDPAV.js} +2 -2
  65. package/dist/cli-bundle/focused-chunks/{chunk-6IY5CVGJ.js → chunk-M54BMYG4.js} +2 -2
  66. package/dist/cli-bundle/focused-chunks/{chunk-6BKT6XQN.js → chunk-NEK7RX3N.js} +2 -2
  67. package/dist/cli-bundle/focused-chunks/{chunk-BHNBPCHP.js → chunk-OKGWIW6C.js} +2 -2
  68. package/dist/cli-bundle/focused-chunks/{chunk-2DGKVXFT.js → chunk-RFDSSOTZ.js} +2 -2
  69. package/dist/cli-bundle/focused-chunks/chunk-SSX5YBDC.js +2 -0
  70. package/dist/cli-bundle/focused-chunks/{chunk-OG57ESZK.js → chunk-TIEQVIFN.js} +2 -2
  71. package/dist/cli-bundle/focused-chunks/{chunk-SQ72CVUH.js → chunk-VEUBDQDP.js} +54 -54
  72. package/dist/cli-bundle/focused-chunks/{chunk-2UWKU2BQ.js → chunk-WDHNPNHX.js} +3 -3
  73. package/dist/cli-bundle/focused-chunks/{field-option-collisions-2C6DLUC4.js → field-option-collisions-32X7FP3H.js} +2 -2
  74. package/dist/cli-bundle/focused-chunks/item-revision-GUYSVVQD.js +2 -0
  75. package/dist/cli-bundle/focused-chunks/{item-transaction-2K4SFLJ7.js → item-transaction-MLKHZPL7.js} +2 -2
  76. package/dist/cli-bundle/focused-chunks/{mutation-actor-DJMZUIZI.js → mutation-actor-RDZJTRW2.js} +2 -2
  77. package/dist/cli-bundle/focused-chunks/{mutation-admission-SDWQVVHN.js → mutation-admission-IQB6XL75.js} +2 -2
  78. package/dist/cli-bundle/focused-chunks/{stage-QBZIK3T5.js → stage-AA7LORZ2.js} +2 -2
  79. package/dist/cli-bundle/main.js +27 -27
  80. package/dist/cli-bundle/sdk-authoring.js +1 -1
  81. package/dist/cli-bundle/sdk-contracts.js +1 -1
  82. package/dist/cli-bundle/sdk-core.js +1 -1
  83. package/dist/cli-bundle/sdk-governance.js +1 -1
  84. package/dist/cli-bundle/sdk-graph.js +1 -1
  85. package/dist/cli-bundle/sdk-merge.js +63 -63
  86. package/dist/cli-bundle/sdk-query.js +1 -1
  87. package/dist/cli-bundle/sdk-runtime.js +1 -1
  88. package/dist/cli-bundle/sdk-testing.js +1 -1
  89. package/dist/cli-bundle/sdk.js +9 -9
  90. package/dist/core/extensions/loader.d.ts +8 -0
  91. package/dist/core/extensions/loader.js +1 -1
  92. package/dist/core/item/actionability.js +1 -1
  93. package/dist/core/output/output.js +16 -16
  94. package/dist/mcp/server.js +1 -1
  95. package/dist/sdk/cli-contracts/enum-contracts.d.ts +25 -1
  96. package/dist/sdk/cli-contracts/enum-contracts.js +1 -1
  97. package/dist/sdk/cli-contracts/flag-contracts.d.ts +1 -1
  98. package/dist/sdk/cli-contracts/flag-contracts.js +1 -1
  99. package/dist/sdk/cli-contracts/runtime-contracts.js +1 -1
  100. package/dist/sdk/cli-contracts/tool-parameter-tables.js +1 -1
  101. package/dist/sdk/cli-contracts/tool-schema.js +1 -1
  102. package/dist/sdk/context-intent-contracts.js +1 -1
  103. package/dist/sdk/extension/install-sources.d.ts +2 -2
  104. package/dist/sdk/extension/install-sources.js +5 -5
  105. package/dist/sdk/lifecycle/expect-hash-admission.d.ts +27 -8
  106. package/dist/sdk/lifecycle/expect-hash-admission.js +1 -1
  107. package/dist/sdk/lifecycle/item-revision.d.ts +12 -4
  108. package/dist/sdk/lifecycle/item-revision.js +1 -1
  109. package/dist/sdk/output-projection.d.ts +1 -1
  110. package/dist/sdk/output-projection.js +1 -1
  111. package/dist/sdk/public-surface.json +1 -1
  112. package/dist/sdk/read-output/surfaces.js +1 -1
  113. package/dist/sdk/runtime/schema.js +1 -1
  114. package/dist/sdk/runtime-input.d.ts +6 -0
  115. package/dist/sdk/runtime-input.js +1 -1
  116. package/dist/sdk/runtime-primitives.d.ts +1 -1
  117. package/dist/sdk/runtime-primitives.js +1 -1
  118. package/dist/sdk/runtime.js +1 -1
  119. package/docs/COMMANDS.md +23 -5
  120. package/docs/EXTENSIONS.md +1 -1
  121. package/docs/SDK.md +15 -2
  122. package/marketplace.json +1 -1
  123. package/node_modules/tar/README.md +1792 -1147
  124. package/node_modules/tar/dist/commonjs/bytes.d.ts +21 -0
  125. package/node_modules/tar/dist/commonjs/bytes.js +83 -0
  126. package/node_modules/tar/dist/commonjs/codec.d.ts +53 -0
  127. package/node_modules/tar/dist/commonjs/codec.js +35 -0
  128. package/node_modules/tar/dist/commonjs/concat.d.ts +3 -0
  129. package/node_modules/tar/dist/commonjs/concat.js +20 -0
  130. package/node_modules/tar/dist/commonjs/create.d.ts +39 -2
  131. package/node_modules/tar/dist/commonjs/create.js +150 -64
  132. package/node_modules/tar/dist/commonjs/dealias.d.ts +79 -0
  133. package/node_modules/tar/dist/commonjs/dealias.js +50 -0
  134. package/node_modules/tar/dist/commonjs/delete.d.ts +19 -0
  135. package/node_modules/tar/dist/commonjs/delete.js +121 -0
  136. package/node_modules/tar/dist/commonjs/entries.d.ts +82 -0
  137. package/node_modules/tar/dist/commonjs/entries.js +398 -0
  138. package/node_modules/tar/dist/commonjs/extract.d.ts +14 -2
  139. package/node_modules/tar/dist/commonjs/extract.js +40 -81
  140. package/node_modules/tar/dist/commonjs/fs.d.ts +201 -0
  141. package/node_modules/tar/dist/commonjs/fs.js +5 -0
  142. package/node_modules/tar/dist/commonjs/header.d.ts +4 -4
  143. package/node_modules/tar/dist/commonjs/header.js +71 -53
  144. package/node_modules/tar/dist/commonjs/index.d.ts +25 -18
  145. package/node_modules/tar/dist/commonjs/index.js +46 -18
  146. package/node_modules/tar/dist/commonjs/index.min.js +2 -3
  147. package/node_modules/tar/dist/commonjs/large-numbers.d.ts +2 -2
  148. package/node_modules/tar/dist/commonjs/large-numbers.js +4 -4
  149. package/node_modules/tar/dist/commonjs/list.d.ts +23 -6
  150. package/node_modules/tar/dist/commonjs/list.js +99 -138
  151. package/node_modules/tar/dist/commonjs/mkdir.d.ts +16 -11
  152. package/node_modules/tar/dist/commonjs/mkdir.js +121 -159
  153. package/node_modules/tar/dist/commonjs/normalize-unicode.js +9 -0
  154. package/node_modules/tar/dist/commonjs/options.d.ts +284 -513
  155. package/node_modules/tar/dist/commonjs/options.js +20 -61
  156. package/node_modules/tar/dist/commonjs/pack.d.ts +150 -96
  157. package/node_modules/tar/dist/commonjs/pack.js +752 -445
  158. package/node_modules/tar/dist/commonjs/parser.d.ts +98 -0
  159. package/node_modules/tar/dist/commonjs/parser.js +452 -0
  160. package/node_modules/tar/dist/commonjs/path-reservations.d.ts +17 -7
  161. package/node_modules/tar/dist/commonjs/path-reservations.js +110 -140
  162. package/node_modules/tar/dist/commonjs/path.d.ts +19 -0
  163. package/node_modules/tar/dist/commonjs/path.js +90 -0
  164. package/node_modules/tar/dist/commonjs/pax.d.ts +3 -1
  165. package/node_modules/tar/dist/commonjs/pax.js +67 -36
  166. package/node_modules/tar/dist/commonjs/read-entry.d.ts +97 -11
  167. package/node_modules/tar/dist/commonjs/read-entry.js +251 -97
  168. package/node_modules/tar/dist/commonjs/read-file.d.ts +22 -0
  169. package/node_modules/tar/dist/commonjs/read-file.js +104 -0
  170. package/node_modules/tar/dist/commonjs/replace.d.ts +45 -1
  171. package/node_modules/tar/dist/commonjs/replace.js +164 -211
  172. package/node_modules/tar/dist/commonjs/server/codecs.d.ts +38 -0
  173. package/node_modules/tar/dist/commonjs/server/codecs.js +252 -0
  174. package/node_modules/tar/dist/commonjs/server/index.d.ts +115 -0
  175. package/node_modules/tar/dist/commonjs/server/index.js +166 -0
  176. package/node_modules/tar/dist/commonjs/server/index.min.js +3 -0
  177. package/node_modules/tar/dist/commonjs/strip-absolute-path.d.ts +8 -0
  178. package/node_modules/tar/dist/commonjs/strip-absolute-path.js +17 -20
  179. package/node_modules/tar/dist/commonjs/to-stream.d.ts +7 -0
  180. package/node_modules/tar/dist/commonjs/to-stream.js +22 -0
  181. package/node_modules/tar/dist/commonjs/types.d.ts +4 -3
  182. package/node_modules/tar/dist/commonjs/types.js +4 -3
  183. package/node_modules/tar/dist/commonjs/unpack.d.ts +143 -89
  184. package/node_modules/tar/dist/commonjs/unpack.js +780 -725
  185. package/node_modules/tar/dist/commonjs/update.d.ts +11 -1
  186. package/node_modules/tar/dist/commonjs/update.js +37 -28
  187. package/node_modules/tar/dist/commonjs/warn.d.ts +27 -0
  188. package/node_modules/tar/dist/commonjs/warn.js +36 -0
  189. package/node_modules/tar/dist/commonjs/win32-path.d.ts +16 -0
  190. package/node_modules/tar/dist/commonjs/win32-path.js +67 -0
  191. package/node_modules/tar/dist/commonjs/write-entry.d.ts +64 -111
  192. package/node_modules/tar/dist/commonjs/write-entry.js +108 -672
  193. package/node_modules/tar/dist/commonjs/write-flag.d.ts +18 -0
  194. package/node_modules/tar/dist/commonjs/write-flag.js +29 -0
  195. package/node_modules/tar/dist/esm/bytes.d.ts +21 -0
  196. package/node_modules/tar/dist/esm/bytes.js +72 -0
  197. package/node_modules/tar/dist/esm/codec.d.ts +53 -0
  198. package/node_modules/tar/dist/esm/codec.js +32 -0
  199. package/node_modules/tar/dist/esm/concat.d.ts +3 -0
  200. package/node_modules/tar/dist/esm/concat.js +16 -0
  201. package/node_modules/tar/dist/esm/create.d.ts +39 -2
  202. package/node_modules/tar/dist/esm/create.js +144 -61
  203. package/node_modules/tar/dist/esm/dealias.d.ts +79 -0
  204. package/node_modules/tar/dist/esm/dealias.js +46 -0
  205. package/node_modules/tar/dist/esm/delete.d.ts +19 -0
  206. package/node_modules/tar/dist/esm/delete.js +117 -0
  207. package/node_modules/tar/dist/esm/entries.d.ts +82 -0
  208. package/node_modules/tar/dist/esm/entries.js +388 -0
  209. package/node_modules/tar/dist/esm/extract.d.ts +14 -2
  210. package/node_modules/tar/dist/esm/extract.js +37 -44
  211. package/node_modules/tar/dist/esm/fs.d.ts +201 -0
  212. package/node_modules/tar/dist/esm/fs.js +4 -0
  213. package/node_modules/tar/dist/esm/header.d.ts +4 -4
  214. package/node_modules/tar/dist/esm/header.js +71 -53
  215. package/node_modules/tar/dist/esm/index.d.ts +25 -18
  216. package/node_modules/tar/dist/esm/index.js +23 -18
  217. package/node_modules/tar/dist/esm/index.min.js +2 -3
  218. package/node_modules/tar/dist/esm/large-numbers.d.ts +2 -2
  219. package/node_modules/tar/dist/esm/large-numbers.js +4 -4
  220. package/node_modules/tar/dist/esm/list.d.ts +23 -6
  221. package/node_modules/tar/dist/esm/list.js +96 -101
  222. package/node_modules/tar/dist/esm/mkdir.d.ts +16 -11
  223. package/node_modules/tar/dist/esm/mkdir.js +119 -154
  224. package/node_modules/tar/dist/esm/normalize-unicode.js +9 -0
  225. package/node_modules/tar/dist/esm/options.d.ts +284 -513
  226. package/node_modules/tar/dist/esm/options.js +17 -51
  227. package/node_modules/tar/dist/esm/pack.d.ts +150 -96
  228. package/node_modules/tar/dist/esm/pack.js +750 -441
  229. package/node_modules/tar/dist/esm/parser.d.ts +98 -0
  230. package/node_modules/tar/dist/esm/parser.js +448 -0
  231. package/node_modules/tar/dist/esm/path-reservations.d.ts +17 -7
  232. package/node_modules/tar/dist/esm/path-reservations.js +110 -140
  233. package/node_modules/tar/dist/esm/path.d.ts +19 -0
  234. package/node_modules/tar/dist/esm/path.js +80 -0
  235. package/node_modules/tar/dist/esm/pax.d.ts +3 -1
  236. package/node_modules/tar/dist/esm/pax.js +66 -35
  237. package/node_modules/tar/dist/esm/read-entry.d.ts +97 -11
  238. package/node_modules/tar/dist/esm/read-entry.js +248 -96
  239. package/node_modules/tar/dist/esm/read-file.d.ts +22 -0
  240. package/node_modules/tar/dist/esm/read-file.js +99 -0
  241. package/node_modules/tar/dist/esm/replace.d.ts +45 -1
  242. package/node_modules/tar/dist/esm/replace.js +160 -207
  243. package/node_modules/tar/dist/esm/server/codecs.d.ts +38 -0
  244. package/node_modules/tar/dist/esm/server/codecs.js +214 -0
  245. package/node_modules/tar/dist/esm/server/index.d.ts +115 -0
  246. package/node_modules/tar/dist/esm/server/index.js +102 -0
  247. package/node_modules/tar/dist/esm/server/index.min.js +3 -0
  248. package/node_modules/tar/dist/esm/strip-absolute-path.d.ts +8 -0
  249. package/node_modules/tar/dist/esm/strip-absolute-path.js +17 -20
  250. package/node_modules/tar/dist/esm/to-stream.d.ts +7 -0
  251. package/node_modules/tar/dist/esm/to-stream.js +18 -0
  252. package/node_modules/tar/dist/esm/types.d.ts +4 -3
  253. package/node_modules/tar/dist/esm/types.js +4 -3
  254. package/node_modules/tar/dist/esm/unpack.d.ts +143 -89
  255. package/node_modules/tar/dist/esm/unpack.js +776 -719
  256. package/node_modules/tar/dist/esm/update.d.ts +11 -1
  257. package/node_modules/tar/dist/esm/update.js +35 -28
  258. package/node_modules/tar/dist/esm/warn.d.ts +27 -0
  259. package/node_modules/tar/dist/esm/warn.js +31 -0
  260. package/node_modules/tar/dist/esm/win32-path.d.ts +16 -0
  261. package/node_modules/tar/dist/esm/win32-path.js +60 -0
  262. package/node_modules/tar/dist/esm/write-entry.d.ts +64 -111
  263. package/node_modules/tar/dist/esm/write-entry.js +107 -633
  264. package/node_modules/tar/dist/esm/write-flag.d.ts +18 -0
  265. package/node_modules/tar/dist/esm/write-flag.js +25 -0
  266. package/node_modules/tar/package.json +68 -224
  267. package/package.json +2 -2
  268. package/packages/pm-beads/package.json +1 -1
  269. package/packages/pm-calendar/package.json +1 -1
  270. package/packages/pm-command-kit/package.json +1 -1
  271. package/packages/pm-digital-twin/package.json +1 -1
  272. package/packages/pm-governance-audit/package.json +1 -1
  273. package/packages/pm-guide-shell/package.json +1 -1
  274. package/packages/pm-kanban/package.json +1 -1
  275. package/packages/pm-lifecycle-hooks/package.json +1 -1
  276. package/packages/pm-linked-test-adapters/package.json +1 -1
  277. package/packages/pm-search-advanced/package.json +1 -1
  278. package/packages/pm-templates/package.json +1 -1
  279. package/packages/pm-todos/package.json +1 -1
  280. package/packages/pm-vcs/package.json +1 -1
  281. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  282. package/plugins/pm-claude/package.json +1 -1
  283. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  284. package/plugins/pm-codex/package.json +1 -1
  285. package/plugins/pm-codex/plugin.json +1 -1
  286. package/runtime-dependencies.json +1 -1
  287. package/dist/cli-bundle/chunks/chunk-A5ZEMOVR.js +0 -2
  288. package/dist/cli-bundle/chunks/chunk-AJLU6KLW.js +0 -2
  289. package/dist/cli-bundle/chunks/chunk-C6WM6ZN4.js +0 -9
  290. package/dist/cli-bundle/chunks/chunk-HZZLSBIJ.js +0 -2
  291. package/dist/cli-bundle/chunks/chunk-L2ZSSMYY.js +0 -2
  292. package/dist/cli-bundle/chunks/chunk-NRQCBUYD.js +0 -113
  293. package/dist/cli-bundle/chunks/chunk-QDV7S2QS.js +0 -2
  294. package/dist/cli-bundle/chunks/item-revision-3LENTXYF.js +0 -2
  295. package/dist/cli-bundle/chunks/item-transaction-66RDV7PH.js +0 -2
  296. package/dist/cli-bundle/focused-chunks/chunk-HTDYNY4L.js +0 -2
  297. package/dist/cli-bundle/focused-chunks/chunk-N64AC5G6.js +0 -100
  298. package/dist/cli-bundle/focused-chunks/chunk-PT7RT3T6.js +0 -44
  299. package/dist/cli-bundle/focused-chunks/chunk-QZRYGYTI.js +0 -2
  300. package/dist/cli-bundle/focused-chunks/chunk-SQMOF65W.js +0 -2
  301. package/dist/cli-bundle/focused-chunks/chunk-T3ILWAEV.js +0 -2
  302. package/dist/cli-bundle/focused-chunks/chunk-W4JMV7GF.js +0 -3
  303. package/dist/cli-bundle/focused-chunks/item-revision-723XCQPS.js +0 -2
  304. package/node_modules/@isaacs/fs-minipass/LICENSE +0 -15
  305. package/node_modules/@isaacs/fs-minipass/README.md +0 -71
  306. package/node_modules/@isaacs/fs-minipass/dist/commonjs/index.d.ts +0 -118
  307. package/node_modules/@isaacs/fs-minipass/dist/commonjs/index.js +0 -430
  308. package/node_modules/@isaacs/fs-minipass/dist/commonjs/package.json +0 -3
  309. package/node_modules/@isaacs/fs-minipass/dist/esm/index.d.ts +0 -118
  310. package/node_modules/@isaacs/fs-minipass/dist/esm/index.js +0 -420
  311. package/node_modules/@isaacs/fs-minipass/dist/esm/package.json +0 -3
  312. package/node_modules/@isaacs/fs-minipass/package.json +0 -72
  313. package/node_modules/chownr/LICENSE.md +0 -63
  314. package/node_modules/chownr/README.md +0 -3
  315. package/node_modules/chownr/dist/commonjs/index.d.ts +0 -3
  316. package/node_modules/chownr/dist/commonjs/index.js +0 -93
  317. package/node_modules/chownr/dist/commonjs/package.json +0 -3
  318. package/node_modules/chownr/dist/esm/index.d.ts +0 -3
  319. package/node_modules/chownr/dist/esm/index.js +0 -85
  320. package/node_modules/chownr/dist/esm/package.json +0 -3
  321. package/node_modules/chownr/package.json +0 -69
  322. package/node_modules/minipass/LICENSE.md +0 -55
  323. package/node_modules/minipass/README.md +0 -825
  324. package/node_modules/minipass/dist/commonjs/index.d.ts +0 -545
  325. package/node_modules/minipass/dist/commonjs/index.js +0 -1038
  326. package/node_modules/minipass/dist/commonjs/package.json +0 -3
  327. package/node_modules/minipass/dist/esm/index.d.ts +0 -545
  328. package/node_modules/minipass/dist/esm/index.js +0 -1020
  329. package/node_modules/minipass/dist/esm/package.json +0 -3
  330. package/node_modules/minipass/package.json +0 -77
  331. package/node_modules/minizlib/LICENSE +0 -26
  332. package/node_modules/minizlib/README.md +0 -64
  333. package/node_modules/minizlib/dist/commonjs/constants.d.ts +0 -2
  334. package/node_modules/minizlib/dist/commonjs/constants.js +0 -123
  335. package/node_modules/minizlib/dist/commonjs/index.d.ts +0 -99
  336. package/node_modules/minizlib/dist/commonjs/index.js +0 -416
  337. package/node_modules/minizlib/dist/commonjs/package.json +0 -3
  338. package/node_modules/minizlib/dist/esm/constants.d.ts +0 -2
  339. package/node_modules/minizlib/dist/esm/constants.js +0 -117
  340. package/node_modules/minizlib/dist/esm/index.d.ts +0 -99
  341. package/node_modules/minizlib/dist/esm/index.js +0 -363
  342. package/node_modules/minizlib/dist/esm/package.json +0 -3
  343. package/node_modules/minizlib/package.json +0 -80
  344. package/node_modules/tar/dist/commonjs/get-write-flag.d.ts +0 -2
  345. package/node_modules/tar/dist/commonjs/get-write-flag.js +0 -32
  346. package/node_modules/tar/dist/commonjs/make-command.d.ts +0 -49
  347. package/node_modules/tar/dist/commonjs/make-command.js +0 -52
  348. package/node_modules/tar/dist/commonjs/normalize-windows-path.d.ts +0 -2
  349. package/node_modules/tar/dist/commonjs/normalize-windows-path.js +0 -12
  350. package/node_modules/tar/dist/commonjs/parse.d.ts +0 -92
  351. package/node_modules/tar/dist/commonjs/parse.js +0 -655
  352. package/node_modules/tar/dist/commonjs/process-umask.d.ts +0 -2
  353. package/node_modules/tar/dist/commonjs/process-umask.js +0 -7
  354. package/node_modules/tar/dist/commonjs/warn-method.d.ts +0 -24
  355. package/node_modules/tar/dist/commonjs/warn-method.js +0 -31
  356. package/node_modules/tar/dist/esm/get-write-flag.d.ts +0 -2
  357. package/node_modules/tar/dist/esm/get-write-flag.js +0 -26
  358. package/node_modules/tar/dist/esm/make-command.d.ts +0 -49
  359. package/node_modules/tar/dist/esm/make-command.js +0 -48
  360. package/node_modules/tar/dist/esm/normalize-windows-path.d.ts +0 -2
  361. package/node_modules/tar/dist/esm/normalize-windows-path.js +0 -9
  362. package/node_modules/tar/dist/esm/parse.d.ts +0 -92
  363. package/node_modules/tar/dist/esm/parse.js +0 -651
  364. package/node_modules/tar/dist/esm/process-umask.d.ts +0 -2
  365. package/node_modules/tar/dist/esm/process-umask.js +0 -3
  366. package/node_modules/tar/dist/esm/warn-method.d.ts +0 -24
  367. package/node_modules/tar/dist/esm/warn-method.js +0 -27
  368. package/node_modules/yallist/LICENSE.md +0 -63
  369. package/node_modules/yallist/README.md +0 -205
  370. package/node_modules/yallist/dist/commonjs/index.d.ts +0 -39
  371. package/node_modules/yallist/dist/commonjs/index.js +0 -384
  372. package/node_modules/yallist/dist/commonjs/package.json +0 -3
  373. package/node_modules/yallist/dist/esm/index.d.ts +0 -39
  374. package/node_modules/yallist/dist/esm/index.js +0 -379
  375. package/node_modules/yallist/dist/esm/package.json +0 -3
  376. package/node_modules/yallist/package.json +0 -68
@@ -1,373 +1,331 @@
1
- // the PEND/UNPEND stuff tracks whether we're ready to emit end/close yet.
2
- // but the path reservations are required to avoid race conditions where
3
- // parallelized unpack ops may mess with one another, due to dependencies
4
- // (like a Link depending on its target) or destructive operations (like
5
- // clobbering an fs object to create one of a different type.)
6
- import * as fsm from '@isaacs/fs-minipass';
7
- import assert from 'node:assert';
8
- import { randomBytes } from 'node:crypto';
9
- import fs from 'node:fs';
10
- import path from 'node:path';
11
- import { getWriteFlag } from './get-write-flag.js';
12
- import { mkdir, mkdirSync } from './mkdir.js';
13
- import { normalizeWindowsPath } from './normalize-windows-path.js';
14
- import { Parser } from './parse.js';
15
- import { stripAbsolutePath } from './strip-absolute-path.js';
1
+ import { SymlinkError } from './symlink-error.js';
16
2
  import * as wc from './winchars.js';
3
+ import { TarReader, TarReaderSync } from './entries.js';
4
+ import { mkdir, mkdirSync } from './mkdir.js';
5
+ import { countOption, ownOptions, } from './options.js';
17
6
  import { PathReservations } from './path-reservations.js';
18
- import { SymlinkError } from './symlink-error.js';
19
- import { umask } from './process-umask.js';
20
- const ONENTRY = Symbol('onEntry');
21
- const CHECKFS = Symbol('checkFs');
22
- const CHECKFS2 = Symbol('checkFs2');
23
- const ISREUSABLE = Symbol('isReusable');
24
- const MAKEFS = Symbol('makeFs');
25
- const FILE = Symbol('file');
26
- const DIRECTORY = Symbol('directory');
27
- const LINK = Symbol('link');
28
- const SYMLINK = Symbol('symlink');
29
- const HARDLINK = Symbol('hardlink');
30
- const ENSURE_NO_SYMLINK = Symbol('ensureNoSymlink');
31
- const UNSUPPORTED = Symbol('unsupported');
32
- const CHECKPATH = Symbol('checkPath');
33
- const STRIPABSOLUTEPATH = Symbol('stripAbsolutePath');
34
- const MKDIR = Symbol('mkdir');
35
- const ONERROR = Symbol('onError');
36
- const PENDING = Symbol('pending');
37
- const PEND = Symbol('pend');
38
- const UNPEND = Symbol('unpend');
39
- const ENDED = Symbol('ended');
40
- const MAYBECLOSE = Symbol('maybeClose');
41
- const SKIP = Symbol('skip');
42
- const DOCHOWN = Symbol('doChown');
43
- const UID = Symbol('uid');
44
- const GID = Symbol('gid');
45
- const CHECKED_CWD = Symbol('checkedCwd');
46
- const platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
47
- const isWindows = platform === 'win32';
7
+ import { dirname, isAbsolute, join, normalize, relative, resolve, } from './path.js';
8
+ import { stripAbsolutePath } from './strip-absolute-path.js';
9
+ import { warn } from './warn.js';
10
+ import { win32Dirname, win32IsAbsolute, win32Resolve, win32Root, } from './win32-path.js';
11
+ import { writeFlags } from './write-flag.js';
48
12
  const DEFAULT_MAX_DEPTH = 1024;
49
- // Unlinks on Windows are not atomic.
50
- //
51
- // This means that if you have a file entry, followed by another
52
- // file entry with an identical name, and you cannot re-use the file
53
- // (because it's a hardlink, or because unlink:true is set, or it's
54
- // Windows, which does not have useful nlink values), then the unlink
55
- // will be committed to the disk AFTER the new file has been written
56
- // over the old one, deleting the new file.
57
- //
58
- // To work around this, on Windows systems, we rename the file and then
59
- // delete the renamed file. It's a sloppy kludge, but frankly, I do not
60
- // know of a better way to do this, given windows' non-atomic unlink
61
- // semantics.
62
- //
63
- // See: https://github.com/npm/node-tar/issues/183
64
- /* c8 ignore start */
65
- const unlinkFile = (path, cb) => {
66
- if (!isWindows) {
67
- return fs.unlink(path, cb);
68
- }
69
- const name = path + '.DELETE.' + randomBytes(16).toString('hex');
70
- fs.rename(path, name, er => {
71
- if (er) {
72
- return cb(er);
73
- }
74
- fs.unlink(name, cb);
75
- });
76
- };
77
- /* c8 ignore stop */
78
- /* c8 ignore start */
79
- const unlinkFileSync = (path) => {
80
- if (!isWindows) {
81
- return fs.unlinkSync(path);
82
- }
83
- const name = path + '.DELETE.' + randomBytes(16).toString('hex');
84
- fs.renameSync(path, name);
85
- fs.unlinkSync(name);
86
- };
87
- /* c8 ignore stop */
88
- // this.gid, entry.gid, this.processUid
89
- const uint32 = (a, b, c) => a !== undefined && a === a >>> 0 ? a
13
+ // Longer than any path that a supported platform can create.
14
+ const MAX_PATH_LENGTH = 32768;
15
+ const DEFAULT_JOBS = 16;
16
+ const fileTypes = new Set([
17
+ 'File',
18
+ 'OldFile',
19
+ 'ContiguousFile',
20
+ ]);
21
+ const dirTypes = new Set(['Directory', 'GNUDumpDir']);
22
+ const linkTypes = new Set(['Link', 'SymbolicLink']);
23
+ // The first of the values that is an unsigned 32-bit integer, or the
24
+ // last value.
25
+ const uint32 = (a, b, c) => a !== undefined ? a
90
26
  : b !== undefined && b === b >>> 0 ? b
91
27
  : c;
92
- export class Unpack extends Parser {
93
- [ENDED] = false;
94
- [CHECKED_CWD] = false;
95
- [PENDING] = 0;
96
- reservations = new PathReservations();
97
- transform;
98
- writable = true;
99
- readable = false;
28
+ /**
29
+ * The parts of the extraction that do not use the file system: the
30
+ * options, the checks of each entry, and the warnings. `Unpack` and
31
+ * `UnpackSync` add the file system work.
32
+ */
33
+ export class UnpackBase {
34
+ /** The options, with no prototype. */
35
+ opt;
36
+ /** The absolute path of the extraction directory. */
37
+ cwd;
38
+ win32;
39
+ strip;
40
+ maxDepth;
41
+ preservePaths;
42
+ unlink;
43
+ keep;
44
+ newer;
45
+ noMtime;
46
+ chmod;
100
47
  uid;
101
48
  gid;
102
- setOwner;
103
49
  preserveOwner;
104
- processGid;
105
- processUid;
106
- maxDepth;
107
50
  forceChown;
108
- win32;
109
- newer;
110
- keep;
111
- noMtime;
112
- preservePaths;
113
- unlink;
114
- cwd;
115
- strip;
51
+ processUid;
52
+ processGid;
116
53
  processUmask;
117
54
  umask;
118
55
  dmode;
119
56
  fmode;
120
- chmod;
121
- constructor(opt = {}) {
122
- opt.ondone = () => {
123
- this[ENDED] = true;
124
- this[MAYBECLOSE]();
125
- };
126
- super(opt);
127
- this.transform = opt.transform;
128
- this.chmod = !!opt.chmod;
57
+ /** Gives the `open` flag for a new file of a given size. */
58
+ writeFlag;
59
+ /** Resolve a path from an absolute path. */
60
+ resolve;
61
+ /** The parent directory of an absolute path. */
62
+ dirname;
63
+ /** Set when an error stops the extraction. */
64
+ fatal;
65
+ constructor(options) {
66
+ const opt = (this.opt = ownOptions(options));
67
+ const win32 = (this.win32 = opt.platform === 'win32');
68
+ this.resolve = win32 ? win32Resolve : resolve;
69
+ this.dirname = win32 ? win32Dirname : dirname;
70
+ if (typeof opt.cwd !== 'string') {
71
+ throw new TypeError('cwd is required');
72
+ }
73
+ const cwd = win32 ? opt.cwd.replaceAll('\\', '/') : opt.cwd;
74
+ if (!(win32 ? win32IsAbsolute : isAbsolute)(cwd)) {
75
+ throw new TypeError('cwd must be an absolute path');
76
+ }
77
+ this.cwd = this.resolve(cwd, '');
129
78
  if (typeof opt.uid === 'number' || typeof opt.gid === 'number') {
130
79
  // need both or neither
131
80
  if (typeof opt.uid !== 'number' || typeof opt.gid !== 'number') {
132
81
  throw new TypeError('cannot set owner without number uid and gid');
133
82
  }
83
+ // A value that is not valid must not fall back to the owner
84
+ // in the archive.
85
+ if (opt.uid !== opt.uid >>> 0 || opt.gid !== opt.gid >>> 0) {
86
+ throw new TypeError('uid and gid must be unsigned 32-bit integers');
87
+ }
134
88
  if (opt.preserveOwner) {
135
89
  throw new TypeError('cannot preserve owner in archive and also set owner explicitly');
136
90
  }
137
91
  this.uid = opt.uid;
138
92
  this.gid = opt.gid;
139
- this.setOwner = true;
140
- }
141
- else {
142
- this.uid = undefined;
143
- this.gid = undefined;
144
- this.setOwner = false;
145
93
  }
146
- // default true for root
94
+ this.processUid = opt.processUid;
95
+ this.processGid = opt.processGid;
147
96
  this.preserveOwner =
148
97
  opt.preserveOwner === undefined && typeof opt.uid !== 'number' ?
149
- !!(process.getuid?.() === 0)
98
+ opt.processUid === 0
150
99
  : !!opt.preserveOwner;
151
- this.processUid =
152
- (this.preserveOwner || this.setOwner) && process.getuid ?
153
- process.getuid()
154
- : undefined;
155
- this.processGid =
156
- (this.preserveOwner || this.setOwner) && process.getgid ?
157
- process.getgid()
158
- : undefined;
159
- // prevent excessively deep nesting of subfolders
160
- // set to `Infinity` to remove this restriction
100
+ this.forceChown = opt.forceChown === true;
161
101
  this.maxDepth =
162
102
  typeof opt.maxDepth === 'number' ? opt.maxDepth : DEFAULT_MAX_DEPTH;
163
- // mostly just for testing, but useful in some cases.
164
- // Forcibly trigger a chown on every entry, no matter what
165
- this.forceChown = opt.forceChown === true;
166
- // turn ><?| in filenames into 0xf000-higher encoded forms
167
- this.win32 = !!opt.win32 || isWindows;
168
- // do not unpack over files that are newer than what's in the archive
169
- this.newer = !!opt.newer;
170
- // do not unpack over ANY files
171
- this.keep = !!opt.keep;
172
- // do not set mtime/atime of extracted entries
173
- this.noMtime = !!opt.noMtime;
174
- // allow .., absolute path entries, and unpacking through symlinks
175
- // without this, warn and skip .., relativize absolutes, and error
176
- // on symlinks in extraction path
103
+ this.strip = Number(opt.strip) || 0;
177
104
  this.preservePaths = !!opt.preservePaths;
178
- // unlink files and links before writing. This breaks existing hard
179
- // links, and removes symlink directories rather than erroring
180
105
  this.unlink = !!opt.unlink;
181
- this.cwd = normalizeWindowsPath(path.resolve(opt.cwd || process.cwd()));
182
- this.strip = Number(opt.strip) || 0;
183
- // if we're not chmodding, then we don't need the process umask
106
+ this.keep = !!opt.keep;
107
+ this.newer = !!opt.newer;
108
+ this.noMtime = !!opt.noMtime;
109
+ this.chmod = !!opt.chmod;
110
+ // Without chmod, the umask of the process is not needed.
184
111
  this.processUmask =
185
112
  !this.chmod ? 0
186
113
  : typeof opt.processUmask === 'number' ? opt.processUmask
187
- : umask();
114
+ : 0o22;
188
115
  this.umask =
189
116
  typeof opt.umask === 'number' ? opt.umask : this.processUmask;
190
- // default mode for dirs created as parents
191
- this.dmode = opt.dmode || 0o0777 & ~this.umask;
192
- this.fmode = opt.fmode || 0o0666 & ~this.umask;
193
- this.on('entry', entry => this[ONENTRY](entry));
194
- }
195
- // a bad or damaged archive is a warning for Parser, but an error
196
- // when extracting. Mark those errors as unrecoverable, because
197
- // the Unpack contract cannot be met.
198
- warn(code, msg, data = {}) {
117
+ this.dmode = opt.dmode || 0o777 & ~this.umask;
118
+ this.fmode = opt.fmode || 0o666 & ~this.umask;
119
+ this.writeFlag = writeFlags(opt.fs.constants, win32);
120
+ }
121
+ /**
122
+ * Report a problem to `onwarn`, or throw it if `strict` is set. A
123
+ * damaged archive is always an error here, because the extraction
124
+ * cannot be complete.
125
+ */
126
+ warn(code, message, data = {}) {
199
127
  if (code === 'TAR_BAD_ARCHIVE' || code === 'TAR_ABORT') {
200
128
  data.recoverable = false;
201
129
  }
202
- return super.warn(code, msg, data);
130
+ data.cwd = this.cwd;
131
+ warn(this.opt, code, message, data);
203
132
  }
204
- [MAYBECLOSE]() {
205
- if (this[ENDED] && this[PENDING] === 0) {
206
- this.emit('prefinish');
207
- this.emit('finish');
208
- this.emit('end');
209
- }
133
+ /** The options for the reader. Its warnings go to `warn()`. */
134
+ readerOptions() {
135
+ return ownOptions(this.opt, {
136
+ strict: false,
137
+ onwarn: (code, message, data) => this.warn(code, message, data),
138
+ });
210
139
  }
211
- // return false if we need to skip this file
212
- // return true if the field was successfully sanitized
213
- [STRIPABSOLUTEPATH](entry, field) {
140
+ /**
141
+ * Report the failure of one entry as a `TAR_ENTRY_ERROR` warning.
142
+ * Throws the error if it stops the extraction: the extraction
143
+ * directory is not usable, the archive cannot be read, or `strict`
144
+ * is set.
145
+ */
146
+ entryError(er, entry) {
147
+ if (this.fatal?.error === er || er?.name === 'CwdError') {
148
+ throw er;
149
+ }
150
+ this.warn('TAR_ENTRY_ERROR', er, { entry });
151
+ }
152
+ /** Record the error that stops the extraction. Returns it. */
153
+ fail(error) {
154
+ this.fatal ??= { error };
155
+ return error;
156
+ }
157
+ // Remove the root of an absolute path, and refuse a path that can
158
+ // leave the extraction directory. False if the entry is refused.
159
+ #stripAbsolutePath(entry, field) {
214
160
  const p = entry[field];
215
- const { type } = entry;
216
161
  if (!p || this.preservePaths)
217
162
  return true;
218
- // strip off the root
219
163
  const [root, stripped] = stripAbsolutePath(p);
220
- const parts = stripped.replaceAll(/\\/g, '/').split('/');
221
- if (parts.includes('..') ||
222
- /* c8 ignore next */
223
- (isWindows && /^[a-z]:\.\.$/i.test(parts[0] ?? ''))) {
224
- // For linkpath, check if the resolved path escapes cwd rather than
225
- // just rejecting any path with '..' - relative symlinks like
226
- // '../sibling/file' are valid if they resolve within the cwd.
227
- // For paths, they just simply may not ever use .. at all.
228
- if (field === 'path' || type === 'Link') {
164
+ const parts = stripped.replaceAll('\\', '/').split('/');
165
+ if (parts.includes('..')) {
166
+ // A path, and the target of a hard link, cannot have '..' at
167
+ // all. The target of a symbolic link is relative to the
168
+ // directory of the link, so '../sibling/file' can be valid.
169
+ if (field === 'path' || entry.type === 'Link') {
229
170
  this.warn('TAR_ENTRY_ERROR', `${field} contains '..'`, {
230
171
  entry,
231
172
  [field]: p,
232
173
  });
233
- // not ok!
234
174
  return false;
235
175
  }
236
- // Resolve linkpath relative to the entry's directory.
237
- // `path.posix` is safe to use because we're operating on
238
- // tar paths, not a filesystem.
239
- const entryDir = path.posix.dirname(entry.path);
240
- const resolved = path.posix.normalize(path.posix.join(entryDir, parts.join('/')));
241
- // If the resolved path escapes (starts with ..), reject it
176
+ // A '..' is only safe at the start of the target. Any named
177
+ // part before it can be a symlink, and then the '..' goes to
178
+ // the parent of the target of that symlink.
179
+ const firstName = parts.findIndex(part => part !== '..' && part !== '.' && part !== '');
180
+ if (firstName !== -1 && parts.includes('..', firstName)) {
181
+ this.warn('TAR_ENTRY_ERROR', `${field} contains '..' after a path portion`, { entry, [field]: p });
182
+ return false;
183
+ }
184
+ // Normalize the path, so that the directory is the one where
185
+ // the link is created. The path 'x/.' creates the link 'x'.
186
+ const entryDir = dirname(normalize(entry.path));
187
+ const resolved = normalize(join(entryDir, parts.join('/')));
242
188
  if (resolved.startsWith('../') || resolved === '..') {
243
- this.warn('TAR_ENTRY_ERROR', `${field} escapes extraction directory`, {
244
- entry,
245
- [field]: p,
246
- });
189
+ this.warn('TAR_ENTRY_ERROR', `${field} escapes extraction directory`, { entry, [field]: p });
247
190
  return false;
248
191
  }
249
192
  }
250
193
  if (root) {
251
- // ok, but triggers warning about stripping root
252
- entry[field] = String(stripped);
253
- this.warn('TAR_ENTRY_INFO', `stripping ${root} from absolute ${field}`, {
254
- entry,
255
- [field]: p,
256
- });
194
+ ;
195
+ entry[field] = stripped;
196
+ this.warn('TAR_ENTRY_INFO', `stripping ${root} from absolute ${field}`, { entry, [field]: p });
257
197
  }
258
198
  return true;
259
199
  }
260
- // no IO, just string checking for absolute indicators
261
- [CHECKPATH](entry) {
262
- const p = normalizeWindowsPath(entry.path);
200
+ /**
201
+ * Check the entry, with no use of the file system. Set its
202
+ * `absolute` path, and change its `path`, `linkpath`, and `mode` to
203
+ * the values to extract. False if the entry must not be extracted.
204
+ */
205
+ check(entry) {
206
+ const p = entry.path;
263
207
  const parts = p.split('/');
264
208
  if (this.strip) {
265
- if (parts.length < this.strip) {
209
+ if (parts.length < this.strip)
266
210
  return false;
267
- }
268
211
  if (entry.type === 'Link') {
269
- const linkparts = normalizeWindowsPath(String(entry.linkpath)).split('/');
270
- if (linkparts.length >= this.strip) {
271
- entry.linkpath = linkparts.slice(this.strip).join('/');
272
- }
273
- else {
212
+ const linkparts = String(entry.linkpath).split('/');
213
+ if (linkparts.length < this.strip)
274
214
  return false;
275
- }
215
+ entry.linkpath = linkparts.slice(this.strip).join('/');
276
216
  }
277
217
  parts.splice(0, this.strip);
218
+ // No part of the path is left, as for the top directory of a
219
+ // package. The entry must not change the extraction directory.
220
+ if (parts.every(part => part === ''))
221
+ return false;
278
222
  entry.path = parts.join('/');
279
223
  }
280
- if (isFinite(this.maxDepth) && parts.length > this.maxDepth) {
224
+ const { maxDepth } = this;
225
+ if (isFinite(maxDepth) && parts.length > maxDepth) {
281
226
  this.warn('TAR_ENTRY_ERROR', 'path excessively deep', {
282
227
  entry,
283
228
  path: p,
284
229
  depth: parts.length,
285
- maxDepth: this.maxDepth,
230
+ maxDepth,
231
+ });
232
+ return false;
233
+ }
234
+ // The path reservations do work for each parent directory of the
235
+ // path and of the linkpath.
236
+ const { linkpath } = entry;
237
+ if (linkpath &&
238
+ isFinite(maxDepth) &&
239
+ linkpath.split('/').length > maxDepth) {
240
+ this.warn('TAR_ENTRY_ERROR', 'linkpath excessively deep', {
241
+ entry,
242
+ path: p,
243
+ linkpath,
244
+ maxDepth,
286
245
  });
287
246
  return false;
288
247
  }
289
- if (!this[STRIPABSOLUTEPATH](entry, 'path') ||
290
- !this[STRIPABSOLUTEPATH](entry, 'linkpath')) {
248
+ for (const field of ['path', 'linkpath']) {
249
+ const { length } = entry[field] ?? '';
250
+ if (length > MAX_PATH_LENGTH) {
251
+ this.warn('TAR_ENTRY_ERROR', `${field} excessively long`, {
252
+ entry,
253
+ path: p,
254
+ length,
255
+ maxLength: MAX_PATH_LENGTH,
256
+ });
257
+ return false;
258
+ }
259
+ }
260
+ if (!this.#stripAbsolutePath(entry, 'path') ||
261
+ !this.#stripAbsolutePath(entry, 'linkpath')) {
291
262
  return false;
292
263
  }
293
- entry.absolute =
294
- path.isAbsolute(entry.path) ?
295
- normalizeWindowsPath(path.resolve(entry.path))
296
- : normalizeWindowsPath(path.resolve(this.cwd, entry.path));
297
- // if we somehow ended up with a path that escapes the cwd, and we are
298
- // not in preservePaths mode, then something is fishy! This should have
299
- // been prevented above, so ignore this for coverage.
300
- /* c8 ignore start - defense in depth */
264
+ const { cwd } = this;
265
+ let absolute = this.resolve(cwd, entry.path);
266
+ // The checks above refuse a path that leaves the extraction
267
+ // directory. This check is defense in depth.
301
268
  if (!this.preservePaths &&
302
- typeof entry.absolute === 'string' &&
303
- entry.absolute.indexOf(this.cwd + '/') !== 0 &&
304
- entry.absolute !== this.cwd) {
269
+ absolute !== cwd &&
270
+ // A root, such as `/` or `c:/`, ends with a slash.
271
+ !absolute.startsWith(cwd.endsWith('/') ? cwd : cwd + '/')) {
305
272
  this.warn('TAR_ENTRY_ERROR', 'path escaped extraction target', {
306
273
  entry,
307
- path: normalizeWindowsPath(entry.path),
308
- resolvedPath: entry.absolute,
309
- cwd: this.cwd,
274
+ path: entry.path,
275
+ resolvedPath: absolute,
276
+ cwd,
310
277
  });
311
278
  return false;
312
279
  }
313
- /* c8 ignore stop */
314
- // an archive can set properties on the extraction directory, but it
315
- // may not replace the cwd with a different kind of thing entirely.
316
- if (entry.absolute === this.cwd &&
317
- entry.type !== 'Directory' &&
318
- entry.type !== 'GNUDumpDir') {
280
+ // An archive can set properties of the extraction directory, but
281
+ // it cannot replace it with a different kind of thing.
282
+ if (absolute === cwd && !dirTypes.has(entry.type))
319
283
  return false;
320
- }
321
- // only encode : chars that aren't drive letter indicators
284
+ // Do not change the ':' of a drive letter.
322
285
  if (this.win32) {
323
- const { root: aRoot } = path.win32.parse(String(entry.absolute));
324
- entry.absolute =
325
- aRoot + wc.encode(String(entry.absolute).slice(aRoot.length));
326
- const { root: pRoot } = path.win32.parse(entry.path);
286
+ const aRoot = win32Root(absolute);
287
+ absolute = aRoot + wc.encode(absolute.slice(aRoot.length));
288
+ const pRoot = win32Root(entry.path);
327
289
  entry.path = pRoot + wc.encode(entry.path.slice(pRoot.length));
328
290
  }
329
- return true;
330
- }
331
- [ONENTRY](entry) {
332
- if (!this[CHECKPATH](entry)) {
333
- return entry.resume();
334
- }
335
- assert.equal(typeof entry.absolute, 'string');
336
- switch (entry.type) {
337
- case 'Directory':
338
- case 'GNUDumpDir':
339
- if (entry.mode) {
340
- entry.mode = entry.mode | 0o700;
341
- }
342
- // eslint-disable-next-line no-fallthrough
343
- case 'File':
344
- case 'OldFile':
345
- case 'ContiguousFile':
346
- case 'Link':
347
- case 'SymbolicLink':
348
- return this[CHECKFS](entry);
349
- case 'CharacterDevice':
350
- case 'BlockDevice':
351
- case 'FIFO':
352
- default:
353
- return this[UNSUPPORTED](entry);
354
- }
355
- }
356
- [ONERROR](er, entry) {
357
- // Cwd has to exist, or else nothing works. That's serious.
358
- // Other errors are warnings, which raise the error in strict
359
- // mode, but otherwise continue on.
360
- if (er.name === 'CwdError') {
361
- this.emit('error', er);
362
- }
363
- else {
364
- this.warn('TAR_ENTRY_ERROR', er, { entry });
365
- this[UNPEND]();
366
- entry.resume();
291
+ entry.absolute = absolute;
292
+ // Never set the setuid, setgid, or sticky bit from an archive.
293
+ if (typeof entry.mode === 'number')
294
+ entry.mode &= 0o777;
295
+ if (dirTypes.has(entry.type)) {
296
+ if (entry.mode)
297
+ entry.mode |= 0o700;
298
+ }
299
+ else if (!fileTypes.has(entry.type) && !linkTypes.has(entry.type)) {
300
+ // A device or a FIFO is never made.
301
+ entry.unsupported = true;
302
+ this.warn('TAR_ENTRY_UNSUPPORTED', `unsupported entry type: ${entry.type}`, { entry });
303
+ return false;
367
304
  }
305
+ return true;
368
306
  }
369
- [MKDIR](dir, mode, cb) {
370
- void mkdir(normalizeWindowsPath(dir), {
307
+ /**
308
+ * The paths that the entry must have for itself while it is made.
309
+ * A link also reserves its target, so that an entry that makes the
310
+ * target, and an entry that goes through the link, do not run at
311
+ * the same time as the link.
312
+ */
313
+ reservedPaths(entry) {
314
+ const { path, linkpath } = entry;
315
+ if (!linkpath)
316
+ return [path];
317
+ // The target of a symlink is relative to the directory of the
318
+ // link. The target of a hard link is relative to the cwd.
319
+ return [
320
+ path,
321
+ entry.type === 'SymbolicLink' && !isAbsolute(linkpath) ?
322
+ join(dirname(path), linkpath)
323
+ : linkpath,
324
+ ];
325
+ }
326
+ /** The options to make a directory with a mode. */
327
+ mkdirOptions(mode) {
328
+ return {
371
329
  uid: this.uid,
372
330
  gid: this.gid,
373
331
  processUid: this.processUid,
@@ -376,516 +334,615 @@ export class Unpack extends Parser {
376
334
  preserve: this.preservePaths,
377
335
  unlink: this.unlink,
378
336
  cwd: this.cwd,
379
- mode: mode,
380
- }, cb);
337
+ mode,
338
+ };
381
339
  }
382
- [DOCHOWN](entry) {
383
- // in preserve owner mode, chown if the entry doesn't match process
384
- // in set owner mode, chown if setting doesn't match process
385
- return (this.forceChown ||
340
+ /**
341
+ * The owner to set on the entry, if it needs one: with
342
+ * `preserveOwner`, when the owner in the archive is not the process
343
+ * owner, and with `uid` and `gid`, when they are not the process
344
+ * owner.
345
+ */
346
+ owner(entry) {
347
+ const doChown = this.forceChown ||
386
348
  (this.preserveOwner &&
387
349
  ((typeof entry.uid === 'number' &&
388
350
  entry.uid !== this.processUid) ||
389
351
  (typeof entry.gid === 'number' &&
390
352
  entry.gid !== this.processGid))) ||
391
353
  (typeof this.uid === 'number' && this.uid !== this.processUid) ||
392
- (typeof this.gid === 'number' && this.gid !== this.processGid));
393
- }
394
- [UID](entry) {
395
- return uint32(this.uid, entry.uid, this.processUid);
396
- }
397
- [GID](entry) {
398
- return uint32(this.gid, entry.gid, this.processGid);
354
+ (typeof this.gid === 'number' && this.gid !== this.processGid);
355
+ const uid = uint32(this.uid, entry.uid, this.processUid);
356
+ const gid = uint32(this.gid, entry.gid, this.processGid);
357
+ return doChown && typeof uid === 'number' && typeof gid === 'number' ?
358
+ { uid, gid }
359
+ : undefined;
360
+ }
361
+ /** The times to set on the entry, if it needs them. */
362
+ times(entry) {
363
+ return entry.mtime && !this.noMtime ?
364
+ { atime: entry.atime || new Date(), mtime: entry.mtime }
365
+ : undefined;
366
+ }
367
+ /** True if the object on disk at the path of the entry must stay. */
368
+ skip(entry, st) {
369
+ return (this.keep || (this.newer && st.mtime > (entry.mtime ?? st.mtime)));
370
+ }
371
+ /**
372
+ * True if the entry can be written into the file that is on disk.
373
+ * A file with more than one link is not used, because the write
374
+ * would change the other links. Windows does not report a useful
375
+ * link count.
376
+ */
377
+ isReusable(entry, st) {
378
+ return (entry.type === 'File' &&
379
+ !this.unlink &&
380
+ st.isFile() &&
381
+ st.nlink <= 1 &&
382
+ !this.win32);
383
+ }
384
+ /**
385
+ * The parts of the path from the extraction directory to the
386
+ * target of a link entry. None of them can be a symbolic link.
387
+ */
388
+ linkParts(entry, absolute) {
389
+ const linkpath = String(entry.linkpath);
390
+ return entry.type === 'Link' ?
391
+ linkpath.split('/')
392
+ : relative(this.cwd, this.resolve(this.dirname(absolute), linkpath)).split('/');
393
+ }
394
+ /**
395
+ * The parts of the path from the extraction directory to the
396
+ * parent directory of an entry. The extraction checks them again
397
+ * after it makes the entry: none of them can be a symbolic link
398
+ * then. So a directory that another process replaced with a
399
+ * symbolic link during the extraction is an error of the entry.
400
+ */
401
+ parentParts(absolute) {
402
+ const { cwd } = this;
403
+ const parent = absolute === cwd ? cwd : this.dirname(absolute);
404
+ return parent === cwd ? [] : relative(cwd, parent).split('/');
405
+ }
406
+ /** The error for a link target that goes through a symbolic link. */
407
+ symlinkError(symlink, parts) {
408
+ return new SymlinkError(symlink, this.resolve(this.cwd, parts.join('/')));
399
409
  }
400
- [FILE](entry, fullyDone) {
401
- const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.fmode;
402
- const stream = new fsm.WriteStream(String(entry.absolute), {
403
- // slight lie, but it can be numeric flags
404
- flags: getWriteFlag(entry.size),
405
- mode: mode,
406
- autoClose: false,
407
- });
408
- stream.on('error', (er) => {
409
- if (stream.fd) {
410
- fs.close(stream.fd, () => { });
411
- }
412
- // flush all the data out so that we aren't left hanging
413
- // if the error wasn't actually fatal. otherwise the parse
414
- // is blocked, and we never proceed.
415
- stream.write = () => true;
416
- this[ONERROR](er, entry);
417
- fullyDone();
418
- });
419
- let actions = 1;
420
- const done = (er) => {
421
- if (er) {
422
- /* c8 ignore start - we should always have a fd by now */
423
- if (stream.fd) {
424
- fs.close(stream.fd, () => { });
410
+ }
411
+ // Unlinks on Windows are not atomic. A file that is made at the path
412
+ // of a file that was just removed can be removed with it. So rename
413
+ // the file first, and then remove it under the new name.
414
+ const deleteName = (path) => path +
415
+ '.DELETE.' +
416
+ Array.from(crypto.getRandomValues(new Uint8Array(16)), b => b.toString(16).padStart(2, '0')).join('');
417
+ /**
418
+ * Extracts the entries of an archive with async file system
419
+ * functions.
420
+ *
421
+ * Several entries are extracted at one time. Entries that use the
422
+ * same path, or a path and a directory above it, are extracted in
423
+ * the order of the archive.
424
+ */
425
+ export class Unpack extends UnpackBase {
426
+ #fs;
427
+ #reservations;
428
+ #jobs;
429
+ // the number of entries that are in work
430
+ #active = 0;
431
+ #wake;
432
+ #checkedCwd = false;
433
+ #cwdCheck;
434
+ constructor(opt) {
435
+ super(opt);
436
+ this.#fs = this.opt.fs;
437
+ this.#reservations = new PathReservations(this.win32);
438
+ this.#jobs = countOption('jobs', this.opt.jobs, DEFAULT_JOBS);
439
+ }
440
+ /**
441
+ * Extract the archive. The promise settles when all the file
442
+ * system work is done. It rejects with the first error that stops
443
+ * the extraction.
444
+ */
445
+ async extract(input) {
446
+ const reader = new TarReader(input, this.readerOptions());
447
+ const { onEntry } = this.opt;
448
+ const stream = !!this.opt.transform;
449
+ try {
450
+ while (!this.fatal) {
451
+ const entry = reader.poll();
452
+ if (entry === null)
453
+ break;
454
+ if (entry === undefined) {
455
+ await reader.fill();
456
+ continue;
425
457
  }
426
- /* c8 ignore stop */
427
- this[ONERROR](er, entry);
428
- fullyDone();
429
- return;
430
- }
431
- if (--actions === 0) {
432
- if (stream.fd !== undefined) {
433
- fs.close(stream.fd, er => {
434
- if (er) {
435
- this[ONERROR](er, entry);
458
+ if (onEntry)
459
+ await onEntry(entry);
460
+ // The caller took the content, so there is nothing to write.
461
+ if (entry.bodyUsed)
462
+ continue;
463
+ if (!this.check(entry))
464
+ continue;
465
+ // A file whose content is all in memory is written while the
466
+ // next entries are read. Other files are written as their
467
+ // content arrives.
468
+ const body = [];
469
+ let inMemory = !stream;
470
+ if (inMemory && fileTypes.has(entry.type)) {
471
+ for (;;) {
472
+ const part = reader.readBody(entry);
473
+ if (part === null)
474
+ break;
475
+ if (part === undefined) {
476
+ inMemory = false;
477
+ break;
436
478
  }
437
- else {
438
- this[UNPEND]();
439
- }
440
- fullyDone();
441
- });
479
+ body.push(part);
480
+ }
442
481
  }
482
+ const work = this.#start(entry, body, inMemory ? undefined : reader);
483
+ if (!inMemory)
484
+ await work;
485
+ while (this.#active >= this.#jobs)
486
+ await this.#idle();
443
487
  }
444
- };
445
- stream.on('finish', () => {
446
- // if futimes fails, try utimes
447
- // if utimes fails, fail with the original error
448
- // same for fchown/chown
449
- const abs = String(entry.absolute);
450
- const fd = stream.fd;
451
- if (typeof fd === 'number' && entry.mtime && !this.noMtime) {
452
- actions++;
453
- const atime = entry.atime || new Date();
454
- const mtime = entry.mtime;
455
- fs.futimes(fd, atime, mtime, er => er ?
456
- fs.utimes(abs, atime, mtime, er2 => done(er2 && er))
457
- : done());
458
- }
459
- if (typeof fd === 'number' && this[DOCHOWN](entry)) {
460
- actions++;
461
- const uid = this[UID](entry);
462
- const gid = this[GID](entry);
463
- if (typeof uid === 'number' && typeof gid === 'number') {
464
- fs.fchown(fd, uid, gid, er => er ? fs.chown(abs, uid, gid, er2 => done(er2 && er)) : done());
465
- }
488
+ }
489
+ catch (er) {
490
+ this.fail(er);
491
+ }
492
+ await reader.return().catch(er => this.fail(er));
493
+ while (this.#active > 0)
494
+ await this.#idle();
495
+ if (this.fatal) {
496
+ const { error } = this.fatal;
497
+ if (error && typeof error === 'object' && 'tarCode' in error) {
498
+ Object.assign(error, { cwd: this.cwd });
466
499
  }
467
- done();
468
- });
469
- const tx = this.transform ? this.transform(entry) || entry : entry;
470
- if (tx !== entry) {
471
- tx.on('error', er => {
472
- this[ONERROR](er, entry);
473
- fullyDone();
474
- });
475
- entry.pipe(tx);
500
+ throw error;
476
501
  }
477
- tx.pipe(stream);
478
502
  }
479
- [DIRECTORY](entry, fullyDone) {
480
- const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.dmode;
481
- this[MKDIR](String(entry.absolute), mode, er => {
482
- if (er) {
483
- this[ONERROR](er, entry);
484
- fullyDone();
485
- return;
503
+ // Resolves when an entry that is in work is done.
504
+ #idle() {
505
+ return new Promise(res => {
506
+ this.#wake = res;
507
+ });
508
+ }
509
+ // Extract the entry when its paths are free. The promise never
510
+ // rejects: a failure is a warning, or it sets `fatal`.
511
+ #start(entry, body, reader) {
512
+ this.#active++;
513
+ return this.#reservations.reserve(this.reservedPaths(entry), async () => {
514
+ try {
515
+ if (!this.fatal)
516
+ await this.#extract(entry, body, reader);
486
517
  }
487
- let actions = 1;
488
- const done = () => {
489
- if (--actions === 0) {
490
- fullyDone();
491
- this[UNPEND]();
492
- entry.resume();
518
+ catch (er) {
519
+ try {
520
+ this.entryError(er, entry);
521
+ }
522
+ catch (fatal) {
523
+ this.fail(fatal);
493
524
  }
494
- };
495
- if (entry.mtime && !this.noMtime) {
496
- actions++;
497
- fs.utimes(String(entry.absolute), entry.atime || new Date(), entry.mtime, done);
498
- }
499
- if (this[DOCHOWN](entry)) {
500
- actions++;
501
- fs.chown(String(entry.absolute), Number(this[UID](entry)), Number(this[GID](entry)), done);
502
525
  }
503
- done();
504
- });
505
- }
506
- [UNSUPPORTED](entry) {
507
- entry.unsupported = true;
508
- this.warn('TAR_ENTRY_UNSUPPORTED', `unsupported entry type: ${entry.type}`, { entry });
509
- entry.resume();
510
- }
511
- [SYMLINK](entry, done) {
512
- const parts = normalizeWindowsPath(path.relative(this.cwd, path.resolve(path.dirname(String(entry.absolute)), String(entry.linkpath)))).split('/');
513
- this[ENSURE_NO_SYMLINK](entry, this.cwd, parts, () => this[LINK](entry, String(entry.linkpath), 'symlink', done), er => {
514
- this[ONERROR](er, entry);
515
- done();
516
- });
517
- }
518
- [HARDLINK](entry, done) {
519
- const linkpath = normalizeWindowsPath(path.resolve(this.cwd, String(entry.linkpath)));
520
- const parts = normalizeWindowsPath(String(entry.linkpath)).split('/');
521
- this[ENSURE_NO_SYMLINK](entry, this.cwd, parts, () => this[LINK](entry, linkpath, 'link', done), er => {
522
- this[ONERROR](er, entry);
523
- done();
524
- });
525
- }
526
- [ENSURE_NO_SYMLINK](entry, cwd, parts, done, onError) {
527
- const p = parts.shift();
528
- if (this.preservePaths || p === undefined)
529
- return done();
530
- const t = path.resolve(cwd, p);
531
- fs.lstat(t, (er, st) => {
532
- if (er)
533
- return done();
534
- if (st?.isSymbolicLink()) {
535
- return onError(new SymlinkError(t, path.resolve(t, parts.join('/'))));
536
- }
537
- this[ENSURE_NO_SYMLINK](entry, t, parts, done, onError);
526
+ this.#active--;
527
+ this.#wake?.();
538
528
  });
539
529
  }
540
- [PEND]() {
541
- this[PENDING]++;
542
- }
543
- [UNPEND]() {
544
- this[PENDING]--;
545
- this[MAYBECLOSE]();
530
+ #mkdir(dir, mode) {
531
+ return mkdir(this.#fs, dir, this.mkdirOptions(mode));
532
+ }
533
+ // The extraction directory must exist. Entries that start at the
534
+ // same time share one check.
535
+ #checkCwd() {
536
+ return (this.#cwdCheck ??= this.#mkdir(this.cwd, this.dmode).then(() => {
537
+ this.#checkedCwd = true;
538
+ }, er => {
539
+ this.#cwdCheck = undefined;
540
+ throw er;
541
+ }));
542
+ }
543
+ async #extract(entry, body, reader) {
544
+ const fs = this.#fs;
545
+ const absolute = entry.absolute;
546
+ const { cwd } = this;
547
+ if (!this.#checkedCwd)
548
+ await this.#checkCwd();
549
+ if (absolute !== cwd) {
550
+ const parent = this.dirname(absolute);
551
+ if (parent !== cwd)
552
+ await this.#mkdir(parent, this.dmode);
553
+ }
554
+ // Remove what is at the path, if the entry cannot use it.
555
+ const st = await fs.lstat(absolute).catch(() => undefined);
556
+ if (st && this.skip(entry, st))
557
+ return;
558
+ if (st && !this.isReusable(entry, st)) {
559
+ if (st.isDirectory() && dirTypes.has(entry.type)) {
560
+ if (this.chmod &&
561
+ entry.mode &&
562
+ (st.mode & 0o7777) !== entry.mode) {
563
+ await fs.chmod(absolute, entry.mode);
564
+ }
565
+ }
566
+ else if (absolute !== cwd) {
567
+ if (st.isDirectory())
568
+ await fs.rmdir(absolute);
569
+ else
570
+ await this.#unlink(absolute);
571
+ }
572
+ }
573
+ if (fileTypes.has(entry.type)) {
574
+ return this.#file(entry, absolute, body, reader);
575
+ }
576
+ if (dirTypes.has(entry.type))
577
+ await this.#directory(entry, absolute);
578
+ else {
579
+ await this.#ensureNoSymlink(this.linkParts(entry, absolute));
580
+ const linkpath = String(entry.linkpath);
581
+ if (entry.type === 'Link') {
582
+ await fs.link(this.resolve(cwd, linkpath), absolute);
583
+ }
584
+ else {
585
+ await fs.symlink(linkpath, absolute);
586
+ }
587
+ }
588
+ await this.#ensureNoSymlink(this.parentParts(absolute));
546
589
  }
547
- [SKIP](entry) {
548
- this[UNPEND]();
549
- entry.resume();
590
+ async #unlink(path) {
591
+ const fs = this.#fs;
592
+ if (!this.win32)
593
+ return fs.unlink(path);
594
+ const name = deleteName(path);
595
+ await fs.rename(path, name);
596
+ await fs.unlink(name);
550
597
  }
551
- // Check if we can reuse an existing filesystem entry safely and
552
- // overwrite it, rather than unlinking and recreating
553
- // Windows doesn't report a useful nlink, so we just never reuse entries
554
- [ISREUSABLE](entry, st) {
555
- return (entry.type === 'File' &&
556
- !this.unlink &&
557
- st.isFile() &&
558
- st.nlink <= 1 &&
559
- !isWindows);
598
+ async #ensureNoSymlink(parts) {
599
+ if (this.preservePaths)
600
+ return;
601
+ let t = this.cwd;
602
+ for (const p of parts) {
603
+ t = this.resolve(t, p);
604
+ const st = await this.#fs.lstat(t).catch(() => undefined);
605
+ if (!st)
606
+ return;
607
+ if (st.isSymbolicLink())
608
+ throw this.symlinkError(t, parts);
609
+ }
560
610
  }
561
- // check if a thing is there, and if so, try to clobber it
562
- [CHECKFS](entry) {
563
- this[PEND]();
564
- const paths = [entry.path];
565
- if (entry.linkpath) {
566
- paths.push(entry.linkpath);
611
+ async #directory(entry, absolute) {
612
+ const fs = this.#fs;
613
+ await this.#mkdir(absolute, entry.mode ?? this.dmode);
614
+ // These do not follow a symbolic link that replaced the
615
+ // directory. A failure is not an error of the entry.
616
+ const times = this.times(entry);
617
+ if (times) {
618
+ await fs.lutimes(absolute, times.atime, times.mtime).catch(() => { });
619
+ }
620
+ const owner = this.owner(entry);
621
+ if (owner) {
622
+ await fs.lchown(absolute, owner.uid, owner.gid).catch(() => { });
567
623
  }
568
- this.reservations.reserve(paths, done => this[CHECKFS2](entry, done));
569
624
  }
570
- [CHECKFS2](entry, fullyDone) {
571
- const done = (er) => {
572
- fullyDone(er);
573
- };
574
- const checkCwd = () => {
575
- this[MKDIR](this.cwd, this.dmode, er => {
576
- if (er) {
577
- this[ONERROR](er, entry);
578
- done();
579
- return;
625
+ async #file(entry, absolute, body, reader) {
626
+ const fs = this.#fs;
627
+ const handle = await fs.open(absolute, this.writeFlag(entry.size), entry.mode ?? this.fmode);
628
+ try {
629
+ // The file is open. Write to it only if no parent directory
630
+ // became a symbolic link before the open.
631
+ await this.#ensureNoSymlink(this.parentParts(absolute));
632
+ if (reader)
633
+ await this.#pipe(entry, body, reader, handle);
634
+ else
635
+ for (const part of body)
636
+ await handle.write(part);
637
+ // Use the open file, so that a symbolic link that replaced the
638
+ // path is not followed. If that fails, use the path.
639
+ const times = this.times(entry);
640
+ if (times) {
641
+ const { atime, mtime } = times;
642
+ await handle.utimes(atime, mtime).catch(async (er) => {
643
+ await fs.utimes(absolute, atime, mtime).catch(() => {
644
+ throw er;
645
+ });
646
+ });
647
+ }
648
+ const owner = this.owner(entry);
649
+ if (owner) {
650
+ const { uid, gid } = owner;
651
+ await handle.chown(uid, gid).catch(async (er) => {
652
+ await fs.chown(absolute, uid, gid).catch(() => {
653
+ throw er;
654
+ });
655
+ });
656
+ }
657
+ }
658
+ catch (er) {
659
+ await handle.close().catch(() => { });
660
+ throw er;
661
+ }
662
+ await handle.close();
663
+ }
664
+ // Write the content of the entry as it arrives, through the
665
+ // transform stream if there is one.
666
+ async #pipe(entry, body, reader, handle) {
667
+ let i = 0;
668
+ const next = async () => {
669
+ if (i < body.length)
670
+ return body[i++];
671
+ try {
672
+ for (;;) {
673
+ const part = reader.readBody(entry);
674
+ if (part !== undefined)
675
+ return part;
676
+ await reader.fill();
580
677
  }
581
- this[CHECKED_CWD] = true;
582
- start();
583
- });
678
+ }
679
+ catch (er) {
680
+ // The archive cannot be read.
681
+ throw this.fail(er);
682
+ }
584
683
  };
585
- const start = () => {
586
- if (entry.absolute !== this.cwd) {
587
- const parent = normalizeWindowsPath(path.dirname(String(entry.absolute)));
588
- if (parent !== this.cwd) {
589
- return this[MKDIR](parent, this.dmode, er => {
590
- if (er) {
591
- this[ONERROR](er, entry);
592
- done();
593
- return;
594
- }
595
- afterMakeParent();
684
+ const tx = this.opt.transform?.(entry);
685
+ if (!tx) {
686
+ // Write one part while the next part is read.
687
+ let writing;
688
+ let failed;
689
+ try {
690
+ for (let part; (part = await next());) {
691
+ await writing;
692
+ if (failed)
693
+ break;
694
+ writing = handle.write(part).then(() => { }, error => {
695
+ failed = { error };
596
696
  });
597
697
  }
598
698
  }
599
- afterMakeParent();
699
+ finally {
700
+ await writing;
701
+ }
702
+ if (failed)
703
+ throw failed.error;
704
+ return;
705
+ }
706
+ const writer = tx.writable.getWriter();
707
+ const out = tx.readable.getReader();
708
+ let failed;
709
+ // Stop the two streams. A read that waits gets the end of the
710
+ // stream, and a write that waits fails.
711
+ const stop = async (error) => {
712
+ failed ??= { error };
713
+ await out.cancel(error).catch(() => { });
714
+ await writer.abort(error).catch(() => { });
600
715
  };
601
- const afterMakeParent = () => {
602
- fs.lstat(String(entry.absolute), (lstatEr, st) => {
603
- if (st &&
604
- (this.keep ||
605
- /* c8 ignore next */
606
- (this.newer && st.mtime > (entry.mtime ?? st.mtime)))) {
607
- this[SKIP](entry);
608
- done();
609
- return;
610
- }
611
- if (lstatEr || this[ISREUSABLE](entry, st)) {
612
- return this[MAKEFS](null, entry, done);
613
- }
614
- if (st.isDirectory()) {
615
- if (entry.type === 'Directory') {
616
- const needChmod = this.chmod && entry.mode && (st.mode & 0o7777) !== entry.mode;
617
- const afterChmod = (er) => this[MAKEFS](er ?? null, entry, done);
618
- if (!needChmod) {
619
- return afterChmod();
620
- }
621
- return fs.chmod(String(entry.absolute), Number(entry.mode), afterChmod);
622
- }
623
- // Not a dir entry, have to remove it.
624
- // NB: the only way to end up with an entry that is the cwd
625
- // itself, in such a way that == does not detect, is a
626
- // tricky windows absolute path with UNC or 8.3 parts (and
627
- // preservePaths:true, or else it will have been stripped).
628
- // In that case, the user has opted out of path protections
629
- // explicitly, so if they blow away the cwd, c'est la vie.
630
- if (entry.absolute !== this.cwd) {
631
- return fs.rmdir(String(entry.absolute), (er) => this[MAKEFS](er ?? null, entry, done));
632
- }
716
+ const feed = (async () => {
717
+ try {
718
+ for (let part; (part = await next());)
719
+ await writer.write(part);
720
+ await writer.close();
721
+ }
722
+ catch (er) {
723
+ await stop(er);
724
+ }
725
+ })();
726
+ try {
727
+ for (;;) {
728
+ const { done, value } = await out.read();
729
+ if (done)
730
+ break;
731
+ await handle.write(value);
732
+ }
733
+ }
734
+ catch (er) {
735
+ await stop(er);
736
+ }
737
+ // The feed reads the archive, so it must end before the next
738
+ // entry is read.
739
+ await feed;
740
+ if (failed)
741
+ throw failed.error;
742
+ }
743
+ }
744
+ /**
745
+ * Extracts the entries of an archive with sync file system
746
+ * functions, one entry at a time.
747
+ */
748
+ export class UnpackSync extends UnpackBase {
749
+ #fs;
750
+ #checkedCwd = false;
751
+ constructor(opt) {
752
+ super(opt);
753
+ this.#fs = this.opt.fs;
754
+ }
755
+ /** Extract the archive. Throws the first error that stops it. */
756
+ extract(input) {
757
+ const reader = new TarReaderSync(input, this.readerOptions());
758
+ const { onEntry } = this.opt;
759
+ try {
760
+ for (const entry of reader) {
761
+ onEntry?.(entry);
762
+ if (entry.bodyUsed)
763
+ continue;
764
+ if (!this.check(entry))
765
+ continue;
766
+ try {
767
+ this.#extract(entry, reader);
633
768
  }
634
- // not a dir, and not reusable
635
- // don't remove if the cwd, we want that error
636
- if (entry.absolute === this.cwd) {
637
- return this[MAKEFS](null, entry, done);
769
+ catch (er) {
770
+ this.entryError(er, entry);
638
771
  }
639
- unlinkFile(String(entry.absolute), er => this[MAKEFS](er ?? null, entry, done));
640
- });
641
- };
642
- if (this[CHECKED_CWD]) {
643
- start();
772
+ }
644
773
  }
645
- else {
646
- checkCwd();
774
+ catch (error) {
775
+ if (error && typeof error === 'object' && 'tarCode' in error) {
776
+ Object.assign(error, { cwd: this.cwd });
777
+ }
778
+ throw error;
647
779
  }
648
780
  }
649
- [MAKEFS](er, entry, done) {
650
- if (er) {
651
- this[ONERROR](er, entry);
652
- done();
781
+ #mkdir(dir, mode) {
782
+ mkdirSync(this.#fs, dir, this.mkdirOptions(mode));
783
+ }
784
+ #extract(entry, reader) {
785
+ const fs = this.#fs;
786
+ const absolute = entry.absolute;
787
+ const { cwd } = this;
788
+ if (!this.#checkedCwd) {
789
+ this.#mkdir(cwd, this.dmode);
790
+ this.#checkedCwd = true;
791
+ }
792
+ if (absolute !== cwd) {
793
+ const parent = this.dirname(absolute);
794
+ if (parent !== cwd)
795
+ this.#mkdir(parent, this.dmode);
796
+ }
797
+ // Remove what is at the path, if the entry cannot use it.
798
+ let st;
799
+ try {
800
+ st = fs.lstatSync(absolute);
801
+ }
802
+ catch { }
803
+ if (st && this.skip(entry, st))
653
804
  return;
805
+ if (st && !this.isReusable(entry, st)) {
806
+ if (st.isDirectory() && dirTypes.has(entry.type)) {
807
+ if (this.chmod &&
808
+ entry.mode &&
809
+ (st.mode & 0o7777) !== entry.mode) {
810
+ fs.chmodSync(absolute, entry.mode);
811
+ }
812
+ }
813
+ else if (absolute !== cwd) {
814
+ if (st.isDirectory())
815
+ fs.rmdirSync(absolute);
816
+ else
817
+ this.#unlink(absolute);
818
+ }
654
819
  }
655
- switch (entry.type) {
656
- case 'File':
657
- case 'OldFile':
658
- case 'ContiguousFile':
659
- return this[FILE](entry, done);
660
- case 'Link':
661
- return this[HARDLINK](entry, done);
662
- case 'SymbolicLink':
663
- return this[SYMLINK](entry, done);
664
- case 'Directory':
665
- case 'GNUDumpDir':
666
- return this[DIRECTORY](entry, done);
667
- }
668
- }
669
- [LINK](entry, linkpath, link, done) {
670
- fs[link](linkpath, String(entry.absolute), er => {
671
- if (er) {
672
- this[ONERROR](er, entry);
820
+ if (fileTypes.has(entry.type)) {
821
+ return this.#file(entry, absolute, reader);
822
+ }
823
+ if (dirTypes.has(entry.type))
824
+ this.#directory(entry, absolute);
825
+ else {
826
+ this.#ensureNoSymlink(this.linkParts(entry, absolute));
827
+ const linkpath = String(entry.linkpath);
828
+ if (entry.type === 'Link') {
829
+ fs.linkSync(this.resolve(cwd, linkpath), absolute);
673
830
  }
674
831
  else {
675
- this[UNPEND]();
676
- entry.resume();
677
- }
678
- done();
679
- });
680
- }
681
- }
682
- const callSync = (fn) => {
683
- try {
684
- return [null, fn()];
685
- }
686
- catch (er) {
687
- return [er, null];
688
- }
689
- };
690
- export class UnpackSync extends Unpack {
691
- sync = true;
692
- [MAKEFS](er, entry) {
693
- return super[MAKEFS](er, entry, () => { });
694
- }
695
- [CHECKFS](entry) {
696
- if (!this[CHECKED_CWD]) {
697
- const er = this[MKDIR](this.cwd, this.dmode);
698
- if (er) {
699
- return this[ONERROR](er, entry);
700
- }
701
- this[CHECKED_CWD] = true;
702
- }
703
- // don't bother to make the parent if the current entry is the cwd,
704
- // we've already checked it.
705
- if (entry.absolute !== this.cwd) {
706
- const parent = normalizeWindowsPath(path.dirname(String(entry.absolute)));
707
- if (parent !== this.cwd) {
708
- const mkParent = this[MKDIR](parent, this.dmode);
709
- if (mkParent) {
710
- return this[ONERROR](mkParent, entry);
711
- }
832
+ fs.symlinkSync(linkpath, absolute);
712
833
  }
713
834
  }
714
- const [lstatEr, st] = callSync(() => fs.lstatSync(String(entry.absolute)));
715
- if (st &&
716
- (this.keep ||
717
- /* c8 ignore next */
718
- (this.newer && st.mtime > (entry.mtime ?? st.mtime)))) {
719
- return this[SKIP](entry);
720
- }
721
- if (lstatEr || this[ISREUSABLE](entry, st)) {
722
- return this[MAKEFS](null, entry);
723
- }
724
- if (st.isDirectory()) {
725
- if (entry.type === 'Directory') {
726
- const needChmod = this.chmod && entry.mode && (st.mode & 0o7777) !== entry.mode;
727
- const [er] = needChmod ?
728
- callSync(() => {
729
- fs.chmodSync(String(entry.absolute), Number(entry.mode));
730
- })
731
- : [];
732
- return this[MAKEFS](er, entry);
733
- }
734
- // not a dir entry, have to remove it
735
- const [er] = callSync(() => fs.rmdirSync(String(entry.absolute)));
736
- this[MAKEFS](er, entry);
737
- }
738
- // not a dir, and not reusable.
739
- // don't remove if it's the cwd, since we want that error.
740
- const [er] = entry.absolute === this.cwd ?
741
- []
742
- : callSync(() => unlinkFileSync(String(entry.absolute)));
743
- this[MAKEFS](er, entry);
744
- }
745
- [FILE](entry, done) {
746
- const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.fmode;
747
- const oner = (er) => {
748
- let closeError;
835
+ this.#ensureNoSymlink(this.parentParts(absolute));
836
+ }
837
+ #unlink(path) {
838
+ const fs = this.#fs;
839
+ if (!this.win32)
840
+ return fs.unlinkSync(path);
841
+ const name = deleteName(path);
842
+ fs.renameSync(path, name);
843
+ fs.unlinkSync(name);
844
+ }
845
+ #ensureNoSymlink(parts) {
846
+ if (this.preservePaths)
847
+ return;
848
+ let t = this.cwd;
849
+ for (const p of parts) {
850
+ t = this.resolve(t, p);
851
+ let st;
749
852
  try {
750
- fs.closeSync(fd);
751
- }
752
- catch (e) {
753
- closeError = e;
853
+ st = this.#fs.lstatSync(t);
754
854
  }
755
- if (er || closeError) {
756
- this[ONERROR](er || closeError, entry);
855
+ catch {
856
+ return;
757
857
  }
758
- done();
759
- };
760
- let fd;
761
- try {
762
- fd = fs.openSync(String(entry.absolute), getWriteFlag(entry.size), mode);
763
- /* c8 ignore start - This is only a problem if the file was successfully
764
- * statted, BUT failed to open. Testing this is annoying, and we
765
- * already have ample testint for other uses of oner() methods.
766
- */
858
+ if (st.isSymbolicLink())
859
+ throw this.symlinkError(t, parts);
767
860
  }
768
- catch (er) {
769
- return oner(er);
770
- }
771
- /* c8 ignore stop */
772
- const tx = this.transform ? this.transform(entry) || entry : entry;
773
- if (tx !== entry) {
774
- tx.on('error', er => this[ONERROR](er, entry));
775
- entry.pipe(tx);
861
+ }
862
+ #directory(entry, absolute) {
863
+ const fs = this.#fs;
864
+ this.#mkdir(absolute, entry.mode ?? this.dmode);
865
+ // These do not follow a symbolic link that replaced the
866
+ // directory. A failure is not an error of the entry.
867
+ const times = this.times(entry);
868
+ if (times) {
869
+ try {
870
+ fs.lutimesSync(absolute, times.atime, times.mtime);
871
+ }
872
+ catch { }
776
873
  }
777
- tx.on('data', (chunk) => {
874
+ const owner = this.owner(entry);
875
+ if (owner) {
778
876
  try {
779
- fs.writeSync(fd, chunk, 0, chunk.length);
877
+ fs.lchownSync(absolute, owner.uid, owner.gid);
780
878
  }
781
- catch (er) {
782
- oner(er);
879
+ catch { }
880
+ }
881
+ }
882
+ #file(entry, absolute, reader) {
883
+ const fs = this.#fs;
884
+ const fd = fs.openSync(absolute, this.writeFlag(entry.size), entry.mode ?? this.fmode);
885
+ try {
886
+ // The file is open. Write to it only if no parent directory
887
+ // became a symbolic link before the open.
888
+ this.#ensureNoSymlink(this.parentParts(absolute));
889
+ const tx = this.opt.transform?.(entry);
890
+ for (;;) {
891
+ let part;
892
+ try {
893
+ part = reader.readBody(entry);
894
+ }
895
+ catch (er) {
896
+ // The archive cannot be read.
897
+ throw this.fail(er);
898
+ }
899
+ if (!part)
900
+ break;
901
+ fs.writeSync(fd, tx ? tx(part) : part);
783
902
  }
784
- });
785
- tx.on('end', () => {
786
- let er = null;
787
- // try both, falling futimes back to utimes
788
- // if either fails, handle the first error
789
- if (entry.mtime && !this.noMtime) {
790
- const atime = entry.atime || new Date();
791
- const mtime = entry.mtime;
903
+ // Use the open file, so that a symbolic link that replaced the
904
+ // path is not followed. If that fails, use the path.
905
+ const times = this.times(entry);
906
+ if (times) {
907
+ const { atime, mtime } = times;
792
908
  try {
793
909
  fs.futimesSync(fd, atime, mtime);
794
910
  }
795
- catch (futimeser) {
911
+ catch (er) {
796
912
  try {
797
- fs.utimesSync(String(entry.absolute), atime, mtime);
913
+ fs.utimesSync(absolute, atime, mtime);
798
914
  }
799
915
  catch {
800
- er = futimeser;
916
+ throw er;
801
917
  }
802
918
  }
803
919
  }
804
- if (this[DOCHOWN](entry)) {
805
- const uid = this[UID](entry);
806
- const gid = this[GID](entry);
920
+ const owner = this.owner(entry);
921
+ if (owner) {
922
+ const { uid, gid } = owner;
807
923
  try {
808
- fs.fchownSync(fd, Number(uid), Number(gid));
924
+ fs.fchownSync(fd, uid, gid);
809
925
  }
810
- catch (fchowner) {
926
+ catch (er) {
811
927
  try {
812
- fs.chownSync(String(entry.absolute), Number(uid), Number(gid));
928
+ fs.chownSync(absolute, uid, gid);
813
929
  }
814
930
  catch {
815
- er = er || fchowner;
931
+ throw er;
816
932
  }
817
933
  }
818
934
  }
819
- oner(er);
820
- });
821
- }
822
- [DIRECTORY](entry, done) {
823
- const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.dmode;
824
- const er = this[MKDIR](String(entry.absolute), mode);
825
- if (er) {
826
- this[ONERROR](er, entry);
827
- done();
828
- return;
829
- }
830
- if (entry.mtime && !this.noMtime) {
831
- try {
832
- fs.utimesSync(String(entry.absolute), entry.atime || new Date(), entry.mtime);
833
- /* c8 ignore next */
834
- }
835
- catch { }
836
935
  }
837
- if (this[DOCHOWN](entry)) {
936
+ catch (er) {
937
+ // Close the file one time, and do not use the descriptor again:
938
+ // the system can give its number to a different file.
838
939
  try {
839
- fs.chownSync(String(entry.absolute), Number(this[UID](entry)), Number(this[GID](entry)));
940
+ fs.closeSync(fd);
840
941
  }
841
942
  catch { }
943
+ throw er;
842
944
  }
843
- done();
844
- entry.resume();
845
- }
846
- [MKDIR](dir, mode) {
847
- try {
848
- return mkdirSync(normalizeWindowsPath(dir), {
849
- uid: this.uid,
850
- gid: this.gid,
851
- processUid: this.processUid,
852
- processGid: this.processGid,
853
- umask: this.processUmask,
854
- preserve: this.preservePaths,
855
- unlink: this.unlink,
856
- cwd: this.cwd,
857
- mode: mode,
858
- });
859
- }
860
- catch (er) {
861
- return er;
862
- }
863
- }
864
- [ENSURE_NO_SYMLINK](_entry, cwd, parts, done, onError) {
865
- if (this.preservePaths || parts.length === 0)
866
- return done();
867
- let t = cwd;
868
- for (const p of parts) {
869
- t = path.resolve(t, p);
870
- const [er, st] = callSync(() => fs.lstatSync(t));
871
- if (er)
872
- return done();
873
- if (st.isSymbolicLink()) {
874
- return onError(new SymlinkError(t, path.resolve(cwd, parts.join('/'))));
875
- }
876
- }
877
- done();
878
- }
879
- [LINK](entry, linkpath, link, done) {
880
- const linkSync = `${link}Sync`;
881
- try {
882
- fs[linkSync](linkpath, String(entry.absolute));
883
- done();
884
- entry.resume();
885
- }
886
- catch (er) {
887
- return this[ONERROR](er, entry);
888
- }
945
+ fs.closeSync(fd);
889
946
  }
890
947
  }
891
948
  //# sourceMappingURL=unpack.js.map