vite_ruby 1.2.12 → 1.2.17

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: c773a06d1ae5abbf91dd4e08eaed27f23ea436277c9ca6515e727b1f36492ed7
4
- data.tar.gz: a11954fbfd1392bd2a3c8b070c9d53218294f51edcabc0f69aa743a6aee6cf40
3
+ metadata.gz: f702f993fc5df33d479953322735001bfb90e05854e8818f968739a957c61671
4
+ data.tar.gz: c6b6a5df4d3c589cc83d62d1356d1a8a13389911a8e18d90c4b1baae8cab27cd
5
5
  SHA512:
6
- metadata.gz: 604ef82de1451193428702a7d6aa12a1eabbb0f9dcaecc0090960dd96236510a78f23db60a23d5a5c31a077be9342eeda2781394a03bf05e07eea47f89ea788b
7
- data.tar.gz: de661b6146515a32168c3fc0ea8f9d41b91e7ac1ee3f6cf4d4e5743c4d0426381b16d23fd2d986ccf769d86c47003500cd2c5777b56874ebc7b48c25b7a1cb7f
6
+ metadata.gz: ff157c02f679fff7590cf7b9786f91ca9e2db5698d13e8cd472a3bed51178bc61c8355753206770d7098303fd48b204600d69e1f230321cfe32e26c4c3b759b5
7
+ data.tar.gz: 953ddd4dfdcc310831dd1bbbbd92b0603df85b3301f9b376a1fd2e3c56bbfa00ead841a647368e1cc34a3d0e13985967cd51c23064323d629624d57dcaffbbf2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,37 @@
1
+ ## <small>1.2.17 (2021-07-12)</small>
2
+
3
+ * fix: Proxy CSS Modules requests to Vite.js with the correct extension (close #98) ([8976872](https://github.com/ElMassimo/vite_ruby/commit/8976872)), closes [#98](https://github.com/ElMassimo/vite_ruby/issues/98)
4
+
5
+
6
+
7
+ ## <small>1.2.16 (2021-07-07)</small>
8
+
9
+ * feat: Enable usage in engines by using `run` from the current instance ([023a61d](https://github.com/ElMassimo/vite_ruby/commit/023a61d))
10
+
11
+
12
+
13
+ ## [1.2.15](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.14...vite_ruby@1.2.15) (2021-07-01)
14
+
15
+
16
+
17
+ ## [1.2.14](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.13...vite_ruby@1.2.14) (2021-07-01)
18
+
19
+
20
+ ### Features
21
+
22
+ * Add support for Jekyll installer ([7b942ec](https://github.com/ElMassimo/vite_ruby/commit/7b942ec745eb28092d684056b02df675ad6ececa))
23
+
24
+
25
+
26
+ ## [1.2.13](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.12...vite_ruby@1.2.13) (2021-06-30)
27
+
28
+
29
+ ### Features
30
+
31
+ * Improve the error message when npm packages are missing ([9159557](https://github.com/ElMassimo/vite_ruby/commit/9159557e5152547554cfe519fae8dbefe26686fb))
32
+
33
+
34
+
1
35
  ## [1.2.12](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.11...vite_ruby@1.2.12) (2021-06-08)
2
36
 
3
37
 
data/lib/vite_ruby.rb CHANGED
@@ -18,28 +18,28 @@ class ViteRuby
18
18
  ENV_PREFIX = 'VITE_RUBY'
19
19
 
20
20
  # Internal: Versions used by default when running `vite install`.
21
- DEFAULT_VITE_VERSION = '^2.2.3'
22
- DEFAULT_PLUGIN_VERSION = '^2.0.2'
23
-
24
- # Internal: Ruby Frameworks that have a companion library for Vite Ruby.
25
- SUPPORTED_FRAMEWORKS = %w[rails hanami roda padrino sinatra].freeze
21
+ DEFAULT_VITE_VERSION = '^2.3.8'
22
+ DEFAULT_PLUGIN_VERSION = '^2.0.4'
23
+
24
+ # Internal: Companion libraries for Vite Ruby, and their target framework.
25
+ COMPANION_LIBRARIES = {
26
+ 'vite_rails' => 'rails',
27
+ 'vite_hanami' => 'hanami',
28
+ 'vite_roda' => 'roda',
29
+ 'vite_padrino' => 'padrino',
30
+ 'vite_sinatra' => 'sinatra',
31
+ 'jekyll-vite' => 'jekyll',
32
+ 'vite_rails_legacy' => 'rails',
33
+ }
26
34
 
27
35
  class << self
28
36
  extend Forwardable
29
37
 
30
- def_delegators :instance, :config, :commands, :run_proxy?
38
+ def_delegators :instance, :config, :commands, :env, :run, :run_proxy?
31
39
  def_delegators :config, :mode
32
40
 
33
41
  def instance
34
- @instance ||= ViteRuby.new
35
- end
36
-
37
- # Public: Additional environment variables to pass to Vite.
38
- #
39
- # Example:
40
- # ViteRuby.env['VITE_RUBY_CONFIG_PATH'] = 'config/alternate_vite.json'
41
- def env
42
- @env ||= load_env_variables
42
+ @instance ||= new
43
43
  end
44
44
 
45
45
  # Internal: Refreshes the manifest.
@@ -52,28 +52,16 @@ class ViteRuby
52
52
  load File.expand_path('tasks/vite.rake', __dir__)
53
53
  end
54
54
 
55
- # Internal: Executes the vite binary.
56
- def run(argv, **options)
57
- ViteRuby::Runner.new(instance).run(argv, **options)
58
- end
59
-
60
- # Internal: Refreshes the config after setting the env vars.
61
- def reload_with(env_vars)
62
- env.update(env_vars)
63
- @instance = nil
64
- config
65
- end
66
-
67
- # Internal: Allows to obtain any env variables for configuration options.
68
- def load_env_variables
69
- ENV.select { |key, _| key.start_with?(ENV_PREFIX) }
55
+ # Internal: Creates a new instance with the specified options.
56
+ def reload_with(**config_options)
57
+ @instance = new(**config_options)
70
58
  end
71
59
 
72
60
  # Internal: Detects if the application has installed a framework-specific
73
61
  # variant of Vite Ruby.
74
62
  def framework_libraries
75
- SUPPORTED_FRAMEWORKS.map { |framework|
76
- if library = (Gem.loaded_specs["vite_#{ framework }"] || Gem.loaded_specs["vite_#{ framework }_legacy"])
63
+ COMPANION_LIBRARIES.map { |name, framework|
64
+ if library = Gem.loaded_specs[name]
77
65
  [framework, library]
78
66
  end
79
67
  }.compact
@@ -82,6 +70,10 @@ class ViteRuby
82
70
 
83
71
  attr_writer :logger
84
72
 
73
+ def initialize(**config_options)
74
+ @config_options = config_options
75
+ end
76
+
85
77
  def logger
86
78
  @logger ||= Logger.new($stdout)
87
79
  end
@@ -99,6 +91,14 @@ class ViteRuby
99
91
  @running_at = false
100
92
  end
101
93
 
94
+ # Public: Additional environment variables to pass to Vite.
95
+ #
96
+ # Example:
97
+ # ViteRuby.env['VITE_RUBY_CONFIG_PATH'] = 'config/alternate_vite.json'
98
+ def env
99
+ @env ||= ENV.select { |key, _| key.start_with?(ENV_PREFIX) }
100
+ end
101
+
102
102
  # Public: The proxy for assets should only run in development mode.
103
103
  def run_proxy?
104
104
  config.mode == 'development'
@@ -107,6 +107,11 @@ class ViteRuby
107
107
  false
108
108
  end
109
109
 
110
+ # Internal: Executes the vite binary.
111
+ def run(argv, **options)
112
+ (@runner ||= ViteRuby::Runner.new(self)).run(argv, **options)
113
+ end
114
+
110
115
  # Public: Keeps track of watched files and triggers builds as needed.
111
116
  def builder
112
117
  @builder ||= ViteRuby::Builder.new(self)
@@ -119,7 +124,7 @@ class ViteRuby
119
124
 
120
125
  # Public: Current instance configuration for Vite.
121
126
  def config
122
- @config ||= ViteRuby::Config.resolve_config
127
+ @config ||= ViteRuby::Config.resolve_config(**@config_options)
123
128
  end
124
129
 
125
130
  # Public: Enables looking up assets managed by Vite using name and type.
@@ -33,7 +33,7 @@ private
33
33
 
34
34
  extend Forwardable
35
35
 
36
- def_delegators :@vite_ruby, :config, :logger
36
+ def_delegators :@vite_ruby, :config, :logger, :run
37
37
 
38
38
  # Internal: Reads metadata recorded on the last build, if it exists.
39
39
  def last_build_attrs
@@ -69,7 +69,7 @@ private
69
69
  def build_with_vite(*args)
70
70
  logger.info 'Building with Vite ⚡️'
71
71
 
72
- stdout, stderr, status = ViteRuby.run(['build', *args])
72
+ stdout, stderr, status = run(['build', *args])
73
73
  log_build_result(stdout, stderr.to_s, status)
74
74
 
75
75
  status.success?
@@ -28,6 +28,14 @@ class ViteRuby::CLI::Install < Dry::CLI::Command
28
28
 
29
29
  protected
30
30
 
31
+ # Internal: The JS packages that should be added to the app.
32
+ def js_dependencies
33
+ [
34
+ "vite@#{ ViteRuby::DEFAULT_VITE_VERSION }",
35
+ "vite-plugin-ruby@#{ ViteRuby::DEFAULT_PLUGIN_VERSION }",
36
+ ]
37
+ end
38
+
31
39
  # Internal: Setup for a plain Rack application.
32
40
  def setup_app_files
33
41
  copy_template 'config/vite.json', to: config.config_path
@@ -64,7 +72,7 @@ private
64
72
  def create_configuration_files
65
73
  copy_template 'config/vite.config.ts', to: root.join('vite.config.ts')
66
74
  setup_app_files
67
- ViteRuby.reload_with('VITE_RUBY_CONFIG_PATH' => config.config_path)
75
+ ViteRuby.reload_with(config_path: config.config_path)
68
76
  end
69
77
 
70
78
  # Internal: Installs vite and vite-plugin-ruby at the project level.
@@ -73,7 +81,7 @@ private
73
81
  write(package_json, '{}') unless package_json.exist?
74
82
 
75
83
  Dir.chdir(root) do
76
- deps = "vite@#{ ViteRuby::DEFAULT_VITE_VERSION } vite-plugin-ruby@#{ ViteRuby::DEFAULT_PLUGIN_VERSION }"
84
+ deps = js_dependencies.join(' ')
77
85
  _, stderr, status = ViteRuby::IO.capture("npx --package @antfu/ni -- ni -D #{ deps }", stdin_data: "\n")
78
86
  _, stderr, = ViteRuby::IO.capture("yarn add -D #{ deps }") unless status.success?
79
87
  say("Could not install JS dependencies.\n", stderr) unless stderr.to_s.empty?
@@ -117,5 +125,5 @@ end
117
125
 
118
126
  # NOTE: This allows framework-specific variants to extend the installation.
119
127
  ViteRuby.framework_libraries.each do |_framework, library|
120
- require "#{ library.name }/installation"
128
+ require "#{ library.name.tr('-', '/') }/installation"
121
129
  end
@@ -33,7 +33,7 @@ private
33
33
  uri = env.fetch('REQUEST_URI') { [env['PATH_INFO'], env['QUERY_STRING']].reject { |str| str.to_s.strip.empty? }.join('?') }
34
34
  .sub(HOST_WITH_PORT_REGEX, '/') # Hanami adds the host and port.
35
35
  .sub('.ts.js', '.ts') # Hanami's javascript helper always adds the extension.
36
- .sub(/(\.(?!min)\w+)\.css$/, '\1') # Rails' stylesheet_link_tag always adds the extension.
36
+ .sub(/(\.(?!min|module)\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
 
@@ -4,7 +4,7 @@
4
4
  class ViteRuby::MissingExecutableError < ViteRuby::Error
5
5
  def initialize(error = nil)
6
6
  super <<~MSG
7
- ❌ The vite binary is not available. Have you installed Vite?
7
+ ❌ The vite binary is not available. Have you installed the npm packages?
8
8
 
9
9
  :troubleshooting:
10
10
  #{ error }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '1.2.12'
4
+ VERSION = '1.2.17'
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.2.12
4
+ version: 1.2.17
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-06-08 00:00:00.000000000 Z
11
+ date: 2021-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -198,8 +198,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
198
198
  licenses:
199
199
  - MIT
200
200
  metadata:
201
- source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.2.12/vite_ruby
202
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.2.12/vite_ruby/CHANGELOG.md
201
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.2.17/vite_ruby
202
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.2.17/vite_ruby/CHANGELOG.md
203
203
  post_install_message:
204
204
  rdoc_options: []
205
205
  require_paths: