@poe-platform/safe-bash 0.1.809 → 0.1.811
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.
- package/dist/audio-ast/flac-source.d.ts +13 -0
- package/dist/audio-ast/index.d.ts +2 -1
- package/dist/audio-ast/index.js +254 -179
- package/dist/audio-ast/wav-source.d.ts +7 -1
- package/dist/image-ast/index.js +1 -1
- package/dist/json-ast/backed-json-parser.d.ts +12 -1
- package/dist/json-ast/index.d.ts +1 -1
- package/dist/office-xml/index.d.ts +1 -0
- package/dist/office-xml/retained-xml-edits.d.ts +22 -0
- package/dist/pdf-ast/cos/mutable-object-store.d.ts +3 -0
- package/dist/pdf-ast/cos/qpdf-json-document.d.ts +43 -0
- package/dist/pdf-ast/cos/qpdf-json-values.d.ts +7 -0
- package/dist/pdf-ast/index.d.ts +1 -0
- package/dist/pdf-ast/index.js +653 -87
- package/dist/pdf-ast/retained-document.d.ts +5 -1
- package/dist/safe-bash/audio-ast.browser.js +2 -1
- package/dist/safe-bash/chunks/{chunk-RQCK77SC.js → chunk-BUYRKFW2.js} +9 -36
- package/dist/safe-bash/chunks/{chunk-SOFBGDXG.js → chunk-HHSOUC3Z.js} +32 -0
- package/dist/safe-bash/chunks/{chunk-WAZEELYB.js → chunk-TPG55BAQ.js} +10 -7
- package/dist/safe-bash/command-chunks/biff-3EFLKBAH-NYWZOYQS.js +4942 -0
- package/dist/safe-bash/command-chunks/{chunk-HEHGHIE2.js → chunk-22MOB45U.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-6DEWZMOL.js → chunk-2CORNDGF.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-62ZAHKFS.js → chunk-2VCKUNDZ.js} +130 -14
- package/dist/safe-bash/command-chunks/{chunk-6UHGIWFX.js → chunk-2ZFLMWOX.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-HONWGFDA.js → chunk-33YCKZZX.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-AXWPJRY6.js → chunk-36XGIPOG.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-32ADKP5E.js → chunk-456PHA3L.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-UJXP3T6R.js → chunk-4CKFNXRN.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-5L6GHFRW.js → chunk-554Z6IKP.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-ORZRWT62.js → chunk-56NYSX65.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-53JP3S6H.js → chunk-5HPU7D36.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-NB7JO7FE.js → chunk-5LI2DLNZ.js} +26 -26
- package/dist/safe-bash/command-chunks/{chunk-YJJBGN7U.js → chunk-5MB64DWR.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-3ZWBBS6U.js → chunk-5OO2P27R.js} +340 -34
- package/dist/safe-bash/command-chunks/{chunk-IC5GJI7E.js → chunk-5Q22ZLNC.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-YO3V5RLY.js → chunk-6CCQI6XZ.js} +12 -12
- package/dist/safe-bash/command-chunks/{chunk-EO2IVGV7.js → chunk-6M6TM5Z5.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-Z54Z3KRN.js → chunk-6QBMND4A.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-INX4JMQ6.js → chunk-6VPQ3CDZ.js} +5 -5
- package/dist/safe-bash/command-chunks/chunk-72C3TZ2U.js +826 -0
- package/dist/safe-bash/command-chunks/{chunk-VGXVN3BX.js → chunk-7GKKMNL6.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-TZJC67W3.js → chunk-7PVHO47B.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-CM3C7AXJ.js → chunk-A2CLZMQZ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-ASR27KHW.js → chunk-A5FZBR7X.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-DMDHE5KC.js → chunk-AHA6IWAJ.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-PTZ55XXN.js → chunk-APEWTWCC.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-YUVH6CE4.js → chunk-ATTWQVR2.js} +17 -17
- package/dist/safe-bash/command-chunks/{chunk-JON5DB3Z.js → chunk-B5LDP7AA.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-CHJL6JMU.js → chunk-COKYZUBW.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-KCTV4NVX.js → chunk-CRV2Q3PB.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-V3WXPCKN.js → chunk-CV7M2QJU.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-D7XBUF76.js → chunk-D2ASPM7R.js} +109 -23
- package/dist/safe-bash/command-chunks/{chunk-VPDSQPSN.js → chunk-DM2CPMB4.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-3DTDMEOP.js → chunk-EAGIJ4VW.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WFDG3N5R.js → chunk-ECDEPKKW.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-JW6CMBF2.js → chunk-EHSM5ZQS.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-WIOH7ZQN.js → chunk-ENT3IV2G.js} +12 -12
- package/dist/safe-bash/command-chunks/{chunk-5IE4LJGB.js → chunk-EUT24Y5Z.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-COKZFXHG.js → chunk-FIIAYCWS.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-MWVFP2HY.js → chunk-GEM47B2P.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-OQCJGUI6.js → chunk-HARUYHH7.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-EHL6B34L.js → chunk-HDJVJTCK.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-JMM3MNAY.js → chunk-HKATEVAP.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-NVBUC644.js → chunk-HKGNBH7Z.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-VWY3EAVQ.js → chunk-HTVIYLVB.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-Z4QJMDK3.js → chunk-IT7TAC3F.js} +16 -16
- package/dist/safe-bash/command-chunks/{chunk-EWS4KYJE.js → chunk-JFYWVQ4V.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-ZCX63QWA.js → chunk-JOCFI7TG.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-F5WTH4O4.js → chunk-JQVHUSDD.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-O4VJEGL6.js → chunk-K5GB2YMN.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-27C3NT5V.js → chunk-KB7DUBVL.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-4DZ32PI7.js → chunk-KCOJA7EM.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-6OKH4X67.js → chunk-KJ4XXZIL.js} +273 -10
- package/dist/safe-bash/command-chunks/{chunk-GLVD3JJG.js → chunk-KL3OIBKB.js} +4712 -4654
- package/dist/safe-bash/command-chunks/{chunk-U6QHTC5J.js → chunk-L5MCW6CM.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-LVL3A7YE.js → chunk-LCZDBW55.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-DJVRDUCA.js → chunk-LXLLA4PM.js} +17 -17
- package/dist/safe-bash/command-chunks/{chunk-K7AGAS3K.js → chunk-M7QE2MN7.js} +6 -6
- package/dist/safe-bash/command-chunks/chunk-MGBHGZEX.js +12 -0
- package/dist/safe-bash/command-chunks/{chunk-SWT6ILF2.js → chunk-MPUHH2KR.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-DC3OJLRB.js → chunk-NQDIT667.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-LWZVDDJA.js → chunk-NUGQQDGE.js} +5 -1
- package/dist/safe-bash/command-chunks/{chunk-MFLQZLFR.js → chunk-OA75SGN2.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-5LATYOF7.js → chunk-OEJM666F.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-AF25YYIO.js → chunk-PMAM4N33.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-4557HE3J.js → chunk-PMWW7KSB.js} +161 -42
- package/dist/safe-bash/command-chunks/{chunk-KMMAJ6H6.js → chunk-PNGDJA6M.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-62BHPSKJ.js → chunk-Q6S57NOQ.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-KJ3PEDI2.js → chunk-Q73EMLLZ.js} +146 -4
- package/dist/safe-bash/command-chunks/{chunk-FXKBM5KJ.js → chunk-QC5RMGSA.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-UQ6UIZMM.js → chunk-QD7ZRDUN.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-JHUYZZGV.js → chunk-QYMEASQ6.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-3GY5VDIX.js → chunk-QZZ73J2O.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-S2CYIGWH.js → chunk-R6EGGK5M.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-7AVN3OBH.js → chunk-RHYJVTJO.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-EWGDSO6U.js → chunk-RID6VYS3.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-MMBRBANA.js → chunk-RNSKXOG3.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-D3ZRZTY5.js → chunk-RQIQ75W5.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-DWKQPLRT.js → chunk-RRL3Y562.js} +11 -11
- package/dist/safe-bash/command-chunks/{chunk-JW3KIZU6.js → chunk-RUXY7GN5.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-NXCMXD74.js → chunk-S6R3IB36.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XUPKFHAQ.js → chunk-SDTPO2VV.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-PIAGKRFW.js → chunk-SPLOIABU.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-KELMIFVV.js → chunk-TI52LKLL.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WLTJDNSQ.js → chunk-TVH4JORU.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-6XVMWFHD.js → chunk-TW73OXPR.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-SFO43CID.js → chunk-UAXSE3XE.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-K35BSUHO.js → chunk-UYWSIIUX.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-JJQ72P3V.js → chunk-VCML4T5D.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DCD32BEY.js → chunk-VU3EQF7F.js} +91 -53
- package/dist/safe-bash/command-chunks/{chunk-2E2YEDVB.js → chunk-W5YSINXC.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-EYNT4OEJ.js → chunk-WGG6G2KG.js} +7 -7
- package/dist/safe-bash/command-chunks/chunk-WH3TIOTS.js +326 -0
- package/dist/safe-bash/command-chunks/{chunk-DVQBZXMQ.js → chunk-WJCN2IXI.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-45FI2IPY.js → chunk-WQ6ABTJU.js} +3 -6
- package/dist/safe-bash/command-chunks/{chunk-XBZ4ZWGL.js → chunk-WVMHRNXZ.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-7GXUCQI4.js → chunk-WXRYDALR.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-S4IIOSRA.js → chunk-X7FA7ZD5.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-SFCERNHU.js → chunk-XPD636C4.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-HYDWQLJ3.js → chunk-XRVKWGVQ.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-3UJWHRK4.js → chunk-XVP6V5K3.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-KTI3BULE.js → chunk-XZ2FWFNV.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-QK3CHRGL.js → chunk-Y4EYCZFT.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-GTWVMFBK.js → chunk-YORJDX4V.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-H6F5SN2N.js → chunk-YSMNXMAO.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-GKYCV6BU.js → chunk-YSY6R6AS.js} +493 -183
- package/dist/safe-bash/command-chunks/{chunk-SE5SJ4JT.js → chunk-Z2JW6M2D.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-5HGEXQVD.js → chunk-ZHRGYR7B.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-HQYFRQ5W.js → chunk-ZIIO6GRY.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-NTRZMQZP.js → chunk-ZMHEGDU2.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-EYBXHGA6.js → chunk-ZXR6LXV5.js} +2 -2
- package/dist/safe-bash/command-chunks/{command-engine-P5DFM4OU.js → command-engine-BEWABZ75.js} +10 -3
- package/dist/safe-bash/command-chunks/{engine-RU4OFLPO-CPLFYD67.js → engine-AXXFTGCL-QBQNBI6K.js} +1 -1
- package/dist/safe-bash/command-chunks/pdf-XHHFTOT4-UJJYOYJ2.js +573 -0
- package/dist/safe-bash/commands/audio/index.browser.js +2 -14
- package/dist/safe-bash/commands/diff-patch/index.js +0 -5
- package/dist/safe-bash/commands/diff3/index.js +0 -2
- package/dist/safe-bash/commands/ffprobe/index.browser.js +2 -5
- package/dist/safe-bash/commands/pandoc/index.browser.js +3 -1
- package/dist/safe-bash/commands/text.js +10 -1
- package/dist/safe-bash/core.d.ts +2 -2
- package/dist/safe-bash/core.js +2 -2
- package/dist/safe-bash/full-core.browser.js +18 -22
- package/dist/safe-bash/lazy-optional.d.ts +9 -0
- package/dist/safe-bash/lazy-optional.js +24 -0
- package/dist/safe-bash/plugins/index.browser.js +5 -3
- package/dist/safe-bash/plugins/index.js +3 -1
- package/dist/safe-bash/plugins/portable-commands.d.ts +1 -1
- package/dist/safe-bash/plugins/portable-commands.js +5 -3
- package/dist/safe-bash/registry-entry.browser.js +1 -1
- package/dist/safe-bash-command-apply-patch/apply.js +2 -2
- package/dist/safe-bash-command-apply-patch/index.js +2 -2
- package/dist/safe-bash-command-apply-patch/parser.d.ts +20 -1
- package/dist/safe-bash-command-apply-patch/parser.js +1 -1
- package/dist/safe-bash-command-diff/index.js +0 -2
- package/dist/safe-bash-command-diff3/index.js +830 -56
- package/dist/safe-bash-command-ffmpeg/index.js +1 -1
- package/dist/safe-bash-command-ffprobe/index.js +3 -2
- package/dist/safe-bash-command-ffprobe/media.js +3 -2
- package/dist/safe-bash-command-ffprobe/options.d.ts +15 -0
- package/dist/safe-bash-command-ffprobe/options.js +7 -0
- package/dist/safe-bash-command-html-to-markdown/index.js +75 -21
- package/dist/safe-bash-command-media/index.js +2 -2
- package/dist/safe-bash-command-media/plugin.js +1 -1
- package/dist/safe-bash-command-media/remote.js +2 -2
- package/dist/safe-bash-command-pandoc/command.js +8 -8
- package/dist/safe-bash-command-pandoc/execution.d.ts +2 -2
- package/dist/safe-bash-command-pandoc/index.d.ts +1 -1
- package/dist/safe-bash-command-pandoc/index.js +37 -37
- package/dist/safe-bash-command-pandoc/lua-filters.js +2 -2
- package/dist/safe-bash-command-pandoc/types.d.ts +17 -2
- package/dist/safe-bash-command-patch/index.js +2 -2
- package/dist/safe-bash-command-patch/patch-publication.d.ts +2 -2
- package/dist/safe-bash-command-patch/patch-publication.js +1 -1
- package/dist/safe-bash-command-patch/patch.js +2 -2
- package/dist/safe-bash-command-pdftk/index.js +616 -265
- package/dist/safe-bash-command-pptx/engine.js +1 -1
- package/dist/safe-bash-command-qpdf/index.js +115 -9
- package/dist/safe-bash-command-soffice/index.js +1 -1
- package/dist/safe-bash-command-ssconvert/index.js +2 -2
- package/dist/safe-bash-command-xmllint/index.js +137 -30
- package/dist/safe-bash-command-xq/index.js +45 -29
- package/dist/safe-bash-compression-engine/bounded-codec.js +2 -2
- package/dist/safe-bash-compression-engine/codec-loader.js +1 -1
- package/dist/safe-bash-compression-engine/files.js +5 -5
- package/dist/safe-bash-compression-engine/index.js +4 -4
- package/dist/safe-bash-compression-engine/operand.js +5 -5
- package/dist/safe-bash-compression-engine/stream.js +4 -4
- package/dist/safe-bash-compression-engine/zstd-decode.js +3 -3
- package/dist/safe-bash-media-engine/imagemagick.d.ts +2 -0
- package/dist/safe-bash-media-engine/index.js +162 -72
- package/dist/safe-bash-network-engine/body.d.ts +1 -0
- package/dist/safe-bash-network-engine/body.js +1 -1
- package/dist/safe-bash-network-engine/transfer.js +11 -3
- package/dist/safe-bash-presentation-engine/accessibility.js +30 -30
- package/dist/safe-bash-presentation-engine/animation-editing.js +15 -15
- package/dist/safe-bash-presentation-engine/animations.js +15 -15
- package/dist/safe-bash-presentation-engine/backgrounds.js +16 -16
- package/dist/safe-bash-presentation-engine/bytes.js +3 -3
- package/dist/safe-bash-presentation-engine/chart-editing.js +33 -33
- package/dist/safe-bash-presentation-engine/chart-object-operations.js +24 -24
- package/dist/safe-bash-presentation-engine/charts.js +30 -30
- package/dist/safe-bash-presentation-engine/command-placeholder.js +55 -54
- package/dist/safe-bash-presentation-engine/comments.js +16 -16
- package/dist/safe-bash-presentation-engine/connector-operations.js +31 -31
- package/dist/safe-bash-presentation-engine/connectors.js +28 -28
- package/dist/safe-bash-presentation-engine/content-types.js +4 -4
- package/dist/safe-bash-presentation-engine/creation.js +6 -6
- package/dist/safe-bash-presentation-engine/diff.js +31 -31
- package/dist/safe-bash-presentation-engine/drawing-format.js +19 -19
- package/dist/safe-bash-presentation-engine/drawing-operations.js +30 -30
- package/dist/safe-bash-presentation-engine/drawing-schema.js +20 -20
- package/dist/safe-bash-presentation-engine/equations.js +16 -16
- package/dist/safe-bash-presentation-engine/errors.js +2 -2
- package/dist/safe-bash-presentation-engine/fields.js +16 -16
- package/dist/safe-bash-presentation-engine/font-metrics.js +3 -3
- package/dist/safe-bash-presentation-engine/image-extraction.js +19 -19
- package/dist/safe-bash-presentation-engine/image-formatting.js +31 -31
- package/dist/safe-bash-presentation-engine/image-insertion.js +17 -17
- package/dist/safe-bash-presentation-engine/image-replacement.js +20 -20
- package/dist/safe-bash-presentation-engine/image-value.js +4 -4
- package/dist/safe-bash-presentation-engine/images.js +18 -18
- package/dist/safe-bash-presentation-engine/index.d.ts +2 -2
- package/dist/safe-bash-presentation-engine/index.js +100 -93
- package/dist/safe-bash-presentation-engine/layouts.js +15 -15
- package/dist/safe-bash-presentation-engine/length.js +3 -3
- package/dist/safe-bash-presentation-engine/links.js +15 -15
- package/dist/safe-bash-presentation-engine/masters.js +14 -14
- package/dist/safe-bash-presentation-engine/media-editing.js +23 -23
- package/dist/safe-bash-presentation-engine/media-extraction.js +16 -16
- package/dist/safe-bash-presentation-engine/media.js +15 -15
- package/dist/safe-bash-presentation-engine/memberships.js +14 -14
- package/dist/safe-bash-presentation-engine/notes.js +15 -15
- package/dist/safe-bash-presentation-engine/ole-enum.js +4 -4
- package/dist/safe-bash-presentation-engine/ole-insertion.js +19 -19
- package/dist/safe-bash-presentation-engine/opaque-objects.js +9 -9
- package/dist/safe-bash-presentation-engine/package-reader.js +5 -5
- package/dist/safe-bash-presentation-engine/package-tools.js +15 -15
- package/dist/safe-bash-presentation-engine/package-uri.js +3 -3
- package/dist/safe-bash-presentation-engine/package-writer.js +4 -4
- package/dist/safe-bash-presentation-engine/presentation-model.js +54 -53
- package/dist/safe-bash-presentation-engine/presentation-settings.js +13 -13
- package/dist/safe-bash-presentation-engine/properties.js +15 -15
- package/dist/safe-bash-presentation-engine/relationships.js +4 -4
- package/dist/safe-bash-presentation-engine/resource-limits.js +1 -1
- package/dist/safe-bash-presentation-engine/retained-inspection.js +12 -12
- package/dist/safe-bash-presentation-engine/retained-package.js +4 -4
- package/dist/safe-bash-presentation-engine/retained-slide-settings.d.ts +15 -0
- package/dist/safe-bash-presentation-engine/retained-text.js +19 -19
- package/dist/safe-bash-presentation-engine/retained-xml-parts.d.ts +26 -0
- package/dist/safe-bash-presentation-engine/sanitize.js +16 -16
- package/dist/safe-bash-presentation-engine/selectors.js +10 -10
- package/dist/safe-bash-presentation-engine/shape-groups.js +30 -30
- package/dist/safe-bash-presentation-engine/shape-operations.js +29 -29
- package/dist/safe-bash-presentation-engine/shape-path-operations.js +31 -31
- package/dist/safe-bash-presentation-engine/shape-paths.js +15 -15
- package/dist/safe-bash-presentation-engine/shape-presets.js +3 -3
- package/dist/safe-bash-presentation-engine/shape-selection.js +30 -30
- package/dist/safe-bash-presentation-engine/shape-transforms.js +17 -17
- package/dist/safe-bash-presentation-engine/shapes.js +26 -26
- package/dist/safe-bash-presentation-engine/slide-copy.js +16 -16
- package/dist/safe-bash-presentation-engine/slide-import.js +17 -17
- package/dist/safe-bash-presentation-engine/slide-merge-split.js +19 -19
- package/dist/safe-bash-presentation-engine/slide-model.js +42 -42
- package/dist/safe-bash-presentation-engine/slide-removal.js +17 -17
- package/dist/safe-bash-presentation-engine/slide-transfer-budget.js +9 -9
- package/dist/safe-bash-presentation-engine/slides.d.ts +2 -0
- package/dist/safe-bash-presentation-engine/slides.js +21 -16
- package/dist/safe-bash-presentation-engine/table-operations.js +32 -32
- package/dist/safe-bash-presentation-engine/table-spans.js +31 -31
- package/dist/safe-bash-presentation-engine/tables.js +30 -30
- package/dist/safe-bash-presentation-engine/tags.js +15 -15
- package/dist/safe-bash-presentation-engine/template-bindings.js +32 -32
- package/dist/safe-bash-presentation-engine/template-repeat.js +39 -39
- package/dist/safe-bash-presentation-engine/text-fitting.js +26 -26
- package/dist/safe-bash-presentation-engine/text-frames.js +26 -26
- package/dist/safe-bash-presentation-engine/text-paragraphs.js +26 -26
- package/dist/safe-bash-presentation-engine/text-reading.js +11 -11
- package/dist/safe-bash-presentation-engine/text-replacement.js +16 -16
- package/dist/safe-bash-presentation-engine/text-runs.js +19 -19
- package/dist/safe-bash-presentation-engine/themes.js +15 -15
- package/dist/safe-bash-presentation-engine/transitions.js +15 -15
- package/dist/safe-bash-presentation-engine/validation.js +9 -9
- package/dist/safe-bash-presentation-engine/xml-parts.d.ts +1 -0
- package/dist/safe-bash-presentation-engine/xml-parts.js +19 -13
- package/dist/safe-bash-presentation-engine/xml-view.js +3 -3
- package/dist/safe-bash-presentation-engine/xml.js +3 -3
- package/dist/safe-bash-xml-engine/document.js +1 -1
- package/dist/safe-bash-xml-engine/index.js +1 -1
- package/dist/safe-bash-xml-engine/json.d.ts +1 -0
- package/dist/safe-bash-xml-engine/json.js +203 -0
- package/dist/safe-bash-xml-engine/stored-json.d.ts +5 -0
- package/dist/spreadsheet-engine/rendering/print/bidi-runs.d.ts +5 -0
- package/dist/spreadsheet-engine/rendering/print/bidi-runs.js +35 -0
- package/dist/spreadsheet-engine/rendering/print/control-bidi.d.ts +8 -0
- package/dist/spreadsheet-engine/rendering/print/control-bidi.js +80 -0
- package/dist/spreadsheet-engine/rendering/print/tab-layout.d.ts +11 -0
- package/dist/spreadsheet-engine/rendering/print/tab-layout.js +15 -0
- package/dist/spreadsheet-engine/rendering/print/text-lines.d.ts +2 -2
- package/dist/spreadsheet-engine/rendering/print/text-lines.js +3 -3
- package/dist/spreadsheet-format-xls/biff-encrypted-properties.d.ts +5 -1
- package/dist/spreadsheet-format-xls/biff-encrypted-properties.js +151 -57
- package/dist/spreadsheet-format-xls/biff-encryption.d.ts +1 -1
- package/dist/spreadsheet-format-xls/biff-encryption.js +8 -3
- package/dist/spreadsheet-format-xls/biff-property-bytes.d.ts +4 -1
- package/dist/spreadsheet-format-xls/biff-property-bytes.js +3 -3
- package/dist/spreadsheet-format-xls/biff-range.js +1 -1
- package/dist/spreadsheet-format-xls/biff.js +11 -3
- package/package.json +6 -2
- package/dist/safe-bash/chunks/chunk-I2A5ZCPD.js +0 -17
- package/dist/safe-bash/chunks/chunk-PQTT2EZP.js +0 -8
- package/dist/safe-bash/command-chunks/biff-DS263V2K-2GP4GZT7.js +0 -4868
- package/dist/safe-bash/command-chunks/chunk-6ZFYWT3U.js +0 -581
- package/dist/safe-bash/command-chunks/chunk-S244SWDH.js +0 -153
- package/dist/safe-bash/command-chunks/pdf-T7AWYZGQ-KNAYJ7YF.js +0 -552
- /package/dist/safe-bash/command-chunks/{chunk-EMMSXKEJ.js → chunk-4Q4R3VZU.js} +0 -0
|
@@ -0,0 +1,826 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PatchPublication,
|
|
3
|
+
TargetDocuments,
|
|
4
|
+
TargetOutput,
|
|
5
|
+
equalTargetLines,
|
|
6
|
+
targetBytes
|
|
7
|
+
} from "./chunk-WH3TIOTS.js";
|
|
8
|
+
import {
|
|
9
|
+
unwrapPatch
|
|
10
|
+
} from "./chunk-JKLOBSMP.js";
|
|
11
|
+
import {
|
|
12
|
+
parsePatch
|
|
13
|
+
} from "./chunk-2VLAXKTS.js";
|
|
14
|
+
import {
|
|
15
|
+
reversePatch,
|
|
16
|
+
startIndex
|
|
17
|
+
} from "./chunk-MOZD7RUY.js";
|
|
18
|
+
import {
|
|
19
|
+
authorizeOutputs,
|
|
20
|
+
authorizePaths,
|
|
21
|
+
backupName,
|
|
22
|
+
candidateStat,
|
|
23
|
+
ensureParents,
|
|
24
|
+
pruneDirectories,
|
|
25
|
+
pruneParents,
|
|
26
|
+
regular,
|
|
27
|
+
rejectName,
|
|
28
|
+
selectTarget
|
|
29
|
+
} from "./chunk-OQNX2OOS.js";
|
|
30
|
+
import {
|
|
31
|
+
safeTarget
|
|
32
|
+
} from "./chunk-AJEQUVDN.js";
|
|
33
|
+
import {
|
|
34
|
+
rejectText
|
|
35
|
+
} from "./chunk-JYTESTBS.js";
|
|
36
|
+
|
|
37
|
+
// packages/safe-bash-command-patch/src/stored-hunks.ts
|
|
38
|
+
import { ToolError } from "../../safe-bash-diff-engine/shared.js";
|
|
39
|
+
async function applyStoredHunks(original, patch, fuzz, budget, ignoreWhitespace = false, application, documents) {
|
|
40
|
+
const source = { length: original.length, at(index) {
|
|
41
|
+
return index >= 0 && index < original.length ? { document: original, index } : void 0;
|
|
42
|
+
} };
|
|
43
|
+
budget.countLines(source.length);
|
|
44
|
+
const result = new TargetOutput(documents);
|
|
45
|
+
try {
|
|
46
|
+
let cursor = 0;
|
|
47
|
+
let offset = 0;
|
|
48
|
+
let outputOffset = 0;
|
|
49
|
+
for (const [hunkIndex, hunk] of patch.hunks.entries()) {
|
|
50
|
+
budget.step();
|
|
51
|
+
const oldLines = hunk.lines.filter((line) => line.kind !== "+");
|
|
52
|
+
let leading = 0;
|
|
53
|
+
let trailing = 0;
|
|
54
|
+
while (leading < hunk.lines.length && hunk.lines[leading].kind === " ") leading++;
|
|
55
|
+
while (trailing < hunk.lines.length - leading && hunk.lines[hunk.lines.length - trailing - 1].kind === " ") trailing++;
|
|
56
|
+
const expected = startIndex(hunk.oldStart, hunk.oldCount) + offset;
|
|
57
|
+
let found = -1;
|
|
58
|
+
let misordered = false;
|
|
59
|
+
let usedFuzz = 0;
|
|
60
|
+
const context = Math.max(leading, trailing);
|
|
61
|
+
const matches = async (position, prefixFuzz, suffixFuzz) => {
|
|
62
|
+
budget.step();
|
|
63
|
+
{
|
|
64
|
+
const c = budget.checkpoint();
|
|
65
|
+
if (c) await c;
|
|
66
|
+
}
|
|
67
|
+
if (position < 0 || position > source.length - hunk.oldCount + suffixFuzz) return false;
|
|
68
|
+
for (let lineIndex = 0; lineIndex < oldLines.length; lineIndex++) {
|
|
69
|
+
if (lineIndex < prefixFuzz || lineIndex >= oldLines.length - suffixFuzz) continue;
|
|
70
|
+
const actual = source.at(position + lineIndex);
|
|
71
|
+
if (actual === void 0) return false;
|
|
72
|
+
const expectedLine = oldLines[lineIndex].text;
|
|
73
|
+
if (!await equalTargetLines(actual, expectedLine, budget, ignoreWhitespace)) return false;
|
|
74
|
+
{
|
|
75
|
+
const c = budget.checkpoint();
|
|
76
|
+
if (c) await c;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (position < cursor) misordered = true;
|
|
80
|
+
return true;
|
|
81
|
+
};
|
|
82
|
+
let matchedPrefixFuzz = 0;
|
|
83
|
+
let matchedSuffixFuzz = 0;
|
|
84
|
+
for (let tolerance = 0; tolerance <= Math.min(fuzz, context); tolerance++) {
|
|
85
|
+
if (application.rejectAll) break;
|
|
86
|
+
usedFuzz = tolerance;
|
|
87
|
+
const prefixFuzz = tolerance + leading - context;
|
|
88
|
+
const suffixFuzz = tolerance + trailing - context;
|
|
89
|
+
if (prefixFuzz < 0 && hunk.oldStart <= 1) {
|
|
90
|
+
if (await matches(0, 0, suffixFuzz)) {
|
|
91
|
+
found = 0;
|
|
92
|
+
matchedPrefixFuzz = 0;
|
|
93
|
+
matchedSuffixFuzz = suffixFuzz;
|
|
94
|
+
}
|
|
95
|
+
if (found >= 0) break;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (suffixFuzz < 0) {
|
|
99
|
+
const end = source.length - hunk.oldCount;
|
|
100
|
+
if (await matches(end, Math.max(0, prefixFuzz), 0)) {
|
|
101
|
+
found = end;
|
|
102
|
+
matchedPrefixFuzz = Math.max(0, prefixFuzz);
|
|
103
|
+
matchedSuffixFuzz = 0;
|
|
104
|
+
}
|
|
105
|
+
if (found >= 0) break;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const retained = oldLines.length - Math.max(0, prefixFuzz) - suffixFuzz;
|
|
109
|
+
if (retained === 0) {
|
|
110
|
+
if (await matches(expected, Math.max(0, prefixFuzz), suffixFuzz)) {
|
|
111
|
+
found = expected;
|
|
112
|
+
matchedPrefixFuzz = Math.max(0, prefixFuzz);
|
|
113
|
+
matchedSuffixFuzz = suffixFuzz;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const maximum = source.length - hunk.oldCount + suffixFuzz;
|
|
119
|
+
const positiveLimit = maximum - expected;
|
|
120
|
+
const negativeLimit = Math.min(expected - cursor, expected);
|
|
121
|
+
const distanceLimit = Math.max(positiveLimit, negativeLimit);
|
|
122
|
+
const firstDistance = positiveLimit < 0 ? -positiveLimit : negativeLimit < 0 ? negativeLimit : 0;
|
|
123
|
+
for (let distance = firstDistance; distance <= distanceLimit; distance++) {
|
|
124
|
+
if (distance <= positiveLimit && await matches(expected + distance, Math.max(0, prefixFuzz), suffixFuzz)) {
|
|
125
|
+
found = expected + distance;
|
|
126
|
+
matchedPrefixFuzz = Math.max(0, prefixFuzz);
|
|
127
|
+
matchedSuffixFuzz = suffixFuzz;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (distance <= negativeLimit && await matches(expected - distance, Math.max(0, prefixFuzz), suffixFuzz)) {
|
|
131
|
+
found = expected - distance;
|
|
132
|
+
matchedPrefixFuzz = Math.max(0, prefixFuzz);
|
|
133
|
+
matchedSuffixFuzz = suffixFuzz;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (found >= 0) break;
|
|
138
|
+
}
|
|
139
|
+
const matched = found;
|
|
140
|
+
if (matched >= 0) offset = matched - startIndex(hunk.oldStart, hunk.oldCount);
|
|
141
|
+
if (misordered) found = -1;
|
|
142
|
+
application.outcomes?.push({
|
|
143
|
+
hunk,
|
|
144
|
+
index: hunkIndex + 1,
|
|
145
|
+
failed: found < 0,
|
|
146
|
+
misordered: found < 0 && misordered,
|
|
147
|
+
line: (matched < 0 ? startIndex(hunk.oldStart, hunk.oldCount) : matched) + 1 + outputOffset,
|
|
148
|
+
outputOffset,
|
|
149
|
+
offset: matched - startIndex(hunk.oldStart, hunk.oldCount),
|
|
150
|
+
fuzz: usedFuzz
|
|
151
|
+
});
|
|
152
|
+
if (found < 0 && application.merge && !misordered) {
|
|
153
|
+
const position = Math.max(cursor, Math.min(source.length, expected));
|
|
154
|
+
while (cursor < position) await result.append(source.at(cursor++));
|
|
155
|
+
let local = Array.from({ length: Math.min(hunk.oldCount, source.length - cursor) }, (_, index) => source.at(cursor + index));
|
|
156
|
+
let anchored = false;
|
|
157
|
+
for (let index = 0; index < oldLines.length; index++) {
|
|
158
|
+
if (await equalTargetLines(oldLines[index].text, local[index] ?? "", budget)) {
|
|
159
|
+
anchored = true;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!anchored) local = [];
|
|
164
|
+
const incoming = hunk.lines.filter((line) => line.kind !== "-").map((line) => line.text);
|
|
165
|
+
const base = oldLines.map((line) => line.text);
|
|
166
|
+
let prefix = 0;
|
|
167
|
+
let suffix = 0;
|
|
168
|
+
while (prefix < Math.min(local.length, incoming.length, base.length) && await equalTargetLines(local[prefix], incoming[prefix], budget) && await equalTargetLines(local[prefix], base[prefix], budget)) prefix++;
|
|
169
|
+
while (suffix < Math.min(local.length, incoming.length, base.length) - prefix && await equalTargetLines(local[local.length - suffix - 1], incoming[incoming.length - suffix - 1], budget) && await equalTargetLines(local[local.length - suffix - 1], base[base.length - suffix - 1], budget)) suffix++;
|
|
170
|
+
{
|
|
171
|
+
const c = budget.checkpoint();
|
|
172
|
+
if (c) await c;
|
|
173
|
+
}
|
|
174
|
+
for (const line of local.slice(0, prefix)) await result.append(line);
|
|
175
|
+
const mergeStart = result.length + 1;
|
|
176
|
+
let identical = local.length === incoming.length;
|
|
177
|
+
for (let index = 0; identical && index < local.length; index++) identical = await equalTargetLines(local[index], incoming[index], budget);
|
|
178
|
+
if (identical) {
|
|
179
|
+
const last = application.outcomes?.pop();
|
|
180
|
+
if (last) application.outcomes.push({ ...last, failed: false, fuzz: 0, offset: position - startIndex(hunk.oldStart, hunk.oldCount) });
|
|
181
|
+
for (const line of local.slice(prefix, local.length - suffix)) await result.append(line);
|
|
182
|
+
} else {
|
|
183
|
+
await result.append("<<<<<<<\n");
|
|
184
|
+
for (const line of local.slice(prefix, local.length - suffix)) await result.append(line);
|
|
185
|
+
if (application.merge === "diff3") {
|
|
186
|
+
await result.append("|||||||\n");
|
|
187
|
+
for (const line of base.slice(prefix, base.length - suffix)) await result.append(line);
|
|
188
|
+
}
|
|
189
|
+
await result.append("=======\n");
|
|
190
|
+
for (const line of incoming.slice(prefix, incoming.length - suffix)) await result.append(line);
|
|
191
|
+
await result.append(">>>>>>>\n");
|
|
192
|
+
const last = application.outcomes?.pop();
|
|
193
|
+
if (last) application.outcomes.push({ ...last, mergeRange: [mergeStart, result.length] });
|
|
194
|
+
}
|
|
195
|
+
for (const line of local.slice(local.length - suffix)) await result.append(line);
|
|
196
|
+
cursor += local.length;
|
|
197
|
+
outputOffset = result.length - cursor;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (found < 0) {
|
|
201
|
+
if (application.partial) continue;
|
|
202
|
+
throw new ToolError(`hunk ${hunkIndex + 1} does not match ${patch.oldPath}`, 1);
|
|
203
|
+
}
|
|
204
|
+
while (cursor < found + matchedPrefixFuzz) await result.append(source.at(cursor++));
|
|
205
|
+
let removed = [];
|
|
206
|
+
let added = [];
|
|
207
|
+
const flush = async () => {
|
|
208
|
+
if (!removed.length && !added.length) return;
|
|
209
|
+
if (application.ifdef) {
|
|
210
|
+
await result.append(`#${removed.length ? "ifndef" : "ifdef"} ${application.ifdef}
|
|
211
|
+
`);
|
|
212
|
+
for (const text of removed) await result.append(text);
|
|
213
|
+
if (removed.length && added.length) await result.append("#else\n");
|
|
214
|
+
for (const text of added) await result.append(text);
|
|
215
|
+
await result.append("#endif\n");
|
|
216
|
+
} else for (const text of added) await result.append(text);
|
|
217
|
+
removed = [];
|
|
218
|
+
added = [];
|
|
219
|
+
};
|
|
220
|
+
for (const line of hunk.lines.slice(matchedPrefixFuzz, hunk.lines.length - matchedSuffixFuzz)) {
|
|
221
|
+
if (line.kind === "+") added.push(line.text);
|
|
222
|
+
else if (line.kind === " ") {
|
|
223
|
+
await flush();
|
|
224
|
+
if (cursor < source.length) await result.append(source.at(cursor++));
|
|
225
|
+
} else {
|
|
226
|
+
removed.push(source.at(cursor) ?? line.text);
|
|
227
|
+
cursor++;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
await flush();
|
|
231
|
+
outputOffset = result.length - cursor;
|
|
232
|
+
}
|
|
233
|
+
while (cursor < source.length) await result.append(source.at(cursor++));
|
|
234
|
+
return await result.finish();
|
|
235
|
+
} finally {
|
|
236
|
+
await result.close();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// packages/safe-bash-command-patch/src/patch.ts
|
|
241
|
+
import { FsError, dirname, pipeBytes, resolvePath, writeBytes } from "../../safe-bash-contracts/index.js";
|
|
242
|
+
import { publicDiagnosticMessage } from "../../safe-bash-contracts/diagnostics.js";
|
|
243
|
+
import { Budget as Budget2, ToolError as ToolError2, definition, host, inspect, integer } from "../../safe-bash-diff-engine/shared.js";
|
|
244
|
+
import { encodeBytes } from "../../safe-bash-io-engine/byte-encoding.js";
|
|
245
|
+
function flags(args) {
|
|
246
|
+
const result = { input: "-", reverse: false, dryRun: false, atomic: false, quiet: false, force: false, backup: true, fuzz: 2, ignoreWhitespace: false, removeEmpty: false };
|
|
247
|
+
const operands = [];
|
|
248
|
+
const select = (format) => {
|
|
249
|
+
result.format = format;
|
|
250
|
+
};
|
|
251
|
+
const versionControl = (parameter) => {
|
|
252
|
+
if (["simple", "never"].includes(parameter)) result.versionControl = "simple";
|
|
253
|
+
else if (["numbered", "t"].includes(parameter)) result.versionControl = "numbered";
|
|
254
|
+
else if (["existing", "nil"].includes(parameter)) result.versionControl = "existing";
|
|
255
|
+
else throw new ToolError2(`invalid version control: ${parameter}`);
|
|
256
|
+
};
|
|
257
|
+
let literal = false;
|
|
258
|
+
let backupSelected = false;
|
|
259
|
+
for (let index = 0; index < args.length; index++) {
|
|
260
|
+
const arg = args[index];
|
|
261
|
+
const value = (attached, name) => {
|
|
262
|
+
const next = attached ?? args[++index];
|
|
263
|
+
if (next === void 0) throw new ToolError2(`${name} requires an argument`);
|
|
264
|
+
return next;
|
|
265
|
+
};
|
|
266
|
+
if (literal || arg === "-" || !arg.startsWith("-")) operands.push(arg);
|
|
267
|
+
else if (arg === "--") literal = true;
|
|
268
|
+
else if (arg === "--dry-run") result.dryRun = true;
|
|
269
|
+
else if (arg === "--atomic") result.atomic = true;
|
|
270
|
+
else if (arg === "--quiet" || arg === "--silent") {
|
|
271
|
+
result.quiet = true;
|
|
272
|
+
result.verbose = false;
|
|
273
|
+
} else if (arg === "--force") result.force = true;
|
|
274
|
+
else if (arg === "--batch") continue;
|
|
275
|
+
else if (arg === "--binary") continue;
|
|
276
|
+
else if (arg === "--posix") result.posix = true;
|
|
277
|
+
else if (arg === "--verbose") {
|
|
278
|
+
result.verbose = true;
|
|
279
|
+
result.quiet = false;
|
|
280
|
+
} else if (arg === "--set-time") result.setTime ??= "local";
|
|
281
|
+
else if (arg === "--set-utc") result.setTime = "utc";
|
|
282
|
+
else if (arg === "--merge" || arg.startsWith("--merge=")) {
|
|
283
|
+
const style = arg.includes("=") ? arg.slice(arg.indexOf("=") + 1) : "merge";
|
|
284
|
+
if (style !== "merge" && style !== "diff3") throw new ToolError2(`invalid merge style: ${style}`);
|
|
285
|
+
result.merge = style;
|
|
286
|
+
} else if (arg === "--backup") result.alwaysBackup = true;
|
|
287
|
+
else if (arg === "--forward") result.forward = true;
|
|
288
|
+
else if (arg === "--no-backup-if-mismatch") {
|
|
289
|
+
result.backup = false;
|
|
290
|
+
backupSelected = true;
|
|
291
|
+
} else if (arg === "--backup-if-mismatch") {
|
|
292
|
+
result.backup = true;
|
|
293
|
+
backupSelected = true;
|
|
294
|
+
} else if (arg === "--reverse") result.reverse = true;
|
|
295
|
+
else if (arg === "--remove-empty-files") result.removeEmpty = true;
|
|
296
|
+
else if (arg === "--ignore-whitespace" || arg === "--ignore-white-space") result.ignoreWhitespace = true;
|
|
297
|
+
else if (arg === "--unified") select("unified");
|
|
298
|
+
else if (arg === "--context") select("context");
|
|
299
|
+
else if (arg === "--normal") select("normal");
|
|
300
|
+
else if (["--strip", "--input", "--fuzz", "--reject-file", "--output", "--directory", "--get", "--suffix", "--prefix", "--basename-prefix", "--version-control", "--ifdef", "--quoting-style", "--reject-format", "--read-only"].includes(arg.split("=")[0])) {
|
|
301
|
+
const [name] = arg.split("=");
|
|
302
|
+
const parameter = value(arg.includes("=") ? arg.slice(arg.indexOf("=") + 1) : void 0, name);
|
|
303
|
+
if (name === "--ifdef") result.ifdef = parameter;
|
|
304
|
+
else if (name === "--quoting-style") {
|
|
305
|
+
if (!["literal", "shell", "shell-always", "shell-escape", "shell-escape-always", "c", "escape", "locale", "clocale"].includes(parameter)) throw new ToolError2(`invalid quoting style: ${parameter}`);
|
|
306
|
+
result.quotingStyle = parameter;
|
|
307
|
+
} else if (name === "--reject-format") {
|
|
308
|
+
if (parameter !== "unified" && parameter !== "context") throw new ToolError2(`invalid reject format: ${parameter}`);
|
|
309
|
+
result.rejectFormat = parameter;
|
|
310
|
+
} else if (name === "--read-only") {
|
|
311
|
+
if (!["ignore", "warn", "fail"].includes(parameter)) throw new ToolError2(`invalid read-only behavior: ${parameter}`);
|
|
312
|
+
result.readOnly = parameter;
|
|
313
|
+
} else if (name === "--strip") result.strip = integer(parameter, "strip count");
|
|
314
|
+
else if (name === "--fuzz") result.fuzz = integer(parameter, "fuzz");
|
|
315
|
+
else if (name === "--reject-file") result.reject = parameter;
|
|
316
|
+
else if (name === "--output") result.output = parameter;
|
|
317
|
+
else if (name === "--directory") result.directory = parameter;
|
|
318
|
+
else if (name === "--suffix") result.suffix = parameter;
|
|
319
|
+
else if (name === "--prefix") result.prefix = parameter;
|
|
320
|
+
else if (name === "--basename-prefix") result.basenamePrefix = parameter;
|
|
321
|
+
else if (name === "--version-control") versionControl(parameter);
|
|
322
|
+
else if (name === "--get") {
|
|
323
|
+
if (parameter !== "0") throw new ToolError2("version-control acquisition is unsupported; use --get=0");
|
|
324
|
+
} else result.input = parameter;
|
|
325
|
+
} else if (arg.startsWith("--")) throw new ToolError2(`unsupported option: ${arg}`);
|
|
326
|
+
else for (let offset = 1; offset < arg.length; offset++) {
|
|
327
|
+
const flag = arg[offset];
|
|
328
|
+
if (flag === "R") result.reverse = true;
|
|
329
|
+
else if (flag === "s") {
|
|
330
|
+
result.quiet = true;
|
|
331
|
+
result.verbose = false;
|
|
332
|
+
} else if (flag === "f") result.force = true;
|
|
333
|
+
else if (flag === "t") continue;
|
|
334
|
+
else if (flag === "T") result.setTime ??= "local";
|
|
335
|
+
else if (flag === "Z") result.setTime = "utc";
|
|
336
|
+
else if (flag === "b") result.alwaysBackup = true;
|
|
337
|
+
else if (flag === "N") result.forward = true;
|
|
338
|
+
else if (flag === "E") result.removeEmpty = true;
|
|
339
|
+
else if (flag === "l") result.ignoreWhitespace = true;
|
|
340
|
+
else if (flag === "u") select("unified");
|
|
341
|
+
else if (flag === "c") select("context");
|
|
342
|
+
else if (flag === "n") select("normal");
|
|
343
|
+
else if (["p", "i", "F", "r", "o", "d", "g", "z", "B", "Y", "V", "D"].includes(flag)) {
|
|
344
|
+
const parameter = value(arg.slice(offset + 1) || void 0, `-${flag}`);
|
|
345
|
+
if (flag === "D") result.ifdef = parameter;
|
|
346
|
+
else if (flag === "p") result.strip = integer(parameter, "strip count");
|
|
347
|
+
else if (flag === "F") result.fuzz = integer(parameter, "fuzz");
|
|
348
|
+
else if (flag === "r") result.reject = parameter;
|
|
349
|
+
else if (flag === "o") result.output = parameter;
|
|
350
|
+
else if (flag === "d") result.directory = parameter;
|
|
351
|
+
else if (flag === "z") result.suffix = parameter;
|
|
352
|
+
else if (flag === "B") result.prefix = parameter;
|
|
353
|
+
else if (flag === "Y") result.basenamePrefix = parameter;
|
|
354
|
+
else if (flag === "V") versionControl(parameter);
|
|
355
|
+
else if (flag === "g") {
|
|
356
|
+
if (parameter !== "0") throw new ToolError2("version-control acquisition is unsupported; use -g0");
|
|
357
|
+
} else result.input = parameter;
|
|
358
|
+
break;
|
|
359
|
+
} else throw new ToolError2(`unsupported option: -${flag}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (operands.length > 2) throw new ToolError2("expected at most a target file and a patch input file");
|
|
363
|
+
if (operands.length) result.target = operands[0];
|
|
364
|
+
if (operands.length === 2) result.input = operands[1];
|
|
365
|
+
if (!result.input || result.input.includes("\0")) throw new ToolError2("invalid patch input path");
|
|
366
|
+
for (const path of [result.output, result.directory]) if (path !== void 0 && (!path || path.includes("\0"))) throw new ToolError2("invalid patch option path");
|
|
367
|
+
if (result.ifdef !== void 0 && (!result.ifdef || [...result.ifdef].some((c) => !"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_".includes(c)))) throw new ToolError2("invalid ifdef symbol");
|
|
368
|
+
if (result.merge) result.fuzz = 0;
|
|
369
|
+
if (result.posix && !backupSelected) result.backup = false;
|
|
370
|
+
return result;
|
|
371
|
+
}
|
|
372
|
+
async function applyContent(sourcePatch, current, exists, options, budget, documents) {
|
|
373
|
+
let reversed = options.reverse;
|
|
374
|
+
let patch = reversed ? reversePatch(sourcePatch) : sourcePatch;
|
|
375
|
+
const emptyOld = () => patch.hunks.every((hunk) => hunk.oldCount === 0 && hunk.oldStart === 0);
|
|
376
|
+
const creation = () => patch.oldPath === "/dev/null" || emptyOld() && (patch.oldEpoch || !exists);
|
|
377
|
+
let autoReversed = false;
|
|
378
|
+
let reverseMismatch = false;
|
|
379
|
+
const declaredCreation = patch.oldPath === "/dev/null" || patch.oldEpoch && emptyOld();
|
|
380
|
+
const declaredDeletion = patch.newPath === "/dev/null" || patch.newEpoch && patch.hunks.every((hunk) => hunk.newCount === 0);
|
|
381
|
+
if (!options.force && (declaredCreation && current.size !== 0 || declaredDeletion && !exists)) {
|
|
382
|
+
patch = reversePatch(patch);
|
|
383
|
+
reversed = !reversed;
|
|
384
|
+
autoReversed = true;
|
|
385
|
+
}
|
|
386
|
+
if (!creation() && !exists) return void 0;
|
|
387
|
+
let outcomes = [];
|
|
388
|
+
let result = await applyStoredHunks(current, patch, options.fuzz, budget, options.ignoreWhitespace, {
|
|
389
|
+
partial: true,
|
|
390
|
+
outcomes,
|
|
391
|
+
...options.ifdef === void 0 ? {} : { ifdef: options.ifdef },
|
|
392
|
+
...options.merge === void 0 ? {} : { merge: options.merge },
|
|
393
|
+
rejectAll: creation() && current.size !== 0
|
|
394
|
+
}, documents);
|
|
395
|
+
if (!options.merge && !options.force && !autoReversed && (outcomes[0]?.failed || outcomes[0]?.fuzz)) {
|
|
396
|
+
const opposite = reversePatch(patch);
|
|
397
|
+
const probe = [];
|
|
398
|
+
const reverseFuzz = outcomes[0].failed ? options.fuzz : outcomes[0].fuzz - 1;
|
|
399
|
+
const probeResult = await applyStoredHunks(current, { ...opposite, hunks: opposite.hunks.slice(0, 1) }, reverseFuzz, budget, options.ignoreWhitespace, { partial: true, outcomes: probe }, documents);
|
|
400
|
+
await documents.release(probeResult);
|
|
401
|
+
if (!probe[0]?.failed) {
|
|
402
|
+
patch = opposite;
|
|
403
|
+
reversed = !reversed;
|
|
404
|
+
autoReversed = true;
|
|
405
|
+
reverseMismatch = true;
|
|
406
|
+
outcomes = [];
|
|
407
|
+
await documents.release(result);
|
|
408
|
+
result = await applyStoredHunks(current, patch, options.fuzz, budget, options.ignoreWhitespace, {
|
|
409
|
+
partial: true,
|
|
410
|
+
outcomes,
|
|
411
|
+
...options.ifdef === void 0 ? {} : { ifdef: options.ifdef },
|
|
412
|
+
...options.merge === void 0 ? {} : { merge: options.merge },
|
|
413
|
+
rejectAll: creation() && current.size !== 0
|
|
414
|
+
}, documents);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
const deletion = patch.newPath === "/dev/null" || patch.newEpoch && patch.hunks.every((hunk) => hunk.newCount === 0 && hunk.newStart === 0);
|
|
418
|
+
if (autoReversed && options.forward) {
|
|
419
|
+
await documents.release(result);
|
|
420
|
+
return { result: current, outcomes: [], reversed, autoReversed, reverseMismatch, deletion: false, skipped: true };
|
|
421
|
+
}
|
|
422
|
+
return { result, outcomes, reversed, autoReversed, reverseMismatch, deletion };
|
|
423
|
+
}
|
|
424
|
+
async function unchanged(item, budget, documents) {
|
|
425
|
+
if (item.sourcePath !== void 0) {
|
|
426
|
+
const source = await inspect(budget, item.sourcePath);
|
|
427
|
+
regular(source, item.sourcePath);
|
|
428
|
+
if (source === void 0 !== (item.sourceOriginal === void 0) || source && !await sameTarget(item.sourcePath, item.sourceOriginal, documents)) throw new ToolError2(`target changed during preflight: ${item.sourcePath}`, 1);
|
|
429
|
+
}
|
|
430
|
+
const stat = await inspect(budget, item.path);
|
|
431
|
+
regular(stat, item.path);
|
|
432
|
+
if (stat === void 0 !== (item.original === void 0) || item.original !== void 0 && !await sameTarget(item.path, item.original, documents)) {
|
|
433
|
+
throw new ToolError2(`target changed during preflight: ${item.path}`, 1);
|
|
434
|
+
}
|
|
435
|
+
for (const path of [item.backupPath, item.rejectPath]) {
|
|
436
|
+
if (path !== void 0) regular(await inspect(budget, path), path);
|
|
437
|
+
}
|
|
438
|
+
for (const parent of item.parents) await inspect(budget, parent);
|
|
439
|
+
}
|
|
440
|
+
async function publish(item, budget, rejects, publication, documents) {
|
|
441
|
+
const context = budget.context;
|
|
442
|
+
await unchanged(item, budget, documents);
|
|
443
|
+
const write = async (path, text, append = false, createParents = true, mode, mtimeMs) => {
|
|
444
|
+
if (createParents) await ensureParents(path, budget);
|
|
445
|
+
else if ((await inspect(budget, dirname(path)))?.type !== "directory") throw new ToolError2(`reject parent does not exist: ${dirname(path)}`);
|
|
446
|
+
const stat = await inspect(budget, path);
|
|
447
|
+
regular(stat, path);
|
|
448
|
+
const capabilities = await host(context, async () => await context.fs.capabilitiesFor?.(path, { signal: context.signal, create: true }) ?? context.fs.capabilities);
|
|
449
|
+
if (capabilities?.atomicStagingAncestry !== true && !(publication.trusted && capabilities?.trustedOwnedStaging === true)) throw new ToolError2("filesystem does not support race-safe patch publication");
|
|
450
|
+
const publicationMode = capabilities?.permissions === false ? void 0 : mode ?? (stat ? stat.mode & 4095 : void 0);
|
|
451
|
+
if (typeof text === "string") text = await documents.load(targetBytes(text));
|
|
452
|
+
if (append && stat) text = await documents.concat(await documents.read(path), text);
|
|
453
|
+
await publication.write(path, text.range(0, text.size), stat, publicationMode, mtimeMs);
|
|
454
|
+
};
|
|
455
|
+
if (item.backup !== void 0 && item.backupPath !== void 0) await write(item.backupPath, item.backup, false, true, item.backupMode);
|
|
456
|
+
if (item.remove) {
|
|
457
|
+
if (item.original !== void 0) {
|
|
458
|
+
const expected = await inspect(budget, item.path);
|
|
459
|
+
regular(expected, item.path);
|
|
460
|
+
if (!expected) throw new ToolError2(`target changed during publication: ${item.path}`, 1);
|
|
461
|
+
await publication.remove(item.path, expected);
|
|
462
|
+
}
|
|
463
|
+
} else if (!item.skipWrite) {
|
|
464
|
+
await write(item.path, item.result, false, true, void 0, item.mtimeMs);
|
|
465
|
+
}
|
|
466
|
+
if (item.rejectPath !== void 0 && item.reject !== void 0) {
|
|
467
|
+
await write(item.rejectPath, item.reject, rejects.has(item.rejectPath), false);
|
|
468
|
+
rejects.add(item.rejectPath);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
async function run(context, budget) {
|
|
472
|
+
const options = flags(context.args);
|
|
473
|
+
const outputToStdout = options.output === "-";
|
|
474
|
+
if (options.directory !== void 0) {
|
|
475
|
+
const cwd = resolvePath(context.cwd, options.directory);
|
|
476
|
+
if ((await inspect(budget, cwd))?.type !== "directory") throw new ToolError2(`not a directory: ${options.directory}`);
|
|
477
|
+
context = { ...context, cwd };
|
|
478
|
+
budget = new Budget2(context, Object.fromEntries(Object.entries(budget.limits).filter(([, value]) => Number.isFinite(value))));
|
|
479
|
+
}
|
|
480
|
+
let publication = new PatchPublication(context);
|
|
481
|
+
if (!options.dryRun) {
|
|
482
|
+
const fs = context.fs;
|
|
483
|
+
const capabilities = await host(context, async () => await fs.capabilitiesFor?.(context.cwd, { signal: context.signal }) ?? fs.capabilities);
|
|
484
|
+
if (capabilities.readOnly === true) throw new FsError("EROFS", { syscall: "patch", path: context.cwd });
|
|
485
|
+
const trusted = capabilities.atomicStagingAncestry !== true && capabilities.trustedOwnedStaging === true;
|
|
486
|
+
if ((trusted ? !fs.prepareDirectory || !fs.removeFileConditional : !fs.confineExtraction || capabilities.atomicStagingAncestry !== true) || !fs.createStagedFile || !fs.publishStagedFile || !fs.removeStagedFile) {
|
|
487
|
+
throw new ToolError2("filesystem does not support race-safe patch publication");
|
|
488
|
+
}
|
|
489
|
+
publication = new PatchPublication(context, trusted);
|
|
490
|
+
await publication.capture(`${context.cwd === "/" ? "" : context.cwd}/.patch-admission`);
|
|
491
|
+
const confined = trusted ? fs : await host(context, () => fs.confineExtraction([context.cwd], { signal: context.signal }));
|
|
492
|
+
context = { ...context, fs: new Proxy(fs, {
|
|
493
|
+
get(target, property) {
|
|
494
|
+
if (trusted && property === "mkdir") return (path) => publication.mkdir(path);
|
|
495
|
+
if (property === "rmdir") return (path) => publication.prune(path);
|
|
496
|
+
const selected = ["mkdir", "rm"].includes(String(property)) ? confined : target;
|
|
497
|
+
const value = Reflect.get(selected, property, selected);
|
|
498
|
+
return typeof value === "function" ? value.bind(selected) : value;
|
|
499
|
+
}
|
|
500
|
+
}) };
|
|
501
|
+
budget = new Budget2(context, Object.fromEntries(Object.entries(budget.limits).filter(([, value]) => Number.isFinite(value))));
|
|
502
|
+
}
|
|
503
|
+
const documents = new TargetDocuments(budget);
|
|
504
|
+
try {
|
|
505
|
+
const empty = await documents.load({ async *[Symbol.asyncIterator]() {
|
|
506
|
+
} });
|
|
507
|
+
const output = options.output === void 0 ? void 0 : safeTarget(options.output, 0, true);
|
|
508
|
+
if (options.output !== void 0 && output === void 0) throw new ToolError2("/dev/null is not an output file");
|
|
509
|
+
const outputPath = output === void 0 || outputToStdout ? void 0 : resolvePath(context.cwd, output);
|
|
510
|
+
const explicit = options.target === void 0 ? void 0 : safeTarget(options.target, 0, true);
|
|
511
|
+
if (options.target !== void 0 && explicit === void 0) throw new ToolError2("/dev/null is not an explicit target");
|
|
512
|
+
if (options.input !== "-") {
|
|
513
|
+
const stat = await inspect(budget, options.input);
|
|
514
|
+
if (stat?.type !== "file") throw new ToolError2("patch input must be a regular file");
|
|
515
|
+
}
|
|
516
|
+
const input = await budget.read(options.input === "-" ? "-" : resolvePath(context.cwd, options.input));
|
|
517
|
+
const progress = options.atomic ? void 0 : {};
|
|
518
|
+
const sections = await parsePatch(await unwrapPatch(input, budget), budget, options.format, explicit, progress);
|
|
519
|
+
const parsed = options.format === "normal" ? sections : sections.filter((patch) => !patch.unlocated);
|
|
520
|
+
if (sections.length && !parsed.length) throw new ToolError2("no identifiable patch; normal input requires a target, Index header, or -n");
|
|
521
|
+
const reject = options.reject === void 0 || options.reject === "-" ? options.reject : safeTarget(options.reject, 0, true);
|
|
522
|
+
if (options.reject !== void 0 && reject === void 0) throw new ToolError2("/dev/null is not a reject file; use -r -");
|
|
523
|
+
const paths = {
|
|
524
|
+
strip: options.strip,
|
|
525
|
+
explicit,
|
|
526
|
+
reject,
|
|
527
|
+
posix: options.posix,
|
|
528
|
+
input: options.input === "-" ? void 0 : resolvePath(context.cwd, options.input)
|
|
529
|
+
};
|
|
530
|
+
const preview = /* @__PURE__ */ new Map();
|
|
531
|
+
const previewParents = /* @__PURE__ */ new Set();
|
|
532
|
+
const authorized = await authorizePaths(parsed, paths, budget, !options.dryRun || options.atomic ? {
|
|
533
|
+
reverse: options.atomic && options.reverse,
|
|
534
|
+
exists: async (path) => preview.has(path) ? preview.get(path) !== void 0 : previewParents.has(path) || await candidateStat(path, budget) !== void 0,
|
|
535
|
+
advance: async (item) => {
|
|
536
|
+
if (outputToStdout) return;
|
|
537
|
+
const path = resolvePath(context.cwd, item.selected);
|
|
538
|
+
const current = preview.has(path) ? preview.get(path) : await inspect(budget, path) ? await documents.read(path) : void 0;
|
|
539
|
+
const applied = await applyContent(item.patch, current ?? empty, current !== void 0, options, budget, documents);
|
|
540
|
+
if (current && current !== applied?.result) await documents.release(current);
|
|
541
|
+
if (!applied) return;
|
|
542
|
+
const remove = options.ifdef === void 0 && applied.result.size === 0 && (!options.posix && applied.deletion || options.removeEmpty);
|
|
543
|
+
preview.set(path, remove ? void 0 : applied.result);
|
|
544
|
+
if (!remove) for (let parent = dirname(path); parent !== "/"; parent = dirname(parent)) previewParents.add(parent);
|
|
545
|
+
}
|
|
546
|
+
} : void 0);
|
|
547
|
+
for (const document of preview.values()) if (document) await documents.release(document);
|
|
548
|
+
preview.clear();
|
|
549
|
+
const targets = new Set(authorized.flatMap((item) => item.selected === void 0 ? [] : [resolvePath(context.cwd, item.selected)]));
|
|
550
|
+
if (outputPath !== void 0) await authorizeOutputs([outputPath], targets, paths.input, budget);
|
|
551
|
+
const staged = /* @__PURE__ */ new Map();
|
|
552
|
+
const stdoutItems = [];
|
|
553
|
+
const stagedParents = /* @__PURE__ */ new Set();
|
|
554
|
+
const touched = /* @__PURE__ */ new Set();
|
|
555
|
+
const rejects = /* @__PURE__ */ new Set();
|
|
556
|
+
const backupPaths = /* @__PURE__ */ new Set();
|
|
557
|
+
const rejectPaths = /* @__PURE__ */ new Set();
|
|
558
|
+
const parents = /* @__PURE__ */ new Set();
|
|
559
|
+
const messages = [];
|
|
560
|
+
let exitCode = 0;
|
|
561
|
+
let committed = 0;
|
|
562
|
+
let publishing = false;
|
|
563
|
+
let activePath;
|
|
564
|
+
let outputContents = empty;
|
|
565
|
+
const statusSink = outputToStdout ? context.stderr : context.stdout;
|
|
566
|
+
const status = async (text) => {
|
|
567
|
+
if (!text) return;
|
|
568
|
+
budget.output(text);
|
|
569
|
+
if (options.atomic) messages.push(text);
|
|
570
|
+
else await writeBytes(statusSink, encodeBytes(text), context.signal);
|
|
571
|
+
};
|
|
572
|
+
const applySection = async (authorizedPatch) => {
|
|
573
|
+
const sourcePatch = authorizedPatch.patch;
|
|
574
|
+
if (sourcePatch.unlocated) {
|
|
575
|
+
if (options.atomic) throw new ToolError2("no file to patch; provide a target or Index header", 1);
|
|
576
|
+
await status(`No file to patch. Skipping patch.
|
|
577
|
+
${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
|
|
578
|
+
`);
|
|
579
|
+
exitCode = 1;
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
const name = await selectTarget(authorizedPatch, async (path2) => options.atomic && staged.has(path2) ? !staged.get(path2).remove : options.atomic && stagedParents.has(path2) || await candidateStat(path2, budget) !== void 0, budget);
|
|
583
|
+
const path = resolvePath(context.cwd, name);
|
|
584
|
+
activePath = path;
|
|
585
|
+
const pruning = pruneParents(name, context.cwd).filter((parent) => parent !== context.cwd);
|
|
586
|
+
if (!options.dryRun) await publication.capture(path, pruning);
|
|
587
|
+
if (path === paths.input || backupPaths.has(path) || rejectPaths.has(path)) throw new ToolError2(`patch target aliases input or an earlier output: ${path}`);
|
|
588
|
+
targets.add(path);
|
|
589
|
+
const prior = options.atomic ? staged.get(path) : void 0;
|
|
590
|
+
const stat = await inspect(budget, path);
|
|
591
|
+
regular(stat, path);
|
|
592
|
+
if (stat && options.readOnly !== "ignore") {
|
|
593
|
+
const capabilities = await host(context, async () => await context.fs.capabilitiesFor?.(path, { signal: context.signal }) ?? context.fs.capabilities);
|
|
594
|
+
if (capabilities?.permissions !== false && !(stat.mode & 146)) {
|
|
595
|
+
const refuse = options.readOnly === "fail";
|
|
596
|
+
await status(`File ${name} is read-only; ${refuse ? "refusing to patch" : "trying to patch anyway"}
|
|
597
|
+
`);
|
|
598
|
+
if (refuse) {
|
|
599
|
+
if (options.atomic) throw new ToolError2(`read-only target: ${name}`, 1);
|
|
600
|
+
const destination = rejectName(outputToStdout ? "-" : name, paths);
|
|
601
|
+
const rejectPath2 = options.dryRun || destination === void 0 ? void 0 : resolvePath(context.cwd, destination);
|
|
602
|
+
if (rejectPath2 !== void 0) {
|
|
603
|
+
await authorizeOutputs([rejectPath2], targets, paths.input, budget);
|
|
604
|
+
if (backupPaths.has(rejectPath2)) throw new ToolError2("reject path aliases another section's backup");
|
|
605
|
+
const patch = options.reverse ? reversePatch(sourcePatch) : sourcePatch;
|
|
606
|
+
const outcomes2 = patch.hunks.map((hunk, index) => ({
|
|
607
|
+
hunk,
|
|
608
|
+
index: index + 1,
|
|
609
|
+
failed: true,
|
|
610
|
+
misordered: false,
|
|
611
|
+
line: hunk.oldStart,
|
|
612
|
+
outputOffset: 0,
|
|
613
|
+
offset: 0,
|
|
614
|
+
fuzz: 0
|
|
615
|
+
}));
|
|
616
|
+
const reject2 = await rejectText(sourcePatch, outcomes2, authorizedPatch.oldName, authorizedPatch.newName, authorizedPatch.indexName, options.reverse, budget, options.rejectFormat);
|
|
617
|
+
const original2 = await documents.read(path);
|
|
618
|
+
publishing = true;
|
|
619
|
+
await publish({ path, original: original2, result: original2, remove: false, skipWrite: true, rejectPath: rejectPath2, reject: reject2, parents: [] }, budget, rejects, publication, documents);
|
|
620
|
+
committed++;
|
|
621
|
+
publishing = false;
|
|
622
|
+
rejectPaths.add(rejectPath2);
|
|
623
|
+
}
|
|
624
|
+
await status(`${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} ${sourcePatch.hunks.length === 1 ? "hunk" : "hunks"} ignored${rejectPath2 === void 0 ? "" : ` -- saving rejects to file ${destination}`}
|
|
625
|
+
`);
|
|
626
|
+
exitCode = 1;
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
const exists = prior ? !prior.remove : stat !== void 0;
|
|
632
|
+
const original = prior ? prior.original : stat ? await documents.read(path) : void 0;
|
|
633
|
+
const current = prior ? prior.remove ? empty : prior.result : original ?? empty;
|
|
634
|
+
if (options.posix && !exists) {
|
|
635
|
+
await status(`No file to patch. Skipping patch.
|
|
636
|
+
${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
|
|
637
|
+
`);
|
|
638
|
+
exitCode = 1;
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
const applied = await applyContent(sourcePatch, current, exists, options, budget, documents);
|
|
642
|
+
if (!applied) {
|
|
643
|
+
if (options.atomic) throw new ToolError2(`patch target does not exist: ${path}`, 1);
|
|
644
|
+
await status(`No file to patch. Skipping patch ${name}.
|
|
645
|
+
${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
|
|
646
|
+
`);
|
|
647
|
+
exitCode = 1;
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
const { result, outcomes, reversed, autoReversed, reverseMismatch, deletion } = applied;
|
|
651
|
+
if (applied.skipped) {
|
|
652
|
+
await status(`Reversed (or previously applied) patch detected! Skipping patch.
|
|
653
|
+
${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
|
|
654
|
+
`);
|
|
655
|
+
exitCode = 1;
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
const failed = outcomes.filter((outcome) => outcome.failed);
|
|
659
|
+
const conflict = failed.length > 0 || deletion && result.size !== 0;
|
|
660
|
+
if (options.atomic && conflict) throw new ToolError2(failed.length ? `hunk ${failed[0].index} does not match ${name}` : `deletion patch leaves content: ${name}`, 1);
|
|
661
|
+
if (conflict) exitCode = 1;
|
|
662
|
+
const mismatch = reverseMismatch || outcomes.some((outcome) => outcome.failed || outcome.offset !== 0 || outcome.fuzz !== 0);
|
|
663
|
+
const backup = !options.dryRun && !outputToStdout && (options.alwaysBackup || options.backup && mismatch) && !touched.has(path) ? original ?? empty : void 0;
|
|
664
|
+
const backupPath = backup === void 0 ? prior?.backupPath : await backupName(path, budget, options);
|
|
665
|
+
const rejectDestination = rejectName(outputToStdout ? "-" : name, paths);
|
|
666
|
+
const rejectPath = !options.dryRun && !options.merge && failed.length && rejectDestination !== void 0 ? resolvePath(context.cwd, rejectDestination) : void 0;
|
|
667
|
+
const rejected = rejectPath === void 0 ? void 0 : await rejectText(sourcePatch, outcomes, authorizedPatch.oldName, authorizedPatch.newName, authorizedPatch.indexName, reversed, budget, options.rejectFormat);
|
|
668
|
+
await authorizeOutputs([outputPath, backupPath, rejectPath], targets, paths.input, budget);
|
|
669
|
+
if (backupPath !== void 0 && rejectPaths.has(backupPath) || rejectPath !== void 0 && backupPaths.has(rejectPath)) {
|
|
670
|
+
throw new ToolError2("reject path aliases another section's backup");
|
|
671
|
+
}
|
|
672
|
+
if (backupPath !== void 0) backupPaths.add(backupPath);
|
|
673
|
+
if (rejectPath !== void 0) rejectPaths.add(rejectPath);
|
|
674
|
+
const remove = options.ifdef === void 0 && output === void 0 && result.size === 0 && (!options.posix && deletion || options.removeEmpty);
|
|
675
|
+
const outputPrior = outputPath === void 0 ? void 0 : staged.get(outputPath);
|
|
676
|
+
const outputOriginal = outputPath === void 0 ? original : outputPrior ? outputPrior.original : await inspect(budget, outputPath) ? await documents.read(outputPath) : void 0;
|
|
677
|
+
if (outputPath !== void 0) outputContents = await documents.concat(outputContents, result);
|
|
678
|
+
let mtimeMs;
|
|
679
|
+
let timeMessage = "";
|
|
680
|
+
if (options.setTime) {
|
|
681
|
+
const oldTime = patchTimestamp(reversed ? sourcePatch.newHeader : sourcePatch.oldHeader, options.setTime);
|
|
682
|
+
const newTime = patchTimestamp(reversed ? sourcePatch.oldHeader : sourcePatch.newHeader, options.setTime);
|
|
683
|
+
if (newTime !== void 0) {
|
|
684
|
+
if (!options.force && stat && oldTime !== void 0 && oldTime !== stat.mtimeMs) timeMessage = `Not setting time of file ${name} (time mismatch)
|
|
685
|
+
`;
|
|
686
|
+
else if (!options.force && mismatch) timeMessage = `Not setting time of file ${name} (contents mismatch)
|
|
687
|
+
`;
|
|
688
|
+
else {
|
|
689
|
+
if (!options.dryRun && !context.fs.utimes) throw new ToolError2("filesystem does not support setting timestamps");
|
|
690
|
+
mtimeMs = newTime;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
const item = {
|
|
695
|
+
path: outputPath ?? path,
|
|
696
|
+
original: outputOriginal,
|
|
697
|
+
result: outputPath === void 0 ? result : outputContents,
|
|
698
|
+
remove,
|
|
699
|
+
...outputToStdout ? { skipWrite: true } : {},
|
|
700
|
+
...outputPath === void 0 ? {} : { sourcePath: path, ...original === void 0 ? {} : { sourceOriginal: original } },
|
|
701
|
+
...backup === void 0 ? prior?.backup === void 0 ? {} : { backup: prior.backup } : { backup },
|
|
702
|
+
...backupPath === void 0 ? {} : { backupPath },
|
|
703
|
+
...prior?.backupMode !== void 0 ? { backupMode: prior.backupMode } : backup !== void 0 && stat ? { backupMode: stat.mode & 4095 } : {},
|
|
704
|
+
...mtimeMs === void 0 ? {} : { mtimeMs },
|
|
705
|
+
...rejectPath === void 0 ? {} : { rejectPath, reject: rejected },
|
|
706
|
+
parents: remove ? pruning : []
|
|
707
|
+
};
|
|
708
|
+
const displayName = quotePatchName(name, options.quotingStyle);
|
|
709
|
+
let message = options.quiet ? "" : `${options.dryRun ? "checking" : "patching"} file ${output === void 0 ? displayName : `${quotePatchName(output, options.quotingStyle)} (read from ${displayName})`}
|
|
710
|
+
`;
|
|
711
|
+
if (options.verbose) {
|
|
712
|
+
const format = sourcePatch.format ?? "unified";
|
|
713
|
+
const headers = sourcePatch.oldHeader === void 0 ? "" : `|${format === "context" ? "***" : "---"} ${sourcePatch.oldHeader}
|
|
714
|
+
|${format === "context" ? "---" : "+++"} ${sourcePatch.newHeader}
|
|
715
|
+
`;
|
|
716
|
+
message = `Hmm... Looks like a ${format} diff to me...
|
|
717
|
+
The text leading up to this was:
|
|
718
|
+
--------------------------
|
|
719
|
+
${headers}--------------------------
|
|
720
|
+
` + message;
|
|
721
|
+
}
|
|
722
|
+
if (autoReversed) message += "Reversed (or previously applied) patch detected! Assuming -R.\n";
|
|
723
|
+
for (const outcome of outcomes) {
|
|
724
|
+
if (outcome.misordered) message += "misordered hunks! output would be garbled\n";
|
|
725
|
+
if (options.quiet) continue;
|
|
726
|
+
if (outcome.failed && options.merge) message += `Hunk #${outcome.index} NOT MERGED at ${outcome.mergeRange?.[0] ?? outcome.line}-${outcome.mergeRange?.[1] ?? outcome.line}.
|
|
727
|
+
`;
|
|
728
|
+
else if (outcome.failed) message += `Hunk #${outcome.index} FAILED at ${outcome.line}.
|
|
729
|
+
`;
|
|
730
|
+
else if (options.verbose || outcome.offset || outcome.fuzz) message += `Hunk #${outcome.index} succeeded at ${outcome.line}${outcome.fuzz ? ` with fuzz ${outcome.fuzz}` : ""}${outcome.offset ? ` (offset ${outcome.offset} ${outcome.offset === 1 ? "line" : "lines"})` : ""}.
|
|
731
|
+
`;
|
|
732
|
+
}
|
|
733
|
+
if (failed.length && !options.merge) message += `${failed.length} out of ${outcomes.length} ${outcomes.length === 1 ? "hunk" : "hunks"} FAILED${options.dryRun || rejectPath === void 0 ? "" : ` -- saving rejects to file ${rejectDestination}`}
|
|
734
|
+
`;
|
|
735
|
+
if (deletion && result.size !== 0) message += `Not deleting file ${name} as content differs from patch
|
|
736
|
+
`;
|
|
737
|
+
message += timeMessage;
|
|
738
|
+
budget.outputLength(result.size);
|
|
739
|
+
if (backup !== void 0) budget.outputLength(backup.size);
|
|
740
|
+
await status(message);
|
|
741
|
+
touched.add(path);
|
|
742
|
+
if (options.atomic) {
|
|
743
|
+
if (outputToStdout) stdoutItems.push(item);
|
|
744
|
+
else {
|
|
745
|
+
staged.set(item.path, item);
|
|
746
|
+
if (!remove) for (let parent = dirname(path); parent !== "/"; parent = dirname(parent)) stagedParents.add(parent);
|
|
747
|
+
}
|
|
748
|
+
} else if (!options.dryRun || outputToStdout) {
|
|
749
|
+
publishing = true;
|
|
750
|
+
if (!options.dryRun) await publish(item, budget, rejects, publication, documents);
|
|
751
|
+
if (outputToStdout) await pipeBytes(result.range(0, result.size), context.stdout, context.signal);
|
|
752
|
+
committed++;
|
|
753
|
+
publishing = false;
|
|
754
|
+
for (const parent of item.parents) parents.add(parent);
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
for (const authorizedPatch of options.atomic && options.reverse ? authorized.slice().reverse() : authorized) {
|
|
758
|
+
activePath = authorizedPatch.selected === void 0 ? void 0 : resolvePath(context.cwd, authorizedPatch.selected);
|
|
759
|
+
try {
|
|
760
|
+
await applySection(authorizedPatch);
|
|
761
|
+
} catch (error) {
|
|
762
|
+
context.signal.throwIfAborted();
|
|
763
|
+
if (committed === 0 && !publishing) throw error;
|
|
764
|
+
throw new ToolError2(`commit stopped; ${committed}/${authorized.length} files committed; failing operation may have side effects; path ${activePath}: ${publicDiagnosticMessage(error, budget.context.onInternalError)}`);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (options.atomic && (!options.dryRun || outputToStdout)) {
|
|
768
|
+
const prepared = outputToStdout ? stdoutItems : [...staged.values()].filter((item) => !(item.remove && item.original === void 0));
|
|
769
|
+
for (const item of prepared) await unchanged(item, budget, documents);
|
|
770
|
+
for (const item of prepared) {
|
|
771
|
+
try {
|
|
772
|
+
if (!options.dryRun) await publish(item, budget, rejects, publication, documents);
|
|
773
|
+
if (outputToStdout) await pipeBytes(item.result.range(0, item.result.size), context.stdout, context.signal);
|
|
774
|
+
committed++;
|
|
775
|
+
} catch (error) {
|
|
776
|
+
context.signal.throwIfAborted();
|
|
777
|
+
throw new ToolError2(`commit stopped; ${committed}/${prepared.length} files committed; failing operation may have side effects; path ${item.path}: ${publicDiagnosticMessage(error, budget.context.onInternalError)}`);
|
|
778
|
+
}
|
|
779
|
+
for (const parent of item.parents) parents.add(parent);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (!options.dryRun) await pruneDirectories(parents, budget);
|
|
783
|
+
if (options.verbose) await status("done\n");
|
|
784
|
+
if (options.atomic && (!options.quiet || messages.length)) await writeBytes(statusSink, encodeBytes(messages.join("")), context.signal);
|
|
785
|
+
if (progress?.error) throw progress.error;
|
|
786
|
+
return exitCode;
|
|
787
|
+
} finally {
|
|
788
|
+
await documents.close();
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
function patchCommand(options = {}) {
|
|
792
|
+
return definition("patch", options, run);
|
|
793
|
+
}
|
|
794
|
+
function patchTimestamp(header, zone) {
|
|
795
|
+
const separator = header?.indexOf(" ") ?? -1;
|
|
796
|
+
if (separator < 0) return void 0;
|
|
797
|
+
let text = header.slice(separator + 1).trim();
|
|
798
|
+
const parts = text.split(" ").filter(Boolean);
|
|
799
|
+
if (zone === "utc" && parts.length === 2) text += " +0000";
|
|
800
|
+
const time = Date.parse(text);
|
|
801
|
+
return Number.isFinite(time) ? time : void 0;
|
|
802
|
+
}
|
|
803
|
+
function quotePatchName(name, style = "shell") {
|
|
804
|
+
const safe = [...name].every((c) => "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_./-".includes(c));
|
|
805
|
+
if (style === "literal" || safe && !["shell-always", "shell-escape-always", "c", "locale", "clocale"].includes(style)) return name;
|
|
806
|
+
if (style === "c" || style === "clocale") return JSON.stringify(name);
|
|
807
|
+
if (style === "locale") return `\u2018${name}\u2019`;
|
|
808
|
+
if (style === "escape") return JSON.stringify(name).slice(1, -1);
|
|
809
|
+
return `'${name.replaceAll("'", "'\\''")}'`;
|
|
810
|
+
}
|
|
811
|
+
async function sameTarget(path, right, documents) {
|
|
812
|
+
const left = await documents.read(path);
|
|
813
|
+
try {
|
|
814
|
+
if (left.size !== right.size || left.length !== right.length) return false;
|
|
815
|
+
for (let index = 0; index < left.length; index++) {
|
|
816
|
+
if (!await equalTargetLines({ document: left, index }, { document: right, index }, documents.budget)) return false;
|
|
817
|
+
}
|
|
818
|
+
return true;
|
|
819
|
+
} finally {
|
|
820
|
+
await documents.release(left);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
export {
|
|
825
|
+
patchCommand
|
|
826
|
+
};
|