Skip to content

Commit 7c6bf48

Browse files
Add message that we only support TS >= 4.1.0 (#3319)
1 parent ada5ee0 commit 7c6bf48

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Diff for: package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@
66
"private": true,
77
"main": "index",
88
"module": "index.mjs",
9-
"types": "index.d.ts",
9+
"types": "NotSupportedTSVersion.d.ts",
10+
"typesVersions": {
11+
">=4.1.0": {
12+
"*": [
13+
"index.d.ts"
14+
],
15+
"*/*": [
16+
"*/index.d.ts"
17+
],
18+
"*/*/*": [
19+
"*/*"
20+
]
21+
}
22+
},
1023
"sideEffects": false,
1124
"homepage": "https://github.com/graphql/graphql-js",
1225
"bugs": {

Diff for: resources/build-npm.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)