node-version-utils 0.1.19 → 0.3.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.
@@ -0,0 +1,11 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: npm
4
+ directory: '/'
5
+ schedule:
6
+ interval: daily
7
+ - package-ecosystem: 'github-actions'
8
+ directory: '/'
9
+ schedule:
10
+ # Check for updates to GitHub Actions every weekday
11
+ interval: 'daily'
@@ -0,0 +1,22 @@
1
+ name: CI
2
+ on:
3
+ - push
4
+ - pull_request
5
+ jobs:
6
+ test:
7
+ name: Node.js ${{ matrix.node-version }} ${{ matrix.os }}
8
+ runs-on: ${{ matrix.os }}
9
+ strategy:
10
+ matrix:
11
+ node: ['latest']
12
+ os: [ubuntu-latest, windows-latest, macOS-latest]
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: actions/setup-node@v2.4.1
16
+ with:
17
+ node-version: ${{ matrix.node-version }}
18
+ - run: git config --global user.name "Github Actions"
19
+ - run: git config --global user.email "actions@users.noreply.github.com"
20
+ - run: npm ci
21
+ - run: npm run lint
22
+ - run: npm run test:engines
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  module.exports = {
2
2
  spawn: require('./lib/spawn'),
3
+ spawnSync: require('./lib/spawnSync'),
3
4
  };
package/lib/spawn.js CHANGED
@@ -1,15 +1,9 @@
1
- var assign = require('object-assign');
2
1
  var crossSpawn = require('cross-spawn-cb');
3
- var prepend = require('path-string-prepend');
4
2
 
5
- var envForInstallPath = require('./envForInstallPath');
6
- var PATH_KEY = require('./constants').PATH_KEY;
3
+ var spawnOptions = require('./spawnOptions');
7
4
 
8
5
  function spawn(installPath, command, args, options, callback) {
9
- // put the path to node and npm at the front and remove nvs
10
- var env = envForInstallPath(process.env, installPath);
11
- env[PATH_KEY] = prepend(env[PATH_KEY] || '', env.npm_config_binroot);
12
- crossSpawn(command, args, assign({}, options, { cwd: process.cwd(), env: env, execPath: env.npm_node_execpath, path: env[PATH_KEY] }), callback);
6
+ crossSpawn(command, args, spawnOptions(installPath, options), callback);
13
7
  }
14
8
 
15
9
  module.exports = function spawnWrapper(installPath, command, args, options, callback) {
@@ -0,0 +1,43 @@
1
+ var path = require('path');
2
+ var assign = require('just-extend');
3
+ var prepend = require('path-string-prepend');
4
+ var NODE = process.platform === 'win32' ? 'node.exe' : 'node';
5
+ var PATH_KEY = require('env-path-key')();
6
+
7
+ var isWindows = process.platform === 'win32';
8
+
9
+ module.exports = function envForInstallPath(installPath, options) {
10
+ var processEnv = process.env;
11
+ var env = {};
12
+ env.npm_config_binroot = isWindows ? installPath : path.join(installPath, 'bin');
13
+ env.npm_config_root = isWindows ? installPath : path.join(installPath, 'lib');
14
+ env.npm_config_man = isWindows ? installPath : path.join(installPath, 'man');
15
+ env.npm_config_prefix = installPath;
16
+ env.npm_node_execpath = path.join(env.npm_config_binroot, NODE);
17
+
18
+ // copy the environment not for npm and skip case-insesitive additional paths
19
+ for (var key in processEnv) {
20
+ // skip npm_ variants
21
+ if (key.length > 4 && (key[0] === 'n' || key[0] === 'N') && (key[1] === 'p' || key[1] === 'P') && (key[2] === 'm' || key[2] === 'M') && key[3] === '_')
22
+ continue;
23
+
24
+ // skip non-matching path
25
+ if (
26
+ key.length === 4 &&
27
+ (key[0] === 'p' || key[0] === 'P') &&
28
+ (key[1] === 'a' || key[1] === 'A') &&
29
+ (key[2] === 't' || key[2] === 'T') &&
30
+ (key[3] === 'h' || key[3] === 'H') &&
31
+ key !== PATH_KEY
32
+ )
33
+ continue;
34
+ env[key] = processEnv[key];
35
+ }
36
+
37
+ // override node
38
+ if (env.NODE !== undefined) env.NODE = env.npm_node_execpath;
39
+
40
+ // put the path to node and npm at the front and remove nvs
41
+ env[PATH_KEY] = prepend(env[PATH_KEY] || '', env.npm_config_binroot);
42
+ return assign({}, options, { cwd: process.cwd(), env: env, execPath: env.npm_node_execpath, path: env[PATH_KEY] });
43
+ };
@@ -0,0 +1,6 @@
1
+ var crossSpawn = require('cross-spawn-cb');
2
+ var spawnOptions = require('./spawnOptions');
3
+
4
+ module.exports = function spawnSync(installPath, command, args, options) {
5
+ return crossSpawn.sync(command, args, spawnOptions(installPath, options));
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-version-utils",
3
- "version": "0.1.19",
3
+ "version": "0.3.1",
4
4
  "description": "Utilities for running commands on a specific version of node by installed path",
5
5
  "keywords": [
6
6
  "node",
@@ -24,18 +24,20 @@
24
24
  "format": "prettier --write .",
25
25
  "lint": "eslint .",
26
26
  "prepublishOnly": "dtd \"npm run lint\" \"depcheck\"",
27
- "test": "mocha-compat test/spec/**/*.test.js --no-timeouts"
27
+ "test": "mocha-compat test/spec/**/*.test.js --no-timeouts",
28
+ "test:engines": "nvu engines npm test"
28
29
  },
29
30
  "dependencies": {
30
- "cross-spawn-cb": "^0.3.1",
31
- "object-assign": "^4.1.1",
31
+ "cross-spawn-cb": "^0.5.2",
32
+ "env-path-key": "^0.2.0",
33
+ "just-extend": "^6.0.1",
32
34
  "path-string-prepend": "^0.2.0"
33
35
  },
34
36
  "devDependencies": {
35
- "babel-eslint": "^10.1.0",
37
+ "@typescript-eslint/parser": "^5.30.0",
36
38
  "cr": "^0.1.0",
37
- "depcheck": "^1.0.0",
38
- "dis-dat": "^0.1.3",
39
+ "depcheck": "^1.4.3",
40
+ "dis-dat": "^0.1.5",
39
41
  "eslint": "^6.8.0",
40
42
  "eslint-config-prettier": "^6.11.0",
41
43
  "eslint-config-standard": "^14.1.1",
@@ -47,12 +49,13 @@
47
49
  "lodash.find": "^4.6.0",
48
50
  "match-semver": "^0.1.0",
49
51
  "mocha-compat": "^3.5.5",
50
- "node-install-release": "^0.1.31",
51
- "prettier": "^2.3.2",
52
+ "node-install-release": "^0.2.4",
53
+ "node-version-use": "^0.2.2",
54
+ "prettier": "^2.7.1",
52
55
  "rimraf": "^2.7.1",
53
56
  "semver": "^5.7.1"
54
57
  },
55
58
  "engines": {
56
- "node": ">=0.12"
59
+ "node": ">=0.10"
57
60
  }
58
61
  }
package/lib/constants.js DELETED
@@ -1,18 +0,0 @@
1
- var isWindows = process.platform === 'win32';
2
-
3
- function windowsPathKey() {
4
- var pathKey = 'Path';
5
-
6
- for (var key in process.env) {
7
- if (key.toUpperCase() === 'PATH') {
8
- pathKey = key;
9
- if (pathKey !== 'PATH') return key; // 'which' in cross-spawn uses PATH in windows, but this causes issues in repeat spawn calls given PATH get propagated so PATH_KEY needs to select 'Path' over 'PATH' if both exist
10
- }
11
- }
12
- return pathKey;
13
- }
14
-
15
- module.exports = {
16
- PATH_KEY: isWindows ? windowsPathKey() : 'PATH',
17
- NODE: isWindows ? 'node.exe' : 'node',
18
- };
@@ -1,26 +0,0 @@
1
- var path = require('path');
2
- var NODE = require('./constants').NODE;
3
- var PATH_KEY = require('./constants').PATH_KEY;
4
-
5
- var isWindows = process.platform === 'win32';
6
-
7
- module.exports = function envForInstallPath(env, installPath) {
8
- var installEnv = {};
9
- installEnv.npm_config_binroot = isWindows ? installPath : path.join(installPath, 'bin');
10
- installEnv.npm_config_root = isWindows ? installPath : path.join(installPath, 'lib');
11
- installEnv.npm_config_man = isWindows ? installPath : path.join(installPath, 'man');
12
- installEnv.npm_config_prefix = installPath;
13
- installEnv.npm_node_execpath = path.join(installEnv.npm_config_binroot, NODE);
14
-
15
- // copy the environment not for npm and skip case-insesitive additional paths
16
- for (var key in env) {
17
- var lowerKey = key.toLowerCase();
18
- if (lowerKey.indexOf('npm_') === 0) continue;
19
- if (lowerKey === 'path' && key !== PATH_KEY) continue;
20
- installEnv[key] = env[key];
21
- }
22
-
23
- // override node
24
- if (installEnv.NODE !== undefined) installEnv.NODE = installEnv.npm_node_execpath;
25
- return installEnv;
26
- };