repopo 0.10.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 (340) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +76 -77
  3. package/THIRD-PARTY-LICENSES.txt +232 -14
  4. package/bin/dev.js +5 -1
  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 +1 -1
  14. package/esm/baseCommand.d.ts.map +1 -1
  15. package/esm/baseCommand.js +7 -10
  16. package/esm/baseCommand.js.map +1 -1
  17. package/esm/commands/check-native.d.ts +25 -0
  18. package/esm/commands/check-native.d.ts.map +1 -0
  19. package/esm/commands/check-native.js +156 -0
  20. package/esm/commands/check-native.js.map +1 -0
  21. package/esm/commands/check.d.ts +7 -34
  22. package/esm/commands/check.d.ts.map +1 -1
  23. package/esm/commands/check.js +76 -265
  24. package/esm/commands/check.js.map +1 -1
  25. package/esm/commands/list.d.ts.map +1 -1
  26. package/esm/commands/list.js +6 -6
  27. package/esm/commands/list.js.map +1 -1
  28. package/esm/concurrency.d.ts +3 -0
  29. package/esm/concurrency.d.ts.map +1 -0
  30. package/esm/concurrency.js +8 -0
  31. package/esm/concurrency.js.map +1 -0
  32. package/esm/config.d.ts +5 -39
  33. package/esm/config.d.ts.map +1 -1
  34. package/esm/config.js +3 -7
  35. package/esm/config.js.map +1 -1
  36. package/esm/context.d.ts +20 -3
  37. package/esm/context.d.ts.map +1 -1
  38. package/esm/context.js +18 -1
  39. package/esm/context.js.map +1 -1
  40. package/esm/executionContractError.d.ts +4 -0
  41. package/esm/executionContractError.d.ts.map +1 -0
  42. package/esm/executionContractError.js +4 -0
  43. package/esm/executionContractError.js.map +1 -0
  44. package/esm/fileCache.d.ts +12 -0
  45. package/esm/fileCache.d.ts.map +1 -0
  46. package/esm/fileCache.js +37 -0
  47. package/esm/fileCache.js.map +1 -0
  48. package/esm/filePaths.d.ts +2 -0
  49. package/esm/filePaths.d.ts.map +1 -0
  50. package/esm/filePaths.js +9 -0
  51. package/esm/filePaths.js.map +1 -0
  52. package/esm/generators.d.ts +0 -20
  53. package/esm/generators.d.ts.map +1 -1
  54. package/esm/generators.js.map +1 -1
  55. package/esm/index.d.ts +3 -11
  56. package/esm/index.d.ts.map +1 -1
  57. package/esm/index.js +3 -14
  58. package/esm/index.js.map +1 -1
  59. package/esm/makePolicy.d.ts +26 -79
  60. package/esm/makePolicy.d.ts.map +1 -1
  61. package/esm/makePolicy.js +51 -95
  62. package/esm/makePolicy.js.map +1 -1
  63. package/esm/perf.d.ts +10 -2
  64. package/esm/perf.d.ts.map +1 -1
  65. package/esm/perf.js +10 -9
  66. package/esm/perf.js.map +1 -1
  67. package/esm/policies/CargoLicenceValidated.d.ts +41 -0
  68. package/esm/policies/CargoLicenceValidated.d.ts.map +1 -0
  69. package/esm/policies/CargoLicenceValidated.js +47 -0
  70. package/esm/policies/CargoLicenceValidated.js.map +1 -0
  71. package/esm/policies/CargoLintsConfigured.d.ts +30 -0
  72. package/esm/policies/CargoLintsConfigured.d.ts.map +1 -0
  73. package/esm/policies/CargoLintsConfigured.js +65 -0
  74. package/esm/policies/CargoLintsConfigured.js.map +1 -0
  75. package/esm/policies/CargoLockPolicy.d.ts +34 -0
  76. package/esm/policies/CargoLockPolicy.d.ts.map +1 -0
  77. package/esm/policies/CargoLockPolicy.js +61 -0
  78. package/esm/policies/CargoLockPolicy.js.map +1 -0
  79. package/esm/policies/CargoTomlRequired.d.ts +34 -0
  80. package/esm/policies/CargoTomlRequired.d.ts.map +1 -0
  81. package/esm/policies/CargoTomlRequired.js +77 -0
  82. package/esm/policies/CargoTomlRequired.js.map +1 -0
  83. package/esm/policies/CargoTomlSorted.d.ts +20 -0
  84. package/esm/policies/CargoTomlSorted.d.ts.map +1 -0
  85. package/esm/policies/CargoTomlSorted.js +168 -0
  86. package/esm/policies/CargoTomlSorted.js.map +1 -0
  87. package/esm/policies/ConditionalScripts.d.ts +10 -8
  88. package/esm/policies/ConditionalScripts.d.ts.map +1 -1
  89. package/esm/policies/ConditionalScripts.js +27 -24
  90. package/esm/policies/ConditionalScripts.js.map +1 -1
  91. package/esm/policies/ExactScripts.d.ts +8 -6
  92. package/esm/policies/ExactScripts.d.ts.map +1 -1
  93. package/esm/policies/ExactScripts.js +18 -20
  94. package/esm/policies/ExactScripts.js.map +1 -1
  95. package/esm/policies/GleamDepVersions.d.ts +25 -0
  96. package/esm/policies/GleamDepVersions.d.ts.map +1 -0
  97. package/esm/policies/GleamDepVersions.js +67 -0
  98. package/esm/policies/GleamDepVersions.js.map +1 -0
  99. package/esm/policies/GleamDocExists.d.ts +24 -0
  100. package/esm/policies/GleamDocExists.d.ts.map +1 -0
  101. package/esm/policies/GleamDocExists.js +39 -0
  102. package/esm/policies/GleamDocExists.js.map +1 -0
  103. package/esm/policies/GleamInternalModulesConfigured.d.ts +21 -0
  104. package/esm/policies/GleamInternalModulesConfigured.d.ts.map +1 -0
  105. package/esm/policies/GleamInternalModulesConfigured.js +32 -0
  106. package/esm/policies/GleamInternalModulesConfigured.js.map +1 -0
  107. package/esm/policies/GleamLicenceConfigured.d.ts +29 -0
  108. package/esm/policies/GleamLicenceConfigured.d.ts.map +1 -0
  109. package/esm/policies/GleamLicenceConfigured.js +36 -0
  110. package/esm/policies/GleamLicenceConfigured.js.map +1 -0
  111. package/esm/policies/GleamManifestCommitted.d.ts +16 -0
  112. package/esm/policies/GleamManifestCommitted.d.ts.map +1 -0
  113. package/esm/policies/GleamManifestCommitted.js +27 -0
  114. package/esm/policies/GleamManifestCommitted.js.map +1 -0
  115. package/esm/policies/GleamMonorepoConsistency.d.ts +38 -0
  116. package/esm/policies/GleamMonorepoConsistency.d.ts.map +1 -0
  117. package/esm/policies/GleamMonorepoConsistency.js +74 -0
  118. package/esm/policies/GleamMonorepoConsistency.js.map +1 -0
  119. package/esm/policies/GleamNameRestrictions.d.ts +25 -0
  120. package/esm/policies/GleamNameRestrictions.d.ts.map +1 -0
  121. package/esm/policies/GleamNameRestrictions.js +44 -0
  122. package/esm/policies/GleamNameRestrictions.js.map +1 -0
  123. package/esm/policies/GleamNoPathDepsInPublished.d.ts +22 -0
  124. package/esm/policies/GleamNoPathDepsInPublished.d.ts.map +1 -0
  125. package/esm/policies/GleamNoPathDepsInPublished.js +43 -0
  126. package/esm/policies/GleamNoPathDepsInPublished.js.map +1 -0
  127. package/esm/policies/GleamPathDepsValid.d.ts +9 -0
  128. package/esm/policies/GleamPathDepsValid.d.ts.map +1 -0
  129. package/esm/policies/GleamPathDepsValid.js +59 -0
  130. package/esm/policies/GleamPathDepsValid.js.map +1 -0
  131. package/esm/policies/GleamProjectStructure.d.ts +32 -0
  132. package/esm/policies/GleamProjectStructure.d.ts.map +1 -0
  133. package/esm/policies/GleamProjectStructure.js +32 -0
  134. package/esm/policies/GleamProjectStructure.js.map +1 -0
  135. package/esm/policies/GleamSharedDependencyVersions.d.ts +37 -0
  136. package/esm/policies/GleamSharedDependencyVersions.d.ts.map +1 -0
  137. package/esm/policies/GleamSharedDependencyVersions.js +101 -0
  138. package/esm/policies/GleamSharedDependencyVersions.js.map +1 -0
  139. package/esm/policies/GleamTomlRequired.d.ts +30 -0
  140. package/esm/policies/GleamTomlRequired.d.ts.map +1 -0
  141. package/esm/policies/GleamTomlRequired.js +37 -0
  142. package/esm/policies/GleamTomlRequired.js.map +1 -0
  143. package/esm/policies/GleamTomlSorted.d.ts +20 -0
  144. package/esm/policies/GleamTomlSorted.d.ts.map +1 -0
  145. package/esm/policies/GleamTomlSorted.js +157 -0
  146. package/esm/policies/GleamTomlSorted.js.map +1 -0
  147. package/esm/policies/GleamVersionConstraint.d.ts +20 -0
  148. package/esm/policies/GleamVersionConstraint.d.ts.map +1 -0
  149. package/esm/policies/GleamVersionConstraint.js +68 -0
  150. package/esm/policies/GleamVersionConstraint.js.map +1 -0
  151. package/esm/policies/HtmlFileHeaders.d.ts +4 -2
  152. package/esm/policies/HtmlFileHeaders.d.ts.map +1 -1
  153. package/esm/policies/HtmlFileHeaders.js +2 -2
  154. package/esm/policies/HtmlFileHeaders.js.map +1 -1
  155. package/esm/policies/JsTsFileHeaders.d.ts +4 -2
  156. package/esm/policies/JsTsFileHeaders.d.ts.map +1 -1
  157. package/esm/policies/JsTsFileHeaders.js +1 -1
  158. package/esm/policies/JsTsFileHeaders.js.map +1 -1
  159. package/esm/policies/LicenseFileExists.d.ts +10 -4
  160. package/esm/policies/LicenseFileExists.d.ts.map +1 -1
  161. package/esm/policies/LicenseFileExists.js +27 -20
  162. package/esm/policies/LicenseFileExists.js.map +1 -1
  163. package/esm/policies/MutuallyExclusiveScripts.d.ts +8 -6
  164. package/esm/policies/MutuallyExclusiveScripts.d.ts.map +1 -1
  165. package/esm/policies/MutuallyExclusiveScripts.js +9 -13
  166. package/esm/policies/MutuallyExclusiveScripts.js.map +1 -1
  167. package/esm/policies/NoBuildDirectory.d.ts +15 -0
  168. package/esm/policies/NoBuildDirectory.d.ts.map +1 -0
  169. package/esm/policies/NoBuildDirectory.js +24 -0
  170. package/esm/policies/NoBuildDirectory.js.map +1 -0
  171. package/esm/policies/NoJsFileExtensions.d.ts +9 -3
  172. package/esm/policies/NoJsFileExtensions.d.ts.map +1 -1
  173. package/esm/policies/NoJsFileExtensions.js +9 -14
  174. package/esm/policies/NoJsFileExtensions.js.map +1 -1
  175. package/esm/policies/NoLargeBinaryFiles.d.ts +9 -4
  176. package/esm/policies/NoLargeBinaryFiles.d.ts.map +1 -1
  177. package/esm/policies/NoLargeBinaryFiles.js +10 -16
  178. package/esm/policies/NoLargeBinaryFiles.js.map +1 -1
  179. package/esm/policies/NoPrivateWorkspaceDependencies.d.ts +10 -6
  180. package/esm/policies/NoPrivateWorkspaceDependencies.d.ts.map +1 -1
  181. package/esm/policies/NoPrivateWorkspaceDependencies.js +12 -14
  182. package/esm/policies/NoPrivateWorkspaceDependencies.js.map +1 -1
  183. package/esm/policies/NoTargetArtifacts.d.ts +14 -0
  184. package/esm/policies/NoTargetArtifacts.d.ts.map +1 -0
  185. package/esm/policies/NoTargetArtifacts.js +37 -0
  186. package/esm/policies/NoTargetArtifacts.js.map +1 -0
  187. package/esm/policies/NoUnsafeWithoutJustification.d.ts +31 -0
  188. package/esm/policies/NoUnsafeWithoutJustification.d.ts.map +1 -0
  189. package/esm/policies/NoUnsafeWithoutJustification.js +79 -0
  190. package/esm/policies/NoUnsafeWithoutJustification.js.map +1 -0
  191. package/esm/policies/NoWildcardDependencies.d.ts +30 -0
  192. package/esm/policies/NoWildcardDependencies.d.ts.map +1 -0
  193. package/esm/policies/NoWildcardDependencies.js +83 -0
  194. package/esm/policies/NoWildcardDependencies.js.map +1 -0
  195. package/esm/policies/PackageAllowedScopes.d.ts +9 -5
  196. package/esm/policies/PackageAllowedScopes.d.ts.map +1 -1
  197. package/esm/policies/PackageAllowedScopes.js +15 -16
  198. package/esm/policies/PackageAllowedScopes.js.map +1 -1
  199. package/esm/policies/PackageEsmType.d.ts +7 -5
  200. package/esm/policies/PackageEsmType.d.ts.map +1 -1
  201. package/esm/policies/PackageEsmType.js +38 -36
  202. package/esm/policies/PackageEsmType.js.map +1 -1
  203. package/esm/policies/PackageFolderName.d.ts +8 -6
  204. package/esm/policies/PackageFolderName.d.ts.map +1 -1
  205. package/esm/policies/PackageFolderName.js +13 -16
  206. package/esm/policies/PackageFolderName.js.map +1 -1
  207. package/esm/policies/PackageJsonProperties.d.ts +5 -3
  208. package/esm/policies/PackageJsonProperties.d.ts.map +1 -1
  209. package/esm/policies/PackageJsonProperties.js +18 -21
  210. package/esm/policies/PackageJsonProperties.js.map +1 -1
  211. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts +2 -7
  212. package/esm/policies/PackageJsonRepoDirectoryProperty.d.ts.map +1 -1
  213. package/esm/policies/PackageJsonRepoDirectoryProperty.js +29 -42
  214. package/esm/policies/PackageJsonRepoDirectoryProperty.js.map +1 -1
  215. package/esm/policies/PackageJsonSorted.d.ts +2 -2
  216. package/esm/policies/PackageJsonSorted.d.ts.map +1 -1
  217. package/esm/policies/PackageJsonSorted.js +51 -31
  218. package/esm/policies/PackageJsonSorted.js.map +1 -1
  219. package/esm/policies/PackageLicense.d.ts +4 -4
  220. package/esm/policies/PackageLicense.d.ts.map +1 -1
  221. package/esm/policies/PackageLicense.js +32 -54
  222. package/esm/policies/PackageLicense.js.map +1 -1
  223. package/esm/policies/PackagePrivateField.d.ts +12 -8
  224. package/esm/policies/PackagePrivateField.d.ts.map +1 -1
  225. package/esm/policies/PackagePrivateField.js +34 -25
  226. package/esm/policies/PackagePrivateField.js.map +1 -1
  227. package/esm/policies/PackageReadme.d.ts +6 -5
  228. package/esm/policies/PackageReadme.d.ts.map +1 -1
  229. package/esm/policies/PackageReadme.js +24 -61
  230. package/esm/policies/PackageReadme.js.map +1 -1
  231. package/esm/policies/PackageScripts.d.ts +26 -22
  232. package/esm/policies/PackageScripts.d.ts.map +1 -1
  233. package/esm/policies/PackageScripts.js +42 -38
  234. package/esm/policies/PackageScripts.js.map +1 -1
  235. package/esm/policies/PackageTestScripts.d.ts +10 -6
  236. package/esm/policies/PackageTestScripts.d.ts.map +1 -1
  237. package/esm/policies/PackageTestScripts.js +17 -19
  238. package/esm/policies/PackageTestScripts.js.map +1 -1
  239. package/esm/policies/PublicApiDocumented.d.ts +21 -0
  240. package/esm/policies/PublicApiDocumented.d.ts.map +1 -0
  241. package/esm/policies/PublicApiDocumented.js +38 -0
  242. package/esm/policies/PublicApiDocumented.js.map +1 -0
  243. package/esm/policies/RequiredGitignorePatterns.d.ts +11 -4
  244. package/esm/policies/RequiredGitignorePatterns.d.ts.map +1 -1
  245. package/esm/policies/RequiredGitignorePatterns.js +29 -36
  246. package/esm/policies/RequiredGitignorePatterns.js.map +1 -1
  247. package/esm/policies/RequiredScripts.d.ts +9 -7
  248. package/esm/policies/RequiredScripts.d.ts.map +1 -1
  249. package/esm/policies/RequiredScripts.js +27 -26
  250. package/esm/policies/RequiredScripts.js.map +1 -1
  251. package/esm/policies/RustDocExists.d.ts +24 -0
  252. package/esm/policies/RustDocExists.d.ts.map +1 -0
  253. package/esm/policies/RustDocExists.js +49 -0
  254. package/esm/policies/RustDocExists.js.map +1 -0
  255. package/esm/policies/RustToolchainExists.d.ts +27 -0
  256. package/esm/policies/RustToolchainExists.d.ts.map +1 -0
  257. package/esm/policies/RustToolchainExists.js +28 -0
  258. package/esm/policies/RustToolchainExists.js.map +1 -0
  259. package/esm/policies/RustfmtConfigExists.d.ts +27 -0
  260. package/esm/policies/RustfmtConfigExists.d.ts.map +1 -0
  261. package/esm/policies/RustfmtConfigExists.js +28 -0
  262. package/esm/policies/RustfmtConfigExists.js.map +1 -0
  263. package/esm/policies/ScriptContains.d.ts +9 -7
  264. package/esm/policies/ScriptContains.d.ts.map +1 -1
  265. package/esm/policies/ScriptContains.js +9 -13
  266. package/esm/policies/ScriptContains.js.map +1 -1
  267. package/esm/policies/SharedDependencyVersions.d.ts +29 -0
  268. package/esm/policies/SharedDependencyVersions.d.ts.map +1 -0
  269. package/esm/policies/SharedDependencyVersions.js +143 -0
  270. package/esm/policies/SharedDependencyVersions.js.map +1 -0
  271. package/esm/policies/WorkspaceInheritance.d.ts +31 -0
  272. package/esm/policies/WorkspaceInheritance.d.ts.map +1 -0
  273. package/esm/policies/WorkspaceInheritance.js +93 -0
  274. package/esm/policies/WorkspaceInheritance.js.map +1 -0
  275. package/esm/policies/WorkspaceMembersValid.d.ts +27 -0
  276. package/esm/policies/WorkspaceMembersValid.d.ts.map +1 -0
  277. package/esm/policies/WorkspaceMembersValid.js +87 -0
  278. package/esm/policies/WorkspaceMembersValid.js.map +1 -0
  279. package/esm/policies/constants.d.ts +8 -0
  280. package/esm/policies/constants.d.ts.map +1 -1
  281. package/esm/policies/constants.js +9 -1
  282. package/esm/policies/constants.js.map +1 -1
  283. package/esm/policies.d.ts +43 -5
  284. package/esm/policies.d.ts.map +1 -1
  285. package/esm/policies.js +63 -6
  286. package/esm/policies.js.map +1 -1
  287. package/esm/policy.d.ts +65 -269
  288. package/esm/policy.d.ts.map +1 -1
  289. package/esm/policy.js +1 -122
  290. package/esm/policy.js.map +1 -1
  291. package/esm/policyDefiners/defineCargoPolicy.d.ts +82 -0
  292. package/esm/policyDefiners/defineCargoPolicy.d.ts.map +1 -0
  293. package/esm/policyDefiners/defineCargoPolicy.js +42 -0
  294. package/esm/policyDefiners/defineCargoPolicy.js.map +1 -0
  295. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts +27 -14
  296. package/esm/policyDefiners/defineFileHeaderPolicy.d.ts.map +1 -1
  297. package/esm/policyDefiners/defineFileHeaderPolicy.js +19 -39
  298. package/esm/policyDefiners/defineFileHeaderPolicy.js.map +1 -1
  299. package/esm/policyDefiners/defineGleamPolicy.d.ts +81 -0
  300. package/esm/policyDefiners/defineGleamPolicy.d.ts.map +1 -0
  301. package/esm/policyDefiners/defineGleamPolicy.js +42 -0
  302. package/esm/policyDefiners/defineGleamPolicy.js.map +1 -0
  303. package/esm/policyDefiners/definePackagePolicy.d.ts +24 -13
  304. package/esm/policyDefiners/definePackagePolicy.d.ts.map +1 -1
  305. package/esm/policyDefiners/definePackagePolicy.js +9 -32
  306. package/esm/policyDefiners/definePackagePolicy.js.map +1 -1
  307. package/esm/policyDefiners/spdxValidator.d.ts +66 -0
  308. package/esm/policyDefiners/spdxValidator.d.ts.map +1 -0
  309. package/esm/policyDefiners/spdxValidator.js +139 -0
  310. package/esm/policyDefiners/spdxValidator.js.map +1 -0
  311. package/esm/policyDefiners/tomlParser.d.ts +8 -0
  312. package/esm/policyDefiners/tomlParser.d.ts.map +1 -0
  313. package/esm/policyDefiners/tomlParser.js +17 -0
  314. package/esm/policyDefiners/tomlParser.js.map +1 -0
  315. package/esm/policyExecution.d.ts +19 -0
  316. package/esm/policyExecution.d.ts.map +1 -0
  317. package/esm/policyExecution.js +224 -0
  318. package/esm/policyExecution.js.map +1 -0
  319. package/esm/repositoryFiles.d.ts +4 -0
  320. package/esm/repositoryFiles.d.ts.map +1 -0
  321. package/esm/repositoryFiles.js +8 -0
  322. package/esm/repositoryFiles.js.map +1 -0
  323. package/esm/runner.d.ts +85 -0
  324. package/esm/runner.d.ts.map +1 -0
  325. package/esm/runner.js +189 -0
  326. package/esm/runner.js.map +1 -0
  327. package/esm/settlePolicyPromise.d.ts +4 -0
  328. package/esm/settlePolicyPromise.d.ts.map +1 -0
  329. package/esm/settlePolicyPromise.js +10 -0
  330. package/esm/settlePolicyPromise.js.map +1 -0
  331. package/esm/tsdoc-metadata.json +1 -1
  332. package/esm/utils/safePaths.d.ts +9 -0
  333. package/esm/utils/safePaths.d.ts.map +1 -0
  334. package/esm/utils/safePaths.js +40 -0
  335. package/esm/utils/safePaths.js.map +1 -0
  336. package/oclif.manifest.json +117 -3
  337. package/package.json +66 -36
  338. package/scripts/benchmark.mjs +341 -0
  339. package/scripts/postinstall.mjs +154 -0
  340. package/sidecar/sidecar.mjs +399 -0
