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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filePaths.js","sourceRoot":"","sources":["../src/filePaths.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAChC,MAAM,UAAU,GAAG,OAAO,CAAC;AAE3B,MAAM,UAAU,cAAc,CAAC,KAAa;IAC3C,OAAO,KAAK;SACV,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC;SAC/B,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;SAC/C,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["const WINDOWS_SEPARATOR = /\\\\/g;\nconst LINE_BREAK = /\\r?\\n/;\n\nexport function parseFilePaths(input: string): string[] {\n\treturn input\n\t\t.replace(WINDOWS_SEPARATOR, \"/\")\n\t\t.split(input.includes(\"\\0\") ? \"\\0\" : LINE_BREAK)\n\t\t.filter((filePath) => filePath.length > 0);\n}\n"]}
@@ -1,23 +1,3 @@
1
- import type { PolicyDefinition } from "./policy.js";
2
- /**
3
- * The definition of a free function that returns a RepoPolicy.
4
- *
5
- * @alpha
6
- */
7
- export type PolicyCreatorFunction<C = undefined> = (args: PolicyDefinition<C>) => PolicyDefinition<C>;
8
- /**
9
- * The definition of a constructor function that returns a RepoPolicy.
10
- *
11
- * @alpha
12
- */
13
- export type PolicyCreatorConstructor<C = undefined> = new (args: PolicyDefinition<C>) => PolicyDefinition<C>;
14
- /**
15
- * A PolicyCreator is a function that can be used to generate a {@link PolicyDefinition}. The function can be a free
16
- * function or a constructor that creates a class implementing the {@link PolicyDefinition} interface.
17
- *
18
- * @alpha
19
- */
20
- export type PolicyCreator = PolicyCreatorConstructor | PolicyCreatorFunction;
21
1
  /**
22
2
  * Checks if a given function is a generator function.
23
3
  *
@@ -1 +1 @@
1
- {"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,SAAS,IAAI,CAClD,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,KACrB,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAEzB;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,GAAG,SAAS,IAAI,KACrD,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,KACrB,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,wBAAwB,GAAG,qBAAqB,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,GAAG,EAAE,IAAI,iBAAiB,CAEzE"}
1
+ {"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,GAAG,EAAE,IAAI,iBAAiB,CAEzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"generators.js","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AA4BA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,oEAAoE;AACpE,MAAM,UAAU,mBAAmB,CAAC,EAAY;IAC/C,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,KAAK,mBAAmB,CAAC;AACpD,CAAC","sourcesContent":["import type { PolicyDefinition } from \"./policy.js\";\n\n/**\n * The definition of a free function that returns a RepoPolicy.\n *\n * @alpha\n */\nexport type PolicyCreatorFunction<C = undefined> = (\n\targs: PolicyDefinition<C>,\n) => PolicyDefinition<C>;\n\n/**\n * The definition of a constructor function that returns a RepoPolicy.\n *\n * @alpha\n */\nexport type PolicyCreatorConstructor<C = undefined> = new (\n\targs: PolicyDefinition<C>,\n) => PolicyDefinition<C>;\n\n/**\n * A PolicyCreator is a function that can be used to generate a {@link PolicyDefinition}. The function can be a free\n * function or a constructor that creates a class implementing the {@link PolicyDefinition} interface.\n *\n * @alpha\n */\nexport type PolicyCreator = PolicyCreatorConstructor | PolicyCreatorFunction;\n\n/**\n * Checks if a given function is a generator function.\n *\n * A generator function is a function that can be paused and resumed, and can yield\n * multiple values over time. This utility function helps identify such functions\n * by checking their constructor name.\n *\n * @param fn - The function to check\n * @returns `true` if the function is a generator function, `false` otherwise\n *\n * @example\n * ```typescript\n * function* myGenerator() {\n * yield 1;\n * yield 2;\n * }\n *\n * function regularFunction() {\n * return 1;\n * }\n *\n * console.log(isGeneratorFunction(myGenerator)); // true\n * console.log(isGeneratorFunction(regularFunction)); // false\n * ```\n *\n * @alpha\n */\n// biome-ignore lint/complexity/noBannedTypes: broad type is OK here\nexport function isGeneratorFunction(fn: Function): fn is GeneratorFunction {\n\treturn fn.constructor.name === \"GeneratorFunction\";\n}\n"]}
1
+ {"version":3,"file":"generators.js","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,oEAAoE;AACpE,MAAM,UAAU,mBAAmB,CAAC,EAAY;IAC/C,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,KAAK,mBAAmB,CAAC;AACpD,CAAC","sourcesContent":["/**\n * Checks if a given function is a generator function.\n *\n * A generator function is a function that can be paused and resumed, and can yield\n * multiple values over time. This utility function helps identify such functions\n * by checking their constructor name.\n *\n * @param fn - The function to check\n * @returns `true` if the function is a generator function, `false` otherwise\n *\n * @example\n * ```typescript\n * function* myGenerator() {\n * yield 1;\n * yield 2;\n * }\n *\n * function regularFunction() {\n * return 1;\n * }\n *\n * console.log(isGeneratorFunction(myGenerator)); // true\n * console.log(isGeneratorFunction(regularFunction)); // false\n * ```\n *\n * @alpha\n */\n// biome-ignore lint/complexity/noBannedTypes: broad type is OK here\nexport function isGeneratorFunction(fn: Function): fn is GeneratorFunction {\n\treturn fn.constructor.name === \"GeneratorFunction\";\n}\n"]}
package/esm/index.d.ts CHANGED
@@ -1,23 +1,10 @@
1
1
  /**
2
- * A tool for enforcing repository policies and standards across codebases.
2
+ * Repository policy authoring, execution, and CLI entry point.
3
3
  *
4
- * @remarks
5
- * Repopo provides a framework for defining and enforcing policies across repositories,
6
- * such as file headers, package.json consistency, and other code standards.
7
- * It can be used as a CLI tool or integrated into CI/CD pipelines.
4
+ * Import `repopo/api` for the programmatic API without the CLI entry point.
8
5
  *
9
6
  * @packageDocumentation
10
7
  */
11
8
  export { run } from "@oclif/core";
