Skip to content

Commit 6e2e8f4

Browse files
committed
refactor: display config parser errors during build
1 parent fe3b4e5 commit 6e2e8f4

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/bundler.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ export class Bundler {
6262
/**
6363
* Runs tsc command to build the source.
6464
*/
65-
async #runTsc() {
65+
async #runTsc(outDir: string) {
6666
try {
67-
await execa('tsc', [], {
67+
await execa('tsc', ['--outDir', outDir], {
6868
cwd: this.#cwd,
6969
preferLocal: true,
7070
localDir: this.#cwd,
@@ -161,7 +161,21 @@ export class Bundler {
161161
/**
162162
* Step 1: Parse config file to get the build output directory
163163
*/
164-
const { config } = new ConfigParser(this.#cwd, 'tsconfig.json', this.#ts).parse()
164+
const { config, error } = new ConfigParser(this.#cwd, 'tsconfig.json', this.#ts).parse()
165+
if (error) {
166+
const compilerHost = this.#ts.createCompilerHost({})
167+
this.#logger.logError(this.#ts.formatDiagnosticsWithColorAndContext([error], compilerHost))
168+
return false
169+
}
170+
171+
if (config!.errors.length) {
172+
const compilerHost = this.#ts.createCompilerHost({})
173+
this.#logger.logError(
174+
this.#ts.formatDiagnosticsWithColorAndContext(config!.errors, compilerHost)
175+
)
176+
return false
177+
}
178+
165179
if (!config) {
166180
return false
167181
}
@@ -177,7 +191,7 @@ export class Bundler {
177191
* Step 3: Build typescript source code
178192
*/
179193
this.#logger.info('compiling typescript source', { suffix: 'tsc' })
180-
const buildCompleted = await this.#runTsc()
194+
const buildCompleted = await this.#runTsc(outDir)
181195
await this.#copyFiles(['ace.js'], outDir)
182196

183197
/**

0 commit comments

Comments
 (0)