vite_ruby 1.2.6 → 1.2.11

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: 25d6f543baa813ce51efadb33c24e701832a892ff73d3091b72978a7937b020c
4
- data.tar.gz: cc3135c8be27c94e4f52ea679ba6ef41d2063af64cf6eb7a1bb4e662260e6171
3
+ metadata.gz: d4580c673ebdae305421db8a2ccc22fd8683302d22c24db85f63d4c2f6638400
4
+ data.tar.gz: 52ea04d44b7f05c734a6011d4e66408135922e6fd0410cbc5d15a1b68c82140a
5
5
  SHA512:
6
- metadata.gz: ea9e613b7b58f625b2c0f014f51b07652da52405308a4d07f5ad481d9d94e39c19ef20ef8feac6d8457277fc09fdb920bac6de2d1b3e99b934ca9715a1e06fd7
7
- data.tar.gz: 2c5d0955a5651ea278bbe6fca0dd6905770709959776ad867c679e0c65e7304d8c7b9d7becf739226825223b8ed0e319461c5e1768d7acef4a2249ef2c34204d
6
+ metadata.gz: 389377989a3dd2db2188c05814a26526ee3fab5647863d7ab42df5dceef737c9f63c9ed71bee59339662338f16c7594bdeaea8ebd4cfd043de2d3a9297194b3e
7
+ data.tar.gz: 75345348dfef36343eb44150d1162725f58171cd9e6a24d6eb6f3bfd29ce4861d74910ffb140ed2f0fef106df839097a17e569610321cd939fce1be2a05da2ba
data/CHANGELOG.md CHANGED
@@ -1,3 +1,43 @@
1
+ ## [1.2.11](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.10...vite_ruby@1.2.11) (2021-05-10)
2
+
3
+
4
+
5
+ ## [1.2.10](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.9...vite_ruby@1.2.10) (2021-05-09)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * Lock dry-cli to 0.6 since 0.7 has breaking changes (close [#76](https://github.com/ElMassimo/vite_ruby/issues/76)) ([9883458](https://github.com/ElMassimo/vite_ruby/commit/9883458443cb0047cd4cceaf02de2a86066d624e))
11
+
12
+
13
+
14
+ ## [1.2.9](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.8...vite_ruby@1.2.9) (2021-05-04)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * Stream output during installation and don't skip installation of npm packages when no lockfile is detected ([#73](https://github.com/ElMassimo/vite_ruby/issues/73)) ([028a5ba](https://github.com/ElMassimo/vite_ruby/commit/028a5bae359085a36aa942d2ad63c23616a00ffb))
20
+
21
+
22
+
23
+ ## [1.2.8](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.7...vite_ruby@1.2.8) (2021-04-29)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * Don't modify url for minified css when proxying a request ([#71](https://github.com/ElMassimo/vite_ruby/issues/71)) ([d30a577](https://github.com/ElMassimo/vite_ruby/commit/d30a577a8436c4987d7c2e08e7eae68e589eb2a7))
29
+
30
+
31
+
32
+ ## [1.2.7](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.6...vite_ruby@1.2.7) (2021-04-28)
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * Support Rails 5.1 by avoiding [incorrectly monkeypatched](https://github.com//github.com/rails/rails/blob/5-1-stable/activesupport/lib/active_support/core_ext/array/prepend_and_append.rb/issues/L2-L3) `Array#append` ([1b59551](https://github.com/ElMassimo/vite_ruby/commit/1b5955170b33a528a2b13d7e7e308e8493d97a91))
38
+
39
+
40
+
1
41
  ## [1.2.6](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.5...vite_ruby@1.2.6) (2021-04-26)
2
42
 
3
43
 
data/lib/vite_ruby.rb CHANGED
@@ -10,6 +10,7 @@ loader.ignore("#{ __dir__ }/install")
10
10
  loader.ignore("#{ __dir__ }/tasks")
11
11
  loader.ignore("#{ __dir__ }/exe")
12
12
  loader.inflector.inflect('cli' => 'CLI')
13
+ loader.inflector.inflect('io' => 'IO')
13
14
  loader.setup
14
15
 
15
16
  class ViteRuby
@@ -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], capture: true)
72
+ stdout, stderr, status = ViteRuby.run(['build', *args])
73
73
  log_build_result(stdout, stderr.to_s, status)
74
74
 
75
75
  status.success?
@@ -1,25 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class ViteRuby::CLI::Build < Dry::CLI::Command
4
- CURRENT_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV']
3
+ class ViteRuby::CLI::Build < ViteRuby::CLI::Vite
5
4
  DEFAULT_ENV = CURRENT_ENV || 'production'
