webpacker 5.2.1 → 6.0.0.beta.4

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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -1
  3. data/.github/workflows/jest.yml +1 -1
  4. data/.github/workflows/js-lint.yml +1 -1
  5. data/.github/workflows/ruby.yml +9 -6
  6. data/.gitignore +2 -0
  7. data/.node-version +1 -1
  8. data/.rubocop.yml +11 -16
  9. data/6_0_upgrade.md +48 -0
  10. data/CHANGELOG.md +27 -0
  11. data/CONTRIBUTING.md +1 -1
  12. data/Gemfile.lock +23 -15
  13. data/README.md +252 -103
  14. data/config/README.md +3 -0
  15. data/config/webpacker.yml +1 -0
  16. data/lib/install/config/webpack/base.js +3 -0
  17. data/lib/install/config/webpack/development.js +2 -2
  18. data/lib/install/config/webpack/production.js +2 -2
  19. data/lib/install/config/webpack/test.js +2 -2
  20. data/lib/install/config/webpacker.yml +12 -39
  21. data/lib/install/{javascript/packs → packs/entrypoints}/application.js +5 -3
  22. data/lib/install/template.rb +36 -22
  23. data/lib/tasks/webpacker.rake +2 -11
  24. data/lib/tasks/webpacker/binstubs.rake +6 -4
  25. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  26. data/lib/tasks/webpacker/check_yarn.rake +1 -2
  27. data/lib/tasks/webpacker/compile.rake +4 -2
  28. data/lib/tasks/webpacker/info.rake +12 -10
  29. data/lib/tasks/webpacker/install.rake +6 -4
  30. data/lib/tasks/webpacker/verify_install.rake +2 -1
  31. data/lib/tasks/webpacker/yarn_install.rake +9 -1
  32. data/lib/webpacker/commands.rb +3 -2
  33. data/lib/webpacker/compiler.rb +16 -9
  34. data/lib/webpacker/configuration.rb +6 -30
  35. data/lib/webpacker/dev_server_runner.rb +23 -2
  36. data/lib/webpacker/helper.rb +26 -36
  37. data/lib/webpacker/manifest.rb +1 -1
  38. data/lib/webpacker/version.rb +1 -1
  39. data/lib/webpacker/webpack_runner.rb +6 -0
  40. data/package.json +23 -39
  41. data/package/__tests__/config.js +5 -37
  42. data/package/__tests__/development.js +11 -12
  43. data/package/__tests__/env.js +12 -4
  44. data/package/__tests__/index.js +9 -0
  45. data/package/__tests__/production.js +6 -6
  46. data/package/__tests__/staging.js +7 -6
  47. data/package/__tests__/test.js +4 -5
  48. data/package/babel/preset.js +55 -0
  49. data/package/config.js +3 -11
  50. data/package/env.js +8 -2
  51. data/package/environments/__tests__/base.js +19 -51
  52. data/package/environments/base.js +65 -125
  53. data/package/environments/development.js +46 -44
  54. data/package/environments/production.js +66 -64
  55. data/package/environments/test.js +2 -2
  56. data/package/index.js +13 -8
  57. data/package/rules/babel.js +9 -7
  58. data/package/rules/coffee.js +6 -0
  59. data/package/rules/erb.js +15 -0
  60. data/package/rules/file.js +21 -19
  61. data/package/rules/index.js +16 -18
  62. data/package/rules/less.js +22 -0
  63. data/package/rules/raw.js +5 -0
  64. data/package/rules/sass.js +12 -9
  65. data/package/rules/stylus.js +26 -0
  66. data/package/utils/get_style_rule.js +26 -36
  67. data/package/utils/helpers.js +26 -35
  68. data/test/compiler_test.rb +0 -12
  69. data/test/configuration_test.rb +3 -34
  70. data/test/dev_server_runner_test.rb +33 -6
  71. data/test/engine_rake_tasks_test.rb +39 -0
  72. data/test/helper_test.rb +15 -9
  73. data/test/mounted_app/Rakefile +4 -0
  74. data/test/mounted_app/test/dummy/Rakefile +3 -0
  75. data/test/mounted_app/test/dummy/bin/rails +3 -0
  76. data/test/mounted_app/test/dummy/bin/rake +3 -0
  77. data/test/mounted_app/test/dummy/config.ru +5 -0
  78. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  79. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  80. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  81. data/test/mounted_app/test/dummy/package.json +7 -0
  82. data/test/rake_tasks_test.rb +1 -10
  83. data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
  84. data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.css +0 -0
  85. data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.js +0 -0
  86. data/test/test_app/config/webpacker.yml +3 -27
  87. data/test/test_app/config/webpacker_public_root.yml +0 -1
  88. data/test/test_app/public/packs/manifest.json +17 -13
  89. data/test/test_app/some.config.js +0 -0
  90. data/test/webpack_runner_test.rb +9 -3
  91. data/webpacker.gemspec +1 -1
  92. data/yarn.lock +1858 -4915
  93. metadata +54 -97
  94. data/.travis.yml +0 -43
  95. data/docs/assets.md +0 -119
  96. data/docs/cloud9.md +0 -310
  97. data/docs/css.md +0 -308
  98. data/docs/deployment.md +0 -130
  99. data/docs/docker.md +0 -68
  100. data/docs/engines.md +0 -213
  101. data/docs/env.md +0 -63
  102. data/docs/es6.md +0 -72
  103. data/docs/folder-structure.md +0 -66
  104. data/docs/integrations.md +0 -220
  105. data/docs/misc.md +0 -23
  106. data/docs/props.md +0 -223
  107. data/docs/target.md +0 -22
  108. data/docs/testing.md +0 -136
  109. data/docs/troubleshooting.md +0 -158
  110. data/docs/typescript.md +0 -190
  111. data/docs/v4-upgrade.md +0 -142
  112. data/docs/webpack-dev-server.md +0 -92
  113. data/docs/webpack.md +0 -364
  114. data/docs/yarn.md +0 -23
  115. data/lib/install/angular.rb +0 -23
  116. data/lib/install/coffee.rb +0 -25
  117. data/lib/install/config/.browserslistrc +0 -1
  118. data/lib/install/config/babel.config.js +0 -70
  119. data/lib/install/config/postcss.config.js +0 -12
  120. data/lib/install/config/webpack/environment.js +0 -3
  121. data/lib/install/elm.rb +0 -39
  122. data/lib/install/erb.rb +0 -25
  123. data/lib/install/examples/angular/hello_angular.js +0 -7
  124. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  125. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  126. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  127. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  128. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  129. data/lib/install/examples/elm/Main.elm +0 -55
  130. data/lib/install/examples/elm/hello_elm.js +0 -16
  131. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  132. data/lib/install/examples/react/babel.config.js +0 -87
  133. data/lib/install/examples/react/hello_react.jsx +0 -26
  134. data/lib/install/examples/react/tsconfig.json +0 -21
  135. data/lib/install/examples/stimulus/application.js +0 -1
  136. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  137. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  138. data/lib/install/examples/svelte/app.svelte +0 -11
  139. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  140. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  141. data/lib/install/examples/typescript/tsconfig.json +0 -24
  142. data/lib/install/examples/vue/app.vue +0 -22
  143. data/lib/install/examples/vue/hello_vue.js +0 -72
  144. data/lib/install/loaders/coffee.js +0 -6
  145. data/lib/install/loaders/elm.js +0 -25
  146. data/lib/install/loaders/erb.js +0 -11
  147. data/lib/install/loaders/svelte.js +0 -9
  148. data/lib/install/loaders/vue.js +0 -6
  149. data/lib/install/react.rb +0 -18
  150. data/lib/install/stimulus.rb +0 -12
  151. data/lib/install/svelte.rb +0 -29
  152. data/lib/install/typescript.rb +0 -39
  153. data/lib/install/vue.rb +0 -49
  154. data/lib/tasks/installers.rake +0 -42
  155. data/package/config_types/__tests__/config_list.js +0 -118
  156. data/package/config_types/__tests__/config_object.js +0 -43
  157. data/package/config_types/config_list.js +0 -75
  158. data/package/config_types/config_object.js +0 -55
  159. data/package/config_types/index.js +0 -7
  160. data/package/rules/module.css.js +0 -3
  161. data/package/rules/module.sass.js +0 -8
  162. data/package/rules/node_modules.js +0 -22
  163. data/package/utils/__tests__/deep_assign.js +0 -32
  164. data/package/utils/__tests__/deep_merge.js +0 -10
  165. data/package/utils/__tests__/get_style_rule.js +0 -65
  166. data/package/utils/__tests__/objectify.js +0 -9
  167. data/package/utils/deep_assign.js +0 -22
  168. data/package/utils/deep_merge.js +0 -22
  169. data/package/utils/objectify.js +0 -3
@@ -0,0 +1,3 @@
1
+ # Note
2
+
3
+ This directory exists for Jest specs that execute code expecting the Rails config directory at this path.
@@ -0,0 +1 @@
1
+ config/lib/install/config/webpacker.yml
@@ -0,0 +1,3 @@
1
+ const { webpackConfig } = require('@rails/webpacker')
2
+
3
+ module.exports = webpackConfig
@@ -1,5 +1,5 @@
1
1
  process.env.NODE_ENV = process.env.NODE_ENV || 'development'
2
2
 
3
- const environment = require('./environment')
3
+ const webpackConfig = require('./base')
4
4
 
5
- module.exports = environment.toWebpackConfig()
5
+ module.exports = webpackConfig
@@ -1,5 +1,5 @@
1
1
  process.env.NODE_ENV = process.env.NODE_ENV || 'production'
2
2
 
3
- const environment = require('./environment')
3
+ const webpackConfig = require('./base')
4
4
 
5
- module.exports = environment.toWebpackConfig()
5
+ module.exports = webpackConfig
@@ -1,5 +1,5 @@
1
1
  process.env.NODE_ENV = process.env.NODE_ENV || 'development'
2
2
 
3
- const environment = require('./environment')
3
+ const webpackConfig = require('./base')
4
4
 
