Class: Bundlebun::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/bundlebun/runner.rb

Overview

Runner is the class that bundlebun uses to run the bundled Bun executable.

See Bundlebun.

Constant Summary collapse

BINSTUB_PATH =

:nodoc:

'bin/bun'
RELATIVE_DIRECTORY =

:nodoc:

'lib/bundlebun/vendor/bun'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = '') ⇒ Runner

Intialize the runner with arguments to run the Bun runtime later via call.

Arguments can be a String or an Array of strings.

Example:

Bundlebun::Runner.new('--version')
Bundlebun::Runner.new(['install', 'postcss'])

Returns error status 127 if the executable does not exist.



76
77
78
# File 'lib/bundlebun/runner.rb', line 76

def initialize(arguments = '')
  @arguments = arguments
end

Class Method Details

.binary_pathObject

A full path to the bundled Bun binary we run.



42
43
44
45
# File 'lib/bundlebun/runner.rb', line 42

def binary_path
  executable = "bun#{RUBY_PLATFORM.match?(/mingw|mswin/) ? ".exe" : ""}"
  File.join(full_directory, executable)
end

.binary_path_exist?Boolean

Does the bundled Bun binary exist?

Returns:

  • (Boolean)


48
49
50
# File 'lib/bundlebun/runner.rb', line 48

def binary_path_exist?
  File.exist?(binary_path)
end

.binstub_exist?Boolean

Does the binstub exist?

Returns:

  • (Boolean)


61
62
63
# File 'lib/bundlebun/runner.rb', line 61

def binstub_exist?
  File.exist?(binstub_path)
end

.binstub_or_binary_pathObject

Returns the preferred way to run Bun when bundlebun is installed.

If the binstub is installed (see binstub_path), use the binstub. If not, use the full binary path for the bundled executable (binary_path).



56
57
58
# File 'lib/bundlebun/runner.rb', line 56

def binstub_or_binary_path
  binstub_exist? ? binstub_path : binary_path
end

.binstub_pathObject

A relative path to binstub bundlebun usually generates with installation Rake tasks.



27
28
29
# File 'lib/bundlebun/runner.rb', line 27

def binstub_path
  BINSTUB_PATH
end

.callObject

Runs the Bun runtime with parameters (can be String or Array of strings).

See Bundlebun::Runner.new, Bundlebun::Runner.call.

Example:

Bundlebun.call('--version')
Bundlebun.call(['add', 'postcss'])

Returns error status 127 if the executable does not exist.



22
23
24
# File 'lib/bundlebun/runner.rb', line 22

def call(...)
  new(...).call
end

.full_directoryObject

A full directory path to the bundled Bun executable from the root of the gem.



37
38
39
# File 'lib/bundlebun/runner.rb', line 37

def full_directory
  File.expand_path("../../#{relative_directory}", __dir__)
end

.relative_directoryObject

A relative directory path to the bundled Bun executable from the root of the gem.



32
33
34
# File 'lib/bundlebun/runner.rb', line 32

def relative_directory
  RELATIVE_DIRECTORY
end

Instance Method Details

#callObject

Runs the Bun executable with previously specified arguments.

Returns error status 127 if the executable does not exist.

Example:

r = Bundlebun::Runner.new('--version')
r.call!

Check other methods of Bundlebun::Runner to see how we determine what to run exactly.



90
91
92
93
# File 'lib/bundlebun/runner.rb', line 90

def call
  check_executable!
  exec(command)
end