6
5
 
7
- def self.shared_options
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])
10
- option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
11
- option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
12
- option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
13
- end
14
-
15
6
  desc 'Bundle all entrypoints using Vite.'
16
7
  shared_options
17
8
  option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)
18
9
 
19
- def call(mode:, args: [], clobber: false, **boolean_opts)
20
- ViteRuby.env['VITE_RUBY_MODE'] = mode
21
- ViteRuby.commands.clobber if clobber
22
- boolean_opts.map { |name, value| args << "--#{ name }" if value }
23
- block_given? ? yield(args) : ViteRuby.commands.build_from_task(*args)
10
+ def call(**options)
11
+ super { |args| ViteRuby.commands.build_from_task(*args) }
24
12
  end
25
13
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class ViteRuby::CLI::Dev < ViteRuby::CLI::Build
3
+ class ViteRuby::CLI::Dev < ViteRuby::CLI::Vite
4
4
  DEFAULT_ENV = CURRENT_ENV || 'development'
5
5
 
6
6
  desc 'Start the Vite development server.'
@@ -8,6 +8,6 @@ class ViteRuby::CLI::Dev < ViteRuby::CLI::Build
8
8
  option(:force, desc: 'Force Vite to re-bundle dependencies', type: :boolean)
9
9
 
10
10
  def call(**options)
11
- super { |args| ViteRuby.run(args) }
11
+ super { |args| ViteRuby.run(args, exec: true) }
12
12
  end
13
13
  end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'fileutils'
5
+
6
+ # NOTE: Extracted from dry-cli version 0.6.0, which later removed this file as
7
+ # it was refactored and extracted into the more complete (and complex) dry-files.
8
+ module ViteRuby::CLI::FileUtils
9
+ class << self
10
+ # Creates a new file or rewrites the contents of an existing file.
11
+ #
12
+ # @since 1.2.11
13
+ # @api private
14
+ def write(path, *content)
15
+ mkdir_p(path)
16
+ File.open(path, File::CREAT | File::WRONLY | File::TRUNC) do |file|
17
+ file.write(Array(content).flatten.join)
18
+ end
19
+ end
20
+
21
+ # Copies source into destination.
22
+ #
23
+ # @since 1.2.11
24
+ # @api private
25
+ def cp(source, destination)
26
+ mkdir_p(destination)
27
+ FileUtils.cp(source, destination)
28
+ end
29
+
30
+ # Adds a new line at the bottom of the file.
31
+ #
32
+ # @since 1.2.11
33
+ # @api private
34
+ def append(path, contents)
35
+ mkdir_p(path)
36
+
37
+ content = File.readlines(path)
38
+ content << "\n" unless content.last.end_with?("\n")
39
+ content << "#{ contents }\n"
40
+
41
+ write(path, content)
42
+ end
43
+
44
+ # Replace first line in `path` that contains `target` with `replacement`.
45
+ #
46
+ # @since 1.2.11
47
+ # @api private
48
+ def replace_first_line(path, target, replacement)
49
+ content = File.readlines(path)
50
+ content[index(content, path, target)] = "#{ replacement }\n"
51
+
52
+ write(path, content)
53
+ end
54
+
55
+ # Inject `contents` in `path` before `target`.
56
+ #
57
+ # @since 1.2.11
58
+ # @api private
59
+ def inject_line_before(path, target, contents)
60
+ _inject_line_before(path, target, contents, method(:index))
61
+ end
62
+
63
+ # Inject `contents` in `path` after `target`.
64
+ #
65
+ # @since 1.2.11
66
+ # @api private
67
+ def inject_line_after(path, target, contents)
68
+ _inject_line_after(path, target, contents, method(:index))
69
+ end
70
+
71
+ # Inject `contents` in `path` after last `target`.
72
+ #
73
+ # @since 1.2.11
74
+ # @api private
75
+ def inject_line_after_last(path, target, contents)
76
+ _inject_line_after(path, target, contents, method(:rindex))
77
+ end
78
+
79
+ private
80
+
81
+ # Creates all parent directories for the given file path.
82
+ #
83
+ # @since 1.2.11
84
+ # @api private
85
+ def mkdir_p(path)
86
+ Pathname.new(path).dirname.mkpath
87
+ end
88
+
89
+ # @since 1.2.11
90
+ # @api private
91
+ def index(content, path, target)
92
+ content.index { |line| line.include?(target) } ||
93
+ raise(ArgumentError, "Cannot find `#{ target }' inside `#{ path }'.")
94
+ end
95
+
96
+ # @since 1.2.11
97
+ # @api private
98
+ def rindex(content, path, target)
99
+ content.rindex { |line| line.include?(target) } ||
100
+ raise(ArgumentError, "Cannot find `#{ target }' inside `#{ path }'.")
101
+ end
102
+
103
+ # @since 1.2.11
104
+ # @api private
105
+ def _inject_line_before(path, target, contents, finder)
106
+ content = File.readlines(path)
107
+ i = finder.call(content, path, target)
108
+
109
+ content.insert(i, "#{ contents }\n")
110
+ write(path, content)
111
+ end
112
+
113
+ # @since 1.2.11
114
+ # @api private
115
+ def _inject_line_after(path, target, contents, finder)
116
+ content = File.readlines(path)
117
+ i = finder.call(content, path, target)
118
+
119
+ content.insert(i + 1, "#{ contents }\n")
120
+ write(path, content)
121
+ end
122
+ end
123
+ end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/cli/utils/files'
4
3
  require 'stringio'
5
- require 'open3'
6
4
 
7
5
  class ViteRuby::CLI::Install < Dry::CLI::Command
8
6
  desc 'Performs the initial configuration setup to get started with Vite Ruby.'
@@ -50,9 +48,9 @@ private
50
48
 
51
49
  def_delegators 'ViteRuby', :config
52
50
 
53
- %i[append cp inject_line_after inject_line_after_last inject_line_before write].each do |util|
51
+ %i[append cp inject_line_after inject_line_after_last inject_line_before replace_first_line write].each do |util|
54
52
  define_method(util) { |*args|
55
- Dry::CLI::Utils::Files.send(util, *args) rescue nil
53
+ ViteRuby::CLI::FileUtils.send(util, *args) rescue nil
56
54
  }
57
55
  end
58
56
 
@@ -73,11 +71,12 @@ private
73
71
  def install_js_dependencies
74
72
  package_json = root.join('package.json')
75
73
  write(package_json, '{}') unless package_json.exist?
74
+
76
75
  Dir.chdir(root) do
77
76
  deps = "vite@#{ ViteRuby::DEFAULT_VITE_VERSION } vite-plugin-ruby@#{ ViteRuby::DEFAULT_PLUGIN_VERSION }"
78
- stdout, stderr, status = Open3.capture3({}, "npx --yes --package @antfu/ni -- ni -D #{ deps }")
79
- stdout, stderr, = Open3.capture3({}, "yarn add -D #{ deps }") unless status.success?
80
- say(stdout, "\n", stderr)
77
+ _, stderr, status = ViteRuby::IO.capture("npx --package @antfu/ni -- ni -D #{ deps }", stdin_data: "\n")
78
+ _, stderr, = ViteRuby::IO.capture("yarn add -D #{ deps }") unless status.success?
79
+ say("Could not install JS dependencies.\n", stderr) unless stderr.to_s.empty?
81
80
  end
82
81
  end
83
82
 
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ViteRuby::CLI::Vite < Dry::CLI::Command
4
+ CURRENT_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV']
5
+
6
+ def self.shared_options
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
+ option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
11
+ option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
12
+ end
13
+
14
+ def call(mode:, args: [], clobber: false, **boolean_opts)
15
+ ViteRuby.env['VITE_RUBY_MODE'] = mode
16
+ ViteRuby.commands.clobber if clobber
17
+ boolean_opts.map { |name, value| args << "--#{ name }" if value }
18
+ yield(args)
19
+ end
20
+ 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(/(\.\w+)\.css$/, '\1') # Rails' stylesheet_link_tag always adds the extension.
36
+ .sub(/(\.(?!min)\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,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ # Public: Builds on top of Ruby I/O open3 providing a friendlier experience.
6
+ module ViteRuby::IO
7
+ class << self
8
+ # Internal: A modified version of capture3 that can continuosly print stdout.
9
+ # NOTE: Streaming output provides a better UX when running bin/vite build.
10
+ def capture(*cmd, with_output: $stdout.method(:puts), stdin_data: '', **opts)
11
+ return Open3.capture3(*cmd, **opts) unless with_output
12
+
13
+ Open3.popen3(*cmd, **opts) { |stdin, stdout, stderr, wait_threads|
14
+ stdin << stdin_data
15
+ stdin.close
16
+ out = Thread.new { read_lines(stdout, &with_output) }
17
+ err = Thread.new { stderr.read }
18
+ [out.value, err.value, wait_threads.value]
19
+ }
20
+ end
21
+
22
+ # Internal: Reads and yield every line in the stream. Returns the full content.
23
+ def read_lines(io)
24
+ buffer = +''
25
+ while line = io.gets
26
+ buffer << line
27
+ yield line
28
+ end
29
+ buffer
30
+ end
31
+ end
32
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'open3'
4
-
5
3
  # Public: Executes Vite commands, providing conveniences for debugging.
6
4
  class ViteRuby::Runner
7
5
  def initialize(vite_ruby)
@@ -9,10 +7,13 @@ class ViteRuby::Runner
9
7
  end
10
8
 
11
9
  # Public: Executes Vite with the specified arguments.
12
- def run(argv, capture: false)
10
+ def run(argv, exec: false)
13
11
  Dir.chdir(config.root) {
14
12
  cmd = command_for(argv)
15
- capture ? capture3_with_output(*cmd, chdir: config.root) : Kernel.exec(*cmd)
13
+ return Kernel.exec(*cmd) if exec
14
+
15
+ log_or_noop = ->(line) { logger.info('vite') { line } } unless config.hide_build_console_output
16
+ ViteRuby::IO.capture(*cmd, chdir: config.root, with_output: log_or_noop)
16
17
  }
17
18
  rescue Errno::ENOENT => error
18
19
  raise ViteRuby::MissingExecutableError, error
@@ -28,11 +29,11 @@ private
28
29
  def command_for(args)
29
30
  [config.to_env].tap do |cmd|
30
31
  args = args.clone
31
- cmd.append('node', '--inspect-brk') if args.delete('--inspect')
32
- cmd.append('node', '--trace-deprecation') if args.delete('--trace_deprecation')
33
- cmd.append(vite_executable)
34
- cmd.append(*args)
35
- cmd.append('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
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)
36
+ cmd.push('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
36
37
  end
37
38
  end
38
39
 
@@ -41,26 +42,4 @@ private
41
42
  bin_path = config.vite_bin_path
42
43
  File.exist?(bin_path) ? bin_path : "#{ `npm bin`.chomp }/vite"
43
44
  end
44
-
45
- # Internal: A modified version of capture3 that continuosly prints stdout.
46
- # NOTE: This improves the experience of running bin/vite build.
47
- def capture3_with_output(*cmd, **opts)
48
- return Open3.capture3(*cmd, opts) if config.hide_build_console_output
49
-
50
- Open3.popen3(*cmd, opts) { |_stdin, stdout, stderr, wait_threads|
51
- out = Thread.new { read_lines(stdout) { |l| logger.info('vite') { l } } }
52
- err = Thread.new { stderr.read }
53
- [out.value, err.value, wait_threads.value]
54
- }
55
- end
56
-
57
- # Internal: Reads and yield every line in the stream. Returns the full content.
58
- def read_lines(io)
59
- buffer = +''
60
- while line = io.gets
61
- buffer << line
62
- yield line
63
- end
64
- buffer
65
- end
66
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '1.2.6'
4
+ VERSION = '1.2.11'
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.6
4
+ version: 1.2.11
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-04-26 00:00:00.000000000 Z
11
+ date: 2021-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.6'
19
+ version: 0.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.6'
26
+ version: 0.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack-proxy
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -219,12 +219,15 @@ files:
219
219
  - lib/vite_ruby/cli/build.rb
220
220
  - lib/vite_ruby/cli/clobber.rb
221
221
  - lib/vite_ruby/cli/dev.rb
222
+ - lib/vite_ruby/cli/file_utils.rb
222
223
  - lib/vite_ruby/cli/install.rb
223
224
  - lib/vite_ruby/cli/version.rb
225
+ - lib/vite_ruby/cli/vite.rb
224
226
  - lib/vite_ruby/commands.rb
225
227
  - lib/vite_ruby/config.rb
226
228
  - lib/vite_ruby/dev_server_proxy.rb
227
229
  - lib/vite_ruby/error.rb
230
+ - lib/vite_ruby/io.rb
228
231
  - lib/vite_ruby/manifest.rb
229
232
  - lib/vite_ruby/missing_entrypoint_error.rb
230
233
  - lib/vite_ruby/missing_executable_error.rb
@@ -237,8 +240,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
237
240
  licenses:
238
241
  - MIT
239
242
  metadata:
240
- source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.2.6/vite_ruby
241
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.2.6/vite_ruby/CHANGELOG.md
243
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.2.11/vite_ruby
244
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.2.11/vite_ruby/CHANGELOG.md
242
245
  post_install_message:
243
246
  rdoc_options: []
244
247
  require_paths: