chore: migrate formatting to Oxfmt (#615)
This commit is contained in:
@@ -2,7 +2,7 @@ import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { analysisErrorJsonSchema } from "../dist/contracts/errorSchemas.js";
|
||||
import { format } from "prettier";
|
||||
import { formatGeneratedFile } from "./lib/format-generated-file.mjs";
|
||||
import { ensureGeneratedFile } from "./lib/generated-file.mjs";
|
||||
|
||||
const arguments_ = new Set(process.argv.slice(2));
|
||||
@@ -13,9 +13,10 @@ for (const argument of arguments_)
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
await ensureGeneratedFile({
|
||||
path: join(root, "docs/error-contract.schema.json"),
|
||||
source: await format(JSON.stringify(analysisErrorJsonSchema), {
|
||||
parser: "json",
|
||||
}),
|
||||
source: await formatGeneratedFile(
|
||||
"docs/error-contract.schema.json",
|
||||
JSON.stringify(analysisErrorJsonSchema),
|
||||
),
|
||||
check: arguments_.has("--check"),
|
||||
generateCommand: "npm run docs:generate",
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { format } from "prettier";
|
||||
import { formatGeneratedFile } from "./lib/format-generated-file.mjs";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { McpServer } from "@modelcontextprotocol/server";
|
||||
@@ -110,7 +110,8 @@ const canonicalizeJson = (value) => {
|
||||
const payloadJson = JSON.stringify(
|
||||
canonicalizeJson({ catalog, auxiliaryProviders }),
|
||||
);
|
||||
const source = await format(
|
||||
const source = await formatGeneratedFile(
|
||||
"src/generatedMcpToolCatalog.ts",
|
||||
`import type { ToolAnnotations } from "@modelcontextprotocol/server";
|
||||
import type {
|
||||
CapabilityDescriptor,
|
||||
@@ -194,7 +195,6 @@ function isRecord(
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
`,
|
||||
{ parser: "typescript" },
|
||||
);
|
||||
|
||||
await ensureGeneratedFile({
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { format } from "oxfmt";
|
||||
import config from "../../.oxfmtrc.json" with { type: "json" };
|
||||
|
||||
/** Format generated source with the same options as the repository formatter. */
|
||||
export const formatGeneratedFile = async (fileName, source) => {
|
||||
const result = await format(fileName, source, config);
|
||||
if (result.errors.length > 0)
|
||||
throw new Error(
|
||||
`Cannot format ${fileName}: ${result.errors.map(({ message }) => message).join("; ")}`,
|
||||
);
|
||||
return result.code;
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import { format } from "prettier";
|
||||
import { formatGeneratedFile } from "./format-generated-file.mjs";
|
||||
|
||||
import { assertSameNames, digest, loadSources } from "./catalog-core.mjs";
|
||||
import {
|
||||
@@ -67,4 +67,7 @@ export const createProductCatalog = async (root) => {
|
||||
|
||||
/** Stable checked-in representation of the product catalog. */
|
||||
export const serializeProductCatalog = (catalog) =>
|
||||
format(JSON.stringify(catalog, null, 2), { parser: "json" });
|
||||
formatGeneratedFile(
|
||||
"docs/product-catalog.json",
|
||||
JSON.stringify(catalog, null, 2),
|
||||
);
|
||||
|
||||
@@ -47,12 +47,10 @@ export async function verifySwitchEvidenceControls({
|
||||
workspace,
|
||||
runId,
|
||||
}) {
|
||||
const { spawnOwnedProviderProcess, ProviderProcessSupervisor } = await import(
|
||||
"../dist/process/ProviderProcess.js"
|
||||
);
|
||||
const { cleanupOwnedProcessGroup } = await import(
|
||||
"../dist/process/ProcessOwnership.js"
|
||||
);
|
||||
const { spawnOwnedProviderProcess, ProviderProcessSupervisor } =
|
||||
await import("../dist/process/ProviderProcess.js");
|
||||
const { cleanupOwnedProcessGroup } =
|
||||
await import("../dist/process/ProcessOwnership.js");
|
||||
const bridge = await realpath(
|
||||
join(dirname(entrypoint), "../bridge/ghidra/ReaGhidraBridge.java"),
|
||||
);
|
||||
|
||||
@@ -67,9 +67,8 @@ for (const [role, command] of Object.entries(commands)) {
|
||||
}
|
||||
let installation;
|
||||
if (!compilerOnly) {
|
||||
const { inspectGhidraInstallation } = await import(
|
||||
"../dist/ghidra/GhidraInstallation.js"
|
||||
);
|
||||
const { inspectGhidraInstallation } =
|
||||
await import("../dist/ghidra/GhidraInstallation.js");
|
||||
assert.ok(
|
||||
process.env.GHIDRA_INSTALL_DIR,
|
||||
"Ghidra switch lane prerequisite missing: GHIDRA_INSTALL_DIR (bring your own)",
|
||||
|
||||
Reference in New Issue
Block a user