Skip to content

Commit 4b92e1f

Browse files
authored
internal: use swc with ts-node (#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 bfc8e5a commit 4b92e1f

File tree

13 files changed

+266
-17
lines changed

13 files changed

+266
-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: 227 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,8 +1125,10 @@ function completeValue(
11251125
incrementalContext,
11261126
deferMap,
11271127
);
1128+
// c8 control statement technically placed a line early secondary to
1129+
// slight swc source mapping error (at least as compared to ts-node without swc)
1130+
/* c8 ignore next 7 */
11281131
}
1129-
/* c8 ignore next 6 */
11301132
// Not reachable, all possible output types have been considered.
11311133
invariant(
11321134
false,

src/type/introspection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,10 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({
240240
}
241241
if (isNonNullType(type)) {
242242
return TypeKind.NON_NULL;
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 */
243246
}
244-
/* c8 ignore next 3 */
245247
// Not reachable, all possible types have been considered)
246248
invariant(false, `Unexpected type: "${inspect(type)}".`);
247249
},

src/utilities/astFromValue.ts

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

139139
throw new TypeError(`Cannot convert value to AST: ${inspect(coerced)}.`);
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 */
140143
}
141-
/* c8 ignore next 3 */
142144
// Not reachable, all possible types have been considered.
143145
invariant(false, 'Unexpected input type: ' + inspect(type));
144146
}

src/utilities/findSchemaChanges.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,10 @@ function typeKindName(type: GraphQLNamedType): string {
715715
}
716716
if (isInputObjectType(type)) {
717717
return 'an Input type';
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 */
718721
}
719-
/* c8 ignore next 3 */
720722
// Not reachable, all possible types have been considered.
721723
invariant(false, 'Unexpected type: ' + inspect(type));
722724
}

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ export function printType(type: GraphQLNamedType): string {
141141
}
142142
if (isInputObjectType(type)) {
143143
return printInputObject(type);
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 */
144147
}
145-
/* c8 ignore next 3 */
146148
// Not reachable, all possible types have been considered.
147149
invariant(false, 'Unexpected type: ' + inspect(type));
148150
}

0 commit comments

Comments
 (0)