{
  "version": 3,
  "sources": ["../../../../src/packages/reviewing.dependencies-hierarchy/getTreeNodeChildId.ts"],
  "sourcesContent": ["import { refToRelative } from '../dependency-path/index.ts';\nimport path from 'node:path';\nimport { getLockfileImporterId } from '../lockfile.fs/index.ts';\nimport type { TreeNodeId } from './TreeNodeId.ts';\nimport type { ProjectSnapshot } from '../lockfile.types/index.ts';\n\nexport type getTreeNodeChildIdOpts = {\n  readonly parentId: TreeNodeId;\n  readonly dep: {\n    readonly alias: string;\n    readonly ref: string;\n  };\n  readonly lockfileDir: string;\n  readonly importers: Record<string, ProjectSnapshot>;\n};\n\nexport function getTreeNodeChildId(\n  opts: getTreeNodeChildIdOpts\n): TreeNodeId | undefined {\n  const depPath = refToRelative(opts.dep.ref, opts.dep.alias);\n\n  if (depPath !== null) {\n    return { type: 'package', depPath };\n  }\n\n  switch (opts.parentId.type) {\n    case 'importer': {\n      // This should be a link given depPath is null.\n      //\n      // TODO: Consider updating refToRelative (or writing a new function) to\n      // return an enum so there's no implicit assumptions.\n      const linkValue = opts.dep.ref.slice('link:'.length);\n\n      // It's a bit roundabout to prepend the lockfile dir only to remove it\n      // through getLockfileImporterId, but we can be more certain the right\n      // importerId is created by reusing the getLockfileImporterId function.\n      const absoluteLinkedPath = path.join(\n        opts.lockfileDir,\n        opts.parentId.importerId,\n        linkValue\n      );\n      const childImporterId = getLockfileImporterId(\n        opts.lockfileDir,\n        absoluteLinkedPath\n      );\n\n      // A 'link:' reference may refer to a package outside of the pnpm workspace.\n      // Return undefined in that case since it would be difficult to list/traverse\n      // that package outside of the pnpm workspace.\n      const isLinkOutsideWorkspace = opts.importers[childImporterId] == null;\n\n      return isLinkOutsideWorkspace\n        ? undefined\n        : { type: 'importer', importerId: childImporterId };\n    }\n\n    case 'package':\n      // In theory an external package could be overridden to link to a\n      // dependency in the pnpm workspace. Avoid traversing through this\n      // edge case for now.\n      return undefined;\n  }\n}\n"],
  "mappings": "AAAA,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AACjB,SAAS,6BAA6B;AAc/B,SAAS,mBACd,MACwB;AACxB,QAAM,UAAU,cAAc,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK;AAE1D,MAAI,YAAY,MAAM;AACpB,WAAO,EAAE,MAAM,WAAW,QAAQ;AAAA,EACpC;AAEA,UAAQ,KAAK,SAAS,MAAM;AAAA,IAC1B,KAAK,YAAY;AAKf,YAAM,YAAY,KAAK,IAAI,IAAI,MAAM,QAAQ,MAAM;AAKnD,YAAM,qBAAqB,KAAK;AAAA,QAC9B,KAAK;AAAA,QACL,KAAK,SAAS;AAAA,QACd;AAAA,MACF;AACA,YAAM,kBAAkB;AAAA,QACtB,KAAK;AAAA,QACL;AAAA,MACF;AAKA,YAAM,yBAAyB,KAAK,UAAU,eAAe,KAAK;AAElE,aAAO,yBACH,SACA,EAAE,MAAM,YAAY,YAAY,gBAAgB;AAAA,IACtD;AAAA,IAEA,KAAK;AAIH,aAAO;AAAA,EACX;AACF;",
  "names": []
}
