-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic tsconfig.json validation (#47595)
* Add validate-tsconfig script * Fix lint errors * Add tsconfig linting to lint-staged
- Loading branch information
1 parent
f12ecd5
commit 46a938a
Showing
12 changed files
with
142 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 ); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters