@gjsify/fs 0.26.0 → 0.27.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.
- package/lib/esm/callback.js +1 -1
- package/lib/esm/fd-ops.js +1 -1
- package/lib/esm/std-fd.js +1 -0
- package/lib/esm/sync.js +1 -1
- package/lib/esm/utimes.js +1 -1
- package/lib/types/std-fd.d.ts +27 -0
- package/lib/types/sync.d.ts +18 -1
- package/package.json +10 -9
package/lib/esm/callback.js
CHANGED
|
@@ -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,
|
|
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,linkSync as d,mkdirSync as f,readFileSync as p,readdirSync as m,readlinkSync as h,realpathSync as g,renameSync as _,rmdirSync as v,truncateSync as y,writeFileSync as b}from"./sync.js";import{open as x,rm as S}from"./promises.js";import C from"@girs/glib-2.0";import w from"@girs/gio-2.0";import{Buffer as T}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=w.File.new_for_path(u);d.query_info_async(n,o,C.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,w.FileQueryInfoFlags.NONE,`stat`,r,i)}function lstat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,w.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,m(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,g(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=w.File.new_for_path(s);l.make_symbolic_link_async(c,C.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}x(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,T.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,T.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]),S(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function rename(e,t,n){Promise.resolve().then(()=>{try{_(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,h(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{y(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{f(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{v(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,p(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{b(o,n),a(null)}catch(e){a(e)}})}function link(e,t,n){Promise.resolve().then(()=>{try{d(e,t),n(null)}catch(e){n(e)}})}function unlink(t,n){let r=e(t);Promise.resolve().then(()=>{C.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};
|
package/lib/esm/fd-ops.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{FileHandle as t}from"./file-handle.js";import{
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{FileHandle as t}from"./file-handle.js";import{isStdFd as n,readStdFdSync as r,writeStdFdSync as i}from"./std-fd.js";import{chmodSync as a,chownSync as o,readFileSync as s,statSync as c,truncateSync as l}from"./sync.js";import{utimesSync as u}from"./utimes.js";function getFH(e){return e instanceof t?t.getInstance(e.fd):t.getInstance(e)}function fstatSync(t,n){return c(e(getFH(t).options.path),n)}function fstat(e,t,n){let r=typeof t==`function`?t:n;fstatAsync(e,typeof t==`function`?{}:t).then(e=>r(null,e),e=>r(e,void 0))}async function fstatAsync(e,t){return t?.bigint,fstatSync(e,t)}function ftruncateSync(t,n=0){l(e(getFH(t).options.path),n)}function ftruncate(e,t,n){let r=typeof t==`function`?t:n;ftruncateAsync(e,typeof t==`function`?0:t).then(()=>r(null),r)}async function ftruncateAsync(e,t=0){ftruncateSync(e,t)}function fdatasyncSync(e){getFH(e)._flushSync()}function fdatasync(e,t){Promise.resolve().then(()=>fdatasyncSync(e)).then(()=>t(null),t)}async function fdatasyncAsync(e){fdatasyncSync(e)}function fsyncSync(e){getFH(e)._flushSync()}function fsync(e,t){Promise.resolve().then(()=>fsyncSync(e)).then(()=>t(null),t)}async function fsyncAsync(e){fsyncSync(e)}function fchmodSync(t,n){a(e(getFH(t).options.path),n)}function fchmod(e,t,n){Promise.resolve().then(()=>fchmodSync(e,t)).then(()=>n(null),n)}async function fchmodAsync(e,t){fchmodSync(e,t)}function fchownSync(t,n,r){o(e(getFH(t).options.path),n,r)}function fchown(e,t,n,r){Promise.resolve().then(()=>fchownSync(e,t,n)).then(()=>r(null),r)}async function fchownAsync(e,t,n){fchownSync(e,t,n)}function futimesSync(t,n,r){u(e(getFH(t).options.path),n,r)}function futimes(e,t,n,r){Promise.resolve().then(()=>futimesSync(e,t,n)).then(()=>r(null),r)}async function futimesAsync(e,t,n){futimesSync(e,t,n)}function closeSync(e){n(e)||getFH(e)._closeSync()}function readSync(e,t,i,a,o){let s=0;return typeof i==`object`&&i?(s=i.offset??0,a=i.length??t.byteLength,o=i.position??null):(s=i??0,a??=t.byteLength-s),n(e)?r(e,t,s,a):getFH(e)._readSync(t,s,a,o??null)}function writeSync(e,t,r,a,o){let s;if(typeof t==`string`)s=new TextEncoder().encode(t),typeof r==`number`&&(o=r);else{let e=typeof r==`number`?r:0,n=typeof a==`number`?a:t.byteLength-e;s=new Uint8Array(t.buffer,t.byteOffset+e,n)}return n(e)?i(e,s):getFH(e)._writeSync(s,o??null)}function readvSync(e,t,n){let r=0;for(let i of t){let t=readSync(e,i,0,i.byteLength,n==null?null:n+r);if(r+=t,t<i.byteLength)break}return r}function readv(e,t,n,r){let i=typeof n==`function`?n:r;readvAsync(e,t,typeof n==`function`?null:n).then(e=>i(null,e.bytesRead,e.buffers),e=>i(e,0,t))}async function readvAsync(e,t,n){return{bytesRead:readvSync(e,t,n),buffers:t}}function writevSync(e,t,n){let r=0;for(let i of t){let t=writeSync(e,i,0,i.byteLength,n==null?null:n+r);r+=t}return r}function writev(e,t,n,r){let i=typeof n==`function`?n:r;writevAsync(e,t,typeof n==`function`?null:n).then(e=>i(null,e.bytesWritten,e.buffers),e=>i(e,0,t))}async function writevAsync(e,t,n){return{bytesWritten:writevSync(e,t,n),buffers:t}}function exists(t,n){try{c(e(t)),n(!0)}catch{n(!1)}}async function openAsBlob(t,n){let r=s(e(t));return new Blob([r],{type:n?.type??``})}export{closeSync,exists,fchmod,fchmodAsync,fchmodSync,fchown,fchownAsync,fchownSync,fdatasync,fdatasyncAsync,fdatasyncSync,fstat,fstatAsync,fstatSync,fsync,fsyncAsync,fsyncSync,ftruncate,ftruncateAsync,ftruncateSync,futimes,futimesAsync,futimesSync,openAsBlob,readSync,readv,readvAsync,readvSync,writeSync,writev,writevAsync,writevSync};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";import t from"@girs/gio-2.0";import n from"@girs/giounix-2.0";const r=0,i=1,a=2;function isStdFd(e){return e===0||e===1||e===2}let o=null;const s={};function stdinInput(){return o||=n.InputStream.new(0,!1),o}function stdOutput(e){return s[e]||(s[e]=n.OutputStream.new(e,!1)),s[e]}function readStdFdAll(e){try{let t=e===0?stdinInput():n.InputStream.new(e,!1),r=[],i=0;for(;;){let e=t.read_bytes(64*1024,null).get_data();if(!e||e.length===0)break;r.push(e),i+=e.length}return concat(r,i)}catch(n){if(e!==0)throw n;let[r,i]=t.File.new_for_path(`/dev/stdin`).load_contents(null);if(!r)throw n;return i}}function readStdFdSync(e,t,r,i){let a=(e===0?stdinInput():n.InputStream.new(e,!1)).read_bytes(i,null).get_data();return a&&a.length>0?(new Uint8Array(t.buffer,t.byteOffset+r).set(a),a.length):0}function writeStdFdSync(t,n){return stdOutput(t).write_bytes(e.Bytes.new(n),null)}function concat(e,t){if(e.length===1)return e[0];let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}export{a as STDERR_FD,r as STDIN_FD,i as STDOUT_FD,isStdFd,readStdFdAll,readStdFdSync,writeStdFdSync};
|
package/lib/esm/sync.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{decode as e,encodeUint8Array as t,getEncodingFromOptions as n}from"./encoding.js";import{normalizePath as r,tempDirPath as i}from"./utils.js";import{FSWatcher as a}from"./fs-watcher.js";import{Dirent as o}from"./dirent.js";import{BigIntStats as s,STAT_ATTRIBUTES as c,Stats as l}from"./stats.js";import{FileHandle as u}from"./file-handle.js";import{createNodeError as d,isNotFoundError as f}from"./errors.js";import p from"@girs/glib-2.0";import
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{decode as e,encodeUint8Array as t,getEncodingFromOptions as n}from"./encoding.js";import{normalizePath as r,tempDirPath as i}from"./utils.js";import{FSWatcher as a}from"./fs-watcher.js";import{Dirent as o}from"./dirent.js";import{BigIntStats as s,STAT_ATTRIBUTES as c,Stats as l}from"./stats.js";import{FileHandle as u}from"./file-handle.js";import{createNodeError as d,isNotFoundError as f}from"./errors.js";import{isStdFd as p,readStdFdAll as m}from"./std-fd.js";import h from"@girs/glib-2.0";import g from"@girs/gio-2.0";import{join as _}from"node:path";import{Buffer as v}from"node:buffer";import{existsSync as y}from"@gjsify/utils";function statSync(e,t){let n=r(e);try{let e=g.File.new_for_path(n).query_info(c,g.FileQueryInfoFlags.NONE,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`stat`,n)}}function lstatSync(e,t){let n=r(e);try{let e=g.File.new_for_path(n).query_info(c,g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`lstat`,n)}}function readdirSync(e,t){let n=r(e),i=g.File.new_for_path(n).enumerate_children(`standard::name,standard::type`,g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null),a=[];try{let e=i.next_file(null);for(;e!==null;)a.push({name:e.get_name(),type:e.get_file_type()}),e=i.next_file(null)}finally{try{i.close(null)}catch{}}let s=[];for(let e of a){let r=_(n,e.name);if(t?.withFileTypes?s.push(new o(r,e.name,e.type)):s.push(e.name),t?.recursive&&e.type===g.FileType.DIRECTORY){let n=readdirSync(r,t);for(let t of n)typeof t==`string`?s.push(_(e.name,t)):s.push(t)}}return s}function realpathSync(e){let t=r(e);return resolveEveryComponent(g.File.new_for_path(t),{left:40},t)}function resolveEveryComponent(e,t,n){let r=e.get_parent();return expandSymlinks(r===null?e:g.File.new_for_path(resolveEveryComponent(r,t,n)).get_child(e.get_basename()),t,n)}function expandSymlinks(e,t,n){let r=e;for(;;){let e=r.query_info(`standard::is-symlink,standard::symlink-target`,g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);if(!e.get_is_symlink())return r.get_path();if(--t.left<0)throw Error(`ELOOP: too many levels of symbolic links, realpath '${n}'`);let i=e.get_symlink_target(),a=r.get_parent(),o=h.path_is_absolute(i)?g.File.new_for_path(i):(a??r).resolve_relative_path(i);r=g.File.new_for_path(resolveEveryComponent(o,t,n))}}realpathSync.native=realpathSync;function symlinkSync(e,t,n){let i=r(t),a=r(e);g.File.new_for_path(i).make_symbolic_link(a,null)}function readFileSync(e,i={encoding:null,flag:`r`}){if(typeof e==`number`&&p(e))return t(n(i,`buffer`),m(e));let a=r(typeof e==`number`?u.getInstance(e).options.path:e),o=g.File.new_for_path(a);try{let[e,r]=o.load_contents(null);if(!e)throw d(Error(`failed to read file`),`read`,a);return t(n(i,`buffer`),r)}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`read`,a)}}function mkdirSync(e,t){let n=!1,i=511;if(typeof t==`object`?(t?.recursive&&(n=t.recursive),t?.mode&&(i=t.mode)):i=t||511,e=r(e),typeof i==`string`)throw TypeError(`mode as string is currently not supported!`);if(n)return mkdirSyncRecursive(e);let a=g.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}}function mkdirSyncRecursive(e){let t=g.File.new_for_path(e);try{return t.make_directory(null),e}catch(t){let n=t;if(n.code===g.IOErrorEnum.EXISTS)return;if(n.code===g.IOErrorEnum.NOT_FOUND){let n=_(e,`..`),r=g.File.new_for_path(n).get_path();if(r===e)throw d(t,`mkdir`,e);let i=mkdirSyncRecursive(r),a=g.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}return i??e}throw d(t,`mkdir`,e)}}function rmdirSync(e,t){let n=r(e),i=g.File.new_for_path(n);try{if(i.query_info(`standard::type`,g.FileQueryInfoFlags.NONE,null).get_file_type()!==g.FileType.DIRECTORY)throw d(Object.assign(Error(),{code:4}),`rmdir`,n);if(i.enumerate_children(`standard::name`,g.FileQueryInfoFlags.NONE,null).next_file(null)!==null)throw d(Object.assign(Error(),{code:5}),`rmdir`,n);i.delete(null)}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`rmdir`,n)}}function unlinkSync(e){let t=r(e),n=g.File.new_for_path(t);try{n.delete(null)}catch(e){throw d(e,`unlink`,t)}}function writeFileSync(e,t){h.file_set_contents(r(e),t)}function renameSync(e,t){let n=r(e),i=r(t),a=g.File.new_for_path(n),o=g.File.new_for_path(i);try{a.move(o,g.FileCopyFlags.OVERWRITE,null,null)}catch(e){throw d(e,`rename`,n,i)}}function copyFileSync(e,t,n){let i=r(e),a=r(t),o=g.File.new_for_path(i),s=g.File.new_for_path(a),c=g.FileCopyFlags.NONE;n&&!(n&1)?c=g.FileCopyFlags.OVERWRITE:n||(c=g.FileCopyFlags.OVERWRITE);try{o.copy(s,c,null,null)}catch(e){throw d(e,`copyfile`,i,a)}}function accessSync(e,t){let n=r(e),i=g.File.new_for_path(n);try{let e=i.query_info(`access::*`,g.FileQueryInfoFlags.NONE,null);if(t!==void 0&&t!==0){let r={code:14,message:`permission denied, access '${n}'`};if(t&4&&!e.get_attribute_boolean(`access::can-read`)||t&2&&!e.get_attribute_boolean(`access::can-write`)||t&1&&!e.get_attribute_boolean(`access::can-execute`))throw d(r,`access`,n)}}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`access`,n)}}function appendFileSync(e,t,n){let i=r(e),a=g.File.new_for_path(i),o;o=typeof t==`string`?new TextEncoder().encode(t):t;try{let e=a.append_to(g.FileCreateFlags.NONE,null);o.length>0&&e.write_bytes(new h.Bytes(o),null),e.close(null)}catch(e){throw d(e,`appendfile`,i)}}function readlinkSync(e,t){let n=r(e),i=g.File.new_for_path(n);try{let e=i.query_info(`standard::symlink-target`,g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null).get_symlink_target();if(!e)throw Object.assign(Error(`EINVAL: invalid argument, readlink '${n}'`),{code:`EINVAL`,errno:-22,syscall:`readlink`,path:n});return(typeof t==`string`?t:t?.encoding)===`buffer`?v.from(e):e}catch(e){throw typeof e.code==`string`?e:d(e,`readlink`,n)}}function linkSync(e,t){let n=r(e),i=r(t);if(g.File.new_for_path(n).query_file_type(g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)===g.FileType.UNKNOWN)throw Object.assign(Error(`ENOENT: no such file or directory, link '${n}' -> '${i}'`),{code:`ENOENT`,errno:-2,syscall:`link`,path:n,dest:i});if(g.File.new_for_path(i).query_file_type(g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)!==g.FileType.UNKNOWN)throw Object.assign(Error(`EEXIST: file already exists, link '${n}' -> '${i}'`),{code:`EEXIST`,errno:-17,syscall:`link`,path:n,dest:i});let a=``;try{let[,,e,t]=h.spawn_sync(null,[`ln`,`--`,n,i],null,h.SpawnFlags.SEARCH_PATH,null);if(a=e?new TextDecoder().decode(e).trim():``,!h.spawn_check_wait_status(t))throw Error(`ln exited non-zero (${t})`);return}catch(e){throw a===``&&e instanceof Error&&(a=e.message),Object.assign(Error(`EPERM: operation not permitted, link '${n}' -> '${i}'`+(a?` (${a})`:``)),{code:`EPERM`,errno:-1,syscall:`link`,path:n,dest:i})}}function truncateSync(e,t){let n=r(e),i=g.File.new_for_path(n);try{let e=i.replace(null,!1,g.FileCreateFlags.NONE,null);if(t&&t>0){let[,n]=i.load_contents(null),r=n.slice(0,t);r.length>0&&e.write_bytes(new h.Bytes(r),null)}e.close(null)}catch(e){throw d(e,`truncate`,n)}}function chmodSync(e,t){let n=r(e),i=typeof t==`string`?parseInt(t,8):t;try{g.File.new_for_path(n).set_attribute_uint32(`unix::mode`,i,g.FileQueryInfoFlags.NONE,null)}catch(e){throw d(e,`chmod`,n)}}function chownSync(e,t,n){let i=r(e);try{let e=g.File.new_for_path(i),r=new g.FileInfo;t!==-1&&r.set_attribute_uint32(`unix::uid`,t),n!==-1&&r.set_attribute_uint32(`unix::gid`,n),e.set_attributes_from_info(r,g.FileQueryInfoFlags.NONE,null)}catch(e){throw d(e,`chown`,i)}}function watch(e,t,n){return new a(r(e),t,n)}function openSync(e,t,n){return new u({path:e,flags:t,mode:n})}function mkdtempSync(t,r){let a=n(r),o=i(t);return mkdirSync(o,{recursive:!1,mode:511}),e(o,a)}function rmSync(e,t){let n=r(e),i=g.File.new_for_path(n),a=t?.recursive||!1,o=t?.force||!1,s;try{s=i.query_file_type(g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}if(s===g.FileType.SYMBOLIC_LINK){try{i.delete(null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}return}if(s===g.FileType.DIRECTORY){let r=readdirSync(e);if(!a&&r.length)throw d(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)rmSync(_(n,e),t)}try{i.delete(null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}}export{accessSync,appendFileSync,chmodSync,chownSync,copyFileSync,y as existsSync,linkSync,lstatSync,mkdirSync,mkdtempSync,openSync,readFileSync,readdirSync,readlinkSync,realpathSync,renameSync,rmSync,rmdirSync,statSync,symlinkSync,truncateSync,unlinkSync,watch,writeFileSync};
|
package/lib/esm/utimes.js
CHANGED
|
@@ -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";function toGLibDateTime(e){let n=e instanceof Date?e.getTime():typeof e==`bigint`?Number(e):typeof e==`string`?Date.parse(e):e*1e3;return t.DateTime.new_from_unix_utc(Math.floor(n/1e3))}function setTimestamps(e,t,r,i){let a=n.File.new_for_path(e),o=new n.FileInfo;o.set_modification_date_time(toGLibDateTime(r)),o.set_access_date_time(toGLibDateTime(t)),a.set_attributes_from_info(o,i,null)}function utimesSync(t,r,i){setTimestamps(e(t),r,i,n.FileQueryInfoFlags.NONE)}function utimes(e,t,n,r){Promise.resolve().then(()=>utimesSync(e,t,n)).then(()=>r(null),r)}async function utimesAsync(e,t,n){utimesSync(e,t,n)}function lutimesSync(t,r,i){setTimestamps(e(t),r,i,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)}function lutimes(e,t,n,r){Promise.resolve().then(()=>lutimesSync(e,t,n)).then(()=>r(null),r)}async function lutimesAsync(e,t,n){lutimesSync(e,t,n)}function lchownSync(
|
|
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";function toGLibDateTime(e){let n=e instanceof Date?e.getTime():typeof e==`bigint`?Number(e):typeof e==`string`?Date.parse(e):e*1e3;return t.DateTime.new_from_unix_utc(Math.floor(n/1e3))}function setTimestamps(e,t,r,i){let a=n.File.new_for_path(e),o=new n.FileInfo;o.set_modification_date_time(toGLibDateTime(r)),o.set_access_date_time(toGLibDateTime(t)),a.set_attributes_from_info(o,i,null)}function utimesSync(t,r,i){setTimestamps(e(t),r,i,n.FileQueryInfoFlags.NONE)}function utimes(e,t,n,r){Promise.resolve().then(()=>utimesSync(e,t,n)).then(()=>r(null),r)}async function utimesAsync(e,t,n){utimesSync(e,t,n)}function lutimesSync(t,r,i){setTimestamps(e(t),r,i,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)}function lutimes(e,t,n,r){Promise.resolve().then(()=>lutimesSync(e,t,n)).then(()=>r(null),r)}async function lutimesAsync(e,t,n){lutimesSync(e,t,n)}function lchownSync(t,r,i){let a=e(t),o=n.File.new_for_path(a),s=new n.FileInfo;r!==-1&&s.set_attribute_uint32(`unix::uid`,r),i!==-1&&s.set_attribute_uint32(`unix::gid`,i),o.set_attributes_from_info(s,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}function lchown(e,t,n,r){Promise.resolve().then(()=>lchownSync(e,t,n)).then(()=>r(null),r)}async function lchownAsync(e,t,n){lchownSync(e,t,n)}function lchmodSync(e,t){}function lchmod(e,t,n){n(null)}async function lchmodAsync(e,t){}export{lchmod,lchmodAsync,lchmodSync,lchown,lchownAsync,lchownSync,lutimes,lutimesAsync,lutimesSync,utimes,utimesAsync,utimesSync};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const STDIN_FD = 0;
|
|
2
|
+
export declare const STDOUT_FD = 1;
|
|
3
|
+
export declare const STDERR_FD = 2;
|
|
4
|
+
/** True for the parent-supplied standard descriptors 0/1/2. */
|
|
5
|
+
export declare function isStdFd(fd: number): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Read the whole of the given standard descriptor to EOF — backs
|
|
8
|
+
* `readFileSync(0)` / `readFile(0)`. Only fd 0 is readable; a read on 1/2
|
|
9
|
+
* surfaces the underlying `EBADF` from GioUnix rather than pretending success.
|
|
10
|
+
*
|
|
11
|
+
* A `/dev/stdin` fallback covers the one host where the GioUnix route was
|
|
12
|
+
* observed unavailable (same defensive second mechanism as the CLI helper this
|
|
13
|
+
* replaces) — `/dev/stdin` is fd 0 by another name and `Gio` is always present.
|
|
14
|
+
*/
|
|
15
|
+
export declare function readStdFdAll(fd: number): Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* Single positional-less read of up to `length` bytes from a standard
|
|
18
|
+
* descriptor into `buffer` at `offset` — backs `readSync(0, …)`. Returns the
|
|
19
|
+
* number of bytes read (0 at EOF). `position` is ignored: stdin is a stream,
|
|
20
|
+
* not a seekable file, which matches Node reading a pipe/TTY.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readStdFdSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Write `data` to a standard descriptor — backs `writeSync(1|2, …)`. Returns
|
|
25
|
+
* the number of bytes written. Writing to fd 0 surfaces GioUnix's `EBADF`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function writeStdFdSync(fd: number, data: Uint8Array): number;
|
package/lib/types/sync.d.ts
CHANGED
|
@@ -14,9 +14,26 @@ export declare function readdirSync(path: PathLike, options?: {
|
|
|
14
14
|
encoding?: string;
|
|
15
15
|
recursive?: boolean;
|
|
16
16
|
}): string[] | Dirent[];
|
|
17
|
+
/**
|
|
18
|
+
* POSIX `realpath(3)`: resolve EVERY component, not merely a trailing symlink.
|
|
19
|
+
*
|
|
20
|
+
* This used to `query_info` the path once and return it UNCHANGED whenever the
|
|
21
|
+
* LEAF was not a symlink, so a symlinked ANCESTOR survived into the result. On a
|
|
22
|
+
* typical Linux box that is invisible — `/tmp` is a real directory, so the
|
|
23
|
+
* identity answer happens to be the right one. On macOS `/var` is a symlink to
|
|
24
|
+
* `private/var`, so `realpathSync(os.tmpdir())` returned `/var/folders/…` while a
|
|
25
|
+
* child process asked for its own cwd reported `/private/var/folders/…`. That
|
|
26
|
+
* surfaced as six `@gjsify/child_process` cwd failures on main's macOS leg — the
|
|
27
|
+
* only leg that runs it, macOS being off for pull requests. The platform was
|
|
28
|
+
* incidental: reproduced on Linux with nothing but a symlinked parent directory.
|
|
29
|
+
*
|
|
30
|
+
* The symlink budget is shared across the whole walk because POSIX counts total
|
|
31
|
+
* resolutions rather than per-component ones, so a cycle reachable through any
|
|
32
|
+
* component still terminates.
|
|
33
|
+
*/
|
|
17
34
|
export declare function realpathSync(path: PathLike): string;
|
|
18
35
|
export declare function symlinkSync(target: PathLike, path: PathLike, _type?: 'file' | 'dir' | 'junction'): void;
|
|
19
|
-
export declare function readFileSync(path: PathLike, options?: {
|
|
36
|
+
export declare function readFileSync(path: PathLike | number, options?: {
|
|
20
37
|
encoding?: string | null;
|
|
21
38
|
flag?: string;
|
|
22
39
|
} | string | null): string | Buffer<ArrayBuffer>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/fs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.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",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
|
-
"clear": "
|
|
50
|
+
"clear": "gjsify clear lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs",
|
|
51
51
|
"check": "gjsify tsc --noEmit",
|
|
52
52
|
"build": "gjsify run build:gjsify && gjsify run build:types",
|
|
53
53
|
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
@@ -66,19 +66,20 @@
|
|
|
66
66
|
"fs"
|
|
67
67
|
],
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@gjsify/cli": "^0.
|
|
70
|
-
"@gjsify/unit": "^0.
|
|
69
|
+
"@gjsify/cli": "^0.27.0",
|
|
70
|
+
"@gjsify/unit": "^0.27.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
|
+
"@girs/giounix-2.0": "^4.1.0",
|
|
76
77
|
"@girs/glib-2.0": "^4.1.0",
|
|
77
|
-
"@gjsify/buffer": "^0.
|
|
78
|
-
"@gjsify/events": "^0.
|
|
79
|
-
"@gjsify/stream": "^0.
|
|
80
|
-
"@gjsify/url": "^0.
|
|
81
|
-
"@gjsify/utils": "^0.
|
|
78
|
+
"@gjsify/buffer": "^0.27.0",
|
|
79
|
+
"@gjsify/events": "^0.27.0",
|
|
80
|
+
"@gjsify/stream": "^0.27.0",
|
|
81
|
+
"@gjsify/url": "^0.27.0",
|
|
82
|
+
"@gjsify/utils": "^0.27.0"
|
|
82
83
|
},
|
|
83
84
|
"gjsify": {
|
|
84
85
|
"runtimes": {
|