Skip to content

Commit a936836

Browse files
committed
internal: use swc with ts-node (graphql#4457)
this currently requires a few changes to c8 control statements to ensure complete code coverage presumably secondary to a bug/difference between how tsc and swc handle source mapping also: use --import with register script instead of --loader to silence node.js warning regarding --loader
1 parent 1481aae commit a936836

File tree

13 files changed

+274
-17
lines changed

13 files changed

+274
-17
lines changed

.mocharc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ check-leaks: true
44
extension:
55
- ts
66
node-option:
7-
- 'loader=ts-node/esm/transpile-only'
7+
- 'import=./resources/register-ts-node.js'

package-lock.json

Lines changed: 228 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
},
3131
"scripts": {
3232
"preversion": "bash -c '. ./resources/checkgit.sh && npm ci --ignore-scripts'",
33-
"version": "node --loader ts-node/esm resources/gen-version.ts && npm test && git add src/version.ts",
33+
"version": "node --import ./resources/register-ts-node.js resources/gen-version.ts && npm test && git add src/version.ts",
3434
"fuzzonly": "mocha --full-trace src/**/__tests__/**/*-fuzz.ts",
35-
"changelog": "node --loader ts-node/esm resources/gen-changelog.ts",
36-
"benchmark": "node --loader ts-node/esm resources/benchmark.ts",
35+
"changelog": "node --import ./resources/register-ts-node.js resources/gen-changelog.ts",
36+
"benchmark": "node --import ./resources/register-ts-node.js resources/benchmark.ts",
3737
"test": "npm run lint && npm run check && npm run testonly:cover && npm run prettier:check && npm run check:spelling && npm run check:integrations",
3838
"lint": "eslint --cache --max-warnings 0 .",
3939
"check": "tsc --pretty",
@@ -45,14 +45,15 @@
4545
"precommit": "lint-staged",
4646
"check:spelling": "cspell --cache --no-progress \"**/*\"",
4747
"check:integrations": "mocha --full-trace resources/integration-test.ts",
48-
"build:npm": "node --loader ts-node/esm resources/build-npm.ts",
49-
"build:deno": "node --loader ts-node/esm resources/build-deno.ts",
50-
"diff:npm": "node --loader ts-node/esm resources/diff-npm-package.ts",
48+
"build:npm": "node --import ./resources/register-ts-node.js resources/build-npm.ts",
49+
"build:deno": "node --import ./resources/register-ts-node.js resources/build-deno.ts",
50+
"diff:npm": "node --import ./resources/register-ts-node.js resources/diff-npm-package.ts",
5151
"gitpublish:npm": "bash ./resources/gitpublish.sh npm npmDist",
5252
"gitpublish:deno": "bash ./resources/gitpublish.sh deno denoDist",
5353
"prepare": "husky"
5454
},
5555
"devDependencies": {
56+
"@swc/core": "^1.12.11",
5657
"@types/chai": "5.0.1",
5758
"@types/mocha": "10.0.10",
5859
"@types/node": "22.10.1",

resources/register-ts-node.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// node.js recommends this instead of using `node --loader ts-node/esm`
2+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
3+
import { register } from 'node:module';
4+
import { pathToFileURL } from 'node:url';
5+
6+
register('ts-node/esm', pathToFileURL('./'));

src/execution/execute.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,10 @@ function completeValue(
856856
path,
857857
result,
858858
);
859-
} /* c8 ignore next 6 */
859+
// c8 control statement technically placed a line early secondary to
860+
// slight swc source mapping error (at least as compared to ts-node without swc)
861+
/* c8 ignore next 7 */
862+
}
860863
// Not reachable, all possible output types have been considered.
861864
invariant(
862865
false,

src/type/introspection.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({
240240
}
241241
if (isNonNullType(type)) {
242242
return TypeKind.NON_NULL;
243-
} /* c8 ignore next 3 */
243+
// c8 control statement technically placed a line early secondary to
244+
// slight swc source mapping error (at least as compared to ts-node without swc)
245+
/* c8 ignore next 4 */
246+
}
244247
// Not reachable, all possible types have been considered)
245248
invariant(false, `Unexpected type: "${inspect(type)}".`);
246249
},

src/utilities/astFromValue.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ export function astFromValue(
137137
}
138138

139139
throw new TypeError(`Cannot convert value to AST: ${inspect(coerced)}.`);
140-
} /* c8 ignore next 3 */
140+
// c8 control statement technically placed a line early secondary to
141+
// slight swc source mapping error (at least as compared to ts-node without swc)
142+
/* c8 ignore next 4 */
143+
}
141144
// Not reachable, all possible types have been considered.
142145
invariant(false, 'Unexpected input type: ' + inspect(type));
143146
}

src/utilities/findSchemaChanges.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,10 @@ function typeKindName(type: GraphQLNamedType): string {
715715
}
716716
if (isInputObjectType(type)) {
717717
return 'an Input type';
718-
} /* c8 ignore next 3 */
718+
// c8 control statement technically placed a line early secondary to
719+
// slight swc source mapping error (at least as compared to ts-node without swc)
720+
/* c8 ignore next 4 */
721+
}
719722
// Not reachable, all possible types have been considered.
720723
invariant(false, 'Unexpected type: ' + inspect(type));
721724
}

src/utilities/mapSchemaConfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,10 @@ export function mapSchemaConfig(
280280
}
281281
if (isInputObjectType(type)) {
282282
return mapInputObjectType(type);
283+
// c8 control statement technically placed a line early secondary to
284+
// slight swc source mapping error (at least as compared to ts-node without swc)
285+
/* c8 ignore next 4 */
283286
}
284-
/* c8 ignore next 3 */
285287
// Not reachable, all possible type definition nodes have been considered.
286288
invariant(false, 'Unexpected type: ' + inspect(type));
287289
}

src/utilities/printSchema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ export function printType(type: GraphQLNamedType): string {
141141
}
142142
if (isInputObjectType(type)) {
143143
return printInputObject(type);
144-
} /* c8 ignore next 3 */
144+
// c8 control statement technically placed a line early secondary to
145+
// slight swc source mapping error (at least as compared to ts-node without swc)
146+
/* c8 ignore next 4 */
147+
}
145148
// Not reachable, all possible types have been considered.
146149
invariant(false, 'Unexpected type: ' + inspect(type));
147150
}

0 commit comments

Comments
 (0)