From 1146efa23ea431b64a7cf8ade7a9dcff1f78d395 Mon Sep 17 00:00:00 2001 From: hanseltime Date: Tue, 3 Dec 2024 13:18:42 -0700 Subject: [PATCH] fix adding swc configuration file support as an option --- src/configuration.ts | 2 ++ src/index.ts | 7 +++++++ src/transpilers/swc.ts | 16 ++++++++++++++-- website/docs/swc.md | 11 +++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/configuration.ts b/src/configuration.ts index b5b36c1c4..478162bc9 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -364,6 +364,7 @@ function filterRecognizedTsConfigTsNodeOptions(jsonObject: any): { moduleTypes, experimentalReplAwait, swc, + swcConfig, experimentalResolver, esm, experimentalSpecifierResolution, @@ -391,6 +392,7 @@ function filterRecognizedTsConfigTsNodeOptions(jsonObject: any): { scopeDir, moduleTypes, swc, + swcConfig, experimentalResolver, esm, experimentalSpecifierResolution, diff --git a/src/index.ts b/src/index.ts index 894c17dba..7b8dac5b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -217,6 +217,13 @@ export interface CreateOptions { * For complete instructions: https://typestrong.org/ts-node/docs/transpilers */ swc?: boolean; + /** + * If using swc as the compiler, this will look for the swc configuration file either at the path + * specified, or using the default .swcrc lookup mechanism of swc if set to true + * + * It will look for nothing if set to false. + */ + swcConfig?: boolean | string; /** * Paths which should not be compiled. * diff --git a/src/transpilers/swc.ts b/src/transpilers/swc.ts index ea41d534c..f3c6d3c25 100644 --- a/src/transpilers/swc.ts +++ b/src/transpilers/swc.ts @@ -13,6 +13,16 @@ export interface SwcTranspilerOptions extends CreateTranspilerOptions { * Default: '@swc/core', falling back to '@swc/wasm' */ swc?: string | typeof swcWasm; + + /** + * This will look for the swc configuration file either at the path + * specified, or using the default .swcrc lookup mechanism of swc if set to true + * + * It will look for nothing if set to false. + * + * Default: false + */ + swcConfig?: boolean | string; } export function create(createOptions: SwcTranspilerOptions): Transpiler { @@ -127,7 +137,8 @@ export function createSwcOptions( compilerOptions: ts.CompilerOptions, nodeModuleEmitKind: NodeModuleEmitKind | undefined, swcInstance: SwcInstance, - swcDepName: string + swcDepName: string, + swcConfig?: SwcTranspilerOptions['swcConfig'] ) { const { esModuleInterop, @@ -219,7 +230,8 @@ export function createSwcOptions( : {}), } : undefined, - swcrc: false, + swcrc: swcConfig === true ? swcConfig : false, + configFile: typeof swcConfig === 'string' ? swcConfig : undefined, jsc: { externalHelpers: importHelpers, parser: { diff --git a/website/docs/swc.md b/website/docs/swc.md index e64646b12..876d1b6eb 100644 --- a/website/docs/swc.md +++ b/website/docs/swc.md @@ -22,4 +22,15 @@ Then add the following to your `tsconfig.json`. } ``` +Note, if you are using a swc configuration file, you can tell ts-node to load the file by supplying the swcConfig argument: + +```json title="tsconfig.json" +{ + "ts-node": { + "swc": true, + "swcConfig": ".development.scwrc" + } +} +``` + > SWC uses `@swc/helpers` instead of `tslib`. If you have enabled `importHelpers`, you must also install `@swc/helpers`.