vite_ruby 3.2.4 → 3.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0370b365c1f6fbddd0cd14fc9467f56d4c039e167e62e380feb5df9c8b72a0d7
4
- data.tar.gz: 13fa2eb1842a8868a9490dfcf99c450a1f8bdda35ad7d89e5da8e904bde55a4e
3
+ metadata.gz: 375a421ac4d10bc65044065ae4a69147c500808a2271ee77ed33b6721c34ca85
4
+ data.tar.gz: 917e97be44a37ad99dd3b700959d00ff26420727867c64b06a2b22354a7d8199
5
5
  SHA512:
6
- metadata.gz: 0e18dd917b8ff8f593196cc4917ec5b4f0ecb0f3a3e6066f4438e4e56d150be0bd830fd9b66b82f95420ab1b53c3e530238f9dcdcb5505612df4d8b551b6f53d
7
- data.tar.gz: 4f781ed0748d645d270c08c9b704c00c7529ab84ea6a531ee0904ef902fd8884410c714d8b30f4a0b9bafe3e493decad00bd4df78ddebc6d9d2c7e167eed008c
6
+ metadata.gz: babcceadc14d4f40e038610c47f09d57f22f1c3a4e3ded4ec1749b18c8ff3d3bb82ca6eaaab2b0036c026b586c705d9916dc3f030475679e7ad77d74c98bdd9e
7
+ data.tar.gz: 90d786e851da59d09ce76bc1162162f0d2e0c6f2824cba5a1e4bc3848936767a1a56387a9daa6fc77ee65d60cfa92cbecb6bca87107869b69150200df26d9cfd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [3.2.5](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.4...vite_ruby@3.2.5) (2022-10-07)
2
+
3
+
4
+ ### Features
5
+
6
+ * display last build errors in MissingEntrypointError ([#274](https://github.com/ElMassimo/vite_ruby/issues/274)) ([107c980](https://github.com/ElMassimo/vite_ruby/commit/107c980449546ef73c527b88f1db11a7201e4438))
7
+
8
+
9
+
1
10
  ## [3.2.4](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.3...vite_ruby@3.2.4) (2022-10-04)
2
11
 
3
12
 
@@ -4,24 +4,32 @@ require 'json'
4
4
  require 'time'
5
5
 
6
6
  # Internal: Value object with information about the last build.
7
- ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current_digest, :last_build_path) do
8
- # Internal: Combines information from a previous build with the current digest.
9
- def self.from_previous(last_build_path, current_digest)
10
- attrs = begin
11
- # Reads metadata recorded on the last build, if it exists.
12
- last_build_path.exist? ? JSON.parse(last_build_path.read.to_s) : {}
7
+ ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current_digest, :last_build_path, :errors, keyword_init: true) do
8
+ class << self
9
+ # Internal: Combines information from a previous build with the current digest.
10
+ def from_previous(last_build_path, current_digest)
11
+ new(
12
+ **parse_metadata(last_build_path),
13
+ current_digest: current_digest,
14
+ last_build_path: last_build_path,
15
+ )
16
+ end
17
+
18
+ private
19
+
20
+ # Internal: Reads metadata recorded on the last build, if it exists.
21
+ def parse_metadata(pathname)
22
+ return default_metadata unless pathname.exist?
23
+
24
+ JSON.parse(pathname.read.to_s).transform_keys(&:to_sym).slice(*members)
13
25
  rescue JSON::JSONError, Errno::ENOENT, Errno::ENOTDIR
14
- {}
26
+ default_metadata
15
27
  end
16
28
 
17
- new(
18
- attrs['success'],
19
- attrs['timestamp'] || 'never',
20
- attrs['vite_ruby'] || 'unknown',
21
- attrs['digest'] || 'none',
22
- current_digest,
23
- last_build_path,
24
- )
29
+ # Internal: To make it evident that there's no last build in error messages.
30
+ def default_metadata
31
+ { timestamp: 'never', digest: 'none' }
32
+ end
25
33
  end
26
34
 
27
35
  # Internal: A build is considered stale when watched files have changed since
@@ -45,14 +53,14 @@ ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current
45
53
  end
46
54
 
47
55
  # Internal: Returns a new build with the specified result.
48
- def with_result(success)
56
+ def with_result(**attrs)
49
57
  self.class.new(
50
- success,
51
- Time.now.strftime('%F %T'),
52
- ViteRuby::VERSION,
53
- current_digest,
54
- current_digest,
55
- last_build_path,
58
+ **attrs,
59
+ timestamp: Time.now.strftime('%F %T'),
60
+ vite_ruby: ViteRuby::VERSION,
61
+ digest: current_digest,
62
+ current_digest: current_digest,
63
+ last_build_path: last_build_path,
56
64
  )
57
65
  end
58
66
 
@@ -65,6 +73,7 @@ ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current
65
73
  def to_json(*_args)
