Skip to content

Commit

Permalink
Make sure definitions are only generated for ESM module. Fixes 316.
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Jan 9, 2025
1 parent 83d65bb commit ec46486
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ nft_path(123456789012345678901234567890n)
// => /nfts/123456789012345678901234567890
```

* Fix rake task for non-esm modules. [#316](https://github.com/railsware/js-routes/issues/316)

## [2.3.4]

* Fix deprecator usage in `rake js:routes:typescript` [#327](https://github.com/railsware/js-routes/issues/327)
Expand Down
7 changes: 5 additions & 2 deletions lib/js_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ def generate(**opts)

sig { params(file_name: FileName, typed: T::Boolean, opts: T.untyped).void }
def generate!(file_name = configuration.file, typed: false, **opts)
Instance.new(file: file_name, **opts).generate!
definitions!(file_name, **opts) if typed
instance = Instance.new(file: file_name, **opts)
instance.generate!
if typed && instance.configuration.modern?
definitions!(file_name, **opts)
end
end

sig { params(file_name: FileName, opts: T.untyped).void }
Expand Down
11 changes: 11 additions & 0 deletions spec/js_routes/zzz_after_initialization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ def file_content
expect(File.exist?(file)).to be(true)
expect(File.exist?(dir.join('typed_routes.d.ts'))).to be(true)
end

it "skips definitions if module is not ESM" do
file = dir.join('typed_routes.js')
definitions = dir.join('typed_routes.d.ts')
JsRoutes.remove!(file)
expect(File.exist?(file)).to be(false)
expect(File.exist?(definitions)).to be(false)
JsRoutes.generate!(file, module_type: nil, typed: true)
expect(File.exist?(file)).to be(true)
expect(File.exist?(definitions)).to be(false)
end
end


Expand Down

0 comments on commit ec46486

Please sign in to comment.