vite_ruby 1.1.2 → 1.2.4

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: 92002c0637f3091425c9ee24948c46105bf8ac61d2350dec3479f09e3e94d4ec
4
- data.tar.gz: 3e7f52fcb96735c8ec3a68618e7e7273a2abcdf81c1ba84be6b1d2f55cb41f0e
3
+ metadata.gz: c6458518b8b17adb635482493bd218588d7c46d6bff8e111b35083e7ef69e6eb
4
+ data.tar.gz: b2008263d7d2915f57df9762cd321bab1082172802787d894b6e10f6ae928a42
5
5
  SHA512:
6
- metadata.gz: ab1d9e7b5270d3de5d887da7a8d13659c742ea4df871c2e36c02d5de722b9847a5bc14cd20d72ad969a0f79cae053b92dd7015353086c68721dcdd643af61997
7
- data.tar.gz: ad906908aabe2d5fba3f0677ffc847fa59008ff186e62135f86b8ad0982727e55cd9a83ef4c7fa075a169c51411efdff8c7a03c78d1cceb52b91316924d47c2d
6
+ metadata.gz: 0b18bf0c81b828ad4d019761f479b916607a9c69f1979826816a86e84d97b3c9774e1463364256a286e575eff824f98231e09becc0b261e0a177cacca0c557db
7
+ data.tar.gz: c4c73277666975746a5054a5758bd93e07a00dfde34e67701342f8ef6abac5cc7b4c64b12ad786d5e5c19bf2a061c9254ae20744faf01a9345a78743e591a0c1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,55 @@
1
+ ## [1.2.4](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.3...vite_ruby@1.2.4) (2021-04-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Avoid removing `base` from proxied requests to avoid confusion. ([25f79a9](https://github.com/ElMassimo/vite_ruby/commit/25f79a9848df3e6c2ffbeb9bd4fbc44f73e4c68a))
7
+
8
+
9
+
10
+ ## [1.2.3](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.2...vite_ruby@1.2.3) (2021-04-15)
11
+
12
+
13
+ ### Features
14
+
15
+ * Add support for .scss, .less, and .styl entrypoints (close [#50](https://github.com/ElMassimo/vite_ruby/issues/50)) ([bb1d295](https://github.com/ElMassimo/vite_ruby/commit/bb1d2953b3a8c5862d26cdfcd5edc5cc918d1c5a))
16
+
17
+
18
+
19
+ ## [1.2.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.1...vite_ruby@1.2.2) (2021-03-20)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * Avoid prompts when using npx outside a CI ([ed7ccd7](https://github.com/ElMassimo/vite_ruby/commit/ed7ccd7d32c079ab78555ecd36dcb68ad2da331e))
25
+ * Simplify installation of build dependencies by using package manager flags ([5c8bb62](https://github.com/ElMassimo/vite_ruby/commit/5c8bb625926f2ab1788a3e3a22aeafd7104984cb))
26
+
27
+
28
+
29
+ ## [1.2.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.0...vite_ruby@1.2.1) (2021-03-19)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * Use the mode option in `clobber` ([add76b2](https://github.com/ElMassimo/vite_ruby/commit/add76b2a63ea64336235536b8b5670bace357b6e))
35
+
36
+
37
+
38
+ # [1.2.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.1.2...vite_ruby@1.2.0) (2021-03-19)
39
+
40
+
41
+ ### Bug Fixes
42
+
43
+ * 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))
44
+
45
+
46
+ ### Features
47
+
48
+ * Add `clobber` to the CLI, usable as `--clear` in the `dev` and `build` commands ([331d861](https://github.com/ElMassimo/vite_ruby/commit/331d86163c12eb3303d3975a94ecc205fa59dd41))
49
+ * Allow `clobber` to receive a `--mode` option. ([e6e7a6d](https://github.com/ElMassimo/vite_ruby/commit/e6e7a6dd0a2acf205d06877f76deb924c1d5aba7))
50
+
51
+
52
+
1
53
  ## [1.1.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.1.1...vite_ruby@1.1.2) (2021-03-19)
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/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'),
@@ -31,9 +31,9 @@ private
31
31
 
32
32
  def rewrite_uri_for_vite(env)
33
33
  uri = env.fetch('REQUEST_URI') { [env['PATH_INFO'], env['QUERY_STRING']].reject { |str| str.to_s.strip.empty? }.join('?') }
34
- .sub(vite_asset_url_prefix, '/')
35
34
  .sub(HOST_WITH_PORT_REGEX, '/') # Hanami adds the host and port.
36
35
  .sub('.ts.js', '.ts') # Hanami's javascript helper always adds the extension.
36
+ .sub(/(\.\w+)\.css$/, '\1') # Rails' stylesheet_link_tag always adds the extension.
37
37
  env['PATH_INFO'], env['QUERY_STRING'] = (env['REQUEST_URI'] = uri).split('?')
38
38
  end
39
39
 
@@ -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.sub(':mode', ViteRuby.mode) 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 `RACK_ENV=:mode 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.2'
4
+ VERSION = '1.2.4'
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.2
4
+ version: 1.2.4
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-19 00:00:00.000000000 Z
11
+ date: 2021-04-21 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.2/vite_ruby
237
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.1.2/vite_ruby/CHANGELOG.md
240
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.2.4/vite_ruby
241
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.2.4/vite_ruby/CHANGELOG.md
238
242
  post_install_message:
239
243
  rdoc_options: []
240
244
  require_paths: