node-version-utils 0.2.0 → 0.4.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/.eslintrc.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": ["standard", "prettier"],
3
+ "parser": "@typescript-eslint/parser",
4
+ "env": {
5
+ "es6": true,
6
+ "node": true,
7
+ "mocha": true
8
+ },
9
+ "rules": {
10
+ "no-var": "off",
11
+ "object-shorthand": "off"
12
+ }
13
+ }
@@ -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,23 @@
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 install node-version-use -g
21
+ - run: npm ci
22
+ - run: npm run lint
23
+ - run: nvu engines --desc npm run test
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,37 @@
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 pathKey = require('cross-spawn-cb').pathKey;
6
+ var startsCaseInsensitiveFn = require('./startsCaseInsensitiveFn');
7
+
8
+ var isWindows = process.platform === 'win32';
9
+
10
+ var startsNPM = startsCaseInsensitiveFn('npm_');
11
+ var startsPath = startsCaseInsensitiveFn('path');
12
+
13
+ module.exports = function spawnOptions(installPath, options) {
14
+ var PATH_KEY = pathKey();
15
+ var processEnv = process.env;
16
+ var env = {};
17
+ env.npm_config_binroot = isWindows ? installPath : path.join(installPath, 'bin');
18
+ env.npm_config_root = isWindows ? installPath : path.join(installPath, 'lib');
19
+ env.npm_config_man = isWindows ? installPath : path.join(installPath, 'man');
20
+ env.npm_config_prefix = installPath;
21
+ env.npm_node_execpath = path.join(env.npm_config_binroot, NODE);
22
+
23
+ // copy the environment not for npm and skip case-insesitive additional paths
24
+ for (var key in processEnv) {
25
+ // skip npm_ variants and non-matching path
26
+ if (key.length > 4 && startsNPM(key)) continue;
27
+ if (key.length === 4 && startsPath(key) && key !== PATH_KEY) continue;
28
+ env[key] = processEnv[key];
29
+ }
30
+
31
+ // override node
32
+ if (env.NODE !== undefined) env.NODE = env.npm_node_execpath;
33
+
34
+ // put the path to node and npm at the front and remove nvs
35
+ env[PATH_KEY] = prepend(env[PATH_KEY] || '', env.npm_config_binroot);
36
+ return assign({}, options, { cwd: process.cwd(), env: env, execPath: env.npm_node_execpath, path: env[PATH_KEY] });
37
+ };
@@ -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
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = function startsCaseInsensitiveFn(string) {
2
+ var lower = string.toLowerCase();
3
+ var upper = string.toUpperCase();
4
+ return function startsCaseInsensitive(key) {
5
+ if (key.length < string.length) return false;
6
+ for (var i = 0; i < string.length; i++) {
7
+ if (key[i] !== lower[i] && key[i] !== upper[i]) return false;
8
+ }
9
+ return true;
10
+ };
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-version-utils",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Utilities for running commands on a specific version of node by installed path",
5
5
  "keywords": [
6
6
  "node",
@@ -27,32 +27,30 @@
27
27
  "test": "mocha-compat test/spec/**/*.test.js --no-timeouts"
28
28
  },
29
29
  "dependencies": {
30
- "cross-spawn-cb": "^0.3.1",
31
- "object-assign": "^4.1.1",
30
+ "cross-spawn-cb": "^0.5.9",
31
+ "just-extend": "^6.0.1",
32
32
  "path-string-prepend": "^0.2.0"
33
33
  },
34
34
  "devDependencies": {
35
- "babel-eslint": "^10.1.0",
35
+ "@typescript-eslint/parser": "^5.30.0",
36
36
  "cr": "^0.1.0",
37
- "depcheck": "^1.0.0",
38
- "dis-dat": "^0.1.3",
39
- "eslint": "^6.8.0",
40
- "eslint-config-prettier": "^6.11.0",
41
- "eslint-config-standard": "^14.1.1",
42
- "eslint-plugin-import": "^2.22.0",
37
+ "depcheck": "^1.4.3",
38
+ "dis-dat": "^0.1.6",
39
+ "eslint": "^8.18.0",
40
+ "eslint-config-prettier": "^8.5.0",
41
+ "eslint-config-standard": "^17.0.0",
42
+ "eslint-plugin-import": "^2.26.0",
43
43
  "eslint-plugin-node": "^11.1.0",
44
- "eslint-plugin-promise": "^4.2.1",
45
- "eslint-plugin-standard": "^4.0.1",
44
+ "eslint-plugin-promise": "^6.0.0",
46
45
  "is-version": "^0.2.0",
47
46
  "lodash.find": "^4.6.0",
48
47
  "match-semver": "^0.1.0",
49
48
  "mocha-compat": "^3.5.5",
50
- "node-install-release": "^0.1.31",
51
- "prettier": "^2.3.2",
52
- "rimraf": "^2.7.1",
49
+ "node-install-release": "^0.2.5",
50
+ "prettier": "^2.7.1",
53
51
  "semver": "^5.7.1"
54
52
  },
55
53
  "engines": {
56
- "node": ">=0.12"
54
+ "node": ">=0.8"
57
55
  }
58
56
  }
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
- };