diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/types/generate-package.ts | 38 |
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 @@ | |||
1 | import { execSync } from 'child_process' | 1 | import { execSync } from 'child_process' |
2 | import depcheck, { PackageDependencies } from 'depcheck' | 2 | import depcheck, { PackageDependencies } from 'depcheck' |
3 | import { copyFile, readJson, remove, writeFile, writeJSON } from 'fs-extra' | 3 | import { copyFile, readJson, remove, writeFile, writeJSON } from 'fs-extra' |
4 | import { resolve } from 'path' | 4 | import { join, resolve } from 'path' |
5 | import { cwd } from 'process' | 5 | import { root } from '../../shared/core-utils' |
6 | 6 | ||
7 | if (!process.argv[2]) { | 7 | if (!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 | ||
22 | async function run () { | 22 | async 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) |