class

Detector::Javascript::CloudflarePages

Inherits Detector < Reference < Object

A Cloudflare Pages Functions module: a file under a project's root functions/ directory exporting an onRequest* handler.

Constants

EXTENSIONS = {".js", ".mjs", ".ts", ".tsx", ".jsx"}
HANDLER_EXPORT = /(?:^|[^\w$.])export\s+(?:(?:async\s+)?function\s*\*?\s*|(?:const|let|var)\s+)onRequest(?:Get|Post|Put|Patch|Delete|Head|Options)?\b|(?:^|[^\w$.])export\s*\{[^}]*\bonRequest(?:Get|Post|Put|Patch|Delete|Head|Options)?\b[^}]*\}/m

export [async] function onRequestGet(, export const onRequest =, export { onRequestPost }.

Instance methods

applicable?(filename : String) : Bool

Cheap filename-only filter the detector pass uses to skip detect on files the detector cannot possibly match. The default true preserves prior behavior (every detector runs on every file). Override with the same predicate the body of detect starts with — e.g., filename.ends_with?(".py") for a Python framework detector — so the detector loop avoids the detect dispatch on files outside the detector's language.

On large codebases (saleor's 4255 .py files) this lifts ~100 virtual detect calls per file out of the hot loop because most detectors' inner first-line is exactly this kind of cheap filename check.

Source
detect(filename : String, file_contents : String) : Bool
Source
name

The tech name; detector_for overrides it. Empty on the bare base.

Source
path_sensitive?

Whether applicable? inspects more than the basename — directory segments (/metadata/, /.kamal/) or root placement.

The detect loop memoizes applicable? by basename, so a detector that consults the path but does not declare it here has its path gate silently deleted: applicable? is only ever asked about the bare filename. That is a false-negative, not a crash, so nothing fails loudly. Noir::Detection.path_sensitive? also probes for this, but the probe is fail-open — a probe whose basename independently matches masks the directory gate behind it (this is exactly how the Hasura metadata/** gate was lost). Declare it explicitly.

Guarded by spec/unit_test/detector/applicable_lookup_fidelity_spec.cr.

Source