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 Also:

Constant Summary collapse

BINSTUB_PATH =
'bin/bun'
RELATIVE_DIRECTORY =
'lib/bundlebun/vendor/bun'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = '') ⇒ Runner

Intialize the Bundlebun::Runner with arguments to run the Bun runtime later via #call.

Examples:

String as an argument

Bundlebun::Runner.new('--version') # => `bun --version`

Array of strings as an argument

Bundlebun::Runner.new(['add', 'postcss']) # => `bun add postcss`

Parameters:

  • arguments (String, Array<String>) (defaults to: '')

    Command arguments to pass to Bun

See Also:



97
98
99
# File 'lib/bundlebun/runner.rb', line 97

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

Class Method Details

.binary_pathString

A full path to the bundled Bun binary we run (includes ‘.exe` on Windows).

Returns:

  • (String)


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

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)


64
65
66
# File 'lib/bundlebun/runner.rb', line 64

def binary_path_exist?
  File.exist?(binary_path)
end

.binstub_exist?Boolean

Does the binstub exist?

Returns:

  • (Boolean)


81
82
83
# File 'lib/bundlebun/runner.rb', line 81

def binstub_exist?
  File.exist?(binstub_path)
end

.binstub_or_binary_pathString

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).

Returns:

  • (String)


74
75
76
# File 'lib/bundlebun/runner.rb', line 74

def binstub_or_binary_path
  binstub_exist? ? binstub_path : binary_path
end

.binstub_pathString

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

Returns:

  • (String)


34
35
36
# File 'lib/bundlebun/runner.rb', line 34

def binstub_path
  BINSTUB_PATH
end

.callInteger

Runs the Bun runtime with parameters.

A wrapper for new, call.

Examples:

String as an argument

Bundlebun.call('--version') # => `bun --version`

Array of strings as an argument

Bundlebun.call(['add', 'postcss']) # => `bun add postcss`

Parameters:

  • arguments (String, Array<String>)

    Command arguments to pass to Bun

Returns:

  • (Integer)

    Exit status code (‘127` if executable not found)

See Also:



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

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

.full_directoryString

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

Returns:

  • (String)


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

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

.relative_directoryString

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

Returns:

  • (String)


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

def relative_directory
  RELATIVE_DIRECTORY
end

Instance Method Details

#callInteger

Runs the Bun executable with previously specified arguments.

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

Examples:

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

Returns:

  • (Integer)

    Exit status code (‘127` if executable not found)

See Also:



112
113
114
115
# File 'lib/bundlebun/runner.rb', line 112

def call
  check_executable!
  exec(command)
end