@@ -5,15 +5,15 @@ var file = process.argv[2],
5
5
estraverse = require ( 'estraverse' ) ,
6
6
curdir = String ( process . cwd ( ) + '/' + process . argv [ 2 ] ) . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) ;
7
7
8
- console . log ( curdir . green ) ;
8
+ hapi = require ( 'hapi' ) ;
9
9
10
- require ( 'hapi' ) ;
10
+ console . log ( curdir . green ) ;
11
11
12
- // console.log(require.resolve('hapi'));
13
12
var requires = { } ;
14
13
15
14
function getRequires ( file , scope ) {
16
- console . log ( file . green )
15
+ curdir = file . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) ;
16
+ console . log ( curdir . green ) ;
17
17
18
18
// console.log(('processing ' + file + '\n').blue);
19
19
@@ -31,18 +31,33 @@ function getRequires(file, scope) {
31
31
}
32
32
}
33
33
if ( node . type == 'CallExpression' && node . callee . name == 'require' ) {
34
- var p ;
34
+ var pkg ;
35
35
if ( node . arguments [ 0 ] . type == 'Literal' ) {
36
- p = node . arguments [ 0 ] . value ;
36
+ pkg = node . arguments [ 0 ] . value ;
37
37
} else if ( node . arguments [ 0 ] . type == 'Identifier' ) {
38
- p = vars [ node . arguments [ 0 ] . name ] ;
38
+ pkg = vars [ node . arguments [ 0 ] . name ] ;
39
39
}
40
40
41
- console . log ( p ) ;
42
- if ( p && require . resolve ( p ) != p ) {
43
- // console.log(require.resolve(p).red);
44
- console . log ( scope , p ) ;
45
- req [ p ] = getRequires ( require . resolve ( p ) , scope + '-' ) ;
41
+ console . log ( String ( pkg ) ) ;
42
+ // Do we actually have a package we are looking at
43
+ if ( pkg ) {
44
+ // Try to load it. If node can't find it, we try a different approach
45
+ try {
46
+ if ( require . resolve ( pkg ) != pkg ) {
47
+ // console.log(require.resolve(pkg).red);
48
+ console . log ( scope , pkg ) ;
49
+ req [ pkg ] = getRequires ( resolve ( pkg ) , scope + '-' ) ;
50
+ }
51
+ } catch ( err ) {
52
+ // Assume it's a folder
53
+ if ( pkg [ 0 ] == "." && pkg [ 1 ] == "/" ) {
54
+ curdir += pkg . slice ( 1 ) ;
55
+ console . log ( scope , 'index.js' ) ;
56
+ req [ 'index.js' ] = getRequires ( resolve ( 'index.js' ) , scope + '-' ) ;
57
+ } else {
58
+ console . log ( String ( pkg ) . red ) ;
59
+ }
60
+ }
46
61
}
47
62
}
48
63
}
@@ -53,11 +68,14 @@ function getRequires(file, scope) {
53
68
}
54
69
55
70
function resolve ( pkg ) {
56
- var s = plg . split ( '.' ) ;
57
- if ( s [ s . length - 1 ] == 'js' ? true : ( fs . exists ( pkg ) || fs . exists ( pkg + ".js" ) ) ) {
58
-
71
+ var s = pkg . split ( '.' ) ;
72
+ if ( pkg [ 0 ] == '.' ) {
73
+ if ( s [ s . length - 1 ] == 'js' ? true : ( fs . exists ( pkg ) || fs . exists ( pkg + ".js" ) ) ) {
74
+ }
75
+ console . log ( pkg . orange ) ;
59
76
}
77
+ return require . resolve ( pkg , { basedir : curdir } ) ;
60
78
}
61
79
62
80
requires = getRequires ( file ) ;
63
- console . log ( requires ) ;
81
+ console . log ( JSON . stringify ( requires ) ) ;
0 commit comments