Skip to content

Commit

Permalink
Merge pull request #451 from nobkd/bun-errors
Browse files Browse the repository at this point in the history
easier bun build error handling
  • Loading branch information
nobkd authored Jan 26, 2025
2 parents 603881b + 1c23201 commit 4909c55
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions packages/nuekit/src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export async function buildJS(args) {
const { outdir, toname, minify, bundle } = args
const is_esbuild = args.esbuild || !process.isBun
const builder = await getBuilder(is_esbuild)
let ret

const opts = {
external: bundle ? ['../@nue/*', '/@nue/*'] : is_esbuild ? undefined : ['*'],
Expand All @@ -43,38 +42,19 @@ export async function buildJS(args) {
}
}

try {
ret = await builder.build(opts)

} catch (e) { ret = e }

// console.info(ret)
const error = parseError(ret)
if (error) throw error
}

export function parseError(buildResult) {
const { logs = [], errors = [] } = buildResult
let error
// make bun always throw on build error
if (!is_esbuild) opts.throw = true

// Bun
if (logs.length) {
const [err] = logs
error = { text: err.message, ...err.position }
}
try {
await builder.build(opts)

// esbuild
if (errors.length) {
} catch ({ errors }) {
const [err] = errors
error = { text: err.text, ...err.location }
}

if (error) {
const error = { text: err.message || err.text, ...(err.location || err.position) }
error.title = error.text.includes('resolve') ? 'Import error' : 'Syntax error'
delete error.file
return error
throw error
}

}

export async function lightningCSS(filename, minify, opts = {}) {
Expand Down

0 comments on commit 4909c55

Please sign in to comment.