shakapacker 7.3.0.beta.1 → 8.0.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +1 -1
  3. data/.eslintrc.js +29 -8
  4. data/.github/PULL_REQUEST_TEMPLATE.md +10 -3
  5. data/.github/workflows/dummy.yml +6 -1
  6. data/.github/workflows/generator.yml +14 -18
  7. data/.github/workflows/node.yml +56 -0
  8. data/.github/workflows/ruby.yml +29 -17
  9. data/.node-version +1 -1
  10. data/.rubocop.yml +1 -0
  11. data/CHANGELOG.md +56 -5
  12. data/README.md +101 -48
  13. data/Rakefile +1 -7
  14. data/docs/customizing_babel_config.md +2 -2
  15. data/docs/deployment.md +13 -6
  16. data/docs/react.md +7 -13
  17. data/docs/troubleshooting.md +4 -4
  18. data/docs/using_esbuild_loader.md +1 -1
  19. data/docs/using_swc_loader.md +1 -1
  20. data/docs/v6_upgrade.md +1 -1
  21. data/docs/v8_upgrade.md +148 -0
  22. data/gemfiles/Gemfile-rails.7.1.x +12 -0
  23. data/jest.config.js +4 -0
  24. data/lib/install/config/shakapacker.yml +2 -2
  25. data/lib/install/template.rb +36 -30
  26. data/lib/shakapacker/base_strategy.rb +2 -1
  27. data/lib/shakapacker/compiler.rb +6 -21
  28. data/lib/shakapacker/configuration.rb +2 -46
  29. data/lib/shakapacker/deprecation_helper.rb +0 -78
  30. data/lib/shakapacker/dev_server.rb +1 -16
  31. data/lib/shakapacker/dev_server_runner.rb +2 -21
  32. data/lib/shakapacker/env.rb +1 -1
  33. data/lib/shakapacker/helper.rb +3 -3
  34. data/lib/shakapacker/instance.rb +1 -3
  35. data/lib/shakapacker/manifest.rb +1 -1
  36. data/lib/shakapacker/railtie.rb +7 -0
  37. data/lib/shakapacker/runner.rb +4 -18
  38. data/lib/shakapacker/utils/manager.rb +58 -0
  39. data/lib/shakapacker/utils/misc.rb +0 -12
  40. data/lib/shakapacker/version.rb +1 -1
  41. data/lib/shakapacker/version_checker.rb +9 -30
  42. data/lib/shakapacker/webpack_runner.rb +2 -21
  43. data/lib/shakapacker.rb +0 -2
  44. data/lib/tasks/shakapacker/check_binstubs.rake +12 -26
  45. data/lib/tasks/shakapacker/check_manager.rake +3 -8
  46. data/lib/tasks/shakapacker/info.rake +6 -15
  47. data/package/babel/preset.js +15 -15
  48. data/package/config.js +15 -19
  49. data/package/dev_server.js +4 -4
  50. data/package/env.js +19 -17
  51. data/package/environments/base.js +41 -24
  52. data/package/environments/development.js +6 -6
  53. data/package/environments/production.js +16 -16
  54. data/package/environments/test.js +1 -1
  55. data/package/esbuild/index.js +6 -6
  56. data/package/index.d.ts +0 -2
  57. data/package/index.js +17 -46
  58. data/package/rules/babel.js +6 -8
  59. data/package/rules/coffee.js +2 -2
  60. data/package/rules/css.js +1 -1
  61. data/package/rules/erb.js +4 -4
  62. data/package/rules/esbuild.js +5 -7
  63. data/package/rules/file.js +14 -7
  64. data/package/rules/index.js +11 -11
  65. data/package/rules/jscommon.js +8 -5
  66. data/package/rules/less.js +10 -9
  67. data/package/rules/raw.js +1 -1
  68. data/package/rules/sass.js +4 -4
  69. data/package/rules/stylus.js +12 -7
  70. data/package/rules/swc.js +5 -7
  71. data/package/swc/index.js +10 -10
  72. data/package/utils/configPath.js +3 -18
  73. data/package/utils/defaultConfigPath.js +1 -1
  74. data/package/utils/{get_style_rule.js → getStyleRule.js} +6 -6
  75. data/package/utils/helpers.js +2 -43
  76. data/package/utils/inliningCss.js +4 -3
  77. data/package/utils/snakeToCamelCase.js +5 -0
  78. data/package/webpackDevServerConfig.js +28 -25
  79. data/package.json +12 -18
  80. data/prettier.config.js +4 -0
  81. data/shakapacker.gemspec +1 -1
  82. data/spec/dummy/app/javascript/packs/application.js +1 -1
  83. data/spec/dummy/config/application.rb +3 -0
  84. data/spec/dummy/config/initializers/react_on_rails.rb +2 -2
  85. data/spec/dummy/config/shakapacker.yml +3 -4
  86. data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -1
  87. data/spec/dummy/config/webpack/webpack.config.js +1 -1
  88. data/spec/dummy/package.json +2 -1
  89. data/spec/dummy/yarn.lock +2 -3
  90. data/spec/fixtures/github_url_package-lock.v1.json +1 -1
  91. data/spec/fixtures/github_url_package-lock.v2.json +2 -2
  92. data/spec/fixtures/github_url_package.json +1 -1
  93. data/spec/fixtures/github_url_pnpm-lock.v7.yaml +1 -1
  94. data/spec/fixtures/github_url_pnpm-lock.v8.yaml +1 -1
  95. data/spec/fixtures/github_url_yarn.v1.lock +1 -1
  96. data/spec/fixtures/github_url_yarn.v2.lock +2 -2
  97. data/spec/generator_specs/e2e_template/template.rb +15 -28
  98. data/spec/generator_specs/generator_spec.rb +6 -136
  99. data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -1
  100. data/spec/shakapacker/compiler_spec.rb +1 -3
  101. data/spec/shakapacker/configuration_spec.rb +4 -56
  102. data/spec/shakapacker/dev_server_runner_spec.rb +19 -102
  103. data/spec/shakapacker/dev_server_spec.rb +1 -16
  104. data/spec/shakapacker/engine_rake_tasks_spec.rb +1 -16
  105. data/spec/shakapacker/helper_spec.rb +3 -3
  106. data/spec/shakapacker/instance_spec.rb +1 -3
  107. data/spec/shakapacker/rake_tasks_spec.rb +2 -14
  108. data/spec/shakapacker/shakapacker_spec.rb +0 -1
  109. data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -1
  110. data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -1
  111. data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -1
  112. data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -1
  113. data/spec/shakapacker/test_app/package.json +2 -1
  114. data/spec/shakapacker/utils_manager_spec.rb +125 -0
  115. data/spec/shakapacker/version_checker_spec.rb +5 -5
  116. data/spec/shakapacker/webpack_runner_spec.rb +19 -28
  117. data/spec/support/package_json_helpers.rb +7 -4
  118. data/test/helpers.js +67 -0
  119. data/test/package/config.test.js +50 -0
  120. data/test/package/dev_server.test.js +44 -0
  121. data/test/package/development.test.js +43 -0
  122. data/test/package/env.test.js +57 -0
  123. data/test/package/environments/base.test.js +105 -0
  124. data/test/package/environments/development.test.js +50 -0
  125. data/test/package/environments/production.test.js +106 -0
  126. data/test/package/index.test.js +45 -0
  127. data/test/package/production.test.js +32 -0
  128. data/test/package/rules/babel.test.js +58 -0
  129. data/test/package/rules/esbuild.test.js +59 -0
  130. data/test/package/rules/file.test.js +81 -0
  131. data/test/package/rules/index.test.js +7 -0
  132. data/test/package/rules/raw.test.js +12 -0
  133. data/test/package/rules/swc.test.js +59 -0
  134. data/test/package/staging.test.js +31 -0
  135. data/test/package/test.test.js +28 -0
  136. data/yarn.lock +1278 -421
  137. metadata +50 -100
  138. data/.github/workflows/jest.yml +0 -33
  139. data/.github/workflows/js-lint.yml +0 -33
  140. data/.github/workflows/rubocop.yml +0 -28
  141. data/.github/workflows/ruby-backward-compatibility.yml +0 -51
  142. data/lib/install/package.json +0 -15
  143. data/lib/tasks/shakapacker/check_yarn.rake +0 -34
  144. data/lib/tasks/shakapacker/yarn_install.rake +0 -24
  145. data/lib/tasks/webpacker/binstubs.rake +0 -9
  146. data/lib/tasks/webpacker/check_binstubs.rake +0 -9
  147. data/lib/tasks/webpacker/check_node.rake +0 -9
  148. data/lib/tasks/webpacker/check_yarn.rake +0 -9
  149. data/lib/tasks/webpacker/clean.rake +0 -9
  150. data/lib/tasks/webpacker/clobber.rake +0 -11
  151. data/lib/tasks/webpacker/compile.rake +0 -9
  152. data/lib/tasks/webpacker/info.rake +0 -9
  153. data/lib/tasks/webpacker/install.rake +0 -9
  154. data/lib/tasks/webpacker/verify_config.rake +0 -9
  155. data/lib/tasks/webpacker/verify_install.rake +0 -9
  156. data/lib/tasks/webpacker/yarn_install.rake +0 -9
  157. data/lib/tasks/webpacker.rake +0 -20
  158. data/lib/webpacker/dev_server_runner.rb +0 -9
  159. data/lib/webpacker/webpack_runner.rb +0 -9
  160. data/lib/webpacker.rb +0 -4
  161. data/package/__tests__/config-bc.js +0 -27
  162. data/package/__tests__/config.js +0 -46
  163. data/package/__tests__/dev_server-bc.js +0 -46
  164. data/package/__tests__/dev_server.js +0 -46
  165. data/package/__tests__/development-bc.js +0 -66
  166. data/package/__tests__/development.js +0 -66
  167. data/package/__tests__/env-bc.js +0 -59
  168. data/package/__tests__/env.js +0 -59
  169. data/package/__tests__/index-bc.js +0 -22
  170. data/package/__tests__/index.js +0 -46
  171. data/package/__tests__/production-bc.js +0 -51
  172. data/package/__tests__/production.js +0 -51
  173. data/package/__tests__/staging-bc.js +0 -53
  174. data/package/__tests__/staging.js +0 -53
  175. data/package/__tests__/test-bc.js +0 -43
  176. data/package/__tests__/test.js +0 -43
  177. data/package/environments/__tests__/base-bc.js +0 -107
  178. data/package/environments/__tests__/base.js +0 -107
  179. data/package/environments/__tests__/development.js +0 -53
  180. data/package/environments/__tests__/production.js +0 -92
  181. data/package/rules/__tests__/__utils__/webpack.js +0 -50
  182. data/package/rules/__tests__/babel.js +0 -63
  183. data/package/rules/__tests__/esbuild.js +0 -64
  184. data/package/rules/__tests__/file.js +0 -79
  185. data/package/rules/__tests__/index.js +0 -7
  186. data/package/rules/__tests__/raw.js +0 -18
  187. data/package/rules/__tests__/swc.js +0 -63
  188. data/package/utils/snakeToCamelCase +0 -7
  189. data/spec/backward_compatibility_specs/command_spec.rb +0 -116
  190. data/spec/backward_compatibility_specs/compiler_spec.rb +0 -59
  191. data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +0 -24
  192. data/spec/backward_compatibility_specs/configuration_spec.rb +0 -294
  193. data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +0 -206
  194. data/spec/backward_compatibility_specs/dev_server_spec.rb +0 -47
  195. data/spec/backward_compatibility_specs/digest_strategy_spec.rb +0 -38
  196. data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +0 -67
  197. data/spec/backward_compatibility_specs/env_spec.rb +0 -23
  198. data/spec/backward_compatibility_specs/helper_spec.rb +0 -243
  199. data/spec/backward_compatibility_specs/instance_spec.rb +0 -31
  200. data/spec/backward_compatibility_specs/manifest_spec.rb +0 -100
  201. data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +0 -55
  202. data/spec/backward_compatibility_specs/rake_tasks_spec.rb +0 -41
  203. data/spec/backward_compatibility_specs/spec_helper_initializer.rb +0 -24
  204. data/spec/backward_compatibility_specs/webpack_runner_spec.rb +0 -86
  205. data/spec/backward_compatibility_specs/webpacker_spec.rb +0 -41
  206. data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +0 -2
  207. data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +0 -3
  208. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/application.js +0 -10
  209. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/generated/something.js +0 -2
  210. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.css +0 -4
  211. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.js +0 -4
  212. data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker +0 -13
  213. data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker-dev-server +0 -13
  214. data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +0 -11
  215. data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +0 -4
  216. data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +0 -1
  217. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
  218. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker.yml +0 -83
  219. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -84
  220. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_defaults_fallback.yml +0 -11
  221. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_manifest_path.yml +0 -80
  222. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_nested_entries.yml +0 -83
  223. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +0 -7
  224. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +0 -85
  225. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_public_root.yml +0 -18
  226. data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +0 -5
  227. data/spec/backward_compatibility_specs/webpacker_test_app/package.json +0 -13
  228. data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +0 -58
  229. data/spec/backward_compatibility_specs/webpacker_test_app/some.config.js +0 -0
  230. data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +0 -1
  231. data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +0 -11
