Skip to content

Add Vite script component (salvage of #2334) - #2351

Merged
nesquena merged 15 commits into
masterfrom
vite-script-component-salvage
Oct 14, 2026
Merged

nesquena merged 15 commits into
masterfrom
vite-script-component-salvage

Conversation

@nesquena

@nesquena nesquena commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

This carries @osbre's commits from #2334 unchanged, plus review polish. When squash-merged, it will credit @osbre with a Co-authored-by trailer.

The component (by @osbre): it adds Vite as a script component via vite_padrino, for both padrino g project demo --script=vite and padrino g component --script=vite in an existing project. It:

  • adds vite_padrino and register VitePadrino;
  • writes config/vite.json, vite.config.ts, package.json, an app/frontend/entrypoints/application.js entrypoint, the Vite rake tasks, and a vite process in Procfile.dev.

It doesn't run npm; it tells you to run npm install and add vite_client_tag / vite_javascript_tag 'application' to your layout.

The Object#try workaround: vite_padrino 3.0.0 calls ActiveSupport's Object#try and crashes without it when entrypoints share a chunk. The upstream fix, ElMassimo/vite_ruby#635, is still pending. So for now the component:

Drop both once a fixed release ships.

Polish added in this salvage, each with a regression test that fails before the change:

  • The activesupport line matches padrino-admin's exactly, so generating admin before or after Vite no longer makes Bundler warn "lists the gem activesupport more than once". An existing gem 'activesupport' or gem('activesupport', ...) line is kept as is.
  • An existing Procfile.dev gets the vite: process appended, or left alone if it's already there, instead of being skipped.
  • Lines appended to Procfile.dev and .gitignore start on a new line. Before, a file without a trailing newline glued the first appended line onto its last line, which could un-ignore .env.
  • Re-running the component without a terminal no longer overwrites an edited vite.config.ts, config/vite.json or entrypoint.
  • Projects without a Gemfile or Rakefile no longer stop halfway.
  • Component files are read as UTF-8 (apply_component_for), so --script=vite, whose entrypoint text isn't ASCII, no longer fails with a SyntaxError under a C/POSIX locale.

Verification:

  • The full bundle exec rake test passes in an isolated environment, plain and with --enable-frozen-string-literal (gen 261 runs, admin 67, 0 failures).
  • CI is green on the head.
  • Real generated projects were checked:
  • Two review passes ran on the final head.

Closes #2334.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JWpdhd1LepyfkNRGx9kwrD

osbre and others added 9 commits October 13, 2026 04:07
The Vite component wrote `gem 'activesupport', '>= 3.1', require: ...`,
which differs from padrino-admin's `gem 'activesupport', '>= 3.1'`, so a
project with both got Bundler's "listed more than once" warning in either
order. Declare it with require_dependencies so the line is identical and
Thor's inject skips the second copy, and require Object#try from
config/boot.rb after Bundler.require (vite_padrino 3.0.0 needs it until
vite_ruby#635 ships).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JWpdhd1LepyfkNRGx9kwrD
The Vite component skipped Procfile.dev when the project already had one,
so `vite dev` was never started. Append the vite line instead, unless the
file already declares a vite process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JWpdhd1LepyfkNRGx9kwrD
Running `padrino g component --script=vite` again without a terminal
overwrote vite.config.ts, config/vite.json and the application entrypoint,
because Thor treats an unanswered conflict prompt as "overwrite". Skip
them when they exist, as package.json already was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JWpdhd1LepyfkNRGx9kwrD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JWpdhd1LepyfkNRGx9kwrD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JWpdhd1LepyfkNRGx9kwrD
Copilot AI balanced review requested due to automatic review settings October 14, 2026 08:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

- Start Procfile.dev and .gitignore additions on a new line when the file
  lacks a trailing newline; otherwise 'web: ...puma' became
  '...pumavite: ...' and '.env' became '.env/public/vite*', un-ignoring it.
- Keep an activesupport line the Gemfile already has instead of adding a
  second one Bundler rejects.
- Say how to add the Object#try require when config/boot.rb has no
  matching Bundler.require line, and link vite_ruby#635 in the comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JWpdhd1LepyfkNRGx9kwrD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JWpdhd1LepyfkNRGx9kwrD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JWpdhd1LepyfkNRGx9kwrD
…ile edits

Read component files as UTF-8, so the Vite component (whose entrypoint text
isn't ASCII) no longer fails with a SyntaxError when the locale is C or POSIX.
Treat gem('activesupport', ...) as an existing activesupport line, and skip
the Rakefile tasks when a project has no Rakefile instead of stopping halfway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JWpdhd1LepyfkNRGx9kwrD
@nesquena
nesquena merged commit 2b2c1a0 into master Oct 14, 2026
15 checks passed
@nesquena
nesquena deleted the vite-script-component-salvage branch October 14, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants