Skip to content

Commit

Permalink
feat: auto-populate tsc paths in swc config
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jun 26, 2023
1 parent c2bc3da commit bf189fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions actions/build.action.ts
@@ -1,5 +1,6 @@
import * as chalk from 'chalk';
import { join } from 'path';
import * as ts from 'typescript';
import { Input } from '../commands';
import { AssetsManager } from '../lib/compiler/assets-manager';
import { Compiler } from '../lib/compiler/compiler';
Expand Down Expand Up @@ -138,6 +139,7 @@ export class BuildAction extends AbstractAction {
pathToTsconfig,
watchMode,
options,
tsOptions,
onSuccess,
);
}
Expand All @@ -149,6 +151,7 @@ export class BuildAction extends AbstractAction {
pathToTsconfig: string,
watchMode: boolean,
options: Input[],
tsOptions: ts.CompilerOptions,
onSuccess: (() => void) | undefined,
) {
const swc = new SwcCompiler(this.pluginsLoader);
Expand All @@ -165,6 +168,7 @@ export class BuildAction extends AbstractAction {
'typeCheck',
options,
),
tsOptions,
assetsManager: this.assetsManager,
},
onSuccess,
Expand Down
7 changes: 5 additions & 2 deletions lib/compiler/defaults/swc-defaults.ts
@@ -1,4 +1,6 @@
export const swcDefaultsFactory = () => {
import * as ts from 'typescript';

export const swcDefaultsFactory = (tsOptions: ts.CompilerOptions) => {
return {
swcOptions: {
module: {
Expand All @@ -16,7 +18,8 @@ export const swcDefaultsFactory = () => {
decoratorMetadata: true,
},
keepClassNames: true,
baseUrl: './',
baseUrl: tsOptions.baseUrl,
paths: tsOptions.paths,
},
minify: false,
swcrc: true,
Expand Down
4 changes: 3 additions & 1 deletion lib/compiler/swc/swc-compiler.ts
Expand Up @@ -3,6 +3,7 @@ import { fork } from 'child_process';
import * as chokidar from 'chokidar';
import { readFileSync } from 'fs';
import { join } from 'path';
import * as ts from 'typescript';
import { Configuration } from '../../configuration';
import { ERROR_PREFIX } from '../../ui';
import { treeKillSync } from '../../utils/tree-kill';
Expand All @@ -22,6 +23,7 @@ export type SwcCompilerExtras = {
watch: boolean;
typeCheck: boolean;
assetsManager: AssetsManager;
tsOptions: ts.CompilerOptions;
};

export class SwcCompiler extends BaseCompiler {
Expand All @@ -39,7 +41,7 @@ export class SwcCompiler extends BaseCompiler {
extras: SwcCompilerExtras,
onSuccess?: () => void,
) {
const swcOptions = swcDefaultsFactory();
const swcOptions = swcDefaultsFactory(extras.tsOptions);
if (extras.watch) {
if (extras.typeCheck) {
this.runTypeChecker(configuration, tsConfigPath, appName, extras);
Expand Down

0 comments on commit bf189fc

Please sign in to comment.