Skip to content

Commit 9e51e46

Browse files
committed
comments
1 parent 1e685b2 commit 9e51e46

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

lib/builders/lookup.js

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ var path = require('path');
66
var debug = require('debug')('component-builder:scripts:lookup');
77
var createManifest = require('component-manifest');
88

9-
// default extensions to look up
10-
var EXTENSIONS = [
9+
var EXTENSIONS = [ // default extensions to look up
1110
'',
1211
'.js',
1312
'.json',
@@ -16,13 +15,25 @@ var EXTENSIONS = [
1615

1716
var RELATIVE_PATH = /^\.{1,2}\/.*/;
1817

18+
/**
19+
* From a file, lookup another file within that dep.
20+
* For use within `require()`s.
21+
*
22+
* @param {Object} file
23+
* @param {Object} opts for manifest generator
24+
*/
1925
function Lookup (file, opts) {
2026
if (!(this instanceof Lookup)) return new Lookup(file, opts);
2127
this.file = file;
2228
this.opts = opts;
2329
this.manifestGenerator = createManifest(opts);
2430
}
2531

32+
/**
33+
* Executes a lookup.
34+
*
35+
* @type {String} target
36+
*/
2637
Lookup.prototype.exec = function* (target) {
2738
var ret;
2839
target = target.toLowerCase();
@@ -37,6 +48,13 @@ Lookup.prototype.exec = function* (target) {
3748
}
3849
};
3950

51+
/**
52+
* Lookup a relative file.
53+
*
54+
* @param {String} target
55+
* @param {Object} file
56+
* @return {String}
57+
*/
4058
Lookup.prototype.relatives = function (target, file) {
4159
file || (file = this.file);
4260

@@ -62,19 +80,28 @@ Lookup.prototype.relatives = function (target, file) {
6280
return null;
6381
};
6482

83+
/**
84+
* Lookup a nonrelative file.
85+
*
86+
* @param {String} target
87+
* @return {String}
88+
*/
6589
Lookup.prototype.nonrelatives = function* (target) {
6690
var frags = tofrags(target);
6791
var head = frags[0], tail = frags[1];
6892
var ret;
6993

94+
// aliases
7095
ret = this.aliases.apply(this, frags)
7196
if (ret != null)
7297
return ret;
7398

99+
// locals
74100
ret = yield* this.locals(target);
75101
if (ret != null)
76102
return ret;
77103

104+
// dependencies
78105
ret = yield* this.dependencies(target);
79106
if (ret != null)
80107
return ret;
@@ -97,6 +124,16 @@ Lookup.prototype.nonrelatives = function* (target) {
97124
return target;
98125
};
99126

127+
/**
128+
* Lookup an alias.
129+
*
130+
* <user>-<repo>
131+
* <user>~<repo>
132+
*
133+
* @param {String} head
134+
* @param {String} tail
135+
* @return {String}
136+
*/
100137
Lookup.prototype.aliases = function (head, tail) {
101138
var deps = this.file.branch.dependencies;
102139
var name;
@@ -145,6 +182,15 @@ Lookup.prototype.foreignRelative = function* (branch, relativeFile) {
145182
return relative;
146183
};
147184

185+
/**
186+
* Lookup a local dependency.
187+
*
188+
* <local-name>
189+
* <local-name>/<filename>
190+
*
191+
* @param {String} target
192+
* @return {String}
193+
*/
148194
Lookup.prototype.locals = function* (target) {
149195
var deps = this.file.branch.locals;
150196
var keys = Object.keys(deps);
@@ -172,6 +218,15 @@ Lookup.prototype.locals = function* (target) {
172218
}
173219
};
174220

221+
/**
222+
* Lookup a remote dependency.
223+
*
224+
* <repo>
225+
* <reference>/<filename>
226+
*
227+
* @param {String} target
228+
* @return {String}
229+
*/
175230
Lookup.prototype.dependencies = function* (target) {
176231
var deps = this.file.branch.dependencies;
177232
var keys = Object.keys(deps);
@@ -200,6 +255,12 @@ Lookup.prototype.dependencies = function* (target) {
200255
}
201256
};
202257

258+
/**
259+
* Split reference name.
260+
*
261+
* @param {String} target
262+
* @return {Array}
263+
*/
203264
function tofrags (target) {
204265
var frags = target.split('/');
205266
var head = frags[0];

0 commit comments

Comments
 (0)