is-executable 2.0.1 → 2.0.2

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 (2) hide show
  1. package/index.js +24 -4
  2. package/package.json +5 -2
package/index.js CHANGED
@@ -8,8 +8,18 @@ const pathExts = isWindows ? new Set(process.env.PATHEXT?.split(';').map(pathExt
8
8
 
9
9
  export async function isExecutable(filePath) {
10
10
  try {
11
- await fsPromises.access(filePath, fs.X_OK);
12
- return isWindows ? pathExts.has(path.extname(filePath)) : true;
11
+ const stats = await fsPromises.stat(filePath);
12
+
13
+ if (isWindows) {
14
+ return stats.isFile() && pathExts.has(path.extname(filePath));
15
+ }
16
+
17
+ if (!stats.isFile()) {
18
+ return false;
19
+ }
20
+
21
+ await fsPromises.access(filePath, fs.constants.X_OK);
22
+ return true;
13
23
  } catch {
14
24
  return false;
15
25
  }
@@ -17,8 +27,18 @@ export async function isExecutable(filePath) {
17
27
 
18
28
  export function isExecutableSync(filePath) {
19
29
  try {
20
- fs.accessSync(filePath, fs.X_OK);
21
- return isWindows ? pathExts.has(path.extname(filePath)) : true;
30
+ const stats = fs.statSync(filePath);
31
+
32
+ if (isWindows) {
33
+ return stats.isFile() && pathExts.has(path.extname(filePath));
34
+ }
35
+
36
+ if (!stats.isFile()) {
37
+ return false;
38
+ }
39
+
40
+ fs.accessSync(filePath, fs.constants.X_OK);
41
+ return true;
22
42
  } catch {
23
43
  return false;
24
44
  }
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "is-executable",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Check whether a file can be executed",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/is-executable",
7
7
  "funding": "https://github.com/sponsors/sindresorhus",
8
8
  "type": "module",
9
9
  "exports": "./index.js",
10
+ "types": "./index.d.ts",
11
+ "sideEffects": false,
10
12
  "engines": {
11
13
  "node": ">=14.16"
12
14
  },
13
15
  "scripts": {
14
- "test": "xo && ava && tsd"
16
+ "//test": "xo && ava && tsd",
17
+ "test": "ava"
15
18
  },
16
19
  "files": [
17
20
  "index.js",