Skip to content

feat(audit): extract detectTemplate into edge-safe modules so content-detection runs on Workers #426

Closed

Description

@lex00

Blocks the #356 hosted service from doing all-lexicon detection on the edge.

Problem

classifyFiles content-detects gcp/k8s/aws/azure/docker(compose)/helm by calling each lexicon's detectTemplate. Getting detectTemplate means importing the lexicon plugin — and plugin.ts statically imports declarative rules (e.g. use-typed-actions, which does import * as ts from "typescript"), so importing it drags the TypeScript compiler and crashes workerd (__filename). Verified in the #356 spike. Also loadAuditPlugins uses a dynamic import("@intentius/chant-lexicon-"+name) esbuild can't bundle for the edge.

Net: the hosted service can do CI (path-detected) but NOT content-detected lexicons on the edge — reopening the #420 gap on Workers.

Fix (mirrors #409)

  • Extract each content lexicon's detectTemplate into a standalone, typescript-free module src/detect.ts; plugin.ts imports it for its detectTemplate. Add a "./detect" exports entry. Lexicons: gcp, k8s, aws, azure, docker, helm.
  • Narrow classifyFiles' param from LexiconPlugin[] to { name: string; detectTemplate?(...) }[] so callers can build detectors from static detect imports (CI lexicons need only {name} — they're path-detected).
  • Guard test: importing the detect modules pulls in no typescript (esbuild metafile).

Done

  • @intentius/chant-lexicon-<lex>/detect importable with no typescript in the graph (gcp/k8s/aws/azure/docker/helm).
  • classifyFiles accepts lightweight detectors; Node audit path unchanged.
  • npx vitest run green.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions