Skip to content

Commit

Permalink
Remove __vendettaVersion and use constModules
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Feb 23, 2024
1 parent 6e4c6df commit 98ca130
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
10 changes: 6 additions & 4 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ try {
jsc: {
externalHelpers: true,
transform: {
optimizer: {
constModules: {
globals: {
vars: {
__vendettaIsDev: `${!isRelease}`,
__vendettaVersion: `"${isRelease ? commitHash : timeString}"`,
"bunny-build": {
version: `"${isRelease ? commitHash : timeString}"`
}
}
}
Expand All @@ -86,6 +85,9 @@ try {
"transform-classes",
"transform-arrow-functions",
"transform-block-scoping"
],
exclude: [
"transform-parameters"
]
},
});
Expand Down
5 changes: 3 additions & 2 deletions src/entry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { instead } from "spitroast";
import { version } from "bunny-build";

// @ts-ignore - shut up fr
globalThis.window = globalThis;
Expand All @@ -18,9 +19,9 @@ const init = (async () => {

console.log(stack ?? e?.toString?.() ?? e);
alert([
"Failed to load Vendetta!\n",
"Failed to load Bunny!\n",
`Build Number: ${ClientInfoManager.Build}`,
`Vendetta: ${__vendettaVersion}`,
`Bunny: ${version}`,
stack || e?.toString?.(),
].join("\n"));
}
Expand Down
1 change: 0 additions & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BunnyObject } from "@lib/windowObject";

declare global {
type React = typeof import("react");
const __vendettaVersion: string;

interface Window {
[key: string]: any;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import settings from "@lib/settings";
import logger from "@lib/logger";
import { getLoaderName, isThemeSupported } from "./loader";
import type { PlatformConstants } from "react-native";
import { version } from "bunny-build";
export let socket: WebSocket;

export interface RNConstants extends PlatformConstants {
Expand Down Expand Up @@ -78,7 +79,7 @@ export function patchLogHook() {
}
}

export const versionHash: string = __vendettaVersion;
export const versionHash: string = version;

export function getDebugInfo() {
// Hermes
Expand Down
12 changes: 7 additions & 5 deletions src/lib/metro/filters.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { instead } from "@lib/patcher";

export type MetroModules = { [id: number]: any };
type MetroModulesIndex = `${number}` | number;

export type MetroModules = { [id: MetroModulesIndex]: any };
export type PropIntellisense<P extends string | symbol> = Record<P, any> & Record<PropertyKey, any>;
export type PropsFinder = <T extends string | symbol>(...props: T[]) => PropIntellisense<T>;
export type PropsFinderAll = <T extends string | symbol>(...props: T[]) => PropIntellisense<T>[];

// Metro require
declare const __r: (moduleId: number) => any;
declare const __r: (moduleId: MetroModulesIndex) => any;

// Internal Metro error reporting logic
const originalHandler = window.ErrorUtils.getGlobalHandler();

// Function to blacklist a module, preventing it from being searched again
const blacklist = (id: number) => Object.defineProperty(window.modules, id, {
const blacklist = (id: MetroModulesIndex) => Object.defineProperty(window.modules, id, {
value: window.modules[id],
enumerable: false,
configurable: true,
Expand All @@ -21,7 +23,7 @@ const blacklist = (id: number) => Object.defineProperty(window.modules, id, {

// Blacklist any "bad-actor" modules, e.g. the dreaded null proxy, the window itself, or undefined modules
for (const key in window.modules) {
const id = Number(key);
const id = key as MetroModulesIndex;
const module = window.modules[id]?.publicModule?.exports;

if (!module || module === window || module["proxygone"] === null) {
Expand Down Expand Up @@ -51,7 +53,7 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
const found = [];

for (const key in modules) {
const id = Number(key);
const id = key as MetroModulesIndex;
const module = modules[id]?.publicModule?.exports;

if (!modules[id].isInitialized) try {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/windowObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function createBunnyObject(unloads: any[]) {
storage: { ...storage },
settings: settings,
loader: {
identity: window.__vendetta_loader,
identity: null,
config: loaderConfig,
},
logger: { ...logger },
Expand Down
3 changes: 3 additions & 0 deletions src/modules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "bunny-build" {
const version: string;
}

0 comments on commit 98ca130

Please sign in to comment.