shakapacker 8.4.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +1 -0
  3. data/.eslintrc.fast.js +40 -0
  4. data/.eslintrc.js +48 -0
  5. data/.github/STATUS.md +1 -0
  6. data/.github/workflows/claude-code-review.yml +54 -0
  7. data/.github/workflows/claude.yml +50 -0
  8. data/.github/workflows/dummy.yml +8 -4
  9. data/.github/workflows/generator.yml +17 -14
  10. data/.github/workflows/node.yml +23 -1
  11. data/.github/workflows/ruby.yml +11 -0
  12. data/.github/workflows/test-bundlers.yml +170 -0
  13. data/.gitignore +17 -0
  14. data/.husky/pre-commit +2 -0
  15. data/.npmignore +56 -0
  16. data/.prettierignore +3 -0
  17. data/.rubocop.yml +1 -0
  18. data/.yalcignore +26 -0
  19. data/CHANGELOG.md +156 -18
  20. data/CLAUDE.md +29 -0
  21. data/CONTRIBUTING.md +138 -20
  22. data/Gemfile.lock +3 -3
  23. data/README.md +130 -5
  24. data/Rakefile +39 -4
  25. data/TODO.md +50 -0
  26. data/TODO_v9.md +87 -0
  27. data/conductor-setup.sh +70 -0
  28. data/conductor.json +7 -0
  29. data/docs/cdn_setup.md +379 -0
  30. data/docs/css-modules-export-mode.md +512 -0
  31. data/docs/deployment.md +10 -1
  32. data/docs/optional-peer-dependencies.md +198 -0
  33. data/docs/peer-dependencies.md +60 -0
  34. data/docs/rspack.md +190 -0
  35. data/docs/rspack_migration_guide.md +202 -0
  36. data/docs/transpiler-migration.md +188 -0
  37. data/docs/transpiler-performance.md +179 -0
  38. data/docs/troubleshooting.md +5 -0
  39. data/docs/typescript-migration.md +378 -0
  40. data/docs/typescript.md +99 -0
  41. data/docs/using_esbuild_loader.md +3 -3
  42. data/docs/using_swc_loader.md +5 -3
  43. data/docs/v6_upgrade.md +10 -0
  44. data/docs/v9_upgrade.md +413 -0
  45. data/lib/install/bin/shakapacker +3 -5
  46. data/lib/install/config/rspack/rspack.config.js +6 -0
  47. data/lib/install/config/rspack/rspack.config.ts +7 -0
  48. data/lib/install/config/shakapacker.yml +12 -2
  49. data/lib/install/config/webpack/webpack.config.ts +7 -0
  50. data/lib/install/package.json +38 -0
  51. data/lib/install/template.rb +194 -44
  52. data/lib/shakapacker/configuration.rb +141 -0
  53. data/lib/shakapacker/dev_server_runner.rb +25 -5
  54. data/lib/shakapacker/doctor.rb +844 -0
  55. data/lib/shakapacker/manifest.rb +4 -2
  56. data/lib/shakapacker/rspack_runner.rb +19 -0
  57. data/lib/shakapacker/runner.rb +144 -4
  58. data/lib/shakapacker/swc_migrator.rb +376 -0
  59. data/lib/shakapacker/utils/manager.rb +2 -0
  60. data/lib/shakapacker/version.rb +1 -1
  61. data/lib/shakapacker/version_checker.rb +1 -1
  62. data/lib/shakapacker/webpack_runner.rb +4 -42
  63. data/lib/shakapacker.rb +2 -1
  64. data/lib/tasks/shakapacker/doctor.rake +8 -0
  65. data/lib/tasks/shakapacker/install.rake +12 -2
  66. data/lib/tasks/shakapacker/migrate_to_swc.rake +13 -0
  67. data/lib/tasks/shakapacker.rake +1 -0
  68. data/package/.npmignore +4 -0
  69. data/package/babel/preset.ts +56 -0
  70. data/package/config.ts +175 -0
  71. data/package/{dev_server.js → dev_server.ts} +8 -5
  72. data/package/env.ts +92 -0
  73. data/package/environments/base.ts +138 -0
  74. data/package/environments/development.ts +90 -0
  75. data/package/environments/production.ts +80 -0
  76. data/package/environments/test.ts +53 -0
  77. data/package/environments/types.ts +90 -0
  78. data/package/esbuild/index.ts +42 -0
  79. data/package/index.d.ts +3 -97
  80. data/package/index.ts +52 -0
  81. data/package/loaders.d.ts +28 -0
  82. data/package/optimization/rspack.ts +36 -0
  83. data/package/optimization/webpack.ts +57 -0
  84. data/package/plugins/rspack.ts +103 -0
  85. data/package/plugins/webpack.ts +62 -0
  86. data/package/rspack/index.ts +64 -0
  87. data/package/rules/{babel.js → babel.ts} +2 -2
  88. data/package/rules/{coffee.js → coffee.ts} +1 -1
  89. data/package/rules/css.ts +3 -0
  90. data/package/rules/{erb.js → erb.ts} +1 -1
  91. data/package/rules/esbuild.ts +10 -0
  92. data/package/rules/file.ts +40 -0
  93. data/package/rules/{jscommon.js → jscommon.ts} +4 -4
  94. data/package/rules/{less.js → less.ts} +4 -4
  95. data/package/rules/raw.ts +25 -0
  96. data/package/rules/rspack.ts +176 -0
  97. data/package/rules/{sass.js → sass.ts} +7 -3
  98. data/package/rules/{stylus.js → stylus.ts} +4 -8
  99. data/package/rules/swc.ts +10 -0
  100. data/package/rules/{index.js → webpack.ts} +1 -1
  101. data/package/swc/index.ts +54 -0
  102. data/package/types/README.md +87 -0
  103. data/package/types/index.ts +60 -0
  104. data/package/types.ts +108 -0
  105. data/package/utils/configPath.ts +6 -0
  106. data/package/utils/debug.ts +49 -0
  107. data/package/utils/defaultConfigPath.ts +4 -0
  108. data/package/utils/errorCodes.ts +219 -0
  109. data/package/utils/errorHelpers.ts +143 -0
  110. data/package/utils/getStyleRule.ts +64 -0
  111. data/package/utils/helpers.ts +85 -0
  112. data/package/utils/{inliningCss.js → inliningCss.ts} +3 -3
  113. data/package/utils/pathValidation.ts +139 -0
  114. data/package/utils/requireOrError.ts +15 -0
  115. data/package/utils/snakeToCamelCase.ts +5 -0
  116. data/package/utils/typeGuards.ts +342 -0
  117. data/package/utils/validateDependencies.ts +61 -0
  118. data/package/webpack-types.d.ts +33 -0
  119. data/package/webpackDevServerConfig.ts +117 -0
  120. data/package.json +134 -9
  121. data/scripts/remove-use-strict.js +45 -0
  122. data/scripts/type-check-no-emit.js +27 -0
  123. data/test/package/config.test.js +3 -0
  124. data/test/package/env.test.js +42 -7
  125. data/test/package/environments/base.test.js +5 -1
  126. data/test/package/rules/babel.test.js +16 -0
  127. data/test/package/rules/esbuild.test.js +1 -1
  128. data/test/package/rules/raw.test.js +40 -7
  129. data/test/package/rules/swc.test.js +1 -1
  130. data/test/package/rules/webpack.test.js +35 -0
  131. data/test/package/staging.test.js +4 -3
  132. data/test/package/transpiler-defaults.test.js +127 -0
  133. data/test/peer-dependencies.sh +85 -0
  134. data/test/scripts/remove-use-strict.test.js +125 -0
  135. data/test/typescript/build.test.js +118 -0
  136. data/test/typescript/environments.test.js +107 -0
  137. data/test/typescript/pathValidation.test.js +142 -0
  138. data/test/typescript/securityValidation.test.js +182 -0
  139. data/tools/README.md +124 -0
  140. data/tools/css-modules-v9-codemod.js +179 -0
  141. data/tsconfig.eslint.json +16 -0
  142. data/tsconfig.json +38 -0
  143. data/yarn.lock +2704 -767
  144. metadata +111 -41
  145. data/package/babel/preset.js +0 -48
  146. data/package/config.js +0 -56
  147. data/package/env.js +0 -48
  148. data/package/environments/base.js +0 -171
  149. data/package/environments/development.js +0 -13
  150. data/package/environments/production.js +0 -88
  151. data/package/environments/test.js +0 -3
  152. data/package/esbuild/index.js +0 -40
  153. data/package/index.js +0 -40
  154. data/package/rules/css.js +0 -3
  155. data/package/rules/esbuild.js +0 -10
  156. data/package/rules/file.js +0 -29
  157. data/package/rules/raw.js +0 -5
  158. data/package/rules/swc.js +0 -10
  159. data/package/swc/index.js +0 -50
  160. data/package/utils/configPath.js +0 -4
  161. data/package/utils/defaultConfigPath.js +0 -2
  162. data/package/utils/getStyleRule.js +0 -40
  163. data/package/utils/helpers.js +0 -62
  164. data/package/utils/snakeToCamelCase.js +0 -5
  165. data/package/webpackDevServerConfig.js +0 -71
  166. data/test/package/rules/index.test.js +0 -16
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shakapacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.4.0
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  - Gaurav Tiwari
9
9
  - Justin Gordon
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2025-09-09 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activesupport
@@ -124,7 +123,6 @@ dependencies:
124
123
  - - ">="
