tapioca 0.4.15 → 0.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tapioca/compilers/sorbet.rb +4 -1
- data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +26 -3
- data/lib/tapioca/generator.rb +51 -6
- data/lib/tapioca/loader.rb +13 -2
- data/lib/tapioca/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80a1d62bade6d75e6ec3a7de5a06f96eb7bc4ea002a70a2503d74393e834e864
|
4
|
+
data.tar.gz: 235cd2477d3f07176bdbddd5653c7a5cff86516f81dd196a65043a5b2f7d68dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23bc803e2b251dfb4ef4c82b0793336810ca9d551355ac1cd8d514c1484ef096d9b00a12cda214ce9b4b83ccf1620a32159035a5bf798a4c2d8a3e96b026e352
|
7
|
+
data.tar.gz: 606e2ad0e81c87e7f89b5933fa160d1b7825dee6f3f3451042ad2ec047a672041b559ed9cb79cf75aa0af7020b9aed2da85e1f52f36bb39b909f5037f8865717
|
@@ -8,6 +8,7 @@ module Tapioca
|
|
8
8
|
module Compilers
|
9
9
|
module Sorbet
|
10
10
|
SORBET = Pathname.new(Gem::Specification.find_by_name("sorbet-static").full_gem_path) / "libexec" / "sorbet"
|
11
|
+
EXE_PATH_ENV_VAR = "TAPIOCA_SORBET_EXE"
|
11
12
|
|
12
13
|
class << self
|
13
14
|
extend(T::Sig)
|
@@ -26,7 +27,9 @@ module Tapioca
|
|
26
27
|
|
27
28
|
sig { returns(String) }
|
28
29
|
def sorbet_path
|
29
|
-
SORBET
|
30
|
+
sorbet_path = ENV.fetch(EXE_PATH_ENV_VAR, SORBET)
|
31
|
+
sorbet_path = SORBET if sorbet_path.empty?
|
32
|
+
sorbet_path.to_s.shellescape
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
@@ -95,6 +95,7 @@ module Tapioca
|
|
95
95
|
return if alias_namespaced?(name)
|
96
96
|
return if seen?(name)
|
97
97
|
return unless parent_declares_constant?(name)
|
98
|
+
return if T::Enum === constant # T::Enum instances are defined via `compile_enums`
|
98
99
|
|
99
100
|
mark_seen(name)
|
100
101
|
compile_constant(name, constant)
|
@@ -183,6 +184,7 @@ module Tapioca
|
|
183
184
|
compile_mixins(constant),
|
184
185
|
compile_mixes_in_class_methods(constant),
|
185
186
|
compile_props(constant),
|
187
|
+
compile_enums(constant),
|
186
188
|
methods,
|
187
189
|
].select { |b| b != "" }.join("\n\n")
|
188
190
|
end
|
@@ -217,6 +219,23 @@ module Tapioca
|
|
217
219
|
end.join("\n")
|
218
220
|
end
|
219
221
|
|
222
|
+
sig { params(constant: Module).returns(String) }
|
223
|
+
def compile_enums(constant)
|
224
|
+
return "" unless constant < T::Enum
|
225
|
+
|
226
|
+
enums = T.cast(constant, T::Enum).values.map do |enum_type|
|
227
|
+
enum_type.instance_variable_get(:@const_name).to_s
|
228
|
+
end
|
229
|
+
|
230
|
+
content = [
|
231
|
+
indented('enums do'),
|
232
|
+
*enums.map { |e| indented(" #{e} = new") }.join("\n"),
|
233
|
+
indented('end'),
|
234
|
+
]
|
235
|
+
|
236
|
+
content.join("\n")
|
237
|
+
end
|
238
|
+
|
220
239
|
sig { params(name: String, constant: Module).returns(T.nilable(String)) }
|
221
240
|
def compile_subconstants(name, constant)
|
222
241
|
output = constants_of(constant).sort.uniq.map do |constant_name|
|
@@ -345,9 +364,13 @@ module Tapioca
|
|
345
364
|
end
|
346
365
|
|
347
366
|
define_singleton_method(:include) do |mod|
|
348
|
-
|
349
|
-
|
350
|
-
|
367
|
+
begin
|
368
|
+
before = singleton_class.ancestors
|
369
|
+
super(mod).tap do
|
370
|
+
mixins_from_modules[mod] = singleton_class.ancestors - before
|
371
|
+
end
|
372
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
373
|
+
# this is a best effort, bail if we can't perform this
|
351
374
|
end
|
352
375
|
end
|
353
376
|
|
data/lib/tapioca/generator.rb
CHANGED
@@ -121,6 +121,8 @@ module Tapioca
|
|
121
121
|
load_application(eager_load: requested_constants.empty?)
|
122
122
|
load_dsl_generators
|
123
123
|
|
124
|
+
rbi_files_to_purge = existing_rbi_filenames(requested_constants)
|
125
|
+
|
124
126
|
say("Compiling DSL RBI files...")
|
125
127
|
say("")
|
126
128
|
|
@@ -133,7 +135,17 @@ module Tapioca
|
|
133
135
|
)
|
134
136
|
|
135
137
|
compiler.run do |constant, contents|
|
136
|
-
compile_dsl_rbi(constant, contents)
|
138
|
+
filename = compile_dsl_rbi(constant, contents)
|
139
|
+
rbi_files_to_purge.delete(filename) if filename
|
140
|
+
end
|
141
|
+
|
142
|
+
unless rbi_files_to_purge.empty?
|
143
|
+
say("")
|
144
|
+
say("Removing stale RBI files...")
|
145
|
+
|
146
|
+
rbi_files_to_purge.sort.each do |filename|
|
147
|
+
remove(filename)
|
148
|
+
end
|
137
149
|
end
|
138
150
|
|
139
151
|
say("")
|
@@ -253,13 +265,38 @@ module Tapioca
|
|
253
265
|
|
254
266
|
sig { params(constant_names: T::Array[String]).returns(T::Array[Module]) }
|
255
267
|
def constantize(constant_names)
|
256
|
-
constant_names.map do |name|
|
268
|
+
constant_map = constant_names.map do |name|
|
257
269
|
begin
|
258
|
-
name.constantize
|
270
|
+
[name, name.constantize]
|
259
271
|
rescue NameError
|
260
|
-
nil
|
272
|
+
[name, nil]
|
273
|
+
end
|
274
|
+
end.to_h
|
275
|
+
|
276
|
+
unprocessable_constants = constant_map.select { |_, v| v.nil? }
|
277
|
+
unless unprocessable_constants.empty?
|
278
|
+
unprocessable_constants.each do |name, _|
|
279
|
+
say("Error: Cannot find constant '#{name}'", :red)
|
280
|
+
remove(dsl_rbi_filename(name))
|
281
|
+
end
|
282
|
+
|
283
|
+
exit(1)
|
284
|
+
end
|
285
|
+
|
286
|
+
constant_map.values
|
287
|
+
end
|
288
|
+
|
289
|
+
sig { params(requested_constants: T::Array[String]).returns(T::Set[Pathname]) }
|
290
|
+
def existing_rbi_filenames(requested_constants)
|
291
|
+
filenames = if requested_constants.empty?
|
292
|
+
Pathname.glob(config.outpath / "**/*.rbi")
|
293
|
+
else
|
294
|
+
requested_constants.map do |constant_name|
|
295
|
+
dsl_rbi_filename(constant_name)
|
261
296
|
end
|
262
|
-
end
|
297
|
+
end
|
298
|
+
|
299
|
+
filenames.to_set
|
263
300
|
end
|
264
301
|
|
265
302
|
sig { returns(T::Hash[String, String]) }
|
@@ -277,6 +314,11 @@ module Tapioca
|
|
277
314
|
.to_h
|
278
315
|
end
|
279
316
|
|
317
|
+
sig { params(constant_name: String).returns(Pathname) }
|
318
|
+
def dsl_rbi_filename(constant_name)
|
319
|
+
config.outpath / "#{constant_name.underscore}.rbi"
|
320
|
+
end
|
321
|
+
|
280
322
|
sig { params(gem_name: String, version: String).returns(Pathname) }
|
281
323
|
def gem_rbi_filename(gem_name, version)
|
282
324
|
config.outpath / "#{gem_name}@#{version}.rbi"
|
@@ -316,6 +358,7 @@ module Tapioca
|
|
316
358
|
|
317
359
|
sig { params(filename: Pathname).void }
|
318
360
|
def remove(filename)
|
361
|
+
return unless filename.exist?
|
319
362
|
say("-- Removing: #{filename}")
|
320
363
|
filename.unlink
|
321
364
|
end
|
@@ -456,7 +499,7 @@ module Tapioca
|
|
456
499
|
end
|
457
500
|
end
|
458
501
|
|
459
|
-
sig { params(constant: Module, contents: String).
|
502
|
+
sig { params(constant: Module, contents: String).returns(T.nilable(Pathname)) }
|
460
503
|
def compile_dsl_rbi(constant, contents)
|
461
504
|
return if contents.nil?
|
462
505
|
|
@@ -476,6 +519,8 @@ module Tapioca
|
|
476
519
|
File.write(filename, out)
|
477
520
|
say("Wrote: ", [:green])
|
478
521
|
say(filename)
|
522
|
+
|
523
|
+
filename
|
479
524
|
end
|
480
525
|
end
|
481
526
|
end
|
data/lib/tapioca/loader.rb
CHANGED
@@ -99,17 +99,28 @@ module Tapioca
|
|
99
99
|
|
100
100
|
sig { void }
|
101
101
|
def eager_load_rails_app
|
102
|
+
rails = Object.const_get("Rails")
|
103
|
+
application = rails.application
|
104
|
+
|
102
105
|
if Object.const_defined?("ActiveSupport")
|
103
106
|
Object.const_get("ActiveSupport").run_load_hooks(
|
104
107
|
:before_eager_load,
|
105
|
-
|
108
|
+
application
|
106
109
|
)
|
107
110
|
end
|
111
|
+
|
108
112
|
if Object.const_defined?("Zeitwerk::Loader")
|
109
113
|
zeitwerk_loader = Object.const_get("Zeitwerk::Loader")
|
110
114
|
zeitwerk_loader.eager_load_all
|
111
115
|
end
|
112
|
-
|
116
|
+
|
117
|
+
if rails.respond_to?(:autoloaders) && rails.autoloaders.zeitwerk_enabled?
|
118
|
+
rails.autoloaders.each(&:eager_load)
|
119
|
+
end
|
120
|
+
|
121
|
+
if application.config.respond_to?(:eager_load_namespaces)
|
122
|
+
application.config.eager_load_namespaces.each(&:eager_load!)
|
123
|
+
end
|
113
124
|
end
|
114
125
|
|
115
126
|
sig { void }
|
data/lib/tapioca/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tapioca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ufuk Kayserilioglu
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-
|
14
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|