mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
The split tools ran oxfmt in the checkout they rewrite. oxfmt looks up its configuration from that directory and from the formatted files' directories, and runs an oxfmt.config.ts it finds there, so a branch that rehome-split rewrites could run code with the maintainer's permissions. The tools now format through format.mjs, which passes the tools checkout's .oxfmtrc.jsonc with --config and disables the nested lookup, so no configuration file of the rewritten checkout is read or run. With no files to format it does nothing, where oxfmt would format the whole directory. The split-tools tests cover split-methods and move-state on a checkout whose root and src directory commit an oxfmt.config.ts that records it ran.
21 lines
973 B
JavaScript
21 lines
973 B
JavaScript
/* Formatting for the split tools. oxfmt reads its configuration from the
|
|
* directory it runs in, its parents and the formatted files' directories,
|
|
* and an oxfmt.config.ts there is code it runs. The tools format files in
|
|
* a checkout they rewrite, which can be a pull request's, so they pass the
|
|
* tools checkout's own configuration and turn the nested lookup off: no
|
|
* configuration file of the rewritten checkout is read or run. */
|
|
import { execFileSync } from "node:child_process";
|
|
import { join } from "node:path";
|
|
|
|
/** Formats `files` (paths relative to `cwd`) with the tools checkout's
|
|
* oxfmt and configuration. */
|
|
export function formatFiles(toolsDir, files, { cwd, stdio }) {
|
|
// With no file arguments oxfmt would format the whole directory.
|
|
if (files.length === 0) return;
|
|
execFileSync(
|
|
join(toolsDir, "node_modules/.bin/oxfmt"),
|
|
["--config", join(toolsDir, ".oxfmtrc.jsonc"), "--disable-nested-config", ...files],
|
|
{ cwd, stdio },
|
|
);
|
|
}
|