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

internal: use swc with ts-node #4457

merged 1 commit into from
Jul 13, 2025

Conversation

yaacovCR
Copy link
Contributor

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

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
@yaacovCR yaacovCR requested a review from a team as a code owner July 11, 2025 15:00
@yaacovCR yaacovCR requested review from Copilot and a team and removed request for a team July 11, 2025 15:00
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR switches the project to use SWC with ts-node by adjusting coverage ignore directives for source-mapping differences and replacing --loader ts-node/esm with a --import registration script.

  • Update c8 ignore annotations (+comments and ignore counts) across multiple GraphQL source files to account for SWC source mapping.
  • Introduce resources/register-ts-node.js and update all npm & Mocha scripts to use node --import instead of --loader.
  • Add @swc/core to devDependencies to enable SWC compilation.

Reviewed Changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/validation/rules/PossibleTypeExtensionsRule.ts Adjusted c8 ignore comments/lines around unreachable invariant.
src/utilities/valueFromAST.ts Updated c8 ignore annotations for SWC mapping in valueFromAST.
src/utilities/printSchema.ts Updated c8 ignore annotations in printType for input object.
src/utilities/mapSchemaConfig.ts Updated c8 ignore annotations in mapSchemaConfig on input types.
src/utilities/findSchemaChanges.ts Updated c8 ignore annotations in typeKindName.
src/utilities/astFromValue.ts Updated c8 ignore annotations in astFromValue.
src/type/introspection.ts Updated c8 ignore annotations in introspection __Type resolver.
src/execution/execute.ts Updated c8 ignore annotations in completeValue.
resources/register-ts-node.js Added ESM registration script for ts-node import-based loader.
package.json Switched npm script flags from --loader to --import and added @swc/core.
.mocharc.yml Replaced Mocha loader=ts-node/esm option with import=./resources/register-ts-node.js.
Comments suppressed due to low confidence (3)

.mocharc.yml:7

  • The indentation under node-option may be incorrect, which can cause Mocha to ignore this setting. Verify YAML spacing so that each option is a direct child of node-option.
  - 'import=./resources/register-ts-node.js'

src/validation/rules/PossibleTypeExtensionsRule.ts:119

  • [nitpick] This coverage-ignore comment and directive is duplicated across many files. Consider centralizing SWC-related coverage ignore in the project’s c8 configuration or as a shared helper, reducing repetitive boilerplate and future maintenance.
    // c8 control statement technically placed a line early secondary to

src/utilities/printSchema.ts:146

  • [nitpick] Ignoring the next four lines may hide coverage gaps beyond the invariant check. If possible, target only the unreachable invariant call or use /* c8 ignore next */ without a count to limit the ignored scope.
    /* c8 ignore next 4 */

@yaacovCR
Copy link
Contributor Author

swc = observably faster on my machine, seems like a win.

I tries tsx which uses esbuild under the hood, but there is a complication with tsx use of keepNames options for esbuild that messes up code coverage:

evanw/esbuild#4239
privatenumber/tsx#659

@benjie
Copy link
Member

benjie commented Jul 11, 2025

Long term we should move to native node type stripping.

@yaacovCR yaacovCR merged commit 4b92e1f into graphql:next Jul 13, 2025
17 checks passed
@yaacovCR yaacovCR deleted the register branch July 13, 2025 17:17
@yaacovCR
Copy link
Contributor Author

Long term we should move to native node type stripping.

#4460

once we drop v20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants