jetpacker 0.4.2 → 0.6.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 (90) 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 +58 -0
  7. data/.gitignore +1 -0
  8. data/.node-version +1 -1
  9. data/.rubocop.yml +113 -13
  10. data/.travis.yml +8 -21
  11. data/CHANGELOG.jetpacker.md +5 -0
  12. data/CHANGELOG.md +68 -2
  13. data/Gemfile +1 -0
  14. data/README.md +23 -649
  15. data/docs/css.md +58 -3
  16. data/docs/deployment.md +2 -2
  17. data/docs/docker.md +17 -17
  18. data/docs/engines.md +13 -0
  19. data/docs/env.md +0 -2
  20. data/docs/integrations.md +220 -0
  21. data/docs/target.md +22 -0
  22. data/docs/testing.md +2 -3
  23. data/docs/troubleshooting.md +3 -1
  24. data/docs/typescript.md +92 -28
  25. data/docs/webpack-dev-server.md +1 -1
  26. data/gemfiles/Gemfile-rails-edge +1 -1
  27. data/jetpacker.gemspec +4 -3
  28. data/lib/install/config/babel.config.js +13 -3
  29. data/lib/install/config/webpacker.yml +1 -4
  30. data/lib/install/examples/react/babel.config.js +12 -0
  31. data/lib/install/examples/react/tsconfig.json +2 -1
  32. data/lib/install/examples/typescript/tsconfig.json +2 -1
  33. data/lib/install/loaders/svelte.js +2 -2
  34. data/lib/install/template.rb +11 -3
  35. data/lib/install/typescript.rb +6 -2
  36. data/lib/jetpacker/version.rb +1 -1
  37. data/lib/tasks/webpacker/check_node.rake +15 -8
  38. data/lib/tasks/webpacker/check_yarn.rake +16 -10
  39. data/lib/tasks/webpacker/clean.rake +12 -8
  40. data/lib/tasks/webpacker/clobber.rake +8 -4
  41. data/lib/tasks/webpacker/yarn_install.rake +11 -16
  42. data/lib/webpacker/commands.rb +33 -9
  43. data/lib/webpacker/compiler.rb +9 -5
  44. data/lib/webpacker/configuration.rb +28 -13
  45. data/lib/webpacker/dev_server_proxy.rb +3 -1
  46. data/lib/webpacker/dev_server_runner.rb +2 -2
  47. data/lib/webpacker/env.rb +5 -1
  48. data/lib/webpacker/helper.rb +37 -18
  49. data/lib/webpacker/manifest.rb +4 -4
  50. data/lib/webpacker/railtie.rb +0 -43
  51. data/lib/webpacker/runner.rb +1 -0
  52. data/lib/webpacker/turbine.rb +0 -41
  53. data/lib/webpacker/version.rb +1 -1
  54. data/lib/webpacker/webpack_runner.rb +2 -2
  55. data/package/__tests__/config.js +12 -1
  56. data/package/__tests__/dev_server.js +2 -0
  57. data/package/__tests__/development.js +14 -1
  58. data/package/config.js +4 -1
  59. data/package/configPath.js +3 -0
  60. data/package/dev_server.js +1 -1
  61. data/package/env.js +1 -2
  62. data/package/environments/__tests__/base.js +29 -2
  63. data/package/environments/base.js +17 -7
  64. data/package/environments/development.js +39 -37
  65. data/package/environments/production.js +1 -3
  66. data/package/rules/babel.js +12 -5
  67. data/package/rules/file.js +3 -2
  68. data/package/rules/node_modules.js +1 -3
  69. data/package/rules/sass.js +10 -1
  70. data/package/utils/helpers.js +1 -1
  71. data/package.json +41 -41
  72. data/test/compiler_test.rb +8 -3
  73. data/test/configuration_test.rb +8 -7
  74. data/test/dev_server_runner_test.rb +1 -1
  75. data/test/helper_test.rb +24 -9
  76. data/test/manifest_test.rb +37 -6
  77. data/test/rake_tasks_test.rb +11 -0
  78. data/test/test_app/app/javascript/packs/multi_entry.css +4 -0
  79. data/test/test_app/app/javascript/packs/multi_entry.js +4 -0
  80. data/test/test_app/config/application.rb +0 -1
  81. data/test/test_app/config/webpacker.yml +7 -1
  82. data/test/test_app/public/packs/manifest.json +1 -0
  83. data/test/webpack_runner_test.rb +1 -1
  84. data/yarn.lock +3895 -3945
  85. metadata +35 -15
  86. data/Gemfile.lock +0 -171
  87. data/gemfiles/Gemfile-rails.4.2.x +0 -9
  88. data/gemfiles/Gemfile-rails.5.0.x +0 -9
  89. data/gemfiles/Gemfile-rails.5.1.x +0 -9
  90. data/lib/install/loaders/typescript.js +0 -11
@@ -53,12 +53,22 @@ module.exports = function(api) {
53
53
  useBuiltIns: true
54
54
  }
55
55
  ],
56
+ [
57
+ '@babel/plugin-proposal-private-methods',
58
+ {
59
+ loose: true
60
+ }
61
+ ],
62
+ [
63
+ '@babel/plugin-proposal-private-property-in-object',
64
+ {
65
+ loose: true
66
+ }
67
+ ],
56
68
  [
57
69
  '@babel/plugin-transform-runtime',
58
70
  {
59
- helpers: false,
60
- regenerator: true,
61
- corejs: false
71
+ helpers: false
62
72
  }
63
73
  ],
64
74
  [
@@ -6,7 +6,6 @@ default: &default
6
6
  public_root_path: public
7
7
  public_output_path: packs
8
8
  cache_path: tmp/cache/webpacker
9
- check_yarn_integrity: false
10
9
  webpack_compile_output: true
11
10
 
12
11
  # Additional paths webpack should lookup modules
@@ -14,6 +13,7 @@ default: &default
14
13
  # Note: Different from original webpacker default which is resolved_paths: []
15
14
  # Unsure if app/assets is better default. Seems convenient.
16
15
  resolved_paths: ['app/assets']
16
+ additional_paths: []
17
17
 
18
18
  # Reload manifest.json on all requests so we reload latest compiled packs
19
19
  cache_manifest: false
@@ -60,9 +60,6 @@ development:
60
60
  <<: *default
61
61
  compile: true
62
62
 
63
- # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
64
- check_yarn_integrity: true
65
-
66
63
  # Reference: https://webpack.js.org/configuration/dev-server/
67
64
  dev_server:
68
65
  https: false
@@ -62,6 +62,18 @@ module.exports = function(api) {
62
62
  useBuiltIns: true
63
63
  }
64
64
  ],
65
+ [
66
+ '@babel/plugin-proposal-private-methods',
67
+ {
68
+ loose: true
69
+ }
70
+ ],
71
+ [
72
+ '@babel/plugin-proposal-private-property-in-object',
73
+ {
74
+ loose: true
75
+ }
76
+ ],
65
77
  [
66
78
  '@babel/plugin-transform-runtime',
67
79
  {
@@ -8,7 +8,8 @@
8
8
  "moduleResolution": "node",
9
9
  "sourceMap": true,
10
10
  "target": "es5",
11
- "jsx": "react"
11
+ "jsx": "react",
12
+ "noEmit": true
12
13
  },
13
14
  "exclude": [
14
15
  "**/*.spec.ts",
@@ -11,7 +11,8 @@
11
11
  "*": ["node_modules/*", "app/javascript/*"]
12
12
  },
13
13
  "sourceMap": true,
14
- "target": "es5"
14
+ "target": "es5",
15
+ "noEmit": true
15
16
  },
16
17
  "exclude": [
17
18
  "**/*.spec.ts",
@@ -1,9 +1,9 @@
1
1
  module.exports = {
2
- test: /\.svelte$/,
2
+ test: /\.svelte(\.erb)?$/,
3
3
  use: [{
4
4
  loader: 'svelte-loader',
5
5
  options: {
6
- hotReload: true
6
+ hotReload: false
7
7
  }
8
8
  }],
9
9
  }
@@ -1,7 +1,7 @@
1
1
  # Install Webpacker
2
2
  copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
3
3
 
4
- puts "Copying webpack core config"
4
+ say "Copying webpack core config"
5
5
  directory "#{__dir__}/config/webpack", "config/webpack"
6
6
 
7
7
  say "Copying postcss.config.js to app root directory"
@@ -34,7 +34,7 @@ if File.exists?(".gitignore")
34
34
  end
35
35
  end
36
36
 
37
- if Webpacker::VERSION =~ /^[0-9]+\.[0-9]+\.[0-9]+$/
37
+ if Webpacker::VERSION.match?(/^[0-9]+\.[0-9]+\.[0-9]+$/)
38
38
  say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
39
39
  run "yarn add @rails/webpacker@#{Webpacker::VERSION}"
40
40
  else
@@ -42,8 +42,16 @@ else
42
42
  run "yarn add @rails/webpacker@next"
43
43
  end
44
44
 
45
+ package_json = File.read("#{__dir__}/../../package.json")
46
+ webpack_version = package_json.match(/"webpack": "(.*)"/)[1]
47
+ webpack_cli_version = package_json.match(/"webpack-cli": "(.*)"/)[1]
48
+
49
+ # needed for experimental Yarn 2 support and should not harm Yarn 1
50
+ say "Installing webpack and webpack-cli as direct dependencies"
51
+ run "yarn add webpack@#{webpack_version} webpack-cli@#{webpack_cli_version}"
52
+
45
53
  say "Installing dev server for live reloading"
46
- run "yarn add --dev webpack-dev-server"
54
+ run "yarn add --dev webpack-dev-server@^3"
47
55
 
48
56
  if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
49
57
  say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
@@ -9,7 +9,7 @@ if File.exist?(package_json)
9
9
  package = JSON.parse(File.read(package_json))
10
10
  package["dependencies"] ||= {}
11
11
 
12
- if package["dependencies"].keys.include?("react")
12
+ if package["dependencies"].key?("react")
13
13
  additional_packages = "@types/react @types/react-dom"
14
14
  example_source = "react"
15
15
  end
@@ -26,6 +26,10 @@ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
26
26
  insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
27
27
  "environment.loaders.prepend('typescript', typescript)\n",
28
28
  before: "module.exports"
29
+ say "Adding TypeScript preset to babel.config.js"
30
+ insert_into_file Jets.root.join("babel.config.js").to_s,
31
+ ",\n ['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }]",
32
+ before: /\s*\].filter\(Boolean\),\n\s*plugins: \[/
29
33
 
30
34
  say "Copying tsconfig.json to the Rails root directory for typescript"
31
35
  copy_file "#{__dir__}/examples/#{example_source}/tsconfig.json", "tsconfig.json"
@@ -41,6 +45,6 @@ copy_file "#{__dir__}/examples/typescript/hello_typescript.ts",
41
45
  "#{Webpacker.config.source_entry_path}/hello_typescript.ts"
42
46
 
43
47
  say "Installing all typescript dependencies"
44
- run "yarn add typescript ts-loader #{additional_packages}"
48
+ run "yarn add typescript @babel/preset-typescript #{additional_packages}"
45
49
 
46
50
  say "Webpacker now supports typescript 🎉", :green
@@ -1,4 +1,4 @@
1
1
  # Separate version from Webpacker version for the jetpacker gem
2
2
  module Jetpacker
3
- VERSION = "0.4.2"
3
+ VERSION = "0.6.0"
4
4
  end
@@ -1,24 +1,31 @@
1
+ require "semantic_range"
1
2
  namespace :webpacker do
2
3
  desc "Verifies if Node.js is installed"
3
4
  task :check_node do
4
5
  begin
5
- node_version = `node -v || nodejs -v`
6
+ node_version = `node -v || nodejs -v`.strip
6
7
  raise Errno::ENOENT if node_version.blank?
7
8
 
8
9
  pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
9
- node_requirement = JSON.parse(pkg_path.read)["engines"]["node"]
10
+ node_range = JSON.parse(pkg_path.read)["engines"]["node"]
11
+ is_valid = SemanticRange.satisfies?(node_version, node_range) rescue false
12
+ semver_major = node_version[/\d+/] rescue nil
13
+ is_unstable = semver_major.to_i.odd? rescue false
10
14
 
11
- requirement = Gem::Requirement.new(node_requirement)
12
- version = Gem::Version.new(node_version.strip.tr("v", ""))
15
+ if is_unstable
16
+ $stderr.puts "Warning: you are using an unstable release of Node.js (#{node_version}). If you encounter issues with Node.js, consider switching to an Active LTS release. More info: https://docs.npmjs.com/try-the-latest-stable-version-of-node"
17
+ end
13
18
 
14
- unless requirement.satisfied_by?(version)
15
- $stderr.puts "Webpacker requires Node.js #{requirement} and you are using #{version}"
19
+ unless is_valid
20
+ $stderr.puts "Webpacker requires Node.js \"#{node_range}\" and you are using #{node_version}"
16
21
  $stderr.puts "Please upgrade Node.js https://nodejs.org/en/download/"
17
- $stderr.puts "Exiting!" && exit!
22
+ $stderr.puts "Exiting!"
23
+ exit!
18
24
  end
19
25
  rescue Errno::ENOENT
20
26
  $stderr.puts "Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/"
21
- $stderr.puts "Exiting!" && exit!
27
+ $stderr.puts "Exiting!"
28
+ exit!
22
29
  end
23
30
  end
24
31
  end
@@ -1,24 +1,30 @@
1
+ require "semantic_range"
1
2
  namespace :webpacker do
2
3
  desc "Verifies if Yarn is installed"
3
4
  task :check_yarn do
4
5
  begin
5
- yarn_version = `yarn --version`
6
+ yarn_version = `yarn --version`.strip
6
7
  raise Errno::ENOENT if yarn_version.blank?
7
8
 
8
9
  pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
9
- yarn_requirement = JSON.parse(pkg_path.read)["engines"]["yarn"]
10
+ yarn_range = JSON.parse(pkg_path.read)["engines"]["yarn"]
11
+ is_valid = SemanticRange.satisfies?(yarn_version, yarn_range) rescue false
12
+ is_unsupported = SemanticRange.satisfies?(yarn_version, ">=4.0.0") rescue false
10
13
 
11
- requirement = Gem::Requirement.new(yarn_requirement)
12
- version = Gem::Version.new(yarn_version)
13
-
14
- unless requirement.satisfied_by?(version)
15
- $stderr.puts "Webpacker requires Yarn #{requirement} and you are using #{version}"
16
- $stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/"
17
- $stderr.puts "Exiting!" && exit!
14
+ unless is_valid
15
+ $stderr.puts "Webpacker requires Yarn \"#{yarn_range}\" and you are using #{yarn_version}"
16
+ if is_unsupported
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
+ else
19
+ $stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/"
20
+ end
21
+ $stderr.puts "Exiting!"
22
+ exit!
18
23
  end
19
24
  rescue Errno::ENOENT
20
25
  $stderr.puts "Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/"
21
- $stderr.puts "Exiting!" && exit!
26
+ $stderr.puts "Exiting!"
27
+ exit!
22
28
  end
23
29
  end
24
30
  end
@@ -4,18 +4,22 @@ require "webpacker/configuration"
4
4
 
5
5
  namespace :webpacker do
6
6
  desc "Remove old compiled webpacks"
7
- task :clean, [:keep] => ["webpacker:verify_install", :environment] do |_, args|
7
+ task :clean, [:keep, :age] => ["webpacker:verify_install", :environment] do |_, args|
8
8
  Webpacker.ensure_log_goes_to_stdout do
9
- Webpacker.clean(Integer(args.keep || 2))
9
+ Webpacker.clean(Integer(args.keep || 2), Integer(args.age || 3600))
10
10
  end
11
11
  end
12
12
  end
13
13
 
14
- # Run clean if the assets:clean is run
15
- if Rake::Task.task_defined?("assets:clean")
16
- Rake::Task["assets:clean"].enhance do
17
- Rake::Task["webpacker:clean"].invoke
14
+ skip_webpacker_clean = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
15
+
16
+ unless skip_webpacker_clean
17
+ # Run clean if the assets:clean is run
18
+ if Rake::Task.task_defined?("assets:clean")
19
+ Rake::Task["assets:clean"].enhance do
20
+ Rake::Task["webpacker:clean"].invoke
21
+ end
22
+ else
23
+ Rake::Task.define_task("assets:clean" => "webpacker:clean")
18
24
  end
19
- else
20
- Rake::Task.define_task("assets:clean" => "webpacker:clean")
21
25
  end
@@ -8,9 +8,13 @@ namespace :webpacker do
8
8
  end
9
9
  end
10
10
 
11
- # Run clobber if the assets:clobber is run
12
- if Rake::Task.task_defined?("assets:clobber")
13
- Rake::Task["assets:clobber"].enhance do
14
- Rake::Task["webpacker:clobber"].invoke
11
+ skip_webpacker_clobber = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
12
+
13
+ unless skip_webpacker_clobber
14
+ # Run clobber if the assets:clobber is run
15
+ if Rake::Task.task_defined?("assets:clobber")
16
+ Rake::Task["assets:clobber"].enhance do
17
+ Rake::Task["webpacker:clobber"].invoke
18
+ end
15
19
  end
16
20
  end
@@ -1,21 +1,16 @@
1
1
  namespace :webpacker do
2
2
  desc "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
3
3
  task :yarn_install do
4
- system "yarn install --no-progress"
5
-
6
- exit(1) unless $?.success?
4
+ valid_node_envs = %w[test development production]
5
+ node_env = ENV.fetch("NODE_ENV") do
6
+ valid_node_envs.include?(Jets.env) ? Jets.env : "production"
7
+ end
8
+ yarn_flags =
9
+ if `yarn --version`.start_with?("1")
10
+ "--no-progress --frozen-lockfile"
11
+ else
12
+ "--immutable"
13
+ end
14
+ system({ "NODE_ENV" => node_env }, "yarn install #{yarn_flags}")
7
15
  end
8
16
  end
9
-
10
- def enhance_yarn_install
11
- Rake::Task["yarn:install"].enhance do
12
- exit(1) unless $?.success?
13
- end
14
- end
15
-
16
- if Rake::Task.task_defined?("yarn:install")
17
- enhance_yarn_install
18
- else
19
- # this is mainly for pre-5.x era
20
- Rake::Task.define_task("yarn:install" => "webpacker:yarn_install")
21
- end
@@ -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
@@ -89,8 +93,12 @@ class Webpacker::Configuration
89
93
  end
90
94
 
91
95
  def load
92
- YAML.load(config_path.read)[env].deep_symbolize_keys
93
-
96
+ config = begin
97
+ YAML.load_file(config_path.to_s, aliases: true)
98
+ rescue ArgumentError
99
+ YAML.load_file(config_path.to_s)
100
+ end
101
+ config[env].deep_symbolize_keys
94
102
  rescue Errno::ENOENT => e
95
103
  raise "Webpacker configuration file not found #{config_path}. " \
96
104
  "Please run rails webpacker:install " \
@@ -103,8 +111,15 @@ class Webpacker::Configuration
103
111
  end
104
112
 
105
113
  def defaults
106
- @defaults ||= \
107
- HashWithIndifferentAccess.new(YAML.load_file(File.expand_path("../../install/config/webpacker.yml", __FILE__))[env])
114
+ @defaults ||= begin
115
+ path = File.expand_path("../../install/config/webpacker.yml", __FILE__)
116
+ config = begin
117
+ YAML.load_file(path, aliases: true)
118
+ rescue ArgumentError
119
+ YAML.load_file(path)
120
+ end
121
+ HashWithIndifferentAccess.new(config[env])
122
+ end
108
123
  end
109
124
 
110
125
  def globbed_path_with_extensions(path)
@@ -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]
data/lib/webpacker/env.rb CHANGED
@@ -27,7 +27,11 @@ class Webpacker::Env
27
27
 
28
28
  def available_environments
29
29
  if config_path.exist?
30
- YAML.load(config_path.read).keys
30
+ begin
31
+ YAML.load_file(config_path.to_s, aliases: true)
32
+ rescue ArgumentError
33
+ YAML.load_file(config_path.to_s)
34
+ end
31
35
  else
32
36
  [].freeze
33
37
  end