shakapacker 7.2.3 → 8.0.0.pre.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) 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 +5 -1
  6. data/.github/workflows/generator.yml +13 -18
  7. data/.github/workflows/node.yml +56 -0
  8. data/.github/workflows/ruby.yml +28 -17
  9. data/.rubocop.yml +1 -0
  10. data/CHANGELOG.md +52 -1
  11. data/README.md +88 -50
  12. data/Rakefile +1 -7
  13. data/docs/customizing_babel_config.md +2 -2
  14. data/docs/deployment.md +13 -6
  15. data/docs/react.md +6 -12
  16. data/docs/troubleshooting.md +4 -4
  17. data/docs/using_esbuild_loader.md +1 -1
  18. data/docs/using_swc_loader.md +1 -1
  19. data/docs/v8_upgrade.md +148 -0
  20. data/gemfiles/Gemfile-rails.7.1.x +12 -0
  21. data/jest.config.js +4 -0
  22. data/lib/install/config/shakapacker.yml +2 -2
  23. data/lib/install/template.rb +36 -30
  24. data/lib/shakapacker/base_strategy.rb +2 -1
  25. data/lib/shakapacker/compiler.rb +5 -20
  26. data/lib/shakapacker/configuration.rb +2 -46
  27. data/lib/shakapacker/deprecation_helper.rb +0 -78
  28. data/lib/shakapacker/dev_server.rb +1 -16
  29. data/lib/shakapacker/dev_server_runner.rb +2 -21
  30. data/lib/shakapacker/env.rb +1 -1
  31. data/lib/shakapacker/instance.rb +1 -3
  32. data/lib/shakapacker/manifest.rb +1 -1
  33. data/lib/shakapacker/railtie.rb +7 -0
  34. data/lib/shakapacker/runner.rb +4 -18
  35. data/lib/shakapacker/utils/manager.rb +58 -0
  36. data/lib/shakapacker/utils/misc.rb +0 -12
  37. data/lib/shakapacker/version.rb +1 -1
  38. data/lib/shakapacker/version_checker.rb +9 -30
  39. data/lib/shakapacker/webpack_runner.rb +2 -21
  40. data/lib/shakapacker.rb +0 -2
  41. data/lib/tasks/shakapacker/check_binstubs.rake +12 -26
  42. data/lib/tasks/shakapacker/check_manager.rake +3 -8
  43. data/lib/tasks/shakapacker/info.rake +6 -15
  44. data/package/babel/preset.js +15 -15
  45. data/package/config.js +15 -17
  46. data/package/dev_server.js +4 -4
  47. data/package/env.js +19 -17
  48. data/package/environments/base.js +41 -24
  49. data/package/environments/development.js +6 -6
  50. data/package/environments/production.js +16 -16
  51. data/package/environments/test.js +1 -1
  52. data/package/esbuild/index.js +6 -6
  53. data/package/index.d.ts +0 -1
  54. data/package/index.js +17 -46
  55. data/package/rules/babel.js +6 -8
  56. data/package/rules/coffee.js +2 -2
  57. data/package/rules/css.js +1 -1
  58. data/package/rules/erb.js +4 -4
  59. data/package/rules/esbuild.js +5 -7
  60. data/package/rules/file.js +17 -7
  61. data/package/rules/index.js +11 -11
  62. data/package/rules/jscommon.js +5 -5
  63. data/package/rules/less.js +6 -6
  64. data/package/rules/raw.js +1 -1
  65. data/package/rules/sass.js +4 -4
  66. data/package/rules/stylus.js +6 -6
  67. data/package/rules/swc.js +5 -7
  68. data/package/swc/index.js +10 -10
  69. data/package/utils/configPath.js +3 -18
  70. data/package/utils/defaultConfigPath.js +1 -1
  71. data/package/utils/{get_style_rule.js → getStyleRule.js} +6 -6
  72. data/package/utils/helpers.js +2 -43
  73. data/package/utils/inliningCss.js +4 -3
  74. data/package/utils/snakeToCamelCase.js +5 -0
  75. data/package/webpackDevServerConfig.js +28 -25
  76. data/package.json +11 -17
  77. data/prettier.config.js +4 -0
  78. data/shakapacker.gemspec +1 -1
  79. data/spec/dummy/app/javascript/packs/application.js +1 -1
  80. data/spec/dummy/config/application.rb +3 -0
  81. data/spec/dummy/config/initializers/react_on_rails.rb +2 -2
  82. data/spec/dummy/config/shakapacker.yml +3 -4
  83. data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -1
  84. data/spec/dummy/config/webpack/webpack.config.js +1 -1
  85. data/spec/dummy/package.json +2 -1
  86. data/spec/dummy/yarn.lock +2 -3
  87. data/spec/generator_specs/e2e_template/template.rb +15 -28
  88. data/spec/generator_specs/generator_spec.rb +6 -136
  89. data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -1
  90. data/spec/shakapacker/compiler_spec.rb +1 -3
  91. data/spec/shakapacker/configuration_spec.rb +4 -56
  92. data/spec/shakapacker/dev_server_runner_spec.rb +19 -102
  93. data/spec/shakapacker/dev_server_spec.rb +1 -16
  94. data/spec/shakapacker/engine_rake_tasks_spec.rb +1 -16
  95. data/spec/shakapacker/instance_spec.rb +1 -3
  96. data/spec/shakapacker/rake_tasks_spec.rb +2 -14
  97. data/spec/shakapacker/shakapacker_spec.rb +0 -1
  98. data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -1
  99. data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -1
  100. data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -1
  101. data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -1
  102. data/spec/shakapacker/test_app/package.json +2 -1
  103. data/spec/shakapacker/utils_manager_spec.rb +125 -0
  104. data/spec/shakapacker/version_checker_spec.rb +4 -4
  105. data/spec/shakapacker/webpack_runner_spec.rb +19 -28
  106. data/spec/support/package_json_helpers.rb +7 -4
  107. data/test/helpers.js +67 -0
  108. data/test/package/config.test.js +50 -0
  109. data/test/package/dev_server.test.js +44 -0
  110. data/test/package/development.test.js +43 -0
  111. data/test/package/env.test.js +57 -0
  112. data/test/package/environments/base.test.js +105 -0
  113. data/test/package/environments/development.test.js +50 -0
  114. data/test/package/environments/production.test.js +106 -0
  115. data/test/package/index.test.js +45 -0
  116. data/test/package/production.test.js +32 -0
  117. data/test/package/rules/babel.test.js +58 -0
  118. data/test/package/rules/esbuild.test.js +59 -0
  119. data/test/package/rules/file.test.js +81 -0
  120. data/test/package/rules/index.test.js +7 -0
  121. data/test/package/rules/raw.test.js +12 -0
  122. data/test/package/rules/swc.test.js +59 -0
  123. data/test/package/staging.test.js +31 -0
  124. data/test/package/test.test.js +28 -0
  125. data/yarn.lock +1278 -421
  126. metadata +52 -102
  127. data/.github/workflows/jest.yml +0 -34
  128. data/.github/workflows/js-lint.yml +0 -34
  129. data/.github/workflows/rubocop.yml +0 -29
  130. data/.github/workflows/ruby-backward-compatibility.yml +0 -52
  131. data/lib/install/package.json +0 -15
  132. data/lib/tasks/shakapacker/check_yarn.rake +0 -34
  133. data/lib/tasks/shakapacker/yarn_install.rake +0 -24
  134. data/lib/tasks/webpacker/binstubs.rake +0 -9
  135. data/lib/tasks/webpacker/check_binstubs.rake +0 -9
  136. data/lib/tasks/webpacker/check_node.rake +0 -9
  137. data/lib/tasks/webpacker/check_yarn.rake +0 -9
  138. data/lib/tasks/webpacker/clean.rake +0 -9
  139. data/lib/tasks/webpacker/clobber.rake +0 -11
  140. data/lib/tasks/webpacker/compile.rake +0 -9
  141. data/lib/tasks/webpacker/info.rake +0 -9
  142. data/lib/tasks/webpacker/install.rake +0 -9
  143. data/lib/tasks/webpacker/verify_config.rake +0 -9
  144. data/lib/tasks/webpacker/verify_install.rake +0 -9
  145. data/lib/tasks/webpacker/yarn_install.rake +0 -9
  146. data/lib/tasks/webpacker.rake +0 -20
  147. data/lib/webpacker/dev_server_runner.rb +0 -9
  148. data/lib/webpacker/webpack_runner.rb +0 -9
  149. data/lib/webpacker.rb +0 -4
  150. data/package/__tests__/config-bc.js +0 -27
  151. data/package/__tests__/config.js +0 -46
  152. data/package/__tests__/dev_server-bc.js +0 -46
  153. data/package/__tests__/dev_server.js +0 -46
  154. data/package/__tests__/development-bc.js +0 -66
  155. data/package/__tests__/development.js +0 -66
  156. data/package/__tests__/env-bc.js +0 -59
  157. data/package/__tests__/env.js +0 -59
  158. data/package/__tests__/index-bc.js +0 -22
  159. data/package/__tests__/index.js +0 -46
  160. data/package/__tests__/production-bc.js +0 -51
  161. data/package/__tests__/production.js +0 -51
  162. data/package/__tests__/staging-bc.js +0 -53
  163. data/package/__tests__/staging.js +0 -53
  164. data/package/__tests__/test-bc.js +0 -43
  165. data/package/__tests__/test.js +0 -43
  166. data/package/environments/__tests__/base-bc.js +0 -107
  167. data/package/environments/__tests__/base.js +0 -107
  168. data/package/environments/__tests__/development.js +0 -53
  169. data/package/environments/__tests__/production.js +0 -92
  170. data/package/rules/__tests__/__utils__/webpack.js +0 -50
  171. data/package/rules/__tests__/babel.js +0 -63
  172. data/package/rules/__tests__/esbuild.js +0 -64
  173. data/package/rules/__tests__/file.js +0 -62
  174. data/package/rules/__tests__/index.js +0 -7
  175. data/package/rules/__tests__/raw.js +0 -18
  176. data/package/rules/__tests__/swc.js +0 -63
  177. data/package/utils/snakeToCamelCase +0 -7
  178. data/spec/backward_compatibility_specs/command_spec.rb +0 -116
  179. data/spec/backward_compatibility_specs/compiler_spec.rb +0 -59
  180. data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +0 -24
  181. data/spec/backward_compatibility_specs/configuration_spec.rb +0 -294
  182. data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +0 -206
  183. data/spec/backward_compatibility_specs/dev_server_spec.rb +0 -47
  184. data/spec/backward_compatibility_specs/digest_strategy_spec.rb +0 -38
  185. data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +0 -67
  186. data/spec/backward_compatibility_specs/env_spec.rb +0 -23
  187. data/spec/backward_compatibility_specs/helper_spec.rb +0 -243
  188. data/spec/backward_compatibility_specs/instance_spec.rb +0 -31
  189. data/spec/backward_compatibility_specs/manifest_spec.rb +0 -100
  190. data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +0 -55
  191. data/spec/backward_compatibility_specs/rake_tasks_spec.rb +0 -41
  192. data/spec/backward_compatibility_specs/spec_helper_initializer.rb +0 -24
  193. data/spec/backward_compatibility_specs/webpack_runner_spec.rb +0 -86
  194. data/spec/backward_compatibility_specs/webpacker_spec.rb +0 -41
  195. data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +0 -2
  196. data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +0 -3
  197. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/application.js +0 -10
  198. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/generated/something.js +0 -2
  199. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.css +0 -4
  200. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.js +0 -4
  201. data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker +0 -13
  202. data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker-dev-server +0 -13
  203. data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +0 -11
  204. data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +0 -4
  205. data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +0 -1
  206. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
  207. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker.yml +0 -83
  208. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -84
  209. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_defaults_fallback.yml +0 -11
  210. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_manifest_path.yml +0 -80
  211. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_nested_entries.yml +0 -83
  212. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +0 -7
  213. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +0 -85
  214. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_public_root.yml +0 -18
  215. data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +0 -5
  216. data/spec/backward_compatibility_specs/webpacker_test_app/package.json +0 -13
  217. data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +0 -58
  218. data/spec/backward_compatibility_specs/webpacker_test_app/some.config.js +0 -0
  219. data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +0 -1
  220. data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +0 -11
@@ -1,6 +1,6 @@
1
- // These are the raw webpacker dev server config settings from the YML file with ENV overrides applied.
2
- const { isBoolean } = require('./utils/helpers')
3
- const config = require('./config')
1
+ // These are the raw shakapacker dev server config settings from the YML file with ENV overrides applied.
2
+ const { isBoolean } = require("./utils/helpers")
3
+ const config = require("./config")
4
4
 
5
5
  const envFetch = (key) => {
6
6
  const value = process.env[key]
@@ -10,7 +10,7 @@ const envFetch = (key) => {
10
10
  const devServerConfig = config.dev_server
11
11
 
12
12
  if (devServerConfig) {
13
- const envPrefix = config.dev_server.env_prefix || 'SHAKAPACKER_DEV_SERVER'
13
+ const envPrefix = config.dev_server.env_prefix || "SHAKAPACKER_DEV_SERVER"
14
14
 
15
15
  Object.keys(devServerConfig).forEach((key) => {
16
16
  const envValue = envFetch(`${envPrefix}_${key.toUpperCase()}`)
data/package/env.js CHANGED
@@ -1,40 +1,42 @@
1
- const { load } = require('js-yaml')
2
- const { readFileSync } = require('fs')
3
- const defaultConfigPath = require('./utils/defaultConfigPath')
1
+ const { load } = require("js-yaml")
2
+ const { readFileSync } = require("fs")
3
+ const defaultConfigPath = require("./utils/defaultConfigPath")
4
4
 
5
- const NODE_ENVIRONMENTS = ['development', 'production', 'test']
6
- const DEFAULT = 'production'
7
- const configPath = require('./utils/configPath')
5
+ const NODE_ENVIRONMENTS = ["development", "production", "test"]
6
+ const DEFAULT = "production"
7
+ const configPath = require("./utils/configPath")
8
8
 
9
9
  const railsEnv = process.env.RAILS_ENV
10
10
  const rawNodeEnv = process.env.NODE_ENV
11
- const nodeEnv
12
- = rawNodeEnv && NODE_ENVIRONMENTS.includes(rawNodeEnv) ? rawNodeEnv : DEFAULT
13
- const isProduction = nodeEnv === 'production'
14
- const isDevelopment = nodeEnv === 'development'
11
+ const nodeEnv =
12
+ rawNodeEnv && NODE_ENVIRONMENTS.includes(rawNodeEnv) ? rawNodeEnv : DEFAULT
13
+ const isProduction = nodeEnv === "production"
14
+ const isDevelopment = nodeEnv === "development"
15
15
 
16
16
  let config
17
17
  try {
18
- config = load(readFileSync(configPath), 'utf8')
18
+ config = load(readFileSync(configPath), "utf8")
19
19
  } catch (error) {
20
- if (error.code === 'ENOENT') {
20
+ if (error.code === "ENOENT") {
21
21
  // File not found, use default configuration
22
- config = load(readFileSync(defaultConfigPath), 'utf8')
22
+ config = load(readFileSync(defaultConfigPath), "utf8")
23
23
  } else {
24
24
  throw error
25
25
  }
26
26
  }
27
27
 
28
- const availableEnvironments = Object.keys(config).join('|')
29
- const regex = new RegExp(`^(${availableEnvironments})$`, 'g')
28
+ const availableEnvironments = Object.keys(config).join("|")
29
+ const regex = new RegExp(`^(${availableEnvironments})$`, "g")
30
30
 
31
- const runningWebpackDevServer = process.env.WEBPACK_SERVE === 'true'
31
+ const runningWebpackDevServer = process.env.WEBPACK_SERVE === "true"
32
32
 
33
33
  const validatedRailsEnv = railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT
34
34
 
35
35
  if (railsEnv && validatedRailsEnv !== railsEnv) {
36
36
  /* eslint no-console:0 */
37
- console.warn(`Warning: '${railsEnv}' environment not found in the configuration. Using '${DEFAULT}' configuration as a fallback.`)
37
+ console.warn(
38
+ `Warning: '${railsEnv}' environment not found in the configuration. Using '${DEFAULT}' configuration as a fallback.`
39
+ )
38
40
  }
39
41
 
40
42
  module.exports = {
@@ -1,28 +1,45 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
- const { basename, dirname, join, relative, resolve } = require('path')
5
- const extname = require('path-complete-extname')
6
- const { sync: globSync } = require('glob')
7
- const WebpackAssetsManifest = require('webpack-assets-manifest')
8
- const webpack = require('webpack')
9
- const rules = require('../rules')
10
- const config = require('../config')
11
- const { isProduction } = require('../env')
12
- const { moduleExists } = require('../utils/helpers')
4
+ const { existsSync, readdirSync } = require("fs")
5
+ const { basename, dirname, join, relative, resolve } = require("path")
6
+ const extname = require("path-complete-extname")
7
+ const WebpackAssetsManifest = require("webpack-assets-manifest")
8
+ const webpack = require("webpack")
9
+ const rules = require("../rules")
10
+ const config = require("../config")
11
+ const { isProduction } = require("../env")
12
+ const { moduleExists } = require("../utils/helpers")
13
+
14
+ const getFilesInDirectory = (dir, includeNested) => {
15
+ if (!existsSync(dir)) {
16
+ return []
17
+ }
18
+
19
+ return readdirSync(dir, { withFileTypes: true }).flatMap((dirent) => {
20
+ const filePath = join(dir, dirent.name)
21
+
22
+ if (dirent.isDirectory() && includeNested) {
23
+ return getFilesInDirectory(filePath, includeNested)
24
+ }
25
+ if (dirent.isFile()) {
26
+ return filePath
27
+ }
28
+ return []
29
+ })
30
+ }
13
31
 
14
32
  const getEntryObject = () => {
15
33
  const entries = {}
16
34
  const rootPath = join(config.source_path, config.source_entry_path)
17
- if (config.source_entry_path === '/' && config.nested_entries) {
35
+ if (config.source_entry_path === "/" && config.nested_entries) {
18
36
  throw new Error(
19
37
  "Your shakapacker config specified using a source_entry_path of '/' with 'nested_entries' == " +
20
- "'true'. Doing this would result in packs for every one of your source files"
38
+ "'true'. Doing this would result in packs for every one of your source files"
21
39
  )
22
40
  }
23
- const nesting = config.nested_entries ? '**/' : ''
24
41
 
25
- globSync(`${rootPath}/${nesting}*.*`).forEach((path) => {
42
+ getFilesInDirectory(rootPath, config.nested_entries).forEach((path) => {
26
43
  const namespace = relative(join(rootPath), dirname(path))
27
44
  const name = join(namespace, basename(path, extname(path)))
28
45
  let assetPaths = resolve(path)
@@ -50,7 +67,7 @@ const getModulePaths = () => {
50
67
  if (config.additional_paths) {
51
68
  config.additional_paths.forEach((path) => result.push(resolve(path)))
52
69
  }
53
- result.push('node_modules')
70
+ result.push("node_modules")
54
71
 
55
72
  return result
56
73
  }
@@ -67,9 +84,9 @@ const getPlugins = () => {
67
84
  })
68
85
  ]
69
86
 
70
- if (moduleExists('css-loader') && moduleExists('mini-css-extract-plugin')) {
71
- const hash = isProduction || config.useContentHash ? '-[contenthash:8]' : ''
72
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
87
+ if (moduleExists("css-loader") && moduleExists("mini-css-extract-plugin")) {
88
+ const hash = isProduction || config.useContentHash ? "-[contenthash:8]" : ""
89
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin")
73
90
  plugins.push(
74
91
  new MiniCssExtractPlugin({
75
92
  filename: `css/[name]${hash}.css`,
@@ -87,35 +104,35 @@ const getPlugins = () => {
87
104
 
88
105
  // Don't use contentHash except for production for performance
89
106
  // https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
90
- const hash = isProduction || config.useContentHash ? '-[contenthash]' : ''
107
+ const hash = isProduction || config.useContentHash ? "-[contenthash]" : ""
91
108
 
92
109
  module.exports = {
93
- mode: 'production',
110
+ mode: "production",
94
111
  output: {
95
112
  filename: `js/[name]${hash}.js`,
96
113
  chunkFilename: `js/[name]${hash}.chunk.js`,
97
114
 
98
115
  // https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
99
- hotUpdateChunkFilename: 'js/[id].[fullhash].hot-update.js',
116
+ hotUpdateChunkFilename: "js/[id].[fullhash].hot-update.js",
100
117
  path: config.outputPath,
101
118
  publicPath: config.publicPath
102
119
  },
103
120
  entry: getEntryObject(),
104
121
  resolve: {
105
- extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.coffee'],
122
+ extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".coffee"],
106
123
  modules: getModulePaths()
107
124
  },
108
125
 
109
126
  plugins: getPlugins(),
110
127
 
111
128
  resolveLoader: {
112
- modules: ['node_modules']
129
+ modules: ["node_modules"]
113
130
  },
114
131
 
115
132
  optimization: {
116
- splitChunks: { chunks: 'all' },
133
+ splitChunks: { chunks: "all" },
117
134
 
118
- runtimeChunk: 'single'
135
+ runtimeChunk: "single"
119
136
  },
120
137
 
121
138
  module: {
@@ -1,12 +1,12 @@
1
- const { merge } = require('webpack-merge')
1
+ const { merge } = require("webpack-merge")
2
2
 
3
- const baseConfig = require('./base')
4
- const webpackDevServerConfig = require('../webpackDevServerConfig')
5
- const { runningWebpackDevServer } = require('../env')
3
+ const baseConfig = require("./base")
4
+ const webpackDevServerConfig = require("../webpackDevServerConfig")
5
+ const { runningWebpackDevServer } = require("../env")
6
6
 
7
7
  const devConfig = {
8
- mode: 'development',
9
- devtool: 'cheap-module-source-map',
8
+ mode: "development",
9
+ devtool: "cheap-module-source-map",
10
10
  ...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
11
11
  }
12
12
 
@@ -1,29 +1,29 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
- const { merge } = require('webpack-merge')
5
- const CompressionPlugin = require('compression-webpack-plugin')
6
- const TerserPlugin = require('terser-webpack-plugin')
7
- const baseConfig = require('./base')
8
- const { moduleExists } = require('../utils/helpers')
9
- const config = require('../config')
4
+ const { merge } = require("webpack-merge")
5
+ const CompressionPlugin = require("compression-webpack-plugin")
6
+ const TerserPlugin = require("terser-webpack-plugin")
7
+ const baseConfig = require("./base")
8
+ const { moduleExists } = require("../utils/helpers")
9
+ const config = require("../config")
10
10
 
11
11
  const getPlugins = () => {
12
12
  const plugins = []
13
13
 
14
14
  plugins.push(
15
15
  new CompressionPlugin({
16
- filename: '[path][base].gz[query]',
17
- algorithm: 'gzip',
16
+ filename: "[path][base].gz[query]",
17
+ algorithm: "gzip",
18
18
  test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
19
19
  })
20
20
  )
21
21
 
22
- if ('brotli' in process.versions) {
22
+ if ("brotli" in process.versions) {
23
23
  plugins.push(
24
24
  new CompressionPlugin({
25
- filename: '[path][base].br[query]',
26
- algorithm: 'brotliCompress',
25
+ filename: "[path][base].br[query]",
26
+ algorithm: "brotliCompress",
27
27
  test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
28
28
  })
29
29
  )
@@ -34,10 +34,10 @@ const getPlugins = () => {
34
34
 
35
35
  const tryCssMinimizer = () => {
36
36
  if (
37
- moduleExists('css-loader') &&
38
- moduleExists('css-minimizer-webpack-plugin')
37
+ moduleExists("css-loader") &&
38
+ moduleExists("css-minimizer-webpack-plugin")
39
39
  ) {
40
- const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
40
+ const CssMinimizerPlugin = require("css-minimizer-webpack-plugin")
41
41
  return new CssMinimizerPlugin()
42
42
  }
43
43
 
@@ -45,8 +45,8 @@ const tryCssMinimizer = () => {
45
45
  }
46
46
 
47
47
  const productionConfig = {
48
- devtool: 'source-map',
49
- stats: 'normal',
48
+ devtool: "source-map",
49
+ stats: "normal",
50
50
  bail: true,
51
51
  plugins: getPlugins(),
52
52
  optimization: {
@@ -1,3 +1,3 @@
1
- const baseConfig = require('./base')
1
+ const baseConfig = require("./base")
2
2
 
3
3
  module.exports = baseConfig
@@ -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
@@ -35,7 +35,6 @@ declare module 'shakapacker' {
35
35
  export const config: Config
36
36
  export const devServer: Record<string, unknown>
37
37
  export function generateWebpackConfig(extraConfig?: Configuration): Configuration
38
- export const globalMutableWebpackConfig: Configuration
39
38
  export const baseConfig: Configuration
40
39
  export const env: Env
41
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/main/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,18 +1,28 @@
1
- const { dirname } = require('path')
2
- const { source_path: sourcePath } = 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
- const folders = dirname(pathData.filename)
11
- .replace(`${sourcePath}`, '')
12
- .split('/')
13
+ const path = dirname(pathData.filename)
14
+ const stripPaths = [...additionalPaths, sourcePath]
15
+
16
+ const selectedStripPath = stripPaths.find((includePath) =>
17
+ path.startsWith(includePath)
18
+ )
19
+
20
+ const folders = path
21
+ .replace(`${selectedStripPath}`, "")
22
+ .split("/")
13
23
  .filter(Boolean)
14
24
 
15
- const foldersWithStatic = ['static', ...folders].join('/')
25
+ const foldersWithStatic = ["static", ...folders].join("/")
16
26
  return `${foldersWithStatic}/[name]-[hash][ext][query]`
17
27
  }
18
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,11 +1,11 @@
1
- const { resolve } = require('path')
2
- const { realpathSync } = require('fs')
1
+ const { resolve } = require("path")
2
+ const { realpathSync } = require("fs")
3
3
  const {
4
4
  source_path: sourcePath,
5
5
  additional_paths: additionalPaths
6
- } = require('../config')
6
+ } = require("../config")
7
7
 
8
- const inclusions = [sourcePath, ...additionalPaths].map(p => {
8
+ const inclusions = [sourcePath, ...additionalPaths].map((p) => {
9
9
  try {
10
10
  return realpathSync(p)
11
11
  } catch (e) {
@@ -18,7 +18,7 @@ module.exports = {
18
18
  exclude: [
19
19
  {
20
20
  // exclude all node_modules from running through babel-loader
21
- and: [resolve('node_modules')],
21
+ and: [resolve("node_modules")],
22
22
  // Do not exclude inclusions, as otherwise these won't be transpiled
23
23
  not: [...inclusions]
24
24
  }
@@ -1,19 +1,19 @@
1
- const path = require('path')
2
- const { canProcess } = require('../utils/helpers')
3
- const getStyleRule = require('../utils/get_style_rule')
1
+ const path = require("path")
2
+ const { canProcess } = require("../utils/helpers")
3
+ const getStyleRule = require("../utils/getStyleRule")
4
4
 
5
5
  const {
6
6
  additional_paths: paths,
7
7
  source_path: sourcePath
8
- } = require('../config')
8
+ } = require("../config")
9
9
 
10
- module.exports = canProcess('less-loader', (resolvedPath) =>
10
+ module.exports = canProcess("less-loader", (resolvedPath) =>
11
11
  getStyleRule(/\.(less)(\.erb)?$/i, [
12
12
  {
13
13
  loader: resolvedPath,
14
14
  options: {
15
15
  lessOptions: {
16
- paths: [path.resolve(__dirname, 'node_modules'), sourcePath, ...paths]
16
+ paths: [path.resolve(__dirname, "node_modules"), sourcePath, ...paths]
17
17
  },
18
18
  sourceMap: true
19
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,