vite_ruby 3.6.2 → 3.8.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: 1e1e2c37395b2cfb186b2c79267e25e5c4b129e2aea33ae65149bb7f87d35e64
4
- data.tar.gz: 94b174a0c5bda1db5bdccadfad545a5430c94c6515cd14c77489322dca40ac9d
3
+ metadata.gz: 0c3311945fbd58ebcc238980b0a10715e2a17603ecefd02f4d4aebea7cec7f24
4
+ data.tar.gz: e2f3336bc55528d31633cc679d70a28370d9eb88f914a940f46b80bd8d99c6db
5
5
  SHA512:
6
- metadata.gz: 338e68fd7be884ed89e390ad65a3718834ae5ed89e9b0953897225b878808e9286355558b1de0e7d307ab6cdef0ceabf129fe3ecbde706f65f36f6729c715150
7
- data.tar.gz: ef26d5734f92a257f3eea83b69f3c8a1f8ad76071854334a0f08207d7b9306c8c616a591b52995d978e21e0d1586d81def989038befaeac075445d844a555f33
6
+ metadata.gz: e8ab449ee34c34192ea1cca6c8cdc013b6d1d241371e8f2e92578e8cb040aca9f7cb7b2e1209094efc74d18f7bc2387afd960242230604a0a9210e8e37b5445e
7
+ data.tar.gz: 4ca76ee1e0288ce280e589668a3104e16c4e15a7efb0579301e5164465c18770ae93f68da9b9c3d6566a8b7a683ecffcd71f677241293d9052ef223209b97688
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ # [3.8.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.7.0...vite_ruby@3.8.0) (2024-08-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * remove `vite:clean` rake task as it can potentially break apps ([824b4ef](https://github.com/ElMassimo/vite_ruby/commit/824b4ef8397828423d2ddda117bf27e365954961)), closes [#438](https://github.com/ElMassimo/vite_ruby/issues/438) [#490](https://github.com/ElMassimo/vite_ruby/issues/490) [#404](https://github.com/ElMassimo/vite_ruby/issues/404)
7
+
8
+
9
+ ### Features
10
+
11
+ * remove `ostruct` dependency (closes [#489](https://github.com/ElMassimo/vite_ruby/issues/489)) ([1dfec47](https://github.com/ElMassimo/vite_ruby/commit/1dfec4759bf2c107433c5f1618d97439f6d5bd01))
12
+
13
+
14
+
15
+ # [3.7.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.6.2...vite_ruby@3.7.0) (2024-07-17)
16
+
17
+
18
+ ### Features
19
+
20
+ * 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)
21
+ * 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)
22
+
23
+
24
+
1
25
  ## [3.6.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.6.1...vite_ruby@3.6.2) (2024-07-16)
2
26
 
3
27
 
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
@@ -25,11 +25,6 @@ namespace :vite do
25
25
  ViteRuby.commands.build_from_task('--ssr') if ViteRuby.config.ssr_build_enabled
26
26
  end
27
27
 
28
- desc 'Remove old bundles created by ViteRuby'
29
- task :clean, [:keep, :age] => :'vite:verify_install' do |_, args|
30
- ViteRuby.commands.clean_from_task(args)
31
- end
32
-
33
28
  desc 'Remove the build output directory for ViteRuby'
34
29
  task clobber: :'vite:verify_install' do
35
30
  ViteRuby.commands.clobber
@@ -43,10 +38,13 @@ namespace :vite do
43
38
  desc 'Ensure build dependencies like Vite are installed before bundling'
44
39
  task :install_dependencies do
45
40
  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?
41
+
42
+ install_cmd = case (pkg = ViteRuby.config.package_manager)
43
+ when 'npm' then 'npm ci'
44
+ else "#{ pkg } install --frozen-lockfile"
45
+ end
46
+
47
+ system(install_env_args, install_cmd)
50
48
  end
51
49
 
52
50
  desc "Provide information on ViteRuby's environment"
@@ -73,14 +71,6 @@ unless ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION'] == 'true'
73
71
  end
74
72
  end
75
73
 
76
- unless Rake::Task.task_defined?('assets:clean')
77
- desc 'Remove old compiled assets'
78
- Rake::Task.define_task('assets:clean', [:keep, :age])
79
- end
80
- Rake::Task['assets:clean'].enhance do |_, args|
81
- Rake::Task['vite:clean'].invoke(*args.to_h.values)
82
- end
83
-
84
74
  if Rake::Task.task_defined?('assets:clobber')
85
75
  Rake::Task['assets:clobber'].enhance do
86
76
  Rake::Task['vite:clobber'].invoke
@@ -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'
@@ -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
@@ -28,38 +28,6 @@ class ViteRuby::Commands
28
28
  $stdout.puts "Removed vite cache and output dirs:\n\t#{ dirs.join("\n\t") }"
29
29
  end
30
30
 
31
- # Public: Receives arguments from a rake task.
32
- def clean_from_task(args)
33
- ensure_log_goes_to_stdout {
34
- clean(keep_up_to: Integer(args.keep || 2), age_in_seconds: Integer(args.age || 3600))
35
- }
36
- end
37
-
38
- # Public: Cleanup old assets in the output directory.
39
- #
40
- # keep_up_to - Max amount of backups to preserve.
41
- # age_in_seconds - Amount of time to look back in order to preserve them.
42
- #
43
- # NOTE: By default keeps the last version, or 2 if created in the past hour.
44
- #
45
- # Examples:
46
- # To force only 1 backup to be kept: clean(1, 0)
47
- # To only keep files created within the last 10 minutes: clean(0, 600)
48
- def clean(keep_up_to: 2, age_in_seconds: 3600)
49
- return false unless may_clean?
50
-
51
- versions
52
- .each_with_index
53
- .drop_while { |(mtime, _files), index|
54
- max_age = [0, Time.now - Time.at(mtime)].max
55
- max_age < age_in_seconds || index < keep_up_to
56
- }
57
- .each do |(_, files), _|
58
- clean_files(files)
59
- end
60
- true
61
- end
62
-
63
31
  # Internal: Installs the binstub for the CLI in the appropriate path.
64
32
  def install_binstubs
65
33
  `bundle binstub vite_ruby --path #{ config.root.join('bin') }`
@@ -109,11 +77,11 @@ class ViteRuby::Commands
109
77
  $stdout.puts "#{ framework }: #{ Gem.loaded_specs[framework]&.version }"
110
78
  end
111
79
 
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
80
  $stdout.puts "ruby: #{ `ruby --version` }"
81
+ $stdout.puts "node: #{ `node --version` }"
82
+
83
+ pkg = config.package_manager
84
+ $stdout.puts "#{ pkg }: #{ `#{ pkg } --version` rescue nil }"
117
85
 
118
86
  $stdout.puts "\n"
119
87
  packages = `npm ls vite vite-plugin-ruby`
@@ -130,31 +98,6 @@ private
130
98
 
131
99
  def_delegators :@vite_ruby, :config, :builder, :manifest, :logger, :logger=
132
100
 
133
- def may_clean?
134
- config.build_output_dir.exist? && config.manifest_paths.any?
135
- end
136
-
137
- def clean_files(files)
138
- files.select { |file| File.file?(file) }.each do |file|
139
- File.delete(file)
140
- logger.info("Removed #{ file }")
141
- end
142
- end
143
-
144
- def versions
145
- all_files = Dir.glob("#{ config.build_output_dir }/**/*")
146
- entries = all_files - config.manifest_paths - files_referenced_in_manifests
147
- entries.reject { |file| File.directory?(file) }
148
- .group_by { |file| File.mtime(file).utc.to_i }
149
- .sort.reverse
150
- end
151
-
152
- def files_referenced_in_manifests
153
- config.manifest_paths.flat_map { |path|
154
- JSON.parse(path.read).map { |_, entry| entry['file'] }
155
- }.compact.uniq.map { |path| config.build_output_dir.join(path).to_s }
156
- end
157
-
158
101
  def with_node_env(env)
159
102
  original = ENV['NODE_ENV']
160
103
  ENV['NODE_ENV'] = env
@@ -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
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ostruct'
4
-
5
3
  # Public: Registry for accessing resources managed by Vite, using a generated
6
4
  # manifest file which maps entrypoint names to file paths.
7
5
  #
@@ -214,7 +212,7 @@ private
214
212
 
215
213
  # Internal: Raises a detailed message when an entry is missing in the manifest.
216
214
  def missing_entry_error(name, **options)
217
- raise ViteRuby::MissingEntrypointError, OpenStruct.new(
215
+ raise ViteRuby::MissingEntrypointError.new(
218
216
  file_name: resolve_entry_name(name, **options),
219
217
  last_build: builder.last_build_metadata,
220
218
  manifest: @manifest,
@@ -5,11 +5,10 @@
5
5
  # NOTE: The complexity here is justified by the improved usability of providing
6
6
  # a more specific error message depending on the situation.
7
7
  class ViteRuby::MissingEntrypointError < ViteRuby::Error
8
- extend Forwardable
9
- def_delegators :@info, :file_name, :last_build, :manifest, :config
8
+ attr_reader :file_name, :last_build, :manifest, :config
10
9
 
11
- def initialize(info)
12
- @info = info
10
+ def initialize(file_name:, last_build:, manifest:, config:)
11
+ @file_name, @last_build, @manifest, @config = file_name, last_build, manifest, config
13
12
  super <<~MSG
14
13
  Vite Ruby can't find #{ file_name } in the manifests.
15
14
 
@@ -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.2'
4
+ VERSION = '3.8.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.2
4
+ version: 3.8.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-08-12 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.2/vite_ruby
212
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.6.2/vite_ruby/CHANGELOG.md
211
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.8.0/vite_ruby
212
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.8.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: []