jetpacker 0.4.2 → 0.5.0

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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +8 -8
  3. data/.github/workflows/jest.yml +38 -0
  4. data/.github/workflows/js-lint.yml +39 -0
  5. data/.github/workflows/rubocop.yml +39 -0
  6. data/.github/workflows/ruby.yml +70 -0
  7. data/.node-version +1 -1
  8. data/.travis.yml +8 -21
  9. data/CHANGELOG.jetpacker.md +5 -0
  10. data/CHANGELOG.md +44 -2
  11. data/Gemfile +1 -0
  12. data/Gemfile.lock +115 -101
  13. data/README.md +23 -649
  14. data/docs/css.md +58 -3
  15. data/docs/deployment.md +2 -2
  16. data/docs/docker.md +17 -17
  17. data/docs/engines.md +13 -0
  18. data/docs/env.md +0 -2
  19. data/docs/integrations.md +220 -0
  20. data/docs/target.md +22 -0
  21. data/docs/testing.md +2 -3
  22. data/docs/troubleshooting.md +3 -1
  23. data/docs/typescript.md +92 -28
  24. data/docs/webpack-dev-server.md +1 -1
  25. data/jetpacker.gemspec +4 -3
  26. data/lib/install/config/babel.config.js +1 -3
  27. data/lib/install/config/webpacker.yml +1 -4
  28. data/lib/install/examples/react/tsconfig.json +2 -1
  29. data/lib/install/examples/typescript/tsconfig.json +2 -1
  30. data/lib/install/loaders/svelte.js +2 -2
  31. data/lib/install/template.rb +1 -1
  32. data/lib/install/typescript.rb +5 -1
  33. data/lib/jetpacker/version.rb +1 -1
  34. data/lib/tasks/webpacker/check_node.rake +15 -8
  35. data/lib/tasks/webpacker/check_yarn.rake +17 -10
  36. data/lib/tasks/webpacker/clean.rake +12 -8
  37. data/lib/tasks/webpacker/clobber.rake +8 -4
  38. data/lib/tasks/webpacker/yarn_install.rake +5 -16
  39. data/lib/webpacker/commands.rb +33 -9
  40. data/lib/webpacker/compiler.rb +9 -5
  41. data/lib/webpacker/configuration.rb +13 -9
  42. data/lib/webpacker/dev_server_proxy.rb +3 -1
  43. data/lib/webpacker/dev_server_runner.rb +2 -2
  44. data/lib/webpacker/helper.rb +37 -18
  45. data/lib/webpacker/manifest.rb +4 -4
  46. data/lib/webpacker/railtie.rb +0 -43
  47. data/lib/webpacker/runner.rb +1 -0
  48. data/lib/webpacker/turbine.rb +0 -41
  49. data/lib/webpacker/version.rb +1 -1
  50. data/lib/webpacker/webpack_runner.rb +2 -2
  51. data/package.json +39 -39
  52. data/package/__tests__/config.js +12 -1
  53. data/package/__tests__/dev_server.js +2 -0
  54. data/package/__tests__/development.js +14 -1
  55. data/package/config.js +4 -1
  56. data/package/configPath.js +3 -0
  57. data/package/dev_server.js +1 -1
  58. data/package/env.js +1 -2
  59. data/package/environments/__tests__/base.js +29 -2
  60. data/package/environments/base.js +17 -7
  61. data/package/environments/development.js +39 -37
  62. data/package/environments/production.js +1 -3
  63. data/package/rules/babel.js +12 -5
  64. data/package/rules/file.js +1 -0
  65. data/package/rules/node_modules.js +1 -3
  66. data/package/rules/sass.js +7 -1
  67. data/package/utils/helpers.js +1 -1
  68. data/test/compiler_test.rb +8 -3
  69. data/test/configuration_test.rb +8 -7
  70. data/test/dev_server_runner_test.rb +1 -1
  71. data/test/helper_test.rb +3 -0
  72. data/test/manifest_test.rb +37 -6
  73. data/test/rake_tasks_test.rb +11 -0
  74. data/test/test_app/app/javascript/packs/multi_entry.css +4 -0
  75. data/test/test_app/app/javascript/packs/multi_entry.js +4 -0
  76. data/test/test_app/config/application.rb +0 -1
  77. data/test/test_app/config/webpacker.yml +7 -1
  78. data/test/test_app/public/packs/manifest.json +1 -0
  79. data/test/webpack_runner_test.rb +1 -1
  80. data/yarn.lock +3405 -2836
  81. metadata +35 -14
  82. data/gemfiles/Gemfile-rails.4.2.x +0 -9
  83. data/gemfiles/Gemfile-rails.5.0.x +0 -9
  84. data/gemfiles/Gemfile-rails.5.1.x +0 -9
  85. data/lib/install/loaders/typescript.js +0 -11
@@ -5,12 +5,34 @@ class Webpacker::Commands
5
5
  @webpacker = webpacker
6
6
  end
7
7
 
8
- def clean(count = 2)
9
- if config.public_output_path.exist? && config.public_manifest_path.exist? && versions.count > count
10
- versions.drop(count).flat_map(&:last).each do |file|
11
- File.delete(file) if File.file?(file)
12
- logger.info "Removed #{file}"
13
- end
8
+ # Cleanup old assets in the compile directory. By default it will
9
+ # keep the latest version, 2 backups created within the past hour.
10
+ #
11
+ # Examples
12
+ #
13
+ # To force only 1 backup to be kept, set count=1 and age=0.
14
+ #
15
+ # To only keep files created within the last 10 minutes, set count=0 and
16
+ # age=600.
17
+ #
18
+ def clean(count = 2, age = 3600)
19
+ if config.public_output_path.exist? && config.public_manifest_path.exist?
20
+ versions
21
+ .sort
22
+ .reverse
23
+ .each_with_index
24
+ .drop_while do |(mtime, _), index|
25
+ max_age = [0, Time.now - Time.at(mtime)].max
26
+ max_age < age && index < count
27
+ end
28
+ .each do |(_, files), index|
29
+ files.each do |file|
30
+ if File.file?(file)
31
+ File.delete(file)
32
+ logger.info "Removed #{file}"
33
+ end
34
+ end
35
+ end
14
36
  end
15
37
 
16
38
  true
@@ -37,14 +59,16 @@ class Webpacker::Commands
37
59
  manifest_config = Dir.glob("#{config.public_manifest_path}*")
38
60
 
39
61
  packs = all_files - manifest_config - current_version
40
- packs.group_by { |file| File.mtime(file).utc.to_i }.sort.reverse
62
+ packs.reject { |file| File.directory?(file) }.group_by { |file| File.mtime(file).utc.to_i }
41
63
  end
42
64
 
43
65
  def current_version
44
- manifest.refresh.values.map do |value|
66
+ packs = manifest.refresh.values.map do |value|
45
67
  next if value.is_a?(Hash)
46
68
 
47
- File.join(config.root_path, "public", value)
69
+ File.join(config.root_path, "public", "#{value}*")
48
70
  end.compact
71
+
72
+ Dir.glob(packs).uniq
49
73
  end
50
74
  end
@@ -4,6 +4,8 @@ require "digest/sha1"
4
4
  class Webpacker::Compiler
5
5
  # Additional paths that test compiler needs to watch
6
6
  # Webpacker::Compiler.watched_paths << 'bower_components'
7
+ #
8
+ # Deprecated. Use additional_paths in the YAML configuration instead.
7
9
  cattr_accessor(:watched_paths) { [] }
8
10
 
9
11
  # Additional environment variables that the compiler is being run with
@@ -20,9 +22,8 @@ class Webpacker::Compiler
20
22
  if stale?
21
23
  run_webpack.tap do |success|
22
24
  # We used to only record the digest on success
23
- # However, the output file is still written on error, (at least with ts-loader), meaning that the
24
- # digest should still be updated. If it's not, you can end up in a situation where a recompile doesn't
25
- # take place when it should.
25
+ # However, the output file is still written on error, meaning that the digest should still be updated.
26
+ # If it's not, you can end up in a situation where a recompile doesn't take place when it should.
26
27
  # See https://github.com/rails/webpacker/issues/2113
27
28
  record_compilation_digest
28
29
  end
@@ -51,6 +52,8 @@ class Webpacker::Compiler
51
52
  end
52
53
 
53
54
  def watched_files_digest
55
+ warn "Webpacker::Compiler.watched_paths has been deprecated. Set additional_paths in webpacker.yml instead." unless watched_paths.empty?
56
+
54
57
  files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) }
55
58
  file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
56
59
  Digest::SHA1.hexdigest(file_ids.join("/"))
@@ -87,7 +90,7 @@ class Webpacker::Compiler
87
90
 
88
91
  def default_watched_paths
89
92
  [
90
- *config.resolved_paths_globbed,
93
+ *config.additional_paths_globbed,
91
94
  config.source_path_globbed,
92
95
  "yarn.lock", "package.json",
93
96
  "config/webpack/**/*"
@@ -102,6 +105,7 @@ class Webpacker::Compiler
102
105
  return env unless defined?(ActionController::Base)
103
106
 
104
107
  env.merge("WEBPACKER_ASSET_HOST" => ENV.fetch("WEBPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host),
105
- "WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root))
108
+ "WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root),
109
+ "WEBPACKER_CONFIG" => webpacker.config_path.to_s)
106
110
  end
107
111
  end
@@ -27,12 +27,12 @@ class Webpacker::Configuration
27
27
  globbed_path_with_extensions(source_path.relative_path_from(root_path))
28
28
  end
29
29
 
30
- def resolved_paths
31
- fetch(:resolved_paths)
30
+ def additional_paths
31
+ fetch(:additional_paths) + resolved_paths
32
32
  end
33
33
 
34
- def resolved_paths_globbed
35
- resolved_paths.map { |p| globbed_path_with_extensions(p) }
34
+ def additional_paths_globbed
35
+ additional_paths.map { |p| globbed_path_with_extensions(p) }
36
36
  end
37
37
 
38
38
  def source_entry_path
@@ -64,11 +64,7 @@ class Webpacker::Configuration
64
64
  end
65
65
 
66
66
  def check_yarn_integrity=(value)
67
- data[:check_yarn_integrity] = value
68
- end
69
-
70
- def check_yarn_integrity?
71
- fetch(:check_yarn_integrity)
67
+ warn "Webpacker::Configuration#check_yarn_integrity=(value) has been deprecated. The integrity check has been removed from Webpacker so changing this setting will have no effect."
72
68
  end
73
69
 
74
70
  def webpack_compile_output?
@@ -80,6 +76,14 @@ class Webpacker::Configuration
80
76
  end
81
77
 
82
78
  private
79
+ def resolved_paths
80
+ paths = data.fetch(:resolved_paths, [])
81
+
82
+ warn "The resolved_paths option has been deprecated. Use additional_paths instead." unless paths.empty?
83
+
84
+ paths
85
+ end
86
+
83
87
  def fetch(key)
84
88
  data.fetch(key, defaults[key])
85
89
  end
@@ -11,7 +11,9 @@ class Webpacker::DevServerProxy < Rack::Proxy
11
11
 
12
12
  def perform_request(env)
13
13
  if env["PATH_INFO"].start_with?("/#{public_output_uri_path}") && dev_server.running?
14
- env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
14
+ env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = dev_server.host
15
+ env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
16
+ env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = dev_server.port.to_s
15
17
  env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = dev_server.protocol
16
18
  unless dev_server.https?
17
19
  env["HTTPS"] = env["HTTP_X_FORWARDED_SSL"] = "off"
@@ -45,6 +45,7 @@ module Webpacker
45
45
 
46
46
  def execute_cmd
47
47
  env = Webpacker::Compiler.env
48
+ env["WEBPACKER_CONFIG"] = @webpacker_config
48
49
 
49
50
  cmd = if node_modules_bin_exist?
50
51
  ["#{@node_modules_bin_path}/webpack-dev-server"]
@@ -52,9 +53,8 @@ module Webpacker
52
53
  ["yarn", "webpack-dev-server"]
53
54
  end
54
55
 
55
- if ARGV.include?("--debug")
56
+ if @argv.include?("--debug-webpacker")
56
57
  cmd = [ "node", "--inspect-brk"] + cmd
57
- ARGV.delete("--debug")
58
58
  end
59
59
 
60
60
  cmd += ["--config", @webpack_config]
@@ -7,8 +7,8 @@ module Webpacker::Helper
7
7
  end
8
8
 
9
9
  # Computes the relative path for a given Webpacker asset.
10
- # Returns the relative path using manifest.json and passes it to asset_path helper.
11
- # This will use asset_path internally, so most of their behaviors will be the same.
10
+ # Returns the relative path using manifest.json and passes it to path_to_asset helper.
11
+ # This will use path_to_asset internally, so most of their behaviors will be the same.
12
12
  #
13
13
  # Example:
14
14
  #
@@ -19,13 +19,13 @@ module Webpacker::Helper
19
19
  # <%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
20
20
  def asset_pack_path(name, **options)
21
21
  if current_webpacker_instance.config.extract_css? || !stylesheet?(name)
22
- asset_path(current_webpacker_instance.manifest.lookup!(name), options)
22
+ path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
23
23
  end
24
24
  end
25
25
 
26
26
  # Computes the absolute path for a given Webpacker asset.
27
- # Returns the absolute path using manifest.json and passes it to asset_url helper.
28
- # This will use asset_url internally, so most of their behaviors will be the same.
27
+ # Returns the absolute path using manifest.json and passes it to url_to_asset helper.
28
+ # This will use url_to_asset internally, so most of their behaviors will be the same.
29
29
  #
30
30
  # Example:
31
31
  #
@@ -36,7 +36,7 @@ module Webpacker::Helper
36
36
  # <%= asset_pack_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
37
37
  def asset_pack_url(name, **options)
38
38
  if current_webpacker_instance.config.extract_css? || !stylesheet?(name)
39
- asset_url(current_webpacker_instance.manifest.lookup!(name), options)
39
+ url_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
40
40
  end
41
41
  end
42
42
 
@@ -46,7 +46,16 @@ module Webpacker::Helper
46
46
  #
47
47
  # <%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
48
48
  # <img alt='Edit Entry' src='/packs/application-k344a6d59eef8632c9d1.png' width='16' height='10' />
49
+ #
50
+ # <%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
51
+ # <img srcset= "/packs/picture-2x-7cca48e6cae66ec07b8e.png 2x" src="/packs/picture-c38deda30895059837cf.png" >
49
52
  def image_pack_tag(name, **options)
53
+ if options[:srcset] && !options[:srcset].is_a?(String)
54
+ options[:srcset] = options[:srcset].map do |src_name, size|
55
+ "#{resolve_path_to_image(src_name)} #{size}"
56
+ end.join(", ")
57
+ end
58
+
50
59
  image_tag(resolve_path_to_image(name), options)
51
60
  end
52
61
 
@@ -61,7 +70,7 @@ module Webpacker::Helper
61
70
  end
62
71
 
63
72
  # Creates a script tag that references the named pack file, as compiled by webpack per the entries list
64
- # in config/webpack/shared.js. By default, this list is auto-generated to match everything in
73
+ # in package/environments/base.js. By default, this list is auto-generated to match everything in
65
74
  # app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
66
75
  #
67
76
  # Example:
@@ -73,10 +82,11 @@ module Webpacker::Helper
73
82
  end
74
83
 
75
84
  # Creates script tags that reference the js chunks from entrypoints when using split chunks API,
76
- # as compiled by webpack per the entries list in config/webpack/shared.js.
85
+ # as compiled by webpack per the entries list in package/environments/base.js.
77
86
  # By default, this list is auto-generated to match everything in
78
87
  # app/javascript/packs/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
79
88
  # See: https://webpack.js.org/plugins/split-chunks-plugin/
89
+ #
80
90
  # Example:
81
91
  #
82
92
  # <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %> # =>
@@ -85,11 +95,15 @@ module Webpacker::Helper
85
95
  # <script src="/packs/calendar-1016838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
86
96
  # <script src="/packs/map~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
87
97
  # <script src="/packs/map-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
98
+ #
88
99
  # DO:
89
- # <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
100
+ #
101
+ # <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
102
+ #
90
103
  # DON'T:
91
- # <%= javascript_packs_with_chunks_tag 'calendar' %>
92
- # <%= javascript_packs_with_chunks_tag 'map' %>
104
+ #
105
+ # <%= javascript_packs_with_chunks_tag 'calendar' %>
106
+ # <%= javascript_packs_with_chunks_tag 'map' %>
93
107
  def javascript_packs_with_chunks_tag(*names, **options)
94
108
  javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options)
95
109
  end
@@ -97,6 +111,7 @@ module Webpacker::Helper
97
111
  # Creates a link tag, for preloading, that references a given Webpacker asset.
98
112
  # In production mode, the digested reference is automatically looked up.
99
113
  # See: https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
114
+ #
100
115
  # Example:
101
116
  #
102
117
  # <%= preload_pack_asset 'fonts/fa-regular-400.woff2' %> # =>
@@ -110,7 +125,7 @@ module Webpacker::Helper
110
125
  end
111
126
 
112
127
  # Creates a link tag that references the named pack file, as compiled by webpack per the entries list
113
- # in config/webpack/shared.js. By default, this list is auto-generated to match everything in
128
+ # in package/environments/base.js. By default, this list is auto-generated to match everything in
114
129
  # app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
115
130
  #
116
131
  # Note: If the development server is running and hot module replacement is active, this will return nothing.
@@ -132,7 +147,7 @@ module Webpacker::Helper
132
147
  end
133
148
 
134
149
  # Creates link tags that reference the css chunks from entrypoints when using split chunks API,
135
- # as compiled by webpack per the entries list in config/webpack/shared.js.
150
+ # as compiled by webpack per the entries list in package/environments/base.js.
136
151
  # By default, this list is auto-generated to match everything in
137
152
  # app/javascript/packs/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
138
153
  # See: https://webpack.js.org/plugins/split-chunks-plugin/
@@ -143,11 +158,15 @@ module Webpacker::Helper
143
158
  # <link rel="stylesheet" media="screen" href="/packs/3-8c7ce31a.chunk.css" />
144
159
  # <link rel="stylesheet" media="screen" href="/packs/calendar-8c7ce31a.chunk.css" />
145
160
  # <link rel="stylesheet" media="screen" href="/packs/map-8c7ce31a.chunk.css" />
161
+ #
146
162
  # DO:
147
- # <%= stylesheet_packs_with_chunks_tag 'calendar', 'map' %>
163
+ #
164
+ # <%= stylesheet_packs_with_chunks_tag 'calendar', 'map' %>
165
+ #
148
166
  # DON'T:
149
- # <%= stylesheet_packs_with_chunks_tag 'calendar' %>
150
- # <%= stylesheet_packs_with_chunks_tag 'map' %>
167
+ #
168
+ # <%= stylesheet_packs_with_chunks_tag 'calendar' %>
169
+ # <%= stylesheet_packs_with_chunks_tag 'map' %>
151
170
  def stylesheet_packs_with_chunks_tag(*names, **options)
152
171
  if current_webpacker_instance.config.extract_css?
153
172
  stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
@@ -169,8 +188,8 @@ module Webpacker::Helper
169
188
 
170
189
  def resolve_path_to_image(name)
171
190
  path = name.starts_with?("media/images/") ? name : "media/images/#{name}"
172
- asset_path(current_webpacker_instance.manifest.lookup!(path))
191
+ path_to_asset(current_webpacker_instance.manifest.lookup!(path))
173
192
  rescue
174
- asset_path(current_webpacker_instance.manifest.lookup!(name))
193
+ path_to_asset(current_webpacker_instance.manifest.lookup!(name))
175
194
  end
176
195
  end
@@ -29,7 +29,7 @@ class Webpacker::Manifest
29
29
  end
30
30
 
31
31
  def lookup_pack_with_chunks!(name, pack_type = {})
32
- lookup_pack_with_chunks(name, pack_type) || handle_missing_entry(name)
32
+ lookup_pack_with_chunks(name, pack_type) || handle_missing_entry(name, pack_type)
33
33
  end
34
34
 
35
35
  # Computes the relative path for a given Webpacker asset using manifest.json.
@@ -46,7 +46,7 @@ class Webpacker::Manifest
46
46
 
47
47
  # Like lookup, except that if no asset is found, raises a Webpacker::Manifest::MissingEntryError.
48
48
  def lookup!(name, pack_type = {})
49
- lookup(name, pack_type) || handle_missing_entry(name)
49
+ lookup(name, pack_type) || handle_missing_entry(name, pack_type)
50
50
  end
51
51
 
52
52
  private
@@ -75,8 +75,8 @@ class Webpacker::Manifest
75
75
  "#{name}.#{manifest_type(pack_type)}"
76
76
  end
77
77
 
78
- def handle_missing_entry(name)
79
- raise Webpacker::Manifest::MissingEntryError, missing_file_from_manifest_error(name)
78
+ def handle_missing_entry(name, pack_type)
79
+ raise Webpacker::Manifest::MissingEntryError, missing_file_from_manifest_error(full_pack_name(name, pack_type[:type]))
80
80
  end
81
81
 
82
82
  def load
@@ -7,49 +7,6 @@ class Webpacker::Engine < ::Rails::Engine
7
7
  # Allows Webpacker config values to be set via Rails env config files
8
8
  config.webpacker = ActiveSupport::OrderedOptions.new
9
9
 
10
- initializer "webpacker.set_configs" do |app|
11
- if app.config.webpacker.key?(:check_yarn_integrity)
12
- Webpacker.config.check_yarn_integrity = app.config.webpacker.check_yarn_integrity
13
- end
14
- end
15
-
16
- # ================================
17
- # Check Yarn Integrity Initializer
18
- # ================================
19
- #
20
- # development (on by default):
21
- #
22
- # to turn off:
23
- # - edit config/environments/development.rb
24
- # - add `config.webpacker.check_yarn_integrity = false`
25
- #
26
- # production (off by default):
27
- #
28
- # to turn on:
29
- # - edit config/environments/production.rb
30
- # - add `config.webpacker.check_yarn_integrity = true`
31
- initializer "webpacker.yarn_check" do |app|
32
- if File.exist?("yarn.lock") && Webpacker.config.config_path.exist? && Webpacker.config.check_yarn_integrity?
33
- output = `yarn check --integrity && yarn check --verify-tree 2>&1`
34
-
35
- unless $?.success?
36
- $stderr.puts "\n\n"
37
- $stderr.puts "========================================"
38
- $stderr.puts " Your Yarn packages are out of date!"
39
- $stderr.puts " Please run `yarn install --check-files` to update."
40
- $stderr.puts "========================================"
41
- $stderr.puts "\n\n"
42
- $stderr.puts "To disable this check, please change `check_yarn_integrity`"
43
- $stderr.puts "to `false` in your webpacker config file (config/webpacker.yml)."
44
- $stderr.puts "\n\n"
45
- $stderr.puts output
46
- $stderr.puts "\n\n"
47
-
48
- exit(1)
49
- end
50
- end
51
- end
52
-
53
10
  initializer "webpacker.proxy" do |app|
54
11
  insert_middleware = Webpacker.config.dev_server.present? rescue nil
55
12
  if insert_middleware
@@ -12,6 +12,7 @@ module Webpacker
12
12
  @app_path = File.expand_path(".", Dir.pwd)
13
13
  @node_modules_bin_path = ENV["WEBPACKER_NODE_MODULES_BIN_PATH"] || `yarn bin`.chomp
14
14
  @webpack_config = File.join(@app_path, "config/webpack/#{ENV["NODE_ENV"]}.js")
15
+ @webpacker_config = File.join(@app_path, "config/webpacker.yml")
15
16
 
16
17
  unless File.exist?(@webpack_config)
17
18
  $stderr.puts "webpack config #{@webpack_config} not found, please run 'bundle exec rails webpacker:install' to install Webpacker with default configs or add the missing config file for your custom environment."
@@ -7,49 +7,8 @@ module Webpacker
7
7
  initializer "webpacker.set_configs" do |app|
8
8
  # Allows Webpacker config values to be set via Jets env config files
9
9
  app.config.webpacker ||= ActiveSupport::OrderedOptions.new # TODO: all config access outside initializer block
10
-
11
- if app.config.webpacker.key?(:check_yarn_integrity)
12
- Webpacker.config.check_yarn_integrity = app.config.webpacker.check_yarn_integrity
13
- end
14
10
  end
15
11
 
16
- # ================================
17
- # Check Yarn Integrity Initializer
18
- # ================================
19
- #
20
- # development (on by default):
21
- #
22
- # to turn off:
23
- # - edit config/environments/development.rb
24
- # - add `config.webpacker.check_yarn_integrity = false`
25
- #
26
- # production (off by default):
27
- #
28
- # to turn on:
29
- # - edit config/environments/production.rb
30
- # - add `config.webpacker.check_yarn_integrity = true`
31
- initializer "webpacker.yarn_check" do |app|
32
- if File.exist?("yarn.lock") && Webpacker.config.config_path.exist? && Webpacker.config.check_yarn_integrity?
33
- output = `yarn check --integrity && yarn check --verify-tree 2>&1`
34
-
35
- unless $?.success?
36
- $stderr.puts "\n\n"
37
- $stderr.puts "========================================"
38
- $stderr.puts " Your Yarn packages are out of date!"
39
- $stderr.puts " Please run `yarn install --check-files` to update."
40
- $stderr.puts "========================================"
41
- $stderr.puts "\n\n"
42
- $stderr.puts "To disable this check, please change `check_yarn_integrity`"
43
- $stderr.puts "to `false` in your webpacker config file (config/webpacker.yml)."
44
- $stderr.puts "\n\n"
45
- $stderr.puts output
46
- $stderr.puts "\n\n"
47
-
48
- exit(1)
49
- end
50
- end
51
- end unless ENV['AWS_LAMBDA_FUNCTION_NAME'] # dont run yarn check on lambda
52
-
53
12
  # TODO: add support load middleware in a Turbine
54
13
  # initializer "webpacker.proxy" do |app|
55
14
  # insert_middleware = Webpacker.config.dev_server.present? rescue nil