{"version":3,"file":"manifest.cjs","names":[],"sources":["../../src/utils/manifest.ts"],"sourcesContent":["import { Remote } from '../type';\n\nexport function composeRemoteRequestId(\n  remoteName: string,\n  expose?: string,\n): string {\n  if (!expose || expose === '.') {\n    return remoteName;\n  }\n\n  return `${remoteName}/${expose.replace(/^\\.\\//, '')}`;\n}\n\n// Function to match a remote with its name and expose\n// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button\n// id: alias(app1) + expose(button) = app1/button\n// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort\nexport function matchRemoteWithNameAndExpose(\n  remotes: Array<Remote>,\n  id: string,\n):\n  | {\n      pkgNameOrAlias: string;\n      expose: string;\n      remote: Remote;\n    }\n  | undefined {\n  for (const remote of remotes) {\n    // match pkgName\n    const isNameMatched = id.startsWith(remote.name);\n    let expose = id.replace(remote.name, '');\n    if (isNameMatched) {\n      if (expose.startsWith('/')) {\n        const pkgNameOrAlias = remote.name;\n        expose = `.${expose}`;\n        return {\n          pkgNameOrAlias,\n          expose,\n          remote,\n        };\n      } else if (expose === '') {\n        return {\n          pkgNameOrAlias: remote.name,\n          expose: '.',\n          remote,\n        };\n      }\n    }\n\n    // match alias\n    const isAliasMatched = remote.alias && id.startsWith(remote.alias);\n    let exposeWithAlias = remote.alias && id.replace(remote.alias, '');\n    if (remote.alias && isAliasMatched) {\n      if (exposeWithAlias && exposeWithAlias.startsWith('/')) {\n        const pkgNameOrAlias = remote.alias;\n        exposeWithAlias = `.${exposeWithAlias}`;\n        return {\n          pkgNameOrAlias,\n          expose: exposeWithAlias,\n          remote,\n        };\n      } else if (exposeWithAlias === '') {\n        return {\n          pkgNameOrAlias: remote.alias,\n          expose: '.',\n          remote,\n        };\n      }\n    }\n  }\n\n  return;\n}\n\n// Function to match a remote with its name or alias\nexport function matchRemote(\n  remotes: Array<Remote>,\n  nameOrAlias: string,\n): Remote | undefined {\n  for (const remote of remotes) {\n    const isNameMatched = nameOrAlias === remote.name;\n    if (isNameMatched) {\n      return remote;\n    }\n\n    const isAliasMatched = remote.alias && nameOrAlias === remote.alias;\n    if (isAliasMatched) {\n      return remote;\n    }\n  }\n  return;\n}\n"],"mappings":";;AAEA,SAAgB,uBACd,YACA,QACQ;AACR,KAAI,CAAC,UAAU,WAAW,IACxB,QAAO;AAGT,QAAO,GAAG,WAAW,GAAG,OAAO,QAAQ,SAAS,GAAG;;AAOrD,SAAgB,6BACd,SACA,IAOY;AACZ,MAAK,MAAM,UAAU,SAAS;EAE5B,MAAM,gBAAgB,GAAG,WAAW,OAAO,KAAK;EAChD,IAAI,SAAS,GAAG,QAAQ,OAAO,MAAM,GAAG;AACxC,MAAI,eACF;OAAI,OAAO,WAAW,IAAI,EAAE;IAC1B,MAAM,iBAAiB,OAAO;AAC9B,aAAS,IAAI;AACb,WAAO;KACL;KACA;KACA;KACD;cACQ,WAAW,GACpB,QAAO;IACL,gBAAgB,OAAO;IACvB,QAAQ;IACR;IACD;;EAKL,MAAM,iBAAiB,OAAO,SAAS,GAAG,WAAW,OAAO,MAAM;EAClE,IAAI,kBAAkB,OAAO,SAAS,GAAG,QAAQ,OAAO,OAAO,GAAG;AAClE,MAAI,OAAO,SAAS,gBAClB;OAAI,mBAAmB,gBAAgB,WAAW,IAAI,EAAE;IACtD,MAAM,iBAAiB,OAAO;AAC9B,sBAAkB,IAAI;AACtB,WAAO;KACL;KACA,QAAQ;KACR;KACD;cACQ,oBAAoB,GAC7B,QAAO;IACL,gBAAgB,OAAO;IACvB,QAAQ;IACR;IACD;;;;AAST,SAAgB,YACd,SACA,aACoB;AACpB,MAAK,MAAM,UAAU,SAAS;AAE5B,MADsB,gBAAgB,OAAO,KAE3C,QAAO;AAIT,MADuB,OAAO,SAAS,gBAAgB,OAAO,MAE5D,QAAO"}