Skip to content

definePackagePolicy

definePackagePolicy<J, C>(args): PolicyShape<C>

Defined in: policyDefiners/definePackagePolicy.ts:97

Define a repo policy for package.json files.

J = PackageJson

C = undefined

DefinePackagePolicyArgs<J, C>

Policy metadata, parsed-JSON handler, and optional defaults.

PolicyShape<C>

A file policy that reads and parses matching package.json files.

This is a helper function that creates a policy pre-configured to match package.json files. The handler receives the parsed JSON content.

const MyPackagePolicy = definePackagePolicy({
name: "MyPackagePolicy",
description: "Ensures package.json has required fields",
handler: async (json, { file }) => {
if (!json.name) {
return { error: "Missing name", fixable: false };
}
return true;
},
});