webpacker 5.2.1 → 6.0.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
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,5 @@
1
+ module.exports = {
2
+ test: [/\.html$/],
3
+ exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
4
+ type: 'asset/source'
5
+ }
@@ -1,14 +1,17 @@
1
+ /* eslint global-require: 0 */
2
+
1
3
  const getStyleRule = require('../utils/get_style_rule')
4
+ const { canProcess } = require('../utils/helpers')
2
5
  const { additional_paths: includePaths } = require('../config')
3
6
 
4
- module.exports = getStyleRule(/\.(scss|sass)(\.erb)?$/i, false, [
5
- {
6
- loader: 'sass-loader',
7
- options: {
8
- sourceMap: true,
9
- sassOptions: {
10
- includePaths
7
+ module.exports = canProcess('sass-loader', (resolvedPath) =>
8
+ getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
9
+ {
10
+ loader: resolvedPath,
11
+ options: {
12
+ sassOptions: { includePaths },
13
+ implementation: require('sass')
11
14
  }
12
15
  }
13
- }
14
- ])
16
+ ])
17
+ )
@@ -0,0 +1,26 @@
1
+ const path = require('path')
2
+ const { canProcess } = require('../utils/helpers')
3
+ const getStyleRule = require('../utils/get_style_rule')
4
+
5
+ const {
6
+ additional_paths: paths,
7
+ source_path: sourcePath
8
+ } = require('../config')
9
+
10
+ module.exports = canProcess('stylus-loader', (resolvedPath) =>
11
+ getStyleRule(/\.(styl)(\.erb)?$/i, [
12
+ {
13
+ loader: resolvedPath,
14
+ options: {
15
+ stylusOptions: {
16
+ include: [
17
+ path.resolve(__dirname, 'node_modules'),
18
+ sourcePath,
19
+ ...paths
20
+ ]
21
+ },
22
+ sourceMap: true
23
+ }
24
+ }
25
+ ])
26
+ )
@@ -1,45 +1,35 @@
1
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2
- const { resolve } = require('path')
3
- const config = require('../config')
1
+ /* eslint global-require: 0 */
4
2
 
5
- const styleLoader = {
6
- loader: 'style-loader'
7
- }
3
+ const { canProcess, moduleExists } = require('./helpers')
8
4
 
9
- const getStyleRule = (test, modules = false, preprocessors = []) => {
10
- const use = [
11
- {
12
- loader: 'css-loader',
13
- options: {
14
- sourceMap: true,
15
- importLoaders: 2,
16
- modules: modules ? {
17
- localIdentName: '[name]__[local]___[hash:base64:5]'
18
- } : false
19
- }
20
- },
21
- {
22
- loader: 'postcss-loader',
23
- options: {
24
- config: { path: resolve() },
25
- sourceMap: true
26
- }
27
- },
28
- ...preprocessors
29
- ]
5
+ const getStyleRule = (test, preprocessors = []) => {
6
+ if (moduleExists('css-loader')) {
7
+ const tryPostcss = () =>
8
+ canProcess('postcss-loader', (loaderPath) => ({
9
+ loader: loaderPath,
10
+ options: { sourceMap: true }
11
+ }))
30
12
 
31
- const options = modules ? { include: /\.module\.[a-z]+$/ } : { exclude: /\.module\.[a-z]+$/ }
13
+ const use = [
14
+ { loader: require('mini-css-extract-plugin').loader },
15
+ {
16
+ loader: require.resolve('css-loader'),
17
+ options: {
18
+ sourceMap: true,
19
+ importLoaders: 2
20
+ }
21
+ },
22
+ tryPostcss(),
23
+ ...preprocessors
24
+ ].filter(Boolean)
32
25
 
33
- if (config.extract_css) {
34
- use.unshift(MiniCssExtractPlugin.loader)
35
- } else {
36
- use.unshift(styleLoader)
26
+ return {
27
+ test,
28
+ use
29
+ }
37
30
  }
38
31
 
39
- // sideEffects - See https://github.com/webpack/webpack/issues/6571
40
- return {
41
- test, use, sideEffects: !modules, ...options
42
- }
32
+ return null
43
33
  }
44
34
 
45
35
  module.exports = getStyleRule
@@ -1,30 +1,5 @@
1
- const { stringify } = require('flatted')
2
-
3
- const isObject = (value) => typeof value === 'object'
4
- && value !== null
5
- && (value.length === undefined || value.length === null)
6
-
7
- const isNotObject = (value) => !isObject(value)
8
-
9
- const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
10
-
11
- const isEmpty = (value) => value === null || value === undefined
12
-
13
- const isString = (key) => key && typeof key === 'string'
14
-
15
- const isStrPath = (key) => {
16
- if (!isString(key)) throw new Error(`Key ${key} should be string`)
17
- return isString(key) && key.includes('.')
18
- }
19
-
20
1
  const isArray = (value) => Array.isArray(value)
21
-
22
- const isEqual = (target, source) => stringify(target) === stringify(source)
23
-
24
- const canMerge = (value) => isObject(value) || isArray(value)
25
-
26
- const prettyPrint = (obj) => JSON.stringify(obj, null, 2)
27
-
2
+ const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
28
3
  const chdirTestApp = () => {
29
4
  try {
30
5
  return process.chdir('test/test_app')
@@ -41,18 +16,34 @@ const resetEnv = () => {
41
16
 
42
17
  const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)
43
18
 
19
+ const moduleExists = (packageName) => {
20
+ try {
21
+ return require.resolve(packageName)
22
+ } catch (e) {
23
+ if (e.code !== 'MODULE_NOT_FOUND') {
24
+ throw e
25
+ }
26
+ return null
27
+ }
28
+ }
29
+
30
+ const canProcess = (rule, fn) => {
31
+ const modulePath = moduleExists(rule)
32
+
33
+ if (modulePath) {
34
+ return fn(modulePath)
35
+ }
36
+
37
+ return null
38
+ }
39
+
44
40
  module.exports = {
45
41
  chdirTestApp,
46
42
  chdirCwd,
47
- ensureTrailingSlash,
48
- isObject,
49
- isNotObject,
50
- isBoolean,
51
43
  isArray,
52
- isEqual,
53
- isEmpty,
54
- isStrPath,
55
- canMerge,
56
- prettyPrint,
44
+ isBoolean,
45
+ ensureTrailingSlash,
46
+ canProcess,
47
+ moduleExists,
57
48
  resetEnv
58
49
  }
@@ -23,18 +23,6 @@ class CompilerTest < Minitest::Test
23
23
  Webpacker.compiler.env = {}
24
24
  end
25
25
 
26
- def test_default_watched_paths
27
- assert_equal Webpacker.compiler.send(:default_watched_paths), [
28
- "app/assets/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
29
- "/etc/yarn/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
30
- "app/elm/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
31
- "app/javascript/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
32
- "yarn.lock",
33
- "package.json",
34
- "config/webpack/**/*"
35
- ]
36
- end
37
-
38
26
  def test_freshness
39
27
  assert Webpacker.compiler.stale?
40
28
  assert !Webpacker.compiler.fresh?
@@ -10,17 +10,12 @@ class ConfigurationTest < Webpacker::Test
10
10
  end
11
11
 
12
12
  def test_source_path
13
- source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
13
+ source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/packs").to_s
14
14
  assert_equal source_path, @config.source_path.to_s
15
15
  end
16
16
 
17
- def test_source_path_globbed
18
- assert_equal @config.source_path_globbed,
19
- "app/javascript/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}"
20
- end
21
-
22
17
  def test_source_entry_path
23
- source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "packs").to_s
18
+ source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/packs", "entrypoints").to_s
24
19
  assert_equal @config.source_entry_path.to_s, source_entry_path
25
20
  end
26
21
 
@@ -54,21 +49,7 @@ class ConfigurationTest < Webpacker::Test
54
49
  end
55
50
 
56
51
  def test_additional_paths
57
- assert_equal @config.additional_paths, ["app/assets", "/etc/yarn", "app/elm"]
58
- end
59
-
60
- def test_additional_paths_globbed
61
- assert_equal @config.additional_paths_globbed, [
62
- "app/assets/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
63
- "/etc/yarn/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
64
- "app/elm/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}"
65
- ]
66
- end
67
-
68
- def test_extensions
69
- config_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/config/webpacker.yml").to_s
70
- webpacker_yml = YAML.load_file(config_path)
71
- assert_equal @config.extensions, webpacker_yml["default"]["extensions"]
52
+ assert_equal @config.additional_paths, ["app/assets", "/etc/yarn", "some.config.js", "app/elm"]
72
53
  end
73
54
 
74
55
  def test_cache_manifest?
@@ -94,16 +75,4 @@ class ConfigurationTest < Webpacker::Test
94
75
  assert Webpacker.config.compile?
95
76
  end
96
77
  end
97
-
98
- def test_extract_css?
99
- assert @config.extract_css?
100
-
101
- with_rails_env("development") do
102
- refute Webpacker.config.extract_css?
103
- end
104
-
105
- with_rails_env("test") do
106
- refute Webpacker.config.extract_css?
107
- end
108
- end
109
78
  end
@@ -13,34 +13,61 @@ class DevServerRunnerTest < Webpacker::Test
13
13
  end
14
14
 
15
15
  def test_run_cmd_via_node_modules
16
- cmd = ["#{test_app_path}/node_modules/.bin/webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]
16
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
17
17
 
18
18
  verify_command(cmd, use_node_modules: true)
19
19
  end
20
20
 
21
21
  def test_run_cmd_via_yarn
22
- cmd = ["yarn", "webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]
22
+ cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
23
23
 
24
24
  verify_command(cmd, use_node_modules: false)
25
25
  end
26
26
 
27
+ def test_run_cmd_argv
28
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--quiet"]
29
+
30
+ verify_command(cmd, argv: ["--quiet"])
31
+ end
32
+
33
+ def test_run_cmd_argv_with_https
34
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--https"]
35
+
36
+ dev_server = Webpacker::DevServer.new({})
37
+ def dev_server.host; "localhost"; end
38
+ def dev_server.port; "3035"; end
39
+ def dev_server.pretty?; false; end
40
+ def dev_server.https?; true; end
41
+ Webpacker::DevServer.stub(:new, dev_server) do
42
+ verify_command(cmd, argv: ["--https"])
43
+ end
44
+ end
45
+
46
+ def test_environment_variables
47
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
48
+ env = Webpacker::Compiler.env.dup
49
+ env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker.yml"
50
+ env["WEBPACK_DEV_SERVER"] = "true"
51
+ verify_command(cmd, env: env)
52
+ end
53
+
27
54
  private
28
55
  def test_app_path
29
56
  File.expand_path("test_app", __dir__)
30
57
  end
31
58
 
32
- def verify_command(cmd, use_node_modules: true)
59
+ def verify_command(cmd, use_node_modules: true, argv: [], env: Webpacker::Compiler.env)
33
60
  cwd = Dir.pwd
34
61
  Dir.chdir(test_app_path)
35
62
 
36
63
  klass = Webpacker::DevServerRunner
37
- instance = klass.new([])
64
+ instance = klass.new(argv)
38
65
  mock = Minitest::Mock.new
39
- mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd])
66
+ mock.expect(:call, nil, [env, *cmd])
40
67
 
41
68
  klass.stub(:new, instance) do
42
69
  instance.stub(:node_modules_bin_exist?, use_node_modules) do
43
- Kernel.stub(:exec, mock) { klass.run([]) }
70
+ Kernel.stub(:exec, mock) { klass.run(argv) }
44
71
  end
45
72
  end
46
73
 
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+
3
+ class EngineRakeTasksTest < Minitest::Test
4
+ def setup
5
+ remove_webpack_binstubs
6
+ end
7
+
8
+ def teardown
9
+ remove_webpack_binstubs
10
+ end
11
+
12
+ def test_task_mounted
13
+ output = Dir.chdir(mounted_app_path) { `rake -T` }
14
+ assert_includes output, "app:webpacker"
15
+ end
16
+
17
+ def test_binstubs
18
+ Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` }
19
+ webpack_binstub_paths.each { |path| assert File.exist?(path) }
20
+ end
21
+
22
+ private
23
+ def mounted_app_path
24
+ File.expand_path("mounted_app", __dir__)
25
+ end
26
+
27
+ def webpack_binstub_paths
28
+ [
29
+ "#{mounted_app_path}/test/dummy/bin/webpack",
30
+ "#{mounted_app_path}/test/dummy/bin/webpack-dev-server",
31
+ ]
32
+ end
33
+
34
+ def remove_webpack_binstubs
35
+ webpack_binstub_paths.each do |path|
36
+ File.delete(path) if File.exist?(path)
37
+ end
38
+ end
39
+ end
@@ -17,21 +17,27 @@ class HelperTest < ActionView::TestCase
17
17
  def test_asset_pack_path
18
18
  assert_equal "/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_path("bootstrap.js")
19
19
  assert_equal "/packs/bootstrap-c38deda30895059837cf.css", asset_pack_path("bootstrap.css")
20
-
21
- Webpacker.config.stub :extract_css?, false do
22
- assert_nil asset_pack_path("bootstrap.css")
23
- assert_equal "/packs/application-k344a6d59eef8632c9d1.png", asset_pack_path("application.png")
24
- end
25
20
  end
26
21
 
27
22
  def test_asset_pack_url
28
23
  assert_equal "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_url("bootstrap.js")
29
24
  assert_equal "https://example.com/packs/bootstrap-c38deda30895059837cf.css", asset_pack_url("bootstrap.css")
25
+ end
30
26
 
31
- Webpacker.config.stub :extract_css?, false do
32
- assert_nil asset_pack_path("bootstrap.css")
33
- assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", asset_pack_url("application.png")
34
- end
27
+ def test_image_pack_path
28
+ assert_equal "/packs/application-k344a6d59eef8632c9d1.png", image_pack_path("application.png")
29
+ assert_equal "/packs/media/images/image-c38deda30895059837cf.jpg", image_pack_path("image.jpg")
30
+ assert_equal "/packs/media/images/image-c38deda30895059837cf.jpg", image_pack_path("media/images/image.jpg")
31
+ assert_equal "/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_path("nested/image.jpg")
32
+ assert_equal "/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_path("media/images/nested/image.jpg")
33
+ end
34
+
35
+ def test_image_pack_url
36
+ assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", image_pack_url("application.png")
37
+ assert_equal "https://example.com/packs/media/images/image-c38deda30895059837cf.jpg", image_pack_url("image.jpg")
38
+ assert_equal "https://example.com/packs/media/images/image-c38deda30895059837cf.jpg", image_pack_url("media/images/image.jpg")
39
+ assert_equal "https://example.com/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_url("nested/image.jpg")
40
+ assert_equal "https://example.com/packs/media/images/nested/image-c38deda30895059837cf.jpg", image_pack_url("media/images/nested/image.jpg")
35
41
  end
36
42
 
37
43
  def test_image_pack_tag
@@ -0,0 +1,4 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
@@ -0,0 +1,3 @@
1
+ require_relative "config/application"
2
+
3
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path("../config/application", __dir__)
3
+ require "rails/commands"