Skip to content

Commit 3fa3c54

Browse files
authored
Refactor and minor improvements (#1280)
* Update gemfiles with x86_64-linux deps * Improve style * Simplify method body * Improve file name and required packages * Add commented entry in common config for ignoring warning
1 parent 6bf3b59 commit 3fa3c54

12 files changed

+38
-29
lines changed

gemfiles/no_sprockets.gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ GEM
169169
nio4r (2.5.9)
170170
nokogiri (1.13.8-x86_64-darwin)
171171
racc (~> 1.4)
172+
nokogiri (1.13.8-x86_64-linux)
173+
racc (~> 1.4)
172174
notiffany (0.1.3)
173175
nenv (~> 0.1)
174176
shellany (~> 0.0)
@@ -243,6 +245,7 @@ GEM
243245

244246
PLATFORMS
245247
x86_64-darwin-20
248+
x86_64-linux
246249

247250
DEPENDENCIES
248251
appraisal

gemfiles/no_sprockets_shakapacker.gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ GEM
171171
nio4r (2.5.9)
172172
nokogiri (1.14.3-x86_64-darwin)
173173
racc (~> 1.4)
174+
nokogiri (1.14.3-x86_64-linux)
175+
racc (~> 1.4)
174176
notiffany (0.1.3)
175177
nenv (~> 0.1)
176178
shellany (~> 0.0)
@@ -256,6 +258,7 @@ GEM
256258

257259
PLATFORMS
258260
x86_64-darwin-20
261+
x86_64-linux
259262

260263
DEPENDENCIES
261264
appraisal

gemfiles/sprockets_3.gemfile.lock

+4
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ GEM
141141
activesupport (>= 4.2.0)
142142
json (2.3.0)
143143
libv8 (7.3.492.27.1-x86_64-darwin-20)
144+
libv8 (7.3.492.27.1-x86_64-linux)
144145
listen (3.0.8)
145146
rb-fsevent (~> 0.9, >= 0.9.4)
146147
rb-inotify (~> 0.9, >= 0.9.7)
@@ -172,6 +173,8 @@ GEM
172173
nio4r (2.5.9)
173174
nokogiri (1.13.8-x86_64-darwin)
174175
racc (~> 1.4)
176+
nokogiri (1.13.8-x86_64-linux)
177+
racc (~> 1.4)
175178
notiffany (0.1.3)
176179
nenv (~> 0.1)
177180
shellany (~> 0.0)
@@ -256,6 +259,7 @@ GEM
256259

257260
PLATFORMS
258261
x86_64-darwin-20
262+
x86_64-linux
259263

260264
DEPENDENCIES
261265
appraisal

gemfiles/sprockets_4.gemfile.lock

+4
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ GEM
141141
activesupport (>= 4.2.0)
142142
json (2.3.0)
143143
libv8 (7.3.492.27.1-x86_64-darwin-20)
144+
libv8 (7.3.492.27.1-x86_64-linux)
144145
listen (3.0.8)
145146
rb-fsevent (~> 0.9, >= 0.9.4)
146147
rb-inotify (~> 0.9, >= 0.9.7)
@@ -172,6 +173,8 @@ GEM
172173
nio4r (2.5.9)
173174
nokogiri (1.13.8-x86_64-darwin)
174175
racc (~> 1.4)
176+
nokogiri (1.13.8-x86_64-linux)
177+
racc (~> 1.4)
175178
notiffany (0.1.3)
176179
nenv (~> 0.1)
177180
shellany (~> 0.0)
@@ -256,6 +259,7 @@ GEM
256259

257260
PLATFORMS
258261
x86_64-darwin-20
262+
x86_64-linux
259263

260264
DEPENDENCIES
261265
appraisal

lib/react/server_rendering/bundle_renderer.rb

+15-21
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ def asset_container
7171
def prepare_options(options)
7272
r_func = render_function(options)
7373
opts = case options
74-
when Hash then options
75-
when TrueClass then {}
76-
else
77-
{}
78-
end
74+
when Hash then options
75+
when TrueClass then {}
76+
else
77+
{}
78+
end
7979
# This seems redundant to pass
8080
opts.merge(render_function: r_func)
8181
end
@@ -100,22 +100,16 @@ def assets_precompiled?
100100
# Or, if the user has provided {.asset_container_class}, use that.
101101
# @return [Class] suitable for {#asset_container}
102102
def asset_container_class
103-
if self.class.asset_container_class.present?
104-
self.class.asset_container_class
105-
elsif SeparateServerBundleContainer.compatible?
106-
SeparateServerBundleContainer
107-
elsif assets_precompiled?
108-
if ManifestContainer.compatible?
109-
ManifestContainer
110-
elsif YamlManifestContainer.compatible?
111-
YamlManifestContainer
112-
else
113-
# Even though they are precompiled, we can't find them :S
114-
EnvironmentContainer
115-
end
116-
else
117-
EnvironmentContainer
118-
end
103+
return self.class.asset_container_class if self.class.asset_container_class.present?
104+
return SeparateServerBundleContainer if SeparateServerBundleContainer.compatible?
105+
106+
return EnvironmentContainer unless assets_precompiled?
107+
108+
return ManifestContainer if ManifestContainer.compatible?
109+
return YamlManifestContainer if YamlManifestContainer.compatible?
110+
111+
# Even though they are precompiled, we can't find them :S
112+
EnvironmentContainer
119113
end
120114
end
121115
end

test/dummy/config/webpack/commonWebpackConfig.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const commonOptions = {
1717
]
1818
}
1919
]
20-
}
20+
},
21+
// Uncommemt if getting "Module not found: Error: Can't resolve 'react-dom/client'" warning
22+
// ignoreWarnings: [/Module not found: Error: Can't resolve 'react-dom\/client'/]
2123
}
2224

2325
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals

test/dummy/config/webpack/development.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const path = require('path')
21
const { devServer, inliningCss } = require('shakapacker')
32

4-
const webpackConfig = require('./ServerClientOrBoth')
3+
const webpackConfig = require('./serverClientOrBoth')
54

65
const developmentEnvOnly = (clientWebpackConfig, serverWebpackConfig) => {
76

test/dummy/config/webpack/production.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Below code should get refactored but the current way that rails/webpacker v5
22
// does the globals, it's tricky
3-
const webpackConfig = require('./ServerClientOrBoth')
3+
const webpackConfig = require('./serverClientOrBoth')
44

55
const productionEnvOnly = (_clientWebpackConfig, _serverWebpackConfig) => {
66
// place any code here that is for production only

test/dummy/config/webpack/serverWebpackConfig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
const webpack = require('webpack')
2+
13
const { merge, config } = require('shakapacker')
24
const commonWebpackConfig = require('./commonWebpackConfig')
35

4-
const webpack = require('webpack')
5-
66
const configureServer = () => {
77
// We need to use "merge" because the clientConfigObject, EVEN after running
88
// toWebpackConfig() is a mutable GLOBAL. Thus any changes, like modifying the

test/dummy/config/webpack/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const webpackConfig = require('./ServerClientOrBoth')
1+
const webpackConfig = require('./serverClientOrBoth')
22

33
const testOnly = (_clientWebpackConfig, _serverWebpackConfig) => {
44
// place any code here that is for test only

test/dummy/config/webpack/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { env, webpackConfig } = require('shakapacker');
21
const { existsSync } = require('fs');
32
const { resolve } = require('path');
3+
const { env, webpackConfig } = require('shakapacker');
44

55
const envSpecificConfig = () => {
66
const path = resolve(__dirname, `${env.nodeEnv}.js`);

0 commit comments

Comments
 (0)