125
124
  - !ruby/object:Gem::Version
126
125
  version: '0'
127
- description:
128
126
  email:
129
127
  - david@basecamp.com
130
128
  - gaurav@gauravtiwari.co.uk
@@ -134,20 +132,30 @@ extensions: []
134
132
  extra_rdoc_files: []
135
133
  files:
136
134
  - ".eslintignore"
135
+ - ".eslintrc.fast.js"
137
136
  - ".eslintrc.js"
138
137
  - ".github/FUNDING.yml"
139
138
  - ".github/ISSUE_TEMPLATE/bug_report.md"
140
139
  - ".github/ISSUE_TEMPLATE/feature_request.md"
141
140
  - ".github/PULL_REQUEST_TEMPLATE.md"
141
+ - ".github/STATUS.md"
142
+ - ".github/workflows/claude-code-review.yml"
143
+ - ".github/workflows/claude.yml"
142
144
  - ".github/workflows/dummy.yml"
143
145
  - ".github/workflows/generator.yml"
144
146
  - ".github/workflows/node.yml"
145
147
  - ".github/workflows/ruby.yml"
148
+ - ".github/workflows/test-bundlers.yml"
146
149
  - ".gitignore"
150
+ - ".husky/pre-commit"
147
151
  - ".node-version"
152
+ - ".npmignore"
153
+ - ".prettierignore"
148
154
  - ".rspec"
