Class: Railpack::BunBundler

Inherits:
Bundler
  • Object
show all
Defined in:
lib/railpack/bundlers/bun_bundler.rb

Instance Attribute Summary

Attributes inherited from Bundler

#config

Instance Method Summary collapse

Methods inherited from Bundler

#commands, #initialize, #name

Constructor Details

This class inherits a constructor from Railpack::Bundler

Instance Method Details

#add(*packages) ⇒ Object



30
31
32
# File 'lib/railpack/bundlers/bun_bundler.rb', line 30

def add(*packages)
  execute([commands[:add], *packages])
end

#base_command ⇒ Object



3
4
5
# File 'lib/railpack/bundlers/bun_bundler.rb', line 3

def base_command
  @base_command ||= detect_bun_path || "bun"
end

#build!(args = []) ⇒ Object



50
51
52
53
# File 'lib/railpack/bundlers/bun_bundler.rb', line 50

def build!(args = [])
  full_args = build_command_args(:build, args)
  execute([commands[:build], *full_args])
end

#default_commands ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/railpack/bundlers/bun_bundler.rb', line 7

def default_commands
  has_build_script = package_json_has_script?('build')
  has_watch_script = package_json_has_script?('watch')

  {
    build: has_build_script ? "run build" : "build",
    watch: has_watch_script ? "run watch" : "build --watch",
    install: "install",
    add: "add",
    remove: "remove",
    exec: "",
    version: "--version"
  }
end

#exec(*args) ⇒ Object



38
39
40
# File 'lib/railpack/bundlers/bun_bundler.rb', line 38

def exec(*args)
  execute([commands[:exec], *args])
end

#execute(command_array) ⇒ Object



22
23
24
# File 'lib/railpack/bundlers/bun_bundler.rb', line 22

def execute(command_array)
  system(base_command, *command_array)
end

#install!(args = []) ⇒ Object



26
27
28
# File 'lib/railpack/bundlers/bun_bundler.rb', line 26

def install!(args = [])
  execute([commands[:install], *args])
end

#installed? ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/railpack/bundlers/bun_bundler.rb', line 46

def installed?
  system("#{base_command} #{commands[:version]} > /dev/null 2>&1")
end

#remove(*packages) ⇒ Object



34
35
36
# File 'lib/railpack/bundlers/bun_bundler.rb', line 34

def remove(*packages)
  execute([commands[:remove], *packages])
end

#version ⇒ Object



42
43
44
# File 'lib/railpack/bundlers/bun_bundler.rb', line 42

def version
  `#{base_command} #{commands[:version]}`.strip
end

#watch(args = []) ⇒ Object



55
56
57
58
# File 'lib/railpack/bundlers/bun_bundler.rb', line 55

def watch(args = [])
  full_args = build_command_args(:watch, args)
  execute([commands[:watch], *full_args])
end