Skip to content

Commit

Permalink
Catch errors when applying user vite plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Tate-CC committed Dec 21, 2023
1 parent 76ab9c6 commit 51e4aec
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions javascript-modules/engines/astro-engine/lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,31 +160,35 @@ export const buildPlugins = [
}
);
build.onLoad({ filter: /.*/ }, async (args) => {
if (astroConfig.vite?.plugins) {
const text = await fs.promises.readFile(args.path, "utf8");
for (const plugin of astroConfig.vite.plugins) {
if (!plugin.transform) {
continue;
try{
if (astroConfig.vite?.plugins) {
const text = await fs.promises.readFile(args.path, "utf8");
for (const plugin of astroConfig.vite.plugins) {
if (!plugin.transform) {
continue;
}

const result = await plugin.transform(
text,
args.path.replace(process.cwd(), "")
);

if (!result) {
continue;
}

if (typeof result !== "string" && !result.code) {
return;
}

return {
contents: typeof result === "string" ? result : result.code,
loader: "js",
};
}

const result = await plugin.transform(
text,
args.path.replace(process.cwd(), "")
);

if (!result) {
continue;
}

if (typeof result !== "string" && !result.code) {
return;
}

return {
contents: typeof result === "string" ? result : result.code,
loader: "js",
};
}
} catch(err){
// Intentionally ignored
}
});
},
Expand Down

0 comments on commit 51e4aec

Please sign in to comment.