Skip to content

Adjust install generator for typescript setups #217

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Andy9822
Copy link
Contributor

@Andy9822 Andy9822 commented Apr 14, 2025

This PR updates the Inertia install generator to use vite_typescript_tag "application" instead of vite_javascript_tag on the application layout when the --typescript flag is passed.

Additionally, it renames the generated application.js file to application.ts to align with the expected TypeScript setup.

This ensures consistency with the rest of the setup—for example, the inertia entrypoint already uses vite_typescript_tag. It also prevents confusion or broken asset references if developers try to update the application layout based on the included comment suggesting the use of vite_typescript_tag:

<%= vite_javascript_tag 'application' %>
    <!--
      If using a TypeScript entrypoint file:
        vite_typescript_tag 'application'

      If using a .jsx or .tsx entrypoint, add the extension:
        vite_javascript_tag 'application.jsx'

      Visit the guide for more information: https://vite-ruby.netlify.app/guide/rails
    -->

If they do switch to vite_typescript_tag 'application', as per the generated comment above, the asset fetching will fail because we generated the file as application.js even though it's a Typescript setup

New behavior

Image

Closes #218

@Andy9822 Andy9822 force-pushed the Fix-install-generator-for-typescript-setups branch 4 times, most recently from 62fb7f4 to b23e8aa Compare April 14, 2025 02:14
@Andy9822 Andy9822 changed the title Fix install generator for typescript setups Adjust install generator for typescript setups Apr 14, 2025
@Andy9822 Andy9822 marked this pull request as draft April 14, 2025 02:56
@Andy9822 Andy9822 force-pushed the Fix-install-generator-for-typescript-setups branch from dfbbe06 to 9e226ae Compare April 14, 2025 03:48
@Andy9822 Andy9822 marked this pull request as ready for review April 14, 2025 03:48
@@ -125,6 +125,13 @@ def install_typescript
return
end

if File.exist?(application_js_path) && application_layout.read.include?("<%= vite_javascript_tag 'application' %>")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can’t find the application_js_path, we skip making any changes.
This likely means the user has customized their setup or didn’t follow the full generator path — so we avoid modifying anything to prevent interfering with their configuration.

@Andy9822 Andy9822 force-pushed the Fix-install-generator-for-typescript-setups branch 2 times, most recently from e452da9 to be6dee5 Compare April 14, 2025 04:10
@Andy9822 Andy9822 force-pushed the Fix-install-generator-for-typescript-setups branch from be6dee5 to 6463fba Compare April 14, 2025 13:57
@Andy9822
Copy link
Contributor Author

hey @bknoles, in case this PR looks good to you, could you help merging this?

I'm not so familiar with contributing to OSS so Im sorry for directly mentioning you, but Im not sure how to properly handle these cases when it comes down to opening a PR, assign or mention someone etc...

@BrandonShar
Copy link
Collaborator

Thanks for the PR @Andy9822 ! @skryukov knows the generators better than Brian and I so I'd like to give him a chance to weigh in.

@skryukov
Copy link
Contributor

@Andy9822 thanks for the PR!

I wonder what happens if a user installs Inertia Rails into an existing app that already uses application.js without TypeScript? Perhaps we could move this logic to the Vite installation step to ensure safety.

@bknoles
Copy link
Collaborator

bknoles commented Apr 23, 2025

Yea, I'd say application.js isn't in the scope of Inertia Rails since it's created by Vite Ruby. If Vite Ruby offered a way to configure its install generator, then it'd be nice to use that, but it doesn't.

Since application.js is a dummy file, I think I'd be ok with Inertia Rails deleting it, if and only if it was created during the Inertia Rails installation process. (i.e. it didn't exist before we running the install generator). To @skryukov's point, we shouldn't tamper with a user's application.js file if it already existed before installing Inertia Rails.

@Andy9822
Copy link
Contributor Author

@Andy9822 thanks for the PR!

I wonder what happens if a user installs Inertia Rails into an existing app that already uses application.js without TypeScript? Perhaps we could move this logic to the Vite installation step to ensure safety.

hmm, not sure Im following what issue you're pointing out here @skryukov 🤔

The code of this PR runs inside the install_typescript function, so the application.js would only be converted to application.ts when installing Inertia with TypeScript

image

I personally don’t think we need to take an "extreme" or so opinionated measure like deleting the application.js file if it’s generated by Inertia — as @bknoles suggested — since it’s actually a fine and useful part of the install command, which helps scaffold a basic structure for you. It’s similar to what you get when generating a new Rails app with its install command.

@skryukov
Copy link
Contributor

hmm, not sure Im following what issue you're pointing out here @skryukov 🤔

I'm talking about a case when someone installs Inertia Rails on top of an existing application (not a rails new one) that uses Ruby Vite—in that case, we don't want to touch their files. So, I believe we should either do nothing or move this logic to the install_vite step.

@Andy9822 Andy9822 force-pushed the Fix-install-generator-for-typescript-setups branch from aa6f9d8 to 4be55da Compare April 27, 2025 19:06
@Andy9822
Copy link
Contributor Author

hmm, not sure Im following what issue you're pointing out here @skryukov 🤔

I'm talking about a case when someone installs Inertia Rails on top of an existing application (not a rails new one) that uses Ruby Vite—in that case, we don't want to touch their files. So, I believe we should either do nothing or move this logic to the install_vite step.

oooh ok, you mean when > Vite < had been installed outside of the Inertia install generator, sorry I finally got what you meant!
I just pushed a commit with that new approach

@Andy9822 Andy9822 force-pushed the Fix-install-generator-for-typescript-setups branch 6 times, most recently from 83e0a3f to 1299957 Compare April 27, 2025 20:26
Users may install Inertia on projects that already have Vite installed.
Now, the renaming only occurs when the Inertia generator is also installing Vite, ensuring
compatibility with existing Vite setups and preventing unnecessary file renaming.
@Andy9822 Andy9822 force-pushed the Fix-install-generator-for-typescript-setups branch from 1299957 to a197826 Compare April 27, 2025 20:28
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inertia:install generator for Typescript uses vite_javascript_tag on the application layout
4 participants