Class: Lilac::CLI::OfflineVerifier

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

Overview

Inspects a built dist directory and reports whether it is self-contained — i.e. it can run with no internet access:

1. The target's runtime assets are vendored locally
 (`vendor/lilac-{full,compiled}/...`).
2. No emitted HTML/JS loads a runtime asset from a remote origin
 (CDN import / `<script src>` / `<link href>` / `fetch()`).

Outbound content links in page copy (<a href="https://...">) are intentionally allowed — the guarantee is about runtime asset loading, not about whether the page links elsewhere.

Stateless; returns an Array of Result (level :ok / :warn / :error — the same shape as Doctor::Result) so both doctor and any future caller can consume it without duplication.

Defined Under Namespace

Classes: Result

Constant Summary collapse

REMOTE_URL =

A remote URL appearing in an asset-loading position. We only flag absolute (https://host, http://host) and protocol-relative (//host) URLs; root-relative (/vendor/...) and bare-relative (./x.js) paths are same-origin and fine. Captured inside the asset-context patterns below so prose links don't false-positive.

%r{(?:https?:)?//[^"'\s)]+}
ASSET_CONTEXTS =

Asset-loading contexts whose URL must be local. Each captures the URL into group 1.

[
  /\bimport\s+[^"']*["'](#{REMOTE_URL})["']/,             # import ... from "URL" / import "URL"
  /\bimport\s*\(\s*["'](#{REMOTE_URL})["']/,              # dynamic import("URL")
  /\bfrom\s+["'](#{REMOTE_URL})["']/,                     # from "URL"
  /\bfetch\s*\(\s*["'](#{REMOTE_URL})["']/,               # fetch("URL")
  /<script\b[^>]*\bsrc\s*=\s*["'](#{REMOTE_URL})["']/i,   # <script src="URL">
  /<link\b[^>]*\bhref\s*=\s*["'](#{REMOTE_URL})["']/i,    # <link href="URL"> (stylesheet/modulepreload)
  /\bnew\s+URL\s*\(\s*["'](#{REMOTE_URL})["']/,           # new URL("URL", ...)
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(output_dir) ⇒ OfflineVerifier

Returns a new instance of OfflineVerifier.



45
46
47
# File 'lib/lilac/cli/offline_verifier.rb', line 45

def initialize(output_dir)
  @output_dir = output_dir
end

Instance Method Details

#verifyObject

Returns Array. Empty of :error/:warn ⇒ self-contained.



50
51
52
53
54
55
56
57
58
59
# File 'lib/lilac/cli/offline_verifier.rb', line 50

def verify
  results = []
  results.concat(check_assets)
  results.concat(check_remote_refs)
  if results.empty?
    results << ok("dist is self-contained (offline-runnable): runtime assets " \
                  "vendored locally, no remote asset URLs")
  end
  results
end