Skip to content

improve(import), display a more concise output when latest is currently used #9343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions scopes/scope/importer/import.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,22 @@ function formatPlainComponentItem({ scope, name, version, deprecated }: any) {
function formatPlainComponentItemWithVersions(bitId: ComponentID, importDetails: ImportDetails) {
const status: ImportStatus = importDetails.status;
const id = bitId.toStringWithoutVersion();
let usingLatest = '';
const getVersionsOutput = () => {
if (!importDetails.versions.length) return '';
if (importDetails.latestVersion) {
if (importDetails.latestVersion === bitId.version && status === 'added') {
usingLatest = ' (latest)';
return '';
}
return `${importDetails.versions.length} new version(s) available, latest ${importDetails.latestVersion}`;
}
return importDetails.versions.length > 5
? `${importDetails.versions.length} new versions`
: `new versions: ${importDetails.versions.join(', ')}`;
};
const versions = getVersionsOutput();
const usedVersion = status === 'added' ? `, currently used version ${bitId.version}` : '';
const usedVersion = status === 'added' ? `currently used version ${bitId.version}${usingLatest}` : '';
const getConflictMessage = () => {
if (!importDetails.filesStatus) return '';
const conflictedFiles = Object.keys(importDetails.filesStatus)
Expand All @@ -340,9 +345,11 @@ function formatPlainComponentItemWithVersions(bitId: ComponentID, importDetails:
if (status === 'up to date' && !missingDeps && !deprecated && !conflictMessage && !removed) {
return undefined;
}
return chalk.dim(
`- ${chalk.green(status)} ${chalk.cyan(
id
)} ${versions}${usedVersion} ${conflictMessage}${deprecated}${removed} ${missingDeps}`
);

const statusOutput = `- ${chalk.green(status)}`;
const idOutput = chalk.cyan(id);
const versionOutput = compact([versions, usedVersion]).join(', ');
const stateOutput = `${conflictMessage}${deprecated}${removed}`;
const output = compact([statusOutput, idOutput, versionOutput, stateOutput, missingDeps]).join(' ');
return chalk.dim(output);
}