Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 404058

Summary: [Node server]Npm install does not work properly on the current working directory.
Product: [ECD] Orion Reporter: libing wang <libingw>
Component: NodeAssignee: libing wang <libingw>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mamacdon
Version: 2.0   
Target Milestone: 3.0 M2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description libing wang CLA 2013-03-21 13:19:20 EDT
I found this when trying to verify if "cwd" works properly in Orion node, after the recent client changes.
Basically the "cwd" passed into a shell page command is always an encoded URI now.

I noticed that Orion node always ignores the cwd and install a package under the folder where "node server.js" is executed.

Need investigations on server side...
Comment 1 libing wang CLA 2013-04-15 16:17:13 EDT
Did some investigations today:
1.If you use a specific work space, e.g. d:\\foo, as the -workspace option when starting orion server, the npm install will work perfectly, creating the node_module folder for the first when you use npm install and install everything under it.

2.If you just use the default .workspace created by orion node, then the package will be installed under the node_module folder whose parent folder is where you started the orion node server.
Comment 2 libing wang CLA 2013-04-16 10:11:03 EDT
According to https://npmjs.org/doc/folders.html, if any of the CWD's parent folder chain contains a folder called node_modules, then that folder(the closest parent or grand parent) is treated as the cwd, or current working directory.

So if you start orionode by "node server.js", orionode creates the so called .workspace folder under the orionode folder. In the meanwhile, as orionode folder already has a sub folder called node_modules, no matter you cd to any sub folder og ".worksapce", npm install treats orionode as the current working directory.
Comment 3 libing wang CLA 2013-04-16 13:59:19 EDT
Summary of the walk-up from the link above:
Starting at the $PWD, npm will walk up the folder tree checking for a folder that contains either a package.json file, or a node_modules folder. If such a thing is found, then that is treated as the effective "current directory" for the purpose of running npm commands. (This behavior is inspired by and similar to git's .git-folder seeking logic when running git commands in a working dir.)
Comment 4 libing wang CLA 2013-04-17 15:06:45 EDT
Talked to Mark and Ken today and here is what we are going to do:

1.If CWD is the workspace root, then NPM command is not available. We will promt message whne user types an NPM command.
2.Whenever an NPM command is triggered in a sub folder of the workspace, we do a walk up from the CWD to the first level children(or so called project) of the workspace. If there is already a sub folder called "node_modules" or a file called package.json in the first node during the walk-up, we do nothing because NPM command will eventually use it.
3.If we cant find "node_modules" in any node during the walk-up, then we will create the "node_modules" folder in the CWD.

4.After making sure the "node_modules" folder is somewhere under the work space, we spawn the NPM command process. By doing this, NPM command will never use any "node_modules" beyond the work space.