@gjsify/fs 0.25.1 → 0.26.0

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.
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{BigIntStats as t,STAT_ATTRIBUTES as n,Stats as r}from"./stats.js";import{FileHandle as i}from"./file-handle.js";import{createNodeError as a}from"./errors.js";import{accessSync as o,appendFileSync as s,chmodSync as c,chownSync as l,copyFileSync as u,mkdirSync as d,readFileSync as f,readdirSync as p,readlinkSync as m,realpathSync as h,renameSync as g,rmdirSync as _,truncateSync as v,writeFileSync as y}from"./sync.js";import{open as b,rm as x}from"./promises.js";import S from"@girs/glib-2.0";import C from"@girs/gio-2.0";import{Buffer as w}from"node:buffer";function parseOptsCb(e,t){return typeof e==`function`?{options:{},callback:e}:{options:e??{},callback:t}}function statImpl(i,o,s,c,l){let u=e(i),d=C.File.new_for_path(u);d.query_info_async(n,o,S.PRIORITY_DEFAULT,null,(e,n)=>{try{let e=d.query_info_finish(n);l(null,c?.bigint?new t(e,u):new r(e,u))}catch(e){l(a(e,s,u))}})}function stat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,C.FileQueryInfoFlags.NONE,`stat`,r,i)}function lstat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,C.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,r,i)}function readdir(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{i(null,p(e,r))}catch(t){i(a(t,`readdir`,e))}})}function realpath(e,t,n){let{callback:r}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{r(null,h(e))}catch(e){r(e)}})}function symlink(t,n,r,i){let o=typeof r==`function`?r:i;if(typeof o!=`function`)throw TypeError(`Callback must be a function. Received `+typeof o);let s=e(n),c=e(t),l=C.File.new_for_path(s);l.make_symbolic_link_async(c,S.PRIORITY_DEFAULT,null,(e,t)=>{try{l.make_symbolic_link_finish(t),o(null)}catch(e){o(a(e,`symlink`,c,s))}})}function open(e,...t){let n,r,i;switch(t.length){case 1:i=t[0];break;case 2:n=t[0],i=t[1];break;case 3:n=t[0],r=t[1],i=t[2];break;default:break}b(e,n,r).then(e=>{i(null,e.fd)}).catch(e=>{i(e,-1)})}function write(e,t,...n){let r=i.getInstance(e);if(typeof t==`string`){let e=n.pop(),i=n[0],a=n[1];r.write(t,i,a).then(t=>{e(null,t.bytesWritten,t.buffer)}).catch(t=>{e(t,0,``)});return}let a=n[n.length-1],o=n[0],s=n[1],c=n[2];r.write(t,o,s,c).then(e=>{a(null,e.bytesWritten,e.buffer)}).catch(e=>{a(e,0,w.from([]))})}function read(e,...t){let n=i.getInstance(e),r=t[t.length-1],a,o,s,c;if(!(t.length<=1))if(typeof t[0]==`object`&&!ArrayBuffer.isView(t[0])){let e=t[0];a=e.buffer,o=e.offset,s=e.length,c=e.position}else a=t[0],o=t[1],s=t[2],c=t[3];n.read(a,o,s,c).then(e=>{r(null,e.bytesRead,e.buffer)}).catch(e=>{r(e,0,w.from([]))})}function close(e,t){i.getInstance(e).close().then(()=>{t(null)}).catch(e=>t(e))}function rm(e,...t){let n={},r=t[t.length-1];t.length>=2&&(n=t[0]),x(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function rename(e,t,n){Promise.resolve().then(()=>{try{g(e,t),n(null)}catch(e){n(e)}})}function copyFile(e,t,n,r){let i=typeof n==`function`?0:n,a=typeof n==`function`?n:r;Promise.resolve().then(()=>{try{u(e,t,i),a(null)}catch(e){a(e)}})}function access(e,t,n){let r=typeof t==`function`?void 0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{o(e,r),i(null)}catch(e){i(e)}})}function appendFile(e,t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n;Promise.resolve().then(()=>{try{s(e,t,a),i(null)}catch(e){i(e)}})}function readlink(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{r(null,m(e,i))}catch(e){r(e,``)}})}function truncate(e,t,n){let r=typeof t==`function`?0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{v(e,r),i(null)}catch(e){i(e)}})}function chmod(e,t,n){Promise.resolve().then(()=>{try{c(e,t),n(null)}catch(e){n(e)}})}function chown(e,t,n,r){Promise.resolve().then(()=>{try{l(e,t,n),r(null)}catch(e){r(e)}})}function mkdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{d(e,i),r(null)}catch(e){r(e)}})}function rmdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{_(e,i),r(null)}catch(e){r(e)}})}function readFile(t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n,o=e(t);Promise.resolve().then(()=>{try{let e=typeof a==`string`?{encoding:a,flag:`r`}:{encoding:a?.encoding??null,flag:a?.flag??`r`};i(null,f(o,e))}catch(e){i(e,null)}})}function writeFile(t,n,r,i){let a=typeof r==`function`?r:i,o=e(t);Promise.resolve().then(()=>{try{y(o,n),a(null)}catch(e){a(e)}})}function link(t,n,r){let i=e(t),a=e(n);Promise.resolve().then(()=>{try{if(!S.spawn_command_line_sync(`ln ${i} ${a}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, link '${i}' -> '${a}'`),{code:`EPERM`,errno:-1,syscall:`link`,path:i,dest:a});r(null)}catch(e){r(e)}})}function unlink(t,n){let r=e(t);Promise.resolve().then(()=>{try{S.unlink(r),n(null)}catch(e){n(e)}})}export{access,appendFile,chmod,chown,close,copyFile,link,lstat,mkdir,open,read,readFile,readdir,readlink,realpath,rename,rm,rmdir,stat,symlink,truncate,unlink,write,writeFile};
1
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{BigIntStats as t,STAT_ATTRIBUTES as n,Stats as r}from"./stats.js";import{FileHandle as i}from"./file-handle.js";import{createNodeError as a}from"./errors.js";import{accessSync as o,appendFileSync as s,chmodSync as c,chownSync as l,copyFileSync as u,mkdirSync as d,readFileSync as f,readdirSync as p,readlinkSync as m,realpathSync as h,renameSync as g,rmdirSync as _,truncateSync as v,writeFileSync as y}from"./sync.js";import{open as b,rm as x}from"./promises.js";import S from"@girs/glib-2.0";import C from"@girs/gio-2.0";import{Buffer as w}from"node:buffer";function parseOptsCb(e,t){return typeof e==`function`?{options:{},callback:e}:{options:e??{},callback:t}}function statImpl(i,o,s,c,l){let u=e(i),d=C.File.new_for_path(u);d.query_info_async(n,o,S.PRIORITY_DEFAULT,null,(e,n)=>{try{let e=d.query_info_finish(n);l(null,c?.bigint?new t(e,u):new r(e,u))}catch(e){l(a(e,s,u))}})}function stat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,C.FileQueryInfoFlags.NONE,`stat`,r,i)}function lstat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,C.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,r,i)}function readdir(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{i(null,p(e,r))}catch(t){i(a(t,`readdir`,e))}})}function realpath(e,t,n){let{callback:r}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{r(null,h(e))}catch(e){r(e)}})}function symlink(t,n,r,i){let o=typeof r==`function`?r:i;if(typeof o!=`function`)throw TypeError(`Callback must be a function. Received `+typeof o);let s=e(n),c=e(t),l=C.File.new_for_path(s);l.make_symbolic_link_async(c,S.PRIORITY_DEFAULT,null,(e,t)=>{try{l.make_symbolic_link_finish(t),o(null)}catch(e){o(a(e,`symlink`,c,s))}})}function open(e,...t){let n,r,i;switch(t.length){case 1:i=t[0];break;case 2:n=t[0],i=t[1];break;case 3:n=t[0],r=t[1],i=t[2];break;default:break}b(e,n,r).then(e=>{i(null,e.fd)}).catch(e=>{i(e,-1)})}function write(e,t,...n){let r=i.getInstance(e);if(typeof t==`string`){let e=n.pop(),i=n[0],a=n[1];r.write(t,i,a).then(t=>{e(null,t.bytesWritten,t.buffer)}).catch(t=>{e(t,0,``)});return}let a=n[n.length-1],o=n[0],s=n[1],c=n[2];r.write(t,o,s,c).then(e=>{a(null,e.bytesWritten,e.buffer)}).catch(e=>{a(e,0,w.from([]))})}function read(e,...t){let n=i.getInstance(e),r=t[t.length-1],a,o,s,c;if(!(t.length<=1))if(typeof t[0]==`object`&&!ArrayBuffer.isView(t[0])){let e=t[0];a=e.buffer,o=e.offset,s=e.length,c=e.position}else a=t[0],o=t[1],s=t[2],c=t[3];n.read(a,o,s,c).then(e=>{r(null,e.bytesRead,e.buffer)}).catch(e=>{r(e,0,w.from([]))})}function close(e,t){i.getInstance(e).close().then(()=>{t(null)}).catch(e=>t(e))}function rm(e,...t){let n={},r=t[t.length-1];t.length>=2&&(n=t[0]),x(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function rename(e,t,n){Promise.resolve().then(()=>{try{g(e,t),n(null)}catch(e){n(e)}})}function copyFile(e,t,n,r){let i=typeof n==`function`?0:n,a=typeof n==`function`?n:r;Promise.resolve().then(()=>{try{u(e,t,i),a(null)}catch(e){a(e)}})}function access(e,t,n){let r=typeof t==`function`?void 0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{o(e,r),i(null)}catch(e){i(e)}})}function appendFile(e,t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n;Promise.resolve().then(()=>{try{s(e,t,a),i(null)}catch(e){i(e)}})}function readlink(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{r(null,m(e,i))}catch(e){r(e,``)}})}function truncate(e,t,n){let r=typeof t==`function`?0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{v(e,r),i(null)}catch(e){i(e)}})}function chmod(e,t,n){Promise.resolve().then(()=>{try{c(e,t),n(null)}catch(e){n(e)}})}function chown(e,t,n,r){Promise.resolve().then(()=>{try{l(e,t,n),r(null)}catch(e){r(e)}})}function mkdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{d(e,i),r(null)}catch(e){r(e)}})}function rmdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{_(e,i),r(null)}catch(e){r(e)}})}function readFile(t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n,o=e(t);Promise.resolve().then(()=>{try{let e=typeof a==`string`?{encoding:a,flag:`r`}:{encoding:a?.encoding??null,flag:a?.flag??`r`};i(null,f(o,e))}catch(e){i(e,null)}})}function writeFile(t,n,r,i){let a=typeof r==`function`?r:i,o=e(t);Promise.resolve().then(()=>{try{y(o,n),a(null)}catch(e){a(e)}})}function link(t,n,r){let i=e(t),a=e(n);Promise.resolve().then(()=>{try{if(!S.spawn_command_line_sync(`ln ${i} ${a}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, link '${i}' -> '${a}'`),{code:`EPERM`,errno:-1,syscall:`link`,path:i,dest:a});r(null)}catch(e){r(e)}})}function unlink(t,n){let r=e(t);Promise.resolve().then(()=>{S.unlink(r),n(null)})}export{access,appendFile,chmod,chown,close,copyFile,link,lstat,mkdir,open,read,readFile,readdir,readlink,realpath,rename,rm,rmdir,stat,symlink,truncate,unlink,write,writeFile};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";import{EventEmitter as r}from"node:events";const i=new WeakMap;var FSWatcher=class extends r{constructor(r,a,o){super(),(!a||typeof a!=`object`)&&(a={persistent:!0});let s=a.persistent!==!1,c=n.Cancellable.new(),l=e(r),u=n.File.new_for_path(l).monitor(n.FileMonitorFlags.NONE,c);u.connect(`changed`,changed.bind(this));let d=null;s&&(d=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),i.set(this,{persistent:s,cancellable:c,sourceId:d,watcher:u}),o&&this.on(`change`,o)}close(){let e=i.get(this);e.cancellable.is_cancelled()||(e.cancellable.cancel(),e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null))}ref(){let e=i.get(this);return!e.persistent&&!e.cancellable.is_cancelled()&&(e.persistent=!0,e.sourceId=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),this}unref(){let e=i.get(this);return e.persistent&&(e.persistent=!1,e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null)),this}};function changed(e,t,r,i){switch(i){case n.FileMonitorEvent.CHANGES_DONE_HINT:this.emit(`change`,`change`,t.get_basename());break;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:this.emit(`change`,`rename`,t.get_basename());break}}function gioEventToNodeType(e){switch(e){case n.FileMonitorEvent.CHANGES_DONE_HINT:return`change`;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:return`rename`;default:return null}}async function*watchAsync(t,r){let i=r?.signal;if(i?.aborted)return;let a=e(t),o=n.File.new_for_path(a),s=n.Cancellable.new(),c;try{c=o.monitor(n.FileMonitorFlags.NONE,s)}catch{return}let l=[],u=[],d=!1;function enqueue(e){d||(u.length>0?u.shift().resolve({value:e,done:!1}):l.push(e))}function terminate(){if(!d)for(d=!0,s.is_cancelled()||s.cancel();u.length>0;)u.shift().resolve({value:void 0,done:!0})}let f=c.connect(`changed`,(e,t,n,r)=>{let i=gioEventToNodeType(r);i!==null&&enqueue({eventType:i,filename:t?.get_basename()??null})}),abortHandler=()=>terminate();i?.addEventListener(`abort`,abortHandler);try{for(;!d;){if(l.length>0){yield l.shift();continue}let e=await new Promise(e=>{u.push({resolve:e})});if(e.done)break;yield e.value}}finally{i?.removeEventListener(`abort`,abortHandler);try{c.disconnect(f)}catch{}s.is_cancelled()||s.cancel()}}export{FSWatcher,FSWatcher as default,watchAsync};
1
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";import{EventEmitter as r}from"node:events";const i=new WeakMap;var FSWatcher=class extends r{constructor(r,a,o){super(),(!a||typeof a!=`object`)&&(a={persistent:!0});let s=a.persistent!==!1,c=n.Cancellable.new(),l=e(r),u=n.File.new_for_path(l).monitor(n.FileMonitorFlags.NONE,c);u.connect(`changed`,changed.bind(this));let d=null;s&&(d=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),i.set(this,{persistent:s,cancellable:c,sourceId:d,watcher:u}),o&&this.on(`change`,o)}close(){let e=i.get(this);e.cancellable.is_cancelled()||(e.cancellable.cancel(),e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null))}ref(){let e=i.get(this);return!e.persistent&&!e.cancellable.is_cancelled()&&(e.persistent=!0,e.sourceId=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),this}unref(){let e=i.get(this);return e.persistent&&(e.persistent=!1,e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null)),this}};function changed(e,t,r,i){switch(i){case n.FileMonitorEvent.CHANGES_DONE_HINT:this.emit(`change`,`change`,t.get_basename());break;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:this.emit(`change`,`rename`,t.get_basename());break}}function gioEventToNodeType(e){switch(e){case n.FileMonitorEvent.CHANGES_DONE_HINT:return`change`;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:return`rename`;default:return null}}async function*watchAsync(t,r){let i=r?.signal;if(i?.aborted)return;let a=e(t),o=n.File.new_for_path(a),s=n.Cancellable.new(),c;try{c=o.monitor(n.FileMonitorFlags.NONE,s)}catch{return}let l=[],u=[],d=!1;function enqueue(e){d||(u.length>0?u.shift().resolve({value:e,done:!1}):l.push(e))}function terminate(){if(!d)for(d=!0,s.is_cancelled()||s.cancel();u.length>0;)u.shift().resolve({value:void 0,done:!0})}let f=c.connect(`changed`,(e,t,n,r)=>{let i=gioEventToNodeType(r);i!==null&&enqueue({eventType:i,filename:t?.get_basename()??null})}),abortHandler=()=>terminate();i?.addEventListener(`abort`,abortHandler);try{for(;!d;){if(l.length>0){yield l.shift();continue}let e=await new Promise(e=>{u.push({resolve:e})});if(e.done)break;yield e.value}}finally{i?.removeEventListener(`abort`,abortHandler),c.disconnect(f),s.is_cancelled()||s.cancel()}}export{FSWatcher,FSWatcher as default,watchAsync};
@@ -406,7 +406,7 @@ export declare class FileHandle implements IFileHandle {
406
406
  * helpers ({@link https://nodejs.org/api/stream_iter.html}). The
407
407
  * stub keeps the @types/node FileHandle interface satisfied so
408
408
  * downstream typecheck passes; calling at runtime throws a clear
409
- * "not yet" error. Tracked in STATUS.md "Open TODOs → Node 25
409
+ * "not yet" error. Tracked in status/open-todos.md → "Node 25
410
410
  * stream/iter integration".
411
411
  */
412
412
  pull(..._args: any[]): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/fs",
3
- "version": "0.25.1",
3
+ "version": "0.26.0",
4
4
  "description": "Node.js fs module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -66,19 +66,19 @@
66
66
  "fs"
67
67
  ],
68
68
  "devDependencies": {
69
- "@gjsify/cli": "^0.25.1",
70
- "@gjsify/unit": "^0.25.1",
69
+ "@gjsify/cli": "^0.26.0",
70
+ "@gjsify/unit": "^0.26.0",
71
71
  "@types/node": "^25.9.2",
72
72
  "typescript": "^6.0.3"
73
73
  },
74
74
  "dependencies": {
75
75
  "@girs/gio-2.0": "^4.1.0",
76
76
  "@girs/glib-2.0": "^4.1.0",
77
- "@gjsify/buffer": "^0.25.1",
78
- "@gjsify/events": "^0.25.1",
79
- "@gjsify/stream": "^0.25.1",
80
- "@gjsify/url": "^0.25.1",
81
- "@gjsify/utils": "^0.25.1"
77
+ "@gjsify/buffer": "^0.26.0",
78
+ "@gjsify/events": "^0.26.0",
79
+ "@gjsify/stream": "^0.26.0",
80
+ "@gjsify/url": "^0.26.0",
81
+ "@gjsify/utils": "^0.26.0"
82
82
  },
83
83
  "gjsify": {
84
84
  "runtimes": {