forked from MetaMask/snaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify-tsconfig.mjs
28 lines (23 loc) · 1.24 KB
/
verify-tsconfig.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { promises as fs } from 'fs';
import pathUtils from 'path';
import { fileURLToPath } from 'url';
const cwd = pathUtils.dirname(fileURLToPath(import.meta.url))
// These are the packages we expect to _not_ be referenced in the root tsconfig.
const IGNORE_LIST = new Set(['examples', 'snaps-types']);
// Get reference paths from root tsconfig.json
const rootTsconfig = JSON.parse(await fs.readFile('./tsconfig.json', { encoding: 'utf8'}));
const rootTsconfigReferences = new Set(rootTsconfig.references.map(
({ path }) => path.split('/').pop()
))
// Get the names of all directories in the packages directory
const packagesPath = pathUtils.resolve(cwd, '../packages');
const packageDirNames = (await fs.readdir(packagesPath, { withFileTypes: true }))
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
// Any unreferenced package dirs must either be referenced or ignored
const unreferencedPackageDirs = packageDirNames.filter((name) => !rootTsconfigReferences.has(name) && !IGNORE_LIST.has(name))
if (unreferencedPackageDirs.length > 0) {
throw new Error(`Found unreferenced package directories not in ignore list:\n\n\t${
unreferencedPackageDirs.join('\n\t')
}\n\nEither reference or ignore the packages to continue.`)
}