Skip to content

Commit

Permalink
Add esbuild overwrites (#580)
Browse files Browse the repository at this point in the history
* Add esbuild overwrites

* Use a patch function > config

* Lint

* Fix esbuild extra imports

* Lint <3
  • Loading branch information
ShadiestGoat authored Dec 1, 2023
1 parent db97189 commit f3aeca4
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 deletions bin/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
rmSync,
writeFileSync,
} from "fs";
import { cwd } from "process";
import esbuild from "esbuild";
import path from "path";
import updateNotifier from "update-notifier";
Expand Down Expand Up @@ -39,6 +40,17 @@ export const directory = process.cwd();

const dirname = path.dirname(fileURLToPath(import.meta.url));
const packageJson = JSON.parse(readFileSync(path.resolve(dirname, "package.json"), "utf-8"));
let extraESBuildConfig = new Promise<(current: esbuild.BuildOptions) => esbuild.BuildOptions>(
(resolve) => resolve((v) => v),
);

if (existsSync("./esbuild.extra.mjs")) {
extraESBuildConfig = new Promise((resolve) => {
import(path.join(cwd(), "esbuild.extra.mjs")).then((v) => {
resolve(v.default);
});
});
}

const updateMessage = `Update available ${chalk.dim("{currentVersion}")}${chalk.reset(
" → ",
Expand Down Expand Up @@ -382,25 +394,31 @@ async function buildPlugin({ watch, noInstall, production, noReload, addon }: Ar

const targets: Array<Promise<esbuild.BuildContext>> = [];

const overwrites = await extraESBuildConfig;

if ("renderer" in manifest) {
targets.push(
esbuild.context({
...common,
entryPoints: [path.join(folderPath, manifest.renderer)],
outfile: `${distPath}/renderer.js`,
}),
esbuild.context(
overwrites({
...common,
entryPoints: [path.join(folderPath, manifest.renderer)],
outfile: `${distPath}/renderer.js`,
}),
),
);

manifest.renderer = "renderer.js";
}

if ("plaintextPatches" in manifest) {
targets.push(
esbuild.context({
...common,
entryPoints: [path.join(folderPath, manifest.plaintextPatches)],
outfile: `${distPath}/plaintextPatches.js`,
}),
esbuild.context(
overwrites({
...common,
entryPoints: [path.join(folderPath, manifest.plaintextPatches)],
outfile: `${distPath}/plaintextPatches.js`,
}),
),
);

manifest.plaintextPatches = "plaintextPatches.js";
Expand Down Expand Up @@ -464,25 +482,31 @@ async function buildTheme({ watch, noInstall, production, noReload, addon }: Arg

const targets: Array<Promise<esbuild.BuildContext>> = [];

const overwrites = await extraESBuildConfig;

if (main) {
targets.push(
esbuild.context({
...common,
entryPoints: [main],
outfile: `${distPath}/main.css`,
}),
esbuild.context(
overwrites({
...common,
entryPoints: [main],
outfile: `${distPath}/main.css`,
}),
),
);

manifest.main = "main.css";
}

if (splash) {
targets.push(
esbuild.context({
...common,
entryPoints: [splash],
outfile: `${distPath}/splash.css`,
}),
esbuild.context(
overwrites({
...common,
entryPoints: [splash],
outfile: `${distPath}/splash.css`,
}),
),
);

manifest.plaintextPatches = "splash.css";
Expand Down

0 comments on commit f3aeca4

Please sign in to comment.