railpack 1.2.12 → 1.2.14
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 +50 -0
- data/lib/railpack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 180f2842cd9e28804b7e3a2e4c3bead7d59d96f1a94dba1a376afb2c00ccbe87
|
|
4
|
+
data.tar.gz: e6f59e92f1e7b71532cc3419a8453c967f5805f5fc09d61e5f6f9bee095d2bb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 00dfe7f2f5b0dc5ab4223353d31cc5e72ddc2017276a64b45d2da375f779db1a3ffccd7060a5bb2a6150a9b7f16ef9fade80b7d765bb5df417902fa90db6a7b5
|
|
7
|
+
data.tar.gz: 16eac4d8a85abd5ba9302adfc41c1f0a2c6e1ddad6a13cd955eb883e4f9f7d6b44d112094c6736045e2b4d7e59ea23414b271337cc4762f0b6e40bf8d5aa3303
|
data/lib/railpack/config.rb
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
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
|
|
|
@@ -41,11 +59,21 @@ module Railpack
|
|
|
41
59
|
# Merge: default <- bundler <- environment
|
|
42
60
|
merged = deep_merge(deep_merge(base_config, bundler_config), env_config)
|
|
43
61
|
|
|
62
|
+
# Validate critical config values
|
|
63
|
+
validate_config!(merged, env)
|
|
64
|
+
|
|
44
65
|
# Deep freeze for immutability
|
|
45
66
|
deep_freeze(merged)
|
|
46
67
|
end
|
|
47
68
|
end
|
|
48
69
|
|
|
70
|
+
# Reload configuration (useful for development/testing)
|
|
71
|
+
def reload!
|
|
72
|
+
@config = load_config
|
|
73
|
+
@merged_cache.clear
|
|
74
|
+
self
|
|
75
|
+
end
|
|
76
|
+
|
|
49
77
|
def bundler(env = current_env)
|
|
50
78
|
# Look directly in config to avoid circular dependency
|
|
51
79
|
env_config = @config[env.to_s] || {}
|
|
@@ -65,6 +93,8 @@ module Railpack
|
|
|
65
93
|
raise Error, "Config is immutable. Set values in config/railpack.yml"
|
|
66
94
|
else
|
|
67
95
|
# Getter - read from merged config (backward compatibility)
|
|
96
|
+
# TODO: In v2.0, remove this fallback and require explicit accessors
|
|
97
|
+
warn "DEPRECATED: Dynamic config access via '#{config_key}' will be removed in v2.0. Use explicit accessors instead." if defined?(Rails) && Rails.logger
|
|
68
98
|
env = args.first || current_env
|
|
69
99
|
return for_environment(env)[config_key] if for_environment(env).key?(config_key)
|
|
70
100
|
super
|
|
@@ -179,6 +209,26 @@ module Railpack
|
|
|
179
209
|
end
|
|
180
210
|
end
|
|
181
211
|
|
|
212
|
+
def validate_config!(config, env)
|
|
213
|
+
# Validate critical config values in production
|
|
214
|
+
if env.to_s == 'production'
|
|
215
|
+
if config['outdir'].nil? || config['outdir'].to_s.empty?
|
|
216
|
+
raise Error, "Production config must specify 'outdir'"
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
bundler_name = config['bundler']
|
|
220
|
+
if bundler_name.nil? || bundler_name.to_s.empty?
|
|
221
|
+
raise Error, "Production config must specify 'bundler'"
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Validate bundler name exists in known bundlers
|
|
226
|
+
bundler_name = config['bundler']
|
|
227
|
+
if bundler_name && !@config.key?(bundler_name)
|
|
228
|
+
warn "Warning: Unknown bundler '#{bundler_name}'. Known bundlers: #{@config.keys.grep(/^(bun|esbuild|rollup|webpack)$/).join(', ')}"
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
182
232
|
def deep_freeze(object)
|
|
183
233
|
case object
|
|
184
234
|
when Hash
|
data/lib/railpack/version.rb
CHANGED