teen_process 2.0.2 → 2.0.4

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/lib/helpers.js CHANGED
@@ -1,5 +1,5 @@
1
- import which from 'which';
2
- import fs from 'fs';
1
+ import path from 'path';
2
+ import fs from 'fs/promises';
3
3
 
4
4
  /**
5
5
  * Decorates ENOENT error received from a spawn system call
@@ -8,24 +8,30 @@ import fs from 'fs';
8
8
  * @param {NodeJS.ErrnoException} error Original error instance. !!! The instance is mutated after
9
9
  * this helper function invocation
10
10
  * @param {string} cmd Original command to execute
11
- * @param {string|URL?} [cwd] Optional path to the current working dir
12
- * @returns {NodeJS.ErrnoException} Mutated error instance with an improved description or an
11
+ * @param {string?} [cwd] Optional path to the current working dir
12
+ * @returns {Promise<NodeJS.ErrnoException>} Mutated error instance with an improved description or an
13
13
  * unchanged error instance
14
14
  */
15
- function formatEnoent (error, cmd, cwd = null) {
16
- try {
17
- which.sync(cmd);
18
- if (cwd) {
19
- try {
20
- fs.accessSync(cwd, fs.constants.R_OK);
21
- } catch (ign) {
22
- error.message = `The current working directory '${cwd}' for '${cmd}' command ` +
23
- `either does not exist or is not accessible`;
15
+ async function formatEnoent (error, cmd, cwd = null) {
16
+ if (cwd) {
17
+ try {
18
+ const stat = await fs.stat(cwd);
19
+ if (!stat.isDirectory()) {
20
+ error.message = `The working directory '${cwd}' of '${cmd}' is not a valid folder path`;
21
+ return error;
22
+ }
23
+ } catch (e) {
24
+ if (e.code === 'ENOENT') {
25
+ error.message = `The working directory '${cwd}' of '${cmd}' does not exist`;
26
+ return error;
24
27
  }
25
28
  }
26
- } catch (ign) {
27
- error.message = `Command '${cmd}' not found. Is it installed?`;
28
29
  }
30
+
31
+ const curDir = path.resolve(cwd ?? process.cwd());
32
+ const pathMsg = process.env.PATH ?? 'which is not defined for the process';
33
+ error.message = `'${cmd}' executable is not found neither in the process working folder (${curDir}) ` +
34
+ `nor in any folders specified in the PATH environment variable (${pathMsg})`;
29
35
  return error;
30
36
  }
31
37
 
package/lib/index.js CHANGED
@@ -1,9 +1,10 @@
1
- // transpile:main
1
+ import {install} from 'source-map-support';
2
+ install();
3
+
2
4
  import * as cp from 'child_process';
3
5
  import * as spIndex from './subprocess';
4
6
  import * as execIndex from './exec';
5
7
 
6
-
7
8
  const { spawn } = cp;
8
9
  const { SubProcess } = spIndex;
9
10
  const { exec } = execIndex;
package/lib/subprocess.js CHANGED
@@ -198,12 +198,12 @@ class SubProcess extends EventEmitter {
198
198
  };
199
199
 
200
200
  // if we get an error spawning the proc, reject and clean up the proc
201
- this.proc.on('error', /** @param {NodeJS.ErrnoException} err */ (err) => {
201
+ this.proc.on('error', /** @param {NodeJS.ErrnoException} err */ async (err) => {
202
202
  this.proc?.removeAllListeners('exit');
203
203
  this.proc?.kill('SIGINT');
204
204
 
205
205
  if (err.code === 'ENOENT') {
206
- err = formatEnoent(err, this.cmd, this.opts?.cwd);
206
+ err = await formatEnoent(err, this.cmd, this.opts?.cwd);
207
207
  }
208
208
  reject(err);
209
209
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teen_process",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "A grown up version of Node's spawn/exec",
5
5
  "keywords": [
6
6
  "child_process",
@@ -31,14 +31,16 @@
31
31
  "build/lib"
32
32
  ],
33
33
  "scripts": {
34
- "build": "babel --out-dir=build/lib lib",
34
+ "build": "tsc -b",
35
+ "clean": "npm run build -- --clean",
35
36
  "dev": "npm run build -- --watch",
36
37
  "lint": "eslint .",
37
38
  "lint:fix": "npm run lint -- --fix",
38
39
  "lint:types": "tsc",
39
40
  "precommit-lint": "lint-staged",
40
41
  "precommit-msg": "echo 'Pre-commit checks...' && exit 0",
41
- "prepare": "npm run build",
42
+ "prepare": "npm run rebuild",
43
+ "rebuild": "npm run clean && npm run build",
42
44
  "test": "mocha"
43
45
  },
44
46
  "pre-commit": [
@@ -56,46 +58,42 @@
56
58
  "singleQuote": true
57
59
  },
58
60
  "dependencies": {
59
- "@babel/runtime": "7.19.0",
60
61
  "bluebird": "3.7.2",
61
62
  "lodash": "4.17.21",
62
- "shell-quote": "1.7.3",
63
- "source-map-support": "0.5.21",
64
- "which": "2.0.2"
63
+ "shell-quote": "1.8.1",
64
+ "source-map-support": "0.5.21"
65
65
  },
66
66
  "devDependencies": {
67
- "@appium/eslint-config-appium": "7.0.0",
68
- "@appium/support": "2.60.0",
69
- "@babel/cli": "7.18.10",
70
- "@babel/core": "7.19.1",
71
- "@babel/eslint-parser": "7.19.1",
72
- "@babel/plugin-transform-runtime": "7.19.1",
73
- "@babel/preset-env": "7.19.1",
74
- "@babel/register": "7.18.9",
75
- "@types/bluebird": "3.5.37",
76
- "@types/chai": "4.3.3",
67
+ "@appium/eslint-config-appium": "8.0.3",
68
+ "@appium/tsconfig": "0.3.0",
69
+ "@appium/types": "0.11.1",
70
+ "@types/bluebird": "3.5.38",
71
+ "@types/chai": "4.3.5",
77
72
  "@types/chai-as-promised": "7.1.5",
78
- "@types/lodash": "4.14.185",
79
- "@types/mocha": "9.1.1",
80
- "@types/node": "18.6.5",
73
+ "@types/lodash": "4.14.195",
74
+ "@types/mocha": "10.0.1",
75
+ "@types/node": "18.16.18",
81
76
  "@types/shell-quote": "1.7.1",
82
- "@types/which": "2.0.1",
83
- "babel-plugin-source-map-support": "2.2.0",
84
- "chai": "4.3.6",
77
+ "@types/sinon": "10.0.15",
78
+ "@types/source-map-support": "0.5.6",
79
+ "@types/ws": "8.5.4",
80
+ "chai": "4.3.7",
85
81
  "chai-as-promised": "7.1.1",
86
- "eslint": "8.24.0",
87
- "eslint-config-prettier": "8.5.0",
88
- "eslint-plugin-import": "2.26.0",
82
+ "eslint": "8.42.0",
83
+ "eslint-config-prettier": "8.8.0",
84
+ "eslint-plugin-import": "2.27.5",
89
85
  "eslint-plugin-mocha": "10.1.0",
90
- "eslint-plugin-promise": "6.0.1",
91
- "lint-staged": "13.0.3",
92
- "mocha": "10.0.0",
86
+ "eslint-plugin-promise": "6.1.1",
87
+ "lint-staged": "13.2.2",
88
+ "mocha": "10.2.0",
93
89
  "pre-commit": "1.2.2",
94
- "prettier": "2.7.1",
95
- "typescript": "4.8.3"
90
+ "prettier": "2.8.8",
91
+ "sinon": "15.1.2",
92
+ "typescript": "5.1.3",
93
+ "ts-node": "10.9.1"
96
94
  },
97
95
  "engines": {
98
- "node": ">=14",
99
- "npm": ">=6"
96
+ "node": "^14.17.0 || ^16.13.0 || >=18.0.0",
97
+ "npm": ">=8"
100
98
  }
101
99
  }