5
- module.exports = environment.toWebpackConfig()
5
+ module.exports = webpackConfig
@@ -1,8 +1,8 @@
1
1
  # Note: You must restart bin/webpack-dev-server for changes to take effect
2
2
 
3
3
  default: &default
4
- source_path: app/javascript
5
- source_entry_path: packs
4
+ source_path: app/packs
5
+ source_entry_path: entrypoints
6
6
  public_root_path: public
7
7
  public_output_path: packs
8
8
  cache_path: tmp/cache/webpacker
@@ -15,38 +15,6 @@ default: &default
15
15
  # Reload manifest.json on all requests so we reload latest compiled packs
16
16
  cache_manifest: false
17
17
 
18
- # Extract and emit a css file
19
- extract_css: false
20
-
21
- static_assets_extensions:
22
- - .jpg
23
- - .jpeg
24
- - .png
25
- - .gif
26
- - .tiff
27
- - .ico
28
- - .svg
29
- - .eot
30
- - .otf
31
- - .ttf
32
- - .woff
33
- - .woff2
34
-
35
- extensions:
36
- - .mjs
37
- - .js
38
- - .sass
39
- - .scss
40
- - .css
41
- - .module.sass
42
- - .module.scss
43
- - .module.css
44
- - .png
45
- - .svg
46
- - .gif
47
- - .jpeg
48
- - .jpg
49
-
50
18
  development:
51
19
  <<: *default
52
20
  compile: true
@@ -57,13 +25,22 @@ development:
57
25
  host: localhost
58
26
  port: 3035
59
27
  public: localhost:3035
28
+ # Inject browserside javascript that required by both HMR and Live(full) reload
29
+ inject_client: true
30
+ # Hot Module Replacement updates modules while the application is running without a full reload
60
31
  hmr: false
61
- # Inline should be set to true if using HMR
32
+ # Inline should be set to true if using HMR; it inserts a script to take care of live reloading
62
33
  inline: true
34
+ # Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
63
35
  overlay: true
36
+ # Should we use gzip compression?
64
37
  compress: true
38
+ # Note that apps that do not check the host are vulnerable to DNS rebinding attacks
65
39
  disable_host_check: true
40
+ # This option lets the browser open with your local IP
66
41
  use_local_ip: false
42
+ # When enabled, nothing except the initial startup information will be written to the console.
43
+ # This also means that errors or warnings from webpack are not visible.
67
44
  quiet: false
68
45
  pretty: false
69
46
  headers:
@@ -71,7 +48,6 @@ development:
71
48
  watch_options:
72
49
  ignored: '**/node_modules/**'
73
50
 
74
-
75
51
  test:
76
52
  <<: *default
77
53
  compile: true
@@ -85,8 +61,5 @@ production:
85
61
  # Production depends on precompilation of packs prior to booting for performance.
86
62
  compile: false
87
63
 
88
- # Extract and emit a css file
89
- extract_css: true
90
-
91
64
  # Cache manifest.json for performance
92
65
  cache_manifest: true
@@ -1,13 +1,12 @@
1
1
  /* eslint no-console:0 */
2
2
  // This file is automatically compiled by Webpack, along with any other files
3
3
  // present in this directory. You're encouraged to place your actual application logic in
4
- // a relevant structure within app/javascript and only use these pack files to reference
4
+ // a relevant structure within app/packs and only use these pack files to reference
5
5
  // that code so it'll be compiled.
6
6
  //
7
- // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
7
+ // To reference this file, add <%= javascript_packs_with_chunks_tag 'application' %> to the appropriate
8
8
  // layout file, like app/views/layouts/application.html.erb
9
9
 
10
-
11
10
  // Uncomment to copy all static images under ../images to the output folder and reference
12
11
  // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
13
12
  // or the `imagePath` JavaScript helper below.
@@ -15,4 +14,7 @@
15
14
  // const images = require.context('../images', true)
16
15
  // const imagePath = (name) => images(name, true)
17
16
 
17
+ import 'core-js/stable'
18
+ import 'regenerator-runtime/runtime'
19
+
18
20
  console.log('Hello World from Webpacker')
@@ -4,26 +4,18 @@ copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
4
4
  say "Copying webpack core config"
5
5
  directory "#{__dir__}/config/webpack", "config/webpack"
6
6
 
7
- say "Copying postcss.config.js to app root directory"
8
- copy_file "#{__dir__}/config/postcss.config.js", "postcss.config.js"
9
-
10
- say "Copying babel.config.js to app root directory"
11
- copy_file "#{__dir__}/config/babel.config.js", "babel.config.js"
12
-
13
- say "Copying .browserslistrc to app root directory"
14
- copy_file "#{__dir__}/config/.browserslistrc", ".browserslistrc"
15
-
16
7
  if Dir.exists?(Webpacker.config.source_path)
17
- say "The JavaScript app source directory already exists"
8
+ say "The packs app source directory already exists"
18
9
  else
19
- say "Creating JavaScript app source directory"
20
- directory "#{__dir__}/javascript", Webpacker.config.source_path
10
+ say "Creating packs app source directory"
11
+ directory "#{__dir__}/packs", Webpacker.config.source_path
21
12
  end
22
13
 
23
14
  apply "#{__dir__}/binstubs.rb"
24
15
 
25
- if File.exists?(".gitignore")
26
- append_to_file ".gitignore" do
16
+ git_ignore_path = Rails.root.join(".gitignore")
17
+ if File.exists?(git_ignore_path)
18
+ append_to_file git_ignore_path do
27
19
  "\n" +
28
20
  "/public/packs\n" +
29
21
  "/public/packs-test\n" +
@@ -34,16 +26,38 @@ if File.exists?(".gitignore")
34
26
  end
35
27
  end
36
28
 
37
- if Webpacker::VERSION =~ /^[0-9]+\.[0-9]+\.[0-9]+$/
38
- say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
39
- run "yarn add @rails/webpacker@#{Webpacker::VERSION}"
40
- else
41
- say "Installing all JavaScript dependencies [from prerelease rails/webpacker]"
42
- run "yarn add @rails/webpacker@next"
29
+ Dir.chdir(Rails.root) do
30
+ if Webpacker::VERSION =~ /^[0-9]+\.[0-9]+\.[0-9]+$/
31
+ say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
32
+ run "yarn add @rails/webpacker@#{Webpacker::VERSION}"
33
+ else
34
+ say "Installing all JavaScript dependencies [from prerelease rails/webpacker]"
35
+ run "yarn add @rails/webpacker@next"
36
+ end
37
+
38
+ package_json = File.read("#{__dir__}/../../package.json")
39
+ webpack_version = package_json.match(/"webpack": "(.*)"/)[1]
40
+ webpack_cli_version = package_json.match(/"webpack-cli": "(.*)"/)[1]
41
+
42
+ # needed for experimental Yarn 2 support and should not harm Yarn 1
43
+ say "Installing webpack and webpack-cli as direct dependencies"
44
+ run "yarn add webpack@#{webpack_version} webpack-cli@#{webpack_cli_version}"
45
+
46
+ say "Installing dev server for live reloading"
47
+ run "yarn add --dev webpack-dev-server @webpack-cli/serve"
43
48
  end
44
49
 
