@salesforce/plugin-packaging
Version:
SF plugin that support Salesforce Packaging Platform
77 lines • 3.39 kB
JavaScript
/*
* Copyright 2026, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core/messages';
import { Package } from '@salesforce/packaging';
import { requiredHubFlag } from '../../../utils/hubFlag.js';
import { maybeGetProject } from '../../../utils/getProject.js';
// Import i18n messages
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_displayancestry');
export class PackageVersionDisplayAncestryCommand extends SfCommand {
static summary = messages.getMessage('summary');
static examples = messages.getMessages('examples');
static deprecateAliases = true;
static aliases = ['force:package:version:displayancestry'];
static flags = {
loglevel,
'target-dev-hub': requiredHubFlag,
'api-version': orgApiVersionFlagWithDeprecations,
package: Flags.string({
char: 'p',
summary: messages.getMessage('flags.package.summary'),
description: messages.getMessage('flags.package.description'),
required: true,
}),
'dot-code': Flags.boolean({
aliases: ['dotcode'],
deprecateAliases: true,
summary: messages.getMessage('flags.dot-code.summary'),
description: messages.getMessage('flags.dot-code.description'),
}),
verbose: Flags.boolean({
summary: messages.getMessage('flags.verbose.summary'),
}),
};
async run() {
const { flags } = await this.parse(PackageVersionDisplayAncestryCommand);
const packageAncestry = await Package.getAncestry(flags.package, await maybeGetProject(), flags['target-dev-hub'].getConnection(flags['api-version']));
const jsonProducer = packageAncestry.getJsonProducer();
if (flags['dot-code']) {
const dotProducer = packageAncestry.getDotProducer();
const dotCodeResult = dotProducer.produce();
if (flags.json) {
return dotCodeResult;
}
else {
this.log(dotCodeResult);
}
}
else {
if (packageAncestry.requestedPackageId?.startsWith('04t')) {
const paths = packageAncestry.getLeafPathToRoot(packageAncestry.requestedPackageId);
this.log(`${paths[0].map((p) => p.getVersion()).join(' -> ')} (root)`);
this.log();
}
const treeProducer = packageAncestry.getTreeProducer(flags.verbose);
if (!flags.json) {
treeProducer.produce();
}
}
return jsonProducer.produce();
}
}
//# sourceMappingURL=displayancestry.js.map