Skip to content

Commit c2435fd

Browse files
Fix TS error caused by importing internal files directly (#3339)
1 parent a745361 commit c2435fd

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { NameNode } from 'graphql/language';
2+
3+
// Parser class is internal API so so any changes to it are never considered breaking changes.
4+
// We just want to test that we are able to import it.
5+
import { Parser } from 'graphql/language/parser';
6+
7+
const parser = new Parser('foo');
8+
const ast: NameNode = parser.parseName();

integrationTests/ts/test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const tsVersions = Object.keys(dependencies)
1111

1212
for (const version of tsVersions) {
1313
console.log(`Testing on ${version} ...`);
14+
childProcess.execSync(tscPath(version), { stdio: 'inherit' });
15+
}
1416

15-
const tscPath = path.join(__dirname, 'node_modules', version, 'bin/tsc');
16-
childProcess.execSync(tscPath, { stdio: 'inherit' });
17+
function tscPath(version) {
18+
return path.join(__dirname, 'node_modules', version, 'bin/tsc');
1719
}

package.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@
66
"private": true,
77
"main": "index",
88
"module": "index.mjs",
9-
"types": "NotSupportedTSVersion.d.ts",
109
"typesVersions": {
1110
">=4.1.0": {
1211
"*": [
13-
"index.d.ts"
14-
],
15-
"*/*": [
16-
"*/index.d.ts"
17-
],
18-
"*/*/*": [
19-
"*/*"
12+
"*"
2013
]
2114
}
2215
},

resources/build-npm.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,23 @@ if (require.main === module) {
5050
'Fail to generate `*.d.ts` files, please run `npm run check`',
5151
);
5252

53-
assert(packageJSON.types, 'Missing "types".');
53+
assert(packageJSON.types === undefined, 'Unexpected "types" in package.json');
5454
const supportedTSVersions = Object.keys(packageJSON.typesVersions);
5555
assert(
5656
supportedTSVersions.length === 1,
5757
'Property "typesVersions" should have exactly one key.',
5858
);
59-
// TODO: revisit once TS implements https://github.com/microsoft/TypeScript/issues/44795
59+
// TODO: revisit once TS implements https://github.com/microsoft/TypeScript/issues/32166
60+
const notSupportedTSVersionFile = 'NotSupportedTSVersion.d.ts';
6061
fs.writeFileSync(
61-
path.join('./npmDist', packageJSON.types),
62+
path.join('./npmDist', notSupportedTSVersionFile),
6263
// Provoke syntax error to show this message
6364
`"Package 'graphql' support only TS versions that are ${supportedTSVersions[0]}".`,
6465
);
66+
packageJSON.typesVersions = {
67+
...packageJSON.typesVersions,
68+
'*': { '*': [notSupportedTSVersionFile] },
69+
};
6570

6671
fs.copyFileSync('./LICENSE', './npmDist/LICENSE');
6772
fs.copyFileSync('./README.md', './npmDist/README.md');

0 commit comments

Comments
 (0)