From 444012167b40862dd4d2112bb62e8371b050f79e Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Mon, 18 Oct 2021 13:46:13 +0300 Subject: [PATCH] Add message that we only support TS >= 4.1.0 --- integrationTests/ts/basic-test.ts | 2 +- package.json | 9 ++++++++- resources/build-npm.js | 16 +++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/integrationTests/ts/basic-test.ts b/integrationTests/ts/basic-test.ts index 76b92a0c0a1..ce36184837f 100644 --- a/integrationTests/ts/basic-test.ts +++ b/integrationTests/ts/basic-test.ts @@ -1,4 +1,4 @@ -import type { ExecutionResult } from 'graphql/execution'; +import type { ExecutionResult } from 'graphql/execution/execute'; import { graphqlSync } from 'graphql'; import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type'; diff --git a/package.json b/package.json index 160546618ea..953f2bfe027 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,14 @@ "private": true, "main": "index", "module": "index.mjs", - "types": "index.d.ts", + "types": "NotSupportedTSVersion.d.ts", + "typesVersions": { + ">=4.1.0": { + "*": ["index.d.ts"], + "*/*": ["*/index.d.ts"], + "*/*/*": ["*/*"] + } + }, "sideEffects": false, "homepage": "https://github.com/graphql/graphql-js", "bugs": { diff --git a/resources/build-npm.js b/resources/build-npm.js index 2e4b723dd04..f71ea32cdfd 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -18,6 +18,8 @@ if (require.main === module) { fs.rmSync('./npmDist', { recursive: true, force: true }); fs.mkdirSync('./npmDist'); + const packageJSON = buildPackageJSON(); + const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ }); for (const filepath of srcFiles) { const srcPath = path.join('./src', filepath); @@ -48,11 +50,23 @@ if (require.main === module) { 'Fail to generate `*.d.ts` files, please run `npm run check`', ); + assert(packageJSON.types, 'Missing "types".'); + const supportedTSVersions = Object.keys(packageJSON.typesVersions); + assert( + supportedTSVersions.length === 1, + 'Property "typesVersions" should have exactly one key.', + ); + // TODO: revisit once TS implements https://github.com/microsoft/TypeScript/issues/44795 + fs.writeFileSync( + path.join('./npmDist', packageJSON.types), + // Provoke syntax error to show this message + `"Package 'graphql' support only TS versions that are ${supportedTSVersions[0]}".`, + ); + fs.copyFileSync('./LICENSE', './npmDist/LICENSE'); fs.copyFileSync('./README.md', './npmDist/README.md'); // Should be done as the last step so only valid packages can be published - const packageJSON = buildPackageJSON(); writeGeneratedFile('./npmDist/package.json', JSON.stringify(packageJSON)); showDirStats('./npmDist');