react_on_rails 8.0.2 → 9.0.0
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/.eslintignore +2 -0
- data/.gitignore +2 -2
- data/.rubocop.yml +5 -0
- data/.travis.yml +12 -1
- data/CHANGELOG.md +185 -6
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +6 -2
- data/Gemfile.rails32 +74 -0
- data/KUDOS.md +5 -0
- data/README.md +200 -84
- data/Rakefile +11 -1
- data/app/helpers/react_on_rails_helper.rb +1 -1
- data/docs/additional-reading/asset-pipeline.md +20 -0
- data/docs/additional-reading/hot-reloading-rails-development.md +4 -75
- data/docs/additional-reading/node-server-rendering.md +2 -166
- data/docs/additional-reading/rails-assets-relative-paths.md +3 -1
- data/docs/additional-reading/rails-engine-integration.md +1 -1
- data/docs/additional-reading/rspec-configuration.md +7 -24
- data/docs/api/ruby-api-hot-reload-view-helpers.md +2 -2
- data/{lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt → docs/basics/configuration.md} +80 -41
- data/docs/basics/generator.md +0 -5
- data/docs/basics/installation-overview.md +6 -5
- data/docs/contributor-info/generator-testing.md +0 -9
- data/docs/tutorial.md +31 -34
- data/lib/generators/USAGE +0 -4
- data/lib/generators/react_on_rails/base_generator.rb +43 -76
- data/lib/generators/react_on_rails/dev_tests_generator.rb +7 -5
- data/lib/generators/react_on_rails/install_generator.rb +5 -10
- data/lib/generators/react_on_rails/react_no_redux_generator.rb +10 -9
- data/lib/generators/react_on_rails/react_with_redux_generator.rb +27 -17
- data/lib/generators/react_on_rails/templates/.eslintrc +2 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +5 -0
- data/lib/generators/react_on_rails/templates/base/base/{client/app → app/javascript}/bundles/HelloWorld/components/HelloWorld.jsx +1 -2
- data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +0 -1
- data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +12 -0
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +41 -0
- data/lib/generators/react_on_rails/templates/dev_tests/.eslintrc +25 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +0 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb +2 -0
- data/lib/generators/react_on_rails/templates/redux/base/{client/app → app/javascript}/bundles/HelloWorld/startup/HelloWorldApp.jsx +1 -3
- data/lib/react_on_rails/configuration.rb +21 -16
- data/lib/react_on_rails/git_utils.rb +9 -3
- data/lib/react_on_rails/prerender_error.rb +15 -9
- data/lib/react_on_rails/server_rendering_pool/exec.rb +21 -8
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +1 -1
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +3 -1
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +12 -8
- data/lib/react_on_rails/test_helper.rb +7 -6
- data/lib/react_on_rails/utils.rb +77 -16
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_checker.rb +2 -1
- data/lib/tasks/assets.rake +12 -4
- data/package.json +25 -21
- data/rakelib/dummy_apps.rake +9 -0
- data/rakelib/example_type.rb +4 -70
- data/rakelib/examples.rake +5 -55
- data/rakelib/node_package.rake +1 -0
- data/rakelib/release.rake +9 -1
- data/rakelib/run_rspec.rake +24 -5
- data/react_on_rails.gemspec +2 -1
- data/webpackConfigLoader.js +45 -72
- data/yarn.lock +638 -252
- metadata +36 -26
- data/lib/generators/react_on_rails/node_generator.rb +0 -24
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +0 -2
- data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb.tt +0 -15
- data/lib/generators/react_on_rails/templates/base/base/client/.babelrc +0 -3
- data/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md +0 -9
- data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +0 -36
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.config.js +0 -77
- data/lib/generators/react_on_rails/templates/base/base/config/webpacker_lite.yml +0 -27
- data/lib/generators/react_on_rails/templates/base/base/package.json.tt +0 -8
- data/lib/generators/react_on_rails/templates/node/base/client/node/package.json +0 -10
- data/lib/generators/react_on_rails/templates/node/base/client/node/server.js +0 -105
- /data/lib/generators/react_on_rails/templates/base/base/{client/app/bundles/HelloWorld/startup/registration.jsx.tt → app/javascript/packs/registration.js.tt} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx → app/javascript/bundles/HelloWorld/actions/helloWorldActionCreators.js} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app → app/javascript}/bundles/HelloWorld/components/HelloWorld.jsx +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx → app/javascript/bundles/HelloWorld/constants/helloWorldConstants.js} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx → app/javascript/bundles/HelloWorld/containers/HelloWorldContainer.js} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx → app/javascript/bundles/HelloWorld/reducers/helloWorldReducer.js} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app/bundles/HelloWorld/store/helloWorldStore.jsx → app/javascript/bundles/HelloWorld/store/helloWorldStore.js} +0 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# NOTE: ReactOnRails::Utils.using_webpacker? always will return false when called here.
|
|
4
|
+
|
|
3
5
|
module ReactOnRails
|
|
4
6
|
def self.configure
|
|
5
7
|
yield(configuration)
|
|
@@ -24,7 +26,7 @@ module ReactOnRails
|
|
|
24
26
|
|
|
25
27
|
raise "Error configuring /config/react_on_rails.rb: invalid value for `config.i18n_dir`. "\
|
|
26
28
|
"Directory does not exist: #{@configuration.i18n_dir}. Set to value to nil or comment it "\
|
|
27
|
-
"out if not using
|
|
29
|
+
"out if not using the React on Rails i18n feature."
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
def self.check_i18n_yml_directory_exists
|
|
@@ -59,7 +61,7 @@ module ReactOnRails
|
|
|
59
61
|
def self.ensure_webpack_generated_files_exists
|
|
60
62
|
return unless @configuration.webpack_generated_files.empty?
|
|
61
63
|
|
|
62
|
-
files = ["
|
|
64
|
+
files = ["hello-world-bundle.js"]
|
|
63
65
|
if @configuration.server_bundle_js_file.present?
|
|
64
66
|
files << @configuration.server_bundle_js_file
|
|
65
67
|
end
|
|
@@ -81,6 +83,7 @@ module ReactOnRails
|
|
|
81
83
|
|
|
82
84
|
def self.configuration
|
|
83
85
|
@configuration ||= Configuration.new(
|
|
86
|
+
node_modules_location: "",
|
|
84
87
|
generated_assets_dirs: nil,
|
|
85
88
|
|
|
86
89
|
# generated_assets_dirs is deprecated
|
|
@@ -97,43 +100,45 @@ module ReactOnRails
|
|
|
97
100
|
skip_display_none: nil,
|
|
98
101
|
|
|
99
102
|
# skip_display_none is deprecated
|
|
100
|
-
webpack_generated_files: [],
|
|
103
|
+
webpack_generated_files: %w[manifest.json],
|
|
101
104
|
rendering_extension: nil,
|
|
102
|
-
server_render_method: "",
|
|
105
|
+
server_render_method: "ExecJS",
|
|
103
106
|
symlink_non_digested_assets_regex: nil,
|
|
104
|
-
|
|
107
|
+
build_test_command: "",
|
|
105
108
|
i18n_dir: "",
|
|
106
109
|
i18n_yml_dir: "",
|
|
107
|
-
|
|
110
|
+
build_production_command: ""
|
|
108
111
|
)
|
|
109
112
|
end
|
|
110
113
|
|
|
111
114
|
class Configuration
|
|
112
|
-
attr_accessor :server_bundle_js_file, :prerender, :replay_console,
|
|
115
|
+
attr_accessor :node_modules_location, :server_bundle_js_file, :prerender, :replay_console,
|
|
113
116
|
:trace, :development_mode,
|
|
114
117
|
:logging_on_server, :server_renderer_pool_size,
|
|
115
118
|
:server_renderer_timeout, :skip_display_none, :raise_on_prerender_error,
|
|
116
119
|
:generated_assets_dirs, :generated_assets_dir,
|
|
117
|
-
:webpack_generated_files, :rendering_extension, :
|
|
118
|
-
:
|
|
120
|
+
:webpack_generated_files, :rendering_extension, :build_test_command,
|
|
121
|
+
:build_production_command,
|
|
119
122
|
:i18n_dir, :i18n_yml_dir,
|
|
120
123
|
:server_render_method, :symlink_non_digested_assets_regex
|
|
121
124
|
|
|
122
|
-
def initialize(
|
|
125
|
+
def initialize(node_modules_location: "", server_bundle_js_file: nil, prerender: nil,
|
|
126
|
+
replay_console: nil,
|
|
123
127
|
trace: nil, development_mode: nil,
|
|
124
128
|
logging_on_server: nil, server_renderer_pool_size: nil,
|
|
125
|
-
server_renderer_timeout: nil, raise_on_prerender_error:
|
|
129
|
+
server_renderer_timeout: nil, raise_on_prerender_error: true,
|
|
126
130
|
skip_display_none: nil, generated_assets_dirs: nil,
|
|
127
131
|
generated_assets_dir: nil, webpack_generated_files: nil,
|
|
128
|
-
rendering_extension: nil,
|
|
129
|
-
|
|
132
|
+
rendering_extension: nil, build_test_command: nil,
|
|
133
|
+
build_production_command: nil,
|
|
130
134
|
i18n_dir: nil, i18n_yml_dir: nil,
|
|
131
|
-
server_render_method:
|
|
135
|
+
server_render_method: "ExecJS", symlink_non_digested_assets_regex: nil)
|
|
136
|
+
self.node_modules_location = node_modules_location
|
|
132
137
|
self.server_bundle_js_file = server_bundle_js_file
|
|
133
138
|
self.generated_assets_dirs = generated_assets_dirs
|
|
134
139
|
self.generated_assets_dir = generated_assets_dir
|
|
135
|
-
self.
|
|
136
|
-
self.
|
|
140
|
+
self.build_test_command = build_test_command
|
|
141
|
+
self.build_production_command = build_production_command
|
|
137
142
|
self.i18n_dir = i18n_dir
|
|
138
143
|
self.i18n_yml_dir = i18n_yml_dir
|
|
139
144
|
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "English"
|
|
4
|
+
|
|
3
5
|
module ReactOnRails
|
|
4
6
|
module GitUtils
|
|
5
7
|
def self.uncommitted_changes?(message_handler)
|
|
6
|
-
return false if ENV["COVERAGE"]
|
|
8
|
+
return false if ENV["COVERAGE"] == "true"
|
|
7
9
|
status = `git status --porcelain`
|
|
8
|
-
return false if status.empty?
|
|
9
|
-
error =
|
|
10
|
+
return false if $CHILD_STATUS.success? && status.empty?
|
|
11
|
+
error = if !$CHILD_STATUS.success?
|
|
12
|
+
"You do not have Git installed. Please install Git, and commit your changes before continuing"
|
|
13
|
+
else
|
|
14
|
+
"You have uncommitted code. Please commit or stash your changes before continuing"
|
|
15
|
+
end
|
|
10
16
|
message_handler.add_error(error)
|
|
11
17
|
true
|
|
12
18
|
end
|
|
@@ -8,24 +8,30 @@ module ReactOnRails
|
|
|
8
8
|
js_code: nil, console_messages: nil)
|
|
9
9
|
message = "ERROR in SERVER PRERENDERING\n".dup
|
|
10
10
|
if err
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
# rubocop:disable Layout/IndentHeredoc
|
|
12
|
+
message << <<-MSG
|
|
13
|
+
Encountered error: \"#{err}\"
|
|
13
14
|
MSG
|
|
15
|
+
# rubocop:enable Layout/IndentHeredoc
|
|
14
16
|
backtrace = err.backtrace.join("\n")
|
|
15
17
|
else
|
|
16
18
|
backtrace = nil
|
|
17
19
|
end
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
# rubocop:disable Layout/IndentHeredoc
|
|
21
|
+
message << <<-MSG
|
|
22
|
+
when prerendering #{component_name} with props: #{props}
|
|
23
|
+
js_code was:
|
|
24
|
+
#{js_code}
|
|
22
25
|
MSG
|
|
26
|
+
# rubocop:enable Layout/IndentHeredoc
|
|
23
27
|
|
|
24
28
|
if console_messages
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
# rubocop:disable Layout/IndentHeredoc
|
|
30
|
+
message << <<-MSG
|
|
31
|
+
console messages:
|
|
32
|
+
#{console_messages}
|
|
28
33
|
MSG
|
|
34
|
+
# rubocop:enable Layout/IndentHeredoc
|
|
29
35
|
end
|
|
30
36
|
|
|
31
37
|
super([message, backtrace].compact.join("\n"))
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "open-uri"
|
|
4
|
+
|
|
3
5
|
module ReactOnRails
|
|
4
6
|
module ServerRenderingPool
|
|
5
7
|
# This implementation of the rendering pool uses ExecJS to execute javasript code
|
|
@@ -14,11 +16,21 @@ module ReactOnRails
|
|
|
14
16
|
|
|
15
17
|
def self.reset_pool_if_server_bundle_was_modified
|
|
16
18
|
return unless ReactOnRails.configuration.development_mode
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
server_bundle_js_file_path = ReactOnRails::Utils.server_bundle_js_file_path
|
|
21
|
+
|
|
22
|
+
if Webpacker.dev_server.running?
|
|
23
|
+
return if @last_loaded_server_bundle == server_bundle_js_file_path
|
|
24
|
+
@last_loaded_server_bundle = server_bundle_js_file_path
|
|
25
|
+
else
|
|
26
|
+
# we're not hashing the server name and we can use the mtime
|
|
27
|
+
file_mtime = File.mtime(server_bundle_js_file_path)
|
|
28
|
+
@server_bundle_timestamp ||= file_mtime
|
|
29
|
+
return if @server_bundle_timestamp == file_mtime
|
|
30
|
+
@server_bundle_timestamp = file_mtime
|
|
31
|
+
end
|
|
32
|
+
|
|
20
33
|
ReactOnRails::ServerRenderingPool.reset_pool
|
|
21
|
-
@server_bundle_timestamp = file_mtime
|
|
22
34
|
end
|
|
23
35
|
|
|
24
36
|
# js_code: JavaScript expression that returns a string.
|
|
@@ -83,14 +95,15 @@ module ReactOnRails
|
|
|
83
95
|
|
|
84
96
|
server_js_file = ReactOnRails::Utils.server_bundle_js_file_path
|
|
85
97
|
|
|
86
|
-
|
|
98
|
+
# bundle_js_code = File.read(server_js_file)
|
|
99
|
+
begin
|
|
100
|
+
bundle_js_code = open(server_js_file, &:read)
|
|
101
|
+
rescue => e
|
|
87
102
|
msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
|
|
88
103
|
"read. You may set the server_bundle_js_file in your configuration to be \"\" to "\
|
|
89
|
-
"avoid this warning"
|
|
104
|
+
"avoid this warning.\nError is: #{e}"
|
|
90
105
|
raise msg
|
|
91
106
|
end
|
|
92
|
-
|
|
93
|
-
bundle_js_code = File.read(server_js_file)
|
|
94
107
|
# rubocop:disable Layout/IndentHeredoc
|
|
95
108
|
base_js_code = <<-JS
|
|
96
109
|
#{console_polyfill}
|
|
@@ -50,7 +50,7 @@ Detected the following stale generated files:
|
|
|
50
50
|
#{stale_files.join("\n ")}
|
|
51
51
|
|
|
52
52
|
React on Rails will ensure your JavaScript generated files are up to date, using your
|
|
53
|
-
|
|
53
|
+
`#{ReactOnRails::Utils.prepend_cd_node_modules_directory(ReactOnRails.configuration.build_test_command)}` command.
|
|
54
54
|
|
|
55
55
|
MSG
|
|
56
56
|
# rubocop:enable Layout/IndentHeredoc
|
|
@@ -8,7 +8,9 @@ module ReactOnRails
|
|
|
8
8
|
def compile_assets
|
|
9
9
|
puts "\nBuilding Webpack assets..."
|
|
10
10
|
|
|
11
|
-
cmd =
|
|
11
|
+
cmd = ReactOnRails::Utils.prepend_cd_node_modules_directory(
|
|
12
|
+
ReactOnRails.configuration.build_test_command
|
|
13
|
+
)
|
|
12
14
|
|
|
13
15
|
ReactOnRails::Utils.invoke_and_exit_if_failed(cmd, "Error in building webpack assets!")
|
|
14
16
|
|
|
@@ -10,22 +10,24 @@ module ReactOnRails
|
|
|
10
10
|
module TestHelper
|
|
11
11
|
class WebpackAssetsStatusChecker
|
|
12
12
|
include Utils::Required
|
|
13
|
-
#
|
|
14
|
-
|
|
13
|
+
# source_path is typically configured in the webpacker.yml file
|
|
14
|
+
# for `source_path`
|
|
15
|
+
# or for legacy React on Rails, it's /client, where all client files go
|
|
16
|
+
attr_reader :source_path, :generated_assets_dir
|
|
15
17
|
|
|
16
18
|
def initialize(
|
|
17
19
|
generated_assets_dir: required("generated_assets_dir"),
|
|
18
|
-
|
|
20
|
+
source_path: required("source_path"),
|
|
19
21
|
webpack_generated_files: required("webpack_generated_files")
|
|
20
22
|
)
|
|
21
23
|
@generated_assets_dir = generated_assets_dir
|
|
22
|
-
@
|
|
24
|
+
@source_path = source_path
|
|
23
25
|
@webpack_generated_files = webpack_generated_files
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
def stale_generated_webpack_files
|
|
27
|
-
manifest_needed = ReactOnRails::Utils.
|
|
28
|
-
!
|
|
29
|
+
manifest_needed = ReactOnRails::Utils.using_webpacker? &&
|
|
30
|
+
!ReactOnRails::Utils.manifest_exists?
|
|
29
31
|
|
|
30
32
|
return ["manifest.json"] if manifest_needed
|
|
31
33
|
|
|
@@ -53,13 +55,15 @@ module ReactOnRails
|
|
|
53
55
|
webpack_generated_files = @webpack_generated_files.map do |bundle_name|
|
|
54
56
|
ReactOnRails::Utils.bundle_js_file_path(bundle_name)
|
|
55
57
|
end
|
|
58
|
+
|
|
56
59
|
if webpack_generated_files.present?
|
|
57
60
|
webpack_generated_files
|
|
58
61
|
else
|
|
59
62
|
file_list = make_file_list(make_globs(generated_assets_dir)).to_ary
|
|
60
63
|
puts "V" * 80
|
|
61
64
|
puts "Please define config.webpack_generated_files (array) so the test helper knows "\
|
|
62
|
-
"which files are required."
|
|
65
|
+
"which files are required. If you are using webpacker, you typically need to only "\
|
|
66
|
+
"include 'manifest.json'."
|
|
63
67
|
puts "Detected the possible following files to check for webpack compilation in "\
|
|
64
68
|
"#{generated_assets_dir}"
|
|
65
69
|
puts file_list.join("\n")
|
|
@@ -70,7 +74,7 @@ module ReactOnRails
|
|
|
70
74
|
end
|
|
71
75
|
|
|
72
76
|
def client_files
|
|
73
|
-
@client_files ||= make_file_list(make_globs(
|
|
77
|
+
@client_files ||= make_file_list(make_globs(source_path)).to_ary
|
|
74
78
|
end
|
|
75
79
|
|
|
76
80
|
def make_globs(dirs)
|
|
@@ -44,26 +44,27 @@ module ReactOnRails
|
|
|
44
44
|
# an example of usage.
|
|
45
45
|
#
|
|
46
46
|
# Typical usage passes all params as nil defaults.
|
|
47
|
-
# webpack_assets_status_checker: provide: `up_to_date?`, `whats_not_up_to_date`, `
|
|
47
|
+
# webpack_assets_status_checker: provide: `up_to_date?`, `whats_not_up_to_date`, `source_path`
|
|
48
48
|
# defaults to ReactOnRails::TestHelper::WebpackAssetsStatusChecker
|
|
49
49
|
# webpack_assets_compiler: provide one method: `def compile`
|
|
50
50
|
# defaults to ReactOnRails::TestHelper::WebpackAssetsCompiler
|
|
51
|
-
#
|
|
51
|
+
# source_path and generated_assets_dir are passed into the default webpack_assets_status_checker if you
|
|
52
52
|
# don't provide one.
|
|
53
53
|
# webpack_generated_files List of files to check for up-to-date-status, defaulting to
|
|
54
54
|
# webpack_generated_files in your configuration
|
|
55
55
|
def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
|
|
56
56
|
webpack_assets_compiler: nil,
|
|
57
|
-
|
|
57
|
+
source_path: nil,
|
|
58
58
|
generated_assets_dir: nil,
|
|
59
59
|
webpack_generated_files: nil)
|
|
60
|
+
ReactOnRails::Utils.check_manifest_not_cached
|
|
60
61
|
if webpack_assets_status_checker.nil?
|
|
61
|
-
|
|
62
|
-
generated_assets_dir ||= ReactOnRails.
|
|
62
|
+
source_path ||= ReactOnRails::Utils.source_path
|
|
63
|
+
generated_assets_dir ||= ReactOnRails::Utils.generated_assets_dir
|
|
63
64
|
webpack_generated_files ||= ReactOnRails.configuration.webpack_generated_files
|
|
64
65
|
|
|
65
66
|
webpack_assets_status_checker ||=
|
|
66
|
-
WebpackAssetsStatusChecker.new(
|
|
67
|
+
WebpackAssetsStatusChecker.new(source_path: source_path,
|
|
67
68
|
generated_assets_dir: generated_assets_dir,
|
|
68
69
|
webpack_generated_files: webpack_generated_files)
|
|
69
70
|
|
data/lib/react_on_rails/utils.rb
CHANGED
|
@@ -21,7 +21,6 @@ module ReactOnRails
|
|
|
21
21
|
# Wraps message and makes it colored.
|
|
22
22
|
# Pass in the msg and color as a symbol.
|
|
23
23
|
def self.wrap_message(msg, color = :red)
|
|
24
|
-
# binding.pry
|
|
25
24
|
wrapper_line = ("=" * 80).to_s
|
|
26
25
|
# rubocop:disable Layout/IndentHeredoc
|
|
27
26
|
fenced_msg = <<-MSG
|
|
@@ -62,25 +61,33 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
|
62
61
|
end
|
|
63
62
|
|
|
64
63
|
def self.server_bundle_js_file_path
|
|
65
|
-
|
|
64
|
+
# Either:
|
|
65
|
+
# 1. Using same bundle for both server and client, so server bundle will be hashed in manifest
|
|
66
|
+
# 2. Using a different bundle (different Webpack config), so file is not hashed, and
|
|
67
|
+
# bundle_js_path will throw.
|
|
68
|
+
# 3. Not using webpacker, and bundle_js_path always returns
|
|
69
|
+
|
|
70
|
+
# Note, server bundle should not be in the manifest
|
|
71
|
+
# If using webpacker gem per https://github.com/rails/webpacker/issues/571
|
|
72
|
+
return @server_bundle_path if @server_bundle_path && !Rails.env.development?
|
|
73
|
+
|
|
74
|
+
bundle_name = ReactOnRails.configuration.server_bundle_js_file
|
|
75
|
+
@server_bundle_path = begin
|
|
76
|
+
bundle_js_file_path(bundle_name)
|
|
77
|
+
rescue Webpacker::Manifest::MissingEntryError
|
|
78
|
+
Rails.root.join(File.join(Webpacker.config.public_output_path, bundle_name)).to_s
|
|
79
|
+
end
|
|
66
80
|
end
|
|
67
81
|
|
|
68
|
-
# TODO: conturbo Write Test for this, with BOTH webpacker_lite installed and not, and
|
|
69
|
-
# with case for webpacker_lite, but server file is not in the file
|
|
70
82
|
def self.bundle_js_file_path(bundle_name)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
if using_webpacker?
|
|
84
|
+
return bundle_name if bundle_name == "manifest.json"
|
|
85
|
+
bundle_js_file_path_from_webpacker(bundle_name)
|
|
86
|
+
else
|
|
87
|
+
# Default to the non-hashed name in the specified output directory, which, for legacy
|
|
88
|
+
# React on Rails, this is the output directory picked up by the asset pipeline.
|
|
89
|
+
File.join(ReactOnRails.configuration.generated_assets_dir, bundle_name)
|
|
77
90
|
end
|
|
78
|
-
|
|
79
|
-
File.join(ReactOnRails.configuration.generated_assets_dir, bundle_name)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def self.using_webpacker_lite?
|
|
83
|
-
ActionController::Base.helpers.respond_to?(:asset_pack_path)
|
|
84
91
|
end
|
|
85
92
|
|
|
86
93
|
def self.running_on_windows?
|
|
@@ -108,5 +115,59 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
|
108
115
|
raise ArgumentError, "#{arg_name} is required"
|
|
109
116
|
end
|
|
110
117
|
end
|
|
118
|
+
|
|
119
|
+
def self.prepend_cd_node_modules_directory(cmd)
|
|
120
|
+
return cmd unless ReactOnRails.configuration.node_modules_location.present?
|
|
121
|
+
"cd #{ReactOnRails.configuration.node_modules_location} && #{cmd}"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def self.source_path
|
|
125
|
+
using_webpacker? ? webpacker_source_path : ReactOnRails.configuration.node_modules_location
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def self.generated_assets_dir
|
|
129
|
+
using_webpacker? ? webpacker_public_output_path : ReactOnRails.configuration.generated_assets_dir
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
###########################################################################
|
|
133
|
+
# WEBPACKER WRAPPERS
|
|
134
|
+
###########################################################################
|
|
135
|
+
def self.using_webpacker?
|
|
136
|
+
ActionController::Base.helpers.respond_to?(:asset_pack_path)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def self.bundle_js_file_path_from_webpacker(bundle_name)
|
|
140
|
+
hashed_bundle_name = Webpacker.manifest.lookup(bundle_name)
|
|
141
|
+
if Webpacker.dev_server.running?
|
|
142
|
+
result = "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{hashed_bundle_name}"
|
|
143
|
+
result
|
|
144
|
+
else
|
|
145
|
+
# Next line will throw if the file or manifest does not exist
|
|
146
|
+
Rails.root.join(File.join("public", hashed_bundle_name)).to_s
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def self.webpacker_source_path
|
|
151
|
+
Webpacker.config.source_path
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def self.webpacker_public_output_path
|
|
155
|
+
Webpacker.config.public_output_path
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def self.manifest_exists?
|
|
159
|
+
Webpacker.config.public_manifest_path.exist?
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def self.check_manifest_not_cached
|
|
163
|
+
return unless using_webpacker? && Webpacker.config.cache_manifest?
|
|
164
|
+
msg = <<-MSG.strip_heredoc
|
|
165
|
+
ERROR: you have enabled cache_manifest in the #{Rails.env} env when using the
|
|
166
|
+
ReactOnRails::TestHelper.configure_rspec_to_compile_assets helper
|
|
167
|
+
To fix this: edit your config/webpacker.yml file and set cache_manifest to false for test.
|
|
168
|
+
MSG
|
|
169
|
+
puts wrap_message(msg)
|
|
170
|
+
exit!
|
|
171
|
+
end
|
|
111
172
|
end
|
|
112
173
|
end
|
|
@@ -36,7 +36,8 @@ module ReactOnRails
|
|
|
36
36
|
" gem: #{gem_version}\n" \
|
|
37
37
|
" node package: #{node_package_version.raw}\n" \
|
|
38
38
|
"Ensure the installed version of the gem is the same as the version of \n"\
|
|
39
|
-
"your installed node package
|
|
39
|
+
"your installed node package.\n"\
|
|
40
|
+
"Run `#{ReactOnRails::Utils.prepend_cd_node_modules_directory('yarn add react-on-rails')}`"
|
|
40
41
|
raise msg
|
|
41
42
|
end
|
|
42
43
|
|
data/lib/tasks/assets.rake
CHANGED
|
@@ -50,12 +50,20 @@ namespace :react_on_rails do
|
|
|
50
50
|
namespace :assets do
|
|
51
51
|
desc <<-DESC.strip_heredoc
|
|
52
52
|
Compile assets with webpack
|
|
53
|
-
Uses command defined with ReactOnRails.configuration.
|
|
54
|
-
|
|
53
|
+
Uses command defined with ReactOnRails.configuration.build_production_command
|
|
54
|
+
|
|
55
|
+
sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
|
|
55
56
|
DESC
|
|
56
57
|
task webpack: :locale do
|
|
57
|
-
if
|
|
58
|
-
|
|
58
|
+
if Rake::Task.task_defined?("webpacker:compile")
|
|
59
|
+
# TODO: Eventually, this will need reconsideration if we use any of the Webpacker compilation
|
|
60
|
+
Rake::Task["webpacker:compile"].clear
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
if ReactOnRails.configuration.build_production_command.present?
|
|
64
|
+
sh ReactOnRails::Utils.prepend_cd_node_modules_directory(
|
|
65
|
+
ReactOnRails.configuration.build_production_command
|
|
66
|
+
).to_s
|
|
59
67
|
end
|
|
60
68
|
end
|
|
61
69
|
end
|
data/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-on-rails",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "react-on-rails JavaScript for react_on_rails Ruby gem",
|
|
5
5
|
"main": "node_package/lib/ReactOnRails.js",
|
|
6
6
|
"directories": {
|
|
@@ -8,37 +8,37 @@
|
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"babel-cli": "^6.24.1",
|
|
11
|
-
"babel-core": "^6.
|
|
12
|
-
"babel-loader": "^
|
|
11
|
+
"babel-core": "^6.25.0",
|
|
12
|
+
"babel-loader": "^7.1.1",
|
|
13
13
|
"babel-plugin-react-transform": "^2.0.2",
|
|
14
14
|
"babel-plugin-transform-flow-strip-types": "^6.22.0",
|
|
15
15
|
"babel-plugin-transform-runtime": "^6.23.0",
|
|
16
16
|
"babel-preset-es2015": "^6.24.1",
|
|
17
17
|
"babel-preset-react": "^6.24.1",
|
|
18
18
|
"babel-preset-stage-2": "^6.24.1",
|
|
19
|
-
"babel-runtime": "^6.
|
|
19
|
+
"babel-runtime": "^6.25.0",
|
|
20
20
|
"babel-tape-runner": "^2.0.1",
|
|
21
|
-
"babel-types": "^6.
|
|
21
|
+
"babel-types": "^6.25.0",
|
|
22
22
|
"babelify": "^7.3.0",
|
|
23
23
|
"blue-tape": "^1.0.0",
|
|
24
|
-
"create-react-class": "^15.
|
|
24
|
+
"create-react-class": "^15.6.0",
|
|
25
25
|
"eslint": "^3.19.0",
|
|
26
|
-
"eslint-config-shakacode": "^
|
|
27
|
-
"eslint-plugin-import": "^2.
|
|
28
|
-
"eslint-plugin-jsx-a11y": "^
|
|
29
|
-
"eslint-plugin-react": "^
|
|
30
|
-
"flow-bin": "^0.
|
|
31
|
-
"jsdom": "^
|
|
32
|
-
"prop-types": "^15.5.
|
|
33
|
-
"react": "^15.
|
|
34
|
-
"react-dom": "^15.
|
|
26
|
+
"eslint-config-shakacode": "^15.0.0",
|
|
27
|
+
"eslint-plugin-import": "^2.6.1",
|
|
28
|
+
"eslint-plugin-jsx-a11y": "^5.1.1",
|
|
29
|
+
"eslint-plugin-react": "^7.1.0",
|
|
30
|
+
"flow-bin": "^0.51.1",
|
|
31
|
+
"jsdom": "^11.1.0",
|
|
32
|
+
"prop-types": "^15.5.10",
|
|
33
|
+
"react": "^15.6.1",
|
|
34
|
+
"react-dom": "^15.6.1",
|
|
35
35
|
"react-transform-hmr": "^1.0.4",
|
|
36
|
-
"redux": "^3.
|
|
37
|
-
"release-it": "^2.
|
|
36
|
+
"redux": "^3.7.2",
|
|
37
|
+
"release-it": "^2.8.2",
|
|
38
38
|
"tap-spec": "^4.1.1",
|
|
39
|
-
"tape": "^4.
|
|
40
|
-
"webpack": "^
|
|
41
|
-
"webpack-manifest-plugin": "^1.1
|
|
39
|
+
"tape": "^4.7.0",
|
|
40
|
+
"webpack": "^3.4.1",
|
|
41
|
+
"webpack-manifest-plugin": "^1.2.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"babel-runtime": ">= 6",
|
|
@@ -85,5 +85,9 @@
|
|
|
85
85
|
"bugs": {
|
|
86
86
|
"url": "https://github.com/shakacode/react_on_rails/issues"
|
|
87
87
|
},
|
|
88
|
-
"homepage": "https://github.com/shakacode/react_on_rails#readme"
|
|
88
|
+
"homepage": "https://github.com/shakacode/react_on_rails#readme",
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"react-on-rails": "^9.0.0-beta.12",
|
|
91
|
+
"react-redux": "^5.0.6"
|
|
92
|
+
}
|
|
89
93
|
}
|
data/rakelib/dummy_apps.rake
CHANGED
|
@@ -14,6 +14,15 @@ namespace :dummy_apps do
|
|
|
14
14
|
bundle_install_in(dummy_app_dir)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
task :dummy_no_webpacker do
|
|
18
|
+
npm_install_cmd = "npm install"
|
|
19
|
+
install_react_on_rails_cmd = "yarn run install-react-on-rails"
|
|
20
|
+
dummy_app_dir = File.join(gem_root, "spec/dummy_no_webpacker")
|
|
21
|
+
sh_in_dir(File.join(gem_root, "spec/dummy_no_webpacker/client"), npm_install_cmd)
|
|
22
|
+
sh_in_dir(dummy_app_dir, install_react_on_rails_cmd)
|
|
23
|
+
sh_in_dir(dummy_app_dir, "BUNDLE_GEMFILE=Gemfile.rails32 bundle install")
|
|
24
|
+
end
|
|
25
|
+
|
|
17
26
|
task dummy_apps: %i[dummy_app node_package] do
|
|
18
27
|
puts "Prepared all Dummy Apps"
|
|
19
28
|
end
|