@@ -18,6 +18,8 @@ if (require.main === module) {
1818 fs . rmSync ( './npmDist' , { recursive : true , force : true } ) ;
1919 fs . mkdirSync ( './npmDist' ) ;
2020
21+ const packageJSON = buildPackageJSON ( ) ;
22+
2123 const srcFiles = readdirRecursive ( './src' , { ignoreDir : / ^ _ _ .* _ _ $ / } ) ;
2224 for ( const filepath of srcFiles ) {
2325 const srcPath = path . join ( './src' , filepath ) ;
@@ -48,11 +50,23 @@ if (require.main === module) {
4850 'Fail to generate `*.d.ts` files, please run `npm run check`' ,
4951 ) ;
5052
53+ assert ( packageJSON . types , 'Missing "types".' ) ;
54+ const supportedTSVersions = Object . keys ( packageJSON . typesVersions ) ;
55+ assert (
56+ supportedTSVersions . length === 1 ,
57+ 'Property "typesVersions" should have exactly one key.' ,
58+ ) ;
59+ // TODO: revisit once TS implements https://github.com/microsoft/TypeScript/issues/44795
60+ fs . writeFileSync (
61+ path . join ( './npmDist' , packageJSON . types ) ,
62+ // Provoke syntax error to show this message
63+ `"Package 'graphql' support only TS versions that are ${ supportedTSVersions [ 0 ] } ".` ,
64+ ) ;
65+
5166 fs . copyFileSync ( './LICENSE' , './npmDist/LICENSE' ) ;
5267 fs . copyFileSync ( './README.md' , './npmDist/README.md' ) ;
5368
5469 // Should be done as the last step so only valid packages can be published
55- const packageJSON = buildPackageJSON ( ) ;
5670 writeGeneratedFile ( './npmDist/package.json' , JSON . stringify ( packageJSON ) ) ;
5771
5872 showDirStats ( './npmDist' ) ;
0 commit comments