Skip to content

Commit

Permalink
perf: cache outDir and rootDir
Browse files Browse the repository at this point in the history
  • Loading branch information
zanminkian committed Apr 21, 2024
1 parent fb1f084 commit 7d3355a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/tscx/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export class Compiler {
private id = "";
private currentSubprocess?: childProcess.ChildProcess;
private tsconfig: TsConfig;
private rootDir: string;
private outDir: string;

constructor(private readonly options: CompilerOptions) {
// setup options
Expand All @@ -32,6 +34,8 @@ export class Compiler {
}
// setup tsconfig
this.tsconfig = this.getTsConfig();
this.rootDir = this.getRootDir();
this.outDir = this.getOutDir();
}

compile() {
Expand All @@ -58,12 +62,10 @@ export class Compiler {
if (this.id !== id) {
return;
}
const outDir = this.getOutDir();
const rootDir = this.getRootDir();

const removeTask = () => remove(outDir);
const removeTask = () => remove(this.outDir);
const tscTask = () => tsc({ project: this.options.project });
const copyfilesTask = () => copyfiles(rootDir, outDir);
const copyfilesTask = () => copyfiles(this.rootDir, this.outDir);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const execTask = () => exec(this.options.exec!);

Expand Down Expand Up @@ -93,6 +95,8 @@ export class Compiler {

refreshTsConfig() {
this.tsconfig = this.getTsConfig();
this.rootDir = this.getRootDir();
this.outDir = this.getOutDir();
}

private getTsConfig(): TsConfig {
Expand Down

0 comments on commit 7d3355a

Please sign in to comment.