Module: Bundlebun::Integrations::ExecJS
- Defined in:
- lib/bundlebun/integrations/execjs.rb
Overview
An integration for [execjs](github.com/rails/execjs).
Runtimes in ExecJS are declared like this: github.com/rails/execjs/blob/master/lib/execjs/runtimes.rb We will redefine the Bun one, changing its command.
Then, we will automatically set the bundlebun-ed Bun as the default runtime.
Class Method Summary collapse
-
.bun! ⇒ Object
Patches the existing module to use bundlebun-ed Bun in place of an already existing, spported Bun runtime: we replace it with a bundled version.
Class Method Details
.bun! ⇒ Object
Patches the existing module to use bundlebun-ed Bun in place of an already existing, spported Bun runtime: we replace it with a bundled version.
Additionally, sets it as a default ExecJS runtime.
Call this after everything is loaded and required. For a Rails application, a good place is an initializer.
See the documentation for more info on installation Rake tasks.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bundlebun/integrations/execjs.rb', line 26 def self.bun! return unless defined?(::ExecJS::Runtimes) # Remove the existing Bun constant if it exists ::ExecJS::Runtimes.send(:remove_const, :Bun) if ::ExecJS::Runtimes.const_defined?(:Bun) # Define new Bun runtime with our custom command bun_runtime = ::ExecJS::Runtimes.const_set(:Bun, ::ExecJS::ExternalRuntime.new( name: "Bun.sh", command: [Bundlebun::Runner.binstub_or_binary_path], runner_path: ::ExecJS.root + "/support/bun_runner.js", encoding: "UTF-8" )) # Set the runtime ::ExecJS.runtime = bun_runtime end |