Files
Neil 9bd6272fdf refactor(tooling): organize build, CI, and test owners (#38130)
* refactor(tooling): organize test runtime and maintenance owners

* test(tooling): preserve relocated runtime fixture dependency edges

* refactor(tooling): preserve xterm routing owner checks

* ci(tooling): include routing owner in sparse checkout

* test(tooling): preserve copied workflow dependency closures

* fix(tooling): normalize hashed JSON assets in release parity

* fix(tooling): distinguish asset aliases from literal references

* fix(tooling): frame normalized asset reference payloads

* fix(tooling): normalize decoded JSON asset references

* refactor(tooling): organize build, CI and release owners

* fix(tooling): align moved generator and workflow path contracts

* fix(tooling): update generated plugin bundle owner banners

* test(tooling): create relocated mobile verifier fixture directories

* test(tooling): copy headless detector dependency closure

* test(tooling): align native batch policy fixtures with owner path

* fix(tooling): link moved reliability command to historical evidence

* fix(tooling): preserve nested sandbox owners and canonical guide source

* fix(tooling): target release version owners in checkout fixture
2026-11-04 21:08:19 -08:00

51 lines
1.7 KiB
JavaScript

import { spawnSync } from 'node:child_process'
import { createRequire } from 'node:module'
import process from 'node:process'
export const AST_GREP_CONFIG = 'config/sgconfig.yml'
export const AST_GREP_SCAN_PATHS = ['src', 'config', 'tests', 'mobile']
// Resolve the platform binary here: Windows .cmd shims need a shell, and temporary scan roots lack dependencies.
export function resolveAstGrepBinary() {
const binary = createRequire(new URL('../../ast-grep-scan.mjs', import.meta.url))(
'@ast-grep/cli/postinstall.js'
).resolveBinaryPath()
if (!binary) {
throw new Error('No @ast-grep/cli binary for this platform; run pnpm install.')
}
return binary
}
/** Runs `ast-grep scan` and returns its JSON matches; exit status 1 only means error findings. */
export function scanAstGrep(root, { filter, minSeverity, paths = AST_GREP_SCAN_PATHS } = {}) {
const args = ['scan', '--config', AST_GREP_CONFIG, '--json=stream', '--color', 'never']
if (filter) {
args.push('--filter', filter)
}
if (minSeverity) {
args.push('--min-severity', minSeverity)
}
const result = spawnSync(resolveAstGrepBinary(), [...args, '--', ...paths], {
cwd: root,
encoding: 'utf8',
maxBuffer: 256 * 1024 * 1024,
windowsHide: true
})
if (result.error) {
throw result.error
}
if (result.status !== 0 && result.status !== 1) {
process.stderr.write(result.stderr)
throw new Error(`ast-grep scan failed with exit code ${result.status}.`)
}
return result.stdout
.split('\n')
.filter((line) => line.trim())
.map((line) => JSON.parse(line))
}
/** Per-language twins share one rule id with a `-tsx` suffix; report them as one rule. */
export function baseRuleId(ruleId) {
return ruleId.replace(/-tsx$/, '')
}