| Summary: | [Node server]Npm install does not work properly on the current working directory. | ||
|---|---|---|---|
| Product: | [ECD] Orion | Reporter: | libing wang <libingw> |
| Component: | Node | Assignee: | 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
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. 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. 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.) 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. |