{
  "version": 3,
  "sources": ["../../../../src/packages/catalogs.resolver/resolveFromCatalog.ts"],
  "sourcesContent": ["import { PnpmError } from '../error/index.ts';\nimport { parseCatalogProtocol } from '../catalogs.protocol-parser/index.ts';\nimport type { Catalogs } from '../catalogs.types/index.ts';\nimport type { WantedDependency } from '../resolve-dependencies/index.ts';\n\n/**\n * Dereferences a wanted dependency using the catalog protocol and returns the\n * configured version.\n *\n * Example: catalog:default -> ^1.2.3\n */\nexport type CatalogResolver = (\n  wantedDependency: WantedDependency\n) => CatalogResolutionResult;\n\nexport type CatalogResolutionResult =\n  | CatalogResolutionFound\n  | CatalogResolutionMisconfiguration\n  | CatalogResolutionUnused;\n\nexport interface CatalogResolutionFound {\n  readonly type: 'found';\n  readonly resolution: CatalogResolution;\n}\n\nexport interface CatalogResolution {\n  /**\n   * The name of the catalog the resolved specifier was defined in.\n   */\n  readonly catalogName: string;\n\n  /**\n   * The specifier that should be used for the wanted dependency. This is a\n   * usable version that replaces the catalog protocol with the relevant user\n   * defined specifier.\n   */\n  readonly specifier: string;\n}\n\n/**\n * The user misconfigured a catalog entry. The entry could be missing or\n * invalid.\n */\nexport interface CatalogResolutionMisconfiguration {\n  readonly type: 'misconfiguration';\n\n  /**\n   * Convenience error to rethrow.\n   */\n  readonly error: PnpmError;\n  readonly catalogName: string;\n}\n\n/**\n * The wanted dependency does not use the catalog protocol.\n */\nexport interface CatalogResolutionUnused {\n  readonly type: 'unused';\n}\n\nexport function resolveFromCatalog(\n  catalogs: Catalogs,\n  wantedDependency: WantedDependency\n): CatalogResolutionResult {\n  if (\n    typeof wantedDependency.alias !== 'string' ||\n    typeof wantedDependency.pref !== 'string'\n  ) {\n    return { type: 'unused' };\n  }\n\n  const catalogName = parseCatalogProtocol(wantedDependency.pref);\n\n  if (catalogName == null) {\n    return { type: 'unused' };\n  }\n\n  const catalogLookup = catalogs[catalogName]?.[wantedDependency.alias];\n\n  if (catalogLookup == null) {\n    return {\n      type: 'misconfiguration',\n      catalogName,\n      error: new PnpmError(\n        'CATALOG_ENTRY_NOT_FOUND_FOR_SPEC',\n        `No catalog entry '${wantedDependency.alias}' was found for catalog '${catalogName}'.`\n      ),\n    };\n  }\n\n  if (parseCatalogProtocol(catalogLookup) != null) {\n    return {\n      type: 'misconfiguration',\n      catalogName,\n      error: new PnpmError(\n        'CATALOG_ENTRY_INVALID_RECURSIVE_DEFINITION',\n        `Found invalid catalog entry using the catalog protocol recursively. The entry for '${wantedDependency.alias}' in catalog '${catalogName}' is invalid.`\n      ),\n    };\n  }\n\n  // Ban catalog entries that use the workspace protocol for a few reasons:\n  //\n  //   1. It's kind of silly. It'd be better to encourage users to use the\n  //      workspace protocol directly.\n  //   2. Catalogs cache the resolved version of a dependency specifier in\n  //      pnpm-lock.yaml for more consistent resolution across importers. The\n  //      link: resolutions can't be shared between importers.\n  const protocolOfLookup = catalogLookup.split(':')[0];\n  if (protocolOfLookup === 'workspace') {\n    return {\n      type: 'misconfiguration',\n      catalogName,\n      error: new PnpmError(\n        'CATALOG_ENTRY_INVALID_WORKSPACE_SPEC',\n        `The workspace protocol cannot be used as a catalog value. The entry for '${wantedDependency.alias}' in catalog '${catalogName}' is invalid.`\n      ),\n    };\n  }\n\n  // A future version of pnpm will try to support this. These protocols aren't\n  // supported today since these are often relative file paths that users expect\n  // to be relative to the repo root rather than the location of the pnpm\n  // workspace package.\n  if (['link', 'file'].includes(protocolOfLookup ?? '')) {\n    return {\n      type: 'misconfiguration',\n      catalogName,\n      error: new PnpmError(\n        'CATALOG_ENTRY_INVALID_SPEC',\n        `The entry for '${wantedDependency.alias}' in catalog '${catalogName}' declares a dependency using the '${protocolOfLookup}' protocol. This is not yet supported, but may be in a future version of pnpm.`\n      ),\n    };\n  }\n\n  return {\n    type: 'found',\n    resolution: {\n      catalogName,\n      specifier: catalogLookup,\n    },\n  };\n}\n"],
  "mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B;AA2D9B,SAAS,mBACd,UACA,kBACyB;AACzB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