@xylabs/ts-scripts-yarn3 7.4.28 → 7.5.1

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 (412) hide show
  1. package/dist/actions/deploy-major.mjs +1 -90
  2. package/dist/actions/deploy-major.mjs.map +1 -1
  3. package/dist/actions/deploy-minor.mjs +1 -90
  4. package/dist/actions/deploy-minor.mjs.map +1 -1
  5. package/dist/actions/deploy-next.mjs +1 -90
  6. package/dist/actions/deploy-next.mjs.map +1 -1
  7. package/dist/actions/deploy.mjs +1 -90
  8. package/dist/actions/deploy.mjs.map +1 -1
  9. package/dist/actions/index.mjs +128 -3840
  10. package/dist/actions/index.mjs.map +1 -1
  11. package/dist/actions/publish.mjs +1 -90
  12. package/dist/actions/publish.mjs.map +1 -1
  13. package/dist/actions/reinstall.mjs +1 -90
  14. package/dist/actions/reinstall.mjs.map +1 -1
  15. package/dist/actions/up.mjs +1 -90
  16. package/dist/actions/up.mjs.map +1 -1
  17. package/dist/actions/updo.mjs +1 -90
  18. package/dist/actions/updo.mjs.map +1 -1
  19. package/dist/actions/upplug.mjs +1 -90
  20. package/dist/actions/upplug.mjs.map +1 -1
  21. package/dist/actions/upyarn.mjs +1 -90
  22. package/dist/actions/upyarn.mjs.map +1 -1
  23. package/dist/actions/yarn3only.mjs +2 -32
  24. package/dist/actions/yarn3only.mjs.map +1 -1
  25. package/dist/bin/xy.mjs +222 -3684
  26. package/dist/bin/xy.mjs.map +1 -1
  27. package/dist/index.d.ts +24 -502
  28. package/dist/index.mjs +224 -4659
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/lib/index.mjs +0 -804
  31. package/dist/lib/index.mjs.map +1 -1
  32. package/dist/lib/yarn/index.mjs +0 -7
  33. package/dist/lib/yarn/index.mjs.map +1 -1
  34. package/dist/pm/index.mjs +82 -0
  35. package/dist/pm/index.mjs.map +1 -0
  36. package/dist/pm/yarnPackageManager.mjs +82 -0
  37. package/dist/pm/yarnPackageManager.mjs.map +1 -0
  38. package/dist/xy/common/index.mjs +7 -1459
  39. package/dist/xy/common/index.mjs.map +1 -1
  40. package/dist/xy/common/upplugCommand.mjs +1 -90
  41. package/dist/xy/common/upplugCommand.mjs.map +1 -1
  42. package/dist/xy/common/upyarnCommand.mjs +1 -90
  43. package/dist/xy/common/upyarnCommand.mjs.map +1 -1
  44. package/dist/xy/common/yarn3OnlyCommand.mjs +1 -33
  45. package/dist/xy/common/yarn3OnlyCommand.mjs.map +1 -1
  46. package/dist/xy/deploy/deployCommand.mjs +3 -90
  47. package/dist/xy/deploy/deployCommand.mjs.map +1 -1
  48. package/dist/xy/deploy/deployMajorCommand.mjs +1 -90
  49. package/dist/xy/deploy/deployMajorCommand.mjs.map +1 -1
  50. package/dist/xy/deploy/deployMinorCommand.mjs +1 -90
  51. package/dist/xy/deploy/deployMinorCommand.mjs.map +1 -1
  52. package/dist/xy/deploy/deployNextCommand.mjs +1 -90
  53. package/dist/xy/deploy/deployNextCommand.mjs.map +1 -1
  54. package/dist/xy/deploy/index.mjs +11 -94
  55. package/dist/xy/deploy/index.mjs.map +1 -1
  56. package/dist/xy/deploy/publishCommand.mjs +1 -90
  57. package/dist/xy/deploy/publishCommand.mjs.map +1 -1
  58. package/dist/xy/index.mjs +183 -3717
  59. package/dist/xy/index.mjs.map +1 -1
  60. package/dist/xy/install/cleanCommand.mjs +6 -118
  61. package/dist/xy/install/cleanCommand.mjs.map +1 -1
  62. package/dist/xy/install/dupdepsCommand.mjs +6 -178
  63. package/dist/xy/install/dupdepsCommand.mjs.map +1 -1
  64. package/dist/xy/install/index.mjs +12 -305
  65. package/dist/xy/install/index.mjs.map +1 -1
  66. package/dist/xy/install/reinstallCommand.mjs +1 -90
  67. package/dist/xy/install/reinstallCommand.mjs.map +1 -1
  68. package/dist/xy/install/staticsCommand.mjs +6 -177
  69. package/dist/xy/install/staticsCommand.mjs.map +1 -1
  70. package/dist/xy/install/upCommand.mjs +1 -90
  71. package/dist/xy/install/upCommand.mjs.map +1 -1
  72. package/dist/xy/install/updoCommand.mjs +1 -90
  73. package/dist/xy/install/updoCommand.mjs.map +1 -1
  74. package/dist/xy/xy.mjs +64 -3595
  75. package/dist/xy/xy.mjs.map +1 -1
  76. package/dist/xy/yarnCommands.mjs +80 -0
  77. package/dist/xy/yarnCommands.mjs.map +1 -0
  78. package/package.json +5 -47
  79. package/dist/actions/build.mjs +0 -140
  80. package/dist/actions/build.mjs.map +0 -1
  81. package/dist/actions/claude-clean.mjs +0 -71
  82. package/dist/actions/claude-clean.mjs.map +0 -1
  83. package/dist/actions/claude-commands.mjs +0 -112
  84. package/dist/actions/claude-commands.mjs.map +0 -1
  85. package/dist/actions/claude-rules.mjs +0 -137
  86. package/dist/actions/claude-rules.mjs.map +0 -1
  87. package/dist/actions/claude-settings.mjs +0 -85
  88. package/dist/actions/claude-settings.mjs.map +0 -1
  89. package/dist/actions/claude-skills.mjs +0 -120
  90. package/dist/actions/claude-skills.mjs.map +0 -1
  91. package/dist/actions/clean-docs.mjs +0 -37
  92. package/dist/actions/clean-docs.mjs.map +0 -1
  93. package/dist/actions/clean-eslint.mjs +0 -26
  94. package/dist/actions/clean-eslint.mjs.map +0 -1
  95. package/dist/actions/clean.mjs +0 -124
  96. package/dist/actions/clean.mjs.map +0 -1
  97. package/dist/actions/compile.mjs +0 -157
  98. package/dist/actions/compile.mjs.map +0 -1
  99. package/dist/actions/copy-assets.mjs +0 -73
  100. package/dist/actions/copy-assets.mjs.map +0 -1
  101. package/dist/actions/cycle.mjs +0 -144
  102. package/dist/actions/cycle.mjs.map +0 -1
  103. package/dist/actions/dead.mjs +0 -98
  104. package/dist/actions/dead.mjs.map +0 -1
  105. package/dist/actions/deplint/checkPackage/checkPackage.mjs +0 -672
  106. package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +0 -1
  107. package/dist/actions/deplint/checkPackage/checkPackageTypes.mjs +0 -1
  108. package/dist/actions/deplint/checkPackage/checkPackageTypes.mjs.map +0 -1
  109. package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs +0 -48
  110. package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs.map +0 -1
  111. package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs +0 -33
  112. package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs.map +0 -1
  113. package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs +0 -30
  114. package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs.map +0 -1
  115. package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs +0 -309
  116. package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs.map +0 -1
  117. package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs +0 -26
  118. package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs.map +0 -1
  119. package/dist/actions/deplint/checkPackage/index.mjs +0 -672
  120. package/dist/actions/deplint/checkPackage/index.mjs.map +0 -1
  121. package/dist/actions/deplint/deplint.mjs +0 -764
  122. package/dist/actions/deplint/deplint.mjs.map +0 -1
  123. package/dist/actions/deplint/findFiles.mjs +0 -39
  124. package/dist/actions/deplint/findFiles.mjs.map +0 -1
  125. package/dist/actions/deplint/findFilesByGlob.mjs +0 -14
  126. package/dist/actions/deplint/findFilesByGlob.mjs.map +0 -1
  127. package/dist/actions/deplint/getBasePackageName.mjs +0 -13
  128. package/dist/actions/deplint/getBasePackageName.mjs.map +0 -1
  129. package/dist/actions/deplint/getCliReferencedPackagesFromFiles.mjs +0 -140
  130. package/dist/actions/deplint/getCliReferencedPackagesFromFiles.mjs.map +0 -1
  131. package/dist/actions/deplint/getDependenciesFromPackageJson.mjs +0 -20
  132. package/dist/actions/deplint/getDependenciesFromPackageJson.mjs.map +0 -1
  133. package/dist/actions/deplint/getExtendsFromTsconfigs.mjs +0 -44
  134. package/dist/actions/deplint/getExtendsFromTsconfigs.mjs.map +0 -1
  135. package/dist/actions/deplint/getExternalImportsFromFiles.mjs +0 -122
  136. package/dist/actions/deplint/getExternalImportsFromFiles.mjs.map +0 -1
  137. package/dist/actions/deplint/getImportsFromFile.mjs +0 -85
  138. package/dist/actions/deplint/getImportsFromFile.mjs.map +0 -1
  139. package/dist/actions/deplint/getRequiredPeerDependencies.mjs +0 -36
  140. package/dist/actions/deplint/getRequiredPeerDependencies.mjs.map +0 -1
  141. package/dist/actions/deplint/getScriptReferencedPackages.mjs +0 -83
  142. package/dist/actions/deplint/getScriptReferencedPackages.mjs.map +0 -1
  143. package/dist/actions/deplint/implicitDevDependencies.mjs +0 -80
  144. package/dist/actions/deplint/implicitDevDependencies.mjs.map +0 -1
  145. package/dist/actions/deplint/index.mjs +0 -764
  146. package/dist/actions/deplint/index.mjs.map +0 -1
  147. package/dist/actions/dupdeps.mjs +0 -184
  148. package/dist/actions/dupdeps.mjs.map +0 -1
  149. package/dist/actions/fix.mjs +0 -147
  150. package/dist/actions/fix.mjs.map +0 -1
  151. package/dist/actions/gen-docs.mjs +0 -109
  152. package/dist/actions/gen-docs.mjs.map +0 -1
  153. package/dist/actions/gitignore.mjs +0 -152
  154. package/dist/actions/gitignore.mjs.map +0 -1
  155. package/dist/actions/gitlint-fix.mjs +0 -27
  156. package/dist/actions/gitlint-fix.mjs.map +0 -1
  157. package/dist/actions/gitlint.mjs +0 -48
  158. package/dist/actions/gitlint.mjs.map +0 -1
  159. package/dist/actions/knip.mjs +0 -98
  160. package/dist/actions/knip.mjs.map +0 -1
  161. package/dist/actions/license.mjs +0 -84
  162. package/dist/actions/license.mjs.map +0 -1
  163. package/dist/actions/lint.mjs +0 -144
  164. package/dist/actions/lint.mjs.map +0 -1
  165. package/dist/actions/lintlint.mjs +0 -230
  166. package/dist/actions/lintlint.mjs.map +0 -1
  167. package/dist/actions/npmignore-gen.mjs +0 -88
  168. package/dist/actions/npmignore-gen.mjs.map +0 -1
  169. package/dist/actions/package/clean-outputs.mjs +0 -29
  170. package/dist/actions/package/clean-outputs.mjs.map +0 -1
  171. package/dist/actions/package/clean-typescript.mjs +0 -29
  172. package/dist/actions/package/clean-typescript.mjs.map +0 -1
  173. package/dist/actions/package/clean.mjs +0 -48
  174. package/dist/actions/package/clean.mjs.map +0 -1
  175. package/dist/actions/package/compile/XyConfig.mjs +0 -1
  176. package/dist/actions/package/compile/XyConfig.mjs.map +0 -1
  177. package/dist/actions/package/compile/buildEntries.mjs +0 -53
  178. package/dist/actions/package/compile/buildEntries.mjs.map +0 -1
  179. package/dist/actions/package/compile/compile.mjs +0 -433
  180. package/dist/actions/package/compile/compile.mjs.map +0 -1
  181. package/dist/actions/package/compile/copyTypeFiles.mjs +0 -34
  182. package/dist/actions/package/compile/copyTypeFiles.mjs.map +0 -1
  183. package/dist/actions/package/compile/deepMerge.mjs +0 -26
  184. package/dist/actions/package/compile/deepMerge.mjs.map +0 -1
  185. package/dist/actions/package/compile/getCompilerOptions.mjs +0 -12
  186. package/dist/actions/package/compile/getCompilerOptions.mjs.map +0 -1
  187. package/dist/actions/package/compile/index.mjs +0 -436
  188. package/dist/actions/package/compile/index.mjs.map +0 -1
  189. package/dist/actions/package/compile/inputs.mjs +0 -22
  190. package/dist/actions/package/compile/inputs.mjs.map +0 -1
  191. package/dist/actions/package/compile/packageCompileTsc.mjs +0 -94
  192. package/dist/actions/package/compile/packageCompileTsc.mjs.map +0 -1
  193. package/dist/actions/package/compile/packageCompileTscTypes.mjs +0 -92
  194. package/dist/actions/package/compile/packageCompileTscTypes.mjs.map +0 -1
  195. package/dist/actions/package/compile/packageCompileTsup.mjs +0 -402
  196. package/dist/actions/package/compile/packageCompileTsup.mjs.map +0 -1
  197. package/dist/actions/package/copy-assets.mjs +0 -46
  198. package/dist/actions/package/copy-assets.mjs.map +0 -1
  199. package/dist/actions/package/cycle.mjs +0 -39
  200. package/dist/actions/package/cycle.mjs.map +0 -1
  201. package/dist/actions/package/gen-docs.mjs +0 -114
  202. package/dist/actions/package/gen-docs.mjs.map +0 -1
  203. package/dist/actions/package/index.mjs +0 -825
  204. package/dist/actions/package/index.mjs.map +0 -1
  205. package/dist/actions/package/lint.mjs +0 -80
  206. package/dist/actions/package/lint.mjs.map +0 -1
  207. package/dist/actions/package/publint.mjs +0 -66
  208. package/dist/actions/package/publint.mjs.map +0 -1
  209. package/dist/actions/package/recompile.mjs +0 -483
  210. package/dist/actions/package/recompile.mjs.map +0 -1
  211. package/dist/actions/package-lint.mjs +0 -178
  212. package/dist/actions/package-lint.mjs.map +0 -1
  213. package/dist/actions/publint.mjs +0 -166
  214. package/dist/actions/publint.mjs.map +0 -1
  215. package/dist/actions/readme-gen.mjs +0 -289
  216. package/dist/actions/readme-gen.mjs.map +0 -1
  217. package/dist/actions/readme-init.mjs +0 -83
  218. package/dist/actions/readme-init.mjs.map +0 -1
  219. package/dist/actions/rebuild.mjs +0 -101
  220. package/dist/actions/rebuild.mjs.map +0 -1
  221. package/dist/actions/recompile.mjs +0 -187
  222. package/dist/actions/recompile.mjs.map +0 -1
  223. package/dist/actions/relint.mjs +0 -144
  224. package/dist/actions/relint.mjs.map +0 -1
  225. package/dist/actions/retest.mjs +0 -123
  226. package/dist/actions/retest.mjs.map +0 -1
  227. package/dist/actions/sonar.mjs +0 -98
  228. package/dist/actions/sonar.mjs.map +0 -1
  229. package/dist/actions/statics.mjs +0 -183
  230. package/dist/actions/statics.mjs.map +0 -1
  231. package/dist/actions/test.mjs +0 -117
  232. package/dist/actions/test.mjs.map +0 -1
  233. package/dist/bin/package/build-only.mjs +0 -445
  234. package/dist/bin/package/build-only.mjs.map +0 -1
  235. package/dist/bin/package/build.mjs +0 -445
  236. package/dist/bin/package/build.mjs.map +0 -1
  237. package/dist/bin/package/clean-outputs.mjs +0 -29
  238. package/dist/bin/package/clean-outputs.mjs.map +0 -1
  239. package/dist/bin/package/clean-typescript.mjs +0 -29
  240. package/dist/bin/package/clean-typescript.mjs.map +0 -1
  241. package/dist/bin/package/clean.mjs +0 -53
  242. package/dist/bin/package/clean.mjs.map +0 -1
  243. package/dist/bin/package/compile-only.mjs +0 -441
  244. package/dist/bin/package/compile-only.mjs.map +0 -1
  245. package/dist/bin/package/compile-tsup.mjs +0 -409
  246. package/dist/bin/package/compile-tsup.mjs.map +0 -1
  247. package/dist/bin/package/compile.mjs +0 -445
  248. package/dist/bin/package/compile.mjs.map +0 -1
  249. package/dist/bin/package/copy-assets-cjs.mjs +0 -54
  250. package/dist/bin/package/copy-assets-cjs.mjs.map +0 -1
  251. package/dist/bin/package/copy-assets-esm.mjs +0 -54
  252. package/dist/bin/package/copy-assets-esm.mjs.map +0 -1
  253. package/dist/bin/package/cycle.mjs +0 -51
  254. package/dist/bin/package/cycle.mjs.map +0 -1
  255. package/dist/bin/package/fix.mjs +0 -92
  256. package/dist/bin/package/fix.mjs.map +0 -1
  257. package/dist/bin/package/gen-docs.mjs +0 -121
  258. package/dist/bin/package/gen-docs.mjs.map +0 -1
  259. package/dist/bin/package/lint-verbose.mjs +0 -92
  260. package/dist/bin/package/lint-verbose.mjs.map +0 -1
  261. package/dist/bin/package/lint.mjs +0 -92
  262. package/dist/bin/package/lint.mjs.map +0 -1
  263. package/dist/bin/package/publint.mjs +0 -75
  264. package/dist/bin/package/publint.mjs.map +0 -1
  265. package/dist/bin/package/recompile.mjs +0 -489
  266. package/dist/bin/package/recompile.mjs.map +0 -1
  267. package/dist/bin/package/relint.mjs +0 -92
  268. package/dist/bin/package/relint.mjs.map +0 -1
  269. package/dist/lib/checkResult.mjs +0 -16
  270. package/dist/lib/checkResult.mjs.map +0 -1
  271. package/dist/lib/claudeMdTemplate.mjs +0 -65
  272. package/dist/lib/claudeMdTemplate.mjs.map +0 -1
  273. package/dist/lib/createBuildConfig.mjs +0 -55
  274. package/dist/lib/createBuildConfig.mjs.map +0 -1
  275. package/dist/lib/defaultBuildConfig.mjs +0 -23
  276. package/dist/lib/defaultBuildConfig.mjs.map +0 -1
  277. package/dist/lib/deleteGlob.mjs +0 -13
  278. package/dist/lib/deleteGlob.mjs.map +0 -1
  279. package/dist/lib/dependencies/DuplicateDetector.mjs +0 -81
  280. package/dist/lib/dependencies/DuplicateDetector.mjs.map +0 -1
  281. package/dist/lib/dependencies/detectDuplicateDependencies.mjs +0 -164
  282. package/dist/lib/dependencies/detectDuplicateDependencies.mjs.map +0 -1
  283. package/dist/lib/dependencies/index.mjs +0 -165
  284. package/dist/lib/dependencies/index.mjs.map +0 -1
  285. package/dist/lib/file/ReadFileSyncOptions.mjs +0 -6
  286. package/dist/lib/file/ReadFileSyncOptions.mjs.map +0 -1
  287. package/dist/lib/file/constants.mjs +0 -8
  288. package/dist/lib/file/constants.mjs.map +0 -1
  289. package/dist/lib/file/fileLines.mjs +0 -32
  290. package/dist/lib/file/fileLines.mjs.map +0 -1
  291. package/dist/lib/file/index.mjs +0 -42
  292. package/dist/lib/file/index.mjs.map +0 -1
  293. package/dist/lib/file/tryReadFileSync.mjs +0 -14
  294. package/dist/lib/file/tryReadFileSync.mjs.map +0 -1
  295. package/dist/lib/generateIgnoreFiles.mjs +0 -84
  296. package/dist/lib/generateIgnoreFiles.mjs.map +0 -1
  297. package/dist/lib/generateReadmeFiles.mjs +0 -257
  298. package/dist/lib/generateReadmeFiles.mjs.map +0 -1
  299. package/dist/lib/gitignoreTemplate.mjs +0 -12
  300. package/dist/lib/gitignoreTemplate.mjs.map +0 -1
  301. package/dist/lib/jsonFormatters.mjs +0 -11
  302. package/dist/lib/jsonFormatters.mjs.map +0 -1
  303. package/dist/lib/loadConfig.mjs +0 -24
  304. package/dist/lib/loadConfig.mjs.map +0 -1
  305. package/dist/lib/parsedPackageJSON.mjs +0 -11
  306. package/dist/lib/parsedPackageJSON.mjs.map +0 -1
  307. package/dist/lib/processEx.mjs +0 -36
  308. package/dist/lib/processEx.mjs.map +0 -1
  309. package/dist/lib/runSteps.mjs +0 -95
  310. package/dist/lib/runSteps.mjs.map +0 -1
  311. package/dist/lib/runStepsAsync.mjs +0 -113
  312. package/dist/lib/runStepsAsync.mjs.map +0 -1
  313. package/dist/lib/runXy.mjs +0 -103
  314. package/dist/lib/runXy.mjs.map +0 -1
  315. package/dist/lib/runXyWithWarning.mjs +0 -13
  316. package/dist/lib/runXyWithWarning.mjs.map +0 -1
  317. package/dist/lib/safeExit.mjs +0 -61
  318. package/dist/lib/safeExit.mjs.map +0 -1
  319. package/dist/lib/string/empty.mjs +0 -8
  320. package/dist/lib/string/empty.mjs.map +0 -1
  321. package/dist/lib/string/index.mjs +0 -12
  322. package/dist/lib/string/index.mjs.map +0 -1
  323. package/dist/lib/string/union.mjs +0 -6
  324. package/dist/lib/string/union.mjs.map +0 -1
  325. package/dist/lib/tryRunLocalScript.mjs +0 -33
  326. package/dist/lib/tryRunLocalScript.mjs.map +0 -1
  327. package/dist/lib/withErrnoException.mjs +0 -13
  328. package/dist/lib/withErrnoException.mjs.map +0 -1
  329. package/dist/lib/withError.mjs +0 -8
  330. package/dist/lib/withError.mjs.map +0 -1
  331. package/dist/loadPackageConfig.mjs +0 -11
  332. package/dist/loadPackageConfig.mjs.map +0 -1
  333. package/dist/types.d.mjs +0 -1
  334. package/dist/types.d.mjs.map +0 -1
  335. package/dist/xy/build/buildCommand.mjs +0 -161
  336. package/dist/xy/build/buildCommand.mjs.map +0 -1
  337. package/dist/xy/build/compileCommand.mjs +0 -174
  338. package/dist/xy/build/compileCommand.mjs.map +0 -1
  339. package/dist/xy/build/compileOnlyCommand.mjs +0 -175
  340. package/dist/xy/build/compileOnlyCommand.mjs.map +0 -1
  341. package/dist/xy/build/copyAssetsCommand.mjs +0 -84
  342. package/dist/xy/build/copyAssetsCommand.mjs.map +0 -1
  343. package/dist/xy/build/index.mjs +0 -507
  344. package/dist/xy/build/index.mjs.map +0 -1
  345. package/dist/xy/build/rebuildCommand.mjs +0 -114
  346. package/dist/xy/build/rebuildCommand.mjs.map +0 -1
  347. package/dist/xy/build/recompileCommand.mjs +0 -204
  348. package/dist/xy/build/recompileCommand.mjs.map +0 -1
  349. package/dist/xy/common/claude/cleanCommand.mjs +0 -79
  350. package/dist/xy/common/claude/cleanCommand.mjs.map +0 -1
  351. package/dist/xy/common/claude/commandsCommand.mjs +0 -120
  352. package/dist/xy/common/claude/commandsCommand.mjs.map +0 -1
  353. package/dist/xy/common/claude/index.mjs +0 -546
  354. package/dist/xy/common/claude/index.mjs.map +0 -1
  355. package/dist/xy/common/claude/initCommand.mjs +0 -319
  356. package/dist/xy/common/claude/initCommand.mjs.map +0 -1
  357. package/dist/xy/common/claude/rulesCommand.mjs +0 -153
  358. package/dist/xy/common/claude/rulesCommand.mjs.map +0 -1
  359. package/dist/xy/common/claude/settingsCommand.mjs +0 -93
  360. package/dist/xy/common/claude/settingsCommand.mjs.map +0 -1
  361. package/dist/xy/common/claude/skillsCommand.mjs +0 -129
  362. package/dist/xy/common/claude/skillsCommand.mjs.map +0 -1
  363. package/dist/xy/common/cleanDocsCommand.mjs +0 -45
  364. package/dist/xy/common/cleanDocsCommand.mjs.map +0 -1
  365. package/dist/xy/common/deadCommand.mjs +0 -116
  366. package/dist/xy/common/deadCommand.mjs.map +0 -1
  367. package/dist/xy/common/genDocsCommand.mjs +0 -125
  368. package/dist/xy/common/genDocsCommand.mjs.map +0 -1
  369. package/dist/xy/common/gitignoreCommand.mjs +0 -158
  370. package/dist/xy/common/gitignoreCommand.mjs.map +0 -1
  371. package/dist/xy/common/gitlintCommand.mjs +0 -82
  372. package/dist/xy/common/gitlintCommand.mjs.map +0 -1
  373. package/dist/xy/common/licenseCommand.mjs +0 -100
  374. package/dist/xy/common/licenseCommand.mjs.map +0 -1
  375. package/dist/xy/common/npmignoreGenCommand.mjs +0 -98
  376. package/dist/xy/common/npmignoreGenCommand.mjs.map +0 -1
  377. package/dist/xy/common/readme/genCommand.mjs +0 -321
  378. package/dist/xy/common/readme/genCommand.mjs.map +0 -1
  379. package/dist/xy/common/readme/index.mjs +0 -361
  380. package/dist/xy/common/readme/index.mjs.map +0 -1
  381. package/dist/xy/common/readme/initCommand.mjs +0 -103
  382. package/dist/xy/common/readme/initCommand.mjs.map +0 -1
  383. package/dist/xy/common/retestCommand.mjs +0 -136
  384. package/dist/xy/common/retestCommand.mjs.map +0 -1
  385. package/dist/xy/common/testCommand.mjs +0 -130
  386. package/dist/xy/common/testCommand.mjs.map +0 -1
  387. package/dist/xy/lint/cycleCommand.mjs +0 -163
  388. package/dist/xy/lint/cycleCommand.mjs.map +0 -1
  389. package/dist/xy/lint/deplintCommand.mjs +0 -814
  390. package/dist/xy/lint/deplintCommand.mjs.map +0 -1
  391. package/dist/xy/lint/fixCommand.mjs +0 -168
  392. package/dist/xy/lint/fixCommand.mjs.map +0 -1
  393. package/dist/xy/lint/index.mjs +0 -1691
  394. package/dist/xy/lint/index.mjs.map +0 -1
  395. package/dist/xy/lint/knipCommand.mjs +0 -121
  396. package/dist/xy/lint/knipCommand.mjs.map +0 -1
  397. package/dist/xy/lint/lintCommand.mjs +0 -186
  398. package/dist/xy/lint/lintCommand.mjs.map +0 -1
  399. package/dist/xy/lint/lintlintCommand.mjs +0 -250
  400. package/dist/xy/lint/lintlintCommand.mjs.map +0 -1
  401. package/dist/xy/lint/packageLintCommand.mjs +0 -193
  402. package/dist/xy/lint/packageLintCommand.mjs.map +0 -1
  403. package/dist/xy/lint/publintCommand.mjs +0 -187
  404. package/dist/xy/lint/publintCommand.mjs.map +0 -1
  405. package/dist/xy/lint/relintCommand.mjs +0 -163
  406. package/dist/xy/lint/relintCommand.mjs.map +0 -1
  407. package/dist/xy/lint/sonarCommand.mjs +0 -121
  408. package/dist/xy/lint/sonarCommand.mjs.map +0 -1
  409. package/dist/xy/param.mjs +0 -8
  410. package/dist/xy/param.mjs.map +0 -1
  411. package/dist/xy/xyParseOptions.mjs +0 -70
  412. package/dist/xy/xyParseOptions.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,345 +1,5 @@
1
- // src/actions/build.ts
2
- import chalk11 from "chalk";
3
-
4
- // src/lib/checkResult.ts
5
- import chalk from "chalk";
6
- var checkResult = (name, result, level = "error", exitOnFail = false) => {
7
- if (result) {
8
- const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
9
- const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
10
- console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
11
- if (exitOnFail) {
12
- process.exit(result);
13
- }
14
- }
15
- };
16
-
17
- // src/lib/claudeMdTemplate.ts
18
- import {
19
- readdirSync,
20
- readFileSync,
21
- statSync
22
- } from "fs";
23
- import { createRequire } from "module";
24
- import PATH from "path";
25
- var require2 = createRequire(import.meta.url);
26
- var packageRoot = PATH.dirname(require2.resolve("@xylabs/ts-scripts-yarn3/package.json"));
27
- var templatesDir = PATH.resolve(packageRoot, "templates", "claude");
28
- var XYLABS_RULES_PREFIX = "xylabs-";
29
- var XYLABS_COMMANDS_PREFIX = "xy-";
30
- var LEGACY_COMMANDS_PREFIX = "xylabs-";
31
- var XYLABS_SKILLS_PREFIX = "xylabs-";
32
- var claudeMdRuleTemplates = () => {
33
- const rulesDir = PATH.resolve(templatesDir, "rules");
34
- const files = readdirSync(rulesDir).filter((f) => f.startsWith(XYLABS_RULES_PREFIX) && f.endsWith(".md"));
35
- const result = {};
36
- for (const file of files) {
37
- result[file] = readFileSync(PATH.resolve(rulesDir, file), "utf8");
38
- }
39
- return result;
40
- };
41
- var claudeCommandTemplates = () => {
42
- const commandsDir = PATH.resolve(templatesDir, "commands");
43
- const files = readdirSync(commandsDir).filter((f) => f.startsWith(XYLABS_COMMANDS_PREFIX) && f.endsWith(".md"));
44
- const result = {};
45
- for (const file of files) {
46
- result[file] = readFileSync(PATH.resolve(commandsDir, file), "utf8");
47
- }
48
- return result;
49
- };
50
- var claudeSkillTemplates = () => {
51
- const skillsDir = PATH.resolve(templatesDir, "skills");
52
- const dirs = readdirSync(skillsDir).filter(
53
- (f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync(PATH.resolve(skillsDir, f)).isDirectory()
54
- );
55
- const result = {};
56
- for (const dir of dirs) {
57
- const dirPath = PATH.resolve(skillsDir, dir);
58
- const files = readdirSync(dirPath, { recursive: true, encoding: "utf8" });
59
- result[dir] = {};
60
- for (const file of files) {
61
- if (statSync(PATH.resolve(dirPath, file)).isFile()) {
62
- result[dir][file] = readFileSync(PATH.resolve(dirPath, file), "utf8");
63
- }
64
- }
65
- }
66
- return result;
67
- };
68
- var claudeMdProjectTemplate = () => readFileSync(PATH.resolve(templatesDir, "CLAUDE-project.md"), "utf8");
69
- var claudeMdLocalTemplate = () => readFileSync(PATH.resolve(templatesDir, "CLAUDE-local.md"), "utf8");
70
-
71
- // src/lib/createBuildConfig.ts
72
- import { readFileSync as readFileSync2 } from "fs";
73
-
74
- // src/lib/defaultBuildConfig.ts
75
- var defaultBuildConfig = {
76
- compilerOptions: {
77
- rootDir: "src",
78
- rootDirs: ["package.json"]
79
- },
80
- exclude: [
81
- "**/build",
82
- "**/dist",
83
- "**/node_modules",
84
- "**/*.spec.*",
85
- "**/*.spec",
86
- "**/*.stories.*",
87
- "**/*.example.*",
88
- "**/spec/*",
89
- "**/stories/*"
90
- ],
91
- include: ["src"]
92
- };
93
-
94
- // src/lib/createBuildConfig.ts
95
- var getGeneralTypescriptConfig = (location) => {
96
- let generalConfig;
97
- try {
98
- generalConfig = readFileSync2(`${location}/tsconfig.json`, { encoding: "utf8" });
99
- } catch {
100
- return false;
101
- }
102
- return JSON.parse(generalConfig);
103
- };
104
- var createBuildConfig = (location, module, target, outDirSuffix) => {
105
- const generalConfigObject = getGeneralTypescriptConfig(location);
106
- if (generalConfigObject === false) {
107
- return void 0;
108
- }
109
- return {
110
- ...generalConfigObject,
111
- compilerOptions: {
112
- ...defaultBuildConfig.compilerOptions,
113
- ...generalConfigObject.compilerOptions,
114
- module,
115
- outDir: `./${generalConfigObject.compilerOptions?.outDir ?? "dist"}/${outDirSuffix}`,
116
- target
117
- },
118
- exclude: [...generalConfigObject.exclude ?? [], ...defaultBuildConfig.exclude],
119
- include: [...generalConfigObject.include ?? [], ...defaultBuildConfig.include]
120
- };
121
- };
122
-
123
- // src/lib/deleteGlob.ts
124
- import fs from "fs";
125
- import { glob } from "glob";
126
- var deleteGlob = (globPath) => {
127
- const files = glob.sync(globPath);
128
- for (const file of files) {
129
- fs.rmSync(file, { recursive: true, force: true });
130
- }
131
- };
132
-
133
- // src/lib/dependencies/detectDuplicateDependencies.ts
134
- import { execSync } from "child_process";
135
-
136
- // src/lib/processEx.ts
137
- import chalk2 from "chalk";
138
-
139
- // src/lib/withError.ts
140
- var withError = (ex, closure, predicate = (ex2) => !!ex2.name && !!ex2.message) => {
141
- return predicate(ex) ? closure(ex) : void 0;
142
- };
143
-
144
- // src/lib/withErrnoException.ts
145
- var withErrnoException = (ex, closure) => {
146
- return withError(ex, closure, (ex2) => ex2.errno !== void 0);
147
- };
148
-
149
- // src/lib/processEx.ts
150
- var processEx = (ex) => {
151
- const error = typeof ex === "string" ? new Error(ex) : ex;
152
- const exitCode = withErrnoException(error, (error2) => {
153
- if (error2.code === "ENOENT") {
154
- console.error(chalk2.red(`'${error2.path}' not found.`));
155
- } else {
156
- console.error(chalk2.red(`Errno: ${error2.code}`));
157
- }
158
- return error2.errno ?? -1;
159
- }) ?? withError(error, (error2) => {
160
- console.error(chalk2.red(`${error2.name}: ${error2.message}`));
161
- return -1;
162
- }) ?? (() => {
163
- console.error(chalk2.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`));
164
- return -1;
165
- })();
166
- process.exit(process.exitCode ?? exitCode);
167
- };
168
-
169
- // src/lib/safeExit.ts
170
- var safeExit = (func, exitOnFail = true) => {
171
- try {
172
- const result = func();
173
- if (result && exitOnFail) {
174
- process.exit(result);
175
- }
176
- return result;
177
- } catch (ex) {
178
- return processEx(ex);
179
- }
180
- };
181
- var safeExitAsync = async (func, exitOnFail = true) => {
182
- try {
183
- const result = await func();
184
- if (result && exitOnFail) {
185
- process.exit(result);
186
- }
187
- return result;
188
- } catch (ex) {
189
- return processEx(ex);
190
- }
191
- };
192
-
193
- // src/lib/dependencies/DuplicateDetector.ts
194
- import { EOL } from "os";
195
- import chalk3 from "chalk";
196
-
197
- // src/lib/jsonFormatters.ts
198
- var multiLineToJSONArray = (output) => {
199
- const withCommas = output.replaceAll("\r\n", "").replaceAll("\n", ",");
200
- const cleanCollection = withCommas.slice(0, Math.max(0, withCommas.length - 1));
201
- const collection = `[${cleanCollection}]`;
202
- return JSON.parse(collection);
203
- };
204
-
205
- // src/lib/dependencies/DuplicateDetector.ts
206
- var trimVirtualMeta = (value) => {
207
- const virtualParts = value.split("virtual:");
208
- if (virtualParts.length > 1) {
209
- const hashParts = virtualParts[1].split("#");
210
- return virtualParts[0] + hashParts[1];
211
- } else {
212
- return value;
213
- }
214
- };
215
- var trimObjectDependencyVirtualMeta = (obj) => {
216
- const resultObj = {};
217
- for (const [key, value] of Object.entries(obj)) {
218
- resultObj[trimVirtualMeta(key)] = {
219
- descriptor: trimVirtualMeta(value.descriptor),
220
- locator: trimVirtualMeta(value.locator)
221
- };
222
- }
223
- return resultObj;
224
- };
225
- var trimDependencyVirtualMeta = (dependencies) => {
226
- return dependencies.map((dependency) => {
227
- return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) };
228
- });
229
- };
230
- var DuplicateDetector = class {
231
- dependency;
232
- dependencyEntries;
233
- constructor(output, dependency) {
234
- this.dependency = dependency;
235
- this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output));
236
- }
237
- detect() {
238
- const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency));
239
- if (result.duplicateVersions.length > 0) {
240
- console.log(chalk3.yellow(`${EOL}Duplicates found for: ${this.dependency}`));
241
- const duplicateVersions = result.duplicateVersions.toString().replaceAll(",", `${EOL} `);
242
- console.log(chalk3.grey(` ${duplicateVersions}`, EOL));
243
- return 1;
244
- } else {
245
- console.log(`${this.dependency} - OK`);
246
- return 0;
247
- }
248
- }
249
- detectReducer(acc, entry) {
250
- const version = Object.entries(entry.children).map(([k]) => k)[0];
251
- if (!acc.currentVersion) {
252
- acc.currentVersion = version;
253
- return acc;
254
- }
255
- if (acc.currentVersion && acc.currentVersion !== version && !version.includes("@virtual:")) {
256
- if (acc.duplicateVersions.length === 0) {
257
- acc.duplicateVersions.push(acc.currentVersion);
258
- }
259
- acc.duplicateVersions.push(version);
260
- acc.duplicateVersions = [...new Set(acc.duplicateVersions)];
261
- }
262
- return acc;
263
- }
264
- resultsFactory = (dependency) => ({
265
- currentVersion: void 0,
266
- dependency,
267
- duplicateVersions: []
268
- });
269
- };
270
-
271
- // src/lib/dependencies/detectDuplicateDependencies.ts
272
- var detectDuplicateDependencies = (depsFromPackageJSON, DefaultDependencies2) => {
273
- let exitCode = 0;
274
- const dependencies = depsFromPackageJSON?.length ? depsFromPackageJSON : DefaultDependencies2;
275
- return safeExit(() => {
276
- if (dependencies) {
277
- for (const dependency of dependencies) {
278
- let output;
279
- try {
280
- const cmd = `yarn why ${dependency} --json`;
281
- output = execSync(cmd).toString();
282
- } catch (e) {
283
- console.error(`Error running yarn why: ${e}`);
284
- exitCode = 1;
285
- continue;
286
- }
287
- if (output) {
288
- exitCode = new DuplicateDetector(output, dependency).detect();
289
- } else {
290
- console.log(`${dependency} - N/A`);
291
- if (depsFromPackageJSON) {
292
- exitCode = 1;
293
- console.log(`\u{1F6A8} Library ${dependency} was requested in package.json but not found`);
294
- }
295
- }
296
- }
297
- return exitCode;
298
- } else {
299
- console.log("\u{1F6A8} No dependencies where passed");
300
- return exitCode;
301
- }
302
- });
303
- };
304
-
305
- // src/lib/file/constants.ts
306
- var WINDOWS_NEWLINE_REGEX = /\r\n/g;
307
- var CROSS_PLATFORM_NEWLINE = "\n";
308
-
309
- // src/lib/file/fileLines.ts
310
- import {
311
- existsSync,
312
- readFileSync as readFileSync3,
313
- writeFileSync
314
- } from "fs";
315
-
316
- // src/lib/string/empty.ts
317
- var empty = (value) => value?.trim().length === 0;
318
- var notEmpty = (value) => !empty(value);
319
-
320
- // src/lib/string/union.ts
321
- var union = (a, b) => /* @__PURE__ */ new Set([...new Set(a), ...new Set(b)]);
322
-
323
- // src/lib/file/ReadFileSyncOptions.ts
324
- var defaultReadFileSyncOptions = { encoding: "utf8" };
325
-
326
- // src/lib/file/fileLines.ts
327
- var readLines = (uri, options = defaultReadFileSyncOptions) => existsSync(uri) ? readFileSync3(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [];
328
- var readNonEmptyLines = (uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty);
329
- var writeLines = (uri, lines, options = defaultReadFileSyncOptions) => {
330
- const existing = existsSync(uri) ? readFileSync3(uri, options) : void 0;
331
- const desired = lines.join(CROSS_PLATFORM_NEWLINE);
332
- if (existing !== desired) writeFileSync(uri, desired, options);
333
- };
334
-
335
- // src/lib/file/tryReadFileSync.ts
336
- import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
337
- var tryReadFileSync = (uri, options = defaultReadFileSyncOptions) => {
338
- return existsSync2(uri) ? readFileSync4(uri, options) : void 0;
339
- };
340
-
341
- // src/lib/generateIgnoreFiles.ts
342
- import chalk4 from "chalk";
1
+ // src/index.ts
2
+ import { registerPackageManager } from "@xylabs/ts-scripts-common";
343
3
 
344
4
  // src/lib/yarn/isYarnVersionOrGreater.ts
345
5
  import { spawnSync } from "child_process";
@@ -375,4014 +35,247 @@ var yarnWorkspace = (pkg) => {
375
35
  return workspace;
376
36
  };
377
37
 
378
- // src/lib/yarn/yarnInitCwd.ts
379
- var INIT_CWD = () => {
380
- if (!process.env.INIT_CWD) console.error("Missing INIT_CWD");
381
- return process.env.INIT_CWD;
382
- };
383
-
384
- // src/lib/generateIgnoreFiles.ts
385
- var localeCompare = (a, b) => a.localeCompare(b);
386
- var mergeEntries = (a, b) => [...union(a, b)].toSorted(localeCompare);
387
- var generateIgnoreFiles = (filename2, pkg) => {
388
- console.log(chalk4.green(`Generate ${filename2} Files`));
389
- const cwd5 = INIT_CWD() ?? ".";
390
- const workspaces = pkg ? [yarnWorkspace(pkg)] : yarnWorkspaces();
391
- const readEntries = (location) => readNonEmptyLines(`${location}/${filename2}`);
392
- const writeEntries = (location, entries) => writeLines(`${location}/${filename2}`, entries);
393
- const results = workspaces.map(({ location, name }) => {
394
- try {
395
- writeEntries(location, mergeEntries(readEntries(cwd5), readEntries(location)));
396
- return 0;
397
- } catch (ex) {
398
- const error = ex;
399
- console.error(`Generate ${filename2} Files [${name}] [${error.message}]`);
400
- return 1;
401
- }
402
- });
403
- const succeeded = results.every((result) => result === 0);
404
- return succeeded ? 0 : 1;
405
- };
406
-
407
- // src/lib/generateReadmeFiles.ts
408
- import { execSync as execSync2 } from "child_process";
409
- import FS, { readFileSync as readFileSync5 } from "fs";
410
- import {
411
- mkdir,
412
- readFile,
413
- writeFile
414
- } from "fs/promises";
415
- import { createRequire as createRequire2 } from "module";
416
- import PATH2 from "path";
417
- import { createInterface } from "readline";
418
- import chalk5 from "chalk";
419
- var require3 = createRequire2(import.meta.url);
420
- var packageRoot2 = PATH2.dirname(require3.resolve("@xylabs/ts-scripts-yarn3/package.json"));
421
- var readmeTemplatesDir = PATH2.resolve(packageRoot2, "templates", "readme");
422
- function fillTemplate(template, data) {
423
- const additionalData = { ...data, safeName: data.name.replaceAll("/", "__").replaceAll("@", "") };
424
- return template.replaceAll(/\{\{(.*?)\}\}/g, (_, key) => additionalData[key.trim()] ?? "");
425
- }
426
- function generateTypedoc(packageLocation, entryPoints) {
427
- const tempDir = PATH2.join(packageLocation, ".temp-typedoc");
428
- try {
429
- if (!FS.existsSync(tempDir)) {
430
- FS.mkdirSync(tempDir, { recursive: true });
431
- }
432
- const typedocConfig = {
433
- disableSources: true,
434
- entryPointStrategy: "expand",
435
- entryPoints: entryPoints.map((ep) => PATH2.resolve(packageLocation, ep)),
436
- excludeExternals: true,
437
- excludeInternal: true,
438
- excludePrivate: true,
439
- githubPages: false,
440
- hideBreadcrumbs: true,
441
- hideGenerator: true,
442
- hidePageTitle: true,
443
- out: tempDir,
444
- plugin: ["typedoc-plugin-markdown"],
445
- readme: "none",
446
- skipErrorChecking: true,
447
- sort: ["source-order"],
448
- theme: "markdown",
449
- useCodeBlocks: true
450
- };
451
- const typedocJsonPath = PATH2.join(tempDir, "typedoc.json");
452
- FS.writeFileSync(typedocJsonPath, JSON.stringify(typedocConfig, null, 2));
453
- try {
454
- execSync2(`npx typedoc --options ${typedocJsonPath}`, {
455
- cwd: process.cwd(),
456
- stdio: ["ignore", "pipe", "pipe"]
457
- });
458
- } catch {
459
- return "";
460
- }
461
- return consolidateMarkdown(tempDir);
462
- } catch {
463
- return "";
464
- } finally {
38
+ // src/pm/yarnPackageManager.ts
39
+ var YarnPackageManager = class {
40
+ command = "yarn";
41
+ lockfile = "yarn.lock";
42
+ name = "yarn";
43
+ dedupe() {
44
+ return ["yarn", ["dedupe"]];
45
+ }
46
+ findWorkspace(name) {
465
47
  try {
466
- FS.rmSync(tempDir, { force: true, recursive: true });
48
+ return yarnWorkspace(name);
467
49
  } catch {
50
+ return void 0;
468
51
  }
469
52
  }
470
- }
471
- function consolidateMarkdown(tempDir) {
472
- let consolidated = "## Reference\n\n";
473
- const mainReadmePath = PATH2.join(tempDir, "README.md");
474
- if (FS.existsSync(mainReadmePath)) {
475
- const mainContent = FS.readFileSync(mainReadmePath, "utf8").replace(/^---(.|\n)*?---\n/, "").replace(/^# .+\n/, "").replaceAll(/\]\((.+?)\.md\)/g, "](#$1)");
476
- consolidated += mainContent + "\n\n";
477
- }
478
- consolidated += processDirectory(tempDir);
479
- return consolidated.replaceAll(/\n\n\n+/g, "\n\n").replaceAll(/^#### /gm, "### ").replaceAll(/^##### /gm, "#### ").replaceAll(/^###### /gm, "##### ");
480
- }
481
- function processDirectory(dir, level = 0) {
482
- const indent = " ".repeat(level);
483
- let content = "";
484
- try {
485
- const items = FS.readdirSync(dir, { withFileTypes: true });
486
- for (const item of items) {
487
- if (item.isDirectory()) continue;
488
- if (item.name === "README.md" || !item.name.endsWith(".md")) continue;
489
- const fileContent = FS.readFileSync(PATH2.join(dir, item.name), "utf8").replace(/^---(.|\n)*?---\n/, "");
490
- const moduleName = item.name.replace(".md", "");
491
- content += `
492
-
493
- ${indent}### <a id="${moduleName}"></a>${moduleName}
494
-
495
- `;
496
- content += fileContent.replace(/^# .+\n/, "").replaceAll(/\]\((.+?)\.md\)/g, "](#$1)");
497
- }
498
- for (const item of items) {
499
- if (!item.isDirectory()) continue;
500
- if (item.name === "spec" || item.name.includes(".spec")) continue;
501
- content += `
502
-
503
- ${indent}### ${item.name}
504
- `;
505
- content += processDirectory(PATH2.join(dir, item.name), level + 1);
506
- }
507
- } catch {
508
- }
509
- return content;
510
- }
511
- function askConfirmation(question) {
512
- const rl = createInterface({ input: process.stdin, output: process.stdout });
513
- return new Promise((resolve) => {
514
- rl.question(question, (answer) => {
515
- rl.close();
516
- resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
517
- });
518
- });
519
- }
520
- var DEFAULT_README_TEMPLATE = readFileSync5(PATH2.resolve(readmeTemplatesDir, "README.template.md"), "utf8");
521
- var DEFAULT_README_BODY = readFileSync5(PATH2.resolve(readmeTemplatesDir, "README.body.md"), "utf8");
522
- function applyLogoConfig(template, logoUrl, logoLinkUrl) {
523
- let result = template;
524
- if (logoUrl) {
525
- result = result.replace(/\[logo]: .+/, `[logo]: ${logoUrl}`);
526
- if (logoLinkUrl) {
527
- result = result.replace(/\[!\[logo]\[]][^)]*\)/, `[![logo][]](${logoLinkUrl})`);
528
- }
529
- } else {
530
- result = result.replace(/\[!\[logo]\[]][^\n]*\n*/, "");
531
- result = result.replace(/\[logo]: [^\n]*\n?/, "");
532
- }
533
- return result;
534
- }
535
- function resolveTemplatePath(templatePath) {
536
- const cwd5 = INIT_CWD() ?? ".";
537
- return templatePath ?? PATH2.join(cwd5, ".xy", "README.template.md");
538
- }
539
- async function loadOrCreateTemplate(resolvedTemplatePath) {
540
- try {
541
- const template = await readFile(resolvedTemplatePath, "utf8");
542
- return { created: false, template };
543
- } catch {
544
- console.log(chalk5.yellow(`Template not found: ${resolvedTemplatePath}`));
545
- const shouldCreate = await askConfirmation("Would you like to create a stock template? (y/N) ");
546
- if (!shouldCreate) {
547
- throw new Error("Template creation declined");
548
- }
549
- const template = DEFAULT_README_TEMPLATE;
550
- await scaffoldTemplate(resolvedTemplatePath, template);
551
- return { created: true, template };
552
- }
553
- }
554
- async function scaffoldTemplate(resolvedTemplatePath, template) {
555
- const xyDir = PATH2.dirname(resolvedTemplatePath);
556
- await mkdir(xyDir, { recursive: true });
557
- await writeFile(resolvedTemplatePath, template);
558
- console.log(chalk5.green(`Created template: ${resolvedTemplatePath}`));
559
- const bodyPath = PATH2.join(xyDir, "README.body.md");
560
- await writeFile(bodyPath, DEFAULT_README_BODY);
561
- console.log(chalk5.green(`Created body template: ${bodyPath}`));
562
- }
563
- async function resolveBody(location, defaultBody) {
564
- const localBodyPath = PATH2.join(location, "README.body.md");
565
- try {
566
- return await readFile(localBodyPath, "utf8");
567
- } catch {
568
- return defaultBody;
569
- }
570
- }
571
- async function generateReadmeForWorkspace(location, name, template, defaultBody, typedoc, verbose) {
572
- try {
573
- const pkgJsonPath = PATH2.join(location, "package.json");
574
- const pkgJson = JSON.parse(await readFile(pkgJsonPath, "utf8"));
575
- const body = await resolveBody(location, defaultBody);
576
- const typedocContent = typedoc ? generateTypedoc(location, ["src/index*.ts"]) : "";
577
- const readmeContent = fillTemplate(template, {
578
- ...pkgJson,
579
- body,
580
- typedoc: typedocContent
581
- });
582
- await writeFile(PATH2.join(location, "README.md"), readmeContent);
583
- if (verbose) console.log(chalk5.green(` ${name}`));
584
- return true;
585
- } catch (ex) {
586
- const error = ex;
587
- console.warn(chalk5.yellow(` Skipped ${location}: ${error.message}`));
588
- return false;
589
- }
590
- }
591
- async function generateReadmeFiles({
592
- logoLinkUrl,
593
- logoUrl,
594
- pkg,
595
- templatePath,
596
- typedoc = false,
597
- verbose = false
598
- }) {
599
- console.log(chalk5.green("Generate README Files"));
600
- const resolvedTemplatePath = resolveTemplatePath(templatePath);
601
- let template;
602
- let templateCreated;
603
- try {
604
- ({ template, created: templateCreated } = await loadOrCreateTemplate(resolvedTemplatePath));
605
- } catch {
606
- return 1;
607
- }
608
- template = applyLogoConfig(template, logoUrl, logoLinkUrl);
609
- if (templateCreated) {
610
- console.log(chalk5.green("Generating README files for all packages..."));
611
- }
612
- const xyDir = PATH2.dirname(resolvedTemplatePath);
613
- const xyBodyPath = PATH2.join(xyDir, "README.body.md");
614
- let defaultBody;
615
- try {
616
- defaultBody = await readFile(xyBodyPath, "utf8");
617
- } catch {
618
- defaultBody = DEFAULT_README_BODY;
619
- }
620
- const workspaces = pkg && !templateCreated ? [yarnWorkspace(pkg)] : yarnWorkspaces();
621
- let failed = false;
622
- for (const { location, name } of workspaces) {
623
- const success = await generateReadmeForWorkspace(location, name, template, defaultBody, typedoc, verbose);
624
- if (!success) failed = true;
625
- }
626
- return failed ? 1 : 0;
627
- }
628
-
629
- // src/lib/gitignoreTemplate.ts
630
- import { readFileSync as readFileSync6 } from "fs";
631
- import { createRequire as createRequire3 } from "module";
632
- import PATH3 from "path";
633
- var require4 = createRequire3(import.meta.url);
634
- var packageRoot3 = PATH3.dirname(require4.resolve("@xylabs/ts-scripts-yarn3/package.json"));
635
- var templatesDir2 = PATH3.resolve(packageRoot3, "templates", "gitignore");
636
- var gitignoreTemplate = () => readFileSync6(PATH3.resolve(templatesDir2, "template.gitignore"), "utf8");
637
-
638
- // src/lib/loadConfig.ts
639
- import chalk6 from "chalk";
640
- import { cosmiconfig } from "cosmiconfig";
641
- import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
642
- import deepmerge from "deepmerge";
643
- var config;
644
- var loadConfig = async (params) => {
645
- if (config === void 0) {
646
- const cosmicConfigResult = await cosmiconfig("xy", { cache: true, loaders: { ".ts": TypeScriptLoader() } }).search();
647
- config = cosmicConfigResult?.config;
648
- const configFilePath = cosmicConfigResult?.filepath;
649
- if (configFilePath !== void 0) {
650
- console.log(chalk6.green(`Loaded config from ${configFilePath}`));
651
- if (config.verbose) {
652
- console.log(chalk6.gray(`${JSON.stringify(config, null, 2)}`));
653
- }
654
- }
655
- }
656
- return deepmerge(config, params ?? {});
657
- };
658
-
659
- // src/lib/parsedPackageJSON.ts
660
- import { readFileSync as readFileSync7 } from "fs";
661
- var parsedPackageJSON = (path14) => {
662
- const pathToPackageJSON = path14 ?? process.env.npm_package_json ?? "";
663
- const packageJSON = readFileSync7(pathToPackageJSON).toString();
664
- return JSON.parse(packageJSON);
665
- };
666
-
667
- // src/lib/runSteps.ts
668
- import { spawnSync as spawnSync3 } from "child_process";
669
- import { existsSync as existsSync3 } from "fs";
670
- import chalk7 from "chalk";
671
- var runSteps = (name, steps, exitOnFail = true, messages) => {
672
- return safeExit(() => {
673
- const pkgName = process.env.npm_package_name;
674
- console.log(chalk7.green(`${name} [${pkgName}]`));
675
- let totalStatus = 0;
676
- for (const [i, [command, args, config2]] of steps.entries()) {
677
- if (messages?.[i]) {
678
- console.log(chalk7.gray(messages?.[i]));
679
- }
680
- const argList = Array.isArray(args) ? args : args.split(" ");
681
- if (command === "node" && !existsSync3(argList[0])) {
682
- throw new Error(`File not found [${argList[0]}]`);
683
- }
684
- const status = spawnSync3(command, Array.isArray(args) ? args : args.split(" "), {
685
- ...config2,
686
- encoding: "utf8",
687
- env: { FORCE_COLOR: "3", ...process.env },
688
- shell: true,
689
- stdio: "inherit"
690
- }).status ?? 0;
691
- checkResult(name, status, "error", exitOnFail);
692
- totalStatus += status ?? 0;
693
- }
694
- return totalStatus;
695
- }, !!exitOnFail);
696
- };
697
-
698
- // src/lib/runStepsAsync.ts
699
- import { spawn } from "child_process";
700
- import { existsSync as existsSync4 } from "fs";
701
- import chalk8 from "chalk";
702
- var runStepAsync = (name, step, exitOnFail = true, message) => {
703
- return new Promise((resolve) => {
704
- const [command, args, config2] = step;
705
- if (message) {
706
- console.log(chalk8.gray(message));
707
- }
708
- const argList = Array.isArray(args) ? args : args.split(" ");
709
- if (command === "node" && !existsSync4(argList[0])) {
710
- throw new Error(`File not found [${argList[0]}]`);
711
- }
712
- spawn(command, Array.isArray(args) ? args : args.split(" "), {
713
- ...config2,
714
- env: { FORCE_COLOR: "3", ...process.env },
715
- shell: true,
716
- stdio: "inherit"
717
- }).on("close", (code) => {
718
- if (code) {
719
- console.error(
720
- chalk8.red(
721
- `Command Exited With Non-Zero Result [${chalk8.gray(code)}] | ${chalk8.yellow(command)} ${chalk8.white(
722
- Array.isArray(args) ? args.join(" ") : args
723
- )}`
724
- )
725
- );
726
- checkResult(name, code, "error", exitOnFail);
727
- resolve(code);
728
- } else {
729
- resolve(0);
730
- }
731
- });
732
- });
733
- };
734
- var runStepsAsync = async (name, steps, exitOnFail = true, messages) => {
735
- return await safeExitAsync(async () => {
736
- const pkgName = process.env.npm_package_name;
737
- console.log(chalk8.green(`${name} [${pkgName}]`));
738
- let result = 0;
739
- for (const [i, step] of steps.entries()) {
740
- result += await runStepAsync(name, step, exitOnFail, messages?.[i]);
741
- }
742
- return result;
743
- });
744
- };
745
-
746
- // src/lib/runXy.ts
747
- var runXy = (command) => {
748
- return runSteps(
749
- `XY [${command}]`,
750
- [["yarn", ["xy", command, ...process.argv.filter((value, index) => index > 1 ? value : void 0)]]]
751
- );
752
- };
753
-
754
- // src/lib/runXyWithWarning.ts
755
- import chalk9 from "chalk";
756
- var runXyWithWarning = (command) => {
757
- const commandString = `yarn ${command}`;
758
- const commandXyString = `yarn xy ${command}`;
759
- console.warn(chalk9.yellow(`WARNING: [${chalk9.white(commandString)}] is deprecated for XY Labs Scripts.`));
760
- console.warn(chalk9.gray(`Did you mean [${chalk9.magenta(commandXyString)}]?`));
761
- return 1;
762
- };
763
-
764
- // src/lib/tryRunLocalScript.ts
765
- import { spawnSync as spawnSync4 } from "child_process";
766
- import { readFileSync as readFileSync8 } from "fs";
767
- import PATH4 from "path";
768
- import chalk10 from "chalk";
769
- function tryRunLocalScript(commandName) {
770
- if (process.env.XY_LOCAL_SCRIPT === "1") return void 0;
771
- const rootPkgPath = PATH4.resolve(process.cwd(), "package.json");
772
- let rootPkg;
773
- try {
774
- rootPkg = JSON.parse(readFileSync8(rootPkgPath, "utf8"));
775
- } catch {
776
- return void 0;
777
- }
778
- if (!rootPkg.scripts?.[commandName]) return void 0;
779
- console.log(chalk10.blue(`Delegating "${commandName}" to local script`));
780
- const result = spawnSync4("yarn", ["run", commandName], {
781
- cwd: process.cwd(),
782
- encoding: "utf8",
783
- env: {
784
- FORCE_COLOR: "3",
785
- ...process.env,
786
- XY_LOCAL_SCRIPT: "1"
787
- },
788
- shell: true,
789
- stdio: "inherit"
790
- });
791
- return result.status ?? 1;
792
- }
793
-
794
- // src/actions/build.ts
795
- var build = async ({
796
- incremental,
797
- jobs,
798
- target,
799
- verbose,
800
- pkg
801
- }) => {
802
- const start = Date.now();
803
- const pkgOptions = pkg === void 0 ? [] : [pkg];
804
- const incrementalOptions = incremental ? ["-i"] : [];
805
- const verboseOptions = verbose ? ["-v"] : [];
806
- const targetOptions = target === void 0 ? [] : ["-t", target];
807
- const jobsOptions = jobs === void 0 ? [] : ["-j", `${jobs}`];
808
- if (jobs !== void 0) {
809
- console.log(chalk11.blue(`Jobs set to [${jobs}]`));
810
- }
811
- const result = await runStepsAsync(`Build${incremental ? "-Incremental" : ""} [${pkg ?? "All"}]`, [
812
- ["yarn", ["xy", "compile", ...pkgOptions, ...targetOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions, "--types", "tsup"]],
813
- ["yarn", ["xy", "publint", ...pkgOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]],
814
- ["yarn", ["xy", "deplint", ...pkgOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]],
815
- ["yarn", ["xy", "lint", ...pkgOptions, ...verboseOptions, ...incrementalOptions]]
816
- ]);
817
- console.log(`${chalk11.gray("Built in")} [${chalk11.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk11.gray("seconds")}`);
818
- return result;
819
- };
820
-
821
- // src/actions/claude-clean.ts
822
- import {
823
- existsSync as existsSync5,
824
- readdirSync as readdirSync2,
825
- rmSync,
826
- unlinkSync
827
- } from "fs";
828
- import PATH5 from "path";
829
- import chalk12 from "chalk";
830
- function removeFile(filePath, label) {
831
- if (existsSync5(filePath)) {
832
- unlinkSync(filePath);
833
- console.log(chalk12.yellow(` Removed ${label}`));
834
- return true;
835
- }
836
- return false;
837
- }
838
- function removeDir(dirPath, label) {
839
- if (existsSync5(dirPath)) {
840
- rmSync(dirPath, { recursive: true });
841
- console.log(chalk12.yellow(` Removed ${label}`));
842
- return true;
843
- }
844
- return false;
845
- }
846
- function claudeClean() {
847
- console.log(chalk12.green("Clean Claude configuration"));
848
- const cwd5 = INIT_CWD() ?? process.cwd();
849
- let removed = 0;
850
- const rootFiles = ["CLAUDE.md", "CLAUDE.local.md"];
851
- for (const file of rootFiles) {
852
- if (removeFile(PATH5.resolve(cwd5, file), file)) removed++;
853
- }
854
- if (removeDir(PATH5.resolve(cwd5, ".claude"), ".claude/")) removed++;
855
- const packagesDir = PATH5.resolve(cwd5, "packages");
856
- if (existsSync5(packagesDir)) {
857
- const findClaudeFiles = (dir, prefix) => {
858
- const entries = readdirSync2(dir, { withFileTypes: true });
859
- for (const entry of entries) {
860
- const fullPath = PATH5.resolve(dir, entry.name);
861
- const label = `${prefix}${entry.name}`;
862
- if (entry.isFile() && (entry.name === "CLAUDE.md" || entry.name === "CLAUDE.local.md")) {
863
- if (removeFile(fullPath, label)) removed++;
864
- } else if (entry.isDirectory() && entry.name === ".claude") {
865
- if (removeDir(fullPath, `${label}/`)) removed++;
866
- } else if (entry.isDirectory() && entry.name !== "node_modules" && entry.name !== "dist") {
867
- findClaudeFiles(fullPath, `${label}/`);
868
- }
869
- }
870
- };
871
- findClaudeFiles(packagesDir, "packages/");
872
- }
873
- if (removed > 0) {
874
- console.log(chalk12.green(` Removed ${removed} item(s)`));
875
- } else {
876
- console.log(chalk12.gray(" Nothing to clean"));
877
- }
878
- return 0;
879
- }
880
-
881
- // src/actions/claude-commands.ts
882
- import {
883
- existsSync as existsSync6,
884
- mkdirSync,
885
- readdirSync as readdirSync3,
886
- readFileSync as readFileSync9,
887
- unlinkSync as unlinkSync2,
888
- writeFileSync as writeFileSync2
889
- } from "fs";
890
- import PATH6 from "path";
891
- import chalk13 from "chalk";
892
- var syncCommandFiles = (commandsDir) => {
893
- const templates = claudeCommandTemplates();
894
- const templateNames = new Set(Object.keys(templates));
895
- let updated = 0;
896
- let created = 0;
897
- for (const [filename2, content] of Object.entries(templates)) {
898
- const targetPath = PATH6.resolve(commandsDir, filename2);
899
- const existing = existsSync6(targetPath) ? readFileSync9(targetPath, "utf8") : void 0;
900
- if (existing === content) continue;
901
- writeFileSync2(targetPath, content, "utf8");
902
- if (existing) {
903
- updated++;
904
- } else {
905
- created++;
906
- }
907
- }
908
- return {
909
- created,
910
- templateNames,
911
- updated
912
- };
913
- };
914
- var removeStaleCommands = (commandsDir, templateNames) => {
915
- const existingCommands = readdirSync3(commandsDir).filter((f) => f.startsWith(XYLABS_COMMANDS_PREFIX) && f.endsWith(".md"));
916
- let removed = 0;
917
- for (const file of existingCommands) {
918
- if (!templateNames.has(file)) {
919
- unlinkSync2(PATH6.resolve(commandsDir, file));
920
- removed++;
921
- }
922
- }
923
- return removed;
924
- };
925
- var removeLegacyCommands = (commandsDir) => {
926
- const legacyFiles = readdirSync3(commandsDir).filter((f) => f.startsWith(LEGACY_COMMANDS_PREFIX) && f.endsWith(".md"));
927
- for (const file of legacyFiles) {
928
- unlinkSync2(PATH6.resolve(commandsDir, file));
929
- }
930
- return legacyFiles.length;
931
- };
932
- var logCommandsResult = (created, updated, removed) => {
933
- if (created || updated || removed) {
934
- const parts = [
935
- created ? `${created} created` : "",
936
- updated ? `${updated} updated` : "",
937
- removed ? `${removed} removed` : ""
938
- ].filter(Boolean);
939
- console.log(chalk13.green(`.claude/commands/${XYLABS_COMMANDS_PREFIX}*.md: ${parts.join(", ")}`));
940
- } else {
941
- console.log(chalk13.gray(`.claude/commands/${XYLABS_COMMANDS_PREFIX}*.md: already up to date`));
942
- }
943
- };
944
- var claudeCommands = () => {
945
- const cwd5 = INIT_CWD() ?? process.cwd();
946
- const commandsDir = PATH6.resolve(cwd5, ".claude", "commands");
947
- mkdirSync(commandsDir, { recursive: true });
948
- const legacy = removeLegacyCommands(commandsDir);
949
- const {
950
- created,
951
- templateNames,
952
- updated
953
- } = syncCommandFiles(commandsDir);
954
- const removed = removeStaleCommands(commandsDir, templateNames);
955
- logCommandsResult(created, updated, removed + legacy);
956
- return 0;
957
- };
958
-
959
- // src/actions/claude-rules.ts
960
- import { spawnSync as spawnSync5 } from "child_process";
961
- import {
962
- existsSync as existsSync7,
963
- mkdirSync as mkdirSync2,
964
- readdirSync as readdirSync4,
965
- readFileSync as readFileSync10,
966
- unlinkSync as unlinkSync3,
967
- writeFileSync as writeFileSync3
968
- } from "fs";
969
- import PATH7 from "path";
970
- import chalk14 from "chalk";
971
- var syncRuleFiles = (rulesDir) => {
972
- const templates = claudeMdRuleTemplates();
973
- const templateNames = new Set(Object.keys(templates));
974
- let updated = 0;
975
- let created = 0;
976
- for (const [filename2, content] of Object.entries(templates)) {
977
- const targetPath = PATH7.resolve(rulesDir, filename2);
978
- const existing = existsSync7(targetPath) ? readFileSync10(targetPath, "utf8") : void 0;
979
- if (existing === content) continue;
980
- writeFileSync3(targetPath, content, "utf8");
981
- if (existing) {
982
- updated++;
983
- } else {
984
- created++;
985
- }
986
- }
987
- return {
988
- created,
989
- templateNames,
990
- updated
991
- };
992
- };
993
- var removeStaleRules = (rulesDir, templateNames) => {
994
- const existingRules = readdirSync4(rulesDir).filter((f) => f.startsWith(XYLABS_RULES_PREFIX) && f.endsWith(".md"));
995
- let removed = 0;
996
- for (const file of existingRules) {
997
- if (!templateNames.has(file)) {
998
- unlinkSync3(PATH7.resolve(rulesDir, file));
999
- removed++;
1000
- }
1001
- }
1002
- return removed;
1003
- };
1004
- var logRulesResult = (created, updated, removed) => {
1005
- if (created || updated || removed) {
1006
- const parts = [
1007
- created ? `${created} created` : "",
1008
- updated ? `${updated} updated` : "",
1009
- removed ? `${removed} removed` : ""
1010
- ].filter(Boolean);
1011
- console.log(chalk14.green(`.claude/rules/${XYLABS_RULES_PREFIX}*.md: ${parts.join(", ")}`));
1012
- } else {
1013
- console.log(chalk14.gray(`.claude/rules/${XYLABS_RULES_PREFIX}*.md: already up to date`));
1014
- }
1015
- };
1016
- var ensureProjectClaudeMd = (cwd5, force) => {
1017
- const projectPath = PATH7.resolve(cwd5, "CLAUDE.md");
1018
- if (!existsSync7(projectPath) || force) {
1019
- if (force && existsSync7(projectPath)) {
1020
- console.log(chalk14.yellow("Regenerating CLAUDE.md"));
1021
- }
1022
- console.log(chalk14.green("Generating CLAUDE.md via claude /init..."));
1023
- const result = spawnSync5("claude", ["-p", "/init", "--allowedTools", "Read", "Write", "Glob", "Grep"], {
1024
- cwd: cwd5,
1025
- shell: true,
1026
- stdio: "inherit"
1027
- });
1028
- if (result.status !== 0) {
1029
- console.error(chalk14.red("claude /init failed \u2014 is Claude Code installed?"));
1030
- return 1;
1031
- }
1032
- } else {
1033
- console.log(chalk14.gray("CLAUDE.md already exists (skipped, use --force to regenerate)"));
1034
- }
1035
- return 0;
1036
- };
1037
- var ensureLocalClaudeMd = (cwd5) => {
1038
- const localPath = PATH7.resolve(cwd5, "CLAUDE.local.md");
1039
- if (existsSync7(localPath)) {
1040
- console.log(chalk14.gray("CLAUDE.local.md already exists (skipped)"));
1041
- } else {
1042
- writeFileSync3(localPath, claudeMdLocalTemplate(), "utf8");
1043
- console.log(chalk14.green("Generated CLAUDE.local.md"));
1044
- }
1045
- };
1046
- var claudeRules = ({ force } = {}) => {
1047
- const cwd5 = INIT_CWD() ?? process.cwd();
1048
- const rulesDir = PATH7.resolve(cwd5, ".claude", "rules");
1049
- mkdirSync2(rulesDir, { recursive: true });
1050
- const {
1051
- created,
1052
- templateNames,
1053
- updated
1054
- } = syncRuleFiles(rulesDir);
1055
- const removed = removeStaleRules(rulesDir, templateNames);
1056
- logRulesResult(created, updated, removed);
1057
- const claudeMdResult = ensureProjectClaudeMd(cwd5, force);
1058
- ensureLocalClaudeMd(cwd5);
1059
- return claudeMdResult ?? 0;
1060
- };
1061
-
1062
- // src/actions/claude-settings.ts
1063
- import {
1064
- existsSync as existsSync8,
1065
- mkdirSync as mkdirSync3,
1066
- writeFileSync as writeFileSync4
1067
- } from "fs";
1068
- import PATH8 from "path";
1069
- import { createInterface as createInterface2 } from "readline";
1070
- import chalk15 from "chalk";
1071
- var DEFAULT_SETTINGS = {
1072
- permissions: {
1073
- allow: [
1074
- "Bash(git *)",
1075
- "Bash(yarn *)",
1076
- "Bash(npx *)",
1077
- "Bash(node *)",
1078
- "Bash(ls *)",
1079
- "Bash(mkdir *)",
1080
- "Bash(cp *)",
1081
- "Bash(mv *)",
1082
- "Bash(rm *)",
1083
- "Bash(cat *)",
1084
- "Bash(head *)",
1085
- "Bash(tail *)",
1086
- "Bash(echo *)",
1087
- "Bash(pwd)",
1088
- "Bash(which *)",
1089
- "Bash(grep *)",
1090
- "Bash(find *)",
1091
- "Bash(npm view *)",
1092
- "Bash(gh *)",
1093
- "Read",
1094
- "Edit",
1095
- "Write",
1096
- "Glob",
1097
- "Grep",
1098
- "Skill"
1099
- ],
1100
- deny: [
1101
- "Bash(git push --force *)",
1102
- "Bash(git reset --hard *)",
1103
- "Bash(rm -rf /*)"
1104
- ]
1105
- }
1106
- };
1107
- function askConfirmation2(question) {
1108
- const rl = createInterface2({ input: process.stdin, output: process.stdout });
1109
- return new Promise((resolve) => {
1110
- rl.question(question, (answer) => {
1111
- rl.close();
1112
- resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
1113
- });
1114
- });
1115
- }
1116
- async function claudeSettings() {
1117
- const cwd5 = INIT_CWD() ?? process.cwd();
1118
- const claudeDir = PATH8.resolve(cwd5, ".claude");
1119
- const settingsPath = PATH8.resolve(claudeDir, "settings.local.json");
1120
- mkdirSync3(claudeDir, { recursive: true });
1121
- if (existsSync8(settingsPath)) {
1122
- const confirmed = await askConfirmation2(
1123
- chalk15.yellow(`${settingsPath} already exists. Replace it? (y/N) `)
1124
- );
1125
- if (!confirmed) {
1126
- console.log(chalk15.gray("Skipped \u2014 existing settings.local.json preserved"));
1127
- return 0;
1128
- }
1129
- }
1130
- writeFileSync4(settingsPath, `${JSON.stringify(DEFAULT_SETTINGS, null, 2)}
1131
- `, "utf8");
1132
- console.log(chalk15.green("Generated .claude/settings.local.json"));
1133
- return 0;
1134
- }
1135
-
1136
- // src/actions/claude-skills.ts
1137
- import {
1138
- existsSync as existsSync9,
1139
- mkdirSync as mkdirSync4,
1140
- readdirSync as readdirSync5,
1141
- readFileSync as readFileSync11,
1142
- rmSync as rmSync2,
1143
- statSync as statSync2,
1144
- writeFileSync as writeFileSync5
1145
- } from "fs";
1146
- import PATH9 from "path";
1147
- import chalk16 from "chalk";
1148
- var syncSkillFiles = (skillsDir) => {
1149
- const templates = claudeSkillTemplates();
1150
- const templateNames = new Set(Object.keys(templates));
1151
- let updated = 0;
1152
- let created = 0;
1153
- for (const [skillName, files] of Object.entries(templates)) {
1154
- const skillDir = PATH9.resolve(skillsDir, skillName);
1155
- mkdirSync4(skillDir, { recursive: true });
1156
- for (const [filename2, content] of Object.entries(files)) {
1157
- const targetPath = PATH9.resolve(skillDir, filename2);
1158
- mkdirSync4(PATH9.dirname(targetPath), { recursive: true });
1159
- const existing = existsSync9(targetPath) ? readFileSync11(targetPath, "utf8") : void 0;
1160
- if (existing === content) continue;
1161
- writeFileSync5(targetPath, content, "utf8");
1162
- if (existing) {
1163
- updated++;
1164
- } else {
1165
- created++;
1166
- }
1167
- }
1168
- }
1169
- return {
1170
- created,
1171
- templateNames,
1172
- updated
1173
- };
1174
- };
1175
- var removeStaleSkills = (skillsDir, templateNames) => {
1176
- const existingSkills = readdirSync5(skillsDir).filter(
1177
- (f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync2(PATH9.resolve(skillsDir, f)).isDirectory()
1178
- );
1179
- let removed = 0;
1180
- for (const dir of existingSkills) {
1181
- if (!templateNames.has(dir)) {
1182
- rmSync2(PATH9.resolve(skillsDir, dir), { recursive: true });
1183
- removed++;
1184
- }
1185
- }
1186
- return removed;
1187
- };
1188
- var logSkillsResult = (created, updated, removed) => {
1189
- if (created || updated || removed) {
1190
- const parts = [
1191
- created ? `${created} created` : "",
1192
- updated ? `${updated} updated` : "",
1193
- removed ? `${removed} removed` : ""
1194
- ].filter(Boolean);
1195
- console.log(chalk16.green(`.claude/skills/${XYLABS_SKILLS_PREFIX}*/: ${parts.join(", ")}`));
1196
- } else {
1197
- console.log(chalk16.gray(`.claude/skills/${XYLABS_SKILLS_PREFIX}*/: already up to date`));
1198
- }
1199
- };
1200
- var claudeSkills = () => {
1201
- const cwd5 = INIT_CWD() ?? process.cwd();
1202
- const skillsDir = PATH9.resolve(cwd5, ".claude", "skills");
1203
- mkdirSync4(skillsDir, { recursive: true });
1204
- const {
1205
- created,
1206
- templateNames,
1207
- updated
1208
- } = syncSkillFiles(skillsDir);
1209
- const removed = removeStaleSkills(skillsDir, templateNames);
1210
- logSkillsResult(created, updated, removed);
1211
- return 0;
1212
- };
1213
-
1214
- // src/actions/clean.ts
1215
- var clean = async ({ verbose, pkg }) => {
1216
- return pkg ? await cleanPackage({ pkg, verbose }) : cleanAll({ verbose });
1217
- };
1218
- var cleanPackage = ({ pkg }) => {
1219
- return runStepsAsync(`Clean [${pkg}]`, [["yarn", ["workspace", pkg, "run", "package-clean"]]]);
1220
- };
1221
- var cleanAll = ({ verbose }) => {
1222
- const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
1223
- return runStepsAsync("Clean", [["yarn", ["workspaces foreach", "-pA", "--jobs 64", ...verboseOptions, "run", "package-clean"]]]);
1224
- };
1225
-
1226
- // src/actions/clean-docs.ts
1227
- import path from "path";
1228
- import chalk17 from "chalk";
1229
- var cleanDocs = () => {
1230
- const pkgName = process.env.npm_package_name;
1231
- console.log(chalk17.green(`Cleaning Docs [${pkgName}]`));
1232
- for (const { location } of yarnWorkspaces()) deleteGlob(path.join(location, "docs"));
1233
- return 0;
1234
- };
1235
-
1236
- // src/actions/compile.ts
1237
- import chalk18 from "chalk";
1238
- var compile = ({
1239
- verbose,
1240
- target,
1241
- pkg,
1242
- incremental,
1243
- publint: publint2,
1244
- jobs
1245
- }) => {
1246
- return pkg ? compilePackage({
1247
- pkg,
1248
- publint: publint2,
1249
- target,
1250
- verbose
1251
- }) : compileAll({
1252
- incremental,
1253
- publint: publint2,
1254
- target,
1255
- verbose,
1256
- jobs
1257
- });
1258
- };
1259
- var compilePackage = ({ target, pkg }) => {
1260
- const targetOptions = target ? ["-t", target] : [];
1261
- return runSteps(
1262
- `Compile [${pkg}]`,
1263
- [["yarn", ["workspace", pkg, "run", "package-compile", ...targetOptions]]]
1264
- );
1265
- };
1266
- var compileAll = ({
1267
- jobs,
1268
- verbose,
1269
- target,
1270
- incremental
1271
- }) => {
1272
- const start = Date.now();
1273
- const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
1274
- const targetOptions = target ? ["-t", target] : [];
1275
- const incrementalOptions = incremental ? ["--since", "-Ap", "--topological-dev"] : ["--parallel", "-Ap", "--topological-dev"];
1276
- const jobsOptions = jobs ? ["-j", `${jobs}`] : [];
1277
- if (jobs) {
1278
- console.log(chalk18.blue(`Jobs set to [${jobs}]`));
1279
- }
1280
- const result = runSteps(`Compile${incremental ? "-Incremental" : ""} [All]`, [
1281
- ["yarn", [
53
+ foreachWorkspace(script, args = [], options) {
54
+ const jobsOptions = options?.jobs ? ["-j", `${options.jobs}`] : [];
55
+ const verboseOptions = options?.verbose ? ["--verbose"] : ["--no-verbose"];
56
+ const incrementalOptions = options?.incremental ? ["--since", "-Ap", "--topological-dev"] : ["--parallel", "-Ap", "--topological-dev"];
57
+ return ["yarn", [
1282
58
  "workspaces",
1283
59
  "foreach",
1284
60
  ...incrementalOptions,
1285
61
  ...jobsOptions,
1286
62
  ...verboseOptions,
1287
63
  "run",
1288
- "package-compile",
1289
- ...targetOptions
1290
- ]]
1291
- ]);
1292
- console.log(`${chalk18.gray("Compiled in")} [${chalk18.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk18.gray("seconds")}`);
1293
- return result;
1294
- };
1295
-
1296
- // src/actions/copy-assets.ts
1297
- import path2 from "path/posix";
1298
- import chalk19 from "chalk";
1299
- import cpy from "cpy";
1300
- var copyPackageTargetAssets = async (target, name, location) => {
1301
- try {
1302
- const values = await cpy(
1303
- ["**/*.jpg", "**/*.png", "**/*.gif", "**/*.svg", "**/*.webp", "**/*.sass", "**/*.scss", "**/*.gif", "**/*.css"],
1304
- `../dist/${target}`,
1305
- {
1306
- cwd: path2.join(process.cwd(), location, "src"),
1307
- flat: false
1308
- }
1309
- );
1310
- for (const value of values) {
1311
- console.log(`${value.split("/").pop()} => ./dist/${target}`);
1312
- }
1313
- return 0;
1314
- } catch (reason) {
1315
- console.log(`Copy Failed: ${name}: ${reason}`);
1316
- return 1;
64
+ script,
65
+ ...args
66
+ ]];
1317
67
  }
1318
- };
1319
- var copyTargetAssets = async (target, pkg) => {
1320
- const workspaces = yarnWorkspaces();
1321
- console.log(chalk19.green(`Copying Assets [${target.toUpperCase()}]`));
1322
- const workspaceList = workspaces.filter(({ name }) => {
1323
- return pkg === void 0 || name === pkg;
1324
- });
1325
- if (workspaceList.length === 0) {
1326
- console.error(`Package not found [${pkg}]`);
1327
- } else {
1328
- const results = await Promise.all(
1329
- workspaceList.map(async (workspace) => {
1330
- const { location, name } = workspace;
1331
- return await copyPackageTargetAssets(target, name, location);
1332
- })
1333
- );
1334
- return results.reduce((prev, result) => prev || result, 0);
68
+ install() {
69
+ return ["yarn", ["install"]];
1335
70
  }
1336
- return 0;
1337
- };
1338
- var copyAssets = async ({ target, pkg }) => {
1339
- switch (target) {
1340
- case "esm": {
1341
- return await copyTargetAssets("esm", pkg);
1342
- }
1343
- case "cjs": {
1344
- return await copyTargetAssets("cjs", pkg);
1345
- }
1346
- default: {
1347
- return await copyTargetAssets("esm", pkg) || await copyTargetAssets("cjs", pkg);
1348
- }
71
+ listWorkspaces() {
72
+ return yarnWorkspaces();
1349
73
  }
1350
- };
1351
-
1352
- // src/actions/cycle.ts
1353
- import { cruise } from "dependency-cruiser";
1354
- var cycle = async ({ verbose, pkg } = {}) => {
1355
- return pkg ? cyclePackage({ pkg, verbose }) : await cycleAll({ verbose });
1356
- };
1357
- var cyclePackage = ({ pkg, verbose }) => {
1358
- const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
1359
- return runSteps(
1360
- `Cycle [${pkg}]`,
1361
- [["yarn", ["workspace", pkg, "run", "package-cycle", ...verboseOptions]]]
1362
- );
1363
- };
1364
- var cycleAll = async ({ verbose = false }) => {
1365
- const pkgName = process.env.npm_package_name;
1366
- const cruiseOptions = {
1367
- ruleSet: {
1368
- forbidden: [
1369
- {
1370
- name: "no-circular",
1371
- severity: "error",
1372
- comment: "This dependency creates a circular reference",
1373
- from: {},
1374
- to: { circular: true }
1375
- }
1376
- ]
1377
- },
1378
- exclude: "node_modules|packages/.*/packages",
1379
- validate: true,
1380
- doNotFollow: { path: "node_modules|packages/.*/packages" },
1381
- tsPreCompilationDeps: false,
1382
- combinedDependencies: true,
1383
- outputType: verbose ? "text" : "err"
1384
- };
1385
- const target = "**/packages/*/src";
1386
- console.log(`Checking for circular dependencies in ${target}...`);
1387
- const result = await cruise([target], cruiseOptions);
1388
- if (result.output) {
1389
- console.log(result.output);
74
+ outdated() {
75
+ return ["yarn", ["outdated"]];
1390
76
  }
1391
- if (result.exitCode === 0) {
1392
- console.log(`${pkgName} \u2705 No dependency violations`);
1393
- } else {
1394
- console.error(`${pkgName} \u274C Dependency violations found`);
77
+ runInWorkspace(pkg, script, args = []) {
78
+ return ["yarn", ["workspace", pkg, "run", script, ...args]];
1395
79
  }
1396
- return result.exitCode;
1397
- };
1398
-
1399
- // src/actions/dead.ts
1400
- var dead = () => {
1401
- return runSteps("Dead", [["yarn", ["ts-prune", "-p", "tsconfig.json"]]]);
1402
- };
1403
-
1404
- // src/actions/deplint/deplint.ts
1405
- import chalk25 from "chalk";
1406
-
1407
- // src/actions/deplint/findFiles.ts
1408
- import fs2 from "fs";
1409
-
1410
- // src/actions/deplint/findFilesByGlob.ts
1411
- import { globSync } from "glob";
1412
- function findFilesByGlob(cwd5, pattern, ignore) {
1413
- return globSync(pattern, {
1414
- cwd: cwd5,
1415
- absolute: true,
1416
- ignore,
1417
- nodir: true
1418
- });
1419
- }
1420
-
1421
- // src/actions/deplint/findFiles.ts
1422
- var codeExtensions = "*.{ts,tsx,mts,cts,js,mjs,cjs}";
1423
- function getWorkspaceIgnores(location) {
1424
- try {
1425
- const raw = fs2.readFileSync(`${location}/package.json`, "utf8");
1426
- const pkg = JSON.parse(raw);
1427
- return pkg.workspaces ?? [];
1428
- } catch {
1429
- return [];
80
+ runXy(args) {
81
+ return ["yarn", ["xy", ...args]];
1430
82
  }
1431
- }
1432
- function findFiles(location) {
1433
- const workspaceIgnores = getWorkspaceIgnores(location).map((w) => `${w}/**`);
1434
- const ignore = ["**/node_modules/**", "dist/**", ...workspaceIgnores];
1435
- const allFiles = findFilesByGlob(location, `./**/${codeExtensions}`, ignore);
1436
- const distFiles = [
1437
- ...findFilesByGlob(location, "./dist/**/*.d.ts"),
1438
- ...findFilesByGlob(location, `./dist/**/${codeExtensions}`)
1439
- ];
1440
- return { allFiles, distFiles };
1441
- }
1442
-
1443
- // src/actions/deplint/getDependenciesFromPackageJson.ts
1444
- import fs3 from "fs";
1445
- import path3 from "path";
1446
- function getDependenciesFromPackageJson(packageJsonPath) {
1447
- const packageJsonFullPath = path3.resolve(packageJsonPath);
1448
- const rawContent = fs3.readFileSync(packageJsonFullPath, "utf8");
1449
- const packageJson = JSON.parse(rawContent);
1450
- const dependencies = packageJson.dependencies ? Object.keys(packageJson.dependencies) : [];
1451
- const devDependencies = packageJson.devDependencies ? Object.keys(packageJson.devDependencies) : [];
1452
- const peerDependencies = packageJson.peerDependencies ? Object.keys(packageJson.peerDependencies) : [];
1453
- return {
1454
- dependencies,
1455
- devDependencies,
1456
- peerDependencies
1457
- };
1458
- }
1459
-
1460
- // src/actions/deplint/getExtendsFromTsconfigs.ts
1461
- import fs4 from "fs";
1462
- import { globSync as globSync2 } from "glob";
1463
-
1464
- // src/actions/deplint/getBasePackageName.ts
1465
- function getBasePackageName(importName) {
1466
- const importNameScrubbed = importName.replaceAll('"', "").trim();
1467
- if (importNameScrubbed.startsWith("@")) {
1468
- const parts = importNameScrubbed.split("/");
1469
- return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : importNameScrubbed;
83
+ versionApply() {
84
+ return ["yarn", ["version", "apply", "--all"]];
1470
85
  }
1471
- return importNameScrubbed.split("/")[0];
1472
- }
1473
-
1474
- // src/actions/deplint/getExtendsFromTsconfigs.ts
1475
- var isExternalReference = (ref) => !ref.startsWith(".") && !ref.startsWith("/");
1476
- function parseExtendsField(value) {
1477
- if (typeof value === "string") return [value];
1478
- if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
1479
- return [];
1480
- }
1481
- function getExtendsFromTsconfigs(location) {
1482
- const tsconfigFiles = globSync2("./tsconfig*.json", { cwd: location, absolute: true });
1483
- const packages = /* @__PURE__ */ new Set();
1484
- for (const file of tsconfigFiles) {
1485
- try {
1486
- const content = fs4.readFileSync(file, "utf8");
1487
- const cleaned = content.replaceAll(/\/\/.*/g, "").replaceAll(/,\s*([}\]])/g, "$1");
1488
- const parsed = JSON.parse(cleaned);
1489
- const refs = parseExtendsField(parsed.extends);
1490
- for (const ref of refs) {
1491
- if (isExternalReference(ref)) {
1492
- packages.add(getBasePackageName(ref));
1493
- }
1494
- }
1495
- } catch {
1496
- }
1497
- }
1498
- return [...packages];
1499
- }
1500
-
1501
- // src/actions/deplint/getImportsFromFile.ts
1502
- import fs5 from "fs";
1503
- import path4 from "path";
1504
- import ts from "typescript";
1505
- function isTypeOnlyImportClause(clause) {
1506
- if (clause === void 0) {
1507
- return false;
1508
- }
1509
- if ("phaseModifier" in clause) {
1510
- const mod = clause.phaseModifier;
1511
- const kind = typeof mod === "number" ? mod : mod?.kind;
1512
- return kind === ts.SyntaxKind.TypeKeyword;
1513
- }
1514
- return clause.isTypeOnly;
1515
- }
1516
- function getImportsFromFile(filePath, importPaths, typeImportPaths) {
1517
- const sourceCode = fs5.readFileSync(filePath, "utf8");
1518
- const isMjsFile = filePath.endsWith(".mjs");
1519
- const sourceFile = ts.createSourceFile(
1520
- path4.basename(filePath),
1521
- sourceCode,
1522
- ts.ScriptTarget.Latest,
1523
- true,
1524
- isMjsFile ? ts.ScriptKind.JS : void 0
1525
- );
1526
- const imports = [];
1527
- const typeImports = [];
1528
- const isDeclarationFile2 = filePath.endsWith(".d.ts");
1529
- function visit(node) {
1530
- if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
1531
- const moduleSpecifier = node.moduleSpecifier?.getFullText();
1532
- const isTypeImport = ts.isImportDeclaration(node) ? isTypeOnlyImportClause(node.importClause) : false;
1533
- if (typeof moduleSpecifier === "string") {
1534
- const trimmed = moduleSpecifier.replaceAll("'", "").replaceAll('"', "").trim();
1535
- if (isTypeImport || isDeclarationFile2) {
1536
- typeImports.push(trimmed);
1537
- } else {
1538
- imports.push(trimmed);
1539
- }
1540
- }
1541
- } else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
1542
- const [arg] = node.arguments;
1543
- if (ts.isStringLiteral(arg)) {
1544
- imports.push(arg.text);
1545
- }
1546
- } else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "require" && node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0])) {
1547
- imports.push(node.arguments[0].text);
1548
- }
1549
- ts.forEachChild(node, visit);
1550
- }
1551
- visit(sourceFile);
1552
- for (const ref of sourceFile.typeReferenceDirectives) {
1553
- typeImports.push(ref.fileName);
1554
- }
1555
- const importsStartsWithExcludes = [".", "#", "node:"];
1556
- const isValidImport = (imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc)) && !imp.includes("*") && !imp.includes("!");
1557
- const cleanedImports = imports.filter(isValidImport).map(getBasePackageName);
1558
- const cleanedTypeImports = typeImports.filter(isValidImport).map(getBasePackageName);
1559
- for (const imp of cleanedImports) {
1560
- importPaths[imp] = importPaths[imp] ?? [];
1561
- importPaths[imp].push(filePath);
1562
- }
1563
- for (const imp of cleanedTypeImports) {
1564
- typeImportPaths[imp] = typeImportPaths[imp] ?? [];
1565
- typeImportPaths[imp].push(filePath);
1566
- }
1567
- return [cleanedImports, cleanedTypeImports];
1568
- }
1569
-
1570
- // src/actions/deplint/getExternalImportsFromFiles.ts
1571
- var internalImportPrefixes = [".", "#", "node:"];
1572
- var removeInternalImports = (imports) => {
1573
- return imports.filter((imp) => !internalImportPrefixes.some((prefix) => imp.startsWith(prefix)));
1574
- };
1575
- var isDeclarationFile = (file) => file.endsWith(".d.ts") || file.endsWith(".d.cts") || file.endsWith(".d.mts");
1576
- function getExternalImportsFromFiles({
1577
- allFiles,
1578
- distFiles,
1579
- tsconfigExtends = []
1580
- }) {
1581
- const allImportPaths = {};
1582
- const distImportPaths = {};
1583
- const distTypeImportPaths = {};
1584
- for (const path14 of allFiles) getImportsFromFile(path14, allImportPaths, allImportPaths).flat();
1585
- const distTypeFiles = distFiles.filter(isDeclarationFile);
1586
- const distCodeFiles = distFiles.filter((file) => !isDeclarationFile(file));
1587
- for (const path14 of distCodeFiles) getImportsFromFile(path14, distImportPaths, distImportPaths).flat();
1588
- for (const path14 of distTypeFiles) getImportsFromFile(path14, distTypeImportPaths, distTypeImportPaths).flat();
1589
- const allImports = Object.keys(allImportPaths);
1590
- const distImports = Object.keys(distImportPaths);
1591
- const externalAllImports = removeInternalImports(allImports);
1592
- const externalDistImports = removeInternalImports(distImports);
1593
- const externalDistTypeImports = removeInternalImports(Object.keys(distTypeImportPaths));
1594
- for (const ext of tsconfigExtends) {
1595
- if (!externalAllImports.includes(ext)) externalAllImports.push(ext);
1596
- }
1597
- return {
1598
- allImportPaths,
1599
- allImports,
1600
- distImportPaths,
1601
- distImports,
1602
- externalAllImports,
1603
- externalDistImports,
1604
- externalDistTypeImports
1605
- };
1606
- }
1607
-
1608
- // src/actions/deplint/checkPackage/getUnlistedDependencies.ts
1609
- import { builtinModules } from "module";
1610
- import chalk20 from "chalk";
1611
- function isRuntimeImportListed(imp, name, dependencies, peerDependencies) {
1612
- return dependencies.includes(imp) || imp === name || peerDependencies.includes(imp) || builtinModules.includes(imp);
1613
- }
1614
- function isTypeImportListed(imp, name, dependencies, devDependencies, peerDependencies) {
1615
- return dependencies.includes(imp) || imp === name || dependencies.includes(`@types/${imp}`) || peerDependencies.includes(imp) || peerDependencies.includes(`@types/${imp}`) || devDependencies.includes(`@types/${imp}`) || builtinModules.includes(imp);
1616
- }
1617
- function logMissing(name, imp, importPaths) {
1618
- console.log(`[${chalk20.blue(name)}] Missing dependency in package.json: ${chalk20.red(imp)}`);
1619
- if (importPaths[imp]) {
1620
- console.log(` ${importPaths[imp].join("\n ")}`);
1621
- }
1622
- }
1623
- function getUnlistedDependencies({ name, location }, {
1624
- dependencies,
1625
- devDependencies,
1626
- peerDependencies
1627
- }, {
1628
- externalDistImports,
1629
- externalDistTypeImports,
1630
- distImportPaths
1631
- }) {
1632
- let unlistedDependencies = 0;
1633
- for (const imp of externalDistImports) {
1634
- if (!isRuntimeImportListed(imp, name, dependencies, peerDependencies)) {
1635
- unlistedDependencies++;
1636
- logMissing(name, imp, distImportPaths);
1637
- }
1638
- }
1639
- for (const imp of externalDistTypeImports) {
1640
- if (!isTypeImportListed(imp, name, dependencies, devDependencies, peerDependencies)) {
1641
- unlistedDependencies++;
1642
- logMissing(name, imp, distImportPaths);
1643
- }
1644
- }
1645
- if (unlistedDependencies > 0) {
1646
- const packageLocation = `${location}/package.json`;
1647
- console.log(` ${chalk20.yellow(packageLocation)}
1648
- `);
1649
- }
1650
- return unlistedDependencies;
1651
- }
1652
-
1653
- // src/actions/deplint/checkPackage/getUnlistedDevDependencies.ts
1654
- import { builtinModules as builtinModules2 } from "module";
1655
- import chalk21 from "chalk";
1656
- function getUnlistedDevDependencies({ name, location }, {
1657
- devDependencies,
1658
- dependencies,
1659
- peerDependencies
1660
- }, {
1661
- allImportPaths,
1662
- externalAllImports,
1663
- distImports
1664
- }) {
1665
- let unlistedDevDependencies = 0;
1666
- for (const imp of externalAllImports) {
1667
- if (!distImports.includes(imp) && imp !== name && !dependencies.includes(imp) && !dependencies.includes(`@types/${imp}`) && !peerDependencies.includes(imp) && !peerDependencies.includes(`@types/${imp}`) && !devDependencies.includes(imp) && !devDependencies.includes(`@types/${imp}`) && !builtinModules2.includes(imp)) {
1668
- unlistedDevDependencies++;
1669
- console.log(`[${chalk21.blue(name)}] Missing devDependency in package.json: ${chalk21.red(imp)}`);
1670
- if (allImportPaths[imp]) {
1671
- console.log(` ${allImportPaths[imp].join("\n ")}`);
1672
- }
1673
- }
1674
- }
1675
- if (unlistedDevDependencies > 0) {
1676
- const packageLocation = `${location}/package.json`;
1677
- console.log(` ${chalk21.yellow(packageLocation)}
1678
- `);
1679
- }
1680
- return unlistedDevDependencies;
1681
- }
1682
-
1683
- // src/actions/deplint/checkPackage/getUnusedDependencies.ts
1684
- import chalk22 from "chalk";
1685
- function getUnusedDependencies({ name, location }, { dependencies }, {
1686
- externalDistImports,
1687
- externalDistTypeImports,
1688
- externalAllImports
1689
- }, exclude) {
1690
- let unusedDependencies = 0;
1691
- for (const dep of dependencies) {
1692
- if (exclude?.has(dep)) continue;
1693
- if (!externalDistImports.includes(dep) && !externalDistImports.includes(dep.replace(/^@types\//, "")) && !externalDistTypeImports.includes(dep) && !externalDistTypeImports.includes(dep.replace(/^@types\//, ""))) {
1694
- unusedDependencies++;
1695
- if (externalAllImports.includes(dep)) {
1696
- console.log(`[${chalk22.blue(name)}] dependency should be devDependency in package.json: ${chalk22.red(dep)}`);
1697
- } else {
1698
- console.log(`[${chalk22.blue(name)}] Unused dependency in package.json: ${chalk22.red(dep)}`);
1699
- }
1700
- }
1701
- }
1702
- if (unusedDependencies > 0) {
1703
- const packageLocation = `${location}/package.json`;
1704
- console.log(` ${chalk22.yellow(packageLocation)}
1705
- `);
1706
- }
1707
- return unusedDependencies;
1708
- }
1709
-
1710
- // src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
1711
- import chalk23 from "chalk";
1712
-
1713
- // src/actions/deplint/getCliReferencedPackagesFromFiles.ts
1714
- import fs8 from "fs";
1715
- import path7 from "path";
1716
- import ts2 from "typescript";
1717
-
1718
- // src/actions/deplint/getScriptReferencedPackages.ts
1719
- import fs7 from "fs";
1720
- import path6 from "path";
1721
-
1722
- // src/actions/deplint/getRequiredPeerDependencies.ts
1723
- import fs6 from "fs";
1724
- import path5 from "path";
1725
- function findDepPackageJson(location, dep) {
1726
- let dir = location;
1727
- while (true) {
1728
- const candidate = path5.join(dir, "node_modules", dep, "package.json");
1729
- if (fs6.existsSync(candidate)) return candidate;
1730
- const parent = path5.dirname(dir);
1731
- if (parent === dir) return void 0;
1732
- dir = parent;
1733
- }
1734
- }
1735
- function getRequiredPeerDependencies(location, allDeps) {
1736
- const required = /* @__PURE__ */ new Set();
1737
- for (const dep of allDeps) {
1738
- const depPkgPath = findDepPackageJson(location, dep);
1739
- if (!depPkgPath) continue;
1740
- try {
1741
- const raw = fs6.readFileSync(depPkgPath, "utf8");
1742
- const pkg = JSON.parse(raw);
1743
- if (pkg.peerDependencies) {
1744
- for (const peer of Object.keys(pkg.peerDependencies)) {
1745
- required.add(peer);
1746
- }
1747
- }
1748
- } catch {
1749
- }
1750
- }
1751
- return required;
1752
- }
1753
-
1754
- // src/actions/deplint/getScriptReferencedPackages.ts
1755
- function getBinNames(location, dep) {
1756
- const depPkgPath = findDepPackageJson(location, dep);
1757
- if (!depPkgPath) return [];
1758
- try {
1759
- const raw = fs7.readFileSync(depPkgPath, "utf8");
1760
- const pkg = JSON.parse(raw);
1761
- if (!pkg.bin) return [];
1762
- if (typeof pkg.bin === "string") return [pkg.name?.split("/").pop() ?? dep];
1763
- return Object.keys(pkg.bin);
1764
- } catch {
1765
- return [];
1766
- }
1767
- }
1768
- function tokenizeScript(script) {
1769
- return script.split(/[&|;$()"`\s]+/).map((t) => t.trim()).filter(Boolean);
1770
- }
1771
- function getScriptReferencedPackages(location, allDeps) {
1772
- const pkgPath = path6.join(location, "package.json");
1773
- let scripts = {};
1774
- try {
1775
- const raw = fs7.readFileSync(pkgPath, "utf8");
1776
- const pkg = JSON.parse(raw);
1777
- scripts = pkg.scripts ?? {};
1778
- } catch {
1779
- return /* @__PURE__ */ new Set();
1780
- }
1781
- const scriptText = Object.values(scripts).join(" ");
1782
- const tokens = new Set(tokenizeScript(scriptText));
1783
- const binToPackage = /* @__PURE__ */ new Map();
1784
- for (const dep of allDeps) {
1785
- const bins = getBinNames(location, dep);
1786
- for (const bin of bins) {
1787
- binToPackage.set(bin, dep);
1788
- }
1789
- }
1790
- const referenced = /* @__PURE__ */ new Set();
1791
- for (const token of tokens) {
1792
- const baseName = getBasePackageName(token);
1793
- if (allDeps.includes(baseName)) {
1794
- referenced.add(baseName);
1795
- }
1796
- const pkg = binToPackage.get(token);
1797
- if (pkg) {
1798
- referenced.add(pkg);
1799
- }
1800
- }
1801
- return referenced;
1802
- }
1803
-
1804
- // src/actions/deplint/getCliReferencedPackagesFromFiles.ts
1805
- var shellCommandFunctions = /* @__PURE__ */ new Set(["execSync", "exec"]);
1806
- var directExecFunctions = /* @__PURE__ */ new Set(["spawn", "spawnSync", "execFile", "execFileSync"]);
1807
- var allExecFunctions = /* @__PURE__ */ new Set([...shellCommandFunctions, ...directExecFunctions]);
1808
- function getCommandTokensFromFile(filePath) {
1809
- const tokens = /* @__PURE__ */ new Set();
1810
- let sourceCode;
1811
- try {
1812
- sourceCode = fs8.readFileSync(filePath, "utf8");
1813
- } catch {
1814
- return tokens;
1815
- }
1816
- const isMjsFile = filePath.endsWith(".mjs");
1817
- const sourceFile = ts2.createSourceFile(
1818
- path7.basename(filePath),
1819
- sourceCode,
1820
- ts2.ScriptTarget.Latest,
1821
- true,
1822
- isMjsFile ? ts2.ScriptKind.JS : void 0
1823
- );
1824
- function visit(node) {
1825
- if (ts2.isCallExpression(node) && node.arguments.length > 0) {
1826
- const fnName = getFunctionName(node.expression);
1827
- if (fnName && allExecFunctions.has(fnName)) {
1828
- const firstArg = node.arguments[0];
1829
- if (ts2.isStringLiteral(firstArg) || ts2.isNoSubstitutionTemplateLiteral(firstArg)) {
1830
- const value = firstArg.text;
1831
- if (shellCommandFunctions.has(fnName)) {
1832
- for (const token of tokenizeScript(value)) {
1833
- tokens.add(token);
1834
- }
1835
- } else {
1836
- tokens.add(value);
1837
- }
1838
- } else if (ts2.isTemplateExpression(firstArg)) {
1839
- const head = firstArg.head.text;
1840
- if (head) {
1841
- for (const token of tokenizeScript(head)) {
1842
- tokens.add(token);
1843
- }
1844
- }
1845
- }
1846
- }
1847
- }
1848
- ts2.forEachChild(node, visit);
1849
- }
1850
- visit(sourceFile);
1851
- return tokens;
1852
- }
1853
- function getFunctionName(expr) {
1854
- if (ts2.isIdentifier(expr)) {
1855
- return expr.text;
1856
- }
1857
- if (ts2.isPropertyAccessExpression(expr) && ts2.isIdentifier(expr.name)) {
1858
- return expr.name.text;
1859
- }
1860
- return void 0;
1861
- }
1862
- function getCliReferencedPackagesFromFiles(allFiles, location, allDeps) {
1863
- const allTokens = /* @__PURE__ */ new Set();
1864
- for (const file of allFiles) {
1865
- for (const token of getCommandTokensFromFile(file)) {
1866
- allTokens.add(token);
1867
- }
1868
- }
1869
- if (allTokens.size === 0) return /* @__PURE__ */ new Set();
1870
- const binToPackage = /* @__PURE__ */ new Map();
1871
- for (const dep of allDeps) {
1872
- for (const bin of getBinNames(location, dep)) {
1873
- binToPackage.set(bin, dep);
1874
- }
1875
- }
1876
- const referenced = /* @__PURE__ */ new Set();
1877
- for (const token of allTokens) {
1878
- const baseName = getBasePackageName(token);
1879
- if (allDeps.includes(baseName)) {
1880
- referenced.add(baseName);
1881
- }
1882
- const pkg = binToPackage.get(token);
1883
- if (pkg) {
1884
- referenced.add(pkg);
1885
- }
1886
- }
1887
- return referenced;
1888
- }
1889
-
1890
- // src/actions/deplint/implicitDevDependencies.ts
1891
- import fs9 from "fs";
1892
- var hasFileWithExtension = (files, extensions) => files.some((f) => extensions.some((ext) => f.endsWith(ext)));
1893
- var tsExtensions = [".ts", ".tsx", ".mts", ".cts"];
1894
- var hasTypescriptFiles = ({ allFiles }) => hasFileWithExtension(allFiles, tsExtensions);
1895
- var decoratorPattern = /^\s*@[a-zA-Z]\w*/m;
1896
- var hasDecorators = ({ allFiles }) => allFiles.filter((f) => tsExtensions.some((ext) => f.endsWith(ext))).some((file) => {
1897
- try {
1898
- const content = fs9.readFileSync(file, "utf8");
1899
- return decoratorPattern.test(content);
1900
- } catch {
1901
- return false;
1902
- }
1903
- });
1904
- var importPlugins = /* @__PURE__ */ new Set(["eslint-plugin-import-x", "eslint-plugin-import"]);
1905
- function hasImportPlugin({ location, allDependencies }) {
1906
- if (allDependencies.some((d) => importPlugins.has(d))) return true;
1907
- for (const dep of allDependencies) {
1908
- const pkgPath = findDepPackageJson(location, dep);
1909
- if (!pkgPath) continue;
1910
- try {
1911
- const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf8"));
1912
- const transitiveDeps = [
1913
- ...Object.keys(pkg.dependencies ?? {}),
1914
- ...Object.keys(pkg.peerDependencies ?? {})
86
+ versionBump(type) {
87
+ if (type === "prerelease") {
88
+ return [
89
+ ["yarn", "workspaces foreach --all version patch --deferred --prerelease"]
1915
90
  ];
1916
- if (transitiveDeps.some((d) => importPlugins.has(d))) return true;
1917
- } catch {
1918
- }
1919
- }
1920
- return false;
1921
- }
1922
- var hasVitest = ({ allDependencies }) => allDependencies.includes("vitest");
1923
- var rules = [
1924
- {
1925
- package: "typescript",
1926
- isNeeded: hasTypescriptFiles
1927
- },
1928
- {
1929
- package: "eslint-import-resolver-typescript",
1930
- isNeeded: (context) => hasTypescriptFiles(context) && context.allDependencies.includes("eslint") && hasImportPlugin(context)
1931
- },
1932
- {
1933
- package: "tslib",
1934
- isNeeded: hasDecorators
1935
- },
1936
- {
1937
- package: "@vitest/coverage-v8",
1938
- isNeeded: hasVitest
1939
- }
1940
- ];
1941
- function getImplicitDevDependencies(context) {
1942
- const implicit = /* @__PURE__ */ new Set();
1943
- for (const rule of rules) {
1944
- if (rule.isNeeded(context)) {
1945
- implicit.add(rule.package);
1946
- }
1947
- }
1948
- return implicit;
1949
- }
1950
-
1951
- // src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
1952
- var allExternalImports = ({
1953
- externalAllImports,
1954
- externalDistImports,
1955
- externalDistTypeImports
1956
- }) => {
1957
- return /* @__PURE__ */ new Set([
1958
- ...externalAllImports,
1959
- ...externalDistImports,
1960
- ...externalDistTypeImports
1961
- ]);
1962
- };
1963
- function isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs, cliRefs) {
1964
- if (implicitDeps.has(dep)) return true;
1965
- if (requiredPeers.has(dep)) return true;
1966
- if (scriptRefs.has(dep)) return true;
1967
- if (cliRefs.has(dep)) return true;
1968
- if (dep.startsWith("@types/")) {
1969
- const baseName = dep.replace(/^@types\//, "");
1970
- return allImports.has(baseName) || allImports.has(dep) || implicitDeps.has(baseName);
1971
- }
1972
- return allImports.has(dep);
1973
- }
1974
- function getUnusedDevDependencies({ name, location }, {
1975
- devDependencies,
1976
- dependencies,
1977
- peerDependencies
1978
- }, sourceParams, fileContext, exclude) {
1979
- const allImports = allExternalImports(sourceParams);
1980
- const allDeps = [...dependencies, ...devDependencies, ...peerDependencies];
1981
- const implicitDeps = getImplicitDevDependencies({
1982
- ...fileContext,
1983
- allDependencies: allDeps,
1984
- location
1985
- });
1986
- const requiredPeers = getRequiredPeerDependencies(location, allDeps);
1987
- const scriptRefs = getScriptReferencedPackages(location, allDeps);
1988
- const cliRefs = getCliReferencedPackagesFromFiles(fileContext.allFiles, location, allDeps);
1989
- let unusedDevDependencies = 0;
1990
- for (const dep of devDependencies) {
1991
- if (exclude?.has(dep)) continue;
1992
- if (dependencies.includes(dep) || peerDependencies.includes(dep)) continue;
1993
- if (!isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs, cliRefs)) {
1994
- unusedDevDependencies++;
1995
- console.log(`[${chalk23.blue(name)}] Unused devDependency in package.json: ${chalk23.red(dep)}`);
1996
- }
1997
- }
1998
- if (unusedDevDependencies > 0) {
1999
- const packageLocation = `${location}/package.json`;
2000
- console.log(` ${chalk23.yellow(packageLocation)}
2001
- `);
2002
- }
2003
- return unusedDevDependencies;
2004
- }
2005
-
2006
- // src/actions/deplint/checkPackage/getUnusedPeerDependencies.ts
2007
- import chalk24 from "chalk";
2008
- function getUnusedPeerDependencies({ name, location }, { peerDependencies, dependencies }, { externalDistImports, externalDistTypeImports }, exclude) {
2009
- let unusedDependencies = 0;
2010
- for (const dep of peerDependencies) {
2011
- if (exclude?.has(dep)) continue;
2012
- if (!externalDistImports.includes(dep) && !externalDistImports.includes(dep.replace(/^@types\//, "")) && !externalDistTypeImports.includes(dep) && !externalDistTypeImports.includes(dep.replace(/^@types\//, ""))) {
2013
- unusedDependencies++;
2014
- if (dependencies.includes(dep)) {
2015
- console.log(`[${chalk24.blue(name)}] Unused peerDependency [already a dependency] in package.json: ${chalk24.red(dep)}`);
2016
- } else {
2017
- console.log(`[${chalk24.blue(name)}] Unused peerDependency in package.json: ${chalk24.red(dep)}`);
2018
- }
2019
- }
2020
- }
2021
- if (unusedDependencies > 0) {
2022
- const packageLocation = `${location}/package.json`;
2023
- console.log(` ${chalk24.yellow(packageLocation)}
2024
- `);
2025
- }
2026
- return unusedDependencies;
2027
- }
2028
-
2029
- // src/actions/deplint/checkPackage/checkPackage.ts
2030
- function logVerbose(name, location, allFiles, distFiles, tsconfigExtends) {
2031
- console.info(`Checking package: ${name} at ${location}`);
2032
- console.info(`All files: ${allFiles.length}, Distribution files: ${distFiles.length}`);
2033
- for (const file of allFiles) {
2034
- console.info(`File: ${file}`);
2035
- }
2036
- for (const file of distFiles) {
2037
- console.info(`Distribution file: ${file}`);
2038
- }
2039
- for (const ext of tsconfigExtends) {
2040
- console.info(`Tsconfig extends: ${ext}`);
2041
- }
2042
- }
2043
- function checkPackage({
2044
- name,
2045
- location,
2046
- deps = false,
2047
- devDeps = false,
2048
- exclude,
2049
- peerDeps = false,
2050
- verbose = false
2051
- }) {
2052
- const { allFiles, distFiles } = findFiles(location);
2053
- const tsconfigExtends = getExtendsFromTsconfigs(location);
2054
- if (verbose) {
2055
- logVerbose(name, location, allFiles, distFiles, tsconfigExtends);
2056
- }
2057
- const checkDeps = deps || !(deps || devDeps || peerDeps);
2058
- const checkDevDeps = devDeps || !(deps || devDeps || peerDeps);
2059
- const checkPeerDeps = peerDeps;
2060
- const sourceParams = getExternalImportsFromFiles({
2061
- allFiles,
2062
- distFiles,
2063
- tsconfigExtends
2064
- });
2065
- const packageParams = getDependenciesFromPackageJson(`${location}/package.json`);
2066
- const unlistedDependencies = checkDeps ? getUnlistedDependencies({ name, location }, packageParams, sourceParams) : 0;
2067
- const unusedDependencies = checkDeps ? getUnusedDependencies({ name, location }, packageParams, sourceParams, exclude) : 0;
2068
- const unlistedDevDependencies = checkDevDeps ? getUnlistedDevDependencies({ name, location }, packageParams, sourceParams) : 0;
2069
- const fileContext = { allFiles, distFiles };
2070
- const unusedDevDependencies = checkDevDeps ? getUnusedDevDependencies({ name, location }, packageParams, sourceParams, fileContext, exclude) : 0;
2071
- const unusedPeerDependencies = checkPeerDeps ? getUnusedPeerDependencies({ name, location }, packageParams, sourceParams, exclude) : 0;
2072
- const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + unusedDevDependencies + unusedPeerDependencies;
2073
- return totalErrors;
2074
- }
2075
-
2076
- // src/actions/deplint/deplint.ts
2077
- var deplint = async ({
2078
- pkg,
2079
- deps,
2080
- devDeps,
2081
- peerDeps,
2082
- verbose,
2083
- cliExclude
2084
- }) => {
2085
- const config2 = await loadConfig();
2086
- const exclude = /* @__PURE__ */ new Set([
2087
- ...config2.deplint?.exclude ?? [],
2088
- ...cliExclude ?? []
2089
- ]);
2090
- let totalErrors = 0;
2091
- if (pkg === void 0) {
2092
- const workspaces = yarnWorkspaces();
2093
- console.info("Deplint Started...");
2094
- for (const workspace of workspaces) {
2095
- totalErrors += checkPackage({
2096
- ...workspace,
2097
- deps,
2098
- devDeps,
2099
- exclude,
2100
- peerDeps,
2101
- verbose
2102
- });
2103
- }
2104
- } else {
2105
- const { location, name } = yarnWorkspace(pkg);
2106
- console.info(`Running Deplint for ${name}`);
2107
- totalErrors += checkPackage({
2108
- name,
2109
- location,
2110
- devDeps,
2111
- deps,
2112
- exclude,
2113
- peerDeps,
2114
- verbose
2115
- });
2116
- }
2117
- if (totalErrors > 0) {
2118
- console.warn(`Deplint: Found ${chalk25.red(totalErrors)} dependency problems. ${chalk25.red("\u2716")}`);
2119
- } else {
2120
- console.info(`Deplint: Found no dependency problems. ${chalk25.green("\u2714")}`);
2121
- }
2122
- return 0;
2123
- };
2124
-
2125
- // src/actions/deploy.ts
2126
- import { readFileSync as readFileSync12 } from "fs";
2127
- var privatePackageExcludeList = () => {
2128
- const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
2129
- workspace,
2130
- JSON.parse(readFileSync12(`${workspace.location}/package.json`, { encoding: "utf8" }))
2131
- ]);
2132
- const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
2133
- const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
2134
- return excludeList;
2135
- };
2136
- var deploy = () => {
2137
- const excludeList = privatePackageExcludeList();
2138
- if (excludeList.length > 0) {
2139
- console.log("Excluding private packages from deployment:", excludeList);
2140
- }
2141
- return runSteps("Deploy [Patch]", [
2142
- ["yarn", "workspaces foreach --all version patch --deferred"],
2143
- ["yarn", "xy clean"],
2144
- ["yarn", "xy build"],
2145
- ["yarn", "version apply --all"]
2146
- ]);
2147
- };
2148
-
2149
- // src/actions/deploy-major.ts
2150
- import { readFileSync as readFileSync13 } from "fs";
2151
- var privatePackageExcludeList2 = () => {
2152
- const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
2153
- workspace,
2154
- JSON.parse(readFileSync13(`${workspace.location}/package.json`, { encoding: "utf8" }))
2155
- ]);
2156
- const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
2157
- const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
2158
- return excludeList;
2159
- };
2160
- var deployMajor = () => {
2161
- const excludeList = privatePackageExcludeList2();
2162
- if (excludeList.length > 0) {
2163
- console.log("Excluding private packages from deployment:", excludeList);
2164
- }
2165
- return runSteps("Deploy [Major]", [
2166
- ["yarn", "workspaces foreach --all version major --deferred"],
2167
- ["yarn", "xy clean"],
2168
- ["yarn", "xy build"],
2169
- ["yarn", "version apply --all"]
2170
- ]);
2171
- };
2172
-
2173
- // src/actions/deploy-minor.ts
2174
- import { readFileSync as readFileSync14 } from "fs";
2175
- var privatePackageExcludeList3 = () => {
2176
- const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
2177
- workspace,
2178
- JSON.parse(readFileSync14(`${workspace.location}/package.json`, { encoding: "utf8" }))
2179
- ]);
2180
- const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
2181
- const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
2182
- return excludeList;
2183
- };
2184
- var deployMinor = () => {
2185
- const excludeList = privatePackageExcludeList3();
2186
- if (excludeList.length > 0) {
2187
- console.log("Excluding private packages from deployment:", excludeList);
2188
- }
2189
- return runSteps("Deploy [Minor]", [
2190
- ["yarn", "workspaces foreach --all version minor --deferred"],
2191
- ["yarn", "xy clean"],
2192
- ["yarn", "xy build"],
2193
- ["yarn", "version apply --all"]
2194
- ]);
2195
- };
2196
-
2197
- // src/actions/deploy-next.ts
2198
- import { readFileSync as readFileSync15 } from "fs";
2199
- var privatePackageExcludeList4 = () => {
2200
- const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
2201
- workspace,
2202
- JSON.parse(readFileSync15(`${workspace.location}/package.json`, { encoding: "utf8" }))
2203
- ]);
2204
- const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
2205
- const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
2206
- return excludeList;
2207
- };
2208
- var deployNext = () => {
2209
- const excludeList = privatePackageExcludeList4();
2210
- if (excludeList.length > 0) {
2211
- console.log("Excluding private packages from deployment:", excludeList);
2212
- }
2213
- return runSteps("Deploy [Next]", [
2214
- ["yarn", "workspaces foreach --all version minor --deferred"],
2215
- ["yarn", "xy clean"],
2216
- ["yarn", "xy build"],
2217
- ["yarn", "version apply --all --prerelease"]
2218
- ]);
2219
- };
2220
-
2221
- // src/actions/dupdeps.ts
2222
- import chalk26 from "chalk";
2223
- var dupdeps = () => {
2224
- console.log(chalk26.green("Checking all Dependencies for Duplicates"));
2225
- const pkg = parsedPackageJSON();
2226
- const allDependencies = { ...pkg?.dependencies, ...pkg?.devDependencies };
2227
- const dependencies = Object.keys(allDependencies);
2228
- return detectDuplicateDependencies(dependencies);
2229
- };
2230
-
2231
- // src/actions/lint.ts
2232
- import chalk27 from "chalk";
2233
- var lintPackage = ({
2234
- pkg,
2235
- fix: fix2,
2236
- verbose
2237
- }) => {
2238
- console.log(chalk27.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
2239
- const start = Date.now();
2240
- const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
2241
- ["yarn", [
2242
- "workspace",
2243
- pkg,
2244
- "run",
2245
- fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint"
2246
- ]]
2247
- ]);
2248
- console.log(chalk27.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk27.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk27.gray("seconds")}`));
2249
- return result;
2250
- };
2251
- var lint = ({
2252
- pkg,
2253
- verbose,
2254
- incremental,
2255
- fix: fix2
2256
- } = {}) => {
2257
- return pkg === void 0 ? lintAllPackages({
2258
- verbose,
2259
- incremental,
2260
- fix: fix2
2261
- }) : lintPackage({
2262
- pkg,
2263
- fix: fix2,
2264
- verbose
2265
- });
2266
- };
2267
- var lintAllPackages = ({ fix: fix2 = false } = {}) => {
2268
- console.log(chalk27.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
2269
- const start = Date.now();
2270
- const fixOptions = fix2 ? ["--fix"] : [];
2271
- const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
2272
- ["yarn", ["eslint", "--cache", "--cache-location", ".eslintcache", "--cache-strategy", "content", ...fixOptions]]
2273
- ]);
2274
- console.log(chalk27.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk27.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk27.gray("seconds")}`));
2275
- return result;
2276
- };
2277
-
2278
- // src/actions/fix.ts
2279
- var fix = (params) => {
2280
- return lint({ ...params, fix: true });
2281
- };
2282
-
2283
- // src/actions/gen-docs.ts
2284
- var genDocs = ({ pkg, incremental }) => {
2285
- return pkg ? genDocsPackage({ pkg }) : genDocsAll({ incremental });
2286
- };
2287
- var genDocsPackage = ({ pkg }) => {
2288
- const steps = [["yarn", ["workspace", pkg, "run", "package-gen-docs"]]];
2289
- return runSteps(`GenDocs [${pkg}]`, [...steps]);
2290
- };
2291
- var genDocsAll = ({ incremental }) => {
2292
- const incrementalOptions = incremental ? ["--since", "-pA"] : ["-pA"];
2293
- const steps = [["yarn", ["workspaces", "foreach", ...incrementalOptions, "run", "package-gen-docs"]]];
2294
- return runSteps(`GenDocs [All${incremental ? "-Incremental" : ""}]`, [...steps]);
2295
- };
2296
-
2297
- // src/actions/gitignore.ts
2298
- import { unlinkSync as unlinkSync4 } from "fs";
2299
- import chalk28 from "chalk";
2300
- var COMMENT_PREFIX = "#";
2301
- var isComment = (line) => line.startsWith(COMMENT_PREFIX);
2302
- var isNegation = (line) => line.startsWith("!");
2303
- function parseTemplateSections(lines) {
2304
- const sections = [];
2305
- let current = [];
2306
- for (const line of lines) {
2307
- if (isComment(line)) {
2308
- if (current.length > 0) {
2309
- sections.push(current);
2310
- }
2311
- current = [line];
2312
- } else {
2313
- current.push(line);
2314
- }
2315
- }
2316
- if (current.length > 0) {
2317
- sections.push(current);
2318
- }
2319
- return sections;
2320
- }
2321
- function mergeWithTemplate(existing, templateContent) {
2322
- const templateLines = templateContent.split("\n").filter((line) => line.trim().length > 0);
2323
- const sections = parseTemplateSections(templateLines);
2324
- const existingEntries = new Set(existing.filter((line) => !isComment(line)));
2325
- const templateEntries = new Set(templateLines.filter((line) => !isComment(line)));
2326
- const customEntries = [...existingEntries].filter((entry) => !templateEntries.has(entry));
2327
- const result = [];
2328
- for (const section of sections) {
2329
- for (const line of section) {
2330
- result.push(line);
2331
- }
2332
- result.push("");
2333
- }
2334
- if (customEntries.length > 0) {
2335
- result.push("# Custom");
2336
- const sorted = [...union(customEntries, [])].toSorted((a, b) => {
2337
- if (isNegation(a) && !isNegation(b)) return 1;
2338
- if (!isNegation(a) && isNegation(b)) return -1;
2339
- return a.localeCompare(b);
2340
- });
2341
- for (const entry of sorted) {
2342
- result.push(entry);
2343
- }
2344
- result.push("");
2345
- }
2346
- return result;
2347
- }
2348
- function removePackageGitignores(cwd5) {
2349
- let removed = 0;
2350
- const workspaces = yarnWorkspaces();
2351
- for (const { location } of workspaces) {
2352
- if (location === ".") continue;
2353
- const filePath = `${cwd5}/${location}/.gitignore`;
2354
- try {
2355
- unlinkSync4(filePath);
2356
- console.log(chalk28.yellow(` Removed ${location}/.gitignore`));
2357
- removed++;
2358
- } catch {
2359
- }
2360
- }
2361
- return removed;
2362
- }
2363
- var gitignoreGen = gitignore;
2364
- function gitignore() {
2365
- console.log(chalk28.green("Generate .gitignore"));
2366
- const cwd5 = INIT_CWD() ?? ".";
2367
- const gitignorePath = `${cwd5}/.gitignore`;
2368
- try {
2369
- const templateContent = gitignoreTemplate();
2370
- const existing = readNonEmptyLines(gitignorePath);
2371
- const merged = mergeWithTemplate(existing, templateContent);
2372
- writeLines(gitignorePath, merged);
2373
- console.log(chalk28.green(" Root .gitignore updated"));
2374
- const removed = removePackageGitignores(cwd5);
2375
- if (removed > 0) {
2376
- console.log(chalk28.green(` Removed ${removed} package .gitignore file(s)`));
2377
- }
2378
- return 0;
2379
- } catch (ex) {
2380
- const error = ex;
2381
- console.error(chalk28.red(`Generate .gitignore failed: ${error.message}`));
2382
- return 1;
2383
- }
2384
- }
2385
-
2386
- // src/actions/gitlint.ts
2387
- import chalk29 from "chalk";
2388
- import ParseGitConfig from "parse-git-config";
2389
- var gitlint = () => {
2390
- console.log(`
2391
- Gitlint Start [${process.cwd()}]
2392
- `);
2393
- let valid = 0;
2394
- let warnings = 0;
2395
- const errors = 0;
2396
- const gitConfig = ParseGitConfig.sync();
2397
- const warn = (message) => {
2398
- console.warn(chalk29.yellow(`Warning: ${message}`));
2399
- warnings++;
2400
- };
2401
- if (gitConfig.core.ignorecase) {
2402
- warn("Please set core.ignorecase to FALSE in .git/config file [run yarn gitlint-fix]");
2403
- } else {
2404
- valid++;
2405
- }
2406
- if (gitConfig.core.autocrlf === false) {
2407
- valid++;
2408
- } else {
2409
- warn("Please set core.autocrlf to FALSE in .git/config file [run yarn gitlint-fix]");
2410
- }
2411
- if (gitConfig.core.eol === "lf") {
2412
- valid++;
2413
- } else {
2414
- warn('Please set core.eol to "lf" in .git/config file [run yarn gitlint-fix]');
2415
- }
2416
- const resultMessages = [];
2417
- if (valid > 0) {
2418
- resultMessages.push(chalk29.green(`Passed: ${valid}`));
2419
- }
2420
- if (warnings > 0) {
2421
- resultMessages.push(chalk29.yellow(`Warnings: ${warnings}`));
2422
- }
2423
- if (errors > 0) {
2424
- resultMessages.push(chalk29.red(` Errors: ${errors}`));
2425
- }
2426
- console.warn(`Gitlint Finish [ ${resultMessages.join(" | ")} ]
2427
- `);
2428
- return warnings + errors === 0 ? 1 : 0;
2429
- };
2430
-
2431
- // src/actions/gitlint-fix.ts
2432
- import { execSync as execSync3 } from "child_process";
2433
- import chalk30 from "chalk";
2434
- import ParseGitConfig2 from "parse-git-config";
2435
- var gitlintFix = () => {
2436
- console.log(`
2437
- Gitlint Fix Start [${process.cwd()}]
2438
- `);
2439
- const gitConfig = ParseGitConfig2.sync();
2440
- if (gitConfig.core.ignorecase) {
2441
- execSync3("git config core.ignorecase false", { stdio: "inherit" });
2442
- console.warn(chalk30.yellow("\nGitlint Fix: Updated core.ignorecase to be false\n"));
2443
- }
2444
- if (gitConfig.core.autocrlf !== false) {
2445
- execSync3("git config core.autocrlf false", { stdio: "inherit" });
2446
- console.warn(chalk30.yellow("\nGitlint Fix: Updated core.autocrlf to be false\n"));
2447
- }
2448
- if (gitConfig.core.eol !== "lf") {
2449
- execSync3("git config core.eol lf", { stdio: "inherit" });
2450
- console.warn(chalk30.yellow('\nGitlint Fix: Updated core.eol to be "lf"\n'));
2451
- }
2452
- return 1;
2453
- };
2454
-
2455
- // src/actions/knip.ts
2456
- var knip = () => {
2457
- return runSteps("Knip", [["yarn", ["knip", "--dependencies", "--no-exit-code"]]]);
2458
- };
2459
-
2460
- // src/actions/license.ts
2461
- import chalk31 from "chalk";
2462
- import { init } from "license-checker";
2463
- var license = async (pkg) => {
2464
- const workspaces = yarnWorkspaces();
2465
- const workspaceList = workspaces.filter(({ name }) => {
2466
- return pkg === void 0 || name === pkg;
2467
- });
2468
- const exclude = /* @__PURE__ */ new Set([
2469
- "MIT",
2470
- "MIT*",
2471
- "ISC",
2472
- "Apache-2.0",
2473
- "BSD",
2474
- "BSD*",
2475
- "BSD-2-Clause",
2476
- "BSD-3-Clause",
2477
- "CC-BY-4.0",
2478
- "Unlicense",
2479
- "CC-BY-3.0",
2480
- "CC0-1.0",
2481
- "LGPL-3.0-only",
2482
- "LGPL-3.0",
2483
- "LGPL-3.0-or-later",
2484
- "Python-2.0"
2485
- ]);
2486
- console.log(chalk31.green("License Checker"));
2487
- return (await Promise.all(
2488
- workspaceList.map(({ location, name }) => {
2489
- return new Promise((resolve) => {
2490
- init({ production: true, start: location }, (error, packages) => {
2491
- if (error) {
2492
- console.error(chalk31.red(`License Checker [${name}] Error`));
2493
- console.error(chalk31.gray(error));
2494
- console.log("\n");
2495
- resolve(1);
2496
- } else {
2497
- console.log(chalk31.green(`License Checker [${name}]`));
2498
- let count = 0;
2499
- for (const [name2, info] of Object.entries(packages)) {
2500
- const licenses = Array.isArray(info.licenses) ? info.licenses : [info.licenses];
2501
- for (let license2 of licenses) {
2502
- if (license2) {
2503
- const processedLicense = license2[0] === "(" && license2.at(-1) === ")" ? license2.slice(1, -2) : license2;
2504
- const orLicenses = processedLicense.split(" OR ");
2505
- let orLicenseFound = false;
2506
- for (const orLicense of orLicenses) {
2507
- if (exclude.has(orLicense)) {
2508
- orLicenseFound = true;
2509
- }
2510
- }
2511
- if (!orLicenseFound) {
2512
- count++;
2513
- console.warn(chalk31.yellow(`${name2}: Package License not allowed [${license2}]`));
2514
- }
2515
- }
2516
- }
2517
- }
2518
- console.log("\n");
2519
- resolve(count);
2520
- }
2521
- });
2522
- });
2523
- })
2524
- )).reduce((prev, value) => prev || value, 0);
2525
- };
2526
-
2527
- // src/actions/lintlint.ts
2528
- import { readFileSync as readFileSync16, writeFileSync as writeFileSync6 } from "fs";
2529
- import PATH10 from "path";
2530
- import chalk32 from "chalk";
2531
- import { findUp } from "find-up";
2532
- function parseRuleValue(value) {
2533
- if (typeof value === "string") {
2534
- return { level: value };
2535
- }
2536
- if (typeof value === "number") {
2537
- return { level: String(value) };
2538
- }
2539
- if (Array.isArray(value) && value.length > 0) {
2540
- return {
2541
- level: String(value[0]),
2542
- options: value.length > 1 ? value.slice(1) : void 0
2543
- };
2544
- }
2545
- return void 0;
2546
- }
2547
- function normalizeLevel(level) {
2548
- if (level === "0" || level === "off") return "off";
2549
- if (level === "1" || level === "warn") return "warn";
2550
- if (level === "2" || level === "error") return "error";
2551
- return level;
2552
- }
2553
- function rulesMatch(a, b) {
2554
- if (normalizeLevel(a.level) !== normalizeLevel(b.level)) return false;
2555
- return JSON.stringify(a.options) === JSON.stringify(b.options);
2556
- }
2557
- function formatRule(entry) {
2558
- if (entry.options) {
2559
- return JSON.stringify([entry.level, ...entry.options]);
2560
- }
2561
- return JSON.stringify([entry.level]);
2562
- }
2563
- function mergeRulesFromBlocks(blocks) {
2564
- const merged = /* @__PURE__ */ new Map();
2565
- for (const block of blocks) {
2566
- if (!block.rules) continue;
2567
- for (const [name, value] of Object.entries(block.rules)) {
2568
- const parsed = parseRuleValue(value);
2569
- if (parsed) merged.set(name, parsed);
2570
- }
2571
- }
2572
- return merged;
2573
- }
2574
- function detectSharedPackage(source) {
2575
- if (source.includes("@xylabs/eslint-config-react-flat")) return "@xylabs/eslint-config-react-flat";
2576
- if (source.includes("@xylabs/eslint-config-flat")) return "@xylabs/eslint-config-flat";
2577
- return void 0;
2578
- }
2579
- function extractLocalRuleBlocks(source) {
2580
- const blocks = [];
2581
- const ruleBlockRegex = /\{\s*(?:files\s*:\s*\[.*?\]\s*,\s*)?rules\s*:\s*\{([^}]*(?:\{[^}]*\}[^}]*)*)\}/g;
2582
- let match;
2583
- while ((match = ruleBlockRegex.exec(source)) !== null) {
2584
- blocks.push(match[1]);
2585
- }
2586
- return blocks;
2587
- }
2588
- function extractRulesFromSourceBlocks(blocks) {
2589
- const rules2 = /* @__PURE__ */ new Map();
2590
- for (const block of blocks) {
2591
- const ruleRegex = /['"]([^'"]+)['"]\s*:\s*(\[[\s\S]*?\](?=\s*,|\s*$))/gm;
2592
- let match;
2593
- while ((match = ruleRegex.exec(block)) !== null) {
2594
- rules2.set(match[1], match[2]);
2595
- }
2596
- }
2597
- return rules2;
2598
- }
2599
- async function resolveSharedConfig(configDir, sharedPkg) {
2600
- try {
2601
- const sharedModule = await import(sharedPkg);
2602
- const config2 = sharedModule.config ?? sharedModule.default;
2603
- if (Array.isArray(config2)) return config2;
2604
- return [];
2605
- } catch {
2606
- const distPath = PATH10.resolve(configDir, "node_modules", sharedPkg, "dist", "node", "index.mjs");
2607
- try {
2608
- const sharedModule = await import(distPath);
2609
- const config2 = sharedModule.config ?? sharedModule.default;
2610
- if (Array.isArray(config2)) return config2;
2611
- } catch {
2612
- const neutralPath = PATH10.resolve(configDir, "node_modules", sharedPkg, "dist", "neutral", "index.mjs");
2613
- const sharedModule = await import(neutralPath);
2614
- const config2 = sharedModule.config ?? sharedModule.default;
2615
- if (Array.isArray(config2)) return config2;
2616
- }
2617
- return [];
2618
- }
2619
- }
2620
- async function loadSharedRules(configDir, sharedPkg, verbose) {
2621
- const sharedBlocks = await resolveSharedConfig(configDir, sharedPkg);
2622
- const sharedRules = mergeRulesFromBlocks(sharedBlocks);
2623
- if (verbose) {
2624
- console.log(chalk32.gray(`Shared config defines ${sharedRules.size} rules`));
2625
- }
2626
- if (sharedRules.size === 0) {
2627
- console.error(chalk32.red("Could not load rules from shared config. Is it installed and built?"));
2628
- return void 0;
2629
- }
2630
- return sharedRules;
2631
- }
2632
- async function loadLocalRules(eslintConfigPath, source, verbose) {
2633
- const localModule = await import(eslintConfigPath);
2634
- const localConfig = localModule.default ?? localModule;
2635
- const localBlocks = Array.isArray(localConfig) ? localConfig : [localConfig];
2636
- const resolved = mergeRulesFromBlocks(localBlocks);
2637
- const localRuleBlocks = extractLocalRuleBlocks(source);
2638
- const explicit = extractRulesFromSourceBlocks(localRuleBlocks);
2639
- if (verbose) {
2640
- console.log(chalk32.gray(`Local config has ${explicit.size} explicit rule setting(s)`));
2641
- }
2642
- return { explicit, resolved };
2643
- }
2644
- function compareRules(explicitRuleNames, allResolvedRules, sharedRules) {
2645
- const redundant = [];
2646
- const overrides = [];
2647
- const additions = [];
2648
- for (const ruleName of explicitRuleNames.keys()) {
2649
- const resolvedEntry = allResolvedRules.get(ruleName);
2650
- const sharedEntry = sharedRules.get(ruleName);
2651
- if (!resolvedEntry) continue;
2652
- if (!sharedEntry) {
2653
- additions.push({ local: resolvedEntry, rule: ruleName });
2654
- } else if (rulesMatch(resolvedEntry, sharedEntry)) {
2655
- redundant.push({
2656
- local: resolvedEntry,
2657
- rule: ruleName,
2658
- shared: sharedEntry
2659
- });
2660
- } else {
2661
- overrides.push({
2662
- local: resolvedEntry,
2663
- rule: ruleName,
2664
- shared: sharedEntry
2665
- });
2666
- }
2667
- }
2668
- return {
2669
- additions,
2670
- overrides,
2671
- redundant
2672
- };
2673
- }
2674
- function reportResults({
2675
- additions,
2676
- overrides,
2677
- redundant
2678
- }, verbose) {
2679
- if (redundant.length > 0) {
2680
- console.log(chalk32.yellow(`
2681
- ${redundant.length} redundant rule(s) (same as shared config \u2014 can be removed):`));
2682
- for (const { rule, local } of redundant) {
2683
- console.log(chalk32.yellow(` ${rule}: ${formatRule(local)}`));
2684
- }
2685
- }
2686
- if (overrides.length > 0) {
2687
- console.log(chalk32.cyan(`
2688
- ${overrides.length} rule override(s) (different from shared config):`));
2689
- for (const {
2690
- rule,
2691
- local,
2692
- shared
2693
- } of overrides) {
2694
- console.log(chalk32.cyan(` ${rule}:`));
2695
- console.log(chalk32.gray(` shared: ${formatRule(shared)}`));
2696
- console.log(chalk32.white(` local: ${formatRule(local)}`));
2697
91
  }
2698
- }
2699
- if (additions.length > 0 && verbose) {
2700
- console.log(chalk32.gray(`
2701
- ${additions.length} local addition(s) (not in shared config):`));
2702
- for (const { rule, local } of additions) {
2703
- console.log(chalk32.gray(` ${rule}: ${formatRule(local)}`));
2704
- }
2705
- }
2706
- if (redundant.length === 0 && overrides.length === 0) {
2707
- console.log(chalk32.green("No redundant or overridden rules found"));
2708
- }
2709
- }
2710
- function fixRedundantRules(eslintConfigPath, source, redundant) {
2711
- let updated = source;
2712
- for (const { rule } of redundant) {
2713
- const escaped = rule.replaceAll("/", String.raw`\/`);
2714
- const pattern = new RegExp(String.raw`[ \t]*['"]${escaped}['"]\s*:\s*\[[^\]]*\],?[ \t]*\n?`, "g");
2715
- updated = updated.replace(pattern, "");
2716
- }
2717
- updated = updated.replaceAll(/\n{3,}/g, "\n\n");
2718
- if (updated !== source) {
2719
- writeFileSync6(eslintConfigPath, updated, "utf8");
2720
- console.log(chalk32.green(`
2721
- Fixed: removed ${redundant.length} redundant rule(s)`));
2722
- }
2723
- }
2724
- async function lintlint({ fix: fix2, verbose } = {}) {
2725
- const eslintConfigPath = await findUp("eslint.config.mjs");
2726
- if (!eslintConfigPath) {
2727
- console.error(chalk32.red("No eslint.config.mjs found"));
2728
- return 1;
2729
- }
2730
- const configDir = PATH10.dirname(eslintConfigPath);
2731
- if (verbose) {
2732
- console.log(chalk32.gray(`Found config: ${eslintConfigPath}`));
2733
- }
2734
- const source = readFileSync16(eslintConfigPath, "utf8");
2735
- const sharedPkg = detectSharedPackage(source);
2736
- if (!sharedPkg) {
2737
- console.log(chalk32.yellow("No @xylabs/eslint-config-flat or @xylabs/eslint-config-react-flat imports found"));
2738
- return 0;
2739
- }
2740
- if (verbose) {
2741
- console.log(chalk32.gray(`Shared package: ${sharedPkg}`));
2742
- }
2743
- const sharedRules = await loadSharedRules(configDir, sharedPkg, !!verbose);
2744
- if (!sharedRules) return 1;
2745
- const { explicit, resolved } = await loadLocalRules(eslintConfigPath, source, !!verbose);
2746
- const results = compareRules(explicit, resolved, sharedRules);
2747
- reportResults(results, !!verbose);
2748
- if (results.redundant.length > 0 && fix2) {
2749
- fixRedundantRules(eslintConfigPath, source, results.redundant);
2750
- }
2751
- return results.redundant.length > 0 && !fix2 ? 1 : 0;
2752
- }
2753
-
2754
- // src/actions/npmignore-gen.ts
2755
- var filename = ".npmignore";
2756
- var npmignoreGen = (pkg) => generateIgnoreFiles(filename, pkg);
2757
-
2758
- // src/actions/package/clean-outputs.ts
2759
- import path8 from "path";
2760
- import chalk33 from "chalk";
2761
- var packageCleanOutputs = () => {
2762
- const pkg = process.env.INIT_CWD ?? ".";
2763
- const pkgName = process.env.npm_package_name;
2764
- const folders = [path8.join(pkg, "dist"), path8.join(pkg, "build"), path8.join(pkg, "docs")];
2765
- console.log(chalk33.green(`Cleaning Outputs [${pkgName}]`));
2766
- for (let folder of folders) {
2767
- deleteGlob(folder);
2768
- }
2769
- return 0;
2770
- };
2771
-
2772
- // src/actions/package/clean-typescript.ts
2773
- import path9 from "path";
2774
- import chalk34 from "chalk";
2775
- var packageCleanTypescript = () => {
2776
- const pkg = process.env.INIT_CWD ?? ".";
2777
- const pkgName = process.env.npm_package_name;
2778
- console.log(chalk34.green(`Cleaning Typescript [${pkgName}]`));
2779
- const files = [path9.join(pkg, "*.tsbuildinfo"), path9.join(pkg, ".tsconfig.*"), path9.join(pkg, ".eslintcache")];
2780
- for (let file of files) {
2781
- deleteGlob(file);
2782
- }
2783
- return 0;
2784
- };
2785
-
2786
- // src/actions/package/clean.ts
2787
- var packageClean = async () => {
2788
- return (await Promise.all([packageCleanOutputs(), packageCleanTypescript()])).reduce((prev, value) => prev + value, 0);
2789
- };
2790
-
2791
- // src/actions/package/compile/compile.ts
2792
- import chalk39 from "chalk";
2793
-
2794
- // src/actions/package/compile/packageCompileTsup.ts
2795
- import chalk38 from "chalk";
2796
- import { build as build2, defineConfig } from "tsup";
2797
-
2798
- // src/actions/package/compile/inputs.ts
2799
- import chalk35 from "chalk";
2800
- import { glob as glob2 } from "glob";
2801
- var getAllInputs = (srcDir, verbose = false) => {
2802
- return [...glob2.sync(`${srcDir}/**/*.ts`, { posix: true }).map((file) => {
2803
- const result = file.slice(Math.max(0, srcDir.length + 1));
2804
- if (verbose) {
2805
- console.log(chalk35.gray(`getAllInputs: ${JSON.stringify(result, null, 2)}`));
2806
- }
2807
- return result;
2808
- }), ...glob2.sync(`${srcDir}/**/*.tsx`, { posix: true }).map((file) => {
2809
- const result = file.slice(Math.max(0, srcDir.length + 1));
2810
- if (verbose) {
2811
- console.log(chalk35.gray(`getAllInputs: ${JSON.stringify(result, null, 2)}`));
2812
- }
2813
- return result;
2814
- })];
2815
- };
2816
-
2817
- // src/actions/package/compile/buildEntries.ts
2818
- var isSpecOrStory = (entry) => {
2819
- return entry.includes(".spec.") || entry.includes(".stories.") || entry.startsWith("spec/") || entry.includes("/spec/") || entry.startsWith("stories/") || entry.includes("/stories/") || entry === "spec.ts" || entry.endsWith("/spec.ts") || entry === "stories.ts" || entry.endsWith("/stories.ts");
2820
- };
2821
- var buildEntries = (srcDir, entryMode = "single", options, excludeSpecAndStories = true, verbose = false) => {
2822
- let entries = [];
2823
- switch (entryMode) {
2824
- case "platform": {
2825
- entries = ["index-node.ts", "index-browser.ts"];
2826
- break;
2827
- }
2828
- case "all": {
2829
- entries = (excludeSpecAndStories ? getAllInputs(srcDir).filter((entry) => !isSpecOrStory(entry)) : getAllInputs(srcDir)).filter((entry) => !entry.endsWith(".d.ts"));
2830
- break;
2831
- }
2832
- case "custom": {
2833
- entries = [];
2834
- break;
2835
- }
2836
- default: {
2837
- entries = ["index.ts"];
2838
- break;
2839
- }
2840
- }
2841
- if (typeof options !== "boolean" && Array.isArray(options?.entry)) {
2842
- entries.push(...options.entry);
2843
- }
2844
- if (verbose) console.log(`buildEntries [${entryMode}] ${entries.length}`);
2845
- return entries;
2846
- };
2847
-
2848
- // src/actions/package/compile/deepMerge.ts
2849
- function deepMerge(target, source) {
2850
- if (!source || typeof source !== "object") return target;
2851
- for (const key of Object.keys(source)) {
2852
- if (typeof source[key] === "object" && source[key] !== null && !Array.isArray(source[key])) {
2853
- if (!target[key] || typeof target[key] !== "object") {
2854
- target[key] = {};
2855
- }
2856
- deepMerge(target[key], source[key]);
2857
- } else {
2858
- target[key] = source[key];
2859
- }
2860
- }
2861
- return target;
2862
- }
2863
- function deepMergeObjects(objects) {
2864
- const result = {};
2865
- for (const obj of objects) {
2866
- deepMerge(result, obj);
2867
- }
2868
- return result;
2869
- }
2870
-
2871
- // src/actions/package/compile/packageCompileTsc.ts
2872
- import { cwd as cwd2 } from "process";
2873
- import chalk36 from "chalk";
2874
- import { createProgramFromConfig } from "tsc-prog";
2875
- import ts3, {
2876
- DiagnosticCategory,
2877
- formatDiagnosticsWithColorAndContext,
2878
- getPreEmitDiagnostics,
2879
- sys
2880
- } from "typescript";
2881
-
2882
- // src/actions/package/compile/getCompilerOptions.ts
2883
- import { cwd } from "process";
2884
- import deepmerge2 from "deepmerge";
2885
- import { getTsconfig } from "get-tsconfig";
2886
- var getCompilerOptions = (options = {}, fileName = "tsconfig.json") => {
2887
- const resolvedTsConfigCompilerOptions = getTsconfig(cwd(), fileName)?.config?.compilerOptions ?? {};
2888
- return deepmerge2(resolvedTsConfigCompilerOptions, options);
2889
- };
2890
-
2891
- // src/actions/package/compile/packageCompileTsc.ts
2892
- var packageCompileTsc = (platform, entries, srcDir = "src", outDir = "dist", compilerOptionsParam, verbose = false) => {
2893
- const pkg = process.env.INIT_CWD ?? cwd2();
2894
- if (verbose) {
2895
- console.log(chalk36.cyan(`Validating code START: ${entries.length} files to ${outDir} from ${srcDir}`));
2896
- }
2897
- const configFilePath = ts3.findConfigFile(
2898
- "./",
2899
- // search path
2900
- ts3.sys.fileExists,
2901
- "tsconfig.json"
2902
- );
2903
- if (configFilePath === void 0) {
2904
- throw new Error("Could not find tsconfig.json");
2905
- }
2906
- const compilerOptions = {
2907
- ...getCompilerOptions({
2908
- removeComments: false,
2909
- skipDefaultLibCheck: true,
2910
- skipLibCheck: true,
2911
- sourceMap: false
2912
- }),
2913
- ...compilerOptionsParam,
2914
- outDir: `${outDir}/${platform}`,
2915
- emitDeclarationOnly: true,
2916
- noEmit: false
2917
- };
2918
- console.log(chalk36.cyan(`Validating Files: ${entries.length}`));
2919
- if (verbose) {
2920
- for (const entry of entries) {
2921
- console.log(chalk36.grey(`Validating: ${entry}`));
2922
- }
2923
- }
2924
- try {
2925
- if (entries.length > 0) {
2926
- const program = createProgramFromConfig({
2927
- configFilePath,
2928
- basePath: pkg ?? cwd2(),
2929
- compilerOptions,
2930
- files: entries.map((entry) => `${srcDir}/${entry}`),
2931
- include: [`${srcDir}/**/*.*`]
2932
- });
2933
- const diagnostics = getPreEmitDiagnostics(program);
2934
- if (diagnostics.length > 0) {
2935
- const formattedDiagnostics = formatDiagnosticsWithColorAndContext(
2936
- diagnostics,
2937
- {
2938
- getCanonicalFileName: (fileName) => fileName,
2939
- getCurrentDirectory: () => srcDir,
2940
- getNewLine: () => sys.newLine
2941
- }
2942
- );
2943
- console.error(formattedDiagnostics);
2944
- }
2945
- const nonEmitPatterns = [".stories.", "/stories/", "/stories.", ".spec.", "/spec/", "/spec.", ".example."];
2946
- program.emit(void 0, (fileName, text, writeByteOrderMark) => {
2947
- if (nonEmitPatterns.some((pattern) => fileName.includes(pattern))) {
2948
- return;
2949
- }
2950
- ts3.sys.writeFile(fileName, text, writeByteOrderMark);
2951
- });
2952
- return diagnostics.reduce((acc, diag) => acc + (diag.category === DiagnosticCategory.Error ? 1 : 0), 0);
2953
- }
2954
- return 0;
2955
- } finally {
2956
- if (verbose) {
2957
- console.log(chalk36.cyan(`Validating code FINISH: ${entries.length} files to ${outDir} from ${srcDir}`));
2958
- }
2959
- }
2960
- };
2961
-
2962
- // src/actions/package/compile/packageCompileTscTypes.ts
2963
- import path10 from "path";
2964
- import { cwd as cwd3 } from "process";
2965
- import chalk37 from "chalk";
2966
- import { rollup } from "rollup";
2967
- import dts from "rollup-plugin-dts";
2968
- import nodeExternals from "rollup-plugin-node-externals";
2969
- var ignoredWarningCodes = /* @__PURE__ */ new Set(["EMPTY_BUNDLE", "UNRESOLVED_IMPORT"]);
2970
- async function bundleDts(inputPath, outputPath, platform, options, verbose = false) {
2971
- const pkg = process.env.INIT_CWD ?? cwd3();
2972
- const tsconfigPath = path10.resolve(pkg, "tsconfig.json");
2973
- const nodePlugIns = platform === "node" ? [nodeExternals()] : [];
2974
- try {
2975
- const bundle = await rollup({
2976
- input: inputPath,
2977
- plugins: [dts({
2978
- ...options,
2979
- tsconfig: tsconfigPath,
2980
- compilerOptions: {
2981
- emitDeclarationOnly: true,
2982
- noEmit: false,
2983
- declarationMap: true
2984
- }
2985
- }), ...nodePlugIns],
2986
- onwarn(warning, warn) {
2987
- if (ignoredWarningCodes.has(warning.code ?? "")) {
2988
- return;
2989
- }
2990
- console.warn(chalk37.yellow(`[${warning.code}] ${warning.message}`));
2991
- console.warn(chalk37.gray(inputPath));
2992
- warn(warning);
2993
- }
2994
- });
2995
- await bundle.write({
2996
- file: outputPath,
2997
- format: "es"
2998
- });
2999
- } catch (ex) {
3000
- const error = ex;
3001
- console.warn(chalk37.red(error));
3002
- console.warn(chalk37.gray(inputPath));
3003
- }
3004
- if (verbose) {
3005
- console.log(`Bundled declarations written to ${outputPath}`);
3006
- }
3007
- }
3008
- var packageCompileTscTypes = async (entries, outDir, platform, srcDir = "build", verbose = false) => {
3009
- if (verbose) {
3010
- console.log(chalk37.cyan(`Compiling Types START [${platform}]: ${entries.length} files to ${outDir} from ${srcDir}`));
3011
- console.log(`Entries: ${entries.join(", ")}`);
3012
- }
3013
- const pkg = process.env.INIT_CWD ?? cwd3();
3014
- const srcRoot = `${pkg}/${srcDir}/${platform}`;
3015
- const entryNameToTypeName = (entry) => {
3016
- const splitEntryName = entry.split(".");
3017
- const newEntryExtension = "d." + splitEntryName.at(-1);
3018
- return [...splitEntryName.slice(0, -1), newEntryExtension].join(".");
3019
- };
3020
- const compilerOptions = getCompilerOptions({
3021
- removeComments: false,
3022
- skipDefaultLibCheck: true,
3023
- skipLibCheck: true,
3024
- declarationMap: true,
3025
- emitDeclarationOnly: true,
3026
- noEmit: true
3027
- });
3028
- const entryNames = entries.map((entry) => entry.split(`${srcDir}/`).at(-1) ?? entry);
3029
- await Promise.all(entryNames.map(async (entryName) => {
3030
- const entryTypeName = entryNameToTypeName(entryName);
3031
- await bundleDts(`${srcRoot}/${entryTypeName}`, `${outDir}/${entryTypeName}`, platform, { compilerOptions }, verbose);
3032
- }));
3033
- if (verbose) {
3034
- console.log(chalk37.cyan(`Compiling Types FINISH: ${entries.length} files to ${outDir} from ${srcDir}`));
3035
- }
3036
- return 0;
3037
- };
3038
-
3039
- // src/actions/package/compile/packageCompileTsup.ts
3040
- var compileFolder = async (srcDir, entries, buildDir, options, bundleTypes = false, verbose) => {
3041
- const outDir = options?.outDir ?? "dist";
3042
- if (verbose) {
3043
- console.log(`compileFolder [${srcDir}, ${options?.outDir}]`);
3044
- }
3045
- if (entries.length === 0) {
3046
- console.warn(chalk38.yellow(`No entries found in ${srcDir} to compile`));
3047
- return 0;
3048
- }
3049
- if (verbose) {
3050
- console.log(chalk38.gray(`buildDir [${buildDir}]`));
3051
- }
3052
- const validationResult = packageCompileTsc(options?.platform ?? "neutral", entries, srcDir, buildDir, void 0, verbose);
3053
- if (validationResult !== 0) {
3054
- console.error(chalk38.red(`Compile:Validation had ${validationResult} errors`));
3055
- return validationResult;
3056
- }
3057
- const optionsParams = tsupOptions([{
3058
- bundle: true,
3059
- cjsInterop: true,
3060
- clean: false,
3061
- dts: false,
3062
- format: ["esm"],
3063
- outDir,
3064
- silent: true,
3065
- sourcemap: true,
3066
- splitting: false,
3067
- tsconfig: "tsconfig.json",
3068
- ...options,
3069
- entry: entries.map((entry) => `${srcDir}/${entry}`)
3070
- }]);
3071
- const optionsResult = defineConfig(optionsParams);
3072
- const optionsList = (await Promise.all(
3073
- (Array.isArray(optionsResult) ? optionsResult : [optionsResult]).flatMap(async (options2) => {
3074
- const result = typeof options2 === "function" ? await options2({}) : [options2];
3075
- return Array.isArray(result) ? result : [result];
3076
- })
3077
- )).flat();
3078
- if (verbose) {
3079
- console.log(chalk38.cyan(`TSUP:build:start [${srcDir}]`));
3080
- console.log(chalk38.gray(`TSUP:build:options [${JSON.stringify(optionsList, null, 2)}]`));
3081
- }
3082
- await Promise.all(optionsList.map((options2) => build2(options2)));
3083
- if (verbose) {
3084
- console.log(chalk38.cyan(`TSUP:build:stop [${srcDir}]`));
3085
- }
3086
- if (bundleTypes) {
3087
- await packageCompileTscTypes(entries, outDir, options?.platform ?? "neutral", buildDir, verbose);
3088
- }
3089
- return 0;
3090
- };
3091
- var tsupOptions = (options = []) => {
3092
- const standardLoaders = {
3093
- ".gif": "copy",
3094
- ".html": "copy",
3095
- ".jpg": "copy",
3096
- ".json": "json",
3097
- ".png": "copy",
3098
- ".svg": "text",
3099
- ".webp": "copy"
3100
- };
3101
- const standardOptions = {
3102
- bundle: true,
3103
- format: ["esm"],
3104
- loader: standardLoaders,
3105
- outExtension: ({ format }) => format === "esm" ? { js: ".mjs" } : { js: ".cjs" },
3106
- skipNodeModulesBundle: true,
3107
- sourcemap: true,
3108
- target: "esnext"
3109
- };
3110
- return deepMergeObjects([standardOptions, ...options]);
3111
- };
3112
- var packageCompileTsup = async (config2) => {
3113
- const compile2 = config2?.compile;
3114
- const verbose = config2?.verbose ?? false;
3115
- const outDirAsBuildDir = compile2?.outDirAsBuildDir ?? true;
3116
- const bundleTypes = compile2?.bundleTypes ?? false;
3117
- if (verbose) {
3118
- console.log("Compiling with TSUP");
3119
- }
3120
- const compileForNode = compile2?.node ?? { src: {} };
3121
- const compileForBrowser = compile2?.browser ?? { src: {} };
3122
- const compileForNeutral = compile2?.neutral ?? { src: {} };
3123
- return (await Promise.all(
3124
- Object.entries(compileForNode).map(async ([srcDir, options]) => {
3125
- const optionsObject = typeof options === "object" ? options : {};
3126
- const inEsBuildOptions = typeof compile2?.node?.esbuildOptions === "object" ? compile2?.node?.esbuildOptions : {};
3127
- const entry = buildEntries(srcDir, compile2?.entryMode, options, true, verbose);
3128
- const platform = "node";
3129
- const rootOutDir = optionsObject.outDir ?? "dist";
3130
- const outDir = rootOutDir + "/" + platform;
3131
- return typeof srcDir === "string" ? await compileFolder(
3132
- srcDir,
3133
- entry,
3134
- outDirAsBuildDir ? rootOutDir : "build",
3135
- tsupOptions([
3136
- inEsBuildOptions,
3137
- compile2?.tsup?.options ?? {},
3138
- typeof options === "object" ? options : {},
3139
- { platform: "node", outDir }
3140
- ]),
3141
- bundleTypes,
3142
- verbose
3143
- ) : 0;
3144
- })
3145
- )).reduce((prev, value) => prev + value, 0) + (await Promise.all(
3146
- Object.entries(compileForBrowser).map(async ([srcDir, options]) => {
3147
- const optionsObject = typeof options === "object" ? options : {};
3148
- const inEsBuildOptions = typeof compile2?.browser?.esbuildOptions === "object" ? compile2?.browser?.esbuildOptions : {};
3149
- const entry = buildEntries(srcDir, compile2?.entryMode, options, true, verbose);
3150
- const platform = "browser";
3151
- const rootOutDir = optionsObject.outDir ?? "dist";
3152
- const outDir = rootOutDir + "/" + platform;
3153
- return typeof srcDir === "string" ? await compileFolder(
3154
- srcDir,
3155
- entry,
3156
- outDirAsBuildDir ? rootOutDir : "build",
3157
- tsupOptions([
3158
- inEsBuildOptions,
3159
- compile2?.tsup?.options ?? {},
3160
- typeof options === "object" ? options : {},
3161
- { platform: "browser", outDir }
3162
- ]),
3163
- bundleTypes,
3164
- verbose
3165
- ) : 0;
3166
- })
3167
- )).reduce((prev, value) => prev + value, 0) + (await Promise.all(
3168
- Object.entries(compileForNeutral).map(async ([srcDir, options]) => {
3169
- const optionsObject = typeof options === "object" ? options : {};
3170
- const inEsBuildOptions = typeof compile2?.neutral?.esbuildOptions === "object" ? compile2?.neutral?.esbuildOptions : {};
3171
- const entry = buildEntries(srcDir, compile2?.entryMode, options, true, verbose);
3172
- const platform = "neutral";
3173
- const rootOutDir = optionsObject.outDir ?? "dist";
3174
- const outDir = rootOutDir + "/" + platform;
3175
- return typeof srcDir === "string" ? await compileFolder(
3176
- srcDir,
3177
- entry,
3178
- outDirAsBuildDir ? rootOutDir : "build",
3179
- tsupOptions([
3180
- inEsBuildOptions,
3181
- compile2?.tsup?.options ?? {},
3182
- typeof options === "object" ? options : {},
3183
- { platform: "neutral", outDir }
3184
- ]),
3185
- bundleTypes,
3186
- verbose
3187
- ) : 0;
3188
- })
3189
- )).reduce((prev, value) => prev + value, 0) + 0;
3190
- };
3191
-
3192
- // src/actions/package/compile/compile.ts
3193
- var packageCompile = async (inConfig = {}) => {
3194
- const pkg = process.env.INIT_CWD;
3195
- console.log(chalk39.green(`Compiling ${pkg}`));
3196
- const config2 = await loadConfig(inConfig);
3197
- return await packageCompileTsup(config2);
3198
- };
3199
-
3200
- // src/actions/package/copy-assets.ts
3201
- import path11 from "path/posix";
3202
- import chalk40 from "chalk";
3203
- import cpy2 from "cpy";
3204
- var copyTargetAssets2 = async (target, name, location) => {
3205
- try {
3206
- const values = await cpy2(
3207
- ["**/*.jpg", "**/*.png", "**/*.gif", "**/*.svg", "**/*.webp", "**/*.sass", "**/*.scss", "**/*.gif", "**/*.css"],
3208
- `../dist/${target}`,
3209
- {
3210
- cwd: path11.join(location, "src"),
3211
- flat: false
3212
- }
3213
- );
3214
- if (values.length > 0) {
3215
- console.log(chalk40.green(`Copying Assets [${target.toUpperCase()}] - ${name} - ${location}`));
3216
- }
3217
- for (const value of values) {
3218
- console.log(`${value.split("/").pop()} => ./dist/${target}`);
3219
- }
3220
- return 0;
3221
- } catch (ex) {
3222
- const error = ex;
3223
- console.log(`Copy Assets Failed: ${name}: ${error.message}`);
3224
- return 1;
3225
- }
3226
- };
3227
- var packageCopyAssets = async ({ target }) => {
3228
- const pkg = process.env.INIT_CWD ?? "./";
3229
- const pkgName = process.env.npm_package_name ?? "Unknown";
3230
- switch (target) {
3231
- case "esm": {
3232
- return await copyTargetAssets2("esm", pkgName, pkg);
3233
- }
3234
- case "cjs": {
3235
- return await copyTargetAssets2("cjs", pkgName, pkg);
3236
- }
3237
- default: {
3238
- return await copyTargetAssets2("esm", pkgName, pkg) || await copyTargetAssets2("cjs", pkgName, pkg);
3239
- }
3240
- }
3241
- };
3242
-
3243
- // src/actions/package/cycle.ts
3244
- import { cruise as cruise2 } from "dependency-cruiser";
3245
- var packageCycle = async () => {
3246
- const pkg = process.env.INIT_CWD;
3247
- const pkgName = process.env.npm_package_name;
3248
- const cruiseOptions = {
3249
- ruleSet: {
3250
- forbidden: [
3251
- {
3252
- name: "no-circular",
3253
- severity: "error",
3254
- comment: "This dependency creates a circular reference",
3255
- from: {},
3256
- to: { circular: true }
3257
- }
3258
- ]
3259
- },
3260
- exclude: "node_modules|packages/.*/packages",
3261
- validate: true,
3262
- doNotFollow: { path: "node_modules|packages/.*/packages" },
3263
- tsPreCompilationDeps: false,
3264
- combinedDependencies: true,
3265
- outputType: "err"
3266
- };
3267
- const target = `${pkg}/src`;
3268
- console.log(`Checking for circular dependencies in ${target}...`);
3269
- const result = await cruise2([target], cruiseOptions);
3270
- console.log(result.output);
3271
- if (result.exitCode === 0) {
3272
- console.log(`${pkgName} \u2705 No dependency violations`);
3273
- } else {
3274
- console.error(`${pkgName} \u274C Dependency violations found`);
3275
- }
3276
- return result.exitCode;
3277
- };
3278
-
3279
- // src/actions/package/gen-docs.ts
3280
- import { existsSync as existsSync10 } from "fs";
3281
- import path12 from "path";
3282
- import chalk41 from "chalk";
3283
- import {
3284
- Application,
3285
- ArgumentsReader,
3286
- TSConfigReader,
3287
- TypeDocReader
3288
- } from "typedoc";
3289
- var ExitCodes = {
3290
- CompileError: 3,
3291
- ExceptionThrown: 6,
3292
- NoEntryPoints: 2,
3293
- Ok: 0,
3294
- OptionError: 1,
3295
- OutputError: 5,
3296
- ValidationError: 4
3297
- };
3298
- var packageGenDocs = async () => {
3299
- const pkg = process.env.INIT_CWD;
3300
- if (pkg !== void 0 && !existsSync10(path12.join(pkg, "typedoc.json"))) {
3301
- return;
3302
- }
3303
- const app = await Application.bootstrap({
3304
- entryPointStrategy: "merge",
3305
- entryPoints: [`${pkg}/src/**/*.ts`, `${pkg}/packages/*/dist/docs.json`],
3306
- excludeExternals: true,
3307
- json: `${pkg}/dist/docs.json`,
3308
- logLevel: "Error",
3309
- tsconfig: `${pkg}/tsconfig.json`
3310
- });
3311
- app.options.addReader(new ArgumentsReader(0));
3312
- app.options.addReader(new TypeDocReader());
3313
- app.options.addReader(new TSConfigReader());
3314
- app.options.addReader(new ArgumentsReader(300));
3315
- return await runTypeDoc(app);
3316
- };
3317
- var runTypeDoc = async (app) => {
3318
- const pkgName = process.env.npm_package_name;
3319
- if (app.options.getValue("version")) {
3320
- console.log(app.toString());
3321
- return ExitCodes.Ok;
3322
- }
3323
- if (app.options.getValue("showConfig")) {
3324
- console.log(app.options.getRawValues());
3325
- return ExitCodes.Ok;
3326
- }
3327
- if (app.logger.hasErrors()) {
3328
- return ExitCodes.OptionError;
3329
- }
3330
- if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
3331
- return ExitCodes.OptionError;
3332
- }
3333
- if (app.options.getValue("entryPoints").length === 0) {
3334
- app.logger.error("No entry points provided");
3335
- return ExitCodes.NoEntryPoints;
3336
- }
3337
- if (app.options.getValue("watch")) {
3338
- await app.convertAndWatch(async (project2) => {
3339
- const out = app.options.getValue("out");
3340
- if (out) {
3341
- await app.generateDocs(project2, out);
3342
- }
3343
- const json = app.options.getValue("json");
3344
- if (json) {
3345
- await app.generateJson(project2, json);
3346
- }
3347
- if (!out && !json) {
3348
- await app.generateDocs(project2, "./docs");
3349
- }
3350
- });
3351
- return ExitCodes.Ok;
3352
- }
3353
- const project = await app.convert();
3354
- if (!project) {
3355
- return ExitCodes.CompileError;
3356
- }
3357
- if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
3358
- return ExitCodes.CompileError;
3359
- }
3360
- app.validate(project);
3361
- if (app.logger.hasErrors()) {
3362
- return ExitCodes.ValidationError;
3363
- }
3364
- if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
3365
- return ExitCodes.ValidationError;
3366
- }
3367
- if (app.options.getValue("emit") !== "none") {
3368
- const out = app.options.getValue("out");
3369
- if (out) {
3370
- await app.generateDocs(project, out);
3371
- }
3372
- const json = app.options.getValue("json");
3373
- if (json) {
3374
- await app.generateJson(project, json);
3375
- }
3376
- if (!out && !json) {
3377
- await app.generateDocs(project, "./docs");
3378
- }
3379
- if (app.logger.hasErrors()) {
3380
- return ExitCodes.OutputError;
3381
- }
3382
- if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
3383
- return ExitCodes.OutputError;
3384
- }
3385
- }
3386
- console.log(chalk41.green(`${pkgName} - Ok`));
3387
- return ExitCodes.Ok;
3388
- };
3389
-
3390
- // src/actions/package/lint.ts
3391
- import { readdirSync as readdirSync6 } from "fs";
3392
- import path13 from "path";
3393
- import { cwd as cwd4 } from "process";
3394
- import { pathToFileURL } from "url";
3395
- import chalk42 from "chalk";
3396
- import { ESLint } from "eslint";
3397
- import { findUp as findUp2 } from "find-up";
3398
- import picomatch from "picomatch";
3399
- var dumpMessages = (lintResults) => {
3400
- const colors = ["white", "yellow", "red"];
3401
- const severity = ["none", "warning", "error"];
3402
- for (const lintResult of lintResults) {
3403
- if (lintResult.messages.length > 0) {
3404
- console.log(chalk42.gray(`
3405
- ${lintResult.filePath}`));
3406
- for (const message of lintResult.messages) {
3407
- console.log(
3408
- chalk42.gray(` ${message.line}:${message.column}`),
3409
- chalk42[colors[message.severity]](` ${severity[message.severity]}`),
3410
- chalk42.white(` ${message.message}`),
3411
- chalk42.gray(` ${message.ruleId}`)
3412
- );
3413
- }
3414
- }
3415
- }
3416
- };
3417
- async function getRootESLintConfig() {
3418
- const configPath = await findUp2("eslint.config.mjs");
3419
- if (configPath === void 0) {
3420
- throw new Error("eslint.config.mjs not found in the monorepo");
3421
- }
3422
- return pathToFileURL(configPath);
3423
- }
3424
- function getFiles(dir, ignoreFolders) {
3425
- const currentDirectory = cwd4();
3426
- const subDirectory = dir.split(currentDirectory)[1]?.split("/")[1];
3427
- if (ignoreFolders.includes(subDirectory)) return [];
3428
- return readdirSync6(dir, { withFileTypes: true }).flatMap((dirent) => {
3429
- const res = path13.resolve(dir, dirent.name);
3430
- const relativePath = subDirectory === void 0 ? dirent.name : `${subDirectory}/${dirent.name}`;
3431
- const ignoreMatchers = ignoreFolders.map((pattern) => picomatch(pattern));
3432
- if (ignoreMatchers.some((isMatch) => isMatch(relativePath))) return [];
3433
- return dirent.isDirectory() ? getFiles(res, ignoreFolders) : [res];
3434
- });
3435
- }
3436
- var packageLint = async (fix2 = false, verbose = false, cache = true) => {
3437
- const pkg = process.env.INIT_CWD;
3438
- const configPath = await getRootESLintConfig();
3439
- const { default: eslintConfig } = await import(configPath.href);
3440
- const start = Date.now();
3441
- const ignoreFolders = ["node_modules", "dist", "packages", ".git", "build", ".yarn", ".vscode", ".github"];
3442
- const engine = new ESLint({
3443
- baseConfig: [...eslintConfig],
3444
- fix: fix2,
3445
- warnIgnored: false,
3446
- cache
3447
- });
3448
- const files = getFiles(cwd4(), ignoreFolders);
3449
- console.log(chalk42.green(`Linting ${pkg} [files = ${files.length}]`));
3450
- if (verbose) {
3451
- for (const file of files) {
3452
- console.log(chalk42.gray(` ${file}`));
3453
- }
3454
- }
3455
- const lintResults = await engine.lintFiles(files);
3456
- dumpMessages(lintResults);
3457
- if (fix2) {
3458
- await ESLint.outputFixes(lintResults);
3459
- }
3460
- const filesCountColor = files.length < 100 ? "green" : files.length < 1e3 ? "yellow" : "red";
3461
- const lintTime = Date.now() - start;
3462
- const lintTimeColor = lintTime < 1e3 ? "green" : lintTime < 3e3 ? "yellow" : "red";
3463
- console.log(chalk42.white(`Linted ${chalk42[filesCountColor](files.length)} files in ${chalk42[lintTimeColor](lintTime)}ms`));
3464
- return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
3465
- };
3466
-
3467
- // src/actions/package/publint.ts
3468
- import { promises as fs10 } from "fs";
3469
- import chalk43 from "chalk";
3470
- import sortPackageJson from "sort-package-json";
3471
- var customPubLint = (pkg) => {
3472
- let errorCount = 0;
3473
- let warningCount = 0;
3474
- if (pkg.files === void 0) {
3475
- console.warn(chalk43.yellow('Publint [custom]: "files" field is missing'));
3476
- warningCount++;
3477
- }
3478
- if (pkg.main !== void 0) {
3479
- console.warn(chalk43.yellow('Publint [custom]: "main" field is deprecated, use "exports" instead'));
3480
- warningCount++;
3481
- }
3482
- if (pkg.sideEffects !== false) {
3483
- console.warn(chalk43.yellow('Publint [custom]: "sideEffects" field should be set to false'));
3484
- warningCount++;
3485
- }
3486
- if (pkg.resolutions !== void 0) {
3487
- console.warn(chalk43.yellow('Publint [custom]: "resolutions" in use'));
3488
- console.warn(chalk43.gray(JSON.stringify(pkg.resolutions, null, 2)));
3489
- warningCount++;
3490
- }
3491
- return [errorCount, warningCount];
3492
- };
3493
- var packagePublint = async ({ strict = true, verbose = false } = {}) => {
3494
- const pkgDir = process.env.INIT_CWD;
3495
- const sortedPkg = sortPackageJson(await fs10.readFile(`${pkgDir}/package.json`, "utf8"));
3496
- await fs10.writeFile(`${pkgDir}/package.json`, sortedPkg);
3497
- const pkg = JSON.parse(await fs10.readFile(`${pkgDir}/package.json`, "utf8"));
3498
- console.log(chalk43.green(`Publint: ${pkg.name}`));
3499
- console.log(chalk43.gray(pkgDir));
3500
- const { publint: publint2 } = await import("publint");
3501
- const { messages } = await publint2({
3502
- level: "suggestion",
3503
- pkgDir,
3504
- strict
3505
- });
3506
- const { formatMessage } = await import("publint/utils");
3507
- for (const message of messages) {
3508
- switch (message.type) {
3509
- case "error": {
3510
- console.error(chalk43.red(`[${message.code}] ${formatMessage(message, pkg)}`));
3511
- break;
3512
- }
3513
- case "warning": {
3514
- console.warn(chalk43.yellow(`[${message.code}] ${formatMessage(message, pkg)}`));
3515
- break;
3516
- }
3517
- default: {
3518
- console.log(chalk43.white(`[${message.code}] ${formatMessage(message, pkg)}`));
3519
- break;
3520
- }
3521
- }
3522
- }
3523
- const [errorCount, warningCount] = customPubLint(pkg);
3524
- if (verbose) {
3525
- console.log(chalk43.gray(`Publint [Finish]: ${pkgDir} [${messages.length + errorCount + warningCount} messages]`));
3526
- }
3527
- return messages.filter((message) => message.type === "error").length + errorCount;
3528
- };
3529
-
3530
- // src/actions/package/recompile.ts
3531
- var packageRecompile = async () => {
3532
- return await packageClean() || await packageCompile();
3533
- };
3534
-
3535
- // src/actions/package-lint.ts
3536
- import { readFileSync as readFileSync17, writeFileSync as writeFileSync7 } from "fs";
3537
- import PATH11 from "path";
3538
- import chalk44 from "chalk";
3539
- import picomatch2 from "picomatch";
3540
- function emptyResult() {
3541
- return {
3542
- errors: [],
3543
- fixable: [],
3544
- warnings: []
3545
- };
3546
- }
3547
- function readRootPackageJson(cwd5) {
3548
- const raw = readFileSync17(PATH11.resolve(cwd5, "package.json"), "utf8");
3549
- return JSON.parse(raw);
3550
- }
3551
- function writeRootPackageJson(cwd5, pkg) {
3552
- const path14 = PATH11.resolve(cwd5, "package.json");
3553
- writeFileSync7(path14, `${JSON.stringify(pkg, null, 2)}
3554
- `, "utf8");
3555
- }
3556
- function isMonorepo(pkg) {
3557
- const workspaces = pkg.workspaces;
3558
- return Array.isArray(workspaces) && workspaces.length > 0;
3559
- }
3560
- function checkPackagesFolder(workspaces) {
3561
- const result = emptyResult();
3562
- for (const { location, name } of workspaces) {
3563
- if (location === ".") continue;
3564
- if (!location.startsWith("packages/") && !location.startsWith("packages\\")) {
3565
- result.errors.push(`${name} (${location}) is not inside a packages/ folder`);
3566
- }
3567
- }
3568
- return result;
3569
- }
3570
- function checkRootPrivate(pkg) {
3571
- const result = emptyResult();
3572
- if (!pkg.private) {
3573
- result.fixable.push("Root package.json must be private to prevent accidental publishing");
3574
- }
3575
- return result;
3576
- }
3577
- function fixRootPrivate(cwd5, pkg) {
3578
- pkg.private = true;
3579
- writeRootPackageJson(cwd5, pkg);
3580
- console.log(chalk44.green(' \u2714 Fixed: set "private": true in root package.json'));
3581
- }
3582
- function checkNoPublishConfigOnPrivate(pkg) {
3583
- const result = emptyResult();
3584
- if (pkg.private && pkg.publishConfig) {
3585
- result.fixable.push("Root package.json has publishConfig but is private \u2014 publishConfig is unnecessary");
3586
- }
3587
- return result;
3588
- }
3589
- function fixNoPublishConfigOnPrivate(cwd5, pkg) {
3590
- delete pkg.publishConfig;
3591
- writeRootPackageJson(cwd5, pkg);
3592
- console.log(chalk44.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
3593
- }
3594
- function checkDiscoverable(pkg, workspaces) {
3595
- const result = emptyResult();
3596
- const globs = pkg.workspaces;
3597
- const matchers = globs.map((glob3) => picomatch2(glob3));
3598
- const isMatch = (location) => matchers.some((m) => m(location));
3599
- for (const { location, name } of workspaces) {
3600
- if (location === ".") continue;
3601
- if (!isMatch(location)) {
3602
- result.errors.push(`${name} (${location}) is not matched by any workspace glob in package.json`);
3603
- }
3604
- }
3605
- return result;
3606
- }
3607
- function logResults(label, result, fix2) {
3608
- let errors = 0;
3609
- let fixed = 0;
3610
- for (const error of result.errors) {
3611
- console.log(chalk44.red(` \u2717 ${error}`));
3612
- errors++;
3613
- }
3614
- for (const fixable of result.fixable) {
3615
- if (fix2) {
3616
- fixed++;
3617
- } else {
3618
- console.log(chalk44.red(` \u2717 ${fixable} (fixable)`));
3619
- errors++;
3620
- }
3621
- }
3622
- for (const warning of result.warnings) {
3623
- console.log(chalk44.yellow(` \u26A0 ${warning}`));
3624
- }
3625
- if (errors === 0 && fixed === 0 && result.warnings.length === 0) {
3626
- console.log(chalk44.green(` \u2713 ${label}`));
3627
- }
3628
- return { errors, fixed };
3629
- }
3630
- function runChecks(entries, cwd5, pkg, fix2) {
3631
- let totalErrors = 0;
3632
- let totalFixed = 0;
3633
- for (const entry of entries) {
3634
- const result = entry.check();
3635
- const log = logResults(entry.label, result, fix2);
3636
- if (fix2 && entry.fix && result.fixable.length > 0) {
3637
- entry.fix(cwd5, pkg);
3638
- }
3639
- totalErrors += log.errors;
3640
- totalFixed += log.fixed;
3641
- }
3642
- return { errors: totalErrors, fixed: totalFixed };
3643
- }
3644
- function logSummary(errors, fixed) {
3645
- if (fixed > 0) {
3646
- console.log(chalk44.green(`
3647
- Fixed ${fixed} issue(s)`));
3648
- }
3649
- if (errors > 0) {
3650
- console.log(chalk44.red(`
3651
- ${errors} error(s) found`));
3652
- } else if (fixed === 0) {
3653
- console.log(chalk44.green("\n All checks passed"));
3654
- }
3655
- }
3656
- function packageLintMonorepo(fix2 = false) {
3657
- const cwd5 = INIT_CWD() ?? process.cwd();
3658
- let pkg;
3659
- try {
3660
- pkg = readRootPackageJson(cwd5);
3661
- } catch {
3662
- console.error(chalk44.red("Could not read package.json"));
3663
- return 1;
3664
- }
3665
- if (!isMonorepo(pkg)) {
3666
- console.log(chalk44.gray("Not a monorepo \u2014 skipping package-lint checks"));
3667
- return 0;
3668
- }
3669
- console.log(chalk44.green("Package Lint"));
3670
- const workspaces = yarnWorkspaces();
3671
- const checks = [
3672
- {
3673
- check: () => checkRootPrivate(pkg),
3674
- fix: fixRootPrivate,
3675
- label: "Root package is private"
3676
- },
3677
- {
3678
- check: () => checkNoPublishConfigOnPrivate(pkg),
3679
- fix: fixNoPublishConfigOnPrivate,
3680
- label: "No publishConfig on private root"
3681
- },
3682
- { check: () => checkPackagesFolder(workspaces), label: "All packages are in packages/ folder" },
3683
- { check: () => checkDiscoverable(pkg, workspaces), label: "All packages are discoverable from workspace globs" }
3684
- ];
3685
- const { errors, fixed } = runChecks(checks, cwd5, pkg, fix2);
3686
- logSummary(errors, fixed);
3687
- return errors > 0 ? 1 : 0;
3688
- }
3689
-
3690
- // src/actions/publint.ts
3691
- var publint = async ({ verbose, pkg }) => {
3692
- return pkg === void 0 ? publintAll({ verbose }) : await publintPackage({ pkg, verbose });
3693
- };
3694
- var publintPackage = ({ pkg }) => {
3695
- return runStepsAsync(`Publint [${pkg}]`, [["yarn", ["workspace", pkg, "run", "package-publint"]]]);
3696
- };
3697
- var publintAll = ({ verbose }) => {
3698
- const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
3699
- return runSteps("Publint", [["yarn", ["workspaces", "foreach", "-pA", ...verboseOptions, "run", "package-publint"]]]);
3700
- };
3701
-
3702
- // src/actions/publish.ts
3703
- var publish = () => {
3704
- return runSteps("Publish", [["npm", ["publish", "--workspaces"]]]);
3705
- };
3706
-
3707
- // src/actions/readme-gen.ts
3708
- async function readmeGen({
3709
- pkg,
3710
- templatePath,
3711
- typedoc,
3712
- verbose
3713
- }) {
3714
- const config2 = await loadConfig();
3715
- return await generateReadmeFiles({
3716
- logoLinkUrl: config2.readme?.logoLinkUrl,
3717
- logoUrl: config2.readme?.logoUrl,
3718
- pkg,
3719
- templatePath,
3720
- typedoc,
3721
- verbose
3722
- });
3723
- }
3724
-
3725
- // src/actions/readme-init.ts
3726
- async function readmeInit({ templatePath }) {
3727
- const config2 = await loadConfig();
3728
- const template = applyLogoConfig(DEFAULT_README_TEMPLATE, config2.readme?.logoUrl, config2.readme?.logoLinkUrl);
3729
- const resolvedTemplatePath = resolveTemplatePath(templatePath);
3730
- await scaffoldTemplate(resolvedTemplatePath, template);
3731
- return 0;
3732
- }
3733
-
3734
- // src/actions/rebuild.ts
3735
- var rebuild = ({ target }) => {
3736
- return runSteps("Rebuild", [
3737
- ["yarn", "xy clean"],
3738
- ["yarn", target ? `xy build -t ${target}` : "xy build"]
3739
- ]);
3740
- };
3741
-
3742
- // src/actions/recompile.ts
3743
- import chalk45 from "chalk";
3744
- var recompile = async ({
3745
- verbose,
3746
- target,
3747
- pkg,
3748
- incremental
3749
- }) => {
3750
- return pkg ? await recompilePackage({
3751
- pkg,
3752
- target,
3753
- verbose
3754
- }) : await recompileAll({
3755
- incremental,
3756
- target,
3757
- verbose
3758
- });
3759
- };
3760
- var recompilePackage = ({ target, pkg }) => {
3761
- const targetOptions = target ? ["-t", target] : [];
3762
- return runStepsAsync(
3763
- `Recompile [${pkg}]`,
3764
- [["yarn", ["workspace", pkg, "run", "package-recompile", ...targetOptions]]]
3765
- );
3766
- };
3767
- var recompileAll = async ({
3768
- jobs,
3769
- verbose,
3770
- target,
3771
- incremental
3772
- }) => {
3773
- const start = Date.now();
3774
- const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
3775
- const targetOptions = target ? ["-t", target] : [];
3776
- const incrementalOptions = incremental ? ["--since", "-Apt", "--topological-dev"] : ["--parallel", "-Apt", "--topological-dev"];
3777
- const jobsOptions = jobs ? ["-j", `${jobs}`] : [];
3778
- if (jobs) {
3779
- console.log(chalk45.blue(`Jobs set to [${jobs}]`));
3780
- }
3781
- const result = await runStepsAsync(`Recompile${incremental ? "-Incremental" : ""} [All]`, [
3782
- [
3783
- "yarn",
3784
- [
3785
- "workspaces",
3786
- "foreach",
3787
- ...incrementalOptions,
3788
- ...jobsOptions,
3789
- ...verboseOptions,
3790
- "run",
3791
- "package-clean",
3792
- ...targetOptions
3793
- ]
3794
- ],
3795
- [
3796
- "yarn",
3797
- [
3798
- "workspaces",
3799
- "foreach",
3800
- ...incrementalOptions,
3801
- ...jobsOptions,
3802
- ...verboseOptions,
3803
- "run",
3804
- "package-compile",
3805
- ...targetOptions
3806
- ]
3807
- ]
3808
- ]);
3809
- console.log(
3810
- `${chalk45.gray("Recompiled in")} [${chalk45.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk45.gray("seconds")}`
3811
- );
3812
- return result;
3813
- };
3814
-
3815
- // src/actions/reinstall.ts
3816
- import {
3817
- closeSync,
3818
- openSync,
3819
- rmSync as rmSync3
3820
- } from "fs";
3821
- var reinstall = () => {
3822
- console.log("Reinstall [Clear Lock File]");
3823
- closeSync(openSync("./yarn.lock", "w"));
3824
- console.log("Reinstall [Clear Node Modules]");
3825
- const workspaces = yarnWorkspaces();
3826
- const result = workspaces.map(({ location, name }) => {
3827
- const dist = `${location}/node_modules`;
3828
- try {
3829
- rmSync3(dist, { force: true, recursive: true });
3830
- return 0;
3831
- } catch (ex) {
3832
- const error = ex;
3833
- console.error(`Reinstall [Clear Node Modules] Failed [${name}, ${error.message}]`);
3834
- return 1;
3835
- }
3836
- }).reduce((prev, result2) => prev || result2, 0);
3837
- return result || runSteps("Reinstall", [["yarn", "install --network-timeout 10000"]]);
3838
- };
3839
-
3840
- // src/actions/relint.ts
3841
- import chalk46 from "chalk";
3842
- var relintPackage = ({
3843
- pkg,
3844
- fix: fix2,
3845
- verbose
3846
- }) => {
3847
- console.log(chalk46.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
3848
- const start = Date.now();
3849
- const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
3850
- ["yarn", [
3851
- "workspace",
3852
- pkg,
3853
- "run",
3854
- fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint"
3855
- ]]
3856
- ]);
3857
- console.log(chalk46.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk46.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk46.gray("seconds")}`));
3858
- return result;
3859
- };
3860
- var relint = ({
3861
- pkg,
3862
- verbose,
3863
- incremental,
3864
- fix: fix2
3865
- } = {}) => {
3866
- return pkg === void 0 ? relintAllPackages({
3867
- verbose,
3868
- incremental,
3869
- fix: fix2
3870
- }) : relintPackage({
3871
- pkg,
3872
- fix: fix2,
3873
- verbose
3874
- });
3875
- };
3876
- var relintAllPackages = ({ fix: fix2 = false } = {}) => {
3877
- console.log(chalk46.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
3878
- const start = Date.now();
3879
- const fixOptions = fix2 ? ["--fix"] : [];
3880
- const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
3881
- ["yarn", ["eslint", ...fixOptions]]
3882
- ]);
3883
- console.log(chalk46.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk46.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk46.gray("seconds")}`));
3884
- return result;
3885
- };
3886
-
3887
- // src/actions/retest.ts
3888
- function isWorkspace(target) {
3889
- return yarnWorkspaces().some((ws) => ws.name === target);
3890
- }
3891
- var retest = ({ target } = {}) => {
3892
- if (target && isWorkspace(target)) {
3893
- return runSteps(`Re-Test [${target}]`, [
3894
- ["yarn", ["workspace", target, "run", "vitest", "--clearCache"]],
3895
- ["yarn", ["workspace", target, "run", "vitest", "."]]
3896
- ]);
3897
- }
3898
- const path14 = target ?? ".";
3899
- return runSteps("Re-Test", [
3900
- ["yarn", ["vitest", "--clearCache"]],
3901
- ["yarn", ["vitest", path14]]
3902
- ]);
3903
- };
3904
-
3905
- // src/actions/sonar.ts
3906
- var sonar = () => {
3907
- return runSteps("Sonar", [["yarn", ["eslint", "-c", "sonar.eslintrc", "."]]]);
3908
- };
3909
-
3910
- // src/actions/statics.ts
3911
- import chalk47 from "chalk";
3912
- var DefaultDependencies = ["axios", "@xylabs/pixel", "react", "graphql", "react-router", "@mui/material", "@mui/system"];
3913
- var statics = () => {
3914
- console.log(chalk47.green("Check Required Static Dependencies"));
3915
- const statics2 = parsedPackageJSON()?.xy?.deps?.statics;
3916
- return detectDuplicateDependencies(statics2, DefaultDependencies);
3917
- };
3918
-
3919
- // src/actions/test.ts
3920
- function isWorkspace2(target) {
3921
- return yarnWorkspaces().some((ws) => ws.name === target);
3922
- }
3923
- var test = ({ target } = {}) => {
3924
- if (target && isWorkspace2(target)) {
3925
- return runSteps(`Test [${target}]`, [["yarn", ["workspace", target, "run", "vitest", "."]]]);
3926
- }
3927
- const path14 = target ?? ".";
3928
- return runSteps("Test", [["yarn", ["vitest", path14]]]);
3929
- };
3930
-
3931
- // src/actions/up.ts
3932
- var up = () => {
3933
- return runSteps("Up", [["yarn", "outdated"]]);
3934
- };
3935
-
3936
- // src/actions/updo.ts
3937
- var updo = () => {
3938
- return runSteps("Updo", [
3939
- ["yarn", "install"],
3940
- ["yarn", "upgrade-interactive"],
3941
- ["yarn", "dedupe"]
3942
- ]);
3943
- };
3944
-
3945
- // src/actions/upplug.ts
3946
- var updateYarnPlugins = () => {
3947
- return runSteps("Update Yarn Plugins", [
3948
- ["yarn", ["plugin", "import", "https://mskelton.dev/yarn-outdated/v3"]],
3949
- ["yarn", ["plugin", "import", "version"]],
3950
- ["yarn", ["plugin", "import", "interactive-tools"]],
3951
- ["yarn", ["plugin", "import", "workspace-tools"]]
3952
- ]);
3953
- };
3954
-
3955
- // src/actions/upyarn.ts
3956
- var updateYarnVersion = () => {
3957
- return runSteps("Update Yarn Version", [["yarn", ["set", "version", "latest"]]]);
3958
- };
3959
-
3960
- // src/actions/yarn3only.ts
3961
- var yarn3Only = () => {
3962
- const [valid, version] = isYarnVersionOrGreater(3);
3963
- if (!valid) {
3964
- processEx(`Invalid Yarn version [${version}]`);
3965
- }
3966
- return 0;
3967
- };
3968
-
3969
- // src/loadPackageConfig.ts
3970
- import { readFile as readFile2 } from "fs/promises";
3971
- var loadPackageConfig = async () => {
3972
- const pkg = process.env.INIT_CWD;
3973
- const pkgConfig = await readFile2(`${pkg}/package.json`, { encoding: "utf8" });
3974
- return JSON.parse(pkgConfig);
3975
- };
3976
-
3977
- // src/xy/build/buildCommand.ts
3978
- var buildCommand = {
3979
- command: "build [package]",
3980
- describe: "Build - Compile & Lint",
3981
- builder: (yargs2) => {
3982
- return yargs2.positional("package", { describe: "Specific package to build" });
3983
- },
3984
- handler: async (argv) => {
3985
- if (argv.verbose) {
3986
- console.log(`Building: ${argv.package ?? "all"}`);
3987
- }
3988
- process.exitCode = await build({
3989
- incremental: !!argv.incremental,
3990
- jobs: argv.jobs,
3991
- pkg: argv.package,
3992
- target: argv.target,
3993
- verbose: !!argv.verbose
3994
- });
3995
- }
3996
- };
3997
-
3998
- // src/xy/build/compileCommand.ts
3999
- var compileCommand = {
4000
- command: "compile [package]",
4001
- describe: "Compile with Typescript & Copy Images",
4002
- builder: (yargs2) => {
4003
- return yargs2.positional("package", { describe: "Specific package to compile" });
4004
- },
4005
- handler: (argv) => {
4006
- if (argv.verbose) {
4007
- console.log(`Compiling: ${argv.package ?? "all"}`);
4008
- }
4009
- process.exitCode = compile({
4010
- incremental: !!argv.incremental,
4011
- jobs: argv.jobs,
4012
- pkg: argv.package,
4013
- target: argv.target,
4014
- verbose: !!argv.verbose
4015
- });
4016
- }
4017
- };
4018
-
4019
- // src/xy/build/compileOnlyCommand.ts
4020
- var compileOnlyCommand = {
4021
- command: "compile-only [package]",
4022
- describe: "Compile with Typescript & Copy Images (No Publint)",
4023
- builder: (yargs2) => {
4024
- return yargs2.positional("package", { describe: "Specific package to compile" });
4025
- },
4026
- handler: (argv) => {
4027
- if (argv.verbose) {
4028
- console.log(`Compiling: ${argv.package ?? "all"}`);
4029
- }
4030
- process.exitCode = compile({
4031
- incremental: !!argv.incremental,
4032
- jobs: argv.jobs,
4033
- pkg: argv.package,
4034
- publint: false,
4035
- target: argv.target,
4036
- verbose: !!argv.verbose
4037
- });
4038
- }
4039
- };
4040
-
4041
- // src/xy/build/copyAssetsCommand.ts
4042
- var copyAssetsCommand = {
4043
- command: "copy-assets [package]",
4044
- describe: "Copy Assets - Copy the assets from src to dist",
4045
- builder: (yargs2) => {
4046
- return yargs2.positional("package", { describe: "Specific package to copy assets" });
4047
- },
4048
- handler: async (argv) => {
4049
- if (argv.verbose) console.log(`Copying Assets: ${argv.package ?? "all"}`);
4050
- process.exitCode = await copyAssets({ target: argv.target });
4051
- }
4052
- };
4053
-
4054
- // src/xy/build/rebuildCommand.ts
4055
- var rebuildCommand = {
4056
- command: "rebuild [package]",
4057
- describe: "Rebuild - Clean, Compile & Lint",
4058
- builder: (yargs2) => {
4059
- return yargs2.positional("package", { describe: "Specific package to rebuild" });
4060
- },
4061
- handler: (argv) => {
4062
- if (argv.verbose) console.log(`Rebuilding: ${argv.package ?? "all"}`);
4063
- process.exitCode = rebuild({ target: argv.target });
4064
- }
4065
- };
4066
-
4067
- // src/xy/build/recompileCommand.ts
4068
- var recompileCommand = {
4069
- command: "recompile [package]",
4070
- describe: "Re-compile with Typescript & Copy Images",
4071
- builder: (yargs2) => {
4072
- return yargs2.positional("package", { describe: "Specific package to re-compile" });
4073
- },
4074
- handler: async (argv) => {
4075
- if (argv.verbose) {
4076
- console.log(`Re-compiling: ${argv.package ?? "all"}`);
4077
- }
4078
- process.exitCode = await recompile({
4079
- incremental: !!argv.incremental,
4080
- jobs: argv.jobs,
4081
- pkg: argv.package,
4082
- target: argv.target,
4083
- verbose: !!argv.verbose
4084
- });
4085
- }
4086
- };
4087
-
4088
- // src/xy/build/index.ts
4089
- var xyBuildCommands = (args) => {
4090
- return args.command(buildCommand).command(compileCommand).command(compileOnlyCommand).command(recompileCommand).command(rebuildCommand).command(copyAssetsCommand);
4091
- };
4092
-
4093
- // src/xy/common/claude/cleanCommand.ts
4094
- var cleanCommand = {
4095
- command: "clean",
4096
- describe: "Remove all Claude configuration files from the repo",
4097
- handler: (argv) => {
4098
- if (argv.verbose) console.log("Claude Clean");
4099
- process.exitCode = claudeClean();
4100
- }
4101
- };
4102
-
4103
- // src/xy/common/claude/commandsCommand.ts
4104
- var commandsCommand = {
4105
- command: "commands",
4106
- describe: "Sync XY Labs standard Claude slash commands to .claude/commands/",
4107
- handler: (argv) => {
4108
- if (argv.verbose) console.log("Claude Commands");
4109
- process.exitCode = claudeCommands();
4110
- }
4111
- };
4112
-
4113
- // src/xy/common/claude/initCommand.ts
4114
- var initCommand = {
4115
- builder: (yargs2) => {
4116
- return yargs2.option("force", {
4117
- alias: "f",
4118
- default: false,
4119
- description: "Overwrite existing CLAUDE.md",
4120
- type: "boolean"
4121
- });
4122
- },
4123
- command: "init",
4124
- describe: "Initialize all Claude configuration (commands, rules, settings)",
4125
- handler: async (argv) => {
4126
- if (argv.verbose) console.log("Claude Init");
4127
- const commandsResult = claudeCommands();
4128
- const rulesResult = claudeRules({ force: argv.force });
4129
- const settingsResult = await claudeSettings();
4130
- process.exitCode = commandsResult || rulesResult || settingsResult;
4131
- }
4132
- };
4133
-
4134
- // src/xy/common/claude/rulesCommand.ts
4135
- var rulesCommand = {
4136
- builder: (yargs2) => {
4137
- return yargs2.option("force", {
4138
- alias: "f",
4139
- default: false,
4140
- description: "Overwrite existing CLAUDE.md",
4141
- type: "boolean"
4142
- });
4143
- },
4144
- command: "rules",
4145
- describe: "Sync XY Labs standard Claude rules to .claude/rules/",
4146
- handler: (argv) => {
4147
- if (argv.verbose) console.log("Claude Rules");
4148
- process.exitCode = claudeRules({ force: argv.force });
4149
- }
4150
- };
4151
-
4152
- // src/xy/common/claude/settingsCommand.ts
4153
- var settingsCommand = {
4154
- command: "settings",
4155
- describe: "Initialize .claude/settings.local.json with XY Labs defaults",
4156
- handler: async (argv) => {
4157
- if (argv.verbose) console.log("Claude Settings");
4158
- process.exitCode = await claudeSettings();
4159
- }
4160
- };
4161
-
4162
- // src/xy/common/claude/skillsCommand.ts
4163
- var skillsCommand = {
4164
- builder: (yargs2) => yargs2,
4165
- command: "skills",
4166
- describe: "Sync XY Labs standard Claude skills to .claude/skills/",
4167
- handler: (argv) => {
4168
- if (argv.verbose) console.log("Claude Skills");
4169
- process.exitCode = claudeSkills();
4170
- }
4171
- };
4172
-
4173
- // src/xy/common/claude/index.ts
4174
- var claudeCommand = {
4175
- builder: (yargs2) => {
4176
- return yargs2.command(cleanCommand).command(commandsCommand).command(initCommand).command(rulesCommand).command(settingsCommand).command(skillsCommand).demandCommand(1, "Please specify a claude subcommand");
4177
- },
4178
- command: "claude",
4179
- describe: "Claude - Claude Code configuration utilities",
4180
- handler: () => {
4181
- }
4182
- };
4183
-
4184
- // src/xy/common/cleanDocsCommand.ts
4185
- var cleanDocsCommand = {
4186
- command: "clean-docs",
4187
- describe: "CleanDocs - Clean TypeDocs",
4188
- handler: (argv) => {
4189
- if (argv.verbose) console.log("Cleaning TypeDocs: all");
4190
- process.exitCode = cleanDocs();
92
+ return [
93
+ ["yarn", `workspaces foreach --all version ${type} --deferred`]
94
+ ];
4191
95
  }
4192
96
  };
4193
97
 
4194
- // src/xy/param.ts
4195
- var packagePositionalParam = (yargs2) => {
4196
- return yargs2.positional("package", { describe: "Specific package to target", type: "string" });
98
+ // src/actions/deploy.ts
99
+ import { readFileSync } from "fs";
100
+ import { runSteps } from "@xylabs/ts-scripts-common";
101
+ var privatePackageExcludeList = () => {
102
+ const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
103
+ workspace,
104
+ JSON.parse(readFileSync(`${workspace.location}/package.json`, { encoding: "utf8" }))
105
+ ]);
106
+ const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
107
+ const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
108
+ return excludeList;
4197
109
  };
4198
-
4199
- // src/xy/common/deadCommand.ts
4200
- var deadCommand = {
4201
- builder: (yargs2) => {
4202
- return packagePositionalParam(yargs2);
4203
- },
4204
- command: "dead [package]",
4205
- describe: "Dead - Check for dead code",
4206
- handler: (argv) => {
4207
- if (argv.verbose) console.log("Dead");
4208
- process.exitCode = dead();
110
+ var deploy = () => {
111
+ const excludeList = privatePackageExcludeList();
112
+ if (excludeList.length > 0) {
113
+ console.log("Excluding private packages from deployment:", excludeList);
4209
114
  }
115
+ return runSteps("Deploy [Patch]", [
116
+ ["yarn", "workspaces foreach --all version patch --deferred"],
117
+ ["yarn", "xy clean"],
118
+ ["yarn", "xy build"],
119
+ ["yarn", "version apply --all"]
120
+ ]);
4210
121
  };
4211
122
 
4212
- // src/xy/common/genDocsCommand.ts
4213
- var genDocsCommand = {
4214
- builder: (yargs2) => {
4215
- return packagePositionalParam(yargs2);
4216
- },
4217
- command: "gen-docs [package]",
4218
- describe: "GenDocs - Generate TypeDocs",
4219
- handler: (argv) => {
4220
- if (argv.verbose) console.log(`Generating TypeDocs: ${argv.package ?? "all"}`);
4221
- process.exitCode = genDocs({ incremental: !!argv.incremental, pkg: argv.package });
4222
- }
123
+ // src/actions/deploy-major.ts
124
+ import { readFileSync as readFileSync2 } from "fs";
125
+ import { runSteps as runSteps2 } from "@xylabs/ts-scripts-common";
126
+ var privatePackageExcludeList2 = () => {
127
+ const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
128
+ workspace,
129
+ JSON.parse(readFileSync2(`${workspace.location}/package.json`, { encoding: "utf8" }))
130
+ ]);
131
+ const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
132
+ const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
133
+ return excludeList;
4223
134
  };
4224
-
4225
- // src/xy/common/gitignoreCommand.ts
4226
- var gitignoreCommand = {
4227
- command: "gitignore",
4228
- describe: "GitIgnore - Generate root .gitignore and remove package .gitignore files",
4229
- handler: (argv) => {
4230
- if (argv.verbose) console.log("GitIgnore");
4231
- process.exitCode = gitignore();
135
+ var deployMajor = () => {
136
+ const excludeList = privatePackageExcludeList2();
137
+ if (excludeList.length > 0) {
138
+ console.log("Excluding private packages from deployment:", excludeList);
4232
139
  }
140
+ return runSteps2("Deploy [Major]", [
141
+ ["yarn", "workspaces foreach --all version major --deferred"],
142
+ ["yarn", "xy clean"],
143
+ ["yarn", "xy build"],
144
+ ["yarn", "version apply --all"]
145
+ ]);
4233
146
  };
4234
147
 
4235
- // src/xy/common/gitlintCommand.ts
4236
- var gitlintCommand = {
4237
- command: "gitlint [package]",
4238
- describe: "Gitlint - Lint your git config",
4239
- handler: (argv) => {
4240
- if (argv.verbose) console.log("Gitlint");
4241
- process.exitCode = argv.fix ? gitlintFix() : gitlint();
4242
- }
148
+ // src/actions/deploy-minor.ts
149
+ import { readFileSync as readFileSync3 } from "fs";
150
+ import { runSteps as runSteps3 } from "@xylabs/ts-scripts-common";
151
+ var privatePackageExcludeList3 = () => {
152
+ const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
153
+ workspace,
154
+ JSON.parse(readFileSync3(`${workspace.location}/package.json`, { encoding: "utf8" }))
155
+ ]);
156
+ const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
157
+ const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
158
+ return excludeList;
4243
159
  };
4244
-
4245
- // src/xy/common/licenseCommand.ts
4246
- var licenseCommand = {
4247
- builder: (yargs2) => {
4248
- return packagePositionalParam(yargs2);
4249
- },
4250
- command: "license [package]",
4251
- describe: "License - Check licenses of dependencies",
4252
- handler: async (argv) => {
4253
- if (argv.verbose) console.log(`License: ${argv.package ?? "all"}`);
4254
- process.exitCode = await license();
160
+ var deployMinor = () => {
161
+ const excludeList = privatePackageExcludeList3();
162
+ if (excludeList.length > 0) {
163
+ console.log("Excluding private packages from deployment:", excludeList);
4255
164
  }
165
+ return runSteps3("Deploy [Minor]", [
166
+ ["yarn", "workspaces foreach --all version minor --deferred"],
167
+ ["yarn", "xy clean"],
168
+ ["yarn", "xy build"],
169
+ ["yarn", "version apply --all"]
170
+ ]);
4256
171
  };
4257
172
 
4258
- // src/xy/common/npmignoreGenCommand.ts
4259
- var npmignoreGenCommand = {
4260
- command: "npmignore-gen",
4261
- describe: "NpmIgnore Gen - Generate .npmignore files",
4262
- handler: (argv) => {
4263
- if (argv.verbose) console.log("NpmIgnore Gen");
4264
- process.exitCode = npmignoreGen();
4265
- }
173
+ // src/actions/deploy-next.ts
174
+ import { readFileSync as readFileSync4 } from "fs";
175
+ import { runSteps as runSteps4 } from "@xylabs/ts-scripts-common";
176
+ var privatePackageExcludeList4 = () => {
177
+ const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
178
+ workspace,
179
+ JSON.parse(readFileSync4(`${workspace.location}/package.json`, { encoding: "utf8" }))
180
+ ]);
181
+ const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
182
+ const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
183
+ return excludeList;
4266
184
  };
4267
-
4268
- // src/xy/common/readme/genCommand.ts
4269
- var genCommand = {
4270
- builder: (yargs2) => {
4271
- return packagePositionalParam(yargs2).option("template", {
4272
- alias: "t",
4273
- description: "Path to README.template.md",
4274
- type: "string"
4275
- }).option("typedoc", {
4276
- default: false,
4277
- description: "Generate TypeDoc reference sections",
4278
- type: "boolean"
4279
- });
4280
- },
4281
- aliases: ["$0"],
4282
- command: "gen [package]",
4283
- describe: "Generate README.md files from template",
4284
- handler: async (argv) => {
4285
- if (argv.verbose) console.log("Readme Gen");
4286
- process.exitCode = await readmeGen({
4287
- pkg: argv.package,
4288
- templatePath: argv.template,
4289
- typedoc: argv.typedoc,
4290
- verbose: !!argv.verbose
4291
- });
185
+ var deployNext = () => {
186
+ const excludeList = privatePackageExcludeList4();
187
+ if (excludeList.length > 0) {
188
+ console.log("Excluding private packages from deployment:", excludeList);
4292
189
  }
190
+ return runSteps4("Deploy [Next]", [
191
+ ["yarn", "workspaces foreach --all version minor --deferred"],
192
+ ["yarn", "xy clean"],
193
+ ["yarn", "xy build"],
194
+ ["yarn", "version apply --all --prerelease"]
195
+ ]);
4293
196
  };
4294
197
 
4295
- // src/xy/common/readme/initCommand.ts
4296
- var initCommand2 = {
4297
- builder: (yargs2) => {
4298
- return yargs2.option("template", {
4299
- alias: "t",
4300
- description: "Path to README.template.md",
4301
- type: "string"
4302
- });
4303
- },
4304
- command: "init",
4305
- describe: "Initialize README template and logo files",
4306
- handler: async (argv) => {
4307
- if (argv.verbose) console.log("Readme Init");
4308
- process.exitCode = await readmeInit({
4309
- templatePath: argv.template,
4310
- verbose: !!argv.verbose
4311
- });
4312
- }
198
+ // src/actions/publish.ts
199
+ import { runSteps as runSteps5 } from "@xylabs/ts-scripts-common";
200
+ var publish = () => {
201
+ return runSteps5("Publish", [["npm", ["publish", "--workspaces"]]]);
4313
202
  };
4314
203
 
4315
- // src/xy/common/readme/index.ts
4316
- var readmeCommand = {
4317
- builder: (yargs2) => {
4318
- return yargs2.command(genCommand).command(initCommand2);
4319
- },
4320
- command: "readme",
4321
- describe: "Readme - README file utilities",
4322
- handler: () => {
4323
- }
204
+ // src/actions/reinstall.ts
205
+ import {
206
+ closeSync,
207
+ openSync,
208
+ rmSync
209
+ } from "fs";
210
+ import { runSteps as runSteps6 } from "@xylabs/ts-scripts-common";
211
+ var reinstall = () => {
212
+ console.log("Reinstall [Clear Lock File]");
213
+ closeSync(openSync("./yarn.lock", "w"));
214
+ console.log("Reinstall [Clear Node Modules]");
215
+ const workspaces = yarnWorkspaces();
216
+ const result = workspaces.map(({ location, name }) => {
217
+ const dist = `${location}/node_modules`;
218
+ try {
219
+ rmSync(dist, { force: true, recursive: true });
220
+ return 0;
221
+ } catch (ex) {
222
+ const error = ex;
223
+ console.error(`Reinstall [Clear Node Modules] Failed [${name}, ${error.message}]`);
224
+ return 1;
225
+ }
226
+ }).reduce((prev, result2) => prev || result2, 0);
227
+ return result || runSteps6("Reinstall", [["yarn", "install --network-timeout 10000"]]);
4324
228
  };
4325
229
 
4326
- // src/xy/common/retestCommand.ts
4327
- var retestCommand = {
4328
- command: "retest [target]",
4329
- describe: "Re-Test - Run Vitest Tests with cleaned cache",
4330
- builder: (yargs2) => {
4331
- return yargs2.positional("target", { describe: "Package name or file/folder path to test" });
4332
- },
4333
- handler: (argv) => {
4334
- if (argv.verbose) console.log(`Re-Testing: ${argv.target ?? "all"}`);
4335
- process.exitCode = retest({ target: argv.target });
4336
- }
230
+ // src/actions/up.ts
231
+ import { runSteps as runSteps7 } from "@xylabs/ts-scripts-common";
232
+ var up = () => {
233
+ return runSteps7("Up", [["yarn", "outdated"]]);
4337
234
  };
4338
235
 
4339
- // src/xy/common/testCommand.ts
4340
- var testCommand = {
4341
- command: "test [target]",
4342
- describe: "Test - Run Vitest Tests",
4343
- builder: (yargs2) => {
4344
- return yargs2.positional("target", { describe: "Package name or file/folder path to test" });
4345
- },
4346
- handler: (argv) => {
4347
- if (argv.verbose) console.log(`Testing: ${argv.target ?? "all"}`);
4348
- process.exitCode = test({ target: argv.target });
4349
- }
236
+ // src/actions/updo.ts
237
+ import { runSteps as runSteps8 } from "@xylabs/ts-scripts-common";
238
+ var updo = () => {
239
+ return runSteps8("Updo", [
240
+ ["yarn", "install"],
241
+ ["yarn", "upgrade-interactive"],
242
+ ["yarn", "dedupe"]
243
+ ]);
4350
244
  };
4351
245
 
4352
- // src/xy/common/upplugCommand.ts
4353
- var upplugCommand = {
4354
- command: "upplug",
4355
- describe: "UpPlug - Update Yarn Plugins",
4356
- handler: (argv) => {
4357
- if (argv.verbose) console.log("UpPlug");
4358
- process.exitCode = updateYarnPlugins();
4359
- }
246
+ // src/actions/upplug.ts
247
+ import { runSteps as runSteps9 } from "@xylabs/ts-scripts-common";
248
+ var updateYarnPlugins = () => {
249
+ return runSteps9("Update Yarn Plugins", [
250
+ ["yarn", ["plugin", "import", "https://mskelton.dev/yarn-outdated/v3"]],
251
+ ["yarn", ["plugin", "import", "version"]],
252
+ ["yarn", ["plugin", "import", "interactive-tools"]],
253
+ ["yarn", ["plugin", "import", "workspace-tools"]]
254
+ ]);
4360
255
  };
4361
256
 
4362
- // src/xy/common/upyarnCommand.ts
4363
- var upyarnCommand = {
4364
- command: "upyarn",
4365
- describe: "UpYarn - Update Yarn Version",
4366
- handler: (argv) => {
4367
- if (argv.verbose) console.log("UpYarn");
4368
- process.exitCode = updateYarnVersion();
4369
- }
257
+ // src/actions/upyarn.ts
258
+ import { runSteps as runSteps10 } from "@xylabs/ts-scripts-common";
259
+ var updateYarnVersion = () => {
260
+ return runSteps10("Update Yarn Version", [["yarn", ["set", "version", "latest"]]]);
4370
261
  };
4371
262
 
4372
- // src/xy/common/yarn3OnlyCommand.ts
4373
- var yarn3OnlyCommand = {
4374
- command: "yarn3only",
4375
- describe: "Yarn3Only - Check if using Yarn v3",
4376
- handler: (argv) => {
4377
- if (argv.verbose) console.log("Yarn 3 Check");
4378
- process.exitCode = yarn3Only();
263
+ // src/actions/yarn3only.ts
264
+ import { processEx } from "@xylabs/ts-scripts-common";
265
+ var yarn3Only = () => {
266
+ const [valid, version] = isYarnVersionOrGreater(3);
267
+ if (!valid) {
268
+ processEx(`Invalid Yarn version [${version}]`);
4379
269
  }
270
+ return 0;
4380
271
  };
4381
272
 
4382
- // src/xy/common/index.ts
4383
- var xyCommonCommands = (args) => {
4384
- return args.command(claudeCommand).command(licenseCommand).command(deadCommand).command(genDocsCommand).command(cleanDocsCommand).command(gitlintCommand).command(gitignoreCommand).command(npmignoreGenCommand).command(readmeCommand).command(retestCommand).command(testCommand).command(upplugCommand).command(upyarnCommand).command(yarn3OnlyCommand);
4385
- };
273
+ // src/actions/index.ts
274
+ import {
275
+ clean,
276
+ dupdeps,
277
+ statics
278
+ } from "@xylabs/ts-scripts-common";
4386
279
 
4387
280
  // src/xy/deploy/deployCommand.ts
4388
281
  var deployCommand = {
@@ -4440,11 +333,11 @@ var xyDeployCommands = (args) => {
4440
333
  };
4441
334
 
4442
335
  // src/xy/install/cleanCommand.ts
4443
- var cleanCommand2 = {
336
+ var cleanCommand = {
4444
337
  command: "clean [package]",
4445
338
  describe: "Clean",
4446
- builder: (yargs2) => {
4447
- return yargs2.positional("package", { describe: "Specific package to clean" });
339
+ builder: (yargs) => {
340
+ return yargs.positional("package", { describe: "Specific package to clean" });
4448
341
  },
4449
342
  handler: async (argv) => {
4450
343
  if (argv.verbose) {
@@ -4509,403 +402,75 @@ var updoCommand = {
4509
402
 
4510
403
  // src/xy/install/index.ts
4511
404
  var xyInstallCommands = (args) => {
4512
- return args.command(cleanCommand2).command(reinstallCommand).command(upCommand).command(updoCommand).command(staticsCommand).command(dupdepsCommand);
4513
- };
4514
-
4515
- // src/xy/lint/cycleCommand.ts
4516
- import chalk48 from "chalk";
4517
- var cycleCommand = {
4518
- command: "cycle [package]",
4519
- describe: "Cycle - Check for dependency cycles",
4520
- builder: (yargs2) => {
4521
- return packagePositionalParam(yargs2);
4522
- },
4523
- handler: async (argv) => {
4524
- const start = Date.now();
4525
- if (argv.verbose) console.log("Cycle");
4526
- process.exitCode = await cycle({ pkg: argv.package });
4527
- console.log(chalk48.blue(`Finished in ${Date.now() - start}ms`));
4528
- }
4529
- };
4530
-
4531
- // src/xy/lint/deplintCommand.ts
4532
- import chalk49 from "chalk";
4533
- var deplintCommand = {
4534
- command: "deplint [package]",
4535
- describe: "Deplint - Run Deplint",
4536
- builder: (yargs2) => {
4537
- return packagePositionalParam(yargs2).option("deps", {
4538
- alias: "d",
4539
- default: false,
4540
- description: "Check dependencies",
4541
- type: "boolean"
4542
- }).option("devDeps", {
4543
- alias: "v",
4544
- default: false,
4545
- description: "Check devDependencies",
4546
- type: "boolean"
4547
- }).option("peerDeps", {
4548
- alias: "p",
4549
- default: false,
4550
- description: "Check peerDependencies",
4551
- type: "boolean"
4552
- }).option("exclude", {
4553
- alias: "e",
4554
- description: "Package names to exclude from unused checks (comma-separated or repeated)",
4555
- type: "array"
4556
- });
4557
- },
4558
- handler: async (argv) => {
4559
- if (argv.verbose) console.log("Deplint");
4560
- const start = Date.now();
4561
- const cliExclude = argv.exclude?.flatMap((v) => String(v).split(",")).map((v) => v.trim()).filter(Boolean);
4562
- process.exitCode = await deplint({
4563
- cliExclude,
4564
- pkg: argv.package,
4565
- deps: !!argv.deps,
4566
- devDeps: !!argv.devDeps,
4567
- peerDeps: !!argv.peerDeps,
4568
- verbose: !!argv.verbose
4569
- });
4570
- console.log(chalk49.blue(`Finished in ${Date.now() - start}ms`));
4571
- }
4572
- };
4573
-
4574
- // src/xy/lint/fixCommand.ts
4575
- import chalk50 from "chalk";
4576
- var fixCommand = {
4577
- command: "fix [package]",
4578
- describe: "Fix - Run Eslint w/fix",
4579
- builder: (yargs2) => {
4580
- return packagePositionalParam(yargs2);
4581
- },
4582
- handler: (argv) => {
4583
- const start = Date.now();
4584
- if (argv.verbose) console.log("Fix");
4585
- process.exitCode = fix();
4586
- console.log(chalk50.blue(`Finished in ${Date.now() - start}ms`));
4587
- }
4588
- };
4589
-
4590
- // src/xy/lint/knipCommand.ts
4591
- import chalk51 from "chalk";
4592
- var knipCommand = {
4593
- command: "knip",
4594
- describe: "Knip - Run Knip",
4595
- builder: (yargs2) => {
4596
- return packagePositionalParam(yargs2);
4597
- },
4598
- handler: (argv) => {
4599
- if (argv.verbose) console.log("Knip");
4600
- const start = Date.now();
4601
- process.exitCode = knip();
4602
- console.log(chalk51.blue(`Knip finished in ${Date.now() - start}ms`));
4603
- }
4604
- };
4605
-
4606
- // src/xy/lint/lintCommand.ts
4607
- import chalk52 from "chalk";
4608
- var lintCommand = {
4609
- command: "lint [package]",
4610
- describe: "Lint - Run Eslint",
4611
- builder: (yargs2) => {
4612
- return packagePositionalParam(yargs2).option("fix", {
4613
- alias: "f",
4614
- default: false,
4615
- description: "Fix fixable issues",
4616
- type: "boolean"
4617
- }).option("cache", {
4618
- alias: "c",
4619
- default: false,
4620
- description: "Use caching for performance",
4621
- type: "boolean"
4622
- });
4623
- },
4624
- handler: (argv) => {
4625
- if (argv.verbose) console.log("Lint");
4626
- const start = Date.now();
4627
- process.exitCode = argv.fix ? fix({
4628
- pkg: argv.package,
4629
- cache: argv.cache,
4630
- verbose: !!argv.verbose
4631
- }) : lint({
4632
- pkg: argv.package,
4633
- cache: argv.cache,
4634
- verbose: !!argv.verbose
4635
- });
4636
- console.log(chalk52.blue(`Finished in ${Date.now() - start}ms`));
4637
- }
405
+ return args.command(cleanCommand).command(reinstallCommand).command(upCommand).command(updoCommand).command(staticsCommand).command(dupdepsCommand);
4638
406
  };
4639
407
 
4640
- // src/xy/lint/lintlintCommand.ts
4641
- var lintlintCommand = {
4642
- command: "lintlint",
4643
- describe: "Lint Lint - Check for redundant or overridden ESLint rules vs shared config",
4644
- builder: (yargs2) => {
4645
- return yargs2.option("fix", {
4646
- default: false,
4647
- description: "Remove redundant rules from local config",
4648
- type: "boolean"
4649
- });
4650
- },
4651
- handler: async (argv) => {
4652
- if (argv.verbose) console.log("Lint Lint");
4653
- process.exitCode = await lintlint({
4654
- fix: argv.fix,
4655
- verbose: !!argv.verbose
4656
- });
4657
- }
4658
- };
408
+ // src/xy/xy.ts
409
+ import { xyBase } from "@xylabs/ts-scripts-common";
4659
410
 
4660
- // src/xy/lint/packageLintCommand.ts
4661
- var packageLintCommand = {
4662
- builder: (yargs2) => {
4663
- return yargs2.option("fix", {
4664
- default: false,
4665
- description: "Auto-fix fixable issues",
4666
- type: "boolean"
4667
- });
4668
- },
4669
- command: "package-lint",
4670
- describe: "Package Lint - Check monorepo package structure",
411
+ // src/xy/common/upplugCommand.ts
412
+ var upplugCommand = {
413
+ command: "upplug",
414
+ describe: "UpPlug - Update Yarn Plugins",
4671
415
  handler: (argv) => {
4672
- if (argv.verbose) console.log("Package Lint");
4673
- process.exitCode = packageLintMonorepo(!!argv.fix);
4674
- }
4675
- };
4676
-
4677
- // src/xy/lint/publintCommand.ts
4678
- import chalk53 from "chalk";
4679
- var publintCommand = {
4680
- command: "publint [package]",
4681
- describe: "Publint - Run Publint",
4682
- builder: (yargs2) => {
4683
- return packagePositionalParam(yargs2);
4684
- },
4685
- handler: async (argv) => {
4686
- if (argv.verbose) console.log("Publint");
4687
- const start = Date.now();
4688
- process.exitCode = await publint({ pkg: argv.package, verbose: !!argv.verbose });
4689
- console.log(chalk53.blue(`Finished in ${Date.now() - start}ms`));
416
+ if (argv.verbose) console.log("UpPlug");
417
+ process.exitCode = updateYarnPlugins();
4690
418
  }
4691
419
  };
4692
420
 
4693
- // src/xy/lint/relintCommand.ts
4694
- import chalk54 from "chalk";
4695
- var relintCommand = {
4696
- command: "relint [package]",
4697
- describe: "Relint - Clean & Lint",
4698
- builder: (yargs2) => {
4699
- return packagePositionalParam(yargs2);
4700
- },
421
+ // src/xy/common/upyarnCommand.ts
422
+ var upyarnCommand = {
423
+ command: "upyarn",
424
+ describe: "UpYarn - Update Yarn Version",
4701
425
  handler: (argv) => {
4702
- if (argv.verbose) console.log("Relinting");
4703
- const start = Date.now();
4704
- process.exitCode = relint();
4705
- console.log(chalk54.blue(`Finished in ${Date.now() - start}ms`));
426
+ if (argv.verbose) console.log("UpYarn");
427
+ process.exitCode = updateYarnVersion();
4706
428
  }
4707
429
  };
4708
430
 
4709
- // src/xy/lint/sonarCommand.ts
4710
- import chalk55 from "chalk";
4711
- var sonarCommand = {
4712
- command: "sonar",
4713
- describe: "Sonar - Run Sonar Check",
4714
- builder: (yargs2) => {
4715
- return packagePositionalParam(yargs2);
4716
- },
431
+ // src/xy/common/yarn3OnlyCommand.ts
432
+ var yarn3OnlyCommand = {
433
+ command: "yarn3only",
434
+ describe: "Yarn3Only - Check if using Yarn v3",
4717
435
  handler: (argv) => {
4718
- const start = Date.now();
4719
- if (argv.verbose) console.log("Sonar Check");
4720
- process.exitCode = sonar();
4721
- console.log(chalk55.blue(`Finished in ${Date.now() - start}ms`));
436
+ if (argv.verbose) console.log("Yarn 3 Check");
437
+ process.exitCode = yarn3Only();
4722
438
  }
4723
439
  };
4724
440
 
4725
- // src/xy/lint/index.ts
4726
- var xyLintCommands = (args) => {
4727
- return args.command(cycleCommand).command(lintCommand).command(lintlintCommand).command(deplintCommand).command(fixCommand).command(relintCommand).command(publintCommand).command(knipCommand).command(packageLintCommand).command(sonarCommand);
4728
- };
4729
-
4730
- // src/xy/xy.ts
4731
- import chalk56 from "chalk";
4732
-
4733
- // src/xy/xyParseOptions.ts
4734
- import yargs from "yargs";
4735
- import { hideBin } from "yargs/helpers";
4736
- var xyParseOptions = () => {
4737
- return yargs(hideBin(process.argv)).scriptName("yarn xy").middleware((argv) => {
4738
- const commandName = argv._[0];
4739
- if (commandName && argv._.length <= 1) {
4740
- const result = tryRunLocalScript(commandName);
4741
- if (result !== void 0) {
4742
- process.exit(result);
4743
- }
4744
- }
4745
- }, true).option("jobs", {
4746
- alias: "j",
4747
- default: void 0,
4748
- description: "Max parallel jobs",
4749
- type: "number"
4750
- }).option("verbose", {
4751
- alias: "v",
4752
- default: false,
4753
- description: "Run with verbose logging",
4754
- type: "boolean"
4755
- }).option("incremental", {
4756
- alias: "i",
4757
- default: false,
4758
- description: "Attempt to perform the action only on changed packages",
4759
- type: "boolean"
4760
- }).option("profile", {
4761
- alias: "p",
4762
- default: false,
4763
- description: "Profile action",
4764
- type: "boolean"
4765
- });
441
+ // src/xy/yarnCommands.ts
442
+ var xyYarnCommands = (args) => {
443
+ return args.command(upplugCommand).command(upyarnCommand).command(yarn3OnlyCommand);
4766
444
  };
4767
445
 
4768
446
  // src/xy/xy.ts
4769
447
  var xy = async () => {
4770
- const options = xyParseOptions();
4771
- return await xyBuildCommands(xyCommonCommands(xyInstallCommands(xyDeployCommands(xyLintCommands(options))))).demandCommand(1).command("*", "", () => {
4772
- console.error(chalk56.yellow(`Command not found [${chalk56.magenta(process.argv[2])}]`));
4773
- console.log(chalk56.gray("Try 'yarn xy --help' for list of commands"));
4774
- }).version().help().argv;
448
+ return await xyBase((args) => xyYarnCommands(xyInstallCommands(xyDeployCommands(args))));
4775
449
  };
450
+
451
+ // src/index.ts
452
+ export * from "@xylabs/ts-scripts-common";
453
+ registerPackageManager(new YarnPackageManager());
4776
454
  export {
4777
- CROSS_PLATFORM_NEWLINE,
4778
- DEFAULT_README_BODY,
4779
- DEFAULT_README_TEMPLATE,
4780
- DuplicateDetector,
4781
- INIT_CWD,
4782
- LEGACY_COMMANDS_PREFIX,
4783
- WINDOWS_NEWLINE_REGEX,
4784
- XYLABS_COMMANDS_PREFIX,
4785
- XYLABS_RULES_PREFIX,
4786
- XYLABS_SKILLS_PREFIX,
4787
- applyLogoConfig,
4788
- build,
4789
- checkResult,
4790
- claudeClean,
4791
- claudeCommandTemplates,
4792
- claudeCommands,
4793
- claudeMdLocalTemplate,
4794
- claudeMdProjectTemplate,
4795
- claudeMdRuleTemplates,
4796
- claudeRules,
4797
- claudeSettings,
4798
- claudeSkillTemplates,
4799
- claudeSkills,
455
+ YarnPackageManager,
4800
456
  clean,
4801
- cleanAll,
4802
- cleanDocs,
4803
- cleanPackage,
4804
- compile,
4805
- compileAll,
4806
- compilePackage,
4807
- copyAssets,
4808
- createBuildConfig,
4809
- cycle,
4810
- cycleAll,
4811
- cyclePackage,
4812
- dead,
4813
- defaultBuildConfig,
4814
- defaultReadFileSyncOptions,
4815
- deleteGlob,
4816
- deplint,
4817
457
  deploy,
4818
458
  deployMajor,
4819
459
  deployMinor,
4820
460
  deployNext,
4821
- detectDuplicateDependencies,
4822
461
  dupdeps,
4823
- empty,
4824
- fix,
4825
- genDocs,
4826
- genDocsAll,
4827
- genDocsPackage,
4828
- generateIgnoreFiles,
4829
- generateReadmeFiles,
4830
- gitignore,
4831
- gitignoreGen,
4832
- gitignoreTemplate,
4833
- gitlint,
4834
- gitlintFix,
4835
462
  isYarnVersionOrGreater,
4836
- knip,
4837
- license,
4838
- lint,
4839
- lintAllPackages,
4840
- lintPackage,
4841
- lintlint,
4842
- loadConfig,
4843
- loadPackageConfig,
4844
- multiLineToJSONArray,
4845
- notEmpty,
4846
- npmignoreGen,
4847
- packageClean,
4848
- packageCleanOutputs,
4849
- packageCleanTypescript,
4850
- packageCompile,
4851
- packageCompileTsc,
4852
- packageCompileTsup,
4853
- packageCopyAssets,
4854
- packageCycle,
4855
- packageGenDocs,
4856
- packageLint,
4857
- packageLintMonorepo,
4858
- packagePublint,
4859
- packageRecompile,
4860
- parsedPackageJSON,
4861
- processEx,
4862
- publint,
4863
- publintAll,
4864
- publintPackage,
4865
463
  publish,
4866
- readLines,
4867
- readNonEmptyLines,
4868
- readmeGen,
4869
- readmeInit,
4870
- rebuild,
4871
- recompile,
4872
- recompileAll,
4873
- recompilePackage,
4874
464
  reinstall,
4875
- relint,
4876
- relintAllPackages,
4877
- relintPackage,
4878
- resolveTemplatePath,
4879
- retest,
4880
- runStepAsync,
4881
- runSteps,
4882
- runStepsAsync,
4883
- runXy,
4884
- runXyWithWarning,
4885
- safeExit,
4886
- safeExitAsync,
4887
- scaffoldTemplate,
4888
- sonar,
4889
465
  statics,
4890
- test,
4891
- tryReadFileSync,
4892
- tryRunLocalScript,
4893
- tsupOptions,
4894
- union,
4895
466
  up,
4896
467
  updateYarnPlugins,
4897
468
  updateYarnVersion,
4898
469
  updo,
4899
- withErrnoException,
4900
- withError,
4901
- writeLines,
4902
470
  xy,
4903
- xyBuildCommands,
4904
- xyCommonCommands,
4905
471
  xyDeployCommands,
4906
472
  xyInstallCommands,
4907
- xyLintCommands,
4908
- xyParseOptions,
473
+ xyYarnCommands,
4909
474
  yarn3Only,
4910
475
  yarnWorkspace,
4911
476
  yarnWorkspaces