Skip to content

Commit 31a88fd

Browse files
justin808claude
andcommitted
Add draft comment for package_json gem issue #25
This comment explains React on Rails' use case for exact version support and provides context for why we had to implement a workaround. To be posted at: shakacode/package_json#25 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f2a0e33 commit 31a88fd

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

package_json_issue_comment.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## React on Rails Use Case
2+
3+
We encountered this limitation in React on Rails and had to work around it by bypassing the `package_json` gem for our main package installation.
4+
5+
### Context
6+
7+
React on Rails requires **exact version matching** between the Ruby gem and npm package (e.g., gem version `16.1.1` must match npm package version `16.1.1` exactly, not `^16.1.1`). This is because the gem and package have tightly coupled APIs that must stay in sync.
8+
9+
### Problem
10+
11+
When using `package_json.manager.add(["react-on-rails@16.1.1"])`, the package gets installed with a caret (`^16.1.1`), which our version checker then rejects during Rails initialization.
12+
13+
This was causing our generator tests to fail because:
14+
15+
1. Generator runs `package_json.manager.add(["react-on-rails@16.1.1"])`
16+
2. Package gets added to package.json as `"react-on-rails": "^16.1.1"`
17+
3. Our version checker validates that versions match exactly
18+
4. Validation fails with error about non-exact version
19+
20+
### Current Workaround
21+
22+
We had to bypass the gem and use direct npm commands:
23+
24+
```ruby
25+
# lib/generators/react_on_rails/install_generator.rb
26+
def add_react_on_rails_package
27+
# Always use direct npm install with --save-exact to ensure exact version matching
28+
# The package_json gem doesn't support --save-exact flag
29+
react_on_rails_pkg = "react-on-rails@#{ReactOnRails::VERSION}"
30+
31+
puts "Installing React on Rails package..."
32+
success = system("npm", "install", "--save-exact", react_on_rails_pkg)
33+
# ...
34+
end
35+
```
36+
37+
### Why We Need This Feature
38+
39+
1. **The gem's abstraction is valuable** - We'd prefer to use the package_json gem's API rather than maintaining package-manager-specific command strings
40+
2. **Loss of package manager agnosticism** - Having to use direct npm commands defeats the purpose of the gem, as we can no longer support yarn/pnpm/bun automatically
41+
3. **Exact version pinning is a legitimate use case** - Packages with tightly coupled Ruby gem + npm package pairs need this feature
42+
43+
### Proposed API
44+
45+
Would love to see something like:
46+
47+
```ruby
48+
package_json.manager.add(["react-on-rails@16.1.1"], exact: true)
49+
```
50+
51+
This would translate to:
52+
53+
- **npm/pnpm**: `--save-exact`
54+
- **yarn/bun**: `--exact`
55+
56+
Happy to test this feature in React on Rails once it's available!
57+
58+
**Reference**: shakacode/react_on_rails@f2a0e331

0 commit comments

Comments
 (0)