lib/tapioca/commands/dsl.rb in tapioca-0.11.1 vs lib/tapioca/commands/dsl.rb in tapioca-0.11.2
- old
+ new
@@ -91,32 +91,25 @@
sig { override.void }
def execute
Loaders::Dsl.load_application(
tapioca_path: @tapioca_path,
- eager_load: @requested_constants.empty?,
+ eager_load: @requested_constants.empty? && @requested_paths.empty?,
app_root: @app_root,
)
if @should_verify
say("Checking for out-of-date RBIs...")
else
say("Compiling DSL RBI files...")
end
say("")
- unless @requested_paths.empty?
- constants_from_paths = Static::SymbolLoader.symbols_from_paths(@requested_paths).to_a
- if constants_from_paths.empty?
- say_error("\nWarning: No constants found in: #{@requested_paths.map(&:to_s).join(", ")}", :yellow)
- end
+ all_requested_constants = @requested_constants + constants_from_requested_paths
- @requested_constants += constants_from_paths
- end
-
outpath = @should_verify ? Pathname.new(Dir.mktmpdir) : @outpath
- rbi_files_to_purge = existing_rbi_filenames(@requested_constants)
+ rbi_files_to_purge = existing_rbi_filenames(all_requested_constants)
pipeline = create_pipeline
processed_files = pipeline.run do |constant, contents|
constant_name = T.must(Tapioca::Runtime::Reflection.name_of(constant))
@@ -144,11 +137,11 @@
say("Done", :green)
if @auto_strictness
say("")
validate_rbi_files(
- command: default_command(:dsl, @requested_constants.join(" ")),
+ command: default_command(:dsl, all_requested_constants.join(" ")),
gem_dir: @gem_dir,
dsl_dir: @outpath.to_s,
auto_strictness: @auto_strictness,
compilers: pipeline.active_compilers,
)
@@ -162,11 +155,12 @@
private
sig { returns(Tapioca::Dsl::Pipeline) }
def create_pipeline
Tapioca::Dsl::Pipeline.new(
- requested_constants: constantize(@requested_constants),
+ requested_constants:
+ constantize(@requested_constants) + constantize(constants_from_requested_paths, ignore_missing: true),
requested_paths: @requested_paths,
requested_compilers: constantize_compilers(@only),
excluded_compilers: constantize_compilers(@exclude),
error_handler: ->(error) {
say_error(error, :bold, :red)
@@ -187,31 +181,31 @@
end
filenames.to_set
end
- sig { params(constant_names: T::Array[String]).returns(T::Array[Module]) }
- def constantize(constant_names)
+ sig { params(constant_names: T::Array[String], ignore_missing: T::Boolean).returns(T::Array[Module]) }
+ def constantize(constant_names, ignore_missing: false)
constant_map = constant_names.to_h do |name|
[name, Object.const_get(name)]
rescue NameError
[name, nil]
end
- unprocessable_constants = constant_map.select { |_, v| v.nil? }
+ processable_constants, unprocessable_constants = constant_map.partition { |_, v| !v.nil? }
- unless unprocessable_constants.empty?
+ unless unprocessable_constants.empty? || ignore_missing
unprocessable_constants.each do |name, _|
say("Error: Cannot find constant '#{name}'", :red)
filename = dsl_rbi_filename(name)
remove_file(filename) if File.file?(filename)
end
raise Thor::Error, ""
end
- constant_map.values
+ processable_constants.map { |_, constant| constant }
end
sig { params(compiler_names: T::Array[String]).returns(T::Array[T.class_of(Tapioca::Dsl::Compiler)]) }
def constantize_compilers(compiler_names)
compiler_map = compiler_names.to_h do |name|
@@ -381,9 +375,17 @@
end
sig { params(constant: String).returns(String) }
def generate_command_for(constant)
default_command(:dsl, constant)
+ end
+
+ sig { returns(T::Array[String]) }
+ def constants_from_requested_paths
+ @constants_from_requested_paths ||= T.let(
+ Static::SymbolLoader.symbols_from_paths(@requested_paths).to_a,
+ T.nilable(T::Array[String]),
+ )
end
end
end
end