forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-tsconfig.mjs
executable file
·63 lines (56 loc) · 1.61 KB
/
validate-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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env node
/**
* External dependencies
*/
// @ts-ignore
import glob from 'glob';
import { dirname, basename } from 'path';
import stripJsonComments from 'strip-json-comments';
import { readFileSync } from 'fs';
let hasErrors = false;
const rootTsconfigJson = JSON.parse( readFileSync( 'tsconfig.json', 'utf8' ) );
const packagesWithTypes = glob
.sync( 'packages/*/tsconfig.json' )
.map( ( tsconfigPath ) => basename( dirname( tsconfigPath ) ) );
for ( const packageName of packagesWithTypes ) {
if (
! rootTsconfigJson.references.some(
( reference ) => reference.path === `packages/${ packageName }`
)
) {
console.error(
`Missing reference to "packages/${ packageName }" in root tsconfig.json`
);
hasErrors = true;
}
const packageJson = JSON.parse(
readFileSync( `packages/${ packageName }/package.json`, 'utf8' )
);
const tsconfigJson = JSON.parse(
stripJsonComments(
readFileSync( `packages/${ packageName }/tsconfig.json`, 'utf8' )
)
);
if ( packageJson.dependencies ) {
for ( const dependency of Object.keys( packageJson.dependencies ) ) {
if ( dependency.startsWith( '@wordpress/' ) ) {
const dependencyPackageName = dependency.slice(
'@wordpress/'.length
);
if (
packagesWithTypes.includes( dependencyPackageName ) &&
! tsconfigJson.references?.some(
( reference ) =>
reference.path === `../${ dependencyPackageName }`
)
) {
console.error(
`Missing reference to "../${ dependencyPackageName }" in packages/${ packageName }/tsconfig.json`
);
hasErrors = true;
}
}
}
}
}
process.exit( hasErrors ? 1 : 0 );