Class: Lilac::CLI::RuntimeResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/lilac/cli/build/runtime_resolver.rb

Overview

Shared discovery logic for the two build-target runtimes (:full / :compiled). Both vendor a wasm bundle plus the SAME mruby-wasm-js JS bridge into dist/vendor/lilac-<target>/, and both discover sources in the same order: explicit CLI/config → env → lilac-wasm-bin gem (the canonical install path — decisions §25) → monorepo sibling layout for in-repo development.

The bridge is identical across targets, so its resolution lives here. Subclasses supply only the wasm-specific bits via the protected hooks at the bottom (env key, gem accessor, monorepo candidate, not-found message).

Direct Known Subclasses

CompiledRuntimeResolver, FullRuntimeResolver

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(lilac_wasm_path: nil, mruby_wasm_js_path: nil, monorepo_root: nil, disable_gem_discovery: false) ⇒ RuntimeResolver

Returns a new instance of RuntimeResolver.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lilac/cli/build/runtime_resolver.rb', line 25

def initialize(lilac_wasm_path: nil, mruby_wasm_js_path: nil,
               monorepo_root: nil, disable_gem_discovery: false)
  @configured_wasm_path   = lilac_wasm_path
  @configured_bridge_path = mruby_wasm_js_path
  # Tests inject a dummy directory to keep the (real) monorepo wasm
  # from being discovered; production callers leave it nil and the
  # gem-relative ancestor is used.
  @monorepo_root_override = monorepo_root
  # Tests that exercise the fallback chain pass `true` so the gem's
  # wasm doesn't satisfy a "nothing should resolve" expectation.
  @disable_gem_discovery  = disable_gem_discovery
end

Instance Method Details

#bridge_pathObject

Directory containing the bridge's index.js, or nil if not found. Shared across targets — the bridge artifact is the same for both.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lilac/cli/build/runtime_resolver.rb', line 57

def bridge_path
  if @configured_bridge_path
    return @configured_bridge_path if bridge_dir?(@configured_bridge_path)
  end
  if (env = ENV["MRUBY_WASM_JS_PATH"]) && bridge_dir?(env)
    return env
  end
  [
    gem_provided_bridge,        # `lilac-wasm-bin` gem (canonical install path)
    monorepo_bridge_candidate,
  ].compact.find { |c| bridge_dir?(c) }
end

#resolve_bridge!Object



76
77
78
# File 'lib/lilac/cli/build/runtime_resolver.rb', line 76

def resolve_bridge!
  bridge_path || raise(self.class::Error, bridge_not_found_message)
end

#resolve_wasm!Object

Raising variants for the build path: a missing runtime must fail the build loudly with an actionable message.



72
73
74
# File 'lib/lilac/cli/build/runtime_resolver.rb', line 72

def resolve_wasm!
  wasm_path || raise(self.class::Error, wasm_not_found_message)
end

#wasm_pathObject

Absolute path to the wasm, or nil if none of the discovery routes turn up a readable file. Non-raising: use this to report discoverability (Doctor); use resolve_wasm! on the build path where absence must be a hard error.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lilac/cli/build/runtime_resolver.rb', line 42

def wasm_path
  return @configured_wasm_path if File.file?(@configured_wasm_path.to_s)
  if (env = ENV[wasm_env_key]) && File.file?(env)
    return env
  end
  if (gem_wasm = gem_provided_wasm) && File.file?(gem_wasm)
    return gem_wasm
  end
  monorepo_wasm_candidate.then { |c| return c if File.file?(c) }

  nil
end