12
- export { type FluidAdapterOptions, type FluidHandler, fromFluidHandlers, } from "./adapters/fluidFramework.js";
13
- export type { RepopoConfig, } from "./config.js";
14
- export type { ExcludedPolicyFileMap } from "./context.js";
15
- export { makePolicy, makePolicyDefinition, type PolicyDefinitionInput, type PolicyOptions, policy, } from "./makePolicy.js";
16
- export type { PolicyAction, PolicyHandlerPerfStats } from "./perf.js";
17
- export { type ConfiguredPolicy, type IdentifiedPolicy, isPolicyError, isPolicyFailure, isPolicyFixResult, Policy, type PolicyArgs, type PolicyDefinition, type PolicyError, type PolicyFailure, type PolicyFixResult, type PolicyFunctionArguments, type PolicyHandler, type PolicyHandlerResult, type PolicyInstance, type PolicyInstanceId, type PolicyInstanceSettings, type PolicyName, type PolicyResolver, type PolicyResult, type PolicyShape, type PolicyStandaloneResolver, } from "./policy.js";
18
- export { type CargoToml, type CargoTomlHandler, type DefineCargoPolicyArgs, defineCargoPolicy, } from "./policyDefiners/defineCargoPolicy.js";
19
- export { type DefineFileHeaderPolicyArgs, defineFileHeaderPolicy, type FileHeaderGeneratorConfig, type FileHeaderPolicyConfig, } from "./policyDefiners/defineFileHeaderPolicy.js";
20
- export { type DefineGleamPolicyArgs, defineGleamPolicy, type GleamToml, type GleamTomlHandler, } from "./policyDefiners/defineGleamPolicy.js";
21
- export { type DefinePackagePolicyArgs, definePackagePolicy as generatePackagePolicy, type PackageJsonHandler, } from "./policyDefiners/definePackagePolicy.js";
22
- export { type PolicyFileResult, PolicyRunner, type PolicyRunnerOptions, type PolicyRunResults, } from "./runner.js";
9
+ export * from "./api.js";
23
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAEX,YAAY,GACZ,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACN,UAAU,EACV,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,MAAM,GACN,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAErB,aAAa,EACb,eAAe,EACf,iBAAiB,EAEjB,MAAM,EACN,KAAK,UAAU,EAEf,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,wBAAwB,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,iBAAiB,GACjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,KAAK,0BAA0B,EAC/B,sBAAsB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,GAC3B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,KAAK,qBAAqB,EAC1B,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,gBAAgB,GACrB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,KAAK,uBAAuB,EAC5B,mBAAmB,IAAI,qBAAqB,EAC5C,KAAK,kBAAkB,GACvB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACN,KAAK,gBAAgB,EACrB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACrB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,cAAc,UAAU,CAAC"}
package/esm/index.js CHANGED
@@ -1,24 +1,10 @@
1
1
  /**
2
- * A tool for enforcing repository policies and standards across codebases.
2
+ * Repository policy authoring, execution, and CLI entry point.
3
3
  *
4
- * @remarks
5
- * Repopo provides a framework for defining and enforcing policies across repositories,
6
- * such as file headers, package.json consistency, and other code standards.
7
- * It can be used as a CLI tool or integrated into CI/CD pipelines.
4
+ * Import `repopo/api` for the programmatic API without the CLI entry point.
8
5
  *
9
6
  * @packageDocumentation
10
7
  */
11
8
  export { run } from "@oclif/core";
12
- export { fromFluidHandlers, } from "./adapters/fluidFramework.js";
13
- export { makePolicy, makePolicyDefinition, policy, } from "./makePolicy.js";
14
- export {
15
- // Type guards
16
- isPolicyError, isPolicyFailure, isPolicyFixResult,
17
- // New types
18
- Policy, } from "./policy.js";
19
- export { defineCargoPolicy, } from "./policyDefiners/defineCargoPolicy.js";
20
- export { defineFileHeaderPolicy, } from "./policyDefiners/defineFileHeaderPolicy.js";
21
- export { defineGleamPolicy, } from "./policyDefiners/defineGleamPolicy.js";
22
- export { definePackagePolicy as generatePackagePolicy, } from "./policyDefiners/definePackagePolicy.js";
23
- export { PolicyRunner, } from "./runner.js";
9
+ export * from "./api.js";
24
10
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAGN,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AAMtC,OAAO,EACN,UAAU,EACV,oBAAoB,EAGpB,MAAM,GACN,MAAM,iBAAiB,CAAC;AAEzB,OAAO;AAGN,cAAc;AACd,aAAa,EACb,eAAe,EACf,iBAAiB;AACjB,YAAY;AACZ,MAAM,GAkBN,MAAM,aAAa,CAAC;AACrB,OAAO,EAIN,iBAAiB,GACjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,sBAAsB,GAGtB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEN,iBAAiB,GAGjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,mBAAmB,IAAI,qBAAqB,GAE5C,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAEN,YAAY,GAGZ,MAAM,aAAa,CAAC","sourcesContent":["/**\n * A tool for enforcing repository policies and standards across codebases.\n *\n * @remarks\n * Repopo provides a framework for defining and enforcing policies across repositories,\n * such as file headers, package.json consistency, and other code standards.\n * It can be used as a CLI tool or integrated into CI/CD pipelines.\n *\n * @packageDocumentation\n */\n\nexport { run } from \"@oclif/core\";\nexport {\n\ttype FluidAdapterOptions,\n\ttype FluidHandler,\n\tfromFluidHandlers,\n} from \"./adapters/fluidFramework.js\";\nexport type {\n\t// PolicyList,\n\tRepopoConfig,\n} from \"./config.js\";\nexport type { ExcludedPolicyFileMap } from \"./context.js\";\nexport {\n\tmakePolicy,\n\tmakePolicyDefinition,\n\ttype PolicyDefinitionInput,\n\ttype PolicyOptions,\n\tpolicy,\n} from \"./makePolicy.js\";\nexport type { PolicyAction, PolicyHandlerPerfStats } from \"./perf.js\";\nexport {\n\ttype ConfiguredPolicy,\n\ttype IdentifiedPolicy,\n\t// Type guards\n\tisPolicyError,\n\tisPolicyFailure,\n\tisPolicyFixResult,\n\t// New types\n\tPolicy,\n\ttype PolicyArgs,\n\t// Legacy types (for backward compatibility)\n\ttype PolicyDefinition,\n\ttype PolicyError,\n\ttype PolicyFailure,\n\ttype PolicyFixResult,\n\ttype PolicyFunctionArguments,\n\ttype PolicyHandler,\n\ttype PolicyHandlerResult,\n\ttype PolicyInstance,\n\ttype PolicyInstanceId,\n\ttype PolicyInstanceSettings,\n\ttype PolicyName,\n\ttype PolicyResolver,\n\ttype PolicyResult,\n\ttype PolicyShape,\n\ttype PolicyStandaloneResolver,\n} from \"./policy.js\";\nexport {\n\ttype CargoToml,\n\ttype CargoTomlHandler,\n\ttype DefineCargoPolicyArgs,\n\tdefineCargoPolicy,\n} from \"./policyDefiners/defineCargoPolicy.js\";\nexport {\n\ttype DefineFileHeaderPolicyArgs,\n\tdefineFileHeaderPolicy,\n\ttype FileHeaderGeneratorConfig,\n\ttype FileHeaderPolicyConfig,\n} from \"./policyDefiners/defineFileHeaderPolicy.js\";\nexport {\n\ttype DefineGleamPolicyArgs,\n\tdefineGleamPolicy,\n\ttype GleamToml,\n\ttype GleamTomlHandler,\n} from \"./policyDefiners/defineGleamPolicy.js\";\nexport {\n\ttype DefinePackagePolicyArgs,\n\tdefinePackagePolicy as generatePackagePolicy,\n\ttype PackageJsonHandler,\n} from \"./policyDefiners/definePackagePolicy.js\";\nexport {\n\ttype PolicyFileResult,\n\tPolicyRunner,\n\ttype PolicyRunnerOptions,\n\ttype PolicyRunResults,\n} from \"./runner.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,cAAc,UAAU,CAAC","sourcesContent":["/**\n * Repository policy authoring, execution, and CLI entry point.\n *\n * Import `repopo/api` for the programmatic API without the CLI entry point.\n *\n * @packageDocumentation\n */\n\nexport { run } from \"@oclif/core\";\nexport * from \"./api.js\";\n"]}
@@ -1,107 +1,27 @@
1
- import type { ConfiguredPolicy, PolicyDefinition, PolicyInstance, PolicyInstanceId, PolicyInstanceSettings, PolicyName, PolicyShape } from "./policy.js";
2
- /**
3
- * Options for configuring a policy instance.
4
- *
5
- * @alpha
6
- */
7
- export interface PolicyOptions {
8
- /**
9
- * A stable identifier for this configured policy instance.
10
- *
11
- * This is required when the same policy definition is configured more than once.
12
- */
13
- instanceId?: PolicyInstanceId;
14
- /**
15
- * File paths matching these patterns will be excluded from this policy.
16
- * Patterns are matched against repo-relative paths.
17
- */
18
- exclude?: (string | RegExp)[];
19
- }
20
- /**
21
- * Configure a policy for use in repopo.
22
- *
23
- * @remarks
24
- * This function takes a policy definition and returns a configured policy instance
25
- * that can be added to the `policies` array in `repopo.config.ts`.
26
- *
27
- * Handlers are automatically normalized: async functions are wrapped for Effection
28
- * compatibility, while generator functions are used directly.
29
- *
30
- * @example
31
- * ```typescript
32
- * // Policy with no config, just options
33
- * policy(NoJsFileExtensions, { exclude: ["bin/*"] })
34
- *
35
- * // Policy with config
36
- * policy(PackageJsonProperties, { verbatim: { license: "MIT" } })
37
- *
38
- * // Policy with config and options
39
- * policy(PackageJsonProperties, { verbatim: { license: "MIT" } }, { exclude: ["vendor/*"] })
40
- *
41
- * // Duplicate policies need stable instance IDs
42
- * policy(PackageJsonProperties, sourceConfig, { instanceId: "source-packages" })
43
- * policy(PackageJsonProperties, testConfig, { instanceId: "test-packages" })
44
- * ```
45
- *
46
- * @alpha
47
- */
48
- export declare function policy<C = void>(policyDef: PolicyShape<C>, options?: PolicyOptions & {
49
- exclude: (string | RegExp)[];
50
- }): ConfiguredPolicy<C>;
51
- /** @alpha */
52
- export declare function policy<C>(policyDef: PolicyShape<C>, config: C, options?: PolicyOptions): ConfiguredPolicy<C>;
53
- /**
54
- * Assigns stable identities to configured policy instances.
55
- *
56
- * Single instances retain the policy name for compatibility. Duplicate instances
57
- * must declare explicit identities so their identities remain stable across config
58
- * reordering and policy renames.
59
- *
60
- * @internal
61
- */
1
+ import type { ConfiguredFilePolicy, ConfiguredPolicy, ConfiguredRepositoryPolicy, DefinedConfig, FilePolicyDefinition, PolicyDefinition, PolicyInstanceId, PolicyName, PolicyOptions, RepositoryPolicyDefinition } from "./policy.js";
2
+ type ConfigOf<D> = D extends PolicyDefinition<infer C> ? C : never;
3
+ type RequiredConfigDefinitions<D> = D extends {
4
+ requiresConfig: true;
5
+ } ? D extends {
6
+ defaultConfig: infer Default;
7
+ } ? undefined extends Default ? D : never : D : never;
8
+ type OptionsFor<D> = [RequiredConfigDefinitions<D>] extends [never] ? [options?: PolicyOptions<ConfigOf<D>>] : [
9
+ options: PolicyOptions<ConfigOf<D>> & {
10
+ config: DefinedConfig<ConfigOf<RequiredConfigDefinitions<D>>>;
11
+ }
12
+ ];
13
+ /** Configure a file definition using a single options object. @public */
14
+ export declare function makePolicy<D extends FilePolicyDefinition<unknown>>(definition: D, ...options: OptionsFor<D>): ConfiguredFilePolicy<ConfigOf<D>>;
15
+ /** Configure a repository definition using a single options object. @public */
16
+ export declare function makePolicy<D extends RepositoryPolicyDefinition<unknown>>(definition: D, ...options: OptionsFor<D>): ConfiguredRepositoryPolicy<ConfigOf<D>>;
17
+ /** Configure a common-union definition without losing scope discrimination. @public */
18
+ export declare function makePolicy<D extends PolicyDefinition<unknown>>(definition: D, ...options: OptionsFor<D>): ConfiguredPolicy<ConfigOf<D>>;
19
+ /** Assign stable IDs, rejecting ambiguous duplicates. @internal */
62
20
  export declare function identifyPolicyInstances<T extends {
63
21
  name: PolicyName;
64
22
  instanceId?: PolicyInstanceId | undefined;
65
23
  }>(policies: readonly T[]): (T & {
66
24
  instanceId: PolicyInstanceId;
67
25
  })[];
