Skip to content

Commit

Permalink
Merge branch 'nuejs:master' into feat/link-components-attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpricedev authored Jan 26, 2025
2 parents e1c9e9f + 5ecb5ac commit e2b6d74
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions packages/nuekit/src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import { join } from 'node:path'
import { resolve } from 'import-meta-resolve'
import { Features, bundleAsync } from 'lightningcss'

// don't reuse saved builder when in test mode
const isTest = process.env.NODE_ENV == 'test'

let jsBuilder
export async function getBuilder(is_esbuild) {
if (jsBuilder) return jsBuilder
if (!isTest && jsBuilder) return jsBuilder

try {
return jsBuilder = is_esbuild ? await import(resolve('esbuild', `file://${process.cwd()}/`)) : Bun
Expand All @@ -21,7 +24,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 +45,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 e2b6d74

Please sign in to comment.