shakapacker 7.2.0.rc.0 → 7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dummy.yml +8 -1
  3. data/.github/workflows/generator.yml +10 -1
  4. data/.github/workflows/jest.yml +5 -1
  5. data/.github/workflows/js-lint.yml +5 -1
  6. data/.github/workflows/rubocop.yml +5 -1
  7. data/.github/workflows/ruby-backward-compatibility.yml +5 -1
  8. data/.github/workflows/ruby.yml +5 -1
  9. data/CHANGELOG.md +21 -1
  10. data/docs/v6_upgrade.md +1 -1
  11. data/lib/install/config/shakapacker.yml +5 -2
  12. data/lib/shakapacker/configuration.rb +14 -2
  13. data/lib/shakapacker/dev_server.rb +7 -1
  14. data/lib/shakapacker/dev_server_runner.rb +5 -2
  15. data/lib/shakapacker/digest_strategy.rb +3 -1
  16. data/lib/shakapacker/version.rb +1 -1
  17. data/package.json +51 -51
  18. data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +84 -18
  19. data/spec/backward_compatibility_specs/digest_strategy_spec.rb +1 -0
  20. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker.yml +1 -1
  21. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +1 -1
  22. data/spec/dummy/Gemfile +0 -2
  23. data/spec/dummy/package.json +1 -2
  24. data/spec/shakapacker/compiler_spec.rb +5 -9
  25. data/spec/shakapacker/configuration_spec.rb +61 -13
  26. data/spec/shakapacker/dev_server_runner_spec.rb +100 -18
  27. data/spec/shakapacker/digest_strategy_spec.rb +22 -0
  28. data/spec/shakapacker/spec_helper_initializer.rb +0 -18
  29. data/spec/shakapacker/test_app/config/shakapacker.yml +1 -1
  30. data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +1 -1
  31. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7c6cb64c439d97ec52580010225f4b2204ea652e281926da18b21be6c7ef545
4
- data.tar.gz: 33adeb8d524cd2c08206bc1b06c3183cd44f469c7c44b453466ea149baceb30d
3
+ metadata.gz: 1e486b8d36133595f767f26dd8461b1b57fbea6daeba86eaa79b2f3ffcf7dbd2
4
+ data.tar.gz: 94b19f6397652a9abbfc3e80ef51ead55d0aec78191ab7bd36383e3ae37f5fce
5
5
  SHA512:
6
- metadata.gz: 22c9e5716abf6528ab34f652a6b145cb97897769b7c9f4da09f63b9090ce3a2faea507db94cc6fcd87cdf5be8bc60be0881ffd2f9f1f7a5d218d37d759021ffc
7
- data.tar.gz: c3a299a84e15d15216d9e6e8c83513b6a9d0ca805587b80779e7e6b8bafd0e8f7090686a6fd82da1eecd829d25a68bf8df25ebf7bec1f82213918edb83953f92
6
+ metadata.gz: 328d290b9d5bf040aea4239675196975569fb0606e1d93c49bdaf73b0b87d5d2267b3f1069ff26297991016e1c6aad5a8d9fad782bfa17a4898cac95cf421d6d
7
+ data.tar.gz: d3067ddec4711898c5a0dcc63b854372917600ecb2019b57c4153bd2a16bf24ce56ec015de3023f46980f7a660ee25e610623339a5b49b1f0e342cbb7dfbead4
@@ -1,6 +1,10 @@
1
1
  name: Dummy specs
2
2
 
3
- on: [push, pull_request]
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'master'
7
+ pull_request:
4
8
 
5
9
  jobs:
6
10
  test:
@@ -10,6 +14,9 @@ jobs:
10
14
  - uses: actions/checkout@v4
11
15
  with:
12
16
  persist-credentials: false
17
+ - uses: actions/setup-node@v3
18
+ with:
19
+ node-version: '16'
13
20
  - uses: ruby/setup-ruby@v1
14
21
  with:
15
22
  ruby-version: '3.1.2'
@@ -1,6 +1,10 @@
1
1
  name: Generator specs
2
2
 
3
- on: [push, pull_request]
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'master'
7
+ pull_request:
4
8
 
5
9
  jobs:
6
10
  test:
@@ -35,6 +39,11 @@ jobs:
35
39
  - uses: ruby/setup-ruby@v1
36
40
  with:
37
41
  ruby-version: ${{ matrix.ruby }}
42
+ # Bundler 2.5.0 dropped support for Ruby 2.6 and 2.7
43
+ - name: Use Bundler 2.4.22
44
+ run: |
45
+ gem install bundler -v '2.4.22'
46
+ bundle config --local path vendor/bundle
38
47
  - name: Install dependencies
39
48
  run: bundle install
40
49
  - run: bundle exec rake run_spec:generator
@@ -1,6 +1,10 @@
1
1
  name: Jest specs
2
2
 
3
- on: [push, pull_request]
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'master'
7
+ pull_request:
4
8
 
5
9
  jobs:
6
10
  jest:
@@ -1,6 +1,10 @@
1
1
  name: JS lint
2
2
 
3
- on: [push, pull_request]
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'master'
7
+ pull_request:
4
8
 
5
9
  jobs:
6
10
  lint:
@@ -1,6 +1,10 @@
1
1
  name: Rubocop
2
2
 
3
- on: [push, pull_request]
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'master'
7
+ pull_request:
4
8
 
5
9
  jobs:
6
10
  rubocop:
@@ -1,6 +1,10 @@
1
1
  name: Ruby specs - Backward compatibility
2
2
 
3
- on: [push, pull_request]
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'master'
7
+ pull_request:
4
8
 
5
9
  jobs:
6
10
  test:
@@ -1,6 +1,10 @@
1
1
  name: Ruby specs
2
2
 
3
- on: [push, pull_request]
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'master'
7
+ pull_request:
4
8
 
5
9
  jobs:
6
10
  test:
data/CHANGELOG.md CHANGED
@@ -9,8 +9,26 @@ Changes since the last non-beta release.
9
9
 
10
10
  _Please add entries here for your pull requests that are not yet released._
11
11
 
12
+ ## [v7.2.1] - December 30, 2023
13
+
14
+ ### Fixed
15
+ - Show deprecation message for `relative_url_root` only if it is set. [PR 400](https://github.com/shakacode/shakapacker/pull/400) by [ahangarha](https://github.com/ahangarha).
16
+
17
+ ## [v7.2.0] - December 28, 2023
18
+
12
19
  ### Added
13
20
  - Experimental support for other JS package managers using `package_json` gem [PR 349](https://github.com/shakacode/shakapacker/pull/349) by [G-Rath](https://github.com/g-rath).
21
+ - Support `hmr: only` configuration [PR 378](https://github.com/shakacode/shakapacker/pull/378) by [SimenB](https://github.com/SimenB).
22
+ - Use `config/shakapacker.yml` as the secondary source for `asset_host` and `relative_url_root` configurations [PR 376](https://github.com/shakacode/shakapacker/pull/376) by [ahangarha](https://github.com/ahangarha).
23
+
24
+ ### Fixed
25
+ - Recommend `server` option instead of the deprecated `https` option when `--https` is provided [PR 380](https://github.com/shakacode/shakapacker/pull/380) by [G-Rath](https://github.com/g-rath)
26
+ - Recompile assets on asset host change [PR 364](https://github.com/shakacode/shakapacker/pull/364) by [ahangarha](https://github.com/ahangarha).
27
+ - Add deprecation warning for `https` option in `shakapacker.yml` (use `server: 'https'` instead) [PR 382](https://github.com/shakacode/shakapacker/pull/382) by [G-Rath](https://github.com/g-rath).
28
+ - Disable Hot Module Replacement in `webpack-dev-server` when `hmr: false` [PR 392](https://github.com/shakacode/shakapacker/pull/392) by [thedanbob](https://github.com/thedanbob).
29
+
30
+ ### Deprecated
31
+ - The usage of `relative_url_root` is deprecated in Shakapacker and will be removed in v8. [PR 376](https://github.com/shakacode/shakapacker/pull/376) by [ahangarha](https://github.com/ahangarha).
14
32
 
15
33
  ## [v7.1.0] - September 30, 2023
16
34
 
@@ -279,7 +297,9 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions
279
297
  ## v5.4.3 and prior changes from rails/webpacker
280
298
  See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
281
299
 
282
- [Unreleased]: https://github.com/shakacode/shakapacker/compare/v7.1.0...master
300
+ [Unreleased]: https://github.com/shakacode/shakapacker/compare/v7.2.1...master
301
+ [v7.2.1]: https://github.com/shakacode/shakapacker/compare/v7.2.0...v7.2.1
302
+ [v7.2.0]: https://github.com/shakacode/shakapacker/compare/v7.1.0...v7.2.0
283
303
  [v7.1.0]: https://github.com/shakacode/shakapacker/compare/v7.0.3...v7.1.0
284
304
  [v7.0.3]: https://github.com/shakacode/shakapacker/compare/v7.0.2...v7.0.3
285
305
  [v7.0.2]: https://github.com/shakacode/shakapacker/compare/v7.0.1...v7.0.2
data/docs/v6_upgrade.md CHANGED
@@ -168,5 +168,5 @@ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from
168
168
 
169
169
  ## Examples of v5 to v6
170
170
 
171
- 1. [React on Rails Project with HMR and SSR](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/compare/webpacker-5.x...master)
171
+ 1. [React on Rails Project with HMR and SSR](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/compare/webpacker-5.x...61e897f2c604085f45b9ab5e23642501e430fb28)
172
172
  2. [Vue and Sass Example](https://github.com/guillaumebriday/upgrade-webpacker-5-to-6)
@@ -50,6 +50,11 @@ default: &default
50
50
  # https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
51
51
  useContentHash: false
52
52
 
53
+ # Setting the asset host here will override Rails.application.config.asset_host.
54
+ # Here, you can set different asset_host per environment. Note that
55
+ # SHAKAPACKER_ASSET_HOST will override both configurations.
56
+ # asset_host: custom-path
57
+
53
58
  development:
54
59
  <<: *default
55
60
  compile: true
@@ -59,8 +64,6 @@ development:
59
64
  # Keys not described there are documented inline and in https://github.com/shakacode/shakapacker/
60
65
  dev_server:
61
66
  # For running dev server with https, set `server: https`.
62
- # You may use `https: true` instead but notice that it is deprecated in favor of `server: https`
63
- # Ensure only one of these entries is set.
64
67
  # server: https
65
68
 
66
69
  host: localhost
@@ -117,11 +117,23 @@ class Shakapacker::Configuration
117
117
  end
118
118
 
119
119
  def asset_host
120
- ENV.fetch("SHAKAPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host)
120
+ ENV.fetch(
121
+ "SHAKAPACKER_ASSET_HOST",
122
+ fetch(:asset_host) || ActionController::Base.helpers.compute_asset_host
123
+ )
121
124
  end
122
125
 
123
126
  def relative_url_root
124
- ENV.fetch("SHAKAPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root)
127
+ result = ENV.fetch(
128
+ "SHAKAPACKER_RELATIVE_URL_ROOT",
129
+ fetch(:relative_url_root) || ActionController::Base.relative_url_root
130
+ )
131
+
132
+ if result
133
+ Shakapacker.puts_deprecation_message("The usage of relative_url_root is deprecated in Shakapacker and will be removed in v8.")
134
+ end
135
+
136
+ result
125
137
  end
126
138
 
127
139
  private
@@ -31,7 +31,13 @@ class Shakapacker::DevServer
31
31
  end
32
32
 
33
33
  def https?
34
- case fetch(:https)
34
+ value = fetch(:https)
35
+
36
+ unless value.nil?
37
+ puts "WARNING: `https: true` has been deprecated in favor of `server: 'https'`"
38
+ end
39
+
40
+ case value
35
41
  when true, "true", Hash
36
42
  true
37
43
  else
@@ -48,7 +48,7 @@ module Shakapacker
48
48
  end
49
49
 
50
50
  if @argv.include?("--https") && !@https
51
- $stdout.puts "Please set https: true in shakapacker.yml to use the --https command line flag."
51
+ $stdout.puts "--https requires that 'server' in shakapacker.yml is set to 'https'"
52
52
  exit!
53
53
  end
54
54
  end
@@ -86,7 +86,10 @@ module Shakapacker
86
86
  cmd += ["--config", @webpack_config]
87
87
  cmd += ["--progress", "--color"] if @pretty
88
88
 
89
- cmd += ["--hot"] if @hot
89
+ # Default behavior of webpack-dev-server is @hot = true
90
+ cmd += ["--hot", "only"] if @hot == "only"
91
+ cmd += ["--no-hot"] if !@hot
92
+
90
93
  cmd += @argv
91
94
 
92
95
  Dir.chdir(@app_path) do
@@ -44,7 +44,9 @@ module Shakapacker
44
44
  end
45
45
  files = Dir[*expanded_paths].reject { |f| File.directory?(f) }
46
46
  file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
47
- Digest::SHA1.hexdigest(file_ids.join("/"))
47
+
48
+ asset_host = Shakapacker.config.asset_host.to_s
49
+ Digest::SHA1.hexdigest(file_ids.join("/").concat(asset_host))
48
50
  end
49
51
 
50
52
  def record_compilation_digest
@@ -1,4 +1,4 @@
1
1
  module Shakapacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "7.2.0.rc.0".freeze
3
+ VERSION = "7.2.1".freeze
4
4
  end
data/package.json CHANGED
@@ -1,40 +1,36 @@
1
1
  {
2
2
  "name": "shakapacker",
3
- "version": "7.2.0-rc.0",
3
+ "version": "7.2.1",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
+ "homepage": "https://github.com/shakacode/shakapacker",
6
+ "bugs": {
7
+ "url": "https://github.com/shakacode/shakapacker/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/shakacode/shakapacker.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "David Heinemeier Hansson <david@basecamp.com>, Justin Gordon <justin@shakacode.com>",
5
15
  "main": "package/index.js",
6
16
  "types": "package/index.d.ts",
7
17
  "files": [
8
18
  "package",
9
19
  "lib/install/config/shakapacker.yml"
10
20
  ],
11
- "engines": {
12
- "node": "^12.13.0 || ^14 || >=16",
13
- "yarn": ">=1 <5"
14
- },
15
- "peerDependencies": {
16
- "@types/babel__core": "^7.0.0",
17
- "@types/webpack": "^5.0.0",
18
- "@babel/core": "^7.17.9",
19
- "@babel/plugin-transform-runtime": "^7.17.0",
20
- "@babel/preset-env": "^7.16.11",
21
- "@babel/runtime": "^7.17.9",
22
- "babel-loader": "^8.2.4 || ^9.0.0",
23
- "compression-webpack-plugin": "^9.0.0 || ^10.0.0",
24
- "terser-webpack-plugin": "^5.3.1",
25
- "webpack": "^5.72.0",
26
- "webpack-assets-manifest": "^5.0.6",
27
- "webpack-cli": "^4.9.2 || ^5.0.0",
28
- "webpack-dev-server": "^4.9.0",
29
- "webpack-merge": "^5.8.0"
21
+ "scripts": {
22
+ "lint": "eslint package/",
23
+ "test": "jest"
30
24
  },
31
- "peerDependenciesMeta": {
32
- "@types/babel__core": {
33
- "optional": true
34
- },
35
- "@types/webpack": {
36
- "optional": true
37
- }
25
+ "jest": {
26
+ "roots": [
27
+ "<rootDir>/package"
28
+ ],
29
+ "testPathIgnorePatterns": [
30
+ "/__fixtures__/",
31
+ "/__utils__/"
32
+ ],
33
+ "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$"
38
34
  },
39
35
  "dependencies": {
40
36
  "glob": "^7.2.0",
@@ -59,31 +55,35 @@
59
55
  "webpack-assets-manifest": "^5.0.6",
60
56
  "webpack-merge": "^5.8.0"
61
57
  },
62
- "jest": {
63
- "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
64
- "testPathIgnorePatterns": [
65
- "/__fixtures__/",
66
- "/__utils__/"
67
- ],
68
- "roots": [
69
- "<rootDir>/package"
70
- ]
71
- },
72
- "publishConfig": {
73
- "access": "public"
74
- },
75
- "scripts": {
76
- "test": "jest",
77
- "lint": "eslint package/"
58
+ "peerDependencies": {
59
+ "@babel/core": "^7.17.9",
60
+ "@babel/plugin-transform-runtime": "^7.17.0",
61
+ "@babel/preset-env": "^7.16.11",
62
+ "@babel/runtime": "^7.17.9",
63
+ "@types/babel__core": "^7.0.0",
64
+ "@types/webpack": "^5.0.0",
65
+ "babel-loader": "^8.2.4 || ^9.0.0",
66
+ "compression-webpack-plugin": "^9.0.0 || ^10.0.0",
67
+ "terser-webpack-plugin": "^5.3.1",
68
+ "webpack": "^5.72.0",
69
+ "webpack-assets-manifest": "^5.0.6",
70
+ "webpack-cli": "^4.9.2 || ^5.0.0",
71
+ "webpack-dev-server": "^4.9.0",
72
+ "webpack-merge": "^5.8.0"
78
73
  },
79
- "repository": {
80
- "type": "git",
81
- "url": "git+https://github.com/shakacode/shakapacker.git"
74
+ "peerDependenciesMeta": {
75
+ "@types/babel__core": {
76
+ "optional": true
77
+ },
78
+ "@types/webpack": {
79
+ "optional": true
80
+ }
82
81
  },
83
- "author": "David Heinemeier Hansson <david@basecamp.com>, Justin Gordon <justin@shakacode.com>",
84
- "license": "MIT",
85
- "bugs": {
86
- "url": "https://github.com/shakacode/shakapacker/issues"
82
+ "engines": {
83
+ "node": "^12.13.0 || ^14 || >=16",
84
+ "yarn": ">=1 <5"
87
85
  },
88
- "homepage": "https://github.com/shakacode/shakapacker"
86
+ "publishConfig": {
87
+ "access": "public"
88
+ }
89
89
  }
@@ -45,19 +45,52 @@ describe "DevServerRunner" do
45
45
  verify_command(cmd, argv: (["--quiet"]))
46
46
  end
47
47
 
48
+ it "does not automatically pass the --https flag" do
49
+ cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
50
+
51
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
52
+ double(
53
+ host: "localhost",
54
+ port: "3035",
55
+ pretty?: false,
56
+ protocol: "https",
57
+ hmr?: true
58
+ )
59
+ )
60
+
61
+ verify_command(cmd)
62
+ end
63
+
48
64
  it "supports the https flag" do
49
65
  cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"])
50
66
 
51
- dev_server = double()
52
- allow(dev_server).to receive(:host).and_return("localhost")
53
- allow(dev_server).to receive(:port).and_return("3035")
54
- allow(dev_server).to receive(:pretty?).and_return(false)
55
- allow(dev_server).to receive(:https?).and_return(true)
56
- allow(dev_server).to receive(:hmr?).and_return(false)
67
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
68
+ double(
69
+ host: "localhost",
70
+ port: "3035",
71
+ pretty?: false,
72
+ protocol: "https",
73
+ hmr?: true
74
+ )
75
+ )
76
+
77
+ verify_command(cmd, argv: ["--https"])
78
+ end
79
+
80
+ it "supports disabling hot module reloading" do
81
+ cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"])
82
+
83
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
84
+ double(
85
+ host: "localhost",
86
+ port: "3035",
87
+ pretty?: false,
88
+ protocol: "http",
89
+ hmr?: false
90
+ )
91
+ )
57
92
 
58
- allow(Shakapacker::DevServer).to receive(:new) do
59
- verify_command(cmd, argv: (["--https"]))
60
- end.and_return(dev_server)
93
+ verify_command(cmd)
61
94
  end
62
95
 
63
96
  it "accepts environment variables" do
@@ -94,19 +127,52 @@ describe "DevServerRunner" do
94
127
  verify_command(cmd, argv: (["--quiet"]))
95
128
  end
96
129
 
130
+ it "does not automatically pass the --https flag" do
131
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
132
+
133
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
134
+ double(
135
+ host: "localhost",
136
+ port: "3035",
137
+ pretty?: false,
138
+ protocol: "https",
139
+ hmr?: true
140
+ )
141
+ )
142
+
143
+ verify_command(cmd)
144
+ end
145
+
97
146
  it "supports the https flag" do
98
147
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
99
148
 
100
- dev_server = double()
101
- allow(dev_server).to receive(:host).and_return("localhost")
102
- allow(dev_server).to receive(:port).and_return("3035")
103
- allow(dev_server).to receive(:pretty?).and_return(false)
104
- allow(dev_server).to receive(:https?).and_return(true)
105
- allow(dev_server).to receive(:hmr?).and_return(false)
149
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
150
+ double(
151
+ host: "localhost",
152
+ port: "3035",
153
+ pretty?: false,
154
+ protocol: "https",
155
+ hmr?: true
156
+ )
157
+ )
158
+
159
+ verify_command(cmd, argv: ["--https"])
160
+ end
161
+
162
+ it "supports disabling hot module reloading" do
163
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]
164
+
165
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
166
+ double(
167
+ host: "localhost",
168
+ port: "3035",
169
+ pretty?: false,
170
+ protocol: "http",
171
+ hmr?: false
172
+ )
173
+ )
106
174
 
107
- allow(Shakapacker::DevServer).to receive(:new) do
108
- verify_command(cmd, argv: (["--https"]))
109
- end.and_return(dev_server)
175
+ verify_command(cmd)
110
176
  end
111
177
 
112
178
  it "accepts environment variables" do
@@ -9,6 +9,7 @@ describe "DigestStrategy" do
9
9
 
10
10
  before :all do
11
11
  @digest_strategy = Webpacker::DigestStrategy.new
12
+ ENV["SHAKAPACKER_ASSET_HOST"] = nil
12
13
  remove_compilation_digest_path
13
14
  end
14
15
 
@@ -48,7 +48,7 @@ development:
48
48
  host: localhost
49
49
  port: 3035
50
50
  public: localhost:3035
51
- hmr: false
51
+ hmr: true
52
52
  overlay: true
53
53
  disable_host_check: true
54
54
  use_local_ip: false
@@ -42,7 +42,7 @@ development:
42
42
  host: localhost
43
43
  port: 3035
44
44
  public: localhost:3035
45
- hmr: false
45
+ hmr: true
46
46
  # If HMR is on, CSS will by inlined by delivering it as part of the script payload via style-loader. Be sure
47
47
  # that you add style-loader to your project dependencies.
48
48
  #
data/spec/dummy/Gemfile CHANGED
@@ -46,8 +46,6 @@ group :test do
46
46
  gem "capybara", "~> 3.39.1"
47
47
  # gem 'capybara-webkit'
48
48
  gem "selenium-webdriver", ">= 4.9"
49
- # Easy installation and use of web drivers to run system tests with browsers
50
- gem "webdrivers"
51
49
  end
52
50
 
53
51
  # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
@@ -39,6 +39,5 @@
39
39
  "fork-ts-checker-webpack-plugin": "^6.5.2",
40
40
  "react-refresh": "^0.14.0",
41
41
  "webpack-dev-server": "^4.9.2"
42
- },
43
- "packageManager": "yarn@3.2.1"
42
+ }
44
43
  }
@@ -50,14 +50,10 @@ describe "Shakapacker::Compiler" do
50
50
  expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to be nil
51
51
  expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to be nil
52
52
 
53
- custom_env_variables = {
54
- "SHAKAPACKER_ASSET_HOST" => "foo.bar",
55
- "SHAKAPACKER_RELATIVE_URL_ROOT" => "/baz"
56
- }
57
-
58
- with_env_variable(custom_env_variables) do
59
- expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to eq "foo.bar"
60
- expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to eq "/baz"
61
- end
53
+ allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("foo.bar")
54
+ allow(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return("/baz")
55
+
56
+ expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to eq "foo.bar"
57
+ expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to eq "/baz"
62
58
  end
63
59
  end
@@ -341,16 +341,35 @@ describe "Shakapacker::Configuration" do
341
341
  end
342
342
 
343
343
  it "returns the value of SHAKAPACKER_ASSET_HOST if set" do
344
- with_env_variable("SHAKAPACKER_ASSET_HOST" => "custom_host.abc") do
345
- expect(config.asset_host).to eq "custom_host.abc"
346
- end
344
+ expect(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("custom_host.abc")
345
+
346
+ expect(config.asset_host).to eq "custom_host.abc"
347
347
  end
348
348
 
349
- it "returns ActionController::Base.helpers.compute_asset_host if SHAKAPACKER_ASSET_HOST is not set" do
350
- allow(ActionController::Base.helpers).to receive(:compute_asset_host).and_return("domain.abc")
349
+ context "without SHAKAPACKER_ASSET_HOST set" do
350
+ it "returns asset_host in shakapacker.yml if set" do
351
+ expect(config).to receive(:fetch).with(:asset_host).and_return("value-in-config-file.com")
352
+ expect(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", "value-in-config-file.com").and_return("value-in-config-file.com")
353
+
354
+ expect(config.asset_host).to eq "value-in-config-file.com"
355
+ end
356
+
357
+ context "without asset_host set in the shakapacker.yml" do
358
+ it "returns ActionController::Base.helpers.compute_asset_host if SHAKAPACKER_ASSET_HOST is not set" do
359
+ expect(config).to receive(:fetch).with(:asset_host).and_return(nil)
360
+ expect(ActionController::Base.helpers).to receive(:compute_asset_host).and_return("domain.abc")
361
+ allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", "domain.abc").and_return("domain.abc")
351
362
 
352
- with_env_variable("SHAKAPACKER_ASSET_HOST" => nil) do
353
- expect(config.asset_host).to eq "domain.abc"
363
+ expect(config.asset_host).to eq "domain.abc"
364
+ end
365
+
366
+ context "without ActionController::Base.helpers.compute_asset_host returing any value" do
367
+ it "returns nil" do
368
+ expect(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return(nil)
369
+
370
+ expect(config.asset_host).to be nil
371
+ end
372
+ end
354
373
  end
355
374
  end
356
375
  end
@@ -364,17 +383,46 @@ describe "Shakapacker::Configuration" do
364
383
  )
365
384
  end
366
385
 
367
- it "returns the value of SHAKAPACKER_RELATIVE_URL_ROOT if set" do
368
- with_env_variable("SHAKAPACKER_RELATIVE_URL_ROOT" => "custom_value") do
386
+ context "with SHAKAPACKER_RELATIVE_URL_ROOT set" do
387
+ before do
388
+ expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return("custom_value")
389
+ end
390
+ it "shows deprecation message" do
391
+ expect { config.relative_url_root }.to output(/deprecated/).to_stdout
392
+ end
393
+
394
+ it "returns the value of SHAKAPACKER_RELATIVE_URL_ROOT" do
369
395
  expect(config.relative_url_root).to eq "custom_value"
370
396
  end
371
397
  end
372
398
 
373
- it "returns ActionController::Base.helpers.compute_asset_host if SHAKAPACKER_RELATIVE_URL_ROOT is not set" do
374
- allow(ActionController::Base).to receive(:relative_url_root).and_return("abcd")
399
+ context "without SHAKAPACKER_RELATIVE_URL_ROOT set" do
400
+ it "returns relative_url_root in shakapacker.yml if set" do
401
+ expect(config).to receive(:fetch).with(:relative_url_root).and_return("value-in-config-file")
402
+ expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", "value-in-config-file").and_return("value-in-config-file")
403
+
404
+ expect(config.relative_url_root).to eq "value-in-config-file"
405
+ end
406
+
407
+ context "without relative_url_root set in the shakapacker.yml" do
408
+ it "returns ActionController::Base.relative_url_root if SHAKAPACKER_RELATIVE_URL_ROOT is not set" do
409
+ expect(ActionController::Base).to receive(:relative_url_root).and_return("abcd")
410
+ expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", "abcd").and_return("abcd")
375
411
 
376
- with_env_variable("SHAKAPACKER_RELATIVE_URL_ROOT" => nil) do
377
- expect(config.relative_url_root).to eq "abcd"
412
+ expect(config.relative_url_root).to eq "abcd"
413
+ end
414
+
415
+ context "without ActionController::Base.relative_url_root returing any value" do
416
+ it "returns an empty string" do
417
+ expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return(nil)
418
+
419
+ expect(config.relative_url_root).to be nil
420
+ end
421
+
422
+ it "doesn't shows deprecation message" do
423
+ expect { config.relative_url_root }.to_not output(/deprecated/).to_stdout
424
+ end
425
+ end
378
426
  end
379
427
  end
380
428
  end
@@ -44,19 +44,52 @@ describe "DevServerRunner" do
44
44
  verify_command(cmd, argv: (["--quiet"]))
45
45
  end
46
46
 
47
+ it "does not automatically pass the --https flag" do
48
+ cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
49
+
50
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
51
+ double(
52
+ host: "localhost",
53
+ port: "3035",
54
+ pretty?: false,
55
+ protocol: "https",
56
+ hmr?: true
57
+ )
58
+ )
59
+
60
+ verify_command(cmd)
61
+ end
62
+
47
63
  it "supports the https flag" do
48
64
  cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"])
49
65
 
50
- dev_server = double()
51
- allow(dev_server).to receive(:host).and_return("localhost")
52
- allow(dev_server).to receive(:port).and_return("3035")
53
- allow(dev_server).to receive(:pretty?).and_return(false)
54
- allow(dev_server).to receive(:https?).and_return(true)
55
- allow(dev_server).to receive(:hmr?).and_return(false)
66
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
67
+ double(
68
+ host: "localhost",
69
+ port: "3035",
70
+ pretty?: false,
71
+ protocol: "https",
72
+ hmr?: true
73
+ )
74
+ )
75
+
76
+ verify_command(cmd, argv: ["--https"])
77
+ end
78
+
79
+ it "supports disabling hot module reloading" do
80
+ cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"])
81
+
82
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
83
+ double(
84
+ host: "localhost",
85
+ port: "3035",
86
+ pretty?: false,
87
+ protocol: "http",
88
+ hmr?: false
89
+ )
90
+ )
56
91
 
57
- allow(Shakapacker::DevServer).to receive(:new) do
58
- verify_command(cmd, argv: (["--https"]))
59
- end.and_return(dev_server)
92
+ verify_command(cmd)
60
93
  end
61
94
 
62
95
  it "accepts environment variables" do
@@ -92,19 +125,68 @@ describe "DevServerRunner" do
92
125
  verify_command(cmd, argv: (["--quiet"]))
93
126
  end
94
127
 
128
+ it "does not automatically pass the --https flag" do
129
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
130
+
131
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
132
+ double(
133
+ host: "localhost",
134
+ port: "3035",
135
+ pretty?: false,
136
+ protocol: "https",
137
+ hmr?: true
138
+ )
139
+ )
140
+
141
+ verify_command(cmd)
142
+ end
143
+
95
144
  it "supports the https flag" do
96
145
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
97
146
 
98
- dev_server = double()
99
- allow(dev_server).to receive(:host).and_return("localhost")
100
- allow(dev_server).to receive(:port).and_return("3035")
101
- allow(dev_server).to receive(:pretty?).and_return(false)
102
- allow(dev_server).to receive(:https?).and_return(true)
103
- allow(dev_server).to receive(:hmr?).and_return(false)
147
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
148
+ double(
149
+ host: "localhost",
150
+ port: "3035",
151
+ pretty?: false,
152
+ protocol: "https",
153
+ hmr?: true
154
+ )
155
+ )
156
+
157
+ verify_command(cmd, argv: ["--https"])
158
+ end
159
+
160
+ it "supports disabling hot module reloading" do
161
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]
162
+
163
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
164
+ double(
165
+ host: "localhost",
166
+ port: "3035",
167
+ pretty?: false,
168
+ protocol: "http",
169
+ hmr?: false
170
+ )
171
+ )
172
+
173
+ verify_command(cmd)
174
+ end
175
+
176
+ it "supports --hot being 'only'" do
177
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot", "only"]
178
+
179
+ allow(Shakapacker::DevServer).to receive(:new).and_return(
180
+ double(
181
+ host: "localhost",
182
+ port: "3035",
183
+ pretty?: false,
184
+ protocol: "http",
185
+ hmr?: "only"
186
+ )
187
+ )
104
188
 
105
- allow(Shakapacker::DevServer).to receive(:new) do
106
- verify_command(cmd, argv: (["--https"]))
107
- end.and_return(dev_server)
189
+ verify_command(cmd)
108
190
  end
109
191
 
110
192
  it "accepts environment variables" do
@@ -28,7 +28,29 @@ describe "DigestStrategy" do
28
28
  expect(@digest_strategy.fresh?).to be true
29
29
  end
30
30
 
31
+ it "is stale when host changes" do
32
+ allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("old-host")
33
+ # Record the digests for old-host
34
+ @digest_strategy.after_compile_hook
35
+
36
+ allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("new-host")
37
+ expect(@digest_strategy.stale?).to be true
38
+ expect(@digest_strategy.fresh?).to be_falsey
39
+ end
40
+
31
41
  it "generates correct compilation_digest_path" do
42
+ allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("custom-path")
43
+
44
+ actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
45
+ host_hash = Digest::SHA1.hexdigest("custom-path")
46
+ expected_path = "last-compilation-digest-#{Shakapacker.env}"
47
+
48
+ expect(actual_path).to eq expected_path
49
+ end
50
+
51
+ it "generates correct compilation_digest_path without the digest of the asset host if asset host is not set" do
52
+ allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return(nil)
53
+
32
54
  actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
33
55
  expected_path = "last-compilation-digest-#{Shakapacker.env}"
34
56
 
@@ -22,21 +22,3 @@ ensure
22
22
  Rails.env = ActiveSupport::StringInquirer.new(original)
23
23
  reloaded_config
24
24
  end
25
-
26
- # Temportarily set env variables to a custom value
27
- # arg: a hash with key:value for each custom env
28
- # Keys could be string or symbol
29
- def with_env_variable(custom_env_hash)
30
- original_env = {}
31
- custom_env_hash.each do |key, new_value|
32
- upcased_key = key.to_s.upcase
33
- original_env[upcased_key] = new_value
34
- ENV[upcased_key] = new_value
35
- end
36
-
37
- yield
38
- ensure
39
- original_env.each do |key, original_value|
40
- ENV[key] = original_value
41
- end
42
- end
@@ -47,7 +47,7 @@ development:
47
47
  host: localhost
48
48
  port: 3035
49
49
  public: localhost:3035
50
- hmr: false
50
+ hmr: true
51
51
  overlay: true
52
52
  disable_host_check: true
53
53
  use_local_ip: false
@@ -42,7 +42,7 @@ development:
42
42
  host: localhost
43
43
  port: 3035
44
44
  public: localhost:3035
45
- hmr: false
45
+ hmr: true
46
46
  # If HMR is on, CSS will by inlined by delivering it as part of the script payload via style-loader. Be sure
47
47
  # that you add style-loader to your project dependencies.
48
48
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shakapacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.0.rc.0
4
+ version: 7.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-10-31 00:00:00.000000000 Z
13
+ date: 2024-01-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -566,7 +566,7 @@ homepage: https://github.com/shakacode/shakapacker
566
566
  licenses:
567
567
  - MIT
568
568
  metadata:
569
- source_code_uri: https://github.com/shakacode/shakapacker/tree/v7.2.0-rc.0
569
+ source_code_uri: https://github.com/shakacode/shakapacker/tree/v7.2.1
570
570
  post_install_message:
571
571
  rdoc_options: []
572
572
  require_paths:
@@ -578,9 +578,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
578
578
  version: 2.6.0
579
579
  required_rubygems_version: !ruby/object:Gem::Requirement
580
580
  requirements:
581
- - - ">"
581
+ - - ">="
582
582
  - !ruby/object:Gem::Version
583
- version: 1.3.1
583
+ version: '0'
584
584
  requirements: []
585
585
  rubygems_version: 3.4.12
586
586
  signing_key: