Skip to content
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

fix adding swc configuration file support as an option #2143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ function filterRecognizedTsConfigTsNodeOptions(jsonObject: any): {
moduleTypes,
experimentalReplAwait,
swc,
swcConfig,
experimentalResolver,
esm,
experimentalSpecifierResolution,
Expand Down Expand Up @@ -391,6 +392,7 @@ function filterRecognizedTsConfigTsNodeOptions(jsonObject: any): {
scopeDir,
moduleTypes,
swc,
swcConfig,
experimentalResolver,
esm,
experimentalSpecifierResolution,
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
16 changes: 14 additions & 2 deletions src/transpilers/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -127,7 +137,8 @@ export function createSwcOptions(
compilerOptions: ts.CompilerOptions,
nodeModuleEmitKind: NodeModuleEmitKind | undefined,
swcInstance: SwcInstance,
swcDepName: string
swcDepName: string,
swcConfig?: SwcTranspilerOptions['swcConfig']
) {
const {
esModuleInterop,
Expand Down Expand Up @@ -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: {
Expand Down
11 changes: 11 additions & 0 deletions website/docs/swc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.