function sortAndNormalizeScopes(obj, baseURL) {
  const normalized = /** @type {ParsedScopesMap} */ ({});
  for (const [scopePrefix, potentialSpecifierMap] of Object.entries(obj)) {
    if (!isJSONObject(potentialSpecifierMap)) {
      throw new TypeError(`The value for the "${scopePrefix}" scope prefix must be an object.`);
    }

    const scopePrefixURL = tryURLParse(scopePrefix, baseURL);
    if (!scopePrefixURL) {
      console.warn(`Invalid scope "${scopePrefix}" (parsed against base URL "${baseURL}").`);
      continue;
    }

    const normalizedScopePrefix = scopePrefixURL.href;
    normalized[normalizedScopePrefix] = sortAndNormalizeSpecifierMap(
      potentialSpecifierMap,
      baseURL,
    );
  }

  const sortedAndNormalized = /** @type {ParsedScopesMap} */ ({});
  const sortedKeys = Object.keys(normalized).sort((a, b) => codeUnitCompare(b, a));
  for (const key of sortedKeys) {
    sortedAndNormalized[key] = normalized[key];
  }

  return sortedAndNormalized;
}
@param {ScopesMap} obj
@param {URL} baseURL