UNPKG

@plugin-web-update/core

Version:

English | [简体中文](./README.zh-CN.md)

36 lines (35 loc) 12.2 kB
var tt=Object.create;var E=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var nt=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var it=(t,c,e)=>c in t?E(t,c,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[c]=e;var S=(t,c)=>()=>(c||t((c={exports:{}}).exports,c),c.exports);var st=(t,c,e,p)=>{if(c&&typeof c=="object"||typeof c=="function")for(let a of rt(c))!ot.call(t,a)&&a!==e&&E(t,a,{get:()=>c[a],enumerable:!(p=et(c,a))||p.enumerable});return t};var ct=(t,c,e)=>(e=t!=null?tt(nt(t)):{},st(c||!t||!t.__esModule?E(e,"default",{value:t,enumerable:!0}):e,t));var A=(t,c,e)=>(it(t,typeof c!="symbol"?c+"":c,e),e),M=(t,c,e)=>{if(!c.has(t))throw TypeError("Cannot "+e)};var w=(t,c,e)=>(M(t,c,"read from private field"),e?e.call(t):c.get(t)),I=(t,c,e)=>{if(c.has(t))throw TypeError("Cannot add the same private member more than once");c instanceof WeakSet?c.add(t):c.set(t,e)},_=(t,c,e,p)=>(M(t,c,"write to private field"),p?p.call(t,e):c.set(t,e),e),b=(t,c,e,p)=>({set _(a){_(t,c,a,e)},get _(){return w(t,c,p)}});var q=S((Kt,B)=>{(function(){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c={rotl:function(e,p){return e<<p|e>>>32-p},rotr:function(e,p){return e<<32-p|e>>>p},endian:function(e){if(e.constructor==Number)return c.rotl(e,8)&16711935|c.rotl(e,24)&4278255360;for(var p=0;p<e.length;p++)e[p]=c.endian(e[p]);return e},randomBytes:function(e){for(var p=[];e>0;e--)p.push(Math.floor(Math.random()*256));return p},bytesToWords:function(e){for(var p=[],a=0,f=0;a<e.length;a++,f+=8)p[f>>>5]|=e[a]<<24-f%32;return p},wordsToBytes:function(e){for(var p=[],a=0;a<e.length*32;a+=8)p.push(e[a>>>5]>>>24-a%32&255);return p},bytesToHex:function(e){for(var p=[],a=0;a<e.length;a++)p.push((e[a]>>>4).toString(16)),p.push((e[a]&15).toString(16));return p.join("")},hexToBytes:function(e){for(var p=[],a=0;a<e.length;a+=2)p.push(parseInt(e.substr(a,2),16));return p},bytesToBase64:function(e){for(var p=[],a=0;a<e.length;a+=3)for(var f=e[a]<<16|e[a+1]<<8|e[a+2],l=0;l<4;l++)a*8+l*6<=e.length*8?p.push(t.charAt(f>>>6*(3-l)&63)):p.push("=");return p.join("")},base64ToBytes:function(e){e=e.replace(/[^A-Z0-9+\/]/ig,"");for(var p=[],a=0,f=0;a<e.length;f=++a%4)f!=0&&p.push((t.indexOf(e.charAt(a-1))&Math.pow(2,-2*f+8)-1)<<f*2|t.indexOf(e.charAt(a))>>>6-f*2);return p}};B.exports=c})()});var R=S((te,D)=>{var O={utf8:{stringToBytes:function(t){return O.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(O.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var c=[],e=0;e<t.length;e++)c.push(t.charCodeAt(e)&255);return c},bytesToString:function(t){for(var c=[],e=0;e<t.length;e++)c.push(String.fromCharCode(t[e]));return c.join("")}}};D.exports=O});var $=S((ee,J)=>{J.exports=function(t){return t!=null&&(H(t)||xt(t)||!!t._isBuffer)};function H(t){return!!t.constructor&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}function xt(t){return typeof t.readFloatLE=="function"&&typeof t.slice=="function"&&H(t.slice(0,0))}});var Y=S((re,z)=>{(function(){var t=q(),c=R().utf8,e=$(),p=R().bin,a=function(f,l){f.constructor==String?l&&l.encoding==="binary"?f=p.stringToBytes(f):f=c.stringToBytes(f):e(f)?f=Array.prototype.slice.call(f,0):!Array.isArray(f)&&f.constructor!==Uint8Array&&(f=f.toString());for(var s=t.bytesToWords(f),h=f.length*8,r=1732584193,n=-271733879,i=-1732584194,o=271733878,u=0;u<s.length;u++)s[u]=(s[u]<<8|s[u]>>>24)&16711935|(s[u]<<24|s[u]>>>8)&4278255360;s[h>>>5]|=128<<h%32,s[(h+64>>>9<<4)+14]=h;for(var m=a._ff,d=a._gg,g=a._hh,y=a._ii,u=0;u<s.length;u+=16){var Q=r,X=n,Z=i,K=o;r=m(r,n,i,o,s[u+0],7,-680876936),o=m(o,r,n,i,s[u+1],12,-389564586),i=m(i,o,r,n,s[u+2],17,606105819),n=m(n,i,o,r,s[u+3],22,-1044525330),r=m(r,n,i,o,s[u+4],7,-176418897),o=m(o,r,n,i,s[u+5],12,1200080426),i=m(i,o,r,n,s[u+6],17,-1473231341),n=m(n,i,o,r,s[u+7],22,-45705983),r=m(r,n,i,o,s[u+8],7,1770035416),o=m(o,r,n,i,s[u+9],12,-1958414417),i=m(i,o,r,n,s[u+10],17,-42063),n=m(n,i,o,r,s[u+11],22,-1990404162),r=m(r,n,i,o,s[u+12],7,1804603682),o=m(o,r,n,i,s[u+13],12,-40341101),i=m(i,o,r,n,s[u+14],17,-1502002290),n=m(n,i,o,r,s[u+15],22,1236535329),r=d(r,n,i,o,s[u+1],5,-165796510),o=d(o,r,n,i,s[u+6],9,-1069501632),i=d(i,o,r,n,s[u+11],14,643717713),n=d(n,i,o,r,s[u+0],20,-373897302),r=d(r,n,i,o,s[u+5],5,-701558691),o=d(o,r,n,i,s[u+10],9,38016083),i=d(i,o,r,n,s[u+15],14,-660478335),n=d(n,i,o,r,s[u+4],20,-405537848),r=d(r,n,i,o,s[u+9],5,568446438),o=d(o,r,n,i,s[u+14],9,-1019803690),i=d(i,o,r,n,s[u+3],14,-187363961),n=d(n,i,o,r,s[u+8],20,1163531501),r=d(r,n,i,o,s[u+13],5,-1444681467),o=d(o,r,n,i,s[u+2],9,-51403784),i=d(i,o,r,n,s[u+7],14,1735328473),n=d(n,i,o,r,s[u+12],20,-1926607734),r=g(r,n,i,o,s[u+5],4,-378558),o=g(o,r,n,i,s[u+8],11,-2022574463),i=g(i,o,r,n,s[u+11],16,1839030562),n=g(n,i,o,r,s[u+14],23,-35309556),r=g(r,n,i,o,s[u+1],4,-1530992060),o=g(o,r,n,i,s[u+4],11,1272893353),i=g(i,o,r,n,s[u+7],16,-155497632),n=g(n,i,o,r,s[u+10],23,-1094730640),r=g(r,n,i,o,s[u+13],4,681279174),o=g(o,r,n,i,s[u+0],11,-358537222),i=g(i,o,r,n,s[u+3],16,-722521979),n=g(n,i,o,r,s[u+6],23,76029189),r=g(r,n,i,o,s[u+9],4,-640364487),o=g(o,r,n,i,s[u+12],11,-421815835),i=g(i,o,r,n,s[u+15],16,530742520),n=g(n,i,o,r,s[u+2],23,-995338651),r=y(r,n,i,o,s[u+0],6,-198630844),o=y(o,r,n,i,s[u+7],10,1126891415),i=y(i,o,r,n,s[u+14],15,-1416354905),n=y(n,i,o,r,s[u+5],21,-57434055),r=y(r,n,i,o,s[u+12],6,1700485571),o=y(o,r,n,i,s[u+3],10,-1894986606),i=y(i,o,r,n,s[u+10],15,-1051523),n=y(n,i,o,r,s[u+1],21,-2054922799),r=y(r,n,i,o,s[u+8],6,1873313359),o=y(o,r,n,i,s[u+15],10,-30611744),i=y(i,o,r,n,s[u+6],15,-1560198380),n=y(n,i,o,r,s[u+13],21,1309151649),r=y(r,n,i,o,s[u+4],6,-145523070),o=y(o,r,n,i,s[u+11],10,-1120210379),i=y(i,o,r,n,s[u+2],15,718787259),n=y(n,i,o,r,s[u+9],21,-343485551),r=r+Q>>>0,n=n+X>>>0,i=i+Z>>>0,o=o+K>>>0}return t.endian([r,n,i,o])};a._ff=function(f,l,s,h,r,n,i){var o=f+(l&s|~l&h)+(r>>>0)+i;return(o<<n|o>>>32-n)+l},a._gg=function(f,l,s,h,r,n,i){var o=f+(l&h|s&~h)+(r>>>0)+i;return(o<<n|o>>>32-n)+l},a._hh=function(f,l,s,h,r,n,i){var o=f+(l^s^h)+(r>>>0)+i;return(o<<n|o>>>32-n)+l},a._ii=function(f,l,s,h,r,n,i){var o=f+(s^(l|~h))+(r>>>0)+i;return(o<<n|o>>>32-n)+l},a._blocksize=16,a._digestsize=16,z.exports=function(f,l){if(f==null)throw new Error("Illegal argument "+f);var s=t.wordsToBytes(a(f,l));return l&&l.asBytes?s:l&&l.asString?p.bytesToString(s):t.bytesToHex(s)}})()});import{dirname as wt}from"path";import{fileURLToPath as vt}from"url";import{execSync as j}from"child_process";import F from"path";import{fileURLToPath as mt}from"url";import ut from"process";import at from"path";import k,{promises as qt}from"fs";import{fileURLToPath as pt}from"url";var P=class{constructor(c){A(this,"value");A(this,"next");this.value=c}},x,v,T,N=class{constructor(){I(this,x,void 0);I(this,v,void 0);I(this,T,void 0);this.clear()}enqueue(c){let e=new P(c);w(this,x)?(w(this,v).next=e,_(this,v,e)):(_(this,x,e),_(this,v,e)),b(this,T)._++}dequeue(){let c=w(this,x);if(c)return _(this,x,w(this,x).next),b(this,T)._--,c.value}clear(){_(this,x,void 0),_(this,v,void 0),_(this,T,0)}get size(){return w(this,T)}*[Symbol.iterator](){let c=w(this,x);for(;c;)yield c.value,c=c.next}};x=new WeakMap,v=new WeakMap,T=new WeakMap;var U={directory:"isDirectory",file:"isFile"};function ft(t){if(!Object.hasOwnProperty.call(U,t))throw new Error(`Invalid type specified: ${t}`)}var lt=(t,c)=>c[U[t]](),ht=t=>t instanceof URL?pt(t):t;function V(t,{cwd:c=ut.cwd(),type:e="file",allowSymlinks:p=!0}={}){ft(e),c=ht(c);let a=p?k.statSync:k.lstatSync;for(let f of t)try{let l=a(at.resolve(c,f),{throwIfNoEntry:!1});if(!l)continue;if(lt(e,l))return f}catch{}}var dt=t=>t instanceof URL?mt(t):t,gt=Symbol("findUpStop");function yt(t,c={}){let e=F.resolve(dt(c.cwd)||""),{root:p}=F.parse(e),a=c.stopAt||p,f=c.limit||Number.POSITIVE_INFINITY,l=[t].flat(),s=r=>{if(typeof t!="function")return V(l,r);let n=t(r.cwd);return typeof n=="string"?V([n],r):n},h=[];for(;;){let r=s({...c,cwd:e});if(r===gt||(r&&h.push(F.resolve(e,r)),e===a||h.length>=f))break;e=F.dirname(e)}return h}function C(t,c={}){return yt(t,{...c,limit:1})[0]}var W=ct(Y(),1);var G="@plugin-web-update/core";var oe="pluginWebUpdateNotice",ie="web_version_by_plugin",se="webUpdateNoticeInjectStyle",ce="webUpdateNoticeInjectScript.global",ue="plugin_web_update_notice",ae="plugin-web-update-notice-anchor",pe="plugin-web-update-notice-refresh-btn",fe="plugin-web-update-notice-dismiss-btn",le="web_update_check_dismiss_version_",he={topLeft:"top: 24px;left: 24px",topRight:"top: 24px;right: 24px",bottomLeft:"bottom: 24px;left: 24px",bottomRight:"bottom: 24px;right: 24px"};var we=G;function ve(){try{return import.meta&&import.meta.url?wt(vt(import.meta.url)):__dirname}catch{return __dirname}}function Te(t){return(0,W.default)(t).slice(0,8)}function Tt(){return C(".git",{type:"directory"})?"Git":C(".svn",{type:"directory"})?"SVN":"unknown"}function St(){try{return process.env.npm_package_version}catch(t){throw console.warn(` ====================================================== [plugin-web-update-notice] cannot get the version of the host project's package.json file! ======================================================`),t}}function It(){try{return j("git rev-parse --short HEAD").toString().replace(` `,"").trim()}catch(t){throw console.warn(` ====================================================== [plugin-web-update-notice] Not a git repository! ======================================================`),t}}function Nt(){try{return j("svnversion").toString().replace(` `,"").trim()}catch(t){throw console.warn(` ====================================================== [plugin-web-update-notice] Not a SVN repository! ======================================================`),t}}function L(){return`${Date.now()}`}function Ft(t){if(!t)throw console.warn(` ====================================================== [plugin-web-update-notice] The versionType is 'custom', but the customVersion is not specified! ======================================================`),new Error("The versionType is 'custom', but the customVersion is not specified!");return t}function Se(t,c){let e={pkg_version:St,git_commit_hash:It,build_timestamp:L,custom:()=>Ft(c),svn_revision_number:Nt},a=t||{Git:"git_commit_hash",SVN:"svn_revision_number",unknown:""}[Tt()];try{let f=e[a];return f?f():(console.warn(` ====================================================== [plugin-web-update-notice] The version type '${t}' is not supported!, we will use the packaging timestamp instead. ======================================================`),L())}catch(f){return console.warn(` ====================================================== [plugin-web-update-notice] get version throw a error, we will use the packaging timestamp instead. ======================================================`),console.error(f),L()}}function Ie(t,c=!1){let e={version:t};return c&&(e.silence=!0),JSON.stringify(e,null,2)}function Ne(t,c,e){let{logVersion:p=!0}=e,a=`${t} window.__checkUpdateSetup__(${JSON.stringify(e)});`;return p&&(a+=` ;const logFn = ${(typeof p=="function"?p:Et).toString()} ;logFn('${c}', ${Date.now()}) `),a}function Et(t,c){console.log(`version: %c${t}`,"color: #1677ff"),console.log(`release time: %c${new Date(c).toLocaleString()}`,"color: #1677ff")}export{ue as CUSTOM_UPDATE_EVENT_NAME,oe as DIRECTORY_NAME,ce as INJECT_SCRIPT_FILE_NAME,se as INJECT_STYLE_FILE_NAME,ie as JSON_FILE_NAME,le as LOCAL_STORAGE_PREFIX,ae as NOTIFICATION_ANCHOR_CLASS_NAME,fe as NOTIFICATION_DISMISS_BTN_CLASS_NAME,he as NOTIFICATION_POSITION_MAP,pe as NOTIFICATION_REFRESH_BTN_CLASS_NAME,Ie as generateJSONFileContent,Ne as generateJsFileContent,Ft as getCustomVersion,Te as getFileHash,It as getGitCommitHash,St as getHostProjectPkgVersion,Nt as getSVNRevisionNumber,L as getTimestamp,Se as getVersion,ve as get__Dirname,Et as logVersionDefault,we as pkgName}; /*! Bundled license information: is-buffer/index.js: (*! * Determine if an object is a Buffer * * @author Feross Aboukhadijeh <https://feross.org> * @license MIT *) */ //# sourceMappingURL=index.js.map