is-executable 1.0.1 → 2.0.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.
package/index.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ Check whether a file can be executed.
3
+
4
+ @param filePath - The file to check.
5
+
6
+ @example
7
+ ```
8
+ import {isExecutable} from 'is-executable';
9
+
10
+ // On macOS
11
+ await isExecutable('/usr/bin/bash');
12
+ //=> true
13
+
14
+ // On macOS
15
+ await isExecutable('/Users/sindresorhus/unicorn.png');
16
+ //=> false
17
+
18
+ // On Windows
19
+ await isExecutable('c:\\Windows\\notepad.exe');
20
+ //=> true
21
+ ```
22
+ */
23
+ export function isExecutable(filePath: string): Promise<boolean>;
24
+
25
+ /**
26
+ Check whether a file can be executed.
27
+
28
+ @param filePath - The file to check.
29
+
30
+ @example
31
+ ```
32
+ import {isExecutableSync} from 'is-executable';
33
+
34
+ // On macOS
35
+ isExecutableSync('/usr/bin/bash');
36
+ //=> true
37
+
38
+ // On macOS
39
+ isExecutableSync('/Users/sindresorhus/unicorn.png');
40
+ //=> false
41
+
42
+ // On Windows
43
+ isExecutableSync('c:\\Windows\\notepad.exe');
44
+ //=> true
45
+ ```
46
+ */
47
+ export function isExecutableSync(filePath: string): boolean;
package/index.js CHANGED
@@ -1,41 +1,25 @@
1
- 'use strict';
1
+ import process from 'node:process';
2
+ import path from 'node:path';
3
+ import fs from 'node:fs';
4
+ import fsPromises from 'node:fs/promises';
2
5
 
3
- var os = require('os');
4
- var path = require('path');
6
+ const isWindows = process.platform === 'win32';
7
+ const pathExts = isWindows ? new Set(process.env.PATHEXT?.split(';').map(pathExt => pathExt.toLowerCase())) : [];
5
8
 
6
- var fs = require('graceful-fs');
9
+ export async function isExecutable(filePath) {
10
+ try {
11
+ await fsPromises.access(filePath, fs.X_OK);
12
+ return isWindows ? pathExts.has(path.extname(filePath)) : true;
13
+ } catch {
14
+ return false;
15
+ }
16
+ }
7
17
 
