Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
opts.on('dependencies', function() { includeDependencies = true; });
opts.on('no-dependencies', function() { includeDependencies = false; });
opts.on('version', function(key, v) {
vers = SEMVER.normalize(v);
});
var packageIds = opts.parse(args); // get list of packageIds
var repo = preferredSource();
if (!repo) {
return Cmds.fail("Cannot find repository to install in", done);
}
Cmds.verbose("Removing from source ", repo.path);
// get installed version information for each package
CORE.iter.chain(function(done) {
var ret = {}, canonicalId, pkg;
if (vers) {
canonicalId = repo.canonicalPackageId(packageIds[0], vers);
pkg = canonicalId ? repo.packageFor(canonicalId) : null;
if (!pkg) return done(null, {}); // no matching versions
ret[packageIds[0]] = [pkg];
} else {
repo.catalogPackages().forEach(function(pkg) {
var packageName = pkg.get('name');
if (!ret[packageName]) ret[packageName] = [];
ret[packageName].push(pkg);
});
}
CORE.prompt(function(err, response) {
CORE.prompt.done();
response = Number(response);
if (isNaN(response)) return CORE.println('Invalid Response');
if (response > last) return done(); // skip
// remove only one if single version selected
if (response < last) versions = [versions[response-1]];
CORE.iter.each(versions, function(pkg, done) {
repo.remove(pkg, done);
})(done);
});
exports.invoke = function(cmd, args, opts, done) {
var paths, remote, username;
opts.on('remote', function(k,v) { remote = v; });
opts.on('username', function(k,v) { username = v; });
paths = opts.parse(args);
if (paths.length === 0) paths = [process.cwd()];
if (remote) remote = REMOTE.normalize(remote);
// select a remote to push to
CORE.iter.chain(function(done) {
if (remote) {
REMOTE.open(remote, done);
} else {
REMOTE.remotes(function(err, remotes) {
var idx=0, lim = remotes.length;
for(idx=0;!remote && idx
var cleanup = function(path, fd) {
CORE.fs.close(fd, function(err) {
CORE.fs.rm(path, CORE.noop);
});
};
if ('function' === typeof headers) {
done = headers;
headers = undefined;
}
var remote = this;
// first make sure we have a directory to write to and then open a
// file for writing
CORE.iter.chain(function(done) {
CORE.fs.mkdir_p(CORE.path.dirname(path), 511, function(err) {
if (err) return done(err);
CORE.fs.open(path, 'w+' , 511, done);
});
// next, open a connection to the server and download...
}, function(fd, done) {
// use a queue to control writing to disk. This allows us to stream
// receiving a file.
var level = 1;
function endWrite() {
if (--level <= 0) {
CORE.verbose('download complete');
return done();
signup: function(done) {
// need to collect some information...
var username;
var password;
var email;
var name;
var remote = this;
// get username
CORE.iter.chain(function(done) {
CORE.println("Create new account for " + remote.url);
CORE.println("Username:");
CORE.prompt(function(err, value) {
if (err) return done(err);
username = value.slice(0,-1);
if (username.length===0) return done("username cannot be empty");
return done();
});
// read name
}, function(done) {
CORE.println("Real name:");
CORE.prompt(function(err, value) {
if (err) return done(err);
name = value.slice(0,-1);
if (name.length===0) return done("Name cannot be empty");
install: function(packageId, version, exact, force, done) {
var context = this;
if ('function' === typeof force) {
done = force;
force = false;
}
// packageId may be either a path or a simple packageId. If it is a
// path then add the descriptor to the DB immediately
CORE.iter.chain(function(done) {
// looks like a path if it begins with ., .., or has a /
if ((packageId[0]==='.') || (packageId.indexOf('/')>=0)) {
context.loadDescriptor(packageId, done);
// it's not a path - so try to find the descriptor in the cache or
// load it from a remote
} else {
context.findDescriptor(packageId, version, exact, done);
}
},
// now we have a package descriptor. Get an install job for this desc
// and use it
function(desc, done) {
if (!desc) return done(packageId + ' not found');
})(function(err, workingPackage) {
if (err) return done(err);
CORE.verbose("Working package at "+workingPackage.path);
CORE.iter.each(packageIds,
unfreezePackage(workingPackage, force)
)(CORE.err(done));
});
};
})(function(err, workingPackage) {
if (err) return done(err);
CORE.verbose("Working package at "+workingPackage.path);
CORE.iter.each(packageIds,
freezePackage(workingPackage, version, force, dirname)
)(CORE.err(done));
});
};
}, function(remote, done) {
if (!remote) return done('No remote found');
CORE.iter.parallel(paths, function(path, done) {
path = CORE.path.normalize(path);
var pkg = require.packageFor(path);
if (!pkg) return done(path + " is not a valid package");
CORE.println("Pushing "+pkg.get('name')+' '+pkg.get('version')+"...");
CORE.verbose(" Pushing to remote " + remote.url);
remote.push(pkg, username, CORE.err(done));
})(done);
})(done);
};
})(function(err, workingPackage) {
if (err) return done(err);
CORE.verbose("Working package at "+workingPackage.path);
CORE.iter.each(packageIds,
forkPackage(workingPackage, version, force, dirname)
)(CORE.err(done));
});
};