Skip to content

Commit d63deca

Browse files
committed
[fix] Remove shelljs's exec - it breaks on windows
1 parent cf5bddd commit d63deca

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

index.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
var spawn = require('cross-spawn')
4-
, shelly = require('shelljs')
54
, which = require('which')
65
, path = require('path')
76
, util = require('util')
@@ -57,6 +56,20 @@ Object.defineProperty(Hook.prototype, 'colors', {
5756
}
5857
});
5958

59+
/**
60+
* Execute a binary.
61+
*
62+
* @param {String} bin Binary that needs to be executed
63+
* @param {Array} args Arguments for the binary
64+
* @returns {Object}
65+
* @api private
66+
*/
67+
Hook.prototype.exec = function exec(bin, args) {
68+
return spawn.sync(bin, args, {
69+
stdio: 'pipe'
70+
});
71+
};
72+
6073
/**
6174
* Parse the package.json so we can create an normalize it's contents to
6275
* a usable configuration structure.
@@ -157,19 +170,14 @@ Hook.prototype.initialize = function initialize() {
157170
//
158171
if (!this.git) return this.log(this.format(Hook.log.binary, 'git'), 0);
159172

160-
this.root = this.shelly.exec(this.git +' rev-parse --show-toplevel', {
161-
silent: true
162-
});
163-
164-
this.status = this.shelly.exec(this.git +' status --porcelain', {
165-
silent: true
166-
});
173+
this.root = this.exec(this.git, ['rev-parse', '--show-toplevel']);
174+
this.status = this.exec(this.git, ['status', '--porcelain']);
167175

168176
if (this.status.code) return this.log(Hook.log.status, 0);
169177
if (this.root.code) return this.log(Hook.log.root, 0);
170178

171-
this.status = this.status.output.trim();
172-
this.root = this.root.output.trim();
179+
this.status = this.status.stdout.toString().trim();
180+
this.root = this.root.stdout.toString().trim();
173181

174182
try {
175183
this.json = require(path.join(this.root, 'package.json'));
@@ -190,9 +198,7 @@ Hook.prototype.initialize = function initialize() {
190198
// execute.
191199
//
192200
if (this.config.template) {
193-
this.shelly.exec(this.git +' config commit.template "'+ this.config.template +'"', {
194-
silent: true
195-
});
201+
this.exec(this.git, ['config', 'commit.template', '"'+ this.config.template +'"']);
196202
}
197203

198204
if (!this.config.run) return this.log(Hook.log.run, 0);
@@ -213,7 +219,7 @@ Hook.prototype.run = function runner() {
213219

214220
//
215221
// There's a reason on why we're using an async `spawn` here instead of the
216-
// `shelly.exec`. The sync `exec` is a hack that writes writes a file to
222+
// `shelljs.exec`. The sync `exec` is a hack that writes writes a file to
217223
// disk and they poll with sync fs calls to see for results. The problem is
218224
// that the way they capture the output which us using input redirection and
219225
// this doesn't have the required `isAtty` information that libraries use to
@@ -239,7 +245,6 @@ Hook.prototype.run = function runner() {
239245
* @public
240246
*/
241247
Hook.prototype.format = util.format;
242-
Hook.prototype.shelly = shelly;
243248

244249
/**
245250
* The various of error and status messages that we can output.

install.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
var fs = require('fs')
77
, path = require('path')
8-
, shelly = require('shelljs')
8+
, spawn = require('cross-spawn')
99
, hook = path.join(__dirname, './hook')
1010
, root = path.resolve(__dirname, '../..')
1111
, exists = fs.existsSync || path.existsSync;
@@ -23,7 +23,7 @@ var git = path.resolve(root, '.git')
2323
//
2424
// Make sure that we can execute the hook without any issues before continuing.
2525
//
26-
if (shelly.exec(hook +' --dry-run', { silent: true }).code !== 0) {
26+
if (spawn.sync('sh', [hook, '--dry-run'], { stdio: 'ignore' }).code !== 0) {
2727
console.error('pre-commit:');
2828
console.error('pre-commit: The --dry-run of the pre-commit hook failed to execute.');
2929
console.error('pre-commit:');

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"license": "MIT",
3232
"dependencies": {
3333
"cross-spawn": "2.0.x",
34-
"shelljs": "0.5.x",
3534
"which": "1.1.x"
3635
},
3736
"devDependencies": {

0 commit comments

Comments
 (0)