45
- say "Installing dev server for live reloading"
46
- run "yarn add --dev webpack-dev-server"
50
+ insert_into_file Rails.root.join("package.json").to_s, before: /\n}\n*$/ do
51
+ <<~JSON.chomp
52
+ ,
53
+ "babel": {
54
+ "presets": ["./node_modules/@rails/webpacker/package/babel/preset.js"]
55
+ },
56
+ "browserslist": [
57
+ "defaults"
58
+ ]
59
+ JSON
60
+ end
47
61
 
48
62
  if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
49
63
  say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
@@ -6,19 +6,10 @@ tasks = {
6
6
  "webpacker:clobber" => "Removes the webpack compiled output directory",
7
7
  "webpacker:check_node" => "Verifies if Node.js is installed",
8
8
  "webpacker:check_yarn" => "Verifies if Yarn is installed",
9
- "webpacker:check_binstubs" => "Verifies that webpack & webpack-dev-server are present",
9
+ "webpacker:check_binstubs" => "Verifies that bin/webpack is present",
10
10
  "webpacker:binstubs" => "Installs Webpacker binstubs in this application",
11
11
  "webpacker:verify_install" => "Verifies if Webpacker is installed",
12
- "webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn",
13
- "webpacker:install:react" => "Installs and setup example React component",
14
- "webpacker:install:vue" => "Installs and setup example Vue component",
15
- "webpacker:install:angular" => "Installs and setup example Angular component",
16
- "webpacker:install:elm" => "Installs and setup example Elm component",
17
- "webpacker:install:svelte" => "Installs and setup example Svelte component",
18
- "webpacker:install:stimulus" => "Installs and setup example Stimulus component",
19
- "webpacker:install:erb" => "Installs Erb loader with an example",
20
- "webpacker:install:coffee" => "Installs CoffeeScript loader with an example",
21
- "webpacker:install:typescript" => "Installs Typescript loader with an example"
12
+ "webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
22
13
  }.freeze
23
14
 
24
15
  desc "Lists all available tasks in Webpacker"
@@ -1,13 +1,15 @@
1
1
  binstubs_template_path = File.expand_path("../../install/binstubs.rb", __dir__).freeze
2
- bin_path = ENV["BUNDLE_BIN"] || "./bin"
2
+ bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
3
3
 
4
4
  namespace :webpacker do
5
5
  desc "Installs Webpacker binstubs in this application"
6
- task binstubs: [:check_node, :check_yarn] do
6
+ task binstubs: [:check_node, :check_yarn] do |task|
7
+ prefix = task.name.split(/#|webpacker:binstubs/).first
8
+
7
9
  if Rails::VERSION::MAJOR >= 5
8
- exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{binstubs_template_path}"
10
+ exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION=#{binstubs_template_path}"
9
11
  else
10
- exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION=#{binstubs_template_path}"
12
+ exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION=#{binstubs_template_path}"
11
13
  end
12
14
  end
13
15
  end
@@ -1,10 +1,10 @@
1
1
  namespace :webpacker do
2
- desc "Verifies that webpack & webpack-dev-server are present."
2
+ desc "Verifies that bin/webpack is present"
3
3
  task :check_binstubs do
4
- unless File.exist?("bin/webpack")
5
- $stderr.puts "webpack binstubs not found.\n"\
4
+ unless File.exist?(Rails.root.join("bin/webpack"))
5
+ $stderr.puts "webpack binstub not found.\n"\
6
6
  "Have you run rails webpacker:install ?\n"\
7
- "Make sure the bin directory or binstubs are not included in .gitignore\n"\
7
+ "Make sure the bin directory and bin/webpack are not included in .gitignore\n"\
8
8
  "Exiting!"
9
9
  exit!
10
10
  end
@@ -9,13 +9,12 @@ namespace :webpacker do
9
9
  pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
10
10
  yarn_range = JSON.parse(pkg_path.read)["engines"]["yarn"]
11
11
  is_valid = SemanticRange.satisfies?(yarn_version, yarn_range) rescue false
12
- is_unsupported = SemanticRange.satisfies?(yarn_version, ">=2.0.0") rescue false
12
+ is_unsupported = SemanticRange.satisfies?(yarn_version, ">=3.0.0") rescue false
13
13
 
14
14
  unless is_valid
15
15
  $stderr.puts "Webpacker requires Yarn \"#{yarn_range}\" and you are using #{yarn_version}"
16
16
  if is_unsupported
17
17
  $stderr.puts "This version of Webpacker does not support Yarn #{yarn_version}. Please downgrade to a supported version of Yarn https://yarnpkg.com/lang/en/docs/install/"
18
- $stderr.puts "For information on using Webpacker with Yarn 2.0, see https://github.com/rails/webpacker/issues/2112"
19
18
  else
20
19
  $stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/"
21
20
  end
@@ -10,8 +10,10 @@ end
10
10
  def enhance_assets_precompile
11
11
  # yarn:install was added in Rails 5.1
12
12
  deps = yarn_install_available? ? [] : ["webpacker:yarn_install"]
13
- Rake::Task["assets:precompile"].enhance(deps) do
14
- Rake::Task["webpacker:compile"].invoke
13
+ Rake::Task["assets:precompile"].enhance(deps) do |task|
14
+ prefix = task.name.split(/#|assets:precompile/).first
15
+
16
+ Rake::Task["#{prefix}webpacker:compile"].invoke
15
17
  end
16
18
  end
17
19
 
@@ -3,17 +3,19 @@ require "webpacker/version"
3
3
  namespace :webpacker do
4
4
  desc "Provide information on Webpacker's environment"
5
5
  task :info do
6
- $stdout.puts "Ruby: #{`ruby --version`}"
7
- $stdout.puts "Rails: #{Rails.version}"
8
- $stdout.puts "Webpacker: #{Webpacker::VERSION}"
9
- $stdout.puts "Node: #{`node --version`}"
10
- $stdout.puts "Yarn: #{`yarn --version`}"
6
+ Dir.chdir(Rails.root) do
7
+ $stdout.puts "Ruby: #{`ruby --version`}"
8
+ $stdout.puts "Rails: #{Rails.version}"
9
+ $stdout.puts "Webpacker: #{Webpacker::VERSION}"
10
+ $stdout.puts "Node: #{`node --version`}"
11
+ $stdout.puts "Yarn: #{`yarn --version`}"
11
12
 
12
- $stdout.puts "\n"
13
- $stdout.puts "@rails/webpacker: \n#{`npm list @rails/webpacker version`}"
13
+ $stdout.puts "\n"
14
+ $stdout.puts "@rails/webpacker: \n#{`npm list @rails/webpacker version`}"
14
15
 
15
- $stdout.puts "Is bin/webpack present?: #{File.exist? 'bin/webpack'}"
16
- $stdout.puts "Is bin/webpack-dev-server present?: #{File.exist? 'bin/webpack-dev-server'}"
17
- $stdout.puts "Is bin/yarn present?: #{File.exist? 'bin/yarn'}"
16
+ $stdout.puts "Is bin/webpack present?: #{File.exist? 'bin/webpack'}"
17
+ $stdout.puts "Is bin/webpack-dev-server present?: #{File.exist? 'bin/webpack-dev-server'}"
18
+ $stdout.puts "Is bin/yarn present?: #{File.exist? 'bin/yarn'}"
19
+ end
18
20
  end
19
21
  end
@@ -1,13 +1,15 @@
1
1
  install_template_path = File.expand_path("../../install/template.rb", __dir__).freeze
2
- bin_path = ENV["BUNDLE_BIN"] || "./bin"
2
+ bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
3
3
 
4
4
  namespace :webpacker do
5
5
  desc "Install Webpacker in this application"
6
- task install: [:check_node, :check_yarn] do
6
+ task install: [:check_node, :check_yarn] do |task|
7
+ prefix = task.name.split(/#|webpacker:install/).first
8
+
7
9
  if Rails::VERSION::MAJOR >= 5
8
- exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{install_template_path}"
10
+ exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION=#{install_template_path}"
9
11
  else
10
- exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION=#{install_template_path}"
12
+ exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION=#{install_template_path}"
11
13
  end
12
14
  end
13
15
  end
@@ -4,7 +4,8 @@ namespace :webpacker do
4
4
  desc "Verifies if Webpacker is installed"
5
5
  task verify_install: [:check_node, :check_yarn, :check_binstubs] do
6
6
  unless Webpacker.config.config_path.exist?
7
- $stderr.puts "Configuration config/webpacker.yml file not found. \n"\
7
+ path = Webpacker.config.config_path.relative_path_from(Pathname.new(pwd)).to_s
8
+ $stderr.puts "Configuration #{path} file not found. \n"\
8
9
  "Make sure webpacker:install is run successfully before " \
9
10
  "running dependent tasks"
10
11
  exit!
@@ -5,6 +5,14 @@ namespace :webpacker do
5
5
  node_env = ENV.fetch("NODE_ENV") do
6
6
  valid_node_envs.include?(Rails.env) ? Rails.env : "production"
7
7
  end
8
- system({ "NODE_ENV" => node_env }, "yarn install --no-progress --frozen-lockfile")
8
+ Dir.chdir(Rails.root) do
9
+ yarn_flags =
10
+ if `yarn --version`.start_with?("1")
11
+ "--no-progress --frozen-lockfile"
12
+ else
13
+ "--immutable"
14
+ end
15
+ system({ "NODE_ENV" => node_env }, "yarn install #{yarn_flags}")
16
+ end
9
17
  end
10
18
  end
@@ -23,7 +23,7 @@ class Webpacker::Commands
23
23
  .each_with_index
24
24
  .drop_while do |(mtime, _), index|
25
25
  max_age = [0, Time.now - Time.at(mtime)].max
26
- max_age < age && index < count
26
+ max_age < age || index < count
27
27
  end
28
28
  .each do |(_, files), index|
29
29
  files.each do |file|
@@ -64,7 +64,8 @@ class Webpacker::Commands
64
64
 
65
65
  def current_version
66
66
  packs = manifest.refresh.values.map do |value|
67
- next if value.is_a?(Hash)
67
+ value = value["src"] if value.is_a?(Hash)
68
+ next unless value.is_a?(String)
68
69
 
69
70
  File.join(config.root_path, "public", "#{value}*")
70
71
  end.compact
@@ -28,14 +28,14 @@ class Webpacker::Compiler
28
28
  record_compilation_digest
29
29
  end
30
30
  else
31
- logger.info "Everything's up-to-date. Nothing to do"
31
+ logger.debug "Everything's up-to-date. Nothing to do"
32
32
  true
33
33
  end
34
34
  end
35
35
 
36
36
  # Returns true if all the compiled packs are up to date with the underlying asset files.
37
37
  def fresh?
38
- watched_files_digest == last_compilation_digest
38
+ last_compilation_digest&.== watched_files_digest
39
39
  end
40
40
 
41
41
  # Returns true if the compiled packs are out of date with the underlying asset files.
@@ -53,10 +53,11 @@ class Webpacker::Compiler
53
53
 
54
54
  def watched_files_digest
55
55
  warn "Webpacker::Compiler.watched_paths has been deprecated. Set additional_paths in webpacker.yml instead." unless watched_paths.empty?
56
-
57
- files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) }
58
- file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
59
- Digest::SHA1.hexdigest(file_ids.join("/"))
56
+ Dir.chdir File.expand_path(config.root_path) do
57
+ files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) }
58
+ file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
59
+ Digest::SHA1.hexdigest(file_ids.join("/"))
60
+ end
60
61
  end
