function sortAndNormalizeSpecifierMap(obj, baseURL) {
  assert(isJSONObject(obj));

  const normalized = /** @type {ParsedSpecifierMap} */ ({});

  for (const [specifierKey, value] of Object.entries(obj)) {
    const normalizedSpecifierKey = normalizeSpecifierKey(specifierKey, baseURL);
    if (!normalizedSpecifierKey) {
      continue;
    }

    if (typeof value !== 'string') {
      console.warn(
        `Invalid address ${JSON.stringify(value)} for the specifier key "${specifierKey}". ` +
          `Addresses must be strings.`,
      );
      normalized[normalizedSpecifierKey] = null;
      continue;
    }

    const addressURL = tryURLLikeSpecifierParse(value, baseURL);
    if (!addressURL) {
      console.warn(`Invalid address "${value}" for the specifier key "${specifierKey}".`);
      normalized[normalizedSpecifierKey] = null;
      continue;
    }

    if (specifierKey.endsWith('/') && !addressURL.href.endsWith('/')) {
      console.warn(
        `Invalid address "${addressURL.href}" for package specifier key "${specifierKey}". ` +
          `Package addresses must end with "/".`,
      );
      normalized[normalizedSpecifierKey] = null;
      continue;
    }

    normalized[normalizedSpecifierKey] = addressURL;
  }

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

  return sortedAndNormalized;
}
@param {SpecifierMap} obj
@param {URL} baseURL
@returns {ParsedSpecifierMap}