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
@@ -1,7 +1,10 @@
1
1
  import { call } from "effection";
2
2
  import jsonfile from "jsonfile";
3
- import { resolve } from "pathe";
3
+ import { ExecutionContractError } from "../executionContractError.js";
4
+ import { readParsedFile } from "../fileCache.js";
4
5
  import { PackageJsonRegexMatch } from "../policies/constants.js";
6
+ import { settlePolicyPromise } from "../settlePolicyPromise.js";
7
+ import { resolveRepoFilePath } from "../utils/safePaths.js";
5
8
  const { readFile: readJson } = jsonfile;
6
9
  /**
7
10
  * Type guard to check if a value is an Effection Operation (generator).
@@ -12,29 +15,6 @@ function isOperation(value) {
12
15
  "next" in value &&
13
16
  typeof value.next === "function");
14
17
  }
15
- /**
16
- * Define a repo policy for package.json files.
17
- *
18
- * @remarks
19
- * This is a helper function that creates a policy pre-configured to match
20
- * package.json files. The handler receives the parsed JSON content.
21
- *
22
- * @example
23
- * ```typescript
24
- * const MyPackagePolicy = definePackagePolicy({
25
- * name: "MyPackagePolicy",
26
- * description: "Ensures package.json has required fields",
27
- * handler: async (json, { file }) => {
28
- * if (!json.name) {
29
- * return { error: "Missing name", fixable: false };
30
- * }
31
- * return true;
32
- * },
33
- * });
34
- * ```
35
- *
36
- * @alpha
37
- */
38
18
  export function definePackagePolicy(args) {
39
19
  const { name, description, handler: packageHandler, defaultConfig } = args;
40
20
  return {
@@ -42,25 +22,22 @@ export function definePackagePolicy(args) {
42
22
  description,
43
23
  match: PackageJsonRegexMatch,
44
24
  defaultConfig,
25
+ requiresConfig: args.requiresConfig,
45
26
  handler: function* (innerArgs) {
46
- const json = yield* call(() => readJson(resolve(innerArgs.root, innerArgs.file)));
27
+ const filePath = resolveRepoFilePath(innerArgs.root, innerArgs.file);
28
+ const json = yield* call(() => readParsedFile(innerArgs, "json", () => readJson(filePath)));
47
29
  const result = packageHandler(json, innerArgs);
48
30
  // Handle both Operation (generator) and Promise return types
49
31
  if (result instanceof Promise) {
50
- return yield* call(() => result);
32
+ return yield* settlePolicyPromise(result);
51
33
  }
52
34
  // Check if it's an Effection Operation (generator)
53
35
  if (isOperation(result)) {
54
36
  return yield* result;
55
37
  }
56
38
  // This should never happen with proper handler typing
57
- throw new Error(`Unexpected handler result type: ${typeof result}`);
39
+ throw new ExecutionContractError(`Unexpected handler result type: ${typeof result}`);
58
40
  },
59
41
  };
60
42
  }
61
- /**
62
- * Alias for definePackagePolicy.
63
- * @alpha
64
- */
65
- export const packagePolicy = definePackagePolicy;
66
43
  //# sourceMappingURL=definePackagePolicy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"definePackagePolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/definePackagePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AACjD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAOjE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC;AAmBxC;;GAEG;AACH,SAAS,WAAW,CAAI,KAAc;IACrC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAA2B,CAAC,IAAI,KAAK,UAAU,CACvD,CAAC;AACH,CAAC;AA6BD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,mBAAmB,CAClC,IAAmC;IAEnC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IAC3E,OAAO;QACN,IAAI;QACJ,WAAW;QACX,KAAK,EAAE,qBAAqB;QAC5B,aAAa;QACb,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS;YAC5B,MAAM,IAAI,GAAM,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAChC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CACjD,CAAC;YACF,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAE/C,6DAA6D;YAC7D,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;YAClC,CAAC;YACD,mDAAmD;YACnD,IAAI,WAAW,CAAsB,MAAM,CAAC,EAAE,CAAC;gBAC9C,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC;YACtB,CAAC;YACD,sDAAsD;YACtD,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,MAAM,EAAE,CAAC,CAAC;QACrE,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC","sourcesContent":["import { call, type Operation } from \"effection\";\nimport jsonfile from \"jsonfile\";\nimport { resolve } from \"pathe\";\nimport type { PackageJson } from \"type-fest\";\nimport { PackageJsonRegexMatch } from \"../policies/constants.js\";\nimport type {\n\tPolicyArgs,\n\tPolicyHandlerResult,\n\tPolicyShape,\n} from \"../policy.js\";\n\nconst { readFile: readJson } = jsonfile;\n\n/**\n * A policy handler especially for policies that target package.json.\n *\n * @remarks\n * Package JSON 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 to allow gradual migration and flexibility.\n *\n * @alpha\n */\nexport type PackageJsonHandler<J, C> = (\n\tjson: J,\n\targs: PolicyArgs<C>,\n) => Operation<PolicyHandlerResult> | Promise<PolicyHandlerResult>;\n\n/**\n * Type guard to check if a value is an Effection Operation (generator).\n */\nfunction isOperation<T>(value: unknown): value is Operation<T> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"next\" in value &&\n\t\ttypeof (value as { next: unknown }).next === \"function\"\n\t);\n}\n\n/**\n * Input arguments for defining a package.json policy.\n *\n * @alpha\n */\nexport interface DefinePackagePolicyArgs<J, C> {\n\t/**\n\t * The name of the policy.\n\t */\n\tname: string;\n\n\t/**\n\t * A description of the policy's purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * The handler function that receives the parsed package.json and policy arguments.\n\t */\n\thandler: PackageJsonHandler<J, C>;\n\n\t/**\n\t * Optional default configuration for the policy.\n\t */\n\tdefaultConfig?: C;\n}\n\n/**\n * Define a repo policy for package.json files.\n *\n * @remarks\n * This is a helper function that creates a policy pre-configured to match\n * package.json files. The handler receives the parsed JSON content.\n *\n * @example\n * ```typescript\n * const MyPackagePolicy = definePackagePolicy({\n * name: \"MyPackagePolicy\",\n * description: \"Ensures package.json has required fields\",\n * handler: async (json, { file }) => {\n * if (!json.name) {\n * return { error: \"Missing name\", fixable: false };\n * }\n * return true;\n * },\n * });\n * ```\n *\n * @alpha\n */\nexport function definePackagePolicy<J = PackageJson, C = undefined>(\n\targs: DefinePackagePolicyArgs<J, C>,\n): PolicyShape<C> {\n\tconst { name, description, handler: packageHandler, defaultConfig } = args;\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: PackageJsonRegexMatch,\n\t\tdefaultConfig,\n\t\thandler: function* (innerArgs) {\n\t\t\tconst json: J = yield* call(() =>\n\t\t\t\treadJson(resolve(innerArgs.root, innerArgs.file)),\n\t\t\t);\n\t\t\tconst result = packageHandler(json, innerArgs);\n\n\t\t\t// Handle both Operation (generator) and Promise return types\n\t\t\tif (result instanceof Promise) {\n\t\t\t\treturn yield* call(() => result);\n\t\t\t}\n\t\t\t// Check if it's an Effection Operation (generator)\n\t\t\tif (isOperation<PolicyHandlerResult>(result)) {\n\t\t\t\treturn yield* result;\n\t\t\t}\n\t\t\t// This should never happen with proper handler typing\n\t\t\tthrow new Error(`Unexpected handler result type: ${typeof result}`);\n\t\t},\n\t};\n}\n\n/**\n * Alias for definePackagePolicy.\n * @alpha\n */\nexport const packagePolicy = definePackagePolicy;\n"]}
1
+ {"version":3,"file":"definePackagePolicy.js","sourceRoot":"","sources":["../../src/policyDefiners/definePackagePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AACjD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAOjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC;AAmBxC;;GAEG;AACH,SAAS,WAAW,CAAI,KAAc;IACrC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAA2B,CAAC,IAAI,KAAK,UAAU,CACvD,CAAC;AACH,CAAC;AAmED,MAAM,UAAU,mBAAmB,CAClC,IAAmC;IAEnC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IAC3E,OAAO;QACN,IAAI;QACJ,WAAW;QACX,KAAK,EAAE,qBAAqB;QAC5B,aAAa;QACb,cAAc,EAAE,IAAI,CAAC,cAAc;QACnC,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS;YAC5B,MAAM,QAAQ,GAAG,mBAAmB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;YACrE,MAAM,IAAI,GAAM,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAChC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAC3D,CAAC;YACF,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAE/C,6DAA6D;YAC7D,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;YAC3C,CAAC;YACD,mDAAmD;YACnD,IAAI,WAAW,CAAe,MAAM,CAAC,EAAE,CAAC;gBACvC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC;YACtB,CAAC;YACD,sDAAsD;YACtD,MAAM,IAAI,sBAAsB,CAC/B,mCAAmC,OAAO,MAAM,EAAE,CAClD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { call, type Operation } from \"effection\";\nimport jsonfile from \"jsonfile\";\nimport type { PackageJson } from \"type-fest\";\nimport { ExecutionContractError } from \"../executionContractError.js\";\nimport { readParsedFile } from \"../fileCache.js\";\nimport { PackageJsonRegexMatch } from \"../policies/constants.js\";\nimport type {\n\tDefinedConfig,\n\tFilePolicyDefinition,\n\tPolicyArgs,\n\tPolicyResult,\n} from \"../policy.js\";\nimport { settlePolicyPromise } from \"../settlePolicyPromise.js\";\nimport { resolveRepoFilePath } from \"../utils/safePaths.js\";\n\nconst { readFile: readJson } = jsonfile;\n\n/**\n * A policy handler especially for policies that target package.json.\n *\n * @remarks\n * Package JSON 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 to allow gradual migration and flexibility.\n *\n * @public\n */\nexport type PackageJsonHandler<J, C> = (\n\tjson: J,\n\targs: PolicyArgs<C>,\n) => Operation<PolicyResult> | Promise<PolicyResult>;\n\n/**\n * Type guard to check if a value is an Effection Operation (generator).\n */\nfunction isOperation<T>(value: unknown): value is Operation<T> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"next\" in value &&\n\t\ttypeof (value as { next: unknown }).next === \"function\"\n\t);\n}\n\n/**\n * Input arguments for defining a package.json policy.\n *\n * @public\n */\nexport interface DefinePackagePolicyArgs<J, C> {\n\t/**\n\t * The name of the policy.\n\t */\n\tname: string;\n\n\t/**\n\t * A description of the policy's purpose.\n\t */\n\tdescription: string;\n\n\t/**\n\t * The handler function that receives the parsed package.json and policy arguments.\n\t */\n\thandler: PackageJsonHandler<J, C>;\n\n\t/**\n\t * Optional default configuration for the policy.\n\t */\n\tdefaultConfig?: C;\n\trequiresConfig?: boolean;\n}\n\n/**\n * Define a repo policy for package.json files.\n *\n * @remarks\n * This is a helper function that creates a policy pre-configured to match\n * package.json files. The handler receives the parsed JSON content.\n *\n * @param args - Policy metadata, parsed-JSON handler, and optional defaults.\n * @returns A file policy that reads and parses matching package.json files.\n *\n * @example\n * ```typescript\n * const MyPackagePolicy = definePackagePolicy({\n * name: \"MyPackagePolicy\",\n * description: \"Ensures package.json has required fields\",\n * handler: async (json, { file }) => {\n * if (!json.name) {\n * return [{ message: \"Missing name\" }];\n * }\n * return [];\n * },\n * });\n * ```\n *\n * @public\n */\nexport function definePackagePolicy<J = PackageJson, C = void>(\n\targs: DefinePackagePolicyArgs<J, C> & { defaultConfig: DefinedConfig<C> },\n): FilePolicyDefinition<C> & { defaultConfig: DefinedConfig<C> };\n/** Define a package policy that requires explicit configuration. @public */\nexport function definePackagePolicy<J = PackageJson, C = void>(\n\targs: DefinePackagePolicyArgs<J, C> & { requiresConfig: true },\n): FilePolicyDefinition<C> & { requiresConfig: true };\n/** Define a package policy with optional configuration. @public */\nexport function definePackagePolicy<J = PackageJson, C = void>(\n\targs: DefinePackagePolicyArgs<J, C>,\n): FilePolicyDefinition<C>;\nexport function definePackagePolicy<J = PackageJson, C = void>(\n\targs: DefinePackagePolicyArgs<J, C>,\n): FilePolicyDefinition<C> {\n\tconst { name, description, handler: packageHandler, defaultConfig } = args;\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\tmatch: PackageJsonRegexMatch,\n\t\tdefaultConfig,\n\t\trequiresConfig: args.requiresConfig,\n\t\thandler: function* (innerArgs) {\n\t\t\tconst filePath = resolveRepoFilePath(innerArgs.root, innerArgs.file);\n\t\t\tconst json: J = yield* call(() =>\n\t\t\t\treadParsedFile(innerArgs, \"json\", () => readJson(filePath)),\n\t\t\t);\n\t\t\tconst result = packageHandler(json, innerArgs);\n\n\t\t\t// Handle both Operation (generator) and Promise return types\n\t\t\tif (result instanceof Promise) {\n\t\t\t\treturn yield* settlePolicyPromise(result);\n\t\t\t}\n\t\t\t// Check if it's an Effection Operation (generator)\n\t\t\tif (isOperation<PolicyResult>(result)) {\n\t\t\t\treturn yield* result;\n\t\t\t}\n\t\t\t// This should never happen with proper handler typing\n\t\t\tthrow new ExecutionContractError(\n\t\t\t\t`Unexpected handler result type: ${typeof result}`,\n\t\t\t);\n\t\t},\n\t};\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { PolicyResult } from "../policy.js";
1
2
  /**
2
3
  * Lazily load spdx-correct. It's an optional peer dependency.
3
4
  *
@@ -41,18 +42,14 @@ export declare function applyCorrections(content: string, corrections: Map<strin
41
42
  *
42
43
  * @internal
43
44
  */
44
- export declare function tryAutoFix(filePath: string, corrections: Map<string, string>, errors: string[]): Promise<{
45
- error: string;
46
- fixable: boolean;
47
- fixed: boolean;
48
- }>;
45
+ export declare function tryAutoFix(filePath: string, corrections: Map<string, string>, errors: string[]): Promise<PolicyResult>;
49
46
  /**
50
47
  * Validate licence identifiers and optionally auto-fix them.
51
48
  *
52
49
  * Combines spdx-correct validation with allowlist checking and auto-fix
53
50
  * into a single helper used by both Cargo and Gleam licence policies.
54
51
  *
55
- * @returns `true` if valid, or a PolicyError-compatible object on failure.
52
+ * @returns An empty array if valid, or findings that describe invalid expressions.
56
53
  * Returns `undefined` if no validation was requested (both allowlist and
57
54
  * validateSpdx are empty/false).
58
55
  *
@@ -65,10 +62,5 @@ export declare function validateLicenceField(options: {
65
62
  shouldResolve: boolean;
66
63
  filePath: string;
67
64
  manualFixMessage: string;
68
- }): Promise<true | {
69
- error: string;
70
- fixable?: boolean;
71
- fixed?: boolean;
72
- manualFix?: string;
73
- } | undefined>;
65
+ }): Promise<PolicyResult>;
74
66
  //# sourceMappingURL=spdxValidator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"spdxValidator.d.ts","sourceRoot":"","sources":["../../src/policyDefiners/spdxValidator.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACtC,OAAO,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAWpC;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACvC,qCAAqC;IACrC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,0DAA0D;IAC1D,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC5C,QAAQ,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,uBAAuB,CAAC,CAqBlC;AAED;;;;GAIG;A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AS,CAAC,CAWpC;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACvC,qCAAqC;IACrC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,0DAA0D;IAC1D,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC5C,QAAQ,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,uBAAuB,CAAC,CAqBlC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,MAAM,EAAE,EAClB,eAAe,EAAE,MAAM,EAAE,GACvB,MAAM,EAAE,CAUV;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC/B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,MAAM,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,YAAY,CAAC,CAqBvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IACnD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC,YAAY,CAAC,CA8CxB"}
@@ -77,14 +77,17 @@ export async function tryAutoFix(filePath, corrections, errors) {
77
77
  const content = await readFile(filePath, "utf-8");
78
78
  const fixed = applyCorrections(content, corrections);
79
79
  await writeFile(filePath, fixed);
80
- return { error: errors.join("; "), fixable: true, fixed: true };
80
+ const correctedMessages = new Set([...corrections].map(([original, corrected]) => `Licence "${original}" should be "${corrected}"`));
81
+ return errors.map((message) => ({
82
+ message,
83
+ fixStatus: correctedMessages.has(message) ? "fixed" : undefined,
84
+ }));
81
85
  }
82
86
  catch {
83
- return {
84
- error: `${errors.join("; ")}. Auto-fix failed.`,
85
- fixable: true,
86
- fixed: false,
87
- };
87
+ return errors.map((message) => ({
88
+ message: `${message}. Auto-fix failed.`,
89
+ fixStatus: "failed",
90
+ }));
88
91
  }
89
92
  }
90
93
  /**
@@ -93,7 +96,7 @@ export async function tryAutoFix(filePath, corrections, errors) {
93
96
  * Combines spdx-correct validation with allowlist checking and auto-fix
94
97
  * into a single helper used by both Cargo and Gleam licence policies.
95
98
  *
96
- * @returns `true` if valid, or a PolicyError-compatible object on failure.
99
+ * @returns An empty array if valid, or findings that describe invalid expressions.
97
100
  * Returns `undefined` if no validation was requested (both allowlist and
98
101
  * validateSpdx are empty/false).
99
102
  *
@@ -105,7 +108,10 @@ export async function validateLicenceField(options) {
105
108
  if (allowedLicences) {
106
109
  const errors = validateAllowlist(licences, allowedLicences);
107
110
  if (errors.length > 0) {
108
- return { error: errors.join("; "), manualFix: manualFixMessage };
111
+ return errors.map((message) => ({
112
+ message,
113
+ manualFix: manualFixMessage,
114
+ }));
109
115
  }
110
116
  }
111
117
  // Validate with spdx-correct
@@ -113,15 +119,21 @@ export async function validateLicenceField(options) {
113
119
  const { errors, corrections } = await validateWithSpdxCorrect(licences);
114
120
  if (errors.length > 0) {
115
121
  if (shouldResolve && corrections.size > 0) {
116
- return tryAutoFix(filePath, corrections, errors);
122
+ const findings = await tryAutoFix(filePath, corrections, errors);
123
+ return findings.map((finding) => ({
124
+ ...finding,
125
+ manualFix: manualFixMessage,
126
+ }));
117
127
  }
118
- return {
119
- error: errors.join("; "),
120
- fixable: corrections.size > 0,
128
+ return errors.map((message) => ({
129
+ message,
130
+ fixStatus: [...corrections].some(([original, corrected]) => message === `Licence "${original}" should be "${corrected}"`)
131
+ ? "available"
132
+ : undefined,
121
133
  manualFix: manualFixMessage,
122
- };
134
+ }));
123
135
  }
124
136
  }
125
- return undefined;
137
+ return [];
126
138
  }
127
139
  //# sourceMappingURL=spdxValidator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spdxValidator.js","sourceRoot":"","sources":["../../src/policyDefiners/spdxValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,OAAe;IAEf,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAExC,CAAC;QACF,MAAM,OAAO,GACZ,GAAG,CAAC,OAAO,IAAK,GAAgD,CAAC;QAClE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAcD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC5C,QAAkB;IAElB,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE9C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAChC,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACnD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,CACV,oBAAoB,OAAO,0EAA0E,CACrG,CAAC;YACF,MAAM;QACP,CAAC;QACD,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,YAAY,OAAO,uCAAuC,CAAC,CAAC;QACzE,CAAC;aAAM,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;YAClC,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CA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C;IACF,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\n\n/**\n * Lazily load spdx-correct. It's an optional peer dependency.\n *\n * @returns The corrected identifier, `null` if unrecognized, or `undefined` if\n * spdx-correct is not installed.\n *\n * @internal\n */\nexport async function tryCorrectLicence(\n\tlicence: string,\n): Promise<string | null | undefined> {\n\ttry {\n\t\tconst mod = (await import(\"spdx-correct\")) as {\n\t\t\tdefault?: (id: string) => string | null;\n\t\t};\n\t\tconst correct =\n\t\t\tmod.default ?? (mod as unknown as (id: string) => string | null);\n\t\treturn correct(licence);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Result of validating licence identifiers with spdx-correct.\n *\n * @internal\n */\nexport interface LicenceValidationResult {\n\t/** Human-readable error messages. */\n\terrors: string[];\n\t/** Map from original identifier to its corrected form. */\n\tcorrections: Map<string, string>;\n}\n\n/**\n * Validate an array of licence identifiers using spdx-correct.\n *\n * @internal\n */\nexport async function validateWithSpdxCorrect(\n\tlicences: string[],\n): Promise<LicenceValidationResult> {\n\tconst errors: string[] = [];\n\tconst corrections = new Map<string, string>();\n\n\tfor (const licence of licences) {\n\t\tconst corrected = await tryCorrectLicence(licence);\n\t\tif (corrected === undefined) {\n\t\t\terrors.push(\n\t\t\t\t`Cannot validate \"${licence}\": spdx-correct is not installed. Install it with: pnpm add spdx-correct`,\n\t\t\t);\n\t\t\tbreak;\n\t\t}\n\t\tif (corrected === null) {\n\t\t\terrors.push(`Licence \"${licence}\" is not a recognized SPDX identifier`);\n\t\t} else if (corrected !== licence) {\n\t\t\tcorrections.set(licence, corrected);\n\t\t\terrors.push(`Licence \"${licence}\" should be \"${corrected}\"`);\n\t\t}\n\t}\n\n\treturn { errors, corrections };\n}\n\n/**\n * Check that all licence identifiers are in the allowed list.\n *\n * @internal\n */\nexport function validateAllowlist(\n\tlicences: string[],\n\tallowedLicences: string[],\n): string[] {\n\tconst errors: string[] = [];\n\tfor (const licence of licences) {\n\t\tif (!allowedLicences.includes(licence)) {\n\t\t\terrors.push(\n\t\t\t\t`Licence \"${licence}\" is not in the allowed list: ${allowedLicences.join(\", \")}`,\n\t\t\t);\n\t\t}\n\t}\n\treturn errors;\n}\n\n/**\n * Replace quoted licence strings in TOML/text content with their corrected forms.\n *\n * @internal\n */\nexport function applyCorrections(\n\tcontent: string,\n\tcorrections: Map<string, string>,\n): string {\n\tlet result = content;\n\tfor (const [original, corrected] of corrections) {\n\t\tresult = result.replace(`\"${original}\"`, `\"${corrected}\"`);\n\t}\n\treturn result;\n}\n\n/**\n * Read a file, apply licence corrections, and write it back.\n *\n * @internal\n */\nexport async function tryAutoFix(\n\tfilePath: string,\n\tcorrections: Map<string, string>,\n\terrors: string[],\n): Promise<{ error: string; fixable: boolean; fixed: boolean }> {\n\ttry {\n\t\tconst content = await readFile(filePath, \"utf-8\");\n\t\tconst fixed = applyCorrections(content, corrections);\n\t\tawait writeFile(filePath, fixed);\n\t\treturn { error: errors.join(\"; \"), fixable: true, fixed: true };\n\t} catch {\n\t\treturn {\n\t\t\terror: `${errors.join(\"; \")}. Auto-fix failed.`,\n\t\t\tfixable: true,\n\t\t\tfixed: false,\n\t\t};\n\t}\n}\n\n/**\n * Validate licence identifiers and optionally auto-fix them.\n *\n * Combines spdx-correct validation with allowlist checking and auto-fix\n * into a single helper used by both Cargo and Gleam licence policies.\n *\n * @returns `true` if valid, or a PolicyError-compatible object on failure.\n * Returns `undefined` if no validation was requested (both allowlist and\n * validateSpdx are empty/false).\n *\n * @internal\n */\nexport async function validateLicenceField(options: {\n\tlicences: string[];\n\tallowedLicences?: string[];\n\tvalidateSpdx: boolean;\n\tshouldResolve: boolean;\n\tfilePath: string;\n\tmanualFixMessage: string;\n}): Promise<\n\t| true\n\t| { error: string; fixable?: boolean; fixed?: boolean; manualFix?: string }\n\t| undefined\n> {\n\tconst {\n\t\tlicences,\n\t\tallowedLicences,\n\t\tvalidateSpdx,\n\t\tshouldResolve,\n\t\tfilePath,\n\t\tmanualFixMessage,\n\t} = options;\n\n\t// Check allowlist first (takes priority)\n\tif (allowedLicences) {\n\t\tconst errors = validateAllowlist(licences, allowedLicences);\n\t\tif (errors.length > 0) {\n\t\t\treturn { error: errors.join(\"; \"), manualFix: manualFixMessage };\n\t\t}\n\t}\n\n\t// Validate with spdx-correct\n\tif (validateSpdx) {\n\t\tconst { errors, corrections } = await validateWithSpdxCorrect(licences);\n\t\tif (errors.length > 0) {\n\t\t\tif (shouldResolve && corrections.size > 0) {\n\t\t\t\treturn tryAutoFix(filePath, corrections, errors);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\terror: errors.join(\"; \"),\n\t\t\t\tfixable: corrections.size > 0,\n\t\t\t\tmanualFix: manualFixMessage,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn undefined;\n}\n"]}
1
+ {"version":3,"file":"spdxValidator.js","sourceRoot":"","sources":["../../src/policyDefiners/spdxValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGvD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,OAAe;IAEf,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAExC,CAAC;QACF,MAAM,OAAO,GACZ,GAAG,CAAC,OAAO,IAAK,GAAgD,CAAC;QAClE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAcD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC5C,QAAkB;IAElB,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE9C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAChC,MAAM,SAAS,G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C;QAC5D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC/B,OAAO;gBACP,SAAS,EAAE,gBAAgB;aAC3B,CAAC,CAAC,CAAC;QACL,CAAC;IACF,CAAC;IAED,6BAA6B;IAC7B,IAAI,YAAY,EAAE,CAAC;QAClB,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QACxE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,IAAI,aAAa,IAAI,WAAW,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;gBAC3C,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;gBACjE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;oBACjC,GAAG,OAAO;oBACV,SAAS,EAAE,gBAAgB;iBAC3B,CAAC,CAAC,CAAC;YACL,CAAC;YACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC/B,OAAO;gBACP,SAAS,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,IAAI,CAC/B,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,EAAE,CACzB,OAAO,KAAK,YAAY,QAAQ,gBAAgB,SAAS,GAAG,CAC7D;oBACA,CAAC,CAAC,WAAW;oBACb,CAAC,CAAC,SAAS;gBACZ,SAAS,EAAE,gBAAgB;aAC3B,CAAC,CAAC,CAAC;QACL,CAAC;IACF,CAAC;IAED,OAAO,EAAE,CAAC;AACX,CAAC","sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\nimport type { PolicyResult } from \"../policy.js\";\n\n/**\n * Lazily load spdx-correct. It's an optional peer dependency.\n *\n * @returns The corrected identifier, `null` if unrecognized, or `undefined` if\n * spdx-correct is not installed.\n *\n * @internal\n */\nexport async function tryCorrectLicence(\n\tlicence: string,\n): Promise<string | null | undefined> {\n\ttry {\n\t\tconst mod = (await import(\"spdx-correct\")) as {\n\t\t\tdefault?: (id: string) => string | null;\n\t\t};\n\t\tconst correct =\n\t\t\tmod.default ?? (mod as unknown as (id: string) => string | null);\n\t\treturn correct(licence);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Result of validating licence identifiers with spdx-correct.\n *\n * @internal\n */\nexport interface LicenceValidationResult {\n\t/** Human-readable error messages. */\n\terrors: string[];\n\t/** Map from original identifier to its corrected form. */\n\tcorrections: Map<string, string>;\n}\n\n/**\n * Validate an array of licence identifiers using spdx-correct.\n *\n * @internal\n */\nexport async function validateWithSpdxCorrect(\n\tlicences: string[],\n): Promise<LicenceValidationResult> {\n\tconst errors: string[] = [];\n\tconst corrections = new Map<string, string>();\n\n\tfor (const licence of licences) {\n\t\tconst corrected = await tryCorrectLicence(licence);\n\t\tif (corrected === undefined) {\n\t\t\terrors.push(\n\t\t\t\t`Cannot validate \"${licence}\": spdx-correct is not installed. Install it with: pnpm add spdx-correct`,\n\t\t\t);\n\t\t\tbreak;\n\t\t}\n\t\tif (corrected === null) {\n\t\t\terrors.push(`Licence \"${licence}\" is not a recognized SPDX identifier`);\n\t\t} else if (corrected !== licence) {\n\t\t\tcorrections.set(licence, corrected);\n\t\t\terrors.push(`Licence \"${licence}\" should be \"${corrected}\"`);\n\t\t}\n\t}\n\n\treturn { errors, corrections };\n}\n\n/**\n * Check that all licence identifiers are in the allowed list.\n *\n * @internal\n */\nexport function validateAllowlist(\n\tlicences: string[],\n\tallowedLicences: string[],\n): string[] {\n\tconst errors: string[] = [];\n\tfor (const licence of licences) {\n\t\tif (!allowedLicences.includes(licence)) {\n\t\t\terrors.push(\n\t\t\t\t`Licence \"${licence}\" is not in the allowed list: ${allowedLicences.join(\", \")}`,\n\t\t\t);\n\t\t}\n\t}\n\treturn errors;\n}\n\n/**\n * Replace quoted licence strings in TOML/text content with their corrected forms.\n *\n * @internal\n */\nexport function applyCorrections(\n\tcontent: string,\n\tcorrections: Map<string, string>,\n): string {\n\tlet result = content;\n\tfor (const [original, corrected] of corrections) {\n\t\tresult = result.replace(`\"${original}\"`, `\"${corrected}\"`);\n\t}\n\treturn result;\n}\n\n/**\n * Read a file, apply licence corrections, and write it back.\n *\n * @internal\n */\nexport async function tryAutoFix(\n\tfilePath: string,\n\tcorrections: Map<string, string>,\n\terrors: string[],\n): Promise<PolicyResult> {\n\ttry {\n\t\tconst content = await readFile(filePath, \"utf-8\");\n\t\tconst fixed = applyCorrections(content, corrections);\n\t\tawait writeFile(filePath, fixed);\n\t\tconst correctedMessages = new Set(\n\t\t\t[...corrections].map(\n\t\t\t\t([original, corrected]) =>\n\t\t\t\t\t`Licence \"${original}\" should be \"${corrected}\"`,\n\t\t\t),\n\t\t);\n\t\treturn errors.map((message) => ({\n\t\t\tmessage,\n\t\t\tfixStatus: correctedMessages.has(message) ? \"fixed\" : undefined,\n\t\t}));\n\t} catch {\n\t\treturn errors.map((message) => ({\n\t\t\tmessage: `${message}. Auto-fix failed.`,\n\t\t\tfixStatus: \"failed\",\n\t\t}));\n\t}\n}\n\n/**\n * Validate licence identifiers and optionally auto-fix them.\n *\n * Combines spdx-correct validation with allowlist checking and auto-fix\n * into a single helper used by both Cargo and Gleam licence policies.\n *\n * @returns An empty array if valid, or findings that describe invalid expressions.\n * Returns `undefined` if no validation was requested (both allowlist and\n * validateSpdx are empty/false).\n *\n * @internal\n */\nexport async function validateLicenceField(options: {\n\tlicences: string[];\n\tallowedLicences?: string[];\n\tvalidateSpdx: boolean;\n\tshouldResolve: boolean;\n\tfilePath: string;\n\tmanualFixMessage: string;\n}): Promise<PolicyResult> {\n\tconst {\n\t\tlicences,\n\t\tallowedLicences,\n\t\tvalidateSpdx,\n\t\tshouldResolve,\n\t\tfilePath,\n\t\tmanualFixMessage,\n\t} = options;\n\n\t// Check allowlist first (takes priority)\n\tif (allowedLicences) {\n\t\tconst errors = validateAllowlist(licences, allowedLicences);\n\t\tif (errors.length > 0) {\n\t\t\treturn errors.map((message) => ({\n\t\t\t\tmessage,\n\t\t\t\tmanualFix: manualFixMessage,\n\t\t\t}));\n\t\t}\n\t}\n\n\t// Validate with spdx-correct\n\tif (validateSpdx) {\n\t\tconst { errors, corrections } = await validateWithSpdxCorrect(licences);\n\t\tif (errors.length > 0) {\n\t\t\tif (shouldResolve && corrections.size > 0) {\n\t\t\t\tconst findings = await tryAutoFix(filePath, corrections, errors);\n\t\t\t\treturn findings.map((finding) => ({\n\t\t\t\t\t...finding,\n\t\t\t\t\tmanualFix: manualFixMessage,\n\t\t\t\t}));\n\t\t\t}\n\t\t\treturn errors.map((message) => ({\n\t\t\t\tmessage,\n\t\t\t\tfixStatus: [...corrections].some(\n\t\t\t\t\t([original, corrected]) =>\n\t\t\t\t\t\tmessage === `Licence \"${original}\" should be \"${corrected}\"`,\n\t\t\t\t)\n\t\t\t\t\t? \"available\"\n\t\t\t\t\t: undefined,\n\t\t\t\tmanualFix: manualFixMessage,\n\t\t\t}));\n\t\t}\n\t}\n\n\treturn [];\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import type { Operation } from "effection";
2
+ import { type ParsedFileCache } from "./fileCache.js";
3
+ import type { IdentifiedPolicy } from "./policy.js";
4
+ import type { PolicyRunResults } from "./runner.js";
5
+ /** Describe thrown values without allowing hostile coercion to discard a run. */
6
+ export declare function executionMessage(cause: unknown): string;
7
+ /** Internal single-policy execution; engines own matching and scheduling. */
8
+ export declare class PolicyExecutor {
9
+ private readonly root;
10
+ private readonly fix;
11
+ constructor(root: string, fix: boolean);
12
+ repository(policy: Extract<IdentifiedPolicy, {
13
+ scope: "repository";
14
+ }>, eligible: readonly string[], output: PolicyRunResults): Operation<boolean>;
15
+ file(file: string, policy: Exclude<IdentifiedPolicy, {
16
+ scope: "repository";
17
+ }>, output: PolicyRunResults, cache: ParsedFileCache | undefined): Operation<boolean>;
18
+ }
19
+ //# sourceMappingURL=policyExecution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policyExecution.d.ts","sourceRoot":"","sources":["../src/policyExecution.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,KAAK,EAAE,gBAAgB,EAAgB,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAsHpD,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAgBvD;AAuBD,6EAA6E;AAC7E,qBAAa,cAAc;IAEzB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBADH,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,OAAO;IAGtB,UAAU,CACjB,MAAM,EAAE,OAAO,CAAC,gBAAgB,EAAE;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC,EAC1D,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,MAAM,EAAE,gBAAgB,GACtB,SAAS,CAAC,OAAO,CAAC;IAyCb,IAAI,CACX,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,CAAC,gBAAgB,EAAE;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC,EAC1D,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,eAAe,GAAG,SAAS,GAChC,SAAS,CAAC,OAAO,CAAC;CA0ErB"}
@@ -0,0 +1,224 @@
1
+ import { types } from "node:util";
2
+ import { ExecutionContractError } from "./executionContractError.js";
3
+ import { fileCache } from "./fileCache.js";
4
+ import { runWithPerf } from "./perf.js";
5
+ import { settlePolicyPromise } from "./settlePolicyPromise.js";
6
+ const windowsAbsolutePath = /^[A-Za-z]:/;
7
+ function* execute(handler) {
8
+ const execution = handler();
9
+ if (execution instanceof Promise) {
10
+ return yield* settlePolicyPromise(execution);
11
+ }
12
+ if (typeof execution === "object" &&
13
+ execution !== null &&
14
+ Symbol.iterator in execution &&
15
+ !Array.isArray(execution)) {
16
+ return yield* execution;
17
+ }
18
+ throw new ExecutionContractError("Handlers and resolvers must be async functions or Effection generators.");
19
+ }
20
+ function validPath(path) {
21
+ return (typeof path === "string" &&
22
+ path.length > 0 &&
23
+ !path.includes("\\") &&
24
+ !path.includes("\0") &&
25
+ !path.startsWith("/") &&
26
+ !windowsAbsolutePath.test(path) &&
27
+ path
28
+ .split("/")
29
+ .every((part) => part !== "" && part !== "." && part !== ".."));
30
+ }
31
+ function validateResult(result, repository, fix) {
32
+ const invalid = () => new ExecutionContractError("Policy handlers and resolvers must return readonly PolicyFinding[] with message, optional manualFix, fixStatus and repository-only files; legacy results are not supported.");
33
+ if (!Array.isArray(result)) {
34
+ throw invalid();
35
+ }
36
+ for (const finding of result) {
37
+ if (typeof finding !== "object" ||
38
+ finding === null ||
39
+ Array.isArray(finding) ||
40
+ Reflect.ownKeys(finding).some((key) => typeof key !== "string" ||
41
+ !["message", "manualFix", "fixStatus", "files"].includes(key)) ||
42
+ !("message" in finding) ||
43
+ typeof finding.message !== "string" ||
44
+ finding.message.length === 0 ||
45
+ ("manualFix" in finding &&
46
+ finding.manualFix !== undefined &&
47
+ typeof finding.manualFix !== "string") ||
48
+ ("fixStatus" in finding &&
49
+ finding.fixStatus !== undefined &&
50
+ !["available", "fixed", "failed"].includes(finding.fixStatus)) ||
51
+ (!fix &&
52
+ (finding.fixStatus === "fixed" || finding.fixStatus === "failed")) ||
53
+ ("files" in finding &&
54
+ !(repository &&
55
+ (finding.files === undefined ||
56
+ (Array.isArray(finding.files) && finding.files.every(validPath)))))) {
57
+ throw invalid();
58
+ }
59
+ }
60
+ }
61
+ function mergeFindings(checked, resolved) {
62
+ // Omission is not resolution; messages identify independent findings.
63
+ const merged = [...checked];
64
+ const used = new Set();
65
+ for (const finding of resolved) {
66
+ const index = checked.findIndex((previous, candidateIndex) => !used.has(candidateIndex) && previous.message === finding.message);
67
+ if (index === -1) {
68
+ merged.push(finding);
69
+ }
70
+ else if (merged[index]?.fixStatus !== "fixed") {
71
+ merged[index] = { ...merged[index], ...finding };
72
+ used.add(index);
73
+ }
74
+ }
75
+ return merged;
76
+ }
77
+ function nativeErrorMessage(cause) {
78
+ let current = cause;
79
+ while (current && !types.isProxy(current)) {
80
+ const descriptor = Object.getOwnPropertyDescriptor(current, "message");
81
+ if (descriptor) {
82
+ return "value" in descriptor && typeof descriptor.value === "string"
83
+ ? descriptor.value
84
+ : undefined;
85
+ }
86
+ current = Object.getPrototypeOf(current);
87
+ }
88
+ return undefined;
89
+ }
90
+ /** Describe thrown values without allowing hostile coercion to discard a run. */
91
+ export function executionMessage(cause) {
92
+ try {
93
+ if (cause === null ||
94
+ (typeof cause !== "object" && typeof cause !== "function")) {
95
+ return String(cause);
96
+ }
97
+ const message = !types.isProxy(cause) && types.isNativeError(cause)
98
+ ? nativeErrorMessage(cause)
99
+ : undefined;
100
+ return message ?? "Policy threw a non-Error or uninspectable value.";
101
+ }
102
+ catch {
103
+ return "Policy threw a value that cannot be inspected.";
104
+ }
105
+ }
106
+ function errorKind(cause) {
107
+ try {
108
+ if (cause === null ||
109
+ (typeof cause !== "object" && typeof cause !== "function")) {
110
+ return "exception";
111
+ }
112
+ let current = cause;
113
+ while (current && !types.isProxy(current)) {
114
+ if (current === ExecutionContractError.prototype) {
115
+ return "contract";
116
+ }
117
+ current = Object.getPrototypeOf(current);
118
+ }
119
+ return "exception";
120
+ }
121
+ catch {
122
+ return "exception";
123
+ }
124
+ }
125
+ /** Internal single-policy execution; engines own matching and scheduling. */
126
+ export class PolicyExecutor {
127
+ root;
128
+ fix;
129
+ constructor(root, fix) {
130
+ this.root = root;
131
+ this.fix = fix;
132
+ }
133
+ *repository(policy, eligible, output) {
134
+ try {
135
+ const findings = yield* runWithPerf(policy.instanceId, "handle", output.perfStats, () => execute(() => policy.handler({
136
+ files: eligible,
137
+ root: this.root,
138
+ resolve: this.fix,
139
+ config: policy.config,
140
+ })));
141
+ validateResult(findings, true, this.fix);
142
+ for (const finding of findings) {
143
+ output.findings.push({
144
+ ...finding,
145
+ scope: "repository",
146
+ policy: policy.name,
147
+ policyId: policy.instanceId,
148
+ });
149
+ }
150
+ }
151
+ catch (cause) {
152
+ output.errors.push({
153
+ scope: "repository",
154
+ files: eligible,
155
+ policy: policy.name,
156
+ policyId: policy.instanceId,
157
+ phase: "handle",
158
+ kind: errorKind(cause),
159
+ message: executionMessage(cause),
160
+ cause,
161
+ });
162
+ return this.fix;
163
+ }
164
+ return false;
165
+ }
166
+ *file(file, policy, output, cache) {
167
+ let stopped = false;
168
+ let phase = "handle";
169
+ let checked = [];
170
+ try {
171
+ const args = {
172
+ file,
173
+ root: this.root,
174
+ resolve: this.fix,
175
+ config: policy.config,
176
+ [fileCache]: cache,
177
+ };
178
+ checked = yield* runWithPerf(policy.instanceId, "handle", output.perfStats, () => execute(() => policy.handler(args)));
179
+ validateResult(checked, false, this.fix);
180
+ if (this.fix &&
181
+ checked.length > 0 &&
182
+ policy.resolver &&
183
+ !checked.some((finding) => finding.fixStatus === "fixed" || finding.fixStatus === "failed")) {
184
+ phase = "resolve";
185
+ const resolver = policy.resolver;
186
+ const resolved = yield* runWithPerf(policy.instanceId, "resolve", output.perfStats, () => execute(() => resolver({
187
+ file,
188
+ root: args.root,
189
+ config: args.config,
190
+ findings: checked.map((finding) => ({ ...finding })),
191
+ })));
192
+ validateResult(resolved, false, true);
193
+ checked = mergeFindings(checked, resolved);
194
+ }
195
+ }
196
+ catch (cause) {
197
+ output.errors.push({
198
+ scope: "file",
199
+ file,
200
+ policy: policy.name,
201
+ policyId: policy.instanceId,
202
+ phase,
203
+ kind: errorKind(cause),
204
+ message: executionMessage(cause),
205
+ cause,
206
+ });
207
+ stopped = this.fix;
208
+ if (phase === "handle") {
209
+ checked = [];
210
+ }
211
+ }
212
+ for (const { files: _files, ...finding } of checked) {
213
+ output.findings.push({
214
+ ...finding,
215
+ scope: "file",
216
+ file,
217
+ policy: policy.name,
218
+ policyId: policy.instanceId,
219
+ });
220
+ }
221
+ return stopped;
222
+ }
223
+ }
224
+ //# sourceMappingURL=policyExecution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policyExecution.js","sourceRoot":"","sources":["../src/policyExecution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,SAAS,EAAwB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAEzC,QAAQ,CAAC,CAAC,OAAO,CAAI,OAAwC;IAC5D,MAAM,SAAS,GAAG,OAAO,EAAE,CAAC;IAC5B,IAAI,SAAS,YAAY,OAAO,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;IACD,IACC,OAAO,SAAS,KAAK,QAAQ;QAC7B,SAAS,KAAK,IAAI;QAClB,MAAM,CAAC,QAAQ,IAAI,SAAS;QAC5B,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EACxB,CAAC;QACF,OAAO,KAAK,CAAC,CAAC,SAAS,CAAC;IACzB,CAAC;IACD,MAAM,IAAI,sBAAsB,CAC/B,yEAAyE,CACzE,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,IAAa;IAC/B,OAAO,CACN,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,CAAC,MAAM,GAAG,CAAC;QACf,CAAC,IAAI,CAAC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CAAC;gBACtB,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC;gBAChC,KAAK;aACL,CAAC,CAAC;YACH,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC;YACnB,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACxB,OAAO,GAAG,EAAE,CAAC;YACd,CAAC;QACF,CAAC;QACD,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,IAAI,OAAO,EAAE,CAAC;YACrD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACpB,GAAG,OAAO;gBACV,KAAK,EAAE,MAAM;gBACb,IAAI;gBACJ,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,QAAQ,EAAE,MAAM,CAAC,UAAU;aAC3B,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;CACD","sourcesContent":["import { types } from \"node:util\";\nimport type { Operation } from \"effection\";\nimport { ExecutionContractError } from \"./executionContractError.js\";\nimport { fileCache, type ParsedFileCache } from \"./fileCache.js\";\nimport { runWithPerf } from \"./perf.js\";\nimport type { IdentifiedPolicy, PolicyResult } from \"./policy.js\";\nimport type { PolicyRunResults } from \"./runner.js\";\nimport { settlePolicyPromise } from \"./settlePolicyPromise.js\";\n\nconst windowsAbsolutePath = /^[A-Za-z]:/;\n\nfunction* execute<T>(handler: () => Promise<T> | Operation<T>): Operation<T> {\n\tconst execution = handler();\n\tif (execution instanceof Promise) {\n\t\treturn yield* settlePolicyPromise(execution);\n\t}\n\tif (\n\t\ttypeof execution === \"object\" &&\n\t\texecution !== null &&\n\t\tSymbol.iterator in execution &&\n\t\t!Array.isArray(execution)\n\t) {\n\t\treturn yield* execution;\n\t}\n\tthrow new ExecutionContractError(\n\t\t\"Handlers and resolvers must be async functions or Effection generators.\",\n\t);\n}\n\nfunction validPath(path: unknown): path is string {\n\treturn (\n\t\ttypeof path === \"string\" &&\n\t\tpath.length > 0 &&\n\t\t!path.includes(\"\\\\\") &&\n\t\t!path.includes(\"\\0\") &&\n\t\t!path.startsWith(\"/\") &&\n\t\t!windowsAbsolutePath.test(path) &&\n\t\tpath\n\t\t\t.split(\"/\")\n\t\t\t.every((part) => part !== \"\" && part !== \".\" && part !== \"..\")\n\t);\n}\n\nfunction validateResult(\n\tresult: unknown,\n\trepository: boolean,\n\tfix: boolean,\n): asserts result is PolicyResult {\n\tconst invalid = () =>\n\t\tnew ExecutionContractError(\n\t\t\t\"Policy handlers and resolvers must return readonly PolicyFinding[] with message, optional manualFix, fixStatus and repository-only files; legacy results are not supported.\",\n\t\t);\n\tif (!Array.isArray(result)) {\n\t\tthrow invalid();\n\t}\n\tfor (const finding of result) {\n\t\tif (\n\t\t\ttypeof finding !== \"object\" ||\n\t\t\tfinding === null ||\n\t\t\tArray.isArray(finding) ||\n\t\t\tReflect.ownKeys(finding).some(\n\t\t\t\t(key) =>\n\t\t\t\t\ttypeof key !== \"string\" ||\n\t\t\t\t\t![\"message\", \"manualFix\", \"fixStatus\", \"files\"].includes(key),\n\t\t\t) ||\n\t\t\t!(\"message\" in finding) ||\n\t\t\ttypeof finding.message !== \"string\" ||\n\t\t\tfinding.message.length === 0 ||\n\t\t\t(\"manualFix\" in finding &&\n\t\t\t\tfinding.manualFix !== undefined &&\n\t\t\t\ttypeof finding.manualFix !== \"string\") ||\n\t\t\t(\"fixStatus\" in finding &&\n\t\t\t\tfinding.fixStatus !== undefined &&\n\t\t\t\t![\"available\", \"fixed\", \"failed\"].includes(finding.fixStatus)) ||\n\t\t\t(!fix &&\n\t\t\t\t(finding.fixStatus === \"fixed\" || finding.fixStatus === \"failed\")) ||\n\t\t\t(\"files\" in finding &&\n\t\t\t\t!(\n\t\t\t\t\trepository &&\n\t\t\t\t\t(finding.files === undefined ||\n\t\t\t\t\t\t(Array.isArray(finding.files) && finding.files.every(validPath)))\n\t\t\t\t))\n\t\t) {\n\t\t\tthrow invalid();\n\t\t}\n\t}\n}\n\nfunction mergeFindings(\n\tchecked: PolicyResult,\n\tresolved: PolicyResult,\n): PolicyResult {\n\t// Omission is not resolution; messages identify independent findings.\n\tconst merged = [...checked];\n\tconst used = new Set<number>();\n\tfor (const finding of resolved) {\n\t\tconst index = checked.findIndex(\n\t\t\t(previous, candidateIndex) =>\n\t\t\t\t!used.has(candidateIndex) && previous.message === finding.message,\n\t\t);\n\t\tif (index === -1) {\n\t\t\tmerged.push(finding);\n\t\t} else if (merged[index]?.fixStatus !== \"fixed\") {\n\t\t\tmerged[index] = { ...merged[index], ...finding };\n\t\t\tused.add(index);\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction nativeErrorMessage(cause: object): string | undefined {\n\tlet current: object | null = cause;\n\twhile (current && !types.isProxy(current)) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(current, \"message\");\n\t\tif (descriptor) {\n\t\t\treturn \"value\" in descriptor && typeof descriptor.value === \"string\"\n\t\t\t\t? descriptor.value\n\t\t\t\t: undefined;\n\t\t}\n\t\tcurrent = Object.getPrototypeOf(current);\n\t}\n\treturn undefined;\n}\n\n/** Describe thrown values without allowing hostile coercion to discard a run. */\nexport function executionMessage(cause: unknown): string {\n\ttry {\n\t\tif (\n\t\t\tcause === null ||\n\t\t\t(typeof cause !== \"object\" && typeof cause !== \"function\")\n\t\t) {\n\t\t\treturn String(cause);\n\t\t}\n\t\tconst message =\n\t\t\t!types.isProxy(cause) && types.isNativeError(cause)\n\t\t\t\t? nativeErrorMessage(cause)\n\t\t\t\t: undefined;\n\t\treturn message ?? \"Policy threw a non-Error or uninspectable value.\";\n\t} catch {\n\t\treturn \"Policy threw a value that cannot be inspected.\";\n\t}\n}\n\nfunction errorKind(cause: unknown): \"contract\" | \"exception\" {\n\ttry {\n\t\tif (\n\t\t\tcause === null ||\n\t\t\t(typeof cause !== \"object\" && typeof cause !== \"function\")\n\t\t) {\n\t\t\treturn \"exception\";\n\t\t}\n\t\tlet current: object | null = cause;\n\t\twhile (current && !types.isProxy(current)) {\n\t\t\tif (current === ExecutionContractError.prototype) {\n\t\t\t\treturn \"contract\";\n\t\t\t}\n\t\t\tcurrent = Object.getPrototypeOf(current);\n\t\t}\n\t\treturn \"exception\";\n\t} catch {\n\t\treturn \"exception\";\n\t}\n}\n\n/** Internal single-policy execution; engines own matching and scheduling. */\nexport class PolicyExecutor {\n\tpublic constructor(\n\t\tprivate readonly root: string,\n\t\tprivate readonly fix: boolean,\n\t) {}\n\n\tpublic *repository(\n\t\tpolicy: Extract<IdentifiedPolicy, { scope: \"repository\" }>,\n\t\teligible: readonly string[],\n\t\toutput: PolicyRunResults,\n\t): Operation<boolean> {\n\t\ttry {\n\t\t\tconst findings = yield* runWithPerf(\n\t\t\t\tpolicy.instanceId,\n\t\t\t\t\"handle\",\n\t\t\t\toutput.perfStats,\n\t\t\t\t() =>\n\t\t\t\t\texecute(() =>\n\t\t\t\t\t\tpolicy.handler({\n\t\t\t\t\t\t\tfiles: eligible,\n\t\t\t\t\t\t\troot: this.root,\n\t\t\t\t\t\t\tresolve: this.fix,\n\t\t\t\t\t\t\tconfig: policy.config,\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t);\n\t\t\tvalidateResult(findings, true, this.fix);\n\t\t\tfor (const finding of findings) {\n\t\t\t\toutput.findings.push({\n\t\t\t\t\t...finding,\n\t\t\t\t\tscope: \"repository\",\n\t\t\t\t\tpolicy: policy.name,\n\t\t\t\t\tpolicyId: policy.instanceId,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (cause: unknown) {\n\t\t\toutput.errors.push({\n\t\t\t\tscope: \"repository\",\n\t\t\t\tfiles: eligible,\n\t\t\t\tpolicy: policy.name,\n\t\t\t\tpolicyId: policy.instanceId,\n\t\t\t\tphase: \"handle\",\n\t\t\t\tkind: errorKind(cause),\n\t\t\t\tmessage: executionMessage(cause),\n\t\t\t\tcause,\n\t\t\t});\n\t\t\treturn this.fix;\n\t\t}\n\t\treturn false;\n\t}\n\n\tpublic *file(\n\t\tfile: string,\n\t\tpolicy: Exclude<IdentifiedPolicy, { scope: \"repository\" }>,\n\t\toutput: PolicyRunResults,\n\t\tcache: ParsedFileCache | undefined,\n\t): Operation<boolean> {\n\t\tlet stopped = false;\n\t\tlet phase: \"handle\" | \"resolve\" = \"handle\";\n\t\tlet checked: PolicyResult = [];\n\t\ttry {\n\t\t\tconst args = {\n\t\t\t\tfile,\n\t\t\t\troot: this.root,\n\t\t\t\tresolve: this.fix,\n\t\t\t\tconfig: policy.config,\n\t\t\t\t[fileCache]: cache,\n\t\t\t};\n\t\t\tchecked = yield* runWithPerf(\n\t\t\t\tpolicy.instanceId,\n\t\t\t\t\"handle\",\n\t\t\t\toutput.perfStats,\n\t\t\t\t() => execute(() => policy.handler(args)),\n\t\t\t);\n\t\t\tvalidateResult(checked, false, this.fix);\n\t\t\tif (\n\t\t\t\tthis.fix &&\n\t\t\t\tchecked.length > 0 &&\n\t\t\t\tpolicy.resolver &&\n\t\t\t\t!checked.some(\n\t\t\t\t\t(finding) =>\n\t\t\t\t\t\tfinding.fixStatus === \"fixed\" || finding.fixStatus === \"failed\",\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tphase = \"resolve\";\n\t\t\t\tconst resolver = policy.resolver;\n\t\t\t\tconst resolved = yield* runWithPerf(\n\t\t\t\t\tpolicy.instanceId,\n\t\t\t\t\t\"resolve\",\n\t\t\t\t\toutput.perfStats,\n\t\t\t\t\t() =>\n\t\t\t\t\t\texecute(() =>\n\t\t\t\t\t\t\tresolver({\n\t\t\t\t\t\t\t\tfile,\n\t\t\t\t\t\t\t\troot: args.root,\n\t\t\t\t\t\t\t\tconfig: args.config,\n\t\t\t\t\t\t\t\tfindings: checked.map((finding) => ({ ...finding })),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tvalidateResult(resolved, false, true);\n\t\t\t\tchecked = mergeFindings(checked, resolved);\n\t\t\t}\n\t\t} catch (cause: unknown) {\n\t\t\toutput.errors.push({\n\t\t\t\tscope: \"file\",\n\t\t\t\tfile,\n\t\t\t\tpolicy: policy.name,\n\t\t\t\tpolicyId: policy.instanceId,\n\t\t\t\tphase,\n\t\t\t\tkind: errorKind(cause),\n\t\t\t\tmessage: executionMessage(cause),\n\t\t\t\tcause,\n\t\t\t});\n\t\t\tstopped = this.fix;\n\t\t\tif (phase === \"handle\") {\n\t\t\t\tchecked = [];\n\t\t\t}\n\t\t}\n\t\tfor (const { files: _files, ...finding } of checked) {\n\t\t\toutput.findings.push({\n\t\t\t\t...finding,\n\t\t\t\tscope: \"file\",\n\t\t\t\tfile,\n\t\t\t\tpolicy: policy.name,\n\t\t\t\tpolicyId: policy.instanceId,\n\t\t\t});\n\t\t}\n\t\treturn stopped;\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { SimpleGit } from "simple-git";
2
+ /** Git's cached inventory includes unstaged deletions; those are not live files. */
3
+ export declare function readRepositoryFiles(git: SimpleGit): Promise<string[]>;
4
+ //# sourceMappingURL=repositoryFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repositoryFiles.d.ts","sourceRoot":"","sources":["../src/repositoryFiles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,oFAAoF;AACpF,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAQ3E"}
@@ -0,0 +1,8 @@
1
+ import { parseFilePaths } from "./filePaths.js";
2
+ /** Git's cached inventory includes unstaged deletions; those are not live files. */
3
+ export async function readRepositoryFiles(git) {
4
+ const files = parseFilePaths(await git.raw("ls-files", "-co", "-z", "--exclude-standard", "--full-name"));
5
+ const deleted = new Set(parseFilePaths(await git.raw("ls-files", "--deleted", "-z", "--full-name")));
6
+ return files.filter((file) => !deleted.has(file));
7
+ }
8
+ //# sourceMappingURL=repositoryFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repositoryFiles.js","sourceRoot":"","sources":["../src/repositoryFiles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,GAAc;IACvD,MAAM,KAAK,GAAG,cAAc,CAC3B,MAAM,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,oBAAoB,EAAE,aAAa,CAAC,CAC3E,CAAC;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,CACtB,cAAc,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAC3E,CAAC;IACF,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import type { SimpleGit } from \"simple-git\";\nimport { parseFilePaths } from \"./filePaths.js\";\n\n/** Git's cached inventory includes unstaged deletions; those are not live files. */\nexport async function readRepositoryFiles(git: SimpleGit): Promise<string[]> {\n\tconst files = parseFilePaths(\n\t\tawait git.raw(\"ls-files\", \"-co\", \"-z\", \"--exclude-standard\", \"--full-name\"),\n\t);\n\tconst deleted = new Set(\n\t\tparseFilePaths(await git.raw(\"ls-files\", \"--deleted\", \"-z\", \"--full-name\")),\n\t);\n\treturn files.filter((file) => !deleted.has(file));\n}\n"]}