repopo 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (333) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +50 -90
  3. package/THIRD-PARTY-LICENSES.txt +169 -11
  4. package/bin/dev.js +0 -0
  5. package/esm/adapters/fluidFramework.d.ts +13 -9
  6. package/esm/adapters/fluidFramework.d.ts.map +1 -1
  7. package/esm/adapters/fluidFramework.js +20 -43
  8. package/esm/adapters/fluidFramework.js.map +1 -1
  9. package/esm/api.d.ts +64 -1
  10. package/esm/api.d.ts.map +1 -1
  11. package/esm/api.js +17 -1
  12. package/esm/api.js.map +1 -1
  13. package/esm/baseCommand.d.ts.map +1 -1
  14. package/esm/baseCommand.js +2 -2
  15. package/esm/baseCommand.js.map +1 -1
  16. package/esm/commands/check-native.d.ts +3 -3
  17. package/esm/commands/check-native.d.ts.map +1 -1
  18. package/esm/commands/check-native.js +26 -7
  19. package/esm/commands/check-native.js.map +1 -1
  20. package/esm/commands/check.d.ts +6 -21
  21. package/esm/commands/check.d.ts.map +1 -1
  22. package/esm/commands/check.js +73 -153
  23. package/esm/commands/check.js.map +1 -1
  24. package/esm/commands/list.d.ts.map +1 -1
  25. package/esm/commands/list.js +2 -1
  26. package/esm/commands/list.js.map +1 -1
  27. package/esm/concurrency.d.ts +3 -0
  28. package/esm/concurrency.d.ts.map +1 -0
  29. package/esm/concurrency.js +8 -0
  30. package/esm/concurrency.js.map +1 -0
  31. package/esm/config.d.ts +5 -39
  32. package/esm/config.d.ts.map +1 -1
  33. package/esm/config.js +3 -7
  34. package/esm/config.js.map +1 -1
  35. package/esm/context.d.ts +8 -1
  36. package/esm/context.d.ts.map +1 -1
  37. package/esm/context.js +8 -1
  38. package/esm/context.js.map +1 -1
  39. package/esm/executionContractError.d.ts +4 -0
  40. package/esm/executionContractError.d.ts.map +1 -0
  41. package/esm/executionContractError.js +4 -0
  42. package/esm/executionContractError.js.map +1 -0
  43. package/esm/fileCache.d.ts +12 -0
  44. package/esm/fileCache.d.ts.map +1 -0
  45. package/esm/fileCache.js +37 -0
  46. package/esm/fileCache.js.map +1 -0
  47. package/esm/filePaths.d.ts +2 -0
  48. package/esm/filePaths.d.ts.map +1 -0
  49. package/esm/filePaths.js +9 -0
  50. package/esm/filePaths.js.map +1 -0
  51. package/esm/generators.d.ts +0 -20
  52. package/esm/generators.d.ts.map +1 -1
  53. package/esm/generators.js.map +1 -1
  54. package/esm/index.d.ts +3 -16
  55. package/esm/index.d.ts.map +1 -1
  56. package/esm/index.js +3 -17
  57. package/esm/index.js.map +1 -1
  58. package/esm/makePolicy.d.ts +20 -100
  59. package/esm/makePolicy.d.ts.map +1 -1
  60. package/esm/makePolicy.js +44 -132
  61. package/esm/makePolicy.js.map +1 -1
  62. package/esm/perf.d.ts +5 -2
  63. package/esm/perf.d.ts.map +1 -1
  64. package/esm/perf.js +10 -9
  65. package/esm/perf.js.map +1 -1
  66. package/esm/policies/CargoLicenceValidated.d.ts +4 -4
  67. package/esm/policies/CargoLicenceValidated.d.ts.map +1 -1
  68. package/esm/policies/CargoLicenceValidated.js +9 -7
  69. package/esm/policies/CargoLicenceValidated.js.map +1 -1
  70. package/esm/policies/CargoLintsConfigured.d.ts +4 -4
  71. package/esm/policies/CargoLintsConfigured.d.ts.map +1 -1
  72. package/esm/policies/CargoLintsConfigured.js +19 -15
  73. package/esm/policies/CargoLintsConfigured.js.map +1 -1
  74. package/esm/policies/CargoLockPolicy.d.ts +4 -4
  75. package/esm/policies/CargoLockPolicy.d.ts.map +1 -1
  76. package/esm/policies/CargoLockPolicy.js +15 -11
  77. package/esm/policies/CargoLockPolicy.js.map +1 -1
  78. package/esm/policies/CargoTomlRequired.d.ts +5 -5
  79. package/esm/policies/CargoTomlRequired.d.ts.map +1 -1
  80. package/esm/policies/CargoTomlRequired.js +7 -7
  81. package/esm/policies/CargoTomlRequired.js.map +1 -1
  82. package/esm/policies/CargoTomlSorted.d.ts +4 -4
  83. package/esm/policies/CargoTomlSorted.d.ts.map +1 -1
  84. package/esm/policies/CargoTomlSorted.js +21 -17
  85. package/esm/policies/CargoTomlSorted.js.map +1 -1
  86. package/esm/policies/ConditionalScripts.d.ts +10 -8
  87. package/esm/policies/ConditionalScripts.d.ts.map +1 -1
  88. package/esm/policies/ConditionalScripts.js +24 -22
  89. package/esm/policies/ConditionalScripts.js.map +1 -1
  90. package/esm/policies/ExactScripts.d.ts +8 -6
  91. package/esm/policies/ExactScripts.d.ts.map +1 -1
  92. package/esm/policies/ExactScripts.js +15 -18
  93. package/esm/policies/ExactScripts.js.map +1 -1
  94. package/esm/policies/GleamDepVersions.d.ts +5 -5
  95. package/esm/policies/GleamDepVersions.d.ts.map +1 -1
  96. package/esm/policies/GleamDepVersions.js +5 -5
  97. package/esm/policies/GleamDepVersions.js.map +1 -1
  98. package/esm/policies/GleamDocExists.d.ts +4 -4
  99. package/esm/policies/GleamDocExists.d.ts.map +1 -1
  100. package/esm/policies/GleamDocExists.js +6 -6
  101. package/esm/policies/GleamDocExists.js.map +1 -1
  102. package/esm/policies/GleamInternalModulesConfigured.d.ts +4 -4
  103. package/esm/policies/GleamInternalModulesConfigured.d.ts.map +1 -1
  104. package/esm/policies/GleamInternalModulesConfigured.js +8 -6
  105. package/esm/policies/GleamInternalModulesConfigured.js.map +1 -1
  106. package/esm/policies/GleamLicenceConfigured.d.ts +4 -4
  107. package/esm/policies/GleamLicenceConfigured.d.ts.map +1 -1
  108. package/esm/policies/GleamLicenceConfigured.js +8 -6
  109. package/esm/policies/GleamLicenceConfigured.js.map +1 -1
  110. package/esm/policies/GleamManifestCommitted.d.ts +10 -3
  111. package/esm/policies/GleamManifestCommitted.d.ts.map +1 -1
  112. package/esm/policies/GleamManifestCommitted.js +10 -9
  113. package/esm/policies/GleamManifestCommitted.js.map +1 -1
  114. package/esm/policies/GleamMonorepoConsistency.d.ts +13 -5
  115. package/esm/policies/GleamMonorepoConsistency.d.ts.map +1 -1
  116. package/esm/policies/GleamMonorepoConsistency.js +10 -10
  117. package/esm/policies/GleamMonorepoConsistency.js.map +1 -1
  118. package/esm/policies/GleamNameRestrictions.d.ts +4 -4
  119. package/esm/policies/GleamNameRestrictions.d.ts.map +1 -1
  120. package/esm/policies/GleamNameRestrictions.js +6 -6
  121. package/esm/policies/GleamNameRestrictions.js.map +1 -1
  122. package/esm/policies/GleamNoPathDepsInPublished.d.ts +4 -4
  123. package/esm/policies/GleamNoPathDepsInPublished.d.ts.map +1 -1
  124. package/esm/policies/GleamNoPathDepsInPublished.js +6 -6
  125. package/esm/policies/GleamNoPathDepsInPublished.js.map +1 -1
  126. package/esm/policies/GleamPathDepsValid.d.ts +3 -3
  127. package/esm/policies/GleamPathDepsValid.d.ts.map +1 -1
  128. package/esm/policies/GleamPathDepsValid.js +5 -5
  129. package/esm/policies/GleamPathDepsValid.js.map +1 -1
  130. package/esm/policies/GleamProjectStructure.d.ts +11 -4
  131. package/esm/policies/GleamProjectStructure.d.ts.map +1 -1
  132. package/esm/policies/GleamProjectStructure.js +7 -8
  133. package/esm/policies/GleamProjectStructure.js.map +1 -1
  134. package/esm/policies/GleamSharedDependencyVersions.d.ts +12 -4
  135. package/esm/policies/GleamSharedDependencyVersions.d.ts.map +1 -1
  136. package/esm/policies/GleamSharedDependencyVersions.js +10 -10
  137. package/esm/policies/GleamSharedDependencyVersions.js.map +1 -1
  138. package/esm/policies/GleamTomlRequired.d.ts +4 -4
  139. package/esm/policies/GleamTomlRequired.d.ts.map +1 -1
  140. package/esm/policies/GleamTomlRequired.js +5 -5
  141. package/esm/policies/GleamTomlRequired.js.map +1 -1
  142. package/esm/policies/GleamTomlSorted.d.ts +4 -4
  143. package/esm/policies/GleamTomlSorted.d.ts.map +1 -1
  144. package/esm/policies/GleamTomlSorted.js +21 -17
  145. package/esm/policies/GleamTomlSorted.js.map +1 -1
  146. package/esm/policies/GleamVersionConstraint.d.ts +4 -4
  147. package/esm/policies/GleamVersionConstraint.d.ts.map +1 -1
  148. package/esm/policies/GleamVersionConstraint.js +14 -10
  149. package/esm/policies/GleamVersionConstraint.js.map +1 -1
  150. package/esm/policies/HtmlFileHeaders.d.ts +4 -2
  151. package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
  152. package/esm/policies/HtmlFileHeaders.js +1 -1
  153. package/esm/policies/HtmlFileHeaders.js.map +1 -1
  154. package/esm/policies/JsTsFileHeaders.d.ts +4 -2
  155. package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
  156. package/esm/policies/JsTsFileHeaders.js +1 -1
  157. package/esm/policies/JsTsFileHeaders.js.map +1 -1
  158. package/esm/policies/LicenseFileExists.d.ts +10 -4
  159. package/esm/policies/LicenseFileExists.d.ts.map +1 -1
  160. package/esm/policies/LicenseFileExists.js +27 -20
  161. package/esm/policies/LicenseFileExists.js.map +1 -1
  162. package/esm/policies/MutuallyExclusiveScripts.d.ts +8 -6
  163. package/esm/policies/MutuallyExclusiveScripts.d.ts.map +1 -1
  164. package/esm/policies/MutuallyExclusiveScripts.js +9 -13
  165. package/esm/policies/MutuallyExclusiveScripts.js.map +1 -1
  166. package/esm/policies/NoBuildDirectory.d.ts +9 -3
  167. package/esm/policies/NoBuildDirectory.d.ts.map +1 -1
  168. package/esm/policies/NoBuildDirectory.js +8 -13
  169. package/esm/policies/NoBuildDirectory.js.map +1 -1
  170. package/esm/policies/NoJsFileExtensions.d.ts +9 -3
  171. package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
  172. package/esm/policies/NoJsFileExtensions.js +9 -14
  173. package/esm/policies/NoJsFileExtensions.js.map +1 -1
  174. package/esm/policies/NoLargeBinaryFiles.d.ts +9 -4
  175. package/esm/policies/NoLargeBinaryFiles.d.ts.map +1 -1
  176. package/esm/policies/NoLargeBinaryFiles.js +10 -16
  177. package/esm/policies/NoLargeBinaryFiles.js.map +1 -1
  178. package/esm/policies/NoPrivateWorkspaceDependencies.d.ts +10 -6
  179. package/esm/policies/NoPrivateWorkspaceDependencies.d.ts.map +1 -1
  180. package/esm/policies/NoPrivateWorkspaceDependencies.js +12 -14
  181. package/esm/policies/NoPrivateWorkspaceDependencies.js.map +1 -1
  182. package/esm/policies/NoTargetArtifacts.d.ts +9 -3
  183. package/esm/policies/NoTargetArtifacts.d.ts.map +1 -1
  184. package/esm/policies/NoTargetArtifacts.js +9 -14
  185. package/esm/policies/NoTargetArtifacts.js.map +1 -1
  186. package/esm/policies/NoUnsafeWithoutJustification.d.ts +11 -4
  187. package/esm/policies/NoUnsafeWithoutJustification.d.ts.map +1 -1
  188. package/esm/policies/NoUnsafeWithoutJustification.js +8 -9
  189. package/esm/policies/NoUnsafeWithoutJustification.js.map +1 -1
  190. package/esm/policies/NoWildcardDependencies.d.ts +5 -5
  191. package/esm/policies/NoWildcardDependencies.d.ts.map +1 -1
  192. package/esm/policies/NoWildcardDependencies.js +6 -6
  193. package/esm/policies/NoWildcardDependencies.js.map +1 -1
  194. package/esm/policies/PackageAllowedScopes.d.ts +9 -5
  195. package/esm/policies/PackageAllowedScopes.d.ts.map +1 -1
  196. package/esm/policies/PackageAllowedScopes.js +15 -16
  197. package/esm/policies/PackageAllowedScopes.js.map +1 -1
  198. package/esm/policies/PackageEsmType.d.ts +7 -5
  199. package/esm/policies/PackageEsmType.d.ts.map +1 -1
  200. package/esm/policies/PackageEsmType.js +31 -31
  201. package/esm/policies/PackageEsmType.js.map +1 -1
  202. package/esm/policies/PackageFolderName.d.ts +8 -6
  203. package/esm/policies/PackageFolderName.d.ts.map +1 -1
  204. package/esm/policies/PackageFolderName.js +13 -16
  205. package/esm/policies/PackageFolderName.js.map +1 -1
  206. package/esm/policies/PackageJsonProperties.d.ts +5 -3
  207. package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
  208. package/esm/policies/PackageJsonProperties.js +6 -17
  209. package/esm/policies/PackageJsonProperties.js.map +1 -1
  210. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +2 -7
  211. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
  212. package/esm/policies/PackageJsonRepoDirectoryProperty.js +28 -42
  213. package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
  214. package/esm/policies/PackageJsonSorted.d.ts +2 -2
  215. package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
  216. package/esm/policies/PackageJsonSorted.js +15 -30
  217. package/esm/policies/PackageJsonSorted.js.map +1 -1
  218. package/esm/policies/PackageLicense.d.ts +4 -4
  219. package/esm/policies/PackageLicense.d.ts.map +1 -1
  220. package/esm/policies/PackageLicense.js +31 -52
  221. package/esm/policies/PackageLicense.js.map +1 -1
  222. package/esm/policies/PackagePrivateField.d.ts +12 -8
  223. package/esm/policies/PackagePrivateField.d.ts.map +1 -1
  224. package/esm/policies/PackagePrivateField.js +31 -23
  225. package/esm/policies/PackagePrivateField.js.map +1 -1
  226. package/esm/policies/PackageReadme.d.ts +6 -5
  227. package/esm/policies/PackageReadme.d.ts.map +1 -1
  228. package/esm/policies/PackageReadme.js +22 -59
  229. package/esm/policies/PackageReadme.js.map +1 -1
  230. package/esm/policies/PackageScripts.d.ts +26 -22
  231. package/esm/policies/PackageScripts.d.ts.map +1 -1
  232. package/esm/policies/PackageScripts.js +39 -36
  233. package/esm/policies/PackageScripts.js.map +1 -1
  234. package/esm/policies/PackageTestScripts.d.ts +10 -6
  235. package/esm/policies/PackageTestScripts.d.ts.map +1 -1
  236. package/esm/policies/PackageTestScripts.js +14 -16
  237. package/esm/policies/PackageTestScripts.js.map +1 -1
  238. package/esm/policies/PublicApiDocumented.d.ts +4 -4
  239. package/esm/policies/PublicApiDocumented.d.ts.map +1 -1
  240. package/esm/policies/PublicApiDocumented.js +10 -8
  241. package/esm/policies/PublicApiDocumented.js.map +1 -1
  242. package/esm/policies/RequiredGitignorePatterns.d.ts +11 -4
  243. package/esm/policies/RequiredGitignorePatterns.d.ts.map +1 -1
  244. package/esm/policies/RequiredGitignorePatterns.js +29 -36
  245. package/esm/policies/RequiredGitignorePatterns.js.map +1 -1
  246. package/esm/policies/RequiredScripts.d.ts +9 -7
  247. package/esm/policies/RequiredScripts.d.ts.map +1 -1
  248. package/esm/policies/RequiredScripts.js +24 -24
  249. package/esm/policies/RequiredScripts.js.map +1 -1
  250. package/esm/policies/RustDocExists.d.ts +4 -4
  251. package/esm/policies/RustDocExists.d.ts.map +1 -1
  252. package/esm/policies/RustDocExists.js +6 -6
  253. package/esm/policies/RustDocExists.js.map +1 -1
  254. package/esm/policies/RustToolchainExists.d.ts +11 -4
  255. package/esm/policies/RustToolchainExists.d.ts.map +1 -1
  256. package/esm/policies/RustToolchainExists.js +10 -9
  257. package/esm/policies/RustToolchainExists.js.map +1 -1
  258. package/esm/policies/RustfmtConfigExists.d.ts +11 -4
  259. package/esm/policies/RustfmtConfigExists.d.ts.map +1 -1
  260. package/esm/policies/RustfmtConfigExists.js +10 -9
  261. package/esm/policies/RustfmtConfigExists.js.map +1 -1
  262. package/esm/policies/ScriptContains.d.ts +9 -7
  263. package/esm/policies/ScriptContains.d.ts.map +1 -1
  264. package/esm/policies/ScriptContains.js +9 -13
  265. package/esm/policies/ScriptContains.js.map +1 -1
  266. package/esm/policies/SharedDependencyVersions.d.ts +9 -4
  267. package/esm/policies/SharedDependencyVersions.d.ts.map +1 -1
  268. package/esm/policies/SharedDependencyVersions.js +28 -20
  269. package/esm/policies/SharedDependencyVersions.js.map +1 -1
  270. package/esm/policies/WorkspaceInheritance.d.ts +11 -4
  271. package/esm/policies/WorkspaceInheritance.d.ts.map +1 -1
  272. package/esm/policies/WorkspaceInheritance.js +10 -11
  273. package/esm/policies/WorkspaceInheritance.js.map +1 -1
  274. package/esm/policies/WorkspaceMembersValid.d.ts +11 -4
  275. package/esm/policies/WorkspaceMembersValid.d.ts.map +1 -1
  276. package/esm/policies/WorkspaceMembersValid.js +10 -11
  277. package/esm/policies/WorkspaceMembersValid.js.map +1 -1
  278. package/esm/policies/constants.d.ts.map +1 -1
  279. package/esm/policies/constants.js +1 -1
  280. package/esm/policies/constants.js.map +1 -1
  281. package/esm/policies.d.ts +13 -5
  282. package/esm/policies.d.ts.map +1 -1
  283. package/esm/policies.js +12 -5
  284. package/esm/policies.js.map +1 -1
  285. package/esm/policy.d.ts +61 -289
  286. package/esm/policy.d.ts.map +1 -1
  287. package/esm/policy.js +1 -122
  288. package/esm/policy.js.map +1 -1
  289. package/esm/policyDefiners/defineCargoPolicy.d.ts +25 -9
  290. package/esm/policyDefiners/defineCargoPolicy.d.ts.map +1 -1
  291. package/esm/policyDefiners/defineCargoPolicy.js +10 -28
  292. package/esm/policyDefiners/defineCargoPolicy.js.map +1 -1
  293. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +27 -14
  294. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
  295. package/esm/policyDefiners/defineFileHeaderPolicy.js +16 -35
  296. package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
  297. package/esm/policyDefiners/defineGleamPolicy.d.ts +25 -9
  298. package/esm/policyDefiners/defineGleamPolicy.d.ts.map +1 -1
  299. package/esm/policyDefiners/defineGleamPolicy.js +10 -27
  300. package/esm/policyDefiners/defineGleamPolicy.js.map +1 -1
  301. package/esm/policyDefiners/definePackagePolicy.d.ts +24 -13
  302. package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -1
  303. package/esm/policyDefiners/definePackagePolicy.js +9 -32
  304. package/esm/policyDefiners/definePackagePolicy.js.map +1 -1
  305. package/esm/policyDefiners/spdxValidator.d.ts +4 -12
  306. package/esm/policyDefiners/spdxValidator.d.ts.map +1 -1
  307. package/esm/policyDefiners/spdxValidator.js +26 -14
  308. package/esm/policyDefiners/spdxValidator.js.map +1 -1
  309. package/esm/policyExecution.d.ts +19 -0
  310. package/esm/policyExecution.d.ts.map +1 -0
  311. package/esm/policyExecution.js +224 -0
  312. package/esm/policyExecution.js.map +1 -0
  313. package/esm/repositoryFiles.d.ts +4 -0
  314. package/esm/repositoryFiles.d.ts.map +1 -0
  315. package/esm/repositoryFiles.js +8 -0
  316. package/esm/repositoryFiles.js.map +1 -0
  317. package/esm/runner.d.ts +72 -47
  318. package/esm/runner.d.ts.map +1 -1
  319. package/esm/runner.js +153 -138
  320. package/esm/runner.js.map +1 -1
  321. package/esm/settlePolicyPromise.d.ts +4 -0
  322. package/esm/settlePolicyPromise.d.ts.map +1 -0
  323. package/esm/settlePolicyPromise.js +10 -0
  324. package/esm/settlePolicyPromise.js.map +1 -0
  325. package/esm/tsdoc-metadata.json +1 -1
  326. package/esm/utils/safePaths.d.ts +9 -0
  327. package/esm/utils/safePaths.d.ts.map +1 -0
  328. package/esm/utils/safePaths.js +40 -0
  329. package/esm/utils/safePaths.js.map +1 -0
  330. package/oclif.manifest.json +19 -2
  331. package/package.json +42 -27
  332. package/scripts/benchmark.mjs +341 -0
  333. package/sidecar/sidecar.mjs +348 -417
