react_on_rails 17.0.0.rc.3 → 17.0.0.rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/generators/react_on_rails/dev_tests_generator.rb +20 -1
- data/lib/generators/react_on_rails/js_dependency_manager.rb +1 -0
- data/lib/generators/react_on_rails/templates/agent_files/AGENTS.md +3 -2
- data/lib/generators/react_on_rails/templates/base/base/bin/switch-bundler +6 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +2 -2
- data/lib/generators/react_on_rails/templates/dev_tests/eslint.config.mjs +50 -0
- data/lib/react_on_rails/controller/form_responders.rb +59 -0
- data/lib/react_on_rails/dev/server_manager.rb +1 -1
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails.rb +1 -0
- data/sig/react_on_rails/controller/form_responders.rbs +10 -0
- metadata +4 -2
- data/lib/generators/react_on_rails/templates/dev_tests/.eslintrc +0 -25
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a437fef821bdc1e6bd3b289e1b627bafc9a5c5850dc1f830c15d683dc1593e2
|
|
4
|
+
data.tar.gz: 4a5679fea3c1f2b24dbbf7b6325690e0e95222b03452c9e6cca211fdf149e83d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c905725d516131bbc94c8103953d0522a62611428c692d414b0f029299d29641f4239d4e88c054bb29aa3dfd6091133dc7c360912ba84ee5fc060540c5d26e3
|
|
7
|
+
data.tar.gz: 3b0af40fdd4fe98d75ec7fa198fd44bdafcc6f529364624e8bf42669e55d01833142698249c3d41b6587b4e65d2fbac69d96105c65667d36c58f117375529998
|
data/Gemfile.lock
CHANGED
|
@@ -8,6 +8,16 @@ module ReactOnRails
|
|
|
8
8
|
class DevTestsGenerator < Rails::Generators::Base
|
|
9
9
|
include GeneratorHelper
|
|
10
10
|
|
|
11
|
+
ESLINT_DEV_DEPENDENCIES = {
|
|
12
|
+
"@eslint/js" => "^9.0.0",
|
|
13
|
+
"eslint" => "^9.0.0",
|
|
14
|
+
"eslint-config-prettier" => "^10.0.0",
|
|
15
|
+
"eslint-plugin-import" => "^2.29.0",
|
|
16
|
+
"eslint-plugin-react" => "^7.37.5",
|
|
17
|
+
"eslint-plugin-react-hooks" => "^6.1.1",
|
|
18
|
+
"globals" => "^16.0.0"
|
|
19
|
+
}.freeze
|
|
20
|
+
|
|
11
21
|
Rails::Generators.hide_namespace(namespace)
|
|
12
22
|
source_root(File.expand_path("templates/dev_tests", __dir__))
|
|
13
23
|
|
|
@@ -24,7 +34,7 @@ module ReactOnRails
|
|
|
24
34
|
desc: "Include React Server Components test (hello_server_spec.rb)"
|
|
25
35
|
|
|
26
36
|
def copy_rspec_files
|
|
27
|
-
%w[.
|
|
37
|
+
%w[eslint.config.mjs
|
|
28
38
|
spec/spec_helper.rb
|
|
29
39
|
spec/rails_helper.rb
|
|
30
40
|
spec/simplecov_helper.rb
|
|
@@ -69,6 +79,15 @@ module ReactOnRails
|
|
|
69
79
|
|
|
70
80
|
File.open(package_json, "w+") { |f| f.puts JSON.pretty_generate(contents) }
|
|
71
81
|
end
|
|
82
|
+
|
|
83
|
+
def add_internal_eslint_dev_dependencies
|
|
84
|
+
package_json = File.join(destination_root, "package.json")
|
|
85
|
+
contents = JSON.parse(File.read(package_json))
|
|
86
|
+
contents["devDependencies"] ||= {}
|
|
87
|
+
contents["devDependencies"].merge!(ESLINT_DEV_DEPENDENCIES)
|
|
88
|
+
|
|
89
|
+
File.open(package_json, "w+") { |f| f.puts JSON.pretty_generate(contents) }
|
|
90
|
+
end
|
|
72
91
|
end
|
|
73
92
|
end
|
|
74
93
|
end
|
|
@@ -160,5 +160,6 @@ bin/rails react_on_rails:doctor
|
|
|
160
160
|
- Hosted docs: https://reactonrails.com/docs/
|
|
161
161
|
- Getting-started tutorial: https://reactonrails.com/docs/getting-started/tutorial/
|
|
162
162
|
- Machine-readable route map / expanded reference (for agents):
|
|
163
|
-
https://github.com/shakacode/react_on_rails/blob/main/llms.txt
|
|
164
|
-
https://github.com/shakacode/react_on_rails/blob/main/llms-full.txt
|
|
163
|
+
https://github.com/shakacode/react_on_rails/blob/main/llms.txt,
|
|
164
|
+
https://github.com/shakacode/react_on_rails/blob/main/llms-full.txt (OSS), and
|
|
165
|
+
https://github.com/shakacode/react_on_rails/blob/main/llms-full-pro.txt (Pro)
|
|
@@ -16,7 +16,12 @@ class BundlerSwitcher
|
|
|
16
16
|
|
|
17
17
|
RSPACK_DEPS = {
|
|
18
18
|
dependencies: %w[@rspack/core@^2.0.0-0 rspack-manifest-plugin@^5.0.0],
|
|
19
|
-
dev_dependencies: %w[
|
|
19
|
+
dev_dependencies: %w[
|
|
20
|
+
@rspack/cli@^2.0.0-0
|
|
21
|
+
@rspack/dev-server@^2.0.0
|
|
22
|
+
@rspack/plugin-react-refresh@^2.0.0
|
|
23
|
+
react-refresh
|
|
24
|
+
]
|
|
20
25
|
}.freeze
|
|
21
26
|
|
|
22
27
|
def initialize(target_bundler)
|
|
@@ -10,8 +10,8 @@ const developmentEnvOnly = (clientWebpackConfig, _serverWebpackConfig) => {
|
|
|
10
10
|
// eslint-disable-next-line global-require
|
|
11
11
|
if (config.assets_bundler === 'rspack') {
|
|
12
12
|
// Rspack uses @rspack/plugin-react-refresh for React Fast Refresh
|
|
13
|
-
const
|
|
14
|
-
clientWebpackConfig.plugins.push(new
|
|
13
|
+
const { ReactRefreshRspackPlugin } = require('@rspack/plugin-react-refresh');
|
|
14
|
+
clientWebpackConfig.plugins.push(new ReactRefreshRspackPlugin());
|
|
15
15
|
} else {
|
|
16
16
|
// Webpack uses @pmmmwh/react-refresh-webpack-plugin
|
|
17
17
|
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import prettier from 'eslint-config-prettier';
|
|
3
|
+
import importPlugin from 'eslint-plugin-import';
|
|
4
|
+
import react from 'eslint-plugin-react';
|
|
5
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
|
6
|
+
import globals from 'globals';
|
|
7
|
+
|
|
8
|
+
const reactHooksRecommendedLatest = reactHooks.configs['recommended-latest'];
|
|
9
|
+
const reactHooksRecommendedLatestConfigs = Array.isArray(reactHooksRecommendedLatest)
|
|
10
|
+
? reactHooksRecommendedLatest
|
|
11
|
+
: [reactHooksRecommendedLatest];
|
|
12
|
+
|
|
13
|
+
export default [
|
|
14
|
+
js.configs.recommended,
|
|
15
|
+
react.configs.flat.recommended,
|
|
16
|
+
importPlugin.flatConfigs.recommended,
|
|
17
|
+
...reactHooksRecommendedLatestConfigs,
|
|
18
|
+
{
|
|
19
|
+
files: ['**/*.{js,jsx,mjs,cjs}'],
|
|
20
|
+
languageOptions: {
|
|
21
|
+
ecmaVersion: 'latest',
|
|
22
|
+
sourceType: 'module',
|
|
23
|
+
globals: {
|
|
24
|
+
...globals.browser,
|
|
25
|
+
...globals.node,
|
|
26
|
+
...globals.mocha,
|
|
27
|
+
__DEBUG_SERVER_ERRORS__: true,
|
|
28
|
+
__SERVER_ERRORS__: true,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
settings: {
|
|
32
|
+
react: {
|
|
33
|
+
version: 'detect',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
rules: {
|
|
37
|
+
'no-console': 'off',
|
|
38
|
+
|
|
39
|
+
// https://github.com/import-js/eslint-plugin-import/issues/340
|
|
40
|
+
'import/no-extraneous-dependencies': 'off',
|
|
41
|
+
|
|
42
|
+
// The internal generated examples use local workspace packages during tests.
|
|
43
|
+
'import/no-unresolved': 'off',
|
|
44
|
+
|
|
45
|
+
'react/prop-types': 'off',
|
|
46
|
+
semi: 'off',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
prettier,
|
|
50
|
+
];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ReactOnRails
|
|
4
|
+
module Controller
|
|
5
|
+
# Opt-in controller helpers for responding to `useRailsForm` submissions
|
|
6
|
+
# (packages/react-on-rails/src/useRailsForm.ts).
|
|
7
|
+
#
|
|
8
|
+
# The hook posts JSON and expects model validation failures as HTTP 422 with
|
|
9
|
+
# the body shape `{ "errors": { "field_name": ["message", ...] } }`. This
|
|
10
|
+
# concern renders exactly that shape from any object exposing ActiveModel
|
|
11
|
+
# errors, so a controller action can stay a plain Rails action:
|
|
12
|
+
#
|
|
13
|
+
# class ContactMessagesController < ApplicationController
|
|
14
|
+
# include ReactOnRails::Controller::FormResponders
|
|
15
|
+
#
|
|
16
|
+
# def create
|
|
17
|
+
# contact_message = ContactMessage.new(contact_message_params)
|
|
18
|
+
# if contact_message.save
|
|
19
|
+
# render json: { message: "Thanks!" }, status: :created
|
|
20
|
+
# else
|
|
21
|
+
# render_model_errors(contact_message)
|
|
22
|
+
# end
|
|
23
|
+
# end
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# Including this concern is optional — `useRailsForm` works against any
|
|
27
|
+
# endpoint that returns the documented shape.
|
|
28
|
+
module FormResponders
|
|
29
|
+
# Renders the validation errors of an ActiveModel/ActiveRecord object as
|
|
30
|
+
# JSON in the shape `useRailsForm` maps onto per-field errors.
|
|
31
|
+
#
|
|
32
|
+
# record: any object responding to `errors` with `ActiveModel::Errors`
|
|
33
|
+
# (or anything whose `errors` responds to `messages`).
|
|
34
|
+
# status: Numeric HTTP status for the response. Defaults to 422
|
|
35
|
+
# (Unprocessable Content), which is what the hook's error mapping
|
|
36
|
+
# keys on. Numeric statuses sidestep Rack/Rails status-symbol
|
|
37
|
+
# renames such as :unprocessable_entity to :unprocessable_content.
|
|
38
|
+
# SECURITY: ActiveModel error messages are sent to the browser verbatim.
|
|
39
|
+
# Review custom validations for internal IDs, admin-only details, or
|
|
40
|
+
# security-sensitive wording before using this on a model.
|
|
41
|
+
def render_model_errors(record, status: 422)
|
|
42
|
+
unless status.is_a?(Integer)
|
|
43
|
+
raise ArgumentError, "render_model_errors status must be an Integer HTTP status code"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
unless record.respond_to?(:errors)
|
|
47
|
+
raise ArgumentError, "render_model_errors record must respond to errors.messages"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
errors = record.errors
|
|
51
|
+
unless errors.respond_to?(:messages)
|
|
52
|
+
raise ArgumentError, "render_model_errors record must respond to errors.messages"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
render json: { errors: errors.messages }, status:
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -515,7 +515,7 @@ module ReactOnRails
|
|
|
515
515
|
when "webpack"
|
|
516
516
|
"config/webpack/development.js: ReactRefreshWebpackPlugin (enabled when WEBPACK_SERVE=true)"
|
|
517
517
|
when "rspack"
|
|
518
|
-
"config/rspack/development.js: @rspack/plugin-react-refresh /
|
|
518
|
+
"config/rspack/development.js: @rspack/plugin-react-refresh / ReactRefreshRspackPlugin " \
|
|
519
519
|
"(enabled for the dev server)"
|
|
520
520
|
else
|
|
521
521
|
"Check your bundler's React Refresh plugin documentation"
|
data/lib/react_on_rails.rb
CHANGED
|
@@ -7,6 +7,7 @@ require "react_on_rails/prerender_error"
|
|
|
7
7
|
require "react_on_rails/json_parse_error"
|
|
8
8
|
require "react_on_rails/helper"
|
|
9
9
|
require "react_on_rails/controller"
|
|
10
|
+
require "react_on_rails/controller/form_responders"
|
|
10
11
|
require "react_on_rails/version"
|
|
11
12
|
require "react_on_rails/version_checker"
|
|
12
13
|
require "react_on_rails/configuration"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module ReactOnRails
|
|
2
|
+
module Controller
|
|
3
|
+
# Opt-in helpers for responding to useRailsForm submissions.
|
|
4
|
+
module FormResponders
|
|
5
|
+
# Renders ActiveModel errors as `{ errors: { field: [messages] } }` JSON
|
|
6
|
+
# with HTTP 422 (by default).
|
|
7
|
+
def render_model_errors: (untyped record, ?status: Integer) -> void
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: react_on_rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 17.0.0.rc.
|
|
4
|
+
version: 17.0.0.rc.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Gordon
|
|
@@ -191,8 +191,8 @@ files:
|
|
|
191
191
|
- lib/generators/react_on_rails/templates/base/tailwind/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx
|
|
192
192
|
- lib/generators/react_on_rails/templates/base/tailwind/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.tsx
|
|
193
193
|
- lib/generators/react_on_rails/templates/base/tailwind/app/javascript/stylesheets/application.css
|
|
194
|
-
- lib/generators/react_on_rails/templates/dev_tests/.eslintrc
|
|
195
194
|
- lib/generators/react_on_rails/templates/dev_tests/.rspec
|
|
195
|
+
- lib/generators/react_on_rails/templates/dev_tests/eslint.config.mjs
|
|
196
196
|
- lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb
|
|
197
197
|
- lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb
|
|
198
198
|
- lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb
|
|
@@ -232,6 +232,7 @@ files:
|
|
|
232
232
|
- lib/react_on_rails/config_path_resolver.rb
|
|
233
233
|
- lib/react_on_rails/configuration.rb
|
|
234
234
|
- lib/react_on_rails/controller.rb
|
|
235
|
+
- lib/react_on_rails/controller/form_responders.rb
|
|
235
236
|
- lib/react_on_rails/dev.rb
|
|
236
237
|
- lib/react_on_rails/dev/database_checker.rb
|
|
237
238
|
- lib/react_on_rails/dev/file_manager.rb
|
|
@@ -302,6 +303,7 @@ files:
|
|
|
302
303
|
- sig/react_on_rails.rbs
|
|
303
304
|
- sig/react_on_rails/configuration.rbs
|
|
304
305
|
- sig/react_on_rails/controller.rbs
|
|
306
|
+
- sig/react_on_rails/controller/form_responders.rbs
|
|
305
307
|
- sig/react_on_rails/dev/database_checker.rbs
|
|
306
308
|
- sig/react_on_rails/dev/file_manager.rbs
|
|
307
309
|
- sig/react_on_rails/dev/pack_generator.rbs
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
extends: eslint-config-shakacode
|
|
3
|
-
|
|
4
|
-
plugins:
|
|
5
|
-
- react
|
|
6
|
-
|
|
7
|
-
globals:
|
|
8
|
-
__DEBUG_SERVER_ERRORS__: true
|
|
9
|
-
__SERVER_ERRORS__: true
|
|
10
|
-
|
|
11
|
-
env:
|
|
12
|
-
browser: true
|
|
13
|
-
node: true
|
|
14
|
-
mocha: true
|
|
15
|
-
|
|
16
|
-
rules:
|
|
17
|
-
no-console: 0
|
|
18
|
-
|
|
19
|
-
# https://github.com/benmosher/eslint-plugin-import/issues/340
|
|
20
|
-
import/no-extraneous-dependencies: 0
|
|
21
|
-
|
|
22
|
-
# because template cannot find react-on-rails
|
|
23
|
-
import/no-unresolved: 0
|
|
24
|
-
|
|
25
|
-
semi: 0
|