bootsnap 1.2.1 → 1.3.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b48e0aabb1c875a210738d7a597b9880430ca2ee
4
- data.tar.gz: c4a7bb3fb47c6d3201d7cfa93893dec981648a77
2
+ SHA256:
3
+ metadata.gz: 59e846e5b543cc8ebf02a676f9adff11d38d87061a4b9c70ba66b102a756dcab
4
+ data.tar.gz: 072267311a56c37998d89c10a2461d425ac0c4ff9a6a31f6145ea8287e2d648d
5
5
  SHA512:
6
- metadata.gz: 3d21de8da773dddbeb6e931daa99bb2873a78a9cf4a57f7d0a6582bf209a1a64a9f9a2cf6dd842a596e045cd9f55b7f32e6d97c0c24a68b39b465cb7dccde74f
7
- data.tar.gz: da239a7e734181d091d71e22e1265baf72e8dc0d2cec1d69fd0ff3f7c38841e08ce6564ba64672c085bd78b341446b63acaaf5236f0dcb6d0401f3ac1aecd395
6
+ metadata.gz: 9e83fad988678cbfb43dc85544d7ee9e4a5d966c547f649e056e97e723244ed69cfa0aa464e9c726aa6812e3e7776de19127f63518af2649af6f6fc914e4e3b5
7
+ data.tar.gz: b907d30c5784c5bc3f0b6368ec2d94fb893e911dc82201dba693d1461da7797b56b1710d5ed977b76894747a72cf1bbd8fa791cb00f29fdf9b45d8a1bd93524c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.3.0
2
+
3
+ * Handle cases where load path entries are symlinked (https://github.com/Shopify/bootsnap/pull/136)
4
+
1
5
  # 1.2.1
2
6
 
3
7
  * Fix method visibility of `Kernel#require`.
data/README.md CHANGED
@@ -10,7 +10,7 @@ to optimize and cache expensive computations. See [How Does This Work](#how-does
10
10
 
11
11
  ## Usage
12
12
 
13
- This gem works on MacOS and Linux.
13
+ This gem works on macOS and Linux.
14
14
 
15
15
  Add `bootsnap` to your `Gemfile`:
16
16
 
@@ -21,12 +21,14 @@ module Bootsnap
21
21
  CACHED_EXTENSIONS = DLEXT2 ? [DOT_RB, DLEXT, DLEXT2] : [DOT_RB, DLEXT]
22
22
 
23
23
  class << self
24
- attr_reader :load_path_cache, :autoload_paths_cache, :loaded_features_index
24
+ attr_reader :load_path_cache, :autoload_paths_cache,
25
+ :loaded_features_index, :realpath_cache
25
26
 
26
27
  def setup(cache_path:, development_mode:, active_support: true)
27
28
  store = Store.new(cache_path)
28
29
 
29
30
  @loaded_features_index = LoadedFeaturesIndex.new
31
+ @realpath_cache = RealpathCache.new
30
32
 
31
33
  @load_path_cache = Cache.new(store, $LOAD_PATH, development_mode: development_mode)
32
34
  require_relative 'load_path_cache/core_ext/kernel_require'
@@ -53,3 +55,4 @@ require_relative 'load_path_cache/cache'
53
55
  require_relative 'load_path_cache/store'
54
56
  require_relative 'load_path_cache/change_observer'
55
57
  require_relative 'load_path_cache/loaded_features_index'
58
+ require_relative 'load_path_cache/realpath_cache'
@@ -9,7 +9,7 @@ module Bootsnap
9
9
  @development_mode = development_mode
10
10
  @store = store
11
11
  @mutex = defined?(::Mutex) ? ::Mutex.new : ::Thread::Mutex.new # TODO: Remove once Ruby 2.2 support is dropped.
12
- @path_obj = path_obj
12
+ @path_obj = path_obj.map { |f| File.exist?(f) ? File.realpath(f) : f }
13
13
  @has_relative_paths = nil
14
14
  reinitialize
15
15
  end
@@ -36,6 +36,14 @@ module Kernel
36
36
  require_with_bootsnap_lfi(path)
37
37
  end
38
38
 
39
+ alias_method :require_relative_without_bootsnap, :require_relative
40
+ def require_relative(path)
41
+ realpath = Bootsnap::LoadPathCache.realpath_cache.call(
42
+ caller_locations(1..1).first.absolute_path, path
43
+ )
44
+ require(realpath)
45
+ end
46
+
39
47
  alias_method :load_without_bootsnap, :load
40
48
  def load(path, wrap = false)
41
49
  if resolved = Bootsnap::LoadPathCache.load_path_cache.find(path)
@@ -78,6 +86,14 @@ class << Kernel
78
86
  require_with_bootsnap_lfi(path)
79
87
  end
80
88
 
89
+ alias_method :require_relative_without_bootsnap, :require_relative
90
+ def require_relative(path)
91
+ realpath = Bootsnap::LoadPathCache.realpath_cache.call(
92
+ caller_locations(1..1).first.absolute_path, path
93
+ )
94
+ require(realpath)
95
+ end
96
+
81
97
  alias_method :load_without_bootsnap, :load
82
98
  def load(path, wrap = false)
83
99
  if resolved = Bootsnap::LoadPathCache.load_path_cache.find(path)
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootsnap
4
+ module LoadPathCache
5
+ class RealpathCache
6
+ def initialize
7
+ @cache = Hash.new { |h, k| h[k] = realpath(*k) }
8
+ end
9
+
10
+ def call(*key)
11
+ @cache[key]
12
+ end
13
+
14
+ private
15
+
16
+ def realpath(caller_location, path)
17
+ base = File.dirname(caller_location)
18
+ file = find_file(File.expand_path(path, base))
19
+ dir = File.dirname(file)
20
+ File.join(dir, File.basename(file))
21
+ end
22
+
23
+ def find_file(name)
24
+ ['', *CACHED_EXTENSIONS].each do |ext|
25
+ filename = "#{name}#{ext}"
26
+ return File.realpath(filename) if File.exist?(filename)
27
+ end
28
+ name
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Bootsnap
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0.beta"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootsnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-22 00:00:00.000000000 Z
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,6 +135,7 @@ files:
135
135
  - lib/bootsnap/load_path_cache/loaded_features_index.rb
136
136
  - lib/bootsnap/load_path_cache/path.rb
137
137
  - lib/bootsnap/load_path_cache/path_scanner.rb
138
+ - lib/bootsnap/load_path_cache/realpath_cache.rb
138
139
  - lib/bootsnap/load_path_cache/store.rb
139
140
  - lib/bootsnap/setup.rb
140
141
  - lib/bootsnap/version.rb
@@ -154,12 +155,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
155
  version: 2.0.0
155
156
  required_rubygems_version: !ruby/object:Gem::Requirement
156
157
  requirements:
157
- - - ">="
158
+ - - ">"
158
159
  - !ruby/object:Gem::Version
159
- version: '0'
160
+ version: 1.3.1
160
161
  requirements: []
161
162
  rubyforge_project:
162
- rubygems_version: 2.6.14
163
+ rubygems_version: 2.7.6
163
164
  signing_key:
164
165
  specification_version: 4
165
166
  summary: Boot large ruby/rails apps faster