@stryke/fs 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.commandExists = commandExists;
7
+ exports.commandExistsSync = commandExistsSync;
8
+ var _nodeChild_process = require("node:child_process");
9
+ var _nodeFs = require("node:fs");
10
+ var _promises = require("node:fs/promises");
11
+ var _nodePath = require("node:path");
12
+ const u = process.platform == "win32";
13
+ async function g(t) {
14
+ try {
15
+ return await (0, _promises.access)(t, _promises.constants.F_OK), !1;
16
+ } catch {
17
+ return !0;
18
+ }
19
+ }
20
+ function x(t) {
21
+ try {
22
+ return (0, _nodeFs.accessSync)(t, _promises.constants.F_OK), !1;
23
+ } catch {
24
+ return !0;
25
+ }
26
+ }
27
+ async function y(t) {
28
+ return (0, _promises.access)(t, _promises.constants.F_OK | _promises.constants.X_OK);
29
+ }
30
+ function p(t) {
31
+ try {
32
+ return (0, _nodeFs.accessSync)(t, _promises.constants.F_OK | _promises.constants.X_OK), !0;
33
+ } catch {
34
+ return !1;
35
+ }
36
+ }
37
+ async function $(t, n) {
38
+ (await g(t)) || ((0, _nodeChild_process.exec)(`command -v ${n} 2>/dev/null && { echo >&1 ${n}; exit 0; }`), await y(t));
39
+ }
40
+ async function d(t, n) {
41
+ /^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(t) && (0, _nodeChild_process.exec)(`where ${n}`);
42
+ }
43
+ function h(t, n) {
44
+ if (x(t)) try {
45
+ return !!(0, _nodeChild_process.execSync)(`command -v ${n} 2>/dev/null && { echo >&1 ${n}; exit 0; }`);
46
+ } catch {
47
+ return !1;
48
+ }
49
+ return p(t);
50
+ }
51
+ function w(t, n) {
52
+ if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(t)) return !1;
53
+ try {
54
+ return !!(0, _nodeChild_process.execSync)(`where ${n}`, {
55
+ stdio: []
56
+ });
57
+ } catch {
58
+ return !1;
59
+ }
60
+ }
61
+ function a(t) {
62
+ return /[^\w/:=-]/.test(t) && (t = `'${t.replace(/'/g, "'\\''")}'`, t = t.replace(/^(?:'')+/g, "").replace(/\\'''/g, "\\'")), t;
63
+ }
64
+ const _ = t => /\\/.test(t) ? `"${(0, _nodePath.dirname)(t)}:${(0, _nodePath.basename)(t)}"` : `"${t}"`;
65
+ async function commandExists(t) {
66
+ const n = a(t);
67
+ return typeof Promise < "u" ? commandExists(t) : u ? d(t, n) : $(t, n);
68
+ }
69
+ function commandExistsSync(t) {
70
+ return u ? w(t, _(t)) : h(t, a(t));
71
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Asynchronously checks if a command exists in the system.
3
+ *
4
+ * @remarks
5
+ * This function will check if the command is available in the system's PATH and if it is executable.
6
+ * @param commandName - The name of the command to check for existence
7
+ * @returns A promise that resolves to `true` if the command exists and is executable, `false` otherwise
8
+ */
9
+ export declare function commandExists(commandName: string): Promise<void>;
10
+ /**
11
+ * Synchronously checks if a command exists in the system.
12
+ *
13
+ * @remarks
14
+ * This function will check if the command is available in the system's PATH and if it is executable.
15
+ * @param commandName - The name of the command to check for existence
16
+ * @returns `true` if the command exists and is executable, `false` otherwise
17
+ */
18
+ export declare function commandExistsSync(commandName: string): boolean;
@@ -0,0 +1 @@
1
+ import{exec as s,execSync as e}from"node:child_process";import{accessSync as c}from"node:fs";import{access as o,constants as r}from"node:fs/promises";import{basename as f,dirname as l}from"node:path";const u=process.platform=="win32";async function g(t){try{return await o(t,r.F_OK),!1}catch{return!0}}function x(t){try{return c(t,r.F_OK),!1}catch{return!0}}async function y(t){return o(t,r.F_OK|r.X_OK)}function p(t){try{return c(t,r.F_OK|r.X_OK),!0}catch{return!1}}async function $(t,n){await g(t)||(s(`command -v ${n} 2>/dev/null && { echo >&1 ${n}; exit 0; }`),await y(t))}async function d(t,n){/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(t)&&s(`where ${n}`)}function h(t,n){if(x(t))try{return!!e(`command -v ${n} 2>/dev/null && { echo >&1 ${n}; exit 0; }`)}catch{return!1}return p(t)}function w(t,n){if(!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-z]:)?[^<>:"|?*\n]+$/im.test(t))return!1;try{return!!e(`where ${n}`,{stdio:[]})}catch{return!1}}function a(t){return/[^\w/:=-]/.test(t)&&(t=`'${t.replace(/'/g,"'\\''")}'`,t=t.replace(/^(?:'')+/g,"").replace(/\\'''/g,"\\'")),t}const _=t=>/\\/.test(t)?`"${l(t)}:${f(t)}"`:`"${t}"`;export async function commandExists(t){const n=a(t);return typeof Promise<"u"?commandExists(t):u?d(t,n):$(t,n)}export function commandExistsSync(t){return u?w(t,_(t)):h(t,a(t))}
package/dist/index.cjs CHANGED
@@ -14,6 +14,17 @@ Object.keys(_chmodX).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
+ var _commandExists = require("./command-exists.cjs");
18
+ Object.keys(_commandExists).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _commandExists[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _commandExists[key];
25
+ }
26
+ });
27
+ });
17
28
  var _compress = require("./compress.cjs");
18
29
  Object.keys(_compress).forEach(function (key) {
19
30
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  * @packageDocumentation
8
8
  */
9
9
  export * from "./chmod-x";
10
+ export * from "./command-exists";
10
11
  export * from "./compress";
11
12
  export * from "./constants";
12
13
  export * from "./copy-file";
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./chmod-x";export*from"./compress";export*from"./constants";export*from"./copy-file";export*from"./get-tsconfig";export*from"./helpers";export*from"./install";export*from"./list-files";export*from"./package-fns";export*from"./read-file";export*from"./remove-file";export*from"./semver-fns";export*from"./write-file";
1
+ export*from"./chmod-x";export*from"./command-exists";export*from"./compress";export*from"./constants";export*from"./copy-file";export*from"./get-tsconfig";export*from"./helpers";export*from"./install";export*from"./list-files";export*from"./package-fns";export*from"./read-file";export*from"./remove-file";export*from"./semver-fns";export*from"./write-file";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.",
6
6
  "repository": {
@@ -252,6 +252,20 @@
252
252
  "default": "./dist/compress.mjs"
253
253
  }
254
254
  },
255
+ "./command-exists": {
256
+ "import": {
257
+ "types": "./dist/command-exists.d.ts",
258
+ "default": "./dist/command-exists.mjs"
259
+ },
260
+ "require": {
261
+ "types": "./dist/command-exists.d.ts",
262
+ "default": "./dist/command-exists.cjs"
263
+ },
264
+ "default": {
265
+ "types": "./dist/command-exists.d.ts",
266
+ "default": "./dist/command-exists.mjs"
267
+ }
268
+ },
255
269
  "./chmod-x": {
256
270
  "import": {
257
271
  "types": "./dist/chmod-x.d.ts",