From aefe50b2dc0c7ec8806e120d7aac94cbecfd5998 Mon Sep 17 00:00:00 2001 From: ShadiestGoat <48590492+ShadiestGoat@users.noreply.github.com> Date: Mon, 23 Oct 2023 00:57:57 +0100 Subject: [PATCH 1/5] Add esbuild overwrites --- bin/index.mts | 14 ++++++++++++++ scripts/build-bin.mts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bin/index.mts b/bin/index.mts index 2581ef27d..010c17b6d 100755 --- a/bin/index.mts +++ b/bin/index.mts @@ -39,6 +39,12 @@ 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(() => ({})) + +if (existsSync("./esbuild.extra.mjs")) { + // @ts-expect-error it doesn't exist here, but it does exist in the pkg + extraESBuildConfig = import("./esbuild.extra.mjs") +} const updateMessage = `Update available ${chalk.dim("{currentVersion}")}${chalk.reset( " → ", @@ -382,12 +388,15 @@ async function buildPlugin({ watch, noInstall, production, noReload, addon }: Ar const targets: Array> = []; + const overwrites = await extraESBuildConfig + if ("renderer" in manifest) { targets.push( esbuild.context({ ...common, entryPoints: [path.join(folderPath, manifest.renderer)], outfile: `${distPath}/renderer.js`, + ...overwrites, }), ); @@ -400,6 +409,7 @@ async function buildPlugin({ watch, noInstall, production, noReload, addon }: Ar ...common, entryPoints: [path.join(folderPath, manifest.plaintextPatches)], outfile: `${distPath}/plaintextPatches.js`, + ...overwrites, }), ); @@ -464,12 +474,15 @@ async function buildTheme({ watch, noInstall, production, noReload, addon }: Arg const targets: Array> = []; + const overwrites = await extraESBuildConfig + if (main) { targets.push( esbuild.context({ ...common, entryPoints: [main], outfile: `${distPath}/main.css`, + ...overwrites, }), ); @@ -482,6 +495,7 @@ async function buildTheme({ watch, noInstall, production, noReload, addon }: Arg ...common, entryPoints: [splash], outfile: `${distPath}/splash.css`, + ...overwrites, }), ); diff --git a/scripts/build-bin.mts b/scripts/build-bin.mts index 3c31be376..85d251645 100644 --- a/scripts/build-bin.mts +++ b/scripts/build-bin.mts @@ -21,7 +21,7 @@ const context = await esbuild.context({ platform: "node", target: `node${NODE_VERSION}`, outfile: "bin.mjs", - external: packageNames, + external: [...packageNames, "./esbuild.extra.mjs"], }); await context.rebuild(); From 7ab19fce75e6a88886ac7ceb6fa664c7313d1961 Mon Sep 17 00:00:00 2001 From: ShadiestGoat <48590492+ShadiestGoat@users.noreply.github.com> Date: Mon, 23 Oct 2023 01:03:32 +0100 Subject: [PATCH 2/5] Use a patch function > config --- bin/index.mts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/bin/index.mts b/bin/index.mts index 010c17b6d..1446061b4 100755 --- a/bin/index.mts +++ b/bin/index.mts @@ -39,7 +39,7 @@ 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(() => ({})) +let extraESBuildConfig = new Promise<(current: esbuild.BuildOptions) => esbuild.BuildOptions>(() => ((v: esbuild.BuildOptions) => v)) if (existsSync("./esbuild.extra.mjs")) { // @ts-expect-error it doesn't exist here, but it does exist in the pkg @@ -392,12 +392,11 @@ async function buildPlugin({ watch, noInstall, production, noReload, addon }: Ar if ("renderer" in manifest) { targets.push( - esbuild.context({ + esbuild.context(overwrites({ ...common, entryPoints: [path.join(folderPath, manifest.renderer)], outfile: `${distPath}/renderer.js`, - ...overwrites, - }), + })), ); manifest.renderer = "renderer.js"; @@ -405,12 +404,11 @@ async function buildPlugin({ watch, noInstall, production, noReload, addon }: Ar if ("plaintextPatches" in manifest) { targets.push( - esbuild.context({ + esbuild.context(overwrites({ ...common, entryPoints: [path.join(folderPath, manifest.plaintextPatches)], outfile: `${distPath}/plaintextPatches.js`, - ...overwrites, - }), + })), ); manifest.plaintextPatches = "plaintextPatches.js"; @@ -478,12 +476,11 @@ async function buildTheme({ watch, noInstall, production, noReload, addon }: Arg if (main) { targets.push( - esbuild.context({ + esbuild.context(overwrites({ ...common, entryPoints: [main], outfile: `${distPath}/main.css`, - ...overwrites, - }), + })), ); manifest.main = "main.css"; @@ -491,12 +488,11 @@ async function buildTheme({ watch, noInstall, production, noReload, addon }: Arg if (splash) { targets.push( - esbuild.context({ + esbuild.context(overwrites({ ...common, entryPoints: [splash], outfile: `${distPath}/splash.css`, - ...overwrites, - }), + })), ); manifest.plaintextPatches = "splash.css"; From 5ed3d555ca358c2d1d723862c6e02807b9a71f57 Mon Sep 17 00:00:00 2001 From: ShadiestGoat <48590492+ShadiestGoat@users.noreply.github.com> Date: Mon, 23 Oct 2023 01:09:49 +0100 Subject: [PATCH 3/5] Lint --- bin/index.mts | 58 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/bin/index.mts b/bin/index.mts index 1446061b4..e72e115b0 100755 --- a/bin/index.mts +++ b/bin/index.mts @@ -39,11 +39,13 @@ 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>(() => ((v: esbuild.BuildOptions) => v)) +let extraESBuildConfig = new Promise<(current: esbuild.BuildOptions) => esbuild.BuildOptions>( + () => (v: esbuild.BuildOptions) => v, +); if (existsSync("./esbuild.extra.mjs")) { // @ts-expect-error it doesn't exist here, but it does exist in the pkg - extraESBuildConfig = import("./esbuild.extra.mjs") + extraESBuildConfig = import("./esbuild.extra.mjs"); } const updateMessage = `Update available ${chalk.dim("{currentVersion}")}${chalk.reset( @@ -388,15 +390,17 @@ async function buildPlugin({ watch, noInstall, production, noReload, addon }: Ar const targets: Array> = []; - const overwrites = await extraESBuildConfig + const overwrites = await extraESBuildConfig; if ("renderer" in manifest) { targets.push( - esbuild.context(overwrites({ - ...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"; @@ -404,11 +408,13 @@ async function buildPlugin({ watch, noInstall, production, noReload, addon }: Ar if ("plaintextPatches" in manifest) { targets.push( - esbuild.context(overwrites({ - ...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"; @@ -472,15 +478,17 @@ async function buildTheme({ watch, noInstall, production, noReload, addon }: Arg const targets: Array> = []; - const overwrites = await extraESBuildConfig + const overwrites = await extraESBuildConfig; if (main) { targets.push( - esbuild.context(overwrites({ - ...common, - entryPoints: [main], - outfile: `${distPath}/main.css`, - })), + esbuild.context( + overwrites({ + ...common, + entryPoints: [main], + outfile: `${distPath}/main.css`, + }), + ), ); manifest.main = "main.css"; @@ -488,11 +496,13 @@ async function buildTheme({ watch, noInstall, production, noReload, addon }: Arg if (splash) { targets.push( - esbuild.context(overwrites({ - ...common, - entryPoints: [splash], - outfile: `${distPath}/splash.css`, - })), + esbuild.context( + overwrites({ + ...common, + entryPoints: [splash], + outfile: `${distPath}/splash.css`, + }), + ), ); manifest.plaintextPatches = "splash.css"; From d277796093bf2015ed33ea4a13534cb587c09c5f Mon Sep 17 00:00:00 2001 From: ShadiestGoat <48590492+ShadiestGoat@users.noreply.github.com> Date: Mon, 23 Oct 2023 23:34:39 +0100 Subject: [PATCH 4/5] Fix esbuild extra imports --- bin/index.mts | 10 +++++++--- scripts/build-bin.mts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/index.mts b/bin/index.mts index e72e115b0..cb88b9ec1 100755 --- a/bin/index.mts +++ b/bin/index.mts @@ -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"; @@ -40,12 +41,15 @@ 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>( - () => (v: esbuild.BuildOptions) => v, + (resolve) => resolve(v => v) ); if (existsSync("./esbuild.extra.mjs")) { - // @ts-expect-error it doesn't exist here, but it does exist in the pkg - extraESBuildConfig = import("./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( diff --git a/scripts/build-bin.mts b/scripts/build-bin.mts index 85d251645..3c31be376 100644 --- a/scripts/build-bin.mts +++ b/scripts/build-bin.mts @@ -21,7 +21,7 @@ const context = await esbuild.context({ platform: "node", target: `node${NODE_VERSION}`, outfile: "bin.mjs", - external: [...packageNames, "./esbuild.extra.mjs"], + external: packageNames, }); await context.rebuild(); From 804e3efbff76750990da557340426cc99244436b Mon Sep 17 00:00:00 2001 From: ShadiestGoat <48590492+ShadiestGoat@users.noreply.github.com> Date: Mon, 23 Oct 2023 23:35:07 +0100 Subject: [PATCH 5/5] Lint <3 --- bin/index.mts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/index.mts b/bin/index.mts index cb88b9ec1..244a84fa5 100755 --- a/bin/index.mts +++ b/bin/index.mts @@ -12,7 +12,7 @@ import { rmSync, writeFileSync, } from "fs"; -import {cwd} from "process"; +import { cwd } from "process"; import esbuild from "esbuild"; import path from "path"; import updateNotifier from "update-notifier"; @@ -41,14 +41,14 @@ 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) + (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) - }) + import(path.join(cwd(), "esbuild.extra.mjs")).then((v) => { + resolve(v.default); + }); }); }