Skip to content

Commit

Permalink
Change comments to yuidoc style
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic authored and mixonic committed Apr 15, 2015
1 parent c21ed56 commit b844284
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 34 deletions.
75 changes: 49 additions & 26 deletions lib/cli/node-modules-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,68 @@ function isSubdirectoryOf(parentPath, possibleChildPath) {
possibleChildPath.indexOf(parentPath) === 0;
}

// A utility function for determining what path an addon may be found at. Addons
// will only be resolved in the project's local `node_modules/` directory. This
// is in contrast to a plain `require('some-module')` lookup, which would resolve
// a library according to the paths in NODE_PATH.
//
// A description of node's lookup logic can be found here:
//
// * https://nodejs.org/api/modules.html#modules_all_together
//
// By requiring with an absolute path this logic is bypassed.
//
/**
A utility function for determining what path an addon may be found at. Addons
will only be resolved in the project's own `node_modules/` directory, they
do not follow the standard node `require` logic that a standard
`require('mode-module')` lookup would use, which finds the module according
to the `NODE_PATH`.
A description of node's lookup logic can be found here:
https://nodejs.org/api/modules.html#modules_all_together
Using this method to discover the correct location of project's `node_modules`
directory allows addons to be looked up properly even when that `node_modules`
directory is outside of the project's root.
This method checks the env variable `EMBER_NODE_PATH`. If present, its value
is used to determine the `node_modules` path.
Possible use cases for this include caching
the `node_modules/` directory outside of a source code checkout, and
ensuring the same source code (shared over a network) can be used with
different environments (Linux, OSX) where binary compatibility may not
exist.
For example, if you have a project in /projects/my-app and its `node_modules`
directory is at /resource/node_modules, you would:
```
# Node uses this as its search path for standard `require('module')` calls
export NODE_PATH=/resource/node_modules
# So that ember addon discovery looks here
export EMBER_NODE_PATH=/resource/node_modules
cd /projects/my-app && ember build
```
@private
@method nodeModulesPath
@param {String} context The starting directory to use to find the
node_modules path. This will usually be the
project's root
@return {String} absolute path to the node_modules directory
*/
module.exports = function nodeModulesPath(context) {

// Optionally configure a different home for `node_modules/` in a parent
// directory of the project. Possible use cases for this include caching
// the `node_modules/` directory outside of a source code checkout, and
// ensuring the same source code (shared over a network) can be used with
// different environments (Linux, OSX) where binary compatibility may not
// exist.
//
// For example, you can specify a different home directory for modules:
//
// EMBER_NODE_PATH=/opt/deps/node_modules NODE_PATH=/opt/deps/node_modules ember build
//
var nodePath = process.env.EMBER_NODE_PATH;
var contextPath = path.resolve(context);

if (nodePath) {
var configuredPath = path.resolve(nodePath);

// The contextPath is likely the project root, or possibly a subdirectory in
// node_modules/ nested dependencies. If it is more specific (a subdirectory
// of) than the configuredPath prefer the more specific contextPath.
// node_modules/ nested dependencies. If it is more specific than the
// the configuredPath (i.e. it is a subdirectory of the configuredPath)
// prefer the more specific contextPath.
if (isSubdirectoryOf(configuredPath, contextPath)) {
return path.resolve(contextPath,'node_modules');
return path.resolve(contextPath, 'node_modules');
} else {
return path.resolve(nodePath);
}
} else {
return path.resolve(contextPath,'node_modules');
return path.resolve(contextPath, 'node_modules');
}
};
14 changes: 7 additions & 7 deletions lib/models/addon-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
@module ember-cli
*/

var assign = require('lodash/object/assign');
var debug = require('debug')('ember-cli:addon-discovery');
var fs = require('fs');
var path = require('path');
var CoreObject = require('core-object');
var resolve = require('resolve');
var findup = require('findup');
var assign = require('lodash/object/assign');
var debug = require('debug')('ember-cli:addon-discovery');
var fs = require('fs');
var path = require('path');
var CoreObject = require('core-object');
var resolve = require('resolve');
var findup = require('findup');

/**
AddonDiscovery is responsible for collecting information about all of the
Expand Down
8 changes: 8 additions & 0 deletions lib/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ Project.prototype.setupBowerDirectory = function() {
debug('bowerDirectory: %s', this.bowerDirectory);
};

/**
Sets the path to the node_modules directory for this
project.
@private
@method setupNodeModulesPath
*/
Project.prototype.setupNodeModulesPath = function(){
this.nodeModulesPath = nodeModulesPath(this.root);
debug('nodeModulesPath: %s', this.nodeModulesPath);
};

var NULL_PROJECT = new Project(process.cwd(), {});
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/models/project-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ describe('models/project.js', function() {

makeProject();

expect(project.nodeModulesPath).to.equal(nodePath);
expect(project.nodeModulesPath).to.equal(path.resolve(nodePath));
});

it('should equal project.root joined with "node_modules" when EMBER_NODE_PATH is not set', function() {
Expand Down

0 comments on commit b844284

Please sign in to comment.