Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

format code in install. install devAlias

  • Loading branch information...
commit af5c70cc6c8704d2790ff7c0791d703f4afcd78a 1 parent f83b920
Hsiaoming Yang authored
Showing with 29 additions and 18 deletions.
  1. +29 −18 lib/install.js
47 lib/install.js
View
@@ -21,18 +21,18 @@ var mo = require('./sdk/module');
var git = require('./sdk/git');
var _cache = {};
-var _options = {
- dest: 'sea-modules',
+var store = {
+ dest: spmrc.get('install.path') || 'sea-modules',
cache: path.join(process.env.HOME, '.spm', 'cache'),
srcCache: path.join(process.env.HOME, '.spm', 'src'),
parallel: 1
};
module.exports = function(options) {
- _options.parallel = options.parallel || _options.parallel;
- _options.dest = options.dest || _options.dest;
- _options.source = options.source;
- _options.force = options.force;
+ store.parallel = options.parallel || store.parallel;
+ store.dest = options.dest || store.dest;
+ store.source = options.source;
+ store.force = options.force;
var packages;
if (options.query && options.query.charAt(0) !== '.') {
@@ -62,7 +62,7 @@ function queueInstall(tasks, callback) {
task = iduri.resolve(task);
}
spmInstall(task, callback);
- }, _options.parallel);
+ }, store.parallel);
tasks.forEach(function(task) {
q.push(task, function(err) {
@@ -78,7 +78,7 @@ function spmInstall(data, callback) {
if (data.version) {
pkg = pkg + '@' + data.version;
}
- if (grunt.util._.contains(Object.keys(_cache), pkg)) {
+ if (_.contains(Object.keys(_cache), pkg)) {
log.debug('ignore', pkg);
callback(null);
return;
@@ -102,7 +102,7 @@ function spmInstall(data, callback) {
if (packages.length) {
log.info('depends', packages.join(', '));
}
- _cache[pkg] = grunt.util._.union(_cache[pkg], packages);
+ _cache[pkg] = _.union(_cache[pkg], packages);
if (packages.length) {
queueInstall(packages, callback);
@@ -113,10 +113,10 @@ function spmInstall(data, callback) {
}
function fetch(query, callback) {
- var force = _options.force;
+ var force = store.force;
log.info('fetch', query);
var data = iduri.resolve(query);
- yuan(_options).info(data, function(err, res, body) {
+ yuan(store).info(data, function(err, res, body) {
if (err) {
fetchCache(data, function(err, result) {
if (err) {
@@ -131,7 +131,7 @@ function fetch(query, callback) {
var filepath = path.join(
body.family, body.name, body.version, body.filename
);
- var dest = path.join(_options.cache, filepath);
+ var dest = path.join(store.cache, filepath);
if (!force && grunt.file.exists(dest) && md5file(dest) === body.md5) {
extract(dest, callback);
} else {
@@ -149,7 +149,7 @@ function fetchTarball(urlpath, dest, callback) {
log.info('download', urlpath);
var data = {urlpath: urlpath, method: 'GET', encoding: null};
- yuan(_options).request(data, function(err, res, body) {
+ yuan(store).request(data, function(err, res, body) {
fs.writeFile(dest, body, function(err) {
if (err) {
callback(err);
@@ -162,7 +162,7 @@ function fetchTarball(urlpath, dest, callback) {
}
function fetchCache(data, callback) {
- var fpath = path.join(_options.cache, data.family, data.name);
+ var fpath = path.join(store.cache, data.family, data.name);
if (!fs.existsSync(fpath)) {
callback('not in cache');
return;
@@ -183,7 +183,7 @@ function fetchCache(data, callback) {
}
function fetchGit(pkg, callback) {
- var dest = path.join(_options.srcCache, pkg.family, pkg.name);
+ var dest = path.join(store.srcCache, pkg.family, pkg.name);
var revision = pkg.revision || pkg.version || 'HEAD';
log.debug('revision', revision);
if (fs.existsSync(dest)) {
@@ -237,9 +237,9 @@ function copy(src, callback) {
var format = spmrc.get('install.format');
var regex = /^\{\{\s*family\s*\}\}\/\{\{\s*name\s*\}\}\/\{\{\s*version\s*\}\}\/\{\{\s*filename\s*\}\}$/;
if (format && /\{\{\s*filename\s*\}\}$/.test(format) && !regex.test(format)) {
- dest = path.join(_options.dest, iduri.idFromPackage(pkg, '', format));
+ dest = path.join(store.dest, iduri.idFromPackage(pkg, '', format));
} else {
- dest = path.join(_options.dest, pkg.family, pkg.name, pkg.version);
+ dest = path.join(store.dest, pkg.family, pkg.name, pkg.version);
format = null;
}
var debugfile = spmrc.get('install.debugfile') || 'true';
@@ -299,7 +299,18 @@ function parseDependencies(pkg) {
if (typeof pkg === 'string') {
pkg = grunt.file.readJSON(pkg);
}
- var alias = (pkg.spm && pkg.spm.alias) || {};
+ var alias = {};
+ if (pkg.spm) {
+ if (pkg.spm.alias) {
+ alias = pkg.spm.alias;
+ }
+ if (pkg.spm.devAlias) {
+ alias = _.extend(alias, pkg.spm.devAlias);
+ }
+ if (pkg.spm.engines) {
+ alias = _.defaults(alias, pkg.spm.engines);
+ }
+ }
var deps = Object.keys(alias).map(function(key) {
return alias[key];
});
Please sign in to comment.
Something went wrong with that request. Please try again.