shakapacker 9.0.0.beta.5 → 9.0.0.beta.7

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +1 -0
  3. data/.github/workflows/claude-code-review.yml +1 -1
  4. data/.github/workflows/generator.yml +6 -0
  5. data/.github/workflows/test-bundlers.yml +9 -9
  6. data/.gitignore +0 -1
  7. data/.npmignore +55 -0
  8. data/CONTRIBUTING.md +64 -0
  9. data/Gemfile.lock +1 -1
  10. data/README.md +81 -0
  11. data/docs/optional-peer-dependencies.md +198 -0
  12. data/docs/transpiler-migration.md +191 -0
  13. data/docs/typescript-migration.md +378 -0
  14. data/docs/v9_upgrade.md +65 -1
  15. data/lib/install/template.rb +54 -7
  16. data/lib/shakapacker/doctor.rb +1 -2
  17. data/lib/shakapacker/version.rb +1 -1
  18. data/package/.npmignore +4 -0
  19. data/package/config.ts +23 -10
  20. data/package/env.ts +15 -2
  21. data/package/environments/base.ts +2 -1
  22. data/package/environments/{development.js → development.ts} +30 -8
  23. data/package/environments/{production.js → production.ts} +18 -4
  24. data/package/environments/test.ts +53 -0
  25. data/package/environments/types.ts +90 -0
  26. data/package/index.ts +2 -1
  27. data/package/loaders.d.ts +1 -0
  28. data/package/types/README.md +87 -0
  29. data/package/types/index.ts +60 -0
  30. data/package/utils/errorCodes.ts +219 -0
  31. data/package/utils/errorHelpers.ts +68 -2
  32. data/package/utils/pathValidation.ts +139 -0
  33. data/package/utils/typeGuards.ts +161 -47
  34. data/package/webpack-types.d.ts +1 -0
  35. data/package.json +111 -5
  36. data/scripts/remove-use-strict.js +45 -0
  37. data/test/package/transpiler-defaults.test.js +127 -0
  38. data/test/peer-dependencies.sh +85 -0
  39. data/test/scripts/remove-use-strict.test.js +125 -0
  40. data/test/typescript/build.test.js +3 -2
  41. data/test/typescript/environments.test.js +107 -0
  42. data/test/typescript/pathValidation.test.js +142 -0
  43. data/test/typescript/securityValidation.test.js +182 -0
  44. metadata +28 -6
  45. data/package/environments/base.js +0 -116
  46. data/package/environments/test.js +0 -19
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shakapacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.0.beta.5
4
+ version: 9.0.0.beta.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -147,6 +147,7 @@ files:
147
147
  - ".github/workflows/test-bundlers.yml"
148
148
  - ".gitignore"
149
149
  - ".node-version"
150
+ - ".npmignore"
150
151
  - ".rspec"
151
152
  - ".rubocop.yml"
152
153
  - ".yalcignore"
@@ -172,6 +173,7 @@ files:
172
173
  - docs/customizing_babel_config.md
173
174
  - docs/deployment.md
174
175
  - docs/developing_shakapacker.md
176
+ - docs/optional-peer-dependencies.md
175
177
  - docs/peer-dependencies.md
176
178
  - docs/react.md
177
179
  - docs/rspack.md
@@ -179,8 +181,10 @@ files:
179
181
  - docs/sprockets.md
180
182
  - docs/style_loader_vs_mini_css.md
181
183
  - docs/subresource_integrity.md
184
+ - docs/transpiler-migration.md
182
185
  - docs/transpiler-performance.md
183
186
  - docs/troubleshooting.md
187
+ - docs/typescript-migration.md
184
188
  - docs/typescript.md
185
189
  - docs/using_esbuild_loader.md
186
190
  - docs/using_swc_loader.md
@@ -247,15 +251,16 @@ files:
247
251
  - lib/tasks/shakapacker/verify_config.rake
248
252
  - lib/tasks/shakapacker/verify_install.rake
249
253
  - package.json
254
+ - package/.npmignore
250
255
  - package/babel/preset.js
251
256
  - package/config.ts
252
257
  - package/dev_server.ts
253
258
  - package/env.ts
254
- - package/environments/base.js
255
259
  - package/environments/base.ts
