Replace shelljs with fs-extra and which
diff --git a/index.js b/index.js
index 5825084..d968711 100644
--- a/index.js
+++ b/index.js
@@ -16,11 +16,11 @@
*/
var Q = require('q');
-var shell = require('shelljs');
+var which = Q.denodeify(require('which'));
var superspawn = require('cordova-common').superspawn;
var events = require('cordova-common').events;
var path = require('path');
-var fs = require('fs');
+var fs = require('fs-extra');
var CordovaError = require('cordova-common').CordovaError;
/*
@@ -49,9 +49,7 @@
nodeModulesDir = path.resolve(path.join(dest, 'node_modules'));
}
// create node_modules if it doesn't exist
- if (!fs.existsSync(nodeModulesDir)) {
- shell.mkdir('-p', nodeModulesDir);
- }
+ fs.ensureDirSync(nodeModulesDir);
} else throw new CordovaError('Need to supply a target and destination');
// set the directory where npm install will be run
@@ -110,11 +108,8 @@
*/
function isNpmInstalled () {
- return Q.Promise(function (resolve) {
- if (!shell.which('npm')) {
- throw new CordovaError('"npm" command line tool is not installed: make sure it is accessible on your PATH.');
- }
- resolve();
+ return which('npm').catch(_ => {
+ throw new CordovaError('"npm" command line tool is not installed: make sure it is accessible on your PATH.');
});
}
diff --git a/package.json b/package.json
index c828575..c82c60f 100644
--- a/package.json
+++ b/package.json
@@ -22,8 +22,9 @@
},
"dependencies": {
"cordova-common": "^2.2.0",
+ "fs-extra": "^6.0.1",
"q": "^1.4.1",
- "shelljs": "^0.7.0"
+ "which": "^1.3.1"
},
"devDependencies": {
"eslint": "^3.19.0",
diff --git a/spec/fetch-unit.spec.js b/spec/fetch-unit.spec.js
index 18449ed..6a30511 100644
--- a/spec/fetch-unit.spec.js
+++ b/spec/fetch-unit.spec.js
@@ -17,17 +17,14 @@
/* eslint-env jasmine */
var fetch = require('../index.js');
-var shell = require('shelljs');
-var fs = require('fs');
+var fs = require('fs-extra');
var superspawn = require('cordova-common').superspawn;
describe('unit tests for index.js', function () {
beforeEach(function () {
spyOn(superspawn, 'spawn').and.returnValue('+ foo@1.2.3');
- spyOn(shell, 'mkdir').and.returnValue(true);
- spyOn(shell, 'which').and.returnValue(Promise.resolve());
spyOn(fetch, 'isNpmInstalled').and.returnValue(Promise.resolve());
- spyOn(fs, 'existsSync').and.returnValue(false);
+ spyOn(fs, 'ensureDirSync').and.returnValue(false);
});
it('should handle missing options', function () {
diff --git a/spec/fetch.spec.js b/spec/fetch.spec.js
index 11d0d3c..80bcbf3 100644
--- a/spec/fetch.spec.js
+++ b/spec/fetch.spec.js
@@ -18,9 +18,8 @@
/* eslint-env jasmine */
var fetch = require('../index.js');
var uninstall = require('../index.js').uninstall;
-var shell = require('shelljs');
var path = require('path');
-var fs = require('fs');
+var fs = require('fs-extra');
var helpers = require('./helpers.js');
var tmpDir;
@@ -32,7 +31,7 @@
afterEach(function () {
process.chdir(__dirname); // Needed to rm the dir on Windows.
- shell.rm('-rf', tmpDir);
+ fs.removeSync(tmpDir);
});
describe('platform fetch/uninstall tests via npm & git', function () {
@@ -85,7 +84,7 @@
beforeEach(function () {
// copy package.json from spec directory to tmpDir
- shell.cp(path.join(__dirname, 'testpkg.json'), 'package.json');
+ fs.copySync(path.join(__dirname, 'testpkg.json'), 'package.json');
});
it('should fetch and uninstall a cordova platform via npm & git tags/branches', function () {
@@ -149,7 +148,7 @@
beforeEach(function () {
// copy package.json from spec directory to tmpDir
- shell.cp(path.join(__dirname, 'testpkg.json'), 'package.json');
+ fs.copySync(path.join(__dirname, 'testpkg.json'), 'package.json');
});
it('should fetch and uninstall a cordova plugin via git commit sha', function () {
@@ -179,7 +178,7 @@
var opts = {};
beforeEach(function () {
- shell.cp('-r', path.join(__dirname, 'support'), 'support');
+ fs.copySync(path.join(__dirname, 'support'), 'support');
});
it('should fetch the same cordova plugin twice in a row', function () {
diff --git a/spec/helpers.js b/spec/helpers.js
index 25c98a4..f6e7248 100644
--- a/spec/helpers.js
+++ b/spec/helpers.js
@@ -18,7 +18,7 @@
*/
var path = require('path');
-var fs = require('fs');
+var fs = require('fs-extra');
var os = require('os');
const tmpDirTemplate = path.join(os.tmpdir(), 'cordova-fetch-tests-');