Skip to content

internal: use swc with ts-node #4457

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

Merged
merged 1 commit into from
Jul 13, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .mocharc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ check-leaks: true
extension:
- ts
node-option:
- 'loader=ts-node/esm/transpile-only'
- 'import=./resources/register-ts-node.js'
227 changes: 227 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
},
"scripts": {
"preversion": "bash -c '. ./resources/checkgit.sh && npm ci --ignore-scripts'",
"version": "node --loader ts-node/esm resources/gen-version.ts && npm test && git add src/version.ts",
"version": "node --import ./resources/register-ts-node.js resources/gen-version.ts && npm test && git add src/version.ts",
"fuzzonly": "mocha --full-trace src/**/__tests__/**/*-fuzz.ts",
"changelog": "node --loader ts-node/esm resources/gen-changelog.ts",
"benchmark": "node --loader ts-node/esm resources/benchmark.ts",
"changelog": "node --import ./resources/register-ts-node.js resources/gen-changelog.ts",
"benchmark": "node --import ./resources/register-ts-node.js resources/benchmark.ts",
"test": "npm run lint && npm run check && npm run testonly:cover && npm run prettier:check && npm run check:spelling && npm run check:integrations",
"lint": "eslint --cache --max-warnings 0 .",
"check": "tsc --pretty",
Expand All @@ -45,14 +45,15 @@
"precommit": "lint-staged",
"check:spelling": "cspell --cache --no-progress \"**/*\"",
"check:integrations": "mocha --full-trace resources/integration-test.ts",
"build:npm": "node --loader ts-node/esm resources/build-npm.ts",
"build:deno": "node --loader ts-node/esm resources/build-deno.ts",
"diff:npm": "node --loader ts-node/esm resources/diff-npm-package.ts",
"build:npm": "node --import ./resources/register-ts-node.js resources/build-npm.ts",
"build:deno": "node --import ./resources/register-ts-node.js resources/build-deno.ts",
"diff:npm": "node --import ./resources/register-ts-node.js resources/diff-npm-package.ts",
"gitpublish:npm": "bash ./resources/gitpublish.sh npm npmDist",
"gitpublish:deno": "bash ./resources/gitpublish.sh deno denoDist",
"prepare": "husky"
},
"devDependencies": {
"@swc/core": "^1.12.11",
"@types/chai": "5.0.1",
"@types/mocha": "10.0.10",
"@types/node": "22.10.1",
Expand Down
6 changes: 6 additions & 0 deletions resources/register-ts-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// node.js recommends this instead of using `node --loader ts-node/esm`
// eslint-disable-next-line n/no-unsupported-features/node-builtins
import { register } from 'node:module';
import { pathToFileURL } from 'node:url';

register('ts-node/esm', pathToFileURL('./'));
4 changes: 3 additions & 1 deletion src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,10 @@ function completeValue(
incrementalContext,
deferMap,
);
// c8 control statement technically placed a line early secondary to
// slight swc source mapping error (at least as compared to ts-node without swc)
/* c8 ignore next 7 */
}
/* c8 ignore next 6 */
// Not reachable, all possible output types have been considered.
invariant(
false,
Expand Down
4 changes: 3 additions & 1 deletion src/type/introspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({
}
if (isNonNullType(type)) {
return TypeKind.NON_NULL;
// c8 control statement technically placed a line early secondary to
// slight swc source mapping error (at least as compared to ts-node without swc)
/* c8 ignore next 4 */
}
/* c8 ignore next 3 */
// Not reachable, all possible types have been considered)
invariant(false, `Unexpected type: "${inspect(type)}".`);
},
Expand Down
4 changes: 3 additions & 1 deletion src/utilities/astFromValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ export function astFromValue(
}

throw new TypeError(`Cannot convert value to AST: ${inspect(coerced)}.`);
// c8 control statement technically placed a line early secondary to
// slight swc source mapping error (at least as compared to ts-node without swc)
/* c8 ignore next 4 */
}
/* c8 ignore next 3 */
// Not reachable, all possible types have been considered.
invariant(false, 'Unexpected input type: ' + inspect(type));
}
Expand Down
4 changes: 3 additions & 1 deletion src/utilities/findSchemaChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,10 @@ function typeKindName(type: GraphQLNamedType): string {
}
if (isInputObjectType(type)) {
return 'an Input type';
// c8 control statement technically placed a line early secondary to
// slight swc source mapping error (at least as compared to ts-node without swc)
/* c8 ignore next 4 */
}
/* c8 ignore next 3 */
// Not reachable, all possible types have been considered.
invariant(false, 'Unexpected type: ' + inspect(type));
}
Expand Down
4 changes: 3 additions & 1 deletion src/utilities/mapSchemaConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,10 @@ export function mapSchemaConfig(
}
if (isInputObjectType(type)) {
return mapInputObjectType(type);
// c8 control statement technically placed a line early secondary to
// slight swc source mapping error (at least as compared to ts-node without swc)
/* c8 ignore next 4 */
}
/* c8 ignore next 3 */
// Not reachable, all possible type definition nodes have been considered.
invariant(false, 'Unexpected type: ' + inspect(type));
}
Expand Down
4 changes: 3 additions & 1 deletion src/utilities/printSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ export function printType(type: GraphQLNamedType): string {
}
if (isInputObjectType(type)) {
return printInputObject(type);
// c8 control statement technically placed a line early secondary to
// slight swc source mapping error (at least as compared to ts-node without swc)
/* c8 ignore next 4 */
}
/* c8 ignore next 3 */
// Not reachable, all possible types have been considered.
invariant(false, 'Unexpected type: ' + inspect(type));
}
Expand Down
4 changes: 3 additions & 1 deletion src/utilities/valueFromAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ export function valueFromAST(
return; // Invalid: intentionally return no value.
}
return result;
// c8 control statement technically placed a line early secondary to
// slight swc source mapping error (at least as compared to ts-node without swc)
/* c8 ignore next 4 */
}
/* c8 ignore next 3 */
// Not reachable, all possible input types have been considered.
invariant(false, 'Unexpected input type: ' + inspect(type));
}
Expand Down
4 changes: 3 additions & 1 deletion src/validation/rules/PossibleTypeExtensionsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ function typeToExtKind(type: GraphQLNamedType): Kind {
}
if (isInputObjectType(type)) {
return Kind.INPUT_OBJECT_TYPE_EXTENSION;
// c8 control statement technically placed a line early secondary to
// slight swc source mapping error (at least as compared to ts-node without swc)
/* c8 ignore next 4 */
}
/* c8 ignore next 3 */
// Not reachable. All possible types have been considered
invariant(false, 'Unexpected type: ' + inspect(type));
}
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"isolatedModules": true,
"verbatimModuleSyntax": true,
"forceConsistentCasingInFileNames": true,

// Type Checking
// https://www.typescriptlang.org/tsconfig#Type_Checking_6248
"strict": true,
Expand All @@ -38,6 +37,6 @@
"allowSyntheticDefaultImports": true
},
"ts-node": {
"esm": true
"swc": true
}
}
Loading