@xylabs/ts-scripts-yarn3 6.0.9 → 6.1.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 (161) hide show
  1. package/dist/actions/build.mjs +2 -2
  2. package/dist/actions/build.mjs.map +1 -1
  3. package/dist/actions/index.mjs +17 -2
  4. package/dist/actions/index.mjs.map +1 -1
  5. package/dist/actions/knip.mjs +113 -0
  6. package/dist/actions/knip.mjs.map +1 -0
  7. package/dist/actions/relint.mjs.map +1 -1
  8. package/dist/bin/xy.mjs +23 -2
  9. package/dist/bin/xy.mjs.map +1 -1
  10. package/dist/index.d.ts +3 -1
  11. package/dist/index.mjs +24 -2
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/types/actions/index.d.ts +1 -0
  14. package/dist/types/actions/index.d.ts.map +1 -1
  15. package/dist/types/actions/knip.d.ts +2 -0
  16. package/dist/types/actions/knip.d.ts.map +1 -0
  17. package/dist/types/actions/relint.d.ts.map +1 -1
  18. package/dist/types/xy/xyLintCommands.d.ts.map +1 -1
  19. package/dist/xy/index.mjs +23 -2
  20. package/dist/xy/index.mjs.map +1 -1
  21. package/dist/xy/xy.mjs +23 -2
  22. package/dist/xy/xy.mjs.map +1 -1
  23. package/dist/xy/xyBuildCommands.mjs +2 -2
  24. package/dist/xy/xyBuildCommands.mjs.map +1 -1
  25. package/dist/xy/xyLintCommands.mjs +21 -0
  26. package/dist/xy/xyLintCommands.mjs.map +1 -1
  27. package/package.json +10 -4
  28. package/spec/yarn/workspace/tsconfig.json +0 -3
  29. package/src/actions/build.ts +0 -34
  30. package/src/actions/clean-docs.ts +0 -12
  31. package/src/actions/clean-eslint.ts +0 -15
  32. package/src/actions/clean-jest.ts +0 -7
  33. package/src/actions/clean.ts +0 -26
  34. package/src/actions/compile-types.ts +0 -67
  35. package/src/actions/compile.ts +0 -67
  36. package/src/actions/copy-assets.ts +0 -70
  37. package/src/actions/cycle.ts +0 -15
  38. package/src/actions/dead.ts +0 -5
  39. package/src/actions/deploy-major.ts +0 -11
  40. package/src/actions/deploy-minor.ts +0 -11
  41. package/src/actions/deploy-next.ts +0 -11
  42. package/src/actions/deploy.ts +0 -11
  43. package/src/actions/deps.ts +0 -43
  44. package/src/actions/dupdeps.ts +0 -12
  45. package/src/actions/fix.ts +0 -6
  46. package/src/actions/gen-docs.ts +0 -26
  47. package/src/actions/gitignore-gen.ts +0 -5
  48. package/src/actions/gitlint-fix.ts +0 -27
  49. package/src/actions/gitlint.ts +0 -46
  50. package/src/actions/index.ts +0 -37
  51. package/src/actions/license.ts +0 -81
  52. package/src/actions/lint.ts +0 -61
  53. package/src/actions/npmignore-gen.ts +0 -5
  54. package/src/actions/package/clean-outputs.ts +0 -18
  55. package/src/actions/package/clean-typescript.ts +0 -18
  56. package/src/actions/package/clean.ts +0 -6
  57. package/src/actions/package/compile/XyConfig.ts +0 -60
  58. package/src/actions/package/compile/buildEntries.ts +0 -22
  59. package/src/actions/package/compile/compile.ts +0 -21
  60. package/src/actions/package/compile/compileTypes.ts +0 -13
  61. package/src/actions/package/compile/copyTypeFiles.ts +0 -38
  62. package/src/actions/package/compile/deepMerge.ts +0 -33
  63. package/src/actions/package/compile/getCompilerOptions.ts +0 -30
  64. package/src/actions/package/compile/index.ts +0 -6
  65. package/src/actions/package/compile/inputs.ts +0 -6
  66. package/src/actions/package/compile/packageCompileTsc.ts +0 -67
  67. package/src/actions/package/compile/packageCompileTscTypes.ts +0 -68
  68. package/src/actions/package/compile/packageCompileTsup.ts +0 -154
  69. package/src/actions/package/copy-assets.ts +0 -46
  70. package/src/actions/package/deps.ts +0 -144
  71. package/src/actions/package/gen-docs.ts +0 -126
  72. package/src/actions/package/index.ts +0 -10
  73. package/src/actions/package/lint.ts +0 -86
  74. package/src/actions/package/publint.ts +0 -75
  75. package/src/actions/package/recompile.ts +0 -6
  76. package/src/actions/publint.ts +0 -26
  77. package/src/actions/rebuild.ts +0 -13
  78. package/src/actions/recompile.ts +0 -81
  79. package/src/actions/reinstall.ts +0 -29
  80. package/src/actions/relint.ts +0 -76
  81. package/src/actions/retest.ts +0 -8
  82. package/src/actions/sonar.ts +0 -5
  83. package/src/actions/statics.ts +0 -13
  84. package/src/actions/test.ts +0 -5
  85. package/src/actions/up.ts +0 -5
  86. package/src/actions/updo.ts +0 -9
  87. package/src/actions/upplug.ts +0 -10
  88. package/src/actions/upyarn.ts +0 -5
  89. package/src/actions/yarn3only.ts +0 -9
  90. package/src/bin/package/build-only.ts +0 -16
  91. package/src/bin/package/build.ts +0 -16
  92. package/src/bin/package/clean-outputs.ts +0 -5
  93. package/src/bin/package/clean-typescript.ts +0 -5
  94. package/src/bin/package/clean.ts +0 -12
  95. package/src/bin/package/compile-only.ts +0 -12
  96. package/src/bin/package/compile-tsup.ts +0 -12
  97. package/src/bin/package/compile-types.ts +0 -16
  98. package/src/bin/package/compile.ts +0 -16
  99. package/src/bin/package/copy-assets-cjs.ts +0 -12
  100. package/src/bin/package/copy-assets-esm.ts +0 -12
  101. package/src/bin/package/deps.ts +0 -12
  102. package/src/bin/package/fix.ts +0 -16
  103. package/src/bin/package/gen-docs.ts +0 -12
  104. package/src/bin/package/lint.ts +0 -16
  105. package/src/bin/package/publint.ts +0 -13
  106. package/src/bin/package/recompile.ts +0 -12
  107. package/src/bin/package/relint.ts +0 -16
  108. package/src/bin/xy.ts +0 -12
  109. package/src/index.ts +0 -4
  110. package/src/lib/checkResult.ts +0 -12
  111. package/src/lib/createBuildConfig.ts +0 -37
  112. package/src/lib/defaultBuildConfig.ts +0 -18
  113. package/src/lib/deleteGlob.ts +0 -13
  114. package/src/lib/dependencies/DuplicateDetector.ts +0 -97
  115. package/src/lib/dependencies/detectDuplicateDependencies.ts +0 -41
  116. package/src/lib/dependencies/index.ts +0 -2
  117. package/src/lib/file/ReadFileSyncOptions.ts +0 -6
  118. package/src/lib/file/constants.ts +0 -2
  119. package/src/lib/file/fileLines.ts +0 -25
  120. package/src/lib/file/index.ts +0 -4
  121. package/src/lib/file/tryReadFileSync.ts +0 -9
  122. package/src/lib/generateIgnoreFiles.ts +0 -31
  123. package/src/lib/index.ts +0 -20
  124. package/src/lib/jsonFormatters.ts +0 -6
  125. package/src/lib/loadConfig.ts +0 -19
  126. package/src/lib/parsedPackageJSON.ts +0 -7
  127. package/src/lib/processEx.ts +0 -27
  128. package/src/lib/runSteps.ts +0 -40
  129. package/src/lib/runStepsAsync.ts +0 -53
  130. package/src/lib/runXy.ts +0 -8
  131. package/src/lib/runXyWithWarning.ts +0 -9
  132. package/src/lib/safeExit.ts +0 -29
  133. package/src/lib/string/empty.ts +0 -2
  134. package/src/lib/string/index.ts +0 -2
  135. package/src/lib/string/union.ts +0 -1
  136. package/src/lib/withErrnoException.ts +0 -7
  137. package/src/lib/withError.ts +0 -8
  138. package/src/lib/yarn/index.ts +0 -3
  139. package/src/lib/yarn/isYarnVersionOrGreater.ts +0 -16
  140. package/src/lib/yarn/workspace/Workspace.ts +0 -4
  141. package/src/lib/yarn/workspace/index.ts +0 -3
  142. package/src/lib/yarn/workspace/yarnWorkspace.ts +0 -8
  143. package/src/lib/yarn/workspace/yarnWorkspaces.ts +0 -21
  144. package/src/lib/yarn/yarnInitCwd.ts +0 -4
  145. package/src/loadPackageConfig.ts +0 -13
  146. package/src/types.d.ts +0 -26
  147. package/src/xy/index.ts +0 -7
  148. package/src/xy/param.ts +0 -5
  149. package/src/xy/xy.ts +0 -20
  150. package/src/xy/xyBuildCommands.ts +0 -127
  151. package/src/xy/xyCommonCommands.ts +0 -167
  152. package/src/xy/xyDeployCommands.ts +0 -53
  153. package/src/xy/xyInstallCommands.ts +0 -80
  154. package/src/xy/xyLintCommands.ts +0 -92
  155. package/src/xy/xyParseOptions.ts +0 -58
  156. package/tsconfig.build.json +0 -29
  157. package/tsconfig.json +0 -4
  158. package/tsconfig.test.json +0 -4
  159. package/tsup.config.ts +0 -16
  160. package/types/node-cmd.d.ts +0 -1
  161. package/xy.config.ts +0 -3