61
62
 
62
63
  def record_compilation_digest
@@ -64,12 +65,18 @@ class Webpacker::Compiler
64
65
  compilation_digest_path.write(watched_files_digest)
65
66
  end
66
67
 
68
+ def optionalRubyRunner
69
+ bin_webpack_path = config.root_path.join("bin/webpack")
70
+ first_line = File.readlines(bin_webpack_path).first.chomp
71
+ /ruby/.match?(first_line) ? RbConfig.ruby : ""
72
+ end
73
+
67
74
  def run_webpack
68
75
  logger.info "Compiling..."
69
76
 
70
77
  stdout, stderr, status = Open3.capture3(
71
78
  webpack_env,
72
- "#{RbConfig.ruby} ./bin/webpack",
79
+ "#{optionalRubyRunner} ./bin/webpack",
73
80
  chdir: File.expand_path(config.root_path)
74
81
  )
75
82
 
@@ -90,8 +97,8 @@ class Webpacker::Compiler
90
97
 
91
98
  def default_watched_paths
92
99
  [
93
- *config.additional_paths_globbed,
94
- config.source_path_globbed,
100
+ *config.additional_paths,
101
+ "#{config.source_path}/**/*",
95
102
  "yarn.lock", "package.json",
96
103
  "config/webpack/**/*"
97
104
  ].freeze