diff --git a/README.md b/README.md index beac3bc..adc3019 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,7 @@ Current inbuilt patches are: Experiments, NoGiftButton and NoIdle Use [Vendetta](https://github.com/vendetta-mod/Vendetta) for more active development and community. ### What's so different about this mod? -Pyoncord has a different approach in how it fetches Discord modules. Unlike other mods, pyoncord waits for Discord to initialize a module, which is lazy loaded. This enables a faster start-up and prevents issues such as the [light/AMOLED theme bug](https://github.com/Aliucord/AliucordRN/issues/39) and [Hindi timestamps](https://github.com/enmity-mod/enmity/issues/11). +Pyoncord has a different approach in how it fetches Discord modules. Unlike other mods, pyoncord ~~waits for Discord to initialize a module, which is lazy loaded~~ only requires Discord modules when needed. This enables a faster start-up and prevents issues such as the [light/AMOLED theme bug](https://github.com/Aliucord/AliucordRN/issues/39) and [Hindi timestamps](https://github.com/enmity-mod/enmity/issues/11). -### Limitations -Due to how Pyoncord fetches Discord modules, modules may be required before they're loaded. This is unlikely to affect patches--but when requiring UI components. This *might* be solvable with a custom Hermes, which is planned. - -This limitation is why this mod exists in the first place, as rearchitecturing is needed to implement this approach in an existing mod. This also makes addons compatibility for other mods nearly impossible. - -### How can I try/contribute to this? -Pyoncord supports loading from Vendetta's loader, you can load Pyoncord by overriding the loader url to load Pyoncord instead. Be familiar with Vendetta development environment: [Vendetta#installing](https://github.com/vendetta-mod/Vendetta#installing) and [Vendetta#contributing](https://github.com/vendetta-mod/Vendetta#contributing). \ No newline at end of file +### How can I try/contribute to this project? +Pyoncord will soon have it own version of Xposed module, however for now, Pyoncord supports loading from Vendetta's loader, you can load Pyoncord by overriding the loader url (https://raw.githubusercontent.com/pyoncord/pyoncord/builds/pyoncord.js) to load Pyoncord instead. Be familiar with Vendetta development environment: [Vendetta#installing](https://github.com/vendetta-mod/Vendetta#installing) and [Vendetta#contributing](https://github.com/vendetta-mod/Vendetta#contributing). diff --git a/build.mjs b/build.mjs index 1e1f290..3c70855 100644 --- a/build.mjs +++ b/build.mjs @@ -9,42 +9,18 @@ import { createServer } from "http"; import { argv } from "process"; const flags = argv.slice(2).filter(arg => arg.startsWith("--")).map(arg => arg.slice(2)); -const isDev = !flags.includes("release"); +const isRelease = flags.includes("release"); const shouldServe = flags.includes("serve"); const shouldWatch = flags.includes("watch"); const commitHash = execSync("git rev-parse --short HEAD").toString().trim(); -console.log(`Building with commit hash ${commitHash}, isDev=${isDev}`); - -/** @type {import("esbuild").Plugin} */ -const swcPlugin = { - name: "swc", - setup(build) { - build.onLoad({ filter: /\.[jt]sx?/ }, async args => { - if (args.path?.includes(".json")) return; - - const result = await swc.transformFile(args.path, { - jsc: { - externalHelpers: true, - }, - env: { - targets: "defaults", - include: [ - "transform-classes", - "transform-arrow-functions", - ], - }, - }); - return { contents: result.code }; - }); - } -}; +console.log(`Building with commit hash ${commitHash}, isRelease=${isRelease}`); try { const ctx = await esbuild.context({ - entryPoints: ["entry.js"], + entryPoints: ["src/entry.js"], bundle: true, - minify: !isDev, + minify: isRelease, format: "esm", target: "esnext", outfile: "dist/pyoncord.js", @@ -52,22 +28,40 @@ try { write: false, define: { __PYONCORD_COMMIT_HASH__: JSON.stringify(commitHash), - __PYONCORD_DEV__: JSON.stringify(isDev) + __PYONCORD_DEV__: JSON.stringify(!isRelease) }, legalComments: "none", - alias: { - "@/*": "./src/*" - }, plugins: [ - swcPlugin, { - name: "bundleWrapper", + name: "swc", + setup(build) { + build.onLoad({ filter: /\.[jt]sx?/ }, async args => { + if (args.path?.includes(".json")) return; + + const result = await swc.transformFile(args.path, { + jsc: { + externalHelpers: true, + }, + env: { + targets: "defaults", + include: [ + "transform-classes", + "transform-arrow-functions", + ], + }, + }); + return { contents: result.code }; + }); + } + }, + { + name: "bundleWriter", setup: build => { build.onEnd(async ({ outputFiles }) => { if (outputFiles.length === 0) return; const { text, path } = outputFiles[0]; - const moduleDefHash = createHash("sha256").update(await readFile("internal-metro/requireDef.ts")).digest("hex"); + const moduleDefHash = createHash("sha256").update(await readFile("src/internal-metro/requireDef.ts")).digest("hex"); const contents = [ `globalThis.__PYON_MODULE_DEFINITIONS_HASH__='${moduleDefHash}';`, @@ -83,7 +77,7 @@ try { { name: "buildLog", setup: async build => { - build.onStart(() => console.log(`Building commit ${commitHash}, isDev=${isDev}...`)); + build.onStart(() => console.log(`Building commit ${commitHash}, isRelease=${isRelease}...`)); build.onEnd(result => console.log(`Built with ${result.errors?.length} errors!`)); } } @@ -96,9 +90,11 @@ try { } if (shouldServe) { + await ctx.rebuild(); + const server = createServer(async (req, res) => { try { - if (req.url.endsWith("/vendetta.js") || req.url.endsWith("/pyoncord.js")) { + if (req.url === "/vendetta.js" || req.url === "/pyoncord.js") { await ctx.rebuild(); const content = await readFile("./dist/pyoncord.js"); res.writeHead(200); diff --git a/package.json b/package.json index c05a7ba..54558f1 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,10 @@ "typings": "index.d.ts" }, "scripts": { - "build": "node build.mjs", - "deploy:root": "node build.mjs --deploy-root", + "dev": "node build.mjs", + "build": "node build.mjs --release", + "serve": "node build.mjs --serve", + "watch": "node build.mjs --watch", "lint": "eslint ./src --ext .js,.jsx,.ts,.tsx --ignore-pattern src/*", "prepublishOnly": "if [ -d lib ]; then rm -r lib; fi && tsc && cp package.json lib && cp LICENSE lib && cp README.md lib" }, @@ -39,7 +41,7 @@ "eslint-plugin-path-alias": "^1.0.0", "eslint-plugin-react": "^7.33.2", "eslint-plugin-simple-import-sort": "^10.0.0", - "typescript": "^5.3.3" + "typescript": "5.2.0" }, "dependencies": { "@swc/helpers": "^0.5.3", diff --git a/src/api/Patcher.ts b/src/core/api/Patcher.ts similarity index 100% rename from src/api/Patcher.ts rename to src/core/api/Patcher.ts diff --git a/src/api/SettingsAPI.ts b/src/core/api/SettingsAPI.ts similarity index 100% rename from src/api/SettingsAPI.ts rename to src/core/api/SettingsAPI.ts diff --git a/src/api/index.ts b/src/core/api/index.ts similarity index 100% rename from src/api/index.ts rename to src/core/api/index.ts diff --git a/src/debug/index.ts b/src/core/debug/index.ts similarity index 100% rename from src/debug/index.ts rename to src/core/debug/index.ts diff --git a/src/index.ts b/src/core/index.ts similarity index 100% rename from src/index.ts rename to src/core/index.ts diff --git a/src/managers/index.ts b/src/core/managers/index.ts similarity index 100% rename from src/managers/index.ts rename to src/core/managers/index.ts diff --git a/src/managers/plugins.ts b/src/core/managers/plugins.ts similarity index 100% rename from src/managers/plugins.ts rename to src/core/managers/plugins.ts diff --git a/src/metro/common.ts b/src/core/metro/common.ts similarity index 100% rename from src/metro/common.ts rename to src/core/metro/common.ts diff --git a/src/metro/index.ts b/src/core/metro/index.ts similarity index 98% rename from src/metro/index.ts rename to src/core/metro/index.ts index 5c9e3ad..ea97a7c 100644 --- a/src/metro/index.ts +++ b/src/core/metro/index.ts @@ -1,8 +1,8 @@ import proxyLazy from "@utils/proxyLazy"; import { after } from "spitroast"; +export * from "@internal-metro"; export * from "@metro/common"; -export * from "internal-metro"; declare const modules: Record; diff --git a/src/native.ts b/src/core/native.ts similarity index 100% rename from src/native.ts rename to src/core/native.ts diff --git a/src/patches/chatInput.ts b/src/core/patches/chatInput.ts similarity index 100% rename from src/patches/chatInput.ts rename to src/core/patches/chatInput.ts diff --git a/src/patches/experiments.ts b/src/core/patches/experiments.ts similarity index 100% rename from src/patches/experiments.ts rename to src/core/patches/experiments.ts diff --git a/src/patches/idle.ts b/src/core/patches/idle.ts similarity index 100% rename from src/patches/idle.ts rename to src/core/patches/idle.ts diff --git a/src/patches/index.ts b/src/core/patches/index.ts similarity index 100% rename from src/patches/index.ts rename to src/core/patches/index.ts diff --git a/src/patches/settings.tsx b/src/core/patches/settings.tsx similarity index 100% rename from src/patches/settings.tsx rename to src/core/patches/settings.tsx diff --git a/src/patches/theme.ts b/src/core/patches/theme.ts similarity index 100% rename from src/patches/theme.ts rename to src/core/patches/theme.ts diff --git a/src/themes.ts b/src/core/themes.ts similarity index 100% rename from src/themes.ts rename to src/core/themes.ts diff --git a/src/ui/screens/General.tsx b/src/core/ui/screens/General.tsx similarity index 100% rename from src/ui/screens/General.tsx rename to src/core/ui/screens/General.tsx diff --git a/src/ui/screens/Plugins.tsx b/src/core/ui/screens/Plugins.tsx similarity index 100% rename from src/ui/screens/Plugins.tsx rename to src/core/ui/screens/Plugins.tsx diff --git a/src/utils/assets.ts b/src/core/utils/assets.ts similarity index 100% rename from src/utils/assets.ts rename to src/core/utils/assets.ts diff --git a/src/utils/findInReactTree.ts b/src/core/utils/findInReactTree.ts similarity index 100% rename from src/utils/findInReactTree.ts rename to src/core/utils/findInReactTree.ts diff --git a/src/utils/findInTree.ts b/src/core/utils/findInTree.ts similarity index 100% rename from src/utils/findInTree.ts rename to src/core/utils/findInTree.ts diff --git a/src/utils/index.ts b/src/core/utils/index.ts similarity index 100% rename from src/utils/index.ts rename to src/core/utils/index.ts diff --git a/src/utils/lazyNavigate.tsx b/src/core/utils/lazyNavigate.tsx similarity index 100% rename from src/utils/lazyNavigate.tsx rename to src/core/utils/lazyNavigate.tsx diff --git a/src/utils/observeObject.ts b/src/core/utils/observeObject.ts similarity index 100% rename from src/utils/observeObject.ts rename to src/core/utils/observeObject.ts diff --git a/src/utils/proxyLazy.ts b/src/core/utils/proxyLazy.ts similarity index 100% rename from src/utils/proxyLazy.ts rename to src/core/utils/proxyLazy.ts diff --git a/entry.js b/src/entry.js similarity index 90% rename from entry.js rename to src/entry.js index 44bff09..2d13868 100644 --- a/entry.js +++ b/src/entry.js @@ -2,7 +2,7 @@ console.log(`Pyon! (Pyoncord, hash=${__PYONCORD_COMMIT_HASH__}, dev=${__PYONCORD try { Object.freeze = Object.seal = Object; - window.pyonRequire = await import("internal-metro/cacher").then(m => m.default()); + window.pyonRequire = await import("./internal-metro/cacher").then(m => m.default()); const { waitForModule } = await import("@metro"); diff --git a/global.d.ts b/src/global.d.ts similarity index 88% rename from global.d.ts rename to src/global.d.ts index 470e939..8ac25e6 100644 --- a/global.d.ts +++ b/src/global.d.ts @@ -1,4 +1,4 @@ -type PyoncordObject = Omit & { +type PyoncordObject = Omit & { unload: () => void; }; diff --git a/internal-metro/cacher.ts b/src/internal-metro/cacher.ts similarity index 100% rename from internal-metro/cacher.ts rename to src/internal-metro/cacher.ts diff --git a/internal-metro/index.ts b/src/internal-metro/index.ts similarity index 100% rename from internal-metro/index.ts rename to src/internal-metro/index.ts diff --git a/internal-metro/requireDef.ts b/src/internal-metro/requireDef.ts similarity index 92% rename from internal-metro/requireDef.ts rename to src/internal-metro/requireDef.ts index fbfd56b..7d9b8d2 100644 --- a/internal-metro/requireDef.ts +++ b/src/internal-metro/requireDef.ts @@ -1,4 +1,4 @@ -import { findByProps } from "internal-metro"; +import { findByProps } from "@internal-metro"; export default () => ({ "react": findByProps("createElement"), diff --git a/tsconfig.json b/tsconfig.json index e5ef691..f54146d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,7 @@ { "include": [ "src/**/*", - "global.d.ts", - "internal-metro/requireDef.ts", - "internal-metro/cacher.ts" + "src/global.d.ts", ], "exclude": [ "node_modules" @@ -25,7 +23,10 @@ "noImplicitAny": false, "paths": { "@*": [ - "src/*" + "src/core/*" + ], + "@internal-metro": [ + "src/internal-metro" ] } }