diff --git a/.babelrc.js b/.babelrc.js index c77ebd6..1977f41 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -7,13 +7,13 @@ export default { '@babel/preset-env', { targets: { - ie: 11 + ie: 11, }, loose: true, - modules: cjs ? 'cjs' : false - } + modules: cjs ? 'cjs' : false, + }, ], - '@babel/preset-typescript' + '@babel/preset-typescript', ], - plugins: [cjs && ['@babel/transform-modules-commonjs']].filter(Boolean) + plugins: [cjs && ['@babel/transform-modules-commonjs']].filter(Boolean), } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6aa63e..26b4396 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -98,7 +98,7 @@ jobs: 'node-standard', 'node-esm', 'react-native', - 'expo' + 'expo', ] steps: - name: Checkout repo diff --git a/.yarn/releases/yarn-4.1.0.cjs b/.yarn/releases/yarn-4.1.0.cjs index 738adce..63ad2d2 100644 --- a/.yarn/releases/yarn-4.1.0.cjs +++ b/.yarn/releases/yarn-4.1.0.cjs @@ -1,7 +1,7 @@ #!/usr/bin/env node /* eslint-disable */ //prettier-ignore -(()=>{var Z3e=Object.create;var NR=Object.defineProperty;var $3e=Object.getOwnPropertyDescriptor;var e_e=Object.getOwnPropertyNames;var t_e=Object.getPrototypeOf,r_e=Object.prototype.hasOwnProperty;var ve=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var Et=(t,e)=>()=>(t&&(e=t(t=0)),e);var _=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Vt=(t,e)=>{for(var r in e)NR(t,r,{get:e[r],enumerable:!0})},n_e=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of e_e(e))!r_e.call(t,a)&&a!==r&&NR(t,a,{get:()=>e[a],enumerable:!(o=$3e(e,a))||o.enumerable});return t};var $e=(t,e,r)=>(r=t!=null?Z3e(t_e(t)):{},n_e(e||!t||!t.__esModule?NR(r,"default",{value:t,enumerable:!0}):r,t));var vi={};Vt(vi,{SAFE_TIME:()=>x7,S_IFDIR:()=>wD,S_IFLNK:()=>ID,S_IFMT:()=>Ou,S_IFREG:()=>jw});var Ou,wD,jw,ID,x7,k7=Et(()=>{Ou=61440,wD=16384,jw=32768,ID=40960,x7=456789e3});var ar={};Vt(ar,{EBADF:()=>Io,EBUSY:()=>i_e,EEXIST:()=>u_e,EINVAL:()=>o_e,EISDIR:()=>c_e,ENOENT:()=>a_e,ENOSYS:()=>s_e,ENOTDIR:()=>l_e,ENOTEMPTY:()=>f_e,EOPNOTSUPP:()=>p_e,EROFS:()=>A_e,ERR_DIR_CLOSED:()=>LR});function Tl(t,e){return Object.assign(new Error(`${t}: ${e}`),{code:t})}function i_e(t){return Tl("EBUSY",t)}function s_e(t,e){return Tl("ENOSYS",`${t}, ${e}`)}function o_e(t){return Tl("EINVAL",`invalid argument, ${t}`)}function Io(t){return Tl("EBADF",`bad file descriptor, ${t}`)}function a_e(t){return Tl("ENOENT",`no such file or directory, ${t}`)}function l_e(t){return Tl("ENOTDIR",`not a directory, ${t}`)}function c_e(t){return Tl("EISDIR",`illegal operation on a directory, ${t}`)}function u_e(t){return Tl("EEXIST",`file already exists, ${t}`)}function A_e(t){return Tl("EROFS",`read-only filesystem, ${t}`)}function f_e(t){return Tl("ENOTEMPTY",`directory not empty, ${t}`)}function p_e(t){return Tl("EOPNOTSUPP",`operation not supported, ${t}`)}function LR(){return Tl("ERR_DIR_CLOSED","Directory handle was closed")}var BD=Et(()=>{});var Ea={};Vt(Ea,{BigIntStatsEntry:()=>ty,DEFAULT_MODE:()=>UR,DirEntry:()=>OR,StatEntry:()=>ey,areStatsEqual:()=>_R,clearStats:()=>vD,convertToBigIntStats:()=>g_e,makeDefaultStats:()=>Q7,makeEmptyStats:()=>h_e});function Q7(){return new ey}function h_e(){return vD(Q7())}function vD(t){for(let e in t)if(Object.hasOwn(t,e)){let r=t[e];typeof r=="number"?t[e]=0:typeof r=="bigint"?t[e]=BigInt(0):MR.types.isDate(r)&&(t[e]=new Date(0))}return t}function g_e(t){let e=new ty;for(let r in t)if(Object.hasOwn(t,r)){let o=t[r];typeof o=="number"?e[r]=BigInt(o):MR.types.isDate(o)&&(e[r]=new Date(o))}return e.atimeNs=e.atimeMs*BigInt(1e6),e.mtimeNs=e.mtimeMs*BigInt(1e6),e.ctimeNs=e.ctimeMs*BigInt(1e6),e.birthtimeNs=e.birthtimeMs*BigInt(1e6),e}function _R(t,e){if(t.atimeMs!==e.atimeMs||t.birthtimeMs!==e.birthtimeMs||t.blksize!==e.blksize||t.blocks!==e.blocks||t.ctimeMs!==e.ctimeMs||t.dev!==e.dev||t.gid!==e.gid||t.ino!==e.ino||t.isBlockDevice()!==e.isBlockDevice()||t.isCharacterDevice()!==e.isCharacterDevice()||t.isDirectory()!==e.isDirectory()||t.isFIFO()!==e.isFIFO()||t.isFile()!==e.isFile()||t.isSocket()!==e.isSocket()||t.isSymbolicLink()!==e.isSymbolicLink()||t.mode!==e.mode||t.mtimeMs!==e.mtimeMs||t.nlink!==e.nlink||t.rdev!==e.rdev||t.size!==e.size||t.uid!==e.uid)return!1;let r=t,o=e;return!(r.atimeNs!==o.atimeNs||r.mtimeNs!==o.mtimeNs||r.ctimeNs!==o.ctimeNs||r.birthtimeNs!==o.birthtimeNs)}var MR,UR,OR,ey,ty,HR=Et(()=>{MR=$e(ve("util")),UR=33188,OR=class{constructor(){this.name="";this.path="";this.mode=0}isBlockDevice(){return!1}isCharacterDevice(){return!1}isDirectory(){return(this.mode&61440)===16384}isFIFO(){return!1}isFile(){return(this.mode&61440)===32768}isSocket(){return!1}isSymbolicLink(){return(this.mode&61440)===40960}},ey=class{constructor(){this.uid=0;this.gid=0;this.size=0;this.blksize=0;this.atimeMs=0;this.mtimeMs=0;this.ctimeMs=0;this.birthtimeMs=0;this.atime=new Date(0);this.mtime=new Date(0);this.ctime=new Date(0);this.birthtime=new Date(0);this.dev=0;this.ino=0;this.mode=UR;this.nlink=1;this.rdev=0;this.blocks=1}isBlockDevice(){return!1}isCharacterDevice(){return!1}isDirectory(){return(this.mode&61440)===16384}isFIFO(){return!1}isFile(){return(this.mode&61440)===32768}isSocket(){return!1}isSymbolicLink(){return(this.mode&61440)===40960}},ty=class{constructor(){this.uid=BigInt(0);this.gid=BigInt(0);this.size=BigInt(0);this.blksize=BigInt(0);this.atimeMs=BigInt(0);this.mtimeMs=BigInt(0);this.ctimeMs=BigInt(0);this.birthtimeMs=BigInt(0);this.atimeNs=BigInt(0);this.mtimeNs=BigInt(0);this.ctimeNs=BigInt(0);this.birthtimeNs=BigInt(0);this.atime=new Date(0);this.mtime=new Date(0);this.ctime=new Date(0);this.birthtime=new Date(0);this.dev=BigInt(0);this.ino=BigInt(0);this.mode=BigInt(UR);this.nlink=BigInt(1);this.rdev=BigInt(0);this.blocks=BigInt(1)}isBlockDevice(){return!1}isCharacterDevice(){return!1}isDirectory(){return(this.mode&BigInt(61440))===BigInt(16384)}isFIFO(){return!1}isFile(){return(this.mode&BigInt(61440))===BigInt(32768)}isSocket(){return!1}isSymbolicLink(){return(this.mode&BigInt(61440))===BigInt(40960)}}});function C_e(t){let e,r;if(e=t.match(y_e))t=e[1];else if(r=t.match(E_e))t=`\\\\${r[1]?".\\":""}${r[2]}`;else return t;return t.replace(/\//g,"\\")}function w_e(t){t=t.replace(/\\/g,"/");let e,r;return(e=t.match(d_e))?t=`/${e[1]}`:(r=t.match(m_e))&&(t=`/unc/${r[1]?".dot/":""}${r[2]}`),t}function DD(t,e){return t===ue?R7(e):jR(e)}var Gw,Bt,dr,ue,V,F7,d_e,m_e,y_e,E_e,jR,R7,Ca=Et(()=>{Gw=$e(ve("path")),Bt={root:"/",dot:".",parent:".."},dr={home:"~",nodeModules:"node_modules",manifest:"package.json",lockfile:"yarn.lock",virtual:"__virtual__",pnpJs:".pnp.js",pnpCjs:".pnp.cjs",pnpData:".pnp.data.json",pnpEsmLoader:".pnp.loader.mjs",rc:".yarnrc.yml",env:".env"},ue=Object.create(Gw.default),V=Object.create(Gw.default.posix);ue.cwd=()=>process.cwd();V.cwd=process.platform==="win32"?()=>jR(process.cwd()):process.cwd;process.platform==="win32"&&(V.resolve=(...t)=>t.length>0&&V.isAbsolute(t[0])?Gw.default.posix.resolve(...t):Gw.default.posix.resolve(V.cwd(),...t));F7=function(t,e,r){return e=t.normalize(e),r=t.normalize(r),e===r?".":(e.endsWith(t.sep)||(e=e+t.sep),r.startsWith(e)?r.slice(e.length):null)};ue.contains=(t,e)=>F7(ue,t,e);V.contains=(t,e)=>F7(V,t,e);d_e=/^([a-zA-Z]:.*)$/,m_e=/^\/\/(\.\/)?(.*)$/,y_e=/^\/([a-zA-Z]:.*)$/,E_e=/^\/unc\/(\.dot\/)?(.*)$/;jR=process.platform==="win32"?w_e:t=>t,R7=process.platform==="win32"?C_e:t=>t;ue.fromPortablePath=R7;ue.toPortablePath=jR});async function SD(t,e){let r="0123456789abcdef";await t.mkdirPromise(e.indexPath,{recursive:!0});let o=[];for(let a of r)for(let n of r)o.push(t.mkdirPromise(t.pathUtils.join(e.indexPath,`${a}${n}`),{recursive:!0}));return await Promise.all(o),e.indexPath}async function T7(t,e,r,o,a){let n=t.pathUtils.normalize(e),u=r.pathUtils.normalize(o),A=[],p=[],{atime:h,mtime:E}=a.stableTime?{atime:Og,mtime:Og}:await r.lstatPromise(u);await t.mkdirpPromise(t.pathUtils.dirname(e),{utimes:[h,E]}),await GR(A,p,t,n,r,u,{...a,didParentExist:!0});for(let I of A)await I();await Promise.all(p.map(I=>I()))}async function GR(t,e,r,o,a,n,u){let A=u.didParentExist?await N7(r,o):null,p=await a.lstatPromise(n),{atime:h,mtime:E}=u.stableTime?{atime:Og,mtime:Og}:p,I;switch(!0){case p.isDirectory():I=await B_e(t,e,r,o,A,a,n,p,u);break;case p.isFile():I=await S_e(t,e,r,o,A,a,n,p,u);break;case p.isSymbolicLink():I=await P_e(t,e,r,o,A,a,n,p,u);break;default:throw new Error(`Unsupported file type (${p.mode})`)}return(u.linkStrategy?.type!=="HardlinkFromIndex"||!p.isFile())&&((I||A?.mtime?.getTime()!==E.getTime()||A?.atime?.getTime()!==h.getTime())&&(e.push(()=>r.lutimesPromise(o,h,E)),I=!0),(A===null||(A.mode&511)!==(p.mode&511))&&(e.push(()=>r.chmodPromise(o,p.mode&511)),I=!0)),I}async function N7(t,e){try{return await t.lstatPromise(e)}catch{return null}}async function B_e(t,e,r,o,a,n,u,A,p){if(a!==null&&!a.isDirectory())if(p.overwrite)t.push(async()=>r.removePromise(o)),a=null;else return!1;let h=!1;a===null&&(t.push(async()=>{try{await r.mkdirPromise(o,{mode:A.mode})}catch(v){if(v.code!=="EEXIST")throw v}}),h=!0);let E=await n.readdirPromise(u),I=p.didParentExist&&!a?{...p,didParentExist:!1}:p;if(p.stableSort)for(let v of E.sort())await GR(t,e,r,r.pathUtils.join(o,v),n,n.pathUtils.join(u,v),I)&&(h=!0);else(await Promise.all(E.map(async x=>{await GR(t,e,r,r.pathUtils.join(o,x),n,n.pathUtils.join(u,x),I)}))).some(x=>x)&&(h=!0);return h}async function v_e(t,e,r,o,a,n,u,A,p,h){let E=await n.checksumFilePromise(u,{algorithm:"sha1"}),I=420,v=A.mode&511,x=`${E}${v!==I?v.toString(8):""}`,C=r.pathUtils.join(h.indexPath,E.slice(0,2),`${x}.dat`),R;(ce=>(ce[ce.Lock=0]="Lock",ce[ce.Rename=1]="Rename"))(R||={});let L=1,U=await N7(r,C);if(a){let ae=U&&a.dev===U.dev&&a.ino===U.ino,fe=U?.mtimeMs!==I_e;if(ae&&fe&&h.autoRepair&&(L=0,U=null),!ae)if(p.overwrite)t.push(async()=>r.removePromise(o)),a=null;else return!1}let J=!U&&L===1?`${C}.${Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0")}`:null,te=!1;return t.push(async()=>{if(!U&&(L===0&&await r.lockPromise(C,async()=>{let ae=await n.readFilePromise(u);await r.writeFilePromise(C,ae)}),L===1&&J)){let ae=await n.readFilePromise(u);await r.writeFilePromise(J,ae);try{await r.linkPromise(J,C)}catch(fe){if(fe.code==="EEXIST")te=!0,await r.unlinkPromise(J);else throw fe}}a||await r.linkPromise(C,o)}),e.push(async()=>{U||(await r.lutimesPromise(C,Og,Og),v!==I&&await r.chmodPromise(C,v)),J&&!te&&await r.unlinkPromise(J)}),!1}async function D_e(t,e,r,o,a,n,u,A,p){if(a!==null)if(p.overwrite)t.push(async()=>r.removePromise(o)),a=null;else return!1;return t.push(async()=>{let h=await n.readFilePromise(u);await r.writeFilePromise(o,h)}),!0}async function S_e(t,e,r,o,a,n,u,A,p){return p.linkStrategy?.type==="HardlinkFromIndex"?v_e(t,e,r,o,a,n,u,A,p,p.linkStrategy):D_e(t,e,r,o,a,n,u,A,p)}async function P_e(t,e,r,o,a,n,u,A,p){if(a!==null)if(p.overwrite)t.push(async()=>r.removePromise(o)),a=null;else return!1;return t.push(async()=>{await r.symlinkPromise(DD(r.pathUtils,await n.readlinkPromise(u)),o)}),!0}var Og,I_e,qR=Et(()=>{Ca();Og=new Date(456789e3*1e3),I_e=Og.getTime()});function PD(t,e,r,o){let a=()=>{let n=r.shift();if(typeof n>"u")return null;let u=t.pathUtils.join(e,n);return Object.assign(t.statSync(u),{name:n,path:void 0})};return new qw(e,a,o)}var qw,L7=Et(()=>{BD();qw=class{constructor(e,r,o={}){this.path=e;this.nextDirent=r;this.opts=o;this.closed=!1}throwIfClosed(){if(this.closed)throw LR()}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.read())!==null;)yield e}finally{await this.close()}}read(e){let r=this.readSync();return typeof e<"u"?e(null,r):Promise.resolve(r)}readSync(){return this.throwIfClosed(),this.nextDirent()}close(e){return this.closeSync(),typeof e<"u"?e(null):Promise.resolve()}closeSync(){this.throwIfClosed(),this.opts.onClose?.(),this.closed=!0}}});function O7(t,e){if(t!==e)throw new Error(`Invalid StatWatcher status: expected '${e}', got '${t}'`)}var M7,ry,U7=Et(()=>{M7=ve("events");HR();ry=class extends M7.EventEmitter{constructor(r,o,{bigint:a=!1}={}){super();this.status="ready";this.changeListeners=new Map;this.startTimeout=null;this.fakeFs=r,this.path=o,this.bigint=a,this.lastStats=this.stat()}static create(r,o,a){let n=new ry(r,o,a);return n.start(),n}start(){O7(this.status,"ready"),this.status="running",this.startTimeout=setTimeout(()=>{this.startTimeout=null,this.fakeFs.existsSync(this.path)||this.emit("change",this.lastStats,this.lastStats)},3)}stop(){O7(this.status,"running"),this.status="stopped",this.startTimeout!==null&&(clearTimeout(this.startTimeout),this.startTimeout=null),this.emit("stop")}stat(){try{return this.fakeFs.statSync(this.path,{bigint:this.bigint})}catch{let o=this.bigint?new ty:new ey;return vD(o)}}makeInterval(r){let o=setInterval(()=>{let a=this.stat(),n=this.lastStats;_R(a,n)||(this.lastStats=a,this.emit("change",a,n))},r.interval);return r.persistent?o:o.unref()}registerChangeListener(r,o){this.addListener("change",r),this.changeListeners.set(r,this.makeInterval(o))}unregisterChangeListener(r){this.removeListener("change",r);let o=this.changeListeners.get(r);typeof o<"u"&&clearInterval(o),this.changeListeners.delete(r)}unregisterAllChangeListeners(){for(let r of this.changeListeners.keys())this.unregisterChangeListener(r)}hasChangeListeners(){return this.changeListeners.size>0}ref(){for(let r of this.changeListeners.values())r.ref();return this}unref(){for(let r of this.changeListeners.values())r.unref();return this}}});function ny(t,e,r,o){let a,n,u,A;switch(typeof r){case"function":a=!1,n=!0,u=5007,A=r;break;default:({bigint:a=!1,persistent:n=!0,interval:u=5007}=r),A=o;break}let p=bD.get(t);typeof p>"u"&&bD.set(t,p=new Map);let h=p.get(e);return typeof h>"u"&&(h=ry.create(t,e,{bigint:a}),p.set(e,h)),h.registerChangeListener(A,{persistent:n,interval:u}),h}function Mg(t,e,r){let o=bD.get(t);if(typeof o>"u")return;let a=o.get(e);typeof a>"u"||(typeof r>"u"?a.unregisterAllChangeListeners():a.unregisterChangeListener(r),a.hasChangeListeners()||(a.stop(),o.delete(e)))}function Ug(t){let e=bD.get(t);if(!(typeof e>"u"))for(let r of e.keys())Mg(t,r)}var bD,YR=Et(()=>{U7();bD=new WeakMap});function b_e(t){let e=t.match(/\r?\n/g);if(e===null)return H7.EOL;let r=e.filter(a=>a===`\r +;(()=>{var Z3e=Object.create;var NR=Object.defineProperty;var $3e=Object.getOwnPropertyDescriptor;var e_e=Object.getOwnPropertyNames;var t_e=Object.getPrototypeOf,r_e=Object.prototype.hasOwnProperty;var ve=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var Et=(t,e)=>()=>(t&&(e=t(t=0)),e);var _=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Vt=(t,e)=>{for(var r in e)NR(t,r,{get:e[r],enumerable:!0})},n_e=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of e_e(e))!r_e.call(t,a)&&a!==r&&NR(t,a,{get:()=>e[a],enumerable:!(o=$3e(e,a))||o.enumerable});return t};var $e=(t,e,r)=>(r=t!=null?Z3e(t_e(t)):{},n_e(e||!t||!t.__esModule?NR(r,"default",{value:t,enumerable:!0}):r,t));var vi={};Vt(vi,{SAFE_TIME:()=>x7,S_IFDIR:()=>wD,S_IFLNK:()=>ID,S_IFMT:()=>Ou,S_IFREG:()=>jw});var Ou,wD,jw,ID,x7,k7=Et(()=>{Ou=61440,wD=16384,jw=32768,ID=40960,x7=456789e3});var ar={};Vt(ar,{EBADF:()=>Io,EBUSY:()=>i_e,EEXIST:()=>u_e,EINVAL:()=>o_e,EISDIR:()=>c_e,ENOENT:()=>a_e,ENOSYS:()=>s_e,ENOTDIR:()=>l_e,ENOTEMPTY:()=>f_e,EOPNOTSUPP:()=>p_e,EROFS:()=>A_e,ERR_DIR_CLOSED:()=>LR});function Tl(t,e){return Object.assign(new Error(`${t}: ${e}`),{code:t})}function i_e(t){return Tl("EBUSY",t)}function s_e(t,e){return Tl("ENOSYS",`${t}, ${e}`)}function o_e(t){return Tl("EINVAL",`invalid argument, ${t}`)}function Io(t){return Tl("EBADF",`bad file descriptor, ${t}`)}function a_e(t){return Tl("ENOENT",`no such file or directory, ${t}`)}function l_e(t){return Tl("ENOTDIR",`not a directory, ${t}`)}function c_e(t){return Tl("EISDIR",`illegal operation on a directory, ${t}`)}function u_e(t){return Tl("EEXIST",`file already exists, ${t}`)}function A_e(t){return Tl("EROFS",`read-only filesystem, ${t}`)}function f_e(t){return Tl("ENOTEMPTY",`directory not empty, ${t}`)}function p_e(t){return Tl("EOPNOTSUPP",`operation not supported, ${t}`)}function LR(){return Tl("ERR_DIR_CLOSED","Directory handle was closed")}var BD=Et(()=>{});var Ea={};Vt(Ea,{BigIntStatsEntry:()=>ty,DEFAULT_MODE:()=>UR,DirEntry:()=>OR,StatEntry:()=>ey,areStatsEqual:()=>_R,clearStats:()=>vD,convertToBigIntStats:()=>g_e,makeDefaultStats:()=>Q7,makeEmptyStats:()=>h_e});function Q7(){return new ey}function h_e(){return vD(Q7())}function vD(t){for(let e in t)if(Object.hasOwn(t,e)){let r=t[e];typeof r=="number"?t[e]=0:typeof r=="bigint"?t[e]=BigInt(0):MR.types.isDate(r)&&(t[e]=new Date(0))}return t}function g_e(t){let e=new ty;for(let r in t)if(Object.hasOwn(t,r)){let o=t[r];typeof o=="number"?e[r]=BigInt(o):MR.types.isDate(o)&&(e[r]=new Date(o))}return e.atimeNs=e.atimeMs*BigInt(1e6),e.mtimeNs=e.mtimeMs*BigInt(1e6),e.ctimeNs=e.ctimeMs*BigInt(1e6),e.birthtimeNs=e.birthtimeMs*BigInt(1e6),e}function _R(t,e){if(t.atimeMs!==e.atimeMs||t.birthtimeMs!==e.birthtimeMs||t.blksize!==e.blksize||t.blocks!==e.blocks||t.ctimeMs!==e.ctimeMs||t.dev!==e.dev||t.gid!==e.gid||t.ino!==e.ino||t.isBlockDevice()!==e.isBlockDevice()||t.isCharacterDevice()!==e.isCharacterDevice()||t.isDirectory()!==e.isDirectory()||t.isFIFO()!==e.isFIFO()||t.isFile()!==e.isFile()||t.isSocket()!==e.isSocket()||t.isSymbolicLink()!==e.isSymbolicLink()||t.mode!==e.mode||t.mtimeMs!==e.mtimeMs||t.nlink!==e.nlink||t.rdev!==e.rdev||t.size!==e.size||t.uid!==e.uid)return!1;let r=t,o=e;return!(r.atimeNs!==o.atimeNs||r.mtimeNs!==o.mtimeNs||r.ctimeNs!==o.ctimeNs||r.birthtimeNs!==o.birthtimeNs)}var MR,UR,OR,ey,ty,HR=Et(()=>{MR=$e(ve("util")),UR=33188,OR=class{constructor(){this.name="";this.path="";this.mode=0}isBlockDevice(){return!1}isCharacterDevice(){return!1}isDirectory(){return(this.mode&61440)===16384}isFIFO(){return!1}isFile(){return(this.mode&61440)===32768}isSocket(){return!1}isSymbolicLink(){return(this.mode&61440)===40960}},ey=class{constructor(){this.uid=0;this.gid=0;this.size=0;this.blksize=0;this.atimeMs=0;this.mtimeMs=0;this.ctimeMs=0;this.birthtimeMs=0;this.atime=new Date(0);this.mtime=new Date(0);this.ctime=new Date(0);this.birthtime=new Date(0);this.dev=0;this.ino=0;this.mode=UR;this.nlink=1;this.rdev=0;this.blocks=1}isBlockDevice(){return!1}isCharacterDevice(){return!1}isDirectory(){return(this.mode&61440)===16384}isFIFO(){return!1}isFile(){return(this.mode&61440)===32768}isSocket(){return!1}isSymbolicLink(){return(this.mode&61440)===40960}},ty=class{constructor(){this.uid=BigInt(0);this.gid=BigInt(0);this.size=BigInt(0);this.blksize=BigInt(0);this.atimeMs=BigInt(0);this.mtimeMs=BigInt(0);this.ctimeMs=BigInt(0);this.birthtimeMs=BigInt(0);this.atimeNs=BigInt(0);this.mtimeNs=BigInt(0);this.ctimeNs=BigInt(0);this.birthtimeNs=BigInt(0);this.atime=new Date(0);this.mtime=new Date(0);this.ctime=new Date(0);this.birthtime=new Date(0);this.dev=BigInt(0);this.ino=BigInt(0);this.mode=BigInt(UR);this.nlink=BigInt(1);this.rdev=BigInt(0);this.blocks=BigInt(1)}isBlockDevice(){return!1}isCharacterDevice(){return!1}isDirectory(){return(this.mode&BigInt(61440))===BigInt(16384)}isFIFO(){return!1}isFile(){return(this.mode&BigInt(61440))===BigInt(32768)}isSocket(){return!1}isSymbolicLink(){return(this.mode&BigInt(61440))===BigInt(40960)}}});function C_e(t){let e,r;if(e=t.match(y_e))t=e[1];else if(r=t.match(E_e))t=`\\\\${r[1]?".\\":""}${r[2]}`;else return t;return t.replace(/\//g,"\\")}function w_e(t){t=t.replace(/\\/g,"/");let e,r;return(e=t.match(d_e))?t=`/${e[1]}`:(r=t.match(m_e))&&(t=`/unc/${r[1]?".dot/":""}${r[2]}`),t}function DD(t,e){return t===ue?R7(e):jR(e)}var Gw,Bt,dr,ue,V,F7,d_e,m_e,y_e,E_e,jR,R7,Ca=Et(()=>{Gw=$e(ve("path")),Bt={root:"/",dot:".",parent:".."},dr={home:"~",nodeModules:"node_modules",manifest:"package.json",lockfile:"yarn.lock",virtual:"__virtual__",pnpJs:".pnp.js",pnpCjs:".pnp.cjs",pnpData:".pnp.data.json",pnpEsmLoader:".pnp.loader.mjs",rc:".yarnrc.yml",env:".env"},ue=Object.create(Gw.default),V=Object.create(Gw.default.posix);ue.cwd=()=>process.cwd();V.cwd=process.platform==="win32"?()=>jR(process.cwd()):process.cwd;process.platform==="win32"&&(V.resolve=(...t)=>t.length>0&&V.isAbsolute(t[0])?Gw.default.posix.resolve(...t):Gw.default.posix.resolve(V.cwd(),...t));F7=function(t,e,r){return e=t.normalize(e),r=t.normalize(r),e===r?".":(e.endsWith(t.sep)||(e=e+t.sep),r.startsWith(e)?r.slice(e.length):null)};ue.contains=(t,e)=>F7(ue,t,e);V.contains=(t,e)=>F7(V,t,e);d_e=/^([a-zA-Z]:.*)$/,m_e=/^\/\/(\.\/)?(.*)$/,y_e=/^\/([a-zA-Z]:.*)$/,E_e=/^\/unc\/(\.dot\/)?(.*)$/;jR=process.platform==="win32"?w_e:t=>t,R7=process.platform==="win32"?C_e:t=>t;ue.fromPortablePath=R7;ue.toPortablePath=jR});async function SD(t,e){let r="0123456789abcdef";await t.mkdirPromise(e.indexPath,{recursive:!0});let o=[];for(let a of r)for(let n of r)o.push(t.mkdirPromise(t.pathUtils.join(e.indexPath,`${a}${n}`),{recursive:!0}));return await Promise.all(o),e.indexPath}async function T7(t,e,r,o,a){let n=t.pathUtils.normalize(e),u=r.pathUtils.normalize(o),A=[],p=[],{atime:h,mtime:E}=a.stableTime?{atime:Og,mtime:Og}:await r.lstatPromise(u);await t.mkdirpPromise(t.pathUtils.dirname(e),{utimes:[h,E]}),await GR(A,p,t,n,r,u,{...a,didParentExist:!0});for(let I of A)await I();await Promise.all(p.map(I=>I()))}async function GR(t,e,r,o,a,n,u){let A=u.didParentExist?await N7(r,o):null,p=await a.lstatPromise(n),{atime:h,mtime:E}=u.stableTime?{atime:Og,mtime:Og}:p,I;switch(!0){case p.isDirectory():I=await B_e(t,e,r,o,A,a,n,p,u);break;case p.isFile():I=await S_e(t,e,r,o,A,a,n,p,u);break;case p.isSymbolicLink():I=await P_e(t,e,r,o,A,a,n,p,u);break;default:throw new Error(`Unsupported file type (${p.mode})`)}return(u.linkStrategy?.type!=="HardlinkFromIndex"||!p.isFile())&&((I||A?.mtime?.getTime()!==E.getTime()||A?.atime?.getTime()!==h.getTime())&&(e.push(()=>r.lutimesPromise(o,h,E)),I=!0),(A===null||(A.mode&511)!==(p.mode&511))&&(e.push(()=>r.chmodPromise(o,p.mode&511)),I=!0)),I}async function N7(t,e){try{return await t.lstatPromise(e)}catch{return null}}async function B_e(t,e,r,o,a,n,u,A,p){if(a!==null&&!a.isDirectory())if(p.overwrite)t.push(async()=>r.removePromise(o)),a=null;else return!1;let h=!1;a===null&&(t.push(async()=>{try{await r.mkdirPromise(o,{mode:A.mode})}catch(v){if(v.code!=="EEXIST")throw v}}),h=!0);let E=await n.readdirPromise(u),I=p.didParentExist&&!a?{...p,didParentExist:!1}:p;if(p.stableSort)for(let v of E.sort())await GR(t,e,r,r.pathUtils.join(o,v),n,n.pathUtils.join(u,v),I)&&(h=!0);else(await Promise.all(E.map(async x=>{await GR(t,e,r,r.pathUtils.join(o,x),n,n.pathUtils.join(u,x),I)}))).some(x=>x)&&(h=!0);return h}async function v_e(t,e,r,o,a,n,u,A,p,h){let E=await n.checksumFilePromise(u,{algorithm:"sha1"}),I=420,v=A.mode&511,x=`${E}${v!==I?v.toString(8):""}`,C=r.pathUtils.join(h.indexPath,E.slice(0,2),`${x}.dat`),R;(ce=>(ce[ce.Lock=0]="Lock",ce[ce.Rename=1]="Rename"))(R||={});let L=1,U=await N7(r,C);if(a){let ae=U&&a.dev===U.dev&&a.ino===U.ino,fe=U?.mtimeMs!==I_e;if(ae&&fe&&h.autoRepair&&(L=0,U=null),!ae)if(p.overwrite)t.push(async()=>r.removePromise(o)),a=null;else return!1}let J=!U&&L===1?`${C}.${Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0")}`:null,te=!1;return t.push(async()=>{if(!U&&(L===0&&await r.lockPromise(C,async()=>{let ae=await n.readFilePromise(u);await r.writeFilePromise(C,ae)}),L===1&&J)){let ae=await n.readFilePromise(u);await r.writeFilePromise(J,ae);try{await r.linkPromise(J,C)}catch(fe){if(fe.code==="EEXIST")te=!0,await r.unlinkPromise(J);else throw fe}}a||await r.linkPromise(C,o)}),e.push(async()=>{U||(await r.lutimesPromise(C,Og,Og),v!==I&&await r.chmodPromise(C,v)),J&&!te&&await r.unlinkPromise(J)}),!1}async function D_e(t,e,r,o,a,n,u,A,p){if(a!==null)if(p.overwrite)t.push(async()=>r.removePromise(o)),a=null;else return!1;return t.push(async()=>{let h=await n.readFilePromise(u);await r.writeFilePromise(o,h)}),!0}async function S_e(t,e,r,o,a,n,u,A,p){return p.linkStrategy?.type==="HardlinkFromIndex"?v_e(t,e,r,o,a,n,u,A,p,p.linkStrategy):D_e(t,e,r,o,a,n,u,A,p)}async function P_e(t,e,r,o,a,n,u,A,p){if(a!==null)if(p.overwrite)t.push(async()=>r.removePromise(o)),a=null;else return!1;return t.push(async()=>{await r.symlinkPromise(DD(r.pathUtils,await n.readlinkPromise(u)),o)}),!0}var Og,I_e,qR=Et(()=>{Ca();Og=new Date(456789e3*1e3),I_e=Og.getTime()});function PD(t,e,r,o){let a=()=>{let n=r.shift();if(typeof n>"u")return null;let u=t.pathUtils.join(e,n);return Object.assign(t.statSync(u),{name:n,path:void 0})};return new qw(e,a,o)}var qw,L7=Et(()=>{BD();qw=class{constructor(e,r,o={}){this.path=e;this.nextDirent=r;this.opts=o;this.closed=!1}throwIfClosed(){if(this.closed)throw LR()}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.read())!==null;)yield e}finally{await this.close()}}read(e){let r=this.readSync();return typeof e<"u"?e(null,r):Promise.resolve(r)}readSync(){return this.throwIfClosed(),this.nextDirent()}close(e){return this.closeSync(),typeof e<"u"?e(null):Promise.resolve()}closeSync(){this.throwIfClosed(),this.opts.onClose?.(),this.closed=!0}}});function O7(t,e){if(t!==e)throw new Error(`Invalid StatWatcher status: expected '${e}', got '${t}'`)}var M7,ry,U7=Et(()=>{M7=ve("events");HR();ry=class extends M7.EventEmitter{constructor(r,o,{bigint:a=!1}={}){super();this.status="ready";this.changeListeners=new Map;this.startTimeout=null;this.fakeFs=r,this.path=o,this.bigint=a,this.lastStats=this.stat()}static create(r,o,a){let n=new ry(r,o,a);return n.start(),n}start(){O7(this.status,"ready"),this.status="running",this.startTimeout=setTimeout(()=>{this.startTimeout=null,this.fakeFs.existsSync(this.path)||this.emit("change",this.lastStats,this.lastStats)},3)}stop(){O7(this.status,"running"),this.status="stopped",this.startTimeout!==null&&(clearTimeout(this.startTimeout),this.startTimeout=null),this.emit("stop")}stat(){try{return this.fakeFs.statSync(this.path,{bigint:this.bigint})}catch{let o=this.bigint?new ty:new ey;return vD(o)}}makeInterval(r){let o=setInterval(()=>{let a=this.stat(),n=this.lastStats;_R(a,n)||(this.lastStats=a,this.emit("change",a,n))},r.interval);return r.persistent?o:o.unref()}registerChangeListener(r,o){this.addListener("change",r),this.changeListeners.set(r,this.makeInterval(o))}unregisterChangeListener(r){this.removeListener("change",r);let o=this.changeListeners.get(r);typeof o<"u"&&clearInterval(o),this.changeListeners.delete(r)}unregisterAllChangeListeners(){for(let r of this.changeListeners.keys())this.unregisterChangeListener(r)}hasChangeListeners(){return this.changeListeners.size>0}ref(){for(let r of this.changeListeners.values())r.ref();return this}unref(){for(let r of this.changeListeners.values())r.unref();return this}}});function ny(t,e,r,o){let a,n,u,A;switch(typeof r){case"function":a=!1,n=!0,u=5007,A=r;break;default:({bigint:a=!1,persistent:n=!0,interval:u=5007}=r),A=o;break}let p=bD.get(t);typeof p>"u"&&bD.set(t,p=new Map);let h=p.get(e);return typeof h>"u"&&(h=ry.create(t,e,{bigint:a}),p.set(e,h)),h.registerChangeListener(A,{persistent:n,interval:u}),h}function Mg(t,e,r){let o=bD.get(t);if(typeof o>"u")return;let a=o.get(e);typeof a>"u"||(typeof r>"u"?a.unregisterAllChangeListeners():a.unregisterChangeListener(r),a.hasChangeListeners()||(a.stop(),o.delete(e)))}function Ug(t){let e=bD.get(t);if(!(typeof e>"u"))for(let r of e.keys())Mg(t,r)}var bD,YR=Et(()=>{U7();bD=new WeakMap});function b_e(t){let e=t.match(/\r?\n/g);if(e===null)return H7.EOL;let r=e.filter(a=>a===`\r `).length,o=e.length-r;return r>o?`\r `:` `}function _g(t,e){return e.replace(/\r?\n/g,b_e(t))}var _7,H7,gf,Mu,Hg=Et(()=>{_7=ve("crypto"),H7=ve("os");qR();Ca();gf=class{constructor(e){this.pathUtils=e}async*genTraversePromise(e,{stableSort:r=!1}={}){let o=[e];for(;o.length>0;){let a=o.shift();if((await this.lstatPromise(a)).isDirectory()){let u=await this.readdirPromise(a);if(r)for(let A of u.sort())o.push(this.pathUtils.join(a,A));else throw new Error("Not supported")}else yield a}}async checksumFilePromise(e,{algorithm:r="sha512"}={}){let o=await this.openPromise(e,"r");try{let n=Buffer.allocUnsafeSlow(65536),u=(0,_7.createHash)(r),A=0;for(;(A=await this.readPromise(o,n,0,65536))!==0;)u.update(A===65536?n:n.slice(0,A));return u.digest("hex")}finally{await this.closePromise(o)}}async removePromise(e,{recursive:r=!0,maxRetries:o=5}={}){let a;try{a=await this.lstatPromise(e)}catch(n){if(n.code==="ENOENT")return;throw n}if(a.isDirectory()){if(r){let n=await this.readdirPromise(e);await Promise.all(n.map(u=>this.removePromise(this.pathUtils.resolve(e,u))))}for(let n=0;n<=o;n++)try{await this.rmdirPromise(e);break}catch(u){if(u.code!=="EBUSY"&&u.code!=="ENOTEMPTY")throw u;nsetTimeout(A,n*100))}}else await this.unlinkPromise(e)}removeSync(e,{recursive:r=!0}={}){let o;try{o=this.lstatSync(e)}catch(a){if(a.code==="ENOENT")return;throw a}if(o.isDirectory()){if(r)for(let a of this.readdirSync(e))this.removeSync(this.pathUtils.resolve(e,a));this.rmdirSync(e)}else this.unlinkSync(e)}async mkdirpPromise(e,{chmod:r,utimes:o}={}){if(e=this.resolve(e),e===this.pathUtils.dirname(e))return;let a=e.split(this.pathUtils.sep),n;for(let u=2;u<=a.length;++u){let A=a.slice(0,u).join(this.pathUtils.sep);if(!this.existsSync(A)){try{await this.mkdirPromise(A)}catch(p){if(p.code==="EEXIST")continue;throw p}if(n??=A,r!=null&&await this.chmodPromise(A,r),o!=null)await this.utimesPromise(A,o[0],o[1]);else{let p=await this.statPromise(this.pathUtils.dirname(A));await this.utimesPromise(A,p.atime,p.mtime)}}}return n}mkdirpSync(e,{chmod:r,utimes:o}={}){if(e=this.resolve(e),e===this.pathUtils.dirname(e))return;let a=e.split(this.pathUtils.sep),n;for(let u=2;u<=a.length;++u){let A=a.slice(0,u).join(this.pathUtils.sep);if(!this.existsSync(A)){try{this.mkdirSync(A)}catch(p){if(p.code==="EEXIST")continue;throw p}if(n??=A,r!=null&&this.chmodSync(A,r),o!=null)this.utimesSync(A,o[0],o[1]);else{let p=this.statSync(this.pathUtils.dirname(A));this.utimesSync(A,p.atime,p.mtime)}}}return n}async copyPromise(e,r,{baseFs:o=this,overwrite:a=!0,stableSort:n=!1,stableTime:u=!1,linkStrategy:A=null}={}){return await T7(this,e,o,r,{overwrite:a,stableSort:n,stableTime:u,linkStrategy:A})}copySync(e,r,{baseFs:o=this,overwrite:a=!0}={}){let n=o.lstatSync(r),u=this.existsSync(e);if(n.isDirectory()){this.mkdirpSync(e);let p=o.readdirSync(r);for(let h of p)this.copySync(this.pathUtils.join(e,h),o.pathUtils.join(r,h),{baseFs:o,overwrite:a})}else if(n.isFile()){if(!u||a){u&&this.removeSync(e);let p=o.readFileSync(r);this.writeFileSync(e,p)}}else if(n.isSymbolicLink()){if(!u||a){u&&this.removeSync(e);let p=o.readlinkSync(r);this.symlinkSync(DD(this.pathUtils,p),e)}}else throw new Error(`Unsupported file type (file: ${r}, mode: 0o${n.mode.toString(8).padStart(6,"0")})`);let A=n.mode&511;this.chmodSync(e,A)}async changeFilePromise(e,r,o={}){return Buffer.isBuffer(r)?this.changeFileBufferPromise(e,r,o):this.changeFileTextPromise(e,r,o)}async changeFileBufferPromise(e,r,{mode:o}={}){let a=Buffer.alloc(0);try{a=await this.readFilePromise(e)}catch{}Buffer.compare(a,r)!==0&&await this.writeFilePromise(e,r,{mode:o})}async changeFileTextPromise(e,r,{automaticNewlines:o,mode:a}={}){let n="";try{n=await this.readFilePromise(e,"utf8")}catch{}let u=o?_g(n,r):r;n!==u&&await this.writeFilePromise(e,u,{mode:a})}changeFileSync(e,r,o={}){return Buffer.isBuffer(r)?this.changeFileBufferSync(e,r,o):this.changeFileTextSync(e,r,o)}changeFileBufferSync(e,r,{mode:o}={}){let a=Buffer.alloc(0);try{a=this.readFileSync(e)}catch{}Buffer.compare(a,r)!==0&&this.writeFileSync(e,r,{mode:o})}changeFileTextSync(e,r,{automaticNewlines:o=!1,mode:a}={}){let n="";try{n=this.readFileSync(e,"utf8")}catch{}let u=o?_g(n,r):r;n!==u&&this.writeFileSync(e,u,{mode:a})}async movePromise(e,r){try{await this.renamePromise(e,r)}catch(o){if(o.code==="EXDEV")await this.copyPromise(r,e),await this.removePromise(e);else throw o}}moveSync(e,r){try{this.renameSync(e,r)}catch(o){if(o.code==="EXDEV")this.copySync(r,e),this.removeSync(e);else throw o}}async lockPromise(e,r){let o=`${e}.flock`,a=1e3/60,n=Date.now(),u=null,A=async()=>{let p;try{[p]=await this.readJsonPromise(o)}catch{return Date.now()-n<500}try{return process.kill(p,0),!0}catch{return!1}};for(;u===null;)try{u=await this.openPromise(o,"wx")}catch(p){if(p.code==="EEXIST"){if(!await A())try{await this.unlinkPromise(o);continue}catch{}if(Date.now()-n<60*1e3)await new Promise(h=>setTimeout(h,a));else throw new Error(`Couldn't acquire a lock in a reasonable time (via ${o})`)}else throw p}await this.writePromise(u,JSON.stringify([process.pid]));try{return await r()}finally{try{await this.closePromise(u),await this.unlinkPromise(o)}catch{}}}async readJsonPromise(e){let r=await this.readFilePromise(e,"utf8");try{return JSON.parse(r)}catch(o){throw o.message+=` (in ${e})`,o}}readJsonSync(e){let r=this.readFileSync(e,"utf8");try{return JSON.parse(r)}catch(o){throw o.message+=` (in ${e})`,o}}async writeJsonPromise(e,r,{compact:o=!1}={}){let a=o?0:2;return await this.writeFilePromise(e,`${JSON.stringify(r,null,a)} diff --git a/README.md b/README.md index e3c5a3b..c09e789 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ import filtersReducer from './features/filters/filtersSlice' const store = configureStore({ reducer: { todos: todosReducer, - filters: filtersReducer - } + filters: filtersReducer, + }, }) // The thunk middleware was automatically added @@ -86,9 +86,9 @@ const store = configureStore({ middleware: getDefaultMiddleware => getDefaultMiddleware({ thunk: { - extraArgument: myCustomApiService - } - }) + extraArgument: myCustomApiService, + }, + }), }) // later @@ -110,10 +110,10 @@ const store = configureStore({ thunk: { extraArgument: { api: myCustomApiService, - otherValue: 42 - } - } - }) + otherValue: 42, + }, + }, + }), }) // later @@ -188,7 +188,7 @@ const INCREMENT_COUNTER = 'INCREMENT_COUNTER' function increment() { return { - type: INCREMENT_COUNTER + type: INCREMENT_COUNTER, } } @@ -264,7 +264,7 @@ function makeASandwich(forPerson, secretSauce) { return { type: 'MAKE_SANDWICH', forPerson, - secretSauce + secretSauce, } } @@ -273,14 +273,14 @@ function apologize(fromPerson, toPerson, error) { type: 'APOLOGIZE', fromPerson, toPerson, - error + error, } } function withdrawMoney(amount) { return { type: 'WITHDRAW', - amount + amount, } } @@ -302,7 +302,7 @@ function makeASandwichWithSecretSauce(forPerson) { return function (dispatch) { return fetchSecretSauce().then( sauce => dispatch(makeASandwich(forPerson, sauce)), - error => dispatch(apologize('The Sandwich Shop', forPerson, error)) + error => dispatch(apologize('The Sandwich Shop', forPerson, error)), ) } } @@ -339,16 +339,16 @@ function makeSandwichesForEverybody() { .then(() => Promise.all([ dispatch(makeASandwichWithSecretSauce('Me')), - dispatch(makeASandwichWithSecretSauce('My wife')) - ]) + dispatch(makeASandwichWithSecretSauce('My wife')), + ]), ) .then(() => dispatch(makeASandwichWithSecretSauce('Our kids'))) .then(() => dispatch( getState().myMoney > 42 ? withdrawMoney(42) - : apologize('Me', 'The Sandwich Shop') - ) + : apologize('Me', 'The Sandwich Shop'), + ), ) } } @@ -359,7 +359,7 @@ function makeSandwichesForEverybody() { store .dispatch(makeSandwichesForEverybody()) .then(() => - response.send(ReactDOMServer.renderToString()) + response.send(ReactDOMServer.renderToString()), ) // I can also dispatch a thunk async action from a component @@ -385,7 +385,7 @@ class SandwichShop extends Component { } export default connect(state => ({ - sandwiches: state.sandwiches + sandwiches: state.sandwiches, }))(SandwichShop) ``` diff --git a/src/index.ts b/src/index.ts index 58bab3d..f925288 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ export type { ThunkAction, ThunkDispatch, ThunkActionDispatch, - ThunkMiddleware + ThunkMiddleware, } from './types' /** A function that accepts a potential "extra argument" value to be injected later, @@ -15,7 +15,7 @@ export type { function createThunkMiddleware< State = any, BasicAction extends Action = AnyAction, - ExtraThunkArg = undefined + ExtraThunkArg = undefined, >(extraArgument?: ExtraThunkArg) { // Standard Redux middleware definition pattern: // See: https://redux.js.org/tutorials/fundamentals/part-4-store#writing-custom-middleware diff --git a/src/types.ts b/src/types.ts index 973e4ac..41a01c7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,14 +14,14 @@ import type { Action, AnyAction, Middleware } from 'redux' export interface ThunkDispatch< State, ExtraThunkArg, - BasicAction extends Action + BasicAction extends Action, > { // When the thunk middleware is added, `store.dispatch` now has three overloads (NOTE: the order here matters for correct behavior and is very fragile - do not reorder these!): // 1) The specific thunk function overload /** Accepts a thunk function, runs it, and returns whatever the thunk itself returns */ ( - thunkAction: ThunkAction + thunkAction: ThunkAction, ): ReturnType // 2) The base overload. @@ -32,7 +32,7 @@ export interface ThunkDispatch< // with TS inference ( see https://github.com/microsoft/TypeScript/issues/14107 ) /** A union of the other two overloads for TS inference purposes */ ( - action: Action | ThunkAction + action: Action | ThunkAction, ): Action | ReturnType } @@ -53,11 +53,11 @@ export type ThunkAction< ReturnType, State, ExtraThunkArg, - BasicAction extends Action + BasicAction extends Action, > = ( dispatch: ThunkDispatch, getState: () => State, - extraArgument: ExtraThunkArg + extraArgument: ExtraThunkArg, ) => ReturnType /** @@ -69,7 +69,7 @@ export type ThunkAction< * @template ActionCreator Thunk action creator to be wrapped */ export type ThunkActionDispatch< - ActionCreator extends (...args: any[]) => ThunkAction + ActionCreator extends (...args: any[]) => ThunkAction, > = ( ...args: Parameters ) => ReturnType> @@ -83,7 +83,7 @@ export type ThunkActionDispatch< export type ThunkMiddleware< State = any, BasicAction extends Action = AnyAction, - ExtraThunkArg = undefined + ExtraThunkArg = undefined, > = Middleware< ThunkDispatch, State, diff --git a/test/test.ts b/test/test.ts index 15b403d..1c22a62 100644 --- a/test/test.ts +++ b/test/test.ts @@ -5,7 +5,7 @@ describe('thunk middleware', () => { const doGetState = () => 42 const nextHandler = thunkMiddleware({ dispatch: doDispatch, - getState: doGetState + getState: doGetState, }) it('must return a function to handle next', () => { @@ -90,7 +90,7 @@ describe('thunk middleware', () => { // @ts-ignore withExtraArgument(extraArg)({ dispatch: doDispatch, - getState: doGetState + getState: doGetState, })()((dispatch: any, getState: any, arg: any) => { expect(dispatch).toBe(doDispatch) expect(getState).toBe(doGetState) diff --git a/tsup.config.ts b/tsup.config.ts index 22b3528..dcf7c4e 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -4,9 +4,9 @@ import fs from 'fs' export default defineConfig(options => { const commonOptions: Partial = { entry: { - 'redux-thunk': 'src/index.ts' + 'redux-thunk': 'src/index.ts', }, - ...options + ...options, } return [ @@ -20,15 +20,15 @@ export default defineConfig(options => { // Support Webpack 4 by pointing `"module"` to a file with a `.js` extension fs.copyFileSync( 'dist/redux-thunk.mjs', - 'dist/redux-thunk.legacy-esm.js' + 'dist/redux-thunk.legacy-esm.js', ) - } + }, }, { ...commonOptions, format: 'cjs', outDir: './dist/cjs/', - outExtension: () => ({ js: '.cjs' }) - } + outExtension: () => ({ js: '.cjs' }), + }, ] }) diff --git a/typescript_test/typescript.ts b/typescript_test/typescript.ts index c6a52b6..cde9f3f 100644 --- a/typescript_test/typescript.ts +++ b/typescript_test/typescript.ts @@ -7,7 +7,7 @@ import type { ThunkAction, ThunkActionDispatch, ThunkDispatch, - ThunkMiddleware + ThunkMiddleware, } from '../src/index' export type State = { @@ -19,7 +19,7 @@ export type Actions = { type: 'FOO' } | { type: 'BAR'; result: number } export type ThunkResult = ThunkAction export const initialState: State = { - foo: 'foo' + foo: 'foo', } export function fakeReducer(state: State = initialState): State { @@ -28,7 +28,7 @@ export function fakeReducer(state: State = initialState): State { export const store = createStore( fakeReducer, - applyMiddleware(thunk as ThunkMiddleware) + applyMiddleware(thunk as ThunkMiddleware), ) store.dispatch(dispatch => { @@ -70,8 +70,8 @@ store.dispatch(testGetState()) const storeThunkArg = createStore( fakeReducer, applyMiddleware( - withExtraArgument('bar') as ThunkMiddleware - ) + withExtraArgument('bar') as ThunkMiddleware, + ), ) storeThunkArg.dispatch({ type: 'FOO' }) @@ -85,23 +85,23 @@ storeThunkArg.dispatch((dispatch, getState, extraArg) => { }) const callDispatchAsync_anyAction = ( - dispatch: ThunkDispatch + dispatch: ThunkDispatch, ) => { const asyncThunk = (): ThunkResult> => () => - ({} as Promise) + ({}) as Promise dispatch(asyncThunk()).then(() => console.log('done')) } const callDispatchAsync_specificActions = ( - dispatch: ThunkDispatch + dispatch: ThunkDispatch, ) => { const asyncThunk = (): ThunkResult> => () => - ({} as Promise) + ({}) as Promise dispatch(asyncThunk()).then(() => console.log('done')) } const callDispatchAny = ( - dispatch: ThunkDispatch + dispatch: ThunkDispatch, ) => { - const asyncThunk = (): any => () => ({} as Promise) + const asyncThunk = (): any => () => ({}) as Promise dispatch(asyncThunk()) // result is any .then(() => console.log('done')) } @@ -127,9 +127,9 @@ const actions: ActionDispatchs = bindActionCreators( { anotherThunkAction, promiseThunkAction, - standardAction + standardAction, }, - store.dispatch + store.dispatch, ) actions.anotherThunkAction() === 'hello' @@ -152,7 +152,7 @@ function testIssue248() { const dispatch: ThunkDispatch = undefined as any function dispatchWrap( - action: Action | ThunkAction + action: Action | ThunkAction, ) { // Should not have an error here thanks to the extra union overload dispatch(action) diff --git a/vitest.config.ts b/vitest.config.ts index 4ef78f4..1732a02 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -8,10 +8,10 @@ export default defineConfig({ 'redux-thunk': './src/index.ts', // @remap-prod-remove-line // this mapping is disabled as we want `dist` imports in the tests only to be used for "type-only" imports which don't play a role for jest - '@internal/': './src/' + '@internal/': './src/', }, deps: { - interopDefault: true - } - } + interopDefault: true, + }, + }, })