@@ -1,53 +0,0 @@
1
- /* test expect, describe, afterAll, beforeEach */
2
-
3
- const { resolve } = require('path')
4
- const { chdirTestApp } = require('../utils/helpers')
5
-
6
- const rootPath = process.cwd()
7
- chdirTestApp()
8
-
9
- describe('Custom environment', () => {
10
- afterAll(() => process.chdir(rootPath))
11
-
12
- describe('generateWebpackConfig', () => {
13
- beforeEach(() => jest.resetModules())
14
-
15
- test('should use staging config and default production environment', () => {
16
- process.env.RAILS_ENV = 'staging'
17
- delete process.env.NODE_ENV
18
-
19
- const { generateWebpackConfig } = require('../index')
20
-
21
- const webpackConfig = generateWebpackConfig()
22
-
23
- expect(webpackConfig.output.path).toEqual(
24
- resolve('public', 'packs-staging')
25
- )
26
- expect(webpackConfig.output.publicPath).toEqual('/packs-staging/')
27
- expect(webpackConfig).toMatchObject({
28
- devtool: 'source-map',
29
- stats: 'normal'
30
- })
31
- })
32
- })
33
-
34
- describe('globalMutableWebpackConfig', () => {
35
- beforeEach(() => jest.resetModules())
36
-
37
- test('should use staging config and default production environment', () => {
38
- process.env.RAILS_ENV = 'staging'
39
- delete process.env.NODE_ENV
40
-
41
- const { globalMutableWebpackConfig: webpackConfig } = require('../index')
42
-
43
- expect(webpackConfig.output.path).toEqual(
44
- resolve('public', 'packs-staging')
45
- )
46
- expect(webpackConfig.output.publicPath).toEqual('/packs-staging/')
47
- expect(webpackConfig).toMatchObject({
48
- devtool: 'source-map',
49
- stats: 'normal'
50
- })
51
- })
52
- })
53
- })
@@ -1,43 +0,0 @@
1
- /* test expect, describe, afterAll, beforeEach */
2
-
3
- const { resolve } = require('path')
4
- const { chdirWebpackerTestApp } = require('../utils/helpers')
5
-
6
- const rootPath = process.cwd()
7
- chdirWebpackerTestApp()
8
-
9
- describe('Backward Compatibility - Test environment', () => {
10
- afterAll(() => process.chdir(rootPath))
11
-
12
- describe('toWebpackConfig', () => {
13
- beforeEach(() => jest.resetModules())
14
-
15
- test('should use test config and production environment', () => {
16
- process.env.RAILS_ENV = 'test'
17
- process.env.NODE_ENV = 'test'
18
-
19
- const { generateWebpackConfig } = require('../index')
20
-
21
- const webpackConfig = generateWebpackConfig()
22
-
23
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs-test'))
24
- expect(webpackConfig.output.publicPath).toEqual('/packs-test/')
25
- expect(webpackConfig.devServer).toEqual(undefined)
26
- })
27
- })
28
-
29
- describe('globalMutableWebpackConfig', () => {
30
- beforeEach(() => jest.resetModules())
31
-
32
- test('should use test config and production environment', () => {
33
- process.env.RAILS_ENV = 'test'
34
- process.env.NODE_ENV = 'test'
35
-
36
- const { globalMutableWebpackConfig: webpackConfig } = require('../index')
37
-
38
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs-test'))
39
- expect(webpackConfig.output.publicPath).toEqual('/packs-test/')
40
- expect(webpackConfig.devServer).toEqual(undefined)
41
- })
42
- })
43
- })
@@ -1,43 +0,0 @@
1
- /* test expect, describe, afterAll, beforeEach */
2
-
3
- const { resolve } = require('path')
4
- const { chdirTestApp } = require('../utils/helpers')
5
-
6
- const rootPath = process.cwd()
7
- chdirTestApp()
8
-
9
- describe('Test environment', () => {
10
- afterAll(() => process.chdir(rootPath))
11
-
12
- describe('generateWebpackConfig', () => {
13
- beforeEach(() => jest.resetModules())
14
-
15
- test('should use test config and production environment', () => {
16
- process.env.RAILS_ENV = 'test'
17
- process.env.NODE_ENV = 'test'
18
-
19
- const { generateWebpackConfig } = require('../index')
20
-
21
- const webpackConfig = generateWebpackConfig()
22
-
23
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs-test'))
24
- expect(webpackConfig.output.publicPath).toEqual('/packs-test/')
25
- expect(webpackConfig.devServer).toEqual(undefined)
26
- })
27
- })
28
-
29
- describe('globalMutableWebpackConfig', () => {
30
- beforeEach(() => jest.resetModules())
31
-
32
- test('should use test config and production environment', () => {
33
- process.env.RAILS_ENV = 'test'
34
- process.env.NODE_ENV = 'test'
35
-
36
- const { globalMutableWebpackConfig: webpackConfig } = require('../index')
37
-
38
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs-test'))
39
- expect(webpackConfig.output.publicPath).toEqual('/packs-test/')
40
- expect(webpackConfig.devServer).toEqual(undefined)
41
- })
42
- })
43
- })
@@ -1,107 +0,0 @@
1
- /* global test expect, describe, afterAll, beforeEach */
2
-
3
- // environment.js expects to find config/webpacker.yml and resolved modules from
4
- // the root of a Rails project
5
-
6
- const { resetEnv, chdirWebpackerTestApp } = require('../../utils/helpers')
7
-
8
- const rootPath = process.cwd()
9
- chdirWebpackerTestApp()
10
-
11
- const { resolve } = require('path')
12
-
13
- const baseConfig = require('../base')
14
- const config = require("../../config");
15
-
16
- describe('Base config', () => {
17
- beforeEach(() => jest.resetModules() && resetEnv())
18
- afterAll(() => process.chdir(rootPath))
19
-
20
- describe('config', () => {
21
- test('should return entry', () => {
22
- expect(baseConfig.entry.application).toEqual(
23
- resolve('app', 'packs', 'entrypoints', 'application.js')
24
- )
25
- })
26
-
27
- test('should return false for css_extract_ignore_order_warnings when using default config', () => {
28
- expect(config.css_extract_ignore_order_warnings).toEqual(false)
29
- })
30
-
31
- test('should return true for css_extract_ignore_order_warnings when configured', () => {
32
- process.env.WEBPACKER_CONFIG = 'config/webpacker_css_extract_ignore_order_warnings.yml'
33
- const config = require("../../config");
34
-
35
- expect(config.css_extract_ignore_order_warnings).toEqual(true)
36
- })
37
-
38
- test('should return only 2 entry points with config.nested_entries == false', () => {
39
- expect(config.nested_entries).toEqual(false)
40
-
41
- expect(baseConfig.entry.multi_entry.sort()).toEqual([
42
- resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
43
- resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
44
- ])
45
- expect(baseConfig.entry['generated/something']).toEqual(undefined)
46
- })
47
-
48
- test('should returns top level and nested entry points with config.nested_entries == true', () => {
49
- process.env.WEBPACKER_CONFIG = 'config/webpacker_nested_entries.yml'
50
- const config = require("../../config");
51
- const baseConfig = require('../base')
52
-
53
- expect(config.nested_entries).toEqual(true)
54
-
55
- expect(baseConfig.entry.application).toEqual(
56
- resolve('app', 'packs', 'entrypoints', 'application.js')
57
- )
58
- expect(baseConfig.entry.multi_entry.sort()).toEqual([
59
- resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
60
- resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
61
- ])
62
- expect(baseConfig.entry['generated/something']).toEqual(
63
- resolve('app', 'packs', 'entrypoints', 'generated', 'something.js')
64
- )
65
- })
66
-
67
- test('should return output', () => {
68
- expect(baseConfig.output.filename).toEqual('js/[name]-[contenthash].js')
69
- expect(baseConfig.output.chunkFilename).toEqual(
70
- 'js/[name]-[contenthash].chunk.js'
71
- )
72
- })
73
-
74
- test('should return default loader rules for each file in config/loaders', () => {
75
- const rules = require('../../rules')
76
-
77
- const defaultRules = Object.keys(rules)
78
- const configRules = baseConfig.module.rules
79
-
80
- expect(defaultRules.length).toEqual(3)
81
- expect(configRules.length).toEqual(3)
82
- })
83
-
84
- test('should return default plugins', () => {
85
- expect(baseConfig.plugins.length).toEqual(2)
86
- })
87
-
88
- test('should return default resolveLoader', () => {
89
- expect(baseConfig.resolveLoader.modules).toEqual(['node_modules'])
90
- })
91
-
92
- test('should return default resolve.modules with additions', () => {
93
- expect(baseConfig.resolve.modules).toEqual([
94
- resolve('app', 'packs'),
95
- resolve('app/assets'),
96
- resolve('/etc/yarn'),
97
- resolve('some.config.js'),
98
- resolve('app/elm'),
99
- 'node_modules'
100
- ])
101
- })
102
-
103
- test('returns plugins property as Array', () => {
104
- expect(baseConfig.plugins).toBeInstanceOf(Array)
105
- })
106
- })
107
- })
@@ -1,107 +0,0 @@
1
- /* global test expect, describe, afterAll, beforeEach */
2
-
3
- // environment.js expects to find config/shakapacker.yml and resolved modules from
4
- // the root of a Rails project
5
-
6
- const { chdirTestApp, chdirCwd, resetEnv } = require('../../utils/helpers')
7
-
8
- const rootPath = process.cwd()
9
- chdirTestApp()
10
-
11
- const { resolve } = require('path')
12
-
13
- const baseConfig = require('../base')
14
- const config = require("../../config");
15
-
16
- describe('Base config', () => {
17
- beforeEach(() => jest.resetModules() && resetEnv())
18
- afterAll(() => process.chdir(rootPath))
19
-
20
- describe('config', () => {
21
- test('should return entry', () => {
22
- expect(baseConfig.entry.application).toEqual(
23
- resolve('app', 'javascript', 'entrypoints', 'application.js')
24
- )
25
- })
26
-
27
- test('should return false for css_extract_ignore_order_warnings when using default config', () => {
28
- expect(config.css_extract_ignore_order_warnings).toEqual(false)
29
- })
30
-
31
- test('should return true for css_extract_ignore_order_warnings when configured', () => {
32
- process.env.SHAKAPACKER_CONFIG = 'config/shakapacker_css_extract_ignore_order_warnings.yml'
33
- const config = require("../../config");
34
-
35
- expect(config.css_extract_ignore_order_warnings).toEqual(true)
36
- })
37
-
38
- test('should return only 2 entry points with config.nested_entries == false', () => {
39
- expect(config.nested_entries).toEqual(false)
40
-
41
- expect(baseConfig.entry.multi_entry.sort()).toEqual([
42
- resolve('app', 'javascript', 'entrypoints', 'multi_entry.css'),
43
- resolve('app', 'javascript', 'entrypoints', 'multi_entry.js')
44
- ])
45
- expect(baseConfig.entry['generated/something']).toEqual(undefined)
46
- })
47
-
48
- test('should returns top level and nested entry points with config.nested_entries == true', () => {
49
- process.env.SHAKAPACKER_CONFIG = 'config/shakapacker_nested_entries.yml'
50
- const config = require("../../config");
51
- const baseConfig = require('../base')
52
-
53
- expect(config.nested_entries).toEqual(true)
54
-
55
- expect(baseConfig.entry.application).toEqual(
56
- resolve('app', 'javascript', 'entrypoints', 'application.js')
57
- )
58
- expect(baseConfig.entry.multi_entry.sort()).toEqual([
59
- resolve('app', 'javascript', 'entrypoints', 'multi_entry.css'),
60
- resolve('app', 'javascript', 'entrypoints', 'multi_entry.js')
61
- ])
62
- expect(baseConfig.entry['generated/something']).toEqual(
63
- resolve('app', 'javascript', 'entrypoints', 'generated', 'something.js')
64
- )
65
- })
66
-
67
- test('should return output', () => {
68
- expect(baseConfig.output.filename).toEqual('js/[name]-[contenthash].js')
69
- expect(baseConfig.output.chunkFilename).toEqual(
70
- 'js/[name]-[contenthash].chunk.js'
71
- )
72
- })
73
-
74
- test('should return default loader rules for each file in config/loaders', () => {
75
- const rules = require('../../rules')
76
-
77
- const defaultRules = Object.keys(rules)
78
- const configRules = baseConfig.module.rules
79
-
80
- expect(defaultRules.length).toEqual(3)
81
- expect(configRules.length).toEqual(3)
82
- })
83
-
84
- test('should return default plugins', () => {
85
- expect(baseConfig.plugins.length).toEqual(2)
86
- })
87
-
88
- test('should return default resolveLoader', () => {
89
- expect(baseConfig.resolveLoader.modules).toEqual(['node_modules'])
90
- })
91
-
92
- test('should return default resolve.modules with additions', () => {
93
- expect(baseConfig.resolve.modules).toEqual([
94
- resolve('app', 'javascript'),
95
- resolve('app/assets'),
96
- resolve('/etc/yarn'),
97
- resolve('some.config.js'),
98
- resolve('app/elm'),
99
- 'node_modules'
100
- ])
101
- })
102
-
103
- test('returns plugins property as Array', () => {
104
- expect(baseConfig.plugins).toBeInstanceOf(Array)
105
- })
106
- })
107
- })
@@ -1,53 +0,0 @@
1
- /* global test expect, describe, afterAll, beforeEach */
2
-
3
- const { chdirTestApp, resetEnv } = require('../../utils/helpers')
4
- const rootPath = process.cwd()
5
- chdirTestApp()
6
-
7
- describe('Development specific config', () => {
8
- beforeEach(() => {
9
- jest.resetModules()
10
- resetEnv()
11
- process.env['NODE_ENV'] = 'development'
12
- })
13
- afterAll(() => process.chdir(rootPath))
14
-
15
- describe('with config.useContentHash = true', () => {
16
- test('sets filename to use contentHash', () => {
17
- const config = require("../../config");
18
- config.useContentHash = true
19
- const environmentConfig = require('../development')
20
-
21
- expect(environmentConfig.output.filename).toEqual('js/[name]-[contenthash].js')
22
- expect(environmentConfig.output.chunkFilename).toEqual(
23
- 'js/[name]-[contenthash].chunk.js'
24
- )
25
- })
26
- })
27
-
28
- describe('with config.useContentHash = false', () => {
29
- test('sets filename without using contentHash', () => {
30
- const config = require("../../config");
31
- config.useContentHash = false
32
- const environmentConfig = require('../development')
33
-
34
- expect(environmentConfig.output.filename).toEqual('js/[name].js')
35
- expect(environmentConfig.output.chunkFilename).toEqual(
36
- 'js/[name].chunk.js'
37
- )
38
- })
39
- })
40
-
41
- describe('with unset config.useContentHash', () => {
42
- test('sets filename without using contentHash', () => {
43
- const config = require("../../config");
44
- delete config.useContentHash
45
- const environmentConfig = require('../development')
46
-
47
- expect(environmentConfig.output.filename).toEqual('js/[name].js')
48
- expect(environmentConfig.output.chunkFilename).toEqual(
49
- 'js/[name].chunk.js'
50
- )
51
- })
52
- })
53
- })
@@ -1,92 +0,0 @@
1
- /* global test expect, describe, afterAll, beforeEach */
2
-
3
- const { chdirTestApp, resetEnv } = require('../../utils/helpers')
4
- const rootPath = process.cwd()
5
- chdirTestApp()
6
-
7
- describe('Production specific config', () => {
8
- beforeEach(() => {
9
- jest.resetModules()
10
- resetEnv()
11
- process.env['NODE_ENV'] = 'production'
12
- })
13
- afterAll(() => process.chdir(rootPath))
14
-
15
- describe('with config.useContentHash = true', () => {
16
- test('sets filename to use contentHash', () => {
17
- const config = require("../../config");
18
- config.useContentHash = true
19
- const environmentConfig = require('../production')
20
-
21
- expect(environmentConfig.output.filename).toEqual('js/[name]-[contenthash].js')
22
- expect(environmentConfig.output.chunkFilename).toEqual(
23
- 'js/[name]-[contenthash].chunk.js'
24
- )
25
- })
26
-
27
- test("doesn't shows any warning message", () => {
28
- const consoleWarnSpy = jest.spyOn(console, 'warn');
29
- const config = require("../../config");
30
- config.useContentHash = true
31
- const environmentConfig = require('../production')
32
-
33
- expect(consoleWarnSpy).not.toHaveBeenCalledWith(
34
- expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
35
- )
36
-
37
- consoleWarnSpy.mockRestore()
38
- })
39
- })
40
-
41
- describe('with config.useContentHash = false', () => {
42
- test('sets filename to use contentHash', () => {
43
- const config = require("../../config");
44
- config.useContentHash = false
45
- const environmentConfig = require('../production')
46
-
47
- expect(environmentConfig.output.filename).toEqual('js/[name]-[contenthash].js')
48
- expect(environmentConfig.output.chunkFilename).toEqual(
49
- 'js/[name]-[contenthash].chunk.js'
50
- )
51
- })
52
-
53
- test('shows a warning message', () => {
54
- const consoleWarnSpy = jest.spyOn(console, 'warn');
55
- const config = require("../../config");
56
- config.useContentHash = false
57
- const environmentConfig = require('../production')
58
-
59
- expect(consoleWarnSpy).toHaveBeenCalledWith(
60
- expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
61
- )
62
-
63
- consoleWarnSpy.mockRestore()
64
- })
65
- })
66
-
67
- describe('with unset config.useContentHash', () => {
68
- test('sets filename to use contentHash', () => {
69
- const config = require("../../config");
70
- delete config.useContentHash
71
- const environmentConfig = require('../production')
72
-
73
- expect(environmentConfig.output.filename).toEqual('js/[name]-[contenthash].js')
74
- expect(environmentConfig.output.chunkFilename).toEqual(
75
- 'js/[name]-[contenthash].chunk.js'
76
- )
77
- })
78
-
79
- test("doesn't shows any warning message", () => {
80
- const consoleWarnSpy = jest.spyOn(console, 'warn');
81
- const config = require("../../config");
82
- delete config.useContentHash
83
- const environmentConfig = require('../production')
84
-
85
- expect(consoleWarnSpy).not.toHaveBeenCalledWith(
86
- expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
87
- )
88
-
89
- consoleWarnSpy.mockRestore()
90
- })
91
- })
92
- })
@@ -1,50 +0,0 @@
1
- const webpack = require("webpack");
2
- const MemoryFS = require("memory-fs");
3
- const thenify = require("thenify");
4
- const path = require("path");
5
-
6
- const createTrackLoader = () => {
7
- const filesTracked = {};
8
- return [
9
- filesTracked,
10
- (source) => {
11
- filesTracked[source.resource] = true;
12
- return source;
13
- },
14
- ];
15
- };
16
-
17
- const node_modules = path.resolve("node_modules");
18
- const node_modules_included = path.resolve("node_modules/included");
19
- const app_javascript = path.resolve("app/javascript");
20
-
21
- const createInMemoryFs = () => {
22
- const fs = new MemoryFS();
23
-
24
- fs.mkdirpSync(node_modules);
25
- fs.mkdirpSync(node_modules_included);
26
- fs.mkdirpSync(app_javascript);
27
-
28
- return fs;
29
- };
30
-
31
- const createTestCompiler = (config, fs = createInMemoryFs()) => {
32
- Object.values(config.entry).forEach((file) => {
33
- fs.writeFileSync(file, "console.log(1);");
34
- });
35
-
36
- const compiler = webpack(config);
37
- compiler.run = thenify(compiler.run);
38
- compiler.inputFileSystem = fs;
39
- compiler.outputFileSystem = fs;
40
- return compiler;
41
- };
42
-
43
- module.exports = {
44
- createTrackLoader,
45
- node_modules,
46
- node_modules_included,
47
- app_javascript,
48
- createInMemoryFs,
49
- createTestCompiler,
50
- };
@@ -1,63 +0,0 @@
1
- const path = require("path");
2
- const {
3
- app_javascript,
4
- node_modules,
5
- node_modules_included,
6
- createTestCompiler,
7
- createTrackLoader,
8
- } = require("./__utils__/webpack");
9
- const babelConfig = require("../babel");
10
-
11
- jest.mock("../../config", () => {
12
- const original = jest.requireActual("../../config");
13
- return {
14
- ...original,
15
- includePaths: [...original.includePaths, "node_modules/included"]
16
- };
17
- });
18
-
19
- const createWebpackConfig = (file, use) => {
20
- return {
21
- entry: { file },
22
- module: {
23
- rules: [
24
- {
25
- ...babelConfig,
26
- use,
27
- },
28
- ],
29
- },
30
- output: {
31
- path: "/",
32
- filename: "scripts-bundled.js",
33
- },
34
- };
35
- };
36
-
37
- describe("babel", () => {
38
- test("process source path", async () => {
39
- const normalPath = `${app_javascript}/a.js`;
40
- const [tracked, loader] = createTrackLoader();
41
- const compiler = createTestCompiler(
42
- createWebpackConfig(normalPath, loader)
43
- );
44
- await compiler.run();
45
- expect(tracked[normalPath]).toBeTruthy();
46
- });
47
-
48
- test("exclude node_modules", async () => {
49
- const ignored = `${node_modules}/a.js`;
50
- const [tracked, loader] = createTrackLoader();
51
- const compiler = createTestCompiler(createWebpackConfig(ignored, loader));
52
- await compiler.run();
53
- expect(tracked[ignored]).toBeUndefined();
54
- });
55
-
56
- test("explicitly included node_modules should be transpiled", async () => {
57
- const included = `${node_modules_included}/a.js`;
58
- const [tracked, loader] = createTrackLoader();
59
- const compiler = createTestCompiler(createWebpackConfig(included, loader));
60
- await compiler.run();
61
- expect(tracked[included]).toBeTruthy();
62
- });
63
- });
@@ -1,64 +0,0 @@
1
- const path = require("path");
2
- const {
3
- app_javascript,
4
- node_modules,
5
- node_modules_included,
6
- createTestCompiler,
7
- createTrackLoader,
8
- } = require("./__utils__/webpack");
9
- const esbuildConfig = require("../esbuild");
10
-
11
- jest.mock("../../config", () => {
12
- const original = jest.requireActual("../../config");
13
- return {
14
- ...original,
15
- webpack_loader: "esbuild",
16
- includePaths: [...original.includePaths, "node_modules/included"]
17
- };
18
- });
19
-
20
- const createWebpackConfig = (file, use) => {
21
- return {
22
- entry: { file },
23
- module: {
24
- rules: [
25
- {
26
- ...esbuildConfig,
27
- use,
28
- },
29
- ],
30
- },
31
- output: {
32
- path: "/",
33
- filename: "scripts-bundled.js",
34
- },
35
- };
36
- };
37
-
38
- describe("swc", () => {
39
- test("process source path", async () => {
40
- const normalPath = `${app_javascript}/a.js`;
41
- const [tracked, loader] = createTrackLoader();
42
- const compiler = createTestCompiler(
43
- createWebpackConfig(normalPath, loader)
44
- );
45
- await compiler.run();
46
- expect(tracked[normalPath]).toBeTruthy();
47
- });
48
-
49
- test("exclude node_modules", async () => {
50
- const ignored = `${node_modules}/a.js`;
51
- const [tracked, loader] = createTrackLoader();
52
- const compiler = createTestCompiler(createWebpackConfig(ignored, loader));
53
- await compiler.run();
54
- expect(tracked[ignored]).toBeUndefined();
55
- });
56
-
57
- test("explicitly included node_modules should be transpiled", async () => {
58
- const included = `${node_modules_included}/a.js`;
59
- const [tracked, loader] = createTrackLoader();
60
- const compiler = createTestCompiler(createWebpackConfig(included, loader));
61
- await compiler.run();
62
- expect(tracked[included]).toBeTruthy();
63
- });
64
- });