railpack 1.2.11 → 1.2.13
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.
- checksums.yaml +4 -4
- data/lib/railpack/config.rb +87 -11
- data/lib/railpack/version.rb +1 -1
- metadata +2 -3
- data/sig/railpack.rbs +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7d46c8ec7498a0fb02c689c31efebb07356d887ceb4f2c71b37bc1df4fbf88c2
|
|
4
|
+
data.tar.gz: 2c72739906a7b8639929cf79262d5da8df504449e33c7b9aee6a49af25058550
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95345502072a45a61e3e1b4524c9a49958a7d67c9f99164ddf9e57cefb3fd7beebefcc38e2fd8869bf080151f37003a267a2e92998b9681ef6794b7ed6f5559d
|
|
7
|
+
data.tar.gz: c5a2e13d273eb5a3c765fa02cc0287b35a5600af8723564bef78caa571a5ff34e7cd690d56b61a5695264881fb0c538858088e7fc46e86a8561ad32415044431
|
data/lib/railpack/config.rb
CHANGED
|
@@ -1,13 +1,38 @@
|
|
|
1
1
|
require "yaml"
|
|
2
2
|
|
|
3
3
|
module Railpack
|
|
4
|
+
# Configuration handler for Railpack bundling settings.
|
|
5
|
+
#
|
|
6
|
+
# This class provides immutable, environment-aware configuration management with:
|
|
7
|
+
# - YAML-based config loading from config/railpack.yml
|
|
8
|
+
# - Three-level merge order: defaults → bundler-specific → environment-specific
|
|
9
|
+
# - Deep-frozen configs for immutability and thread safety
|
|
10
|
+
# - Explicit accessors for common config keys with method_missing fallback
|
|
11
|
+
#
|
|
12
|
+
# Example config/railpack.yml:
|
|
13
|
+
# default:
|
|
14
|
+
# bundler: bun
|
|
15
|
+
# outdir: app/assets/builds
|
|
16
|
+
# development:
|
|
17
|
+
# sourcemap: true
|
|
18
|
+
# production:
|
|
19
|
+
# minify: true
|
|
20
|
+
#
|
|
21
|
+
# All configs are immutable after loading. Set values in config/railpack.yml only.
|
|
4
22
|
class Config
|
|
5
23
|
class Error < StandardError; end
|
|
6
24
|
|
|
25
|
+
# Known config keys that get explicit accessors
|
|
26
|
+
CONFIG_KEYS = %w[
|
|
27
|
+
target format minify sourcemap splitting
|
|
28
|
+
entrypoint entrypoints outdir platform mode analyze_bundle
|
|
29
|
+
].freeze
|
|
30
|
+
|
|
7
31
|
attr_reader :config
|
|
8
32
|
|
|
9
33
|
def initialize
|
|
10
34
|
@config = load_config
|
|
35
|
+
@merged_cache = {}
|
|
11
36
|
end
|
|
12
37
|
|
|
13
38
|
def current_env
|
|
@@ -18,13 +43,35 @@ module Railpack
|
|
|
18
43
|
end
|
|
19
44
|
end
|
|
20
45
|
|
|
46
|
+
# Explicit accessors for known config keys
|
|
47
|
+
CONFIG_KEYS.each do |key|
|
|
48
|
+
define_method(key) do |env = current_env|
|
|
49
|
+
for_environment(env)[key]
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
21
53
|
def for_environment(env = current_env)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
54
|
+
@merged_cache[env.to_s] ||= begin
|
|
55
|
+
base_config = @config["default"] || {}
|
|
56
|
+
bundler_config = bundler_config(env)
|
|
57
|
+
env_config = @config[env.to_s] || {}
|
|
58
|
+
|
|
59
|
+
# Merge: default <- bundler <- environment
|
|
60
|
+
merged = deep_merge(deep_merge(base_config, bundler_config), env_config)
|
|
25
61
|
|
|
26
|
-
|
|
27
|
-
|
|
62
|
+
# Validate critical config values
|
|
63
|
+
validate_config!(merged, env)
|
|
64
|
+
|
|
65
|
+
# Deep freeze for immutability
|
|
66
|
+
deep_freeze(merged)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Reload configuration (useful for development/testing)
|
|
71
|
+
def reload!
|
|
72
|
+
@config = load_config
|
|
73
|
+
@merged_cache.clear
|
|
74
|
+
self
|
|
28
75
|
end
|
|
29
76
|
|
|
30
77
|
def bundler(env = current_env)
|
|
@@ -42,12 +89,10 @@ module Railpack
|
|
|
42
89
|
def method_missing(method, *args)
|
|
43
90
|
config_key = method.to_s
|
|
44
91
|
if method.end_with?('=')
|
|
45
|
-
# Setter -
|
|
46
|
-
|
|
47
|
-
@config[current_env.to_s] ||= {}
|
|
48
|
-
@config[current_env.to_s][key] = args.first
|
|
92
|
+
# Setter - no longer allowed, config is immutable
|
|
93
|
+
raise Error, "Config is immutable. Set values in config/railpack.yml"
|
|
49
94
|
else
|
|
50
|
-
# Getter - read from merged config
|
|
95
|
+
# Getter - read from merged config (backward compatibility)
|
|
51
96
|
env = args.first || current_env
|
|
52
97
|
return for_environment(env)[config_key] if for_environment(env).key?(config_key)
|
|
53
98
|
super
|
|
@@ -105,7 +150,7 @@ module Railpack
|
|
|
105
150
|
|
|
106
151
|
def load_config
|
|
107
152
|
if config_path.exist?
|
|
108
|
-
YAML.safe_load(File.read(config_path), aliases:
|
|
153
|
+
YAML.safe_load(File.read(config_path), permitted_classes: [], aliases: false)
|
|
109
154
|
else
|
|
110
155
|
default_config
|
|
111
156
|
end
|
|
@@ -161,5 +206,36 @@ module Railpack
|
|
|
161
206
|
end
|
|
162
207
|
end
|
|
163
208
|
end
|
|
209
|
+
|
|
210
|
+
def validate_config!(config, env)
|
|
211
|
+
# Validate critical config values in production
|
|
212
|
+
if env.to_s == 'production'
|
|
213
|
+
if config['outdir'].nil? || config['outdir'].to_s.empty?
|
|
214
|
+
raise Error, "Production config must specify 'outdir'"
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
bundler_name = config['bundler']
|
|
218
|
+
if bundler_name.nil? || bundler_name.to_s.empty?
|
|
219
|
+
raise Error, "Production config must specify 'bundler'"
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# Validate bundler name exists in known bundlers
|
|
224
|
+
bundler_name = config['bundler']
|
|
225
|
+
if bundler_name && !@config.key?(bundler_name)
|
|
226
|
+
warn "Warning: Unknown bundler '#{bundler_name}'. Known bundlers: #{@config.keys.grep(/^(bun|esbuild|rollup|webpack)$/).join(', ')}"
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def deep_freeze(object)
|
|
231
|
+
case object
|
|
232
|
+
when Hash
|
|
233
|
+
object.each_value { |v| deep_freeze(v) }.freeze
|
|
234
|
+
when Array
|
|
235
|
+
object.each { |v| deep_freeze(v) }.freeze
|
|
236
|
+
else
|
|
237
|
+
object.freeze
|
|
238
|
+
end
|
|
239
|
+
end
|
|
164
240
|
end
|
|
165
241
|
end
|
data/lib/railpack/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: railpack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.13
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- 21tycoons LLC
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-01-
|
|
10
|
+
date: 2026-01-27 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: minitest
|
|
@@ -47,7 +47,6 @@ files:
|
|
|
47
47
|
- lib/railpack/manager.rb
|
|
48
48
|
- lib/railpack/version.rb
|
|
49
49
|
- lib/tasks/railpack.rake
|
|
50
|
-
- sig/railpack.rbs
|
|
51
50
|
- test/bundler_test.rb
|
|
52
51
|
- test/config_test.rb
|
|
53
52
|
- test/manager_test.rb
|
data/sig/railpack.rbs
DELETED