256
- - package/environments/development.js
257
- - package/environments/production.js
258
- - package/environments/test.js
260
+ - package/environments/development.ts
261
+ - package/environments/production.ts
262
+ - package/environments/test.ts
263
+ - package/environments/types.ts
259
264
  - package/esbuild/index.js
260
265
  - package/index.d.ts
261
266
  - package/index.ts
@@ -281,13 +286,17 @@ files:
281
286
  - package/rules/webpack.js
282
287
  - package/swc/index.js
283
288
  - package/types.ts
289
+ - package/types/README.md
290
+ - package/types/index.ts
284
291
  - package/utils/configPath.ts
285
292
  - package/utils/debug.ts
286
293
  - package/utils/defaultConfigPath.ts
294
+ - package/utils/errorCodes.ts
287
295
  - package/utils/errorHelpers.ts
288
296
  - package/utils/getStyleRule.ts
289
297
  - package/utils/helpers.ts
290
298
  - package/utils/inliningCss.ts
299
+ - package/utils/pathValidation.ts
291
300
  - package/utils/requireOrError.ts
292
301
  - package/utils/snakeToCamelCase.ts
293
302
  - package/utils/typeGuards.ts
@@ -295,6 +304,7 @@ files:
295
304
  - package/webpack-types.d.ts
296
305
  - package/webpackDevServerConfig.ts
297
306
  - prettier.config.js
307
+ - scripts/remove-use-strict.js
298
308
  - shakapacker.gemspec
299
309
  - test/helpers.js
300
310
  - test/package/config.test.js
@@ -317,8 +327,14 @@ files:
317
327
  - test/package/rules/webpack.test.js
318
328
  - test/package/staging.test.js
319
329
  - test/package/test.test.js
330
+ - test/package/transpiler-defaults.test.js
331
+ - test/peer-dependencies.sh
320
332
  - test/resolver.js
333
+ - test/scripts/remove-use-strict.test.js
321
334
  - test/typescript/build.test.js
335
+ - test/typescript/environments.test.js
336
+ - test/typescript/pathValidation.test.js
337
+ - test/typescript/securityValidation.test.js
322
338
  - tools/README.md
323
339
  - tools/css-modules-v9-codemod.js
324
340
  - tsconfig.json
@@ -327,7 +343,7 @@ homepage: https://github.com/shakacode/shakapacker
327
343
  licenses:
328
344
  - MIT
329
345
  metadata:
330
- source_code_uri: https://github.com/shakacode/shakapacker/tree/v9.0.0.beta.5
346
+ source_code_uri: https://github.com/shakacode/shakapacker/tree/v9.0.0.beta.7
331
347
  rdoc_options: []
332
348
  require_paths:
333
349
  - lib
@@ -367,5 +383,11 @@ test_files:
367
383
  - test/package/rules/webpack.test.js
368
384
  - test/package/staging.test.js
369
385
  - test/package/test.test.js
386
+ - test/package/transpiler-defaults.test.js
387
+ - test/peer-dependencies.sh
370
388
  - test/resolver.js
389
+ - test/scripts/remove-use-strict.test.js
371
390
  - test/typescript/build.test.js
391
+ - test/typescript/environments.test.js
392
+ - test/typescript/pathValidation.test.js
393
+ - test/typescript/securityValidation.test.js
@@ -1,116 +0,0 @@
1
- /* eslint global-require: 0 */
2
- /* eslint import/no-dynamic-require: 0 */
3
- const { basename, dirname, join, relative, resolve } = require("path")
4
- const { existsSync, readdirSync } = require("fs")
5
- const extname = require("path-complete-extname")
6
- const config = require("../config")
7
- const { isProduction } = require("../env")
8
-
9
- const pluginsPath = resolve(
10
- __dirname,
11
- "..",
12
- "plugins",
13
- `${config.assets_bundler}.js`
14
- )
15
- const { getPlugins } = require(pluginsPath)
16
- const rulesPath = resolve(
17
- __dirname,
18
- "..",
19
- "rules",
20
- `${config.assets_bundler}.js`
21
- )
22
- const rules = require(rulesPath)
23
-
24
- // Don't use contentHash except for production for performance
25
- // https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
26
- const hash = isProduction || config.useContentHash ? "-[contenthash]" : ""
27
- const getFilesInDirectory = (dir, includeNested) => {
28
- if (!existsSync(dir)) {
29
- return []
30
- }
31
- return readdirSync(dir, { withFileTypes: true }).flatMap((dirent) => {
32
- const filePath = join(dir, dirent.name)
33
- if (dirent.isDirectory() && includeNested) {
34
- return getFilesInDirectory(filePath, includeNested)
35
- }
36
- if (dirent.isFile()) {
37
- return filePath
38
- }
39
- return []
40
- })
41
- }
42
- const getEntryObject = () => {
43
- const entries = {}
44
- const rootPath = join(config.source_path, config.source_entry_path)
45
- if (config.source_entry_path === "/" && config.nested_entries) {
46
- throw new Error(
47
- `Invalid Shakapacker configuration detected!\n\n` +
48
- `You have set source_entry_path to '/' with nested_entries enabled.\n` +
49
- `This would create webpack entry points for EVERY file in your source directory,\n` +
50
- `which would severely impact build performance.\n\n` +
51
- `To fix this issue, either:\n` +
52
- `1. Set 'nested_entries: false' in your shakapacker.yml\n` +
53
- `2. Change 'source_entry_path' to a specific subdirectory (e.g., 'packs')\n` +
54
- `3. Or use both options for better organization of your entry points`
55
- )
56
- }
57
- getFilesInDirectory(rootPath, config.nested_entries).forEach((path) => {
58
- const namespace = relative(join(rootPath), dirname(path))
59
- const name = join(namespace, basename(path, extname(path)))
60
- const assetPath = resolve(path)
61
- // Allows for multiple filetypes per entry (https://webpack.js.org/guides/entry-advanced/)
62
- // Transforms the config object value to an array with all values under the same name
63
- const previousPaths = entries[name]
64
- if (previousPaths) {
65
- const pathArray = Array.isArray(previousPaths)
66
- ? previousPaths
67
- : [previousPaths]
68
- pathArray.push(assetPath)
69
- entries[name] = pathArray
70
- } else {
71
- entries[name] = assetPath
72
- }
73
- })
74
- return entries
75
- }
76
- const getModulePaths = () => {
77
- const result = [resolve(config.source_path)]
78
- if (config.additional_paths) {
79
- config.additional_paths.forEach((path) => result.push(resolve(path)))
80
- }
81
- result.push("node_modules")
82
- return result
83
- }
84
- const baseConfig = {
85
- mode: "production",
86
- output: {
87
- filename: `js/[name]${hash}.js`,
88
- chunkFilename: `js/[name]${hash}.chunk.js`,
89
- // https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
90
- hotUpdateChunkFilename: "js/[id].[fullhash].hot-update.js",
91
- path: config.outputPath,
92
- publicPath: config.publicPath,
93
- // This is required for SRI to work.
94
- crossOriginLoading:
95
- config.integrity && config.integrity.enabled
96
- ? config.integrity.cross_origin
97
- : false
98
- },
99
- entry: getEntryObject(),
100
- resolve: {
101
- extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".coffee"],
102
- modules: getModulePaths()
103
- },
104
- plugins: getPlugins(),
105
- resolveLoader: {
106
- modules: ["node_modules"]
107
- },
108
- optimization: {
109
- splitChunks: { chunks: "all" },
110
- runtimeChunk: "single"
111
- },
112
- module: {
113
- rules
114
- }
115
- }
116
- module.exports = baseConfig
@@ -1,19 +0,0 @@
1
- const { merge } = require("webpack-merge")
2
- const config = require("../config")
3
- const baseConfig = require("./base")
4
-
5
- const rspackTestConfig = () => ({
6
- mode: "development",
7
- devtool: "cheap-module-source-map",
8
- // Disable file watching in test mode
9
- watchOptions: {
10
- ignored: /node_modules/
11
- }
12
- })
13
-
14
- const webpackTestConfig = () => ({})
15
-
16
- const bundlerConfig =
17
- config.assets_bundler === "rspack" ? rspackTestConfig() : webpackTestConfig()
18
-
19
- module.exports = merge(baseConfig, bundlerConfig)