Skip to content

Commit

Permalink
πŸ› fix: fixes for android & the build script on windows (#6)
Browse files Browse the repository at this point in the history
* Fix serve script on non-Unix systems

* Use `Set` for module IDs blacklist

* Block initializing blacklisted modules

* Add back RTN Profiler patch for Android
  • Loading branch information
PalmDevs authored Jan 25, 2025
1 parent 17f8fa3 commit 0dcc2d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
},
"scripts": {
"build": "rollup -c",
"serve": "clear && bun run server/index.ts"
"serve": "bun run server/index.ts"
},
"dependencies": {
"react-native-svg": "^15.11.1"
}
}
}
2 changes: 2 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
console.clear();

const BASE_PATH = './dist';
const PORT = Bun.argv[2] ?? 8080;

Expand Down
31 changes: 16 additions & 15 deletions src/api/metro/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CACHE_KEY } from '@constants';
import Filters from './filters';


const blacklist = [];
const blacklist = new Set();

export { CACHE_KEY } from '@constants';
export type * from '@typings/api/metro';
Expand All @@ -27,7 +27,7 @@ for (let i = 0, len = Cache.moduleIds.length; i < len; i++) {
const mdl = window.modules.get(id);

if (Cache.hasModuleFlag(id, ModuleFlags.BLACKLISTED)) {
blacklist.push(id);
blacklist.add(id);
continue;
}

Expand All @@ -43,18 +43,19 @@ for (let i = 0, len = Cache.moduleIds.length; i < len; i++) {

if (isInvalidExport(exported)) {
Cache.addModuleFlag(moduleObject.id, ModuleFlags.BLACKLISTED);
blacklist.push(moduleObject.id);
blacklist.add(moduleObject.id);
} else {
// TODO: Fix android.
// if (!data.patchedRTNProfiler && exported.default?.reactProfilingEnabled) {
// const offender = (Number(id) + 1).toString();
if (!data.patchedRTNProfiler && exported.default?.reactProfilingEnabled) {
const offender = id + 1;

// Cacher.addFlag(offender, ModuleFlags.BLACKLISTED);
// deenumerate(offender);
// i++;
if (!window.modules.get(offender)?.isInitialized) {
Cache.addModuleFlag(offender, ModuleFlags.BLACKLISTED);
blacklist.add(offender);
i++;

// data.patchedRTNProfiler = true;
// }
data.patchedRTNProfiler = true;
}
}

if (!data.patchedNativeRequire && exported.default?.name === 'requireNativeComponent') {
const orig = exported.default;
Expand Down Expand Up @@ -150,8 +151,6 @@ export function find(filter: Filter | Filter, options: SearchOptions = {}) {
const rawModule = window.modules.get(id);
if (!rawModule) continue;

if (blacklist.includes(id)) continue;

if (!rawModule.isInitialized) {
const initialized = initializeModule(id);
if (!initialized) continue;
Expand Down Expand Up @@ -261,6 +260,8 @@ export function findByName<U extends string, T extends U[] | StringFindWithOptio
};

export function initializeModule(id: number) {
if (blacklist.has(id)) return;

try {
__r(id);

Expand All @@ -273,7 +274,7 @@ export function initializeModule(id: number) {
return true;
} catch (e) {
Cache.addModuleFlag(id, ModuleFlags.BLACKLISTED);
blacklist.push(id);
blacklist.add(id);
return false;
}
}
Expand All @@ -284,7 +285,7 @@ function searchExports(filter: Fn, rawModule: any, id: number, esModules: boolea

if (isInvalidExport(mdl)) {
Cache.addModuleFlag(id, ModuleFlags.BLACKLISTED);
blacklist.push(id);
blacklist.add(id);
return null;
}

Expand Down

0 comments on commit 0dcc2d1

Please sign in to comment.