Skip to content

Commit

Permalink
Fix TS error caused by importing internal files directly
Browse files Browse the repository at this point in the history
Fixes graphql#3338
Caused by graphql#3319
  • Loading branch information
IvanGoncharov committed Oct 27, 2021
1 parent a745361 commit c9180df
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
8 changes: 8 additions & 0 deletions 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();
6 changes: 4 additions & 2 deletions integrationTests/ts/test.js
Expand Up @@ -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');
}
9 changes: 1 addition & 8 deletions package.json
Expand Up @@ -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"
],
"*/*/*": [
"*/*"
"*"
]
}
},
Expand Down
11 changes: 8 additions & 3 deletions resources/build-npm.js
Expand Up @@ -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');
Expand Down

0 comments on commit c9180df

Please sign in to comment.