Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm install and dep resolvement needs to happen in the same dir #285

Merged
merged 2 commits into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/cli/domain/get-components-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@ var path = require('path');
var _ = require('underscore');

module.exports = function(components){
var deps = [];

var deps = { modules: [], withVersions: [] };

_.forEach(components, function(c){

var pkg = fs.readJsonSync(path.join(c, 'package.json'));

_.forEach(_.keys(pkg.dependencies), function(d){
if(!_.contains(deps, d)){
deps.push(d + '@' + pkg.dependencies[d]);

var version = pkg.dependencies[d],
hasVersion = !_.isEmpty(version),
depToInstall = hasVersion ? (d + '@' + version) : d;

if(!_.contains(deps.withVersions, depToInstall)){
deps.withVersions.push(depToInstall);
}

if(!_.contains(deps.modules, d)){
deps.modules.push(d);
}
});
});
Expand Down
4 changes: 3 additions & 1 deletion src/cli/domain/get-missing-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ module.exports = function(dependencies, components){
var missing = [];

_.forEach(dependencies, function(npmModule){

var index = npmModule.indexOf('@'),
moduleName = npmModule;

if (index > 0) {
moduleName = npmModule.substr(0, index);
}
var pathToModule = path.resolve('node_modules/', moduleName);

try {
if(!!require.cache[pathToModule]){
delete require.cache[pathToModule];
Expand Down
4 changes: 2 additions & 2 deletions src/cli/domain/npm-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
var npm = require('npm');
var path = require('path');

module.exports = function(dependencies, baseDir, cb){
module.exports = function(dependencies, cb){
npm.load({}, function(npmEr){
if(!!npmEr){ return cb(npmEr); }
npm.commands.install(path.resolve(baseDir), dependencies, cb);
npm.commands.install(path.resolve('.'), dependencies, cb);
});
};
6 changes: 3 additions & 3 deletions src/cli/facade/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function(dependencies){
if(_.isEmpty(missing)){ return cb(); }

log.warn(format(strings.messages.cli.INSTALLING_DEPS, missing.join(', ')));
npmInstaller(missing, componentsDir, function(err, result){
npmInstaller(missing, function(err, result){
if(!!err){
log.err(err.toString());
throw err;
Expand Down Expand Up @@ -95,11 +95,11 @@ module.exports = function(dependencies){
log.warn(strings.messages.cli.CHECKING_DEPENDENCIES, true);

var dependencies = getComponentsDependencies(components),
missing = getMissingDeps(dependencies, components);
missing = getMissingDeps(dependencies.withVersions, components);

if(_.isEmpty(missing)){
log.ok('OK');
return cb(dependencies);
return cb(dependencies.modules);
}

log.err('FAIL');
Expand Down