@stryke/fs 0.33.32 → 0.33.34

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.
Files changed (190) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  3. package/dist/buffer.cjs +60 -1
  4. package/dist/buffer.mjs +56 -1
  5. package/dist/buffer.mjs.map +1 -1
  6. package/dist/chmod-x.cjs +93 -1
  7. package/dist/chmod-x.mjs +87 -1
  8. package/dist/chmod-x.mjs.map +1 -1
  9. package/dist/command-exists.cjs +102 -1
  10. package/dist/command-exists.mjs +100 -1
  11. package/dist/command-exists.mjs.map +1 -1
  12. package/dist/compress.cjs +29 -1
  13. package/dist/compress.mjs +28 -1
  14. package/dist/compress.mjs.map +1 -1
  15. package/dist/constants.mjs +1 -1
  16. package/dist/convert/src/array-buffer-to-string.cjs +19 -1
  17. package/dist/convert/src/array-buffer-to-string.mjs +18 -1
  18. package/dist/convert/src/array-buffer-to-string.mjs.map +1 -1
  19. package/dist/convert/src/to-array.cjs +15 -1
  20. package/dist/convert/src/to-array.mjs +14 -1
  21. package/dist/convert/src/to-array.mjs.map +1 -1
  22. package/dist/convert/src/uint8-array-to-string.cjs +15 -1
  23. package/dist/convert/src/uint8-array-to-string.mjs +15 -1
  24. package/dist/convert/src/uint8-array-to-string.mjs.map +1 -1
  25. package/dist/copy-file.cjs +87 -1
  26. package/dist/copy-file.mjs +83 -1
  27. package/dist/copy-file.mjs.map +1 -1
  28. package/dist/exists.cjs +27 -1
  29. package/dist/exists.mjs +25 -1
  30. package/dist/exists.mjs.map +1 -1
  31. package/dist/get-parent-path.cjs +35 -1
  32. package/dist/get-parent-path.mjs +34 -1
  33. package/dist/get-parent-path.mjs.map +1 -1
  34. package/dist/get-workspace-root.cjs +158 -1
  35. package/dist/get-workspace-root.mjs +150 -1
  36. package/dist/get-workspace-root.mjs.map +1 -1
  37. package/dist/helpers/src/get-unique.cjs +14 -1
  38. package/dist/helpers/src/get-unique.mjs +13 -1
  39. package/dist/helpers/src/get-unique.mjs.map +1 -1
  40. package/dist/helpers.cjs +83 -1
  41. package/dist/helpers.mjs +77 -1
  42. package/dist/helpers.mjs.map +1 -1
  43. package/dist/index.cjs +122 -1
  44. package/dist/index.mjs +25 -1
  45. package/dist/install.cjs +35 -1
  46. package/dist/install.mjs +33 -1
  47. package/dist/install.mjs.map +1 -1
  48. package/dist/is-file.cjs +51 -1
  49. package/dist/is-file.mjs +47 -1
  50. package/dist/is-file.mjs.map +1 -1
  51. package/dist/json/src/storm-json.cjs +117 -1
  52. package/dist/json/src/storm-json.mjs +115 -1
  53. package/dist/json/src/storm-json.mjs.map +1 -1
  54. package/dist/json/src/utils/code-frames.cjs +77 -3
  55. package/dist/json/src/utils/code-frames.mjs +76 -3
  56. package/dist/json/src/utils/code-frames.mjs.map +1 -1
  57. package/dist/json/src/utils/parse-error.cjs +34 -1
  58. package/dist/json/src/utils/parse-error.mjs +33 -1
  59. package/dist/json/src/utils/parse-error.mjs.map +1 -1
  60. package/dist/json/src/utils/parse.cjs +45 -1
  61. package/dist/json/src/utils/parse.mjs +45 -1
  62. package/dist/json/src/utils/parse.mjs.map +1 -1
  63. package/dist/json/src/utils/stringify.cjs +67 -1
  64. package/dist/json/src/utils/stringify.mjs +67 -1
  65. package/dist/json/src/utils/stringify.mjs.map +1 -1
  66. package/dist/json/src/utils/strip-comments.cjs +86 -4
  67. package/dist/json/src/utils/strip-comments.mjs +86 -4
  68. package/dist/json/src/utils/strip-comments.mjs.map +1 -1
  69. package/dist/json.cjs +74 -1
  70. package/dist/json.mjs +71 -1
  71. package/dist/json.mjs.map +1 -1
  72. package/dist/list-files.cjs +86 -1
  73. package/dist/list-files.mjs +79 -1
  74. package/dist/list-files.mjs.map +1 -1
  75. package/dist/package-fns.cjs +148 -1
  76. package/dist/package-fns.mjs +141 -1
  77. package/dist/package-fns.mjs.map +1 -1
  78. package/dist/path/src/append.cjs +57 -1
  79. package/dist/path/src/append.mjs +56 -1
  80. package/dist/path/src/append.mjs.map +1 -1
  81. package/dist/path/src/correct-path.cjs +138 -1
  82. package/dist/path/src/correct-path.mjs +134 -1
  83. package/dist/path/src/correct-path.mjs.map +1 -1
  84. package/dist/path/src/cwd.cjs +17 -1
  85. package/dist/path/src/cwd.mjs +16 -1
  86. package/dist/path/src/cwd.mjs.map +1 -1
  87. package/dist/path/src/file-path-fns.cjs +169 -1
  88. package/dist/path/src/file-path-fns.mjs +164 -1
  89. package/dist/path/src/file-path-fns.mjs.map +1 -1
  90. package/dist/path/src/is-parent-path.cjs +32 -1
  91. package/dist/path/src/is-parent-path.mjs +32 -1
  92. package/dist/path/src/is-parent-path.mjs.map +1 -1
  93. package/dist/path/src/is-root-dir.cjs +14 -1
  94. package/dist/path/src/is-root-dir.mjs +13 -1
  95. package/dist/path/src/is-root-dir.mjs.map +1 -1
  96. package/dist/path/src/is-type.cjs +68 -1
  97. package/dist/path/src/is-type.mjs +66 -1
  98. package/dist/path/src/is-type.mjs.map +1 -1
  99. package/dist/path/src/join-paths.cjs +106 -1
  100. package/dist/path/src/join-paths.mjs +106 -1
  101. package/dist/path/src/join-paths.mjs.map +1 -1
  102. package/dist/path/src/regex.cjs +18 -1
  103. package/dist/path/src/regex.mjs +11 -1
  104. package/dist/path/src/regex.mjs.map +1 -1
  105. package/dist/path/src/replace.cjs +24 -1
  106. package/dist/path/src/replace.mjs +24 -1
  107. package/dist/path/src/replace.mjs.map +1 -1
  108. package/dist/path/src/resolve-parent-path.cjs +18 -1
  109. package/dist/path/src/resolve-parent-path.mjs +18 -1
  110. package/dist/path/src/resolve-parent-path.mjs.map +1 -1
  111. package/dist/path/src/slash.cjs +15 -1
  112. package/dist/path/src/slash.mjs +14 -1
  113. package/dist/path/src/slash.mjs.map +1 -1
  114. package/dist/read-file.cjs +47 -1
  115. package/dist/read-file.mjs +43 -1
  116. package/dist/read-file.mjs.map +1 -1
  117. package/dist/registry.cjs +142 -1
  118. package/dist/registry.mjs +137 -1
  119. package/dist/registry.mjs.map +1 -1
  120. package/dist/remove-file.cjs +27 -1
  121. package/dist/remove-file.mjs +25 -1
  122. package/dist/remove-file.mjs.map +1 -1
  123. package/dist/resolve.cjs +228 -3
  124. package/dist/resolve.mjs +217 -3
  125. package/dist/resolve.mjs.map +1 -1
  126. package/dist/semver-fns.cjs +129 -1
  127. package/dist/semver-fns.mjs +119 -1
  128. package/dist/semver-fns.mjs.map +1 -1
  129. package/dist/string-format/src/package.cjs +92 -1
  130. package/dist/string-format/src/package.mjs +91 -1
  131. package/dist/string-format/src/package.mjs.map +1 -1
  132. package/dist/toml.cjs +66 -3
  133. package/dist/toml.mjs +61 -3
  134. package/dist/toml.mjs.map +1 -1
  135. package/dist/tsconfig.cjs +37 -1
  136. package/dist/tsconfig.mjs +35 -1
  137. package/dist/tsconfig.mjs.map +1 -1
  138. package/dist/type-checks/src/get-object-tag.cjs +15 -1
  139. package/dist/type-checks/src/get-object-tag.mjs +14 -1
  140. package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
  141. package/dist/type-checks/src/index.cjs +14 -1
  142. package/dist/type-checks/src/index.mjs +16 -1
  143. package/dist/type-checks/src/is-buffer.cjs +12 -1
  144. package/dist/type-checks/src/is-buffer.mjs +11 -1
  145. package/dist/type-checks/src/is-buffer.mjs.map +1 -1
  146. package/dist/type-checks/src/is-collection.cjs +1 -1
  147. package/dist/type-checks/src/is-collection.mjs +3 -1
  148. package/dist/type-checks/src/is-empty.cjs +20 -1
  149. package/dist/type-checks/src/is-empty.mjs +20 -1
  150. package/dist/type-checks/src/is-empty.mjs.map +1 -1
  151. package/dist/type-checks/src/is-error.cjs +29 -1
  152. package/dist/type-checks/src/is-error.mjs +29 -1
  153. package/dist/type-checks/src/is-error.mjs.map +1 -1
  154. package/dist/type-checks/src/is-null.cjs +12 -1
  155. package/dist/type-checks/src/is-null.mjs +11 -1
  156. package/dist/type-checks/src/is-null.mjs.map +1 -1
  157. package/dist/type-checks/src/is-number.cjs +18 -1
  158. package/dist/type-checks/src/is-number.mjs +17 -1
  159. package/dist/type-checks/src/is-number.mjs.map +1 -1
  160. package/dist/type-checks/src/is-object.cjs +19 -1
  161. package/dist/type-checks/src/is-object.mjs +19 -1
  162. package/dist/type-checks/src/is-object.mjs.map +1 -1
  163. package/dist/type-checks/src/is-plain-object.cjs +64 -1
  164. package/dist/type-checks/src/is-plain-object.mjs +63 -1
  165. package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
  166. package/dist/type-checks/src/is-set-string.cjs +20 -1
  167. package/dist/type-checks/src/is-set-string.mjs +20 -1
  168. package/dist/type-checks/src/is-set-string.mjs.map +1 -1
  169. package/dist/type-checks/src/is-set.cjs +19 -1
  170. package/dist/type-checks/src/is-set.mjs +19 -1
  171. package/dist/type-checks/src/is-set.mjs.map +1 -1
  172. package/dist/type-checks/src/is-string.cjs +12 -1
  173. package/dist/type-checks/src/is-string.mjs +11 -1
  174. package/dist/type-checks/src/is-string.mjs.map +1 -1
  175. package/dist/type-checks/src/is-undefined.cjs +8 -1
  176. package/dist/type-checks/src/is-undefined.mjs +7 -1
  177. package/dist/type-checks/src/is-undefined.mjs.map +1 -1
  178. package/dist/type-checks/src/type-detect.cjs +15 -1
  179. package/dist/type-checks/src/type-detect.mjs +16 -1
  180. package/dist/type-checks/src/type-detect.mjs.map +1 -1
  181. package/dist/types/src/base.cjs +6 -1
  182. package/dist/types/src/base.mjs +5 -1
  183. package/dist/types/src/base.mjs.map +1 -1
  184. package/dist/write-file.cjs +40 -1
  185. package/dist/write-file.mjs +38 -1
  186. package/dist/write-file.mjs.map +1 -1
  187. package/dist/yaml.cjs +29 -1
  188. package/dist/yaml.mjs +27 -1
  189. package/dist/yaml.mjs.map +1 -1
  190. 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.33](https://github.com/storm-software/stryke/releases/tag/fs%400.33.33) (01/16/2026)
6
+
7
+ ### Updated Dependencies
8
+
9
+ - Updated **string-format** to **v0.13.3**
10
+ - Updated **type-checks** to **v0.5.19**
11
+ - Updated **convert** to **v0.6.34**
12
+ - Updated **helpers** to **v0.9.36**
13
+ - Updated **types** to **v0.10.33**
14
+ - Updated **json** to **v0.9.37**
15
+ - Updated **path** to **v0.25.1**
16
+
17
+ ## [0.33.32](https://github.com/storm-software/stryke/releases/tag/fs%400.33.32) (01/16/2026)
18
+
19
+ ### Updated Dependencies
20
+
21
+ - Updated **path** to **v0.25.0**
22
+
5
23
  ## [0.33.31](https://github.com/storm-software/stryke/releases/tag/fs%400.33.31) (01/16/2026)
6
24
 
7
25
  ### Updated Dependencies
@@ -1 +1,29 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
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 e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./path/src/file-path-fns.cjs`),n=require(`./helpers.cjs`);let r=require(`node:buffer`),i=require(`node:fs`),a=require(`node:fs/promises`);async function o(e){if(!e)throw Error(`No file path provided to read data`);if(!(0,i.existsSync)(e))throw Error(`File does not exist at path: ${e}`);let t=await(0,a.readFile)(e);return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}function s(e){if(!e)throw Error(`No file path provided to read data`);if(!(0,i.existsSync)(e))throw Error(`File does not exist at path: ${e}`);let t=(0,i.readFileSync)(e);return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}async function c(e,o){if(!e)throw Error(`No file path provided to write data`);(0,i.existsSync)(t.findFilePath(e))||await n.createDirectory(t.findFilePath(e)),await(0,a.writeFile)(e,r.Buffer.from(o))}function l(e,a){if(!e)throw Error(`No file path provided to write data`);(0,i.existsSync)(t.findFilePath(e))||n.createDirectorySync(t.findFilePath(e)),(0,i.writeFileSync)(e,r.Buffer.from(a))}exports.readFileBuffer=o,exports.readFileBufferSync=s,exports.writeFileBuffer=c,exports.writeFileBufferSync=l;
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 as e}from"./path/src/file-path-fns.mjs";import{createDirectory as t,createDirectorySync as n}from"./helpers.mjs";import{Buffer as r}from"node:buffer";import{existsSync as i,readFileSync as a,writeFileSync as o}from"node:fs";import{readFile as s,writeFile as c}from"node:fs/promises";async function l(e){if(!e)throw Error(`No file path provided to read data`);if(!i(e))throw Error(`File does not exist at path: ${e}`);let t=await s(e);return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}function u(e){if(!e)throw Error(`No file path provided to read data`);if(!i(e))throw Error(`File does not exist at path: ${e}`);let t=a(e);return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}async function d(n,a){if(!n)throw Error(`No file path provided to write data`);i(e(n))||await t(e(n)),await c(n,r.from(a))}function f(t,a){if(!t)throw Error(`No file path provided to write data`);i(e(t))||n(e(t)),o(t,r.from(a))}export{l as readFileBuffer,u as readFileBufferSync,d as writeFileBuffer,f as writeFileBufferSync};
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
@@ -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":"+SA8BA,eAAsB,EAAe,EAAwC,CAC3E,GAAI,CAAC,EACH,MAAU,MAAM,qCAAqC,CAEvD,GAAI,CAAC,EAAW,EAAS,CACvB,MAAU,MAAM,gCAAgC,IAAW,CAG7D,IAAM,EAAI,MAAM,EAAS,EAAS,CAElC,OAAO,EAAE,OAAO,MACd,EAAE,WACF,EAAE,WAAa,EAAE,WAClB,CASH,SAAgB,EAAmB,EAA+B,CAChE,GAAI,CAAC,EACH,MAAU,MAAM,qCAAqC,CAEvD,GAAI,CAAC,EAAW,EAAS,CACvB,MAAU,MAAM,gCAAgC,IAAW,CAG7D,IAAM,EAAI,EAAa,EAAS,CAEhC,OAAO,EAAE,OAAO,MAAM,EAAE,WAAY,EAAE,WAAa,EAAE,WAAW,CASlE,eAAsB,EAAgB,EAAkB,EAAmB,CACzE,GAAI,CAAC,EACH,MAAU,MAAM,sCAAsC,CAEnD,EAAW,EAAa,EAAS,CAAC,EACrC,MAAM,EAAgB,EAAa,EAAS,CAAC,CAG/C,MAAM,EAAU,EAAU,EAAO,KAAK,EAAK,CAAC,CAS9C,SAAgB,EAAoB,EAAkB,EAAmB,CACvE,GAAI,CAAC,EACH,MAAU,MAAM,sCAAsC,CAEnD,EAAW,EAAa,EAAS,CAAC,EACrC,EAAoB,EAAa,EAAS,CAAC,CAG7C,EAAc,EAAU,EAAO,KAAK,EAAK,CAAC"}
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 e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`node:fs`),n=require(`node:fs/promises`);function r(e){if(process.platform===`win32`)return;let n=(0,t.statSync)(e),r=n.mode|73;n.mode!==r&&(0,t.chmodSync)(e,r.toString(8).slice(-3))}async function i(e){if(process.platform===`win32`)return;let r=(0,t.statSync)(e),i=r.mode|73;if(r.mode!==i)return(0,n.chmod)(e,i.toString(8).slice(-3))}async function a(e){try{return await(0,n.access)(e,t.constants.W_OK),!0}catch{return!1}}function o(e){try{return(0,t.accessSync)(e,t.constants.W_OK),!0}catch{return!1}}async function s(e){try{return await(0,n.access)(e,t.constants.X_OK),!0}catch{return!1}}function c(e){try{return(0,t.accessSync)(e,t.constants.X_OK),!0}catch{return!1}}exports.chmodX=i,exports.chmodXSync=r,exports.isExecutable=s,exports.isExecutableSync=c,exports.isWritable=a,exports.isWritableSync=o;
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.mjs CHANGED
@@ -1,2 +1,88 @@
1
- import{accessSync as e,chmodSync as t,constants as n,statSync as r}from"node:fs";import{access as i,chmod as a}from"node:fs/promises";function o(e){if(process.platform===`win32`)return;let n=r(e),i=n.mode|73;n.mode!==i&&t(e,i.toString(8).slice(-3))}async function s(e){if(process.platform===`win32`)return;let t=r(e),n=t.mode|73;if(t.mode!==n)return a(e,n.toString(8).slice(-3))}async function c(e){try{return await i(e,n.W_OK),!0}catch{return!1}}function l(t){try{return e(t,n.W_OK),!0}catch{return!1}}async function u(e){try{return await i(e,n.X_OK),!0}catch{return!1}}function d(t){try{return e(t,n.X_OK),!0}catch{return!1}}export{s as chmodX,o as chmodXSync,u as isExecutable,d as isExecutableSync,c as isWritable,l as isWritableSync};
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
@@ -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":"sIA0BA,SAAgB,EAAW,EAAc,CAGvC,GAAI,QAAQ,WAAa,QACvB,OAGF,IAAM,EAAI,EAAS,EAAK,CAClB,EAAU,EAAE,KAAO,GAErB,EAAE,OAAS,GAKf,EAAU,EAFI,EAAQ,SAAS,EAAE,CAAC,MAAM,GAAG,CAErB,CAQxB,eAAsB,EAAO,EAAc,CAGzC,GAAI,QAAQ,WAAa,QACvB,OAGF,IAAM,EAAI,EAAS,EAAK,CAClB,EAAU,EAAE,KAAO,GAErB,KAAE,OAAS,EAKf,OAAO,EAAM,EAFC,EAAQ,SAAS,EAAE,CAAC,MAAM,GAAG,CAElB,CAS3B,eAAsB,EAAW,EAAoC,CACnE,GAAI,CAEF,OADA,MAAM,EAAO,EAAU,EAAU,KAAK,CAC/B,QACD,CACN,MAAO,IAUX,SAAgB,EAAe,EAA2B,CACxD,GAAI,CAEF,OADA,EAAW,EAAU,EAAU,KAAK,CAC7B,QACD,CACN,MAAO,IAUX,eAAsB,EAAa,EAAoC,CACrE,GAAI,CAEF,OADA,MAAM,EAAO,EAAU,EAAU,KAAK,CAC/B,QACD,CACN,MAAO,IAUX,SAAgB,EAAiB,EAA2B,CAC1D,GAAI,CAEF,OADA,EAAW,EAAU,EAAU,KAAK,CAC7B,QACD,CACN,MAAO"}
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"}
@@ -1 +1,102 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`node:fs`),n=require(`node:fs/promises`),r=require(`node:child_process`),i=require(`node:path`);const a=process.platform==`win32`;async function o(e){try{return await(0,n.access)(e,n.constants.F_OK),!1}catch{return!0}}function s(e){try{return(0,t.accessSync)(e,n.constants.F_OK),!1}catch{return!0}}async function c(e){return(0,n.access)(e,n.constants.F_OK|n.constants.X_OK)}function l(e){try{return(0,t.accessSync)(e,n.constants.F_OK|n.constants.X_OK),!0}catch{return!1}}async function u(e,t){await o(e)||((0,r.exec)(`command -v ${t} 2>/dev/null && { echo >&1 ${t}; exit 0; }`),await c(e))}async function d(e,t){/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(e)&&(0,r.exec)(`where ${t}`)}function f(e,t){if(s(e))try{return!!(0,r.execSync)(`command -v ${t} 2>/dev/null && { echo >&1 ${t}; exit 0; }`)}catch{return!1}return l(e)}function p(e,t){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(e))return!1;try{return!!(0,r.execSync)(`where ${t}`,{stdio:[]})}catch{return!1}}function m(e){return/[^\w/:=-]/.test(e)&&(e=`'${e.replace(/'/g,`'\\''`)}'`,e=e.replace(/^(?:'')+/g,``).replace(/\\'''/g,`\\'`)),e}const h=e=>/\\/.test(e)?`"${(0,i.dirname)(e)}:${(0,i.basename)(e)}"`:`"${e}"`;async function g(e){let t=m(e);return typeof Promise<`u`?g(e):a?d(e,t):u(e,t)}function _(e){return a?p(e,h(e)):f(e,m(e))}exports.commandExists=g,exports.commandExistsSync=_;
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;
@@ -1,2 +1,101 @@
1
- import{accessSync as e}from"node:fs";import{access as t,constants as n}from"node:fs/promises";import{exec as r,execSync as i}from"node:child_process";import{basename as a,dirname as o}from"node:path";const s=process.platform==`win32`;async function c(e){try{return await t(e,n.F_OK),!1}catch{return!0}}function l(t){try{return e(t,n.F_OK),!1}catch{return!0}}async function u(e){return t(e,n.F_OK|n.X_OK)}function d(t){try{return e(t,n.F_OK|n.X_OK),!0}catch{return!1}}async function f(e,t){await c(e)||(r(`command -v ${t} 2>/dev/null && { echo >&1 ${t}; exit 0; }`),await u(e))}async function p(e,t){/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(e)&&r(`where ${t}`)}function m(e,t){if(l(e))try{return!!i(`command -v ${t} 2>/dev/null && { echo >&1 ${t}; exit 0; }`)}catch{return!1}return d(e)}function h(e,t){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(e))return!1;try{return!!i(`where ${t}`,{stdio:[]})}catch{return!1}}function g(e){return/[^\w/:=-]/.test(e)&&(e=`'${e.replace(/'/g,`'\\''`)}'`,e=e.replace(/^(?:'')+/g,``).replace(/\\'''/g,`\\'`)),e}const _=e=>/\\/.test(e)?`"${o(e)}:${a(e)}"`:`"${e}"`;async function v(e){let t=g(e);return typeof Promise<`u`?v(e):s?p(e,t):f(e,t)}function y(e){return s?h(e,_(e)):m(e,g(e))}export{v as commandExists,y as commandExistsSync};
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