@@ -256,6 +256,12 @@ export interface CreateOptions {
256
256
* Specify a custom transpiler for use with transpileOnly
257
257
*/
258
258
transpiler ?: string | [ string , object ] ;
259
+ /**
260
+ * Transpile with swc instead of the TypeScript compiler, and skip typechecking.
261
+ *
262
+ * Equivalent to setting both `transpileOnly: true` and `transpiler: 'ts-node/transpilers/swc'`
263
+ */
264
+ swc ?: boolean ;
259
265
/**
260
266
* Paths which should not be compiled.
261
267
*
@@ -608,11 +614,33 @@ export function create(rawOptions: CreateOptions = {}): Service {
608
614
( { compiler, ts } = loadCompiler ( options . compiler , configFilePath ) ) ;
609
615
}
610
616
617
+ // swc implies two other options
618
+ // typeCheck option was implemented specifically to allow overriding tsconfig transpileOnly from the command-line
619
+ // So we should allow using typeCheck to override swc
620
+ if ( options . swc && ! options . typeCheck ) {
621
+ if ( options . transpileOnly === false ) {
622
+ throw new Error (
623
+ "Cannot enable 'swc' option with 'transpileOnly: false'. 'swc' implies 'transpileOnly'."
624
+ ) ;
625
+ }
626
+ if ( options . transpiler ) {
627
+ throw new Error (
628
+ "Cannot specify both 'swc' and 'transpiler' options. 'swc' uses the built-in swc transpiler."
629
+ ) ;
630
+ }
631
+ }
632
+
611
633
const readFile = options . readFile || ts . sys . readFile ;
612
634
const fileExists = options . fileExists || ts . sys . fileExists ;
613
635
// typeCheck can override transpileOnly, useful for CLI flag to override config file
614
636
const transpileOnly =
615
- options . transpileOnly === true && options . typeCheck !== true ;
637
+ ( options . transpileOnly === true || options . swc === true ) &&
638
+ options . typeCheck !== true ;
639
+ const transpiler = options . transpiler
640
+ ? options . transpiler
641
+ : options . swc
642
+ ? require . resolve ( './transpilers/swc.js' )
643
+ : undefined ;
616
644
const transformers = options . transformers || undefined ;
617
645
const diagnosticFilters : Array < DiagnosticFilter > = [
618
646
{
@@ -668,17 +696,15 @@ export function create(rawOptions: CreateOptions = {}): Service {
668
696
) ;
669
697
}
670
698
let customTranspiler : Transpiler | undefined = undefined ;
671
- if ( options . transpiler ) {
699
+ if ( transpiler ) {
672
700
if ( ! transpileOnly )
673
701
throw new Error (
674
702
'Custom transpiler can only be used when transpileOnly is enabled.'
675
703
) ;
676
704
const transpilerName =
677
- typeof options . transpiler === 'string'
678
- ? options . transpiler
679
- : options . transpiler [ 0 ] ;
705
+ typeof transpiler === 'string' ? transpiler : transpiler [ 0 ] ;
680
706
const transpilerOptions =
681
- typeof options . transpiler === 'string' ? { } : options . transpiler [ 1 ] ?? { } ;
707
+ typeof transpiler === 'string' ? { } : transpiler [ 1 ] ?? { } ;
682
708
// TODO mimic fixed resolution logic from loadCompiler main
683
709
// TODO refactor into a more generic "resolve dep relative to project" helper
684
710
const transpilerPath = require . resolve ( transpilerName , {
0 commit comments