webpacker 4.3.0 → 6.0.0.rc.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +8 -8
  3. data/.github/workflows/jest.yml +30 -0
  4. data/.github/workflows/js-lint.yml +31 -0
  5. data/.github/workflows/rubocop.yml +39 -0
  6. data/.github/workflows/ruby.yml +48 -0
  7. data/.gitignore +2 -0
  8. data/.node-version +1 -1
  9. data/.rubocop.yml +117 -16
  10. data/CHANGELOG.md +91 -5
  11. data/CONTRIBUTING.md +20 -1
  12. data/Gemfile +1 -0
  13. data/Gemfile.lock +121 -109
  14. data/README.md +365 -387
  15. data/config/README.md +3 -0
  16. data/config/webpacker.yml +1 -0
  17. data/docs/deployment.md +9 -11
  18. data/docs/developing_webpacker.md +29 -0
  19. data/docs/troubleshooting.md +64 -26
  20. data/docs/v6_upgrade.md +113 -0
  21. data/gemfiles/Gemfile-rails-edge +1 -1
  22. data/gemfiles/{Gemfile-rails.4.2.x → Gemfile-rails.6.1.x} +4 -1
  23. data/lib/install/{javascript/packs/application.js → application.js} +2 -5
  24. data/lib/install/bin/webpack +4 -7
  25. data/lib/install/bin/yarn +18 -0
  26. data/lib/install/config/webpack/base.js +3 -0
  27. data/lib/install/config/webpack/development.js +2 -2
  28. data/lib/install/config/webpack/production.js +2 -2
  29. data/lib/install/config/webpack/test.js +2 -2
  30. data/lib/install/config/webpacker.yml +22 -54
  31. data/lib/install/package.json +15 -0
  32. data/lib/install/template.rb +66 -23
  33. data/lib/tasks/webpacker/binstubs.rake +6 -4
  34. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  35. data/lib/tasks/webpacker/check_node.rake +18 -8
  36. data/lib/tasks/webpacker/check_yarn.rake +19 -10
  37. data/lib/tasks/webpacker/clean.rake +12 -6
  38. data/lib/tasks/webpacker/clobber.rake +9 -5
  39. data/lib/tasks/webpacker/compile.rake +4 -2
  40. data/lib/tasks/webpacker/info.rake +12 -10
  41. data/lib/tasks/webpacker/install.rake +6 -4
  42. data/lib/tasks/webpacker/verify_config.rake +14 -0
  43. data/lib/tasks/webpacker/verify_install.rake +1 -10
  44. data/lib/tasks/webpacker/yarn_install.rake +13 -16
  45. data/lib/tasks/webpacker.rake +2 -11
  46. data/lib/tasks/yarn.rake +38 -0
  47. data/lib/webpacker/commands.rb +40 -11
  48. data/lib/webpacker/compiler.rb +23 -12
  49. data/lib/webpacker/configuration.rb +24 -33
  50. data/lib/webpacker/dev_server.rb +6 -0
  51. data/lib/webpacker/dev_server_proxy.rb +3 -1
  52. data/lib/webpacker/dev_server_runner.rb +34 -10
  53. data/lib/webpacker/env.rb +5 -1
  54. data/lib/webpacker/helper.rb +72 -87
  55. data/lib/webpacker/instance.rb +4 -0
  56. data/lib/webpacker/manifest.rb +6 -7
  57. data/lib/webpacker/railtie.rb +8 -45
  58. data/lib/webpacker/runner.rb +1 -0
  59. data/lib/webpacker/version.rb +1 -1
  60. data/lib/webpacker/webpack_runner.rb +30 -4
  61. data/lib/webpacker.rb +1 -1
  62. data/package/__tests__/config.js +6 -27
  63. data/package/__tests__/dev_server.js +2 -0
  64. data/package/__tests__/development.js +18 -13
  65. data/package/__tests__/env.js +16 -4
  66. data/package/__tests__/index.js +9 -0
  67. data/package/__tests__/production.js +6 -6
  68. data/package/__tests__/staging.js +7 -6
  69. data/package/__tests__/test.js +4 -5
  70. data/package/babel/preset.js +54 -0
  71. data/package/config.js +7 -12
  72. data/package/configPath.js +3 -0
  73. data/package/dev_server.js +1 -1
  74. data/package/env.js +14 -6
  75. data/package/environments/__tests__/base.js +26 -31
  76. data/package/environments/base.js +78 -128
  77. data/package/environments/development.js +47 -43
  78. data/package/environments/production.js +66 -66
  79. data/package/environments/test.js +2 -2
  80. data/package/index.js +15 -8
  81. data/package/inliningCss.js +7 -0
  82. data/package/rules/babel.js +20 -11
  83. data/package/rules/coffee.js +6 -0
  84. data/package/rules/erb.js +15 -0
  85. data/package/rules/file.js +21 -18
  86. data/package/rules/index.js +16 -18
  87. data/package/rules/less.js +22 -0
  88. data/package/rules/raw.js +5 -0
  89. data/package/rules/sass.js +14 -6
  90. data/package/rules/stylus.js +26 -0
  91. data/package/utils/get_style_rule.js +28 -36
  92. data/package/utils/helpers.js +28 -35
  93. data/package.json +26 -46
  94. data/test/command_test.rb +76 -0
  95. data/test/compiler_test.rb +4 -11
  96. data/test/configuration_test.rb +5 -35
  97. data/test/dev_server_runner_test.rb +36 -6
  98. data/test/engine_rake_tasks_test.rb +39 -0
  99. data/test/helper_test.rb +77 -60
  100. data/test/manifest_test.rb +53 -6
  101. data/test/mounted_app/Rakefile +4 -0
  102. data/test/mounted_app/test/dummy/Rakefile +3 -0
  103. data/test/mounted_app/test/dummy/bin/rails +3 -0
  104. data/test/mounted_app/test/dummy/bin/rake +3 -0
  105. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  106. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  107. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  108. data/test/mounted_app/test/dummy/config.ru +5 -0
  109. data/test/mounted_app/test/dummy/package.json +7 -0
  110. data/test/rake_tasks_test.rb +12 -10
  111. data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
  112. data/test/test_app/app/packs/entrypoints/multi_entry.css +4 -0
  113. data/test/test_app/app/packs/entrypoints/multi_entry.js +4 -0
  114. data/test/test_app/config/application.rb +0 -1
  115. data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
  116. data/test/test_app/config/webpacker.yml +7 -27
  117. data/test/test_app/config/webpacker_other_location.yml +79 -0
  118. data/test/test_app/config/webpacker_public_root.yml +0 -1
  119. data/test/test_app/public/packs/manifest.json +36 -17
  120. data/test/test_app/some.config.js +0 -0
  121. data/test/webpack_runner_test.rb +10 -4
  122. data/test/webpacker_test.rb +21 -0
  123. data/webpacker.gemspec +5 -4
  124. data/yarn.lock +3387 -6898
  125. metadata +90 -99
  126. data/.travis.yml +0 -57
  127. data/docs/assets.md +0 -119
  128. data/docs/cloud9.md +0 -310
  129. data/docs/css.md +0 -254
  130. data/docs/docker.md +0 -68
  131. data/docs/engines.md +0 -200
  132. data/docs/env.md +0 -65
  133. data/docs/es6.md +0 -72
  134. data/docs/folder-structure.md +0 -66
  135. data/docs/misc.md +0 -23
  136. data/docs/props.md +0 -223
  137. data/docs/testing.md +0 -137
  138. data/docs/typescript.md +0 -126
  139. data/docs/v4-upgrade.md +0 -142
  140. data/docs/webpack-dev-server.md +0 -92
  141. data/docs/webpack.md +0 -364
  142. data/docs/yarn.md +0 -23
  143. data/gemfiles/Gemfile-rails.5.0.x +0 -9
  144. data/gemfiles/Gemfile-rails.5.1.x +0 -9
  145. data/lib/install/angular.rb +0 -23
  146. data/lib/install/coffee.rb +0 -25
  147. data/lib/install/config/.browserslistrc +0 -1
  148. data/lib/install/config/babel.config.js +0 -72
  149. data/lib/install/config/postcss.config.js +0 -12
  150. data/lib/install/config/webpack/environment.js +0 -3
  151. data/lib/install/elm.rb +0 -39
  152. data/lib/install/erb.rb +0 -25
  153. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  154. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  155. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  156. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  157. data/lib/install/examples/angular/hello_angular.js +0 -7
  158. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  159. data/lib/install/examples/elm/Main.elm +0 -55
  160. data/lib/install/examples/elm/hello_elm.js +0 -16
  161. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  162. data/lib/install/examples/react/babel.config.js +0 -87
  163. data/lib/install/examples/react/hello_react.jsx +0 -26
  164. data/lib/install/examples/react/tsconfig.json +0 -20
  165. data/lib/install/examples/stimulus/application.js +0 -1
  166. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  167. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  168. data/lib/install/examples/svelte/app.svelte +0 -11
  169. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  170. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  171. data/lib/install/examples/typescript/tsconfig.json +0 -23
  172. data/lib/install/examples/vue/app.vue +0 -22
  173. data/lib/install/examples/vue/hello_vue.js +0 -72
  174. data/lib/install/loaders/coffee.js +0 -6
  175. data/lib/install/loaders/elm.js +0 -25
  176. data/lib/install/loaders/erb.js +0 -11
  177. data/lib/install/loaders/svelte.js +0 -9
  178. data/lib/install/loaders/typescript.js +0 -11
  179. data/lib/install/loaders/vue.js +0 -6
  180. data/lib/install/react.rb +0 -18
  181. data/lib/install/stimulus.rb +0 -12
  182. data/lib/install/svelte.rb +0 -29
  183. data/lib/install/typescript.rb +0 -46
  184. data/lib/install/vue.rb +0 -49
  185. data/lib/tasks/installers.rake +0 -42
  186. data/package/config_types/__tests__/config_list.js +0 -118
  187. data/package/config_types/__tests__/config_object.js +0 -43
  188. data/package/config_types/config_list.js +0 -75
  189. data/package/config_types/config_object.js +0 -55
  190. data/package/config_types/index.js +0 -7
  191. data/package/rules/module.css.js +0 -3
  192. data/package/rules/module.sass.js +0 -8
  193. data/package/rules/node_modules.js +0 -24
  194. data/package/utils/__tests__/deep_assign.js +0 -32
  195. data/package/utils/__tests__/deep_merge.js +0 -10
  196. data/package/utils/__tests__/get_style_rule.js +0 -65
  197. data/package/utils/__tests__/objectify.js +0 -9
  198. data/package/utils/deep_assign.js +0 -22
  199. data/package/utils/deep_merge.js +0 -22
  200. data/package/utils/objectify.js +0 -3
