railpack 1.2.0 → 1.2.1
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/bundlers/webpack_bundler.rb +49 -0
- data/lib/railpack/config.rb +3 -1
- data/lib/railpack/manager.rb +75 -2
- data/lib/railpack/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 65190ba06f3b41df3783655f29f50d8bddfc9e3380698a0c76f4c29f5e1b4841
|
|
4
|
+
data.tar.gz: e417b5906674f996132cdf84b92ee66cfad9c9e2d5e8b2917a2125dd5dc58965
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fbec7a17d5c6dcb309fc30d5880206ec0507d771b5f08c01bbed97bdaf4a35ba0402da65956723c6824ce5087f973b84c8dc2accf736d292d692b22cd44aee81
|
|
7
|
+
data.tar.gz: d064a8f46b8e517ee119ccb29ecbc13c9ab87f67291529dc5b3aae02a9cc6fe7a36b0652f604dbfb34ee7df813aef2e6a1987bff0348f130db9743b23cc29c04
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Railpack
|
|
2
|
+
class WebpackBundler < Bundler
|
|
3
|
+
def commands
|
|
4
|
+
{
|
|
5
|
+
build: "webpack",
|
|
6
|
+
watch: "webpack --watch",
|
|
7
|
+
build_dev: "webpack",
|
|
8
|
+
clean: "rm -rf dist/",
|
|
9
|
+
install: "npm install",
|
|
10
|
+
add: "npm install",
|
|
11
|
+
remove: "npm uninstall",
|
|
12
|
+
exec: "node",
|
|
13
|
+
version: "webpack --version"
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def build!(args = [])
|
|
18
|
+
execute!([commands[:build], *args])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def watch(args = [])
|
|
22
|
+
execute([commands[:watch], *args])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def install!(args = [])
|
|
26
|
+
execute!([commands[:install], *args])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def add(*packages)
|
|
30
|
+
execute([commands[:add], *packages])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def remove(*packages)
|
|
34
|
+
execute([commands[:remove], *packages])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def exec(*args)
|
|
38
|
+
execute([commands[:exec], *args])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def version
|
|
42
|
+
`#{commands[:version]}`.strip
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def installed?
|
|
46
|
+
system("#{commands[:version]} > /dev/null 2>&1")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
data/lib/railpack/config.rb
CHANGED
data/lib/railpack/manager.rb
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require 'digest'
|
|
2
|
+
require 'pathname'
|
|
3
|
+
|
|
1
4
|
module Railpack
|
|
2
5
|
class Manager
|
|
3
6
|
BUNDLERS = {
|
|
@@ -13,16 +16,45 @@ module Railpack
|
|
|
13
16
|
|
|
14
17
|
# Unified API - delegate to the selected bundler
|
|
15
18
|
def build!(args = [])
|
|
19
|
+
start_time = Time.now
|
|
16
20
|
config = Railpack.config.for_environment(Rails.env)
|
|
17
21
|
Railpack.trigger_build_start(config)
|
|
18
22
|
|
|
19
23
|
begin
|
|
24
|
+
Railpack.logger.info "🚀 Starting #{config['bundler']} build for #{Rails.env} environment"
|
|
20
25
|
result = @bundler.build!(args)
|
|
21
|
-
|
|
26
|
+
duration = ((Time.now - start_time) * 1000).round(2)
|
|
27
|
+
|
|
28
|
+
# Calculate bundle size if output directory exists
|
|
29
|
+
bundle_size = calculate_bundle_size(config)
|
|
30
|
+
|
|
31
|
+
success_result = {
|
|
32
|
+
success: true,
|
|
33
|
+
config: config,
|
|
34
|
+
duration: duration,
|
|
35
|
+
bundle_size: bundle_size
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Railpack.logger.info "✅ Build completed successfully in #{duration}ms (#{bundle_size}kb)"
|
|
39
|
+
|
|
40
|
+
# Generate asset manifest for Rails
|
|
41
|
+
generate_asset_manifest(config)
|
|
42
|
+
|
|
43
|
+
Railpack.trigger_build_complete(success_result)
|
|
22
44
|
result
|
|
23
45
|
rescue => error
|
|
46
|
+
duration = ((Time.now - start_time) * 1000).round(2)
|
|
47
|
+
Railpack.logger.error "❌ Build failed after #{duration}ms: #{error.message}"
|
|
48
|
+
|
|
49
|
+
error_result = {
|
|
50
|
+
success: false,
|
|
51
|
+
error: error,
|
|
52
|
+
config: config,
|
|
53
|
+
duration: duration
|
|
54
|
+
}
|
|
55
|
+
|
|
24
56
|
Railpack.trigger_error(error)
|
|
25
|
-
Railpack.trigger_build_complete(
|
|
57
|
+
Railpack.trigger_build_complete(error_result)
|
|
26
58
|
raise
|
|
27
59
|
end
|
|
28
60
|
end
|
|
@@ -77,5 +109,46 @@ module Railpack
|
|
|
77
109
|
|
|
78
110
|
bundler_class.new(Railpack.config)
|
|
79
111
|
end
|
|
112
|
+
|
|
113
|
+
def calculate_bundle_size(config)
|
|
114
|
+
outdir = config['outdir']
|
|
115
|
+
return 'unknown' unless outdir && Dir.exist?(outdir)
|
|
116
|
+
|
|
117
|
+
total_size = 0
|
|
118
|
+
Dir.glob("#{outdir}/**/*.{js,css,map}").each do |file|
|
|
119
|
+
total_size += File.size(file) if File.file?(file)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
(total_size / 1024.0).round(2)
|
|
123
|
+
rescue
|
|
124
|
+
'unknown'
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def generate_asset_manifest(config)
|
|
128
|
+
outdir = config['outdir']
|
|
129
|
+
return unless outdir && Dir.exist?(outdir)
|
|
130
|
+
|
|
131
|
+
manifest = {}
|
|
132
|
+
|
|
133
|
+
# Find built assets
|
|
134
|
+
Dir.glob("#{outdir}/**/*.{js,css}").each do |file|
|
|
135
|
+
next unless File.file?(file)
|
|
136
|
+
relative_path = Pathname.new(file).relative_path_from(Pathname.new(outdir)).to_s
|
|
137
|
+
|
|
138
|
+
# Map logical names to physical files
|
|
139
|
+
if relative_path.include?('application') && relative_path.end_with?('.js')
|
|
140
|
+
manifest['application.js'] = relative_path
|
|
141
|
+
elsif relative_path.include?('application') && relative_path.end_with?('.css')
|
|
142
|
+
manifest['application.css'] = relative_path
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Write manifest for Rails asset pipeline
|
|
147
|
+
manifest_path = "#{outdir}/.sprockets-manifest-#{Digest::MD5.hexdigest(manifest.to_s)}.json"
|
|
148
|
+
File.write(manifest_path, JSON.pretty_generate(manifest))
|
|
149
|
+
Railpack.logger.debug "📄 Generated asset manifest: #{manifest_path}"
|
|
150
|
+
rescue => error
|
|
151
|
+
Railpack.logger.warn "⚠️ Failed to generate asset manifest: #{error.message}"
|
|
152
|
+
end
|
|
80
153
|
end
|
|
81
154
|
end
|
data/lib/railpack/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- 21tycoons LLC
|
|
@@ -42,6 +42,7 @@ files:
|
|
|
42
42
|
- lib/railpack/bundlers/bun_bundler.rb
|
|
43
43
|
- lib/railpack/bundlers/esbuild_bundler.rb
|
|
44
44
|
- lib/railpack/bundlers/rollup_bundler.rb
|
|
45
|
+
- lib/railpack/bundlers/webpack_bundler.rb
|
|
45
46
|
- lib/railpack/config.rb
|
|
46
47
|
- lib/railpack/manager.rb
|
|
47
48
|
- lib/railpack/version.rb
|