@code-pushup/js-packages-plugin
Advanced tools
Comparing version 0.48.0 to 0.49.0
342
index.js
@@ -7,3 +7,3 @@ // packages/plugin-js-packages/src/lib/js-packages-plugin.ts | ||
var name = "@code-pushup/js-packages-plugin"; | ||
var version = "0.48.0"; | ||
var version = "0.49.0"; | ||
@@ -779,5 +779,12 @@ // packages/plugin-js-packages/src/lib/config.ts | ||
// packages/utils/src/lib/reports/utils.ts | ||
import ansis from "ansis"; | ||
import { md } from "build-md"; | ||
// packages/utils/src/lib/reports/constants.ts | ||
var TERMINAL_WIDTH = 80; | ||
// packages/utils/src/lib/file-system.ts | ||
import { bold, gray } from "ansis"; | ||
import { bundleRequire } from "bundle-require"; | ||
import chalk2 from "chalk"; | ||
import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises"; | ||
@@ -789,8 +796,3 @@ import { join } from "node:path"; | ||
import { cliui } from "@poppinss/cliui"; | ||
import chalk from "chalk"; | ||
// packages/utils/src/lib/reports/constants.ts | ||
var TERMINAL_WIDTH = 80; | ||
// packages/utils/src/lib/logging.ts | ||
import { underline } from "ansis"; | ||
var singletonUiInstance; | ||
@@ -838,34 +840,5 @@ function ui() { | ||
// packages/utils/src/lib/text-formats/constants.ts | ||
var NEW_LINE = "\n"; | ||
var TAB = " "; | ||
// packages/utils/src/lib/git/git.ts | ||
import { simpleGit } from "simple-git"; | ||
// packages/utils/src/lib/text-formats/html/details.ts | ||
function details(title, content, cfg = { open: false }) { | ||
return `<details${cfg.open ? " open" : ""}>${NEW_LINE}<summary>${title}</summary>${NEW_LINE}${// ⚠️ The blank line is needed to ensure Markdown in content is rendered correctly. | ||
NEW_LINE}${content}${NEW_LINE}${// @TODO in the future we could consider adding it only if the content ends with a code block | ||
// ⚠️ The blank line ensure Markdown in content is rendered correctly. | ||
NEW_LINE}</details>${// ⚠️ The blank line is needed to ensure Markdown after details is rendered correctly. | ||
NEW_LINE}`; | ||
} | ||
// packages/utils/src/lib/text-formats/html/font-style.ts | ||
var boldElement = "b"; | ||
function bold(text) { | ||
return `<${boldElement}>${text}</${boldElement}>`; | ||
} | ||
var italicElement = "i"; | ||
function italic(text) { | ||
return `<${italicElement}>${text}</${italicElement}>`; | ||
} | ||
var codeElement = "code"; | ||
function code(text) { | ||
return `<${codeElement}>${text}</${codeElement}>`; | ||
} | ||
// packages/utils/src/lib/text-formats/html/link.ts | ||
function link(href, text) { | ||
return `<a href="${href}">${text || href}</a>`; | ||
} | ||
// packages/utils/src/lib/transform.ts | ||
@@ -889,260 +862,3 @@ import { platform } from "node:os"; | ||
} | ||
function capitalize(text) { | ||
return `${text.charAt(0).toLocaleUpperCase()}${text.slice( | ||
1 | ||
)}`; | ||
} | ||
// packages/utils/src/lib/text-formats/table.ts | ||
function rowToStringArray({ rows, columns = [] }) { | ||
if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") { | ||
throw new TypeError( | ||
"Column can`t be object when rows are primitive values" | ||
); | ||
} | ||
return rows.map((row) => { | ||
if (Array.isArray(row)) { | ||
return row.map(String); | ||
} | ||
const objectRow = row; | ||
if (columns.length === 0 || typeof columns.at(0) === "string") { | ||
return Object.values(objectRow).map( | ||
(value) => value == null ? "" : String(value) | ||
); | ||
} | ||
return columns.map( | ||
({ key }) => objectRow[key] == null ? "" : String(objectRow[key]) | ||
); | ||
}); | ||
} | ||
function columnsToStringArray({ | ||
rows, | ||
columns = [] | ||
}) { | ||
const firstRow = rows.at(0); | ||
const primitiveRows = Array.isArray(firstRow); | ||
if (typeof columns.at(0) === "string" && !primitiveRows) { | ||
throw new Error("invalid union type. Caught by model parsing."); | ||
} | ||
if (columns.length === 0) { | ||
if (Array.isArray(firstRow)) { | ||
return firstRow.map((_, idx) => String(idx)); | ||
} | ||
return Object.keys(firstRow); | ||
} | ||
if (typeof columns.at(0) === "string") { | ||
return columns.map(String); | ||
} | ||
const cols = columns; | ||
return cols.map(({ label, key }) => label ?? capitalize(key)); | ||
} | ||
function getColumnAlignmentForKeyAndIndex(targetKey, targetIdx, columns = []) { | ||
const column = columns.at(targetIdx) ?? columns.find((col) => col.key === targetKey); | ||
if (typeof column === "string") { | ||
return column; | ||
} else if (typeof column === "object") { | ||
return column.align ?? "center"; | ||
} else { | ||
return "center"; | ||
} | ||
} | ||
function getColumnAlignmentForIndex(targetIdx, columns = []) { | ||
const column = columns.at(targetIdx); | ||
if (column == null) { | ||
return "center"; | ||
} else if (typeof column === "string") { | ||
return column; | ||
} else if (typeof column === "object") { | ||
return column.align ?? "center"; | ||
} else { | ||
return "center"; | ||
} | ||
} | ||
function getColumnAlignments(tableData) { | ||
const { rows, columns = [] } = tableData; | ||
if (rows.at(0) == null) { | ||
throw new Error("first row can`t be undefined."); | ||
} | ||
if (Array.isArray(rows.at(0))) { | ||
const firstPrimitiveRow = rows.at(0); | ||
return Array.from({ length: firstPrimitiveRow.length }).map( | ||
(_, idx) => getColumnAlignmentForIndex(idx, columns) | ||
); | ||
} | ||
const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1); | ||
if (columns.length > 0) { | ||
return columns.map( | ||
(column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex( | ||
column.key, | ||
idx, | ||
columns | ||
) | ||
); | ||
} | ||
return Object.keys(biggestRow ?? {}).map((_) => "center"); | ||
} | ||
// packages/utils/src/lib/text-formats/html/table.ts | ||
function wrap(elem, content) { | ||
return `<${elem}>${content}</${elem}>${NEW_LINE}`; | ||
} | ||
function wrapRow(content) { | ||
const elem = "tr"; | ||
return `<${elem}>${NEW_LINE}${content}</${elem}>${NEW_LINE}`; | ||
} | ||
function table(tableData) { | ||
if (tableData.rows.length === 0) { | ||
throw new Error("Data can't be empty"); | ||
} | ||
const tableHeaderCols = columnsToStringArray(tableData).map((s) => wrap("th", s)).join(""); | ||
const tableHeaderRow = wrapRow(tableHeaderCols); | ||
const tableBody = rowToStringArray(tableData).map((arr) => { | ||
const columns = arr.map((s) => wrap("td", s)).join(""); | ||
return wrapRow(columns); | ||
}).join(""); | ||
return wrap("table", `${NEW_LINE}${tableHeaderRow}${tableBody}`); | ||
} | ||
// packages/utils/src/lib/text-formats/md/font-style.ts | ||
var boldWrap = "**"; | ||
function bold2(text) { | ||
return `${boldWrap}${text}${boldWrap}`; | ||
} | ||
var italicWrap = "_"; | ||
function italic2(text) { | ||
return `${italicWrap}${text}${italicWrap}`; | ||
} | ||
var strikeThroughWrap = "~"; | ||
function strikeThrough(text) { | ||
return `${strikeThroughWrap}${text}${strikeThroughWrap}`; | ||
} | ||
var codeWrap = "`"; | ||
function code2(text) { | ||
return `${codeWrap}${text}${codeWrap}`; | ||
} | ||
// packages/utils/src/lib/text-formats/md/headline.ts | ||
function headline(text, hierarchy = 1) { | ||
return `${"#".repeat(hierarchy)} ${text}${NEW_LINE}`; | ||
} | ||
function h(text, hierarchy = 1) { | ||
return headline(text, hierarchy); | ||
} | ||
function h1(text) { | ||
return headline(text, 1); | ||
} | ||
function h2(text) { | ||
return headline(text, 2); | ||
} | ||
function h3(text) { | ||
return headline(text, 3); | ||
} | ||
function h4(text) { | ||
return headline(text, 4); | ||
} | ||
function h5(text) { | ||
return headline(text, 5); | ||
} | ||
function h6(text) { | ||
return headline(text, 6); | ||
} | ||
// packages/utils/src/lib/text-formats/md/image.ts | ||
function image(src, alt) { | ||
return ``; | ||
} | ||
// packages/utils/src/lib/text-formats/md/link.ts | ||
function link2(href, text) { | ||
return `[${text || href}](${href})`; | ||
} | ||
// packages/utils/src/lib/text-formats/md/list.ts | ||
function li(text, order = "unordered") { | ||
const style = order === "unordered" ? "-" : "- [ ]"; | ||
return `${style} ${text}`; | ||
} | ||
function indentation(text, level = 1) { | ||
return `${TAB.repeat(level)}${text}`; | ||
} | ||
// packages/utils/src/lib/text-formats/md/paragraphs.ts | ||
function paragraphs(...sections) { | ||
return sections.filter(Boolean).join(`${NEW_LINE}${NEW_LINE}`); | ||
} | ||
// packages/utils/src/lib/text-formats/md/section.ts | ||
function section(...contents) { | ||
return `${lines(...contents)}${NEW_LINE}`; | ||
} | ||
function lines(...contents) { | ||
const filteredContent = contents.filter( | ||
(value) => value != null && value !== "" && value !== false | ||
); | ||
return `${filteredContent.join(NEW_LINE)}`; | ||
} | ||
// packages/utils/src/lib/text-formats/md/table.ts | ||
var alignString = /* @__PURE__ */ new Map([ | ||
["left", ":--"], | ||
["center", ":--:"], | ||
["right", "--:"] | ||
]); | ||
function tableRow(rows) { | ||
return `|${rows.join("|")}|`; | ||
} | ||
function table2(data) { | ||
if (data.rows.length === 0) { | ||
throw new Error("Data can't be empty"); | ||
} | ||
const alignmentRow = getColumnAlignments(data).map( | ||
(s) => alignString.get(s) ?? String(alignString.get("center")) | ||
); | ||
return section( | ||
`${lines( | ||
tableRow(columnsToStringArray(data)), | ||
tableRow(alignmentRow), | ||
...rowToStringArray(data).map(tableRow) | ||
)}` | ||
); | ||
} | ||
// packages/utils/src/lib/text-formats/index.ts | ||
var md = { | ||
bold: bold2, | ||
italic: italic2, | ||
strikeThrough, | ||
code: code2, | ||
link: link2, | ||
image, | ||
headline, | ||
h, | ||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5, | ||
h6, | ||
indentation, | ||
lines, | ||
li, | ||
section, | ||
paragraphs, | ||
table: table2 | ||
}; | ||
var html = { | ||
bold, | ||
italic, | ||
code, | ||
link, | ||
details, | ||
table | ||
}; | ||
// packages/utils/src/lib/reports/utils.ts | ||
var { image: image2, bold: boldMd } = md; | ||
// packages/utils/src/lib/git/git.ts | ||
import { simpleGit } from "simple-git"; | ||
// packages/utils/src/lib/git/git.commits-and-tags.ts | ||
@@ -1155,30 +871,22 @@ import { simpleGit as simpleGit2 } from "simple-git"; | ||
// packages/utils/src/lib/progress.ts | ||
import chalk3 from "chalk"; | ||
import { black, bold as bold2, gray as gray2, green } from "ansis"; | ||
import { MultiProgressBars } from "multi-progress-bars"; | ||
// packages/utils/src/lib/reports/generate-md-report.ts | ||
import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md"; | ||
// packages/utils/src/lib/reports/formatting.ts | ||
var { headline: headline2, lines: lines2, link: link3, section: section2, table: table3 } = md; | ||
import { MarkdownDocument, md as md2 } from "build-md"; | ||
// packages/utils/src/lib/reports/generate-md-report-categoy-section.ts | ||
var { link: link4, section: section3, h2: h22, lines: lines3, li: li2, bold: boldMd2, h3: h32, indentation: indentation2 } = md; | ||
import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md"; | ||
// packages/utils/src/lib/reports/generate-md-report.ts | ||
var { h1: h12, h2: h23, h3: h33, lines: lines4, link: link5, section: section4, code: codeMd } = md; | ||
var { bold: boldHtml, details: details2 } = html; | ||
// packages/utils/src/lib/reports/generate-md-reports-diff.ts | ||
var { | ||
h1: h13, | ||
h2: h24, | ||
lines: lines5, | ||
link: link6, | ||
bold: boldMd3, | ||
italic: italicMd, | ||
table: table4, | ||
section: section5 | ||
} = md; | ||
var { details: details3 } = html; | ||
import { | ||
MarkdownDocument as MarkdownDocument4, | ||
md as md5 | ||
} from "build-md"; | ||
// packages/utils/src/lib/reports/log-stdout-summary.ts | ||
import chalk4 from "chalk"; | ||
import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis"; | ||
@@ -1669,2 +1377,5 @@ // packages/plugin-js-packages/src/lib/runner/utils.ts | ||
// packages/plugin-js-packages/src/lib/runner/audit/transform.ts | ||
import { md as md6 } from "build-md"; | ||
// packages/plugin-js-packages/src/lib/runner/constants.ts | ||
@@ -1681,2 +1392,3 @@ import { join as join2 } from "node:path"; | ||
// packages/plugin-js-packages/src/lib/runner/outdated/transform.ts | ||
import { md as md7 } from "build-md"; | ||
import { clean, diff, neq } from "semver"; | ||
@@ -1683,0 +1395,0 @@ |
{ | ||
"name": "@code-pushup/js-packages-plugin", | ||
"version": "0.48.0", | ||
"version": "0.49.0", | ||
"dependencies": { | ||
"@code-pushup/models": "0.48.0", | ||
"@code-pushup/utils": "0.48.0", | ||
"@code-pushup/models": "0.49.0", | ||
"@code-pushup/utils": "0.49.0", | ||
"build-md": "^0.4.1", | ||
"semver": "^7.6.0", | ||
@@ -8,0 +9,0 @@ "zod": "^3.22.4" |
Sorry, the diff of this file is too big to display
132670
5
3441
+ Addedbuild-md@^0.4.1
+ Added@code-pushup/models@0.49.0(transitive)
+ Added@code-pushup/utils@0.49.0(transitive)
+ Addedansis@3.16.0(transitive)
+ Addedbuild-md@0.4.2(transitive)
- Removed@code-pushup/models@0.48.0(transitive)
- Removed@code-pushup/utils@0.48.0(transitive)
Updated@code-pushup/models@0.49.0
Updated@code-pushup/utils@0.49.0