Skip to content

Commit

Permalink
fix: Select all available app ids for the given bundle name
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Mar 22, 2024
1 parent e90376c commit 8751792
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,23 @@ function getDebuggerAppKey (bundleId, appDict) {
*
* @param {string} bundleId
* @param {Record<string, any>} appDict
* @returns {string|undefined}
* @returns {string[]}
*/
function appIdForBundle (bundleId, appDict) {
let appId;
function appIdsForBundle (bundleId, appDict) {
/** @type {Set<string>} */
const appIds = new Set();
for (const [key, data] of _.toPairs(appDict)) {
if (data.bundleId.endsWith(bundleId)) {
appId = key;
break;
appIds.add(key);
}
}

// if nothing is found, try to get the generic app
if (!appId && bundleId !== WEB_CONTENT_BUNDLE_ID) {
return appIdForBundle(WEB_CONTENT_BUNDLE_ID, appDict);
if (appIds.size === 0 && bundleId !== WEB_CONTENT_BUNDLE_ID) {
return appIdsForBundle(WEB_CONTENT_BUNDLE_ID, appDict);
}

return appId;
return Array.from(appIds);
}

/**
Expand All @@ -176,7 +176,6 @@ function getPossibleDebuggerAppKeys(bundleIds, appDict) {
log.debug('Skip checking bundle identifiers because the bundleIds includes a wildcard');
return _.uniq(Object.keys(appDict));
}
let proxiedAppIds = [];

// go through the possible bundle identifiers
const possibleBundleIds = _.uniq([
Expand All @@ -188,24 +187,24 @@ function getPossibleDebuggerAppKeys(bundleIds, appDict) {
...bundleIds,
]);
log.debug(`Checking for bundle identifiers: ${possibleBundleIds.join(', ')}`);
/** @type {Set<string>} */
const proxiedAppIds = new Set();
for (const bundleId of possibleBundleIds) {
const appId = appIdForBundle(bundleId, appDict);

// now we need to determine if we should pick a proxy for this instead
if (appId) {
proxiedAppIds.push(appId);
for (const appId of appIdsForBundle(bundleId, appDict)) {
proxiedAppIds.add(appId);
log.debug(`Found app id key '${appId}' for bundle '${bundleId}'`);
for (const [key, data] of _.toPairs(appDict)) {
if (data.isProxy && data.hostId === appId) {
log.debug(`Found separate bundleId '${data.bundleId}' ` +
`acting as proxy for '${bundleId}', with app id '${key}'`);
proxiedAppIds.push(key);
proxiedAppIds.add(key);
}
}
}
}

return _.uniq(proxiedAppIds);
return Array.from(proxiedAppIds);
}

function checkParams (params) {
Expand Down

0 comments on commit 8751792

Please sign in to comment.