shakapacker 9.0.0.beta.0 → 9.0.0.beta.2

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/claude-code-review.yml +54 -0
  3. data/.github/workflows/claude.yml +50 -0
  4. data/.rubocop.yml +1 -0
  5. data/CHANGELOG.md +6 -2
  6. data/Gemfile.lock +1 -1
  7. data/Rakefile +18 -1
  8. data/docs/rspack.md +7 -7
  9. data/docs/rspack_migration_guide.md +202 -0
  10. data/docs/using_esbuild_loader.md +3 -3
  11. data/docs/using_swc_loader.md +5 -3
  12. data/lib/install/bin/shakapacker +3 -17
  13. data/lib/install/config/shakapacker.yml +5 -4
  14. data/lib/shakapacker/configuration.rb +36 -3
  15. data/lib/shakapacker/dev_server_runner.rb +19 -9
  16. data/lib/shakapacker/manifest.rb +4 -3
  17. data/lib/shakapacker/rspack_runner.rb +4 -42
  18. data/lib/shakapacker/runner.rb +105 -11
  19. data/lib/shakapacker/utils/manager.rb +2 -0
  20. data/lib/shakapacker/version.rb +1 -1
  21. data/lib/shakapacker/version_checker.rb +1 -1
  22. data/lib/shakapacker/webpack_runner.rb +4 -42
  23. data/lib/tasks/shakapacker/install.rake +6 -2
  24. data/package/config.js +24 -0
  25. data/package/environments/base.js +12 -2
  26. data/package/environments/development.js +52 -12
  27. data/package/environments/production.js +8 -3
  28. data/package/environments/test.js +5 -3
  29. data/package/index.d.ts +57 -29
  30. data/package/index.js +1 -1
  31. data/package/optimization/rspack.js +9 -5
  32. data/package/plugins/rspack.js +12 -28
  33. data/package/rspack/index.js +57 -0
  34. data/package/rules/babel.js +2 -2
  35. data/package/rules/esbuild.js +2 -2
  36. data/package/rules/raw.js +5 -5
  37. data/package/rules/rspack.js +73 -7
  38. data/package/rules/swc.js +2 -2
  39. data/package/utils/debug.js +49 -0
  40. data/package/utils/getStyleRule.js +3 -3
  41. data/package/utils/requireOrError.js +1 -1
  42. data/package/utils/validateDependencies.js +61 -0
  43. data/package/webpackDevServerConfig.js +2 -0
  44. data/package.json +1 -1
  45. data/test/package/rules/esbuild.test.js +1 -1
  46. data/test/package/rules/swc.test.js +1 -1
  47. metadata +8 -3
  48. data/lib/install/bin/shakapacker-rspack +0 -13
@@ -4,48 +4,10 @@ require_relative "runner"
4
4
 
5
5
  module Shakapacker
6
6
  class RspackRunner < Shakapacker::Runner
7
- RSPACK_COMMANDS = [
8
- "help",
9
- "h",
10
- "--help",
11
- "-h",
12
- "version",
13
- "v",
14
- "--version",
15
- "-v",
16
- "info",
17
- "i"
18
- ].freeze
19
-
20
- def run
21
- env = Shakapacker::Compiler.env
22
- env["SHAKAPACKER_CONFIG"] = @shakapacker_config
23
- env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""
24
-
25
- cmd = build_cmd
26
-
27
- if @argv.delete("--debug-shakapacker")
28
- env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk"
29
- end
30
-
31
- if @argv.delete "--trace-deprecation"
32
- env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --trace-deprecation"
33
- end
34
-
35
- if @argv.delete "--no-deprecation"
36
- env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --no-deprecation"
37
- end
38
-
39
- # Rspack commands are not compatible with --config option.
40
- if (@argv & RSPACK_COMMANDS).empty?
41
- cmd += ["--config", @webpack_config]
42
- end
43
-
44
- cmd += @argv
45
-
46
- Dir.chdir(@app_path) do
47
- Kernel.exec env, *cmd
48
- end
7
+ def self.run(argv)
8
+ $stdout.sync = true
9
+ ENV["NODE_ENV"] ||= (ENV["RAILS_ENV"] == "production") ? "production" : "development"
10
+ new(argv).run
49
11
  end
50
12
 
51
13
  private
