@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 +6 -6
- package/dist/buffer.d.ts +3 -3
- package/dist/buffer.mjs +1 -1
- package/dist/registry.cjs +45 -45
- package/dist/registry.d.ts +8 -0
- package/dist/registry.mjs +1 -1
- package/package.json +6 -6
package/dist/buffer.cjs
CHANGED
|
@@ -3,28 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
15
|
+
const l = r => {
|
|
16
16
|
const {
|
|
17
|
-
values:
|
|
18
|
-
tokens:
|
|
17
|
+
values: e,
|
|
18
|
+
tokens: n
|
|
19
19
|
} = (0, _nodeUtil.parseArgs)({
|
|
20
|
-
args:
|
|
20
|
+
args: r,
|
|
21
21
|
strict: !1,
|
|
22
22
|
tokens: !0
|
|
23
23
|
});
|
|
24
24
|
let o = null;
|
|
25
|
-
for (let
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
if (
|
|
29
|
-
o = typeof
|
|
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 (
|
|
32
|
+
if (t.kind !== "positional") {
|
|
33
33
|
o = null;
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
|
-
o && (o.name in
|
|
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
|
|
38
|
+
return e;
|
|
39
39
|
};
|
|
40
|
-
const tokenizeArgs =
|
|
41
|
-
const
|
|
42
|
-
let
|
|
40
|
+
const tokenizeArgs = r => {
|
|
41
|
+
const e = [];
|
|
42
|
+
let n = !1,
|
|
43
43
|
o = !0;
|
|
44
|
-
for (let
|
|
45
|
-
let
|
|
46
|
-
if (
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
} else if (
|
|
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 (
|
|
53
|
-
|
|
52
|
+
} else if (t === '"') {
|
|
53
|
+
n = !n;
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
|
-
o ? (
|
|
56
|
+
o ? (e.push(t), o = !1) : e[e.length - 1] += t;
|
|
57
57
|
}
|
|
58
|
-
if (
|
|
59
|
-
return
|
|
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(
|
|
64
|
-
return Object.entries(
|
|
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
|
|
68
|
-
if (
|
|
69
|
-
const
|
|
70
|
-
return delete
|
|
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
|
|
74
|
-
return Object.keys(
|
|
73
|
+
const r = getParsedNodeOptionsWithoutInspect();
|
|
74
|
+
return Object.keys(r).length === 0 ? "" : formatNodeOptions(r);
|
|
75
75
|
}
|
|
76
|
-
async function getRegistry(
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
o =
|
|
80
|
-
let
|
|
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
|
|
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
|
-
|
|
89
|
-
} catch (
|
|
90
|
-
throw new Error(`Failed to get registry from "${
|
|
91
|
-
cause:
|
|
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
|
|
94
|
+
return i;
|
|
95
95
|
}
|
package/dist/registry.d.ts
CHANGED
|
@@ -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
|
|
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.
|
|
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.
|
|
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.
|
|
27
|
-
"@stryke/type-checks": "^0.3.
|
|
28
|
-
"@stryke/types": "^0.8.
|
|
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": "
|
|
340
|
+
"gitHead": "9ad3e3608ebc05bf2f02848ad83d50f5476c9f6f"
|
|
341
341
|
}
|