11import { platform } from 'os'
22import { resolve } from 'path'
33
4- import { transform , transformSync } from '@swc-node/core'
4+ import { transform , transformSync , Options } from '@swc-node/core'
55import { SourcemapMap , installSourceMapSupport } from '@swc-node/sourcemap-support'
66import { addHook } from 'pirates'
77import * as ts from 'typescript'
@@ -77,12 +77,16 @@ export function compile(
7777 return code
7878 } )
7979 } else {
80- const swcRegisterConfig = tsCompilerOptionsToSwcConfig ( options , filename )
81- if ( process . env . SWCRC === 'true' ) {
80+ let swcRegisterConfig : Options
81+ if ( process . env . SWCRC ) {
8282 // when SWCRC environment variable is set to true it will use swcrc file
83- swcRegisterConfig . swc = {
84- swcrc : true ,
83+ swcRegisterConfig = {
84+ swc : {
85+ swcrc : true ,
86+ } ,
8587 }
88+ } else {
89+ swcRegisterConfig = tsCompilerOptionsToSwcConfig ( options , filename )
8690 }
8791 const { code, map } = transformSync ( sourcecode , filename , swcRegisterConfig )
8892 // in case of map is undefined
@@ -93,7 +97,11 @@ export function compile(
9397 }
9498}
9599
96- export function register ( options = readDefaultTsConfig ( ) , hookOpts = { } ) {
100+ export function register ( options : Partial < ts . CompilerOptions > = { } , hookOpts = { } ) {
101+ if ( ! process . env . SWCRC ) {
102+ options = readDefaultTsConfig ( )
103+ }
104+ options . module = ts . ModuleKind . CommonJS
97105 installSourceMapSupport ( )
98106 return addHook ( ( code , filename ) => compile ( code , filename , options ) , {
99107 exts : DEFAULT_EXTENSIONS ,
0 commit comments