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,22 +1,22 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
- const { resolve } = require('path')
5
- const { existsSync } = require('fs')
6
- const { merge } = require('webpack-merge')
4
+ const { resolve } = require("path")
5
+ const { existsSync } = require("fs")
6
+ const { merge } = require("webpack-merge")
7
7
 
8
8
  const getLoaderExtension = (filename) => {
9
9
  const matchData = filename.match(/\.([jt]sx?)?(\.erb)?$/)
10
10
 
11
11
  if (!matchData) {
12
- return 'js'
12
+ return "js"
13
13
  }
14
14
 
15
15
  return matchData[1]
16
16
  }
17
17
 
18
18
  const getCustomConfig = () => {
19
- const path = resolve('config', 'esbuild.config.js')
19
+ const path = resolve("config", "esbuild.config.js")
20
20
  if (existsSync(path)) {
21
21
  return require(path)
22
22
  }
@@ -26,7 +26,7 @@ const getCustomConfig = () => {
26
26
  const getEsbuildLoaderConfig = (filenameToProcess) => {
27
27
  const customConfig = getCustomConfig()
28
28
  const defaultConfig = {
29
- loader: require.resolve('esbuild-loader'),
29
+ loader: require.resolve("esbuild-loader"),
30
30
  options: {
31
31
  loader: getLoaderExtension(filenameToProcess)
32
32
  }
data/package/index.d.ts CHANGED
@@ -22,7 +22,6 @@ declare module 'shakapacker' {
22
22
  publicPath: string
23
23
  publicPathWithoutCDN: string
24
24
  manifestPath: string
25
- includePaths: string[]
26
25
  }
27
26
 
28
27
  export interface Env {
@@ -36,7 +35,6 @@ declare module 'shakapacker' {
36
35
  export const config: Config
37
36
  export const devServer: Record<string, unknown>
38
37
  export function generateWebpackConfig(extraConfig?: Configuration): Configuration
39
- export const globalMutableWebpackConfig: Configuration
40
38
  export const baseConfig: Configuration
41
39
  export const env: Env
42
40
  export const rules: Record<string, unknown>
data/package/index.js CHANGED
@@ -1,41 +1,35 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
- const webpackMerge = require('webpack-merge')
5
- const { resolve } = require('path')
6
- const { existsSync } = require('fs')
7
- const baseConfig = require('./environments/base')
8
- const rules = require('./rules')
9
- const config = require('./config')
10
- const devServer = require('./dev_server')
11
- const env = require('./env')
12
- const { moduleExists, canProcess } = require('./utils/helpers')
13
- const inliningCss = require('./utils/inliningCss')
14
-
15
- const globalMutableWebpackConfig = () => {
16
- const { nodeEnv } = env
17
- const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
18
- const environmentConfig = existsSync(path) ? require(path) : baseConfig
19
- return environmentConfig
20
- }
4
+ const webpackMerge = require("webpack-merge")
5
+ const { resolve } = require("path")
6
+ const { existsSync } = require("fs")
7
+ const baseConfig = require("./environments/base")
8
+ const rules = require("./rules")
9
+ const config = require("./config")
10
+ const devServer = require("./dev_server")
11
+ const env = require("./env")
12
+ const { moduleExists, canProcess } = require("./utils/helpers")
13
+ const inliningCss = require("./utils/inliningCss")
21
14
 
22
15
  const generateWebpackConfig = (extraConfig = {}, ...extraArgs) => {
23
16
  if (extraArgs.length > 0) {
24
17
  throw new Error(
25
- 'Only one extra config may be passed here - use webpack-merge to merge configs before passing them to Shakapacker'
18
+ "Only one extra config may be passed here - use webpack-merge to merge configs before passing them to Shakapacker"
26
19
  )
27
20
  }
28
21
 
29
- const environmentConfig = globalMutableWebpackConfig()
30
- const immutable = webpackMerge.merge({}, environmentConfig, extraConfig)
31
- return immutable
22
+ const { nodeEnv } = env
23
+ const path = resolve(__dirname, "environments", `${nodeEnv}.js`)
24
+ const environmentConfig = existsSync(path) ? require(path) : baseConfig
25
+
26
+ return webpackMerge.merge({}, environmentConfig, extraConfig)
32
27
  }
33
28
 
34
- const shakapackerObject = {
29
+ module.exports = {
35
30
  config, // shakapacker.yml
36
31
  devServer,
37
32
  generateWebpackConfig,
38
- globalMutableWebpackConfig: globalMutableWebpackConfig(),
39
33
  baseConfig,
40
34
  env,
41
35
  rules,
@@ -44,26 +38,3 @@ const shakapackerObject = {
44
38
  inliningCss,
45
39
  ...webpackMerge
46
40
  }
47
-
48
- // For backward compatibility
49
- const shakapackerProxyHandler = {
50
- get(target, prop) {
51
- if (prop === 'webpackConfig') {
52
- // eslint-disable-next-line no-console
53
- console.warn(`⚠️
54
- DEPRECATION NOTICE:
55
- The 'webpackConfig' is deprecated and will be removed in a future version.
56
- Please use 'globalMutableWebpackConfig' instead, or use
57
- 'generateWebpackConfig()' to avoid unwanted config mutation across the app.
58
-
59
- For more information, see version 7 upgrade documentation at:
60
- https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md
61
- `)
62
- return globalMutableWebpackConfig()
63
- }
64
-
65
- return target[prop]
66
- }
67
- }
68
-
69
- module.exports = new Proxy(shakapackerObject, shakapackerProxyHandler)
@@ -1,16 +1,14 @@
1
- const { loaderMatches } = require('../utils/helpers')
2
- const {
3
- webpack_loader: webpackLoader
4
- } = require('../config')
5
- const { isProduction } = require('../env')
6
- const jscommon = require('./jscommon')
1
+ const { loaderMatches } = require("../utils/helpers")
2
+ const { webpack_loader: webpackLoader } = require("../config")
3
+ const { isProduction } = require("../env")
4
+ const jscommon = require("./jscommon")
7
5
 
8
- module.exports = loaderMatches(webpackLoader, 'babel', () => ({
6
+ module.exports = loaderMatches(webpackLoader, "babel", () => ({
9
7
  test: /\.(js|jsx|mjs|ts|tsx|coffee)?(\.erb)?$/,
10
8
  ...jscommon,
11
9
  use: [
12
10
  {
13
- loader: require.resolve('babel-loader'),
11
+ loader: require.resolve("babel-loader"),
14
12
  options: {
15
13
  cacheDirectory: true,
16
14
  cacheCompression: isProduction,
@@ -1,6 +1,6 @@
1
- const { canProcess } = require('../utils/helpers')
1
+ const { canProcess } = require("../utils/helpers")
2
2
 
3
- module.exports = canProcess('coffee-loader', (resolvedPath) => ({
3
+ module.exports = canProcess("coffee-loader", (resolvedPath) => ({
4
4
  test: /\.coffee(\.erb)?$/,
5
5
  use: [{ loader: resolvedPath }]
6
6
  }))
data/package/rules/css.js CHANGED
@@ -1,3 +1,3 @@
1
- const getStyleRule = require('../utils/get_style_rule')
1
+ const getStyleRule = require("../utils/getStyleRule")
2
2
 
3
3
  module.exports = getStyleRule(/\.(css)$/i)
data/package/rules/erb.js CHANGED
@@ -1,10 +1,10 @@
1
- const { canProcess } = require('../utils/helpers')
1
+ const { canProcess } = require("../utils/helpers")
2
2
 
3
- const runner = /^win/.test(process.platform) ? 'ruby ' : ''
3
+ const runner = /^win/.test(process.platform) ? "ruby " : ""
4
4
 
5
- module.exports = canProcess('rails-erb-loader', (resolvedPath) => ({
5
+ module.exports = canProcess("rails-erb-loader", (resolvedPath) => ({
6
6
  test: /\.erb$/,
7
- enforce: 'pre',
7
+ enforce: "pre",
8
8
  exclude: /node_modules/,
9
9
  use: [
10
10
  {
@@ -1,11 +1,9 @@
1
- const { loaderMatches } = require('../utils/helpers')
2
- const { getEsbuildLoaderConfig } = require('../esbuild')
3
- const {
4
- webpack_loader: webpackLoader
5
- } = require('../config')
6
- const jscommon = require('./jscommon')
1
+ const { loaderMatches } = require("../utils/helpers")
2
+ const { getEsbuildLoaderConfig } = require("../esbuild")
3
+ const { webpack_loader: webpackLoader } = require("../config")
4
+ const jscommon = require("./jscommon")
7
5
 
8
- module.exports = loaderMatches(webpackLoader, 'esbuild', () => ({
6
+ module.exports = loaderMatches(webpackLoader, "esbuild", () => ({
9
7
  test: /\.(ts|tsx|js|jsx|mjs|coffee)?(\.erb)?$/,
10
8
  ...jscommon,
11
9
  use: ({ resource }) => getEsbuildLoaderConfig(resource)
@@ -1,21 +1,28 @@
1
- const { dirname } = require('path')
2
- const { includePaths } = require('../config')
1
+ const { dirname } = require("path")
2
+ const {
3
+ additional_paths: additionalPaths,
4
+ source_path: sourcePath
5
+ } = require("../config")
3
6
 
4
7
  module.exports = {
5
8
  test: /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2|svg)$/,
6
9
  exclude: /\.(js|mjs|jsx|ts|tsx)$/,
7
- type: 'asset/resource',
10
+ type: "asset/resource",
8
11
  generator: {
9
12
  filename: (pathData) => {
10
13
  const path = dirname(pathData.filename)
11
- const selectedIncludePath = includePaths.find((includePath) => path.includes(includePath))
14
+ const stripPaths = [...additionalPaths, sourcePath]
15
+
16
+ const selectedStripPath = stripPaths.find((includePath) =>
17
+ path.startsWith(includePath)
18
+ )
12
19
 
13
20
  const folders = path
14
- .replace(`${selectedIncludePath}`, '')
15
- .split('/')
21
+ .replace(`${selectedStripPath}`, "")
22
+ .split("/")
16
23
  .filter(Boolean)
17
24
 
18
- const foldersWithStatic = ['static', ...folders].join('/')
25
+ const foldersWithStatic = ["static", ...folders].join("/")
19
26
  return `${foldersWithStatic}/[name]-[hash][ext][query]`
20
27
  }
21
28
  }
@@ -2,17 +2,17 @@
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
4
  const rules = {
5
- raw: require('./raw'),
6
- file: require('./file'),
7
- css: require('./css'),
8
- sass: require('./sass'),
9
- babel: require('./babel'),
10
- swc: require('./swc'),
11
- esbuild: require('./esbuild'),
12
- erb: require('./erb'),
13
- coffee: require('./coffee'),
14
- less: require('./less'),
15
- stylus: require('./stylus')
5
+ raw: require("./raw"),
6
+ file: require("./file"),
7
+ css: require("./css"),
8
+ sass: require("./sass"),
9
+ babel: require("./babel"),
10
+ swc: require("./swc"),
11
+ esbuild: require("./esbuild"),
12
+ erb: require("./erb"),
13
+ coffee: require("./coffee"),
14
+ less: require("./less"),
15
+ stylus: require("./stylus")
16
16
  }
17
17
 
18
18
  module.exports = Object.keys(rules)
@@ -1,8 +1,11 @@
1
- const { resolve } = require('path')
2
- const { realpathSync } = require('fs')
3
- const { includePaths } = require('../config')
1
+ const { resolve } = require("path")
2
+ const { realpathSync } = require("fs")
3
+ const {
4
+ source_path: sourcePath,
5
+ additional_paths: additionalPaths
6
+ } = require("../config")
4
7
 
5
- const inclusions = includePaths.map(p => {
8
+ const inclusions = [sourcePath, ...additionalPaths].map((p) => {
6
9
  try {
7
10
  return realpathSync(p)
8
11
  } catch (e) {
@@ -15,7 +18,7 @@ module.exports = {
15
18
  exclude: [
16
19
  {
17
20
  // exclude all node_modules from running through babel-loader
18
- and: [resolve('node_modules')],
21
+ and: [resolve("node_modules")],
19
22
  // Do not exclude inclusions, as otherwise these won't be transpiled
20
23
  not: [...inclusions]
21
24
  }
@@ -1,18 +1,19 @@
1
- const path = require('path')
2
- const { canProcess } = require('../utils/helpers')
3
- const getStyleRule = require('../utils/get_style_rule')
4
- const { includePaths } = require('../config')
1
+ const path = require("path")
2
+ const { canProcess } = require("../utils/helpers")
3
+ const getStyleRule = require("../utils/getStyleRule")
5
4
 
6
- module.exports = canProcess('less-loader', (resolvedPath) =>
5
+ const {
6
+ additional_paths: paths,
7
+ source_path: sourcePath
8
+ } = require("../config")
9
+
10
+ module.exports = canProcess("less-loader", (resolvedPath) =>
7
11
  getStyleRule(/\.(less)(\.erb)?$/i, [
8
12
  {
9
13
  loader: resolvedPath,
10
14
  options: {
11
15
  lessOptions: {
12
- paths: [
13
- path.resolve(__dirname, 'node_modules'),
14
- ...includePaths
15
- ]
16
+ paths: [path.resolve(__dirname, "node_modules"), sourcePath, ...paths]
16
17
  },
17
18
  sourceMap: true
18
19
  }
data/package/rules/raw.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
2
  test: /\.html$/,
3
3
  exclude: /\.(js|mjs|jsx|ts|tsx)$/,
4
- type: 'asset/source'
4
+ type: "asset/source"
5
5
  }
@@ -1,10 +1,10 @@
1
1
  /* eslint global-require: 0 */
2
2
 
3
- const getStyleRule = require('../utils/get_style_rule')
4
- const { canProcess } = require('../utils/helpers')
5
- const { additional_paths: includePaths } = require('../config')
3
+ const getStyleRule = require("../utils/getStyleRule")
4
+ const { canProcess } = require("../utils/helpers")
5
+ const { additional_paths: includePaths } = require("../config")
6
6
 
7
- module.exports = canProcess('sass-loader', (resolvedPath) =>
7
+ module.exports = canProcess("sass-loader", (resolvedPath) =>
8
8
  getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
9
9
  {
10
10
  loader: resolvedPath,
@@ -1,17 +1,22 @@
1
- const path = require('path')
2
- const { canProcess } = require('../utils/helpers')
3
- const getStyleRule = require('../utils/get_style_rule')
4
- const { includePaths } = require('../config')
1
+ const path = require("path")
2
+ const { canProcess } = require("../utils/helpers")
3
+ const getStyleRule = require("../utils/getStyleRule")
5
4
 
6
- module.exports = canProcess('stylus-loader', (resolvedPath) =>
5
+ const {
6
+ additional_paths: paths,
7
+ source_path: sourcePath
8
+ } = require("../config")
9
+
10
+ module.exports = canProcess("stylus-loader", (resolvedPath) =>
7
11
  getStyleRule(/\.(styl(us)?)(\.erb)?$/i, [
8
12
  {
9
13
  loader: resolvedPath,
10
14
  options: {
11
15
  stylusOptions: {
12
16
  include: [
13
- path.resolve(__dirname, 'node_modules'),
14
- ...includePaths
17
+ path.resolve(__dirname, "node_modules"),
18
+ sourcePath,
19
+ ...paths
15
20
  ]
16
21
  },
17
22
  sourceMap: true
data/package/rules/swc.js CHANGED
@@ -1,11 +1,9 @@
1
- const { loaderMatches } = require('../utils/helpers')
2
- const { getSwcLoaderConfig } = require('../swc')
3
- const {
4
- webpack_loader: webpackLoader
5
- } = require('../config')
6
- const jscommon = require('./jscommon')
1
+ const { loaderMatches } = require("../utils/helpers")
2
+ const { getSwcLoaderConfig } = require("../swc")
3
+ const { webpack_loader: webpackLoader } = require("../config")
4
+ const jscommon = require("./jscommon")
7
5
 
8
- module.exports = loaderMatches(webpackLoader, 'swc', () => ({
6
+ module.exports = loaderMatches(webpackLoader, "swc", () => ({
9
7
  test: /\.(ts|tsx|js|jsx|mjs|coffee)?(\.erb)?$/,
10
8
  ...jscommon,
11
9
  use: ({ resource }) => getSwcLoaderConfig(resource)
data/package/swc/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
- const { resolve } = require('path')
5
- const { existsSync } = require('fs')
6
- const { merge } = require('webpack-merge')
4
+ const { resolve } = require("path")
5
+ const { existsSync } = require("fs")
6
+ const { merge } = require("webpack-merge")
7
7
 
8
8
  const isJsxFile = (filename) => !!filename.match(/\.(jsx|tsx)?(\.erb)?$/)
9
9
 
10
10
  const isTypescriptFile = (filename) => !!filename.match(/\.(ts|tsx)?(\.erb)?$/)
11
11
 
12
12
  const getCustomConfig = () => {
13
- const path = resolve('config', 'swc.config.js')
13
+ const path = resolve("config", "swc.config.js")
14
14
  if (existsSync(path)) {
15
15
  return require(path)
16
16
  }
@@ -20,15 +20,15 @@ const getCustomConfig = () => {
20
20
  const getSwcLoaderConfig = (filenameToProcess) => {
21
21
  const customConfig = getCustomConfig()
22
22
  const defaultConfig = {
23
- loader: require.resolve('swc-loader'),
23
+ loader: require.resolve("swc-loader"),
24
24
  options: {
25
25
  jsc: {
26
26
  parser: {
27
27
  dynamicImport: true,
28
28
  syntax: isTypescriptFile(filenameToProcess)
29
- ? 'typescript'
30
- : 'ecmascript',
31
- [isTypescriptFile(filenameToProcess) ? 'tsx' : 'jsx']:
29
+ ? "typescript"
30
+ : "ecmascript",
31
+ [isTypescriptFile(filenameToProcess) ? "tsx" : "jsx"]:
32
32
  isJsxFile(filenameToProcess)
33
33
  },
34
34
  loose: true
@@ -36,8 +36,8 @@ const getSwcLoaderConfig = (filenameToProcess) => {
36
36
  sourceMaps: true,
37
37
  env: {
38
38
  coreJs: 3,
39
- exclude: ['transform-typeof-symbol'],
40
- mode: 'entry'
39
+ exclude: ["transform-typeof-symbol"],
40
+ mode: "entry"
41
41
  }
42
42
  }
43
43
  }
@@ -1,19 +1,4 @@
1
- const fs = require('fs')
2
- const { resolve } = require('path')
3
- const { setShakapackerEnvVariablesForBackwardCompatibility } = require('./helpers')
1
+ const { resolve } = require("path")
4
2
 
5
- setShakapackerEnvVariablesForBackwardCompatibility()
6
-
7
- // For backward compatibility
8
- const resolveToPhysicalFilePath = () => {
9
- const shakapackerConfigPath = resolve('config', 'shakapacker.yml')
10
- const webpackerConfigPath = resolve('config', 'webpacker.yml')
11
-
12
- if (fs.existsSync(shakapackerConfigPath)) return shakapackerConfigPath
13
- if (fs.existsSync(webpackerConfigPath)) return webpackerConfigPath
14
-
15
- // If neither of files exist, try to resolve to shakapacker.yml to get more relevant error
16
- return shakapackerConfigPath
17
- }
18
-
19
- module.exports = process.env.SHAKAPACKER_CONFIG || resolveToPhysicalFilePath()
3
+ module.exports =
4
+ process.env.SHAKAPACKER_CONFIG || resolve("config", "shakapacker.yml")
@@ -1,2 +1,2 @@
1
- const path = require.resolve('../../lib/install/config/shakapacker.yml')
1
+ const path = require.resolve("../../lib/install/config/shakapacker.yml")
2
2
  module.exports = path
@@ -1,11 +1,11 @@
1
1
  /* eslint global-require: 0 */
2
- const { canProcess, moduleExists } = require('./helpers')
3
- const inliningCss = require('./inliningCss')
2
+ const { canProcess, moduleExists } = require("./helpers")
3
+ const inliningCss = require("./inliningCss")
4
4
 
5
5
  const getStyleRule = (test, preprocessors = []) => {
6
- if (moduleExists('css-loader')) {
6
+ if (moduleExists("css-loader")) {
7
7
  const tryPostcss = () =>
8
- canProcess('postcss-loader', (loaderPath) => ({
8
+ canProcess("postcss-loader", (loaderPath) => ({
9
9
  loader: loaderPath,
10
10
  options: { sourceMap: true }
11
11
  }))
@@ -13,9 +13,9 @@ const getStyleRule = (test, preprocessors = []) => {
13
13
  // style-loader is required when using css modules with HMR on the webpack-dev-server
14
14
 
15
15
  const use = [
16
- inliningCss ? 'style-loader' : require('mini-css-extract-plugin').loader,
16
+ inliningCss ? "style-loader" : require("mini-css-extract-plugin").loader,
17
17
  {
18
- loader: require.resolve('css-loader'),
18
+ loader: require.resolve("css-loader"),
19
19
  options: {
20
20
  sourceMap: true,
21
21
  importLoaders: 2,
@@ -1,35 +1,12 @@
1
- const isArray = (value) => Array.isArray(value)
2
1
  const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
3
- const chdirTestApp = () => {
4
- try {
5
- return process.chdir('spec/shakapacker/test_app')
6
- } catch (e) {
7
- return null
8
- }
9
- }
10
2
 
11
- // For backward compatibility
12
- const chdirWebpackerTestApp = () => {
13
- try {
14
- return process.chdir('spec/backward_compatibility_specs/webpacker_test_app')
15
- } catch (e) {
16
- return null
17
- }
18
- }
19
-
20
- const chdirCwd = () => process.chdir(process.cwd())
21
-
22
- const resetEnv = () => {
23
- process.env = {}
24
- }
25
-
26
- const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)
3
+ const ensureTrailingSlash = (path) => (path.endsWith("/") ? path : `${path}/`)
27
4
 
28
5
  const resolvedPath = (packageName) => {
29
6
  try {
30
7
  return require.resolve(packageName)
31
8
  } catch (e) {
32
- if (e.code !== 'MODULE_NOT_FOUND') {
9
+ if (e.code !== "MODULE_NOT_FOUND") {
33
10
  throw e
34
11
  }
35
12
  return null
@@ -64,28 +41,10 @@ const loaderMatches = (configLoader, loaderToCheck, fn) => {
64
41
  return fn()
65
42
  }
66
43
 
67
- // For backward compatibility
68
- // Set SHAKAPACKER_XYZ only if SHAKAPACKER_XYZ is not defined but WEBPACKER_XYZ is.
69
- const setShakapackerEnvVariablesForBackwardCompatibility = () => {
70
- const webpackerEnvVariables = Object.entries(process.env).filter((key) => /^WEBPACKER_/.test(key))
71
- webpackerEnvVariables.forEach(([webpackerEnvKey, webpackerEnvValue]) => {
72
- const shakapackerKey = webpackerEnvKey.replace(/^WEBPACKER/, 'SHAKAPACKER')
73
- if (!process.env[shakapackerKey]) {
74
- process.env[shakapackerKey] = webpackerEnvValue
75
- }
76
- })
77
- }
78
-
79
44
  module.exports = {
80
- chdirTestApp,
81
- chdirWebpackerTestApp,
82
- setShakapackerEnvVariablesForBackwardCompatibility,
83
- chdirCwd,
84
- isArray,
85
45
  isBoolean,
86
46
  ensureTrailingSlash,
87
47
  canProcess,
88
48
  moduleExists,
89
- resetEnv,
90
49
  loaderMatches
91
50
  }
@@ -1,7 +1,8 @@
1
- const { runningWebpackDevServer } = require('../env')
2
- const devServer = require('../dev_server')
1
+ const { runningWebpackDevServer } = require("../env")
2
+ const devServer = require("../dev_server")
3
3
 
4
4
  // This logic is tied to lib/shakapacker/instance.rb
5
- const inliningCss = runningWebpackDevServer && devServer.hmr && devServer.inline_css !== false
5
+ const inliningCss =
6
+ runningWebpackDevServer && devServer.hmr && devServer.inline_css !== false
6
7
 
7
8
  module.exports = inliningCss
@@ -0,0 +1,5 @@
1
+ function snakeToCamelCase(s) {
2
+ return s.replace(/(_\w)/g, (match) => match[1].toUpperCase())
3
+ }
4
+
5
+ module.exports = snakeToCamelCase