From c9180df1761306058d4b6820d4f85c02cf720291 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Wed, 27 Oct 2021 14:57:52 +0300 Subject: [PATCH] Fix TS error caused by importing internal files directly Fixes #3338 Caused by #3319 --- integrationTests/ts/internalImports-test.ts | 8 ++++++++ integrationTests/ts/test.js | 6 ++++-- package.json | 9 +-------- resources/build-npm.js | 11 ++++++++--- 4 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 integrationTests/ts/internalImports-test.ts diff --git a/integrationTests/ts/internalImports-test.ts b/integrationTests/ts/internalImports-test.ts new file mode 100644 index 0000000000..62d9628df8 --- /dev/null +++ b/integrationTests/ts/internalImports-test.ts @@ -0,0 +1,8 @@ +import type { NameNode } from 'graphql/language'; + +// Parser class is internal API so so any changes to it are never considered breaking changes. +// We just want to test that we are able to import it. +import { Parser } from 'graphql/language/parser'; + +const parser = new Parser('foo'); +const ast: NameNode = parser.parseName(); diff --git a/integrationTests/ts/test.js b/integrationTests/ts/test.js index 158aee4cf6..b328fe160b 100644 --- a/integrationTests/ts/test.js +++ b/integrationTests/ts/test.js @@ -11,7 +11,9 @@ const tsVersions = Object.keys(dependencies) for (const version of tsVersions) { console.log(`Testing on ${version} ...`); + childProcess.execSync(tscPath(version), { stdio: 'inherit' }); +} - const tscPath = path.join(__dirname, 'node_modules', version, 'bin/tsc'); - childProcess.execSync(tscPath, { stdio: 'inherit' }); +function tscPath(version) { + return path.join(__dirname, 'node_modules', version, 'bin/tsc'); } diff --git a/package.json b/package.json index 7819938b4a..e4887467ea 100644 --- a/package.json +++ b/package.json @@ -6,17 +6,10 @@ "private": true, "main": "index", "module": "index.mjs", - "types": "NotSupportedTSVersion.d.ts", "typesVersions": { ">=4.1.0": { "*": [ - "index.d.ts" - ], - "*/*": [ - "*/index.d.ts" - ], - "*/*/*": [ - "*/*" + "*" ] } }, diff --git a/resources/build-npm.js b/resources/build-npm.js index f71ea32cdf..5ea2505852 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -50,18 +50,23 @@ if (require.main === module) { 'Fail to generate `*.d.ts` files, please run `npm run check`', ); - assert(packageJSON.types, 'Missing "types".'); + assert(packageJSON.types === undefined, 'Unexpected "types" in package.json'); 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 + // TODO: revisit once TS implements https://github.com/microsoft/TypeScript/issues/32166 + const notSupportedTSVersionFile = 'NotSupportedTSVersion.d.ts'; fs.writeFileSync( - path.join('./npmDist', packageJSON.types), + path.join('./npmDist', notSupportedTSVersionFile), // Provoke syntax error to show this message `"Package 'graphql' support only TS versions that are ${supportedTSVersions[0]}".`, ); + packageJSON.typesVersions = { + ...packageJSON.typesVersions, + '*': { '*': [notSupportedTSVersionFile] }, + }; fs.copyFileSync('./LICENSE', './npmDist/LICENSE'); fs.copyFileSync('./README.md', './npmDist/README.md');