vite_ruby 3.6.1 → 3.7.0

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: c43c5405ffc154281d526ae4c1f2b99c4b1c81c2161477573d9b08534fcef2e5
4
- data.tar.gz: 9ea913409fd700fee2c2d666fa208af2886a62a1b3ad81aa186bee9e02e33024
3
+ metadata.gz: 99a8b071373aa761774cd95dd665040264cc7646114315edeecc3e355af3ef23
4
+ data.tar.gz: 1276207af761a598b3ea291ead1ccc2ceafb13117adcc150988d4532b8c71ae3
5
5
  SHA512:
6
- metadata.gz: d012ee60dd480fd9f6ed6f7fb53a539112f891ac582fbaf26c6b7baa38151fa4e647cbd6bf7f4173d4dffa43d9a41360ea7ff9d7ebe550a95375dc35cc75c996
7
- data.tar.gz: 907d01e3458f7dc82b832815b700a94c13e4e79144a4b5ebd0466a7d074d98edbb6148614ba0545c1750d81e6c3ef89ba00ee7904c8c09def8cc2686330dccdc
6
+ metadata.gz: c213bbcc8ed5aeed6c8862f51fa096be5fc8d9cfa3c708c7e50a607869c94d8989cf5484704ec4f155760b7f6e53f3be2ab11526e7b2c9df1849b121bb7d79d4
7
+ data.tar.gz: 2f5d739582f2d1135ee5326cc8ffdd5c773dac791828317a61f7ff32a352d54e77f38d32d3d6b174f6439c98ff27479a786352b740f485c834b4f0e68cb67878
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [3.7.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.6.2...vite_ruby@3.7.0) (2024-07-17)
2
+
3
+
4
+ ### Features
5
+
6
+ * add `package_manager` config option, experimental support for bun ([#481](https://github.com/ElMassimo/vite_ruby/issues/481)) ([4426cb1](https://github.com/ElMassimo/vite_ruby/commit/4426cb1007dbb58f4637a4423b1e7d640db96841)), closes [#324](https://github.com/ElMassimo/vite_ruby/issues/324)
7
+ * change default execution to use `npx vite` instead ([#480](https://github.com/ElMassimo/vite_ruby/issues/480)) ([330f61f](https://github.com/ElMassimo/vite_ruby/commit/330f61fedadf1274547a069856125e52002d0065)), closes [#462](https://github.com/ElMassimo/vite_ruby/issues/462)
8
+
9
+
10
+
11
+ ## [3.6.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.6.1...vite_ruby@3.6.2) (2024-07-16)
12
+
13
+
14
+
1
15
  ## [3.6.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.6.0...vite_ruby@3.6.1) (2024-07-16)
2
16
 
3
17
 
data/default.vite.json CHANGED
@@ -7,6 +7,7 @@
7
7
  "publicOutputDir": "vite",
8
8
  "configPath": "config/vite.json",
9
9
  "devServerConnectTimeout": 0.01,
10
+ "packageManager": null,
10
11
  "publicDir": "public",
11
12
  "entrypointsDir": "entrypoints",
12
13
  "sourceCodeDir": "app/frontend",
@@ -16,7 +17,7 @@
16
17
  "https": null,
17
18
  "port": 3036,
18
19
  "hideBuildConsoleOutput": false,
19
- "viteBinPath": "node_modules/.bin/vite",
20
+ "viteBinPath": null,
20
21
  "watchAdditionalPaths": [],
21
22
  "base": "",
22
23
  "ssrBuildEnabled": false,
data/lib/tasks/vite.rake CHANGED
@@ -43,10 +43,13 @@ namespace :vite do
43
43
  desc 'Ensure build dependencies like Vite are installed before bundling'
44
44
  task :install_dependencies do
45
45
  install_env_args = ENV['VITE_RUBY_SKIP_INSTALL_DEV_DEPENDENCIES'] == 'true' ? {} : { 'NODE_ENV' => 'development' }
46
- cmd = ViteRuby.commands.legacy_npm_version? ? 'npx ci --yes' : 'npx --yes ci'
47
- result = system(install_env_args, cmd)
48
- # Fallback to `yarn` if `npx` is not available.
49
- system(install_env_args, 'yarn install --frozen-lockfile') if result.nil?
46
+
47
+ install_cmd = case (pkg = ViteRuby.config.package_manager)
48
+ when 'npm' then 'npm ci'
49
+ else "#{ pkg } install --frozen-lockfile"
50
+ end
51
+
52
+ system(install_env_args, install_cmd)
50
53
  end
51
54
 
52
55
  desc "Provide information on ViteRuby's environment"
@@ -6,7 +6,11 @@ require 'json'
6
6
  class ViteRuby::CLI::Install < Dry::CLI::Command
7
7
  desc 'Performs the initial configuration setup to get started with Vite Ruby.'
8
8
 
9
- def call(**)
9
+ option(:package_manager, values: %w[npm pnpm yarn bun], aliases: %w[package-manager with], desc: 'The package manager to use when installing JS dependencies.')
10
+
11
+ def call(package_manager: nil, **)
12
+ ENV['VITE_RUBY_PACKAGE_MANAGER'] ||= package_manager if package_manager
13
+
10
14
  $stdout.sync = true
11
15
 
12
16
  say 'Creating binstub'
@@ -81,7 +85,7 @@ private
81
85
  def install_js_dependencies
82
86
  package_json = root.join('package.json')
83
87
  unless package_json.exist?
84
- write(package.json, <<~JSON)
88
+ write package_json, <<~JSON
85
89
  {
86
90
  "private": true,
87
91
  "type": "module"
@@ -93,8 +97,7 @@ private
93
97
  FileUtils.mv root.join('vite.config.ts'), root.join('vite.config.mts'), force: true, verbose: true
94
98
  end
95
99
 
96
- deps = js_dependencies.join(' ')
97
- run_with_capture("#{ npm_install } -D #{ deps }", stdin_data: "\n")
100
+ install_js_packages js_dependencies.join(' ')
98
101
  end
99
102
 
100
103
  # Internal: Adds compilation output dirs to git ignore.
@@ -128,12 +131,8 @@ private
128
131
  end
129
132
  end
130
133
 
131
- # Internal: Support all popular package managers.
132
- def npm_install
133
- return 'yarn add' if root.join('yarn.lock').exist?
134
- return 'pnpm install' if root.join('pnpm-lock.yaml').exist?
135
-
136
- 'npm install'
134
+ def install_js_packages(deps)
135
+ run_with_capture("#{ config.package_manager } add -D #{ deps }", stdin_data: "\n")
137
136
  end
138
137
 
139
138
  # Internal: Avoid printing warning about missing vite.json, we will create one.
@@ -5,7 +5,6 @@ class ViteRuby::CLI::UpgradePackages < ViteRuby::CLI::Install
5
5
 
6
6
  def call(**)
7
7
  say 'Upgrading npm packages'
8
- deps = js_dependencies.join(' ')
9
- run_with_capture("#{ npm_install } -D #{ deps }")
8
+ install_js_packages js_dependencies.join(' ')
10
9
  end
11
10
  end
@@ -5,6 +5,7 @@ class ViteRuby::CLI::Vite < Dry::CLI::Command
5
5
 
6
6
  def self.executable_options
7
7
  option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: ['m'], desc: 'The build mode for Vite')
8
+ option(:node_options, desc: 'Node options for the Vite executable', aliases: ['node-options'])
8
9
  option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
9
10
  option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
10
11
  end
@@ -15,10 +16,20 @@ class ViteRuby::CLI::Vite < Dry::CLI::Command
15
16
  option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
16
17
  end
17
18
 
18
- def call(mode:, args: [], clobber: false, **boolean_opts)
19
+ def call(mode:, args: [], clobber: false, node_options: nil, inspect: nil, trace_deprecation: nil, **boolean_opts)
19
20
  ViteRuby.env['VITE_RUBY_MODE'] = mode
20
21
  ViteRuby.commands.clobber if clobber
22
+
23
+ node_options = [
24
+ node_options,
25
+ ('--inspect-brk' if inspect),
26
+ ('--trace-deprecation' if trace_deprecation),
27
+ ].compact.join(' ')
28
+
29
+ args << %(--node-options="#{ node_options }") unless node_options.empty?
30
+
21
31
  boolean_opts.map { |name, value| args << "--#{ name }" if value }
32
+
22
33
  yield(args)
23
34
  end
24
35
  end
@@ -109,11 +109,11 @@ class ViteRuby::Commands
109
109
  $stdout.puts "#{ framework }: #{ Gem.loaded_specs[framework]&.version }"
110
110
  end
111
111
 
112
- $stdout.puts "node: #{ `node --version` }"
113
- $stdout.puts "npm: #{ `npm --version` }"
114
- $stdout.puts "yarn: #{ `yarn --version` rescue nil }"
115
- $stdout.puts "pnpm: #{ `pnpm --version` rescue nil }"
116
112
  $stdout.puts "ruby: #{ `ruby --version` }"
113
+ $stdout.puts "node: #{ `node --version` }"
114
+
115
+ pkg = config.package_manager
116
+ $stdout.puts "#{ pkg }: #{ `#{ pkg } --version` rescue nil }"
117
117
 
118
118
  $stdout.puts "\n"
119
119
  packages = `npm ls vite vite-plugin-ruby`
@@ -96,10 +96,11 @@ private
96
96
  def coerce_values(config)
97
97
  config['mode'] = config['mode'].to_s
98
98
  config['port'] = config['port'].to_i
99
- config['root'] = Pathname.new(config['root'])
100
- config['build_cache_dir'] = config['root'].join(config['build_cache_dir'])
101
- config['ssr_output_dir'] = config['root'].join(config['ssr_output_dir'])
99
+ config['root'] = root = Pathname.new(config['root'])
100
+ config['build_cache_dir'] = root.join(config['build_cache_dir'])
101
+ config['ssr_output_dir'] = root.join(config['ssr_output_dir'])
102
102
  coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https', 'skip_compatibility_check', 'skip_proxy')
103
+ config['package_manager'] ||= detect_package_manager(root)
103
104
  end
104
105
 
105
106
  # Internal: Coerces configuration options to boolean.
@@ -107,6 +108,15 @@ private
107
108
  names.each { |name| config[name] = [true, 'true'].include?(config[name]) }
108
109
  end
109
110
 
111
+ def detect_package_manager(root)
112
+ return 'npm' if root.join('package-lock.json').exist?
113
+ return 'pnpm' if root.join('pnpm-lock.yaml').exist?
114
+ return 'bun' if root.join('bun.lockb').exist?
115
+ return 'yarn' if root.join('yarn.lock').exist?
116
+
117
+ 'npm'
118
+ end
119
+
110
120
  def initialize(attrs)
111
121
  @config = attrs.tap { |config| coerce_values(config) }.freeze
112
122
  ViteRuby::CompatibilityCheck.verify_plugin_version(root) unless skip_compatibility_check
@@ -189,6 +199,7 @@ private
189
199
 
190
200
  # Internal: If any of these files is modified the build won't be skipped.
191
201
  DEFAULT_WATCHED_PATHS = %w[
202
+ bun.lockb
192
203
  package-lock.json
193
204
  package.json
194
205
  pnpm-lock.yaml
@@ -196,8 +207,8 @@ private
196
207
  tailwind.config.js
197
208
  vite.config.js
198
209
  vite.config.mjs
199
- vite.config.ts
200
210
  vite.config.mts
211
+ vite.config.ts
201
212
  windi.config.ts
202
213
  yarn.lock
203
214
  ].freeze
@@ -28,24 +28,26 @@ private
28
28
  # Internal: Returns an Array with the command to run.
29
29
  def command_for(args)
30
30
  [config.to_env(env)].tap do |cmd|
31
- args = args.clone
32
- cmd.push('node', '--inspect-brk') if args.delete('--inspect')
33
- cmd.push('node', '--trace-deprecation') if args.delete('--trace_deprecation')
34
- cmd.push(*vite_executable)
35
- cmd.push(*args)
31
+ exec_args, vite_args = args.partition { |arg| arg.start_with?('--node-options') }
32
+ cmd.push(*vite_executable(*exec_args))
33
+ cmd.push(*vite_args)
36
34
  cmd.push('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
37
35
  end
38
36
  end
39
37
 
40
38
  # Internal: Resolves to an executable for Vite.
41
- def vite_executable
39
+ def vite_executable(*exec_args)
42
40
  bin_path = config.vite_bin_path
43
- return [bin_path] if File.exist?(bin_path)
44
-
45
- if config.root.join('yarn.lock').exist?
46
- %w[yarn vite]
47
- else
48
- ["#{ `npm bin`.chomp }/vite"]
41
+ return [bin_path] if bin_path && File.exist?(bin_path)
42
+
43
+ x = case config.package_manager
44
+ when 'npm' then %w[npx]
45
+ when 'pnpm' then %w[pnpm exec]
46
+ when 'bun' then %w[bun x]
47
+ when 'yarn' then %w[yarn]
48
+ else raise ArgumentError, "Unknown package manager #{ config.package_manager.inspect }"
49
49
  end
50
+
51
+ [*x, *exec_args, 'vite']
50
52
  end
51
53
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '3.6.1'
4
+ VERSION = '3.7.0'
5
5
 
6
6
  # Internal: Versions used by default when running `vite install`.
7
7
  DEFAULT_VITE_VERSION = '^5.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.6.1
4
+ version: 3.7.0
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: 2024-07-16 00:00:00.000000000 Z
11
+ date: 2024-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -208,8 +208,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
208
208
  licenses:
209
209
  - MIT
210
210
  metadata:
211
- source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.6.1/vite_ruby
212
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.6.1/vite_ruby/CHANGELOG.md
211
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.7.0/vite_ruby
212
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.7.0/vite_ruby/CHANGELOG.md
213
213
  post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
214
214
  manually, please run:\n\tbundle exec vite upgrade"
215
215
  rdoc_options: []