Permalink
Browse files

[master] Added npm#force command, to install dependencies inside app …

…dir not chroot. Maybe a fix to #284  #313 but mostly with trammi module
  • Loading branch information...
1 parent a3b735e commit cbbb414591d643d8a7963f0e62e0d66f9eba53a4 @alejandro alejandro committed Mar 16, 2012
Showing with 12 additions and 4 deletions.
  1. +1 −1 lib/app.js
  2. +11 −3 lib/npm.js
View
@@ -598,7 +598,7 @@ module.exports = {
lib.check_available_versions(function(d){
if (typeof d == 'array' || typeof d == 'object') {
d = d.map(function(v){
- return v.trim().substr(0,5);
+ return v.trim().substr(0,7);
});
}
res.json({
View
@@ -47,10 +47,16 @@ module.exports = {
});
var node_version;
var process_version = process.version.replace('v','');
+ var force = false;
// in the package what type of data is? #TODO
// always a try/catch for avoid mistakes and exceptions on the package.json read operation
+ // Due to #322, try to force the installation to the location of server|index|app.js
+ // the force command is going to install the node_modules inside the original path and not to
+ // chroot
try {
- node_version = JSON.parse(fs.readFileSync(app_user_npm_home + '/package.json', 'utf8'))['node'];
+ var jsonFile = JSON.parse(fs.readFileSync(app_user_npm_home + '/package.json', 'utf8'));
+ node_version = jsonFile['node'];
+ force = jsonFile['npm'] && jsonFile['npm'] === 'force' ? true :false ;
} catch(e){
node_version = process_version;
}
@@ -62,11 +68,13 @@ module.exports = {
}
// Inherit the installation to n, but n throw an error if the version is lower than 0.6.3
var command = 'n npm ' +node_version;
- if (parseFloat(node_version) <0.6 ){
+ if (parseFloat(node_version) < 0.6 ){
command = 'npm ';
}
+ var node_modules = app_user_home;
+ if (force) node_modules = app_user_npm_home;
package = p.join(' ');
- var cmd = 'cd ' + app_user_home + '; if [ ! -d node_modules ]; then mkdir node_modules; fi; '+ command
+ var cmd = 'cd ' + node_modules + '; if [ ! -d node_modules ]; then mkdir node_modules; fi; '+ command
+ ' ' + action + ' ' + package;
var pr = exec(cmd, function(err, stdout, stderr) {
res.send({

0 comments on commit cbbb414

Please sign in to comment.