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
@@ -0,0 +1,32 @@
1
+ const { resolve } = require("path")
2
+ const { chdirTestApp } = require("../helpers")
3
+
4
+ const rootPath = process.cwd()
5
+ chdirTestApp()
6
+
7
+ describe("Production environment", () => {
8
+ afterAll(() => process.chdir(rootPath))
9
+
10
+ describe("generateWebpackConfig", () => {
11
+ beforeEach(() => jest.resetModules())
12
+
13
+ test("should use production config and environment", () => {
14
+ process.env.RAILS_ENV = "production"
15
+ process.env.NODE_ENV = "production"
16
+
17
+ const { generateWebpackConfig } = require("../../package/index")
18
+
19
+ const webpackConfig = generateWebpackConfig()
20
+
21
+ expect(webpackConfig.output.path).toStrictEqual(
22
+ resolve("public", "packs")
23
+ )
24
+ expect(webpackConfig.output.publicPath).toBe("/packs/")
25
+
26
+ expect(webpackConfig).toMatchObject({
27
+ devtool: "source-map",
28
+ stats: "normal"
29
+ })
30
+ })
31
+ })
32
+ })
@@ -0,0 +1,58 @@
1
+ const {
2
+ pathToAppJavascript,
3
+ pathToNodeModules,
4
+ pathToNodeModulesIncluded,
5
+ createTestCompiler,
6
+ createTrackLoader
7
+ } = require("../../helpers")
8
+ const babelConfig = require("../../../package/rules/babel")
9
+
10
+ jest.mock("../../../package/config", () => {
11
+ const original = jest.requireActual("../../../package/config")
12
+ return {
13
+ ...original,
14
+ additional_paths: [...original.additional_paths, "node_modules/included"]
15
+ }
16
+ })
17
+
18
+ const createWebpackConfig = (file, use) => ({
19
+ entry: { file },
20
+ module: {
21
+ rules: [
22
+ {
23
+ ...babelConfig,
24
+ use
25
+ }
26
+ ]
27
+ },
28
+ output: {
29
+ path: "/",
30
+ filename: "scripts-bundled.js"
31
+ }
32
+ })
33
+
34
+ describe("babel", () => {
35
+ test("process source path", async () => {
36
+ const normalPath = `${pathToAppJavascript}/a.js`
37
+ const [tracked, loader] = createTrackLoader()
38
+ const compiler = createTestCompiler(createWebpackConfig(normalPath, loader))
39
+ await compiler.run()
40
+ expect(tracked[normalPath]).toBeTruthy()
41
+ })
42
+
43
+ test("exclude node_modules", async () => {
44
+ const ignored = `${pathToNodeModules}/a.js`
45
+ const [tracked, loader] = createTrackLoader()
46
+ const compiler = createTestCompiler(createWebpackConfig(ignored, loader))
47
+ await compiler.run()
48
+ expect(tracked[ignored]).toBeUndefined()
49
+ })
50
+
51
+ test("explicitly included node_modules should be transpiled", async () => {
52
+ const included = `${pathToNodeModulesIncluded}/a.js`
53
+ const [tracked, loader] = createTrackLoader()
54
+ const compiler = createTestCompiler(createWebpackConfig(included, loader))
55
+ await compiler.run()
56
+ expect(tracked[included]).toBeTruthy()
57
+ })
58
+ })
@@ -0,0 +1,59 @@
1
+ const {
2
+ pathToAppJavascript,
3
+ pathToNodeModules,
4
+ pathToNodeModulesIncluded,
5
+ createTestCompiler,
6
+ createTrackLoader
7
+ } = require("../../helpers")
8
+ const esbuildConfig = require("../../../package/rules/esbuild")
9
+
10
+ jest.mock("../../../package/config", () => {
11
+ const original = jest.requireActual("../../../package/config")
12
+ return {
13
+ ...original,
14
+ webpack_loader: "esbuild",
15
+ additional_paths: [...original.additional_paths, "node_modules/included"]
16
+ }
17
+ })
18
+
19
+ const createWebpackConfig = (file, use) => ({
20
+ entry: { file },
21
+ module: {
22
+ rules: [
23
+ {
24
+ ...esbuildConfig,
25
+ use
26
+ }
27
+ ]
28
+ },
29
+ output: {
30
+ path: "/",
31
+ filename: "scripts-bundled.js"
32
+ }
33
+ })
34
+
35
+ describe("swc", () => {
36
+ test("process source path", async () => {
37
+ const normalPath = `${pathToAppJavascript}/a.js`
38
+ const [tracked, loader] = createTrackLoader()
39
+ const compiler = createTestCompiler(createWebpackConfig(normalPath, loader))
40
+ await compiler.run()
41
+ expect(tracked[normalPath]).toBeTruthy()
42
+ })
43
+
44
+ test("exclude node_modules", async () => {
45
+ const ignored = `${pathToNodeModules}/a.js`
46
+ const [tracked, loader] = createTrackLoader()
47
+ const compiler = createTestCompiler(createWebpackConfig(ignored, loader))
48
+ await compiler.run()
49
+ expect(tracked[ignored]).toBeUndefined()
50
+ })
51
+
52
+ test("explicitly included node_modules should be transpiled", async () => {
53
+ const included = `${pathToNodeModulesIncluded}/a.js`
54
+ const [tracked, loader] = createTrackLoader()
55
+ const compiler = createTestCompiler(createWebpackConfig(included, loader))
56
+ await compiler.run()
57
+ expect(tracked[included]).toBeTruthy()
58
+ })
59
+ })
@@ -0,0 +1,81 @@
1
+ const file = require("../../../package/rules/file")
2
+
3
+ jest.mock("../../../package/config", () => {
4
+ const original = jest.requireActual("../../../package/config")
5
+ return {
6
+ ...original,
7
+ additional_paths: [...original.additional_paths, "app/assets"]
8
+ }
9
+ })
10
+
11
+ describe("file", () => {
12
+ test("expected file types", () => {
13
+ const types = [
14
+ ".bmp",
15
+ ".gif",
16
+ ".jpg",
17
+ ".jpeg",
18
+ ".png",
19
+ ".tiff",
20
+ ".ico",
21
+ ".avif",
22
+ ".webp",
23
+ ".eot",
24
+ ".otf",
25
+ ".ttf",
26
+ ".woff",
27
+ ".woff2",
28
+ ".svg"
29
+ ]
30
+ types.forEach((type) => expect(file.test.test(type)).toBe(true))
31
+ })
32
+
33
+ test("exclude expected file types", () => {
34
+ const types = [".js", ".mjs", ".jsx", ".ts", ".tsx"]
35
+ types.forEach((type) => expect(file.exclude.test(type)).toBe(true))
36
+ })
37
+
38
+ test("correct generated output path is returned for top level files", () => {
39
+ const pathData = {
40
+ filename: "app/javascript/image.svg"
41
+ }
42
+ expect(file.generator.filename(pathData)).toBe(
43
+ "static/[name]-[hash][ext][query]"
44
+ )
45
+ })
46
+
47
+ test("correct generated output path is returned for nested files", () => {
48
+ const pathData = {
49
+ filename: "app/javascript/images/image.svg"
50
+ }
51
+ expect(file.generator.filename(pathData)).toBe(
52
+ "static/images/[name]-[hash][ext][query]"
53
+ )
54
+ })
55
+
56
+ test("correct generated output path is returned for deeply nested files", () => {
57
+ const pathData = {
58
+ filename: "app/javascript/images/nested/deeply/image.svg"
59
+ }
60
+ expect(file.generator.filename(pathData)).toBe(
61
+ "static/images/nested/deeply/[name]-[hash][ext][query]"
62
+ )
63
+ })
64
+
65
+ test("correct generated output path is returned for additional_paths", () => {
66
+ const pathData = {
67
+ filename: "app/assets/images/image.svg"
68
+ }
69
+
70
+ expect(file.generator.filename(pathData)).toBe(
71
+ "static/images/[name]-[hash][ext][query]"
72
+ )
73
+
74
+ const pathData2 = {
75
+ filename: "app/javascript/app/assets/image.svg"
76
+ }
77
+ expect(file.generator.filename(pathData2)).toBe(
78
+ "static/app/assets/[name]-[hash][ext][query]"
79
+ )
80
+ })
81
+ })
@@ -0,0 +1,7 @@
1
+ const rules = require("../../../package/rules/index")
2
+
3
+ describe("index", () => {
4
+ test("rule tests are regexes", () => {
5
+ rules.forEach((rule) => expect(rule.test instanceof RegExp).toBe(true))
6
+ })
7
+ })
@@ -0,0 +1,12 @@
1
+ const raw = require("../../../package/rules/raw")
2
+
3
+ describe("raw", () => {
4
+ test("expected file types", () => {
5
+ expect(raw.test.test(".html")).toBe(true)
6
+ })
7
+
8
+ test("exclude expected file types", () => {
9
+ const types = [".js", ".mjs", ".jsx", ".ts", ".tsx"]
10
+ types.forEach((type) => expect(raw.exclude.test(type)).toBe(true))
11
+ })
12
+ })
@@ -0,0 +1,59 @@
1
+ const {
2
+ pathToAppJavascript,
3
+ pathToNodeModules,
4
+ pathToNodeModulesIncluded,
5
+ createTestCompiler,
6
+ createTrackLoader
7
+ } = require("../../helpers")
8
+ const swcConfig = require("../../../package/rules/swc")
9
+
10
+ jest.mock("../../../package/config", () => {
11
+ const original = jest.requireActual("../../../package/config")
12
+ return {
13
+ ...original,
14
+ webpack_loader: "swc",
15
+ additional_paths: [...original.additional_paths, "node_modules/included"]
16
+ }
17
+ })
18
+
19
+ const createWebpackConfig = (file, use) => ({
20
+ entry: { file },
21
+ module: {
22
+ rules: [
23
+ {
24
+ ...swcConfig,
25
+ use
26
+ }
27
+ ]
28
+ },
29
+ output: {
30
+ path: "/",
31
+ filename: "scripts-bundled.js"
32
+ }
33
+ })
34
+
35
+ describe("swc", () => {
36
+ test("process files in source_path", async () => {
37
+ const normalPath = `${pathToAppJavascript}/a.js`
38
+ const [tracked, loader] = createTrackLoader()
39
+ const compiler = createTestCompiler(createWebpackConfig(normalPath, loader))
40
+ await compiler.run()
41
+ expect(tracked[normalPath]).toBeTruthy()
42
+ })
43
+
44
+ test("exclude node_modules", async () => {
45
+ const ignored = `${pathToNodeModules}/a.js`
46
+ const [tracked, loader] = createTrackLoader()
47
+ const compiler = createTestCompiler(createWebpackConfig(ignored, loader))
48
+ await compiler.run()
49
+ expect(tracked[ignored]).toBeUndefined()
50
+ })
51
+
52
+ test("explicitly included node_modules should be transpiled", async () => {
53
+ const included = `${pathToNodeModulesIncluded}/a.js`
54
+ const [tracked, loader] = createTrackLoader()
55
+ const compiler = createTestCompiler(createWebpackConfig(included, loader))
56
+ await compiler.run()
57
+ expect(tracked[included]).toBeTruthy()
58
+ })
59
+ })
@@ -0,0 +1,31 @@
1
+ const { resolve } = require("path")
2
+ const { chdirTestApp } = require("../helpers")
3
+
4
+ const rootPath = process.cwd()
5
+ chdirTestApp()
6
+
7
+ describe("Custom environment", () => {
8
+ afterAll(() => process.chdir(rootPath))
9
+
10
+ describe("generateWebpackConfig", () => {
11
+ beforeEach(() => jest.resetModules())
12
+
13
+ test("should use staging config and default production environment", () => {
14
+ process.env.RAILS_ENV = "staging"
15
+ delete process.env.NODE_ENV
16
+
17
+ const { generateWebpackConfig } = require("../../package/index")
18
+
19
+ const webpackConfig = generateWebpackConfig()
20
+
21
+ expect(webpackConfig.output.path).toStrictEqual(
22
+ resolve("public", "packs-staging")
23
+ )
24
+ expect(webpackConfig.output.publicPath).toBe("/packs-staging/")
25
+ expect(webpackConfig).toMatchObject({
26
+ devtool: "source-map",
27
+ stats: "normal"
28
+ })
29
+ })
30
+ })
31
+ })
@@ -0,0 +1,28 @@
1
+ const { resolve } = require("path")
2
+ const { chdirTestApp } = require("../helpers")
3
+
4
+ const rootPath = process.cwd()
5
+ chdirTestApp()
6
+
7
+ describe("Test environment", () => {
8
+ afterAll(() => process.chdir(rootPath))
9
+
10
+ describe("generateWebpackConfig", () => {
11
+ beforeEach(() => jest.resetModules())
12
+
13
+ test("should use test config and production environment", () => {
14
+ process.env.RAILS_ENV = "test"
15
+ process.env.NODE_ENV = "test"
16
+
17
+ const { generateWebpackConfig } = require("../../package/index")
18
+
19
+ const webpackConfig = generateWebpackConfig()
20
+
21
+ expect(webpackConfig.output.path).toStrictEqual(
22
+ resolve("public", "packs-test")
23
+ )
24
+ expect(webpackConfig.output.publicPath).toBe("/packs-test/")
25
+ expect(webpackConfig.devServer).toBeUndefined()
26
+ })
27
+ })
28
+ })