Skip to content

Commit 9f29098

Browse files
committed
Move isGitUrl() method to utils/location.js
1 parent 0b666e5 commit 9f29098

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

lib/constants/gitPrefix.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
/*
3+
Prefix used for git URLs
4+
*/
5+
module.exports = 'git+';

lib/utils/git.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ var pathUtil = require('./path');
77
var Promise = require('./promise');
88
var command = require('./command');
99
var fs = require('./fs');
10+
var LocationUtils = require('./location');
1011

11-
var GIT_PREFIX = 'git+';
12+
var GIT_PREFIX = require('../constants/gitPrefix');
1213

1314
function Git() {
1415
this.tmpDir;
@@ -65,7 +66,7 @@ Git.prototype.clone = function(host, ref) {
6566
// Get file from a git repo
6667
Git.prototype.resolve = function(giturl) {
6768
// Path to a file in a git repo?
68-
if (!Git.isUrl(giturl)) {
69+
if (!LocationUtils.isGitUrl(giturl)) {
6970
if (this.resolveRoot(giturl)) return Promise(giturl);
7071
return Promise(null);
7172
}
@@ -97,16 +98,11 @@ Git.prototype.resolveRoot = function(filepath) {
9798
return path.resolve(this.tmpDir, repoId);
9899
};
99100

100-
// Check if an url is a git dependency url
101-
Git.isUrl = function(giturl) {
102-
return (giturl.indexOf(GIT_PREFIX) === 0);
103-
};
104-
105101
// Parse and extract infos
106102
Git.parseUrl = function(giturl) {
107103
var ref, uri, fileParts, filepath;
108104

109-
if (!Git.isUrl(giturl)) return null;
105+
if (!LocationUtils.isGitUrl(giturl)) return null;
110106
giturl = giturl.slice(GIT_PREFIX.length);
111107

112108
uri = new URI(giturl);

lib/utils/location.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var url = require('url');
22
var path = require('path');
33

4+
var GIT_PREFIX = require('../constants/gitPrefix');
5+
46
// Is the url an external url
57
function isExternal(href) {
68
try {
@@ -19,6 +21,11 @@ function isDataURI(href) {
1921
}
2022
}
2123

24+
// Is a git content reference URL
25+
function isGitUrl(giturl) {
26+
return (giturl.indexOf(GIT_PREFIX) === 0);
27+
}
28+
2229
// Inverse of isExternal
2330
function isRelative(href) {
2431
return !isExternal(href);
@@ -108,6 +115,7 @@ function areIdenticalPaths(p1, p2) {
108115
module.exports = {
109116
areIdenticalPaths: areIdenticalPaths,
110117
isDataURI: isDataURI,
118+
isGitUrl: isGitUrl,
111119
isExternal: isExternal,
112120
isRelative: isRelative,
113121
isAnchor: isAnchor,

0 commit comments

Comments
 (0)