Skip to content

Commit

Permalink
Add spawn sync
Browse files Browse the repository at this point in the history
  • Loading branch information
kmalakoff committed Nov 3, 2021
1 parent b79a470 commit c8568e0
Show file tree
Hide file tree
Showing 12 changed files with 2,909 additions and 293 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: npm
directory: '/'
schedule:
interval: daily
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
# Check for updates to GitHub Actions every weekday
interval: 'daily'
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['latest']
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2.4.1
with:
node-version: ${{ matrix.node-version }}
- run: git config --global user.name "Github Actions"
- run: git config --global user.email "actions@users.noreply.github.com"
- run: npm ci
- run: npm run lint
- run: npm run test:engines
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
spawn: require('./lib/spawn'),
spawnSync: require('./lib/spawnSync'),
};
5 changes: 2 additions & 3 deletions lib/constants.js → lib/env-path-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function windowsPathKey() {
return pathKey;
}

module.exports = {
PATH_KEY: isWindows ? windowsPathKey() : 'PATH',
NODE: isWindows ? 'node.exe' : 'node',
module.exports = function () {
return isWindows ? windowsPathKey() : 'PATH';
};
26 changes: 0 additions & 26 deletions lib/envForInstallPath.js

This file was deleted.

10 changes: 2 additions & 8 deletions lib/spawn.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
var assign = require('object-assign');
var crossSpawn = require('cross-spawn-cb');
var prepend = require('path-string-prepend');

var envForInstallPath = require('./envForInstallPath');
var PATH_KEY = require('./constants').PATH_KEY;
var spawnOptions = require('./spawnOptions');

function spawn(installPath, command, args, options, callback) {
// put the path to node and npm at the front and remove nvs
var env = envForInstallPath(process.env, installPath);
env[PATH_KEY] = prepend(env[PATH_KEY] || '', env.npm_config_binroot);
crossSpawn(command, args, assign({}, options, { cwd: process.cwd(), env: env, execPath: env.npm_node_execpath, path: env[PATH_KEY] }), callback);
crossSpawn(command, args, spawnOptions(installPath, options), callback);
}

module.exports = function spawnWrapper(installPath, command, args, options, callback) {
Expand Down
32 changes: 32 additions & 0 deletions lib/spawnOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var path = require('path');
var assign = require('object-assign');
var prepend = require('path-string-prepend');
var NODE = process.platform === 'win32' ? 'node.exe' : 'node';
var PATH_KEY = require('./env-path-key')();

var isWindows = process.platform === 'win32';

module.exports = function envForInstallPath(installPath, options) {
var processEnv = process.env;
var env = {};
env.npm_config_binroot = isWindows ? installPath : path.join(installPath, 'bin');
env.npm_config_root = isWindows ? installPath : path.join(installPath, 'lib');
env.npm_config_man = isWindows ? installPath : path.join(installPath, 'man');
env.npm_config_prefix = installPath;
env.npm_node_execpath = path.join(env.npm_config_binroot, NODE);

// copy the environment not for npm and skip case-insesitive additional paths
for (var key in processEnv) {
var lowerKey = key.toLowerCase();
if (lowerKey.indexOf('npm_') === 0) continue;
if (lowerKey === 'path' && key !== PATH_KEY) continue;
env[key] = processEnv[key];
}

// override node
if (env.NODE !== undefined) env.NODE = env.npm_node_execpath;

// put the path to node and npm at the front and remove nvs
env[PATH_KEY] = prepend(env[PATH_KEY] || '', env.npm_config_binroot);
return assign({}, options, { cwd: process.cwd(), env: env, execPath: env.npm_node_execpath, path: env[PATH_KEY] });
};
6 changes: 6 additions & 0 deletions lib/spawnSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var crossSpawn = require('cross-spawn-cb');
var spawnOptions = require('./spawnOptions');

module.exports = function spawnSync(installPath, command, args, options) {
return crossSpawn.sync(command, args, spawnOptions(installPath, options));
};
Loading

0 comments on commit c8568e0

Please sign in to comment.