fix(lib/modules/metro/runtime): add flag once importedAll or importedDefault exports cached
This commit is contained in:
parent
dba76a9f81
commit
d8d85cfab1
5 changed files with 14 additions and 5 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { getCurrentStack } from '@revenge-mod/utils/error'
|
||||
import { cacheFilterResultForId } from '../caches'
|
||||
import { metroRequire } from '../metro/custom'
|
||||
import { mInitialized } from '../metro/patches'
|
||||
import { metroRequire } from '../metro/runtime'
|
||||
import { isModuleExportBad } from '../metro/utils'
|
||||
import { FilterFlag } from './filters'
|
||||
import type { If } from '@revenge-mod/utils/types'
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { getCurrentStack } from '@revenge-mod/utils/error'
|
||||
import { proxify } from '@revenge-mod/utils/proxy'
|
||||
import { cacheFilterNotFound, getFilterMatches } from '../caches'
|
||||
import { metroRequire } from '../metro/custom'
|
||||
import {
|
||||
mImportedPaths,
|
||||
mInitialized,
|
||||
mList,
|
||||
mUninitialized,
|
||||
} from '../metro/patches'
|
||||
import { metroRequire } from '../metro/runtime'
|
||||
import {
|
||||
getInitializedModuleExports,
|
||||
isModuleInitialized,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import {
|
|||
metroImportAll,
|
||||
metroImportDefault,
|
||||
metroRequire,
|
||||
} from './custom'
|
||||
} from './runtime'
|
||||
import { onModuleInitialized } from './subscriptions'
|
||||
import {
|
||||
executeImportedPathSubscriptions,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
/**
|
||||
* A more performant implementation of Metro's core functions.
|
||||
* A minimal implementation of Metro's runtime with little overhead.
|
||||
* Making initialization faster and use less resources.
|
||||
*
|
||||
* Also avoids cloning exports, allowing for patches to be applied directly without checking for clones.
|
||||
*/
|
||||
|
||||
import { mList } from './patches'
|
||||
|
|
@ -58,6 +60,9 @@ export const metroImportDefault: Metro.RequireFn = moduleId => {
|
|||
if (mod.flags & HasImportedDefault) return mod.importedDefault
|
||||
|
||||
const exports = metroRequire(moduleId)
|
||||
|
||||
mod.flags |= HasImportedDefault
|
||||
|
||||
return (mod.importedDefault = exports?.__esModule
|
||||
? exports.default
|
||||
: exports)
|
||||
|
|
@ -68,7 +73,11 @@ export const metroImportAll: Metro.RequireFn = moduleId => {
|
|||
if (mod.flags & HasImportedAll) return mod.importedAll
|
||||
|
||||
const exports = metroRequire(moduleId)
|
||||
// Our implementation doesn't match Metro's because we modify the exports directly instead of cloning
|
||||
// But this is why ours is superior, it allows patching the exports without needing to do it more than a single time
|
||||
if (!exports?.__esModule) exports.default = exports
|
||||
|
||||
mod.flags |= HasImportedAll
|
||||
|
||||
return (mod.importedAll = exports)
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { isProxy } from '@revenge-mod/utils/proxy'
|
||||
import { Initialized } from './custom'
|
||||
import { mDeps, mList } from './patches'
|
||||
import { Initialized } from './runtime'
|
||||
import type { Metro } from '../types'
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue