/** * Go build-constraint evaluation for static dependency analysis. * * Supports both forms: * - Modern `//go:build` (boolean expression with `&&`, `||`, `!`, parens) * - Legacy `// +build` (OR-of-AND term lists; multiple lines AND'd) * * When both are present (`gofmt` emits both for files that must compile * under pre-1.17 Go), `//go:build` wins per the spec. * * Honored alongside the in-source forms: Go's filename-suffix conventions * (`name_.go`, `name_.go`, `name__.go`, with an * optional trailing `_test`). See `shouldIncludeFilename`. * * Build policy lives on `BuildContext`, not hardcoded in the matcher: * - `cgo` evaluates to `ctx.cgoEnabled ?? false` — static analysis never * runs cgo, so it defaults off. * - `go1.M` version tags evaluate against `ctx.goVersion` when supplied * (`ctx-minor >= tag-minor`); with no version handy they're treated as * satisfied, since over-including is safer than under-including for graph * computation. * * @see https://pkg.go.dev/go/build#hdr-Build_Constraints — the constraint spec this implements * @see https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md — why `//go:build` replaced `// +build` */ /** Canonical Go `GOOS` values per `internal/syslist.KnownOS`. */ declare const KNOWN_GOOSES_LIST: readonly ["aix", "android", "darwin", "dragonfly", "freebsd", "hurd", "illumos", "ios", "js", "linux", "nacl", "netbsd", "openbsd", "plan9", "solaris", "wasip1", "windows", "zos"]; /** Closed union of Go GOOS values; used internally to enforce membership. */ type KnownGoOS = (typeof KNOWN_GOOSES_LIST)[number]; /** Exported GOOS type with an escape hatch for unknown Node platforms. */ export type GoOS = KnownGoOS | (string & {}); /** Canonical Go `GOARCH` values per `internal/syslist.KnownArch`. */ declare const KNOWN_GOARCHES_LIST: readonly ["386", "amd64", "amd64p32", "arm", "arm64", "arm64be", "armbe", "loong64", "mips", "mips64", "mips64le", "mips64p32", "mips64p32le", "mipsle", "ppc", "ppc64", "ppc64le", "riscv", "riscv64", "s390", "s390x", "sparc", "sparc64", "wasm"]; type KnownGoArch = (typeof KNOWN_GOARCHES_LIST)[number]; export type GoArch = KnownGoArch | (string & {}); export interface BuildContext { readonly goos: GoOS; readonly goarch: GoArch; /** User-supplied tags (e.g. `integration`, `debug`). Default empty. */ readonly tags: ReadonlySet; /** * Whether cgo is enabled in the target environment. Static analysis never * invokes cgo, so the matcher treats this as `false` when unset — a * `//go:build cgo` file is excluded unless a caller opts in. */ readonly cgoEnabled?: boolean; /** * Target Go toolchain version as `1.N`. A `go1.M` build tag means "requires * Go 1.M or newer"; when `goVersion` is set the matcher gates on `N >= M` * (compared numerically). When unset, every `go1.M` tag is satisfied, since * over-including is safer than under-including for graph computation. * * @see https://pkg.go.dev/go/build#hdr-Build_Constraints — `go1.N` release tags */ readonly goVersion?: `1.${number}`; } /** * Derive a default `BuildContext` from the current Node process. * The result is process-stable — safe to memoize at module level (the sole * caller does). Freezing the object stops a caller reassigning a field of the * shared default; the `tags` set's immutability is the job of its * `ReadonlySet` type, since `Object.freeze` does not lock a Set's contents at * runtime (the empty-set freeze is a harmless backstop, not the guarantee). * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze — `Object.freeze` does not lock a Set's contents */ export declare function getDefaultBuildContext(): BuildContext; /** * Decide whether a Go source file should be considered for import * extraction given its content and a build context. Returns `true` when * no recognized build constraint is present. * * @param sourceLabel - Optional identifier (typically a file path) used * in warning messages when the evaluator hits a malformed-expression * fallback. Omit it to silence those warnings (the unit tests do). */ export declare function shouldIncludeFile(content: string, ctx: BuildContext, sourceLabel?: string): boolean; /** * Decide whether a Go source file should be considered for import * extraction based on its filename, honoring Go's implicit platform * suffix rules. Returns `true` when the filename carries no recognized * suffix or when the suffix matches `ctx`. * * Recognized patterns (Go's `go/build` algorithm, simplified): * - `name_.go` — gates on GOOS * - `name_.go` — gates on GOARCH * - `name__.go` — gates on both * - any of the above with `_test` appended before `.go` * * "Known" GOOS/GOARCH means the value appears in Go's `internal/syslist`. * A name like `nethelper.go` whose tokens don't match either set is * treated as unconstrained. * * @param filePath - Full path or basename — directory parts are stripped. */ export declare function shouldIncludeFilename(filePath: string, ctx: BuildContext): boolean; export {};