@@ -1,5 +0,0 @@
1
- import { runSteps } from '../lib/index.ts'
2
-
3
- export const sonar = () => {
4
- return runSteps('Sonar', [['yarn', ['eslint', '-c', 'sonar.eslintrc', '.']]])
5
- }
@@ -1,13 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- import { detectDuplicateDependencies, parsedPackageJSON } from '../lib/index.ts'
4
-
5
- const DefaultDependencies = ['axios', '@xylabs/pixel', 'react', 'graphql', 'react-router', '@mui/material', '@mui/system']
6
-
7
- export const statics = () => {
8
- console.log(chalk.green('Check Required Static Dependencies'))
9
-
10
- const statics = parsedPackageJSON()?.xy?.deps?.statics
11
-
12
- return detectDuplicateDependencies(statics, DefaultDependencies)
13
- }
@@ -1,5 +0,0 @@
1
- import { runSteps } from '../lib/index.ts'
2
-
3
- export const test = () => {
4
- return runSteps('Test', [['yarn', ['vitest', '.']]])
5
- }
package/src/actions/up.ts DELETED
@@ -1,5 +0,0 @@
1
- import { runSteps } from '../lib/index.ts'
2
-
3
- export const up = () => {
4
- return runSteps('Up', [['yarn', 'outdated']])
5
- }
@@ -1,9 +0,0 @@
1
- import { runSteps } from '../lib/index.ts'
2
-
3
- export const updo = () => {
4
- return runSteps('Updo', [
5
- ['yarn', 'install'],
6
- ['yarn', 'upgrade-interactive'],
7
- ['yarn', 'dedupe'],
8
- ])
9
- }
@@ -1,10 +0,0 @@
1
- import { runSteps } from '../lib/index.ts'
2
-
3
- export const updateYarnPlugins = () => {
4
- return runSteps('Update Yarn Plugins', [
5
- ['yarn', ['plugin', 'import', 'https://mskelton.dev/yarn-outdated/v3']],
6
- ['yarn', ['plugin', 'import', 'version']],
7
- ['yarn', ['plugin', 'import', 'interactive-tools']],
8
- ['yarn', ['plugin', 'import', 'workspace-tools']],
9
- ])
10
- }
@@ -1,5 +0,0 @@
1
- import { runSteps } from '../lib/index.ts'
2
-
3
- export const updateYarnVersion = () => {
4
- return runSteps('Update Yarn Version', [['yarn', ['set', 'version', 'latest']]])
5
- }
@@ -1,9 +0,0 @@
1
- import { isYarnVersionOrGreater, processEx } from '../lib/index.ts'
2
-
3
- export const yarn3Only = () => {
4
- const [valid, version] = isYarnVersionOrGreater(3)
5
- if (!valid) {
6
- processEx(`Invalid Yarn version [${version}]`)
7
- }
8
- return 0
9
- }
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageCompile } from '../../actions/index.ts'
6
-
7
- packageCompile({ verbose: true, publint: false })
8
- .then((value) => {
9
- if (value) {
10
- process.exit(value)
11
- }
12
- })
13
- .catch((reason) => {
14
- console.error(chalk.red(reason))
15
- process.exit(-1)
16
- })
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageCompile } from '../../actions/index.ts'
6
-
7
- packageCompile({ verbose: false, publint: true })
8
- .then((value) => {
9
- if (value) {
10
- process.exit(value)
11
- }
12
- })
13
- .catch((reason) => {
14
- console.error(chalk.red(reason))
15
- process.exit(-1)
16
- })
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { packageCleanOutputs } from '../../actions/index.ts'
4
-
5
- process.exitCode = packageCleanOutputs()
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { packageCleanTypescript } from '../../actions/index.ts'
4
-
5
- process.exitCode = packageCleanTypescript()
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { packageClean } from '../../actions/index.ts'
4
-
5
- packageClean()
6
- .then(() => {
7
- process.exit(0)
8
- })
9
- .catch((error) => {
10
- console.error(error)
11
- process.exit(1)
12
- })
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageCompile } from '../../actions/index.ts'
6
-
7
- packageCompile({ verbose: true, publint: false })
8
- .then(value => (process.exitCode = value))
9
- .catch((reason) => {
10
- console.error(chalk.red(reason))
11
- process.exitCode = 1
12
- })
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageCompileTsup } from '../../actions/index.ts'
6
-
7
- packageCompileTsup({ verbose: true })
8
- .then(value => (process.exitCode = value))
9
- .catch((reason) => {
10
- console.error(chalk.red(reason))
11
- process.exitCode = 1
12
- })
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageCompileTypes } from '../../actions/index.ts'
6
-
7
- packageCompileTypes({ verbose: true })
8
- .then((value) => {
9
- if (value) {
10
- process.exit(value)
11
- }
12
- })
13
- .catch((reason) => {
14
- console.error(chalk.red(reason))
15
- process.exit(-1)
16
- })
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageCompile } from '../../actions/index.ts'
6
-
7
- packageCompile({ verbose: false })
8
- .then((value) => {
9
- if (value) {
10
- process.exit(value)
11
- }
12
- })
13
- .catch((reason) => {
14
- console.error(chalk.red(reason))
15
- process.exit(-1)
16
- })
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageCopyAssets } from '../../actions/index.ts'
6
-
7
- packageCopyAssets({ target: 'cjs' })
8
- .then(value => (process.exitCode = value))
9
- .catch((reason) => {
10
- console.error(chalk.red(reason))
11
- process.exitCode = 1
12
- })
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageCopyAssets } from '../../actions/index.ts'
6
-
7
- packageCopyAssets({ target: 'esm' })
8
- .then(value => (process.exitCode = value))
9
- .catch((reason) => {
10
- console.error(chalk.red(reason))
11
- process.exitCode = 1
12
- })
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageDeps } from '../../actions/index.ts'
6
-
7
- packageDeps()
8
- .then(value => (process.exitCode = value))
9
- .catch((ex: Error) => {
10
- console.error(`Deps Failed: ${chalk.red(ex)}`)
11
- process.exitCode = 0
12
- })
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageLint } from '../../actions/index.ts'
6
-
7
- packageLint(true)
8
- .then((value) => {
9
- if (value) {
10
- process.exit(value)
11
- }
12
- })
13
- .catch((reason) => {
14
- console.error(chalk.red(reason))
15
- process.exit(-1)
16
- })
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { packageGenDocs } from '../../actions/index.ts'
4
-
5
- packageGenDocs()
6
- .then(() => {
7
- process.exit(0)
8
- })
9
- .catch((error) => {
10
- console.error(error)
11
- process.exit(1)
12
- })
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageLint } from '../../actions/index.ts'
6
-
7
- packageLint()
8
- .then((value) => {
9
- if (value) {
10
- process.exit(value)
11
- }
12
- })
13
- .catch((reason) => {
14
- console.error(chalk.red(reason))
15
- process.exit(-1)
16
- })
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packagePublint } from '../../actions/index.ts'
6
-
7
- packagePublint()
8
- .then(value => (process.exitCode = value))
9
- .catch((ex: Error) => {
10
- console.error(`Publint Failed: ${chalk.red(ex)}`)
11
- console.error(chalk.gray(ex.stack))
12
- process.exitCode = -1
13
- })
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageRecompile } from '../../actions/index.ts'
6
-
7
- packageRecompile()
8
- .then(value => (process.exitCode = value))
9
- .catch((reason) => {
10
- console.error(chalk.red(reason))
11
- process.exitCode = 1
12
- })
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk'
4
-
5
- import { packageLint } from '../../actions/index.ts'
6
-
7
- packageLint(false, false, true)
8
- .then((value) => {
9
- if (value) {
10
- process.exit(value)
11
- }
12
- })
13
- .catch((reason) => {
14
- console.error(chalk.red(reason))
15
- process.exit(-1)
16
- })
package/src/bin/xy.ts DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { xy } from '../xy/index.ts'
4
-
5
- xy()
6
- .then(() => {
7
- process.exit(0)
8
- })
9
- .catch((error) => {
10
- console.error(error)
11
- process.exit(1)
12
- })
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './actions/index.ts'
2
- export * from './lib/index.ts'
3
- export * from './loadPackageConfig.ts'
4
- export * from './xy/index.ts'
@@ -1,12 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- export const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {
4
- if (result) {
5
- const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'
6
- const chalkFunc = level === 'error' ? chalk.red : chalk.yellow
7
- console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))
8
- if (exitOnFail) {
9
- process.exit(result)
10
- }
11
- }
12
- }
@@ -1,37 +0,0 @@
1
- import { readFileSync } from 'node:fs'
2
-
3
- import { defaultBuildConfig } from './defaultBuildConfig.ts'
4
-
5
- const getGeneralTypescriptConfig = (location: string) => {
6
- let generalConfig: string | undefined
7
- try {
8
- generalConfig = readFileSync(`${location}/tsconfig.json`, { encoding: 'utf8' })
9
- } catch {
10
- return false
11
- }
12
- return JSON.parse(generalConfig)
13
- }
14
-
15
- export const createBuildConfig = (
16
- location: string,
17
- module: 'ESNext' | 'CommonJS',
18
- target: 'ESNext' | 'ES6',
19
- outDirSuffix: string,
20
- ): Record<string, unknown> | undefined => {
21
- const generalConfigObject = getGeneralTypescriptConfig(location)
22
- if (generalConfigObject === false) {
23
- return undefined
24
- }
25
- return {
26
- ...generalConfigObject,
27
- compilerOptions: {
28
- ...defaultBuildConfig.compilerOptions,
29
- ...generalConfigObject.compilerOptions,
30
- module,
31
- outDir: `./${generalConfigObject.compilerOptions?.outDir ?? 'dist'}/${outDirSuffix}`,
32
- target,
33
- },
34
- exclude: [...(generalConfigObject.exclude ?? []), ...defaultBuildConfig.exclude],
35
- include: [...(generalConfigObject.include ?? []), ...defaultBuildConfig.include],
36
- }
37
- }
@@ -1,18 +0,0 @@
1
- export const defaultBuildConfig = {
2
- compilerOptions: {
3
- rootDir: 'src',
4
- rootDirs: ['package.json'],
5
- },
6
- exclude: [
7
- '**/build',
8
- '**/dist',
9
- '**/node_modules',
10
- '**/*.spec.*',
11
- '**/*.spec',
12
- '**/*.stories.*',
13
- '**/*.example.*',
14
- '**/spec/*',
15
- '**/stories/*',
16
- ],
17
- include: ['src'],
18
- }
@@ -1,13 +0,0 @@
1
- import fs from 'node:fs'
2
-
3
- import { glob } from 'glob'
4
-
5
- export const deleteGlob = (globPath: string) => {
6
- // Find all files matching the glob pattern
7
- const files = glob.sync(globPath)
8
-
9
- // Remove each file or directory
10
- for (const file of files) {
11
- fs.rmSync(file, { recursive: true, force: true })
12
- }
13
- }
@@ -1,97 +0,0 @@
1
- import { EOL } from 'node:os'
2
-
3
- import chalk from 'chalk'
4
-
5
- import { multiLineToJSONArray } from '../jsonFormatters.ts'
6
-
7
- interface ChildFields {
8
- descriptor: string
9
- locator: string
10
- }
11
-
12
- const trimVirtualMeta = (value: string): string => {
13
- const virtualParts = value.split('virtual:')
14
- if (virtualParts.length > 1) {
15
- const hashParts = virtualParts[1].split('#')
16
- return virtualParts[0] + hashParts[1]
17
- } else {
18
- return value
19
- }
20
- }
21
-
22
- const trimObjectDependencyVirtualMeta = (obj: Record<string, ChildFields>): Record<string, ChildFields> => {
23
- const resultObj: Record<string, ChildFields> = {}
24
- for (const [key, value] of Object.entries(obj)) {
25
- resultObj[trimVirtualMeta(key)] = {
26
- descriptor: trimVirtualMeta(value.descriptor),
27
- locator: trimVirtualMeta(value.locator),
28
- }
29
- }
30
- return resultObj
31
- }
32
-
33
- const trimDependencyVirtualMeta = (dependencies: DependencyEntries): DependencyEntries => {
34
- return dependencies.map((dependency) => {
35
- return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) }
36
- })
37
- }
38
-
39
- interface DependencyEntry {
40
- children: Record<string, ChildFields>
41
- value: string
42
- }
43
-
44
- type DependencyEntries = DependencyEntry[]
45
-
46
- interface Results {
47
- currentVersion: string | undefined
48
- dependency: string
49
- duplicateVersions: string[]
50
- }
51
-
52
- export class DuplicateDetector {
53
- private dependency: string
54
- private dependencyEntries: DependencyEntries
55
-
56
- constructor(output: string, dependency: string) {
57
- this.dependency = dependency
58
- this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output))
59
- }
60
-
61
- detect() {
62
- // eslint-disable-next-line unicorn/no-array-reduce
63
- const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency))
64
- if (result.duplicateVersions.length > 0) {
65
- console.log(chalk.yellow(`${EOL}Duplicates found for: ${this.dependency}`))
66
- const duplicateVersions = result.duplicateVersions.toString().replaceAll(',', `${EOL} `)
67
- console.log(chalk.grey(` ${duplicateVersions}`, EOL))
68
- return 1
69
- } else {
70
- console.log(`${this.dependency} - OK`)
71
- return 0
72
- }
73
- }
74
-
75
- private detectReducer(acc: Results, entry: DependencyEntry) {
76
- const version = Object.entries(entry.children).map(([k]) => k)[0]
77
-
78
- if (!acc.currentVersion) {
79
- acc.currentVersion = version
80
- return acc
81
- }
82
-
83
- if (acc.currentVersion && acc.currentVersion !== version && !version.includes('@virtual:')) {
84
- // if first duplicate, push the current version as the first duplicate
85
- if (acc.duplicateVersions.length === 0) {
86
- acc.duplicateVersions.push(acc.currentVersion)
87
- }
88
- acc.duplicateVersions.push(version)
89
- acc.duplicateVersions = [...new Set(acc.duplicateVersions)]
90
- }
91
- return acc
92
- }
93
-
94
- private resultsFactory = (dependency: string): Results => ({
95
- currentVersion: undefined, dependency, duplicateVersions: [],
96
- })
97
- }
@@ -1,41 +0,0 @@
1
- import { execSync } from 'node:child_process'
2
-
3
- import { safeExit } from '../safeExit.ts'
4
- import { DuplicateDetector } from './DuplicateDetector.ts'
5
-
6
- export const detectDuplicateDependencies = (depsFromPackageJSON?: string[], DefaultDependencies?: string[]) => {
7
- let exitCode = 0
8
-
9
- const dependencies = depsFromPackageJSON?.length ? depsFromPackageJSON : DefaultDependencies
10
-
11
- return safeExit(() => {
12
- if (dependencies) {
13
- for (const dependency of dependencies) {
14
- let output: string
15
-
16
- try {
17
- const cmd = `yarn why ${dependency} --json`
18
- output = execSync(cmd).toString()
19
- } catch (e) {
20
- console.error(`Error running yarn why: ${e}`)
21
- exitCode = 1
22
- continue
23
- }
24
-
25
- if (output) {
26
- exitCode = new DuplicateDetector(output, dependency).detect()
27
- } else {
28
- console.log(`${dependency} - N/A`)
29
- if (depsFromPackageJSON) {
30
- exitCode = 1
31
- console.log(`🚨 Library ${dependency} was requested in package.json but not found`)
32
- }
33
- }
34
- }
35
- return exitCode
36
- } else {
37
- console.log('🚨 No dependencies where passed')
38
- return exitCode
39
- }
40
- })
41
- }
@@ -1,2 +0,0 @@
1
- export * from './detectDuplicateDependencies.ts'
2
- export * from './DuplicateDetector.ts'
@@ -1,6 +0,0 @@
1
- export type ReadFileSyncOptions = BufferEncoding | {
2
- encoding: BufferEncoding
3
- flags?: string
4
- }
5
-
6
- export const defaultReadFileSyncOptions: ReadFileSyncOptions = { encoding: 'utf8' }
@@ -1,2 +0,0 @@
1
- export const WINDOWS_NEWLINE_REGEX = /\r\n/g
2
- export const CROSS_PLATFORM_NEWLINE = '\n'
@@ -1,25 +0,0 @@
1
- import type { PathLike, WriteFileOptions } from 'node:fs'
2
- import {
3
- existsSync, readFileSync,
4
- writeFileSync,
5
- } from 'node:fs'
6
-
7
- import { notEmpty } from '../string/index.ts'
8
- import { CROSS_PLATFORM_NEWLINE, WINDOWS_NEWLINE_REGEX } from './constants.ts'
9
- import type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'
10
- import { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'
11
-
12
- export const readLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>
13
- existsSync(uri)
14
- ? readFileSync(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE)
15
- : []
16
-
17
- export const readNonEmptyLines = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string[] =>
18
- readLines(uri, options).filter(notEmpty)
19
-
20
- export const writeLines = (uri: PathLike, lines: string[], options: WriteFileOptions = defaultReadFileSyncOptions) => {
21
- const existing = existsSync(uri) ? readFileSync(uri, options) : undefined
22
- const desired = lines.join(CROSS_PLATFORM_NEWLINE)
23
- // Check if the file is different before writing
24
- if (existing !== desired) writeFileSync(uri, desired, options)
25
- }
@@ -1,4 +0,0 @@
1
- export * from './constants.ts'
2
- export * from './fileLines.ts'
3
- export * from './ReadFileSyncOptions.ts'
4
- export * from './tryReadFileSync.ts'
@@ -1,9 +0,0 @@
1
- import type { PathLike } from 'node:fs'
2
- import { existsSync, readFileSync } from 'node:fs'
3
-
4
- import type { ReadFileSyncOptions } from './ReadFileSyncOptions.ts'
5
- import { defaultReadFileSyncOptions } from './ReadFileSyncOptions.ts'
6
-
7
- export const tryReadFileSync = (uri: PathLike, options: ReadFileSyncOptions = defaultReadFileSyncOptions): string | undefined => {
8
- return existsSync(uri) ? readFileSync(uri, options) : undefined
9
- }