js-routes 2.2.8 → 2.2.10

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -9
  3. data/Readme.md +60 -45
  4. data/lib/js_routes/configuration.rb +80 -34
  5. data/lib/js_routes/engine.rb +2 -0
  6. data/lib/js_routes/generators/base.rb +19 -0
  7. data/lib/js_routes/generators/middleware.rb +6 -8
  8. data/lib/js_routes/generators/webpacker.rb +1 -3
  9. data/lib/js_routes/instance.rb +50 -15
  10. data/lib/js_routes/middleware.rb +16 -3
  11. data/lib/js_routes/route.rb +60 -17
  12. data/lib/js_routes/types.rb +38 -0
  13. data/lib/js_routes/version.rb +2 -1
  14. data/lib/js_routes.rb +25 -7
  15. metadata +28 -45
  16. data/.document +0 -5
  17. data/.eslintrc.js +0 -15
  18. data/.github/workflows/ci.yml +0 -36
  19. data/.gitignore +0 -65
  20. data/.nvmrc +0 -1
  21. data/.rspec +0 -1
  22. data/Appraisals +0 -17
  23. data/Gemfile +0 -4
  24. data/Rakefile +0 -37
  25. data/VERSION_2_UPGRADE.md +0 -66
  26. data/gemfiles/rails50_sprockets_3.gemfile +0 -8
  27. data/gemfiles/rails51_sprockets_3.gemfile +0 -8
  28. data/gemfiles/rails52_sprockets_3.gemfile +0 -8
  29. data/gemfiles/rails70_sprockets_4.gemfile +0 -8
  30. data/js-routes.gemspec +0 -39
  31. data/package.json +0 -38
  32. data/spec/dummy/app/assets/config/manifest.js +0 -2
  33. data/spec/dummy/app/assets/javascripts/.gitkeep +0 -0
  34. data/spec/dummy/config/routes.rb +0 -55
  35. data/spec/js_routes/default_serializer_spec.rb +0 -31
  36. data/spec/js_routes/module_types/amd_spec.rb +0 -35
  37. data/spec/js_routes/module_types/cjs_spec.rb +0 -15
  38. data/spec/js_routes/module_types/dts/routes.spec.d.ts +0 -115
  39. data/spec/js_routes/module_types/dts/test.spec.ts +0 -56
  40. data/spec/js_routes/module_types/dts_spec.rb +0 -111
  41. data/spec/js_routes/module_types/esm_spec.rb +0 -45
  42. data/spec/js_routes/module_types/nil_spec.rb +0 -87
  43. data/spec/js_routes/module_types/umd_spec.rb +0 -85
  44. data/spec/js_routes/options_spec.rb +0 -508
  45. data/spec/js_routes/rails_routes_compatibility_spec.rb +0 -473
  46. data/spec/js_routes/route_specification_spec.rb +0 -37
  47. data/spec/js_routes/zzz_sprockets_spec.rb +0 -152
  48. data/spec/spec_helper.rb +0 -135
  49. data/spec/support/routes.rb +0 -81
  50. data/spec/tsconfig.json +0 -4
  51. data/tsconfig.json +0 -28
  52. data/yarn.lock +0 -2457
@@ -1,26 +1,36 @@
1
+ # typed: strict
1
2
  require "js_routes/configuration"
2
3
  require "js_routes/route"
4
+ require "js_routes/types"
5
+ require 'fileutils'
3
6
 
4
7
  module JsRoutes
5
8
  class Instance # :nodoc:
9
+ include JsRoutes::Types
10
+ extend T::Sig
6
11
 
12
+ sig { returns(JsRoutes::Configuration) }
7
13
  attr_reader :configuration
8
14
  #
9
15
  # Implementation
10
16
  #
11
17
 
12
- def initialize(options = {})
13
- @configuration = JsRoutes.configuration.merge(options)
18
+ sig { params(options: T.untyped).void }
19
+ def initialize(**options)
20
+ options = T.let(options, Options)
21
+ @configuration = T.let(JsRoutes.configuration.merge(options), JsRoutes::Configuration)
14
22
  end
15
23
 
24
+ sig {returns(String)}
16
25
  def generate
17
26
  # Ensure routes are loaded. If they're not, load them.
18
- if named_routes.empty? && application.respond_to?(:reload_routes!)
27
+ application = T.unsafe(self.application)
28
+ if named_routes.empty? && application.respond_to?(:reload_routes!, true)
19
29
  application.reload_routes!
20
30
  end
