Several things changed.

- Make force and offline part of config, clearing all the options mess in the architecture
- Fix some bugs with the renderer
- Parse cli options
This commit is contained in:
André Cruz
2013-05-26 13:47:13 +01:00
parent c8d4d39068
commit 005b3356f2
10 changed files with 55 additions and 51 deletions

View File

@@ -10,11 +10,9 @@ var copy = require('../util/copy');
var createError = require('../util/createError');
var endpointParser = require('../util/endpointParser');
function Manager(options) {
options = options || {};
this._config = options.config || defaultConfig;
this._repository = new PackageRepository(options);
function Manager(config) {
this._config = config || defaultConfig;
this._repository = new PackageRepository(config);
}
// -----------------

View File

@@ -6,19 +6,17 @@ var resolverFactory = require('./resolverFactory');
var defaultConfig = require('../config');
var createError = require('../util/createError');
function PackageRepository(options) {
options = options || {};
options.config = options.config || defaultConfig;
function PackageRepository(config) {
var registryOptions;
this._options = options;
this._config = options.config;
this._config = config || defaultConfig;
// Instantiate the registry and store it in the options object
// because it will be passed to the resolver factory
this._options.registryClient = new RegistryClient(mout.object.fillIn({
cache: this._config.roaming.registry
}, this._config));
// Instantiate the registry
registryOptions = mout.object.deepMixIn({}, this._config);
registryOptions.cache = this._config.roaming.registry;
this._registryClient = new RegistryClient(registryOptions);
// Instantiate the resolve cache
this._resolveCache = new ResolveCache(this._config.roaming.cache);
}
@@ -30,7 +28,7 @@ PackageRepository.prototype.fetch = function (decEndpoint) {
var that = this;
// Get the appropriate resolver
resolverFactory(decEndpoint, this._options)
resolverFactory(decEndpoint, this._registryClient, this._config)
// Decide if we retrieve from the cache or not
// Also decide we if validate the cached entry or not
.then(function (resolver) {
@@ -40,7 +38,7 @@ PackageRepository.prototype.fetch = function (decEndpoint) {
decEndpoint.resolverName = resolver.getName();
// If force flag is used, bypass cache
if (that._options.force) {
if (that._config.force) {
deferred.notify({
level: 'action',
tag: 'resolve',
@@ -57,7 +55,7 @@ PackageRepository.prototype.fetch = function (decEndpoint) {
// If there's no package in the cache
if (!canonicalPkg) {
// And the offline flag is passed, error out
if (that._options.offline) {
if (that._config.offline) {
throw createError('No cached version for ' + resolver.getSource() + '#' + resolver.getTarget(), 'ENOCACHE', {
resolver: resolver
});
@@ -86,7 +84,7 @@ PackageRepository.prototype.fetch = function (decEndpoint) {
});
// If offline flag is used, use directly the cached one
if (that._options.offline) {
if (that._config.offline) {
return [canonicalPkg, pkgMeta];
}

View File

@@ -9,17 +9,14 @@ var defaultConfig = require('../config');
var createError = require('../util/createError');
var endpointParser = require('../util/endpointParser');
function Project(options) {
options = options || {};
this._options = options;
this._config = options.config || defaultConfig;
this._manager = new Manager(options);
function Project(config) {
this._config = config || defaultConfig;
this._manager = new Manager(this._config);
}
// -----------------
Project.prototype.install = function (endpoints) {
Project.prototype.install = function (endpoints, options) {
var repairResult;
var that = this;
@@ -86,6 +83,8 @@ Project.prototype.install = function (endpoints) {
.fin(function () {
that._working = false;
});
// TODO: handle save saveDev production
};
Project.prototype.update = function (names) {
@@ -125,7 +124,7 @@ Project.prototype._analyse = function () {
// that is, the parent-child relationships
this._restoreNode(root, flattened);
// Do the same for the dev dependencies
if (!this._options.production) {
if (!this._config.production) {
this._restoreNode(root, flattened, 'devDependencies');
}

View File

@@ -6,19 +6,18 @@ var resolvers = require('./resolvers');
var defaultConfig = require('../config');
var createError = require('../util/createError');
function createResolver(decEndpoint, options) {
function createResolver(decEndpoint, registryClient, config) {
var resOptions;
var source = decEndpoint.source;
var resolvedPath;
options = options || {};
options.config = options.config || defaultConfig;
config = config || defaultConfig;
// Setup resolver options
resOptions = {
target: decEndpoint.target,
name: decEndpoint.name,
config: options.config
config: config
};
// Git case: git git+ssh, git+http, git+https
@@ -38,7 +37,7 @@ function createResolver(decEndpoint, options) {
}
// Check if source is a git repository
resolvedPath = path.resolve(options.config.cwd, source);
resolvedPath = path.resolve(config.cwd, source);
// Below we try a series of asyc tests to guess the type of resolver to use
// If a step was unable to guess the resolver, it throws an error
@@ -69,7 +68,7 @@ function createResolver(decEndpoint, options) {
var parts = source.split('/');
if (parts.length === 2) {
source = mout.string.interpolate(options.config.shorthandResolver, {
source = mout.string.interpolate(config.shorthandResolver, {
shorthand: source,
owner: parts[0],
package: parts[1]
@@ -84,14 +83,12 @@ function createResolver(decEndpoint, options) {
})
// As last resort, we try the registry
.fail(function (err) {
var registry = options.registryClient;
if (!registry) {
if (!registryClient) {
throw err;
}
return function () {
return Q.nfcall(registry.lookup.bind(registry), source, options)
return Q.nfcall(registryClient.lookup.bind(registryClient), source)
.then(function (entry) {
decEndpoint.registryName = source;
// TODO: Handle entry.type.. for now it's only 'alias'