Skip to content
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

fix: licenses output table misplaced #8071

Merged
merged 6 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 38 additions & 6 deletions reviewing/plugin-commands-licenses/src/outputRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,45 @@ function renderLicensesTable (
for (let i = 0; i < columnNames.length; i++)
columnNames[i] = chalk.blueBright(columnNames[i])

const data = [
columnNames,
...deduplicateLicensesPackages(sortLicensesPackages(licensePackages))
.map((licensePkg) => columnFns.map((fn) => fn(licensePkg))),
]
let detailsColumnMaxWidth = 40
let packageColumnMaxWidth = 0
let licenseColumnMaxWidth = 0
if (opts.long) {
// Use the package link to determine the width of the details column
detailsColumnMaxWidth = licensePackages.reduce((max, pkg) => Math.max(max, pkg.homepage?.length ?? 0), 0)
for (let i = 1; i < data.length; i++) {
const row = data[i]
const texts = row[2].split('\n')
const repeatCount = Math.max(0, texts.length - 1)
btea marked this conversation as resolved.
Show resolved Hide resolved
row[0] += '\n '.repeat(repeatCount) // Add extra spaces to the package column
row[1] += '\n '.repeat(repeatCount) // Add extra spaces to the license column
btea marked this conversation as resolved.
Show resolved Hide resolved
packageColumnMaxWidth = Math.max(packageColumnMaxWidth, row[0].length)
licenseColumnMaxWidth = Math.max(licenseColumnMaxWidth, row[1].length)
}
const remainColumnWidth = process.stdout.columns - packageColumnMaxWidth - licenseColumnMaxWidth - 20
btea marked this conversation as resolved.
Show resolved Hide resolved
if (detailsColumnMaxWidth > remainColumnWidth) {
detailsColumnMaxWidth = remainColumnWidth
}
detailsColumnMaxWidth = Math.max(detailsColumnMaxWidth, 40)
btea marked this conversation as resolved.
Show resolved Hide resolved
}

return table(
[
columnNames,
...deduplicateLicensesPackages(sortLicensesPackages(licensePackages))
.map((licensePkg) => columnFns.map((fn) => fn(licensePkg))),
],
TABLE_OPTIONS
data,
{
...TABLE_OPTIONS,
columns: {
...TABLE_OPTIONS.columns,
2: {
width: detailsColumnMaxWidth,
wrapWord: true,
},
},
}
)
}

Expand Down