21
31
  content = File.read(@configuration.source_file)
22
32
 
23
- if !@configuration.dts?
33
+ unless @configuration.dts?
24
34
  content = js_variables.inject(content) do |js, (key, value)|
25
35
  js.gsub!("RubyVariables.#{key}", value.to_s) ||
26
36
  raise("Missing key #{key} in JS template")
@@ -29,11 +39,12 @@ module JsRoutes
29
39
  content + routes_export + prevent_types_export
30
40
  end
31
41
 
42
+ sig { void }
32
43
  def generate!
33
44
  # Some libraries like Devise did not load their routes yet
34
45
  # so we will wait until initialization process finishes
35
46
  # https://github.com/railsware/js-routes/issues/7
36
- Rails.configuration.after_initialize do
47
+ T.unsafe(Rails).configuration.after_initialize do
37
48
  file_path = Rails.root.join(@configuration.output_file)
38
49
  source_code = generate
39
50
 
@@ -47,18 +58,29 @@ module JsRoutes
47
58
  end
48
59
  end
49
60
 
61
+ sig { void }
62
+ def remove!
63
+ path = Rails.root.join(@configuration.output_file)
64
+ FileUtils.rm_rf(path)
65
+ FileUtils.rm_rf(path.sub(%r{\.js\z}, '.d.ts'))
66
+ end
67
+
50
68
  protected
51
69
 
70
+ sig { returns(T::Hash[String, String]) }
52
71
  def js_variables
72
+ version = Rails.version
73
+ prefix = @configuration.prefix
74
+ prefix = prefix.call if prefix.is_a?(Proc)
53
75
  {
54
76
  'GEM_VERSION' => JsRoutes::VERSION,
55
77
  'ROUTES_OBJECT' => routes_object,
56
- 'RAILS_VERSION' => ActionPack.version,
57
- 'DEPRECATED_GLOBBING_BEHAVIOR' => ActionPack::VERSION::MAJOR == 4 && ActionPack::VERSION::MINOR == 0,
58
- 'DEPRECATED_FALSE_PARAMETER_BEHAVIOR' => ActionPack::VERSION::MAJOR < 7,
78
+ 'RAILS_VERSION' => ::Rails.version,
79
+ 'DEPRECATED_GLOBBING_BEHAVIOR' => version >= '4.0.0' && version < '4.1.0',
80
+ 'DEPRECATED_FALSE_PARAMETER_BEHAVIOR' => version < '7.0.0',
59
81
  'APP_CLASS' => application.class.to_s,
60
82
  'DEFAULT_URL_OPTIONS' => json(@configuration.default_url_options),
61
- 'PREFIX' => json(@configuration.prefix),
83
+ 'PREFIX' => json(prefix),
62
84
  'SPECIAL_OPTIONS_KEY' => json(@configuration.special_options_key),
63
85
  'SERIALIZER' => @configuration.serializer || json(nil),
64
86
  'MODULE_TYPE' => json(@configuration.module_type),
@@ -66,6 +88,7 @@ module JsRoutes
66
88
  }
67
89
  end
68
90
 
91
+ sig { returns(String) }
69
92
  def wrapper_variable
70
93
  case @configuration.module_type
71
94
  when 'ESM'
@@ -86,18 +109,22 @@ module JsRoutes
86
109
  end
87
110
  end
88
111
 
112
+ sig { returns(Application) }
89
113
  def application
90
- @configuration.application
114
+ @configuration.application.call
91
115
  end
92
116
 
93
- def json(string)
94
- JsRoutes.json(string)
117
+ sig { params(value: T.untyped).returns(String) }
118
+ def json(value)
119
+ JsRoutes.json(value)
95
120
  end
96
121
 
122
+ sig { returns(T::Hash[Symbol, JourneyRoute]) }
97
123
  def named_routes
98
- application.routes.named_routes.to_a
124
+ T.unsafe(application).routes.named_routes.to_h
99
125
  end
100
126
 
127
+ sig { returns(String) }
101
128
  def routes_object
102
129
  return json({}) if @configuration.modern?
103
130
  properties = routes_list.map do |comment, name, body|
@@ -106,10 +133,11 @@ module JsRoutes
106
133
  "{\n" + properties.join(",\n\n") + "}\n"
107
134
  end
108
135
 
136
+ sig { returns(T::Array[StringArray]) }
109
137
  def static_exports
110
138
  [:configure, :config, :serialize].map do |name|