68
- /**
69
- * Input arguments for creating a policy definition.
70
- *
71
- * @deprecated Use {@link PolicyShape} directly instead.
72
- *
73
- * @alpha
74
- */
75
- export type PolicyDefinitionInput<C = undefined> = PolicyDefinition<C>;
76
- /**
77
- * Creates a {@link PolicyDefinition} from the provided arguments.
78
- *
79
- * @deprecated Define policies as object literals satisfying {@link PolicyShape} instead.
80
- *
81
- * @example
82
- * ```typescript
83
- * const MyPolicy = makePolicyDefinition({
84
- * name: "MyPolicy",
85
- * description: "Ensures files follow conventions",
86
- * match: /\.ts$/,
87
- * handler: async ({ file }) => true,
88
- * });
89
- * ```
90
- *
91
- * @alpha
92
- */
93
- export declare function makePolicyDefinition<C = undefined>(args: PolicyDefinitionInput<C>): PolicyDefinition<C>;
94
- /**
95
- * Combine a {@link PolicyDefinition} with a policy-specific config and other settings.
96
- *
97
- * @deprecated Use the `policy` function instead, which has a simpler API.
98
- *
99
- * @example
100
- * ```typescript
101
- * makePolicy(NoJsFileExtensions, undefined, { excludeFiles: ["bin/*"] })
102
- * ```
103
- *
104
- * @alpha
105
- */
106
- export declare function makePolicy<C>(definition: PolicyDefinition<C>, config?: C, settings?: PolicyInstanceSettings<C>): PolicyInstance<C>;
26
+ export {};
107
27
  //# sourceMappingURL=makePolicy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"makePolicy.d.ts","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,gBAAgB,EAEhB,gBAAgB,EAGhB,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,WAAW,EACX,MAAM,aAAa,CAAC;AAMrB;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;OAIG;IACH,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAE9B;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CAC9B;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,MAAM,CAAC,CAAC,GAAG,IAAI,EAC9B,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,EACzB,OAAO,CAAC,EAAE,aAAa,GAAG;IAAE,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;CAAE,GACxD,gBAAgB,CAAC,CAAC,CAAC,CAAC;AACvB,aAAa;AACb,wBAAgB,MAAM,CAAC,CAAC,EACvB,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,aAAa,GACrB,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAmDvB;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACtC,CAAC,SAAS;IACT,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;CAC1C,EACA,QAAQ,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,C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Function } from "./generators.js";