@@ -7,10 +7,54 @@ require "pathname"
7
7
 
8
8
  module Shakapacker
9
9
  class Runner
10
+ attr_reader :config
11
+
12
+ # Common commands that don't work with --config option
13
+ BASE_COMMANDS = [
14
+ "help",
15
+ "h",
16
+ "--help",
17
+ "-h",
18
+ "version",
19
+ "v",
20
+ "--version",
21
+ "-v",
22
+ "info",
23
+ "i"
24
+ ].freeze
10
25
  def self.run(argv)
11
26
  $stdout.sync = true
12
27
  ENV["NODE_ENV"] ||= (ENV["RAILS_ENV"] == "production") ? "production" : "development"
13
- new(argv).run
28
+
29
+ # Create a single runner instance to avoid loading configuration twice.
30
+ # We extend it with the appropriate build command based on the bundler type.
31
+ runner = new(argv)
32
+
33
+ if runner.config.rspack?
34
+ require_relative "rspack_runner"
35
+ # Extend the runner instance with rspack-specific methods
36
+ # This avoids creating a new RspackRunner which would reload the configuration
37
+ runner.extend(Module.new do
38
+ def build_cmd
39
+ package_json.manager.native_exec_command("rspack")
40
+ end
41
+
42
+ def assets_bundler_commands
43
+ BASE_COMMANDS + %w[build watch]
44
+ end
45
+ end)
46
+ runner.run
47
+ else
48
+ require_relative "webpack_runner"
49
+ # Extend the runner instance with webpack-specific methods
50
+ # This avoids creating a new WebpackRunner which would reload the configuration
51
+ runner.extend(Module.new do
52
+ def build_cmd
53
+ package_json.manager.native_exec_command("webpack")
54
+ end
55
+ end)
56
+ runner.run
57
+ end
14
58
  end
15
59
 
16
60
  def initialize(argv)
@@ -23,7 +67,7 @@ module Shakapacker
23
67
  config_path: Pathname.new(@shakapacker_config),
24
68
  env: ENV["RAILS_ENV"] || ENV["NODE_ENV"] || "development"
25
69
  )
26
- @webpack_config = find_bundler_config
70
+ @webpack_config = find_assets_bundler_config
27
71
 
28
72
  Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
29
73
  end
@@ -32,8 +76,55 @@ module Shakapacker
32
76
  @package_json ||= PackageJson.read(@app_path)
33
77
  end
34
78
 
79
+ def run
80
+ puts "[Shakapacker] Preparing environment for assets bundler execution..."
81
+ env = Shakapacker::Compiler.env
82
+ env["SHAKAPACKER_CONFIG"] = @shakapacker_config
83
+ env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""
84
+
85
+ cmd = build_cmd
86
+ puts "[Shakapacker] Base command: #{cmd.join(" ")}"
87
+
88
+ if @argv.delete("--debug-shakapacker")
89
+ puts "[Shakapacker] Debug mode enabled (--debug-shakapacker)"
90
+ env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk"
91
+ end
92
+
93
+ if @argv.delete "--trace-deprecation"
94
+ puts "[Shakapacker] Trace deprecation enabled (--trace-deprecation)"
95
+ env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --trace-deprecation"
96
+ end
97
+
98
+ if @argv.delete "--no-deprecation"
99
+ puts "[Shakapacker] Deprecation warnings disabled (--no-deprecation)"
100
+ env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --no-deprecation"
101
+ end
102
+
103
+ # Commands are not compatible with --config option.
104
+ if (@argv & assets_bundler_commands).empty?
105
+ puts "[Shakapacker] Adding config file: #{@webpack_config}"
106
+ cmd += ["--config", @webpack_config]
107
+ else
108
+ puts "[Shakapacker] Skipping config file (running assets bundler command: #{(@argv & assets_bundler_commands).join(", ")})"
109
+ end
110
+
111
+ cmd += @argv
112
+ puts "[Shakapacker] Final command: #{cmd.join(" ")}"
113
+ puts "[Shakapacker] Working directory: #{@app_path}"
114
+
115
+ Dir.chdir(@app_path) do
116
+ Kernel.exec env, *cmd
117
+ end
118
+ end
119
+
120
+ protected
121
+
122
+ def assets_bundler_commands
123
+ BASE_COMMANDS
124
+ end
125
+
35
126
  private