111
139
  [
112
- "", name,
140
+ "", name.to_s,
113
141
  @configuration.dts? ?
114
142
  "RouterExposedMethods['#{name}']" :
115
143
  "__jsr.#{name}"
@@ -117,6 +145,7 @@ module JsRoutes
117
145
  end
118
146
  end
119
147
 
148
+ sig { returns(String) }
120
149
  def routes_export
121
150
  return "" unless @configuration.modern?
122
151
  [*static_exports, *routes_list].map do |comment, name, body|
@@ -124,6 +153,7 @@ module JsRoutes
124
153
  end.join
125
154
  end
126
155
 
156
+ sig { returns(String) }
127
157
  def prevent_types_export
128
158
  return "" unless @configuration.dts?
129
159
  <<-JS
@@ -133,18 +163,21 @@ export {};
133
163
  JS
134
164
  end
135
165
 
166
+ sig { returns(String) }
136
167
  def export_separator
137
168
  @configuration.dts? ? ': ' : ' = '
138
169
  end
139
170
 
171
+ sig { returns(T::Array[StringArray]) }
140
172
  def routes_list
141
173
  named_routes.sort_by(&:first).flat_map do |_, route|
142
174
  route_helpers_if_match(route) + mounted_app_routes(route)
143
175
  end
144
176
  end
145
177
 
178
+ sig { params(route: JourneyRoute).returns(T::Array[StringArray]) }
146
179
  def mounted_app_routes(route)
147
- rails_engine_app = app_from_route(route)
180
+ rails_engine_app = T.unsafe(app_from_route(route))
148
181
  if rails_engine_app.respond_to?(:superclass) &&
149
182
  rails_engine_app.superclass == Rails::Engine && !route.path.anchored
150
183
  rails_engine_app.routes.named_routes.flat_map do |_, engine_route|
@@ -155,6 +188,7 @@ export {};
155
188
  end
156
189
  end
157
190
 
191
+ sig { params(route: JourneyRoute).returns(T.untyped) }
158
192
  def app_from_route(route)
159
193
  app = route.app
160
194
  # rails engine in Rails 4.2 use additional
@@ -166,6 +200,7 @@ export {};
166
200
  end
167
201
  end
168
202
 
203
+ sig { params(route: JourneyRoute, parent_route: T.nilable(JourneyRoute)).returns(T::Array[StringArray]) }
169
204
  def route_helpers_if_match(route, parent_route = nil)
170
205
  Route.new(@configuration, route, parent_route).helpers
171
206
  end
@@ -1,3 +1,6 @@
1
+ # typed: strict
2
+ require "js_routes/types"
3
+
1
4
  module JsRoutes
2
5
  # A Rack middleware that automatically updates routes file
3
6
  # whenever routes.rb is modified
@@ -5,12 +8,19 @@ module JsRoutes
5
8
  # Inspired by
6
9
  # https://github.com/fnando/i18n-js/blob/main/lib/i18n/js/middleware.rb
7
10
  class Middleware
11
+ include JsRoutes::Types
12
+ include RackApp
13
+
14
+ extend T::Sig
15
+
16
+ sig { params(app: T.untyped).void }
8
17
  def initialize(app)
9
18
  @app = app
10
- @routes_file = Rails.root.join("config/routes.rb")
11
- @mtime = nil
19
+ @routes_file = T.let(Rails.root.join("config/routes.rb"), Pathname)
20
+ @mtime = T.let(nil, T.nilable(Time))
12
21
  end
13
22
 
23
+ sig { override.params(env: StringHash).returns(UntypedArray) }
14
24
  def call(env)
15
25
  update_js_routes
16
26
  @app.call(env)
@@ -18,6 +28,7 @@ module JsRoutes
18
28
 
19
29
  protected
20
30
 
31
+ sig { void }
21
32
  def update_js_routes
22
33
  new_mtime = routes_mtime
23
34
  unless new_mtime == @mtime
@@ -26,11 +37,13 @@ module JsRoutes
26
37
  end
27
38
  end
28
39
 
40
+ sig { void }
29
41
  def regenerate
30
42
  JsRoutes.generate!
31
- JsRoutes.definitions!
43
+ JsRoutes.definitions! if JsRoutes.configuration.modern?
32
44
  end
33
45
 
46
+ sig { returns(T.nilable(Time)) }
34
47
  def routes_mtime
35
48
  File.mtime(@routes_file)
36
49
  rescue Errno::ENOENT
@@ -1,8 +1,16 @@
1
+ # typed: strict
2
+
3
+ require "js_routes/types"
4
+ require "action_dispatch/journey/route"
5
+
1
6
  module JsRoutes
2
7
  class Route #:nodoc:
3
- FILTERED_DEFAULT_PARTS = [:controller, :action]
4
- URL_OPTIONS = [:protocol, :domain, :host, :port, :subdomain]
5
- NODE_TYPES = {
8
+ include JsRoutes::Types
9
+ extend T::Sig
10
+
11
+ FILTERED_DEFAULT_PARTS = T.let([:controller, :action].freeze, SymbolArray)
12
+ URL_OPTIONS = T.let([:protocol, :domain, :host, :port, :subdomain].freeze, SymbolArray)
13
+ NODE_TYPES = T.let({
6
14
  GROUP: 1,
7
15
  CAT: 2,
8
16
  SYMBOL: 3,
@@ -11,84 +19,110 @@ module JsRoutes
11
19
  LITERAL: 6,
12
20
  SLASH: 7,
13
21
  DOT: 8
14
- }
22
+ }.freeze, T::Hash[Symbol, Integer])
15
23
 
16
- attr_reader :configuration, :route, :parent_route
24
+ sig {returns(JsRoutes::Configuration)}
25
+ attr_reader :configuration
17
26
 
27
+ sig {returns(JourneyRoute)}
28
+ attr_reader :route
29
+
30
+ sig {returns(T.nilable(JourneyRoute))}
31
+ attr_reader :parent_route
32
+
33
+ sig { params(configuration: JsRoutes::Configuration, route: JourneyRoute, parent_route: T.nilable(JourneyRoute)).void }
18
34
  def initialize(configuration, route, parent_route = nil)
19
35
  @configuration = configuration
20
36
  @route = route
21
37
  @parent_route = parent_route
22
38
  end
23
39
 
40
+ sig { returns(T::Array[StringArray]) }
24
41
  def helpers
25
42
  helper_types.map do |absolute|
26
43
  [ documentation, helper_name(absolute), body(absolute) ]
27
44
  end
28
45
  end
29
46
 
47
+ sig {returns(T::Array[T::Boolean])}
30
48
  def helper_types
31
49
  return [] unless match_configuration?
32
- @configuration[:url_links] ? [true, false] : [false]
50
+ @configuration.url_links ? [true, false] : [false]
33
51
  end
34
52
 
53
+ sig { params(absolute: T::Boolean).returns(String) }
35
54
  def body(absolute)
36
55
  if @configuration.dts?
37
56
  definition_body
38
57
  else
39
58
  # For tree-shaking ESM, add a #__PURE__ comment informing Webpack/minifiers that the call to `__jsr.r`
40
59
  # has no side-effects (e.g. modifying global variables) and is safe to remove when unused.
41
- # https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects
60
+ # https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sidyeeffects
42
61
  pure_comment = @configuration.esm? ? '/*#__PURE__*/ ' : ''
43
62
  "#{pure_comment}__jsr.r(#{arguments(absolute).map{|a| json(a)}.join(', ')})"
44
63
  end
45
64
  end
46
65
 
66
+ sig { returns(String) }
47
67
  def definition_body
68
+ options_type = optional_parts_type ? "#{optional_parts_type} & RouteOptions" : "RouteOptions"
48
69
  args = required_parts.map{|p| "#{apply_case(p)}: RequiredRouteParameter"}
49
- args << "options?: #{optional_parts_type} & RouteOptions"
70
+ args << "options?: #{options_type}"
50
71
  "((\n#{args.join(",\n").indent(2)}\n) => string) & RouteHelperExtras"
51
72
  end
52
73
 
74
+ sig { returns(T.nilable(String)) }
53
75
  def optional_parts_type
54
- @optional_parts_type ||=
55
- "{" + optional_parts.map {|p| "#{p}?: OptionalRouteParameter"}.join(', ') + "}"
76
+ return nil if optional_parts.empty?
77
+ @optional_parts_type ||= T.let(
78
+ "{" + optional_parts.map {|p| "#{p}?: OptionalRouteParameter"}.join(', ') + "}",
79
+ T.nilable(String)
80
+ )
56
81
  end
57
82
 
58
83
  protected
59
84
 
85
+
86
+ sig { params(absolute: T::Boolean).returns(UntypedArray) }
60
87
  def arguments(absolute)
61
88
  absolute ? [*base_arguments, true] : base_arguments
62
89
  end
63
90
 
91
+ sig { returns(T::Boolean) }
64
92
  def match_configuration?
65
- !match?(@configuration[:exclude]) && match?(@configuration[:include])
93
+ !match?(@configuration.exclude) && match?(@configuration.include)
66
94
  end
67
95
 
96
+ sig { returns(T.nilable(String)) }
68
97
  def base_name
69
- @base_name ||= parent_route ?
70
- [parent_route.name, route.name].join('_') : route.name
98
+ @base_name ||= T.let(parent_route ?
99
+ [parent_route&.name, route.name].join('_') : route.name, T.nilable(String))
71
100
  end
72
101
 
102
+ sig { returns(T.nilable(RouteSpec)) }
73
103
  def parent_spec
74
104
  parent_route&.path&.spec
75
105
  end
76
106
 
107
+ sig { returns(RouteSpec) }
77
108
  def spec
78
109
  route.path.spec
79
110
  end
80
111
 
112
+ sig { params(value: T.untyped).returns(String) }
81
113
  def json(value)
82
114
  JsRoutes.json(value)
83
115
  end
84
116
 
117
+ sig { params(absolute: T::Boolean).returns(String) }
85
118
  def helper_name(absolute)
86
- suffix = absolute ? :url : @configuration[:compact] ? nil : :path
119
+ suffix = absolute ? :url : @configuration.compact ? nil : :path
87
120
  apply_case(base_name, suffix)
88
121
  end
89
122
 
123
+ sig { returns(String) }
90
124
  def documentation
91
- return nil unless @configuration[:documentation]
125
+ return '' unless @configuration.documentation
92
126
  <<-JS
93
127
  /**
94
128
  * Generates rails route to
@@ -99,18 +133,22 @@ module JsRoutes
99
133
  JS
100
134
  end
101
135
 
136
+ sig { returns(SymbolArray) }
102
137
  def required_parts
103
138
  route.required_parts
104
139
  end
105
140
 
141
+ sig { returns(SymbolArray) }
106
142
  def optional_parts
107
143
  route.path.optional_names
108
144
  end
109
145
 
146
+ sig { returns(UntypedArray) }
110
147
  def base_arguments
111
- @base_arguments ||= [parts_table, serialize(spec, parent_spec)]
148
+ @base_arguments ||= T.let([parts_table, serialize(spec, parent_spec)], T.nilable(UntypedArray))
112
149
  end
113
150
 
151
+ sig { returns(T::Hash[Symbol, Options]) }
114
152
  def parts_table
115
153
  parts_table = {}
116
154
  route.parts.each do |part, hash|
@@ -131,25 +169,29 @@ JS
131
169
  parts_table
132
170
  end
133
171
 
172
+ sig { returns(String) }
134
173
  def documentation_params
135
174
  required_parts.map do |param|
136
175
  "\n * @param {any} #{apply_case(param)}"
137
176
  end.join
138
177
  end
139
178
 
179
+ sig { params(matchers: Clusivity).returns(T::Boolean) }
140
180
  def match?(matchers)
141
181
  Array(matchers).any? { |regex| base_name =~ regex }
142
182
  end
143
183
 
184
+ sig { params(values: T.nilable(Literal)).returns(String) }
144
185
  def apply_case(*values)
145
186
  value = values.compact.map(&:to_s).join('_')
146
- @configuration[:camel_case] ? value.camelize(:lower) : value
187
+ @configuration.camel_case ? value.camelize(:lower) : value
147
188
  end
148
189
 
149
190
  # This function serializes Journey route into JSON structure
150
191
  # We do not use Hash for human readable serialization
151
192
  # And preffer Array serialization because it is shorter.
152
193
  # Routes.js file will be smaller.
194
+ sig { params(spec: SpecNode, parent_spec: T.nilable(RouteSpec)).returns(T.nilable(T.any(UntypedArray, String))) }
153
195
  def serialize(spec, parent_spec=nil)
154
196
  return nil unless spec
155
197
  # Rails 4 globbing requires * removal
@@ -168,6 +210,7 @@ JS
168
210
  result
169
211
  end
170
212
 
213
+ sig { params(spec: RouteSpec, parent_spec: T.nilable(RouteSpec)).returns(UntypedArray) }
171
214
  def serialize_spec(spec, parent_spec = nil)
172
215
  [
173
216
  NODE_TYPES[spec.type],
@@ -0,0 +1,38 @@
1
+ # typed: strict
2
+ require "action_dispatch/journey/route"
3
+ require "pathname"
4
+ require "sorbet-runtime"
5
+
6
+ module JsRoutes
7
+ module Types
8
+ extend T::Sig
9
+
10
+ UntypedArray = T.type_alias {T::Array[T.untyped]}
11
+ StringArray = T.type_alias {T::Array[String]}
12
+ SymbolArray = T.type_alias {T::Array[Symbol]}
13
+ StringHash = T.type_alias { T::Hash[String, T.untyped] }
14
+ Options = T.type_alias { T::Hash[Symbol, T.untyped] }
15
+ SpecNode = T.type_alias { T.any(String, RouteSpec, NilClass) }
16
+ Literal = T.type_alias { T.any(String, Symbol) }
17
+ JourneyRoute = T.type_alias{ActionDispatch::Journey::Route}
18
+ RouteSpec = T.type_alias {T.untyped}
19
+ Application = T.type_alias { T.any(T::Class[Rails::Engine], Rails::Application) }
20
+ ApplicationCaller = T.type_alias { T.proc.returns(Application) }
21
+ Clusivity = T.type_alias { T.any(Regexp, T::Array[Regexp]) }
22
+ FileName = T.type_alias { T.any(String, Pathname, NilClass) }
23
+ ConfigurationBlock = T.type_alias { T.proc.params(arg0: JsRoutes::Configuration).void }
24
+ Prefix = T.type_alias do
25
+ T.any(T.proc.returns(String), String, NilClass)
26
+ end
27
+
28
+ module RackApp
29
+ extend T::Sig
30
+ extend T::Helpers
31
+
32
+ interface!
33
+
34
+ sig { abstract.params(input: StringHash).returns(UntypedArray) }
35
+ def call(input); end
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,4 @@
1
+ # typed: strict
1
2
  module JsRoutes
2
- VERSION = "2.2.8"
3
+ VERSION = "2.2.10"
3
4
  end
data/lib/js_routes.rb CHANGED
@@ -1,45 +1,63 @@
1
+ # typed: strict
1
2
  if defined?(::Rails)
2
3
  require 'js_routes/engine'
3
4
  end
4
5
  require 'js_routes/version'
5
6
  require "js_routes/configuration"
6
7
  require "js_routes/instance"
8
+ require "js_routes/types"
7
9
  require 'active_support/core_ext/string/indent'
8
10
 
9
11
  module JsRoutes
12
+ extend T::Sig
10
13
 
11
14
  #
12
15
  # API
13
16
  #
14
17
 
15
18
  class << self
19
+ include JsRoutes::Types
20
+ extend T::Sig
21
+
22
+ sig { params(block: ConfigurationBlock).void }
16
23
  def setup(&block)
17
- configuration.assign(&block)
24
+ configuration.setup(&block)
18
25
  end
19
26
 
27
+ sig { returns(JsRoutes::Configuration) }
20
28
  def configuration
21
- @configuration ||= Configuration.new
29
+ @configuration ||= T.let(Configuration.new, T.nilable(JsRoutes::Configuration))
22
30
  end
23
31
 
32
+ sig { params(opts: T.untyped).returns(String) }
24
33
  def generate(**opts)
25
- Instance.new(opts).generate
34
+ Instance.new(**opts).generate
26
35
  end
27
36
 
37
+ sig { params(file_name: FileName, opts: T.untyped).void }
28
38
  def generate!(file_name = configuration.file, **opts)
29
39
  Instance.new(file: file_name, **opts).generate!
30
40
  end
31
41
 
42
+ sig { params(file_name: FileName, opts: T.untyped).void }
43
+ def remove!(file_name = configuration.file, **opts)
44
+ Instance.new(file: file_name, **opts).remove!
45
+ end
46
+
47
+ sig { params(opts: T.untyped).returns(String) }
32
48
  def definitions(**opts)
33
- generate(module_type: 'DTS', **opts)
49
+ generate(**opts, module_type: 'DTS',)
34
50
  end
35
51
 
52
+ sig { params(file_name: FileName, opts: T.untyped).void }
36
53
  def definitions!(file_name = nil, **opts)
37
54
  file_name ||= configuration.file&.sub(%r{(\.d)?\.(j|t)s\Z}, ".d.ts")
38
- generate!(file_name, module_type: 'DTS', **opts)
55
+ generate!(file_name, **opts, module_type: 'DTS')
39
56
  end
40
57
 
41
- def json(string)
42
- ActiveSupport::JSON.encode(string)
58
+ sig { params(value: T.untyped).returns(String) }
59
+ def json(value)
60
+ ActiveSupport::JSON.encode(value)
43
61
  end
44
62
  end
45
63
  module Generators