lib/vite_ruby/builder.rb in vite_ruby-3.2.4 vs lib/vite_ruby/builder.rb in vite_ruby-3.2.5
- old
+ new
@@ -12,11 +12,14 @@
# and triggers a Vite build if any files have changed.
def build(*args)
last_build = last_build_metadata(ssr: args.include?('--ssr'))
if args.delete('--force') || last_build.stale?
- build_with_vite(*args).tap { |success| record_build_metadata(success, last_build) }
+ stdout, stderr, success = build_with_vite(*args)
+ log_build_result(stdout, stderr, success)
+ record_build_metadata(last_build, errors: stderr, success: success)
+ success
elsif last_build.success
logger.debug "Skipping vite build. Watched files have not changed since the last build at #{ last_build.timestamp }"
true
else
logger.error "Skipping vite build. Watched files have not changed since the build failed at #{ last_build.timestamp } ❌"
@@ -34,13 +37,13 @@
extend Forwardable
def_delegators :@vite_ruby, :config, :logger, :run
# Internal: Writes a digest of the watched files to disk for future checks.
- def record_build_metadata(success, build)
+ def record_build_metadata(build, **attrs)
config.build_cache_dir.mkpath
- build.with_result(success).write_to_cache
+ build.with_result(**attrs).write_to_cache
end
# Internal: The file path where metadata of the last build is stored.
def last_build_path(ssr:)
config.build_cache_dir.join("last#{ '-ssr' if ssr }-build-#{ config.mode }.json")
@@ -55,27 +58,22 @@
Digest::SHA1.hexdigest(file_ids.join('/'))
end
end
# Public: Initiates a Vite build command to generate assets.
- #
- # Returns true if the build is successful, or false if it failed.
def build_with_vite(*args)
logger.info 'Building with Vite ⚡️'
- stdout, stderr, status = run(['build', *args])
- log_build_result(stdout, stderr.to_s, status)
-
- status.success?
+ run(['build', *args])
end
# Internal: Outputs the build results.
#
# NOTE: By default it also outputs the manifest entries.
def log_build_result(_stdout, stderr, status)
- if status.success?
+ if status
logger.info "Build with Vite complete: #{ config.build_output_dir }"
- logger.error stderr.to_s unless stderr.empty?
+ logger.error stderr unless stderr.empty?
else
logger.error stderr
logger.error 'Build with Vite failed! ❌'
logger.error '❌ Check that vite and vite-plugin-ruby are in devDependencies and have been installed. ' if stderr.include?('ERR! canceled')
end