Skip to content

Commit

Permalink
Merge pull request #2044 from opal/elia/path-reader-fixes
Browse files Browse the repository at this point in the history
Fix PathReader when a file is missing
  • Loading branch information
elia committed Dec 22, 2019
2 parents 951cd0b + 6af7e86 commit 9d00d29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 2 additions & 10 deletions lib/opal/builder.rb
Expand Up @@ -195,16 +195,8 @@ def process_require(rel_path, options)

source = stub?(rel_path) ? '' : read(rel_path)

if source.nil?
message = "can't find file: #{rel_path.inspect}"
case missing_require_severity
when :error then raise LoadError, message
when :warning then warn "can't find file: #{rel_path.inspect}"
when :ignore then # noop
end

return # the handling is delegated to the runtime
end
# The handling is delegated to the runtime
return if source.nil?

abs_path = expand_path(rel_path)
rel_path = expand_ext(rel_path)
Expand Down
2 changes: 1 addition & 1 deletion lib/opal/path_reader.rb
Expand Up @@ -17,7 +17,7 @@ def initialize(paths = Opal.paths, extensions = DEFAULT_EXTENSIONS)
def read(path)
full_path = expand(path)
return nil if full_path.nil?
File.open(full_path, 'rb:UTF-8', &:read)
File.open(full_path, 'rb:UTF-8', &:read) if File.exist?(full_path)
end

def expand(path)
Expand Down

0 comments on commit 9d00d29

Please sign in to comment.