UNPKG

isomorphic-git

Version:

A pure JavaScript reimplementation of git for node and browsers

3 lines 5.47 kB
/*! For license information please see index.umd.min.js.LICENSE.txt */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.git=e():t.git=e()}(self,()=>(()=>{"use strict";var t={6867:t=>{const e=(t,e)=>function(...r){return new(0,e.promiseModule)((n,i)=>{e.multiArgs?r.push((...t)=>{e.errorFirst?t[0]?i(t):(t.shift(),n(t)):n(t)}):e.errorFirst?r.push((t,e)=>{t?i(t):n(e)}):r.push(n),t.apply(this,r)})};t.exports=(t,r)=>{r=Object.assign({exclude:[/.+(Sync|Stream)$/],errorFirst:!0,promiseModule:Promise},r);const n=typeof t;if(null===t||"object"!==n&&"function"!==n)throw new TypeError(`Expected \`input\` to be a \`Function\` or \`Object\`, got \`${null===t?"null":n}\``);const i=t=>{const e=e=>"string"==typeof e?t===e:e.test(t);return r.include?r.include.some(e):!r.exclude.some(e)};let o;o="function"===n?function(...n){return r.excludeMain?t(...n):e(t,r).apply(this,n)}:Object.create(Object.getPrototypeOf(t));for(const n in t){const c=t[n];o[n]="function"==typeof c&&i(n)?e(c,r):c}return o}}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,r),o.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};r.r(n),r.d(n,{FileSystem:()=>f});var i=r(6867);function o(t,e){return-(t<e)||+(t>e)}function c(t){const e=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return-1===e?".":0===e?"/":t.slice(0,e)}async function s(t,e){const r=await t.readdir(e);null==r?await t.rm(e):r.length?await Promise.all(r.map(r=>{const n=function(...t){if(0===t.length)return".";let e;for(let r=0;r<t.length;++r){const n=t[r];n.length>0&&(void 0===e?e=n:e+="/"+n)}return void 0===e?".":function(t){if(!t.length)return".";const e="/"===t[0],r="/"===t.at(-1);return(t=function(t,e){let r="",n=0,i=-1,o=0,c="\0";for(let s=0;s<=t.length;++s){if(s<t.length)c=t[s];else{if("/"===c)break;c="/"}if("/"===c){if(i===s-1||1===o);else if(2===o){if(r.length<2||2!==n||"."!==r.at(-1)||"."!==r.at(-2)){if(r.length>2){const t=r.lastIndexOf("/");-1===t?(r="",n=0):(r=r.slice(0,t),n=r.length-1-r.lastIndexOf("/")),i=s,o=0;continue}if(0!==r.length){r="",n=0,i=s,o=0;continue}}e&&(r+=r.length>0?"/..":"..",n=2)}else r.length>0?r+="/"+t.slice(i+1,s):r=t.slice(i+1,s),n=s-i-1;i=s,o=0}else"."===c&&-1!==o?++o:o=-1}return r}(t,!e)).length?(r&&(t+="/"),e?`/${t}`:t):e?"/":r?"./":"."}(e)}(e,r);return t.lstat(n).then(e=>{if(e)return e.isDirectory()?s(t,n):t.rm(n)})})).then(()=>t.rmdir(e)):await t.rmdir(e)}function a(t){return"function"==typeof t}function l(t){return function(t){return t&&"object"==typeof t}(e=(t=>{try{return t.readFile().catch(t=>t)}catch(t){return t}})(t))&&a(e.then)&&a(e.catch);var e}const u=["readFile","writeFile","mkdir","rmdir","unlink","stat","lstat","readdir","readlink","symlink"];function d(t,e){if(l(e))for(const r of u)t[`_${r}`]=e[r].bind(e);else for(const r of u)t[`_${r}`]=i(e[r].bind(e));l(e)?(e.cp&&(t._cp=e.cp.bind(e)),e.rm?t._rm=e.rm.bind(e):e.rmdir.length>1?t._rm=e.rmdir.bind(e):t._rm=s.bind(null,t)):(e.cp&&(t._cp=i(e.cp.bind(e))),e.rm?t._rm=i(e.rm.bind(e)):e.rmdir.length>2?t._rm=i(e.rmdir.bind(e)):t._rm=s.bind(null,t))}class f{constructor(t){if(void 0!==t._original_unwrapped_fs)return t;const e=Object.getOwnPropertyDescriptor(t,"promises");e&&e.enumerable?d(this,t.promises):d(this,t),this._original_unwrapped_fs=t}async exists(t,e={}){try{return await this._stat(t),!0}catch(t){if("ENOENT"===t.code||"ENOTDIR"===t.code||(t.code||"").includes("ENS"))return!1;throw console.log('Unhandled error in "FileSystem.exists()" function',t),t}}async read(t,e={}){try{let r=await this._readFile(t,e);if("true"===e.autocrlf)try{r=new TextDecoder("utf8",{fatal:!0}).decode(r),r=r.replace(/\r\n/g,"\n"),r=(new TextEncoder).encode(r)}catch(t){}return"string"!=typeof r&&(r=Buffer.from(r)),r}catch(t){return null}}async write(t,e,r={}){try{await this._writeFile(t,e,r)}catch(n){await this.mkdir(c(t)),await this._writeFile(t,e,r)}}async mkdir(t,e=!1){try{await this._mkdir(t)}catch(r){if(null===r)return;if("EEXIST"===r.code)return;if(e)throw r;if("ENOENT"===r.code){const e=c(t);if("."===e||"/"===e||e===t)throw r;await this.mkdir(e),await this.mkdir(t,!0)}}}async rm(t){try{await this._unlink(t)}catch(t){if("ENOENT"!==t.code)throw t}}async rmdir(t,e){try{e&&e.recursive?await this._rm(t,e):await this._rmdir(t)}catch(t){if("ENOENT"!==t.code)throw t}}async readdir(t){try{const e=await this._readdir(t);return e.sort(o),e}catch(t){return"ENOTDIR"===t.code?null:[]}}async readdirDeep(t){const e=await this._readdir(t);return(await Promise.all(e.map(async e=>{const r=t+"/"+e;return(await this._stat(r)).isDirectory()?this.readdirDeep(r):r}))).reduce((t,e)=>t.concat(e),[])}async lstat(t){try{return await this._lstat(t)}catch(t){if("ENOENT"===t.code||(t.code||"").includes("ENS"))return null;throw t}}async readlink(t,e={encoding:"buffer"}){try{const r=await this._readlink(t,e);return Buffer.isBuffer(r)?r:Buffer.from(r)}catch(t){if("ENOENT"===t.code||(t.code||"").includes("ENS"))return null;throw t}}async writelink(t,e){return this._symlink(e.toString("utf8"),t)}}return n})()); //# sourceMappingURL=index.umd.min.js.map