@stryke/fs 0.33.31 → 0.33.33
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/CHANGELOG.md +18 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -1
- package/dist/buffer.cjs +60 -1
- package/dist/buffer.mjs +56 -1
- package/dist/buffer.mjs.map +1 -1
- package/dist/chmod-x.cjs +93 -1
- package/dist/chmod-x.d.cts.map +1 -1
- package/dist/chmod-x.mjs +87 -1
- package/dist/chmod-x.mjs.map +1 -1
- package/dist/command-exists.cjs +102 -1
- package/dist/command-exists.mjs +100 -1
- package/dist/command-exists.mjs.map +1 -1
- package/dist/compress.cjs +29 -1
- package/dist/compress.mjs +28 -1
- package/dist/compress.mjs.map +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/convert/src/array-buffer-to-string.cjs +19 -1
- package/dist/convert/src/array-buffer-to-string.mjs +18 -1
- package/dist/convert/src/array-buffer-to-string.mjs.map +1 -1
- package/dist/convert/src/to-array.cjs +15 -1
- package/dist/convert/src/to-array.mjs +14 -1
- package/dist/convert/src/to-array.mjs.map +1 -1
- package/dist/convert/src/uint8-array-to-string.cjs +15 -1
- package/dist/convert/src/uint8-array-to-string.mjs +15 -1
- package/dist/convert/src/uint8-array-to-string.mjs.map +1 -1
- package/dist/copy-file.cjs +87 -1
- package/dist/copy-file.mjs +83 -1
- package/dist/copy-file.mjs.map +1 -1
- package/dist/exists.cjs +27 -1
- package/dist/exists.mjs +25 -1
- package/dist/exists.mjs.map +1 -1
- package/dist/get-parent-path.cjs +35 -1
- package/dist/get-parent-path.mjs +34 -1
- package/dist/get-parent-path.mjs.map +1 -1
- package/dist/get-workspace-root.cjs +158 -1
- package/dist/get-workspace-root.mjs +150 -1
- package/dist/get-workspace-root.mjs.map +1 -1
- package/dist/helpers/src/get-unique.cjs +14 -1
- package/dist/helpers/src/get-unique.mjs +13 -1
- package/dist/helpers/src/get-unique.mjs.map +1 -1
- package/dist/helpers.cjs +83 -1
- package/dist/helpers.mjs +77 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +122 -1
- package/dist/index.mjs +25 -1
- package/dist/install.cjs +35 -1
- package/dist/install.mjs +33 -1
- package/dist/install.mjs.map +1 -1
- package/dist/is-file.cjs +51 -1
- package/dist/is-file.mjs +47 -1
- package/dist/is-file.mjs.map +1 -1
- package/dist/json/src/storm-json.cjs +117 -1
- package/dist/json/src/storm-json.mjs +115 -1
- package/dist/json/src/storm-json.mjs.map +1 -1
- package/dist/json/src/utils/code-frames.cjs +77 -3
- package/dist/json/src/utils/code-frames.mjs +76 -3
- package/dist/json/src/utils/code-frames.mjs.map +1 -1
- package/dist/json/src/utils/parse-error.cjs +34 -1
- package/dist/json/src/utils/parse-error.mjs +33 -1
- package/dist/json/src/utils/parse-error.mjs.map +1 -1
- package/dist/json/src/utils/parse.cjs +45 -1
- package/dist/json/src/utils/parse.mjs +45 -1
- package/dist/json/src/utils/parse.mjs.map +1 -1
- package/dist/json/src/utils/stringify.cjs +67 -1
- package/dist/json/src/utils/stringify.mjs +67 -1
- package/dist/json/src/utils/stringify.mjs.map +1 -1
- package/dist/json/src/utils/strip-comments.cjs +86 -4
- package/dist/json/src/utils/strip-comments.mjs +86 -4
- package/dist/json/src/utils/strip-comments.mjs.map +1 -1
- package/dist/json.cjs +74 -1
- package/dist/json.mjs +71 -1
- package/dist/json.mjs.map +1 -1
- package/dist/list-files.cjs +86 -1
- package/dist/list-files.mjs +79 -1
- package/dist/list-files.mjs.map +1 -1
- package/dist/package-fns.cjs +148 -1
- package/dist/package-fns.mjs +141 -1
- package/dist/package-fns.mjs.map +1 -1
- package/dist/path/src/append.cjs +57 -1
- package/dist/path/src/append.mjs +56 -1
- package/dist/path/src/append.mjs.map +1 -1
- package/dist/path/src/correct-path.cjs +138 -1
- package/dist/path/src/correct-path.mjs +134 -1
- package/dist/path/src/correct-path.mjs.map +1 -1
- package/dist/path/src/cwd.cjs +17 -1
- package/dist/path/src/cwd.mjs +16 -1
- package/dist/path/src/cwd.mjs.map +1 -1
- package/dist/path/src/file-path-fns.cjs +169 -1
- package/dist/path/src/file-path-fns.mjs +164 -1
- package/dist/path/src/file-path-fns.mjs.map +1 -1
- package/dist/path/src/is-parent-path.cjs +32 -1
- package/dist/path/src/is-parent-path.mjs +32 -1
- package/dist/path/src/is-parent-path.mjs.map +1 -1
- package/dist/path/src/is-root-dir.cjs +14 -1
- package/dist/path/src/is-root-dir.mjs +13 -1
- package/dist/path/src/is-root-dir.mjs.map +1 -1
- package/dist/path/src/is-type.cjs +68 -1
- package/dist/path/src/is-type.mjs +66 -1
- package/dist/path/src/is-type.mjs.map +1 -1
- package/dist/path/src/join-paths.cjs +106 -1
- package/dist/path/src/join-paths.mjs +106 -1
- package/dist/path/src/join-paths.mjs.map +1 -1
- package/dist/path/src/regex.cjs +18 -1
- package/dist/path/src/regex.mjs +11 -1
- package/dist/path/src/regex.mjs.map +1 -1
- package/dist/path/src/replace.cjs +24 -1
- package/dist/path/src/replace.mjs +24 -1
- package/dist/path/src/replace.mjs.map +1 -1
- package/dist/path/src/resolve-parent-path.cjs +18 -1
- package/dist/path/src/resolve-parent-path.mjs +18 -1
- package/dist/path/src/resolve-parent-path.mjs.map +1 -1
- package/dist/path/src/slash.cjs +15 -1
- package/dist/path/src/slash.mjs +14 -1
- package/dist/path/src/slash.mjs.map +1 -1
- package/dist/read-file.cjs +47 -1
- package/dist/read-file.mjs +43 -1
- package/dist/read-file.mjs.map +1 -1
- package/dist/registry.cjs +142 -1
- package/dist/registry.mjs +137 -1
- package/dist/registry.mjs.map +1 -1
- package/dist/remove-file.cjs +27 -1
- package/dist/remove-file.mjs +25 -1
- package/dist/remove-file.mjs.map +1 -1
- package/dist/resolve.cjs +228 -3
- package/dist/resolve.mjs +217 -3
- package/dist/resolve.mjs.map +1 -1
- package/dist/semver-fns.cjs +129 -1
- package/dist/semver-fns.mjs +119 -1
- package/dist/semver-fns.mjs.map +1 -1
- package/dist/string-format/src/package.cjs +92 -1
- package/dist/string-format/src/package.mjs +91 -1
- package/dist/string-format/src/package.mjs.map +1 -1
- package/dist/toml.cjs +66 -3
- package/dist/toml.mjs +61 -3
- package/dist/toml.mjs.map +1 -1
- package/dist/tsconfig.cjs +37 -1
- package/dist/tsconfig.mjs +35 -1
- package/dist/tsconfig.mjs.map +1 -1
- package/dist/type-checks/src/get-object-tag.cjs +15 -1
- package/dist/type-checks/src/get-object-tag.mjs +14 -1
- package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
- package/dist/type-checks/src/index.cjs +14 -1
- package/dist/type-checks/src/index.mjs +16 -1
- package/dist/type-checks/src/is-buffer.cjs +12 -1
- package/dist/type-checks/src/is-buffer.mjs +11 -1
- package/dist/type-checks/src/is-buffer.mjs.map +1 -1
- package/dist/type-checks/src/is-collection.cjs +1 -1
- package/dist/type-checks/src/is-collection.mjs +3 -1
- package/dist/type-checks/src/is-empty.cjs +20 -1
- package/dist/type-checks/src/is-empty.mjs +20 -1
- package/dist/type-checks/src/is-empty.mjs.map +1 -1
- package/dist/type-checks/src/is-error.cjs +29 -1
- package/dist/type-checks/src/is-error.mjs +29 -1
- package/dist/type-checks/src/is-error.mjs.map +1 -1
- package/dist/type-checks/src/is-null.cjs +12 -1
- package/dist/type-checks/src/is-null.mjs +11 -1
- package/dist/type-checks/src/is-null.mjs.map +1 -1
- package/dist/type-checks/src/is-number.cjs +18 -1
- package/dist/type-checks/src/is-number.mjs +17 -1
- package/dist/type-checks/src/is-number.mjs.map +1 -1
- package/dist/type-checks/src/is-object.cjs +19 -1
- package/dist/type-checks/src/is-object.mjs +19 -1
- package/dist/type-checks/src/is-object.mjs.map +1 -1
- package/dist/type-checks/src/is-plain-object.cjs +64 -1
- package/dist/type-checks/src/is-plain-object.mjs +63 -1
- package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
- package/dist/type-checks/src/is-set-string.cjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs.map +1 -1
- package/dist/type-checks/src/is-set.cjs +19 -1
- package/dist/type-checks/src/is-set.mjs +19 -1
- package/dist/type-checks/src/is-set.mjs.map +1 -1
- package/dist/type-checks/src/is-string.cjs +12 -1
- package/dist/type-checks/src/is-string.mjs +11 -1
- package/dist/type-checks/src/is-string.mjs.map +1 -1
- package/dist/type-checks/src/is-undefined.cjs +8 -1
- package/dist/type-checks/src/is-undefined.mjs +7 -1
- package/dist/type-checks/src/is-undefined.mjs.map +1 -1
- package/dist/type-checks/src/type-detect.cjs +15 -1
- package/dist/type-checks/src/type-detect.mjs +16 -1
- package/dist/type-checks/src/type-detect.mjs.map +1 -1
- package/dist/types/src/base.cjs +6 -1
- package/dist/types/src/base.mjs +5 -1
- package/dist/types/src/base.mjs.map +1 -1
- package/dist/write-file.cjs +40 -1
- package/dist/write-file.mjs +38 -1
- package/dist/write-file.mjs.map +1 -1
- package/dist/yaml.cjs +29 -1
- package/dist/yaml.mjs +27 -1
- package/dist/yaml.mjs.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Stryke - Fs
|
|
4
4
|
|
|
5
|
+
## [0.33.32](https://github.com/storm-software/stryke/releases/tag/fs%400.33.32) (01/16/2026)
|
|
6
|
+
|
|
7
|
+
### Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated **path** to **v0.25.0**
|
|
10
|
+
|
|
11
|
+
## [0.33.31](https://github.com/storm-software/stryke/releases/tag/fs%400.33.31) (01/16/2026)
|
|
12
|
+
|
|
13
|
+
### Updated Dependencies
|
|
14
|
+
|
|
15
|
+
- Updated **string-format** to **v0.13.2**
|
|
16
|
+
- Updated **type-checks** to **v0.5.18**
|
|
17
|
+
- Updated **convert** to **v0.6.33**
|
|
18
|
+
- Updated **helpers** to **v0.9.35**
|
|
19
|
+
- Updated **types** to **v0.10.32**
|
|
20
|
+
- Updated **json** to **v0.9.36**
|
|
21
|
+
- Updated **path** to **v0.24.4**
|
|
22
|
+
|
|
5
23
|
## [0.33.30](https://github.com/storm-software/stryke/releases/tag/fs%400.33.30) (01/15/2026)
|
|
6
24
|
|
|
7
25
|
### Updated Dependencies
|
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
package/dist/buffer.cjs
CHANGED
|
@@ -1 +1,60 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_file_path_fns = require('./path/src/file-path-fns.cjs');
|
|
3
|
+
const require_helpers = require('./helpers.cjs');
|
|
4
|
+
let node_buffer = require("node:buffer");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
let node_fs_promises = require("node:fs/promises");
|
|
7
|
+
|
|
8
|
+
//#region src/buffer.ts
|
|
9
|
+
/**
|
|
10
|
+
* 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.
|
|
11
|
+
*
|
|
12
|
+
* @param filePath - The path to the file to read.
|
|
13
|
+
* @returns The content of the file as an ArrayBuffer.
|
|
14
|
+
*/
|
|
15
|
+
async function readFileBuffer(filePath) {
|
|
16
|
+
if (!filePath) throw new Error("No file path provided to read data");
|
|
17
|
+
if (!(0, node_fs.existsSync)(filePath)) throw new Error(`File does not exist at path: ${filePath}`);
|
|
18
|
+
const b = await (0, node_fs_promises.readFile)(filePath);
|
|
19
|
+
return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 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.
|
|
23
|
+
*
|
|
24
|
+
* @param filePath - The path to the file to read.
|
|
25
|
+
* @returns The content of the file as an ArrayBuffer.
|
|
26
|
+
*/
|
|
27
|
+
function readFileBufferSync(filePath) {
|
|
28
|
+
if (!filePath) throw new Error("No file path provided to read data");
|
|
29
|
+
if (!(0, node_fs.existsSync)(filePath)) throw new Error(`File does not exist at path: ${filePath}`);
|
|
30
|
+
const b = (0, node_fs.readFileSync)(filePath);
|
|
31
|
+
return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Writes an ArrayBuffer to a file at the specified path.
|
|
35
|
+
*
|
|
36
|
+
* @param filePath - The path to the file where the data should be written.
|
|
37
|
+
* @param data - The ArrayBuffer containing the data to write.
|
|
38
|
+
*/
|
|
39
|
+
async function writeFileBuffer(filePath, data) {
|
|
40
|
+
if (!filePath) throw new Error("No file path provided to write data");
|
|
41
|
+
if (!(0, node_fs.existsSync)(require_file_path_fns.findFilePath(filePath))) await require_helpers.createDirectory(require_file_path_fns.findFilePath(filePath));
|
|
42
|
+
await (0, node_fs_promises.writeFile)(filePath, node_buffer.Buffer.from(data));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Writes an ArrayBuffer to a file at the specified path.
|
|
46
|
+
*
|
|
47
|
+
* @param filePath - The path to the file where the data should be written.
|
|
48
|
+
* @param data - The ArrayBuffer containing the data to write.
|
|
49
|
+
*/
|
|
50
|
+
function writeFileBufferSync(filePath, data) {
|
|
51
|
+
if (!filePath) throw new Error("No file path provided to write data");
|
|
52
|
+
if (!(0, node_fs.existsSync)(require_file_path_fns.findFilePath(filePath))) require_helpers.createDirectorySync(require_file_path_fns.findFilePath(filePath));
|
|
53
|
+
(0, node_fs.writeFileSync)(filePath, node_buffer.Buffer.from(data));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
exports.readFileBuffer = readFileBuffer;
|
|
58
|
+
exports.readFileBufferSync = readFileBufferSync;
|
|
59
|
+
exports.writeFileBuffer = writeFileBuffer;
|
|
60
|
+
exports.writeFileBufferSync = writeFileBufferSync;
|
package/dist/buffer.mjs
CHANGED
|
@@ -1,2 +1,57 @@
|
|
|
1
|
-
import{findFilePath
|
|
1
|
+
import { findFilePath } from "./path/src/file-path-fns.mjs";
|
|
2
|
+
import { createDirectory, createDirectorySync } from "./helpers.mjs";
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
6
|
+
|
|
7
|
+
//#region src/buffer.ts
|
|
8
|
+
/**
|
|
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
|
+
*
|
|
11
|
+
* @param filePath - The path to the file to read.
|
|
12
|
+
* @returns The content of the file as an ArrayBuffer.
|
|
13
|
+
*/
|
|
14
|
+
async function readFileBuffer(filePath) {
|
|
15
|
+
if (!filePath) throw new Error("No file path provided to read data");
|
|
16
|
+
if (!existsSync(filePath)) throw new Error(`File does not exist at path: ${filePath}`);
|
|
17
|
+
const b = await readFile(filePath);
|
|
18
|
+
return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 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.
|
|
22
|
+
*
|
|
23
|
+
* @param filePath - The path to the file to read.
|
|
24
|
+
* @returns The content of the file as an ArrayBuffer.
|
|
25
|
+
*/
|
|
26
|
+
function readFileBufferSync(filePath) {
|
|
27
|
+
if (!filePath) throw new Error("No file path provided to read data");
|
|
28
|
+
if (!existsSync(filePath)) throw new Error(`File does not exist at path: ${filePath}`);
|
|
29
|
+
const b = readFileSync(filePath);
|
|
30
|
+
return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Writes an ArrayBuffer to a file at the specified path.
|
|
34
|
+
*
|
|
35
|
+
* @param filePath - The path to the file where the data should be written.
|
|
36
|
+
* @param data - The ArrayBuffer containing the data to write.
|
|
37
|
+
*/
|
|
38
|
+
async function writeFileBuffer(filePath, data) {
|
|
39
|
+
if (!filePath) throw new Error("No file path provided to write data");
|
|
40
|
+
if (!existsSync(findFilePath(filePath))) await createDirectory(findFilePath(filePath));
|
|
41
|
+
await writeFile(filePath, Buffer.from(data));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Writes an ArrayBuffer to a file at the specified path.
|
|
45
|
+
*
|
|
46
|
+
* @param filePath - The path to the file where the data should be written.
|
|
47
|
+
* @param data - The ArrayBuffer containing the data to write.
|
|
48
|
+
*/
|
|
49
|
+
function writeFileBufferSync(filePath, data) {
|
|
50
|
+
if (!filePath) throw new Error("No file path provided to write data");
|
|
51
|
+
if (!existsSync(findFilePath(filePath))) createDirectorySync(findFilePath(filePath));
|
|
52
|
+
writeFileSync(filePath, Buffer.from(data));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { readFileBuffer, readFileBufferSync, writeFileBuffer, writeFileBufferSync };
|
|
2
57
|
//# sourceMappingURL=buffer.mjs.map
|
package/dist/buffer.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.mjs","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { findFilePath } from \"@stryke/path\";\nimport { Buffer } from \"node:buffer\";\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { createDirectory, createDirectorySync } from \"./helpers\";\n\n/**\n * 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.\n *\n * @param filePath - The path to the file to read.\n * @returns The content of the file as an ArrayBuffer.\n */\nexport async function readFileBuffer(filePath: string): Promise<ArrayBuffer> {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n if (!existsSync(filePath)) {\n throw new Error(`File does not exist at path: ${filePath}`);\n }\n\n const b = await readFile(filePath);\n\n return b.buffer.slice(\n b.byteOffset,\n b.byteOffset + b.byteLength\n ) as ArrayBuffer;\n}\n\n/**\n * 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.\n *\n * @param filePath - The path to the file to read.\n * @returns The content of the file as an ArrayBuffer.\n */\nexport function readFileBufferSync(filePath: string): ArrayBuffer {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n if (!existsSync(filePath)) {\n throw new Error(`File does not exist at path: ${filePath}`);\n }\n\n const b = readFileSync(filePath);\n\n return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);\n}\n\n/**\n * Writes an ArrayBuffer to a file at the specified path.\n *\n * @param filePath - The path to the file where the data should be written.\n * @param data - The ArrayBuffer containing the data to write.\n */\nexport async function writeFileBuffer(filePath: string, data: ArrayBuffer) {\n if (!filePath) {\n throw new Error(\"No file path provided to write data\");\n }\n if (!existsSync(findFilePath(filePath))) {\n await createDirectory(findFilePath(filePath));\n }\n\n await writeFile(filePath, Buffer.from(data));\n}\n\n/**\n * Writes an ArrayBuffer to a file at the specified path.\n *\n * @param filePath - The path to the file where the data should be written.\n * @param data - The ArrayBuffer containing the data to write.\n */\nexport function writeFileBufferSync(filePath: string, data: ArrayBuffer) {\n if (!filePath) {\n throw new Error(\"No file path provided to write data\");\n }\n if (!existsSync(findFilePath(filePath))) {\n createDirectorySync(findFilePath(filePath));\n }\n\n writeFileSync(filePath, Buffer.from(data));\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"buffer.mjs","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { findFilePath } from \"@stryke/path\";\nimport { Buffer } from \"node:buffer\";\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { createDirectory, createDirectorySync } from \"./helpers\";\n\n/**\n * 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.\n *\n * @param filePath - The path to the file to read.\n * @returns The content of the file as an ArrayBuffer.\n */\nexport async function readFileBuffer(filePath: string): Promise<ArrayBuffer> {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n if (!existsSync(filePath)) {\n throw new Error(`File does not exist at path: ${filePath}`);\n }\n\n const b = await readFile(filePath);\n\n return b.buffer.slice(\n b.byteOffset,\n b.byteOffset + b.byteLength\n ) as ArrayBuffer;\n}\n\n/**\n * 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.\n *\n * @param filePath - The path to the file to read.\n * @returns The content of the file as an ArrayBuffer.\n */\nexport function readFileBufferSync(filePath: string): ArrayBuffer {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n if (!existsSync(filePath)) {\n throw new Error(`File does not exist at path: ${filePath}`);\n }\n\n const b = readFileSync(filePath);\n\n return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);\n}\n\n/**\n * Writes an ArrayBuffer to a file at the specified path.\n *\n * @param filePath - The path to the file where the data should be written.\n * @param data - The ArrayBuffer containing the data to write.\n */\nexport async function writeFileBuffer(filePath: string, data: ArrayBuffer) {\n if (!filePath) {\n throw new Error(\"No file path provided to write data\");\n }\n if (!existsSync(findFilePath(filePath))) {\n await createDirectory(findFilePath(filePath));\n }\n\n await writeFile(filePath, Buffer.from(data));\n}\n\n/**\n * Writes an ArrayBuffer to a file at the specified path.\n *\n * @param filePath - The path to the file where the data should be written.\n * @param data - The ArrayBuffer containing the data to write.\n */\nexport function writeFileBufferSync(filePath: string, data: ArrayBuffer) {\n if (!filePath) {\n throw new Error(\"No file path provided to write data\");\n }\n if (!existsSync(findFilePath(filePath))) {\n createDirectorySync(findFilePath(filePath));\n }\n\n writeFileSync(filePath, Buffer.from(data));\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,eAAsB,eAAe,UAAwC;AAC3E,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,qCAAqC;AAEvD,KAAI,CAAC,WAAW,SAAS,CACvB,OAAM,IAAI,MAAM,gCAAgC,WAAW;CAG7D,MAAM,IAAI,MAAM,SAAS,SAAS;AAElC,QAAO,EAAE,OAAO,MACd,EAAE,YACF,EAAE,aAAa,EAAE,WAClB;;;;;;;;AASH,SAAgB,mBAAmB,UAA+B;AAChE,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,qCAAqC;AAEvD,KAAI,CAAC,WAAW,SAAS,CACvB,OAAM,IAAI,MAAM,gCAAgC,WAAW;CAG7D,MAAM,IAAI,aAAa,SAAS;AAEhC,QAAO,EAAE,OAAO,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW;;;;;;;;AASlE,eAAsB,gBAAgB,UAAkB,MAAmB;AACzE,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,sCAAsC;AAExD,KAAI,CAAC,WAAW,aAAa,SAAS,CAAC,CACrC,OAAM,gBAAgB,aAAa,SAAS,CAAC;AAG/C,OAAM,UAAU,UAAU,OAAO,KAAK,KAAK,CAAC;;;;;;;;AAS9C,SAAgB,oBAAoB,UAAkB,MAAmB;AACvE,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,sCAAsC;AAExD,KAAI,CAAC,WAAW,aAAa,SAAS,CAAC,CACrC,qBAAoB,aAAa,SAAS,CAAC;AAG7C,eAAc,UAAU,OAAO,KAAK,KAAK,CAAC"}
|
package/dist/chmod-x.cjs
CHANGED
|
@@ -1 +1,93 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
let node_fs_promises = require("node:fs/promises");
|
|
4
|
+
|
|
5
|
+
//#region src/chmod-x.ts
|
|
6
|
+
/**
|
|
7
|
+
* Adds execute permissions to a file
|
|
8
|
+
*
|
|
9
|
+
* @param file - The file to add execute permissions to
|
|
10
|
+
*/
|
|
11
|
+
function chmodXSync(file) {
|
|
12
|
+
if (process.platform === "win32") return;
|
|
13
|
+
const s = (0, node_fs.statSync)(file);
|
|
14
|
+
const newMode = s.mode | 73;
|
|
15
|
+
if (s.mode === newMode) return;
|
|
16
|
+
(0, node_fs.chmodSync)(file, newMode.toString(8).slice(-3));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Adds execute permissions to a file
|
|
20
|
+
*
|
|
21
|
+
* @param file - The file to add execute permissions to
|
|
22
|
+
*/
|
|
23
|
+
async function chmodX(file) {
|
|
24
|
+
if (process.platform === "win32") return;
|
|
25
|
+
const s = (0, node_fs.statSync)(file);
|
|
26
|
+
const newMode = s.mode | 73;
|
|
27
|
+
if (s.mode === newMode) return;
|
|
28
|
+
return (0, node_fs_promises.chmod)(file, newMode.toString(8).slice(-3));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Checks the write permission of a file
|
|
32
|
+
*
|
|
33
|
+
* @param filename - The file to check the permission of
|
|
34
|
+
* @returns A promise that resolves to true if the file is writable, false otherwise
|
|
35
|
+
*/
|
|
36
|
+
async function isWritable(filename) {
|
|
37
|
+
try {
|
|
38
|
+
await (0, node_fs_promises.access)(filename, node_fs.constants.W_OK);
|
|
39
|
+
return true;
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Checks the write permission of a file
|
|
46
|
+
*
|
|
47
|
+
* @param filename - The file to check the permission of
|
|
48
|
+
* @returns True if the file is writable, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
function isWritableSync(filename) {
|
|
51
|
+
try {
|
|
52
|
+
(0, node_fs.accessSync)(filename, node_fs.constants.W_OK);
|
|
53
|
+
return true;
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks the execute permission of a file
|
|
60
|
+
*
|
|
61
|
+
* @param filename - The file to check the permission of
|
|
62
|
+
* @returns A promise that resolves to true if the file is executable, false otherwise
|
|
63
|
+
*/
|
|
64
|
+
async function isExecutable(filename) {
|
|
65
|
+
try {
|
|
66
|
+
await (0, node_fs_promises.access)(filename, node_fs.constants.X_OK);
|
|
67
|
+
return true;
|
|
68
|
+
} catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Checks the execute permission of a file
|
|
74
|
+
*
|
|
75
|
+
* @param filename - The file to check the permission of
|
|
76
|
+
* @returns True if the file is executable, false otherwise
|
|
77
|
+
*/
|
|
78
|
+
function isExecutableSync(filename) {
|
|
79
|
+
try {
|
|
80
|
+
(0, node_fs.accessSync)(filename, node_fs.constants.X_OK);
|
|
81
|
+
return true;
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.chmodX = chmodX;
|
|
89
|
+
exports.chmodXSync = chmodXSync;
|
|
90
|
+
exports.isExecutable = isExecutable;
|
|
91
|
+
exports.isExecutableSync = isExecutableSync;
|
|
92
|
+
exports.isWritable = isWritable;
|
|
93
|
+
exports.isWritableSync = isWritableSync;
|
package/dist/chmod-x.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chmod-x.d.cts","names":[],"sources":["../src/chmod-x.ts"],"sourcesContent":[],"mappings":";;AA0BA;AAuBA;AAwBA;AAeA;AAesB,iBA7EN,UAAA,CA6EsC,
|
|
1
|
+
{"version":3,"file":"chmod-x.d.cts","names":[],"sources":["../src/chmod-x.ts"],"sourcesContent":[],"mappings":";;AA0BA;AAuBA;AAwBA;AAeA;AAesB,iBA7EN,UAAA,CA6EsC,IAAA,EAAO,MAAA,CAAA,EAAA,IAAA;AAe7D;;;;;iBArEsB,MAAA,gBAAmB;;;;;;;iBAwBnB,UAAA,oBAA8B;;;;;;;iBAepC,cAAA;;;;;;;iBAeM,YAAA,oBAAgC;;;;;;;iBAetC,gBAAA"}
|
package/dist/chmod-x.mjs
CHANGED
|
@@ -1,2 +1,88 @@
|
|
|
1
|
-
import{accessSync
|
|
1
|
+
import { accessSync, chmodSync, constants, statSync } from "node:fs";
|
|
2
|
+
import { access, chmod } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
//#region src/chmod-x.ts
|
|
5
|
+
/**
|
|
6
|
+
* Adds execute permissions to a file
|
|
7
|
+
*
|
|
8
|
+
* @param file - The file to add execute permissions to
|
|
9
|
+
*/
|
|
10
|
+
function chmodXSync(file) {
|
|
11
|
+
if (process.platform === "win32") return;
|
|
12
|
+
const s = statSync(file);
|
|
13
|
+
const newMode = s.mode | 73;
|
|
14
|
+
if (s.mode === newMode) return;
|
|
15
|
+
chmodSync(file, newMode.toString(8).slice(-3));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Adds execute permissions to a file
|
|
19
|
+
*
|
|
20
|
+
* @param file - The file to add execute permissions to
|
|
21
|
+
*/
|
|
22
|
+
async function chmodX(file) {
|
|
23
|
+
if (process.platform === "win32") return;
|
|
24
|
+
const s = statSync(file);
|
|
25
|
+
const newMode = s.mode | 73;
|
|
26
|
+
if (s.mode === newMode) return;
|
|
27
|
+
return chmod(file, newMode.toString(8).slice(-3));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Checks the write permission of a file
|
|
31
|
+
*
|
|
32
|
+
* @param filename - The file to check the permission of
|
|
33
|
+
* @returns A promise that resolves to true if the file is writable, false otherwise
|
|
34
|
+
*/
|
|
35
|
+
async function isWritable(filename) {
|
|
36
|
+
try {
|
|
37
|
+
await access(filename, constants.W_OK);
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks the write permission of a file
|
|
45
|
+
*
|
|
46
|
+
* @param filename - The file to check the permission of
|
|
47
|
+
* @returns True if the file is writable, false otherwise
|
|
48
|
+
*/
|
|
49
|
+
function isWritableSync(filename) {
|
|
50
|
+
try {
|
|
51
|
+
accessSync(filename, constants.W_OK);
|
|
52
|
+
return true;
|
|
53
|
+
} catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Checks the execute permission of a file
|
|
59
|
+
*
|
|
60
|
+
* @param filename - The file to check the permission of
|
|
61
|
+
* @returns A promise that resolves to true if the file is executable, false otherwise
|
|
62
|
+
*/
|
|
63
|
+
async function isExecutable(filename) {
|
|
64
|
+
try {
|
|
65
|
+
await access(filename, constants.X_OK);
|
|
66
|
+
return true;
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Checks the execute permission of a file
|
|
73
|
+
*
|
|
74
|
+
* @param filename - The file to check the permission of
|
|
75
|
+
* @returns True if the file is executable, false otherwise
|
|
76
|
+
*/
|
|
77
|
+
function isExecutableSync(filename) {
|
|
78
|
+
try {
|
|
79
|
+
accessSync(filename, constants.X_OK);
|
|
80
|
+
return true;
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { chmodX, chmodXSync, isExecutable, isExecutableSync, isWritable, isWritableSync };
|
|
2
88
|
//# sourceMappingURL=chmod-x.mjs.map
|
package/dist/chmod-x.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chmod-x.mjs","names":[],"sources":["../src/chmod-x.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { accessSync, chmodSync, constants, statSync } from \"node:fs\";\nimport { access, chmod } from \"node:fs/promises\";\n\n/**\n * Adds execute permissions to a file\n *\n * @param file - The file to add execute permissions to\n */\nexport function chmodXSync(file: string) {\n // Note: skip for windows as chmod does on exist there\n // and will error with `EACCES: permission denied`\n if (process.platform === \"win32\") {\n return;\n }\n\n const s = statSync(file);\n const newMode = s.mode | 64 | 8 | 1;\n\n if (s.mode === newMode) {\n return;\n }\n const base8 = newMode.toString(8).slice(-3);\n\n chmodSync(file, base8);\n}\n\n/**\n * Adds execute permissions to a file\n *\n * @param file - The file to add execute permissions to\n */\nexport async function chmodX(file: string) {\n // Note: skip for windows as chmod does on exist there\n // and will error with `EACCES: permission denied`\n if (process.platform === \"win32\") {\n return;\n }\n\n const s = statSync(file);\n const newMode = s.mode | 64 | 8 | 1;\n\n if (s.mode === newMode) {\n return;\n }\n const base8 = newMode.toString(8).slice(-3);\n\n return chmod(file, base8);\n}\n\n/**\n * Checks the write permission of a file\n *\n * @param filename - The file to check the permission of\n * @returns A promise that resolves to true if the file is writable, false otherwise\n */\nexport async function isWritable(filename: string): Promise<boolean> {\n try {\n await access(filename, constants.W_OK);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Checks the write permission of a file\n *\n * @param filename - The file to check the permission of\n * @returns True if the file is writable, false otherwise\n */\nexport function isWritableSync(filename: string): boolean {\n try {\n accessSync(filename, constants.W_OK);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Checks the execute permission of a file\n *\n * @param filename - The file to check the permission of\n * @returns A promise that resolves to true if the file is executable, false otherwise\n */\nexport async function isExecutable(filename: string): Promise<boolean> {\n try {\n await access(filename, constants.X_OK);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Checks the execute permission of a file\n *\n * @param filename - The file to check the permission of\n * @returns True if the file is executable, false otherwise\n */\nexport function isExecutableSync(filename: string): boolean {\n try {\n accessSync(filename, constants.X_OK);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"chmod-x.mjs","names":[],"sources":["../src/chmod-x.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { accessSync, chmodSync, constants, statSync } from \"node:fs\";\nimport { access, chmod } from \"node:fs/promises\";\n\n/**\n * Adds execute permissions to a file\n *\n * @param file - The file to add execute permissions to\n */\nexport function chmodXSync(file: string) {\n // Note: skip for windows as chmod does on exist there\n // and will error with `EACCES: permission denied`\n if (process.platform === \"win32\") {\n return;\n }\n\n const s = statSync(file);\n const newMode = s.mode | 64 | 8 | 1;\n\n if (s.mode === newMode) {\n return;\n }\n const base8 = newMode.toString(8).slice(-3);\n\n chmodSync(file, base8);\n}\n\n/**\n * Adds execute permissions to a file\n *\n * @param file - The file to add execute permissions to\n */\nexport async function chmodX(file: string) {\n // Note: skip for windows as chmod does on exist there\n // and will error with `EACCES: permission denied`\n if (process.platform === \"win32\") {\n return;\n }\n\n const s = statSync(file);\n const newMode = s.mode | 64 | 8 | 1;\n\n if (s.mode === newMode) {\n return;\n }\n const base8 = newMode.toString(8).slice(-3);\n\n return chmod(file, base8);\n}\n\n/**\n * Checks the write permission of a file\n *\n * @param filename - The file to check the permission of\n * @returns A promise that resolves to true if the file is writable, false otherwise\n */\nexport async function isWritable(filename: string): Promise<boolean> {\n try {\n await access(filename, constants.W_OK);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Checks the write permission of a file\n *\n * @param filename - The file to check the permission of\n * @returns True if the file is writable, false otherwise\n */\nexport function isWritableSync(filename: string): boolean {\n try {\n accessSync(filename, constants.W_OK);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Checks the execute permission of a file\n *\n * @param filename - The file to check the permission of\n * @returns A promise that resolves to true if the file is executable, false otherwise\n */\nexport async function isExecutable(filename: string): Promise<boolean> {\n try {\n await access(filename, constants.X_OK);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Checks the execute permission of a file\n *\n * @param filename - The file to check the permission of\n * @returns True if the file is executable, false otherwise\n */\nexport function isExecutableSync(filename: string): boolean {\n try {\n accessSync(filename, constants.X_OK);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAgB,WAAW,MAAc;AAGvC,KAAI,QAAQ,aAAa,QACvB;CAGF,MAAM,IAAI,SAAS,KAAK;CACxB,MAAM,UAAU,EAAE,OAAO;AAEzB,KAAI,EAAE,SAAS,QACb;AAIF,WAAU,MAFI,QAAQ,SAAS,EAAE,CAAC,MAAM,GAAG,CAErB;;;;;;;AAQxB,eAAsB,OAAO,MAAc;AAGzC,KAAI,QAAQ,aAAa,QACvB;CAGF,MAAM,IAAI,SAAS,KAAK;CACxB,MAAM,UAAU,EAAE,OAAO;AAEzB,KAAI,EAAE,SAAS,QACb;AAIF,QAAO,MAAM,MAFC,QAAQ,SAAS,EAAE,CAAC,MAAM,GAAG,CAElB;;;;;;;;AAS3B,eAAsB,WAAW,UAAoC;AACnE,KAAI;AACF,QAAM,OAAO,UAAU,UAAU,KAAK;AACtC,SAAO;SACD;AACN,SAAO;;;;;;;;;AAUX,SAAgB,eAAe,UAA2B;AACxD,KAAI;AACF,aAAW,UAAU,UAAU,KAAK;AACpC,SAAO;SACD;AACN,SAAO;;;;;;;;;AAUX,eAAsB,aAAa,UAAoC;AACrE,KAAI;AACF,QAAM,OAAO,UAAU,UAAU,KAAK;AACtC,SAAO;SACD;AACN,SAAO;;;;;;;;;AAUX,SAAgB,iBAAiB,UAA2B;AAC1D,KAAI;AACF,aAAW,UAAU,UAAU,KAAK;AACpC,SAAO;SACD;AACN,SAAO"}
|
package/dist/command-exists.cjs
CHANGED
|
@@ -1 +1,102 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
let node_fs_promises = require("node:fs/promises");
|
|
4
|
+
let node_child_process = require("node:child_process");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
|
|
7
|
+
//#region src/command-exists.ts
|
|
8
|
+
const isUsingWindows = process.platform == "win32";
|
|
9
|
+
async function fileNotExists(commandName) {
|
|
10
|
+
try {
|
|
11
|
+
await (0, node_fs_promises.access)(commandName, node_fs_promises.constants.F_OK);
|
|
12
|
+
return false;
|
|
13
|
+
} catch (_) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function fileNotExistsSync(commandName) {
|
|
18
|
+
try {
|
|
19
|
+
(0, node_fs.accessSync)(commandName, node_fs_promises.constants.F_OK);
|
|
20
|
+
return false;
|
|
21
|
+
} catch (_) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function localExecutable(commandName) {
|
|
26
|
+
return (0, node_fs_promises.access)(commandName, node_fs_promises.constants.F_OK | node_fs_promises.constants.X_OK);
|
|
27
|
+
}
|
|
28
|
+
function localExecutableSync(commandName) {
|
|
29
|
+
try {
|
|
30
|
+
(0, node_fs.accessSync)(commandName, node_fs_promises.constants.F_OK | node_fs_promises.constants.X_OK);
|
|
31
|
+
return true;
|
|
32
|
+
} catch (_) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function commandExistsUnix(commandName, cleanedCommandName) {
|
|
37
|
+
if (!await fileNotExists(commandName)) {
|
|
38
|
+
(0, node_child_process.exec)(`command -v ${cleanedCommandName} 2>/dev/null && { echo >&1 ${cleanedCommandName}; exit 0; }`);
|
|
39
|
+
await localExecutable(commandName);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function commandExistsWindows(commandName, cleanedCommandName) {
|
|
43
|
+
if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(commandName)) return;
|
|
44
|
+
(0, node_child_process.exec)(`where ${cleanedCommandName}`);
|
|
45
|
+
}
|
|
46
|
+
function commandExistsUnixSync(commandName, cleanedCommandName) {
|
|
47
|
+
if (fileNotExistsSync(commandName)) try {
|
|
48
|
+
return !!(0, node_child_process.execSync)(`command -v ${cleanedCommandName} 2>/dev/null && { echo >&1 ${cleanedCommandName}; exit 0; }`);
|
|
49
|
+
} catch (_) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return localExecutableSync(commandName);
|
|
53
|
+
}
|
|
54
|
+
function commandExistsWindowsSync(commandName, cleanedCommandName) {
|
|
55
|
+
if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(commandName)) return false;
|
|
56
|
+
try {
|
|
57
|
+
return !!(0, node_child_process.execSync)(`where ${cleanedCommandName}`, { stdio: [] });
|
|
58
|
+
} catch (_) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function cleanInput(s) {
|
|
63
|
+
if (/[^\w/:=-]/.test(s)) {
|
|
64
|
+
s = `'${s.replace(/'/g, "'\\''")}'`;
|
|
65
|
+
s = s.replace(/^(?:'')+/g, "").replace(/\\'''/g, "\\'");
|
|
66
|
+
}
|
|
67
|
+
return s;
|
|
68
|
+
}
|
|
69
|
+
const cleanWindowsInput = (s) => {
|
|
70
|
+
if (/\\/.test(s)) return `"${(0, node_path.dirname)(s)}:${(0, node_path.basename)(s)}"`;
|
|
71
|
+
return `"${s}"`;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Asynchronously checks if a command exists in the system.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* This function will check if the command is available in the system's PATH and if it is executable.
|
|
78
|
+
* @param commandName - The name of the command to check for existence
|
|
79
|
+
* @returns A promise that resolves to `true` if the command exists and is executable, `false` otherwise
|
|
80
|
+
*/
|
|
81
|
+
async function commandExists(commandName) {
|
|
82
|
+
const cleanedCommandName = cleanInput(commandName);
|
|
83
|
+
if (typeof Promise !== "undefined") return commandExists(commandName);
|
|
84
|
+
if (isUsingWindows) return commandExistsWindows(commandName, cleanedCommandName);
|
|
85
|
+
else return commandExistsUnix(commandName, cleanedCommandName);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Synchronously checks if a command exists in the system.
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* This function will check if the command is available in the system's PATH and if it is executable.
|
|
92
|
+
* @param commandName - The name of the command to check for existence
|
|
93
|
+
* @returns `true` if the command exists and is executable, `false` otherwise
|
|
94
|
+
*/
|
|
95
|
+
function commandExistsSync(commandName) {
|
|
96
|
+
if (isUsingWindows) return commandExistsWindowsSync(commandName, cleanWindowsInput(commandName));
|
|
97
|
+
else return commandExistsUnixSync(commandName, cleanInput(commandName));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
exports.commandExists = commandExists;
|
|
102
|
+
exports.commandExistsSync = commandExistsSync;
|
package/dist/command-exists.mjs
CHANGED
|
@@ -1,2 +1,101 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { accessSync } from "node:fs";
|
|
2
|
+
import { access, constants as constants$1 } from "node:fs/promises";
|
|
3
|
+
import { exec, execSync } from "node:child_process";
|
|
4
|
+
import { basename, dirname } from "node:path";
|
|
5
|
+
|
|
6
|
+
//#region src/command-exists.ts
|
|
7
|
+
const isUsingWindows = process.platform == "win32";
|
|
8
|
+
async function fileNotExists(commandName) {
|
|
9
|
+
try {
|
|
10
|
+
await access(commandName, constants$1.F_OK);
|
|
11
|
+
return false;
|
|
12
|
+
} catch (_) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function fileNotExistsSync(commandName) {
|
|
17
|
+
try {
|
|
18
|
+
accessSync(commandName, constants$1.F_OK);
|
|
19
|
+
return false;
|
|
20
|
+
} catch (_) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function localExecutable(commandName) {
|
|
25
|
+
return access(commandName, constants$1.F_OK | constants$1.X_OK);
|
|
26
|
+
}
|
|
27
|
+
function localExecutableSync(commandName) {
|
|
28
|
+
try {
|
|
29
|
+
accessSync(commandName, constants$1.F_OK | constants$1.X_OK);
|
|
30
|
+
return true;
|
|
31
|
+
} catch (_) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function commandExistsUnix(commandName, cleanedCommandName) {
|
|
36
|
+
if (!await fileNotExists(commandName)) {
|
|
37
|
+
exec(`command -v ${cleanedCommandName} 2>/dev/null && { echo >&1 ${cleanedCommandName}; exit 0; }`);
|
|
38
|
+
await localExecutable(commandName);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function commandExistsWindows(commandName, cleanedCommandName) {
|
|
42
|
+
if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(commandName)) return;
|
|
43
|
+
exec(`where ${cleanedCommandName}`);
|
|
44
|
+
}
|
|
45
|
+
function commandExistsUnixSync(commandName, cleanedCommandName) {
|
|
46
|
+
if (fileNotExistsSync(commandName)) try {
|
|
47
|
+
return !!execSync(`command -v ${cleanedCommandName} 2>/dev/null && { echo >&1 ${cleanedCommandName}; exit 0; }`);
|
|
48
|
+
} catch (_) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return localExecutableSync(commandName);
|
|
52
|
+
}
|
|
53
|
+
function commandExistsWindowsSync(commandName, cleanedCommandName) {
|
|
54
|
+
if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(commandName)) return false;
|
|
55
|
+
try {
|
|
56
|
+
return !!execSync(`where ${cleanedCommandName}`, { stdio: [] });
|
|
57
|
+
} catch (_) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function cleanInput(s) {
|
|
62
|
+
if (/[^\w/:=-]/.test(s)) {
|
|
63
|
+
s = `'${s.replace(/'/g, "'\\''")}'`;
|
|
64
|
+
s = s.replace(/^(?:'')+/g, "").replace(/\\'''/g, "\\'");
|
|
65
|
+
}
|
|
66
|
+
return s;
|
|
67
|
+
}
|
|
68
|
+
const cleanWindowsInput = (s) => {
|
|
69
|
+
if (/\\/.test(s)) return `"${dirname(s)}:${basename(s)}"`;
|
|
70
|
+
return `"${s}"`;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Asynchronously checks if a command exists in the system.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* This function will check if the command is available in the system's PATH and if it is executable.
|
|
77
|
+
* @param commandName - The name of the command to check for existence
|
|
78
|
+
* @returns A promise that resolves to `true` if the command exists and is executable, `false` otherwise
|
|
79
|
+
*/
|
|
80
|
+
async function commandExists(commandName) {
|
|
81
|
+
const cleanedCommandName = cleanInput(commandName);
|
|
82
|
+
if (typeof Promise !== "undefined") return commandExists(commandName);
|
|
83
|
+
if (isUsingWindows) return commandExistsWindows(commandName, cleanedCommandName);
|
|
84
|
+
else return commandExistsUnix(commandName, cleanedCommandName);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Synchronously checks if a command exists in the system.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* This function will check if the command is available in the system's PATH and if it is executable.
|
|
91
|
+
* @param commandName - The name of the command to check for existence
|
|
92
|
+
* @returns `true` if the command exists and is executable, `false` otherwise
|
|
93
|
+
*/
|
|
94
|
+
function commandExistsSync(commandName) {
|
|
95
|
+
if (isUsingWindows) return commandExistsWindowsSync(commandName, cleanWindowsInput(commandName));
|
|
96
|
+
else return commandExistsUnixSync(commandName, cleanInput(commandName));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//#endregion
|
|
100
|
+
export { commandExists, commandExistsSync };
|
|
2
101
|
//# sourceMappingURL=command-exists.mjs.map
|