Remove lodash dependency

This commit is contained in:
Samy Pesse
2016-04-30 23:07:43 +02:00
parent c1d53ec11f
commit c681cd286a
6 changed files with 56 additions and 43 deletions
+10 -6
View File
@@ -1,4 +1,4 @@
var _ = require('lodash');
var is = require('is');
var path = require('path');
var crc = require('crc');
var URI = require('urijs');
@@ -69,7 +69,7 @@ Git.prototype.resolve = function(giturl) {
if (this.resolveRoot(giturl)) return Promise(giturl);
return Promise(null);
}
if (_.isString(giturl)) giturl = Git.parseUrl(giturl);
if (is.string(giturl)) giturl = Git.parseUrl(giturl);
if (!giturl) return Promise(null);
// Clone or get from cache
@@ -88,8 +88,10 @@ Git.prototype.resolveRoot = function(filepath) {
// Extract first directory (is the repo id)
relativeToGit = path.relative(this.tmpDir, filepath);
repoId = _.first(relativeToGit.split(path.sep));
if (!repoId) return;
repoId = relativeToGit.split(path.sep)[0];
if (!repoId) {
return;
}
// Return an absolute file
return path.resolve(this.tmpDir, repoId);
@@ -114,10 +116,12 @@ Git.parseUrl = function(giturl) {
// Extract file inside the repo (after the .git)
fileParts = uri.path().split('.git');
filepath = fileParts.length > 1? fileParts.slice(1).join('.git') : '';
if (filepath[0] == '/') filepath = filepath.slice(1);
if (filepath[0] == '/') {
filepath = filepath.slice(1);
}
// Recreate pathname without the real filename
uri.path(_.first(fileParts)+'.git');
uri.path(fileParts[0] + '.git');
return {
host: uri.toString(),