@xylabs/ts-scripts-yarn3 7.0.2 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/dist/actions/build.mjs +39 -87
  2. package/dist/actions/build.mjs.map +1 -1
  3. package/dist/actions/clean-docs.mjs +8 -22
  4. package/dist/actions/clean-docs.mjs.map +1 -1
  5. package/dist/actions/clean-eslint.mjs +5 -11
  6. package/dist/actions/clean-eslint.mjs.map +1 -1
  7. package/dist/actions/clean-jest.mjs +16 -29
  8. package/dist/actions/clean-jest.mjs.map +1 -1
  9. package/dist/actions/clean.mjs +32 -63
  10. package/dist/actions/clean.mjs.map +1 -1
  11. package/dist/actions/compile.mjs +50 -76
  12. package/dist/actions/compile.mjs.map +1 -1
  13. package/dist/actions/copy-assets.mjs +23 -38
  14. package/dist/actions/copy-assets.mjs.map +1 -1
  15. package/dist/actions/cycle.mjs +28 -57
  16. package/dist/actions/cycle.mjs.map +1 -1
  17. package/dist/actions/dead.mjs +16 -31
  18. package/dist/actions/dead.mjs.map +1 -1
  19. package/dist/actions/deplint/checkPackage/checkPackage.mjs +48 -71
  20. package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +1 -1
  21. package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs +5 -5
  22. package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs.map +1 -1
  23. package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs +9 -5
  24. package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs.map +1 -1
  25. package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs +5 -5
  26. package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs.map +1 -1
  27. package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs +0 -4
  28. package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs.map +1 -1
  29. package/dist/actions/deplint/checkPackage/index.mjs +48 -71
  30. package/dist/actions/deplint/checkPackage/index.mjs.map +1 -1
  31. package/dist/actions/deplint/deplint.mjs +61 -86
  32. package/dist/actions/deplint/deplint.mjs.map +1 -1
  33. package/dist/actions/deplint/findFiles.mjs +4 -20
  34. package/dist/actions/deplint/findFiles.mjs.map +1 -1
  35. package/dist/actions/deplint/findFilesByGlob.mjs +1 -8
  36. package/dist/actions/deplint/findFilesByGlob.mjs.map +1 -1
  37. package/dist/actions/deplint/getBasePackageName.mjs +0 -4
  38. package/dist/actions/deplint/getBasePackageName.mjs.map +1 -1
  39. package/dist/actions/deplint/getDependenciesFromPackageJson.mjs +0 -4
  40. package/dist/actions/deplint/getDependenciesFromPackageJson.mjs.map +1 -1
  41. package/dist/actions/deplint/getExternalImportsFromFiles.mjs +12 -24
  42. package/dist/actions/deplint/getExternalImportsFromFiles.mjs.map +1 -1
  43. package/dist/actions/deplint/getImportsFromFile.mjs +9 -16
  44. package/dist/actions/deplint/getImportsFromFile.mjs.map +1 -1
  45. package/dist/actions/deplint/index.mjs +61 -86
  46. package/dist/actions/deplint/index.mjs.map +1 -1
  47. package/dist/actions/deploy-major.mjs +26 -57
  48. package/dist/actions/deploy-major.mjs.map +1 -1
  49. package/dist/actions/deploy-minor.mjs +26 -57
  50. package/dist/actions/deploy-minor.mjs.map +1 -1
  51. package/dist/actions/deploy-next.mjs +26 -57
  52. package/dist/actions/deploy-next.mjs.map +1 -1
  53. package/dist/actions/deploy.mjs +26 -57
  54. package/dist/actions/deploy.mjs.map +1 -1
  55. package/dist/actions/dupdeps.mjs +26 -37
  56. package/dist/actions/dupdeps.mjs.map +1 -1
  57. package/dist/actions/fix.mjs +36 -54
  58. package/dist/actions/fix.mjs.map +1 -1
  59. package/dist/actions/gen-docs.mjs +25 -65
  60. package/dist/actions/gen-docs.mjs.map +1 -1
  61. package/dist/actions/gitignore-gen.mjs +28 -44
  62. package/dist/actions/gitignore-gen.mjs.map +1 -1
  63. package/dist/actions/gitlint-fix.mjs +5 -14
  64. package/dist/actions/gitlint-fix.mjs.map +1 -1
  65. package/dist/actions/gitlint.mjs +4 -7
  66. package/dist/actions/gitlint.mjs.map +1 -1
  67. package/dist/actions/index.mjs +705 -1251
  68. package/dist/actions/index.mjs.map +1 -1
  69. package/dist/actions/knip.mjs +16 -31
  70. package/dist/actions/knip.mjs.map +1 -1
  71. package/dist/actions/license.mjs +37 -51
  72. package/dist/actions/license.mjs.map +1 -1
  73. package/dist/actions/lint.mjs +33 -48
  74. package/dist/actions/lint.mjs.map +1 -1
  75. package/dist/actions/npmignore-gen.mjs +28 -44
  76. package/dist/actions/npmignore-gen.mjs.map +1 -1
  77. package/dist/actions/package/clean-outputs.mjs +6 -16
  78. package/dist/actions/package/clean-outputs.mjs.map +1 -1
  79. package/dist/actions/package/clean-typescript.mjs +6 -16
  80. package/dist/actions/package/clean-typescript.mjs.map +1 -1
  81. package/dist/actions/package/clean.mjs +12 -29
  82. package/dist/actions/package/clean.mjs.map +1 -1
  83. package/dist/actions/package/compile/buildEntries.mjs +19 -34
  84. package/dist/actions/package/compile/buildEntries.mjs.map +1 -1
  85. package/dist/actions/package/compile/compile.mjs +165 -195
  86. package/dist/actions/package/compile/compile.mjs.map +1 -1
  87. package/dist/actions/package/compile/copyTypeFiles.mjs +20 -23
  88. package/dist/actions/package/compile/copyTypeFiles.mjs.map +1 -1
  89. package/dist/actions/package/compile/deepMerge.mjs +0 -5
  90. package/dist/actions/package/compile/deepMerge.mjs.map +1 -1
  91. package/dist/actions/package/compile/getCompilerOptions.mjs +2 -5
  92. package/dist/actions/package/compile/getCompilerOptions.mjs.map +1 -1
  93. package/dist/actions/package/compile/index.mjs +165 -195
  94. package/dist/actions/package/compile/index.mjs.map +1 -1
  95. package/dist/actions/package/compile/inputs.mjs +15 -25
  96. package/dist/actions/package/compile/inputs.mjs.map +1 -1
  97. package/dist/actions/package/compile/packageCompileTsc.mjs +25 -17
  98. package/dist/actions/package/compile/packageCompileTsc.mjs.map +1 -1
  99. package/dist/actions/package/compile/packageCompileTscTypes.mjs +19 -36
  100. package/dist/actions/package/compile/packageCompileTscTypes.mjs.map +1 -1
  101. package/dist/actions/package/compile/packageCompileTsup.mjs +160 -185
  102. package/dist/actions/package/compile/packageCompileTsup.mjs.map +1 -1
  103. package/dist/actions/package/copy-assets.mjs +12 -21
  104. package/dist/actions/package/copy-assets.mjs.map +1 -1
  105. package/dist/actions/package/cycle.mjs +5 -14
  106. package/dist/actions/package/cycle.mjs.map +1 -1
  107. package/dist/actions/package/gen-docs.mjs +11 -12
  108. package/dist/actions/package/gen-docs.mjs.map +1 -1
  109. package/dist/actions/package/index.mjs +236 -308
  110. package/dist/actions/package/index.mjs.map +1 -1
  111. package/dist/actions/package/lint.mjs +16 -39
  112. package/dist/actions/package/lint.mjs.map +1 -1
  113. package/dist/actions/package/publint.mjs +13 -14
  114. package/dist/actions/package/publint.mjs.map +1 -1
  115. package/dist/actions/package/recompile.mjs +179 -223
  116. package/dist/actions/package/recompile.mjs.map +1 -1
  117. package/dist/actions/publint.mjs +37 -71
  118. package/dist/actions/publint.mjs.map +1 -1
  119. package/dist/actions/rebuild.mjs +17 -29
  120. package/dist/actions/rebuild.mjs.map +1 -1
  121. package/dist/actions/recompile.mjs +50 -67
  122. package/dist/actions/recompile.mjs.map +1 -1
  123. package/dist/actions/reinstall.mjs +25 -43
  124. package/dist/actions/reinstall.mjs.map +1 -1
  125. package/dist/actions/relint.mjs +40 -63
  126. package/dist/actions/relint.mjs.map +1 -1
  127. package/dist/actions/retest.mjs +17 -35
  128. package/dist/actions/retest.mjs.map +1 -1
  129. package/dist/actions/sonar.mjs +16 -32
  130. package/dist/actions/sonar.mjs.map +1 -1
  131. package/dist/actions/statics.mjs +27 -46
  132. package/dist/actions/statics.mjs.map +1 -1
  133. package/dist/actions/test.mjs +16 -30
  134. package/dist/actions/test.mjs.map +1 -1
  135. package/dist/actions/up.mjs +16 -27
  136. package/dist/actions/up.mjs.map +1 -1
  137. package/dist/actions/updo.mjs +18 -33
  138. package/dist/actions/updo.mjs.map +1 -1
  139. package/dist/actions/upplug.mjs +19 -53
  140. package/dist/actions/upplug.mjs.map +1 -1
  141. package/dist/actions/upyarn.mjs +16 -31
  142. package/dist/actions/upyarn.mjs.map +1 -1
  143. package/dist/actions/yarn3only.mjs +12 -23
  144. package/dist/actions/yarn3only.mjs.map +1 -1
  145. package/dist/bin/package/build-only.mjs +165 -194
  146. package/dist/bin/package/build-only.mjs.map +1 -1
  147. package/dist/bin/package/build.mjs +166 -197
  148. package/dist/bin/package/build.mjs.map +1 -1
  149. package/dist/bin/package/clean-outputs.mjs +6 -15
  150. package/dist/bin/package/clean-outputs.mjs.map +1 -1
  151. package/dist/bin/package/clean-typescript.mjs +6 -15
  152. package/dist/bin/package/clean-typescript.mjs.map +1 -1
  153. package/dist/bin/package/clean.mjs +12 -28
  154. package/dist/bin/package/clean.mjs.map +1 -1
  155. package/dist/bin/package/compile-only.mjs +165 -194
  156. package/dist/bin/package/compile-only.mjs.map +1 -1
  157. package/dist/bin/package/compile-tsup.mjs +160 -184
  158. package/dist/bin/package/compile-tsup.mjs.map +1 -1
  159. package/dist/bin/package/compile.mjs +165 -194
  160. package/dist/bin/package/compile.mjs.map +1 -1
  161. package/dist/bin/package/copy-assets-cjs.mjs +13 -23
  162. package/dist/bin/package/copy-assets-cjs.mjs.map +1 -1
  163. package/dist/bin/package/copy-assets-esm.mjs +13 -23
  164. package/dist/bin/package/copy-assets-esm.mjs.map +1 -1
  165. package/dist/bin/package/cycle.mjs +5 -13
  166. package/dist/bin/package/cycle.mjs.map +1 -1
  167. package/dist/bin/package/fix.mjs +16 -38
  168. package/dist/bin/package/fix.mjs.map +1 -1
  169. package/dist/bin/package/gen-docs.mjs +11 -11
  170. package/dist/bin/package/gen-docs.mjs.map +1 -1
  171. package/dist/bin/package/lint.mjs +16 -38
  172. package/dist/bin/package/lint.mjs.map +1 -1
  173. package/dist/bin/package/publint.mjs +13 -13
  174. package/dist/bin/package/publint.mjs.map +1 -1
  175. package/dist/bin/package/recompile.mjs +179 -222
  176. package/dist/bin/package/recompile.mjs.map +1 -1
  177. package/dist/bin/package/relint.mjs +16 -38
  178. package/dist/bin/package/relint.mjs.map +1 -1
  179. package/dist/bin/xy.mjs +932 -1266
  180. package/dist/bin/xy.mjs.map +1 -1
  181. package/dist/index.mjs +1191 -1612
  182. package/dist/index.mjs.map +1 -1
  183. package/dist/lib/checkResult.mjs +2 -5
  184. package/dist/lib/checkResult.mjs.map +1 -1
  185. package/dist/lib/createBuildConfig.mjs +9 -24
  186. package/dist/lib/createBuildConfig.mjs.map +1 -1
  187. package/dist/lib/defaultBuildConfig.mjs +2 -6
  188. package/dist/lib/defaultBuildConfig.mjs.map +1 -1
  189. package/dist/lib/deleteGlob.mjs +3 -9
  190. package/dist/lib/deleteGlob.mjs.map +1 -1
  191. package/dist/lib/dependencies/DuplicateDetector.mjs +12 -23
  192. package/dist/lib/dependencies/DuplicateDetector.mjs.map +1 -1
  193. package/dist/lib/dependencies/detectDuplicateDependencies.mjs +22 -33
  194. package/dist/lib/dependencies/detectDuplicateDependencies.mjs.map +1 -1
  195. package/dist/lib/dependencies/index.mjs +22 -33
  196. package/dist/lib/dependencies/index.mjs.map +1 -1
  197. package/dist/lib/file/ReadFileSyncOptions.mjs +1 -3
  198. package/dist/lib/file/ReadFileSyncOptions.mjs.map +1 -1
  199. package/dist/lib/file/constants.mjs.map +1 -1
  200. package/dist/lib/file/fileLines.mjs +12 -13
  201. package/dist/lib/file/fileLines.mjs.map +1 -1
  202. package/dist/lib/file/index.mjs +14 -15
  203. package/dist/lib/file/index.mjs.map +1 -1
  204. package/dist/lib/file/tryReadFileSync.mjs +3 -8
  205. package/dist/lib/file/tryReadFileSync.mjs.map +1 -1
  206. package/dist/lib/generateIgnoreFiles.mjs +27 -43
  207. package/dist/lib/generateIgnoreFiles.mjs.map +1 -1
  208. package/dist/lib/index.mjs +99 -157
  209. package/dist/lib/index.mjs.map +1 -1
  210. package/dist/lib/jsonFormatters.mjs +2 -5
  211. package/dist/lib/jsonFormatters.mjs.map +1 -1
  212. package/dist/lib/loadConfig.mjs +3 -11
  213. package/dist/lib/loadConfig.mjs.map +1 -1
  214. package/dist/lib/parsedPackageJSON.mjs +2 -5
  215. package/dist/lib/parsedPackageJSON.mjs.map +1 -1
  216. package/dist/lib/processEx.mjs +6 -9
  217. package/dist/lib/processEx.mjs.map +1 -1
  218. package/dist/lib/runSteps.mjs +13 -19
  219. package/dist/lib/runSteps.mjs.map +1 -1
  220. package/dist/lib/runStepsAsync.mjs +22 -22
  221. package/dist/lib/runStepsAsync.mjs.map +1 -1
  222. package/dist/lib/runXy.mjs +19 -31
  223. package/dist/lib/runXy.mjs.map +1 -1
  224. package/dist/lib/runXyWithWarning.mjs +2 -5
  225. package/dist/lib/runXyWithWarning.mjs.map +1 -1
  226. package/dist/lib/safeExit.mjs +10 -13
  227. package/dist/lib/safeExit.mjs.map +1 -1
  228. package/dist/lib/string/empty.mjs +2 -5
  229. package/dist/lib/string/empty.mjs.map +1 -1
  230. package/dist/lib/string/index.mjs +3 -9
  231. package/dist/lib/string/index.mjs.map +1 -1
  232. package/dist/lib/string/union.mjs +1 -7
  233. package/dist/lib/string/union.mjs.map +1 -1
  234. package/dist/lib/withErrnoException.mjs +4 -7
  235. package/dist/lib/withErrnoException.mjs.map +1 -1
  236. package/dist/lib/withError.mjs +2 -5
  237. package/dist/lib/withError.mjs.map +1 -1
  238. package/dist/lib/yarn/index.mjs +11 -30
  239. package/dist/lib/yarn/index.mjs.map +1 -1
  240. package/dist/lib/yarn/isYarnVersionOrGreater.mjs +4 -15
  241. package/dist/lib/yarn/isYarnVersionOrGreater.mjs.map +1 -1
  242. package/dist/lib/yarn/workspace/index.mjs +5 -16
  243. package/dist/lib/yarn/workspace/index.mjs.map +1 -1
  244. package/dist/lib/yarn/workspace/yarnWorkspace.mjs +5 -16
  245. package/dist/lib/yarn/workspace/yarnWorkspace.mjs.map +1 -1
  246. package/dist/lib/yarn/workspace/yarnWorkspaces.mjs +3 -14
  247. package/dist/lib/yarn/workspace/yarnWorkspaces.mjs.map +1 -1
  248. package/dist/lib/yarn/yarnInitCwd.mjs +2 -5
  249. package/dist/lib/yarn/yarnInitCwd.mjs.map +1 -1
  250. package/dist/loadPackageConfig.mjs +3 -8
  251. package/dist/loadPackageConfig.mjs.map +1 -1
  252. package/dist/xy/index.mjs +932 -1267
  253. package/dist/xy/index.mjs.map +1 -1
  254. package/dist/xy/param.mjs +3 -9
  255. package/dist/xy/param.mjs.map +1 -1
  256. package/dist/xy/xy.mjs +932 -1267
  257. package/dist/xy/xy.mjs.map +1 -1
  258. package/dist/xy/xyBuildCommands.mjs +228 -320
  259. package/dist/xy/xyBuildCommands.mjs.map +1 -1
  260. package/dist/xy/xyCommonCommands.mjs +251 -336
  261. package/dist/xy/xyCommonCommands.mjs.map +1 -1
  262. package/dist/xy/xyDeployCommands.mjs +99 -161
  263. package/dist/xy/xyDeployCommands.mjs.map +1 -1
  264. package/dist/xy/xyInstallCommands.mjs +145 -193
  265. package/dist/xy/xyInstallCommands.mjs.map +1 -1
  266. package/dist/xy/xyLintCommands.mjs +302 -403
  267. package/dist/xy/xyLintCommands.mjs.map +1 -1
  268. package/dist/xy/xyParseOptions.mjs +2 -5
  269. package/dist/xy/xyParseOptions.mjs.map +1 -1
  270. package/package.json +8 -9
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/dependencies/detectDuplicateDependencies.ts","../../../src/lib/processEx.ts","../../../src/lib/withError.ts","../../../src/lib/withErrnoException.ts","../../../src/lib/safeExit.ts","../../../src/lib/dependencies/DuplicateDetector.ts","../../../src/lib/jsonFormatters.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\n\nimport { safeExit } from '../safeExit.ts'\nimport { DuplicateDetector } from './DuplicateDetector.ts'\n\nexport const detectDuplicateDependencies = (depsFromPackageJSON?: string[], DefaultDependencies?: string[]) => {\n let exitCode = 0\n\n const dependencies = depsFromPackageJSON?.length ? depsFromPackageJSON : DefaultDependencies\n\n return safeExit(() => {\n if (dependencies) {\n for (const dependency of dependencies) {\n let output: string\n\n try {\n const cmd = `yarn why ${dependency} --json`\n output = execSync(cmd).toString()\n } catch (e) {\n console.error(`Error running yarn why: ${e}`)\n exitCode = 1\n continue\n }\n\n if (output) {\n exitCode = new DuplicateDetector(output, dependency).detect()\n } else {\n console.log(`${dependency} - N/A`)\n if (depsFromPackageJSON) {\n exitCode = 1\n console.log(`🚨 Library ${dependency} was requested in package.json but not found`)\n }\n }\n }\n return exitCode\n } else {\n console.log('🚨 No dependencies where passed')\n return exitCode\n }\n })\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => (!!ex.name && !!ex.message),\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(\n ex: unknown, closure: (error: T) => number,\n) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import { EOL } from 'node:os'\n\nimport chalk from 'chalk'\n\nimport { multiLineToJSONArray } from '../jsonFormatters.ts'\n\ninterface ChildFields {\n descriptor: string\n locator: string\n}\n\nconst trimVirtualMeta = (value: string): string => {\n const virtualParts = value.split('virtual:')\n if (virtualParts.length > 1) {\n const hashParts = virtualParts[1].split('#')\n return virtualParts[0] + hashParts[1]\n } else {\n return value\n }\n}\n\nconst trimObjectDependencyVirtualMeta = (obj: Record<string, ChildFields>): Record<string, ChildFields> => {\n const resultObj: Record<string, ChildFields> = {}\n for (const [key, value] of Object.entries(obj)) {\n resultObj[trimVirtualMeta(key)] = {\n descriptor: trimVirtualMeta(value.descriptor),\n locator: trimVirtualMeta(value.locator),\n }\n }\n return resultObj\n}\n\nconst trimDependencyVirtualMeta = (dependencies: DependencyEntries): DependencyEntries => {\n return dependencies.map((dependency) => {\n return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) }\n })\n}\n\ninterface DependencyEntry {\n children: Record<string, ChildFields>\n value: string\n}\n\ntype DependencyEntries = DependencyEntry[]\n\ninterface Results {\n currentVersion: string | undefined\n dependency: string\n duplicateVersions: string[]\n}\n\nexport class DuplicateDetector {\n private dependency: string\n private dependencyEntries: DependencyEntries\n\n constructor(output: string, dependency: string) {\n this.dependency = dependency\n this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output))\n }\n\n detect() {\n // eslint-disable-next-line unicorn/no-array-reduce\n const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency))\n if (result.duplicateVersions.length > 0) {\n console.log(chalk.yellow(`${EOL}Duplicates found for: ${this.dependency}`))\n const duplicateVersions = result.duplicateVersions.toString().replaceAll(',', `${EOL} `)\n console.log(chalk.grey(` ${duplicateVersions}`, EOL))\n return 1\n } else {\n console.log(`${this.dependency} - OK`)\n return 0\n }\n }\n\n private detectReducer(acc: Results, entry: DependencyEntry) {\n const version = Object.entries(entry.children).map(([k]) => k)[0]\n\n if (!acc.currentVersion) {\n acc.currentVersion = version\n return acc\n }\n\n if (acc.currentVersion && acc.currentVersion !== version && !version.includes('@virtual:')) {\n // if first duplicate, push the current version as the first duplicate\n if (acc.duplicateVersions.length === 0) {\n acc.duplicateVersions.push(acc.currentVersion)\n }\n acc.duplicateVersions.push(version)\n acc.duplicateVersions = [...new Set(acc.duplicateVersions)]\n }\n return acc\n }\n\n private resultsFactory = (dependency: string): Results => ({\n currentVersion: undefined, dependency, duplicateVersions: [],\n })\n}\n","export const multiLineToJSONArray = (output: string) => {\n const withCommas = output.replaceAll('\\r\\n', '').replaceAll('\\n', ',')\n const cleanCollection = withCommas.slice(0, Math.max(0, withCommas.length - 1))\n const collection = `[${cleanCollection}]`\n return JSON.parse(collection)\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;;;ACAzB,OAAOC,WAAW;;;ACAX,IAAMC,YAAY,wBAEvBC,IACAC,SACAC,YAAY,CAACF,QAAW,CAAC,CAACA,IAAGG,QAAQ,CAAC,CAACH,IAAGI,YAAQ;AAElD,SAAOF,UAAUF,EAAAA,IAAWC,QAAQD,EAAAA,IAAWK;AACjD,GAPyB;;;ACElB,IAAMC,qBAAqB,wBAChCC,IAAaC,YAAAA;AAEb,SAAOC,UAAaF,IAAIC,SAAS,CAACD,QAAiBA,IAA6BG,UAAUC,MAAAA;AAC5F,GAJkC;;;AFG3B,IAAMC,YAAY,wBAACC,OAAAA;AACxB,QAAMC,QAAQ,OAAOD,OAAO,WAAW,IAAIE,MAAMF,EAAAA,IAAMA;AACvD,QAAMG,WACFC,mBAAmBH,OAAO,CAACA,WAAAA;AAC3B,QAAIA,OAAMI,SAAS,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F;MACF;AACA,aAAOJ;IACT,OAAO;AACLU,cAAQI,IAAI,wCAAA;AACZ,aAAOd;IACT;EACF,CAAA;AACF,GAnC2C;","names":["execSync","chalk","withError","ex","closure","predicate","name","message","undefined","withErrnoException","ex","closure","withError","errno","undefined","processEx","ex","error","Error","exitCode","withErrnoException","code","console","chalk","red","path","errno","withError","name","message","JSON","stringify","process","exit","safeExit","func","exitOnFail","result","process","exit","ex","processEx","EOL","chalk","multiLineToJSONArray","output","withCommas","replaceAll","cleanCollection","slice","Math","max","length","collection","JSON","parse","trimVirtualMeta","value","virtualParts","split","length","hashParts","trimObjectDependencyVirtualMeta","obj","resultObj","key","Object","entries","descriptor","locator","trimDependencyVirtualMeta","dependencies","map","dependency","children","DuplicateDetector","dependencyEntries","output","multiLineToJSONArray","detect","result","reduce","detectReducer","resultsFactory","duplicateVersions","console","log","chalk","yellow","EOL","toString","replaceAll","grey","acc","entry","version","k","currentVersion","includes","push","Set","undefined","detectDuplicateDependencies","depsFromPackageJSON","DefaultDependencies","exitCode","dependencies","length","safeExit","dependency","output","cmd","execSync","toString","e","console","error","DuplicateDetector","detect","log"]}
1
+ {"version":3,"sources":["../../../src/lib/dependencies/detectDuplicateDependencies.ts","../../../src/lib/processEx.ts","../../../src/lib/withError.ts","../../../src/lib/withErrnoException.ts","../../../src/lib/safeExit.ts","../../../src/lib/dependencies/DuplicateDetector.ts","../../../src/lib/jsonFormatters.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\n\nimport { safeExit } from '../safeExit.ts'\nimport { DuplicateDetector } from './DuplicateDetector.ts'\n\nexport const detectDuplicateDependencies = (depsFromPackageJSON?: string[], DefaultDependencies?: string[]) => {\n let exitCode = 0\n\n const dependencies = depsFromPackageJSON?.length ? depsFromPackageJSON : DefaultDependencies\n\n return safeExit(() => {\n if (dependencies) {\n for (const dependency of dependencies) {\n let output: string\n\n try {\n const cmd = `yarn why ${dependency} --json`\n output = execSync(cmd).toString()\n } catch (e) {\n console.error(`Error running yarn why: ${e}`)\n exitCode = 1\n continue\n }\n\n if (output) {\n exitCode = new DuplicateDetector(output, dependency).detect()\n } else {\n console.log(`${dependency} - N/A`)\n if (depsFromPackageJSON) {\n exitCode = 1\n console.log(`🚨 Library ${dependency} was requested in package.json but not found`)\n }\n }\n }\n return exitCode\n } else {\n console.log('🚨 No dependencies where passed')\n return exitCode\n }\n })\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => (!!ex.name && !!ex.message),\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(\n ex: unknown, closure: (error: T) => number,\n) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import { EOL } from 'node:os'\n\nimport chalk from 'chalk'\n\nimport { multiLineToJSONArray } from '../jsonFormatters.ts'\n\ninterface ChildFields {\n descriptor: string\n locator: string\n}\n\nconst trimVirtualMeta = (value: string): string => {\n const virtualParts = value.split('virtual:')\n if (virtualParts.length > 1) {\n const hashParts = virtualParts[1].split('#')\n return virtualParts[0] + hashParts[1]\n } else {\n return value\n }\n}\n\nconst trimObjectDependencyVirtualMeta = (obj: Record<string, ChildFields>): Record<string, ChildFields> => {\n const resultObj: Record<string, ChildFields> = {}\n for (const [key, value] of Object.entries(obj)) {\n resultObj[trimVirtualMeta(key)] = {\n descriptor: trimVirtualMeta(value.descriptor),\n locator: trimVirtualMeta(value.locator),\n }\n }\n return resultObj\n}\n\nconst trimDependencyVirtualMeta = (dependencies: DependencyEntries): DependencyEntries => {\n return dependencies.map((dependency) => {\n return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) }\n })\n}\n\ninterface DependencyEntry {\n children: Record<string, ChildFields>\n value: string\n}\n\ntype DependencyEntries = DependencyEntry[]\n\ninterface Results {\n currentVersion: string | undefined\n dependency: string\n duplicateVersions: string[]\n}\n\nexport class DuplicateDetector {\n private dependency: string\n private dependencyEntries: DependencyEntries\n\n constructor(output: string, dependency: string) {\n this.dependency = dependency\n this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output))\n }\n\n detect() {\n // eslint-disable-next-line unicorn/no-array-reduce\n const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency))\n if (result.duplicateVersions.length > 0) {\n console.log(chalk.yellow(`${EOL}Duplicates found for: ${this.dependency}`))\n const duplicateVersions = result.duplicateVersions.toString().replaceAll(',', `${EOL} `)\n console.log(chalk.grey(` ${duplicateVersions}`, EOL))\n return 1\n } else {\n console.log(`${this.dependency} - OK`)\n return 0\n }\n }\n\n private detectReducer(acc: Results, entry: DependencyEntry) {\n const version = Object.entries(entry.children).map(([k]) => k)[0]\n\n if (!acc.currentVersion) {\n acc.currentVersion = version\n return acc\n }\n\n if (acc.currentVersion && acc.currentVersion !== version && !version.includes('@virtual:')) {\n // if first duplicate, push the current version as the first duplicate\n if (acc.duplicateVersions.length === 0) {\n acc.duplicateVersions.push(acc.currentVersion)\n }\n acc.duplicateVersions.push(version)\n acc.duplicateVersions = [...new Set(acc.duplicateVersions)]\n }\n return acc\n }\n\n private resultsFactory = (dependency: string): Results => ({\n currentVersion: undefined, dependency, duplicateVersions: [],\n })\n}\n","export const multiLineToJSONArray = (output: string) => {\n const withCommas = output.replaceAll('\\r\\n', '').replaceAll('\\n', ',')\n const cleanCollection = withCommas.slice(0, Math.max(0, withCommas.length - 1))\n const collection = `[${cleanCollection}]`\n return JSON.parse(collection)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,OAAO,WAAW;;;ACAX,IAAM,YAAY,CAEvB,IACA,SACA,YAAY,CAACA,QAAW,CAAC,CAACA,IAAG,QAAQ,CAAC,CAACA,IAAG,YACvC;AACH,SAAO,UAAU,EAAO,IAAI,QAAQ,EAAO,IAAI;AACjD;;;ACLO,IAAM,qBAAqB,CAChC,IAAa,YACV;AACH,SAAO,UAAa,IAAI,SAAS,CAACC,QAAiBA,IAA6B,UAAU,MAAS;AACrG;;;AFDO,IAAM,YAAY,CAAC,OAAgB;AACxC,QAAM,QAAQ,OAAO,OAAO,WAAW,IAAI,MAAM,EAAE,IAAI;AACvD,QAAM,WACF,mBAAmB,OAAO,CAACC,WAAU;AACrC,QAAIA,OAAM,SAAS,UAAU;AAC3B,cAAQ,MAAM,MAAM,IAAI,IAAIA,OAAM,IAAI,cAAc,CAAC;AAAA,IACvD,OAAO;AACL,cAAQ,MAAM,MAAM,IAAI,UAAUA,OAAM,IAAI,EAAE,CAAC;AAAA,IACjD;AACA,WAAOA,OAAM,SAAS;AAAA,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,kBAAkB,WAAW,GAAG;AACtC,YAAI,kBAAkB,KAAK,IAAI,cAAc;AAAA,MAC/C;AACA,UAAI,kBAAkB,KAAK,OAAO;AAClC,UAAI,oBAAoB,CAAC,GAAG,IAAI,IAAI,IAAI,iBAAiB,CAAC;AAAA,IAC5D;AACA,WAAO;AAAA,EACT;AAAA,EAEQ,iBAAiB,CAAC,gBAAiC;AAAA,IACzD,gBAAgB;AAAA,IAAW;AAAA,IAAY,mBAAmB,CAAC;AAAA,EAC7D;AACF;;;AL3FO,IAAM,8BAA8B,CAAC,qBAAgC,wBAAmC;AAC7G,MAAI,WAAW;AAEf,QAAM,eAAe,qBAAqB,SAAS,sBAAsB;AAEzE,SAAO,SAAS,MAAM;AACpB,QAAI,cAAc;AAChB,iBAAW,cAAc,cAAc;AACrC,YAAI;AAEJ,YAAI;AACF,gBAAM,MAAM,YAAY,UAAU;AAClC,mBAAS,SAAS,GAAG,EAAE,SAAS;AAAA,QAClC,SAAS,GAAG;AACV,kBAAQ,MAAM,2BAA2B,CAAC,EAAE;AAC5C,qBAAW;AACX;AAAA,QACF;AAEA,YAAI,QAAQ;AACV,qBAAW,IAAI,kBAAkB,QAAQ,UAAU,EAAE,OAAO;AAAA,QAC9D,OAAO;AACL,kBAAQ,IAAI,GAAG,UAAU,QAAQ;AACjC,cAAI,qBAAqB;AACvB,uBAAW;AACX,oBAAQ,IAAI,qBAAc,UAAU,8CAA8C;AAAA,UACpF;AAAA,QACF;AAAA,MACF;AACA,aAAO;AAAA,IACT,OAAO;AACL,cAAQ,IAAI,wCAAiC;AAC7C,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":["ex","ex","error","chalk","chalk"]}
@@ -1,7 +1,5 @@
1
1
  // src/lib/file/ReadFileSyncOptions.ts
2
- var defaultReadFileSyncOptions = {
3
- encoding: "utf8"
4
- };
2
+ var defaultReadFileSyncOptions = { encoding: "utf8" };
5
3
  export {
6
4
  defaultReadFileSyncOptions
7
5
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n"],"mappings":";AAKO,IAAMA,6BAAkD;EAAEC,UAAU;AAAO;","names":["defaultReadFileSyncOptions","encoding"]}
1
+ {"version":3,"sources":["../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n"],"mappings":";AAKO,IAAM,6BAAkD,EAAE,UAAU,OAAO;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/file/constants.ts"],"sourcesContent":["export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n"],"mappings":";AAAO,IAAMA,wBAAwB;AAC9B,IAAMC,yBAAyB;","names":["WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE"]}
1
+ {"version":3,"sources":["../../../src/lib/file/constants.ts"],"sourcesContent":["export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n"],"mappings":";AAAO,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB;","names":[]}
@@ -1,30 +1,29 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // src/lib/file/fileLines.ts
5
- import { existsSync, readFileSync, writeFileSync } from "fs";
2
+ import {
3
+ existsSync,
4
+ readFileSync,
5
+ writeFileSync
6
+ } from "fs";
6
7
 
7
8
  // src/lib/string/empty.ts
8
- var empty = /* @__PURE__ */ __name((value) => value?.trim().length === 0, "empty");
9
- var notEmpty = /* @__PURE__ */ __name((value) => !empty(value), "notEmpty");
9
+ var empty = (value) => value?.trim().length === 0;
10
+ var notEmpty = (value) => !empty(value);
10
11
 
11
12
  // src/lib/file/constants.ts
12
13
  var WINDOWS_NEWLINE_REGEX = /\r\n/g;
13
14
  var CROSS_PLATFORM_NEWLINE = "\n";
14
15
 
15
16
  // src/lib/file/ReadFileSyncOptions.ts
16
- var defaultReadFileSyncOptions = {
17
- encoding: "utf8"
18
- };
17
+ var defaultReadFileSyncOptions = { encoding: "utf8" };
19
18
 
20
19
  // src/lib/file/fileLines.ts
21
- var readLines = /* @__PURE__ */ __name((uri, options = defaultReadFileSyncOptions) => existsSync(uri) ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [], "readLines");
22
- var readNonEmptyLines = /* @__PURE__ */ __name((uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty), "readNonEmptyLines");
23
- var writeLines = /* @__PURE__ */ __name((uri, lines, options = defaultReadFileSyncOptions) => {
20
+ var readLines = (uri, options = defaultReadFileSyncOptions) => existsSync(uri) ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [];
21
+ var readNonEmptyLines = (uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty);
22
+ var writeLines = (uri, lines, options = defaultReadFileSyncOptions) => {
24
23
  const existing = existsSync(uri) ? readFileSync(uri, options) : void 0;
25
24
  const desired = lines.join(CROSS_PLATFORM_NEWLINE);
26
25
  if (existing !== desired) writeFileSync(uri, desired, options);
27
- }, "writeLines");
26
+ };
28
27
  export {
29
28
  readLines,
30
29
  readNonEmptyLines,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/file/fileLines.ts","../../../src/lib/string/empty.ts","../../../src/lib/file/constants.ts","../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["import type { PathLike, WriteFileOptions } from 'node:fs'\nimport {\n existsSync, readFileSync,\n writeFileSync,\n} from 'node:fs'\n\nimport { notEmpty } from '../string/index.ts'\nimport { CROSS_PLATFORM_NEWLINE, WINDOWS_NEWLINE_REGEX } from './constants.ts'\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const readLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n existsSync(uri)\n ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE)\n : []\n\nexport const readNonEmptyLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n readLines(uri, options).filter(notEmpty)\n\nexport const writeLines = (uri: PathLike, lines: string[], options: WriteFileOptions = defaultReadFileSyncOptions) => {\n const existing = existsSync(uri) ? readFileSync(uri, options) : undefined\n const desired = lines.join(CROSS_PLATFORM_NEWLINE)\n // Check if the file is different before writing\n if (existing !== desired) writeFileSync(uri, desired, options)\n}\n","export const empty = (value?: string | undefined): boolean => value?.trim().length === 0\nexport const notEmpty = (value?: string | undefined): boolean => !empty(value)\n","export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n"],"mappings":";;;;AACA,SACEA,YAAYC,cACZC,qBACK;;;ACJA,IAAMC,QAAQ,wBAACC,UAAwCA,OAAOC,KAAAA,EAAOC,WAAW,GAAlE;AACd,IAAMC,WAAW,wBAACH,UAAwC,CAACD,MAAMC,KAAAA,GAAhD;;;ACDjB,IAAMI,wBAAwB;AAC9B,IAAMC,yBAAyB;;;ACI/B,IAAMC,6BAAkD;EAAEC,UAAU;AAAO;;;AHM3E,IAAMC,YAAY,wBAACC,KAAeC,UAA+BC,+BACtEC,WAAWH,GAAAA,IACPI,aAAaJ,KAAKC,OAAAA,EAASI,QAAQC,uBAAuBC,sBAAAA,EAAwBC,MAAMD,sBAAAA,IACxF,CAAA,GAHmB;AAKlB,IAAME,oBAAoB,wBAACT,KAAeC,UAA+BC,+BAC9EH,UAAUC,KAAKC,OAAAA,EAASS,OAAOC,QAAAA,GADA;AAG1B,IAAMC,aAAa,wBAACZ,KAAea,OAAiBZ,UAA4BC,+BAA0B;AAC/G,QAAMY,WAAWX,WAAWH,GAAAA,IAAOI,aAAaJ,KAAKC,OAAAA,IAAWc;AAChE,QAAMC,UAAUH,MAAMI,KAAKV,sBAAAA;AAE3B,MAAIO,aAAaE,QAASE,eAAclB,KAAKgB,SAASf,OAAAA;AACxD,GAL0B;","names":["existsSync","readFileSync","writeFileSync","empty","value","trim","length","notEmpty","WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","defaultReadFileSyncOptions","encoding","readLines","uri","options","defaultReadFileSyncOptions","existsSync","readFileSync","replace","WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","split","readNonEmptyLines","filter","notEmpty","writeLines","lines","existing","undefined","desired","join","writeFileSync"]}
1
+ {"version":3,"sources":["../../../src/lib/file/fileLines.ts","../../../src/lib/string/empty.ts","../../../src/lib/file/constants.ts","../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["import type { PathLike, WriteFileOptions } from 'node:fs'\nimport {\n existsSync, readFileSync,\n writeFileSync,\n} from 'node:fs'\n\nimport { notEmpty } from '../string/index.ts'\nimport { CROSS_PLATFORM_NEWLINE, WINDOWS_NEWLINE_REGEX } from './constants.ts'\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const readLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n existsSync(uri)\n ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE)\n : []\n\nexport const readNonEmptyLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n readLines(uri, options).filter(notEmpty)\n\nexport const writeLines = (uri: PathLike, lines: string[], options: WriteFileOptions = defaultReadFileSyncOptions) => {\n const existing = existsSync(uri) ? readFileSync(uri, options) : undefined\n const desired = lines.join(CROSS_PLATFORM_NEWLINE)\n // Check if the file is different before writing\n if (existing !== desired) writeFileSync(uri, desired, options)\n}\n","export const empty = (value?: string | undefined): boolean => value?.trim().length === 0\nexport const notEmpty = (value?: string | undefined): boolean => !empty(value)\n","export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n"],"mappings":";AACA;AAAA,EACE;AAAA,EAAY;AAAA,EACZ;AAAA,OACK;;;ACJA,IAAM,QAAQ,CAAC,UAAwC,OAAO,KAAK,EAAE,WAAW;AAChF,IAAM,WAAW,CAAC,UAAwC,CAAC,MAAM,KAAK;;;ACDtE,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB;;;ACI/B,IAAM,6BAAkD,EAAE,UAAU,OAAO;;;AHM3E,IAAM,YAAY,CAAC,KAAe,UAA+B,+BACtE,WAAW,GAAG,IACV,aAAa,KAAK,OAAO,EAAE,QAAQ,uBAAuB,sBAAsB,EAAE,MAAM,sBAAsB,IAC9G,CAAC;AAEA,IAAM,oBAAoB,CAAC,KAAe,UAA+B,+BAC9E,UAAU,KAAK,OAAO,EAAE,OAAO,QAAQ;AAElC,IAAM,aAAa,CAAC,KAAe,OAAiB,UAA4B,+BAA+B;AACpH,QAAM,WAAW,WAAW,GAAG,IAAI,aAAa,KAAK,OAAO,IAAI;AAChE,QAAM,UAAU,MAAM,KAAK,sBAAsB;AAEjD,MAAI,aAAa,QAAS,eAAc,KAAK,SAAS,OAAO;AAC/D;","names":[]}
@@ -1,36 +1,35 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // src/lib/file/constants.ts
5
2
  var WINDOWS_NEWLINE_REGEX = /\r\n/g;
6
3
  var CROSS_PLATFORM_NEWLINE = "\n";
7
4
 
8
5
  // src/lib/file/fileLines.ts
9
- import { existsSync, readFileSync, writeFileSync } from "fs";
6
+ import {
7
+ existsSync,
8
+ readFileSync,
9
+ writeFileSync
10
+ } from "fs";
10
11
 
11
12
  // src/lib/string/empty.ts
12
- var empty = /* @__PURE__ */ __name((value) => value?.trim().length === 0, "empty");
13
- var notEmpty = /* @__PURE__ */ __name((value) => !empty(value), "notEmpty");
13
+ var empty = (value) => value?.trim().length === 0;
14
+ var notEmpty = (value) => !empty(value);
14
15
 
15
16
  // src/lib/file/ReadFileSyncOptions.ts
16
- var defaultReadFileSyncOptions = {
17
- encoding: "utf8"
18
- };
17
+ var defaultReadFileSyncOptions = { encoding: "utf8" };
19
18
 
20
19
  // src/lib/file/fileLines.ts
21
- var readLines = /* @__PURE__ */ __name((uri, options = defaultReadFileSyncOptions) => existsSync(uri) ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [], "readLines");
22
- var readNonEmptyLines = /* @__PURE__ */ __name((uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty), "readNonEmptyLines");
23
- var writeLines = /* @__PURE__ */ __name((uri, lines, options = defaultReadFileSyncOptions) => {
20
+ var readLines = (uri, options = defaultReadFileSyncOptions) => existsSync(uri) ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [];
21
+ var readNonEmptyLines = (uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty);
22
+ var writeLines = (uri, lines, options = defaultReadFileSyncOptions) => {
24
23
  const existing = existsSync(uri) ? readFileSync(uri, options) : void 0;
25
24
  const desired = lines.join(CROSS_PLATFORM_NEWLINE);
26
25
  if (existing !== desired) writeFileSync(uri, desired, options);
27
- }, "writeLines");
26
+ };
28
27
 
29
28
  // src/lib/file/tryReadFileSync.ts
30
29
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
31
- var tryReadFileSync = /* @__PURE__ */ __name((uri, options = defaultReadFileSyncOptions) => {
30
+ var tryReadFileSync = (uri, options = defaultReadFileSyncOptions) => {
32
31
  return existsSync2(uri) ? readFileSync2(uri, options) : void 0;
33
- }, "tryReadFileSync");
32
+ };
34
33
  export {
35
34
  CROSS_PLATFORM_NEWLINE,
36
35
  WINDOWS_NEWLINE_REGEX,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/file/constants.ts","../../../src/lib/file/fileLines.ts","../../../src/lib/string/empty.ts","../../../src/lib/file/ReadFileSyncOptions.ts","../../../src/lib/file/tryReadFileSync.ts"],"sourcesContent":["export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n","import type { PathLike, WriteFileOptions } from 'node:fs'\nimport {\n existsSync, readFileSync,\n writeFileSync,\n} from 'node:fs'\n\nimport { notEmpty } from '../string/index.ts'\nimport { CROSS_PLATFORM_NEWLINE, WINDOWS_NEWLINE_REGEX } from './constants.ts'\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const readLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n existsSync(uri)\n ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE)\n : []\n\nexport const readNonEmptyLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n readLines(uri, options).filter(notEmpty)\n\nexport const writeLines = (uri: PathLike, lines: string[], options: WriteFileOptions = defaultReadFileSyncOptions) => {\n const existing = existsSync(uri) ? readFileSync(uri, options) : undefined\n const desired = lines.join(CROSS_PLATFORM_NEWLINE)\n // Check if the file is different before writing\n if (existing !== desired) writeFileSync(uri, desired, options)\n}\n","export const empty = (value?: string | undefined): boolean => value?.trim().length === 0\nexport const notEmpty = (value?: string | undefined): boolean => !empty(value)\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n","import type { PathLike } from 'node:fs'\nimport { existsSync, readFileSync } from 'node:fs'\n\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const tryReadFileSync = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string | undefined => {\n return existsSync(uri) ? readFileSync(uri, options) : undefined\n}\n"],"mappings":";;;;AAAO,IAAMA,wBAAwB;AAC9B,IAAMC,yBAAyB;;;ACAtC,SACEC,YAAYC,cACZC,qBACK;;;ACJA,IAAMC,QAAQ,wBAACC,UAAwCA,OAAOC,KAAAA,EAAOC,WAAW,GAAlE;AACd,IAAMC,WAAW,wBAACH,UAAwC,CAACD,MAAMC,KAAAA,GAAhD;;;ACIjB,IAAMI,6BAAkD;EAAEC,UAAU;AAAO;;;AFM3E,IAAMC,YAAY,wBAACC,KAAeC,UAA+BC,+BACtEC,WAAWH,GAAAA,IACPI,aAAaJ,KAAKC,OAAAA,EAASI,QAAQC,uBAAuBC,sBAAAA,EAAwBC,MAAMD,sBAAAA,IACxF,CAAA,GAHmB;AAKlB,IAAME,oBAAoB,wBAACT,KAAeC,UAA+BC,+BAC9EH,UAAUC,KAAKC,OAAAA,EAASS,OAAOC,QAAAA,GADA;AAG1B,IAAMC,aAAa,wBAACZ,KAAea,OAAiBZ,UAA4BC,+BAA0B;AAC/G,QAAMY,WAAWX,WAAWH,GAAAA,IAAOI,aAAaJ,KAAKC,OAAAA,IAAWc;AAChE,QAAMC,UAAUH,MAAMI,KAAKV,sBAAAA;AAE3B,MAAIO,aAAaE,QAASE,eAAclB,KAAKgB,SAASf,OAAAA;AACxD,GAL0B;;;AGlB1B,SAASkB,cAAAA,aAAYC,gBAAAA,qBAAoB;AAKlC,IAAMC,kBAAkB,wBAACC,KAAeC,UAA+BC,+BAA0B;AACtG,SAAOC,YAAWH,GAAAA,IAAOI,cAAaJ,KAAKC,OAAAA,IAAWI;AACxD,GAF+B;","names":["WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","existsSync","readFileSync","writeFileSync","empty","value","trim","length","notEmpty","defaultReadFileSyncOptions","encoding","readLines","uri","options","defaultReadFileSyncOptions","existsSync","readFileSync","replace","WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","split","readNonEmptyLines","filter","notEmpty","writeLines","lines","existing","undefined","desired","join","writeFileSync","existsSync","readFileSync","tryReadFileSync","uri","options","defaultReadFileSyncOptions","existsSync","readFileSync","undefined"]}
1
+ {"version":3,"sources":["../../../src/lib/file/constants.ts","../../../src/lib/file/fileLines.ts","../../../src/lib/string/empty.ts","../../../src/lib/file/ReadFileSyncOptions.ts","../../../src/lib/file/tryReadFileSync.ts"],"sourcesContent":["export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n","import type { PathLike, WriteFileOptions } from 'node:fs'\nimport {\n existsSync, readFileSync,\n writeFileSync,\n} from 'node:fs'\n\nimport { notEmpty } from '../string/index.ts'\nimport { CROSS_PLATFORM_NEWLINE, WINDOWS_NEWLINE_REGEX } from './constants.ts'\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const readLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n existsSync(uri)\n ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE)\n : []\n\nexport const readNonEmptyLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n readLines(uri, options).filter(notEmpty)\n\nexport const writeLines = (uri: PathLike, lines: string[], options: WriteFileOptions = defaultReadFileSyncOptions) => {\n const existing = existsSync(uri) ? readFileSync(uri, options) : undefined\n const desired = lines.join(CROSS_PLATFORM_NEWLINE)\n // Check if the file is different before writing\n if (existing !== desired) writeFileSync(uri, desired, options)\n}\n","export const empty = (value?: string | undefined): boolean => value?.trim().length === 0\nexport const notEmpty = (value?: string | undefined): boolean => !empty(value)\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n","import type { PathLike } from 'node:fs'\nimport { existsSync, readFileSync } from 'node:fs'\n\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const tryReadFileSync = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string | undefined => {\n return existsSync(uri) ? readFileSync(uri, options) : undefined\n}\n"],"mappings":";AAAO,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB;;;ACAtC;AAAA,EACE;AAAA,EAAY;AAAA,EACZ;AAAA,OACK;;;ACJA,IAAM,QAAQ,CAAC,UAAwC,OAAO,KAAK,EAAE,WAAW;AAChF,IAAM,WAAW,CAAC,UAAwC,CAAC,MAAM,KAAK;;;ACItE,IAAM,6BAAkD,EAAE,UAAU,OAAO;;;AFM3E,IAAM,YAAY,CAAC,KAAe,UAA+B,+BACtE,WAAW,GAAG,IACV,aAAa,KAAK,OAAO,EAAE,QAAQ,uBAAuB,sBAAsB,EAAE,MAAM,sBAAsB,IAC9G,CAAC;AAEA,IAAM,oBAAoB,CAAC,KAAe,UAA+B,+BAC9E,UAAU,KAAK,OAAO,EAAE,OAAO,QAAQ;AAElC,IAAM,aAAa,CAAC,KAAe,OAAiB,UAA4B,+BAA+B;AACpH,QAAM,WAAW,WAAW,GAAG,IAAI,aAAa,KAAK,OAAO,IAAI;AAChE,QAAM,UAAU,MAAM,KAAK,sBAAsB;AAEjD,MAAI,aAAa,QAAS,eAAc,KAAK,SAAS,OAAO;AAC/D;;;AGvBA,SAAS,cAAAA,aAAY,gBAAAC,qBAAoB;AAKlC,IAAM,kBAAkB,CAAC,KAAe,UAA+B,+BAAmD;AAC/H,SAAOC,YAAW,GAAG,IAAIC,cAAa,KAAK,OAAO,IAAI;AACxD;","names":["existsSync","readFileSync","existsSync","readFileSync"]}
@@ -1,18 +1,13 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // src/lib/file/tryReadFileSync.ts
5
2
  import { existsSync, readFileSync } from "fs";
6
3
 
7
4
  // src/lib/file/ReadFileSyncOptions.ts
8
- var defaultReadFileSyncOptions = {
9
- encoding: "utf8"
10
- };
5
+ var defaultReadFileSyncOptions = { encoding: "utf8" };
11
6
 
12
7
  // src/lib/file/tryReadFileSync.ts
13
- var tryReadFileSync = /* @__PURE__ */ __name((uri, options = defaultReadFileSyncOptions) => {
8
+ var tryReadFileSync = (uri, options = defaultReadFileSyncOptions) => {
14
9
  return existsSync(uri) ? readFileSync(uri, options) : void 0;
15
- }, "tryReadFileSync");
10
+ };
16
11
  export {
17
12
  tryReadFileSync
18
13
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/file/tryReadFileSync.ts","../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["import type { PathLike } from 'node:fs'\nimport { existsSync, readFileSync } from 'node:fs'\n\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const tryReadFileSync = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string | undefined => {\n return existsSync(uri) ? readFileSync(uri, options) : undefined\n}\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n"],"mappings":";;;;AACA,SAASA,YAAYC,oBAAoB;;;ACIlC,IAAMC,6BAAkD;EAAEC,UAAU;AAAO;;;ADC3E,IAAMC,kBAAkB,wBAACC,KAAeC,UAA+BC,+BAA0B;AACtG,SAAOC,WAAWH,GAAAA,IAAOI,aAAaJ,KAAKC,OAAAA,IAAWI;AACxD,GAF+B;","names":["existsSync","readFileSync","defaultReadFileSyncOptions","encoding","tryReadFileSync","uri","options","defaultReadFileSyncOptions","existsSync","readFileSync","undefined"]}
1
+ {"version":3,"sources":["../../../src/lib/file/tryReadFileSync.ts","../../../src/lib/file/ReadFileSyncOptions.ts"],"sourcesContent":["import type { PathLike } from 'node:fs'\nimport { existsSync, readFileSync } from 'node:fs'\n\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const tryReadFileSync = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string | undefined => {\n return existsSync(uri) ? readFileSync(uri, options) : undefined\n}\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n"],"mappings":";AACA,SAAS,YAAY,oBAAoB;;;ACIlC,IAAM,6BAAkD,EAAE,UAAU,OAAO;;;ADC3E,IAAM,kBAAkB,CAAC,KAAe,UAA+B,+BAAmD;AAC/H,SAAO,WAAW,GAAG,IAAI,aAAa,KAAK,OAAO,IAAI;AACxD;","names":[]}
@@ -1,6 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // src/lib/generateIgnoreFiles.ts
5
2
  import chalk from "chalk";
6
3
 
@@ -9,78 +6,65 @@ var WINDOWS_NEWLINE_REGEX = /\r\n/g;
9
6
  var CROSS_PLATFORM_NEWLINE = "\n";
10
7
 
11
8
  // src/lib/file/fileLines.ts
12
- import { existsSync, readFileSync, writeFileSync } from "fs";
9
+ import {
10
+ existsSync,
11
+ readFileSync,
12
+ writeFileSync
13
+ } from "fs";
13
14
 
14
15
  // src/lib/string/empty.ts
15
- var empty = /* @__PURE__ */ __name((value) => value?.trim().length === 0, "empty");
16
- var notEmpty = /* @__PURE__ */ __name((value) => !empty(value), "notEmpty");
16
+ var empty = (value) => value?.trim().length === 0;
17
+ var notEmpty = (value) => !empty(value);
17
18
 
18
19
  // src/lib/string/union.ts
19
- var union = /* @__PURE__ */ __name((a, b) => /* @__PURE__ */ new Set([
20
- ...new Set(a),
21
- ...new Set(b)
22
- ]), "union");
20
+ var union = (a, b) => /* @__PURE__ */ new Set([...new Set(a), ...new Set(b)]);
23
21
 
24
22
  // src/lib/file/ReadFileSyncOptions.ts
25
- var defaultReadFileSyncOptions = {
26
- encoding: "utf8"
27
- };
23
+ var defaultReadFileSyncOptions = { encoding: "utf8" };
28
24
 
29
25
  // src/lib/file/fileLines.ts
30
- var readLines = /* @__PURE__ */ __name((uri, options = defaultReadFileSyncOptions) => existsSync(uri) ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [], "readLines");
31
- var readNonEmptyLines = /* @__PURE__ */ __name((uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty), "readNonEmptyLines");
32
- var writeLines = /* @__PURE__ */ __name((uri, lines, options = defaultReadFileSyncOptions) => {
26
+ var readLines = (uri, options = defaultReadFileSyncOptions) => existsSync(uri) ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [];
27
+ var readNonEmptyLines = (uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty);
28
+ var writeLines = (uri, lines, options = defaultReadFileSyncOptions) => {
33
29
  const existing = existsSync(uri) ? readFileSync(uri, options) : void 0;
34
30
  const desired = lines.join(CROSS_PLATFORM_NEWLINE);
35
31
  if (existing !== desired) writeFileSync(uri, desired, options);
36
- }, "writeLines");
32
+ };
37
33
 
38
34
  // src/lib/yarn/workspace/yarnWorkspaces.ts
39
35
  import { spawnSync } from "child_process";
40
- var yarnWorkspaces = /* @__PURE__ */ __name(() => {
41
- const result = spawnSync("yarn", [
42
- "workspaces",
43
- "list",
44
- "--json",
45
- "--recursive"
46
- ], {
47
- encoding: "utf8",
48
- shell: true
49
- });
36
+ var yarnWorkspaces = () => {
37
+ const result = spawnSync("yarn", ["workspaces", "list", "--json", "--recursive"], { encoding: "utf8", shell: true });
50
38
  if (result.error) {
51
39
  throw result.error;
52
40
  }
53
41
  return result.stdout.toString().split("\n").slice(0, -1).map((item) => {
54
42
  return JSON.parse(item);
55
43
  });
56
- }, "yarnWorkspaces");
44
+ };
57
45
 
58
46
  // src/lib/yarn/workspace/yarnWorkspace.ts
59
- var yarnWorkspace = /* @__PURE__ */ __name((pkg) => {
47
+ var yarnWorkspace = (pkg) => {
60
48
  const workspace = yarnWorkspaces().find(({ name }) => name === pkg);
61
49
  if (!workspace) throw new Error(`Workspace ${pkg} not found`);
62
50
  return workspace;
63
- }, "yarnWorkspace");
51
+ };
64
52
 
65
53
  // src/lib/yarn/yarnInitCwd.ts
66
- var INIT_CWD = /* @__PURE__ */ __name(() => {
54
+ var INIT_CWD = () => {
67
55
  if (!process.env.INIT_CWD) console.error("Missing INIT_CWD");
68
56
  return process.env.INIT_CWD;
69
- }, "INIT_CWD");
57
+ };
70
58
 
71
59
  // src/lib/generateIgnoreFiles.ts
72
- var localeCompare = /* @__PURE__ */ __name((a, b) => a.localeCompare(b), "localeCompare");
73
- var mergeEntries = /* @__PURE__ */ __name((a, b) => [
74
- ...union(a, b)
75
- ].sort(localeCompare), "mergeEntries");
76
- var generateIgnoreFiles = /* @__PURE__ */ __name((filename, pkg) => {
60
+ var localeCompare = (a, b) => a.localeCompare(b);
61
+ var mergeEntries = (a, b) => [...union(a, b)].sort(localeCompare);
62
+ var generateIgnoreFiles = (filename, pkg) => {
77
63
  console.log(chalk.green(`Generate ${filename} Files`));
78
64
  const cwd = INIT_CWD() ?? ".";
79
- const workspaces = pkg ? [
80
- yarnWorkspace(pkg)
81
- ] : yarnWorkspaces();
82
- const readEntries = /* @__PURE__ */ __name((location) => readNonEmptyLines(`${location}/${filename}`), "readEntries");
83
- const writeEntries = /* @__PURE__ */ __name((location, entries) => writeLines(`${location}/${filename}`, entries), "writeEntries");
65
+ const workspaces = pkg ? [yarnWorkspace(pkg)] : yarnWorkspaces();
66
+ const readEntries = (location) => readNonEmptyLines(`${location}/${filename}`);
67
+ const writeEntries = (location, entries) => writeLines(`${location}/${filename}`, entries);
84
68
  const results = workspaces.map(({ location, name }) => {
85
69
  try {
86
70
  writeEntries(location, mergeEntries(readEntries(cwd), readEntries(location)));
@@ -93,7 +77,7 @@ var generateIgnoreFiles = /* @__PURE__ */ __name((filename, pkg) => {
93
77
  });
94
78
  const succeeded = results.every((result) => result === 0);
95
79
  return succeeded ? 0 : 1;
96
- }, "generateIgnoreFiles");
80
+ };
97
81
  export {
98
82
  generateIgnoreFiles
99
83
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/generateIgnoreFiles.ts","../../src/lib/file/constants.ts","../../src/lib/file/fileLines.ts","../../src/lib/string/empty.ts","../../src/lib/string/union.ts","../../src/lib/file/ReadFileSyncOptions.ts","../../src/lib/yarn/workspace/yarnWorkspaces.ts","../../src/lib/yarn/workspace/yarnWorkspace.ts","../../src/lib/yarn/yarnInitCwd.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { readNonEmptyLines, writeLines } from './file/index.ts'\nimport { union } from './string/index.ts'\nimport {\n INIT_CWD, yarnWorkspace, yarnWorkspaces,\n} from './yarn/index.ts'\n\nconst localeCompare = (a: string, b: string) => a.localeCompare(b)\n\nconst mergeEntries = (a: string[], b: string[]): string[] => [...union(a, b)].sort(localeCompare)\n\nexport const generateIgnoreFiles = (filename: string, pkg?: string) => {\n console.log(chalk.green(`Generate ${filename} Files`))\n const cwd = INIT_CWD() ?? '.'\n const workspaces = pkg ? [yarnWorkspace(pkg)] : yarnWorkspaces()\n const readEntries = (location: string): string[] => readNonEmptyLines(`${location}/${filename}`)\n const writeEntries = (location: string, entries: string[]) => writeLines(`${location}/${filename}`, entries)\n const results = workspaces.map(({ location, name }) => {\n try {\n writeEntries(location, mergeEntries(readEntries(cwd), readEntries(location)))\n return 0\n } catch (ex) {\n const error = ex as Error\n console.error(`Generate ${filename} Files [${name}] [${error.message}]`)\n return 1\n }\n })\n const succeeded = results.every(result => result === 0)\n return succeeded ? 0 : 1\n}\n","export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n","import type { PathLike, WriteFileOptions } from 'node:fs'\nimport {\n existsSync, readFileSync,\n writeFileSync,\n} from 'node:fs'\n\nimport { notEmpty } from '../string/index.ts'\nimport { CROSS_PLATFORM_NEWLINE, WINDOWS_NEWLINE_REGEX } from './constants.ts'\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const readLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n existsSync(uri)\n ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE)\n : []\n\nexport const readNonEmptyLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n readLines(uri, options).filter(notEmpty)\n\nexport const writeLines = (uri: PathLike, lines: string[], options: WriteFileOptions = defaultReadFileSyncOptions) => {\n const existing = existsSync(uri) ? readFileSync(uri, options) : undefined\n const desired = lines.join(CROSS_PLATFORM_NEWLINE)\n // Check if the file is different before writing\n if (existing !== desired) writeFileSync(uri, desired, options)\n}\n","export const empty = (value?: string | undefined): boolean => value?.trim().length === 0\nexport const notEmpty = (value?: string | undefined): boolean => !empty(value)\n","export const union = (a: string[], b: string[]): Set<string> => new Set([...new Set(a), ...new Set(b)])\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n","import { spawnSync } from 'node:child_process'\n\nimport type { Workspace } from './Workspace.ts'\n\nexport const yarnWorkspaces = (): Workspace[] => {\n const result = spawnSync('yarn', ['workspaces', 'list', '--json', '--recursive'], { encoding: 'utf8', shell: true })\n if (result.error) {\n throw result.error\n }\n return (\n result.stdout\n .toString()\n // NOTE: This probably doesn't work on Windows\n // TODO: Replace /r/n with /n first\n .split('\\n')\n .slice(0, -1)\n .map((item) => {\n return JSON.parse(item)\n })\n )\n}\n","import type { Workspace } from './Workspace.ts'\nimport { yarnWorkspaces } from './yarnWorkspaces.ts'\n\nexport const yarnWorkspace = (pkg: string): Workspace => {\n const workspace = yarnWorkspaces().find(({ name }) => name === pkg)\n if (!workspace) throw new Error(`Workspace ${pkg} not found`)\n return workspace\n}\n","export const INIT_CWD = () => {\n if (!process.env.INIT_CWD) console.error('Missing INIT_CWD')\n return process.env.INIT_CWD\n}\n"],"mappings":";;;;AAAA,OAAOA,WAAW;;;ACAX,IAAMC,wBAAwB;AAC9B,IAAMC,yBAAyB;;;ACAtC,SACEC,YAAYC,cACZC,qBACK;;;ACJA,IAAMC,QAAQ,wBAACC,UAAwCA,OAAOC,KA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AACzB,GAlBmC;","names":["chalk","WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","existsSync","readFileSync","writeFileSync","empty","value","trim","length","notEmpty","union","a","b","Set","defaultReadFileSyncOptions","encoding","readLines","uri","options","defaultReadFileSyncOptions","existsSync","readFileSync","replace","WINDOWS_NEWLINE_REGEX","CROSS_PLATFORM_NEWLINE","split","readNonEmptyLines","filter","notEmpty","writeLines","lines","existing","undefined","desired","join","writeFileSync","spawnSync","yarnWorkspaces","result","spawnSync","encoding","shell","error","stdout","toString","split","slice","map","item","JSON","parse","yarnWorkspace","pkg","workspace","yarnWorkspaces","find","name","Error","INIT_CWD","process","env","console","error","localeCompare","a","b","mergeEntries","union","sort","generateIgnoreFiles","filename","pkg","console","log","chalk","green","cwd","INIT_CWD","workspaces","yarnWorkspace","yarnWorkspaces","readEntries","location","readNonEmptyLines","writeEntries","entries","writeLines","results","map","name","ex","error","message","succeeded","every","result"]}
1
+ {"version":3,"sources":["../../src/lib/generateIgnoreFiles.ts","../../src/lib/file/constants.ts","../../src/lib/file/fileLines.ts","../../src/lib/string/empty.ts","../../src/lib/string/union.ts","../../src/lib/file/ReadFileSyncOptions.ts","../../src/lib/yarn/workspace/yarnWorkspaces.ts","../../src/lib/yarn/workspace/yarnWorkspace.ts","../../src/lib/yarn/yarnInitCwd.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { readNonEmptyLines, writeLines } from './file/index.ts'\nimport { union } from './string/index.ts'\nimport {\n INIT_CWD, yarnWorkspace, yarnWorkspaces,\n} from './yarn/index.ts'\n\nconst localeCompare = (a: string, b: string) => a.localeCompare(b)\n\nconst mergeEntries = (a: string[], b: string[]): string[] => [...union(a, b)].sort(localeCompare)\n\nexport const generateIgnoreFiles = (filename: string, pkg?: string) => {\n console.log(chalk.green(`Generate ${filename} Files`))\n const cwd = INIT_CWD() ?? '.'\n const workspaces = pkg ? [yarnWorkspace(pkg)] : yarnWorkspaces()\n const readEntries = (location: string): string[] => readNonEmptyLines(`${location}/${filename}`)\n const writeEntries = (location: string, entries: string[]) => writeLines(`${location}/${filename}`, entries)\n const results = workspaces.map(({ location, name }) => {\n try {\n writeEntries(location, mergeEntries(readEntries(cwd), readEntries(location)))\n return 0\n } catch (ex) {\n const error = ex as Error\n console.error(`Generate ${filename} Files [${name}] [${error.message}]`)\n return 1\n }\n })\n const succeeded = results.every(result => result === 0)\n return succeeded ? 0 : 1\n}\n","export const WINDOWS_NEWLINE_REGEX = /\\r\\n/g\nexport const CROSS_PLATFORM_NEWLINE = '\\n'\n","import type { PathLike, WriteFileOptions } from 'node:fs'\nimport {\n existsSync, readFileSync,\n writeFileSync,\n} from 'node:fs'\n\nimport { notEmpty } from '../string/index.ts'\nimport { CROSS_PLATFORM_NEWLINE, WINDOWS_NEWLINE_REGEX } from './constants.ts'\nimport type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'\nimport { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'\n\nexport const readLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n existsSync(uri)\n ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE)\n : []\n\nexport const readNonEmptyLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>\n readLines(uri, options).filter(notEmpty)\n\nexport const writeLines = (uri: PathLike, lines: string[], options: WriteFileOptions = defaultReadFileSyncOptions) => {\n const existing = existsSync(uri) ? readFileSync(uri, options) : undefined\n const desired = lines.join(CROSS_PLATFORM_NEWLINE)\n // Check if the file is different before writing\n if (existing !== desired) writeFileSync(uri, desired, options)\n}\n","export const empty = (value?: string | undefined): boolean => value?.trim().length === 0\nexport const notEmpty = (value?: string | undefined): boolean => !empty(value)\n","export const union = (a: string[], b: string[]): Set<string> => new Set([...new Set(a), ...new Set(b)])\n","export type ReadFileSyncOptions = BufferEncoding | {\n encoding: BufferEncoding\n flags?: string\n}\n\nexport const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }\n","import { spawnSync } from 'node:child_process'\n\nimport type { Workspace } from './Workspace.ts'\n\nexport const yarnWorkspaces = (): Workspace[] => {\n const result = spawnSync('yarn', ['workspaces', 'list', '--json', '--recursive'], { encoding: 'utf8', shell: true })\n if (result.error) {\n throw result.error\n }\n return (\n result.stdout\n .toString()\n // NOTE: This probably doesn't work on Windows\n // TODO: Replace /r/n with /n first\n .split('\\n')\n .slice(0, -1)\n .map((item) => {\n return JSON.parse(item)\n })\n )\n}\n","import type { Workspace } from './Workspace.ts'\nimport { yarnWorkspaces } from './yarnWorkspaces.ts'\n\nexport const yarnWorkspace = (pkg: string): Workspace => {\n const workspace = yarnWorkspaces().find(({ name }) => name === pkg)\n if (!workspace) throw new Error(`Workspace ${pkg} not found`)\n return workspace\n}\n","export const INIT_CWD = () => {\n if (!process.env.INIT_CWD) console.error('Missing INIT_CWD')\n return process.env.INIT_CWD\n}\n"],"mappings":";AAAA,OAAO,WAAW;;;ACAX,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB;;;ACAtC;AAAA,EACE;AAAA,EAAY;AAAA,EACZ;AAAA,OACK;;;ACJA,IAAM,QAAQ,CAAC,UAAwC,OAAO,KAAK,EAAE,WAAW;AAChF,IAAM,WAAW,CAAC,UAAwC,CAAC,MAAM,KAAK;;;ACDtE,IAAM,QAAQ,CAAC,GAAa,MAA6B,oBAAI,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC;;;ACK/F,IAAM,6BAAkD,EAAE,UAAU,OAAO;;;AHM3E,IAAM,YAAY,CAAC,KAAe,UAA+B,+BACtE,WAAW,GAAG,IACV,aAAa,KAAK,OAAO,EAAE,QAAQ,uBAAuB,sBAAsB,EAAE,MAAM,sBAAsB,IAC9G,CAAC;AAEA,IAAM,oBAAoB,CAAC,KAAe,UAA+B,+BAC9E,UAAU,KAAK,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