webpacker 6.0.0.rc.3 → 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.
@@ -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
- directory "#{__dir__}/packs", Webpacker.config.source_path
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
- # Install only production deps when for not usual envs.
9
- valid_node_envs = %w[test development production]
10
- node_env = ENV.fetch("NODE_ENV") do
11
- valid_node_envs.include?(Rails.env) ? Rails.env : "production"
12
- end
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
- system(
22
- { "NODE_ENV" => node_env },
23
- "#{RbConfig.ruby} \"#{Rails.root}/bin/yarn\" install #{yarn_flags}",
24
- exception: true
25
- )
26
- rescue Errno::ENOENT
27
- $stderr.puts "bin/yarn was not found."
28
- $stderr.puts "Please run `bundle exec rails app:update:bin` to create it."
29
- exit 1
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
 
@@ -65,7 +65,7 @@ module Webpacker
65
65
  def execute_cmd
66
66
  env = Webpacker::Compiler.env
67
67
  env["WEBPACKER_CONFIG"] = @webpacker_config
68
- env["WEBPACK_DEV_SERVER"] = "true"
68
+ env["WEBPACK_SERVE"] = "true"
69
69
 
70
70
  cmd = if node_modules_bin_exist?
71
71
  ["#{@node_modules_bin_path}/webpack", "serve"]
@@ -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
@@ -1,4 +1,4 @@
1
1
  module Webpacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "6.0.0.rc.3".freeze
3
+ VERSION = "6.0.0.rc.6".freeze
4
4
  end
@@ -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.include?("--debug-webpacker")
17
- cmd = [ "node", "--inspect-brk"] + cmd
18
- @argv.delete "--debug-webpacker"
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
- if @argv.include?("--trace-deprecation")
22
- cmd = [ "node", "--trace-deprecation"] + cmd
23
- @argv.delete "--trace-deprecation"
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 += ["--config", @webpack_config] + @argv
46
+ cmd += @argv
27
47
 
28
48
  Dir.chdir(@app_path) do
29
49
  Kernel.exec env, *cmd
@@ -11,27 +11,20 @@ describe('Development environment', () => {
11
11
  describe('webpackConfig', () => {
12
12
  beforeEach(() => jest.resetModules())
13
13
 
14
- test('should use development config and environment including devServer if WEBPACK_DEV_SERVER', () => {
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.WEBPACK_DEV_SERVER = 'true'
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
- test('should use development config and environment if WEBPACK_DEV_SERVER', () => {
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.WEBPACK_DEV_SERVER = undefined
27
+ process.env.WEBPACK_SERVE = undefined
35
28
  const { webpackConfig } = require('../index')
36
29
 
37
30
  expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
data/package/env.js CHANGED
@@ -16,10 +16,7 @@ const config = load(readFileSync(configPath), 'utf8')
16
16
  const availableEnvironments = Object.keys(config).join('|')
17
17
  const regex = new RegExp(`^(${availableEnvironments})$`, 'g')
18
18
 
19
- // v4 of webpack-dev-server will switch to WEBPACK_DEV_SERVE
20
- // https://github.com/rails/webpacker/issues/3057
21
- const runningWebpackDevServer = process.env.WEBPACK_DEV_SERVER === 'true' ||
22
- process.env.WEBPACK_DEV_SERVE === 'true'
19
+ const runningWebpackDevServer = process.env.WEBPACK_SERVE === 'true'
23
20
 
24
21
  module.exports = {
25
22
  railsEnv: railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT,
@@ -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}/**/*.*`).forEach((path) => {
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
- if (devServer.hmr) {
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: !devServer.hmr,
27
+ liveReload,
32
28
  historyApiFallback: { disableDotRule: true },
33
29
  headers: devServer.headers,
34
30
  static: {
@@ -18,6 +18,6 @@ module.exports = {
18
18
  exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
19
19
  type: 'asset/resource',
20
20
  generator: {
21
- filename: 'static/[hash][ext][query]'
21
+ filename: 'static/[name]-[hash][ext][query]'
22
22
  }
23
23
  }
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rails/webpacker",
3
- "version": "6.0.0-rc.3",
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.0",
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.0",
19
- "@babel/runtime": "^7.15.3",
18
+ "@babel/preset-env": "^7.15.6",
19
+ "@babel/runtime": "^7.15.4",
20
20
  "babel-loader": "^8.2.2",
21
- "compression-webpack-plugin": "^8.0.1",
22
- "glob": "^7.1.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.1.4",
27
- "webpack": "^5.51.1",
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.0"
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.1",
37
+ "eslint-plugin-import": "^2.24.2",
38
38
  "eslint-plugin-jsx-a11y": "^6.4.1",
39
- "eslint-plugin-react": "^7.24.0",
40
- "jest": "^27.0.6"
39
+ "eslint-plugin-react": "^7.26.0",
40
+ "jest": "^27.2.1"
41
41
  },
42
42
  "jest": {
43
43
  "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
@@ -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["WEBPACK_DEV_SERVER"] = "true"
53
+ env["WEBPACK_SERVE"] = "true"
54
54
  verify_command(cmd, env: env)
55
55
  end
56
56
 
@@ -0,0 +1 @@
1
+ $test_app_autoload_paths_in_initializer = ActiveSupport::Dependencies.autoload_paths
@@ -27,4 +27,8 @@ class WebpackerTest < Webpacker::Test
27
27
  assert Webpacker.inlining_css?
28
28
  end
29
29
  end
30
+
31
+ def test_app_autoload_paths_cleanup
32
+ assert_empty $test_app_autoload_paths_in_initializer
33
+ end
30
34
  end
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.4.0"
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"