Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken configuration when module_type is Nil and namespace is being used. #315

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/js_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,26 @@ def generate!(file_name = configuration.file, **opts)

sig { params(opts: T.untyped).returns(String) }
def definitions(**opts)
generate(**opts, module_type: 'DTS',)
generate(**opts, module_type: default_module_type,)
end

sig { params(file_name: FileName, opts: T.untyped).void }
def definitions!(file_name = nil, **opts)
file_name ||= configuration.file&.sub(%r{(\.d)?\.(j|t)s\Z}, ".d.ts")
generate!(file_name, **opts, module_type: 'DTS')
generate!(file_name, **opts, module_type: default_module_type)
end

sig { params(value: T.untyped).returns(String) }
def json(value)
ActiveSupport::JSON.encode(value)
end

sig { returns(T.nilable(String)) }
def default_module_type
'DTS' if configuration.module_type && configuration.module_type != 'NIL'
end


end
module Generators
end
Expand Down
10 changes: 10 additions & 0 deletions spec/js_routes/module_types/dts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,15 @@
generated_js = JsRoutes.definitions(**options)
expect(generated_js).to include('export {};')
end

it 'does not use DTS module if module_type is not set' do
previous_module_type = JsRoutes.configuration.module_type
JsRoutes.configuration.module_type = nil

generated_js = JsRoutes.definitions(**options.merge(module_type: nil))
expect(generated_js).not_to include('export {};')

JsRoutes.configuration.module_type = previous_module_type
end
end
end
Loading