isexe 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.ts +14 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +46 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/options.d.ts +32 -0
- package/dist/cjs/options.d.ts.map +1 -0
- package/dist/cjs/options.js +3 -0
- package/dist/cjs/options.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/posix.d.ts +18 -0
- package/dist/cjs/posix.d.ts.map +1 -0
- package/dist/cjs/posix.js +67 -0
- package/dist/cjs/posix.js.map +1 -0
- package/dist/cjs/win32.d.ts +18 -0
- package/dist/cjs/win32.d.ts.map +1 -0
- package/dist/cjs/win32.js +62 -0
- package/dist/cjs/win32.js.map +1 -0
- package/dist/mjs/index.d.ts +14 -0
- package/dist/mjs/index.d.ts.map +1 -0
- package/dist/mjs/index.js +16 -0
- package/dist/mjs/index.js.map +1 -0
- package/dist/mjs/options.d.ts +32 -0
- package/dist/mjs/options.d.ts.map +1 -0
- package/dist/mjs/options.js +2 -0
- package/dist/mjs/options.js.map +1 -0
- package/dist/mjs/package.json +3 -0
- package/dist/mjs/posix.d.ts +18 -0
- package/dist/mjs/posix.d.ts.map +1 -0
- package/dist/mjs/posix.js +62 -0
- package/dist/mjs/posix.js.map +1 -0
- package/dist/mjs/win32.d.ts +18 -0
- package/dist/mjs/win32.d.ts.map +1 -0
- package/dist/mjs/win32.js +57 -0
- package/dist/mjs/win32.js.map +1 -0
- package/package.json +4 -1
- package/.github/workflows/ci.yml +0 -39
- package/.github/workflows/typedoc.yml +0 -50
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -78
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/functions/index.isexe.html +0 -68
- package/docs/functions/index.sync.html +0 -69
- package/docs/functions/posix.isexe.html +0 -66
- package/docs/functions/posix.sync.html +0 -66
- package/docs/functions/win32.isexe.html +0 -66
- package/docs/functions/win32.sync.html +0 -66
- package/docs/index.html +0 -84
- package/docs/interfaces/options.IsexeOptions.html +0 -114
- package/docs/modules/index.html +0 -83
- package/docs/modules/options.html +0 -55
- package/docs/modules/posix.html +0 -61
- package/docs/modules/win32.html +0 -61
- package/scripts/fixup.sh +0 -16
- package/src/index.ts +0 -17
- package/src/options.ts +0 -35
- package/src/posix.ts +0 -76
- package/src/win32.ts +0 -67
- package/test/fixtures/index.ts +0 -31
- package/test/index.ts +0 -24
- package/test/options.ts +0 -19
- package/test/posix.ts +0 -137
- package/test/win32.ts +0 -96
- package/tsconfig/build.json +0 -10
- package/tsconfig/cjs.json +0 -7
- package/tsconfig/esm.json +0 -7
- package/tsconfig.json +0 -17
- package/typedoc.json +0 -5
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as posix from './posix.js';
|
|
2
|
+
import * as win32 from './win32.js';
|
|
3
|
+
export * from './options.js';
|
|
4
|
+
export { win32, posix };
|
|
5
|
+
/**
|
|
6
|
+
* Determine whether a path is executable on the current platform.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isexe: (path: string, options?: import("./options.js").IsexeOptions) => Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Synchronously determine whether a path is executable on the
|
|
11
|
+
* current platform.
|
|
12
|
+
*/
|
|
13
|
+
export declare const sync: (path: string, options?: import("./options.js").IsexeOptions) => boolean;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AAKvB;;GAEG;AACH,eAAO,MAAM,KAAK,mFAAa,CAAA;AAC/B;;;GAGG;AACH,eAAO,MAAM,IAAI,0EAAY,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.sync = exports.isexe = exports.posix = exports.win32 = void 0;
|
|
30
|
+
const posix = __importStar(require("./posix.js"));
|
|
31
|
+
exports.posix = posix;
|
|
32
|
+
const win32 = __importStar(require("./win32.js"));
|
|
33
|
+
exports.win32 = win32;
|
|
34
|
+
__exportStar(require("./options.js"), exports);
|
|
35
|
+
const platform = process.env._ISEXE_TEST_PLATFORM_ || process.platform;
|
|
36
|
+
const impl = platform === 'win32' ? win32 : posix;
|
|
37
|
+
/**
|
|
38
|
+
* Determine whether a path is executable on the current platform.
|
|
39
|
+
*/
|
|
40
|
+
exports.isexe = impl.isexe;
|
|
41
|
+
/**
|
|
42
|
+
* Synchronously determine whether a path is executable on the
|
|
43
|
+
* current platform.
|
|
44
|
+
*/
|
|
45
|
+
exports.sync = impl.sync;
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAmC;AAGnB,sBAAK;AAFrB,kDAAmC;AAE1B,sBAAK;AADd,+CAA4B;AAG5B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,OAAO,CAAC,QAAQ,CAAA;AACtE,MAAM,IAAI,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;AAEjD;;GAEG;AACU,QAAA,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;AAC/B;;;GAGG;AACU,QAAA,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA","sourcesContent":["import * as posix from './posix.js'\nimport * as win32 from './win32.js'\nexport * from './options.js'\nexport { win32, posix }\n\nconst platform = process.env._ISEXE_TEST_PLATFORM_ || process.platform\nconst impl = platform === 'win32' ? win32 : posix\n\n/**\n * Determine whether a path is executable on the current platform.\n */\nexport const isexe = impl.isexe\n/**\n * Synchronously determine whether a path is executable on the\n * current platform.\n */\nexport const sync = impl.sync\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface IsexeOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Ignore errors arising from attempting to get file access status
|
|
4
|
+
* Note that EACCES is always ignored, because that just means
|
|
5
|
+
* it's not executable. If this is not set, then attempting to check
|
|
6
|
+
* the executable-ness of a nonexistent file will raise ENOENT, for
|
|
7
|
+
* example.
|
|
8
|
+
*/
|
|
9
|
+
ignoreErrors?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* effective uid when checking executable mode flags on posix
|
|
12
|
+
* Defaults to process.getuid()
|
|
13
|
+
*/
|
|
14
|
+
uid?: number;
|
|
15
|
+
/**
|
|
16
|
+
* effective gid when checking executable mode flags on posix
|
|
17
|
+
* Defaults to process.getgid()
|
|
18
|
+
*/
|
|
19
|
+
gid?: number;
|
|
20
|
+
/**
|
|
21
|
+
* effective group ID list to use when checking executable mode flags
|
|
22
|
+
* on posix
|
|
23
|
+
* Defaults to process.getgroups()
|
|
24
|
+
*/
|
|
25
|
+
groups?: number[];
|
|
26
|
+
/**
|
|
27
|
+
* The ;-delimited path extension list for win32 implementation.
|
|
28
|
+
* Defaults to process.env.PATHEXT
|
|
29
|
+
*/
|
|
30
|
+
pathExt?: string;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IAEtB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"","sourcesContent":["export interface IsexeOptions {\n /**\n * Ignore errors arising from attempting to get file access status\n * Note that EACCES is always ignored, because that just means\n * it's not executable. If this is not set, then attempting to check\n * the executable-ness of a nonexistent file will raise ENOENT, for\n * example.\n */\n ignoreErrors?: boolean\n\n /**\n * effective uid when checking executable mode flags on posix\n * Defaults to process.getuid()\n */\n uid?: number\n\n /**\n * effective gid when checking executable mode flags on posix\n * Defaults to process.getgid()\n */\n gid?: number\n\n /**\n * effective group ID list to use when checking executable mode flags\n * on posix\n * Defaults to process.getgroups()\n */\n groups?: number[]\n\n /**\n * The ;-delimited path extension list for win32 implementation.\n * Defaults to process.env.PATHEXT\n */\n pathExt?: string\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the Posix implementation of isexe, which uses the file
|
|
3
|
+
* mode and uid/gid values.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { IsexeOptions } from './options';
|
|
8
|
+
/**
|
|
9
|
+
* Determine whether a path is executable according to the mode and
|
|
10
|
+
* current (or specified) user and group IDs.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isexe: (path: string, options?: IsexeOptions) => Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Synchronously determine whether a path is executable according to
|
|
15
|
+
* the mode and current (or specified) user and group IDs.
|
|
16
|
+
*/
|
|
17
|
+
export declare const sync: (path: string, options?: IsexeOptions) => boolean;
|
|
18
|
+
//# sourceMappingURL=posix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posix.d.ts","sourceRoot":"","sources":["../../src/posix.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,KAAK,SACV,MAAM,YACH,YAAY,KACpB,QAAQ,OAAO,CASjB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,SACT,MAAM,YACH,YAAY,KACpB,OASF,CAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This is the Posix implementation of isexe, which uses the file
|
|
4
|
+
* mode and uid/gid values.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.sync = exports.isexe = void 0;
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const promises_1 = require("fs/promises");
|
|
12
|
+
/**
|
|
13
|
+
* Determine whether a path is executable according to the mode and
|
|
14
|
+
* current (or specified) user and group IDs.
|
|
15
|
+
*/
|
|
16
|
+
const isexe = async (path, options = {}) => {
|
|
17
|
+
const { ignoreErrors = false } = options;
|
|
18
|
+
try {
|
|
19
|
+
return checkStat(await (0, promises_1.stat)(path), options);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
const er = e;
|
|
23
|
+
if (ignoreErrors || er.code === 'EACCES')
|
|
24
|
+
return false;
|
|
25
|
+
throw er;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.isexe = isexe;
|
|
29
|
+
/**
|
|
30
|
+
* Synchronously determine whether a path is executable according to
|
|
31
|
+
* the mode and current (or specified) user and group IDs.
|
|
32
|
+
*/
|
|
33
|
+
const sync = (path, options = {}) => {
|
|
34
|
+
const { ignoreErrors = false } = options;
|
|
35
|
+
try {
|
|
36
|
+
return checkStat((0, fs_1.statSync)(path), options);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
const er = e;
|
|
40
|
+
if (ignoreErrors || er.code === 'EACCES')
|
|
41
|
+
return false;
|
|
42
|
+
throw er;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.sync = sync;
|
|
46
|
+
const checkStat = (stat, options) => stat.isFile() && checkMode(stat, options);
|
|
47
|
+
const checkMode = (stat, options) => {
|
|
48
|
+
const myUid = options.uid ?? process.getuid?.();
|
|
49
|
+
const myGroups = options.groups ?? process.getgroups?.() ?? [];
|
|
50
|
+
const myGid = options.gid ?? process.getgid?.() ?? myGroups[0];
|
|
51
|
+
if (myUid === undefined || myGid === undefined) {
|
|
52
|
+
throw new Error('cannot get uid or gid');
|
|
53
|
+
}
|
|
54
|
+
const groups = new Set([myGid, ...myGroups]);
|
|
55
|
+
const mod = stat.mode;
|
|
56
|
+
const uid = stat.uid;
|
|
57
|
+
const gid = stat.gid;
|
|
58
|
+
const u = parseInt('100', 8);
|
|
59
|
+
const g = parseInt('010', 8);
|
|
60
|
+
const o = parseInt('001', 8);
|
|
61
|
+
const ug = u | g;
|
|
62
|
+
return !!(mod & o ||
|
|
63
|
+
(mod & g && groups.has(gid)) ||
|
|
64
|
+
(mod & u && uid === myUid) ||
|
|
65
|
+
(mod & ug && myUid === 0));
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=posix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posix.js","sourceRoot":"","sources":["../../src/posix.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2BAAoC;AACpC,0CAAkC;AAGlC;;;GAGG;AACI,MAAM,KAAK,GAAG,KAAK,EACxB,IAAY,EACZ,UAAwB,EAAE,EACR,EAAE;IACpB,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IACxC,IAAI;QACF,OAAO,SAAS,CAAC,MAAM,IAAA,eAAI,EAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;KAC5C;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,EAAE,GAAG,CAA0B,CAAA;QACrC,IAAI,YAAY,IAAI,EAAE,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAA;QACtD,MAAM,EAAE,CAAA;KACT;AACH,CAAC,CAAA;AAZY,QAAA,KA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G,GAAG,IAAI,CAAC,GAAG,CAAA;IACpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;IAEpB,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;IAEhB,OAAO,CAAC,CAAC,CACP,GAAG,GAAG,CAAC;QACP,CAAC,GAAG,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC,GAAG,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,CAAC;QAC1B,CAAC,GAAG,GAAG,EAAE,IAAI,KAAK,KAAK,CAAC,CAAC,CAC1B,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\n * This is the Posix implementation of isexe, which uses the file\n * mode and uid/gid values.\n *\n * @module\n */\n\nimport { Stats, statSync } from 'fs'\nimport { stat } from 'fs/promises'\nimport { IsexeOptions } from './options'\n\n/**\n * Determine whether a path is executable according to the mode and\n * current (or specified) user and group IDs.\n */\nexport const isexe = async (\n path: string,\n options: IsexeOptions = {}\n): Promise<boolean> => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(await stat(path), options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\n/**\n * Synchronously determine whether a path is executable according to\n * the mode and current (or specified) user and group IDs.\n */\nexport const sync = (\n path: string,\n options: IsexeOptions = {}\n): boolean => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(statSync(path), options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\nconst checkStat = (stat: Stats, options: IsexeOptions) =>\n stat.isFile() && checkMode(stat, options)\n\nconst checkMode = (stat: Stats, options: IsexeOptions) => {\n const myUid = options.uid ?? process.getuid?.()\n const myGroups = options.groups ?? process.getgroups?.() ?? []\n const myGid = options.gid ?? process.getgid?.() ?? myGroups[0]\n if (myUid === undefined || myGid === undefined) {\n throw new Error('cannot get uid or gid')\n }\n\n const groups = new Set([myGid, ...myGroups])\n\n const mod = stat.mode\n const uid = stat.uid\n const gid = stat.gid\n\n const u = parseInt('100', 8)\n const g = parseInt('010', 8)\n const o = parseInt('001', 8)\n const ug = u | g\n\n return !!(\n mod & o ||\n (mod & g && groups.has(gid)) ||\n (mod & u && uid === myUid) ||\n (mod & ug && myUid === 0)\n )\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the Windows implementation of isexe, which uses the file
|
|
3
|
+
* extension and PATHEXT setting.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { IsexeOptions } from './options';
|
|
8
|
+
/**
|
|
9
|
+
* Determine whether a path is executable based on the file extension
|
|
10
|
+
* and PATHEXT environment variable (or specified pathExt option)
|
|
11
|
+
*/
|
|
12
|
+
export declare const isexe: (path: string, options?: IsexeOptions) => Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Synchronously determine whether a path is executable based on the file
|
|
15
|
+
* extension and PATHEXT environment variable (or specified pathExt option)
|
|
16
|
+
*/
|
|
17
|
+
export declare const sync: (path: string, options?: IsexeOptions) => boolean;
|
|
18
|
+
//# sourceMappingURL=win32.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"win32.d.ts","sourceRoot":"","sources":["../../src/win32.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,KAAK,SACV,MAAM,YACH,YAAY,KACpB,QAAQ,OAAO,CASjB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,SACT,MAAM,YACH,YAAY,KACpB,OASF,CAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This is the Windows implementation of isexe, which uses the file
|
|
4
|
+
* extension and PATHEXT setting.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.sync = exports.isexe = void 0;
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const promises_1 = require("fs/promises");
|
|
12
|
+
/**
|
|
13
|
+
* Determine whether a path is executable based on the file extension
|
|
14
|
+
* and PATHEXT environment variable (or specified pathExt option)
|
|
15
|
+
*/
|
|
16
|
+
const isexe = async (path, options = {}) => {
|
|
17
|
+
const { ignoreErrors = false } = options;
|
|
18
|
+
try {
|
|
19
|
+
return checkStat(await (0, promises_1.stat)(path), path, options);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
const er = e;
|
|
23
|
+
if (ignoreErrors || er.code === 'EACCES')
|
|
24
|
+
return false;
|
|
25
|
+
throw er;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.isexe = isexe;
|
|
29
|
+
/**
|
|
30
|
+
* Synchronously determine whether a path is executable based on the file
|
|
31
|
+
* extension and PATHEXT environment variable (or specified pathExt option)
|
|
32
|
+
*/
|
|
33
|
+
const sync = (path, options = {}) => {
|
|
34
|
+
const { ignoreErrors = false } = options;
|
|
35
|
+
try {
|
|
36
|
+
return checkStat((0, fs_1.statSync)(path), path, options);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
const er = e;
|
|
40
|
+
if (ignoreErrors || er.code === 'EACCES')
|
|
41
|
+
return false;
|
|
42
|
+
throw er;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.sync = sync;
|
|
46
|
+
const checkPathExt = (path, options) => {
|
|
47
|
+
const { pathExt = process.env.PATHEXT || '' } = options;
|
|
48
|
+
const peSplit = pathExt.split(';');
|
|
49
|
+
if (peSplit.indexOf('') !== -1) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
for (let i = 0; i < peSplit.length; i++) {
|
|
53
|
+
const p = peSplit[i].toLowerCase();
|
|
54
|
+
const ext = path.substring(path.length - p.length).toLowerCase();
|
|
55
|
+
if (p && ext === p) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
};
|
|
61
|
+
const checkStat = (stat, path, options) => stat.isFile() && checkPathExt(path, options);
|
|
62
|
+
//# sourceMappingURL=win32.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"win32.js","sourceRoot":"","sources":["../../src/win32.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2BAAoC;AACpC,0CAAkC;AAGlC;;;GAGG;AACI,MAAM,KAAK,GAAG,KAAK,EACxB,IAAY,EACZ,UAAwB,EAAE,EACR,EAAE;IACpB,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IACxC,IAAI;QACF,OAAO,SAAS,CAAC,MAAM,IAAA,eAAI,EAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;KAClD;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,EAAE,GAAG,CAA0B,CAAA;QACrC,IAAI,YAAY,IAAI,EAAE,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAA;QACtD,MAAM,EAAE,CAAA;KACT;AACH,CAAC,CAAA;AAZY,QAAA,KAAK,SAYjB;AAED;;;GAGG;AACI,MAAM,IAAI,GAAG,CAClB,IAAY,EACZ,UAAwB,EAAE,EACjB,EAAE;IACX,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IACxC,IAAI;QACF,OAAO,S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HEXT setting.\n *\n * @module\n */\n\nimport { Stats, statSync } from 'fs'\nimport { stat } from 'fs/promises'\nimport { IsexeOptions } from './options'\n\n/**\n * Determine whether a path is executable based on the file extension\n * and PATHEXT environment variable (or specified pathExt option)\n */\nexport const isexe = async (\n path: string,\n options: IsexeOptions = {}\n): Promise<boolean> => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(await stat(path), path, options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\n/**\n * Synchronously determine whether a path is executable based on the file\n * extension and PATHEXT environment variable (or specified pathExt option)\n */\nexport const sync = (\n path: string,\n options: IsexeOptions = {}\n): boolean => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(statSync(path), path, options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\nconst checkPathExt = (path: string, options: IsexeOptions) => {\n const { pathExt = process.env.PATHEXT || '' } = options\n const peSplit = pathExt.split(';')\n if (peSplit.indexOf('') !== -1) {\n return true\n }\n\n for (let i = 0; i < peSplit.length; i++) {\n const p = peSplit[i].toLowerCase()\n const ext = path.substring(path.length - p.length).toLowerCase()\n\n if (p && ext === p) {\n return true\n }\n }\n return false\n}\n\nconst checkStat = (stat: Stats, path: string, options: IsexeOptions) =>\n stat.isFile() && checkPathExt(path, options)\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as posix from './posix.js';
|
|
2
|
+
import * as win32 from './win32.js';
|
|
3
|
+
export * from './options.js';
|
|
4
|
+
export { win32, posix };
|
|
5
|
+
/**
|
|
6
|
+
* Determine whether a path is executable on the current platform.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isexe: (path: string, options?: import("./options.js").IsexeOptions) => Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Synchronously determine whether a path is executable on the
|
|
11
|
+
* current platform.
|
|
12
|
+
*/
|
|
13
|
+
export declare const sync: (path: string, options?: import("./options.js").IsexeOptions) => boolean;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AAKvB;;GAEG;AACH,eAAO,MAAM,KAAK,mFAAa,CAAA;AAC/B;;;GAGG;AACH,eAAO,MAAM,IAAI,0EAAY,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as posix from './posix.js';
|
|
2
|
+
import * as win32 from './win32.js';
|
|
3
|
+
export * from './options.js';
|
|
4
|
+
export { win32, posix };
|
|
5
|
+
const platform = process.env._ISEXE_TEST_PLATFORM_ || process.platform;
|
|
6
|
+
const impl = platform === 'win32' ? win32 : posix;
|
|
7
|
+
/**
|
|
8
|
+
* Determine whether a path is executable on the current platform.
|
|
9
|
+
*/
|
|
10
|
+
export const isexe = impl.isexe;
|
|
11
|
+
/**
|
|
12
|
+
* Synchronously determine whether a path is executable on the
|
|
13
|
+
* current platform.
|
|
14
|
+
*/
|
|
15
|
+
export const sync = impl.sync;
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AAEvB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,OAAO,CAAC,QAAQ,CAAA;AACtE,MAAM,IAAI,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;AAC/B;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA","sourcesContent":["import * as posix from './posix.js'\nimport * as win32 from './win32.js'\nexport * from './options.js'\nexport { win32, posix }\n\nconst platform = process.env._ISEXE_TEST_PLATFORM_ || process.platform\nconst impl = platform === 'win32' ? win32 : posix\n\n/**\n * Determine whether a path is executable on the current platform.\n */\nexport const isexe = impl.isexe\n/**\n * Synchronously determine whether a path is executable on the\n * current platform.\n */\nexport const sync = impl.sync\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface IsexeOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Ignore errors arising from attempting to get file access status
|
|
4
|
+
* Note that EACCES is always ignored, because that just means
|
|
5
|
+
* it's not executable. If this is not set, then attempting to check
|
|
6
|
+
* the executable-ness of a nonexistent file will raise ENOENT, for
|
|
7
|
+
* example.
|
|
8
|
+
*/
|
|
9
|
+
ignoreErrors?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* effective uid when checking executable mode flags on posix
|
|
12
|
+
* Defaults to process.getuid()
|
|
13
|
+
*/
|
|
14
|
+
uid?: number;
|
|
15
|
+
/**
|
|
16
|
+
* effective gid when checking executable mode flags on posix
|
|
17
|
+
* Defaults to process.getgid()
|
|
18
|
+
*/
|
|
19
|
+
gid?: number;
|
|
20
|
+
/**
|
|
21
|
+
* effective group ID list to use when checking executable mode flags
|
|
22
|
+
* on posix
|
|
23
|
+
* Defaults to process.getgroups()
|
|
24
|
+
*/
|
|
25
|
+
groups?: number[];
|
|
26
|
+
/**
|
|
27
|
+
* The ;-delimited path extension list for win32 implementation.
|
|
28
|
+
* Defaults to process.env.PATHEXT
|
|
29
|
+
*/
|
|
30
|
+
pathExt?: string;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IAEtB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"","sourcesContent":["export interface IsexeOptions {\n /**\n * Ignore errors arising from attempting to get file access status\n * Note that EACCES is always ignored, because that just means\n * it's not executable. If this is not set, then attempting to check\n * the executable-ness of a nonexistent file will raise ENOENT, for\n * example.\n */\n ignoreErrors?: boolean\n\n /**\n * effective uid when checking executable mode flags on posix\n * Defaults to process.getuid()\n */\n uid?: number\n\n /**\n * effective gid when checking executable mode flags on posix\n * Defaults to process.getgid()\n */\n gid?: number\n\n /**\n * effective group ID list to use when checking executable mode flags\n * on posix\n * Defaults to process.getgroups()\n */\n groups?: number[]\n\n /**\n * The ;-delimited path extension list for win32 implementation.\n * Defaults to process.env.PATHEXT\n */\n pathExt?: string\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the Posix implementation of isexe, which uses the file
|
|
3
|
+
* mode and uid/gid values.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { IsexeOptions } from './options';
|
|
8
|
+
/**
|
|
9
|
+
* Determine whether a path is executable according to the mode and
|
|
10
|
+
* current (or specified) user and group IDs.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isexe: (path: string, options?: IsexeOptions) => Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Synchronously determine whether a path is executable according to
|
|
15
|
+
* the mode and current (or specified) user and group IDs.
|
|
16
|
+
*/
|
|
17
|
+
export declare const sync: (path: string, options?: IsexeOptions) => boolean;
|
|
18
|
+
//# sourceMappingURL=posix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posix.d.ts","sourceRoot":"","sources":["../../src/posix.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,KAAK,SACV,MAAM,YACH,YAAY,KACpB,QAAQ,OAAO,CASjB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,SACT,MAAM,YACH,YAAY,KACpB,OASF,CAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the Posix implementation of isexe, which uses the file
|
|
3
|
+
* mode and uid/gid values.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { statSync } from 'fs';
|
|
8
|
+
import { stat } from 'fs/promises';
|
|
9
|
+
/**
|
|
10
|
+
* Determine whether a path is executable according to the mode and
|
|
11
|
+
* current (or specified) user and group IDs.
|
|
12
|
+
*/
|
|
13
|
+
export const isexe = async (path, options = {}) => {
|
|
14
|
+
const { ignoreErrors = false } = options;
|
|
15
|
+
try {
|
|
16
|
+
return checkStat(await stat(path), options);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
const er = e;
|
|
20
|
+
if (ignoreErrors || er.code === 'EACCES')
|
|
21
|
+
return false;
|
|
22
|
+
throw er;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Synchronously determine whether a path is executable according to
|
|
27
|
+
* the mode and current (or specified) user and group IDs.
|
|
28
|
+
*/
|
|
29
|
+
export const sync = (path, options = {}) => {
|
|
30
|
+
const { ignoreErrors = false } = options;
|
|
31
|
+
try {
|
|
32
|
+
return checkStat(statSync(path), options);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
const er = e;
|
|
36
|
+
if (ignoreErrors || er.code === 'EACCES')
|
|
37
|
+
return false;
|
|
38
|
+
throw er;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const checkStat = (stat, options) => stat.isFile() && checkMode(stat, options);
|
|
42
|
+
const checkMode = (stat, options) => {
|
|
43
|
+
const myUid = options.uid ?? process.getuid?.();
|
|
44
|
+
const myGroups = options.groups ?? process.getgroups?.() ?? [];
|
|
45
|
+
const myGid = options.gid ?? process.getgid?.() ?? myGroups[0];
|
|
46
|
+
if (myUid === undefined || myGid === undefined) {
|
|
47
|
+
throw new Error('cannot get uid or gid');
|
|
48
|
+
}
|
|
49
|
+
const groups = new Set([myGid, ...myGroups]);
|
|
50
|
+
const mod = stat.mode;
|
|
51
|
+
const uid = stat.uid;
|
|
52
|
+
const gid = stat.gid;
|
|
53
|
+
const u = parseInt('100', 8);
|
|
54
|
+
const g = parseInt('010', 8);
|
|
55
|
+
const o = parseInt('001', 8);
|
|
56
|
+
const ug = u | g;
|
|
57
|
+
return !!(mod & o ||
|
|
58
|
+
(mod & g && groups.has(gid)) ||
|
|
59
|
+
(mod & u && uid === myUid) ||
|
|
60
|
+
(mod & ug && myUid === 0));
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=posix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posix.js","sourceRoot":"","sources":["../../src/posix.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAS,QAAQ,EAAE,MAAM,IAAI,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC;;;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AE,CAAA;IAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC9D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE;QAC9C,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;KACzC;IAED,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAA;IAE5C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAA;IACrB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;IACpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;IAEpB,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;IAEhB,OAAO,CAAC,CAAC,CACP,GAAG,GAAG,CAAC;QACP,CAAC,GAAG,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC,GAAG,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,CAAC;QAC1B,CAAC,GAAG,GAAG,EAAE,IAAI,KAAK,KAAK,CAAC,CAAC,CAC1B,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\n * This is the Posix implementation of isexe, which uses the file\n * mode and uid/gid values.\n *\n * @module\n */\n\nimport { Stats, statSync } from 'fs'\nimport { stat } from 'fs/promises'\nimport { IsexeOptions } from './options'\n\n/**\n * Determine whether a path is executable according to the mode and\n * current (or specified) user and group IDs.\n */\nexport const isexe = async (\n path: string,\n options: IsexeOptions = {}\n): Promise<boolean> => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(await stat(path), options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\n/**\n * Synchronously determine whether a path is executable according to\n * the mode and current (or specified) user and group IDs.\n */\nexport const sync = (\n path: string,\n options: IsexeOptions = {}\n): boolean => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(statSync(path), options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\nconst checkStat = (stat: Stats, options: IsexeOptions) =>\n stat.isFile() && checkMode(stat, options)\n\nconst checkMode = (stat: Stats, options: IsexeOptions) => {\n const myUid = options.uid ?? process.getuid?.()\n const myGroups = options.groups ?? process.getgroups?.() ?? []\n const myGid = options.gid ?? process.getgid?.() ?? myGroups[0]\n if (myUid === undefined || myGid === undefined) {\n throw new Error('cannot get uid or gid')\n }\n\n const groups = new Set([myGid, ...myGroups])\n\n const mod = stat.mode\n const uid = stat.uid\n const gid = stat.gid\n\n const u = parseInt('100', 8)\n const g = parseInt('010', 8)\n const o = parseInt('001', 8)\n const ug = u | g\n\n return !!(\n mod & o ||\n (mod & g && groups.has(gid)) ||\n (mod & u && uid === myUid) ||\n (mod & ug && myUid === 0)\n )\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the Windows implementation of isexe, which uses the file
|
|
3
|
+
* extension and PATHEXT setting.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { IsexeOptions } from './options';
|
|
8
|
+
/**
|
|
9
|
+
* Determine whether a path is executable based on the file extension
|
|
10
|
+
* and PATHEXT environment variable (or specified pathExt option)
|
|
11
|
+
*/
|
|
12
|
+
export declare const isexe: (path: string, options?: IsexeOptions) => Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Synchronously determine whether a path is executable based on the file
|
|
15
|
+
* extension and PATHEXT environment variable (or specified pathExt option)
|
|
16
|
+
*/
|
|
17
|
+
export declare const sync: (path: string, options?: IsexeOptions) => boolean;
|
|
18
|
+
//# sourceMappingURL=win32.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"win32.d.ts","sourceRoot":"","sources":["../../src/win32.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,KAAK,SACV,MAAM,YACH,YAAY,KACpB,QAAQ,OAAO,CASjB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,SACT,MAAM,YACH,YAAY,KACpB,OASF,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the Windows implementation of isexe, which uses the file
|
|
3
|
+
* extension and PATHEXT setting.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { statSync } from 'fs';
|
|
8
|
+
import { stat } from 'fs/promises';
|
|
9
|
+
/**
|
|
10
|
+
* Determine whether a path is executable based on the file extension
|
|
11
|
+
* and PATHEXT environment variable (or specified pathExt option)
|
|
12
|
+
*/
|
|
13
|
+
export const isexe = async (path, options = {}) => {
|
|
14
|
+
const { ignoreErrors = false } = options;
|
|
15
|
+
try {
|
|
16
|
+
return checkStat(await stat(path), path, options);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
const er = e;
|
|
20
|
+
if (ignoreErrors || er.code === 'EACCES')
|
|
21
|
+
return false;
|
|
22
|
+
throw er;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Synchronously determine whether a path is executable based on the file
|
|
27
|
+
* extension and PATHEXT environment variable (or specified pathExt option)
|
|
28
|
+
*/
|
|
29
|
+
export const sync = (path, options = {}) => {
|
|
30
|
+
const { ignoreErrors = false } = options;
|
|
31
|
+
try {
|
|
32
|
+
return checkStat(statSync(path), path, options);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
const er = e;
|
|
36
|
+
if (ignoreErrors || er.code === 'EACCES')
|
|
37
|
+
return false;
|
|
38
|
+
throw er;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const checkPathExt = (path, options) => {
|
|
42
|
+
const { pathExt = process.env.PATHEXT || '' } = options;
|
|
43
|
+
const peSplit = pathExt.split(';');
|
|
44
|
+
if (peSplit.indexOf('') !== -1) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
for (let i = 0; i < peSplit.length; i++) {
|
|
48
|
+
const p = peSplit[i].toLowerCase();
|
|
49
|
+
const ext = path.substring(path.length - p.length).toLowerCase();
|
|
50
|
+
if (p && ext === p) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
};
|
|
56
|
+
const checkStat = (stat, path, options) => stat.isFile() && checkPathExt(path, options);
|
|
57
|
+
//# sourceMappingURL=win32.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"win32.js","sourceRoot":"","sources":["../../src/win32.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAS,QAAQ,EAAE,MAAM,IAAI,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACxB,IAAY,EACZ,UAAwB,EAAE,EACR,EAAE;IACpB,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IACxC,IAAI;QACF,OAAO,SAAS,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;KAClD;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,EAAE,GAAG,CAA0B,CAAA;QACr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AO,IAAI,CAAA;SACZ;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,IAAW,EAAE,IAAY,EAAE,OAAqB,EAAE,EAAE,CACrE,IAAI,CAAC,MAAM,EAAE,IAAI,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA","sourcesContent":["/**\n * This is the Windows implementation of isexe, which uses the file\n * extension and PATHEXT setting.\n *\n * @module\n */\n\nimport { Stats, statSync } from 'fs'\nimport { stat } from 'fs/promises'\nimport { IsexeOptions } from './options'\n\n/**\n * Determine whether a path is executable based on the file extension\n * and PATHEXT environment variable (or specified pathExt option)\n */\nexport const isexe = async (\n path: string,\n options: IsexeOptions = {}\n): Promise<boolean> => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(await stat(path), path, options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\n/**\n * Synchronously determine whether a path is executable based on the file\n * extension and PATHEXT environment variable (or specified pathExt option)\n */\nexport const sync = (\n path: string,\n options: IsexeOptions = {}\n): boolean => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(statSync(path), path, options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\nconst checkPathExt = (path: string, options: IsexeOptions) => {\n const { pathExt = process.env.PATHEXT || '' } = options\n const peSplit = pathExt.split(';')\n if (peSplit.indexOf('') !== -1) {\n return true\n }\n\n for (let i = 0; i < peSplit.length; i++) {\n const p = peSplit[i].toLowerCase()\n const ext = path.substring(path.length - p.length).toLowerCase()\n\n if (p && ext === p) {\n return true\n }\n }\n return false\n}\n\nconst checkStat = (stat: Stats, path: string, options: IsexeOptions) =>\n stat.isFile() && checkPathExt(path, options)\n"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isexe",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Minimal module to check if a file is executable.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/mjs/index.js",
|
|
7
7
|
"types": "./dist/cjs/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
8
11
|
"exports": {
|
|
9
12
|
".": {
|
|
10
13
|
"import": {
|