feat(lib/modules/metro/utils)!: remove confusing functions
This commit is contained in:
parent
6a6a67e78f
commit
b56e6153a5
3 changed files with 28 additions and 47 deletions
|
|
@ -1,9 +1,5 @@
|
|||
import { _inits } from '../metro/_internal'
|
||||
import {
|
||||
getModuleDependencies,
|
||||
initializedModuleHasBadExports,
|
||||
isModuleInitialized,
|
||||
} from '../metro/utils'
|
||||
import { getModuleDependencies, isModuleInitialized } from '../metro/utils'
|
||||
import type { If, LogicalOr } from '@revenge-mod/utils/types'
|
||||
import type { Metro } from '../types'
|
||||
|
||||
|
|
@ -533,8 +529,7 @@ export const moduleStateAware = createFilterGenerator<
|
|||
>(
|
||||
([initializedFilter, uninitializedFilter, strict], id, exports) => {
|
||||
if (isModuleInitialized(id)) {
|
||||
if (initializedModuleHasBadExports(id)) return false
|
||||
if (initializedFilter(id, exports))
|
||||
if (_inits.has(id) && initializedFilter(id, exports))
|
||||
return strict ? uninitializedFilter(id) : true
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
import { _inits } from '../metro/_internal'
|
||||
import {
|
||||
onAnyModuleInitialized,
|
||||
onModuleFinishedImporting,
|
||||
} from '../metro/subscriptions'
|
||||
import {
|
||||
getInitializedModuleExports,
|
||||
initializedModuleHasBadExports,
|
||||
} from '../metro/utils'
|
||||
import { getInitializedModuleExports } from '../metro/utils'
|
||||
import { exportsFromFilterResultFlag, runFilter } from './_internal'
|
||||
import type { MaybeDefaultExportMatched, Metro } from '../types'
|
||||
import type { RunFilterReturnExportsOptions } from './_internal'
|
||||
|
|
@ -91,13 +89,18 @@ export function waitForModules(
|
|||
)
|
||||
}
|
||||
: (id, exports) => {
|
||||
if (initializedModuleHasBadExports(id)) return
|
||||
const flag = runFilter(filter, id, exports, options)
|
||||
if (flag)
|
||||
callback(
|
||||
exportsFromFilterResultFlag(flag, exports, options),
|
||||
id,
|
||||
)
|
||||
if (_inits.has(id)) {
|
||||
const flag = runFilter(filter, id, exports, options)
|
||||
if (flag)
|
||||
callback(
|
||||
exportsFromFilterResultFlag(
|
||||
flag,
|
||||
exports,
|
||||
options,
|
||||
),
|
||||
id,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -138,9 +141,8 @@ export function waitForModuleByImportedPath<T = any>(
|
|||
}
|
||||
}
|
||||
: (id, cmpPath) => {
|
||||
if (path === cmpPath) {
|
||||
if (path === cmpPath && _inits.has(id)) {
|
||||
unsub()
|
||||
if (initializedModuleHasBadExports(id)) return
|
||||
callback(getInitializedModuleExports(id), id)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,55 +1,39 @@
|
|||
import { isProxy } from '@revenge-mod/utils/proxy'
|
||||
import { _inits, _metas, _uninits } from './_internal'
|
||||
import { _metas } from './_internal'
|
||||
import type { Metro } from '../types'
|
||||
|
||||
/**
|
||||
* Returns whether an uninitialized module has bad exports.
|
||||
*
|
||||
* @see {@link isModuleExportsBad} for more information on what is considered bad module exports.
|
||||
*
|
||||
* @param id The module ID.
|
||||
*/
|
||||
export function uninitializedModuleHasBadExports(id: Metro.ModuleID): boolean {
|
||||
return !_uninits.has(id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether an initialized module has bad exports.
|
||||
*
|
||||
* @see {@link isModuleExportsBad} for more information on what is considered bad module exports.
|
||||
*
|
||||
* @param id The module ID.
|
||||
*/
|
||||
export function initializedModuleHasBadExports(id: Metro.ModuleID): boolean {
|
||||
return !_inits.has(id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dependencies of a module.
|
||||
* @param id The module ID.
|
||||
* @throws {TypeError} If the module with the given ID does not exist.
|
||||
*/
|
||||
export function getModuleDependencies(
|
||||
id: Metro.ModuleID,
|
||||
): Metro.DependencyMap | undefined {
|
||||
return _metas.get(id)?.[0]
|
||||
return _metas.get(id)![0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a module is initialized.
|
||||
* @param id The module ID.
|
||||
* @throws {TypeError} If the module with the given ID does not exist.
|
||||
*/
|
||||
export function isModuleInitialized(id: Metro.ModuleID): boolean {
|
||||
return _metas.get(id)?.[1]!
|
||||
export function isModuleInitialized(id: Metro.ModuleID): boolean | undefined {
|
||||
return _metas.get(id)![1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exports of an initialized module.
|
||||
*
|
||||
* @see {@link isModuleInitialized} to check if the module is initialized.
|
||||
*
|
||||
* @param id The module ID.
|
||||
* @throws {TypeError} If the module with the given ID does not exist, or is not initialized.
|
||||
*/
|
||||
export function getInitializedModuleExports(
|
||||
id: Metro.ModuleID,
|
||||
): Metro.ModuleExports | undefined {
|
||||
return _metas.get(id)?.[2]?.exports
|
||||
return _metas.get(id)![2]!.exports
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue