@@ -6,8 +6,7 @@ var path = require('path');
6
6
var debug = require ( 'debug' ) ( 'component-builder:scripts:lookup' ) ;
7
7
var createManifest = require ( 'component-manifest' ) ;
8
8
9
- // default extensions to look up
10
- var EXTENSIONS = [
9
+ var EXTENSIONS = [ // default extensions to look up
11
10
'' ,
12
11
'.js' ,
13
12
'.json' ,
@@ -16,13 +15,25 @@ var EXTENSIONS = [
16
15
17
16
var RELATIVE_PATH = / ^ \. { 1 , 2 } \/ .* / ;
18
17
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
+ */
19
25
function Lookup ( file , opts ) {
20
26
if ( ! ( this instanceof Lookup ) ) return new Lookup ( file , opts ) ;
21
27
this . file = file ;
22
28
this . opts = opts ;
23
29
this . manifestGenerator = createManifest ( opts ) ;
24
30
}
25
31
32
+ /**
33
+ * Executes a lookup.
34
+ *
35
+ * @type {String } target
36
+ */
26
37
Lookup . prototype . exec = function * ( target ) {
27
38
var ret ;
28
39
target = target . toLowerCase ( ) ;
@@ -37,6 +48,13 @@ Lookup.prototype.exec = function* (target) {
37
48
}
38
49
} ;
39
50
51
+ /**
52
+ * Lookup a relative file.
53
+ *
54
+ * @param {String } target
55
+ * @param {Object } file
56
+ * @return {String }
57
+ */
40
58
Lookup . prototype . relatives = function ( target , file ) {
41
59
file || ( file = this . file ) ;
42
60
@@ -62,19 +80,28 @@ Lookup.prototype.relatives = function (target, file) {
62
80
return null ;
63
81
} ;
64
82
83
+ /**
84
+ * Lookup a nonrelative file.
85
+ *
86
+ * @param {String } target
87
+ * @return {String }
88
+ */
65
89
Lookup . prototype . nonrelatives = function * ( target ) {
66
90
var frags = tofrags ( target ) ;
67
91
var head = frags [ 0 ] , tail = frags [ 1 ] ;
68
92
var ret ;
69
93
94
+ // aliases
70
95
ret = this . aliases . apply ( this , frags )
71
96
if ( ret != null )
72
97
return ret ;
73
98
99
+ // locals
74
100
ret = yield * this . locals ( target ) ;
75
101
if ( ret != null )
76
102
return ret ;
77
103
104
+ // dependencies
78
105
ret = yield * this . dependencies ( target ) ;
79
106
if ( ret != null )
80
107
return ret ;
@@ -97,6 +124,16 @@ Lookup.prototype.nonrelatives = function* (target) {
97
124
return target ;
98
125
} ;
99
126
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
+ */
100
137
Lookup . prototype . aliases = function ( head , tail ) {
101
138
var deps = this . file . branch . dependencies ;
102
139
var name ;
@@ -145,6 +182,15 @@ Lookup.prototype.foreignRelative = function* (branch, relativeFile) {
145
182
return relative ;
146
183
} ;
147
184
185
+ /**
186
+ * Lookup a local dependency.
187
+ *
188
+ * <local-name>
189
+ * <local-name>/<filename>
190
+ *
191
+ * @param {String } target
192
+ * @return {String }
193
+ */
148
194
Lookup . prototype . locals = function * ( target ) {
149
195
var deps = this . file . branch . locals ;
150
196
var keys = Object . keys ( deps ) ;
@@ -172,6 +218,15 @@ Lookup.prototype.locals = function* (target) {
172
218
}
173
219
} ;
174
220
221
+ /**
222
+ * Lookup a remote dependency.
223
+ *
224
+ * <repo>
225
+ * <reference>/<filename>
226
+ *
227
+ * @param {String } target
228
+ * @return {String }
229
+ */
175
230
Lookup . prototype . dependencies = function * ( target ) {
176
231
var deps = this . file . branch . dependencies ;
177
232
var keys = Object . keys ( deps ) ;
@@ -200,6 +255,12 @@ Lookup.prototype.dependencies = function* (target) {
200
255
}
201
256
} ;
202
257
258
+ /**
259
+ * Split reference name.
260
+ *
261
+ * @param {String } target
262
+ * @return {Array }
263
+ */
203
264
function tofrags ( target ) {
204
265
var frags = target . split ( '/' ) ;
205
266
var head = frags [ 0 ] ;
0 commit comments