Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TS error caused by importing internal files directly #3339

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions integrationTests/ts/internalImports-test.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
],
"*/*/*": [
"*/*"
"*"
]
}
},
11 changes: 8 additions & 3 deletions resources/build-npm.js
Original file line number Diff line number Diff line change
@@ -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');