vite_ruby 1.1.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 436737196c45af00694c405d697cea826566bec8ab5e0ef246f5917b253df3cf
4
- data.tar.gz: c052a43c6faa9c07318658f870a50db7aabdf7beb7074e80dc9026272125becc
3
+ metadata.gz: 75c25f6f407996069ce830b7822b0d10041f930ce7ce6bc317a6413a73f66ae8
4
+ data.tar.gz: c8e1bb8d969e408f0b21bdd3a4bb9d0e5a0a61e5d72635bb021c2f423676b170
5
5
  SHA512:
6
- metadata.gz: b164085097cd79feabc3dffec84129b042a92ede8a37de7aaa04adb1a679be37af609d4eba1f105cb5a924cb173e425c850795f346a2648de7b4dd80b3e9f1d1
7
- data.tar.gz: 67bb02e9619228ac48361fac841c46d032f1f0094ea6fc57cfe8dd68431f1fb4a1101de7dea04b911b40057acbf1484eda11046a2dce85c5699a1643b6c129ef
6
+ metadata.gz: 913332a8629f8521a7af235951e761a103b167ed76f17021691835a8508c52d51e7ac9cdf39f46e73461a98c6d11de99900eccd4c4a45490ee23a405c7904f7c
7
+ data.tar.gz: 91faeb4e8810c9b260d2dc91b0df4db41f50b3f533ca44c60859200ecfbfddccb3406814f651048f89f4f6e119f6d032cfbe85d603289be65399f9815e68cd34
data/CHANGELOG.md CHANGED
@@ -1,3 +1,55 @@
1
+ ## [1.2.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.1...vite_ruby@1.2.2) (2021-03-20)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Avoid prompts when using npx outside a CI ([ed7ccd7](https://github.com/ElMassimo/vite_ruby/commit/ed7ccd7d32c079ab78555ecd36dcb68ad2da331e))
7
+ * Simplify installation of build dependencies by using package manager flags ([5c8bb62](https://github.com/ElMassimo/vite_ruby/commit/5c8bb625926f2ab1788a3e3a22aeafd7104984cb))
8
+
9
+
10
+
11
+ ## [1.2.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.0...vite_ruby@1.2.1) (2021-03-19)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * Use the mode option in `clobber` ([add76b2](https://github.com/ElMassimo/vite_ruby/commit/add76b2a63ea64336235536b8b5670bace357b6e))
17
+
18
+
19
+
20
+ # [1.2.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.1.2...vite_ruby@1.2.0) (2021-03-19)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * Improve error messages when the Vite executable is missing ([#41](https://github.com/ElMassimo/vite_ruby/issues/41)) ([a79edc6](https://github.com/ElMassimo/vite_ruby/commit/a79edc6cc603c1094ede9e899226e98f734e7bbe))
26
+
27
+
28
+ ### Features
29
+
30
+ * Add `clobber` to the CLI, usable as `--clear` in the `dev` and `build` commands ([331d861](https://github.com/ElMassimo/vite_ruby/commit/331d86163c12eb3303d3975a94ecc205fa59dd41))
31
+ * Allow `clobber` to receive a `--mode` option. ([e6e7a6d](https://github.com/ElMassimo/vite_ruby/commit/e6e7a6dd0a2acf205d06877f76deb924c1d5aba7))
32
+
33
+
34
+
35
+ ## [1.1.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.1.1...vite_ruby@1.1.2) (2021-03-19)
36
+
37
+
38
+ ### Features
39
+
40
+ * Automatically retry failed builds after a certain time ([cbb3058](https://github.com/ElMassimo/vite_ruby/commit/cbb305863a49c46e7a0d95c773f56f7d822d01d9))
41
+
42
+
43
+
44
+ ## [1.1.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.1.0...vite_ruby@1.1.1) (2021-03-19)
45
+
46
+
47
+ ### Bug Fixes
48
+
49
+ * handle getaddrinfo errors when checking dev server ([#39](https://github.com/ElMassimo/vite_ruby/issues/39)) ([df57d6b](https://github.com/ElMassimo/vite_ruby/commit/df57d6ba5d8ed20e15bd2de3a57c8ff711671d28))
50
+
51
+
52
+
1
53
  # [1.1.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.0.5...vite_ruby@1.1.0) (2021-03-07)
2
54
 
3
55
 
data/default.vite.json CHANGED
@@ -13,5 +13,6 @@
13
13
  "https": null,
14
14
  "port": 3036,
15
15
  "hideBuildConsoleOutput": false,
16
+ "viteBinPath": "node_modules/.bin/vite",
16
17
  "watchAdditionalPaths": []
17
18
  }
data/lib/tasks/vite.rake CHANGED
@@ -22,7 +22,6 @@ namespace :vite do
22
22
  desc 'Remove the vite build output directory'
23
23
  task clobber: :'vite:verify_install' do
24
24
  ViteRuby.commands.clobber
25
- $stdout.puts "Removed vite build output directory #{ ViteRuby.config.build_output_dir }"
26
25
  end
27
26
 
28
27
  desc 'Verifies if ViteRuby is properly installed in this application'
@@ -30,9 +29,9 @@ namespace :vite do
30
29
  ViteRuby.commands.verify_install
31
30
  end
32
31
 
33
- desc 'Install all JavaScript dependencies'
32
+ desc 'Ensures build dependencies like Vite are installed when compiling assets'
34
33
  task :install_dependencies do
35
- system({ 'NODE_ENV' => 'development' }, 'npx ci')
34
+ system({ 'NODE_ENV' => 'development' }, 'npx --yes ci')
36
35
  end
37
36
 
38
37
  desc "Provide information on ViteRuby's environment"
@@ -49,3 +48,9 @@ if Rake::Task.task_defined?('assets:precompile')
49
48
  else
50
49
  Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build'])
51
50
  end
51
+
52
+ # Any prerequisite task that installs packages should also install build dependencies.
53
+ if ARGV.include?('assets:precompile')
54
+ ENV['NPM_CONFIG_PRODUCTION'] = 'false'
55
+ ENV['YARN_PRODUCTION'] = 'false'
56
+ end
data/lib/vite_ruby.rb CHANGED
@@ -94,7 +94,7 @@ class ViteRuby
94
94
  Socket.tcp(config.host, config.port, connect_timeout: config.dev_server_connect_timeout).close
95
95
  @running_at = Time.now
96
96
  true
97
- rescue SystemCallError
97
+ rescue StandardError
98
98
  @running_at = false
99
99
  end
100
100
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'time'
4
+
3
5
  # Internal: Value object with information about the last build.
4
6
  ViteRuby::Build = Struct.new(:success, :timestamp, :digest, :current_digest) do
5
7
  # Internal: Combines information from a previous build with the current digest.
@@ -7,16 +9,26 @@ ViteRuby::Build = Struct.new(:success, :timestamp, :digest, :current_digest) do
7
9
  new(attrs['success'], attrs['timestamp'] || 'never', attrs['digest'] || 'none', current_digest)
8
10
  end
9
11
 
10
- # Internal: Returns true if watched files have changed since the last build.
12
+ # Internal: A build is considered stale when watched files have changed since
13
+ # the last build, or when a certain time has ellapsed in case of failure.
11
14
  def stale?
12
- digest != current_digest
15
+ digest != current_digest || retry_failed?
13
16
  end
14
17
 
15
- # Internal: Returns true if watched files have not changed since the last build.
18
+ # Internal: A build is considered fresh if watched files have not changed, or
19
+ # the last failed build happened recently.
16
20
  def fresh?
17
21
  !stale?
18
22
  end
19
23
 
24
+ # Internal: To avoid cascading build failures, if the last build failed and it
25
+ # happened within a short time window, a new build should not be triggered.
26
+ def retry_failed?
27
+ !success && Time.parse(timestamp) + 3 < Time.now # 3 seconds
28
+ rescue ArgumentError
29
+ true
30
+ end
31
+
20
32
  # Internal: Returns a new build with the specified result.
21
33
  def with_result(success)
22
34
  self.class.new(success, Time.now.strftime('%F %T'), current_digest)
data/lib/vite_ruby/cli.rb CHANGED
@@ -8,6 +8,7 @@ class ViteRuby::CLI
8
8
  extend Dry::CLI::Registry
9
9
 
10
10
  register 'build', Build, aliases: ['b']
11
+ register 'clobber', Clobber, aliases: %w[clean clear]
11
12
  register 'dev', Dev, aliases: %w[d serve]
12
13
  register 'install', Install, aliases: %w[setup init]
13
14
  register 'version', Version, aliases: ['v', '-v', '--version', 'info']
@@ -5,7 +5,8 @@ class ViteRuby::CLI::Build < Dry::CLI::Command
5
5
  DEFAULT_ENV = CURRENT_ENV || 'production'
6
6
 
7
7
  def self.shared_options
8
- option(:mode, default: self::DEFAULT_ENV, values: %w[development production], aliases: ['m'], desc: 'The build mode for Vite')
8
+ option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: ['m'], desc: 'The build mode for Vite')
9
+ option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
9
10
  option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
10
11
  option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
11
12
  option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
@@ -15,8 +16,9 @@ class ViteRuby::CLI::Build < Dry::CLI::Command
15
16
  shared_options
16
17
  option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)
17
18
 
18
- def call(mode:, args: [], **boolean_opts)
19
+ def call(mode:, args: [], clobber: false, **boolean_opts)
19
20
  ViteRuby.env['VITE_RUBY_MODE'] = mode
21
+ ViteRuby.commands.clobber if clobber
20
22
  boolean_opts.map { |name, value| args << "--#{ name }" if value }
21
23
  block_given? ? yield(args) : ViteRuby.commands.build_from_task(*args)
22
24
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ViteRuby::CLI::Clobber < Dry::CLI::Command
4
+ desc 'Clear the Vite cache, temp files, and builds'
5
+
6
+ current_env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
7
+
8
+ option(:mode, default: current_env, values: %w[development production test], aliases: ['m'], desc: 'The mode to use')
9
+
10
+ def call(mode:, **)
11
+ ViteRuby.env['VITE_RUBY_MODE'] = mode
12
+ ViteRuby.commands.clobber
13
+ end
14
+ end
@@ -75,7 +75,7 @@ private
75
75
  write(package_json, '{}') unless package_json.exist?
76
76
  Dir.chdir(root) do
77
77
  deps = "vite@#{ ViteRuby::DEFAULT_VITE_VERSION } vite-plugin-ruby@#{ ViteRuby::DEFAULT_PLUGIN_VERSION }"
78
- stdout, stderr, status = Open3.capture3({ 'CI' => 'true' }, "npx --package @antfu/ni -- ni -D #{ deps }")
78
+ stdout, stderr, status = Open3.capture3({}, "npx --yes --package @antfu/ni -- ni -D #{ deps }")
79
79
  stdout, stderr, = Open3.capture3({}, "yarn add -D #{ deps }") unless status.success?
80
80
  say(stdout, "\n", stderr)
81
81
  end
@@ -23,9 +23,9 @@ class ViteRuby::Commands
23
23
 
24
24
  # Public: Removes all build cache and previously compiled assets.
25
25
  def clobber
26
- config.build_output_dir.rmtree if config.build_output_dir.exist?
27
- config.build_cache_dir.rmtree if config.build_cache_dir.exist?
28
- config.vite_cache_dir.rmtree if config.vite_cache_dir.exist?
26
+ dirs = [config.build_output_dir, config.build_cache_dir, config.vite_cache_dir]
27
+ dirs.each { |dir| dir.rmtree if dir.exist? }
28
+ $stdout.puts "Removed vite cache and output dirs:\n\t#{ dirs.join("\n\t") }"
29
29
  end
30
30
 
31
31
  # Public: Receives arguments from a rake task.
@@ -91,7 +91,7 @@ private
91
91
  }
92
92
 
93
93
  # Internal: Default values for a Ruby application.
94
- def config_defaults(asset_host: nil, mode: ENV.fetch('RACK_ENV', 'production'), root: Dir.pwd)
94
+ def config_defaults(asset_host: nil, mode: ENV.fetch('RACK_ENV', 'development'), root: Dir.pwd)
95
95
  {
96
96
  'asset_host' => option_from_env('asset_host') || asset_host,
97
97
  'config_path' => option_from_env('config_path') || DEFAULT_CONFIG.fetch('config_path'),
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Internal: Provides common functionality for errors.
4
+ class ViteRuby::Error < StandardError
5
+ def message
6
+ super.sub(':troubleshooting:', <<~MSG)
7
+ Visit the Troubleshooting guide for more information:
8
+ https://vite-ruby.netlify.app/guide/troubleshooting.html#troubleshooting
9
+ MSG
10
+ end
11
+ end
@@ -10,9 +10,6 @@
10
10
  # NOTE: Using "autoBuild": true` in `config/vite.json` file will trigger a build
11
11
  # on demand as needed, before performing any lookup.
12
12
  class ViteRuby::Manifest
13
- class MissingEntryError < StandardError
14
- end
15
-
16
13
  def initialize(vite_ruby)
17
14
  @vite_ruby = vite_ruby
18
15
  @build_mutex = Mutex.new if config.auto_build
@@ -142,39 +139,11 @@ private
142
139
 
143
140
  # Internal: Raises a detailed message when an entry is missing in the manifest.
144
141
  def missing_entry_error(name, type: nil, **_options)
145
- file_name = with_file_extension(name, type)
146
- last_build = builder.last_build_metadata
147
- raise ViteRuby::Manifest::MissingEntryError, <<~MSG
148
- Vite Ruby can't find #{ file_name } in #{ config.manifest_path.relative_path_from(config.root) } or #{ config.assets_manifest_path.relative_path_from(config.root) }.
149
-
150
- Possible causes:
151
- #{ possible_causes(last_build) }
152
- Visit the Troubleshooting guide for more information:
153
- https://vite-ruby.netlify.app/guide/troubleshooting.html#troubleshooting
154
- #{ "\nContent in your manifests:\n#{ JSON.pretty_generate(@manifest) }\n" if last_build.success }
155
- #{ "\nLast build in #{ config.mode } mode:\n#{ last_build.to_json }\n" unless last_build.success.nil? }
156
- MSG
142
+ raise ViteRuby::MissingEntrypointError, OpenStruct.new(
143
+ file_name: with_file_extension(name, type),
144
+ last_build: builder.last_build_metadata,
145
+ manifest: @manifest,
146
+ config: config,
147
+ )
157
148
  end
158
-
159
- def possible_causes(last_build)
160
- return FAILED_BUILD_CAUSES if last_build.success == false
161
- return DEFAULT_CAUSES if config.auto_build
162
-
163
- DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
164
- end
165
-
166
- FAILED_BUILD_CAUSES = <<-MSG
167
- - The last build failed. Try running `bin/vite build --force` manually and check for errors.
168
- MSG
169
-
170
- DEFAULT_CAUSES = <<-MSG
171
- - The file path is incorrect.
172
- - The file is not in the entrypoints directory.
173
- - Some files are outside the sourceCodeDir, and have not been added to watchAdditionalPaths.
174
- MSG
175
-
176
- NO_AUTO_BUILD_CAUSES = <<-MSG
177
- - You have not run `bin/vite dev` to start Vite, or the dev server is not reachable.
178
- - "autoBuild" is set to `false` in your config/vite.json for this environment.
179
- MSG
180
149
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Internal: Raised when an entry is not found in the build manifest.
4
+ #
5
+ # NOTE: The complexity here is justified by the improved usability of providing
6
+ # a more specific error message depending on the situation.
7
+ class ViteRuby::MissingEntrypointError < ViteRuby::Error
8
+ extend Forwardable
9
+ def_delegators :@info, :file_name, :last_build, :manifest, :config
10
+
11
+ def initialize(info)
12
+ @info = info
13
+ super <<~MSG
14
+ Vite Ruby can't find #{ file_name } in #{ config.manifest_path.relative_path_from(config.root) } or #{ config.assets_manifest_path.relative_path_from(config.root) }.
15
+
16
+ Possible causes:
17
+ #{ possible_causes(last_build) }
18
+ :troubleshooting:
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? }
21
+ MSG
22
+ end
23
+
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
29
+ end
30
+
31
+ FAILED_BUILD_CAUSES = <<-MSG
32
+ - The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.
33
+ MSG
34
+
35
+ DEFAULT_CAUSES = <<-MSG
36
+ - The file path is incorrect.
37
+ - The file is not in the entrypoints directory.
38
+ - Some files are outside the sourceCodeDir, and have not been added to watchAdditionalPaths.
39
+ MSG
40
+
41
+ NO_AUTO_BUILD_CAUSES = <<-MSG
42
+ - You have not run `bin/vite dev` to start Vite, or the dev server is not reachable.
43
+ - "autoBuild" is set to `false` in your config/vite.json for this environment.
44
+ MSG
45
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Internal: Raised when the Vite executable can not be found.
4
+ class ViteRuby::MissingExecutableError < ViteRuby::Error
5
+ def initialize(error = nil)
6
+ super <<~MSG
7
+ ❌ The vite binary is not available. Have you installed Vite?
8
+
9
+ :troubleshooting:
10
+ #{ error }
11
+ MSG
12
+ end
13
+ end
@@ -10,11 +10,12 @@ class ViteRuby::Runner
10
10
 
11
11
  # Public: Executes Vite with the specified arguments.
12
12
  def run(argv, capture: false)
13
- if capture
14
- capture3_with_output(*command_for(argv), chdir: config.root)
15
- else
16
- Dir.chdir(config.root) { Kernel.exec(*command_for(argv)) }
17
- end
13
+ Dir.chdir(config.root) {
14
+ cmd = command_for(argv)
15
+ capture ? capture3_with_output(*cmd, chdir: config.root) : Kernel.exec(*cmd)
16
+ }
17
+ rescue Errno::ENOENT => error
18
+ raise ViteRuby::MissingExecutableError, error
18
19
  end
19
20
 
20
21
  private
@@ -29,15 +30,16 @@ private
29
30
  args = args.clone
30
31
  cmd.append('node', '--inspect-brk') if args.delete('--inspect')
31
32
  cmd.append('node', '--trace-deprecation') if args.delete('--trace_deprecation')
32
- cmd.append(*vite_executable(cmd))
33
+ cmd.append(vite_executable)
33
34
  cmd.append(*args)
34
35
  cmd.append('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
35
36
  end
36
37
  end
37
38
 
38
39
  # Internal: Resolves to an executable for Vite.
39
- def vite_executable(cmd)
40
- cmd.include?('node') ? ['./node_modules/.bin/vite'] : ['npx', '--no-install', '--', 'vite']
40
+ def vite_executable
41
+ bin_path = config.vite_bin_path
42
+ File.exist?(bin_path) ? bin_path : "#{ `npm bin`.chomp }/vite"
41
43
  end
42
44
 
43
45
  # Internal: A modified version of capture3 that continuosly prints stdout.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.2'
5
5
  end
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: 1.1.0
4
+ version: 1.2.2
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: 2021-03-07 00:00:00.000000000 Z
11
+ date: 2021-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -217,13 +217,17 @@ files:
217
217
  - lib/vite_ruby/builder.rb
218
218
  - lib/vite_ruby/cli.rb
219
219
  - lib/vite_ruby/cli/build.rb
220
+ - lib/vite_ruby/cli/clobber.rb
220
221
  - lib/vite_ruby/cli/dev.rb
221
222
  - lib/vite_ruby/cli/install.rb
222
223
  - lib/vite_ruby/cli/version.rb
223
224
  - lib/vite_ruby/commands.rb
224
225
  - lib/vite_ruby/config.rb
225
226
  - lib/vite_ruby/dev_server_proxy.rb
227
+ - lib/vite_ruby/error.rb
226
228
  - lib/vite_ruby/manifest.rb
229
+ - lib/vite_ruby/missing_entrypoint_error.rb
230
+ - lib/vite_ruby/missing_executable_error.rb
227
231
  - lib/vite_ruby/runner.rb
228
232
  - lib/vite_ruby/version.rb
229
233
  - templates/config/vite.config.ts
@@ -233,8 +237,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
233
237
  licenses:
234
238
  - MIT
235
239
  metadata:
236
- source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.1.0/vite_ruby
237
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.1.0/vite_ruby/CHANGELOG.md
240
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.2.2/vite_ruby
241
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.2.2/vite_ruby/CHANGELOG.md
238
242
  post_install_message:
239
243
  rdoc_options: []
240
244
  require_paths: