Skip to content

Commit bf189fc

Browse files
committedJun 26, 2023
feat: auto-populate tsc paths in swc config
1 parent c2bc3da commit bf189fc

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed
 

‎actions/build.action.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as chalk from 'chalk';
22
import { join } from 'path';
3+
import * as ts from 'typescript';
34
import { Input } from '../commands';
45
import { AssetsManager } from '../lib/compiler/assets-manager';
56
import { Compiler } from '../lib/compiler/compiler';
@@ -138,6 +139,7 @@ export class BuildAction extends AbstractAction {
138139
pathToTsconfig,
139140
watchMode,
140141
options,
142+
tsOptions,
141143
onSuccess,
142144
);
143145
}
@@ -149,6 +151,7 @@ export class BuildAction extends AbstractAction {
149151
pathToTsconfig: string,
150152
watchMode: boolean,
151153
options: Input[],
154+
tsOptions: ts.CompilerOptions,
152155
onSuccess: (() => void) | undefined,
153156
) {
154157
const swc = new SwcCompiler(this.pluginsLoader);
@@ -165,6 +168,7 @@ export class BuildAction extends AbstractAction {
165168
'typeCheck',
166169
options,
167170
),
171+
tsOptions,
168172
assetsManager: this.assetsManager,
169173
},
170174
onSuccess,

‎lib/compiler/defaults/swc-defaults.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export const swcDefaultsFactory = () => {
1+
import * as ts from 'typescript';
2+
3+
export const swcDefaultsFactory = (tsOptions: ts.CompilerOptions) => {
24
return {
35
swcOptions: {
46
module: {
@@ -16,7 +18,8 @@ export const swcDefaultsFactory = () => {
1618
decoratorMetadata: true,
1719
},
1820
keepClassNames: true,
19-
baseUrl: './',
21+
baseUrl: tsOptions.baseUrl,
22+
paths: tsOptions.paths,
2023
},
2124
minify: false,
2225
swcrc: true,

‎lib/compiler/swc/swc-compiler.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fork } from 'child_process';
33
import * as chokidar from 'chokidar';
44
import { readFileSync } from 'fs';
55
import { join } from 'path';
6+
import * as ts from 'typescript';
67
import { Configuration } from '../../configuration';
78
import { ERROR_PREFIX } from '../../ui';
89
import { treeKillSync } from '../../utils/tree-kill';
@@ -22,6 +23,7 @@ export type SwcCompilerExtras = {
2223
watch: boolean;
2324
typeCheck: boolean;
2425
assetsManager: AssetsManager;
26+
tsOptions: ts.CompilerOptions;
2527
};
2628

2729
export class SwcCompiler extends BaseCompiler {
@@ -39,7 +41,7 @@ export class SwcCompiler extends BaseCompiler {
3941
extras: SwcCompilerExtras,
4042
onSuccess?: () => void,
4143
) {
42-
const swcOptions = swcDefaultsFactory();
44+
const swcOptions = swcDefaultsFactory(extras.tsOptions);
4345
if (extras.watch) {
4446
if (extras.typeCheck) {
4547
this.runTypeChecker(configuration, tsConfigPath, appName, extras);

0 commit comments

Comments
 (0)
Please sign in to comment.