From f2d719dac30d6d882b23810469caafebdab70a0e Mon Sep 17 00:00:00 2001 From: Cory Hutchison Date: Mon, 15 Mar 2021 14:27:24 -0600 Subject: [PATCH 01/10] Remove Config.generate_command and update tests --- lib/tapioca/cli.rb | 4 ---- lib/tapioca/config.rb | 1 - lib/tapioca/generator.rb | 11 +++++------ spec/tapioca/cli_spec.rb | 29 ++++++++++++++--------------- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/lib/tapioca/cli.rb b/lib/tapioca/cli.rb index 247202023..e90110946 100644 --- a/lib/tapioca/cli.rb +++ b/lib/tapioca/cli.rb @@ -19,10 +19,6 @@ class Cli < Thor aliases: ["--out", "-o"], banner: "directory", desc: "The output directory for generated RBI files" - class_option :generate_command, - aliases: ["--cmd", "-c"], - banner: "command", - desc: "The command to run to regenerate RBI files" class_option :exclude, aliases: ["-x"], type: :array, diff --git a/lib/tapioca/config.rb b/lib/tapioca/config.rb index 277831fa5..65e143c9c 100644 --- a/lib/tapioca/config.rb +++ b/lib/tapioca/config.rb @@ -8,7 +8,6 @@ class Config < T::Struct const(:outdir, String) const(:prerequire, T.nilable(String)) const(:postrequire, String) - const(:generate_command, String) const(:exclude, T::Array[String]) const(:typed_overrides, T::Hash[String, String]) const(:todos_path, String) diff --git a/lib/tapioca/generator.rb b/lib/tapioca/generator.rb index f5e75e123..0736d1963 100644 --- a/lib/tapioca/generator.rb +++ b/lib/tapioca/generator.rb @@ -63,7 +63,7 @@ def build_requires content = String.new content << rbi_header( - config.generate_command, + "tapioca require", reason: "explicit gem requires", strictness: "false" ) @@ -99,7 +99,7 @@ def build_todos content = String.new content << rbi_header( - config.generate_command, + "tapioca todo", reason: "unresolved constants", strictness: "false" ) @@ -484,7 +484,7 @@ def compile_gem_rbi(gem) rbi_body_content = compiler.compile(gem) content = String.new content << rbi_header( - config.generate_command, + "tapioca sync", reason: "types exported from the `#{gem.name}` gem", strictness: strictness ) @@ -510,14 +510,13 @@ def compile_gem_rbi(gem) def compile_dsl_rbi(constant, contents, outpath: config.outpath) return if contents.nil? - command = format(config.generate_command, constant.name) constant_name = Module.instance_method(:name).bind(constant).call rbi_name = constant_name.underscore + ".rbi" filename = outpath / rbi_name out = String.new out << rbi_header( - command, + "tapioca dsl", reason: "dynamic methods in `#{constant.name}`" ) out << contents @@ -555,7 +554,7 @@ def verify_dsl_rbi(tmp_dir:) sig { params(dir: String).void } def perform_dsl_verification(dir) if (error = verify_dsl_rbi(tmp_dir: Pathname.new(dir))) - say("RBI files are out-of-date, please run `#{config.generate_command}` to update.") + say("RBI files are out-of-date, please run `tapioca dsl` to update.") say("Reason: ", [:red]) say(error) exit(1) diff --git a/spec/tapioca/cli_spec.rb b/spec/tapioca/cli_spec.rb index a8e6d22f6..0f9f3755e 100644 --- a/spec/tapioca/cli_spec.rb +++ b/spec/tapioca/cli_spec.rb @@ -9,7 +9,7 @@ module Contents FOO_RBI = <<~CONTENTS # DO NOT EDIT MANUALLY # This is an autogenerated file for types exported from the `foo` gem. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca sync`. # typed: true @@ -25,7 +25,7 @@ def bar(a = T.unsafe(nil), b: T.unsafe(nil), **opts); end BAR_RBI = <<~CONTENTS # DO NOT EDIT MANUALLY # This is an autogenerated file for types exported from the `bar` gem. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca sync`. # typed: true @@ -41,7 +41,7 @@ def bar(a = T.unsafe(nil), b: T.unsafe(nil), **opts); end BAZ_RBI = <<~CONTENTS # DO NOT EDIT MANUALLY # This is an autogenerated file for types exported from the `baz` gem. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca sync`. # typed: true @@ -68,7 +68,6 @@ class Tapioca::CliSpec < Minitest::HooksSpec def execute(command, args = [], flags = {}) flags = { outdir: outdir, - generate_command: "'generate command'", }.merge(flags).flat_map { |k, v| ["--#{k}", v.to_s] } exec_command = [ @@ -204,7 +203,7 @@ def foo assert_equal(<<~CONTENTS, File.read(repo_path / "sorbet/rbi/todo.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for unresolved constants. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca todo`. # typed: false @@ -220,7 +219,7 @@ module Foo::Undef2; end File.write(repo_path / "sorbet/rbi/todo.rbi", <<-RBI) # DO NOT EDIT MANUALLY # This is an autogenerated file for unresolved constants. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca todo`. # typed: false @@ -281,7 +280,7 @@ module Foo::Undef2; end assert_equal(<<~CONTENTS, File.read(repo_path / "sorbet/tapioca/require.rb")) # DO NOT EDIT MANUALLY # This is an autogenerated file for explicit gem requires. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca require`. # typed: false @@ -312,7 +311,7 @@ module Foo::Undef2; end assert_equal(<<~CONTENTS, File.read(repo_path / "sorbet/tapioca/require.rb")) # DO NOT EDIT MANUALLY # This is an autogenerated file for explicit gem requires. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca require`. # typed: false @@ -363,7 +362,7 @@ module Foo::Undef2; end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/post.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Post`. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca dsl`. # typed: true class Post @@ -448,7 +447,7 @@ def title=(title); end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/baz/role.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Baz::Role`. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca dsl`. # typed: true module Baz @@ -465,7 +464,7 @@ def title=(title); end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/post.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Post`. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca dsl`. # typed: true class Post @@ -480,7 +479,7 @@ def title=(title); end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/namespace/comment.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Namespace::Comment`. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca dsl`. # typed: true module Namespace @@ -612,7 +611,7 @@ class Image output = execute("dsl", "--verify") assert_includes(output, <<~OUTPUT) - RBI files are out-of-date, please run `generate command` to update. + RBI files are out-of-date, please run `tapioca dsl` to update. Reason: New file(s) introduced. OUTPUT assert_includes($?.to_s, "exit 1") # rubocop:disable Style/SpecialGlobalVars @@ -653,7 +652,7 @@ class Image output = execute("dsl", "--verify") assert_includes(output, <<~OUTPUT) - RBI files are out-of-date, please run `generate command` to update. + RBI files are out-of-date, please run `tapioca dsl` to update. Reason: File(s) updated: - sorbet/rbi/dsl/image.rbi OUTPUT @@ -879,7 +878,7 @@ class Foo::Secret assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/qux@0.5.0.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for types exported from the `qux` gem. - # Please instead update this file by running `generate command`. + # Please instead update this file by running `tapioca sync`. # typed: true From 2278e659d34c1faa5637c3e4199c7299a3649a86 Mon Sep 17 00:00:00 2001 From: Cory Hutchison Date: Tue, 16 Mar 2021 09:52:36 -0600 Subject: [PATCH 02/10] Re-add -c flag with deprecation --- lib/tapioca/cli.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tapioca/cli.rb b/lib/tapioca/cli.rb index e90110946..cfaeb3dd4 100644 --- a/lib/tapioca/cli.rb +++ b/lib/tapioca/cli.rb @@ -19,6 +19,10 @@ class Cli < Thor aliases: ["--out", "-o"], banner: "directory", desc: "The output directory for generated RBI files" + class_option :generate_command, + aliases: ["--cmd", "-c"], + banner: "command", + desc: "[DEPRECATED] The command to run to regenerate RBI files" class_option :exclude, aliases: ["-x"], type: :array, From eac26ac7506bad48bf63bd6838af40598bb49a26 Mon Sep 17 00:00:00 2001 From: Cory Hutchison Date: Tue, 16 Mar 2021 09:53:04 -0600 Subject: [PATCH 03/10] Add constant_name to RBI header --- lib/tapioca/generator.rb | 2 +- spec/tapioca/cli_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/tapioca/generator.rb b/lib/tapioca/generator.rb index 0736d1963..8d8e0acd1 100644 --- a/lib/tapioca/generator.rb +++ b/lib/tapioca/generator.rb @@ -516,7 +516,7 @@ def compile_dsl_rbi(constant, contents, outpath: config.outpath) out = String.new out << rbi_header( - "tapioca dsl", + "tapioca dsl #{constant_name}", reason: "dynamic methods in `#{constant.name}`" ) out << contents diff --git a/spec/tapioca/cli_spec.rb b/spec/tapioca/cli_spec.rb index 0f9f3755e..a8e4db4ff 100644 --- a/spec/tapioca/cli_spec.rb +++ b/spec/tapioca/cli_spec.rb @@ -362,7 +362,7 @@ module Foo::Undef2; end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/post.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Post`. - # Please instead update this file by running `tapioca dsl`. + # Please instead update this file by running `tapioca dsl Post`. # typed: true class Post @@ -447,7 +447,7 @@ def title=(title); end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/baz/role.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Baz::Role`. - # Please instead update this file by running `tapioca dsl`. + # Please instead update this file by running `tapioca dsl Baz::Role`. # typed: true module Baz @@ -464,7 +464,7 @@ def title=(title); end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/post.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Post`. - # Please instead update this file by running `tapioca dsl`. + # Please instead update this file by running `tapioca dsl Post`. # typed: true class Post @@ -479,7 +479,7 @@ def title=(title); end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/namespace/comment.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Namespace::Comment`. - # Please instead update this file by running `tapioca dsl`. + # Please instead update this file by running `tapioca dsl Namespace::Comment`. # typed: true module Namespace From c0eb1f1fac9e2882c660192bde7476ccf9c74111 Mon Sep 17 00:00:00 2001 From: Cory Hutchison Date: Tue, 16 Mar 2021 10:49:18 -0600 Subject: [PATCH 04/10] Add tapioca binstub --- lib/tapioca/cli.rb | 45 +++++++++++++++++++++++++++------------- spec/tapioca/cli_spec.rb | 2 ++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/tapioca/cli.rb b/lib/tapioca/cli.rb index cfaeb3dd4..cd059e550 100644 --- a/lib/tapioca/cli.rb +++ b/lib/tapioca/cli.rb @@ -38,20 +38,9 @@ class Cli < Thor desc "init", "initializes folder structure" def init - create_file(Config::SORBET_CONFIG, skip: true) do - <<~CONTENT - --dir - . - CONTENT - end - create_file(Config::DEFAULT_POSTREQUIRE, skip: true) do - <<~CONTENT - # typed: false - # frozen_string_literal: true - - # Add your extra requires here - CONTENT - end + create_config + create_post_require + generate_binstub end desc "require", "generate the list of files to be required by tapioca" @@ -103,6 +92,34 @@ def __print_version puts "Tapioca v#{Tapioca::VERSION}" end + private + + def create_config + create_file(Config::SORBET_CONFIG, skip: true) do + <<~CONTENT + --dir + . + CONTENT + end + end + + def create_post_require + create_file(Config::DEFAULT_POSTREQUIRE, skip: true) do + <<~CONTENT + # typed: false + # frozen_string_literal: true + + # Add your extra requires here + CONTENT + end + end + + def generate_binstub + installer = Bundler::Installer.new(Bundler.root, Bundler.definition) + spec = Bundler.definition.specs.find { |s| s.name == "tapioca" } + installer.generate_bundler_executable_stubs(spec, { force: true }) + end + no_commands do def self.exit_on_failure? true diff --git a/spec/tapioca/cli_spec.rb b/spec/tapioca/cli_spec.rb index a8e4db4ff..ace6ae5f8 100644 --- a/spec/tapioca/cli_spec.rb +++ b/spec/tapioca/cli_spec.rb @@ -141,6 +141,8 @@ def execute(command, args = [], flags = {}) # Add your extra requires here CONTENTS + + assert_path_exists(repo_path / "bin/tapioca") end it 'must not overwrite files' do From a2fcc02febe6266be4b986f02f26fc13acbea12f Mon Sep 17 00:00:00 2001 From: Cory Hutchison Date: Tue, 16 Mar 2021 14:32:34 -0600 Subject: [PATCH 05/10] Resolve tapioca => bin/tapioca tests --- lib/tapioca/config.rb | 1 + lib/tapioca/config_builder.rb | 11 +---------- lib/tapioca/generator.rb | 16 ++++++++-------- spec/support/repo/bin/tapioca | 2 +- spec/tapioca/cli_spec.rb | 34 +++++++++++++++++----------------- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/lib/tapioca/config.rb b/lib/tapioca/config.rb index 65e143c9c..a842007aa 100644 --- a/lib/tapioca/config.rb +++ b/lib/tapioca/config.rb @@ -26,6 +26,7 @@ def outpath TAPIOCA_PATH = T.let("#{SORBET_PATH}/tapioca", String) TAPIOCA_CONFIG = T.let("#{TAPIOCA_PATH}/config.yml", String) + DEFAULT_COMMAND = T.let("bin/tapioca", String) DEFAULT_POSTREQUIRE = T.let("#{TAPIOCA_PATH}/require.rb", String) DEFAULT_RBIDIR = T.let("#{SORBET_PATH}/rbi", String) DEFAULT_DSLDIR = T.let("#{DEFAULT_RBIDIR}/dsl", String) diff --git a/lib/tapioca/config_builder.rb b/lib/tapioca/config_builder.rb index 0d37b78d7..0097d3026 100644 --- a/lib/tapioca/config_builder.rb +++ b/lib/tapioca/config_builder.rb @@ -40,15 +40,6 @@ def default_options(command) DEFAULT_OPTIONS.merge("outdir" => default_outdir) end - sig { returns(String) } - def default_command - command = File.basename($PROGRAM_NAME) - # Hack to avoid flags ending up in the header of the RBIs - args = ARGV.grep_v(/^-/).join(" ") - - "#{command} #{args}".strip - end - sig { params(options: T::Hash[String, T.untyped]).returns(T::Hash[String, T.untyped]) } def merge_options(*options) options.each_with_object({}) do |option, result| @@ -66,7 +57,7 @@ def merge_options(*options) DEFAULT_OPTIONS = T.let({ "postrequire" => Config::DEFAULT_POSTREQUIRE, "outdir" => nil, - "generate_command" => default_command, + "generate_command" => Config::DEFAULT_COMMAND, "exclude" => [], "typed_overrides" => Config::DEFAULT_OVERRIDES, "todos_path" => Config::DEFAULT_TODOSPATH, diff --git a/lib/tapioca/generator.rb b/lib/tapioca/generator.rb index 8d8e0acd1..9a1ae7b9f 100644 --- a/lib/tapioca/generator.rb +++ b/lib/tapioca/generator.rb @@ -63,7 +63,7 @@ def build_requires content = String.new content << rbi_header( - "tapioca require", + "#{Config::DEFAULT_COMMAND} require", reason: "explicit gem requires", strictness: "false" ) @@ -76,8 +76,8 @@ def build_requires say("Done", :green) say("All requires from this application have been written to #{name}.", [:green, :bold]) - cmd = set_color("tapioca sync", :yellow, :bold) - say("Please review changes and commit them, then run #{cmd}.", [:green, :bold]) + cmd = set_color("#{Config::DEFAULT_COMMAND} sync", :yellow, :bold) + say("Please review changes and commit them, then run `#{cmd}`.", [:green, :bold]) end sig { void } @@ -99,7 +99,7 @@ def build_todos content = String.new content << rbi_header( - "tapioca todo", + "#{Config::DEFAULT_COMMAND} todo", reason: "unresolved constants", strictness: "false" ) @@ -225,7 +225,7 @@ def explain_failed_require(file, error) say_error("If you populated ", :yellow) say_error("#{file} ", :bold, :blue) say_error("with ", :yellow) - say_error("tapioca require", :bold, :blue) + say_error("`#{Config::DEFAULT_COMMAND} require`", :bold, :blue) say_error("you should probably review it and remove the faulty line.", :yellow) end @@ -484,7 +484,7 @@ def compile_gem_rbi(gem) rbi_body_content = compiler.compile(gem) content = String.new content << rbi_header( - "tapioca sync", + "#{Config::DEFAULT_COMMAND} sync", reason: "types exported from the `#{gem.name}` gem", strictness: strictness ) @@ -516,7 +516,7 @@ def compile_dsl_rbi(constant, contents, outpath: config.outpath) out = String.new out << rbi_header( - "tapioca dsl #{constant_name}", + "#{Config::DEFAULT_COMMAND} dsl #{constant_name}", reason: "dynamic methods in `#{constant.name}`" ) out << contents @@ -554,7 +554,7 @@ def verify_dsl_rbi(tmp_dir:) sig { params(dir: String).void } def perform_dsl_verification(dir) if (error = verify_dsl_rbi(tmp_dir: Pathname.new(dir))) - say("RBI files are out-of-date, please run `tapioca dsl` to update.") + say("RBI files are out-of-date, please run `#{Config::DEFAULT_COMMAND} dsl` to update.") say("Reason: ", [:red]) say(error) exit(1) diff --git a/spec/support/repo/bin/tapioca b/spec/support/repo/bin/tapioca index e13303f95..32290dee5 100755 --- a/spec/support/repo/bin/tapioca +++ b/spec/support/repo/bin/tapioca @@ -26,4 +26,4 @@ end require "rubygems" require "bundler/setup" -load(Gem.bin_path("tapioca", "tapioca")) +load Gem.bin_path("tapioca", "tapioca") diff --git a/spec/tapioca/cli_spec.rb b/spec/tapioca/cli_spec.rb index ace6ae5f8..8ab696a7c 100644 --- a/spec/tapioca/cli_spec.rb +++ b/spec/tapioca/cli_spec.rb @@ -9,7 +9,7 @@ module Contents FOO_RBI = <<~CONTENTS # DO NOT EDIT MANUALLY # This is an autogenerated file for types exported from the `foo` gem. - # Please instead update this file by running `tapioca sync`. + # Please instead update this file by running `bin/tapioca sync`. # typed: true @@ -25,7 +25,7 @@ def bar(a = T.unsafe(nil), b: T.unsafe(nil), **opts); end BAR_RBI = <<~CONTENTS # DO NOT EDIT MANUALLY # This is an autogenerated file for types exported from the `bar` gem. - # Please instead update this file by running `tapioca sync`. + # Please instead update this file by running `bin/tapioca sync`. # typed: true @@ -41,7 +41,7 @@ def bar(a = T.unsafe(nil), b: T.unsafe(nil), **opts); end BAZ_RBI = <<~CONTENTS # DO NOT EDIT MANUALLY # This is an autogenerated file for types exported from the `baz` gem. - # Please instead update this file by running `tapioca sync`. + # Please instead update this file by running `bin/tapioca sync`. # typed: true @@ -205,7 +205,7 @@ def foo assert_equal(<<~CONTENTS, File.read(repo_path / "sorbet/rbi/todo.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for unresolved constants. - # Please instead update this file by running `tapioca todo`. + # Please instead update this file by running `bin/tapioca todo`. # typed: false @@ -221,7 +221,7 @@ module Foo::Undef2; end File.write(repo_path / "sorbet/rbi/todo.rbi", <<-RBI) # DO NOT EDIT MANUALLY # This is an autogenerated file for unresolved constants. - # Please instead update this file by running `tapioca todo`. + # Please instead update this file by running `bin/tapioca todo`. # typed: false @@ -275,14 +275,14 @@ module Foo::Undef2; end assert_equal(<<~OUTPUT, output) Compiling sorbet/tapioca/require.rb, this may take a few seconds... Done All requires from this application have been written to sorbet/tapioca/require.rb. - Please review changes and commit them, then run tapioca sync. + Please review changes and commit them, then run `bin/tapioca sync`. OUTPUT assert_path_exists(repo_path / "sorbet/tapioca/require.rb") assert_equal(<<~CONTENTS, File.read(repo_path / "sorbet/tapioca/require.rb")) # DO NOT EDIT MANUALLY # This is an autogenerated file for explicit gem requires. - # Please instead update this file by running `tapioca require`. + # Please instead update this file by running `bin/tapioca require`. # typed: false @@ -306,14 +306,14 @@ module Foo::Undef2; end assert_equal(<<~OUTPUT, output) Compiling sorbet/tapioca/require.rb, this may take a few seconds... Done All requires from this application have been written to sorbet/tapioca/require.rb. - Please review changes and commit them, then run tapioca sync. + Please review changes and commit them, then run `bin/tapioca sync`. OUTPUT assert_path_exists(repo_path / "sorbet/tapioca/require.rb") assert_equal(<<~CONTENTS, File.read(repo_path / "sorbet/tapioca/require.rb")) # DO NOT EDIT MANUALLY # This is an autogenerated file for explicit gem requires. - # Please instead update this file by running `tapioca require`. + # Please instead update this file by running `bin/tapioca require`. # typed: false @@ -364,7 +364,7 @@ module Foo::Undef2; end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/post.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Post`. - # Please instead update this file by running `tapioca dsl Post`. + # Please instead update this file by running `bin/tapioca dsl Post`. # typed: true class Post @@ -449,7 +449,7 @@ def title=(title); end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/baz/role.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Baz::Role`. - # Please instead update this file by running `tapioca dsl Baz::Role`. + # Please instead update this file by running `bin/tapioca dsl Baz::Role`. # typed: true module Baz @@ -466,7 +466,7 @@ def title=(title); end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/post.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Post`. - # Please instead update this file by running `tapioca dsl Post`. + # Please instead update this file by running `bin/tapioca dsl Post`. # typed: true class Post @@ -481,7 +481,7 @@ def title=(title); end assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/namespace/comment.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for dynamic methods in `Namespace::Comment`. - # Please instead update this file by running `tapioca dsl Namespace::Comment`. + # Please instead update this file by running `bin/tapioca dsl Namespace::Comment`. # typed: true module Namespace @@ -613,7 +613,7 @@ class Image output = execute("dsl", "--verify") assert_includes(output, <<~OUTPUT) - RBI files are out-of-date, please run `tapioca dsl` to update. + RBI files are out-of-date, please run `bin/tapioca dsl` to update. Reason: New file(s) introduced. OUTPUT assert_includes($?.to_s, "exit 1") # rubocop:disable Style/SpecialGlobalVars @@ -654,7 +654,7 @@ class Image output = execute("dsl", "--verify") assert_includes(output, <<~OUTPUT) - RBI files are out-of-date, please run `tapioca dsl` to update. + RBI files are out-of-date, please run `bin/tapioca dsl` to update. Reason: File(s) updated: - sorbet/rbi/dsl/image.rbi OUTPUT @@ -718,7 +718,7 @@ class Foo::Secret LoadError: cannot load such file -- foo/will_fail Tapioca could not load all the gems required by your application. - If you populated /postrequire_faulty.rb with tapioca require + If you populated /postrequire_faulty.rb with `bin/tapioca require` you should probably review it and remove the faulty line. OUTPUT end @@ -880,7 +880,7 @@ class Foo::Secret assert_equal(<<~CONTENTS.chomp, File.read("#{outdir}/qux@0.5.0.rbi")) # DO NOT EDIT MANUALLY # This is an autogenerated file for types exported from the `qux` gem. - # Please instead update this file by running `tapioca sync`. + # Please instead update this file by running `bin/tapioca sync`. # typed: true From 8b4e9570f5392f0586ee23d54c28dab8a2aebab6 Mon Sep 17 00:00:00 2001 From: Cory Hutchison Date: Tue, 16 Mar 2021 14:49:40 -0600 Subject: [PATCH 06/10] Add deprecation to option builder and add tests --- lib/tapioca/cli.rb | 2 +- lib/tapioca/config_builder.rb | 3 +++ spec/tapioca/cli_spec.rb | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/tapioca/cli.rb b/lib/tapioca/cli.rb index cd059e550..dc340d5d9 100644 --- a/lib/tapioca/cli.rb +++ b/lib/tapioca/cli.rb @@ -22,7 +22,7 @@ class Cli < Thor class_option :generate_command, aliases: ["--cmd", "-c"], banner: "command", - desc: "[DEPRECATED] The command to run to regenerate RBI files" + desc: "The command to run to regenerate RBI files" class_option :exclude, aliases: ["-x"], type: :array, diff --git a/lib/tapioca/config_builder.rb b/lib/tapioca/config_builder.rb index 0097d3026..82630d092 100644 --- a/lib/tapioca/config_builder.rb +++ b/lib/tapioca/config_builder.rb @@ -10,6 +10,9 @@ class << self sig { params(command: Symbol, options: T::Hash[String, T.untyped]).returns(Config) } def from_options(command, options) + puts(<<~MSG) if options.include?("generate_command") + DEPRECATION: The `-c` and `--cmd` flags will be removed in a future release. + MSG Config.from_hash( merge_options(default_options(command), config_options, options) ) diff --git a/spec/tapioca/cli_spec.rb b/spec/tapioca/cli_spec.rb index 8ab696a7c..9c56243e3 100644 --- a/spec/tapioca/cli_spec.rb +++ b/spec/tapioca/cli_spec.rb @@ -995,4 +995,21 @@ class Foo::Secret refute_path_exists("#{outdir}/baz@0.0.1.rbi") end end + + describe("deprecations") do + it "prints the correct deprecation message with -c" do + output = execute("dsl", ["-c", "foo"]) + assert_includes(output, "DEPRECATION: The `-c` and `--cmd` flags will be removed in a future release.") + end + + it "prints the correct deprecation message with --cmd" do + output = execute("dsl", ["--cmd", "foo"]) + assert_includes(output, "DEPRECATION: The `-c` and `--cmd` flags will be removed in a future release.") + end + + it "doesn't print the correct deprecation message with no flag" do + output = execute("dsl") + refute_includes(output, "DEPRECATION: The `-c` and `--cmd` flags will be removed in a future release.") + end + end end From 7949eca899cbceb7f551eeefd73a671135566d93 Mon Sep 17 00:00:00 2001 From: Cory Hutchison Date: Tue, 16 Mar 2021 14:50:46 -0600 Subject: [PATCH 07/10] Rubocop fixes --- lib/tapioca/config_builder.rb | 2 +- spec/support/repo/bin/tapioca | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tapioca/config_builder.rb b/lib/tapioca/config_builder.rb index 82630d092..0c31609e7 100644 --- a/lib/tapioca/config_builder.rb +++ b/lib/tapioca/config_builder.rb @@ -11,7 +11,7 @@ class << self sig { params(command: Symbol, options: T::Hash[String, T.untyped]).returns(Config) } def from_options(command, options) puts(<<~MSG) if options.include?("generate_command") - DEPRECATION: The `-c` and `--cmd` flags will be removed in a future release. + DEPRECATION: The `-c` and `--cmd` flags will be removed in a future release. MSG Config.from_hash( merge_options(default_options(command), config_options, options) diff --git a/spec/support/repo/bin/tapioca b/spec/support/repo/bin/tapioca index 32290dee5..e13303f95 100755 --- a/spec/support/repo/bin/tapioca +++ b/spec/support/repo/bin/tapioca @@ -26,4 +26,4 @@ end require "rubygems" require "bundler/setup" -load Gem.bin_path("tapioca", "tapioca") +load(Gem.bin_path("tapioca", "tapioca")) From 249791634f42684f7514d27e92ef7b60eeefb5f6 Mon Sep 17 00:00:00 2001 From: Cory Hutchison Date: Tue, 16 Mar 2021 14:52:10 -0600 Subject: [PATCH 08/10] Add rubocop exclusion for generated file --- .rubocop.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.rubocop.yml b/.rubocop.yml index 96b245937..54185c840 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -30,6 +30,7 @@ Sorbet/TrueSigil: - "**/*.rb" Exclude: - "spec/support/gems/baz/lib/baz.rb" + - "spec/support/repo/bin/tapioca" Sorbet/ConstantsFromStrings: Enabled: false From 2697e7891c9a7e0426febcfa9f5b964e7c759925 Mon Sep 17 00:00:00 2001 From: Cory Hutchison Date: Tue, 16 Mar 2021 15:17:26 -0600 Subject: [PATCH 09/10] Improve option parsing/merging --- .rubocop.yml | 2 +- lib/tapioca/config_builder.rb | 8 ++++---- spec/support/repo/bin/tapioca | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 54185c840..5f6b84634 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,6 +10,7 @@ AllCops: TargetRubyVersion: 2.4 Exclude: - 'vendor/**/*' + - "spec/support/repo/bin/tapioca" Style/CaseEquality: Enabled: false @@ -30,7 +31,6 @@ Sorbet/TrueSigil: - "**/*.rb" Exclude: - "spec/support/gems/baz/lib/baz.rb" - - "spec/support/repo/bin/tapioca" Sorbet/ConstantsFromStrings: Enabled: false diff --git a/lib/tapioca/config_builder.rb b/lib/tapioca/config_builder.rb index 0c31609e7..8b6cb149e 100644 --- a/lib/tapioca/config_builder.rb +++ b/lib/tapioca/config_builder.rb @@ -10,12 +10,13 @@ class << self sig { params(command: Symbol, options: T::Hash[String, T.untyped]).returns(Config) } def from_options(command, options) + merged_options = merge_options(default_options(command), config_options, options) + puts(<<~MSG) if options.include?("generate_command") DEPRECATION: The `-c` and `--cmd` flags will be removed in a future release. MSG - Config.from_hash( - merge_options(default_options(command), config_options, options) - ) + + Config.from_hash(merged_options) end private @@ -60,7 +61,6 @@ def merge_options(*options) DEFAULT_OPTIONS = T.let({ "postrequire" => Config::DEFAULT_POSTREQUIRE, "outdir" => nil, - "generate_command" => Config::DEFAULT_COMMAND, "exclude" => [], "typed_overrides" => Config::DEFAULT_OVERRIDES, "todos_path" => Config::DEFAULT_TODOSPATH, diff --git a/spec/support/repo/bin/tapioca b/spec/support/repo/bin/tapioca index e13303f95..32290dee5 100755 --- a/spec/support/repo/bin/tapioca +++ b/spec/support/repo/bin/tapioca @@ -26,4 +26,4 @@ end require "rubygems" require "bundler/setup" -load(Gem.bin_path("tapioca", "tapioca")) +load Gem.bin_path("tapioca", "tapioca") From 23a7968328edc5cd7536df278189184847985b79 Mon Sep 17 00:00:00 2001 From: Cory Hutchison Date: Wed, 17 Mar 2021 08:50:26 -0600 Subject: [PATCH 10/10] Fix check for deprecation --- lib/tapioca/config_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tapioca/config_builder.rb b/lib/tapioca/config_builder.rb index 8b6cb149e..471b7e513 100644 --- a/lib/tapioca/config_builder.rb +++ b/lib/tapioca/config_builder.rb @@ -12,7 +12,7 @@ class << self def from_options(command, options) merged_options = merge_options(default_options(command), config_options, options) - puts(<<~MSG) if options.include?("generate_command") + puts(<<~MSG) if merged_options.include?("generate_command") DEPRECATION: The `-c` and `--cmd` flags will be removed in a future release. MSG