webpacker 6.0.0.rc.1 → 6.0.0.rc.6
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/.github/workflows/jest.yml +6 -17
- data/.github/workflows/js-lint.yml +6 -17
- data/.github/workflows/ruby.yml +13 -38
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +15 -3
- data/CONTRIBUTING.md +19 -0
- data/Gemfile.lock +84 -84
- data/README.md +118 -164
- data/docs/developing_webpacker.md +4 -4
- data/docs/troubleshooting.md +5 -1
- data/docs/v6_upgrade.md +72 -34
- data/lib/install/{packs/entrypoints/application.js → application.js} +3 -7
- data/lib/install/bin/webpack +4 -7
- data/lib/install/bin/yarn +18 -0
- data/lib/install/config/webpacker.yml +16 -13
- data/lib/install/package.json +15 -0
- data/lib/install/template.rb +37 -15
- data/lib/tasks/yarn.rake +38 -0
- data/lib/webpacker/commands.rb +19 -15
- data/lib/webpacker/dev_server_runner.rb +1 -1
- data/lib/webpacker/helper.rb +2 -2
- data/lib/webpacker/railtie.rb +7 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +27 -7
- data/package/__tests__/development.js +4 -11
- data/package/config.js +3 -3
- data/package/env.js +3 -6
- data/package/environments/base.js +1 -1
- data/package/environments/development.js +34 -32
- data/package/rules/file.js +1 -1
- data/package.json +15 -15
- data/test/command_test.rb +76 -0
- data/test/dev_server_runner_test.rb +1 -1
- data/test/helper_test.rb +13 -4
- data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/test/webpacker_test.rb +4 -0
- data/webpacker.gemspec +2 -2
- data/yarn.lock +1392 -2825
- metadata +16 -11
@@ -12,41 +12,43 @@ let devConfig = {
|
|
12
12
|
}
|
13
13
|
|
14
14
|
if (runningWebpackDevServer) {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
const liveReload = devServer.live_reload !== undefined ? devServer.live_reload : !devServer.hmr
|
16
|
+
|
17
|
+
const devServerConfig = {
|
18
|
+
devMiddleware: {
|
19
|
+
publicPath
|
20
|
+
},
|
21
|
+
compress: devServer.compress,
|
22
|
+
allowedHosts: devServer.allowed_hosts,
|
23
|
+
host: devServer.host,
|
24
|
+
port: devServer.port,
|
25
|
+
https: devServer.https,
|
26
|
+
hot: devServer.hmr,
|
27
|
+
liveReload,
|
28
|
+
historyApiFallback: { disableDotRule: true },
|
29
|
+
headers: devServer.headers,
|
30
|
+
static: {
|
31
|
+
publicPath: contentBase
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
if (devServer.static) {
|
36
|
+
devServerConfig.static = { ...devServerConfig.static, ...devServer.static }
|
37
|
+
}
|
38
|
+
|
39
|
+
if (devServer.client) {
|
40
|
+
devServerConfig.client = devServer.client
|
19
41
|
}
|
20
42
|
|
21
43
|
devConfig = merge(devConfig, {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
hot: devServer.hmr,
|
31
|
-
contentBase,
|
32
|
-
inline: devServer.inline || devServer.hmr,
|
33
|
-
injectClient: devServer.hmr,
|
34
|
-
injectHot: devServer.hmr,
|
35
|
-
useLocalIp: devServer.use_local_ip,
|
36
|
-
public: devServer.public,
|
37
|
-
publicPath,
|
38
|
-
historyApiFallback: { disableDotRule: true },
|
39
|
-
headers: devServer.headers,
|
40
|
-
overlay: devServer.overlay,
|
41
|
-
stats: {
|
42
|
-
colors: true,
|
43
|
-
entrypoints: false,
|
44
|
-
errorDetails: true,
|
45
|
-
modules: false,
|
46
|
-
moduleTrace: false
|
47
|
-
},
|
48
|
-
watchOptions: devServer.watch_options
|
49
|
-
}
|
44
|
+
stats: {
|
45
|
+
colors: true,
|
46
|
+
entrypoints: false,
|
47
|
+
errorDetails: true,
|
48
|
+
modules: false,
|
49
|
+
moduleTrace: false
|
50
|
+
},
|
51
|
+
devServer: devServerConfig
|
50
52
|
})
|
51
53
|
}
|
52
54
|
|
data/package/rules/file.js
CHANGED
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rails/webpacker",
|
3
|
-
"version": "6.0.0-rc.
|
3
|
+
"version": "6.0.0-rc.6",
|
4
4
|
"description": "Use webpack to manage app-like JavaScript modules in Rails",
|
5
5
|
"main": "package/index.js",
|
6
6
|
"files": [
|
@@ -8,36 +8,36 @@
|
|
8
8
|
"lib/install/config/webpacker.yml"
|
9
9
|
],
|
10
10
|
"engines": {
|
11
|
-
"node": "
|
11
|
+
"node": ">= 12.13.0 || >=14",
|
12
12
|
"yarn": ">=1 <4"
|
13
13
|
},
|
14
14
|
"dependencies": {
|
15
|
-
"@babel/core": "^7.15.
|
15
|
+
"@babel/core": "^7.15.5",
|
16
16
|
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
17
17
|
"@babel/plugin-transform-runtime": "^7.15.0",
|
18
|
-
"@babel/preset-env": "^7.15.
|
19
|
-
"@babel/runtime": "^7.15.
|
18
|
+
"@babel/preset-env": "^7.15.6",
|
19
|
+
"@babel/runtime": "^7.15.4",
|
20
20
|
"babel-loader": "^8.2.2",
|
21
|
-
"compression-webpack-plugin": "^
|
22
|
-
"glob": "^7.
|
23
|
-
"js-yaml": "^
|
21
|
+
"compression-webpack-plugin": "^9.0.0",
|
22
|
+
"glob": "^7.2.0",
|
23
|
+
"js-yaml": "^4.1.0",
|
24
24
|
"path-complete-extname": "^1.0.0",
|
25
25
|
"pnp-webpack-plugin": "^1.7.0",
|
26
|
-
"terser-webpack-plugin": "^5.
|
27
|
-
"webpack": "^5.
|
26
|
+
"terser-webpack-plugin": "^5.2.4",
|
27
|
+
"webpack": "^5.53.0",
|
28
28
|
"webpack-assets-manifest": "^5.0.6",
|
29
29
|
"webpack-cli": "^4.8.0",
|
30
30
|
"webpack-merge": "^5.8.0",
|
31
|
-
"webpack-sources": "^3.2.
|
31
|
+
"webpack-sources": "^3.2.1"
|
32
32
|
},
|
33
33
|
"devDependencies": {
|
34
34
|
"eslint": "^7.32.0",
|
35
35
|
"eslint-config-airbnb": "^18.2.1",
|
36
|
-
"eslint-config-prettier": "^
|
37
|
-
"eslint-plugin-import": "^2.24.
|
36
|
+
"eslint-config-prettier": "^8.3.0",
|
37
|
+
"eslint-plugin-import": "^2.24.2",
|
38
38
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
39
|
-
"eslint-plugin-react": "^7.
|
40
|
-
"jest": "^
|
39
|
+
"eslint-plugin-react": "^7.26.0",
|
40
|
+
"jest": "^27.2.1"
|
41
41
|
},
|
42
42
|
"jest": {
|
43
43
|
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|
data/test/command_test.rb
CHANGED
@@ -31,3 +31,79 @@ class CommandTest < Minitest::Test
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
class ClearCommandVersioningTest < Minitest::Test
|
36
|
+
def setup
|
37
|
+
@now = Time.parse("2021-01-01 12:34:56 UTC")
|
38
|
+
# Test assets to be kept and deleted, path and mtime
|
39
|
+
@prev_files = {
|
40
|
+
# recent versions to be kept with Webpacker.commands.clean(count = 2)
|
41
|
+
"js/application-deadbeef.js" => @now - 4000,
|
42
|
+
"js/common-deadbeee.js" => @now - 4002,
|
43
|
+
"css/common-deadbeed.css" => @now - 4004,
|
44
|
+
"media/images/logo-deadbeeb.css" => @now - 4006,
|
45
|
+
"js/application-1eadbeef.js" => @now - 8000,
|
46
|
+
"js/common-1eadbeee.js" => @now - 8002,
|
47
|
+
"css/common-1eadbeed.css" => @now - 8004,
|
48
|
+
"media/images/logo-1eadbeeb.css" => @now - 8006,
|
49
|
+
# new files to be kept with Webpacker.commands.clean(age = 3600)
|
50
|
+
"js/brandnew-0001.js" => @now,
|
51
|
+
"js/brandnew-0002.js" => @now - 10,
|
52
|
+
"js/brandnew-0003.js" => @now - 20,
|
53
|
+
"js/brandnew-0004.js" => @now - 40,
|
54
|
+
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
55
|
+
@expired_files = {
|
56
|
+
# old files that are outside count = 2 or age = 3600 and to be deleted
|
57
|
+
"js/application-0eadbeef.js" => @now - 9000,
|
58
|
+
"js/common-0eadbeee.js" => @now - 9002,
|
59
|
+
"css/common-0eadbeed.css" => @now - 9004,
|
60
|
+
"js/brandnew-0005.js" => @now - 3640,
|
61
|
+
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
62
|
+
@all_files = @prev_files.merge(@expired_files)
|
63
|
+
@dir_glob_stub = Proc.new { |arg|
|
64
|
+
case arg
|
65
|
+
when "#{Webpacker.config.public_output_path}/**/*"
|
66
|
+
@all_files.keys
|
67
|
+
else
|
68
|
+
[]
|
69
|
+
end
|
70
|
+
}
|
71
|
+
@file_mtime_stub = Proc.new { |longpath|
|
72
|
+
@all_files[longpath]
|
73
|
+
}
|
74
|
+
@file_delete_mock = Minitest::Mock.new
|
75
|
+
@expired_files.keys.each do |longpath|
|
76
|
+
@file_delete_mock.expect(:delete, 1, [longpath])
|
77
|
+
end
|
78
|
+
@file_delete_stub = Proc.new { |longpath|
|
79
|
+
if @prev_files.has_key?(longpath)
|
80
|
+
flunk "#{longpath} should not be deleted"
|
81
|
+
else
|
82
|
+
@file_delete_mock.delete(longpath)
|
83
|
+
end
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def time_and_files_stub(&proc)
|
88
|
+
Time.stub :now, @now do
|
89
|
+
Dir.stub :glob, @dir_glob_stub do
|
90
|
+
File.stub :directory?, false do
|
91
|
+
File.stub :file?, true do
|
92
|
+
File.stub :mtime, @file_mtime_stub do
|
93
|
+
File.stub :delete, @file_delete_stub do
|
94
|
+
yield proc
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
@file_delete_mock.verify
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_clean_command_with_versioned_files
|
105
|
+
time_and_files_stub do
|
106
|
+
assert Webpacker.commands.clean
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -50,7 +50,7 @@ class DevServerRunnerTest < Webpacker::Test
|
|
50
50
|
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
|
51
51
|
env = Webpacker::Compiler.env.dup
|
52
52
|
ENV["WEBPACKER_CONFIG"] = env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
|
53
|
-
env["
|
53
|
+
env["WEBPACK_SERVE"] = "true"
|
54
54
|
verify_command(cmd, env: env)
|
55
55
|
end
|
56
56
|
|
data/test/helper_test.rb
CHANGED
@@ -96,12 +96,21 @@ class HelperTest < ActionView::TestCase
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_javascript_pack_tag
|
99
|
+
assert_equal \
|
100
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
101
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
102
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>\n) +
|
103
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>),
|
104
|
+
javascript_pack_tag("application", "bootstrap")
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_javascript_pack_with_no_defer_tag
|
99
108
|
assert_equal \
|
100
109
|
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
101
110
|
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
102
111
|
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>\n) +
|
103
112
|
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
104
|
-
javascript_pack_tag("application", "bootstrap")
|
113
|
+
javascript_pack_tag("application", "bootstrap", defer: false)
|
105
114
|
end
|
106
115
|
|
107
116
|
def test_javascript_pack_tag_splat
|
@@ -114,9 +123,9 @@ class HelperTest < ActionView::TestCase
|
|
114
123
|
|
115
124
|
def test_javascript_pack_tag_symbol
|
116
125
|
assert_equal \
|
117
|
-
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
118
|
-
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
119
|
-
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
|
126
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
127
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
128
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
120
129
|
javascript_pack_tag(:application)
|
121
130
|
end
|
122
131
|
|
@@ -0,0 +1 @@
|
|
1
|
+
$test_app_autoload_paths_in_initializer = ActiveSupport::Dependencies.autoload_paths
|
data/test/webpacker_test.rb
CHANGED
data/webpacker.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
"changelog_uri" => "https://github.com/rails/webpacker/blob/v#{Webpacker::VERSION}/CHANGELOG.md"
|
16
16
|
}
|
17
17
|
|
18
|
-
s.required_ruby_version = ">= 2.
|
18
|
+
s.required_ruby_version = ">= 2.7.0"
|
19
19
|
|
20
20
|
s.add_dependency "activesupport", ">= 5.2"
|
21
21
|
s.add_dependency "railties", ">= 5.2"
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency "semantic_range", ">= 2.3.0"
|
24
24
|
|
25
25
|
s.add_development_dependency "bundler", ">= 1.3.0"
|
26
|
-
s.add_development_dependency "rubocop"
|
26
|
+
s.add_development_dependency "rubocop"
|
27
27
|
s.add_development_dependency "rubocop-performance"
|
28
28
|
|
29
29
|
s.files = `git ls-files`.split("\n")
|