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,27 +0,0 @@
1
- /* global test expect, describe */
2
- const { resolve } = require('path')
3
- const { chdirWebpackerTestApp, resetEnv } = require('../utils/helpers')
4
-
5
- const rootPath = process.cwd()
6
- chdirWebpackerTestApp()
7
-
8
- const config = require('../config')
9
-
10
- describe('Backward Compatibility - Config', () => {
11
- beforeEach(() => jest.resetModules() && resetEnv())
12
- afterAll(() => process.chdir(rootPath))
13
-
14
- test('x public path with asset host', () => {
15
- process.env.RAILS_ENV = 'development'
16
- process.env.WEBPACKER_ASSET_HOST = 'http://foo.com/'
17
- const config = require('../config')
18
-
19
- expect(config.publicPath).toEqual('http://foo.com/packs/')
20
- })
21
-
22
- test('x should allow overriding manifestPath', () => {
23
- process.env.WEBPACKER_CONFIG = 'config/webpacker_manifest_path.yml'
24
- const config = require('../config')
25
- expect(config.manifestPath).toEqual(resolve('app/packs/manifest.json'))
26
- })
27
- })
@@ -1,46 +0,0 @@
1
- /* global test expect, describe */
2
-
3
- const { chdirTestApp, resetEnv } = require('../utils/helpers')
4
- const { resolve } = require('path')
5
-
6
- const rootPath = process.cwd()
7
- chdirTestApp()
8
-
9
- const config = require('../config')
10
-
11
- describe('Config', () => {
12
- beforeEach(() => jest.resetModules() && resetEnv())
13
- afterAll(() => process.chdir(rootPath))
14
-
15
- test('public path', () => {
16
- process.env.RAILS_ENV = 'development'
17
- const config = require('../config')
18
- expect(config.publicPath).toEqual('/packs/')
19
- })
20
-
21
- test('public path with asset host', () => {
22
- process.env.RAILS_ENV = 'development'
23
- process.env.SHAKAPACKER_ASSET_HOST = 'http://foo.com/'
24
- const config = require('../config')
25
- expect(config.publicPath).toEqual('http://foo.com/packs/')
26
- })
27
-
28
- test('should return additional paths as listed in app config, with resolved paths', () => {
29
- expect(config.additional_paths).toEqual([
30
- 'app/assets',
31
- '/etc/yarn',
32
- 'some.config.js',
33
- 'app/elm'
34
- ])
35
- })
36
-
37
- test('should default manifestPath to the public dir', () => {
38
- expect(config.manifestPath).toEqual(resolve('public/packs/manifest.json'))
39
- })
40
-
41
- test('should allow overriding manifestPath', () => {
42
- process.env.SHAKAPACKER_CONFIG = 'config/shakapacker_manifest_path.yml'
43
- const config = require('../config')
44
- expect(config.manifestPath).toEqual(resolve('app/javascript/manifest.json'))
45
- })
46
- })
@@ -1,46 +0,0 @@
1
- /* global test expect, describe */
2
-
3
- const { chdirWebpackerTestApp } = require('../utils/helpers')
4
-
5
- const rootPath = process.cwd()
6
- chdirWebpackerTestApp()
7
-
8
- describe('Backward Compatibility - DevServer', () => {
9
- beforeEach(() => jest.resetModules())
10
- afterAll(() => process.chdir(rootPath))
11
-
12
- test('with NODE_ENV and RAILS_ENV set to development', () => {
13
- process.env.NODE_ENV = 'development'
14
- process.env.RAILS_ENV = 'development'
15
- process.env.WEBPACKER_DEV_SERVER_HOST = '0.0.0.0'
16
- process.env.WEBPACKER_DEV_SERVER_PORT = 5000
17
- process.env.WEBPACKER_DEV_SERVER_DISABLE_HOST_CHECK = false
18
-
19
- const devServer = require('../dev_server')
20
- expect(devServer).toBeDefined()
21
- expect(devServer.host).toEqual('0.0.0.0')
22
- expect(devServer.port).toEqual('5000')
23
- expect(devServer.disable_host_check).toBe(false)
24
- })
25
-
26
- test('with custom env prefix', () => {
27
- const config = require('../config')
28
- config.dev_server.env_prefix = 'TEST_WEBPACKER_DEV_SERVER'
29
-
30
- process.env.NODE_ENV = 'development'
31
- process.env.RAILS_ENV = 'development'
32
- process.env.TEST_WEBPACKER_DEV_SERVER_HOST = '0.0.0.0'
33
- process.env.TEST_WEBPACKER_DEV_SERVER_PORT = 5000
34
-
35
- const devServer = require('../dev_server')
36
- expect(devServer).toBeDefined()
37
- expect(devServer.host).toEqual('0.0.0.0')
38
- expect(devServer.port).toEqual('5000')
39
- })
40
-
41
- test('with NODE_ENV and RAILS_ENV set to production', () => {
42
- process.env.RAILS_ENV = 'production'
43
- process.env.NODE_ENV = 'production'
44
- expect(require('../dev_server')).toEqual({})
45
- })
46
- })
@@ -1,46 +0,0 @@
1
- /* global test expect, describe */
2
-
3
- const { chdirTestApp } = require('../utils/helpers')
4
-
5
- const rootPath = process.cwd()
6
- chdirTestApp()
7
-
8
- describe('DevServer', () => {
9
- beforeEach(() => jest.resetModules())
10
- afterAll(() => process.chdir(rootPath))
11
-
12
- test('with NODE_ENV and RAILS_ENV set to development', () => {
13
- process.env.NODE_ENV = 'development'
14
- process.env.RAILS_ENV = 'development'
15
- process.env.SHAKAPACKER_DEV_SERVER_HOST = '0.0.0.0'
16
- process.env.SHAKAPACKER_DEV_SERVER_PORT = 5000
17
- process.env.SHAKAPACKER_DEV_SERVER_DISABLE_HOST_CHECK = false
18
-
19
- const devServer = require('../dev_server')
20
- expect(devServer).toBeDefined()
21
- expect(devServer.host).toEqual('0.0.0.0')
22
- expect(devServer.port).toEqual('5000')
23
- expect(devServer.disable_host_check).toBe(false)
24
- })
25
-
26
- test('with custom env prefix', () => {
27
- const config = require('../config')
28
- config.dev_server.env_prefix = 'TEST_SHAKAPACKER_DEV_SERVER'
29
-
30
- process.env.NODE_ENV = 'development'
31
- process.env.RAILS_ENV = 'development'
32
- process.env.TEST_SHAKAPACKER_DEV_SERVER_HOST = '0.0.0.0'
33
- process.env.TEST_SHAKAPACKER_DEV_SERVER_PORT = 5000
34
-
35
- const devServer = require('../dev_server')
36
- expect(devServer).toBeDefined()
37
- expect(devServer.host).toEqual('0.0.0.0')
38
- expect(devServer.port).toEqual('5000')
39
- })
40
-
41
- test('with NODE_ENV and RAILS_ENV set to production', () => {
42
- process.env.RAILS_ENV = 'production'
43
- process.env.NODE_ENV = 'production'
44
- expect(require('../dev_server')).toEqual({})
45
- })
46
- })
@@ -1,66 +0,0 @@
1
- /* test expect, describe, afterAll, beforeEach */
2
-
3
- const { resolve } = require('path')
4
- const { chdirWebpackerTestApp, resetEnv } = require('../utils/helpers')
5
-
6
- const rootPath = process.cwd()
7
- chdirWebpackerTestApp()
8
-
9
- describe('Backward Compatibility - Development environment', () => {
10
- beforeEach(() => jest.resetModules() && resetEnv())
11
- afterAll(() => process.chdir(rootPath))
12
-
13
- describe('generateWebpackConfig', () => {
14
- beforeEach(() => jest.resetModules())
15
-
16
- test('should use development config and environment including devServer if WEBPACK_SERVE', () => {
17
- process.env.RAILS_ENV = 'development'
18
- process.env.NODE_ENV = 'development'
19
- process.env.WEBPACK_SERVE = 'true'
20
- const { generateWebpackConfig } = require('../index')
21
-
22
- const webpackConfig = generateWebpackConfig()
23
-
24
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
25
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
26
- })
27
-
28
- test('should use development config and environment if WEBPACK_SERVE', () => {
29
- process.env.RAILS_ENV = 'development'
30
- process.env.NODE_ENV = 'development'
31
- process.env.WEBPACK_SERVE = undefined
32
- const { generateWebpackConfig } = require('../index')
33
-
34
- const webpackConfig = generateWebpackConfig()
35
-
36
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
37
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
38
- expect(webpackConfig.devServer).toEqual(undefined)
39
- })
40
- })
41
-
42
- describe('globalMutableWebpackConfig', () => {
43
- beforeEach(() => jest.resetModules())
44
-
45
- test('should use development config and environment including devServer if WEBPACK_SERVE', () => {
46
- process.env.RAILS_ENV = 'development'
47
- process.env.NODE_ENV = 'development'
48
- process.env.WEBPACK_SERVE = 'true'
49
- const { globalMutableWebpackConfig: webpackConfig } = require('../index')
50
-
51
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
52
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
53
- })
54
-
55
- test('should use development config and environment if WEBPACK_SERVE', () => {
56
- process.env.RAILS_ENV = 'development'
57
- process.env.NODE_ENV = 'development'
58
- process.env.WEBPACK_SERVE = undefined
59
- const { globalMutableWebpackConfig: webpackConfig } = require('../index')
60
-
61
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
62
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
63
- expect(webpackConfig.devServer).toEqual(undefined)
64
- })
65
- })
66
- })
@@ -1,66 +0,0 @@
1
- /* test expect, describe, afterAll, beforeEach */
2
-
3
- const { resolve } = require('path')
4
- const { chdirTestApp, resetEnv } = require('../utils/helpers')
5
-
6
- const rootPath = process.cwd()
7
- chdirTestApp()
8
-
9
- describe('Development environment', () => {
10
- beforeEach(() => jest.resetModules() && resetEnv())
11
- afterAll(() => process.chdir(rootPath))
12
-
13
- describe('generateWebpackConfig', () => {
14
- beforeEach(() => jest.resetModules())
15
-
16
- test('should use development config and environment including devServer if WEBPACK_SERVE', () => {
17
- process.env.RAILS_ENV = 'development'
18
- process.env.NODE_ENV = 'development'
19
- process.env.WEBPACK_SERVE = 'true'
20
- const { generateWebpackConfig } = require('../index')
21
-
22
- const webpackConfig = generateWebpackConfig()
23
-
24
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
25
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
26
- })
27
-
28
- test('should use development config and environment if WEBPACK_SERVE', () => {
29
- process.env.RAILS_ENV = 'development'
30
- process.env.NODE_ENV = 'development'
31
- process.env.WEBPACK_SERVE = undefined
32
- const { generateWebpackConfig } = require('../index')
33
-
34
- const webpackConfig = generateWebpackConfig()
35
-
36
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
37
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
38
- expect(webpackConfig.devServer).toEqual(undefined)
39
- })
40
- })
41
-
42
- describe('globalMutableWebpackConfig', () => {
43
- beforeEach(() => jest.resetModules())
44
-
45
- test('should use development config and environment including devServer if WEBPACK_SERVE', () => {
46
- process.env.RAILS_ENV = 'development'
47
- process.env.NODE_ENV = 'development'
48
- process.env.WEBPACK_SERVE = 'true'
49
- const { globalMutableWebpackConfig: webpackConfig } = require('../index')
50
-
51
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
52
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
53
- })
54
-
55
- test('should use development config and environment if WEBPACK_SERVE', () => {
56
- process.env.RAILS_ENV = 'development'
57
- process.env.NODE_ENV = 'development'
58
- process.env.WEBPACK_SERVE = undefined
59
- const { globalMutableWebpackConfig: webpackConfig } = require('../index')
60
-
61
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
62
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
63
- expect(webpackConfig.devServer).toEqual(undefined)
64
- })
65
- })
66
- })
@@ -1,59 +0,0 @@
1
- /* global test expect, describe */
2
-
3
- const { chdirWebpackerTestApp, resetEnv } = require('../utils/helpers')
4
-
5
- const rootPath = process.cwd()
6
- chdirWebpackerTestApp()
7
-
8
- describe('Backward Compatibility - Env', () => {
9
- beforeEach(() => jest.resetModules() && resetEnv())
10
- afterAll(() => process.chdir(rootPath))
11
-
12
- test('with NODE_ENV and RAILS_ENV set to development', () => {
13
- process.env.RAILS_ENV = 'development'
14
- process.env.NODE_ENV = 'development'
15
- expect(require('../env')).toEqual({
16
- railsEnv: 'development',
17
- nodeEnv: 'development',
18
- isProduction: false,
19
- isDevelopment: true,
20
- runningWebpackDevServer: false
21
- })
22
- })
23
-
24
- test('with undefined NODE_ENV and RAILS_ENV set to development', () => {
25
- process.env.RAILS_ENV = 'development'
26
- delete process.env.NODE_ENV
27
- expect(require('../env')).toEqual({
28
- railsEnv: 'development',
29
- nodeEnv: 'production',
30
- isProduction: true,
31
- isDevelopment: false,
32
- runningWebpackDevServer: false
33
- })
34
- })
35
-
36
- test('with undefined NODE_ENV and RAILS_ENV', () => {
37
- delete process.env.NODE_ENV
38
- delete process.env.RAILS_ENV
39
- expect(require('../env')).toEqual({
40
- railsEnv: 'production',
41
- nodeEnv: 'production',
42
- isProduction: true,
43
- isDevelopment: false,
44
- runningWebpackDevServer: false
45
- })
46
- })
47
-
48
- test('with a non-standard environment', () => {
49
- process.env.RAILS_ENV = 'staging'
50
- process.env.NODE_ENV = 'staging'
51
- expect(require('../env')).toEqual({
52
- railsEnv: 'staging',
53
- nodeEnv: 'production',
54
- isProduction: true,
55
- isDevelopment: false,
56
- runningWebpackDevServer: false
57
- })
58
- })
59
- })
@@ -1,59 +0,0 @@
1
- /* global test expect, describe */
2
-
3
- const { chdirTestApp } = require('../utils/helpers')
4
-
5
- const rootPath = process.cwd()
6
- chdirTestApp()
7
-
8
- describe('Env', () => {
9
- beforeEach(() => jest.resetModules())
10
- afterAll(() => process.chdir(rootPath))
11
-
12
- test('with NODE_ENV and RAILS_ENV set to development', () => {
13
- process.env.RAILS_ENV = 'development'
14
- process.env.NODE_ENV = 'development'
15
- expect(require('../env')).toEqual({
16
- railsEnv: 'development',
17
- nodeEnv: 'development',
18
- isProduction: false,
19
- isDevelopment: true,
20
- runningWebpackDevServer: false
21
- })
22
- })
23
-
24
- test('with undefined NODE_ENV and RAILS_ENV set to development', () => {
25
- process.env.RAILS_ENV = 'development'
26
- delete process.env.NODE_ENV
27
- expect(require('../env')).toEqual({
28
- railsEnv: 'development',
29
- nodeEnv: 'production',
30
- isProduction: true,
31
- isDevelopment: false,
32
- runningWebpackDevServer: false
33
- })
34
- })
35
-
36
- test('with undefined NODE_ENV and RAILS_ENV', () => {
37
- delete process.env.NODE_ENV
38
- delete process.env.RAILS_ENV
39
- expect(require('../env')).toEqual({
40
- railsEnv: 'production',
41
- nodeEnv: 'production',
42
- isProduction: true,
43
- isDevelopment: false,
44
- runningWebpackDevServer: false
45
- })
46
- })
47
-
48
- test('with a non-standard environment', () => {
49
- process.env.RAILS_ENV = 'staging'
50
- process.env.NODE_ENV = 'staging'
51
- expect(require('../env')).toEqual({
52
- railsEnv: 'staging',
53
- nodeEnv: 'production',
54
- isProduction: true,
55
- isDevelopment: false,
56
- runningWebpackDevServer: false
57
- })
58
- })
59
- })
@@ -1,22 +0,0 @@
1
- const index = require('../index')
2
-
3
- describe('index', () => {
4
- describe('webpackConfig', () => {
5
- test('is a global object', () => {
6
- const { webpackConfig, globalMutableWebpackConfig } = require('../index')
7
-
8
- expect(webpackConfig).toBe(globalMutableWebpackConfig)
9
- })
10
-
11
- test('Shows warning with deprecation message', () => {
12
- const consoleSpy = jest.spyOn(console, "warn");
13
-
14
- const { webpackConfig } = require('../index')
15
-
16
- expect(consoleSpy).toHaveBeenCalledWith(
17
- expect.stringMatching(/The 'webpackConfig' is deprecated/)
18
- )
19
- consoleSpy.mockRestore();
20
- })
21
- })
22
- })
@@ -1,46 +0,0 @@
1
- const index = require('../index')
2
- const { generateWebpackConfig } = require("../index");
3
-
4
- describe('index', () => {
5
- test('exports webpack-merge v5 functions', () => {
6
- expect(index.merge).toBeInstanceOf(Function)
7
- expect(index.mergeWithRules).toBeInstanceOf(Function)
8
- expect(index.mergeWithCustomize).toBeInstanceOf(Function)
9
- })
10
-
11
- test('webpackConfig returns an immutable object', () => {
12
- const { generateWebpackConfig } = require('../index')
13
-
14
- const webpackConfig1 = generateWebpackConfig()
15
- const webpackConfig2 = generateWebpackConfig()
16
-
17
- webpackConfig1.newKey = 'new value'
18
- webpackConfig1.output.path = 'new path'
19
-
20
- expect(webpackConfig2).not.toHaveProperty('newKey')
21
- expect(webpackConfig2.output.path).not.toEqual('new value')
22
- })
23
-
24
- test('webpackConfig merges extra config', () => {
25
- const { generateWebpackConfig } = require('../index')
26
-
27
- const webpackConfig = generateWebpackConfig({
28
- newKey: 'new value',
29
- output: {
30
- path: 'new path'
31
- }
32
- })
33
-
34
- expect(webpackConfig).toHaveProperty('newKey', 'new value')
35
- expect(webpackConfig).toHaveProperty('output.path', 'new path')
36
- expect(webpackConfig).toHaveProperty('output.publicPath', '/packs/')
37
- })
38
-
39
- test('webpackConfig errors if multiple configs are provided', () => {
40
- const { generateWebpackConfig } = require('../index')
41
-
42
- expect(() => generateWebpackConfig({}, {})).toThrow(
43
- 'use webpack-merge to merge configs before passing them to Shakapacker'
44
- )
45
- })
46
- })
@@ -1,51 +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 - Production environment', () => {
10
- afterAll(() => process.chdir(rootPath))
11
-
12
- describe('generateWebpackConfig', () => {
13
- beforeEach(() => jest.resetModules())
14
-
15
- test('should use production config and environment', () => {
16
- process.env.RAILS_ENV = 'production'
17
- process.env.NODE_ENV = 'production'
18
-
19
- const { generateWebpackConfig } = require('../index')
20
-
21
- const webpackConfig = generateWebpackConfig()
22
-
23
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
24
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
25
-
26
- expect(webpackConfig).toMatchObject({
27
- devtool: 'source-map',
28
- stats: 'normal'
29
- })
30
- })
31
- })
32
-
33
- describe('globalMutableWebpackConfig', () => {
34
- beforeEach(() => jest.resetModules())
35
-
36
- test('should use production config and environment', () => {
37
- process.env.RAILS_ENV = 'production'
38
- process.env.NODE_ENV = 'production'
39
-
40
- const { globalMutableWebpackConfig: webpackConfig } = require('../index')
41
-
42
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
43
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
44
-
45
- expect(webpackConfig).toMatchObject({
46
- devtool: 'source-map',
47
- stats: 'normal'
48
- })
49
- })
50
- })
51
- })
@@ -1,51 +0,0 @@
1
- /* test expect, describe, afterAll, beforeEach */
2
-
3
- const { resolve } = require('path')
4
- const { chdirTestApp, chdirCwd } = require('../utils/helpers')
5
-
6
- const rootPath = process.cwd()
7
- chdirTestApp()
8
-
9
- describe('Production environment', () => {
10
- afterAll(() => process.chdir(rootPath))
11
-
12
- describe('generateWebpackConfig', () => {
13
- beforeEach(() => jest.resetModules())
14
-
15
- test('should use production config and environment', () => {
16
- process.env.RAILS_ENV = 'production'
17
- process.env.NODE_ENV = 'production'
18
-
19
- const { generateWebpackConfig } = require('../index')
20
-
21
- const webpackConfig = generateWebpackConfig()
22
-
23
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
24
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
25
-
26
- expect(webpackConfig).toMatchObject({
27
- devtool: 'source-map',
28
- stats: 'normal'
29
- })
30
- })
31
- })
32
-
33
- describe('globalMutableWebpackConfig', () => {
34
- beforeEach(() => jest.resetModules())
35
-
36
- test('should use production config and environment', () => {
37
- process.env.RAILS_ENV = 'production'
38
- process.env.NODE_ENV = 'production'
39
-
40
- const { globalMutableWebpackConfig: webpackConfig } = require('../index')
41
-
42
- expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
43
- expect(webpackConfig.output.publicPath).toEqual('/packs/')
44
-
45
- expect(webpackConfig).toMatchObject({
46
- devtool: 'source-map',
47
- stats: 'normal'
48
- })
49
- })
50
- })
51
- })
@@ -1,53 +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 - 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
- })