@stryke/fs 0.23.0 → 0.23.1

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/dist/buffer.cjs CHANGED
@@ -3,28 +3,28 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.readBufferFile = readBufferFile;
7
- exports.readBufferFileSync = readBufferFileSync;
8
- exports.writeBufferFile = writeBufferFile;
6
+ exports.readFileBuffer = readFileBuffer;
7
+ exports.readFileBufferSync = readFileBufferSync;
8
+ exports.writeFileBuffer = writeFileBuffer;
9
9
  exports.writeFileBufferSync = writeFileBufferSync;
10
10
  var _path = require("@stryke/path");
11
11
  var _nodeBuffer = require("node:buffer");
12
12
  var _nodeFs = require("node:fs");
13
13
  var _promises = require("node:fs/promises");
14
14
  var _helpers = require("./helpers.cjs");
15
- async function readBufferFile(r) {
15
+ async function readFileBuffer(r) {
16
16
  if (!r) throw new Error("No file path provided to read data");
17
17
  if (!(0, _nodeFs.existsSync)(r)) throw new Error(`File does not exist at path: ${r}`);
18
18
  const e = await (0, _promises.readFile)(r);
19
19
  return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
20
20
  }
21
- function readBufferFileSync(r) {
21
+ function readFileBufferSync(r) {
22
22
  if (!r) throw new Error("No file path provided to read data");
23
23
  if (!(0, _nodeFs.existsSync)(r)) throw new Error(`File does not exist at path: ${r}`);
24
24
  const e = (0, _nodeFs.readFileSync)(r);
25
25
  return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
26
26
  }
27
- async function writeBufferFile(r, e) {
27
+ async function writeFileBuffer(r, e) {
28
28
  if (!r) throw new Error("No file path provided to write data");
29
29
  (0, _nodeFs.existsSync)((0, _path.findFilePath)(r)) || (await (0, _helpers.createDirectory)((0, _path.findFilePath)(r))), await (0, _promises.writeFile)(r, _nodeBuffer.Buffer.from(e));
30
30
  }
package/dist/buffer.d.ts CHANGED
@@ -4,21 +4,21 @@
4
4
  * @param filePath - The path to the file to read.
5
5
  * @returns The content of the file as an ArrayBuffer.
6
6
  */
7
- export declare function readBufferFile(filePath: string): Promise<ArrayBuffer>;
7
+ export declare function readFileBuffer(filePath: string): Promise<ArrayBuffer>;
8
8
  /**
9
9
  * Reads a file from the given path and returns its content as an ArrayBuffer. The file is expected to be located relative to the current directory of this module.
10
10
  *
11
11
  * @param filePath - The path to the file to read.
12
12
  * @returns The content of the file as an ArrayBuffer.
13
13
  */
14
- export declare function readBufferFileSync(filePath: string): ArrayBuffer;
14
+ export declare function readFileBufferSync(filePath: string): ArrayBuffer;
15
15
  /**
16
16
  * Writes an ArrayBuffer to a file at the specified path.
17
17
  *
18
18
  * @param filePath - The path to the file where the data should be written.
19
19
  * @param data - The ArrayBuffer containing the data to write.
20
20
  */
21
- export declare function writeBufferFile(filePath: string, data: ArrayBuffer): Promise<void>;
21
+ export declare function writeFileBuffer(filePath: string, data: ArrayBuffer): Promise<void>;
22
22
  /**
23
23
  * Writes an ArrayBuffer to a file at the specified path.
24
24
  *
package/dist/buffer.mjs CHANGED
@@ -1 +1 @@
1
- import{findFilePath as t}from"@stryke/path";import{Buffer as i}from"node:buffer";import{existsSync as o,readFileSync as f,writeFileSync as n}from"node:fs";import{readFile as a,writeFile as s}from"node:fs/promises";import{createDirectory as d,createDirectorySync as w}from"./helpers";export async function readBufferFile(r){if(!r)throw new Error("No file path provided to read data");if(!o(r))throw new Error(`File does not exist at path: ${r}`);const e=await a(r);return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}export function readBufferFileSync(r){if(!r)throw new Error("No file path provided to read data");if(!o(r))throw new Error(`File does not exist at path: ${r}`);const e=f(r);return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}export async function writeBufferFile(r,e){if(!r)throw new Error("No file path provided to write data");o(t(r))||await d(t(r)),await s(r,i.from(e))}export function writeFileBufferSync(r,e){if(!r)throw new Error("No file path provided to write data");o(t(r))||w(t(r)),n(r,i.from(e))}
1
+ import{findFilePath as t}from"@stryke/path";import{Buffer as i}from"node:buffer";import{existsSync as o,readFileSync as f,writeFileSync as n}from"node:fs";import{readFile as a,writeFile as s}from"node:fs/promises";import{createDirectory as d,createDirectorySync as w}from"./helpers";export async function readFileBuffer(r){if(!r)throw new Error("No file path provided to read data");if(!o(r))throw new Error(`File does not exist at path: ${r}`);const e=await a(r);return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}export function readFileBufferSync(r){if(!r)throw new Error("No file path provided to read data");if(!o(r))throw new Error(`File does not exist at path: ${r}`);const e=f(r);return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}export async function writeFileBuffer(r,e){if(!r)throw new Error("No file path provided to write data");o(t(r))||await d(t(r)),await s(r,i.from(e))}export function writeFileBufferSync(r,e){if(!r)throw new Error("No file path provided to write data");o(t(r))||w(t(r)),n(r,i.from(e))}
package/dist/registry.cjs CHANGED
@@ -12,84 +12,84 @@ var _installPkg = require("@antfu/install-pkg");
12
12
  var _getWorkspaceRoot = require("@stryke/path/get-workspace-root");
13
13
  var _nodeChild_process = require("node:child_process");
14
14
  var _nodeUtil = require("node:util");
15
- const l = n => {
15
+ const l = r => {
16
16
  const {
17
- values: t,
18
- tokens: r
17
+ values: e,
18
+ tokens: n
19
19
  } = (0, _nodeUtil.parseArgs)({
20
- args: n,
20
+ args: r,
21
21
  strict: !1,
22
22
  tokens: !0
23
23
  });
24
24
  let o = null;
25
- for (let s = 0; s < r.length; s++) {
26
- const e = r[s];
27
- if (e.kind === "option-terminator") break;
28
- if (e.kind === "option") {
29
- o = typeof e.value > "u" ? e : null;
25
+ for (let i = 0; i < n.length; i++) {
26
+ const t = n[i];
27
+ if (t.kind === "option-terminator") break;
28
+ if (t.kind === "option") {
29
+ o = typeof t.value > "u" ? t : null;
30
30
  continue;
31
31
  }
32
- if (e.kind !== "positional") {
32
+ if (t.kind !== "positional") {
33
33
  o = null;
34
34
  continue;
35
35
  }
36
- o && (o.name in t && typeof t[o.name] == "string" ? t[o.name] += ` ${e.value}` : t[o.name] = e.value);
36
+ o && (o.name in e && typeof e[o.name] == "string" ? e[o.name] += ` ${t.value}` : e[o.name] = t.value);
37
37
  }
38
- return t;
38
+ return e;
39
39
  };
40
- const tokenizeArgs = n => {
41
- const t = [];
42
- let r = !1,
40
+ const tokenizeArgs = r => {
41
+ const e = [];
42
+ let n = !1,
43
43
  o = !0;
44
- for (let s = 0; s < n.length; s++) {
45
- let e = n[s];
46
- if (e === "\\" && r) {
47
- if (n.length === s + 1) throw new Error("Invalid escape character at the end.");
48
- e = n[++s];
49
- } else if (e === " " && !r) {
44
+ for (let i = 0; i < r.length; i++) {
45
+ let t = r[i];
46
+ if (t === "\\" && n) {
47
+ if (r.length === i + 1) throw new Error("Invalid escape character at the end.");
48
+ t = r[++i];
49
+ } else if (t === " " && !n) {
50
50
  o = !0;
51
51
  continue;
52
- } else if (e === '"') {
53
- r = !r;
52
+ } else if (t === '"') {
53
+ n = !n;
54
54
  continue;
55
55
  }
56
- o ? (t.push(e), o = !1) : t[t.length - 1] += e;
56
+ o ? (e.push(t), o = !1) : e[e.length - 1] += t;
57
57
  }
58
- if (r) throw new Error("Unterminated string");
59
- return t;
58
+ if (n) throw new Error("Unterminated string");
59
+ return e;
60
60
  };
61
61
  exports.tokenizeArgs = tokenizeArgs;
62
62
  const f = () => process.env.NODE_OPTIONS ? tokenizeArgs(process.env.NODE_OPTIONS) : [];
63
- function formatNodeOptions(n) {
64
- return Object.entries(n).map(([t, r]) => r === !0 ? `--${t}` : r ? `--${t}=${r.includes(" ") && !r.startsWith('"') ? JSON.stringify(r) : r}` : null).filter(t => t !== null).join(" ");
63
+ function formatNodeOptions(r) {
64
+ return Object.entries(r).map(([e, n]) => n === !0 ? `--${e}` : n ? `--${e}=${n.includes(" ") && !n.startsWith('"') ? JSON.stringify(n) : n}` : null).filter(e => e !== null).join(" ");
65
65
  }
66
66
  function getParsedNodeOptionsWithoutInspect() {
67
- const n = f();
68
- if (n.length === 0) return {};
69
- const t = l(n);
70
- return delete t.inspect, delete t["inspect-brk"], delete t.inspect_brk, t;
67
+ const r = f();
68
+ if (r.length === 0) return {};
69
+ const e = l(r);
70
+ return delete e.inspect, delete e["inspect-brk"], delete e.inspect_brk, e;
71
71
  }
72
72
  function getFormattedNodeOptionsWithoutInspect() {
73
- const n = getParsedNodeOptionsWithoutInspect();
74
- return Object.keys(n).length === 0 ? "" : formatNodeOptions(n);
73
+ const r = getParsedNodeOptionsWithoutInspect();
74
+ return Object.keys(r).length === 0 ? "" : formatNodeOptions(r);
75
75
  }
76
- async function getRegistry(n) {
77
- const t = (0, _getWorkspaceRoot.getWorkspaceRoot)(n),
78
- r = await (0, _installPkg.detectPackageManager)(t),
79
- o = r === "npm" ? "--no-workspaces" : "";
80
- let s = "https://registry.npmjs.org/";
76
+ async function getRegistry(r) {
77
+ const e = (0, _getWorkspaceRoot.getWorkspaceRoot)(r),
78
+ n = await (0, _installPkg.detectPackageManager)(e),
79
+ o = n === "npm" ? "--no-workspaces" : "";
80
+ let i = "https://registry.npmjs.org/";
81
81
  try {
82
- const e = (0, _nodeChild_process.execSync)(`${r} config get registry ${o}`, {
82
+ const t = (0, _nodeChild_process.execSync)(`${n} config get registry ${o}`, {
83
83
  env: {
84
84
  ...process.env,
85
85
  NODE_OPTIONS: getFormattedNodeOptionsWithoutInspect()
86
86
  }
87
87
  }).toString().trim();
88
- e.startsWith("http") && (s = e.endsWith("/") ? e : `${e}/`);
89
- } catch (e) {
90
- throw new Error(`Failed to get registry from "${r}".`, {
91
- cause: e
88
+ t.startsWith("http") && (i = t.endsWith("/") ? t : `${t}/`);
89
+ } catch (t) {
90
+ throw new Error(`Failed to get registry from "${n}".`, {
91
+ cause: t
92
92
  });
93
93
  }
94
- return s;
94
+ return i;
95
95
  }
@@ -1,3 +1,11 @@
1
+ export interface NodeOptionsToken {
2
+ kind: "option";
3
+ index: number;
4
+ name: string;
5
+ rawName: string;
6
+ value: undefined;
7
+ inlineValue: undefined;
8
+ }
1
9
  /**
2
10
  * Tokenizes the arguments string into an array of strings, supporting quoted
3
11
  * values and escaped characters.
package/dist/registry.mjs CHANGED
@@ -1 +1 @@
1
- import{detectPackageManager as i}from"@antfu/install-pkg";import{getWorkspaceRoot as c}from"@stryke/path/get-workspace-root";import{execSync as a}from"node:child_process";import{parseArgs as g}from"node:util";const l=n=>{const{values:t,tokens:r}=g({args:n,strict:!1,tokens:!0});let o=null;for(let s=0;s<r.length;s++){const e=r[s];if(e.kind==="option-terminator")break;if(e.kind==="option"){o=typeof e.value>"u"?e:null;continue}if(e.kind!=="positional"){o=null;continue}o&&(o.name in t&&typeof t[o.name]=="string"?t[o.name]+=` ${e.value}`:t[o.name]=e.value)}return t};export const tokenizeArgs=n=>{const t=[];let r=!1,o=!0;for(let s=0;s<n.length;s++){let e=n[s];if(e==="\\"&&r){if(n.length===s+1)throw new Error("Invalid escape character at the end.");e=n[++s]}else if(e===" "&&!r){o=!0;continue}else if(e==='"'){r=!r;continue}o?(t.push(e),o=!1):t[t.length-1]+=e}if(r)throw new Error("Unterminated string");return t};const f=()=>process.env.NODE_OPTIONS?tokenizeArgs(process.env.NODE_OPTIONS):[];export function formatNodeOptions(n){return Object.entries(n).map(([t,r])=>r===!0?`--${t}`:r?`--${t}=${r.includes(" ")&&!r.startsWith('"')?JSON.stringify(r):r}`:null).filter(t=>t!==null).join(" ")}export function getParsedNodeOptionsWithoutInspect(){const n=f();if(n.length===0)return{};const t=l(n);return delete t.inspect,delete t["inspect-brk"],delete t.inspect_brk,t}export function getFormattedNodeOptionsWithoutInspect(){const n=getParsedNodeOptionsWithoutInspect();return Object.keys(n).length===0?"":formatNodeOptions(n)}export async function getRegistry(n){const t=c(n),r=await i(t),o=r==="npm"?"--no-workspaces":"";let s="https://registry.npmjs.org/";try{const e=a(`${r} config get registry ${o}`,{env:{...process.env,NODE_OPTIONS:getFormattedNodeOptionsWithoutInspect()}}).toString().trim();e.startsWith("http")&&(s=e.endsWith("/")?e:`${e}/`)}catch(e){throw new Error(`Failed to get registry from "${r}".`,{cause:e})}return s}
1
+ import{detectPackageManager as s}from"@antfu/install-pkg";import{getWorkspaceRoot as a}from"@stryke/path/get-workspace-root";import{execSync as c}from"node:child_process";import{parseArgs as g}from"node:util";const l=r=>{const{values:e,tokens:n}=g({args:r,strict:!1,tokens:!0});let o=null;for(let i=0;i<n.length;i++){const t=n[i];if(t.kind==="option-terminator")break;if(t.kind==="option"){o=typeof t.value>"u"?t:null;continue}if(t.kind!=="positional"){o=null;continue}o&&(o.name in e&&typeof e[o.name]=="string"?e[o.name]+=` ${t.value}`:e[o.name]=t.value)}return e};export const tokenizeArgs=r=>{const e=[];let n=!1,o=!0;for(let i=0;i<r.length;i++){let t=r[i];if(t==="\\"&&n){if(r.length===i+1)throw new Error("Invalid escape character at the end.");t=r[++i]}else if(t===" "&&!n){o=!0;continue}else if(t==='"'){n=!n;continue}o?(e.push(t),o=!1):e[e.length-1]+=t}if(n)throw new Error("Unterminated string");return e};const f=()=>process.env.NODE_OPTIONS?tokenizeArgs(process.env.NODE_OPTIONS):[];export function formatNodeOptions(r){return Object.entries(r).map(([e,n])=>n===!0?`--${e}`:n?`--${e}=${n.includes(" ")&&!n.startsWith('"')?JSON.stringify(n):n}`:null).filter(e=>e!==null).join(" ")}export function getParsedNodeOptionsWithoutInspect(){const r=f();if(r.length===0)return{};const e=l(r);return delete e.inspect,delete e["inspect-brk"],delete e.inspect_brk,e}export function getFormattedNodeOptionsWithoutInspect(){const r=getParsedNodeOptionsWithoutInspect();return Object.keys(r).length===0?"":formatNodeOptions(r)}export async function getRegistry(r){const e=a(r),n=await s(e),o=n==="npm"?"--no-workspaces":"";let i="https://registry.npmjs.org/";try{const t=c(`${n} config get registry ${o}`,{env:{...process.env,NODE_OPTIONS:getFormattedNodeOptionsWithoutInspect()}}).toString().trim();t.startsWith("http")&&(i=t.endsWith("/")?t:`${t}/`)}catch(t){throw new Error(`Failed to get registry from "${n}".`,{cause:t})}return i}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "type": "module",
5
5
  "description": "A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.",
6
6
  "repository": {
@@ -15,7 +15,7 @@
15
15
  "@antfu/install-pkg": "^1.0.0",
16
16
  "@ltd/j-toml": "^1.38.0",
17
17
  "@stryke/convert": "^0.3.1",
18
- "@stryke/path": "^0.12.1",
18
+ "@stryke/path": "^0.12.2",
19
19
  "@zkochan/js-yaml": "^0.0.7",
20
20
  "chalk": "^5.4.1",
21
21
  "defu": "^6.1.4",
@@ -23,9 +23,9 @@
23
23
  "mlly": "1.7.4",
24
24
  "nanotar": "^0.2.0",
25
25
  "semver": "7.7.1",
26
- "@stryke/json": "^0.9.2",
27
- "@stryke/type-checks": "^0.3.6",
28
- "@stryke/types": "^0.8.6"
26
+ "@stryke/json": "^0.9.3",
27
+ "@stryke/type-checks": "^0.3.7",
28
+ "@stryke/types": "^0.8.7"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^22.14.0",
@@ -337,5 +337,5 @@
337
337
  "main": "./dist/index.cjs",
338
338
  "module": "./dist/index.mjs",
339
339
  "types": "./dist/index.d.ts",
340
- "gitHead": "57da58e3434302b35f798674d9f18f92ca7f7ac9"
340
+ "gitHead": "9ad3e3608ebc05bf2f02848ad83d50f5476c9f6f"
341
341
  }