Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Folder restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Jan 13, 2024
1 parent c80ee49 commit 715d362
Show file tree
Hide file tree
Showing 35 changed files with 50 additions and 56 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
### 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).
70 changes: 33 additions & 37 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,59 @@ 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",
keepNames: true,
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}';`,
Expand All @@ -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!`));
}
}
Expand All @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/metro/index.ts → src/core/metro/index.ts
Original file line number Diff line number Diff line change
@@ -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<number, any>;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion entry.js → src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion global.d.ts → src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type PyoncordObject = Omit<typeof import("./src"), "default"> & {
type PyoncordObject = Omit<typeof import("./srcb/src"), "default"> & {
unload: () => void;
};

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findByProps } from "internal-metro";
import { findByProps } from "@internal-metro";

export default () => ({
"react": findByProps("createElement"),
Expand Down
9 changes: 5 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"include": [
"src/**/*",
"global.d.ts",
"internal-metro/requireDef.ts",
"internal-metro/cacher.ts"
"src/global.d.ts",
],
"exclude": [
"node_modules"
Expand All @@ -25,7 +23,10 @@
"noImplicitAny": false,
"paths": {
"@*": [
"src/*"
"src/core/*"
],
"@internal-metro": [
"src/internal-metro"
]
}
}
Expand Down

0 comments on commit 715d362

Please sign in to comment.