@@ -27,7 +27,7 @@ def self.build(*args, &block)
27
27
end
28
28
29
29
def build ( path , options = { } )
30
- source = path_reader . read ( path )
30
+ source = read ( path )
31
31
build_str ( source , path , options )
32
32
end
33
33
@@ -63,11 +63,25 @@ def source_map
63
63
private
64
64
65
65
def tree_requires ( asset , path )
66
+ if path . nil? or path . empty?
67
+ dirname = Dir . pwd
68
+ else
69
+ dirname = File . dirname ( File . expand_path ( path ) )
70
+ end
71
+
72
+ paths = path_reader . paths . map { |p | File . expand_path ( p ) }
73
+
66
74
asset . required_trees . flat_map do |tree |
67
- base = File . expand_path ( File . dirname ( path ) )
68
- expanded = File . expand_path File . join ( base , tree , '*.rb' )
69
- Dir [ expanded ] . map do |file |
70
- file . gsub ( /(\. js)?(\. (?:rb|opal))/ , '' ) [ ( base . size +1 ) ..-1 ]
75
+ expanded = File . expand_path ( tree , dirname )
76
+ base = paths . find { |p | expanded . start_with? ( p ) }
77
+ next [ ] if base . nil?
78
+
79
+ globs = [ ]
80
+ globs << File . join ( base , tree , '*.rb' )
81
+ globs << File . join ( base , tree , '*.opal' )
82
+ globs << File . join ( base , tree , '*.js' )
83
+ Dir [ *globs ] . map do |file |
84
+ Pathname ( file ) . relative_path_from ( Pathname ( base ) ) . to_s . gsub ( /(\. js)?(\. (?:rb|opal))/ , '' )
71
85
end
72
86
end
73
87
end
@@ -78,25 +92,34 @@ def processor_for(source, filename, path, options)
78
92
return processor . new ( source , filename , compiler_options . merge ( options ) )
79
93
end
80
94
95
+ def read ( path )
96
+ path_reader . read ( path ) or
97
+ raise ArgumentError , "can't find file: #{ path . inspect } in #{ path_reader . paths . inspect } "
98
+ end
99
+
81
100
def process_require ( filename , options )
82
101
return if prerequired . include? ( filename )
83
102
return if already_processed . include? ( filename )
84
103
already_processed << filename
85
104
86
- source = stub? ( filename ) ? '' : path_reader . read ( filename )
105
+ source = stub? ( filename ) ? '' : read ( filename )
87
106
88
- if source . nil? && @compiler_options [ :dynamic_require_severity ] != :error
89
- raise LoadError , "can't find file: #{ filename . inspect } "
107
+ if source . nil?
108
+ message = "can't find file: #{ filename . inspect } "
109
+ case @compiler_options [ :dynamic_require_severity ]
110
+ when :error then raise LoadError , message
111
+ when :warning then warn "can't find file: #{ filename . inspect } "
112
+ end
90
113
end
91
114
92
115
path = path_reader . expand ( filename ) . to_s unless stub? ( filename )
93
116
asset = processor_for ( source , filename , path , options . merge ( requirable : true ) )
94
- process_requires ( asset , options )
117
+ process_requires ( asset . requires + tree_requires ( asset , path ) , options )
95
118
processed << asset
96
119
end
97
120
98
- def process_requires ( asset , options )
99
- asset . requires . map { |r | process_require ( r , options ) }
121
+ def process_requires ( requires , options )
122
+ requires . map { |r | process_require ( r , options ) }
100
123
end
101
124
102
125
def already_processed
0 commit comments