8
- var isWindows = os.type().indexOf('Windows') === 0;
9
-
10
- var pathExts = !isWindows ? [] : (function () {
11
- /* eslint-disable no-process-env */ // need this for cross-platform use
12
- return (process.env.PATHEXT || '').split(';').map(function (pathExt) {
13
- return pathExt.toLowerCase();
14
- });
15
- /* eslint-enable no-process-env */
16
- }());
17
-
18
- module.exports = function isExe (filePath) {
19
- return new Promise(function (resolve) {
20
- fs.access(filePath, fs.X_OK, function (err) {
21
- if (err) {
22
- resolve(false);
23
- return;
24
- }
25
- if (isWindows) {
26
- resolve(pathExts.indexOf(path.extname(filePath)) !== -1);
27
- return;
28
- }
29
- resolve(true);
30
- });
31
- });
32
- };
33
-
34
- module.exports.sync = function isExeSync (filePath) {
35
- try {
36
- fs.accessSync(filePath, fs.X_OK);
37
- return !isWindows ? true : pathExts.indexOf(path.extname(filePath)) !== -1;
38
- } catch (err) {
39
- return false;
40
- }
41
- };
18
+ export function isExecutableSync(filePath) {
19
+ try {
20
+ fs.accessSync(filePath, fs.X_OK);
21
+ return isWindows ? pathExts.has(path.extname(filePath)) : true;
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
package/license ADDED
@@ -0,0 +1,10 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+ Copyright (c) Ron Waldon
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json CHANGED
@@ -1,43 +1,37 @@
1
1
  {
2
- "name": "is-executable",
3
- "description": "cross-platform helper to determine whether a file can be executed",
4
- "version": "1.0.1",
5
- "bugs": {
6
- "url": "https://github.com/jokeyrhyme/is-executable.js/issues"
7
- },
8
- "dependencies": {
9
- "graceful-fs": "4.1.2"
10
- },
11
- "devDependencies": {
12
- "@jokeyrhyme/eslint-config-es2015": "1.0.0",
13
- "@jokeyrhyme/eslint-config-es5": "^1.0.0",
14
- "ava": "^0.7.0",
15
- "eslint": "^1.10.3",
16
- "eslint-config-semistandard": "^5.0.0",
17
- "eslint-config-standard": "^4.4.0",
18
- "eslint-plugin-standard": "^1.3.1",
19
- "fixpack": "^2.2.0",
20
- "npm-run-all": "^1.4.0"
21
- },
22
- "engines": {
23
- "node": ">=4.0.0",
24
- "npm": ">=3.0.0"
25
- },
26
- "files": [
27
- "index.js"
28
- ],
29
- "homepage": "https://github.com/jokeyrhyme/is-executable.js#readme",
30
- "keywords": [],
31
- "license": "BSD-2-Clause",
32
- "main": "index.js",
33
- "repository": {
34
- "type": "git",
35
- "url": "git+https://github.com/jokeyrhyme/is-executable.js.git"
36
- },
37
- "scripts": {
38
- "eslint": "eslint --fix .",
39
- "fixpack": "fixpack",
40
- "posttest": "npm-run-all eslint fixpack",
41
- "test": "ava"
42
- }
2
+ "name": "is-executable",
3
+ "version": "2.0.0",
4
+ "description": "Check whether a file can be executed",
5
+ "license": "MIT",
6
+ "repository": "sindresorhus/is-executable",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "type": "module",
9
+ "exports": "./index.js",
10
+ "engines": {
11
+ "node": "=>14.16"
12
+ },
13
+ "scripts": {
14
+ "test": "xo && ava && tsd"
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "index.d.ts"
19
+ ],
20
+ "keywords": [
21
+ "executable",
22
+ "execute",
23
+ "exe",
24
+ "file",
25
+ "binary",
26
+ "check",
27
+ "detect",
28
+ "access",
29
+ "fs",
30
+ "permission"
31
+ ],
32
+ "devDependencies": {
33
+ "ava": "^4.3.3",
34
+ "tsd": "^0.24.1",
35
+ "xo": "^0.52.4"
36
+ }
43
37
  }
package/readme.md ADDED
@@ -0,0 +1,33 @@
1
+ # is-executable
2
+
3
+ > Check whether a file can be [executed](https://www.yesik.it/blog/2018-the-x-permission-bit)
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install is-executable
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import {isExecutable} from 'is-executable';
15
+
16
+ // On macOS
17
+ await isExecutable('/usr/bin/bash');
18
+ //=> true
19
+
20
+ // On macOS
21
+ await isExecutable('/Users/sindresorhus/unicorn.png');
22
+ //=> false
23
+
24
+ // On Windows
25
+ await isExecutable('c:\\Windows\\notepad.exe');
26
+ //=> true
27
+ ```
28
+
29
+ ## API
30
+
31
+ ### `isExecutable(filePath: string) => Promise<boolean>`
32
+
33
+ ### `isExecutableSync(filePath: string) => boolean`
package/LICENSE DELETED
@@ -1,24 +0,0 @@
1
- Copyright (c) 2015, Ron Waldon
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
6
-
7
- * Redistributions of source code must retain the above copyright notice, this
8
- list of conditions and the following disclaimer.
9
-
10
- * Redistributions in binary form must reproduce the above copyright notice,
11
- this list of conditions and the following disclaimer in the documentation
12
- and/or other materials provided with the distribution.
13
-
14
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
-
package/README.md DELETED
@@ -1,31 +0,0 @@
1
- # is-executable.js
2
-
3
- cross-platform helper to determine whether a file can be executed
4
-
5
- [![npm module](https://img.shields.io/npm/v/is-executable.svg)](https://www.npmjs.com/package/is-executable)
6
- [![Build Status](https://travis-ci.org/jokeyrhyme/is-executable.js.png)](https://travis-ci.org/jokeyrhyme/is-executable.js)
7
- [![Build status](https://ci.appveyor.com/api/projects/status/bbip8ej03e57p3e2/branch/master?svg=true)](https://ci.appveyor.com/project/jokeyrhyme/is-executable-js/branch/master)
8
-
9
-
10
- ## Why?
11
-
12
- Node.js' built-in [`fs.access()`](https://nodejs.org/dist/latest-v5.x/docs/api/fs.html#fs_fs_access_path_mode_callback) is not useful enough for Windows use cases.
13
-
14
-
15
- ## Usage
16
-
17
- ```js
18
- const isExe = require('is-executable');
19
-
20
- isExe.sync('c:\\Windows\\notepad.exe'); // => true on Windows
21
- isExe.sync('/usr/bin/bash'); // => true on OS X / Linux
22
- ```
23
-
24
-
25
- ## API
26
-
27
-
28
- ### isExe (filePath: String) => Promise
29
-
30
-
31
- ### isExe.sync (filePath: String) => Boolean