Skip to content

Commit 4754f28

Browse files
committed
fix: handle oxc transform errors
1 parent 4fbfed7 commit 4754f28

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/build/plugins/oxc.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { MinifyOptions } from "oxc-minify";
22
import type { OXCOptions } from "nitro/types";
33
import type { Plugin } from "rollup";
44

5-
import { transform } from "oxc-transform";
5+
import { transformSync } from "oxc-transform";
66
import { minifySync } from "oxc-minify";
77

88
export function oxc(
@@ -15,10 +15,14 @@ export function oxc(
1515
id: /^(?!.*\/node_modules\/).*\.m?[jt]sx?$/,
1616
},
1717
handler(code, id) {
18-
return transform(id, code, {
18+
const res = transformSync(id, code, {
1919
sourcemap: options.sourcemap,
2020
...options.transform,
2121
});
22+
if (res.errors?.length > 0) {
23+
this.error(res.errors.join("\n"));
24+
}
25+
return res;
2226
},
2327
},
2428
renderChunk(code, chunk) {

src/build/plugins/route-meta.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,18 @@ export function routeMeta(nitro: Nitro) {
4646
let meta: NitroEventHandler["meta"] | null = null;
4747

4848
try {
49-
const jsCode = transformSync(id, code).code;
50-
const ast = this.parse(jsCode);
49+
const transformRes = transformSync(id, code);
50+
if (transformRes.errors?.length > 0) {
51+
for (const error of transformRes.errors) {
52+
this.warn(error);
53+
}
54+
return {
55+
code: `export default {};`,
56+
map: null,
57+
};
58+
}
59+
60+
const ast = this.parse(transformRes.code);
5161
for (const node of ast.body) {
5262
if (
5363
node.type === "ExpressionStatement" &&

0 commit comments

Comments
 (0)