mirror of
https://github.com/bower/bower.git
synced 2026-02-11 14:34:58 -05:00
Minor tweaks to the resolver factory.
This commit is contained in:
@@ -9,28 +9,27 @@ var createError = require('../util/createError');
|
||||
function getConstructor(source, config, registryClient) {
|
||||
var resolvedPath;
|
||||
var remote;
|
||||
var resolvedSource = source;
|
||||
|
||||
// Git case: git git+ssh, git+http, git+https
|
||||
// .git at the end (probably ssh shorthand)
|
||||
if (/^git(\+(ssh|https?))?:\/\//i.test(source) || /\.git\/?$/i.test(source)) {
|
||||
resolvedSource = source.replace(/^git\+/, '');
|
||||
source = source.replace(/^git\+/, '');
|
||||
return Q.fcall(function () {
|
||||
remote = url.parse(source);
|
||||
|
||||
// If it's a GitHub repository, return the specialized resolver
|
||||
if (remote.hostname.toLowerCase() === 'github.com') {
|
||||
return [resolvers.GitHub, resolvedSource];
|
||||
return [resolvers.GitHub, source];
|
||||
}
|
||||
|
||||
return [resolvers.GitRemote, resolvedSource];
|
||||
return [resolvers.GitRemote, source];
|
||||
});
|
||||
}
|
||||
|
||||
// URL case
|
||||
if (/^https?:\/\//i.exec(source)) {
|
||||
return Q.fcall(function () {
|
||||
return [resolvers.Url, resolvedSource];
|
||||
return [resolvers.Url, source];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,9 +44,9 @@ function getConstructor(source, config, registryClient) {
|
||||
return Q.nfcall(fs.stat, path.join(resolvedPath, '.git'))
|
||||
.then(function (stats) {
|
||||
if (stats.isDirectory()) {
|
||||
resolvedSource = resolvedPath;
|
||||
source = resolvedPath;
|
||||
return function () {
|
||||
return Q.resolve([resolvers.GitFs, resolvedSource]);
|
||||
return Q.resolve([resolvers.GitFs, source]);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -57,9 +56,9 @@ function getConstructor(source, config, registryClient) {
|
||||
.fail(function () {
|
||||
return Q.nfcall(fs.stat, resolvedPath)
|
||||
.then(function () {
|
||||
resolvedSource = resolvedPath;
|
||||
source = resolvedPath;
|
||||
return function () {
|
||||
return Q.resolve([resolvers.Fs, resolvedSource]);
|
||||
return Q.resolve([resolvers.Fs, source]);
|
||||
};
|
||||
});
|
||||
})
|
||||
@@ -68,14 +67,14 @@ function getConstructor(source, config, registryClient) {
|
||||
var parts = source.split('/');
|
||||
|
||||
if (parts.length === 2) {
|
||||
resolvedSource = mout.string.interpolate(config.shorthandResolver, {
|
||||
source = mout.string.interpolate(config.shorthandResolver, {
|
||||
shorthand: source,
|
||||
owner: parts[0],
|
||||
package: parts[1]
|
||||
});
|
||||
|
||||
return function () {
|
||||
return Q.resolve([resolvers.GitRemote, resolvedSource]);
|
||||
return Q.resolve([resolvers.GitRemote, source]);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -96,9 +95,9 @@ function getConstructor(source, config, registryClient) {
|
||||
|
||||
// TODO: Handle entry.type.. for now it's only 'alias'
|
||||
// When we got published packages, this needs to be adjusted
|
||||
resolvedSource = entry.url;
|
||||
source = entry.url;
|
||||
|
||||
return getConstructor(resolvedSource, config, registryClient)
|
||||
return getConstructor(source, config, registryClient)
|
||||
.spread(function (ConcreteResolver, source) {
|
||||
return [ConcreteResolver, source, true];
|
||||
});
|
||||
@@ -117,16 +116,21 @@ function getConstructor(source, config, registryClient) {
|
||||
function createInstance(decEndpoint, config, logger, registryClient) {
|
||||
return getConstructor(decEndpoint.source, config, registryClient)
|
||||
.spread(function (ConcreteResolver, source, fromRegistry) {
|
||||
var resolverDecEndpoint = mout.object.pick(decEndpoint, ['name', 'target']);
|
||||
var decEndpointCopy = mout.object.pick(decEndpoint, ['name', 'target']);
|
||||
|
||||
resolverDecEndpoint.source = source;
|
||||
decEndpointCopy.source = source;
|
||||
|
||||
// Signal if it was fetched from the registry
|
||||
if (fromRegistry) {
|
||||
decEndpoint.registry = true;
|
||||
// If no name was specified, assume the name from the registry
|
||||
if (!decEndpointCopy.name) {
|
||||
decEndpointCopy.name = decEndpoint.source;
|
||||
decEndpoint.name = decEndpoint.source;
|
||||
}
|
||||
}
|
||||
|
||||
return new ConcreteResolver(resolverDecEndpoint, config, logger);
|
||||
return new ConcreteResolver(decEndpointCopy, config, logger);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user