| 498 | } |
| 499 | |
| 500 | function resolveInstallPlan(options = {}) { |
| 501 | const manifests = loadInstallManifests(options); |
| 502 | const requestedProfileId = options.profileId || null; |
| 503 | const explicitModuleIds = dedupeStrings(options.moduleIds); |
| 504 | const includedComponentIds = dedupeStrings(options.includeComponentIds); |
| 505 | const excludedComponentIds = dedupeStrings(options.excludeComponentIds); |
| 506 | const requestedModuleIds = []; |
| 507 | const target = options.target || null; |
| 508 | |
| 509 | if (target && !SUPPORTED_INSTALL_TARGETS.includes(target)) { |
| 510 | throw new Error( |
| 511 | `Unknown install target: ${target}. Expected one of ${SUPPORTED_INSTALL_TARGETS.join(', ')}` |
| 512 | ); |
| 513 | } |
| 514 | |
| 515 | const shouldUseTargetDefaultProfile = !requestedProfileId |
| 516 | && explicitModuleIds.length === 0 |
| 517 | && includedComponentIds.length === 0; |
| 518 | const targetDefaultProfileId = shouldUseTargetDefaultProfile |
| 519 | ? getTargetDefaultProfileId(target, manifests) |
| 520 | : null; |
| 521 | const profileId = requestedProfileId || targetDefaultProfileId; |
| 522 | const targetDefaultExclusions = targetDefaultProfileId |
| 523 | ? getTargetDefaultExclusions(target, manifests) |
| 524 | : []; |
| 525 | |
| 526 | if (profileId) { |
| 527 | const profile = manifests.profiles[profileId]; |
| 528 | if (!profile) { |
| 529 | throw new Error(`Unknown install profile: ${profileId}`); |
| 530 | } |
| 531 | requestedModuleIds.push(...profile.modules); |
| 532 | } |
| 533 | |
| 534 | requestedModuleIds.push(...explicitModuleIds); |
| 535 | requestedModuleIds.push(...expandComponentIdsToModuleIds(includedComponentIds, manifests)); |
| 536 | |
| 537 | const excludedModuleIds = expandComponentIdsToModuleIds(excludedComponentIds, manifests); |
| 538 | const excludedModuleOwners = new Map(); |
| 539 | for (const componentId of excludedComponentIds) { |
| 540 | const component = manifests.componentsById.get(componentId); |
| 541 | if (!component) { |
| 542 | throw new Error(`Unknown install component: ${componentId}`); |
| 543 | } |
| 544 | for (const moduleId of component.modules) { |
| 545 | const owners = excludedModuleOwners.get(moduleId) || []; |
| 546 | owners.push(componentId); |
| 547 | excludedModuleOwners.set(moduleId, owners); |
| 548 | } |
| 549 | } |
| 550 | for (const exclusion of targetDefaultExclusions) { |
| 551 | const owners = excludedModuleOwners.get(exclusion.moduleId) || []; |
| 552 | owners.push(`${target} default`); |
| 553 | excludedModuleOwners.set(exclusion.moduleId, owners); |
| 554 | } |
| 555 | |
| 556 | const validatedProjectRoot = readOptionalStringOption(options, 'projectRoot'); |
| 557 | const validatedHomeDir = readOptionalStringOption(options, 'homeDir'); |