fix(lib/modules): fix subscriptions not having correct module ids
This commit is contained in:
parent
0e09be1728
commit
b29e1bc2f6
3 changed files with 22 additions and 10 deletions
|
|
@ -28,7 +28,7 @@ export function patchMetroDefine(metroDefine: Metro.DefineFn) {
|
|||
const prevIId = _mInitingId
|
||||
_mInitingId = id
|
||||
|
||||
_executeRequiredSubscription()
|
||||
_executeRequiredSubscription(id)
|
||||
|
||||
try {
|
||||
origFactory(global, req, importDefault, importAll, module, exports, deps)
|
||||
|
|
@ -43,7 +43,7 @@ export function patchMetroDefine(metroDefine: Metro.DefineFn) {
|
|||
_mInitingId = prevIId
|
||||
_mUninited.delete(id)
|
||||
// Don't use exports here, as modules can set module.exports to a different object
|
||||
_executeInitializedSubscription(module.exports)
|
||||
_executeInitializedSubscription(id, module.exports)
|
||||
}
|
||||
}) satisfies Metro.FactoryFn,
|
||||
id,
|
||||
|
|
@ -73,3 +73,16 @@ export function _blacklist(id: Metro.ModuleID) {
|
|||
|
||||
// TODO(modules): caching
|
||||
}
|
||||
|
||||
/// BLACKLIST RESTORATION
|
||||
|
||||
if (globalThis.__REVENGE_CACHE_MODULE_BLACKLIST__)
|
||||
for (const id of globalThis.__REVENGE_CACHE_MODULE_BLACKLIST__) _blacklist(id)
|
||||
|
||||
// @ts-expect-error
|
||||
// biome-ignore lint/performance/noDelete: no
|
||||
delete globalThis.__REVENGE_CACHE_MODULE_BLACKLIST__
|
||||
|
||||
declare namespace globalThis {
|
||||
const __REVENGE_CACHE_MODULE_BLACKLIST__: Metro.ModuleID[] | undefined
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ const unsubForImportTracker = waitForModules(byProps('fileFinishedImporting'), (
|
|||
unsubForImportTracker()
|
||||
exports.fileFinishedImporting = (path: string) => {
|
||||
orig(path)
|
||||
_mPaths.set(path, _mInitingId)
|
||||
_executeImportedPathSubscription(path)
|
||||
const id = _mInitingId
|
||||
_mPaths.set(path, id)
|
||||
_executeImportedPathSubscription(id, path)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ export const _initAll = new Set<ModuleInitializedCallback>()
|
|||
export const _initSpecific = new Map<Metro.ModuleID, Set<ModuleInitializedCallback>>()
|
||||
export const _importedPath = new Set<ModuleWithImportedPathInitializedCallback>()
|
||||
|
||||
export function _executeRequiredSubscription() {
|
||||
const id = _mInitingId
|
||||
export function _executeRequiredSubscription(id: Metro.ModuleID) {
|
||||
for (const cb of _reqAll) cb(id)
|
||||
if (_reqSpecific.has(id)) {
|
||||
for (const cb of _reqSpecific.get(id)!) cb(id)
|
||||
|
|
@ -18,8 +17,7 @@ export function _executeRequiredSubscription() {
|
|||
}
|
||||
}
|
||||
|
||||
export function _executeInitializedSubscription(exports: Metro.ModuleExports) {
|
||||
const id = _mInitingId
|
||||
export function _executeInitializedSubscription(id: Metro.ModuleID, exports: Metro.ModuleExports) {
|
||||
for (const cb of _initAll) cb(id, exports)
|
||||
if (_initSpecific.has(id)) {
|
||||
for (const cb of _initSpecific.get(id)!) cb(id, exports)
|
||||
|
|
@ -27,6 +25,6 @@ export function _executeInitializedSubscription(exports: Metro.ModuleExports) {
|
|||
}
|
||||
}
|
||||
|
||||
export function _executeImportedPathSubscription(path: string) {
|
||||
for (const cb of _importedPath) cb(_mInitingId, path)
|
||||
export function _executeImportedPathSubscription(id: Metro.ModuleID, path: string) {
|
||||
for (const cb of _importedPath) cb(id, path)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue