shakapacker 6.3.0.pre.rc.1 → 6.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,8 +14,15 @@ const { moduleExists } = require('../utils/helpers')
14
14
  const getEntryObject = () => {
15
15
  const entries = {}
16
16
  const rootPath = join(config.source_path, config.source_entry_path)
17
+ if (config.source_entry_path === '/' && config.nested_entries) {
18
+ throw new Error(
19
+ "Your webpacker config specified using a source_entry_path of '/' with 'nested_entries' == " +
20
+ "'true'. Doing this would result in packs for every one of your source files"
21
+ )
22
+ }
23
+ const nesting = config.nested_entries ? '**/' : ''
17
24
 
18
- globSync(`${rootPath}/*.*`).forEach((path) => {
25
+ globSync(`${rootPath}/${nesting}*.*`).forEach((path) => {
19
26
  const namespace = relative(join(rootPath), dirname(path))
20
27
  const name = join(namespace, basename(path, extname(path)))
21
28
  let assetPaths = resolve(path)
data/package/rules/erb.js CHANGED
@@ -9,7 +9,13 @@ module.exports = canProcess('rails-erb-loader', (resolvedPath) => ({
9
9
  use: [
10
10
  {
11
11
  loader: resolvedPath,
12
- options: { runner: `${runner}bin/rails runner` }
12
+ options: {
13
+ runner: `${runner}bin/rails runner`,
14
+ env: {
15
+ ...process.env,
16
+ DISABLE_SPRING: 1
17
+ }
18
+ }
13
19
  }
14
20
  ]
15
21
  }))
@@ -1,4 +1,4 @@
1
- const { dirname, join } = require('path')
1
+ const { dirname } = require('path')
2
2
  const { source_path: sourcePath } = require('../config')
3
3
 
4
4
  module.exports = {
@@ -12,7 +12,7 @@ module.exports = {
12
12
  .split('/')
13
13
  .slice(1)
14
14
 
15
- const foldersWithStatic = join('static', ...folders)
15
+ const foldersWithStatic = ['static', ...folders].join('/')
16
16
  return `${foldersWithStatic}/[name]-[hash][ext][query]`
17
17
  }
18
18
  }
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shakapacker",
3
- "version": "6.3.0-rc.1",
3
+ "version": "6.4.1",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "main": "package/index.js",
6
6
  "files": [
@@ -13,16 +13,16 @@
13
13
  },
14
14
  "peerDependencies": {
15
15
  "@babel/core": "^7.17.9",
16
- "@babel/plugin-transform-runtime": "^7.17.9",
16
+ "@babel/plugin-transform-runtime": "^7.17.0",
17
17
  "@babel/preset-env": "^7.16.11",
18
18
  "@babel/runtime": "^7.17.9",
19
19
  "babel-loader": "^8.2.4",
20
- "compression-webpack-plugin": "^9.0.0",
20
+ "compression-webpack-plugin": "^9.0.0 || ^10.0.0",
21
21
  "terser-webpack-plugin": "^5.3.1",
22
22
  "webpack": "^5.72.0",
23
23
  "webpack-assets-manifest": "^5.0.6",
24
24
  "webpack-cli": "^4.9.2",
25
- "webpack-dev-server": "^4.8.1",
25
+ "webpack-dev-server": "^4.9.0",
26
26
  "webpack-merge": "^5.8.0"
27
27
  },
28
28
  "dependencies": {
@@ -0,0 +1,27 @@
1
+ require "test_helper"
2
+
3
+ class CompilerStrategyTest < Minitest::Test
4
+ def test_mtime_strategy_returned
5
+ Webpacker.config.stub :compiler_strategy, "mtime" do
6
+ assert_instance_of Webpacker::MtimeStrategy, Webpacker::CompilerStrategy.from_config
7
+ end
8
+ end
9
+
10
+ def test_digest_strategy_returned
11
+ Webpacker.config.stub :compiler_strategy, "digest" do
12
+ assert_instance_of Webpacker::DigestStrategy, Webpacker::CompilerStrategy.from_config
13
+ end
14
+ end
15
+
16
+ def test_raise_on_unknown_strategy
17
+ Webpacker.config.stub :compiler_strategy, "other" do
18
+ error = assert_raises do
19
+ Webpacker::CompilerStrategy.from_config
20
+ end
21
+
22
+ assert_equal \
23
+ "Unknown strategy 'other'. Available options are 'mtime' and 'digest'.",
24
+ error.message
25
+ end
26
+ end
27
+ end
@@ -9,46 +9,43 @@ class CompilerTest < Minitest::Test
9
9
  Webpacker.compiler.env = {}
10
10
  end
11
11
 
12
- def setup
13
- @manifest_timestamp = Time.parse("2021-01-01 12:34:56 UTC")
14
- end
15
-
16
- def with_stubs(latest_timestamp:, manifest_exists: true)
17
- Webpacker.compiler.stub :latest_modified_timestamp, latest_timestamp do
18
- FileTest.stub :exist?, manifest_exists do
19
- File.stub :mtime, @manifest_timestamp do
20
- yield
21
- end
22
- end
12
+ def test_compile_true_when_fresh
13
+ mock = Minitest::Mock.new
14
+ mock.expect(:stale?, false)
15
+ Webpacker.compiler.stub(:strategy, mock) do
16
+ assert Webpacker.compiler.compile
23
17
  end
18
+ assert_mock mock
24
19
  end
25
20
 
26
- def test_freshness_when_manifest_missing
27
- latest_timestamp = @manifest_timestamp + 3600
28
-
29
- with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
30
- assert Webpacker.compiler.stale?
31
- end
32
- end
21
+ def test_after_compile_hook_called_on_success
22
+ mock = Minitest::Mock.new
23
+ mock.expect(:stale?, true)
24
+ mock.expect(:after_compile_hook, nil)
33
25
 
34
- def test_freshness_when_manifest_older
35
- latest_timestamp = @manifest_timestamp + 3600
26
+ status = OpenStruct.new(success?: true)
36
27
 
37
- with_stubs(latest_timestamp: latest_timestamp.to_i) do
38
- assert Webpacker.compiler.stale?
28
+ Webpacker.compiler.stub(:strategy, mock) do
29
+ Open3.stub :capture3, [:sterr, :stdout, status] do
30
+ Webpacker.compiler.compile
31
+ end
39
32
  end
33
+ assert_mock mock
40
34
  end
41
35
 
42
- def test_freshness_when_manifest_newer
43
- latest_timestamp = @manifest_timestamp - 3600
36
+ def test_after_compile_hook_called_on_failure
37
+ mock = Minitest::Mock.new
38
+ mock.expect(:stale?, true)
39
+ mock.expect(:after_compile_hook, nil)
44
40
 
45
- with_stubs(latest_timestamp: latest_timestamp.to_i) do
46
- assert Webpacker.compiler.fresh?
47
- end
48
- end
41
+ status = OpenStruct.new(success?: false)
49
42
 
50
- def test_compile
51
- assert !Webpacker.compiler.compile
43
+ Webpacker.compiler.stub(:strategy, mock) do
44
+ Open3.stub :capture3, [:sterr, :stdout, status] do
45
+ Webpacker.compiler.compile
46
+ end
47
+ end
48
+ assert_mock mock
52
49
  end
53
50
 
54
51
  def test_external_env_variables
@@ -0,0 +1,33 @@
1
+ require "test_helper"
2
+
3
+ class DigestStrategyTest < Minitest::Test
4
+ def remove_compilation_digest_path
5
+ @digest_strategy.send(:compilation_digest_path).tap do |path|
6
+ path.delete if path.exist?
7
+ end
8
+ end
9
+
10
+ def setup
11
+ @digest_strategy = Webpacker::DigestStrategy.new
12
+ remove_compilation_digest_path
13
+ end
14
+
15
+ def teardown
16
+ remove_compilation_digest_path
17
+ end
18
+
19
+ def test_freshness
20
+ assert @digest_strategy.stale?
21
+ assert !@digest_strategy.fresh?
22
+ end
23
+
24
+ def test_freshness_after_compilation_hook
25
+ @digest_strategy.after_compile_hook
26
+ assert @digest_strategy.fresh?
27
+ assert !@digest_strategy.stale?
28
+ end
29
+
30
+ def test_compilation_digest_path
31
+ assert_equal @digest_strategy.send(:compilation_digest_path).basename.to_s, "last-compilation-digest-#{Webpacker.env}"
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ require "test_helper"
2
+
3
+ class MtimeStrategyTest < Minitest::Test
4
+ def setup
5
+ @mtime_strategy = Webpacker::MtimeStrategy.new
6
+ @manifest_timestamp = Time.parse("2021-01-01 12:34:56 UTC")
7
+ end
8
+
9
+ def with_stubs(latest_timestamp:, manifest_exists: true)
10
+ @mtime_strategy.stub :latest_modified_timestamp, latest_timestamp do
11
+ FileTest.stub :exist?, manifest_exists do
12
+ File.stub :mtime, @manifest_timestamp do
13
+ yield
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ def test_freshness_when_manifest_missing
20
+ latest_timestamp = @manifest_timestamp + 3600
21
+
22
+ with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
23
+ assert @mtime_strategy.stale?
24
+ end
25
+ end
26
+
27
+ def test_freshness_when_manifest_older
28
+ latest_timestamp = @manifest_timestamp + 3600
29
+
30
+ with_stubs(latest_timestamp: latest_timestamp.to_i) do
31
+ assert @mtime_strategy.stale?
32
+ end
33
+ end
34
+
35
+ def test_freshness_when_manifest_newer
36
+ latest_timestamp = @manifest_timestamp - 3600
37
+
38
+ with_stubs(latest_timestamp: latest_timestamp.to_i) do
39
+ assert @mtime_strategy.fresh?
40
+ end
41
+ end
42
+ end
@@ -30,42 +30,8 @@ class RakeTasksTest < Minitest::Test
30
30
  refute_includes output, "Webpacker requires Yarn"
31
31
  end
32
32
 
33
- def test_rake_webpacker_yarn_install_in_non_production_environments
34
- assert_includes test_app_dev_dependencies, "right-pad"
35
-
36
- Webpacker.with_node_env("test") do
37
- Dir.chdir(test_app_path) do
38
- `bundle exec rake webpacker:yarn_install`
39
- end
40
- end
41
-
42
- assert_includes installed_node_module_names, "right-pad",
43
- "Expected dev dependencies to be installed"
44
- end
45
-
46
- def test_rake_webpacker_yarn_install_in_production_environment
47
- Webpacker.with_node_env("production") do
48
- Dir.chdir(test_app_path) do
49
- `bundle exec rake webpacker:yarn_install`
50
- end
51
- end
52
-
53
- refute_includes installed_node_module_names, "right-pad",
54
- "Expected only production dependencies to be installed"
55
- end
56
-
57
33
  private
58
34
  def test_app_path
59
35
  File.expand_path("test_app", __dir__)
60
36
  end
61
-
62
- def test_app_dev_dependencies
63
- package_json = File.expand_path("package.json", test_app_path)
64
- JSON.parse(File.read(package_json))["devDependencies"]
65
- end
66
-
67
- def installed_node_module_names
68
- node_modules_path = File.expand_path("node_modules", test_app_path)
69
- Dir.chdir(node_modules_path) { Dir.glob("*") }
70
- end
71
37
  end
@@ -0,0 +1,2 @@
1
+ /* eslint no-console:0 */
2
+ console.log('entrypoints/nested/something')
@@ -3,6 +3,7 @@
3
3
  default: &default
4
4
  source_path: app/packs
5
5
  source_entry_path: entrypoints
6
+ nested_entries: false
6
7
  public_root_path: public
7
8
  public_output_path: packs
8
9
  cache_path: tmp/webpacker
@@ -0,0 +1,83 @@
1
+ # Note: You must restart bin/webpacker-dev-server for changes to take effect
2
+
3
+ default: &default
4
+ source_path: app/packs
5
+ source_entry_path: entrypoints
6
+ nested_entries: true
7
+ public_root_path: public
8
+ public_output_path: packs
9
+ cache_path: tmp/webpacker
10
+ webpack_compile_output: false
11
+ webpack_loader: babel
12
+
13
+ # Location for manifest.json, defaults to {public_output_path}/manifest.json if unset
14
+ # manifest_path: public/packs/manifest.json
15
+
16
+ # Additional paths webpack should look up modules
17
+ # ['app/assets', 'engine/foo/app/assets']
18
+ additional_paths:
19
+ - app/assets
20
+ - /etc/yarn
21
+ - some.config.js
22
+ - app/elm
23
+
24
+ # Reload manifest.json on all requests so we reload latest compiled packs
25
+ cache_manifest: false
26
+
27
+ static_assets_extensions:
28
+ - .jpg
29
+ - .jpeg
30
+ - .png
31
+ - .gif
32
+ - .tiff
33
+ - .ico
34
+ - .svg
35
+
36
+ extensions:
37
+ - .mjs
38
+ - .js
39
+
40
+ development:
41
+ <<: *default
42
+ compile: true
43
+ ensure_consistent_versioning: true
44
+
45
+ # Reference: https://webpack.js.org/configuration/dev-server/
46
+ dev_server:
47
+ https: false
48
+ host: localhost
49
+ port: 3035
50
+ public: localhost:3035
51
+ hmr: false
52
+ overlay: true
53
+ disable_host_check: true
54
+ use_local_ip: false
55
+ pretty: false
56
+
57
+ test:
58
+ <<: *default
59
+ compile: true
60
+
61
+ # Compile test packs to a separate directory
62
+ public_output_path: packs-test
63
+
64
+ production:
65
+ <<: *default
66
+
67
+ # Production depends on precompilation of packs prior to booting for performance.
68
+ compile: false
69
+
70
+ # Cache manifest.json for performance
71
+ cache_manifest: true
72
+
73
+ staging:
74
+ <<: *default
75
+
76
+ # Production depends on precompilation of packs prior to booting for performance.
77
+ compile: false
78
+
79
+ # Cache manifest.json for performance
80
+ cache_manifest: true
81
+
82
+ # Compile staging packs to a separate directory
83
+ public_output_path: packs-staging
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: 6.3.0.pre.rc.1
4
+ version: 6.4.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: 2022-04-24 00:00:00.000000000 Z
13
+ date: 2022-06-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -142,6 +142,8 @@ files:
142
142
  - docs/customizing_babel_config.md
143
143
  - docs/deployment.md
144
144
  - docs/developing_webpacker.md
145
+ - docs/react.md
146
+ - docs/sprockets.md
145
147
  - docs/style_loader_vs_mini_css.md
146
148
  - docs/troubleshooting.md
147
149
  - docs/using_esbuild_loader.md
@@ -179,16 +181,20 @@ files:
179
181
  - lib/tasks/webpacker/yarn_install.rake
180
182
  - lib/tasks/yarn.rake
181
183
  - lib/webpacker.rb
184
+ - lib/webpacker/base_strategy.rb
182
185
  - lib/webpacker/commands.rb
183
186
  - lib/webpacker/compiler.rb
187
+ - lib/webpacker/compiler_strategy.rb
184
188
  - lib/webpacker/configuration.rb
185
189
  - lib/webpacker/dev_server.rb
186
190
  - lib/webpacker/dev_server_proxy.rb
187
191
  - lib/webpacker/dev_server_runner.rb
192
+ - lib/webpacker/digest_strategy.rb
188
193
  - lib/webpacker/env.rb
189
194
  - lib/webpacker/helper.rb
190
195
  - lib/webpacker/instance.rb
191
196
  - lib/webpacker/manifest.rb
197
+ - lib/webpacker/mtime_strategy.rb
192
198
  - lib/webpacker/railtie.rb
193
199
  - lib/webpacker/runner.rb
194
200
  - lib/webpacker/version.rb
@@ -236,10 +242,12 @@ files:
236
242
  - package/utils/helpers.js
237
243
  - rakelib/release.rake
238
244
  - test/command_test.rb
245
+ - test/compiler_strategy_test.rb
239
246
  - test/compiler_test.rb
240
247
  - test/configuration_test.rb
241
248
  - test/dev_server_runner_test.rb
242
249
  - test/dev_server_test.rb
250
+ - test/digest_strategy_test.rb
243
251
  - test/engine_rake_tasks_test.rb
244
252
  - test/env_test.rb
245
253
  - test/fixtures/beta_package.json
@@ -261,9 +269,11 @@ files:
261
269
  - test/mounted_app/test/dummy/config/environment.rb
262
270
  - test/mounted_app/test/dummy/config/webpacker.yml
263
271
  - test/mounted_app/test/dummy/package.json
272
+ - test/mtime_strategy_test.rb
264
273
  - test/rake_tasks_test.rb
265
274
  - test/test_app/Rakefile
266
275
  - test/test_app/app/packs/entrypoints/application.js
276
+ - test/test_app/app/packs/entrypoints/generated/something.js
267
277
  - test/test_app/app/packs/entrypoints/multi_entry.css
268
278
  - test/test_app/app/packs/entrypoints/multi_entry.js
269
279
  - test/test_app/bin/webpacker
@@ -275,6 +285,7 @@ files:
275
285
  - test/test_app/config/webpack/webpack.config.js
276
286
  - test/test_app/config/webpacker.yml
277
287
  - test/test_app/config/webpacker_manifest_path.yml
288
+ - test/test_app/config/webpacker_nested_entries.yml
278
289
  - test/test_app/config/webpacker_no_precompile.yml
279
290
  - test/test_app/config/webpacker_other_location.yml
280
291
  - test/test_app/config/webpacker_public_root.yml
@@ -292,7 +303,7 @@ homepage: https://github.com/shakacode/shakapacker
292
303
  licenses:
293
304
  - MIT
294
305
  metadata:
295
- source_code_uri: https://github.com/shakacode/shakapacker/tree/v6.3.0-rc.1
306
+ source_code_uri: https://github.com/shakacode/shakapacker/tree/v6.4.1
296
307
  post_install_message:
297
308
  rdoc_options: []
298
309
  require_paths:
@@ -304,9 +315,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
304
315
  version: 2.6.0
305
316
  required_rubygems_version: !ruby/object:Gem::Requirement
306
317
  requirements:
307
- - - ">"
318
+ - - ">="
308
319
  - !ruby/object:Gem::Version
309
- version: 1.3.1
320
+ version: '0'
310
321
  requirements: []
311
322
  rubygems_version: 3.2.32
312
323
  signing_key:
@@ -314,10 +325,12 @@ specification_version: 4
314
325
  summary: Use webpack to manage app-like JavaScript modules in Rails
315
326
  test_files:
316
327
  - test/command_test.rb
328
+ - test/compiler_strategy_test.rb
317
329
  - test/compiler_test.rb
318
330
  - test/configuration_test.rb
319
331
  - test/dev_server_runner_test.rb
320
332
  - test/dev_server_test.rb
333
+ - test/digest_strategy_test.rb
321
334
  - test/engine_rake_tasks_test.rb
322
335
  - test/env_test.rb
323
336
  - test/fixtures/beta_package.json
@@ -339,9 +352,11 @@ test_files:
339
352
  - test/mounted_app/test/dummy/config/environment.rb
340
353
  - test/mounted_app/test/dummy/config/webpacker.yml
341
354
  - test/mounted_app/test/dummy/package.json
355
+ - test/mtime_strategy_test.rb
342
356
  - test/rake_tasks_test.rb
343
357
  - test/test_app/Rakefile
344
358
  - test/test_app/app/packs/entrypoints/application.js
359
+ - test/test_app/app/packs/entrypoints/generated/something.js
345
360
  - test/test_app/app/packs/entrypoints/multi_entry.css
346
361
  - test/test_app/app/packs/entrypoints/multi_entry.js
347
362
  - test/test_app/bin/webpacker
@@ -353,6 +368,7 @@ test_files:
353
368
  - test/test_app/config/webpack/webpack.config.js
354
369
  - test/test_app/config/webpacker.yml
355
370
  - test/test_app/config/webpacker_manifest_path.yml
371
+ - test/test_app/config/webpacker_nested_entries.yml
356
372
  - test/test_app/config/webpacker_no_precompile.yml
357
373
  - test/test_app/config/webpacker_other_location.yml
358
374
  - test/test_app/config/webpacker_public_root.yml