Files
pbakaus_impeccable/crates/wasm/Cargo.toml
T
Paul BakausandClaude Fable 5.1 1d0493af30 Rule packs: downstream crates add rules on all three engines; wasm detect surface
A crate that depends on this workspace can now add rules without forking
it. `impeccable_core::rule_pack::RulePack` (object-safe, Send + Sync +
Debug) carries a pack's registry rows plus three hooks that default to
empty: `check_text` for the text engine, `check_element_dom` and
`check_page_dom` for the browser driver. `impeccable_html::StaticRulePack`
adds `check_document` for the static engine, where the document model
belongs to the html crate and detect cannot name it.

The registry keeps ANTIPATTERNS as the built-in list; `registry::extend`
appends a pack's rows and every lookup consults them after the built-ins,
so a pack can never shadow a built-in id (extend panics on a collision and
is idempotent per slice). `all_antipatterns()` is the built-ins followed by
the registered rows.

Hook order, chosen so built-in output cannot move:

- detect_text: after every matcher, analyzer and the dedupe, before inline
  ignores, so `impeccable-disable` waives pack rules like built-in ones.
- detect_html_source: after the element rules, the design-system merge and
  the page passes, again before inline ignores. One pack pass per HTML
  file: the document hook when set, otherwise the text hook over the raw
  source, so a pack implementing both never reports twice.
- collect_browser_findings: the element hook at the end of the per-element
  loop through the same disabled-rules filter and group, the page hook
  after every built-in page pass with the same el-or-body attribution.

A pack travels on TextOptions / ScanOptions, DetectHtmlOptions
(static_rule_pack plus rule_pack), StaticHtmlEngine, and BrowserConfig
(serde-skipped: a pack is a Rust value, not JSON from the page). The
shipped binary installs none.

`crates/wasm --features detect` exposes the two file engines as JSON
exports for hosts that cannot exec the binary: `detect_text_json` and
`detect_html_source_json`, options `{ inlineIgnores?, designSystem? }`,
returning the findings array `detect --json` prints. `antipatterns_json`
now includes a pack's rows. `set_rule_pack` and `set_static_rule_pack` are
Rust-only, for a crate that links this one as an rlib.

Tests: registry extension and collision in foundation, one test pack per
engine (crates/core, crates/detect, crates/html tests) proving each hook
fires, that the built-in findings are unchanged, and that the waivers and
the disabled-rules list cover pack rules, plus the wasm export shapes.
Workspace tests 346 to 361, oracle 795/0 unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vau2X53xGTjjTCXWMVBoNY
2026-09-03 09:37:37 -07:00

41 lines
1.6 KiB
TOML

[package]
name = "impeccable-wasm"
edition.workspace = true
version.workspace = true
license.workspace = true
publish.workspace = true
[lib]
crate-type = ["cdylib", "rlib"]
[features]
default = []
# The JSON-in/JSON-out exports over the pure core surface (exports_pure.rs),
# for the site and other consumers. Off in the shipped in-page bundle: the
# scan path never calls them and they add ~150 KB of wasm plus ~80 KB of glue.
# `cargo xtask bundle --pure` builds a bundle that carries them; native
# `cargo test -p impeccable-wasm` covers them either way.
pure-exports = ["impeccable-core/vectors"]
# The file-scanning engines as JSON-in / JSON-out exports (exports_detect.rs):
# `detect_text_json` and `detect_html_source_json`, for hosts that cannot exec
# the binary (Cloudflare Workers and other wasm sandboxes). Off in the in-page
# bundle, which scans the live DOM instead and would only pay the parser's
# weight for nothing.
detect = ["dep:impeccable-detect", "dep:impeccable-html"]
[dependencies]
impeccable-core = { workspace = true }
impeccable-detect = { workspace = true, optional = true }
impeccable-html = { workspace = true, optional = true }
wasm-bindgen = "0.2"
serde_json = { workspace = true }
[dev-dependencies]
impeccable-wasm = { path = ".", features = ["pure-exports", "detect"] }
# wasm-pack runs wasm-opt on the release build. `--all-features` is required:
# the bundled wasm-opt predates the wasm features rustc emits by default
# (bulk memory, multivalue, reference types) and rejects the module otherwise.
[package.metadata.wasm-pack.profile.release]
wasm-opt = ["-Oz", "--all-features"]