36
- def find_bundler_config
127
+ def find_assets_bundler_config
37
128
  if @config.rspack?
38
129
  find_rspack_config_with_fallback
39
130
  else
@@ -41,34 +132,35 @@ module Shakapacker
41
132
  end
42
133
  end
43
134
 
44
- def get_bundler_type
45
- @config.bundler
46
- end
47
-
48
135
  def find_rspack_config_with_fallback
49
136
  # First try rspack-specific paths
50
137
  rspack_paths = %w[ts js].map do |ext|
51
138
  File.join(@app_path, "config/rspack/rspack.config.#{ext}")
52
139
  end
53
140
 
141
+ puts "[Shakapacker] Looking for Rspack config in: #{rspack_paths.join(", ")}"
54
142
  rspack_path = rspack_paths.find { |f| File.exist?(f) }
55
- return rspack_path if rspack_path
143
+ if rspack_path
144
+ puts "[Shakapacker] Found Rspack config: #{rspack_path}"
145
+ return rspack_path
146
+ end
56
147
 
57
148
  # Fallback to webpack config with deprecation warning
58
149
  webpack_paths = %w[ts js].map do |ext|
59
150
  File.join(@app_path, "config/webpack/webpack.config.#{ext}")
60
151
  end
61
152
 
153
+ puts "[Shakapacker] Rspack config not found, checking for webpack config fallback..."
62
154
  webpack_path = webpack_paths.find { |f| File.exist?(f) }
63
155
  if webpack_path
64
- $stderr.puts "⚠️ DEPRECATION WARNING: Using webpack config file for Rspack bundler."
156
+ $stderr.puts "⚠️ DEPRECATION WARNING: Using webpack config file for Rspack assets bundler."
65
157
  $stderr.puts " Please create config/rspack/rspack.config.js and migrate your configuration."
66
158
  $stderr.puts " Using: #{webpack_path}"
67
159
  return webpack_path
68
160
  end
69
161
 
70
162
  # No config found
71
- $stderr.puts "rspack config #{rspack_paths.last} not found, please run 'bundle exec rails shakapacker:install' to install Shakapacker with default configs or create the missing config file."
163
+ $stderr.puts "[Shakapacker] ERROR: rspack config #{rspack_paths.last} not found, please run 'bundle exec rails shakapacker:install' to install Shakapacker with default configs or create the missing config file."
72
164
  exit(1)
73
165
  end
74
166
 
@@ -76,11 +168,13 @@ module Shakapacker
76
168
  possible_paths = %w[ts js].map do |ext|
77
169
  File.join(@app_path, "config/webpack/webpack.config.#{ext}")
78
170
  end
171
+ puts "[Shakapacker] Looking for Webpack config in: #{possible_paths.join(", ")}"
79
172
  path = possible_paths.find { |f| File.exist?(f) }
80
173
  unless path
81
- $stderr.puts "webpack config #{possible_paths.last} not found, please run 'bundle exec rails shakapacker:install' to install Shakapacker with default configs or add the missing config file for your custom environment."
174
+ $stderr.puts "[Shakapacker] ERROR: webpack config #{possible_paths.last} not found, please run 'bundle exec rails shakapacker:install' to install Shakapacker with default configs or add the missing config file for your custom environment."
82
175
  exit(1)
83
176
  end
177
+ puts "[Shakapacker] Found Webpack config: #{path}"
84
178
  path
85
179
  end
86
180
  end
@@ -58,6 +58,8 @@ module Shakapacker
58
58
  def self.rails_root
59
59
  if defined?(APP_ROOT)
60
60
  Pathname.new(APP_ROOT)
61
+ elsif ENV["APP_ROOT"]
62
+ Pathname.new(ENV["APP_ROOT"])
61
63
  elsif defined?(Rails)
62
64
  Rails.root
63
65
  else
@@ -1,4 +1,4 @@
1
1
  module Shakapacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "9.0.0.beta.0".freeze
3
+ VERSION = "9.0.0.beta.2".freeze
4
4
  end
@@ -126,7 +126,7 @@ module Shakapacker
126
126
  end
127
127
 
128
128
  def relative_path?
129
- raw.match(%r{(\.\.|\Afile:///)}).present?
129
+ raw.match(%r{(\.\.|\Afile:)}).present?
130
130
  end
131
131
 
132
132
  def git_url?
@@ -4,48 +4,10 @@ require_relative "runner"
4
4
 
5
5
  module Shakapacker
6
6
  class WebpackRunner < Shakapacker::Runner
7
- WEBPACK_COMMANDS = [
8
- "help",
9
- "h",
10
- "--help",
11
- "-h",
12
- "version",
13
- "v",
14
- "--version",
15
- "-v",
16
- "info",
17
- "i"
18
- ].freeze
19
-
20
- def run
21
- env = Shakapacker::Compiler.env
22
- env["SHAKAPACKER_CONFIG"] = @shakapacker_config
23
- env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""
24
-
25
- cmd = build_cmd
26
-
27
- if @argv.delete("--debug-shakapacker")
28
- env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk"
29
- end
30
-
31
- if @argv.delete "--trace-deprecation"
32
- env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --trace-deprecation"
33
- end
34
-
35
- if @argv.delete "--no-deprecation"
36
- env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --no-deprecation"
37
- end
38
-
39
- # Webpack commands are not compatible with --config option.
40
- if (@argv & WEBPACK_COMMANDS).empty?
41
- cmd += ["--config", @webpack_config]
42
- end
43
-
44
- cmd += @argv
45
-
46
- Dir.chdir(@app_path) do
47
- Kernel.exec env, *cmd
48
- end
7
+ def self.run(argv)
8
+ $stdout.sync = true
9
+ ENV["NODE_ENV"] ||= (ENV["RAILS_ENV"] == "production") ? "production" : "development"
10
+ new(argv).run
49
11
  end
50
12
 
51
13
  private
@@ -2,10 +2,14 @@ install_template_path = File.expand_path("../../install/template.rb", __dir__).f
2
2
  bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
3
3
 
4
4
  namespace :shakapacker do
5
- desc "Install Shakapacker in this application"
6
- task install: [:check_node] do |task|
5
+ desc "Install Shakapacker in this application (use ASSETS_BUNDLER=rspack for Rspack)"
6
+ task :install, [:bundler] => [:check_node] do |task, args|
7
7
  Shakapacker::Configuration.installing = true
8
8
 
9
+ if args[:bundler] == "rspack" || ENV["ASSETS_BUNDLER"] == "rspack"
10
+ ENV["SHAKAPACKER_ASSETS_BUNDLER"] = "rspack"
11
+ end
12
+
9
13
  prefix = task.name.split(/#|shakapacker:install/).first
10
14
 
11
15
  if Rails::VERSION::MAJOR >= 5
data/package/config.js CHANGED
@@ -53,4 +53,28 @@ if (config.manifest_path) {
53
53
  // Ensure no duplicate hash functions exist in the returned config object
54
54
  config.integrity.hash_functions = [...new Set(config.integrity.hash_functions)]
55
55
 
56
+ // Allow ENV variable to override assets_bundler
57
+ if (process.env.SHAKAPACKER_ASSETS_BUNDLER) {
58
+ config.assets_bundler = process.env.SHAKAPACKER_ASSETS_BUNDLER
59
+ }
60
+
61
+ // Define clear defaults
62
+ const DEFAULT_JAVASCRIPT_TRANSPILER =
63
+ config.assets_bundler === "rspack" ? "swc" : "babel"
64
+
65
+ // Backward compatibility: Add webpack_loader property that maps to javascript_transpiler
66
+ // Show deprecation warning if webpack_loader is used
67
+ if (config.webpack_loader && !config.javascript_transpiler) {
68
+ console.warn(
69
+ "⚠️ DEPRECATION WARNING: The 'webpack_loader' configuration option is deprecated. Please use 'javascript_transpiler' instead as it better reflects its purpose of configuring JavaScript transpilation regardless of the bundler used."
70
+ )
71
+ config.javascript_transpiler = config.webpack_loader
72
+ } else if (!config.javascript_transpiler) {
73
+ config.javascript_transpiler =
74
+ config.webpack_loader || DEFAULT_JAVASCRIPT_TRANSPILER
75
+ }
76
+
77
+ // Ensure webpack_loader is always available for backward compatibility
78
+ config.webpack_loader = config.javascript_transpiler
79
+
56
80
  module.exports = config
@@ -7,9 +7,19 @@ const extname = require("path-complete-extname")
7
7
  const config = require("../config")
8
8
  const { isProduction } = require("../env")
9
9
 
10
- const pluginsPath = resolve(__dirname, "..", "plugins", `${config.bundler}.js`)
10
+ const pluginsPath = resolve(
11
+ __dirname,
12
+ "..",
13
+ "plugins",
14
+ `${config.assets_bundler}.js`
15
+ )
11
16
  const { getPlugins } = require(pluginsPath)
12
- const rulesPath = resolve(__dirname, "..", "rules", `${config.bundler}.js`)
17
+ const rulesPath = resolve(
18
+ __dirname,
19
+ "..",
20
+ "rules",
21
+ `${config.assets_bundler}.js`
22
+ )
13
23
  const rules = require(rulesPath)
14
24
 
15
25
  // Don't use contentHash except for production for performance
@@ -3,26 +3,66 @@ const config = require("../config")
3
3
  const baseConfig = require("./base")
4
4
  const webpackDevServerConfig = require("../webpackDevServerConfig")
5
5
  const { runningWebpackDevServer } = require("../env")
6
+ const { moduleExists } = require("../utils/helpers")
6
7
 
7
- const webpackDevConfig = {
8
+ const baseDevConfig = {
8
9
  mode: "development",
9
- devtool: "cheap-module-source-map",
10
- ...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
10
+ devtool: "cheap-module-source-map"
11
11
  }
12
12
 
13
- const rspackDevConfig = {
14
- mode: "development",
15
- devtool: "cheap-module-source-map",
16
- // Force writing assets to disk in development for Rails compatibility
17
- devServer: {
18
- ...webpackDevServerConfig(),
19
- devMiddleware: {
20
- writeToDisk: true
13
+ const webpackDevConfig = () => {
14
+ const webpackConfig = {
15
+ ...baseDevConfig,
16
+ ...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
17
+ }
18
+
19
+ const devServerConfig = webpackDevServerConfig()
20
+ if (
21
+ runningWebpackDevServer &&
22
+ devServerConfig.hot &&
23
+ moduleExists("@pmmmwh/react-refresh-webpack-plugin")
24
+ ) {
25
+ // eslint-disable-next-line global-require
26
+ const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin")
27
+ webpackConfig.plugins = [
28
+ ...(webpackConfig.plugins || []),
29
+ new ReactRefreshWebpackPlugin()
30
+ ]
31
+ }
32
+
33
+ return webpackConfig
34
+ }
35
+
36
+ const rspackDevConfig = () => {
37
+ const devServerConfig = webpackDevServerConfig()
38
+ const rspackConfig = {
39
+ ...baseDevConfig,
40
+ devServer: {
41
+ ...devServerConfig,
42
+ devMiddleware: {
43
+ ...devServerConfig.devMiddleware,
44
+ writeToDisk: (filePath) => !filePath.includes(".hot-update.")
45
+ }
21
46
  }
22
47
  }
48
+
49
+ if (
50
+ runningWebpackDevServer &&
51
+ devServerConfig.hot &&
52
+ moduleExists("@rspack/plugin-react-refresh")
53
+ ) {
54
+ // eslint-disable-next-line global-require
55
+ const ReactRefreshPlugin = require("@rspack/plugin-react-refresh")
56
+ rspackConfig.plugins = [
57
+ ...(rspackConfig.plugins || []),
58
+ new ReactRefreshPlugin()
59
+ ]
60
+ }
61
+
62
+ return rspackConfig
23
63
  }
24
64
 
25
65
  const bundlerConfig =
26
- config.bundler === "rspack" ? rspackDevConfig : webpackDevConfig
66
+ config.assets_bundler === "rspack" ? rspackDevConfig() : webpackDevConfig()
27
67
 
28
68
  module.exports = merge(baseConfig, bundlerConfig)
@@ -1,14 +1,19 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
- const { merge } = require("webpack-merge")
5
4
  const { resolve } = require("path")
5
+ const { merge } = require("webpack-merge")
6
6
  const baseConfig = require("./base")
7
7
  const { moduleExists } = require("../utils/helpers")
8
8
  const config = require("../config")
9
9
 
10
- const path = resolve(__dirname, "..", "optimization", `${config.bundler}.js`)
11
- const { getOptimization } = require(path)
10
+ const optimizationPath = resolve(
11
+ __dirname,
12
+ "..",
13
+ "optimization",
14
+ `${config.assets_bundler}.js`
15
+ )
16
+ const { getOptimization } = require(optimizationPath)
12
17
 
13
18
  let CompressionPlugin = null
14
19
  if (moduleExists("compression-webpack-plugin")) {
@@ -2,16 +2,18 @@ const { merge } = require("webpack-merge")
2
2
  const config = require("../config")
3
3
  const baseConfig = require("./base")
4
4
 
5
- const rspackTestConfig = {
5
+ const rspackTestConfig = () => ({
6
6
  mode: "development",
7
7
  devtool: "cheap-module-source-map",
8
8
  // Disable file watching in test mode
9
9
  watchOptions: {
10
10
  ignored: /node_modules/
11
11
  }
12
- }
12
+ })
13
+
14
+ const webpackTestConfig = () => ({})
13
15
 
14
16
  const bundlerConfig =
15
- config.bundler === "rspack" ? rspackTestConfig : baseConfig
17
+ config.assets_bundler === "rspack" ? rspackTestConfig() : webpackTestConfig()
16
18
 
17
19
  module.exports = merge(baseConfig, bundlerConfig)
data/package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- declare module 'shakapacker' {
2
- import { Configuration, RuleSetRule } from 'webpack'
3
- import * as https from 'node:https';
1
+ declare module "shakapacker" {
2
+ import { Configuration, RuleSetRule } from "webpack"
3
+ import * as https from "node:https"
4
4
 
5
5
  export interface Config {
6
6
  source_path: string
@@ -14,11 +14,11 @@ declare module 'shakapacker' {
14
14
  shakapacker_precompile: boolean
15
15
  additional_paths: string[]
16
16
  cache_manifest: boolean
17
- webpack_loader: string
17
+ javascript_transpiler: string
18
18
  ensure_consistent_versioning: boolean
19
19
  compiler_strategy: string
20
20
  useContentHash: boolean
21
- compile: boolean,
21
+ compile: boolean
22
22
  outputPath: string
23
23
  publicPath: string
24
24
  publicPathWithoutCDN: string
@@ -33,9 +33,11 @@ declare module 'shakapacker' {
33
33
  runningWebpackDevServer: boolean
34
34
  }
35
35
 
36
- type Header = Array<{ key: string; value: string }> | Record<string, string | string[]>
37
- type ServerType = 'http' | 'https' | 'spdy'
38
- type WebSocketType = 'sockjs' | 'ws'
36
+ type Header =
37
+ | Array<{ key: string; value: string }>
38
+ | Record<string, string | string[]>
39
+ type ServerType = "http" | "https" | "spdy"
40
+ type WebSocketType = "sockjs" | "ws"
39
41
 
40
42
  /**
41
43
  * This has the same keys and behavior as https://webpack.js.org/configuration/dev-server/ except:
@@ -44,59 +46,85 @@ declare module 'shakapacker' {
44
46
  * @see {import('webpack-dev-server').Configuration}
45
47
  */
46
48
  interface DevServerConfig {
47
- allowed_hosts?: 'all' | 'auto' | string | string[]
49
+ allowed_hosts?: "all" | "auto" | string | string[]
48
50
  bonjour?: boolean | Record<string, unknown> // bonjour.BonjourOptions
49
51
  client?: Record<string, unknown> // Client
50
52
  compress?: boolean
51
53
  dev_middleware?: Record<string, unknown> // webpackDevMiddleware.Options
52
54
  headers?: Header | (() => Header)
53
55
  history_api_fallback?: boolean | Record<string, unknown> // HistoryApiFallbackOptions
54
- hmr?: 'only' | boolean
55
- host?: 'local-ip' | 'local-ipv4' | 'local-ipv6' | string
56
+ hmr?: "only" | boolean
57
+ host?: "local-ip" | "local-ipv4" | "local-ipv6" | string
56
58
  http2?: boolean
57
59
  https?: boolean | https.ServerOptions
58
60
  ipc?: boolean | string
59
61
  magic_html?: boolean
60
62
  live_reload?: boolean
61
- open?: boolean | string | string[] | Record<string, unknown> | Record<string, unknown>[]
62
- port?: 'auto' | string | number
63
+ open?:
64
+ | boolean
65
+ | string
66
+ | string[]
67
+ | Record<string, unknown>
68
+ | Record<string, unknown>[]
69
+ port?: "auto" | string | number
63
70
  proxy?: unknown // ProxyConfigMap | ProxyConfigArray
64
71
  setup_exit_signals?: boolean
65
72
  static?: boolean | string | unknown // Static | Array<string | Static>
66
73
  watch_files?: string | string[] | unknown // WatchFiles | Array<WatchFiles | string>
67
- web_socket_server?: string | boolean | WebSocketType | { type?: string | boolean | WebSocketType, options?: Record<string, unknown> }
68
- server?: string | boolean | ServerType | { type?: string | boolean | ServerType, options?: https.ServerOptions }
74
+ web_socket_server?:
75
+ | string
76
+ | boolean
77
+ | WebSocketType
78
+ | {
79
+ type?: string | boolean | WebSocketType
80
+ options?: Record<string, unknown>
81
+ }
82
+ server?:
83
+ | string
84
+ | boolean
85
+ | ServerType
86
+ | { type?: string | boolean | ServerType; options?: https.ServerOptions }
69
87
  [otherWebpackDevServerConfigKey: string]: unknown
70
88
  }
71
89
 
72
90
  export const config: Config
73
91
  export const devServer: DevServerConfig
74
- export function generateWebpackConfig(extraConfig?: Configuration): Configuration
92
+ export function generateWebpackConfig(
93
+ extraConfig?: Configuration
94
+ ): Configuration
75
95
  export const baseConfig: Configuration
76
96
  export const env: Env
77
97
  export const rules: RuleSetRule[]
78
98
  export function moduleExists(packageName: string): boolean
79
- export function canProcess<T = unknown>(rule: string, fn: (modulePath: string) => T): T | null
99
+ export function canProcess<T = unknown>(
100
+ rule: string,
101
+ fn: (modulePath: string) => T
102
+ ): T | null
80
103
  export const inliningCss: boolean
81
- export * from 'webpack-merge'
104
+ export * from "webpack-merge"
82
105
  }
83
106
 
84
- declare module 'shakapacker/rspack' {
85
- import type { RspackOptions, RuleSetRule } from '@rspack/core'
86
-
87
- export const config: Config
88
- export function generateRspackConfig(extraConfig?: RspackOptions): RspackOptions
107
+ declare module "shakapacker/rspack" {
108
+ import type { RspackOptions } from "@rspack/core"
109
+
110
+ export const config: import("shakapacker").Config
111
+ export function generateRspackConfig(
112
+ extraConfig?: RspackOptions
113
+ ): RspackOptions
89
114
  export const baseConfig: RspackOptions
90
- export const env: Env
91
- export const rules: RuleSetRule[]
115
+ export const env: import("shakapacker").Env
116
+ export const rules: NonNullable<RspackOptions["module"]>["rules"]
92
117
  export function moduleExists(packageName: string): boolean
93
- export function canProcess<T = unknown>(rule: string, fn: (modulePath: string) => T): T | null
118
+ export function canProcess<T = unknown>(
119
+ rule: string,
120
+ fn: (modulePath: string) => T
121
+ ): T | null
94
122
  export const inliningCss: boolean
95
- export * from 'webpack-merge'
123
+ export * from "webpack-merge"
96
124
  }
97
125
 
98
- declare module 'shakapacker/package/babel/preset.js' {
99
- import { ConfigAPI, PluginItem, TransformOptions } from '@babel/core'
126
+ declare module "shakapacker/package/babel/preset.js" {
127
+ import { ConfigAPI, PluginItem, TransformOptions } from "@babel/core"
100
128
 
101
129
  interface RequiredTransformOptions {
102
130
  plugins: PluginItem[]
data/package/index.js CHANGED
@@ -7,7 +7,7 @@ const { existsSync } = require("fs")
7
7
  const config = require("./config")
8
8
  const baseConfig = require("./environments/base")
9
9
 
10
- const rulesPath = resolve(__dirname, "rules", `${config.bundler}.js`)
10
+ const rulesPath = resolve(__dirname, "rules", `${config.assets_bundler}.js`)
11
11
  const rules = require(rulesPath)
12
12
  const devServer = require("./dev_server")
13
13
  const env = require("./env")