Skip to content

Commit 98c3496

Browse files
Merge pull request #600 from RubyElders/relative-shim
2 parents 5c3be7f + 0df841f commit 98c3496

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/gems/js/lib/js/require_remote.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ module JS
3737
# rescue LoadError
3838
# JS::RequireRemote.instance.load(path)
3939
# end
40-
# end
40+
# end
41+
#
42+
# You can also load included shim to achieve the same.
43+
#
44+
# == Example
45+
#
46+
# require 'js/require_remote/relative_shim'
4147
#
4248
class RequireRemote
4349
include Singleton
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'js/require_remote'
2+
3+
module Kernel
4+
alias original_require_relative require_relative
5+
6+
def require_relative(path)
7+
caller_path = caller_locations(1, 1).first.absolute_path || ''
8+
dir = File.dirname(caller_path)
9+
file = File.absolute_path(path, dir)
10+
11+
original_require_relative(file)
12+
rescue LoadError
13+
JS::RequireRemote.instance.load(path)
14+
end
15+
end

0 commit comments

Comments
 (0)