vite_ruby 3.1.1 → 3.1.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: 272fe6da1fb380725808470d8a54d547343027d8f81df36f0535bda3a6a0f0db
4
- data.tar.gz: 0d906d89d6f6d5ce8502555117013fc0a1f325e26533419972f089913ea8da69
3
+ metadata.gz: b89bf35a3d3734c64977195bf0695546b121e9ff83d02859475f503fdd65f865
4
+ data.tar.gz: dda1241e89c4f794504e51c9c47cffa8eb37238fc17406432a876e49328600eb
5
5
  SHA512:
6
- metadata.gz: a094dd8a9123615b06e1266515015d5c2ef8a82842b006a6262f552e0412e68465b8c7a45c2a16749d23abba5577d9a4c89ec125b59b68bad5767db9f800750a
7
- data.tar.gz: 765d8ddd8023f28029eeff363815257b3b1b1601c652f6df213a53c9a39a1f9bd47ee63af11b8c9dc6ab2c845843988aebec4195c3cb885c131c56e40c488615
6
+ metadata.gz: 62a5252117efadda1bedaf21b8bcb63b86f6489eed35706e2afbc2ecb9c8258f944c1b6b4276884b5920671b528e96bc9c00a4fd034932b79842dcbc8ec50612
7
+ data.tar.gz: d0425780b02d50a35a79d6791134bf400aebdf07abb9c19c70e692976c68062ec681364486d44c95c5592a4f802db856daca6afe0b3fa7cb8b8b669c5d8e3ccc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [3.1.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.1...vite_ruby@3.1.2) (2022-05-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * add support for SSR builds (experimental) ([#212](https://github.com/ElMassimo/vite_ruby/issues/212)) ([4d6cd2b](https://github.com/ElMassimo/vite_ruby/commit/4d6cd2b84f670b1703e3bde7033e822be97bf505))
7
+ * ignore any vite dirs in .gitignore installation (for ssr builds) ([fd68420](https://github.com/ElMassimo/vite_ruby/commit/fd68420dfaeb79b97f8edade5bf17bfe81fd2486))
8
+
9
+
10
+
1
11
  ## [3.1.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.0...vite_ruby@3.1.1) (2022-04-14)
2
12
 
3
13
 
data/default.vite.json CHANGED
@@ -17,5 +17,8 @@
17
17
  "hideBuildConsoleOutput": false,
18
18
  "viteBinPath": "node_modules/.bin/vite",
19
19
  "watchAdditionalPaths": [],
20
- "base": ""
20
+ "base": "",
21
+ "ssrBuildEnabled": false,
22
+ "ssrEntrypoint": "~/ssr/ssr.{js,ts,jsx,tsx}",
23
+ "ssrOutputDir": "public/ssr"
21
24
  }
data/lib/tasks/vite.rake CHANGED
@@ -9,27 +9,38 @@ namespace :vite do
9
9
  ViteRuby.commands.install_binstubs
10
10
  end
11
11
 
12
- desc 'Compile JavaScript packs using vite for production with digests'
12
+ desc 'Bundle frontend entrypoints using ViteRuby'
13
13
  task build: :'vite:verify_install' do
14
14
  ViteRuby.commands.build_from_task
15
15
  end
16
16
 
17
- desc 'Remove old compiled vites'
17
+ desc 'Bundle a Node.js app from the SSR entrypoint using ViteRuby'
18
+ task build_ssr: :'vite:verify_install' do
19
+ ViteRuby.commands.build_from_task('--ssr')
20
+ end
21
+
22
+ desc 'Bundle entrypoints using Vite Ruby (SSR only if enabled)'
23
+ task build_all: :'vite:verify_install' do
24
+ ViteRuby.commands.build_from_task
25
+ ViteRuby.commands.build_from_task('--ssr') if ViteRuby.config.ssr_build_enabled
26
+ end
27
+
28
+ desc 'Remove old bundles created by ViteRuby'
18
29
  task :clean, [:keep, :age] => :'vite:verify_install' do |_, args|
19
30
  ViteRuby.commands.clean_from_task(args)
20
31
  end
21
32
 
22
- desc 'Remove the vite build output directory'
33
+ desc 'Remove the build output directory for ViteRuby'
23
34
  task clobber: :'vite:verify_install' do
24
35
  ViteRuby.commands.clobber
25
36
  end
26
37
 
27
- desc 'Verifies if ViteRuby is properly installed in this application'
38
+ desc 'Verify if ViteRuby is properly installed in the app'
28
39
  task :verify_install do
29
40
  ViteRuby.commands.verify_install
30
41
  end
31
42
 
32
- desc 'Ensures build dependencies like Vite are installed when compiling assets'
43
+ desc 'Ensure build dependencies like Vite are installed before bundling'
33
44
  task :install_dependencies do
34
45
  system({ 'NODE_ENV' => 'development' }, 'npx ci --yes')
35
46
  end
@@ -45,10 +56,10 @@ unless ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION'] == 'true'
45
56
  Rake::Task['assets:precompile'].enhance do |task|
46
57
  prefix = task.name.split(/#|assets:precompile/).first
47
58
  Rake::Task["#{ prefix }vite:install_dependencies"].invoke
48
- Rake::Task["#{ prefix }vite:build"].invoke
59
+ Rake::Task["#{ prefix }vite:build_all"].invoke
49
60
  end
50
61
  else
51
- Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build'])
62
+ Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build_all'])
52
63
  end
53
64
 
54
65
  unless Rake::Task.task_defined?('assets:clean')
@@ -1,17 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'time'
4
5
 
5
6
  # Internal: Value object with information about the last build.
6
- ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current_digest) do
7
+ ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current_digest, :last_build_path) do
7
8
  # Internal: Combines information from a previous build with the current digest.
8
- def self.from_previous(attrs, 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) : {}
13
+ rescue JSON::JSONError, Errno::ENOENT, Errno::ENOTDIR
14
+ {}
15
+ end
16
+
9
17
  new(
10
18
  attrs['success'],
11
19
  attrs['timestamp'] || 'never',
12
20
  attrs['vite_ruby'] || 'unknown',
13
21
  attrs['digest'] || 'none',
14
22
  current_digest,
23
+ last_build_path,
15
24
  )
16
25
  end
17
26
 
@@ -42,11 +51,23 @@ ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current
42
51
  Time.now.strftime('%F %T'),
43
52
  ViteRuby::VERSION,
44
53
  current_digest,
54
+ current_digest,
55
+ last_build_path,
45
56
  )
46
57
  end
47
58
 
59
+ # Internal: Writes the result of the new build to a local file.
60
+ def write_to_cache
61
+ last_build_path.write to_json
62
+ end
63
+
48
64
  # Internal: Returns a JSON string with the metadata of the build.
49
65
  def to_json(*_args)
50
- JSON.pretty_generate(to_h)
66
+ JSON.pretty_generate(
67
+ success: success,
68
+ timestamp: timestamp,
69
+ vite_ruby: vite_ruby,
70
+ digest: digest,
71
+ )
51
72
  end
52
73
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
3
  require 'digest/sha1'
5
4
 
6
5
  # Public: Keeps track of watched files and triggers builds as needed.
@@ -12,7 +11,8 @@ class ViteRuby::Builder
12
11
  # Public: Checks if the watched files have changed since the last compilation,
13
12
  # and triggers a Vite build if any files have changed.
14
13
  def build(*args)
15
- last_build = last_build_metadata
14
+ last_build = last_build_metadata(ssr: args.include?('--ssr'))
15
+
16
16
  if args.delete('--force') || last_build.stale?
17
17
  build_with_vite(*args).tap { |success| record_build_metadata(success, last_build) }
18
18
  elsif last_build.success
@@ -25,8 +25,8 @@ class ViteRuby::Builder
25
25
  end
26
26
 
27
27
  # Internal: Reads the result of the last compilation from disk.
28
- def last_build_metadata
29
- ViteRuby::Build.from_previous(last_build_attrs, watched_files_digest)
28
+ def last_build_metadata(ssr: false)
29
+ ViteRuby::Build.from_previous(last_build_path(ssr: ssr), watched_files_digest)
30
30
  end
31
31
 
32
32
  private
@@ -35,22 +35,15 @@ private
35
35
 
36
36
  def_delegators :@vite_ruby, :config, :logger, :run
37
37
 
38
- # Internal: Reads metadata recorded on the last build, if it exists.
39
- def last_build_attrs
40
- last_build_path.exist? ? JSON.parse(last_build_path.read.to_s) : {}
41
- rescue JSON::JSONError, Errno::ENOENT, Errno::ENOTDIR
42
- {}
43
- end
44
-
45
38
  # Internal: Writes a digest of the watched files to disk for future checks.
46
39
  def record_build_metadata(success, build)
47
40
  config.build_cache_dir.mkpath
48
- last_build_path.write build.with_result(success).to_json
41
+ build.with_result(success).write_to_cache
49
42
  end
50
43
 
51
44
  # Internal: The file path where metadata of the last build is stored.
52
- def last_build_path
53
- config.build_cache_dir.join("last-build-#{ config.mode }.json")
45
+ def last_build_path(ssr:)
46
+ config.build_cache_dir.join("last#{ '-ssr' if ssr }-build-#{ config.mode }.json")
54
47
  end
55
48
 
56
49
  # Internal: Returns a digest of all the watched files, allowing to detect
@@ -5,6 +5,7 @@ class ViteRuby::CLI::Build < ViteRuby::CLI::Vite
5
5
 
6
6
  desc 'Bundle all entrypoints using Vite.'
7
7
  shared_options
8
+ option(:ssr, desc: 'Build the SSR entrypoint instead', type: :boolean)
8
9
  option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)
9
10
  option(:watch, desc: 'Start the Rollup watcher and rebuild on files changes', type: :boolean)
10
11
 
@@ -91,9 +91,7 @@ private
91
91
  append(gitignore_file, <<~GITIGNORE)
92
92
 
93
93
  # Vite Ruby
94
- /public/vite
95
- /public/vite-dev
96
- /public/vite-test
94
+ /public/vite*
97
95
  node_modules
98
96
  # Vite uses dotenv and suggests to ignore local-only env files. See
99
97
  # https://vitejs.dev/guide/env-and-mode.html#env-files
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ViteRuby::CLI::SSR < ViteRuby::CLI::Vite
4
+ DEFAULT_ENV = CURRENT_ENV || 'production'
5
+
6
+ desc 'Run the resulting app from building in SSR mode.'
7
+ executable_options
8
+
9
+ def call(mode:, inspect: false, trace_deprecation: false)
10
+ ViteRuby.env['VITE_RUBY_MODE'] = mode
11
+ cmd = [
12
+ 'node',
13
+ ('--inspect-brk' if inspect),
14
+ ('--trace-deprecation' if trace_deprecation),
15
+ ViteRuby.config.ssr_output_dir.join('ssr.js'),
16
+ ]
17
+ Kernel.exec(*cmd.compact.map(&:to_s))
18
+ end
19
+ end
@@ -3,14 +3,18 @@
3
3
  class ViteRuby::CLI::Vite < Dry::CLI::Command
4
4
  CURRENT_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV']
5
5
 
6
- def self.shared_options
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(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
9
- option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
10
8
  option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
11
9
  option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
12
10
  end
13
11
 
12
+ def self.shared_options
13
+ executable_options
14
+ option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
15
+ option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
16
+ end
17
+
14
18
  def call(mode:, args: [], clobber: false, **boolean_opts)
15
19
  ViteRuby.env['VITE_RUBY_MODE'] = mode
16
20
  ViteRuby.commands.clobber if clobber
data/lib/vite_ruby/cli.rb CHANGED
@@ -11,6 +11,7 @@ class ViteRuby::CLI
11
11
  register 'clobber', Clobber, aliases: %w[clean clear]
12
12
  register 'dev', Dev, aliases: %w[d serve]
13
13
  register 'install', Install
14
+ register 'ssr', SSR
14
15
  register 'version', Version, aliases: ['v', '-v', '--version', 'info']
15
16
  register 'upgrade', Upgrade, aliases: ['update']
16
17
  register 'upgrade_packages', UpgradePackages, aliases: ['update_packages']
@@ -23,7 +23,7 @@ class ViteRuby::Commands
23
23
 
24
24
  # Public: Removes all build cache and previously compiled assets.
25
25
  def clobber
26
- dirs = [config.build_output_dir, config.build_cache_dir, config.vite_cache_dir]
26
+ dirs = [config.build_output_dir, config.ssr_output_dir, config.build_cache_dir, config.vite_cache_dir]
27
27
  dirs.each { |dir| dir.rmtree if dir.exist? }
28
28
  $stdout.puts "Removed vite cache and output dirs:\n\t#{ dirs.join("\n\t") }"
29
29
  end
@@ -24,7 +24,7 @@ module ViteRuby::CompatibilityCheck
24
24
  raise ArgumentError, <<~ERROR
25
25
  vite-plugin-ruby@#{ npm_req } might not be compatible with vite_ruby-#{ ViteRuby::VERSION }
26
26
 
27
- You may disable this check if needed: https://vite-ruby.netlify.app/config/#skipCompatibilityCheck
27
+ You may disable this check if needed: https://vite-ruby.netlify.app/config/#skipcompatibilitycheck
28
28
 
29
29
  You may upgrade both by running:
30
30
 
@@ -79,6 +79,7 @@ private
79
79
  config['port'] = config['port'].to_i
80
80
  config['root'] = Pathname.new(config['root'])
81
81
  config['build_cache_dir'] = config['root'].join(config['build_cache_dir'])
82
+ config['ssr_output_dir'] = config['root'].join(config['ssr_output_dir'])
82
83
  coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https', 'skip_compatibility_check')
83
84
  end
84
85
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '3.1.1'
4
+ VERSION = '3.1.2'
5
5
 
6
6
  # Internal: Versions used by default when running `vite install`.
7
7
  DEFAULT_VITE_VERSION = '^2.9.1'
data/lib/vite_ruby.rb CHANGED
@@ -11,6 +11,7 @@ loader.ignore("#{ __dir__ }/install")
11
11
  loader.ignore("#{ __dir__ }/tasks")
12
12
  loader.ignore("#{ __dir__ }/exe")
13
13
  loader.inflector.inflect('cli' => 'CLI')
14
+ loader.inflector.inflect('ssr' => 'SSR')
14
15
  loader.inflector.inflect('io' => 'IO')
15
16
  loader.setup
16
17
 
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.1.1
4
+ version: 3.1.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: 2022-04-14 00:00:00.000000000 Z
11
+ date: 2022-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -179,6 +179,7 @@ files:
179
179
  - lib/vite_ruby/cli/dev.rb
180
180
  - lib/vite_ruby/cli/file_utils.rb
181
181
  - lib/vite_ruby/cli/install.rb
182
+ - lib/vite_ruby/cli/ssr.rb
182
183
  - lib/vite_ruby/cli/upgrade.rb
183
184
  - lib/vite_ruby/cli/upgrade_packages.rb
184
185
  - lib/vite_ruby/cli/version.rb
@@ -201,8 +202,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
201
202
  licenses:
202
203
  - MIT
203
204
  metadata:
204
- source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.1.1/vite_ruby
205
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.1.1/vite_ruby/CHANGELOG.md
205
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.1.2/vite_ruby
206
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.1.2/vite_ruby/CHANGELOG.md
206
207
  post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
207
208
  manually, please run:\n\tbundle exec vite upgrade"
208
209
  rdoc_options: []