66
74
  JSON.pretty_generate(
67
75
  success: success,
76
+ errors: errors,
68
77
  timestamp: timestamp,
69
78
  vite_ruby: vite_ruby,
70
79
  digest: digest,
@@ -14,7 +14,10 @@ class ViteRuby::Builder
14
14
  last_build = last_build_metadata(ssr: args.include?('--ssr'))
15
15
 
16
16
  if args.delete('--force') || last_build.stale?
17
- build_with_vite(*args).tap { |success| record_build_metadata(success, last_build) }
17
+ stdout, stderr, success = build_with_vite(*args)
18
+ log_build_result(stdout, stderr, success)
19
+ record_build_metadata(last_build, errors: stderr, success: success)
20
+ success
18
21
  elsif last_build.success
19
22
  logger.debug "Skipping vite build. Watched files have not changed since the last build at #{ last_build.timestamp }"
20
23
  true
@@ -36,9 +39,9 @@ private
36
39
  def_delegators :@vite_ruby, :config, :logger, :run
37
40
 
38
41
  # Internal: Writes a digest of the watched files to disk for future checks.
39
- def record_build_metadata(success, build)
42
+ def record_build_metadata(build, **attrs)
40
43
  config.build_cache_dir.mkpath
41
- build.with_result(success).write_to_cache
44
+ build.with_result(**attrs).write_to_cache
42
45
  end
43
46
 
44
47
  # Internal: The file path where metadata of the last build is stored.
@@ -57,24 +60,19 @@ private
57
60
  end
58
61
 
59
62
  # Public: Initiates a Vite build command to generate assets.
60
- #
61
- # Returns true if the build is successful, or false if it failed.
62
63
  def build_with_vite(*args)
63
64
  logger.info 'Building with Vite ⚡️'
64
65
 
65
- stdout, stderr, status = run(['build', *args])
66
- log_build_result(stdout, stderr.to_s, status)
67
-
68
- status.success?
66
+ run(['build', *args])
69
67
  end
70
68
 
71
69
  # Internal: Outputs the build results.
72
70
  #
73
71
  # NOTE: By default it also outputs the manifest entries.
74
72
  def log_build_result(_stdout, stderr, status)
75
- if status.success?
73
+ if status
76
74
  logger.info "Build with Vite complete: #{ config.build_output_dir }"
77
- logger.error stderr.to_s unless stderr.empty?
75
+ logger.error stderr unless stderr.empty?
78
76
  else
79
77
  logger.error stderr
80
78
  logger.error 'Build with Vite failed! ❌'
@@ -111,7 +111,7 @@ private
111
111
  def run_with_capture(*args, **options)
112
112
  Dir.chdir(root) do
113
113
  _, stderr, status = ViteRuby::IO.capture(*args, **options)
114
- say(stderr) unless status.success? || stderr.to_s.empty?
114
+ say(stderr) unless status || stderr.empty?
115
115
  end
116
116
  end
117
117
 
data/lib/vite_ruby/io.rb CHANGED
@@ -15,7 +15,7 @@ module ViteRuby::IO
15
15
  stdin.close
16
16
  out = Thread.new { read_lines(stdout, &with_output) }
17
17
  err = Thread.new { stderr.read }
18
- [out.value, err.value, wait_threads.value]
18
+ [out.value, err.value.to_s, wait_threads.value.success?]
19
19
  }
20
20
  end
21
21
 
@@ -17,19 +17,27 @@ class ViteRuby::MissingEntrypointError < ViteRuby::Error
17
17
  #{ possible_causes(last_build) }
18
18
  :troubleshooting:
19
19
  #{ "\nContent in your manifests:\n#{ JSON.pretty_generate(manifest) }\n" if last_build.success }
20
- #{ "Last build in #{ config.mode } mode:\n#{ last_build.to_json }\n" unless last_build.success.nil? }
20
+ #{ "Last build in #{ config.mode } mode:\n#{ last_build.to_json }\n" if last_build.success }
21
21
  MSG
22
22
  end
23
23
 
24
24
  def possible_causes(last_build)
25
- return FAILED_BUILD_CAUSES.sub(':mode:', config.mode) if last_build.success == false
26
- return DEFAULT_CAUSES if config.auto_build
27
-
28
- DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
25
+ if last_build.success == false
26
+ FAILED_BUILD_CAUSES
27
+ .sub(':mode:', config.mode)
28
+ .sub(':errors:', last_build.errors.to_s.gsub(/^(?!$)/, ' '))
29
+ elsif config.auto_build
30
+ DEFAULT_CAUSES
31
+ else
32
+ DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
33
+ end
29
34
  end
30
35
 
31
- FAILED_BUILD_CAUSES = <<-MSG
32
- - The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.
36
+ FAILED_BUILD_CAUSES = <<~MSG
37
+ - The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.
38
+
39
+ Errors:
40
+ :errors:
33
41
  MSG
34
42
 
35
43
  DEFAULT_CAUSES = <<-MSG
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '3.2.4'
4
+ VERSION = '3.2.5'
5
5
 
6
6
  # Internal: Versions used by default when running `vite install`.
7
7
  DEFAULT_VITE_VERSION = '^3.0.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vite_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.4
4
+ version: 3.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Máximo Mussini
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-04 00:00:00.000000000 Z
11
+ date: 2022-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -202,8 +202,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
202
202
  licenses:
203
203
  - MIT
204
204
  metadata:
205
- source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.2.4/vite_ruby
206
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.2.4/vite_ruby/CHANGELOG.md
205
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.2.5/vite_ruby
206
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.2.5/vite_ruby/CHANGELOG.md
207
207
  post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
208
208
  manually, please run:\n\tbundle exec vite upgrade"
209
209
  rdoc_options: []
@@ -213,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
213
  requirements:
214
214
  - - ">="
215
215
  - !ruby/object:Gem::Version
216
- version: '2.4'
216
+ version: '2.5'
217
217
  required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  requirements:
219
219
  - - ">="