Skip to content

Commit

Permalink
fix(astro-engine): Define ENV_BOOKSHOP_LIVE in typescript files
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlynch committed Sep 24, 2024
1 parent de6f520 commit 4cc0701
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions javascript-modules/engines/astro-engine/lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,35 @@ export const buildPlugins = [
loader: "js",
};
});
build.onLoad({ filter: /\.ts$/ }, async (args) => {
let text = await fs.promises.readFile(args.path, "utf8");
let jsResult = await esbuild.transform(text, {
loader: "ts",
target: "esnext",
sourcemap: false,
define: { ENV_BOOKSHOP_LIVE: "true" },
});

let result = await bookshopTransform(
jsResult.code,
args.path.replace(process.cwd(), "")
);

if (!result) {
console.warn("Bookshop transform failed:", args.path);
result = jsResult;
}

let importTransform = (await resolveConfig({}, "build")).plugins.find(
({ name }) => name === "vite:import-glob"
).transform;
let viteResult = await importTransform(result.code, args.path);

return {
contents: viteResult?.code ?? result.code,
loader: "js",
};
});
build.onLoad(
{
filter: /astro(\/|\\)dist(\/|\\)runtime(\/|\\)server(\/|\\)index.js$/,
Expand Down

0 comments on commit 4cc0701

Please sign in to comment.