mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-09 06:33:03 -04:00
Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
commit
67bacaf855
20 changed files with 775 additions and 715 deletions
|
@ -17,41 +17,44 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import esbuild from "esbuild";
|
||||
// @ts-check
|
||||
|
||||
import { createPackage } from "@electron/asar";
|
||||
import { readdir, writeFile } from "fs/promises";
|
||||
import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
import { BUILD_TIMESTAMP, commonOpts, exists, globPlugins, IS_DEV, IS_REPORTER, IS_COMPANION_TEST, IS_STANDALONE, IS_UPDATER_DISABLED, resolvePluginName, VERSION, watch } from "./common.mjs";
|
||||
import { BUILD_TIMESTAMP, commonOpts, exists, globPlugins, IS_DEV, IS_REPORTER, IS_COMPANION_TEST, IS_STANDALONE, IS_UPDATER_DISABLED, resolvePluginName, VERSION, commonRendererPlugins, watch, buildOrWatchAll, stringifyValues } from "./common.mjs";
|
||||
|
||||
const defines = {
|
||||
IS_STANDALONE: String(IS_STANDALONE),
|
||||
IS_DEV: String(IS_DEV),
|
||||
IS_REPORTER: String(IS_REPORTER),
|
||||
IS_COMPANION_TEST: String(IS_COMPANION_TEST),
|
||||
IS_UPDATER_DISABLED: String(IS_UPDATER_DISABLED),
|
||||
IS_WEB: "false",
|
||||
IS_EXTENSION: "false",
|
||||
VERSION: JSON.stringify(VERSION),
|
||||
BUILD_TIMESTAMP: String(BUILD_TIMESTAMP)
|
||||
};
|
||||
const defines = stringifyValues({
|
||||
IS_STANDALONE,
|
||||
IS_DEV,
|
||||
IS_REPORTER,
|
||||
IS_COMPANION_TEST,
|
||||
IS_UPDATER_DISABLED,
|
||||
IS_WEB: false,
|
||||
IS_EXTENSION: false,
|
||||
VERSION,
|
||||
BUILD_TIMESTAMP
|
||||
});
|
||||
|
||||
if (defines.IS_STANDALONE === "false")
|
||||
if (defines.IS_STANDALONE === "false") {
|
||||
// If this is a local build (not standalone), optimize
|
||||
// for the specific platform we're on
|
||||
defines["process.platform"] = JSON.stringify(process.platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {esbuild.BuildOptions}
|
||||
* @type {import("esbuild").BuildOptions}
|
||||
*/
|
||||
const nodeCommonOpts = {
|
||||
...commonOpts,
|
||||
define: defines,
|
||||
format: "cjs",
|
||||
platform: "node",
|
||||
target: ["esnext"],
|
||||
external: ["electron", "original-fs", "~pluginNatives", ...commonOpts.external],
|
||||
define: defines
|
||||
// @ts-ignore this is never undefined
|
||||
external: ["electron", "original-fs", "~pluginNatives", ...commonOpts.external]
|
||||
};
|
||||
|
||||
const sourceMapFooter = s => watch ? "" : `//# sourceMappingURL=vencord://${s}.js.map`;
|
||||
|
@ -105,26 +108,28 @@ const globNativesPlugin = {
|
|||
}
|
||||
};
|
||||
|
||||
await Promise.all([
|
||||
/** @type {import("esbuild").BuildOptions[]} */
|
||||
const buildConfigs = ([
|
||||
// Discord Desktop main & renderer & preload
|
||||
esbuild.build({
|
||||
{
|
||||
...nodeCommonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/main/index.ts")],
|
||||
outfile: "dist/desktop/patcher.js",
|
||||
footer: { js: "//# sourceURL=VencordPatcher\n" + sourceMapFooter("patcher") },
|
||||
sourcemap,
|
||||
plugins: [
|
||||
// @ts-ignore this is never undefined
|
||||
...nodeCommonOpts.plugins,
|
||||
globNativesPlugin
|
||||
],
|
||||
define: {
|
||||
...defines,
|
||||
IS_DISCORD_DESKTOP: "true",
|
||||
IS_VESKTOP: "false",
|
||||
IS_EQUIBOP: "false"
|
||||
},
|
||||
plugins: [
|
||||
...nodeCommonOpts.plugins,
|
||||
globNativesPlugin
|
||||
]
|
||||
}),
|
||||
esbuild.build({
|
||||
}
|
||||
},
|
||||
{
|
||||
...commonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/Vencord.ts")],
|
||||
outfile: "dist/desktop/renderer.js",
|
||||
|
@ -143,8 +148,8 @@ await Promise.all([
|
|||
IS_VESKTOP: "false",
|
||||
IS_EQUIBOP: "false"
|
||||
}
|
||||
}),
|
||||
esbuild.build({
|
||||
},
|
||||
{
|
||||
...nodeCommonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/preload.ts")],
|
||||
outfile: "dist/desktop/preload.js",
|
||||
|
@ -156,27 +161,27 @@ await Promise.all([
|
|||
IS_VESKTOP: "false",
|
||||
IS_EQUIBOP: "false"
|
||||
}
|
||||
}),
|
||||
},
|
||||
|
||||
// Equicord Desktop main & renderer & preload
|
||||
esbuild.build({
|
||||
// Vencord Desktop main & renderer & preload
|
||||
{
|
||||
...nodeCommonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/main/index.ts")],
|
||||
outfile: "dist/equibop/main.js",
|
||||
footer: { js: "//# sourceURL=VencordMain\n" + sourceMapFooter("main") },
|
||||
sourcemap,
|
||||
plugins: [
|
||||
...nodeCommonOpts.plugins,
|
||||
globNativesPlugin
|
||||
],
|
||||
define: {
|
||||
...defines,
|
||||
IS_DISCORD_DESKTOP: "false",
|
||||
IS_VESKTOP: "false",
|
||||
IS_EQUIBOP: "true"
|
||||
},
|
||||
plugins: [
|
||||
...nodeCommonOpts.plugins,
|
||||
globNativesPlugin
|
||||
]
|
||||
}),
|
||||
esbuild.build({
|
||||
}
|
||||
},
|
||||
{
|
||||
...commonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/Vencord.ts")],
|
||||
outfile: "dist/equibop/renderer.js",
|
||||
|
@ -195,8 +200,8 @@ await Promise.all([
|
|||
IS_VESKTOP: "false",
|
||||
IS_EQUIBOP: "true"
|
||||
}
|
||||
}),
|
||||
esbuild.build({
|
||||
},
|
||||
{
|
||||
...nodeCommonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/preload.ts")],
|
||||
outfile: "dist/equibop/preload.js",
|
||||
|
@ -208,14 +213,10 @@ await Promise.all([
|
|||
IS_VESKTOP: "false",
|
||||
IS_EQUIBOP: "true"
|
||||
}
|
||||
}),
|
||||
]).catch(err => {
|
||||
console.error("Build failed");
|
||||
console.error(err.message);
|
||||
// make ci fail
|
||||
if (!commonOpts.watch)
|
||||
process.exitCode = 1;
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
await buildOrWatchAll(buildConfigs);
|
||||
|
||||
await Promise.all([
|
||||
writeFile("dist/desktop/package.json", JSON.stringify({
|
||||
|
|
|
@ -17,42 +17,42 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import esbuild from "esbuild";
|
||||
// @ts-check
|
||||
|
||||
import { readFileSync } from "fs";
|
||||
import { appendFile, mkdir, readdir, readFile, rm, writeFile } from "fs/promises";
|
||||
import { join } from "path";
|
||||
import Zip from "zip-local";
|
||||
|
||||
import { BUILD_TIMESTAMP, commonOpts, globPlugins, IS_DEV, IS_REPORTER, IS_COMPANION_TEST, VERSION } from "./common.mjs";
|
||||
import { BUILD_TIMESTAMP, commonOpts, globPlugins, IS_DEV, IS_REPORTER, IS_COMPANION_TEST, VERSION, commonRendererPlugins, buildOrWatchAll, stringifyValues } from "./common.mjs";
|
||||
|
||||
/**
|
||||
* @type {esbuild.BuildOptions}
|
||||
* @type {import("esbuild").BuildOptions}
|
||||
*/
|
||||
const commonOptions = {
|
||||
...commonOpts,
|
||||
entryPoints: ["browser/Vencord.ts"],
|
||||
globalName: "Vencord",
|
||||
format: "iife",
|
||||
globalName: "Vencord",
|
||||
external: ["~plugins", "~git-hash", "/assets/*"],
|
||||
target: ["esnext"],
|
||||
plugins: [
|
||||
globPlugins("web"),
|
||||
...commonOpts.plugins
|
||||
...commonRendererPlugins
|
||||
],
|
||||
target: ["esnext"],
|
||||
define: {
|
||||
IS_WEB: "true",
|
||||
IS_EXTENSION: "false",
|
||||
IS_STANDALONE: "true",
|
||||
IS_DEV: String(IS_DEV),
|
||||
IS_REPORTER: String(IS_REPORTER),
|
||||
IS_COMPANION_TEST: String(IS_COMPANION_TEST),
|
||||
IS_DISCORD_DESKTOP: "false",
|
||||
IS_VESKTOP: "false",
|
||||
IS_EQUIBOP: "false",
|
||||
IS_UPDATER_DISABLED: "true",
|
||||
VERSION: JSON.stringify(VERSION),
|
||||
BUILD_TIMESTAMP: String(BUILD_TIMESTAMP)
|
||||
}
|
||||
define: stringifyValues({
|
||||
IS_WEB: true,
|
||||
IS_EXTENSION: false,
|
||||
IS_STANDALONE: true,
|
||||
IS_DEV,
|
||||
IS_REPORTER,
|
||||
IS_COMPANION_TEST,
|
||||
IS_DISCORD_DESKTOP: false,
|
||||
IS_VESKTOP: false,
|
||||
IS_UPDATER_DISABLED: true,
|
||||
VERSION,
|
||||
BUILD_TIMESTAMP
|
||||
})
|
||||
};
|
||||
|
||||
const MonacoWorkerEntryPoints = [
|
||||
|
@ -67,58 +67,60 @@ const RnNoiseFiles = [
|
|||
"LICENSE"
|
||||
];
|
||||
|
||||
await Promise.all(
|
||||
[
|
||||
esbuild.build({
|
||||
entryPoints: MonacoWorkerEntryPoints.map(entry => `node_modules/monaco-editor/esm/${entry}`),
|
||||
bundle: true,
|
||||
minify: true,
|
||||
format: "iife",
|
||||
outbase: "node_modules/monaco-editor/esm/",
|
||||
outdir: "dist/browser/monaco"
|
||||
}),
|
||||
esbuild.build({
|
||||
entryPoints: ["browser/monaco.ts"],
|
||||
bundle: true,
|
||||
minify: true,
|
||||
format: "iife",
|
||||
outfile: "dist/browser/monaco/index.js",
|
||||
loader: {
|
||||
".ttf": "file"
|
||||
}
|
||||
}),
|
||||
esbuild.build({
|
||||
...commonOptions,
|
||||
outfile: "dist/browser/browser.js",
|
||||
footer: { js: "//# sourceURL=VencordWeb" }
|
||||
}),
|
||||
esbuild.build({
|
||||
...commonOptions,
|
||||
outfile: "dist/browser/extension.js",
|
||||
define: {
|
||||
...commonOptions?.define,
|
||||
IS_EXTENSION: "true",
|
||||
},
|
||||
footer: { js: "//# sourceURL=VencordWeb" }
|
||||
}),
|
||||
esbuild.build({
|
||||
...commonOptions,
|
||||
inject: ["browser/GMPolyfill.js", ...(commonOptions?.inject || [])],
|
||||
define: {
|
||||
...(commonOptions?.define),
|
||||
window: "unsafeWindow",
|
||||
},
|
||||
outfile: "dist/Vencord.user.js",
|
||||
banner: {
|
||||
js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", `${VERSION}.${new Date().getTime()}`)
|
||||
},
|
||||
footer: {
|
||||
// UserScripts get wrapped in an iife, so define Vencord prop on window that returns our local
|
||||
js: "Object.defineProperty(unsafeWindow,'Vencord',{get:()=>Vencord});"
|
||||
}
|
||||
})
|
||||
]
|
||||
);
|
||||
|
||||
/** @type {import("esbuild").BuildOptions[]} */
|
||||
const buildConfigs = [
|
||||
{
|
||||
entryPoints: MonacoWorkerEntryPoints.map(entry => `node_modules/monaco-editor/esm/${entry}`),
|
||||
bundle: true,
|
||||
minify: true,
|
||||
format: "iife",
|
||||
outbase: "node_modules/monaco-editor/esm/",
|
||||
outdir: "dist/vendor/monaco"
|
||||
},
|
||||
{
|
||||
entryPoints: ["browser/monaco.ts"],
|
||||
bundle: true,
|
||||
minify: true,
|
||||
format: "iife",
|
||||
outfile: "dist/vendor/monaco/index.js",
|
||||
loader: {
|
||||
".ttf": "file"
|
||||
}
|
||||
},
|
||||
{
|
||||
...commonOptions,
|
||||
outfile: "dist/browser.js",
|
||||
footer: { js: "//# sourceURL=VencordWeb" }
|
||||
},
|
||||
{
|
||||
...commonOptions,
|
||||
outfile: "dist/extension.js",
|
||||
define: {
|
||||
...commonOptions.define,
|
||||
IS_EXTENSION: "true"
|
||||
},
|
||||
footer: { js: "//# sourceURL=VencordWeb" }
|
||||
},
|
||||
{
|
||||
...commonOptions,
|
||||
inject: ["browser/GMPolyfill.js", ...(commonOptions?.inject || [])],
|
||||
define: {
|
||||
...commonOptions.define,
|
||||
window: "unsafeWindow",
|
||||
},
|
||||
outfile: "dist/Vencord.user.js",
|
||||
banner: {
|
||||
js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", `${VERSION}.${new Date().getTime()}`)
|
||||
},
|
||||
footer: {
|
||||
// UserScripts get wrapped in an iife, so define Vencord prop on window that returns our local
|
||||
js: "Object.defineProperty(unsafeWindow,'Vencord',{get:()=>Vencord});"
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
await buildOrWatchAll(buildConfigs);
|
||||
|
||||
/**
|
||||
* @type {(dir: string) => Promise<string[]>}
|
||||
|
@ -157,9 +159,9 @@ async function loadDir(dir, basePath = "") {
|
|||
*/
|
||||
async function buildExtension(target, files) {
|
||||
const entries = {
|
||||
"dist/Vencord.js": await readFile("dist/browser/extension.js"),
|
||||
"dist/Vencord.css": await readFile("dist/browser/extension.css"),
|
||||
...await loadDir("dist/browser/monaco"),
|
||||
"dist/Vencord.js": await readFile("dist/extension.js"),
|
||||
"dist/Vencord.css": await readFile("dist/extension.css"),
|
||||
...await loadDir("dist/vendor/monaco", "dist/"),
|
||||
...Object.fromEntries(await Promise.all(RnNoiseFiles.map(async file =>
|
||||
[`third-party/rnnoise/${file.replace(/^dist\//, "")}`, await readFile(`node_modules/@sapphi-red/web-noise-suppressor/${file}`)]
|
||||
))),
|
||||
|
@ -168,7 +170,7 @@ async function buildExtension(target, files) {
|
|||
if (f.startsWith("manifest")) {
|
||||
const json = JSON.parse(content.toString("utf-8"));
|
||||
json.version = VERSION;
|
||||
content = new TextEncoder().encode(JSON.stringify(json));
|
||||
content = Buffer.from(new TextEncoder().encode(JSON.stringify(json)));
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
|
@ -16,11 +16,13 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// @ts-check
|
||||
|
||||
import "../suppressExperimentalWarnings.js";
|
||||
import "../checkNodeVersion.js";
|
||||
|
||||
import { exec, execSync } from "child_process";
|
||||
import esbuild from "esbuild";
|
||||
import esbuild, { build, context } from "esbuild";
|
||||
import { constants as FsConstants, readFileSync } from "fs";
|
||||
import { access, readdir, readFile } from "fs/promises";
|
||||
import { minify as minifyHtml } from "html-minifier-terser";
|
||||
|
@ -29,8 +31,9 @@ import { fileURLToPath } from "url";
|
|||
import { promisify } from "util";
|
||||
|
||||
import { getPluginTarget } from "../utils.mjs";
|
||||
import { builtinModules } from "module";
|
||||
|
||||
const PackageJSON = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../../package.json")));
|
||||
const PackageJSON = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../../package.json"), "utf-8"));
|
||||
|
||||
export const VERSION = PackageJSON.version;
|
||||
// https://reproducible-builds.org/docs/source-date-epoch/
|
||||
|
@ -56,6 +59,34 @@ export const banner = {
|
|||
`.trim()
|
||||
};
|
||||
|
||||
/**
|
||||
* JSON.stringify all values in an object
|
||||
* @type {(obj: Record<string, any>) => Record<string, string>}
|
||||
*/
|
||||
export function stringifyValues(obj) {
|
||||
for (const key in obj) {
|
||||
obj[key] = JSON.stringify(obj[key]);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("esbuild").BuildOptions[]} buildConfigs
|
||||
*/
|
||||
export async function buildOrWatchAll(buildConfigs) {
|
||||
if (watch) {
|
||||
await Promise.all(buildConfigs.map(cfg =>
|
||||
context(cfg).then(ctx => ctx.watch())
|
||||
));
|
||||
} else {
|
||||
await Promise.all(buildConfigs.map(cfg => build(cfg)))
|
||||
.catch(error => {
|
||||
console.error(error.message);
|
||||
process.exit(1); // exit immediately to skip the rest of the builds
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const PluginDefinitionNameMatcher = /definePlugin\(\{\s*(["'])?name\1:\s*(["'`])(.+?)\2/;
|
||||
/**
|
||||
* @param {string} base
|
||||
|
@ -271,6 +302,18 @@ export const fileUrlPlugin = {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {(filter: RegExp, message: string) => import("esbuild").Plugin}
|
||||
*/
|
||||
export const banImportPlugin = (filter, message) => ({
|
||||
name: "ban-imports",
|
||||
setup: build => {
|
||||
build.onResolve({ filter }, () => {
|
||||
return { errors: [{ text: message }] };
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const styleModule = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "module/style.js"), "utf-8");
|
||||
|
||||
/**
|
||||
|
@ -303,17 +346,28 @@ export const stylePlugin = {
|
|||
export const commonOpts = {
|
||||
logLevel: "info",
|
||||
bundle: true,
|
||||
watch,
|
||||
minify: !watch && !IS_REPORTER,
|
||||
sourcemap: watch ? "inline" : "",
|
||||
sourcemap: watch ? "inline" : "external",
|
||||
legalComments: "linked",
|
||||
banner,
|
||||
plugins: [fileUrlPlugin, gitHashPlugin, gitRemotePlugin, stylePlugin],
|
||||
external: ["~plugins", "~git-hash", "~git-remote", "/assets/*"],
|
||||
inject: [join(dirname(fileURLToPath(import.meta.url)), "inject/react.mjs")],
|
||||
jsxFactory: "VencordCreateElement",
|
||||
jsxFragment: "VencordFragment",
|
||||
jsx: "transform",
|
||||
// Work around https://github.com/evanw/esbuild/issues/2460
|
||||
tsconfig: join(dirname(fileURLToPath(import.meta.url)), "tsconfig.esbuild.json")
|
||||
jsxFactory: "VencordCreateElement",
|
||||
jsxFragment: "VencordFragment"
|
||||
};
|
||||
|
||||
const escapedBuiltinModules = builtinModules
|
||||
.map(m => m.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"))
|
||||
.join("|");
|
||||
const builtinModuleRegex = new RegExp(`^(node:)?(${escapedBuiltinModules})$`);
|
||||
|
||||
export const commonRendererPlugins = [
|
||||
banImportPlugin(builtinModuleRegex, "Cannot import node inbuilt modules in browser code. You need to use a native.ts file"),
|
||||
banImportPlugin(/^react$/, "Cannot import from react. React and hooks should be imported from @webpack/common"),
|
||||
banImportPlugin(/^electron(\/.*)?$/, "Cannot import electron in browser code. You need to use a native.ts file"),
|
||||
banImportPlugin(/^ts-pattern$/, "Cannot import from ts-pattern. match and P should be imported from @webpack/common"),
|
||||
// @ts-ignore this is never undefined
|
||||
...commonOpts.plugins
|
||||
];
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// Work around https://github.com/evanw/esbuild/issues/2460
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "react"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue