webpacker 6.0.0.rc.5 → 6.0.0.rc.6
Sign up to get free protection for your applications and to get access to all the features.
- 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 +7 -7
- data/README.md +28 -19
- data/docs/troubleshooting.md +5 -1
- data/docs/v6_upgrade.md +68 -30
- data/lib/install/{packs/entrypoints/application.js → application.js} +3 -7
- data/lib/install/bin/webpack +4 -7
- data/lib/install/config/webpacker.yml +4 -2
- data/lib/install/package.json +0 -2
- data/lib/install/template.rb +10 -1
- data/lib/tasks/yarn.rake +22 -20
- 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 +2 -9
- data/package/environments/base.js +1 -1
- data/package/environments/development.js +2 -6
- data/package/rules/file.js +1 -1
- data/package.json +12 -12
- data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/test/webpacker_test.rb +4 -0
- data/webpacker.gemspec +1 -1
- data/yarn.lock +1081 -1508
- metadata +9 -7
data/lib/install/template.rb
CHANGED
@@ -9,7 +9,8 @@ if Dir.exists?(Webpacker.config.source_path)
|
|
9
9
|
say "The packs app source directory already exists"
|
10
10
|
else
|
11
11
|
say "Creating packs app source directory"
|
12
|
-
|
12
|
+
empty_directory "app/javascript"
|
13
|
+
copy_file "#{__dir__}/application.js", "app/javascript/application.js"
|
13
14
|
end
|
14
15
|
|
15
16
|
apply "#{__dir__}/binstubs.rb"
|
@@ -53,6 +54,14 @@ Rails.application.config.assets.paths << Rails.root.join("node_modules")
|
|
53
54
|
RUBY
|
54
55
|
end
|
55
56
|
|
57
|
+
if (csp_config_path = Rails.root.join("config/initializers/content_security_policy.rb")).exist?
|
58
|
+
say "Make note of webpack-dev-server exemption needed to csp"
|
59
|
+
insert_into_file csp_config_path, <<-RUBY, after: %(# Rails.application.config.content_security_policy do |policy|)
|
60
|
+
# # If you are using webpack-dev-server then specify webpack-dev-server host
|
61
|
+
# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
|
62
|
+
RUBY
|
63
|
+
end
|
64
|
+
|
56
65
|
results = []
|
57
66
|
|
58
67
|
Dir.chdir(Rails.root) do
|
data/lib/tasks/yarn.rake
CHANGED
@@ -5,28 +5,30 @@
|
|
5
5
|
namespace :yarn do
|
6
6
|
desc "Install all JavaScript dependencies as specified via Yarn"
|
7
7
|
task :install do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
yarn_flags =
|
15
|
-
if `#{RbConfig.ruby} "#{Rails.root}/bin/yarn" --version`.start_with?("1")
|
16
|
-
"--no-progress --frozen-lockfile"
|
17
|
-
else
|
18
|
-
"--immutable"
|
8
|
+
begin
|
9
|
+
# Install only production deps when for not usual envs.
|
10
|
+
valid_node_envs = %w[test development production]
|
11
|
+
node_env = ENV.fetch("NODE_ENV") do
|
12
|
+
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
|
19
13
|
end
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
yarn_flags =
|
16
|
+
if `#{RbConfig.ruby} "#{Rails.root}/bin/yarn" --version`.start_with?("1")
|
17
|
+
"--no-progress --frozen-lockfile"
|
18
|
+
else
|
19
|
+
"--immutable"
|
20
|
+
end
|
21
|
+
|
22
|
+
system(
|
23
|
+
{ "NODE_ENV" => node_env },
|
24
|
+
"#{RbConfig.ruby} \"#{Rails.root}/bin/yarn\" install #{yarn_flags}",
|
25
|
+
exception: true
|
26
|
+
)
|
27
|
+
rescue Errno::ENOENT
|
28
|
+
$stderr.puts "bin/yarn was not found."
|
29
|
+
$stderr.puts "Please run `bundle exec rails app:update:bin` to create it."
|
30
|
+
exit 1
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
data/lib/webpacker/railtie.rb
CHANGED
@@ -51,4 +51,11 @@ class Webpacker::Engine < ::Rails::Engine
|
|
51
51
|
app.config.javascript_path = Webpacker.config.source_path.relative_path_from(Rails.root.join("app")).to_s
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
initializer "webpacker.remove_app_packs_from_the_autoload_paths" do
|
56
|
+
Rails.application.config.before_initialize do
|
57
|
+
source_path = Webpacker.config.source_path.to_s
|
58
|
+
ActiveSupport::Dependencies.autoload_paths.delete(source_path)
|
59
|
+
end
|
60
|
+
end
|
54
61
|
end
|
data/lib/webpacker/version.rb
CHANGED
@@ -3,6 +3,19 @@ require "webpacker/runner"
|
|
3
3
|
|
4
4
|
module Webpacker
|
5
5
|
class WebpackRunner < Webpacker::Runner
|
6
|
+
WEBPACK_COMMANDS = [
|
7
|
+
"help",
|
8
|
+
"h",
|
9
|
+
"--help",
|
10
|
+
"-h",
|
11
|
+
"version",
|
12
|
+
"v",
|
13
|
+
"--version",
|
14
|
+
"-v",
|
15
|
+
"info",
|
16
|
+
"i"
|
17
|
+
].freeze
|
18
|
+
|
6
19
|
def run
|
7
20
|
env = Webpacker::Compiler.env
|
8
21
|
env["WEBPACKER_CONFIG"] = @webpacker_config
|
@@ -13,17 +26,24 @@ module Webpacker
|
|
13
26
|
["yarn", "webpack"]
|
14
27
|
end
|
15
28
|
|
16
|
-
if @argv.
|
17
|
-
cmd = [
|
18
|
-
|
29
|
+
if @argv.delete "--debug-webpacker"
|
30
|
+
cmd = ["node", "--inspect-brk"] + cmd
|
31
|
+
end
|
32
|
+
|
33
|
+
if @argv.delete "--trace-deprecation"
|
34
|
+
cmd = ["node", "--trace-deprecation"] + cmd
|
35
|
+
end
|
36
|
+
|
37
|
+
if @argv.delete "--no-deprecation"
|
38
|
+
cmd = ["node", "--no-deprecation"] + cmd
|
19
39
|
end
|
20
40
|
|
21
|
-
|
22
|
-
|
23
|
-
|
41
|
+
# Webpack commands are not compatible with --config option.
|
42
|
+
if (@argv & WEBPACK_COMMANDS).empty?
|
43
|
+
cmd += ["--config", @webpack_config]
|
24
44
|
end
|
25
45
|
|
26
|
-
cmd +=
|
46
|
+
cmd += @argv
|
27
47
|
|
28
48
|
Dir.chdir(@app_path) do
|
29
49
|
Kernel.exec env, *cmd
|
@@ -14,24 +14,17 @@ describe('Development environment', () => {
|
|
14
14
|
test('should use development config and environment including devServer if WEBPACK_SERVE', () => {
|
15
15
|
process.env.RAILS_ENV = 'development'
|
16
16
|
process.env.NODE_ENV = 'development'
|
17
|
-
process.env.
|
17
|
+
process.env.WEBPACK_SERVE = 'true'
|
18
18
|
const { webpackConfig } = require('../index')
|
19
19
|
|
20
20
|
expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
|
21
21
|
expect(webpackConfig.output.publicPath).toEqual('/packs/')
|
22
|
-
expect(webpackConfig).toMatchObject({
|
23
|
-
devServer: {
|
24
|
-
host: 'localhost',
|
25
|
-
port: 3035,
|
26
|
-
hot: false
|
27
|
-
}
|
28
|
-
})
|
29
22
|
})
|
30
23
|
|
31
24
|
test('should use development config and environment if WEBPACK_SERVE', () => {
|
32
25
|
process.env.RAILS_ENV = 'development'
|
33
26
|
process.env.NODE_ENV = 'development'
|
34
|
-
process.env.
|
27
|
+
process.env.WEBPACK_SERVE = undefined
|
35
28
|
const { webpackConfig } = require('../index')
|
36
29
|
|
37
30
|
expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
|
@@ -16,7 +16,7 @@ const getEntryObject = () => {
|
|
16
16
|
const entries = {}
|
17
17
|
const rootPath = join(config.source_path, config.source_entry_path)
|
18
18
|
|
19
|
-
globSync(`${rootPath}
|
19
|
+
globSync(`${rootPath}/*.*`).forEach((path) => {
|
20
20
|
const namespace = relative(join(rootPath), dirname(path))
|
21
21
|
const name = join(namespace, basename(path, extname(path)))
|
22
22
|
let assetPaths = resolve(path)
|
@@ -12,11 +12,7 @@ let devConfig = {
|
|
12
12
|
}
|
13
13
|
|
14
14
|
if (runningWebpackDevServer) {
|
15
|
-
|
16
|
-
devConfig = merge(devConfig, {
|
17
|
-
output: { filename: '[name]-[hash].js' }
|
18
|
-
})
|
19
|
-
}
|
15
|
+
const liveReload = devServer.live_reload !== undefined ? devServer.live_reload : !devServer.hmr
|
20
16
|
|
21
17
|
const devServerConfig = {
|
22
18
|
devMiddleware: {
|
@@ -28,7 +24,7 @@ if (runningWebpackDevServer) {
|
|
28
24
|
port: devServer.port,
|
29
25
|
https: devServer.https,
|
30
26
|
hot: devServer.hmr,
|
31
|
-
liveReload
|
27
|
+
liveReload,
|
32
28
|
historyApiFallback: { disableDotRule: true },
|
33
29
|
headers: devServer.headers,
|
34
30
|
static: {
|
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": [
|
@@ -12,32 +12,32 @@
|
|
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.
|
21
|
+
"compression-webpack-plugin": "^9.0.0",
|
22
|
+
"glob": "^7.2.0",
|
23
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
36
|
"eslint-config-prettier": "^8.3.0",
|
37
|
-
"eslint-plugin-import": "^2.24.
|
37
|
+
"eslint-plugin-import": "^2.24.2",
|
38
38
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
39
|
-
"eslint-plugin-react": "^7.
|
40
|
-
"jest": "^27.
|
39
|
+
"eslint-plugin-react": "^7.26.0",
|
40
|
+
"jest": "^27.2.1"
|
41
41
|
},
|
42
42
|
"jest": {
|
43
43
|
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|
@@ -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"
|