package/esm/policy.d.ts CHANGED
@@ -1,313 +1,85 @@
1
1
  import type { Operation } from "effection";
2
- /**
3
- * A type representing a policy name.
4
- *
5
- * @alpha
6
- */
2
+ /** Display name of a policy. @public */
7
3
  export type PolicyName = string;
8
- /**
9
- * A stable identifier for a configured policy instance.
10
- *
11
- * @alpha
12
- */
4
+ /** Stable configured-instance identity. @public */
13
5
  export type PolicyInstanceId = string;
14
- /**
15
- * Arguments passed to policy handler functions.
16
- *
17
- * @alpha
18
- */
6
+ /** Arguments supplied to a file handler. @public */
19
7
  export interface PolicyArgs<C = void> {
20
- /**
21
- * Path to the file, relative to the repo root.
22
- */
23
8
  file: string;
24
- /**
25
- * Absolute path to the root of the repo.
26
- */
27
9
  root: string;
28
- /**
29
- * If true, the handler should resolve any violations automatically if possible.
30
- */
31
10
  resolve: boolean;
32
- /**
33
- * Optional configuration for the policy.
34
- */
35
11
  config?: C | undefined;
36
12
  }
37
- /**
38
- * @deprecated Use {@link PolicyArgs} instead.
39
- * @alpha
40
- */
41
- export type PolicyFunctionArguments<C> = PolicyArgs<C>;
42
- /**
43
- * A policy error returned when a file fails a policy check.
44
- *
45
- * @alpha
46
- */
47
- export interface PolicyError {
48
- /**
49
- * The error message describing what failed.
50
- */
51
- error: string;
52
- /**
53
- * Set to `true` if the policy violation can be fixed automatically.
54
- */
55
- fixable?: boolean | undefined;
56
- /**
57
- * Set to `true` if the violation was successfully fixed (only set when resolve=true).
58
- */
59
- fixed?: boolean | undefined;
60
- /**
61
- * An optional string that tells the user how to manually fix the failure.
62
- */
63
- manualFix?: string | undefined;
13
+ /** Arguments supplied to a repository handler; selection never limits files. @public */
14
+ export interface RepositoryPolicyArgs<C = void> extends Omit<PolicyArgs<C>, "file"> {
15
+ files: readonly string[];
64
16
  }
65
- /**
66
- * The result of a policy handler.
67
- * Returns `true` if the file passes the policy, or a {@link PolicyError} if it fails.
68
- *
69
- * @alpha
70
- */
71
- export type PolicyResult = true | PolicyError;
72
- /**
73
- * A policy failure (legacy format).
74
- *
75
- * @deprecated Use {@link PolicyError} instead, which has a simpler API.
76
- *
77
- * @alpha
78
- */
79
- export interface PolicyFailure {
80
- /**
81
- * Name of the policy that failed.
82
- */
83
- name: PolicyName;
84
- /**
85
- * Path to the file that failed the policy.
86
- */
87
- file: string;
88
- /**
89
- * Set to `true` if the policy can be fixed automatically.
90
- */
91
- autoFixable?: boolean | undefined;
92
- /**
93
- * An optional error message accompanying the failure.
94
- */
95
- errorMessages: string[];
96
- /**
97
- * An optional string that tells the user how to fix the failure(s).
98
- */
17
+ /** A single independently actionable violation or recorded fix. @public */
18
+ export interface PolicyFinding {
19
+ message: string;
99
20
  manualFix?: string | undefined;
21
+ fixStatus?: "available" | "fixed" | "failed" | undefined;
22
+ /** Repo-relative affected files. Only repository handlers may supply this. */
23
+ files?: readonly string[] | undefined;
100
24
  }
101
- /**
102
- * The result of an automatic fix for a failing policy (legacy format).
103
- *
104
- * @deprecated Use {@link PolicyError} with `fixed: boolean` instead.
105
- *
106
- * @alpha
107
- */
108
- export interface PolicyFixResult extends PolicyFailure {
109
- /**
110
- * Set to true if the failure was resolved by the automated fixer.
111
- */
112
- resolved: boolean;
113
- }
114
- /**
115
- * Result type that accepts both legacy and new formats.
116
- *
117
- * @alpha
118
- */
119
- export type PolicyHandlerResult = true | PolicyFailure | PolicyFixResult | PolicyError;
120
- /**
121
- * A policy handler function that checks a file against a policy.
122
- *
123
- * @remarks
124
- * Policy handlers can be implemented in two ways:
125
- * - As an async function returning a Promise
126
- * - As an Effection generator function returning an Operation
127
- *
128
- * Both styles are supported. Async handlers are automatically wrapped for Effection.
129
- *
130
- * Handlers can return either the legacy format ({@link PolicyFailure}) or
131
- * the new format ({@link PolicyError}). The new format is simpler and recommended
132
- * for new policies.
133
- *
134
- * @alpha
135
- */
136
- export type PolicyHandler<C = unknown | undefined> = ((args: PolicyArgs<C>) => Promise<PolicyHandlerResult>) | ((args: PolicyArgs<C>) => Operation<PolicyHandlerResult>);
137
- /**
138
- * A standalone resolver function that can fix policy violations (legacy format).
139
- *
140
- * @deprecated Use {@link PolicyResolver} instead, which uses {@link PolicyError}.
141
- *
142
- * @alpha
143
- */
144
- export type PolicyStandaloneResolver<C = undefined> = (args: Omit<PolicyArgs<C>, "resolve">) => Promise<PolicyFixResult> | Operation<PolicyFixResult>;
145
- /**
146
- * A standalone resolver function using the new format.
147
- *
148
- * @alpha
149
- */
150
- export type PolicyResolver<C = void> = (args: Omit<PolicyArgs<C>, "resolve">) => Promise<PolicyError> | Operation<PolicyError>;
151
- /**
152
- * Interface describing the shape of a policy definition.
153
- *
154
- * @typeParam C - Type of configuration object used by the policy
155
- *
156
- * @alpha
157
- */
158
- export interface PolicyShape<C = void> {
159
- /**
160
- * The name of the policy; displayed in UI and used in settings.
161
- */
25
+ /** Empty means pass. Fixed findings remain visible. @public */
26
+ export type PolicyResult = readonly PolicyFinding[];
27
+ /** Standalone file fixers receive and return the complete findings list. @public */
28
+ export type PolicyResolver<C = void> = {
29
+ resolve(args: Omit<PolicyArgs<C>, "resolve"> & {
30
+ findings: PolicyResult;
31
+ }): Promise<PolicyResult> | Operation<PolicyResult>;
32
+ }["resolve"];
33
+ /** File scope is the default. @public */
34
+ export interface FilePolicyDefinition<C = void> {
162
35
  name: PolicyName;
163
- /**
164
- * A detailed description of the policy and its purpose.
165
- */
166
36
  description: string;
167
- /**
168
- * A regular expression that matches files this policy applies to.
169
- */
37
+ scope?: "file";
170
38
  match: RegExp;
171
- /**
172
- * The handler function that checks if a file complies with the policy.
173
- */
174
- handler: PolicyHandler<C>;
175
- /**
176
- * An optional resolver function that can automatically fix violations.
177
- */
178
- resolver?: PolicyStandaloneResolver<C> | undefined;
179
- /**
180
- * A default configuration that will be used if none is provided.
181
- */
39
+ handler(args: PolicyArgs<C>): Promise<PolicyResult> | Operation<PolicyResult>;
40
+ resolver?: PolicyResolver<C> | undefined;
182
41
  defaultConfig?: C | undefined;
42
+ requiresConfig?: boolean | undefined;
183
43
  }
184
- /**
185
- * Abstract base class for creating policies with object-based construction.
186
- *
187
- * @remarks
188
- * This class accepts a {@link PolicyShape} object in its constructor,
189
- * making it easier to add new optional properties in the future without breaking changes.
190
- *
191
- * @alpha
192
- */
193
- export declare abstract class Policy<C = void> implements PolicyShape<C> {
194
- readonly name: string;
195
- readonly description: string;
196
- readonly match: RegExp;
197
- readonly handler: PolicyHandler<C>;
198
- readonly defaultConfig?: C | undefined;
199
- readonly resolver?: PolicyStandaloneResolver<C> | undefined;
200
- constructor(definition: PolicyShape<C>);
44
+ /** Repository scope is explicit; repository fixers are inline only. @public */
45
+ export interface RepositoryPolicyDefinition<C = void> {
46
+ name: PolicyName;
47
+ description: string;
48
+ scope: "repository";
49
+ handler(args: RepositoryPolicyArgs<C>): Promise<PolicyResult> | Operation<PolicyResult>;
50
+ resolver?: never;
51
+ defaultConfig?: C | undefined;
52
+ requiresConfig?: boolean | undefined;
201
53
  }
202
- /**
203
- * @deprecated Use {@link PolicyShape} instead.
204
- * @alpha
205
- */
206
- export type PolicyDefinition<C = undefined> = PolicyShape<C>;
207
- /**
208
- * A policy instance with configuration and exclusion settings applied.
209
- *
210
- * @typeParam C - Type of configuration object used by the policy
211
- *
212
- * @alpha
213
- */
214
- export interface ConfiguredPolicy<C = void> extends PolicyShape<C> {
215
- /**
216
- * An optional stable identifier for this configured policy instance.
217
- *
218
- * This is required when the same policy definition is configured more than once.
219
- */
220
- instanceId?: PolicyInstanceId | undefined;
221
- /**
222
- * The configuration applied to this policy instance.
223
- */
54
+ /** A canonical policy definition. @public */
55
+ export type PolicyDefinition<C = void> = FilePolicyDefinition<C> | RepositoryPolicyDefinition<C>;
56
+ /** Async and Effection file handlers are supported. @public */
57
+ export type PolicyHandler<C = void> = FilePolicyDefinition<C>["handler"];
58
+ /** Async and Effection repository handlers are supported. @public */
59
+ export type RepositoryPolicyHandler<C = void> = RepositoryPolicyDefinition<C>["handler"];
60
+ /** Exclude undefined (including void) while preserving allowed null values. @internal */
61
+ export type DefinedConfig<C> = NonNullable<C> | (C & null);
62
+ /** Instance configuration and repo-relative regex exclusions. @public */
63
+ export interface PolicyOptions<C = void> {
224
64
  config?: C | undefined;
225
- /**
226
- * File paths matching these patterns will be excluded from this policy.
227
- * @deprecated Use `excludeFiles` instead for backward compatibility.
228
- */
229
- exclude?: (string | RegExp)[] | undefined;
230
- /**
231
- * File paths matching these patterns will be excluded from this policy.
232
- */
233
- excludeFiles?: (string | RegExp)[] | undefined;
234
- /**
235
- * Internal normalized handler (always an Effection Operation).
236
- * This is set by the policy() function and used by the execution engine.
237
- * @internal
238
- */
239
- _internalHandler?: (args: PolicyArgs<C>) => Operation<PolicyHandlerResult>;
240
- }
241
- /**
242
- * Settings for configuring a policy instance.
243
- * @alpha
244
- */
245
- export interface PolicyInstanceSettings<C> {
246
- /**
247
- * A stable identifier for this configured policy instance.
248
- */
65
+ exclude?: readonly (string | RegExp)[] | undefined;
249
66
  instanceId?: PolicyInstanceId | undefined;
250
- /**
251
- * An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded
252
- * from policy.
253
- *
254
- * Paths will be matched relative to the root of the repo.
255
- */
256
- excludeFiles?: (string | RegExp)[];
257
- /**
258
- * The config that is applied to the policy instance.
259
- */
260
- config?: C | undefined;
261
67
  }
262
- /**
263
- * @deprecated Use {@link ConfiguredPolicy} instead.
264
- * @alpha
265
- */
266
- export type PolicyInstance<C = undefined> = ConfiguredPolicy<C>;
267
- /**
268
- * A configured policy instance with its runtime identity assigned.
269
- *
270
- * @alpha
271
- */
272
- export type IdentifiedPolicy<C = undefined> = ConfiguredPolicy<C> & {
68
+ /** A configured file policy. @public */
69
+ export type ConfiguredFilePolicy<C = void> = FilePolicyDefinition<C> & PolicyOptions<C>;
70
+ /** A configured repository policy. @public */
71
+ export type ConfiguredRepositoryPolicy<C = void> = RepositoryPolicyDefinition<C> & PolicyOptions<C>;
72
+ /** A configured policy, retaining scope discrimination. @public */
73
+ export type ConfiguredPolicy<C = unknown> = ConfiguredFilePolicy<C> | ConfiguredRepositoryPolicy<C>;
74
+ /** A configured policy with a validated stable identity. @public */
75
+ export type IdentifiedPolicy<C = unknown> = ConfiguredPolicy<C> & {
273
76
  instanceId: PolicyInstanceId;
274
77
  };
275
- /**
276
- * Type guard to check if a result is a {@link PolicyFixResult} (legacy).
277
- *
278
- * @deprecated Use {@link isPolicyError} instead when working with the new {@link PolicyError} format.
279
- *
280
- * @alpha
281
- */
282
- export declare function isPolicyFixResult(toCheck: any): toCheck is PolicyFixResult;
283
- /**
284
- * Type guard to check if a result is a PolicyError (new format).
285
- *
286
- * @alpha
287
- */
288
- export declare function isPolicyError(toCheck: any): toCheck is PolicyError;
289
- /**
290
- * Type guard to check if a result is a {@link PolicyFailure} (legacy format).
291
- *
292
- * @deprecated Use {@link isPolicyError} instead when working with the new {@link PolicyError} format.
293
- *
294
- * @alpha
295
- */
296
- export declare function isPolicyFailure(toCheck: any): toCheck is PolicyFailure;
297
- /**
298
- * Converts a legacy PolicyFailure/PolicyFixResult to the new PolicyError format.
299
- * @internal
300
- */
301
- export declare function convertLegacyResult(result: PolicyHandlerResult, _file: string): PolicyResult;
302
- /**
303
- * Converts a new PolicyError to the legacy PolicyFailure format.
304
- * @internal
305
- */
306
- export declare function convertToLegacyResult(result: PolicyError, policyName: string, file: string): PolicyFailure | PolicyFixResult;
307
- /**
308
- * Default policies included with repopo.
309
- *
310
- * @alpha
311
- */
312
- export declare const DefaultPolicies: Policy<any>[];
78
+ /** The default definitions, configured when no policies are supplied. @public */
79
+ export declare const DefaultPolicies: readonly [{
80
+ name: string;
81
+ description: string;
82
+ match: RegExp;
83
+ handler: () => Operation<PolicyFinding[]>;
84
+ }, FilePolicyDefinition<void>, FilePolicyDefinition<void>];
313
85
  //# sourceMappingURL=policy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAK3C;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC;;;;GAIG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,IAAI;IACnC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAMvD;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE9B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE5B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC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AiF;AACjF,eAAO,MAAM,eAAe;;;;;0DAIlB,CAAC"}
package/esm/policy.js CHANGED
@@ -1,128 +1,7 @@
1
1
  import { NoJsFileExtensions } from "./policies/NoJsFileExtensions.js";
2
2
  import { PackageJsonRepoDirectoryProperty } from "./policies/PackageJsonRepoDirectoryProperty.js";
3
3
  import { PackageJsonSorted } from "./policies/PackageJsonSorted.js";
4
- /**
5
- * Abstract base class for creating policies with object-based construction.
6
- *
7
- * @remarks
8
- * This class accepts a {@link PolicyShape} object in its constructor,
9
- * making it easier to add new optional properties in the future without breaking changes.
10
- *
11
- * @alpha
12
- */
13
- export class Policy {
14
- name;
15
- description;
16
- match;
17
- handler;
18
- defaultConfig;
19
- resolver;
20
- constructor(definition) {
21
- this.name = definition.name;
22
- this.description = definition.description;
23
- this.match = definition.match;
24
- this.handler = definition.handler;
25
- this.defaultConfig = definition.defaultConfig;
26
- this.resolver = definition.resolver;
27
- }
28
- }
29
- // ============================================================================
30
- // Type Guards
31
- // ============================================================================
32
- /**
33
- * Type guard to check if a result is a {@link PolicyFixResult} (legacy).
34
- *
35
- * @deprecated Use {@link isPolicyError} instead when working with the new {@link PolicyError} format.
36
- *
37
- * @alpha
38
- */
39
- // biome-ignore lint/suspicious/noExplicitAny: type guard
40
- export function isPolicyFixResult(toCheck) {
41
- if (typeof toCheck !== "object" || toCheck === null) {
42
- return false;
43
- }
44
- return "resolved" in toCheck;
45
- }
46
- /**
47
- * Type guard to check if a result is a PolicyError (new format).
48
- *
49
- * @alpha
50
- */
51
- // biome-ignore lint/suspicious/noExplicitAny: type guard
52
- export function isPolicyError(toCheck) {
53
- if (typeof toCheck !== "object" || toCheck === null) {
54
- return false;
55
- }
56
- return "error" in toCheck && typeof toCheck.error === "string";
57
- }
58
- /**
59
- * Type guard to check if a result is a {@link PolicyFailure} (legacy format).
60
- *
61
- * @deprecated Use {@link isPolicyError} instead when working with the new {@link PolicyError} format.
62
- *
63
- * @alpha
64
- */
65
- // biome-ignore lint/suspicious/noExplicitAny: type guard
66
- export function isPolicyFailure(toCheck) {
67
- if (typeof toCheck !== "object" || toCheck === null) {
68
- return false;
69
- }
70
- return "errorMessages" in toCheck && Array.isArray(toCheck.errorMessages);
71
- }
72
- // ============================================================================
73
- // Conversion Functions
74
- // ============================================================================
75
- /**
76
- * Converts a legacy PolicyFailure/PolicyFixResult to the new PolicyError format.
77
- * @internal
78
- */
79
- export function convertLegacyResult(result, _file) {
80
- if (result === true) {
81
- return true;
82
- }
83
- // Check if it's already the new format
84
- if (isPolicyError(result)) {
85
- return result;
86
- }
87
- // It's a legacy PolicyFailure or PolicyFixResult
88
- const error = result.errorMessages?.join("; ") ?? "Policy violation";
89
- const isFixResult = isPolicyFixResult(result);
90
- return {
91
- error,
92
- fixable: result.autoFixable ?? false,
93
- fixed: isFixResult ? result.resolved : undefined,
94
- manualFix: result.manualFix,
95
- };
96
- }
97
- /**
98
- * Converts a new PolicyError to the legacy PolicyFailure format.
99
- * @internal
100
- */
101
- export function convertToLegacyResult(result, policyName, file) {
102
- const base = {
103
- name: policyName,
104
- file,
105
- autoFixable: result.fixable,
106
- errorMessages: [result.error],
107
- manualFix: result.manualFix,
108
- };
109
- if (result.fixed !== undefined) {
110
- return {
111
- ...base,
112
- resolved: result.fixed,
113
- };
114
- }
115
- return base;
116
- }
117
- // ============================================================================
118
- // Default Policies
119
- // ============================================================================
120
- /**
121
- * Default policies included with repopo.
122
- *
123
- * @alpha
124
- */
125
- // biome-ignore lint/suspicious/noExplicitAny: FIXME
4
+ /** The default definitions, configured when no policies are supplied. @public */
126
5
  export const DefaultPolicies = [
127
6
  NoJsFileExtensions,
128
7
  PackageJsonRepoDirectoryProperty,
package/esm/policy.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,C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CAAC;IAC7B,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;GAIG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,eAAe,GAAkB;IAC7C,kBAAkB;IAClB,gCAAgC;IAChC,iBAAiB;CACR,CAAC","sourcesContent":["import type { Operation } from \"effection\";\nimport { NoJsFileExtensions } from \"./policies/NoJsFileExtensions.js\";\nimport { PackageJsonRepoDirectoryProperty } from \"./policies/PackageJsonRepoDirectoryProperty.js\";\nimport { PackageJsonSorted } from \"./policies/PackageJsonSorted.js\";\n\n/**\n * A type representing a policy name.\n *\n * @alpha\n */\nexport type PolicyName = string;\n\n/**\n * A stable identifier for a configured policy instance.\n *\n * @alpha\n */\nexport type PolicyInstanceId = string;\n\n/**\n * Arguments passed to policy handler functions.\n *\n * @alpha\n */\nexport interface PolicyArgs<C = void> {\n\t/**\n\t * Path to the file, relative to the repo root.\n\t */\n\tfile: string;\n\n\t/**\n\t * Absolute path to the root of the repo.\n\t */\n\troot: string;\n\n\t/**\n\t * If true, the handler should resolve any violations automatically if possible.\n\t */\n\tresolve: boolean;\n\n\t/**\n\t * Optional configuration for the policy.\n\t */\n\tconfig?: C | undefined;\n}\n\n/**\n * @deprecated Use {@link PolicyArgs} instead.\n * @alpha\n */\nexport type PolicyFunctionArguments<C> = PolicyArgs<C>;\n\n// ============================================================================\n// New Result Types\n// ============================================================================\n\n/**\n * A policy error returned when a file fails a policy check.\n *\n * @alpha\n */\nexport interface PolicyError {\n\t/**\n\t * The error message describing what failed.\n\t */\n\terror: string;\n\n\t/**\n\t * Set to `true` if the policy violation can be fixed automatically.\n\t */\n\tfixable?: boolean | undefined;\n\n\t/**\n\t * Set to `true` if the violation was successfully fixed (only set when resolve=true).\n\t */\n\tfixed?: boolean | undefined;\n\n\t/**\n\t * An optional string that tells the user how to manually fix the failure.\n\t */\n\tmanualFix?: string | undefined;\n}\n\n/**\n * The result of a policy handler.\n * Returns `true` if the file passes the policy, or a {@link PolicyError} if it fails.\n *\n * @alpha\n */\nexport type PolicyResult = true | PolicyError;\n\n// ============================================================================\n// Legacy Result Types (Still supported for backward compatibility)\n// ============================================================================\n\n/**\n * A policy failure (legacy format).\n *\n * @deprecated Use {@link PolicyError} instead, which has a simpler API.\n *\n * @alpha\n */\nexport interface PolicyFailure {\n\t/**\n\t * Name of the policy that failed.\n\t */\n\tname: PolicyName;\n\n\t/**\n\t * Path to the file that failed the policy.\n\t */\n\tfile: string;\n\n\t/**\n\t * Set to `true` if the policy can be fixed automatically.\n\t */\n\tautoFixable?: boolean | undefined;\n\n\t/**\n\t * An optional error message accompanying the failure.\n\t */\n\terrorMessages: string[];\n\n\t/**\n\t * An optional string that tells the user how to fix the failure(s).\n\t */\n\tmanualFix?: string | undefined;\n}\n\n/**\n * The result of an automatic fix for a failing policy (legacy format).\n *\n * @deprecated Use {@link PolicyError} with `fixed: boolean` instead.\n *\n * @alpha\n */\nexport interface PolicyFixResult extends PolicyFailure {\n\t/**\n\t * Set to true if the failure was resolved by the automated fixer.\n\t */\n\tresolved: boolean;\n}\n\n/**\n * Result type that accepts both legacy and new formats.\n *\n * @alpha\n */\nexport type PolicyHandlerResult =\n\t| true\n\t| PolicyFailure\n\t| PolicyFixResult\n\t| PolicyError;\n\n// ============================================================================\n// Handler Types\n// ============================================================================\n\n/**\n * A policy handler function that checks a file against a policy.\n *\n * @remarks\n * Policy handlers can be implemented in two ways:\n * - As an async function returning a Promise\n * - As an Effection generator function returning an Operation\n *\n * Both styles are supported. Async handlers are automatically wrapped for Effection.\n *\n * Handlers can return either the legacy format ({@link PolicyFailure}) or\n * the new format ({@link PolicyError}). The new format is simpler and recommended\n * for new policies.\n *\n * @alpha\n */\nexport type PolicyHandler<C = unknown | undefined> =\n\t| ((args: PolicyArgs<C>) => Promise<PolicyHandlerResult>)\n\t| ((args: PolicyArgs<C>) => Operation<PolicyHandlerResult>);\n\n/**\n * A standalone resolver function that can fix policy violations (legacy format).\n *\n * @deprecated Use {@link PolicyResolver} instead, which uses {@link PolicyError}.\n *\n * @alpha\n */\nexport type PolicyStandaloneResolver<C = undefined> = (\n\targs: Omit<PolicyArgs<C>, \"resolve\">,\n) => Promise<PolicyFixResult> | Operation<PolicyFixResult>;\n\n/**\n * A standalone resolver function using the new format.\n *\n * @alpha\n */\nexport type PolicyResolver<C = void> = (\n\targs: Omit<PolicyArgs<C>, \"resolve\">,\n) => Promise<PolicyError> | Operation<PolicyError>;\n\n// ============================================================================\n// Policy Definition Types\n// ============================================================================\n\n/**\n * Interface describing the shape of a policy definition.\n *\n * @typeParam C - Type of configuration object used by the policy\n *\n * @alpha\n */\nexport interface PolicyShape<C = void> {\n\t/**\n\t * The name of the policy; displayed in UI and used in settings.\n\t */\n\tname: PolicyName;\n\n\t/**\n\t * A detailed description of the policy and its purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * A regular expression that matches files this policy applies to.\n\t */\n\tmatch: RegExp;\n\n\t/**\n\t * The handler function that checks if a file complies with the policy.\n\t */\n\thandler: PolicyHandler<C>;\n\n\t/**\n\t * An optional resolver function that can automatically fix violations.\n\t */\n\tresolver?: PolicyStandaloneResolver<C> | undefined;\n\n\t/**\n\t * A default configuration that will be used if none is provided.\n\t */\n\tdefaultConfig?: C | undefined;\n}\n\n/**\n * Abstract base class for creating policies with object-based construction.\n *\n * @remarks\n * This class accepts a {@link PolicyShape} object in its constructor,\n * making it easier to add new optional properties in the future without breaking changes.\n *\n * @alpha\n */\nexport abstract class Policy<C = void> implements PolicyShape<C> {\n\tpublic readonly name: string;\n\tpublic readonly description: string;\n\tpublic readonly match: RegExp;\n\tpublic readonly handler: PolicyHandler<C>;\n\tpublic readonly defaultConfig?: C | undefined;\n\tpublic readonly resolver?: PolicyStandaloneResolver<C> | undefined;\n\n\tpublic constructor(definition: PolicyShape<C>) {\n\t\tthis.name = definition.name;\n\t\tthis.description = definition.description;\n\t\tthis.match = definition.match;\n\t\tthis.handler = definition.handler;\n\t\tthis.defaultConfig = definition.defaultConfig;\n\t\tthis.resolver = definition.resolver;\n\t}\n}\n\n/**\n * @deprecated Use {@link PolicyShape} instead.\n * @alpha\n */\nexport type PolicyDefinition<C = undefined> = PolicyShape<C>;\n\n/**\n * A policy instance with configuration and exclusion settings applied.\n *\n * @typeParam C - Type of configuration object used by the policy\n *\n * @alpha\n */\nexport interface ConfiguredPolicy<C = void> extends PolicyShape<C> {\n\t/**\n\t * An optional stable identifier for this configured policy instance.\n\t *\n\t * This is required when the same policy definition is configured more than once.\n\t */\n\tinstanceId?: PolicyInstanceId | undefined;\n\n\t/**\n\t * The configuration applied to this policy instance.\n\t */\n\tconfig?: C | undefined;\n\n\t/**\n\t * File paths matching these patterns will be excluded from this policy.\n\t * @deprecated Use `excludeFiles` instead for backward compatibility.\n\t */\n\texclude?: (string | RegExp)[] | undefined;\n\n\t/**\n\t * File paths matching these patterns will be excluded from this policy.\n\t */\n\texcludeFiles?: (string | RegExp)[] | undefined;\n\n\t/**\n\t * Internal normalized handler (always an Effection Operation).\n\t * This is set by the policy() function and used by the execution engine.\n\t * @internal\n\t */\n\t_internalHandler?: (args: PolicyArgs<C>) => Operation<PolicyHandlerResult>;\n}\n\n/**\n * Settings for configuring a policy instance.\n * @alpha\n */\nexport interface PolicyInstanceSettings<C> {\n\t/**\n\t * A stable identifier for this configured policy instance.\n\t */\n\tinstanceId?: PolicyInstanceId | undefined;\n\n\t/**\n\t * An array of strings/regular expressions. File paths that match any of these expressions will be completely excluded\n\t * from policy.\n\t *\n\t * Paths will be matched relative to the root of the repo.\n\t */\n\texcludeFiles?: (string | RegExp)[];\n\n\t/**\n\t * The config that is applied to the policy instance.\n\t */\n\tconfig?: C | undefined;\n}\n\n/**\n * @deprecated Use {@link ConfiguredPolicy} instead.\n * @alpha\n */\nexport type PolicyInstance<C = undefined> = ConfiguredPolicy<C>;\n\n/**\n * A configured policy instance with its runtime identity assigned.\n *\n * @alpha\n */\nexport type IdentifiedPolicy<C = undefined> = ConfiguredPolicy<C> & {\n\tinstanceId: PolicyInstanceId;\n};\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\n/**\n * Type guard to check if a result is a {@link PolicyFixResult} (legacy).\n *\n * @deprecated Use {@link isPolicyError} instead when working with the new {@link PolicyError} format.\n *\n * @alpha\n */\n// biome-ignore lint/suspicious/noExplicitAny: type guard\nexport function isPolicyFixResult(toCheck: any): toCheck is PolicyFixResult {\n\tif (typeof toCheck !== \"object\" || toCheck === null) {\n\t\treturn false;\n\t}\n\treturn \"resolved\" in toCheck;\n}\n\n/**\n * Type guard to check if a result is a PolicyError (new format).\n *\n * @alpha\n */\n// biome-ignore lint/suspicious/noExplicitAny: type guard\nexport function isPolicyError(toCheck: any): toCheck is PolicyError {\n\tif (typeof toCheck !== \"object\" || toCheck === null) {\n\t\treturn false;\n\t}\n\treturn \"error\" in toCheck && typeof toCheck.error === \"string\";\n}\n\n/**\n * Type guard to check if a result is a {@link PolicyFailure} (legacy format).\n *\n * @deprecated Use {@link isPolicyError} instead when working with the new {@link PolicyError} format.\n *\n * @alpha\n */\n// biome-ignore lint/suspicious/noExplicitAny: type guard\nexport function isPolicyFailure(toCheck: any): toCheck is PolicyFailure {\n\tif (typeof toCheck !== \"object\" || toCheck === null) {\n\t\treturn false;\n\t}\n\treturn \"errorMessages\" in toCheck && Array.isArray(toCheck.errorMessages);\n}\n\n// ============================================================================\n// Conversion Functions\n// ============================================================================\n\n/**\n * Converts a legacy PolicyFailure/PolicyFixResult to the new PolicyError format.\n * @internal\n */\nexport function convertLegacyResult(\n\tresult: PolicyHandlerResult,\n\t_file: string,\n): PolicyResult {\n\tif (result === true) {\n\t\treturn true;\n\t}\n\n\t// Check if it's already the new format\n\tif (isPolicyError(result)) {\n\t\treturn result;\n\t}\n\n\t// It's a legacy PolicyFailure or PolicyFixResult\n\tconst error = result.errorMessages?.join(\"; \") ?? \"Policy violation\";\n\tconst isFixResult = isPolicyFixResult(result);\n\n\treturn {\n\t\terror,\n\t\tfixable: result.autoFixable ?? false,\n\t\tfixed: isFixResult ? result.resolved : undefined,\n\t\tmanualFix: result.manualFix,\n\t};\n}\n\n/**\n * Converts a new PolicyError to the legacy PolicyFailure format.\n * @internal\n */\nexport function convertToLegacyResult(\n\tresult: PolicyError,\n\tpolicyName: string,\n\tfile: string,\n): PolicyFailure | PolicyFixResult {\n\tconst base: PolicyFailure = {\n\t\tname: policyName,\n\t\tfile,\n\t\tautoFixable: result.fixable,\n\t\terrorMessages: [result.error],\n\t\tmanualFix: result.manualFix,\n\t};\n\n\tif (result.fixed !== undefined) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tresolved: result.fixed,\n\t\t} satisfies PolicyFixResult;\n\t}\n\n\treturn base;\n}\n\n// ============================================================================\n// Default Policies\n// ============================================================================\n\n/**\n * Default policies included with repopo.\n *\n * @alpha\n */\n// biome-ignore lint/suspicious/noExplicitAny: FIXME\nexport const DefaultPolicies: Policy<any>[] = [\n\tNoJsFileExtensions,\n\tPackageJsonRepoDirectoryProperty,\n\tPackageJsonSorted,\n] as const;\n"]}
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAqGpE,iFAAiF;AACjF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,kBAAkB;IAClB,gCAAgC;IAChC,iBAAiB;CACR,CAAC","sourcesContent":["import type { Operation } from \"effection\";\nimport { NoJsFileExtensions } from \"./policies/NoJsFileExtensions.js\";\nimport { PackageJsonRepoDirectoryProperty } from \"./policies/PackageJsonRepoDirectoryProperty.js\";\nimport { PackageJsonSorted } from \"./policies/PackageJsonSorted.js\";\n\n/** Display name of a policy. @public */\nexport type PolicyName = string;\n/** Stable configured-instance identity. @public */\nexport type PolicyInstanceId = string;\n\n/** Arguments supplied to a file handler. @public */\nexport interface PolicyArgs<C = void> {\n\tfile: string;\n\troot: string;\n\tresolve: boolean;\n\tconfig?: C | undefined;\n}\n\n/** Arguments supplied to a repository handler; selection never limits files. @public */\nexport interface RepositoryPolicyArgs<C = void>\n\textends Omit<PolicyArgs<C>, \"file\"> {\n\tfiles: readonly string[];\n}\n\n/** A single independently actionable violation or recorded fix. @public */\nexport interface PolicyFinding {\n\tmessage: string;\n\tmanualFix?: string | undefined;\n\tfixStatus?: \"available\" | \"fixed\" | \"failed\" | undefined;\n\t/** Repo-relative affected files. Only repository handlers may supply this. */\n\tfiles?: readonly string[] | undefined;\n}\n\n/** Empty means pass. Fixed findings remain visible. @public */\nexport type PolicyResult = readonly PolicyFinding[];\n\n/** Standalone file fixers receive and return the complete findings list. @public */\nexport type PolicyResolver<C = void> = {\n\tresolve(\n\t\targs: Omit<PolicyArgs<C>, \"resolve\"> & { findings: PolicyResult },\n\t): Promise<PolicyResult> | Operation<PolicyResult>;\n}[\"resolve\"];\n\n/** File scope is the default. @public */\nexport interface FilePolicyDefinition<C = void> {\n\tname: PolicyName;\n\tdescription: string;\n\tscope?: \"file\";\n\tmatch: RegExp;\n\thandler(args: PolicyArgs<C>): Promise<PolicyResult> | Operation<PolicyResult>;\n\tresolver?: PolicyResolver<C> | undefined;\n\tdefaultConfig?: C | undefined;\n\trequiresConfig?: boolean | undefined;\n}\n\n/** Repository scope is explicit; repository fixers are inline only. @public */\nexport interface RepositoryPolicyDefinition<C = void> {\n\tname: PolicyName;\n\tdescription: string;\n\tscope: \"repository\";\n\thandler(\n\t\targs: RepositoryPolicyArgs<C>,\n\t): Promise<PolicyResult> | Operation<PolicyResult>;\n\tresolver?: never;\n\tdefaultConfig?: C | undefined;\n\trequiresConfig?: boolean | undefined;\n}\n\n/** A canonical policy definition. @public */\nexport type PolicyDefinition<C = void> =\n\t| FilePolicyDefinition<C>\n\t| RepositoryPolicyDefinition<C>;\n\n/** Async and Effection file handlers are supported. @public */\nexport type PolicyHandler<C = void> = FilePolicyDefinition<C>[\"handler\"];\n/** Async and Effection repository handlers are supported. @public */\nexport type RepositoryPolicyHandler<C = void> =\n\tRepositoryPolicyDefinition<C>[\"handler\"];\n\n/** Exclude undefined (including void) while preserving allowed null values. @internal */\nexport type DefinedConfig<C> = NonNullable<C> | (C & null);\n\n/** Instance configuration and repo-relative regex exclusions. @public */\nexport interface PolicyOptions<C = void> {\n\tconfig?: C | undefined;\n\texclude?: readonly (string | RegExp)[] | undefined;\n\tinstanceId?: PolicyInstanceId | undefined;\n}\n\n/** A configured file policy. @public */\nexport type ConfiguredFilePolicy<C = void> = FilePolicyDefinition<C> &\n\tPolicyOptions<C>;\n/** A configured repository policy. @public */\nexport type ConfiguredRepositoryPolicy<C = void> =\n\tRepositoryPolicyDefinition<C> & PolicyOptions<C>;\n/** A configured policy, retaining scope discrimination. @public */\nexport type ConfiguredPolicy<C = unknown> =\n\t| ConfiguredFilePolicy<C>\n\t| ConfiguredRepositoryPolicy<C>;\n/** A configured policy with a validated stable identity. @public */\nexport type IdentifiedPolicy<C = unknown> = ConfiguredPolicy<C> & {\n\tinstanceId: PolicyInstanceId;\n};\n\n/** The default definitions, configured when no policies are supplied. @public */\nexport const DefaultPolicies = [\n\tNoJsFileExtensions,\n\tPackageJsonRepoDirectoryProperty,\n\tPackageJsonSorted,\n] as const;\n"]}
@@ -1,9 +1,9 @@
1
1
  import { type Operation } from "effection";
2
- import type { PolicyArgs, PolicyHandlerResult, PolicyShape } from "../policy.js";
2
+ import type { DefinedConfig, FilePolicyDefinition, PolicyArgs, PolicyResult } from "../policy.js";
3
3
  /**
4
4
  * A parsed Cargo.toml represented as a record of sections and values.
5
5
  *
6
- * @alpha
6
+ * @public
7
7
  */
8
8
  export type CargoToml = Record<string, unknown>;
9
9
  /**
@@ -12,13 +12,13 @@ export type CargoToml = Record<string, unknown>;
12
12
  * @remarks
13
13
  * Receives the parsed TOML content and the standard policy arguments.
14
14
  *
15
- * @alpha
15
+ * @public
16
16
  */
17
- export type CargoTomlHandler<C> = (toml: CargoToml, args: PolicyArgs<C>) => Operation<PolicyHandlerResult> | Promise<PolicyHandlerResult>;
17
+ export type CargoTomlHandler<C> = (toml: CargoToml, args: PolicyArgs<C>) => Operation<PolicyResult> | Promise<PolicyResult>;
18
18
  /**
19
19
  * Input arguments for defining a Cargo.toml policy.
20
20
  *
21
- * @alpha
21
+ * @public
22
22
  */
23
23
  export interface DefineCargoPolicyArgs<C> {
24
24
  /**
@@ -37,6 +37,7 @@ export interface DefineCargoPolicyArgs<C> {
37
37
  * Optional default configuration for the policy.
38
38
  */
39
39
  defaultConfig?: C;
40
+ requiresConfig?: boolean;
40
41
  }
41
42
  /**
42
43
  * Define a repo policy for Cargo.toml files.
@@ -45,6 +46,9 @@ export interface DefineCargoPolicyArgs<C> {
45
46
  * This is a helper function that creates a policy pre-configured to match
46
47
  * Cargo.toml files. The handler receives the parsed TOML content.
47
48
  *
49
+ * @param args - Policy metadata, parsed-TOML handler, and optional defaults.
50
+ * @returns A file policy that reads and parses matching Cargo.toml files.
51
+ *
48
52
  * @example
49
53
  * ```typescript
50
54
  * const MyCargoPolicy = defineCargoPolicy({
@@ -53,14 +57,26 @@ export interface DefineCargoPolicyArgs<C> {
53
57
  * handler: async (toml, { file }) => {
54
58
  * const pkg = toml.package as Record<string, unknown> | undefined;
55
59
  * if (!pkg?.name) {
56
- * return { error: "Missing package name", fixable: false };
60
+ * return [{ message: "Missing package name" }];
57
61
  * }
58
- * return true;
62
+ * return [];
59
63
  * },
60
64
  * });
61
65
  * ```
62
66
  *
63
- * @alpha
67
+ * @public
64
68
  */
65
- export declare function defineCargoPolicy<C = undefined>(args: DefineCargoPolicyArgs<C>): PolicyShape<C>;
69
+ export declare function defineCargoPolicy<C = void>(args: DefineCargoPolicyArgs<C> & {
70
+ defaultConfig: DefinedConfig<C>;
71
+ }): FilePolicyDefinition<C> & {
72
+ defaultConfig: DefinedConfig<C>;
73
+ };
74
+ /** Define a Cargo policy that requires explicit configuration. @public */
75
+ export declare function defineCargoPolicy<C = void>(args: DefineCargoPolicyArgs<C> & {
76
+ requiresConfig: true;
77
+ }): FilePolicyDefinition<C> & {
78
+ requiresConfig: true;
79
+ };
80
+ /** Define a Cargo policy with optional configuration. @public */
81
+ export declare function defineCargoPolicy<C = void>(args: DefineCargoPolicyArgs<C>): FilePolicyDefinition<C>;
66
82
  //# sourceMappingURL=defineCargoPolicy.d.ts.map