@@ -1 +1 @@
1
- {"version":3,"file":"PackageFolderName.js","sourceRoot":"","sources":["../../src/policies/PackageFolderName.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAgE3D;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,KAAa,EAAE,WAAqB;IAC7D,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,WA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,CACjC,CAAC;QAEF,uCAAuC;QACvC,IAAI,UAAU,KAAK,kBAAkB,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC;QACb,CAAC;QAED,iCAAiC;QACjC,MAAM,UAAU,GAAkB;YACjC,IAAI,EAAE,iBAAiB,CAAC,IAAI;YAC5B,IAAI;YACJ,WAAW,EAAE,KAAK,EAAE,8BAA8B;YAClD,aAAa,EAAE;gBACd,mBAAmB,UAAU,kCAAkC,WAAW,6BAA6B,kBAAkB,GAAG;aAC5H;SACD,CAAC;QACF,OAAO,UAAU,CAAC;IACnB,CAAC;CACD,CAAC,CAAC","sourcesContent":["import path from \"pathe\";\nimport picomatch from \"picomatch\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFailure } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\nimport { parsePackageName } from \"../utils/packageName.js\";\n\n/**\n * Configuration for the PackageFolderName policy.\n *\n * This policy ensures that package folder names match their package names,\n * promoting consistency and making packages easier to find in the file system.\n *\n * @example\n * ```typescript\n * const config: PackageFolderNameConfig = {\n * // Strip all scopes when matching folder names\n * stripScopes: [\"@*\"],\n * // Or strip specific scopes\n * stripScopes: [\"@myorg\", \"@internal\"],\n * // These packages are exempt from the check\n * excludePackages: [\"@myorg/special-name\"],\n * };\n * ```\n *\n * @alpha\n */\nexport interface PackageFolderNameConfig {\n\t/**\n\t * A list of npm scope patterns to strip when comparing folder names to package names.\n\t *\n\t * For scoped packages like `@myorg/my-package`, if `@myorg` matches a pattern in this list,\n\t * the policy will expect the folder to be named `my-package` (not `@myorg/my-package`).\n\t *\n\t * @remarks\n\t *\n\t * Supports glob patterns:\n\t * - `@*` - matches all scopes\n\t * - `@myorg` - matches exactly `@myorg`\n\t * - `@my*` - matches scopes starting with `@my`\n\t *\n\t * @example\n\t * ```typescript\n\t * // Strip all scopes - @anything/my-package → folder \"my-package\"\n\t * stripScopes: [\"@*\"]\n\t *\n\t * // Strip specific scopes only\n\t * stripScopes: [\"@myorg\", \"@internal\"]\n\t *\n\t * // Strip scopes matching a pattern\n\t * stripScopes: [\"@fluid*\"]\n\t * ```\n\t */\n\tstripScopes?: string[];\n\n\t/**\n\t * A list of package names that are exempt from folder name matching.\n\t *\n\t * Use this for packages that intentionally have different folder names,\n\t * such as legacy packages or packages with special naming requirements.\n\t *\n\t * @example\n\t * ```typescript\n\t * excludePackages: [\"@myorg/cli\", \"legacy-package\"]\n\t * ```\n\t */\n\texcludePackages?: string[];\n}\n\n/**\n * Check if a scope should be stripped based on the patterns.\n *\n * @param scope - The scope to check (e.g., `@myorg`)\n * @param stripScopes - List of scope patterns to match (supports glob patterns via picomatch)\n * @returns `true` if the scope matches any pattern\n */\nfunction shouldStripScope(scope: string, stripScopes: string[]): boolean {\n\tif (stripScopes.length === 0) {\n\t\treturn false;\n\t}\n\n\treturn picomatch.isMatch(scope, stripScopes);\n}\n\n/**\n * Get the expected folder name from a package name.\n *\n * @param packageName - The package name (e.g., `@myorg/my-package`)\n * @param stripScopes - Scope patterns to strip from the package name\n * @returns The expected folder name\n */\nfunction getExpectedFolderName(\n\tpackageName: string,\n\tstripScopes: string[],\n): string {\n\tconst { scope, unscopedName } = parsePackageName(packageName);\n\n\t// Check if the package is scoped and should have scope stripped\n\tif (scope !== undefined && shouldStripScope(scope, stripScopes)) {\n\t\treturn unscopedName;\n\t}\n\n\t// Return full package name for unscoped packages or scopes not in stripScopes\n\treturn packageName;\n}\n\n/**\n * A policy that ensures package folder names match package names.\n *\n * This policy helps maintain a consistent and predictable file structure\n * in monorepos by ensuring that folder names correspond to package names.\n * This makes it easier to locate packages in the file system.\n *\n * @remarks\n *\n * The policy compares the immediate parent folder name of the package.json\n * against the package name. For scoped packages, the scope can optionally\n * be stripped based on the `stripScopes` configuration.\n *\n * For example:\n * - `packages/my-lib/package.json` with name `my-lib` ✓\n * - `packages/my-lib/package.json` with name `@myorg/my-lib` ✓ (if @myorg in stripScopes)\n * - `packages/wrong-name/package.json` with name `my-lib` ✗\n *\n * @example\n * ```typescript\n * import { makePolicy } from \"repopo\";\n * import { PackageFolderName } from \"repopo/policies\";\n *\n * const config: RepopoConfig = {\n * policies: [\n * makePolicy(PackageFolderName, {\n * stripScopes: [\"@myorg\", \"@internal\"],\n * excludePackages: [\"@myorg/special-case\"],\n * }),\n * ],\n * };\n * ```\n *\n * @alpha\n */\nexport const PackageFolderName = definePackagePolicy<\n\tPackageJson,\n\tPackageFolderNameConfig | undefined\n>({\n\tname: \"PackageFolderName\",\n\tdescription:\n\t\t\"Ensures package folder names match package names for consistent file structure.\",\n\thandler: async (json, { file, config }) => {\n\t\t// If no config provided, use defaults (check all packages)\n\t\tconst effectiveConfig = config ?? {};\n\n\t\tconst packageName = json.name;\n\n\t\t// Skip packages without a name\n\t\tif (packageName === undefined) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Skip the root package (common in monorepos)\n\t\tif (packageName === \"root\") {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Skip explicitly excluded packages\n\t\tif (effectiveConfig.excludePackages?.includes(packageName)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Get the folder name (parent directory of package.json)\n\t\tconst folderName = path.basename(path.dirname(file));\n\n\t\t// Get the expected folder name\n\t\tconst expectedFolderName = getExpectedFolderName(\n\t\t\tpackageName,\n\t\t\teffectiveConfig.stripScopes ?? [],\n\t\t);\n\n\t\t// Compare folder name to expected name\n\t\tif (folderName === expectedFolderName) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Mismatch - build error message\n\t\tconst failResult: PolicyFailure = {\n\t\t\tname: PackageFolderName.name,\n\t\t\tfile,\n\t\t\tautoFixable: false, // Can't auto-fix folder names\n\t\t\terrorMessages: [\n\t\t\t\t`Package folder \"${folderName}\" does not match package name \"${packageName}\". Expected folder name: \"${expectedFolderName}\"`,\n\t\t\t],\n\t\t};\n\t\treturn failResult;\n\t},\n});\n"]}
1
+ {"version":3,"file":"PackageFolderName.js","sourceRoot":"","sources":["../../src/policies/Pack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8C;QAC9C,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;YAC5B,OAAO,EAAE,CAAC;QACX,CAAC;QAED,oCAAoC;QACpC,IAAI,eAAe,CAAC,eAAe,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5D,OAAO,EAAE,CAAC;QACX,CAAC;QAED,yDAAyD;QACzD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAErD,+BAA+B;QAC/B,MAAM,kBAAkB,GAAG,qBAAqB,CAC/C,WAAW,EACX,eAAe,CAAC,WAAW,IAAI,EAAE,CACjC,CAAC;QAEF,uCAAuC;QACvC,IAAI,UAAU,KAAK,kBAAkB,EAAE,CAAC;YACvC,OAAO,EAAE,CAAC;QACX,CAAC;QAED,iCAAiC;QACjC,MAAM,UAAU,GAAoB;YACnC,mBAAmB,UAAU,kCAAkC,WAAW,6BAA6B,kBAAkB,GAAG;SAC5H,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;QAClC,OAAO,UAAU,CAAC;IACnB,CAAC;CACD,CAAC,CAAC","sourcesContent":["import path from \"pathe\";\nimport picomatch from \"picomatch\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFinding } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\nimport { parsePackageName } from \"../utils/packageName.js\";\n\n/**\n * Configuration for the PackageFolderName policy.\n *\n * This policy ensures that package folder names match their package names,\n * promoting consistency and making packages easier to find in the file system.\n *\n * @example\n * ```typescript\n * const config: PackageFolderNameConfig = {\n * // Strip all scopes when matching folder names\n * stripScopes: [\"@*\"],\n * // Or strip specific scopes\n * stripScopes: [\"@myorg\", \"@internal\"],\n * // These packages are exempt from the check\n * excludePackages: [\"@myorg/special-name\"],\n * };\n * ```\n *\n * @public\n */\nexport interface PackageFolderNameConfig {\n\t/**\n\t * A list of npm scope patterns to strip when comparing folder names to package names.\n\t *\n\t * For scoped packages like `@myorg/my-package`, if `@myorg` matches a pattern in this list,\n\t * the policy will expect the folder to be named `my-package` (not `@myorg/my-package`).\n\t *\n\t * @remarks\n\t *\n\t * Supports glob patterns:\n\t * - `@*` - matches all scopes\n\t * - `@myorg` - matches exactly `@myorg`\n\t * - `@my*` - matches scopes starting with `@my`\n\t *\n\t * @example\n\t * ```typescript\n\t * // Strip all scopes - @anything/my-package → folder \"my-package\"\n\t * stripScopes: [\"@*\"]\n\t *\n\t * // Strip specific scopes only\n\t * stripScopes: [\"@myorg\", \"@internal\"]\n\t *\n\t * // Strip scopes matching a pattern\n\t * stripScopes: [\"@fluid*\"]\n\t * ```\n\t */\n\tstripScopes?: string[];\n\n\t/**\n\t * A list of package names that are exempt from folder name matching.\n\t *\n\t * Use this for packages that intentionally have different folder names,\n\t * such as legacy packages or packages with special naming requirements.\n\t *\n\t * @example\n\t * ```typescript\n\t * excludePackages: [\"@myorg/cli\", \"legacy-package\"]\n\t * ```\n\t */\n\texcludePackages?: string[];\n}\n\n/**\n * Check if a scope should be stripped based on the patterns.\n *\n * @param scope - The scope to check (e.g., `@myorg`)\n * @param stripScopes - List of scope patterns to match (supports glob patterns via picomatch)\n * @returns `true` if the scope matches any pattern\n */\nfunction shouldStripScope(scope: string, stripScopes: string[]): boolean {\n\tif (stripScopes.length === 0) {\n\t\treturn false;\n\t}\n\n\treturn picomatch.isMatch(scope, stripScopes);\n}\n\n/**\n * Get the expected folder name from a package name.\n *\n * @param packageName - The package name (e.g., `@myorg/my-package`)\n * @param stripScopes - Scope patterns to strip from the package name\n * @returns The expected folder name\n */\nfunction getExpectedFolderName(\n\tpackageName: string,\n\tstripScopes: string[],\n): string {\n\tconst { scope, unscopedName } = parsePackageName(packageName);\n\n\t// Check if the package is scoped and should have scope stripped\n\tif (scope !== undefined && shouldStripScope(scope, stripScopes)) {\n\t\treturn unscopedName;\n\t}\n\n\t// Return full package name for unscoped packages or scopes not in stripScopes\n\treturn packageName;\n}\n\n/**\n * A policy that ensures package folder names match package names.\n *\n * This policy helps maintain a consistent and predictable file structure\n * in monorepos by ensuring that folder names correspond to package names.\n * This makes it easier to locate packages in the file system.\n *\n * @remarks\n *\n * The policy compares the immediate parent folder name of the package.json\n * against the package name. For scoped packages, the scope can optionally\n * be stripped based on the `stripScopes` configuration.\n *\n * For example:\n * - `packages/my-lib/package.json` with name `my-lib` ✓\n * - `packages/my-lib/package.json` with name `@myorg/my-lib` ✓ (if `@myorg` is in `stripScopes`)\n * - `packages/wrong-name/package.json` with name `my-lib` ✗\n *\n * @example\n * ```typescript\n * import { makePolicy } from \"repopo\";\n * import { PackageFolderName } from \"repopo/policies\";\n *\n * const config: RepopoConfig = {\n * policies: [\n * makePolicy(PackageFolderName, {\n * config: {\n * stripScopes: [\"@myorg\", \"@internal\"],\n * excludePackages: [\"@myorg/special-case\"],\n * },\n * }),\n * ],\n * };\n * ```\n *\n * @public\n */\nexport const PackageFolderName = definePackagePolicy<\n\tPackageJson,\n\tPackageFolderNameConfig | undefined\n>({\n\tname: \"PackageFolderName\",\n\tdescription:\n\t\t\"Ensures package folder names match package names for consistent file structure.\",\n\thandler: async (json, { file, config }) => {\n\t\t// If no config provided, use defaults (check all packages)\n\t\tconst effectiveConfig = config ?? {};\n\n\t\tconst packageName = json.name;\n\n\t\t// Skip packages without a name\n\t\tif (packageName === undefined) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Skip the root package (common in monorepos)\n\t\tif (packageName === \"root\") {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Skip explicitly excluded packages\n\t\tif (effectiveConfig.excludePackages?.includes(packageName)) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Get the folder name (parent directory of package.json)\n\t\tconst folderName = path.basename(path.dirname(file));\n\n\t\t// Get the expected folder name\n\t\tconst expectedFolderName = getExpectedFolderName(\n\t\t\tpackageName,\n\t\t\teffectiveConfig.stripScopes ?? [],\n\t\t);\n\n\t\t// Compare folder name to expected name\n\t\tif (folderName === expectedFolderName) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Mismatch - build error message\n\t\tconst failResult: PolicyFinding[] = [\n\t\t\t`Package folder \"${folderName}\" does not match package name \"${packageName}\". Expected folder name: \"${expectedFolderName}\"`,\n\t\t].map((message) => ({ message }));\n\t\treturn failResult;\n\t},\n});\n"]}
@@ -2,7 +2,7 @@ import type { PackageJson } from "type-fest";
2
2
  /**
3
3
  * Policy settings for the PackageJsonProperties repo policy.
4
4
  *
5
- * @alpha
5
+ * @public
6
6
  */
7
7
  export interface PackageJsonPropertiesSettings {
8
8
  /**
@@ -13,7 +13,9 @@ export interface PackageJsonPropertiesSettings {
13
13
  /**
14
14
  * A RepoPolicy that checks that package.json properties in packages match expected values.
15
15
  *
16
- * @alpha
16
+ * @public
17
17
  */
18
- export declare const PackageJsonProperties: import("../policy.js").PolicyShape<PackageJsonPropertiesSettings | undefined>;
18
+ export declare const PackageJsonProperties: import("../policy.js").FilePolicyDefinition<PackageJsonPropertiesSettings> & {
19
+ requiresConfig: true;
20
+ };
19
21
  //# sourceMappingURL=PackageJsonProperties.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackageJsonProperties.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAM7C;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC7C;;OAEG;IACH,QAAQ,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,+EAkDhC,CAAC"}
1
+ {"version":3,"file":"PackageJsonProperties.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAa7C;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC7C;;OAEG;IACH,QAAQ,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;CAoChC,CAAC"}
@@ -1,29 +1,32 @@
1
- import { defu } from "defu";
1
+ import { createDefu } from "defu";
2
2
  import { call } from "effection";
3
3
  import jsonfile from "jsonfile";
4
4
  import diff from "microdiff";
5
+ import { resolve as resolvePath } from "pathe";
5
6
  import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
6
7
  const { writeFile: writeJson } = jsonfile;
8
+ const mergeProperties = createDefu((object, key, value) => {
9
+ if (Array.isArray(value)) {
10
+ object[key] = value;
11
+ return true;
12
+ }
13
+ return false;
14
+ });
7
15
  /**
8
16
  * A RepoPolicy that checks that package.json properties in packages match expected values.
9
17
  *
10
- * @alpha
18
+ * @public
11
19
  */
12
20
  export const PackageJsonProperties = definePackagePolicy({
13
21
  name: "PackageJsonProperties",
14
22
  description: "Ensures package.json files contain required properties with correct values.",
15
- handler: function* (json, { file, config, resolve }) {
23
+ requiresConfig: true,
24
+ handler: function* (json, { file, root, config, resolve }) {
16
25
  if (config === undefined) {
17
- return true;
26
+ throw new TypeError("PackageJsonProperties requires config.");
18
27
  }
19
28
  const { verbatim } = config;
20
- const failResult = {
21
- name: PackageJsonProperties.name,
22
- file,
23
- autoFixable: true,
24
- errorMessages: [],
25
- };
26
- const merged = defu(verbatim, json);
29
+ const merged = mergeProperties(verbatim, json);
27
30
  const result = diff(merged, json);
28
31
  const messages = [];
29
32
  for (const diffResult of result) {
@@ -31,19 +34,13 @@ export const PackageJsonProperties = definePackagePolicy({
31
34
  }
32
35
  if (messages.length > 0) {
33
36
  if (resolve) {
34
- const fixResult = {
35
- ...failResult,
36
- resolved: false,
37
- };
38
- yield* call(() => writeJson(file, merged, { spaces: "\t" }));
39
- fixResult.resolved = true;
40
- return fixResult;
37
+ yield* call(() => writeJson(resolvePath(root, file), merged, { spaces: "\t" }));
38
+ return messages.map((message) => ({ message, fixStatus: "fixed" }));
41
39
  }
42
40
  // There were errors, and we're not resolving them, so return a fail result
43
- failResult.errorMessages = messages;
44
- return failResult;
41
+ return messages.map((message) => ({ message, fixStatus: "available" }));
45
42
  }
46
- return true;
43
+ return [];
47
44
  },
48
45
  });
49
46
  //# sourceMappingURL=PackageJsonProperties.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackageJsonProperties.js","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;AAc1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,mBAAmB,CAGtD;IACD,IAAI,EAAE,uBAAuB;IAC7B,WAAW,EACV,6EAA6E;IAC9E,OAAO,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;QAClD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACb,CAAC;QACD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QAE5B,MAAM,UAAU,GAAkB;YACjC,IAAI,EAAE,qBAAqB,CAAC,IAAI;YAChC,IAAI;YACJ,WAAW,EAAE,IAAI;YACjB,aAAa,EAAE,EAAE;SACjB,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAElC,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,KAAK,MAAM,UAAU,IAAI,MAAM,EAAE,CAAC;YACjC,QAAQ,CAAC,IAAI,CACZ,2CAA2C,UAAU,CAAC,IAAI,IAAI,CAC9D,CAAC;QACH,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,IAAI,OAAO,EAAE,CAAC;gBACb,MAAM,SAAS,GAAoB;oBAClC,GAAG,UAAU;oBACb,QAAQ,EAAE,KAAK;iBACf,CAAC;gBAEF,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBAE7D,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC;gBAC1B,OAAO,SAAS,CAAC;YAClB,CAAC;YAED,2EAA2E;YAC3E,UAAU,CAAC,aAAa,GAAG,QAAQ,CAAC;YACpC,OAAO,UAAU,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC,CAAC","sourcesContent":["import { defu } from \"defu\";\nimport { call } from \"effection\";\nimport jsonfile from \"jsonfile\";\nimport diff from \"microdiff\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFailure, PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\nconst { writeFile: writeJson } = jsonfile;\n\n/**\n * Policy settings for the PackageJsonProperties repo policy.\n *\n * @alpha\n */\nexport interface PackageJsonPropertiesSettings {\n\t/**\n\t * Sets a package.json property to the value provided. The value will be used verbatim.\n\t */\n\tverbatim: PackageJson;\n}\n\n/**\n * A RepoPolicy that checks that package.json properties in packages match expected values.\n *\n * @alpha\n */\nexport const PackageJsonProperties = definePackagePolicy<\n\tPackageJson,\n\tPackageJsonPropertiesSettings | undefined\n>({\n\tname: \"PackageJsonProperties\",\n\tdescription:\n\t\t\"Ensures package.json files contain required properties with correct values.\",\n\thandler: function* (json, { file, config, resolve }) {\n\t\tif (config === undefined) {\n\t\t\treturn true;\n\t\t}\n\t\tconst { verbatim } = config;\n\n\t\tconst failResult: PolicyFailure = {\n\t\t\tname: PackageJsonProperties.name,\n\t\t\tfile,\n\t\t\tautoFixable: true,\n\t\t\terrorMessages: [],\n\t\t};\n\n\t\tconst merged = defu(verbatim, json);\n\t\tconst result = diff(merged, json);\n\n\t\tconst messages: string[] = [];\n\t\tfor (const diffResult of result) {\n\t\t\tmessages.push(\n\t\t\t\t`Incorrect package.json field value for '${diffResult.path}'.`,\n\t\t\t);\n\t\t}\n\n\t\tif (messages.length > 0) {\n\t\t\tif (resolve) {\n\t\t\t\tconst fixResult: PolicyFixResult = {\n\t\t\t\t\t...failResult,\n\t\t\t\t\tresolved: false,\n\t\t\t\t};\n\n\t\t\t\tyield* call(() => writeJson(file, merged, { spaces: \"\\t\" }));\n\n\t\t\t\tfixResult.resolved = true;\n\t\t\t\treturn fixResult;\n\t\t\t}\n\n\t\t\t// There were errors, and we're not resolving them, so return a fail result\n\t\t\tfailResult.errorMessages = messages;\n\t\t\treturn failResult;\n\t\t}\n\n\t\treturn true;\n\t},\n});\n"]}
1
+ {"version":3,"file":"PackageJsonProperties.js","sourceRoot":"","sources":["../../src/policies/PackageJsonProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;AAE1C,MAAM,eAAe,GAAG,UAAU,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,KA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AE,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;YACrE,CAAC;YAED,2EAA2E;YAC3E,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CACD,CAAC,CAAC","sourcesContent":["import { createDefu } from \"defu\";\nimport { call } from \"effection\";\nimport jsonfile from \"jsonfile\";\nimport diff from \"microdiff\";\nimport { resolve as resolvePath } from \"pathe\";\nimport type { PackageJson } from \"type-fest\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\nconst { writeFile: writeJson } = jsonfile;\n\nconst mergeProperties = createDefu((object, key, value) => {\n\tif (Array.isArray(value)) {\n\t\tobject[key] = value;\n\t\treturn true;\n\t}\n\treturn false;\n});\n\n/**\n * Policy settings for the PackageJsonProperties repo policy.\n *\n * @public\n */\nexport interface PackageJsonPropertiesSettings {\n\t/**\n\t * Sets a package.json property to the value provided. The value will be used verbatim.\n\t */\n\tverbatim: PackageJson;\n}\n\n/**\n * A RepoPolicy that checks that package.json properties in packages match expected values.\n *\n * @public\n */\nexport const PackageJsonProperties = definePackagePolicy<\n\tPackageJson,\n\tPackageJsonPropertiesSettings\n>({\n\tname: \"PackageJsonProperties\",\n\tdescription:\n\t\t\"Ensures package.json files contain required properties with correct values.\",\n\trequiresConfig: true,\n\thandler: function* (json, { file, root, config, resolve }) {\n\t\tif (config === undefined) {\n\t\t\tthrow new TypeError(\"PackageJsonProperties requires config.\");\n\t\t}\n\t\tconst { verbatim } = config;\n\t\tconst merged = mergeProperties(verbatim, json);\n\t\tconst result = diff(merged, json);\n\n\t\tconst messages: string[] = [];\n\t\tfor (const diffResult of result) {\n\t\t\tmessages.push(\n\t\t\t\t`Incorrect package.json field value for '${diffResult.path}'.`,\n\t\t\t);\n\t\t}\n\n\t\tif (messages.length > 0) {\n\t\t\tif (resolve) {\n\t\t\t\tyield* call(() =>\n\t\t\t\t\twriteJson(resolvePath(root, file), merged, { spaces: \"\\t\" }),\n\t\t\t\t);\n\t\t\t\treturn messages.map((message) => ({ message, fixStatus: \"fixed\" }));\n\t\t\t}\n\n\t\t\t// There were errors, and we're not resolving them, so return a fail result\n\t\t\treturn messages.map((message) => ({ message, fixStatus: \"available\" }));\n\t\t}\n\t\treturn [];\n\t},\n});\n"]}
@@ -1,8 +1,3 @@
1
- /**
2
- * A RepoPolicy that checks that the repository.directory property in package.json is set correctly. If the repository
3
- * field is a string instead of an object the package will be ignored.
4
- *
5
- * @alpha
6
- */
7
- export declare const PackageJsonRepoDirectoryProperty: import("../policy.js").PolicyShape<undefined>;
1
+ /** Ensures repository.directory matches each package's repository-relative directory. @public */
2
+ export declare const PackageJsonRepoDirectoryProperty: import("../policy.js").FilePolicyDefinition<void>;
8
3
  //# sourceMappingURL=PackageJsonRepoDirectoryProperty.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackageJsonRepoDirectoryProperty.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,+CAuD3C,CAAC"}
1
+ {"version":3,"file":"PackageJsonRepoDirectoryProperty.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"AAKA,iGAAiG;AACjG,eAAO,MAAM,gCAAgC,mDAqC3C,CAAC"}
@@ -2,54 +2,41 @@ import assert from "node:assert/strict";
2
2
  import { updatePackageJsonFile } from "@fluid-tools/build-infrastructure";
3
3
  import path from "pathe";
4
4
  import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
5
- /**
6
- * A RepoPolicy that checks that the repository.directory property in package.json is set correctly. If the repository
7
- * field is a string instead of an object the package will be ignored.
8
- *
9
- * @alpha
10
- */
5
+ /** Ensures repository.directory matches each package's repository-relative directory. @public */
11
6
  export const PackageJsonRepoDirectoryProperty = definePackagePolicy({
12
7
  name: "PackageJsonRepoDirectoryProperty",
13
8
  description: "Ensures the repository.directory property in package.json is set correctly for monorepo packages.",
14
- handler: function* (json, { file, root, resolve }) {
15
- const failResult = {
16
- name: PackageJsonRepoDirectoryProperty.name,
17
- file,
18
- autoFixable: true,
19
- errorMessages: [],
20
- };
21
- const fixResult = {
22
- ...failResult,
23
- resolved: false,
24
- };
25
- const pkgDir = path.dirname(file);
26
- const maybeDir = path.relative(root, pkgDir);
27
- const relativePkgDir = maybeDir === "" ? undefined : maybeDir;
28
- if (typeof json.repository === "object" &&
29
- json.repository.directory !== relativePkgDir) {
30
- if (resolve) {
31
- try {
32
- updatePackageJsonFile(file, (pkgJson) => {
33
- assert(typeof pkgJson.repository === "object");
34
- if (relativePkgDir === undefined) {
35
- delete pkgJson.repository.directory;
36
- }
37
- else {
38
- pkgJson.repository.directory = relativePkgDir;
39
- }
40
- });
41
- fixResult.resolved = true;
9
+ handler: async (json, { file, root, resolve }) => {
10
+ const packageJsonPath = path.resolve(root, file);
11
+ const directory = path.relative(root, path.dirname(packageJsonPath)) || undefined;
12
+ if (typeof json.repository !== "object" ||
13
+ json.repository.directory === directory) {
14
+ return [];
15
+ }
16
+ const message = `repository.directory value is wrong. Expected '${directory}', got '${json.repository.directory}'`;
17
+ if (!resolve) {
18
+ return [{ message, fixStatus: "available" }];
19
+ }
20
+ try {
21
+ updatePackageJsonFile(packageJsonPath, (pkg) => {
22
+ assert(typeof pkg.repository === "object");
23
+ if (directory === undefined) {
24
+ delete pkg.repository.directory;
42
25
  }
43
- catch (error) {
44
- fixResult.resolved = false;
45
- fixResult.errorMessages.push(`${error.message}\n${error.stack}`);
26
+ else {
27
+ pkg.repository.directory = directory;
46
28
  }
47
- return fixResult;
48
- }
49
- failResult.errorMessages.push(`repository.directory value is wrong. Expected '${relativePkgDir}', got '${json.repository.directory}'`);
50
- return failResult;
29
+ });
30
+ }
31
+ catch (error) {
32
+ return [
33
+ {
34
+ message: `${message}: ${error instanceof Error ? error.message : String(error)}`,
35
+ fixStatus: "failed",
36
+ },
37
+ ];
51
38
  }
52
- return true;
39
+ return [{ message, fixStatus: "fixed" }];
53
40
  },
54
41
  });
55
42
  //# sourceMappingURL=PackageJsonRepoDirectoryProperty.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackageJsonRepoDirectoryProperty.js","sourceRoot":"","sources":["../../src/policies/PackageJsonRepoDirectoryProperty.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,IAAI,MAAM,OAAO,CAAC;AAGzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAGjE;IACD,IAAI,EAAE,kCAAkC;IACxC,WAAW,EACV,mGAAmG;IACpG,OAAO,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE;QAChD,MAAM,UAAU,GAAkB;YACjC,IAAI,EAAE,gCAAgC,CAAC,IAAI;YAC3C,IAAI;YACJ,WAAW,EAAE,IAAI;YACjB,aAAa,EAAE,EAAE;SACjB,CAAC;QAEF,MAAM,SAAS,GAAoB;YAClC,GAAG,UAAU;YACb,QAAQ,EAAE,KAAK;SACf,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC7C,MAAM,cAAc,GAAG,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;QAE9D,IACC,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ;YACnC,IAAI,CAAC,UAAU,CAAC,SAAS,KAAK,cAAc,EAC3C,CAAC;YACF,IAAI,OAAO,EAAE,CAAC;gBACb,IAAI,CAAC;oBACJ,qBAAqB,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;wBACvC,MAAM,CAAC,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC;wBAC/C,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;4BAClC,OAAO,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC;wBACrC,CAAC;6BAAM,CAAC;4BACP,OAAO,CAAC,UAAU,CAAC,SAAS,GAAG,cAAc,CAAC;wBAC/C,CAAC;oBACF,CAAC,CAAC,CAAC;oBACH,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC;gBAC3B,CAAC;gBAAC,OAAO,KAAc,EAAE,CAAC;oBACzB,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;oBAC3B,SAAS,CAAC,aAAa,CAAC,IAAI,CAC3B,GAAI,KAAe,CAAC,OAAO,KAAM,KAAe,CAAC,KAAK,EAAE,CACxD,CAAC;gBACH,CAAC;gBACD,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,UAAU,CAAC,aAAa,CAAC,IAAI,CAC5B,kDAAkD,cAAc,WAAW,IAAI,CAAC,UAAU,CAAC,SAAS,GAAG,CACvG,CAAC;YACF,OAAO,UAAU,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { updatePackageJsonFile } from \"@fluid-tools/build-infrastructure\";\nimport path from \"pathe\";\nimport type { PackageJson } from \"type-fest\";\nimport type { PolicyFailure, PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * A RepoPolicy that checks that the repository.directory property in package.json is set correctly. If the repository\n * field is a string instead of an object the package will be ignored.\n *\n * @alpha\n */\nexport const PackageJsonRepoDirectoryProperty = definePackagePolicy<\n\tPackageJson,\n\tundefined\n>({\n\tname: \"PackageJsonRepoDirectoryProperty\",\n\tdescription:\n\t\t\"Ensures the repository.directory property in package.json is set correctly for monorepo packages.\",\n\thandler: function* (json, { file, root, resolve }) {\n\t\tconst failResult: PolicyFailure = {\n\t\t\tname: PackageJsonRepoDirectoryProperty.name,\n\t\t\tfile,\n\t\t\tautoFixable: true,\n\t\t\terrorMessages: [],\n\t\t};\n\n\t\tconst fixResult: PolicyFixResult = {\n\t\t\t...failResult,\n\t\t\tresolved: false,\n\t\t};\n\n\t\tconst pkgDir = path.dirname(file);\n\t\tconst maybeDir = path.relative(root, pkgDir);\n\t\tconst relativePkgDir = maybeDir === \"\" ? undefined : maybeDir;\n\n\t\tif (\n\t\t\ttypeof json.repository === \"object\" &&\n\t\t\tjson.repository.directory !== relativePkgDir\n\t\t) {\n\t\t\tif (resolve) {\n\t\t\t\ttry {\n\t\t\t\t\tupdatePackageJsonFile(file, (pkgJson) => {\n\t\t\t\t\t\tassert(typeof pkgJson.repository === \"object\");\n\t\t\t\t\t\tif (relativePkgDir === undefined) {\n\t\t\t\t\t\t\tdelete pkgJson.repository.directory;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tpkgJson.repository.directory = relativePkgDir;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tfixResult.resolved = true;\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tfixResult.resolved = false;\n\t\t\t\t\tfixResult.errorMessages.push(\n\t\t\t\t\t\t`${(error as Error).message}\\n${(error as Error).stack}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn fixResult;\n\t\t\t}\n\t\t\tfailResult.errorMessages.push(\n\t\t\t\t`repository.directory value is wrong. Expected '${relativePkgDir}', got '${json.repository.directory}'`,\n\t\t\t);\n\t\t\treturn failResult;\n\t\t}\n\n\t\treturn true;\n\t},\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S,EAAE,CAAC;oBAC7B,OAAO,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;gBACjC,CAAC;qBAAM,CAAC;oBACP,GAAG,CAAC,UAAU,CAAC,SAAS,GAAG,SAAS,CAAC;gBACtC,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACzB,OAAO;gBACN;oBACC,OAAO,EAAE,GAAG,OAAO,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;oBAChF,SAAS,EAAE,QAAQ;iBACnB;aACD,CAAC;QACH,CAAC;QACD,OAAO,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1C,CAAC;CACD,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { updatePackageJsonFile } from \"@fluid-tools/build-infrastructure\";\nimport path from \"pathe\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/** Ensures repository.directory matches each package's repository-relative directory. @public */\nexport const PackageJsonRepoDirectoryProperty = definePackagePolicy({\n\tname: \"PackageJsonRepoDirectoryProperty\",\n\tdescription:\n\t\t\"Ensures the repository.directory property in package.json is set correctly for monorepo packages.\",\n\thandler: async (json, { file, root, resolve }) => {\n\t\tconst packageJsonPath = path.resolve(root, file);\n\t\tconst directory =\n\t\t\tpath.relative(root, path.dirname(packageJsonPath)) || undefined;\n\t\tif (\n\t\t\ttypeof json.repository !== \"object\" ||\n\t\t\tjson.repository.directory === directory\n\t\t) {\n\t\t\treturn [];\n\t\t}\n\t\tconst message = `repository.directory value is wrong. Expected '${directory}', got '${json.repository.directory}'`;\n\t\tif (!resolve) {\n\t\t\treturn [{ message, fixStatus: \"available\" }];\n\t\t}\n\t\ttry {\n\t\t\tupdatePackageJsonFile(packageJsonPath, (pkg) => {\n\t\t\t\tassert(typeof pkg.repository === \"object\");\n\t\t\t\tif (directory === undefined) {\n\t\t\t\t\tdelete pkg.repository.directory;\n\t\t\t\t} else {\n\t\t\t\t\tpkg.repository.directory = directory;\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error: unknown) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tmessage: `${message}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\tfixStatus: \"failed\",\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\treturn [{ message, fixStatus: \"fixed\" }];\n\t},\n});\n"]}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * A repo policy that checks if package.json files in the repo are sorted using sort-package-json.
3
3
  *
4
- * @alpha
4
+ * @public
5
5
  */
6
- export declare const PackageJsonSorted: import("../policy.js").PolicyShape<undefined>;
6
+ export declare const PackageJsonSorted: import("../policy.js").FilePolicyDefinition<void>;
7
7
  //# sourceMappingURL=PackageJsonSorted.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackageJsonSorted.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonSorted.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,+CAiD5B,CAAC"}
1
+ {"version":3,"file":"PackageJsonSorted.d.ts","sourceRoot":"","sources":["../../src/policies/PackageJsonSorted.ts"],"names":[],"mappings":"AAwCA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,mDA6C5B,CAAC"}
@@ -1,56 +1,76 @@
1
- import { updatePackageJsonFile } from "@tylerbu/cli-api";
2
- import { call } from "effection";
1
+ import jsonfile from "jsonfile";
3
2
  import { resolve as resolvePath } from "pathe";
4
- import { sortPackageJson } from "sort-package-json";
5
3
  import { definePackagePolicy } from "../policyDefiners/definePackagePolicy.js";
4
+ import { detectIndentation } from "../utils/indentation.js";
5
+ const { writeFile: writeJson } = jsonfile;
6
+ const missingDependencyMessage = "PackageJsonSorted requires the optional peer dependency sort-package-json. Install it to enable this policy.";
7
+ function isMissingSortPackageJsonError(error) {
8
+ if (error instanceof Error &&
9
+ "code" in error &&
10
+ error.code === "ERR_MODULE_NOT_FOUND" &&
11
+ error.message.includes("sort-package-json")) {
12
+ return true;
13
+ }
14
+ return (typeof error === "object" &&
15
+ error !== null &&
16
+ "cause" in error &&
17
+ isMissingSortPackageJsonError(error.cause));
18
+ }
19
+ async function loadSortPackageJson() {
20
+ try {
21
+ const { sortPackageJson } = await import("sort-package-json");
22
+ return sortPackageJson;
23
+ }
24
+ catch (error) {
25
+ if (isMissingSortPackageJsonError(error)) {
26
+ return undefined;
27
+ }
28
+ throw error;
29
+ }
30
+ }
6
31
  /**
7
32
  * A repo policy that checks if package.json files in the repo are sorted using sort-package-json.
8
33
  *
9
- * @alpha
34
+ * @public
10
35
  */
11
36
  export const PackageJsonSorted = definePackagePolicy({
12
37
  name: "PackageJsonSorted",
13
38
  description: "Ensures package.json files are sorted consistently using sort-package-json.",
14
- handler: function* (json, { file, root, resolve }) {
39
+ handler: async (json, { file, root, resolve }) => {
40
+ const sortPackageJson = await loadSortPackageJson();
41
+ if (sortPackageJson === undefined) {
42
+ const result = [missingDependencyMessage].map((message) => ({ message }));
43
+ return result;
44
+ }
15
45
  const sortedJson = sortPackageJson(json);
16
46
  const isSorted = JSON.stringify(sortedJson) === JSON.stringify(json);
17
47
  if (isSorted) {
18
- return true;
48
+ return [];
19
49
  }
20
50
  if (resolve) {
21
51
  try {
22
- yield* call(() => updatePackageJsonFile(resolvePath(root, file), (pkgJson) => pkgJson, {
23
- sort: true,
24
- }));
25
- const result = {
26
- name: PackageJsonSorted.name,
27
- file,
28
- resolved: true,
29
- errorMessages: [],
30
- };
52
+ const packageJsonPath = resolvePath(root, file);
53
+ const indent = await detectIndentation(packageJsonPath);
54
+ await writeJson(packageJsonPath, sortedJson, { spaces: indent });
55
+ const result = [
56
+ { message: "package.json is not sorted.", fixStatus: "fixed" },
57
+ ];
31
58
  return result;
32
59
  }
33
60
  catch (error) {
34
- const result = {
35
- name: PackageJsonSorted.name,
36
- file,
37
- resolved: false,
38
- autoFixable: true,
39
- errorMessages: [
40
- error.message,
41
- error.stack ?? "",
42
- ],
43
- };
61
+ const result = [
62
+ {
63
+ message: error instanceof Error ? error.message : String(error),
64
+ fixStatus: "failed",
65
+ },
66
+ ];
44
67
  return result;
45
68
  }
46
69
  }
47
70
  else {
48
- const result = {
49
- name: PackageJsonSorted.name,
50
- file,
51
- autoFixable: true,
52
- errorMessages: [],
53
- };
71
+ const result = [
72
+ { message: "package.json is not sorted.", fixStatus: "available" },
73
+ ];
54
74
  return result;
55
75
  }
56
76
  },
@@ -1 +1 @@
1
- {"version":3,"file":"PackageJsonSorted.js","sourceRoot":"","sources":["../../src/policies/PackageJsonSorted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;IACpD,IAAI,EAAE,mBAAmB;IACzB,WAAW,EACV,6EAA6E;IAC9E,OAAO,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE;QAChD,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAErE,IAAI,QAAQ,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QACb,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,CAAC;gBACJ,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAChB,qBAAqB,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE;oBACpE,IAAI,EAAE,IAAI;iBACV,CAAC,CACF,CAAC;gBACF,MAAM,MAAM,GAAoB;oBAC/B,IAAI,EAAE,iBAAiB,CAAC,IAAI;oBAC5B,IAAI;oBACJ,QAAQ,EAAE,IAAI;oBACd,aAAa,EAAE,EAAE;iBACjB,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACzB,MAAM,MAAM,GAAoB;oBAC/B,IAAI,EAAE,iBAAiB,CAAC,IAAI;oBAC5B,IAAI;oBACJ,QAAQ,EAAE,KAAK;oBACf,WAAW,EAAE,IAAI;oBACjB,aAAa,EAAE;wBACb,KAAe,CAAC,OAAO;wBACvB,KAAe,CAAC,KAAK,IAAI,EAAE;qBAC5B;iBACD,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC;QACF,CAAC;aAAM,CAAC;YACP,MAAM,MAAM,GAAkB;gBAC7B,IAAI,EAAE,iBAAiB,CAAC,IAAI;gBAC5B,IAAI;gBACJ,WAAW,EAAE,IAAI;gBACjB,aAAa,EAAE,EAAE;aACjB,CAAC;YACF,OAAO,MAAM,CAAC;QACf,CAAC;IACF,CAAC;CACD,CAAC,CAAC","sourcesContent":["import { updatePackageJsonFile } from \"@tylerbu/cli-api\";\nimport { call } from \"effection\";\nimport { resolve as resolvePath } from \"pathe\";\nimport { sortPackageJson } from \"sort-package-json\";\nimport type { PolicyFailure, PolicyFixResult } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\n\n/**\n * A repo policy that checks if package.json files in the repo are sorted using sort-package-json.\n *\n * @alpha\n */\nexport const PackageJsonSorted = definePackagePolicy({\n\tname: \"PackageJsonSorted\",\n\tdescription:\n\t\t\"Ensures package.json files are sorted consistently using sort-package-json.\",\n\thandler: function* (json, { file, root, resolve }) {\n\t\tconst sortedJson = sortPackageJson(json);\n\t\tconst isSorted = JSON.stringify(sortedJson) === JSON.stringify(json);\n\n\t\tif (isSorted) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (resolve) {\n\t\t\ttry {\n\t\t\t\tyield* call(() =>\n\t\t\t\t\tupdatePackageJsonFile(resolvePath(root, file), (pkgJson) => pkgJson, {\n\t\t\t\t\t\tsort: true,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tconst result: PolicyFixResult = {\n\t\t\t\t\tname: PackageJsonSorted.name,\n\t\t\t\t\tfile,\n\t\t\t\t\tresolved: true,\n\t\t\t\t\terrorMessages: [],\n\t\t\t\t};\n\t\t\t\treturn result;\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst result: PolicyFixResult = {\n\t\t\t\t\tname: PackageJsonSorted.name,\n\t\t\t\t\tfile,\n\t\t\t\t\tresolved: false,\n\t\t\t\t\tautoFixable: true,\n\t\t\t\t\terrorMessages: [\n\t\t\t\t\t\t(error as Error).message,\n\t\t\t\t\t\t(error as Error).stack ?? \"\",\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t\treturn result;\n\t\t\t}\n\t\t} else {\n\t\t\tconst result: PolicyFailure = {\n\t\t\t\tname: PackageJsonSorted.name,\n\t\t\t\tfile,\n\t\t\t\tautoFixable: true,\n\t\t\t\terrorMessages: [],\n\t\t\t};\n\t\t\treturn result;\n\t\t}\n\t},\n});\n"]}
1
+ {"version":3,"file":"PackageJsonSorted.js","sourceRoot":"","sources":["../../src/policies/PackageJsonSorted.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,y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AAE,OAAO,EAAE,CAAC,CAC1B,CAAC;YACF,OAAO,MAAM,CAAC;QACf,CAAC;QAED,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAErE,IAAI,QAAQ,EAAE,CAAC;YACd,OAAO,EAAE,CAAC;QACX,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,CAAC;gBACJ,MAAM,eAAe,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAChD,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,eAAe,CAAC,CAAC;gBACxD,MAAM,SAAS,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;gBACjE,MAAM,MAAM,GAAoB;oBAC/B,EAAE,OAAO,EAAE,6BAA6B,EAAE,SAAS,EAAE,OAAO,EAAE;iBAC9D,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACzB,MAAM,MAAM,GAAoB;oBAC/B;wBACC,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;wBAC/D,SAAS,EAAE,QAAQ;qBACnB;iBACD,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC;QACF,CAAC;aAAM,CAAC;YACP,MAAM,MAAM,GAAoB;gBAC/B,EAAE,OAAO,EAAE,6BAA6B,EAAE,SAAS,EAAE,WAAW,EAAE;aAClE,CAAC;YACF,OAAO,MAAM,CAAC;QACf,CAAC;IACF,CAAC;CACD,CAAC,CAAC","sourcesContent":["import jsonfile from \"jsonfile\";\nimport { resolve as resolvePath } from \"pathe\";\nimport type { PolicyFinding } from \"../policy.js\";\nimport { definePackagePolicy } from \"../policyDefiners/definePackagePolicy.js\";\nimport { detectIndentation } from \"../utils/indentation.js\";\n\nconst { writeFile: writeJson } = jsonfile;\nconst missingDependencyMessage =\n\t\"PackageJsonSorted requires the optional peer dependency sort-package-json. Install it to enable this policy.\";\n\nfunction isMissingSortPackageJsonError(error: unknown): boolean {\n\tif (\n\t\terror instanceof Error &&\n\t\t\"code\" in error &&\n\t\terror.code === \"ERR_MODULE_NOT_FOUND\" &&\n\t\terror.message.includes(\"sort-package-json\")\n\t) {\n\t\treturn true;\n\t}\n\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"cause\" in error &&\n\t\tisMissingSortPackageJsonError(error.cause)\n\t);\n}\n\nasync function loadSortPackageJson() {\n\ttry {\n\t\tconst { sortPackageJson } = await import(\"sort-package-json\");\n\t\treturn sortPackageJson;\n\t} catch (error: unknown) {\n\t\tif (isMissingSortPackageJsonError(error)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * A repo policy that checks if package.json files in the repo are sorted using sort-package-json.\n *\n * @public\n */\nexport const PackageJsonSorted = definePackagePolicy({\n\tname: \"PackageJsonSorted\",\n\tdescription:\n\t\t\"Ensures package.json files are sorted consistently using sort-package-json.\",\n\thandler: async (json, { file, root, resolve }) => {\n\t\tconst sortPackageJson = await loadSortPackageJson();\n\t\tif (sortPackageJson === undefined) {\n\t\t\tconst result: PolicyFinding[] = [missingDependencyMessage].map(\n\t\t\t\t(message) => ({ message }),\n\t\t\t);\n\t\t\treturn result;\n\t\t}\n\n\t\tconst sortedJson = sortPackageJson(json);\n\t\tconst isSorted = JSON.stringify(sortedJson) === JSON.stringify(json);\n\n\t\tif (isSorted) {\n\t\t\treturn [];\n\t\t}\n\n\t\tif (resolve) {\n\t\t\ttry {\n\t\t\t\tconst packageJsonPath = resolvePath(root, file);\n\t\t\t\tconst indent = await detectIndentation(packageJsonPath);\n\t\t\t\tawait writeJson(packageJsonPath, sortedJson, { spaces: indent });\n\t\t\t\tconst result: PolicyFinding[] = [\n\t\t\t\t\t{ message: \"package.json is not sorted.\", fixStatus: \"fixed\" },\n\t\t\t\t];\n\t\t\t\treturn result;\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst result: PolicyFinding[] = [\n\t\t\t\t\t{\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t\tfixStatus: \"failed\",\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t\treturn result;\n\t\t\t}\n\t\t} else {\n\t\t\tconst result: PolicyFinding[] = [\n\t\t\t\t{ message: \"package.json is not sorted.\", fixStatus: \"available\" },\n\t\t\t];\n\t\t\treturn result;\n\t\t}\n\t},\n});\n"]}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Policy settings for the PackageLicense repo policy.
3
3
  *
4
- * @alpha
4
+ * @public
5
5
  */
6
6
  export interface PackageLicenseSettings {
7
7
  /**
@@ -50,12 +50,12 @@ export interface PackageLicenseSettings {
50
50
  * makePolicy(PackageLicense),
51
51
  *
52
52
  * // Or require LICENSE for all packages including private
53
- * makePolicy(PackageLicense, { skipPrivate: false }),
53
+ * // makePolicy(PackageLicense, { config: { skipPrivate: false } }),
54
54
  * ],
55
55
  * };
56
56
  * ```
57
57
  *
58
- * @alpha
58
+ * @public
59
59
  */
60
- export declare const PackageLicense: import("../policy.js").PolicyShape<PackageLicenseSettings | undefined>;
60
+ export declare const PackageLicense: import("../policy.js").FilePolicyDefinition<PackageLicenseSettings | undefined>;
61
61
  //# sourceMappingURL=PackageLicense.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackageLicense.d.ts","sourceRoot":"","sources":["../../src/policies/PackageLicense.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AA8CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,cAAc,wEA0FzB,CAAC"}
1
+ {"version":3,"file":"PackageLicense.d.ts","sourceRoot":"","sources":["../../src/policies/PackageLicense.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAkCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,cAAc,iFA6EzB,CAAC"}
@@ -6,35 +6,23 @@ const DEFAULT_LICENSE_FILE_NAME = "LICENSE";
6
6
  const POLICY_NAME = "PackageLicense";
7
7
  /**
8
8
  * Copies the root LICENSE file to the package directory.
9
- * @returns A PolicyFixResult indicating success or failure.
9
+ * @returns Findings that record whether the license was fixed.
10
10
  */
11
- async function copyLicenseFile(rootLicensePath, packageLicensePath, policyName, file, packageName, licenseFileName, isCreate) {
11
+ async function copyLicenseFile(rootLicensePath, packageLicensePath, _policyName, _file, packageName, licenseFileName, isCreate) {
12
12
  try {
13
13
  await copyFile(rootLicensePath, packageLicensePath);
14
- return {
15
- name: policyName,
16
- file,
17
- resolved: true,
18
- autoFixable: true,
19
- errorMessages: [
20
- isCreate
21
- ? `Created ${licenseFileName} file for package "${packageName}"`
22
- : `Updated ${licenseFileName} file for package "${packageName}" to match root`,
23
- ],
24
- };
14
+ return [
15
+ isCreate
16
+ ? `Created ${licenseFileName} file for package "${packageName}"`
17
+ : `Updated ${licenseFileName} file for package "${packageName}" to match root`,
18
+ ].map((message) => ({ message, fixStatus: "fixed" }));
25
19
  }
26
20
  catch {
27
- return {
28
- name: policyName,
29
- file,
30
- resolved: false,
31
- autoFixable: true,
32
- errorMessages: [
33
- isCreate
34
- ? `Failed to copy ${licenseFileName} to package "${packageName}"`
35
- : `Failed to update ${licenseFileName} for package "${packageName}"`,
36
- ],
37
- };
21
+ return [
22
+ isCreate
23
+ ? `Failed to copy ${licenseFileName} to package "${packageName}"`
24
+ : `Failed to update ${licenseFileName} for package "${packageName}"`,
25
+ ].map((message) => ({ message, fixStatus: "failed" }));
38
26
  }
39
27
  }
40
28
  /**
@@ -64,12 +52,12 @@ async function copyLicenseFile(rootLicensePath, packageLicensePath, policyName,
64
52
  * makePolicy(PackageLicense),
65
53
  *
66
54
  * // Or require LICENSE for all packages including private
67
- * makePolicy(PackageLicense, { skipPrivate: false }),
55
+ * // makePolicy(PackageLicense, { config: { skipPrivate: false } }),
68
56
  * ],
69
57
  * };
70
58
  * ```
71
59
  *
72
- * @alpha
60
+ * @public
73
61
  */
74
62
  export const PackageLicense = definePackagePolicy({
75
63
  name: "PackageLicense",
@@ -79,37 +67,29 @@ export const PackageLicense = definePackagePolicy({
79
67
  const licenseFileName = config?.licenseFileName ?? DEFAULT_LICENSE_FILE_NAME;
80
68
  // Skip private packages if configured to do so
81
69
  if (skipPrivate && json.private === true) {
82
- return true;
70
+ return [];
83
71
  }
84
72
  const packageName = json.name ?? "unknown";
85
- // file is an absolute path, get the directory containing package.json
86
- const packageDir = path.dirname(file);
73
+ const packageDir = path.dirname(path.resolve(root, file));
87
74
  const packageLicensePath = path.join(packageDir, licenseFileName);
88
75
  const rootLicensePath = path.join(root, licenseFileName);
89
76
  // Check if root LICENSE exists
90
77
  if (!existsSync(rootLicensePath)) {
91
- return {
92
- name: POLICY_NAME,
93
- file,
94
- autoFixable: false,
95
- errorMessages: [
96
- `Cannot validate package LICENSE: root ${licenseFileName} file not found`,
97
- ],
98
- };
78
+ return [
79
+ `Cannot validate package LICENSE: root ${licenseFileName} file not found`,
80
+ ].map((message) => ({ message }));
99
81
  }
100
82
  // Check if package LICENSE exists
101
83
  if (!existsSync(packageLicensePath)) {
102
84
  if (resolve) {
103
85
  return await copyLicenseFile(rootLicensePath, packageLicensePath, POLICY_NAME, file, packageName, licenseFileName, true);
104
86
  }
105
- return {
106
- name: POLICY_NAME,
107
- file,
108
- autoFixable: true,
109
- errorMessages: [
110
- `${licenseFileName} file missing for package "${packageName}"`,
111
- ],
112
- };
87
+ return [
88
+ `${licenseFileName} file missing for package "${packageName}"`,
89
+ ].map((message) => ({
90
+ message,
91
+ fixStatus: "available",
92
+ }));
113
93
  }
114
94
  // Compare package LICENSE with root LICENSE
115
95
  const [packageLicenseContent, rootLicenseContent] = await Promise.all([
@@ -120,16 +100,14 @@ export const PackageLicense = definePackagePolicy({
120
100
  if (resolve) {
121
101
  return await copyLicenseFile(rootLicensePath, packageLicensePath, POLICY_NAME, file, packageName, licenseFileName, false);
122
102
  }
123
- return {
124
- name: POLICY_NAME,
125
- file,
126
- autoFixable: true,
127
- errorMessages: [
128
- `${licenseFileName} file in package "${packageName}" doesn't match root ${licenseFileName}`,
129
- ],
130
- };
103
+ return [
104
+ `${licenseFileName} file in package "${packageName}" doesn't match root ${licenseFileName}`,
105
+ ].map((message) => ({
106
+ message,
107
+ fixStatus: "available",
108
+ }));
131
109
  }
132
- return true;
110
+ return [];
133
111
  },
134
112
  });
135
113
  //# sourceMappingURL=PackageLicense.js.map