From 3c322ef9ea0295c3d1b0e59ee289234bfae1fb6b Mon Sep 17 00:00:00 2001 From: Matteo Figus Date: Sun, 11 Sep 2016 16:35:46 +0100 Subject: [PATCH 1/2] npm install and dep resolvement needs to happen in the same dir --- src/cli/domain/get-components-deps.js | 11 +++++++++-- src/cli/domain/get-missing-deps.js | 5 ++++- src/cli/domain/npm-installer.js | 4 ++-- src/cli/facade/dev.js | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/cli/domain/get-components-deps.js b/src/cli/domain/get-components-deps.js index 736d9c389..04409c847 100644 --- a/src/cli/domain/get-components-deps.js +++ b/src/cli/domain/get-components-deps.js @@ -7,10 +7,17 @@ var _ = require('underscore'); module.exports = function(components){ var deps = []; _.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, depToInstall)){ + deps.push(depToInstall); } }); }); diff --git a/src/cli/domain/get-missing-deps.js b/src/cli/domain/get-missing-deps.js index a06f02639..b6dfb204f 100644 --- a/src/cli/domain/get-missing-deps.js +++ b/src/cli/domain/get-missing-deps.js @@ -8,13 +8,16 @@ 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); + var pathToModule = path.resolve('node_modules/', moduleName); + try { if(!!require.cache[pathToModule]){ delete require.cache[pathToModule]; diff --git a/src/cli/domain/npm-installer.js b/src/cli/domain/npm-installer.js index 2d72899c9..71d7d4e88 100644 --- a/src/cli/domain/npm-installer.js +++ b/src/cli/domain/npm-installer.js @@ -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); }); }; \ No newline at end of file diff --git a/src/cli/facade/dev.js b/src/cli/facade/dev.js index d18519711..1e85bd406 100644 --- a/src/cli/facade/dev.js +++ b/src/cli/facade/dev.js @@ -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; From 2db7d3bd0770680c9063b622f243ec10f4606ba7 Mon Sep 17 00:00:00 2001 From: Matteo Figus Date: Sun, 11 Sep 2016 17:33:34 +0100 Subject: [PATCH 2/2] Dependency resolvment bugfix --- src/cli/domain/get-components-deps.js | 12 +++++++++--- src/cli/domain/get-missing-deps.js | 5 ++--- src/cli/facade/dev.js | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/cli/domain/get-components-deps.js b/src/cli/domain/get-components-deps.js index 04409c847..bbe513a07 100644 --- a/src/cli/domain/get-components-deps.js +++ b/src/cli/domain/get-components-deps.js @@ -5,7 +5,9 @@ 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')); @@ -16,8 +18,12 @@ module.exports = function(components){ hasVersion = !_.isEmpty(version), depToInstall = hasVersion ? (d + '@' + version) : d; - if(!_.contains(deps, depToInstall)){ - deps.push(depToInstall); + if(!_.contains(deps.withVersions, depToInstall)){ + deps.withVersions.push(depToInstall); + } + + if(!_.contains(deps.modules, d)){ + deps.modules.push(d); } }); }); diff --git a/src/cli/domain/get-missing-deps.js b/src/cli/domain/get-missing-deps.js index b6dfb204f..8d6ae7796 100644 --- a/src/cli/domain/get-missing-deps.js +++ b/src/cli/domain/get-missing-deps.js @@ -8,14 +8,13 @@ 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 { diff --git a/src/cli/facade/dev.js b/src/cli/facade/dev.js index 1e85bd406..06a0d843d 100644 --- a/src/cli/facade/dev.js +++ b/src/cli/facade/dev.js @@ -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');