migrate to bun (#781)
This commit is contained in:
parent
022e2a7a37
commit
faf400acf3
25 changed files with 1394 additions and 199 deletions
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
|
|
@ -31,10 +31,10 @@ jobs:
|
|||
|
||||
- name: Generate plugin lists
|
||||
run: |
|
||||
pnpm generatePluginJson dist/plugins.json
|
||||
pnpm generateEquicordPluginJson dist/equicordplugins.json
|
||||
pnpm generateVencordPluginJson dist/vencordplugins.json
|
||||
pnpm generateDevsList dist/devs.json
|
||||
bun run generatePluginJson dist/plugins.json
|
||||
bun run generateEquicordPluginJson dist/equicordplugins.json
|
||||
bun run generateVencordPluginJson dist/vencordplugins.json
|
||||
bun run generateDevsList dist/devs.json
|
||||
|
||||
- name: Collect files to be released
|
||||
run: |
|
||||
|
|
|
|||
8
.github/workflows/nixosBuild.yml
vendored
8
.github/workflows/nixosBuild.yml
vendored
|
|
@ -29,10 +29,10 @@ jobs:
|
|||
|
||||
- name: Generate plugin lists
|
||||
run: |
|
||||
pnpm generatePluginJson dist/plugins.json
|
||||
pnpm generateEquicordPluginJson dist/equicordplugins.json
|
||||
pnpm generateVencordPluginJson dist/vencordplugins.json
|
||||
pnpm generateDevsList dist/devs.json
|
||||
bun run generatePluginJson dist/plugins.json
|
||||
bun run generateEquicordPluginJson dist/equicordplugins.json
|
||||
bun run generateVencordPluginJson dist/vencordplugins.json
|
||||
bun run generateDevsList dist/devs.json
|
||||
|
||||
- name: Collect files to be released
|
||||
run: |
|
||||
|
|
|
|||
17
.github/workflows/publish.yml
vendored
17
.github/workflows/publish.yml
vendored
|
|
@ -58,24 +58,19 @@ jobs:
|
|||
with:
|
||||
tag_prefix: "v"
|
||||
|
||||
- name: Setup PNPM
|
||||
- name: Setup Bun
|
||||
if: steps.check.outputs.release == 'true'
|
||||
uses: pnpm/action-setup@v3
|
||||
|
||||
- name: Use Node.js 20
|
||||
if: steps.check.outputs.release == 'true'
|
||||
uses: actions/setup-node@v4
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
node-version: 20
|
||||
cache: "pnpm"
|
||||
bun-version: latest
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.check.outputs.release == 'true'
|
||||
run: pnpm install --frozen-lockfile
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Build web
|
||||
if: steps.check.outputs.release == 'true'
|
||||
run: pnpm buildWebStandalone
|
||||
run: bun run buildWebStandalone
|
||||
|
||||
- name: Create sources zip
|
||||
if: steps.check.outputs.release == 'true'
|
||||
|
|
@ -83,7 +78,7 @@ jobs:
|
|||
|
||||
- name: Publish extension
|
||||
if: steps.check.outputs.release == 'true'
|
||||
run: pnpx @equicord/publish-browser-extension@latest --chrome-zip dist/extension-chrome.zip --firefox-zip dist/extension-firefox.zip --firefox-sources-zip dist/extension-sources.zip --edge-zip dist/extension-chrome.zip
|
||||
run: bunx @equicord/publish-browser-extension@latest --chrome-zip dist/extension-chrome.zip --firefox-zip dist/extension-firefox.zip --firefox-sources-zip dist/extension-sources.zip --edge-zip dist/extension-chrome.zip
|
||||
|
||||
env:
|
||||
CHROME_EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }}
|
||||
|
|
|
|||
1
.github/workflows/reportBrokenPlugins.yml
vendored
1
.github/workflows/reportBrokenPlugins.yml
vendored
|
|
@ -56,7 +56,6 @@ jobs:
|
|||
- name: Run Reporter
|
||||
timeout-minutes: 10
|
||||
run: |
|
||||
export PATH="$PWD/node_modules/.bin:$PATH"
|
||||
export CHROMIUM_BIN=${{ steps.setup-chrome.outputs.chrome-path }}
|
||||
|
||||
bun build scripts/generateReport.ts --outfile dist/report.mjs --target bun
|
||||
|
|
|
|||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
|
|
@ -17,10 +17,6 @@ jobs:
|
|||
- uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: latest
|
||||
- name: Use Node.js 20
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
- name: Lint & Test if desktop version compiles
|
||||
|
|
|
|||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -10,8 +10,8 @@ equicord_installer
|
|||
.DS_Store
|
||||
|
||||
yarn.lock
|
||||
bun.lock
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
|
|
|||
2
.npmrc
2
.npmrc
|
|
@ -1,2 +0,0 @@
|
|||
strict-peer-dependencies=false
|
||||
package-manager-strict=false
|
||||
|
|
@ -79,7 +79,7 @@ bun run inject
|
|||
Build Equicord for web:
|
||||
|
||||
```shell
|
||||
pnpm buildWeb
|
||||
bun run buildWeb
|
||||
```
|
||||
|
||||
After building Equicord's web extension, locate the appropriate ZIP file in the `dist` directory and follow your browser’s guide for installing custom extensions, if supported.
|
||||
|
|
|
|||
12
package.json
12
package.json
|
|
@ -13,6 +13,10 @@
|
|||
},
|
||||
"license": "GPL-3.0-or-later",
|
||||
"author": "Equicord",
|
||||
"workspaces": [
|
||||
"packages/discord-types",
|
||||
"packages/vencord-types"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "bun run scripts/build/build.mjs",
|
||||
"buildStandalone": "bun run build --standalone",
|
||||
|
|
@ -36,7 +40,8 @@
|
|||
"lint:fix": "bun run lint --fix",
|
||||
"test": "bun run buildStandalone && bun run testTsc && bun run lint:fix && bun run lint-styles && bun run generatePluginJson",
|
||||
"testWeb": "bun run lint:fix && bun run buildWeb && bun run testTsc",
|
||||
"testTsc": "tsc --noEmit"
|
||||
"testTsc": "tsc --noEmit",
|
||||
"postinstall": "bun run scripts/applyPatches.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ffmpeg/ffmpeg": "^0.12.10",
|
||||
|
|
@ -62,6 +67,7 @@
|
|||
"@electron/asar": "^4.0.1",
|
||||
"@stylistic/eslint-plugin": "^5.6.0",
|
||||
"@types/adm-zip": "^0.5.7",
|
||||
"@types/bun": "^1.3.9",
|
||||
"@types/chrome": "^0.1.30",
|
||||
"@types/diff": "^7.0.2",
|
||||
"@types/lodash": "^4.17.20",
|
||||
|
|
@ -69,7 +75,7 @@
|
|||
"@types/react": "^19.0.10",
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"@types/yazl": "^3.3.0",
|
||||
"@vencord/discord-types": "link:@vencord/discord-types",
|
||||
"@vencord/discord-types": "workspace:*",
|
||||
"diff": "^8.0.2",
|
||||
"esbuild": "^0.27.0",
|
||||
"eslint": "9.39.1",
|
||||
|
|
@ -93,7 +99,7 @@
|
|||
"typescript-transform-paths": "^3.5.5",
|
||||
"zip-local": "^0.3.5"
|
||||
},
|
||||
"packageManager": "bun@1.1.0",
|
||||
"packageManager": "bun@1.3.9",
|
||||
"trustedDependencies": [
|
||||
"esbuild"
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@equicord/discord-types",
|
||||
"name": "@vencord/discord-types",
|
||||
"author": "Equicord & Vencord Contributors",
|
||||
"private": false,
|
||||
"description": "Typescript definitions for the webpack modules of the Discord Web app",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
"dependencies": {
|
||||
"@types/lodash": "4.17.15",
|
||||
"@types/node": "^22.13.4",
|
||||
"@vencord/discord-types": "^1.0.0",
|
||||
"@vencord/discord-types": "workspace:*",
|
||||
"highlight.js": "11.11.1",
|
||||
"moment": "^2.22.2",
|
||||
"ts-pattern": "^5.6.0",
|
||||
|
|
|
|||
31
scripts/applyPatches.mjs
Normal file
31
scripts/applyPatches.mjs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env bun
|
||||
|
||||
import { join } from "path";
|
||||
|
||||
const ROOT = join(import.meta.dir, "..");
|
||||
|
||||
const patches = {
|
||||
"@types/less": {
|
||||
file: join(ROOT, "node_modules/@types/less/index.d.ts"),
|
||||
original: "export = less;",
|
||||
patched: "export = LessStatic;",
|
||||
removeLines: ["declare var less: LessStatic;"]
|
||||
}
|
||||
};
|
||||
|
||||
for (const [pkg, patch] of Object.entries(patches)) {
|
||||
const file = Bun.file(patch.file);
|
||||
if (!await file.exists()) continue;
|
||||
|
||||
let content = await file.text();
|
||||
|
||||
if (content.includes(patch.patched)) continue;
|
||||
|
||||
content = content.replace(patch.original, patch.patched);
|
||||
for (const line of patch.removeLines) {
|
||||
content = content.replace(line, "").replace(/\n{3,}/g, "\n\n");
|
||||
}
|
||||
|
||||
await Bun.write(patch.file, content.trimEnd() + "\n");
|
||||
console.log(`Patched ${pkg}`);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/node
|
||||
#!/usr/bin/env bun
|
||||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2022 Vendicated and contributors
|
||||
|
|
@ -20,12 +20,13 @@
|
|||
// @ts-check
|
||||
|
||||
import { createPackage } from "@electron/asar";
|
||||
import { readdir, writeFile } from "fs/promises";
|
||||
import { dirname, join, resolve } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { readdir } from "fs/promises";
|
||||
import { join, resolve } from "path";
|
||||
|
||||
import { BUILD_TIMESTAMP, commonOpts, exists, globPlugins, IS_DEV, IS_REPORTER, IS_COMPANION_TEST, IS_STANDALONE, IS_UPDATER_DISABLED, resolvePluginName, VERSION, commonRendererPlugins, watch, buildOrWatchAll, stringifyValues, IS_ANTI_CRASH_TEST } from "./common.mjs";
|
||||
|
||||
const __dirname = import.meta.dir;
|
||||
|
||||
const defines = stringifyValues({
|
||||
IS_STANDALONE,
|
||||
IS_DEV,
|
||||
|
|
@ -123,7 +124,7 @@ const buildConfigs = ([
|
|||
// Discord Desktop main & renderer & preload
|
||||
{
|
||||
...nodeCommonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/main/index.ts")],
|
||||
entryPoints: [join(__dirname, "../../src/main/index.ts")],
|
||||
outfile: "dist/desktop/patcher.js",
|
||||
footer: { js: "//# sourceURL=file:///VencordPatcher\n" + sourceMapFooter("patcher") },
|
||||
sourcemap,
|
||||
|
|
@ -141,7 +142,7 @@ const buildConfigs = ([
|
|||
},
|
||||
{
|
||||
...commonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/Vencord.ts")],
|
||||
entryPoints: [join(__dirname, "../../src/Vencord.ts")],
|
||||
outfile: "dist/desktop/renderer.js",
|
||||
format: "iife",
|
||||
target: ["esnext"],
|
||||
|
|
@ -161,7 +162,7 @@ const buildConfigs = ([
|
|||
},
|
||||
{
|
||||
...nodeCommonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/preload.ts")],
|
||||
entryPoints: [join(__dirname, "../../src/preload.ts")],
|
||||
outfile: "dist/desktop/preload.js",
|
||||
footer: { js: "//# sourceURL=file:///VencordPreload\n" + sourceMapFooter("preload") },
|
||||
sourcemap,
|
||||
|
|
@ -176,7 +177,7 @@ const buildConfigs = ([
|
|||
// Vencord Desktop main & renderer & preload
|
||||
{
|
||||
...nodeCommonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/main/index.ts")],
|
||||
entryPoints: [join(__dirname, "../../src/main/index.ts")],
|
||||
outfile: "dist/equibop/main.js",
|
||||
footer: { js: "//# sourceURL=file:///VencordDesktopMain\n" + sourceMapFooter("main") },
|
||||
sourcemap,
|
||||
|
|
@ -193,7 +194,7 @@ const buildConfigs = ([
|
|||
},
|
||||
{
|
||||
...commonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/Vencord.ts")],
|
||||
entryPoints: [join(__dirname, "../../src/Vencord.ts")],
|
||||
outfile: "dist/equibop/renderer.js",
|
||||
format: "iife",
|
||||
target: ["esnext"],
|
||||
|
|
@ -213,7 +214,7 @@ const buildConfigs = ([
|
|||
},
|
||||
{
|
||||
...nodeCommonOpts,
|
||||
entryPoints: [join(dirname(fileURLToPath(import.meta.url)), "../../src/preload.ts")],
|
||||
entryPoints: [join(__dirname, "../../src/preload.ts")],
|
||||
outfile: "dist/equibop/preload.js",
|
||||
footer: { js: "//# sourceURL=file:///VencordPreload\n" + sourceMapFooter("preload") },
|
||||
sourcemap,
|
||||
|
|
@ -229,11 +230,11 @@ const buildConfigs = ([
|
|||
await buildOrWatchAll(buildConfigs);
|
||||
|
||||
await Promise.all([
|
||||
writeFile("dist/desktop/package.json", JSON.stringify({
|
||||
Bun.write("dist/desktop/package.json", JSON.stringify({
|
||||
name: "equicord",
|
||||
main: "patcher.js"
|
||||
})),
|
||||
writeFile("dist/equibop/package.json", JSON.stringify({
|
||||
Bun.write("dist/equibop/package.json", JSON.stringify({
|
||||
name: "equicord",
|
||||
main: "main.js"
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/node
|
||||
#!/usr/bin/env bun
|
||||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2022 Vendicated and contributors
|
||||
|
|
@ -19,9 +19,8 @@
|
|||
|
||||
// @ts-check
|
||||
|
||||
import { readFileSync } from "fs";
|
||||
import { appendFile, mkdir, readdir, readFile, rm, writeFile } from "fs/promises";
|
||||
import path, { join } from "path";
|
||||
import { appendFile, mkdir, readdir, rm } 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, commonRendererPlugins, buildOrWatchAll, stringifyValues, IS_ANTI_CRASH_TEST } from "./common.mjs";
|
||||
|
|
@ -107,7 +106,7 @@ const buildConfigs = [
|
|||
},
|
||||
outfile: "dist/Equicord.user.js",
|
||||
banner: {
|
||||
js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", `${VERSION}.${new Date().getTime()}`)
|
||||
js: (await Bun.file("browser/userscript.meta.js").text()).replace("%version%", `${VERSION}.${Date.now()}`)
|
||||
},
|
||||
footer: {
|
||||
// UserScripts get wrapped in an iife, so define Vencord prop on window that returns our local
|
||||
|
|
@ -144,7 +143,7 @@ async function loadDir(dir, basePath = "") {
|
|||
await Promise.all(
|
||||
files.map(
|
||||
async f =>
|
||||
[f.slice(basePath.length), await readFile(f)]
|
||||
[f.slice(basePath.length), Buffer.from(await Bun.file(f).arrayBuffer())]
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
@ -155,15 +154,15 @@ async function loadDir(dir, basePath = "") {
|
|||
*/
|
||||
async function buildExtension(target, files) {
|
||||
const entries = {
|
||||
"dist/Equicord.js": await readFile("dist/browser/extension.js"),
|
||||
"dist/Equicord.css": await readFile("dist/browser/extension.css"),
|
||||
"dist/Equicord.js": Buffer.from(await Bun.file("dist/browser/extension.js").arrayBuffer()),
|
||||
"dist/Equicord.css": Buffer.from(await Bun.file("dist/browser/extension.css").arrayBuffer()),
|
||||
...await loadDir("dist/browser/vendor/monaco", "dist/browser/"),
|
||||
...Object.fromEntries(await Promise.all(files.map(async f => {
|
||||
let content = await readFile(join("browser", f));
|
||||
let content = Buffer.from(await Bun.file(join("browser", f)).arrayBuffer());
|
||||
if (f.startsWith("manifest")) {
|
||||
const json = JSON.parse(content.toString("utf-8"));
|
||||
json.version = VERSION;
|
||||
content = Buffer.from(new TextEncoder().encode(JSON.stringify(json)));
|
||||
content = Buffer.from(JSON.stringify(json));
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
@ -178,13 +177,13 @@ async function buildExtension(target, files) {
|
|||
const dest = join("dist/browser", target, file);
|
||||
const parentDirectory = join(dest, "..");
|
||||
await mkdir(parentDirectory, { recursive: true });
|
||||
await writeFile(dest, content);
|
||||
await Bun.write(dest, content);
|
||||
}));
|
||||
|
||||
console.info("Unpacked Extension written to dist/browser/" + target);
|
||||
}
|
||||
|
||||
const appendCssRuntime = readFile("dist/Equicord.user.css", "utf-8").then(content => {
|
||||
const appendCssRuntime = Bun.file("dist/Equicord.user.css").text().then(content => {
|
||||
const cssRuntime = `unsafeWindow._vcUserScriptRendererCss=\`${content.replaceAll("`", "\\`")}\``;
|
||||
|
||||
return appendFile("dist/Equicord.user.js", cssRuntime);
|
||||
|
|
|
|||
|
|
@ -18,21 +18,17 @@
|
|||
|
||||
// @ts-check
|
||||
|
||||
import "../suppressExperimentalWarnings.js";
|
||||
import "../checkNodeVersion.js";
|
||||
|
||||
import { exec, execSync } from "child_process";
|
||||
import esbuild, { build, context } from "esbuild";
|
||||
import { constants as FsConstants, readFileSync } from "fs";
|
||||
import { access, readdir, readFile } from "fs/promises";
|
||||
import { existsSync } from "fs";
|
||||
import { readdir } from "fs/promises";
|
||||
import { minify as minifyHtml } from "html-minifier-terser";
|
||||
import { dirname, join, relative, resolve } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { promisify } from "util";
|
||||
import { join, relative, resolve } from "path";
|
||||
|
||||
import { getPluginTarget } from "../utils.mjs";
|
||||
|
||||
const PackageJSON = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../../package.json"), "utf-8"));
|
||||
const __dirname = import.meta.dir;
|
||||
|
||||
const PackageJSON = await Bun.file(join(__dirname, "../../package.json")).json();
|
||||
|
||||
export const VERSION = PackageJSON.version;
|
||||
// https://reproducible-builds.org/docs/source-date-epoch/
|
||||
|
|
@ -48,7 +44,7 @@ if (!IS_COMPANION_TEST && process.argv.includes("--companion-test"))
|
|||
console.error("--companion-test must be run with --reporter for any effect");
|
||||
|
||||
export const IS_UPDATER_DISABLED = process.argv.includes("--disable-updater");
|
||||
export const gitHash = process.env.EQUICORD_HASH || execSync("git rev-parse HEAD", { encoding: "utf-8" }).trim();
|
||||
export const gitHash = process.env.EQUICORD_HASH || new TextDecoder().decode(Bun.spawnSync(["git", "rev-parse", "HEAD"]).stdout).trim();
|
||||
|
||||
export const banner = {
|
||||
js: `
|
||||
|
|
@ -95,14 +91,11 @@ const PluginDefinitionNameMatcher = /definePlugin\(\{\s*(["'])?name\1:\s*(["'`])
|
|||
export async function resolvePluginName(base, dirent) {
|
||||
const fullPath = join(base, dirent.name);
|
||||
const content = dirent.isFile()
|
||||
? await readFile(fullPath, "utf-8")
|
||||
? await Bun.file(fullPath).text()
|
||||
: await (async () => {
|
||||
for (const file of ["index.ts", "index.tsx"]) {
|
||||
try {
|
||||
return await readFile(join(fullPath, file), "utf-8");
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const f = Bun.file(join(fullPath, file));
|
||||
if (await f.exists()) return await f.text();
|
||||
}
|
||||
throw new Error(`Invalid plugin ${fullPath}: could not resolve entry point`);
|
||||
})();
|
||||
|
|
@ -113,10 +106,8 @@ export async function resolvePluginName(base, dirent) {
|
|||
})();
|
||||
}
|
||||
|
||||
export async function exists(path) {
|
||||
return await access(path, FsConstants.F_OK)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
export function exists(path) {
|
||||
return Bun.file(path).exists().then(e => e || existsSync(path));
|
||||
}
|
||||
|
||||
// https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
|
||||
|
|
@ -230,8 +221,8 @@ export const gitRemotePlugin = {
|
|||
build.onLoad({ filter, namespace: "git-remote" }, async () => {
|
||||
let remote = process.env.EQUICORD_REMOTE;
|
||||
if (!remote) {
|
||||
const res = await promisify(exec)("git remote get-url origin", { encoding: "utf-8" });
|
||||
remote = res.stdout.trim()
|
||||
const proc = Bun.spawn(["git", "remote", "get-url", "origin"], { stdout: "pipe" });
|
||||
remote = (await new Response(proc.stdout).text()).trim()
|
||||
.replace("https://github.com/", "")
|
||||
.replace("git@github.com:", "")
|
||||
.replace(/.git$/, "");
|
||||
|
|
@ -263,15 +254,18 @@ export const fileUrlPlugin = {
|
|||
const minify = searchParams.has("minify");
|
||||
const noTrim = searchParams.get("trim") === "false";
|
||||
|
||||
const encoding = base64 ? "base64" : "utf-8";
|
||||
|
||||
let content;
|
||||
if (!minify) {
|
||||
content = await readFile(path, encoding);
|
||||
if (!noTrim) content = content.trimEnd();
|
||||
if (base64) {
|
||||
const buf = Buffer.from(await Bun.file(path).arrayBuffer());
|
||||
content = buf.toString("base64");
|
||||
} else {
|
||||
content = await Bun.file(path).text();
|
||||
if (!noTrim) content = content.trimEnd();
|
||||
}
|
||||
} else {
|
||||
if (path.endsWith(".html")) {
|
||||
content = await minifyHtml(await readFile(path, "utf-8"), {
|
||||
content = await minifyHtml(await Bun.file(path).text(), {
|
||||
collapseWhitespace: true,
|
||||
removeComments: true,
|
||||
minifyCSS: true,
|
||||
|
|
@ -316,7 +310,7 @@ export const banImportPlugin = (filter, message) => ({
|
|||
}
|
||||
});
|
||||
|
||||
const styleModule = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "module/style.js"), "utf-8");
|
||||
const styleModule = await Bun.file(join(__dirname, "module/style.js")).text();
|
||||
|
||||
/**
|
||||
* @type {import("esbuild").Plugin}
|
||||
|
|
@ -329,7 +323,7 @@ export const stylePlugin = {
|
|||
namespace: "managed-style",
|
||||
}));
|
||||
onLoad({ filter: /\.css$/, namespace: "managed-style" }, async ({ path }) => {
|
||||
const css = await readFile(path, "utf-8");
|
||||
const css = await Bun.file(path).text();
|
||||
const name = relative(process.cwd(), path).replaceAll("\\", "/");
|
||||
|
||||
return {
|
||||
|
|
@ -354,7 +348,7 @@ export const commonOpts = {
|
|||
banner,
|
||||
plugins: [fileUrlPlugin, gitHashPlugin, gitRemotePlugin, stylePlugin],
|
||||
external: ["~plugins", "~git-hash", "~git-remote", "/assets/*"],
|
||||
inject: [join(dirname(fileURLToPath(import.meta.url)), "inject/react.mjs")],
|
||||
inject: [join(__dirname, "inject/react.mjs")],
|
||||
jsx: "transform",
|
||||
jsxFactory: "VencordCreateElement",
|
||||
jsxFragment: "VencordFragment"
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2023 Vendicated and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (Number(process.versions.node.split(".")[0]) < 18)
|
||||
throw `Your node version (${process.version}) is too old, please update to v18 or higher https://nodejs.org/en/download/`;
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { BigIntLiteral, createSourceFile, Identifier, isCallExpression, isIdentifier, isObjectLiteralExpression, isPropertyAssignment, isSatisfiesExpression, isVariableStatement, NamedDeclaration, ObjectLiteralExpression, ScriptTarget, StringLiteral } from "typescript";
|
||||
|
||||
interface Dev {
|
||||
|
|
@ -41,8 +40,8 @@ function getObjectProp(node: ObjectLiteralExpression, name: string) {
|
|||
return prop;
|
||||
}
|
||||
|
||||
function parseDevs() {
|
||||
const file = createSourceFile("constants.ts", readFileSync("src/utils/constants.ts", "utf8"), ScriptTarget.Latest);
|
||||
async function parseDevs() {
|
||||
const file = createSourceFile("constants.ts", await Bun.file("src/utils/constants.ts").text(), ScriptTarget.Latest);
|
||||
|
||||
for (const child of file.getChildAt(0).getChildren()) {
|
||||
if (!isVariableStatement(child)) continue;
|
||||
|
|
@ -72,8 +71,8 @@ function parseDevs() {
|
|||
throw new Error("Could not find Devs constant");
|
||||
}
|
||||
|
||||
function parseEquicordDevs() {
|
||||
const file = createSourceFile("constants.ts", readFileSync("src/utils/constants.ts", "utf8"), ScriptTarget.Latest);
|
||||
async function parseEquicordDevs() {
|
||||
const file = createSourceFile("constants.ts", await Bun.file("src/utils/constants.ts").text(), ScriptTarget.Latest);
|
||||
|
||||
for (const child of file.getChildAt(0).getChildren()) {
|
||||
if (!isVariableStatement(child)) continue;
|
||||
|
|
@ -104,8 +103,8 @@ function parseEquicordDevs() {
|
|||
}
|
||||
|
||||
(async () => {
|
||||
parseDevs();
|
||||
parseEquicordDevs();
|
||||
await parseDevs();
|
||||
await parseEquicordDevs();
|
||||
|
||||
const allDevs = {
|
||||
vencord: devs,
|
||||
|
|
@ -114,7 +113,7 @@ function parseEquicordDevs() {
|
|||
|
||||
const data = JSON.stringify(allDevs, null, 2);
|
||||
if (process.argv.length > 2) {
|
||||
writeFileSync(process.argv[2], data);
|
||||
await Bun.write(process.argv[2], data);
|
||||
} else {
|
||||
console.log(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { readdirSync, writeFileSync } from "fs";
|
||||
import { readdirSync } from "fs";
|
||||
import { getEntryPoint, isPluginFile, parseDevs, parseEquicordDevs, parseFile, PluginData } from "./utils";
|
||||
|
||||
(async () => {
|
||||
parseDevs();
|
||||
parseEquicordDevs();
|
||||
await parseDevs();
|
||||
await parseEquicordDevs();
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ import { getEntryPoint, isPluginFile, parseDevs, parseEquicordDevs, parseFile, P
|
|||
const data = JSON.stringify(plugins);
|
||||
|
||||
if (outputPath) {
|
||||
writeFileSync(outputPath, data);
|
||||
await Bun.write(outputPath, data);
|
||||
} else {
|
||||
console.log(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
/// <reference types="../src/modules" />
|
||||
|
||||
import { createHmac } from "crypto";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
import pup, { JSHandle } from "puppeteer-core";
|
||||
|
||||
|
|
@ -359,7 +358,7 @@ page.on("pageerror", (e: any) => {
|
|||
|
||||
await page.evaluateOnNewDocument(`
|
||||
if (location.host.endsWith("discord.com")) {
|
||||
${readFileSync("./dist/browser/browser.js", "utf-8")};
|
||||
${await Bun.file("./dist/browser/browser.js").text()};
|
||||
}
|
||||
`);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,20 +16,14 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import "./checkNodeVersion.js";
|
||||
|
||||
import { execFileSync, execSync } from "child_process";
|
||||
import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
||||
import { dirname, join } from "path";
|
||||
import { Readable } from "stream";
|
||||
import { finished } from "stream/promises";
|
||||
import { fileURLToPath } from "url";
|
||||
import { mkdirSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
const BASE_URL = "https://github.com/Equicord/Equilotl/releases/latest/download/";
|
||||
const INSTALLER_PATH_DARWIN = "Equilotl.app/Contents/MacOS/Equilotl";
|
||||
const INSTALLER_APP_DARWIN = "Equilotl.app";
|
||||
|
||||
const BASE_DIR = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const BASE_DIR = join(import.meta.dir, "..");
|
||||
const FILE_DIR = join(BASE_DIR, "dist", "Installer");
|
||||
const ETAG_FILE = join(FILE_DIR, "etag.txt");
|
||||
|
||||
|
|
@ -60,8 +54,9 @@ async function ensureBinary() {
|
|||
? join(FILE_DIR, INSTALLER_APP_DARWIN)
|
||||
: null;
|
||||
|
||||
const etag = existsSync(outputFile) && existsSync(ETAG_FILE)
|
||||
? readFileSync(ETAG_FILE, "utf-8")
|
||||
const etagFile = Bun.file(ETAG_FILE);
|
||||
const etag = await Bun.file(outputFile).exists() && await etagFile.exists()
|
||||
? await etagFile.text()
|
||||
: null;
|
||||
|
||||
const res = await fetch(BASE_URL + filename, {
|
||||
|
|
@ -78,33 +73,31 @@ async function ensureBinary() {
|
|||
if (!res.ok)
|
||||
throw new Error(`Failed to download installer: ${res.status} ${res.statusText}`);
|
||||
|
||||
writeFileSync(ETAG_FILE, res.headers.get("etag"));
|
||||
await Bun.write(ETAG_FILE, res.headers.get("etag"));
|
||||
|
||||
if (process.platform === "darwin") {
|
||||
console.log("Saving zip...");
|
||||
const zip = new Uint8Array(await res.arrayBuffer());
|
||||
writeFileSync(downloadName, zip);
|
||||
await Bun.write(downloadName, new Uint8Array(await res.arrayBuffer()));
|
||||
|
||||
console.log("Unzipping app bundle...");
|
||||
execSync(`ditto -x -k '${downloadName}' '${FILE_DIR}'`);
|
||||
Bun.spawnSync(["ditto", "-x", "-k", downloadName, FILE_DIR], { stdio: ["inherit", "inherit", "inherit"] });
|
||||
|
||||
console.log("Clearing quarantine from installer app (this is required to run it)");
|
||||
console.log("xattr might error, that's okay");
|
||||
|
||||
const logAndRun = cmd => {
|
||||
console.log("Running", cmd);
|
||||
const logAndRun = args => {
|
||||
console.log("Running", args.join(" "));
|
||||
try {
|
||||
execSync(cmd);
|
||||
Bun.spawnSync(args, { stdio: ["inherit", "inherit", "inherit"] });
|
||||
} catch { }
|
||||
};
|
||||
logAndRun(`sudo xattr -dr com.apple.quarantine '${outputApp}'`);
|
||||
logAndRun(["sudo", "xattr", "-dr", "com.apple.quarantine", outputApp]);
|
||||
} else {
|
||||
// WHY DOES NODE FETCH RETURN A WEB STREAM OH MY GOD
|
||||
const body = Readable.fromWeb(res.body);
|
||||
await finished(body.pipe(createWriteStream(outputFile, {
|
||||
mode: 0o755,
|
||||
autoClose: true
|
||||
})));
|
||||
await Bun.write(outputFile, new Uint8Array(await res.arrayBuffer()));
|
||||
if (process.platform !== "win32") {
|
||||
const { chmodSync } = await import("fs");
|
||||
chmodSync(outputFile, 0o755);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Finished downloading!");
|
||||
|
|
@ -118,19 +111,18 @@ const installerBin = await ensureBinary();
|
|||
|
||||
console.log("Now running Installer...");
|
||||
|
||||
const argStart = process.argv.indexOf("--");
|
||||
const args = argStart === -1 ? [] : process.argv.slice(argStart + 1);
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
try {
|
||||
execFileSync(installerBin, args, {
|
||||
stdio: "inherit",
|
||||
env: {
|
||||
...process.env,
|
||||
EQUICORD_USER_DATA_DIR: BASE_DIR,
|
||||
EQUICORD_DIRECTORY: join(BASE_DIR, "dist/desktop"),
|
||||
EQUICORD_DEV_INSTALL: "1"
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
const result = Bun.spawnSync([installerBin, ...args], {
|
||||
stdio: ["inherit", "inherit", "inherit"],
|
||||
env: {
|
||||
...process.env,
|
||||
EQUICORD_USER_DATA_DIR: BASE_DIR,
|
||||
EQUICORD_DIRECTORY: join(BASE_DIR, "dist/desktop"),
|
||||
EQUICORD_DEV_INSTALL: "1"
|
||||
}
|
||||
});
|
||||
|
||||
if (!result.success) {
|
||||
console.error("Something went wrong. Please check the logs above.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2022 Vendicated and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
process.emit = (originalEmit => function (name, data) {
|
||||
if (name === "warning" && data?.name === "ExperimentalWarning")
|
||||
return false;
|
||||
|
||||
return originalEmit.apply(process, arguments);
|
||||
})(process.emit);
|
||||
|
|
@ -16,8 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Dirent, readdirSync, readFileSync, writeFileSync } from "fs";
|
||||
import { access, readFile } from "fs/promises";
|
||||
import { Dirent, readdirSync } from "fs";
|
||||
import { join, sep } from "path";
|
||||
import { normalize as posixNormalize, sep as posixSep } from "path/posix";
|
||||
import { BigIntLiteral, createSourceFile, Identifier, isArrayLiteralExpression, isCallExpression, isExportAssignment, isIdentifier, isObjectLiteralExpression, isPropertyAccessExpression, isPropertyAssignment, isSatisfiesExpression, isStringLiteral, isVariableStatement, NamedDeclaration, NodeArray, ObjectLiteralExpression, PropertyAssignment, ScriptTarget, StringLiteral, SyntaxKind } from "typescript";
|
||||
|
|
@ -68,8 +67,8 @@ export function getObjectProp(node: ObjectLiteralExpression, name: string) {
|
|||
return prop;
|
||||
}
|
||||
|
||||
export function parseDevs() {
|
||||
const file = createSourceFile("constants.ts", readFileSync("src/utils/constants.ts", "utf8"), ScriptTarget.Latest);
|
||||
export async function parseDevs() {
|
||||
const file = createSourceFile("constants.ts", await Bun.file("src/utils/constants.ts").text(), ScriptTarget.Latest);
|
||||
|
||||
for (const child of file.getChildAt(0).getChildren()) {
|
||||
if (!isVariableStatement(child)) continue;
|
||||
|
|
@ -99,8 +98,8 @@ export function parseDevs() {
|
|||
throw new Error("Could not find Devs constant");
|
||||
}
|
||||
|
||||
export function parseEquicordDevs() {
|
||||
const file = createSourceFile("constants.ts", readFileSync("src/utils/constants.ts", "utf8"), ScriptTarget.Latest);
|
||||
export async function parseEquicordDevs() {
|
||||
const file = createSourceFile("constants.ts", await Bun.file("src/utils/constants.ts").text(), ScriptTarget.Latest);
|
||||
|
||||
for (const child of file.getChildAt(0).getChildren()) {
|
||||
if (!isVariableStatement(child)) continue;
|
||||
|
|
@ -131,7 +130,7 @@ export function parseEquicordDevs() {
|
|||
}
|
||||
|
||||
export async function parseFile(fileName: string) {
|
||||
const file = createSourceFile(fileName, await readFile(fileName, "utf8"), ScriptTarget.Latest);
|
||||
const file = createSourceFile(fileName, await Bun.file(fileName).text(), ScriptTarget.Latest);
|
||||
|
||||
const fail = (reason: string) => {
|
||||
return new Error(`Invalid plugin ${fileName}, because ${reason}`);
|
||||
|
|
@ -260,10 +259,7 @@ export async function getEntryPoint(dir: string, dirent: Dirent) {
|
|||
|
||||
for (const name of ["index.ts", "index.tsx"]) {
|
||||
const full = join(base, name);
|
||||
try {
|
||||
await access(full);
|
||||
return full;
|
||||
} catch { }
|
||||
if (await Bun.file(full).exists()) return full;
|
||||
}
|
||||
|
||||
throw new Error(`${dirent.name}: Couldn't find entry point`);
|
||||
|
|
|
|||
|
|
@ -180,7 +180,6 @@ export function toInlineCode(s: string) {
|
|||
return "``" + ZWSP + s.replaceAll("`", ZWSP + "`" + ZWSP) + ZWSP + "``";
|
||||
}
|
||||
|
||||
// @ts-expect-error Missing RegExp.escape
|
||||
export const escapeRegExp: (s: string) => string = RegExp.escape ?? function (s: string) {
|
||||
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue