aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-28 15:07:46 +0100
committerChocobozzz <me@florianbigard.com>2021-12-28 15:10:55 +0100
commit81d02aac56d76227c094d40b17b29875d88417f4 (patch)
tree3d99f59bb4edc18cf15b1f7843617ff942a3ef96 /packages
parent10a72a7e617273cdbe897766f77f427eb57b689a (diff)
downloadPeerTube-81d02aac56d76227c094d40b17b29875d88417f4.tar.gz
PeerTube-81d02aac56d76227c094d40b17b29875d88417f4.tar.zst
PeerTube-81d02aac56d76227c094d40b17b29875d88417f4.zip
Fix types package dependencies
Diffstat (limited to 'packages')
-rw-r--r--packages/types/generate-package.ts38
1 files changed, 26 insertions, 12 deletions
diff --git a/packages/types/generate-package.ts b/packages/types/generate-package.ts
index 853989d68..125259bb4 100644
--- a/packages/types/generate-package.ts
+++ b/packages/types/generate-package.ts
@@ -1,8 +1,8 @@
1import { execSync } from 'child_process' 1import { execSync } from 'child_process'
2import depcheck, { PackageDependencies } from 'depcheck' 2import depcheck, { PackageDependencies } from 'depcheck'
3import { copyFile, readJson, remove, writeFile, writeJSON } from 'fs-extra' 3import { copyFile, readJson, remove, writeFile, writeJSON } from 'fs-extra'
4import { resolve } from 'path' 4import { join, resolve } from 'path'
5import { cwd } from 'process' 5import { root } from '../../shared/core-utils'
6 6
7if (!process.argv[2]) { 7if (!process.argv[2]) {
8 console.error('Need version as argument') 8 console.error('Need version as argument')
@@ -20,14 +20,14 @@ run()
20 }) 20 })
21 21
22async function run () { 22async function run () {
23 const typesPath = resolve(cwd(), './packages/types/') 23 const typesPath = __dirname
24 const typesDistPath = resolve(cwd(), typesPath, './dist/') 24 const typesDistPath = join(typesPath, 'dist')
25 const typesDistPackageJsonPath = resolve(typesDistPath, './package.json') 25 const typesDistPackageJsonPath = join(typesDistPath, 'package.json')
26 const typesDistGitIgnorePath = resolve(typesDistPath, './.gitignore') 26 const typesDistGitIgnorePath = join(typesDistPath, '.gitignore')
27 const mainPackageJson = await readJson(resolve(cwd(), './package.json')) 27 const mainPackageJson = await readJson(join(root(), 'package.json'))
28 const distTsConfigPath = resolve(cwd(), typesPath, './tsconfig.dist.json') 28 const distTsConfigPath = join(typesPath, 'tsconfig.dist.json')
29 const distTsConfig = await readJson(distTsConfigPath) 29 const distTsConfig = await readJson(distTsConfigPath)
30 const clientPackageJson = await readJson(resolve(cwd(), './client/package.json')) 30 const clientPackageJson = await readJson(join(root(), 'client', 'package.json'))
31 31
32 await remove(typesDistPath) 32 await remove(typesDistPath)
33 execSync('npm run tsc -- -b --verbose packages/types', { stdio: 'inherit' }) 33 execSync('npm run tsc -- -b --verbose packages/types', { stdio: 'inherit' })
@@ -35,8 +35,9 @@ async function run () {
35 35
36 const allDependencies = Object.assign( 36 const allDependencies = Object.assign(
37 mainPackageJson.dependencies, 37 mainPackageJson.dependencies,
38 mainPackageJson.devDepencies, 38 mainPackageJson.devDependencies,
39 clientPackageJson.dependencies 39 clientPackageJson.dependencies,
40 clientPackageJson.devDependencies
40 ) as PackageDependencies 41 ) as PackageDependencies
41 42
42 // https://github.com/depcheck/depcheck#api 43 // https://github.com/depcheck/depcheck#api
@@ -50,7 +51,20 @@ async function run () {
50 package: { dependencies: allDependencies } 51 package: { dependencies: allDependencies }
51 } 52 }
52 53
53 const { dependencies: unusedDependencies } = await depcheck(resolve(typesPath), depcheckOptions) 54 const result = await depcheck(typesDistPath, depcheckOptions)
55
56 if (Object.keys(result.invalidDirs).length !== 0) {
57 console.error('Invalid directories detected.', { invalidDirs: result.invalidDirs })
58 process.exit(-1)
59 }
60
61 if (Object.keys(result.invalidFiles).length !== 0) {
62 console.error('Invalid files detected.', { invalidFiles: result.invalidFiles })
63 process.exit(-1)
64 }
65
66 const unusedDependencies = result.dependencies
67
54 console.log(`Removing ${Object.keys(unusedDependencies).length} unused dependencies.`) 68 console.log(`Removing ${Object.keys(unusedDependencies).length} unused dependencies.`)
55 const dependencies = Object 69 const dependencies = Object
56 .keys(allDependencies) 70 .keys(allDependencies)