3
- /**
4
- * Normalizes a handler to always return an Effection Operation.
5
- * Detection happens once at registration time, not per-invocation.
6
- */
7
- function normalizeHandler(handler) {
8
- if (isGeneratorFunction(handler)) {
9
- // Already a generator, return as-is
10
- return handler;
1
+ import { exclusionRegex } from "./context.js";
2
+ export function makePolicy(definition, options, ...extra) {
3
+ const guidance = "Use makePolicy(definition, { config, exclude, instanceId }); positional config, third arguments and excludeFiles are no longer supported.";
4
+ if (extra.length > 0 ||
5
+ (options !== undefined &&
6
+ (typeof options !== "object" ||
7
+ options === null ||
8
+ Array.isArray(options) ||
9
+ Object.keys(options).some((key) => !["config", "exclude", "instanceId"].includes(key))))) {
10
+ throw new TypeError(guidance);
11
11
  }
12
- // Async function - wrap with call()
13
- return function* (args) {
14
- const asyncHandler = handler;
15
- return yield* call(() => asyncHandler(args));
16
- };
17
- }
18
- /** @alpha */
19
- export function policy(policyDef, configOrOptions, maybeOptions) {
20
- // Determine if the second argument is config or options
21
- let config;
22
- let options;
23
- if (maybeOptions !== undefined) {
24
- // Three-argument form: policy(def, config, options)
25
- config = configOrOptions;
26
- options = maybeOptions;
12
+ if (definition.scope === "repository" && definition.resolver !== undefined) {
13
+ throw new TypeError("Repository policies support inline fixes only; remove resolver.");
27
14
  }
28
- else if (configOrOptions !== undefined) {
29
- // Two-argument form: need to determine if it's config or options
30
- // PolicyOptions has a specific shape with 'exclude' property
31
- if (typeof configOrOptions === "object" &&
32
- configOrOptions !== null &&
33
- "exclude" in configOrOptions &&
34
- !("name" in configOrOptions) &&
35
- Object.keys(configOrOptions).every((k) => k === "exclude" || k === "instanceId")) {
36
- // It's options (has 'exclude' and only option keys)
37
- options = configOrOptions;
38
- }
39
- else {
40
- // It's config
41
- config = configOrOptions;
42
- }
15
+ if (options?.exclude !== undefined &&
16
+ !(Array.isArray(options.exclude) &&
17
+ options.exclude.every((value) => typeof value === "string" || value instanceof RegExp))) {
18
+ throw new TypeError(guidance);
19
+ }
20
+ if (options?.instanceId !== undefined &&
21
+ (typeof options.instanceId !== "string" || options.instanceId.length === 0)) {
22
+ throw new TypeError("instanceId must be a nonempty string.");
43
23
  }
44
- // Merge with default config if available
45
- const effectiveConfig = config ?? policyDef.defaultConfig;
46
- // Support both 'exclude' and 'excludeFiles' for backward compatibility
47
- const excludePatterns = options?.exclude;
48
- return {
49
- ...policyDef,
50
- config: effectiveConfig,
51
- exclude: excludePatterns,
52
- excludeFiles: excludePatterns,
53
- instanceId: options?.instanceId,
54
- _internalHandler: normalizeHandler(policyDef.handler),
55
- };
24
+ options?.exclude?.forEach(exclusionRegex);
25
+ const config = options?.config === undefined ? definition.defaultConfig : options.config;
26
+ if (definition.requiresConfig && config === undefined) {
27
+ throw new TypeError(`Policy '${definition.name}' requires config. ${guidance}`);
28
+ }
29
+ return { ...definition, ...options, config };
56
30
  }
57
- /**
58
- * Assigns stable identities to configured policy instances.
59
- *
60
- * Single instances retain the policy name for compatibility. Duplicate instances
61
- * must declare explicit identities so their identities remain stable across config
62
- * reordering and policy renames.
63
- *
64
- * @internal
65
- */
31
+ /** Assign stable IDs, rejecting ambiguous duplicates. @internal */
66
32
  export function identifyPolicyInstances(policies) {
67
- const explicitIds = new Set();
68
- const nameCounts = new Map();
69
- for (const configuredPolicy of policies) {
70
- nameCounts.set(configuredPolicy.name, (nameCounts.get(configuredPolicy.name) ?? 0) + 1);
71
- if (configuredPolicy.instanceId !== undefined) {
72
- if (explicitIds.has(configuredPolicy.instanceId)) {
73
- throw new Error(`Duplicate policy instance ID: ${configuredPolicy.instanceId}`);
33
+ const names = new Map();
34
+ const ids = new Set();
35
+ for (const policy of policies) {
36
+ names.set(policy.name, (names.get(policy.name) ?? 0) + 1);
37
+ if (policy.instanceId !== undefined) {
38
+ if (ids.has(policy.instanceId)) {
39
+ throw new Error(`Duplicate policy instance ID: ${policy.instanceId}`);
74
40
  }
75
- explicitIds.add(configuredPolicy.instanceId);
41
+ ids.add(policy.instanceId);
76
42
  }
77
43
  }
78
- const usedIds = new Set(explicitIds);
79
- return policies.map((configuredPolicy) => {
80
- if (configuredPolicy.instanceId !== undefined) {
81
- return {
82
- ...configuredPolicy,
83
- instanceId: configuredPolicy.instanceId,
84
- };
44
+ return policies.map((policy) => {
45
+ if (policy.instanceId !== undefined) {
46
+ return { ...policy, instanceId: policy.instanceId };
85
47
  }
86
- if ((nameCounts.get(configuredPolicy.name) ?? 0) > 1) {
87
- throw new Error(`Policy '${configuredPolicy.name}' is configured multiple times. Set a unique instanceId for each instance.`);
48
+ if ((names.get(policy.name) ?? 0) > 1) {
49
+ throw new Error(`Policy '${policy.name}' is configured multiple times. Set a unique instanceId for each instance.`);
88
50
  }
89
- const instanceId = configuredPolicy.name;
90
- if (usedIds.has(instanceId)) {
91
- throw new Error(`Policy instance ID '${instanceId}' conflicts with another configured policy. Set an explicit unique instanceId.`);
51
+ if (ids.has(policy.name)) {
52
+ throw new Error(`Policy instance ID '${policy.name}' conflicts with another configured policy. Set an explicit unique instanceId.`);
92
53
  }
93
- usedIds.add(instanceId);
94
- return {
95
- ...configuredPolicy,
96
- instanceId,
97
- };
54
+ ids.add(policy.name);
55
+ return { ...policy, instanceId: policy.name };
98
56
  });
99
57
  }
100
- /**
101
- * Creates a {@link PolicyDefinition} from the provided arguments.
102
- *
103
- * @deprecated Define policies as object literals satisfying {@link PolicyShape} instead.
104
- *
105
- * @example
106
- * ```typescript
107
- * const MyPolicy = makePolicyDefinition({
108
- * name: "MyPolicy",
109
- * description: "Ensures files follow conventions",
110
- * match: /\.ts$/,
111
- * handler: async ({ file }) => true,
112
- * });
113
- * ```
114
- *
115
- * @alpha
116
- */
117
- export function makePolicyDefinition(args) {
118
- return {
119
- name: args.name,
120
- description: args.description,
121
- match: args.match,
122
- handler: args.handler,
123
- defaultConfig: args.defaultConfig,
124
- resolver: args.resolver,
125
- };
126
- }
127
- /**
128
- * Combine a {@link PolicyDefinition} with a policy-specific config and other settings.
129
- *
130
- * @deprecated Use the `policy` function instead, which has a simpler API.
131
- *
132
- * @example
133
- * ```typescript
134
- * makePolicy(NoJsFileExtensions, undefined, { excludeFiles: ["bin/*"] })
135
- * ```
136
- *
137
- * @alpha
138
- */
139
- export function makePolicy(definition, config, settings) {
140
- return {
141
- ...definition,
142
- ...settings,
143
- config,
144
- };
145
- }
146
58
  //# sourceMappingURL=makePolicy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"makePolicy.js","sourceRoot":"","sources":["../src/makePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAsCtD;;;GAGG;AACH,SAAS,gBAAgB,CACxB,OAAyB;IAEzB,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,oCAAoC;QACpC,OAAO,OAAkE,CAAC;IAC3E,CAAC;IAED,oCAAoC;IACpC,OAAO,QAAQ,CAAC,EAAE,IAAmB;QACpC,MAAM,YAAY,GAAG,OAEY,CAAC;QAClC,OAAO,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC;AACH,CAAC;AAwCD,aAAa;AACb,MAAM,UAAU,MAAM,CACrB,SAAyB,EACzB,eAAmC,EACnC,YAA4B;IAE5B,wDAAwD;IACxD,IAAI,MAAqB,CAAC;IAC1B,IAAI,OAAkC,CAAC;IAEvC,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAChC,oDAAoD;QACpD,MAAM,GAAG,eAAoB,CAAC;QAC9B,OAAO,GAAG,YAAY,CAAC;IACxB,CAAC;SAAM,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAC1C,iEAAiE;QACjE,6DAA6D;QAC7D,IACC,OAAO,eAAe,KAAK,QAAQ;YACnC,eAAe,KAAK,IAAI;YACxB,SAAS,IAAI,eAAe;YAC5B,CAAC,CAAC,MAAM,IAAI,eAAe,CAA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,MAAM,UAAU,UAAU,CACzB,UAA+B,EAC/B,MAAU,EACV,QAAoC;IAEpC,OAAO;QACN,GAAG,UAAU;QACb,GAAG,QAAQ;QACX,MAAM;KACsB,CAAC;AAC/B,CAAC","sourcesContent":["import { call, type Operation } from \"effection\";\nimport { isGeneratorFunction } from \"./generators.js\";\nimport type {\n\tConfiguredPolicy,\n\tPolicyArgs,\n\tPolicyDefinition,\n\tPolicyHandler,\n\tPolicyHandlerResult,\n\tPolicyInstance,\n\tPolicyInstanceId,\n\tPolicyInstanceSettings,\n\tPolicyName,\n\tPolicyShape,\n} from \"./policy.js\";\n\n// ============================================================================\n// New API: policy() function\n// ============================================================================\n\n/**\n * Options for configuring a policy instance.\n *\n * @alpha\n */\nexport interface PolicyOptions {\n\t/**\n\t * A 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;\n\n\t/**\n\t * File paths matching these patterns will be excluded from this policy.\n\t * Patterns are matched against repo-relative paths.\n\t */\n\texclude?: (string | RegExp)[];\n}\n\n/**\n * Normalizes a handler to always return an Effection Operation.\n * Detection happens once at registration time, not per-invocation.\n */\nfunction normalizeHandler<C>(\n\thandler: PolicyHandler<C>,\n): (args: PolicyArgs<C>) => Operation<PolicyHandlerResult> {\n\tif (isGeneratorFunction(handler)) {\n\t\t// Already a generator, return as-is\n\t\treturn handler as (args: PolicyArgs<C>) => Operation<PolicyHandlerResult>;\n\t}\n\n\t// Async function - wrap with call()\n\treturn function* (args: PolicyArgs<C>): Operation<PolicyHandlerResult> {\n\t\tconst asyncHandler = handler as (\n\t\t\tpolicyArgs: PolicyArgs<C>,\n\t\t) => Promise<PolicyHandlerResult>;\n\t\treturn yield* call(() => asyncHandler(args));\n\t};\n}\n\n/**\n * Configure a policy for use in repopo.\n *\n * @remarks\n * This function takes a policy definition and returns a configured policy instance\n * that can be added to the `policies` array in `repopo.config.ts`.\n *\n * Handlers are automatically normalized: async functions are wrapped for Effection\n * compatibility, while generator functions are used directly.\n *\n * @example\n * ```typescript\n * // Policy with no config, just options\n * policy(NoJsFileExtensions, { exclude: [\"bin/*\"] })\n *\n * // Policy with config\n * policy(PackageJsonProperties, { verbatim: { license: \"MIT\" } })\n *\n * // Policy with config and options\n * policy(PackageJsonProperties, { verbatim: { license: \"MIT\" } }, { exclude: [\"vendor/*\"] })\n *\n * // Duplicate policies need stable instance IDs\n * policy(PackageJsonProperties, sourceConfig, { instanceId: \"source-packages\" })\n * policy(PackageJsonProperties, testConfig, { instanceId: \"test-packages\" })\n * ```\n *\n * @alpha\n */\nexport function policy<C = void>(\n\tpolicyDef: PolicyShape<C>,\n\toptions?: PolicyOptions & { exclude: (string | RegExp)[] },\n): ConfiguredPolicy<C>;\n/** @alpha */\nexport function policy<C>(\n\tpolicyDef: PolicyShape<C>,\n\tconfig: C,\n\toptions?: PolicyOptions,\n): ConfiguredPolicy<C>;\n/** @alpha */\nexport function policy<C>(\n\tpolicyDef: PolicyShape<C>,\n\tconfigOrOptions?: C | PolicyOptions,\n\tmaybeOptions?: PolicyOptions,\n): ConfiguredPolicy<C> {\n\t// Determine if the second argument is config or options\n\tlet config: C | undefined;\n\tlet options: PolicyOptions | undefined;\n\n\tif (maybeOptions !== undefined) {\n\t\t// Three-argument form: policy(def, config, options)\n\t\tconfig = configOrOptions as C;\n\t\toptions = maybeOptions;\n\t} else if (configOrOptions !== undefined) {\n\t\t// Two-argument form: need to determine if it's config or options\n\t\t// PolicyOptions has a specific shape with 'exclude' property\n\t\tif (\n\t\t\ttypeof configOrOptions === \"object\" &&\n\t\t\tconfigOrOptions !== null &&\n\t\t\t\"exclude\" in configOrOptions &&\n\t\t\t!(\"name\" in configOrOptions) &&\n\t\t\tObject.keys(configOrOptions).every(\n\t\t\t\t(k) => k === \"exclude\" || k === \"instanceId\",\n\t\t\t)\n\t\t) {\n\t\t\t// It's options (has 'exclude' and only option keys)\n\t\t\toptions = configOrOptions as PolicyOptions;\n\t\t} else {\n\t\t\t// It's config\n\t\t\tconfig = configOrOptions as C;\n\t\t}\n\t}\n\n\t// Merge with default config if available\n\tconst effectiveConfig = config ?? (policyDef.defaultConfig as C | undefined);\n\n\t// Support both 'exclude' and 'excludeFiles' for backward compatibility\n\tconst excludePatterns = options?.exclude;\n\n\treturn {\n\t\t...policyDef,\n\t\tconfig: effectiveConfig,\n\t\texclude: excludePatterns,\n\t\texcludeFiles: excludePatterns,\n\t\tinstanceId: options?.instanceId,\n\t\t_internalHandler: normalizeHandler(policyDef.handler),\n\t};\n}\n\n/**\n * Assigns stable identities to configured policy instances.\n *\n * Single instances retain the policy name for compatibility. Duplicate instances\n * must declare explicit identities so their identities remain stable across config\n * reordering and policy renames.\n *\n * @internal\n */\nexport function identifyPolicyInstances<\n\tT extends {\n\t\tname: PolicyName;\n\t\tinstanceId?: PolicyInstanceId | undefined;\n\t},\n>(policies: readonly T[]): (T & { instanceId: PolicyInstanceId })[] {\n\tconst explicitIds = new Set<PolicyInstanceId>();\n\tconst nameCounts = new Map<PolicyName, number>();\n\n\tfor (const configuredPolicy of policies) {\n\t\tnameCounts.set(\n\t\t\tconfiguredPolicy.name,\n\t\t\t(nameCounts.get(configuredPolicy.name) ?? 0) + 1,\n\t\t);\n\t\tif (configuredPolicy.instanceId !== undefined) {\n\t\t\tif (explicitIds.has(configuredPolicy.instanceId)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Duplicate policy instance ID: ${configuredPolicy.instanceId}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\texplicitIds.add(configuredPolicy.instanceId);\n\t\t}\n\t}\n\n\tconst usedIds = new Set(explicitIds);\n\n\treturn policies.map((configuredPolicy) => {\n\t\tif (configuredPolicy.instanceId !== undefined) {\n\t\t\treturn {\n\t\t\t\t...configuredPolicy,\n\t\t\t\tinstanceId: configuredPolicy.instanceId,\n\t\t\t};\n\t\t}\n\n\t\tif ((nameCounts.get(configuredPolicy.name) ?? 0) > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Policy '${configuredPolicy.name}' is configured multiple times. Set a unique instanceId for each instance.`,\n\t\t\t);\n\t\t}\n\n\t\tconst instanceId = configuredPolicy.name;\n\t\tif (usedIds.has(instanceId)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Policy instance ID '${instanceId}' conflicts with another configured policy. Set an explicit unique instanceId.`,\n\t\t\t);\n\t\t}\n\t\tusedIds.add(instanceId);\n\n\t\treturn {\n\t\t\t...configuredPolicy,\n\t\t\tinstanceId,\n\t\t};\n\t});\n}\n\n// ============================================================================\n// Legacy API (Still supported for backward compatibility)\n// ============================================================================\n\n/**\n * Input arguments for creating a policy definition.\n *\n * @deprecated Use {@link PolicyShape} directly instead.\n *\n * @alpha\n */\nexport type PolicyDefinitionInput<C = undefined> = PolicyDefinition<C>;\n\n/**\n * Creates a {@link PolicyDefinition} from the provided arguments.\n *\n * @deprecated Define policies as object literals satisfying {@link PolicyShape} instead.\n *\n * @example\n * ```typescript\n * const MyPolicy = makePolicyDefinition({\n * name: \"MyPolicy\",\n * description: \"Ensures files follow conventions\",\n * match: /\\.ts$/,\n * handler: async ({ file }) => true,\n * });\n * ```\n *\n * @alpha\n */\nexport function makePolicyDefinition<C = undefined>(\n\targs: PolicyDefinitionInput<C>,\n): PolicyDefinition<C> {\n\treturn {\n\t\tname: args.name,\n\t\tdescription: args.description,\n\t\tmatch: args.match,\n\t\thandler: args.handler,\n\t\tdefaultConfig: args.defaultConfig,\n\t\tresolver: args.resolver,\n\t};\n}\n\n/**\n * Combine a {@link PolicyDefinition} with a policy-specific config and other settings.\n *\n * @deprecated Use the `policy` function instead, which has a simpler API.\n *\n * @example\n * ```typescript\n * makePolicy(NoJsFileExtensions, undefined, { excludeFiles: [\"bin/*\"] })\n * ```\n *\n * @alpha\n */\nexport function makePolicy<C>(\n\tdefinition: PolicyDefinition<C>,\n\tconfig?: C,\n\tsettings?: PolicyInstanceSettings<C>,\n): PolicyInstance<C> {\n\treturn {\n\t\t...definition,\n\t\t...settings,\n\t\t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AAC;QAC5B,CAAC;IACF,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC9B,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACrC,OAAO,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;QACrD,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CACd,WAAW,MAAM,CAAC,IAAI,4EAA4E,CAClG,CAAC;QACH,CAAC;QACD,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CACd,uBAAuB,MAAM,CAAC,IAAI,gFAAgF,CAClH,CAAC;QACH,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACrB,OAAO,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IAC/C,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { exclusionRegex } from \"./context.js\";\nimport type {\n\tConfiguredFilePolicy,\n\tConfiguredPolicy,\n\tConfiguredRepositoryPolicy,\n\tDefinedConfig,\n\tFilePolicyDefinition,\n\tPolicyDefinition,\n\tPolicyInstanceId,\n\tPolicyName,\n\tPolicyOptions,\n\tRepositoryPolicyDefinition,\n} from \"./policy.js\";\n\ntype ConfigOf<D> = D extends PolicyDefinition<infer C> ? C : never;\ntype RequiredConfigDefinitions<D> = D extends { requiresConfig: true }\n\t? D extends { defaultConfig: infer Default }\n\t\t? undefined extends Default\n\t\t\t? D\n\t\t\t: never\n\t\t: D\n\t: never;\ntype OptionsFor<D> = [RequiredConfigDefinitions<D>] extends [never]\n\t? [options?: PolicyOptions<ConfigOf<D>>]\n\t: [\n\t\t\toptions: PolicyOptions<ConfigOf<D>> & {\n\t\t\t\tconfig: DefinedConfig<ConfigOf<RequiredConfigDefinitions<D>>>;\n\t\t\t},\n\t\t];\n\n/** Configure a file definition using a single options object. @public */\nexport function makePolicy<D extends FilePolicyDefinition<unknown>>(\n\tdefinition: D,\n\t...options: OptionsFor<D>\n): ConfiguredFilePolicy<ConfigOf<D>>;\n/** Configure a repository definition using a single options object. @public */\nexport function makePolicy<D extends RepositoryPolicyDefinition<unknown>>(\n\tdefinition: D,\n\t...options: OptionsFor<D>\n): ConfiguredRepositoryPolicy<ConfigOf<D>>;\n/** Configure a common-union definition without losing scope discrimination. @public */\nexport function makePolicy<D extends PolicyDefinition<unknown>>(\n\tdefinition: D,\n\t...options: OptionsFor<D>\n): ConfiguredPolicy<ConfigOf<D>>;\nexport function makePolicy(\n\tdefinition: PolicyDefinition<unknown>,\n\toptions?: PolicyOptions<unknown>,\n\t...extra: unknown[]\n): ConfiguredPolicy<unknown> {\n\tconst guidance =\n\t\t\"Use makePolicy(definition, { config, exclude, instanceId }); positional config, third arguments and excludeFiles are no longer supported.\";\n\tif (\n\t\textra.length > 0 ||\n\t\t(options !== undefined &&\n\t\t\t(typeof options !== \"object\" ||\n\t\t\t\toptions === null ||\n\t\t\t\tArray.isArray(options) ||\n\t\t\t\tObject.keys(options).some(\n\t\t\t\t\t(key) => ![\"config\", \"exclude\", \"instanceId\"].includes(key),\n\t\t\t\t)))\n\t) {\n\t\tthrow new TypeError(guidance);\n\t}\n\tif (definition.scope === \"repository\" && definition.resolver !== undefined) {\n\t\tthrow new TypeError(\n\t\t\t\"Repository policies support inline fixes only; remove resolver.\",\n\t\t);\n\t}\n\tif (\n\t\toptions?.exclude !== undefined &&\n\t\t!(\n\t\t\tArray.isArray(options.exclude) &&\n\t\t\toptions.exclude.every(\n\t\t\t\t(value) => typeof value === \"string\" || value instanceof RegExp,\n\t\t\t)\n\t\t)\n\t) {\n\t\tthrow new TypeError(guidance);\n\t}\n\tif (\n\t\toptions?.instanceId !== undefined &&\n\t\t(typeof options.instanceId !== \"string\" || options.instanceId.length === 0)\n\t) {\n\t\tthrow new TypeError(\"instanceId must be a nonempty string.\");\n\t}\n\toptions?.exclude?.forEach(exclusionRegex);\n\tconst config =\n\t\toptions?.config === undefined ? definition.defaultConfig : options.config;\n\tif (definition.requiresConfig && config === undefined) {\n\t\tthrow new TypeError(\n\t\t\t`Policy '${definition.name}' requires config. ${guidance}`,\n\t\t);\n\t}\n\treturn { ...definition, ...options, config };\n}\n\n/** Assign stable IDs, rejecting ambiguous duplicates. @internal */\nexport function identifyPolicyInstances<\n\tT extends { name: PolicyName; instanceId?: PolicyInstanceId | undefined },\n>(policies: readonly T[]): (T & { instanceId: PolicyInstanceId })[] {\n\tconst names = new Map<string, number>();\n\tconst ids = new Set<string>();\n\tfor (const policy of policies) {\n\t\tnames.set(policy.name, (names.get(policy.name) ?? 0) + 1);\n\t\tif (policy.instanceId !== undefined) {\n\t\t\tif (ids.has(policy.instanceId)) {\n\t\t\t\tthrow new Error(`Duplicate policy instance ID: ${policy.instanceId}`);\n\t\t\t}\n\t\t\tids.add(policy.instanceId);\n\t\t}\n\t}\n\treturn policies.map((policy) => {\n\t\tif (policy.instanceId !== undefined) {\n\t\t\treturn { ...policy, instanceId: policy.instanceId };\n\t\t}\n\t\tif ((names.get(policy.name) ?? 0) > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Policy '${policy.name}' is configured multiple times. Set a unique instanceId for each instance.`,\n\t\t\t);\n\t\t}\n\t\tif (ids.has(policy.name)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Policy instance ID '${policy.name}' conflicts with another configured policy. Set an explicit unique instanceId.`,\n\t\t\t);\n\t\t}\n\t\tids.add(policy.name);\n\t\treturn { ...policy, instanceId: policy.name };\n\t});\n}\n"]}
package/esm/perf.d.ts CHANGED
@@ -3,16 +3,19 @@ import type { Operation } from "effection";
3
3
  import type { PolicyInstanceId } from "./policy.js";
4
4
  /**
5
5
  * The type of action a policy can perform.
6
- * @alpha
6
+ * @public
7
7
  */
8
8
  export type PolicyAction = "check" | "resolve" | "handle";
9
9
  /**
10
10
  * Stores performance data for each handler. Used to collect and display performance stats.
11
- * @alpha
11
+ * @public
12
12
  */
13
13
  export interface PolicyHandlerPerfStats {
14
+ /** Number of candidate file paths supplied to the runner. */
14
15
  count: number;
16
+ /** Number of candidate files admitted past global exclusions. */
15
17
  processed: number;
18
+ /** Total elapsed milliseconds per action and configured policy instance. */
16
19
  data: Map<PolicyAction, Map<PolicyInstanceId, number>>;
17
20
  }
18
21
  export declare function newPerfStats(): PolicyHandlerPerfStats;
package/esm/perf.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAC;CACvD;AAED,wBAAgB,YAAY,IAAI,sBAAsB,CAMrD;AAED,wBAAiB,WAAW,CAAC,CAAC,EAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,sBAAsB,EAC7B,GAAG,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,GACrB,SAAS,CAAC,CAAC,CAAC,CAWd;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAWzE"}
1
+ {"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAC;CACvD;AAED,wBAAgB,YAAY,IAAI,sBAAsB,CAMrD;AAED,wBAAiB,WAAW,CAAC,CAAC,EAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,sBAAsB,EAC7B,GAAG,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,GACrB,SAAS,CAAC,CAAC,CAAC,CASd;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAWzE"}
package/esm/perf.js CHANGED
@@ -6,14 +6,15 @@ export function newPerfStats() {
6
6
  };
7
7
  }
8
8
  export function* runWithPerf(name, action, stats, run) {
9
- const actionMap = stats.data.get(action) ?? new Map();
10
- let dur = actionMap.get(name) ?? 0;
11
- const start = Date.now();
12
- const result = yield* run();
13
- dur += Date.now() - start;
14
- actionMap.set(name, dur);
15
- stats.data.set(action, actionMap);
16
- return result;
9
+ const start = performance.now();
10
+ try {
11
+ return yield* run();
12
+ }
13
+ finally {
14
+ const actionMap = stats.data.get(action) ?? new Map();
15
+ actionMap.set(name, (actionMap.get(name) ?? 0) + performance.now() - start);
16
+ stats.data.set(action, actionMap);
17
+ }
17
18
  }
18
19
  export function logStats(stats, log) {
19
20
  log.log(`Statistics: ${stats.processed} files processed, ` +
@@ -21,7 +22,7 @@ export function logStats(stats, log) {
21
22
  for (const [action, handlerPerf] of stats.data.entries()) {
22
23
  log.log(`Performance for "${action}":`);
23
24
  for (const [handler, dur] of handlerPerf.entries()) {
24
- log.log(` ${handler}: ${dur}ms`);
25
+ log.log(` ${handler}: ${Math.round(dur * 10) / 10}ms`);
25
26
  }
26
27
  }
27
28
  }
package/esm/perf.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"perf.js","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAoBA,MAAM,UAAU,YAAY;IAC3B,OAAO;QACN,KAAK,EAAE,CAAC;QACR,SAAS,EAAE,CAAC;QACZ,IAAI,EAAE,IAAI,GAAG,EAA+C;KAC5D,CAAC;AACH,CAAC;AAED,MAAM,SAAS,CAAC,CAAC,WAAW,CAC3B,IAAY,EACZ,MAAoB,EACpB,KAA6B,EAC7B,GAAuB;IAEvB,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,GAAG,EAAkB,CAAC;IACtE,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEnC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC;IAC5B,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAE1B,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAA6B,EAAE,GAAW;IAClE,GAAG,CAAC,GAAG,CACN,eAAe,KAAK,CAAC,SAAS,oBAAoB;QACjD,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,SAAS,cAAc,KAAK,CAAC,KAAK,QAAQ,CAClE,CAAC;IACF,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1D,GAAG,CAAC,GAAG,CAAC,oBAAoB,MAAM,IAAI,CAAC,CAAC;QACxC,KAAK,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;YACpD,GAAG,CAAC,GAAG,CAAC,OAAO,OAAO,KAAK,GAAG,IAAI,CAAC,CAAC;QACrC,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type { Logger } from \"@tylerbu/cli-api\";\nimport type { Operation } from \"effection\";\nimport type { PolicyInstanceId } from \"./policy.js\";\n\n/**\n * The type of action a policy can perform.\n * @alpha\n */\nexport type PolicyAction = \"check\" | \"resolve\" | \"handle\";\n\n/**\n * Stores performance data for each handler. Used to collect and display performance stats.\n * @alpha\n */\nexport interface PolicyHandlerPerfStats {\n\tcount: number;\n\tprocessed: number;\n\tdata: Map<PolicyAction, Map<PolicyInstanceId, number>>;\n}\n\nexport function newPerfStats(): PolicyHandlerPerfStats {\n\treturn {\n\t\tcount: 0,\n\t\tprocessed: 0,\n\t\tdata: new Map<PolicyAction, Map<PolicyInstanceId, number>>(),\n\t};\n}\n\nexport function* runWithPerf<T>(\n\tname: string,\n\taction: PolicyAction,\n\tstats: PolicyHandlerPerfStats,\n\trun: () => Operation<T>,\n): Operation<T> {\n\tconst actionMap = stats.data.get(action) ?? new Map<string, number>();\n\tlet dur = actionMap.get(name) ?? 0;\n\n\tconst start = Date.now();\n\tconst result = yield* run();\n\tdur += Date.now() - start;\n\n\tactionMap.set(name, dur);\n\tstats.data.set(action, actionMap);\n\treturn result;\n}\n\nexport function logStats(stats: PolicyHandlerPerfStats, log: Logger): void {\n\tlog.log(\n\t\t`Statistics: ${stats.processed} files processed, ` +\n\t\t\t`${stats.count - stats.processed} excluded, ${stats.count} total`,\n\t);\n\tfor (const [action, handlerPerf] of stats.data.entries()) {\n\t\tlog.log(`Performance for \"${action}\":`);\n\t\tfor (const [handler, dur] of handlerPerf.entries()) {\n\t\t\tlog.log(` ${handler}: ${dur}ms`);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"perf.js","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAuBA,MAAM,UAAU,YAAY;IAC3B,OAAO;QACN,KAAK,EAAE,CAAC;QACR,SAAS,EAAE,CAAC;QACZ,IAAI,EAAE,IAAI,GAAG,EAA+C;KAC5D,CAAC;AACH,CAAC;AAED,MAAM,SAAS,CAAC,CAAC,WAAW,CAC3B,IAAY,EACZ,MAAoB,EACpB,KAA6B,EAC7B,GAAuB;IAEvB,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,IAAI,CAAC;QACJ,OAAO,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC;IACrB,CAAC;YAAS,CAAC;QACV,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,GAAG,EAAkB,CAAC;QACtE,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;QAC5E,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACnC,CAAC;AACF,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAA6B,EAAE,GAAW;IAClE,GAAG,CAAC,GAAG,CACN,eAAe,KAAK,CAAC,SAAS,oBAAoB;QACjD,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,SAAS,cAAc,KAAK,CAAC,KAAK,QAAQ,CAClE,CAAC;IACF,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1D,GAAG,CAAC,GAAG,CAAC,oBAAoB,MAAM,IAAI,CAAC,CAAC;QACxC,KAAK,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;YACpD,GAAG,CAAC,GAAG,CAAC,OAAO,OAAO,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC3D,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import type { Logger } from \"@tylerbu/cli-api\";\nimport type { Operation } from \"effection\";\nimport type { PolicyInstanceId } from \"./policy.js\";\n\n/**\n * The type of action a policy can perform.\n * @public\n */\nexport type PolicyAction = \"check\" | \"resolve\" | \"handle\";\n\n/**\n * Stores performance data for each handler. Used to collect and display performance stats.\n * @public\n */\nexport interface PolicyHandlerPerfStats {\n\t/** Number of candidate file paths supplied to the runner. */\n\tcount: number;\n\t/** Number of candidate files admitted past global exclusions. */\n\tprocessed: number;\n\t/** Total elapsed milliseconds per action and configured policy instance. */\n\tdata: Map<PolicyAction, Map<PolicyInstanceId, number>>;\n}\n\nexport function newPerfStats(): PolicyHandlerPerfStats {\n\treturn {\n\t\tcount: 0,\n\t\tprocessed: 0,\n\t\tdata: new Map<PolicyAction, Map<PolicyInstanceId, number>>(),\n\t};\n}\n\nexport function* runWithPerf<T>(\n\tname: string,\n\taction: PolicyAction,\n\tstats: PolicyHandlerPerfStats,\n\trun: () => Operation<T>,\n): Operation<T> {\n\tconst start = performance.now();\n\ttry {\n\t\treturn yield* run();\n\t} finally {\n\t\tconst actionMap = stats.data.get(action) ?? new Map<string, number>();\n\t\tactionMap.set(name, (actionMap.get(name) ?? 0) + performance.now() - start);\n\t\tstats.data.set(action, actionMap);\n\t}\n}\n\nexport function logStats(stats: PolicyHandlerPerfStats, log: Logger): void {\n\tlog.log(\n\t\t`Statistics: ${stats.processed} files processed, ` +\n\t\t\t`${stats.count - stats.processed} excluded, ${stats.count} total`,\n\t);\n\tfor (const [action, handlerPerf] of stats.data.entries()) {\n\t\tlog.log(`Performance for \"${action}\":`);\n\t\tfor (const [handler, dur] of handlerPerf.entries()) {\n\t\t\tlog.log(` ${handler}: ${Math.round(dur * 10) / 10}ms`);\n\t\t}\n\t}\n}\n"]}
@@ -1,8 +1,8 @@
1
- import type { PolicyShape } from "../policy.js";
1
+ import type { FilePolicyDefinition } from "../policy.js";
2
2
  /**
3
3
  * Configuration for the CargoLicenceValidated policy.
4
4
  *
5
- * @alpha
5
+ * @public
6
6
  */
7
7
  export interface CargoLicenceValidatedConfig {
8
8
  /**
@@ -35,7 +35,7 @@ export interface CargoLicenceValidatedConfig {
35
35
  * `licences`). This policy validates that the value is a recognized SPDX
36
36
  * identifier and can auto-fix common mistakes like wrong casing.
37
37
  *
38
- * @alpha
38
+ * @public
39
39
  */
40
- export declare const CargoLicenceValidated: PolicyShape<CargoLicenceValidatedConfig>;
40
+ export declare const CargoLicenceValidated: FilePolicyDefinition<CargoLicenceValidatedConfig>;
41
41
  //# sourceMappingURL=CargoLicenceValidated.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CargoLicenceValidated.d.ts","sourceRoot":"","sources":["../../src/policies/CargoLicenceValidated.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAOhD;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC3C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAKD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,2BAA2B,CAuCxE,CAAC"}
1
+ {"version":3,"file":"CargoLicenceValidated.d.ts","sourceRoot":"","sources":["../../src/policies/CargoLicenceValidated.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOzD;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC3C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAKD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,mDAsC4B,CAAC"}