149
155
  - ".rubocop.yml"
156
+ - ".yalcignore"
150
157
  - CHANGELOG.md
158
+ - CLAUDE.md
151
159
  - CONTRIBUTING.md
152
160
  - Gemfile
153
161
  - Gemfile.development_dependencies
@@ -155,23 +163,38 @@ files:
155
163
  - MIT-LICENSE
156
164
  - README.md
157
165
  - Rakefile
166
+ - TODO.md
167
+ - TODO_v9.md
158
168
  - __mocks__/nonexistent/package.json
159
169
  - __mocks__/sass-loader/package.json
170
+ - conductor-setup.sh
171
+ - conductor.json
160
172
  - config/README.md
161
173
  - config/shakapacker.yml
174
+ - docs/cdn_setup.md
175
+ - docs/css-modules-export-mode.md
162
176
  - docs/customizing_babel_config.md
163
177
  - docs/deployment.md
164
178
  - docs/developing_shakapacker.md
179
+ - docs/optional-peer-dependencies.md
180
+ - docs/peer-dependencies.md
165
181
  - docs/react.md
182
+ - docs/rspack.md
183
+ - docs/rspack_migration_guide.md
166
184
  - docs/sprockets.md
167
185
  - docs/style_loader_vs_mini_css.md
168
186
  - docs/subresource_integrity.md
187
+ - docs/transpiler-migration.md
188
+ - docs/transpiler-performance.md
169
189
  - docs/troubleshooting.md
190
+ - docs/typescript-migration.md
191
+ - docs/typescript.md
170
192
  - docs/using_esbuild_loader.md
171
193
  - docs/using_swc_loader.md
172
194
  - docs/v6_upgrade.md
173
195
  - docs/v7_upgrade.md
174
196
  - docs/v8_upgrade.md
197
+ - docs/v9_upgrade.md
175
198
  - gemfiles/Gemfile-rails-edge
176
199
  - gemfiles/Gemfile-rails.6.0.x
177
200
  - gemfiles/Gemfile-rails.6.1.x
@@ -184,8 +207,12 @@ files:
184
207
  - lib/install/bin/shakapacker
185
208
  - lib/install/bin/shakapacker-dev-server
186
209
  - lib/install/binstubs.rb
210
+ - lib/install/config/rspack/rspack.config.js
211
+ - lib/install/config/rspack/rspack.config.ts
187
212
  - lib/install/config/shakapacker.yml
188
213
  - lib/install/config/webpack/webpack.config.js
214
+ - lib/install/config/webpack/webpack.config.ts
215
+ - lib/install/package.json
189
216
  - lib/install/template.rb
190
217
  - lib/shakapacker.rb
191
218
  - lib/shakapacker/base_strategy.rb
@@ -198,13 +225,16 @@ files:
198
225
  - lib/shakapacker/dev_server_proxy.rb
199
226
  - lib/shakapacker/dev_server_runner.rb
200
227
  - lib/shakapacker/digest_strategy.rb
228
+ - lib/shakapacker/doctor.rb
201
229
  - lib/shakapacker/env.rb
202
230
  - lib/shakapacker/helper.rb
203
231
  - lib/shakapacker/instance.rb
204
232
  - lib/shakapacker/manifest.rb
205
233
  - lib/shakapacker/mtime_strategy.rb
206
234
  - lib/shakapacker/railtie.rb
235
+ - lib/shakapacker/rspack_runner.rb
207
236
  - lib/shakapacker/runner.rb
237
+ - lib/shakapacker/swc_migrator.rb
208
238
  - lib/shakapacker/utils/manager.rb
209
239
  - lib/shakapacker/utils/misc.rb
210
240
  - lib/shakapacker/utils/version_syntax_converter.rb
@@ -219,44 +249,68 @@ files:
219
249
  - lib/tasks/shakapacker/clean.rake
220
250
  - lib/tasks/shakapacker/clobber.rake
221
251
  - lib/tasks/shakapacker/compile.rake
252
+ - lib/tasks/shakapacker/doctor.rake
222
253
  - lib/tasks/shakapacker/info.rake
223
254
  - lib/tasks/shakapacker/install.rake
255
+ - lib/tasks/shakapacker/migrate_to_swc.rake
224
256
  - lib/tasks/shakapacker/verify_config.rake
225
257
  - lib/tasks/shakapacker/verify_install.rake
226
258
  - package.json
227
- - package/babel/preset.js
228
- - package/config.js
229
- - package/dev_server.js
230
- - package/env.js
231
- - package/environments/base.js
232
- - package/environments/development.js
233
- - package/environments/production.js
234
- - package/environments/test.js
235
- - package/esbuild/index.js
259
+ - package/.npmignore
260
+ - package/babel/preset.ts
261
+ - package/config.ts
262
+ - package/dev_server.ts
263
+ - package/env.ts
264
+ - package/environments/base.ts
265
+ - package/environments/development.ts
266
+ - package/environments/production.ts
267
+ - package/environments/test.ts
268
+ - package/environments/types.ts
269
+ - package/esbuild/index.ts
236
270
  - package/index.d.ts
237
- - package/index.js
238
- - package/rules/babel.js
239
- - package/rules/coffee.js
240
- - package/rules/css.js
241
- - package/rules/erb.js
242
- - package/rules/esbuild.js
243
- - package/rules/file.js
244
- - package/rules/index.js
245
- - package/rules/jscommon.js
246
- - package/rules/less.js
247
- - package/rules/raw.js
248
- - package/rules/sass.js
249
- - package/rules/stylus.js
250
- - package/rules/swc.js
251
- - package/swc/index.js
252
- - package/utils/configPath.js
253
- - package/utils/defaultConfigPath.js
254
- - package/utils/getStyleRule.js
255
- - package/utils/helpers.js
256
- - package/utils/inliningCss.js
257
- - package/utils/snakeToCamelCase.js
258
- - package/webpackDevServerConfig.js
271
+ - package/index.ts
272
+ - package/loaders.d.ts
273
+ - package/optimization/rspack.ts
274
+ - package/optimization/webpack.ts
275
+ - package/plugins/rspack.ts
276
+ - package/plugins/webpack.ts
277
+ - package/rspack/index.ts
278
+ - package/rules/babel.ts
279
+ - package/rules/coffee.ts
280
+ - package/rules/css.ts
281
+ - package/rules/erb.ts
282
+ - package/rules/esbuild.ts
283
+ - package/rules/file.ts
284
+ - package/rules/jscommon.ts
285
+ - package/rules/less.ts
286
+ - package/rules/raw.ts
287
+ - package/rules/rspack.ts
288
+ - package/rules/sass.ts
289
+ - package/rules/stylus.ts
290
+ - package/rules/swc.ts
291
+ - package/rules/webpack.ts
292
+ - package/swc/index.ts
293
+ - package/types.ts
294
+ - package/types/README.md
295
+ - package/types/index.ts
296
+ - package/utils/configPath.ts
297
+ - package/utils/debug.ts
298
+ - package/utils/defaultConfigPath.ts
299
+ - package/utils/errorCodes.ts
300
+ - package/utils/errorHelpers.ts
301
+ - package/utils/getStyleRule.ts
302
+ - package/utils/helpers.ts
303
+ - package/utils/inliningCss.ts
304
+ - package/utils/pathValidation.ts
305
+ - package/utils/requireOrError.ts
306
+ - package/utils/snakeToCamelCase.ts
307
+ - package/utils/typeGuards.ts
308
+ - package/utils/validateDependencies.ts
309
+ - package/webpack-types.d.ts
310
+ - package/webpackDevServerConfig.ts
259
311
  - prettier.config.js
312
+ - scripts/remove-use-strict.js
313
+ - scripts/type-check-no-emit.js
260
314
  - shakapacker.gemspec
261
315
  - test/helpers.js
262
316
  - test/package/config.test.js
@@ -272,21 +326,31 @@ files:
272
326
  - test/package/rules/babel.test.js
273
327
  - test/package/rules/esbuild.test.js
274
328
  - test/package/rules/file.test.js
275
- - test/package/rules/index.test.js
276
329
  - test/package/rules/raw.test.js
277
330
  - test/package/rules/sass.test.js
278
331
  - test/package/rules/sass1.test.js
279
332
  - test/package/rules/swc.test.js
333
+ - test/package/rules/webpack.test.js
280
334
  - test/package/staging.test.js
281
335
  - test/package/test.test.js
336
+ - test/package/transpiler-defaults.test.js
337
+ - test/peer-dependencies.sh
282
338
  - test/resolver.js
339
+ - test/scripts/remove-use-strict.test.js
340
+ - test/typescript/build.test.js
341
+ - test/typescript/environments.test.js
342
+ - test/typescript/pathValidation.test.js
343
+ - test/typescript/securityValidation.test.js
344
+ - tools/README.md
345
+ - tools/css-modules-v9-codemod.js
346
+ - tsconfig.eslint.json
347
+ - tsconfig.json
283
348
  - yarn.lock
284
349
  homepage: https://github.com/shakacode/shakapacker
285
350
  licenses:
286
351
  - MIT
287
352
  metadata:
288
- source_code_uri: https://github.com/shakacode/shakapacker/tree/v8.4.0
289
- post_install_message:
353
+ source_code_uri: https://github.com/shakacode/shakapacker/tree/v9.0.0
290
354
  rdoc_options: []
291
355
  require_paths:
292
356
  - lib
@@ -301,8 +365,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
365
  - !ruby/object:Gem::Version
302
366
  version: '0'
303
367
  requirements: []
304
- rubygems_version: 3.5.22
305
- signing_key:
368
+ rubygems_version: 3.6.7
306
369
  specification_version: 4
307
370
  summary: Use webpack to manage app-like JavaScript modules in Rails
308
371
  test_files:
@@ -320,11 +383,18 @@ test_files:
320
383
  - test/package/rules/babel.test.js
321
384
  - test/package/rules/esbuild.test.js
322
385
  - test/package/rules/file.test.js
323
- - test/package/rules/index.test.js
324
386
  - test/package/rules/raw.test.js
325
387
  - test/package/rules/sass.test.js
326
388
  - test/package/rules/sass1.test.js
327
389
  - test/package/rules/swc.test.js
390
+ - test/package/rules/webpack.test.js
328
391
  - test/package/staging.test.js
329
392
  - test/package/test.test.js
393
+ - test/package/transpiler-defaults.test.js
394
+ - test/peer-dependencies.sh
330
395
  - test/resolver.js
396
+ - test/scripts/remove-use-strict.test.js
397
+ - test/typescript/build.test.js
398
+ - test/typescript/environments.test.js
399
+ - test/typescript/pathValidation.test.js
400
+ - test/typescript/securityValidation.test.js
@@ -1,48 +0,0 @@
1
- const { moduleExists, packageFullVersion } = require("../utils/helpers")
2
-
3
- const coreJsVersion = () => {
4
- try {
5
- return packageFullVersion("core-js").match(/^\d+\.\d+/)[0]
6
- } catch (e) {
7
- if (e.code !== "MODULE_NOT_FOUND") {
8
- throw e
9
- }
10
-
11
- return "3.8"
12
- }
13
- }
14
-
15
- /** @param api {import("@babel/core").ConfigAPI} */
16
- module.exports = function config(api) {
17
- const validEnv = ["development", "test", "production"]
18
- const currentEnv = api.env()
19
- const isDevelopmentEnv = api.env("development")
20
- const isProductionEnv = api.env("production")
21
- const isTestEnv = api.env("test")
22
-
23
- if (!validEnv.includes(currentEnv)) {
24
- throw new Error(
25
- `Please specify a valid NODE_ENV or BABEL_ENV environment variable. Valid values are "development", "test", and "production". Instead, received: "${currentEnv}".`
26
- )
27
- }
28
-
29
- return {
30
- presets: [
31
- isTestEnv && ["@babel/preset-env", { targets: { node: "current" } }],
32
- (isProductionEnv || isDevelopmentEnv) && [
33
- "@babel/preset-env",
34
- {
35
- useBuiltIns: "entry",
36
- corejs: coreJsVersion(),
37
- modules: "auto",
38
- bugfixes: true,
39
- exclude: ["transform-typeof-symbol"]
40
- }
41
- ],
42
- moduleExists("@babel/preset-typescript") && "@babel/preset-typescript"
43
- ].filter(Boolean),
44
- plugins: [["@babel/plugin-transform-runtime", { helpers: false }]].filter(
45
- Boolean
46
- )
47
- }
48
- }
data/package/config.js DELETED
@@ -1,56 +0,0 @@
1
- const { resolve } = require("path")
2
- const { load } = require("js-yaml")
3
- const { existsSync, readFileSync } = require("fs")
4
-
5
- const { merge } = require("webpack-merge")
6
- const { ensureTrailingSlash } = require("./utils/helpers")
7
- const { railsEnv } = require("./env")
8
- const configPath = require("./utils/configPath")
9
-
10
- const defaultConfigPath = require("./utils/defaultConfigPath")
11
-
12
- const getDefaultConfig = () => {
13
- const defaultConfig = load(readFileSync(defaultConfigPath), "utf8")
14
- return defaultConfig[railsEnv] || defaultConfig.production
15
- }
16
-
17
- const defaults = getDefaultConfig()
18
- let config
19
-
20
- if (existsSync(configPath)) {
21
- const appYmlObject = load(readFileSync(configPath), "utf8")
22
- const envAppConfig = appYmlObject[railsEnv]
23
-
24
- if (!envAppConfig) {
25
- /* eslint no-console:0 */
26
- console.warn(
27
- `Warning: ${railsEnv} key not found in the configuration file. Using production configuration as a fallback.`
28
- )
29
- }
30
-
31
- config = merge(defaults, envAppConfig || {})
32
- } else {
33
- config = merge(defaults, {})
34
- }
35
-
36
- config.outputPath = resolve(config.public_root_path, config.public_output_path)
37
-
38
- // Ensure that the publicPath includes our asset host so dynamic imports
39
- // (code-splitting chunks and static assets) load from the CDN instead of a relative path.
40
- const getPublicPath = () => {
41
- const rootUrl = ensureTrailingSlash(process.env.SHAKAPACKER_ASSET_HOST || "/")
42
- return `${rootUrl}${config.public_output_path}/`
43
- }
44
-
45
- config.publicPath = getPublicPath()
46
- config.publicPathWithoutCDN = `/${config.public_output_path}/`
47
-
48
- if (config.manifest_path) {
49
- config.manifestPath = resolve(config.manifest_path)
50
- } else {
51
- config.manifestPath = resolve(config.outputPath, "manifest.json")
52
- }
53
- // Ensure no duplicate hash functions exist in the returned config object
54
- config.integrity.hash_functions = [...new Set(config.integrity.hash_functions)]
55
-
56
- module.exports = config
data/package/env.js DELETED
@@ -1,48 +0,0 @@
1
- const { load } = require("js-yaml")
2
- const { readFileSync } = require("fs")
3
- const defaultConfigPath = require("./utils/defaultConfigPath")
4
-
5
- const NODE_ENVIRONMENTS = ["development", "production", "test"]
6
- const DEFAULT = "production"
7
- const configPath = require("./utils/configPath")
8
-
9
- const railsEnv = process.env.RAILS_ENV
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"
15
-
16
- let config
17
- try {
18
- config = load(readFileSync(configPath), "utf8")
19
- } catch (error) {
20
- if (error.code === "ENOENT") {
21
- // File not found, use default configuration
22
- config = load(readFileSync(defaultConfigPath), "utf8")
23
- } else {
24
- throw error
25
- }
26
- }
27
-
28
- const availableEnvironments = Object.keys(config).join("|")
29
- const regex = new RegExp(`^(${availableEnvironments})$`, "g")
30
-
31
- const runningWebpackDevServer = process.env.WEBPACK_SERVE === "true"
32
-
33
- const validatedRailsEnv = railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT
34
-
35
- if (railsEnv && validatedRailsEnv !== railsEnv) {
36
- /* eslint no-console:0 */
37
- console.warn(
38
- `Warning: '${railsEnv}' environment not found in the configuration. Using '${DEFAULT}' configuration as a fallback.`
39
- )
40
- }
41
-
42
- module.exports = {
43
- railsEnv: validatedRailsEnv,
44
- nodeEnv,
45
- isProduction,
46
- isDevelopment,
47
- runningWebpackDevServer
48
- }
@@ -1,171 +0,0 @@
1
- /* eslint global-require: 0 */
2
- /* eslint import/no-dynamic-require: 0 */
3
-
4
- const { existsSync, readdirSync } = require("fs")
5
- const { basename, dirname, join, relative, resolve } = require("path")
6
- const extname = require("path-complete-extname")
7
- // TODO: Change to `const { WebpackAssetsManifest }` when dropping 'webpack-assets-manifest < 6.0.0' (Node >=20.10.0) support
8
- const WebpackAssetsManifest = require("webpack-assets-manifest")
9
- const webpack = require("webpack")
10
- const rules = require("../rules")
11
- const config = require("../config")
12
- const { isProduction } = require("../env")
13
- const { moduleExists } = require("../utils/helpers")
14
-
15
- const getFilesInDirectory = (dir, includeNested) => {
16
- if (!existsSync(dir)) {
17
- return []
18
- }
19
-
20
- return readdirSync(dir, { withFileTypes: true }).flatMap((dirent) => {
21
- const filePath = join(dir, dirent.name)
22
-
23
- if (dirent.isDirectory() && includeNested) {
24
- return getFilesInDirectory(filePath, includeNested)
25
- }
26
- if (dirent.isFile()) {
27
- return filePath
28
- }
29
- return []
30
- })
31
- }
32
-
33
- const getEntryObject = () => {
34
- const entries = {}
35
- const rootPath = join(config.source_path, config.source_entry_path)
36
- if (config.source_entry_path === "/" && config.nested_entries) {
37
- throw new Error(
38
- "Your shakapacker config specified using a source_entry_path of '/' with 'nested_entries' == " +
39
- "'true'. Doing this would result in packs for every one of your source files"
40
- )
41
- }
42
-
43
- getFilesInDirectory(rootPath, config.nested_entries).forEach((path) => {
44
- const namespace = relative(join(rootPath), dirname(path))
45
- const name = join(namespace, basename(path, extname(path)))
46
- let assetPaths = resolve(path)
47
-
48
- // Allows for multiple filetypes per entry (https://webpack.js.org/guides/entry-advanced/)
49
- // Transforms the config object value to an array with all values under the same name
50
- let previousPaths = entries[name]
51
- if (previousPaths) {
52
- previousPaths = Array.isArray(previousPaths)
53
- ? previousPaths
54
- : [previousPaths]
55
- previousPaths.push(assetPaths)
56
- assetPaths = previousPaths
57
- }
58
-
59
- entries[name] = assetPaths
60
- })
61
-
62
- return entries
63
- }
64
-
65
- const getModulePaths = () => {
66
- const result = [resolve(config.source_path)]
67
-
68
- if (config.additional_paths) {
69
- config.additional_paths.forEach((path) => result.push(resolve(path)))
70
- }
71
- result.push("node_modules")
72
-
73
- return result
74
- }
75
-
76
- // TODO: Remove WebpackAssetsManifestConstructor workaround when dropping 'webpack-assets-manifest < 6.0.0' (Node >=20.10.0) support
77
- const WebpackAssetsManifestConstructor =
78
- "WebpackAssetsManifest" in WebpackAssetsManifest
79
- ? WebpackAssetsManifest.WebpackAssetsManifest
80
- : WebpackAssetsManifest
81
- const getPlugins = () => {
82
- const plugins = [
83
- new webpack.EnvironmentPlugin(process.env),
84
- new WebpackAssetsManifestConstructor({
85
- entrypoints: true,
86
- writeToDisk: true,
87
- output: config.manifestPath,
88
- entrypointsUseAssets: true,
89
- publicPath: config.publicPathWithoutCDN,
90
- integrity: config.integrity.enabled,
91
- integrityHashes: config.integrity.hash_functions
92
- })
93
- ]
94
-
95
- if (moduleExists("css-loader") && moduleExists("mini-css-extract-plugin")) {
96
- const hash = isProduction || config.useContentHash ? "-[contenthash:8]" : ""
97
- const MiniCssExtractPlugin = require("mini-css-extract-plugin")
98
- plugins.push(
99
- new MiniCssExtractPlugin({
100
- filename: `css/[name]${hash}.css`,
101
- chunkFilename: `css/[id]${hash}.css`,
102
- // For projects where css ordering has been mitigated through consistent use of scoping or naming conventions,
103
- // the css order warnings can be disabled by setting the ignoreOrder flag.
104
- // Read: https://stackoverflow.com/questions/51971857/mini-css-extract-plugin-warning-in-chunk-chunkname-mini-css-extract-plugin-con
105
- ignoreOrder: config.css_extract_ignore_order_warnings
106
- })
107
- )
108
- }
109
-
110
- if (
111
- moduleExists("webpack-subresource-integrity") &&
112
- config.integrity.enabled
113
- ) {
114
- const {
115
- SubresourceIntegrityPlugin
116
- } = require("webpack-subresource-integrity")
117
-
118
- plugins.push(
119
- new SubresourceIntegrityPlugin({
120
- hashFuncNames: config.integrity.hash_functions,
121
- enabled: isProduction
122
- })
123
- )
124
- }
125
-
126
- return plugins
127
- }
128
-
129
- // Don't use contentHash except for production for performance
130
- // https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
131
- const hash = isProduction || config.useContentHash ? "-[contenthash]" : ""
132
-
133
- module.exports = {
134
- mode: "production",
135
- output: {
136
- filename: `js/[name]${hash}.js`,
137
- chunkFilename: `js/[name]${hash}.chunk.js`,
138
-
139
- // https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
140
- hotUpdateChunkFilename: "js/[id].[fullhash].hot-update.js",
141
- path: config.outputPath,
142
- publicPath: config.publicPath,
143
-
144
- // This is required for SRI to work.
145
- crossOriginLoading: config.integrity.enabled
146
- ? config.integrity.cross_origin
147
- : false
148
- },
149
- entry: getEntryObject(),
150
- resolve: {
151
- extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".coffee"],
152
- modules: getModulePaths()
153
- },
154
-
155
- plugins: getPlugins(),
156
-
157
- resolveLoader: {
158
- modules: ["node_modules"]
159
- },
160
-
161
- optimization: {
162
- splitChunks: { chunks: "all" },
163
-
164
- runtimeChunk: "single"
165
- },
166
-
167
- module: {
168
- strictExportPresence: true,
169
- rules
170
- }
171
- }
@@ -1,13 +0,0 @@
1
- const { merge } = require("webpack-merge")
2
-
3
- const baseConfig = require("./base")
4
- const webpackDevServerConfig = require("../webpackDevServerConfig")
5
- const { runningWebpackDevServer } = require("../env")
6
-
7
- const devConfig = {
8
- mode: "development",
9
- devtool: "cheap-module-source-map",
10
- ...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
11
- }
12
-
13
- module.exports = merge(baseConfig, devConfig)