@@ -1,46 +0,0 @@
1
- require "webpacker/configuration"
2
-
3
- additional_packages = ""
4
- example_source = "typescript"
5
-
6
- # Additional configuration is required for React projects
7
- package_json = Rails.root.join("package.json")
8
- if File.exist?(package_json)
9
- package = JSON.parse(File.read(package_json))
10
- package["dependencies"] ||= {}
11
-
12
- if package["dependencies"].keys.include?("react")
13
- additional_packages = "@types/react @types/react-dom"
14
- example_source = "react"
15
- end
16
- end
17
-
18
- say "Copying typescript loader to config/webpack/loaders"
19
- copy_file "#{__dir__}/loaders/typescript.js", Rails.root.join("config/webpack/loaders/typescript.js").to_s
20
-
21
- say "Adding typescript loader to config/webpack/environment.js"
22
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
23
- "const typescript = require('./loaders/typescript')\n",
24
- after: /require\(('|")@rails\/webpacker\1\);?\n/
25
-
26
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
27
- "environment.loaders.prepend('typescript', typescript)\n",
28
- before: "module.exports"
29
-
30
- say "Copying tsconfig.json to the Rails root directory for typescript"
31
- copy_file "#{__dir__}/examples/#{example_source}/tsconfig.json", "tsconfig.json"
32
-
33
- say "Updating webpack paths to include .ts file extension"
34
- insert_into_file Webpacker.config.config_path, "- .ts\n".indent(4), after: /\s+extensions:\n/
35
-
36
- say "Updating webpack paths to include .tsx file extension"
37
- insert_into_file Webpacker.config.config_path, "- .tsx\n".indent(4), after: /\s+extensions:\n/
38
-
39
- say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
40
- copy_file "#{__dir__}/examples/typescript/hello_typescript.ts",
41
- "#{Webpacker.config.source_entry_path}/hello_typescript.ts"
42
-
43
- say "Installing all typescript dependencies"
44
- run "yarn add typescript ts-loader #{additional_packages}"
45
-
46
- say "Webpacker now supports typescript 🎉", :green
data/lib/install/vue.rb DELETED
@@ -1,49 +0,0 @@
1
- require "webpacker/configuration"
2
-
3
- say "Copying vue loader to config/webpack/loaders"
4
- copy_file "#{__dir__}/loaders/vue.js", Rails.root.join("config/webpack/loaders/vue.js").to_s
5
-
6
- say "Adding vue loader plugin to config/webpack/environment.js"
7
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
8
- "const { VueLoaderPlugin } = require('vue-loader')\n",
9
- after: /require\(('|")@rails\/webpacker\1\);?\n/
10
-
11
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
- "environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())\n",
13
- before: "module.exports"
14
-
15
- say "Adding vue loader to config/webpack/environment.js"
16
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
17
- "const vue = require('./loaders/vue')\n",
18
- after: "require('vue-loader')\n"
19
-
20
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
21
- "environment.loaders.prepend('vue', vue)\n",
22
- before: "module.exports"
23
-
24
- say "Updating webpack paths to include .vue file extension"
25
- insert_into_file Webpacker.config.config_path, "- .vue\n".indent(4), after: /\s+extensions:\n/
26
-
27
- say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
28
- copy_file "#{__dir__}/examples/vue/hello_vue.js",
29
- "#{Webpacker.config.source_entry_path}/hello_vue.js"
30
-
31
- say "Copying Vue app file to #{Webpacker.config.source_entry_path}"
32
- copy_file "#{__dir__}/examples/vue/app.vue",
33
- "#{Webpacker.config.source_path}/app.vue"
34
-
35
- say "Installing all Vue dependencies"
36
- run "yarn add vue vue-loader vue-template-compiler"
37
-
38
- if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
39
- say "You need to enable unsafe-eval rule.", :yellow
40
- say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
41
- say "config/initializers/content_security_policy.rb with a snippet like this:", :yellow
42
- say "if Rails.env.development?", :yellow
43
- say " policy.script_src :self, :https, :unsafe_eval", :yellow
44
- say "else", :yellow
45
- say " policy.script_src :self, :https", :yellow
46
- say "end", :yellow
47
- end
48
-
49
- say "Webpacker now supports Vue.js 🎉", :green
@@ -1,42 +0,0 @@
1
- installers = {
2
- "Angular": :angular,
3
- "Elm": :elm,
4
- "React": :react,
5
- "Vue": :vue,
6
- "Erb": :erb,
7
- "Coffee": :coffee,
8
- "Typescript": :typescript,
9
- "Svelte": :svelte,
10
- "Stimulus": :stimulus
11
- }.freeze
12
-
13
- dependencies = {
14
- "Angular": [:typescript]
15
- }
16
-
17
- bin_path = ENV["BUNDLE_BIN"] || "./bin"
18
-
19
- namespace :webpacker do
20
- namespace :install do
21
- installers.each do |name, task_name|
22
- desc "Install everything needed for #{name}"
23
- task task_name => ["webpacker:verify_install"] do
24
- template = File.expand_path("../install/#{task_name}.rb", __dir__)
25
- base_path =
26
- if Rails::VERSION::MAJOR >= 5
27
- "#{RbConfig.ruby} #{bin_path}/rails app:template"
28
- else
29
- "#{RbConfig.ruby} #{bin_path}/rake rails:template"
30
- end
31
-
32
- dependencies[name] ||= []
33
- dependencies[name].each do |dependency|
34
- dependency_template = File.expand_path("../install/#{dependency}.rb", __dir__)
35
- system "#{base_path} LOCATION=#{dependency_template}"
36
- end
37
-
38
- exec "#{base_path} LOCATION=#{template}"
39
- end
40
- end
41
- end
42
- end
@@ -1,118 +0,0 @@
1
- /* global test expect */
2
-
3
- const ConfigList = require('../config_list')
4
-
5
- test('new', () => {
6
- const list = new ConfigList()
7
- expect(list).toBeInstanceOf(ConfigList)
8
- expect(list).toBeInstanceOf(Array)
9
- })
10
-
11
- test('get', () => {
12
- const list = new ConfigList()
13
- list.append('key', 'value')
14
- expect(list.get('key')).toEqual('value')
15
- })
16
-
17
- test('append', () => {
18
- const list = new ConfigList()
19
- list.append('key', 'value')
20
- expect(list.append('key1', 'value1')).toEqual([
21
- { key: 'key', value: 'value' },
22
- { key: 'key1', value: 'value1' }
23
- ])
24
- })
25
-
26
- test('prepend', () => {
27
- const list = new ConfigList()
28
- list.append('key', 'value')
29
- expect(list.prepend('key1', 'value1')).toEqual([
30
- { key: 'key1', value: 'value1' },
31
- { key: 'key', value: 'value' }
32
- ])
33
- })
34
-
35
- test('insert without position', () => {
36
- const list = new ConfigList()
37
- list.append('key', 'value')
38
-
39
- expect(list.insert('key1', 'value1')).toEqual([
40
- { key: 'key', value: 'value' },
41
- { key: 'key1', value: 'value1' }
42
- ])
43
-
44
- expect(list.insert('key2', 'value2')).toEqual([
45
- { key: 'key', value: 'value' },
46
- { key: 'key1', value: 'value1' },
47
- { key: 'key2', value: 'value2' }
48
- ])
49
- })
50
-
51
- test('insert before an item', () => {
52
- const list = new ConfigList()
53
- list.append('key', 'value')
54
- list.append('key1', 'value1')
55
-
56
- expect(list.insert('key2', 'value2', { before: 'key' })).toEqual([
57
- { key: 'key2', value: 'value2' },
58
- { key: 'key', value: 'value' },
59
- { key: 'key1', value: 'value1' }
60
- ])
61
-
62
- expect(list.insert('key3', 'value3', { before: 'key2' })).toEqual([
63
- { key: 'key3', value: 'value3' },
64
- { key: 'key2', value: 'value2' },
65
- { key: 'key', value: 'value' },
66
- { key: 'key1', value: 'value1' }
67
- ])
68
- })
69
-
70
- test('insert after an item', () => {
71
- const list = new ConfigList()
72
- list.append('key', 'value')
73
- list.append('key1', 'value1')
74
-
75
- expect(list.insert('key2', 'value2', { after: 'key' })).toEqual([
76
- { key: 'key', value: 'value' },
77
- { key: 'key2', value: 'value2' },
78
- { key: 'key1', value: 'value1' }
79
- ])
80
-
81
- expect(list.insert('key3', 'value3', { after: 'key2' })).toEqual([
82
- { key: 'key', value: 'value' },
83
- { key: 'key2', value: 'value2' },
84
- { key: 'key3', value: 'value3' },
85
- { key: 'key1', value: 'value1' }
86
- ])
87
- })
88
-
89
- test('delete', () => {
90
- const list = new ConfigList()
91
- list.append('key', 'value')
92
- list.append('key1', 'value1')
93
- expect(list.delete('key')).toEqual([{ key: 'key1', value: 'value1' }])
94
- expect(list.delete('key1')).toEqual([])
95
- })
96
-
97
- test('getIndex', () => {
98
- const list = new ConfigList()
99
- list.append('key', 'value')
100
- list.append('key1', 'value1')
101
- expect(list.getIndex('key')).toEqual(0)
102
- expect(list.getIndex('key2')).toEqual(-1)
103
- expect(() => list.getIndex('key2', true)).toThrow('Item key2 not found')
104
- })
105
-
106
- test('values', () => {
107
- const list = new ConfigList()
108
- list.append('key', 'value')
109
- list.append('key1', 'value1')
110
- expect(list.values()).toEqual(['value', 'value1'])
111
- })
112
-
113
- test('keys', () => {
114
- const list = new ConfigList()
115
- list.append('key', 'value')
116
- list.append('key1', 'value1')
117
- expect(list.keys()).toEqual(['key', 'key1'])
118
- })
@@ -1,43 +0,0 @@
1
- /* global test expect */
2
-
3
- const ConfigObject = require('../config_object')
4
-
5
- test('new', () => {
6
- const object = new ConfigObject()
7
- expect(object).toBeInstanceOf(ConfigObject)
8
- expect(object).toBeInstanceOf(Object)
9
- })
10
-
11
- test('set', () => {
12
- const object = new ConfigObject()
13
- expect(object.set('key', 'value')).toEqual({ key: 'value' })
14
- })
15
-
16
- test('get', () => {
17
- const object = new ConfigObject()
18
- object.set('key', 'value')
19
- object.set('key1', 'value1')
20
- expect(object.get('key')).toEqual('value')
21
- })
22
-
23
- test('delete', () => {
24
- const object = new ConfigObject()
25
- object.set('key', { key1: 'value' })
26
- expect(object.delete('key.key1')).toEqual({ key: {} })
27
- expect(object.delete('key')).toEqual({})
28
- })
29
-
30
- test('toObject', () => {
31
- const object = new ConfigObject()
32
- object.set('key', 'value')
33
- object.set('key1', 'value1')
34
- expect(object.toObject()).toEqual({ key: 'value', key1: 'value1' })
35
- })
36
-
37
- test('merge', () => {
38
- const object = new ConfigObject()
39
- object.set('foo', {})
40
- expect(object.merge({ key: 'foo', value: 'bar' })).toEqual(
41
- { foo: {}, key: 'foo', value: 'bar' }
42
- )
43
- })
@@ -1,75 +0,0 @@
1
- /**
2
- * @class
3
- * @extends { Array }
4
- */
5
- class ConfigList extends Array {
6
- static get [Symbol.species]() { return Array }
7
-
8
- get(key) {
9
- const index = this.getIndex(key, true)
10
- return this[index].value
11
- }
12
-
13
- append(key, value) {
14
- return this.add({ key, value })
15
- }
16
-
17
- prepend(key, value) {
18
- return this.add({ key, value }, 'prepend')
19
- }
20
-
21
- insert(key, value, pos = {}) {
22
- if (!(pos.before || pos.after)) return this.append(key, value)
23
-
24
- const currentIndex = this.getIndex(key)
25
- if (currentIndex >= 0) this.splice(currentIndex, 1)
26
-
27
- let newIndex = this.getIndex(pos.before || pos.after)
28
- if (pos.after) newIndex += 1
29
-
30
- this.splice(newIndex, 0, { key, value })
31
- return this
32
- }
33
-
34
- delete(key) {
35
- const index = this.getIndex(key, true)
36
- this.splice(index, 1)
37
- return this
38
- }
39
-
40
- getIndex(key, shouldThrow = false) {
41
- const index = this.findIndex((entry) => (
42
- entry === key
43
- || entry.key === key
44
- || (entry.constructor && entry.constructor.name === key)
45
- ))
46
-
47
- if (shouldThrow && index < 0) throw new Error(`Item ${key} not found`)
48
- return index
49
- }
50
-
51
- add({ key, value }, strategy = 'append') {
52
- const index = this.getIndex(key)
53
- if (index >= 0) this.delete(key)
54
-
55
- switch (strategy) {
56
- case 'prepend':
57
- this.unshift({ key, value })
58
- break
59
- default:
60
- this.push({ key, value })
61
- }
62
-
63
- return this
64
- }
65
-
66
- values() {
67
- return this.map((item) => item.value)
68
- }
69
-
70
- keys() {
71
- return this.map((item) => item.key)
72
- }
73
- }
74
-
75
- module.exports = ConfigList
@@ -1,55 +0,0 @@
1
- const objectify = require('../utils/objectify')
2
- const deepAssign = require('../utils/deep_assign')
3
- const deepMerge = require('../utils/deep_merge')
4
- const { isStrPath, prettyPrint } = require('../utils/helpers')
5
-
6
- /**
7
- * @class
8
- * @extends { Object }
9
- */
10
- class ConfigObject extends Object {
11
- constructor(props = {}) {
12
- super()
13
- this.merge(props)
14
- }
15
-
16
- get(key) {
17
- return isStrPath(key) ? objectify(key, this) : this[key]
18
- }
19
-
20
- set(key, value) {
21
- Object.assign(this, deepAssign(this, key, value))
22
- return this
23
- }
24
-
25
- delete(key) {
26
- let obj = this
27
- let propKey = key
28
-
29
- if (isStrPath(key)) {
30
- const keys = key.split('.')
31
- propKey = keys.pop()
32
- const parentObjPath = keys.join('.')
33
- obj = objectify(parentObjPath, this)
34
- }
35
-
36
- if (!obj) throw new Error(`Prop not found: ${key} in ${prettyPrint(obj)}`)
37
- delete obj[propKey]
38
-
39
- return this
40
- }
41
-
42
- toObject() {
43
- const object = {}
44
- /* eslint no-return-assign: 0 */
45
- Object.keys(this).forEach((key) => (object[key] = this[key]))
46
- return object
47
- }
48
-
49
- merge(config) {
50
- Object.assign(this, deepMerge(this, config))
51
- return this
52
- }
53
- }
54
-
55
- module.exports = ConfigObject
@@ -1,7 +0,0 @@
1
- const ConfigObject = require('./config_object')
2
- const ConfigList = require('./config_list')
3
-
4
- module.exports = {
5
- ConfigObject,
6
- ConfigList
7
- }
@@ -1,3 +0,0 @@
1
- const getStyleRule = require('../utils/get_style_rule')
2
-
3
- module.exports = getStyleRule(/\.(css)$/i, true)
@@ -1,8 +0,0 @@
1
- const getStyleRule = require('../utils/get_style_rule')
2
-
3
- module.exports = getStyleRule(/\.(scss|sass)$/i, true, [
4
- {
5
- loader: 'sass-loader',
6
- options: { sourceMap: true }
7
- }
8
- ])
@@ -1,24 +0,0 @@
1
- const { join } = require('path')
2
- const { cache_path: cachePath } = require('../config')
3
- const { nodeEnv } = require('../env')
4
-
5
- // Compile standard ES features for JS in node_modules with Babel.
6
- // Regex details for exclude: https://regex101.com/r/SKPnnv/1
7
- module.exports = {
8
- test: /\.(js|mjs)$/,
9
- include: /node_modules/,
10
- exclude: /(?:@?babel(?:\/|\\{1,2}|-).+)|regenerator-runtime|core-js|^webpack$|^webpack-assets-manifest$|^webpack-cli$|^webpack-sources$|^@rails\/webpacker$/,
11
- use: [
12
- {
13
- loader: 'babel-loader',
14
- options: {
15
- babelrc: false,
16
- presets: [['@babel/preset-env', { modules: false }]],
17
- cacheDirectory: join(cachePath, 'babel-loader-node-modules'),
18
- cacheCompression: nodeEnv === 'production',
19
- compact: false,
20
- sourceMaps: false
21
- }
22
- }
23
- ]
24
- }
@@ -1,32 +0,0 @@
1
- /* global test expect */
2
-
3
- const deepAssign = require('../deep_assign')
4
-
5
- describe('deepAssign()', () => {
6
- test('deeply assigns nested properties', () => {
7
- const object = { foo: { bar: { } } }
8
- const path = 'foo.bar'
9
- const value = { x: 1, y: 2 }
10
- const expectation = { foo: { bar: { x: 1, y: 2 } } }
11
- expect(deepAssign(object, path, value)).toEqual(expectation)
12
- })
13
-
14
- test('allows assignment of a literal false', () => {
15
- const object = { foo: { bar: { } } }
16
- const path = 'foo.bar'
17
- const value = false
18
- const expectation = { foo: { bar: false } }
19
- expect(deepAssign(object, path, value)).toEqual(expectation)
20
- })
21
-
22
- test('does not allow assignment of other falsy values', () => {
23
- const object = { foo: { bar: { } } }
24
- const path = 'foo.bar'
25
- const values = [undefined, null, 0, '']
26
-
27
- values.forEach(value => {
28
- const expectation = new Error(`Value can't be ${value}`)
29
- expect(() => deepAssign(object, path, value)).toThrow(expectation)
30
- })
31
- })
32
- })
@@ -1,10 +0,0 @@
1
- /* global test expect */
2
-
3
- const deepMerge = require('../deep_merge')
4
-
5
- test('deep merge objects together', () => {
6
- const object1 = { foo: { bar: [1, 2, 3], z: 1 }, x: 0 }
7
- const object2 = { foo: { bar: ['x', 'y'] }, x: 1, y: 2 }
8
- const expectation = { foo: { bar: [1, 2, 3, 'x', 'y'], z: 1 }, x: 1, y: 2 }
9
- expect(deepMerge(object1, object2)).toEqual(expectation)
10
- })
@@ -1,65 +0,0 @@
1
- const { chdirTestApp, chdirCwd } = require('../helpers')
2
-
3
- chdirTestApp()
4
-
5
- const getStyleRule = require('../get_style_rule')
6
-
7
- describe('getStyleRule', () => {
8
- afterAll(chdirCwd)
9
-
10
- test('excludes modules by default', () => {
11
- const cssRule = getStyleRule(/\.(css)$/i)
12
- const expectation = {
13
- test: /\.(css)$/i,
14
- exclude: /\.module\.[a-z]+$/
15
- }
16
-
17
- expect(cssRule).toMatchObject(expectation)
18
- })
19
-
20
- test('includes modules if set to true', () => {
21
- const cssRule = getStyleRule(/\.(scss)$/i, true)
22
- const expectation = {
23
- test: /\.(scss)$/i,
24
- include: /\.module\.[a-z]+$/
25
- }
26
-
27
- expect(cssRule).toMatchObject(expectation)
28
- })
29
-
30
- test('adds extra preprocessors if supplied', () => {
31
- const expectation = [{ foo: 'bar' }]
32
- const cssRule = getStyleRule(/\.(css)$/i, true, expectation)
33
-
34
- expect(cssRule.use).toMatchObject(expect.arrayContaining(expectation))
35
- })
36
-
37
- test('adds mini-css-extract-plugin when extract_css is true', () => {
38
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
39
- const expectation = [MiniCssExtractPlugin.loader]
40
-
41
- require('../../config').extract_css = true
42
- const cssRule = getStyleRule(/\.(css)$/i)
43
-
44
- expect(cssRule.use).toMatchObject(expect.arrayContaining(expectation))
45
- })
46
-
47
- test('adds style-loader when extract_css is true', () => {
48
- const expectation = [{loader: 'style-loader'}]
49
-
50
- require('../../config').extract_css = false
51
- const cssRule = getStyleRule(/\.(css)$/i)
52
-
53
- expect(cssRule.use).toMatchObject(expect.objectContaining(expectation))
54
- })
55
-
56
- test(`doesn't add mini-css-extract-plugin when extract_css is false`, () => {
57
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
58
- const expectation = [MiniCssExtractPlugin.loader]
59
-
60
- require('../../config').extract_css = false
61
- const cssRule = getStyleRule(/\.(css)$/i)
62
-
63
- expect(cssRule.use).toMatchObject(expect.not.arrayContaining(expectation))
64
- })
65
- })
@@ -1,9 +0,0 @@
1
- /* global test expect */
2
-
3
- const objectify = require('../objectify')
4
-
5
- test('Get object from a string path', () => {
6
- const object = { foo: { bar: { x: 1 } } }
7
- expect(objectify('foo.bar', object)).toEqual({ x: 1 })
8
- expect(objectify('some.bar', object)).toEqual(undefined)
9
- })
@@ -1,22 +0,0 @@
1
- const { canMerge, prettyPrint } = require('./helpers')
2
- const deepMerge = require('./deep_merge')
3
-
4
- const deepAssign = (obj, path, value) => {
5
- if (!value && value !== false) throw new Error(`Value can't be ${value}`)
6
-
7
- const keys = path.split('.')
8
- const key = keys.pop()
9
-
10
- const objRef = keys.reduce((acc, currentValue) => {
11
- /* eslint no-param-reassign: 0 */
12
- if (!acc[currentValue]) acc[currentValue] = {}
13
- return acc[currentValue]
14
- }, obj)
15
-
16
- if (!objRef) throw new Error(`Prop not found: ${path} in ${prettyPrint(obj)}`)
17
-
18
- objRef[key] = canMerge(value) ? deepMerge(objRef[key], value) : value
19
- return obj
20
- }
21
-
22
- module.exports = deepAssign
@@ -1,22 +0,0 @@
1
- const {
2
- isObject, isArray, isEqual, isEmpty
3
- } = require('./helpers')
4
-
5
- const deepMerge = (target, source) => {
6
- if (isEmpty(target)) return source
7
- if (isEmpty(source)) return target
8
- if (isEqual(target, source)) return source
9
- if (isArray(target) && isArray(source)) return [...new Set([...target, ...source])]
10
- if (!(isObject(target) && isObject(source))) return source
11
-
12
- return [...Object.keys(target), ...Object.keys(source)].reduce(
13
- (result, key) => ({
14
-
15
- ...result,
16
- [key]: deepMerge(target[key], source[key])
17
- }),
18
- {}
19
- )
20
- }
21
-
22
- module.exports = deepMerge
@@ -1,3 +0,0 @@
1
- const objectify = (path, obj) => path.split('.').reduce((prev, curr) => (prev ? prev[curr] : undefined), obj)
2
-
3
- module.exports = objectify