@code-pushup/utils 0.52.0 → 0.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var MAX_ISSUE_MESSAGE_LENGTH = 1024;
|
|
|
12
12
|
var slugRegex = /^[a-z\d]+(?:-[a-z\d]+)*$/;
|
|
13
13
|
var filenameRegex = /^(?!.*[ \\/:*?"<>|]).+$/;
|
|
14
14
|
function hasDuplicateStrings(strings) {
|
|
15
|
-
const sortedStrings =
|
|
15
|
+
const sortedStrings = strings.toSorted();
|
|
16
16
|
const duplStrings = sortedStrings.filter(
|
|
17
17
|
(item, index) => index !== 0 && item === sortedStrings[index - 1]
|
|
18
18
|
);
|
|
@@ -1873,7 +1873,7 @@ function getColumnAlignments(tableData) {
|
|
|
1873
1873
|
(_, idx) => getColumnAlignmentForIndex(idx, columns)
|
|
1874
1874
|
);
|
|
1875
1875
|
}
|
|
1876
|
-
const biggestRow =
|
|
1876
|
+
const biggestRow = rows.toSorted((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
|
|
1877
1877
|
if (columns.length > 0) {
|
|
1878
1878
|
return columns.map(
|
|
1879
1879
|
(column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
|
|
@@ -1924,25 +1924,30 @@ import {
|
|
|
1924
1924
|
} from "build-md";
|
|
1925
1925
|
import { posix as pathPosix } from "node:path";
|
|
1926
1926
|
|
|
1927
|
-
// packages/utils/src/lib/reports/
|
|
1927
|
+
// packages/utils/src/lib/reports/types.ts
|
|
1928
|
+
var SUPPORTED_ENVIRONMENTS = [
|
|
1929
|
+
"vscode",
|
|
1930
|
+
"github",
|
|
1931
|
+
"gitlab",
|
|
1932
|
+
"other"
|
|
1933
|
+
];
|
|
1934
|
+
|
|
1935
|
+
// packages/utils/src/lib/reports/environment-type.ts
|
|
1936
|
+
var environmentChecks = {
|
|
1937
|
+
vscode: () => process.env["TERM_PROGRAM"] === "vscode",
|
|
1938
|
+
github: () => process.env["GITHUB_ACTIONS"] === "true",
|
|
1939
|
+
gitlab: () => process.env["GITLAB_CI"] === "true",
|
|
1940
|
+
other: () => true
|
|
1941
|
+
};
|
|
1928
1942
|
function getEnvironmentType() {
|
|
1929
|
-
|
|
1930
|
-
return "vscode";
|
|
1931
|
-
}
|
|
1932
|
-
if (isGitHub()) {
|
|
1933
|
-
return "github";
|
|
1934
|
-
}
|
|
1935
|
-
return "other";
|
|
1936
|
-
}
|
|
1937
|
-
function isVSCode() {
|
|
1938
|
-
return process.env["TERM_PROGRAM"] === "vscode";
|
|
1939
|
-
}
|
|
1940
|
-
function isGitHub() {
|
|
1941
|
-
return process.env["GITHUB_ACTIONS"] === "true";
|
|
1943
|
+
return SUPPORTED_ENVIRONMENTS.find((env) => environmentChecks[env]()) ?? "other";
|
|
1942
1944
|
}
|
|
1943
1945
|
function getGitHubBaseUrl() {
|
|
1944
1946
|
return `${process.env["GITHUB_SERVER_URL"]}/${process.env["GITHUB_REPOSITORY"]}/blob/${process.env["GITHUB_SHA"]}`;
|
|
1945
1947
|
}
|
|
1948
|
+
function getGitLabBaseUrl() {
|
|
1949
|
+
return `${process.env["CI_SERVER_URL"]}/${process.env["CI_PROJECT_PATH"]}/-/blob/${process.env["CI_COMMIT_SHA"]}`;
|
|
1950
|
+
}
|
|
1946
1951
|
|
|
1947
1952
|
// packages/utils/src/lib/reports/formatting.ts
|
|
1948
1953
|
function tableSection(tableData, options) {
|
|
@@ -2008,6 +2013,15 @@ function formatGitHubLink(file, position) {
|
|
|
2008
2013
|
const lineRange = end && start !== end ? `${start}-${end}` : start;
|
|
2009
2014
|
return `${baseUrl}/${file}#${lineRange}`;
|
|
2010
2015
|
}
|
|
2016
|
+
function formatGitLabLink(file, position) {
|
|
2017
|
+
const baseUrl = getGitLabBaseUrl();
|
|
2018
|
+
if (!position) {
|
|
2019
|
+
return `${baseUrl}/${file}`;
|
|
2020
|
+
}
|
|
2021
|
+
const { startLine, endLine } = position;
|
|
2022
|
+
const lineRange = endLine && startLine !== endLine ? `${startLine}-${endLine}` : startLine;
|
|
2023
|
+
return `${baseUrl}/${file}#L${lineRange}`;
|
|
2024
|
+
}
|
|
2011
2025
|
function formatFileLink(file, position, outputDir) {
|
|
2012
2026
|
const relativePath = pathPosix.relative(outputDir, file);
|
|
2013
2027
|
const env = getEnvironmentType();
|
|
@@ -2016,6 +2030,8 @@ function formatFileLink(file, position, outputDir) {
|
|
|
2016
2030
|
return position ? `${relativePath}#L${position.startLine}` : relativePath;
|
|
2017
2031
|
case "github":
|
|
2018
2032
|
return formatGitHubLink(file, position);
|
|
2033
|
+
case "gitlab":
|
|
2034
|
+
return formatGitLabLink(file, position);
|
|
2019
2035
|
default:
|
|
2020
2036
|
return relativePath;
|
|
2021
2037
|
}
|
|
@@ -2067,7 +2083,7 @@ function getSortableGroupByRef({ plugin, slug, weight }, plugins) {
|
|
|
2067
2083
|
throwIsNotPresentError(`Group ${slug}`, groupPlugin.slug);
|
|
2068
2084
|
}
|
|
2069
2085
|
const sortedAudits = getSortedGroupAudits(group, groupPlugin.slug, plugins);
|
|
2070
|
-
const sortedAuditRefs =
|
|
2086
|
+
const sortedAuditRefs = group.refs.toSorted((a, b) => {
|
|
2071
2087
|
const aIndex = sortedAudits.findIndex((ref) => ref.slug === a.slug);
|
|
2072
2088
|
const bIndex = sortedAudits.findIndex((ref) => ref.slug === b.slug);
|
|
2073
2089
|
return aIndex - bIndex;
|
|
@@ -2096,7 +2112,7 @@ function sortReport(report) {
|
|
|
2096
2112
|
const sortedAuditsAndGroups = [...audits, ...groups].sort(
|
|
2097
2113
|
compareCategoryAuditsAndGroups
|
|
2098
2114
|
);
|
|
2099
|
-
const sortedRefs =
|
|
2115
|
+
const sortedRefs = category.refs.toSorted((a, b) => {
|
|
2100
2116
|
const aIndex = sortedAuditsAndGroups.findIndex(
|
|
2101
2117
|
(ref) => ref.slug === a.slug && ref.plugin === a.plugin
|
|
2102
2118
|
);
|
|
@@ -2116,12 +2132,12 @@ function sortReport(report) {
|
|
|
2116
2132
|
function sortPlugins(plugins) {
|
|
2117
2133
|
return plugins.map((plugin) => ({
|
|
2118
2134
|
...plugin,
|
|
2119
|
-
audits:
|
|
2135
|
+
audits: plugin.audits.toSorted(compareAudits).map(
|
|
2120
2136
|
(audit) => audit.details?.issues ? {
|
|
2121
2137
|
...audit,
|
|
2122
2138
|
details: {
|
|
2123
2139
|
...audit.details,
|
|
2124
|
-
issues:
|
|
2140
|
+
issues: audit.details.issues.toSorted(compareIssues)
|
|
2125
2141
|
}
|
|
2126
2142
|
} : audit
|
|
2127
2143
|
)
|
|
@@ -2398,7 +2414,7 @@ function formatPortalLink(portalUrl) {
|
|
|
2398
2414
|
return portalUrl && md5.link(portalUrl, "\u{1F575}\uFE0F See full comparison in Code PushUp portal \u{1F50D}");
|
|
2399
2415
|
}
|
|
2400
2416
|
function sortChanges(changes) {
|
|
2401
|
-
return
|
|
2417
|
+
return changes.toSorted(
|
|
2402
2418
|
(a, b) => Math.abs(b.scores.diff) - Math.abs(a.scores.diff) || Math.abs(b.values?.diff ?? 0) - Math.abs(a.values?.diff ?? 0)
|
|
2403
2419
|
);
|
|
2404
2420
|
}
|
package/package.json
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.1",
|
|
4
4
|
"description": "Low-level utilities (helper functions, etc.) used by Code PushUp CLI",
|
|
5
|
-
"dependencies": {
|
|
6
|
-
"@code-pushup/models": "0.52.0",
|
|
7
|
-
"@isaacs/cliui": "^8.0.2",
|
|
8
|
-
"@poppinss/cliui": "^6.4.0",
|
|
9
|
-
"ansis": "^3.3.0",
|
|
10
|
-
"build-md": "^0.4.2",
|
|
11
|
-
"bundle-require": "^4.0.1",
|
|
12
|
-
"esbuild": "^0.19.2",
|
|
13
|
-
"multi-progress-bars": "^5.0.3",
|
|
14
|
-
"semver": "^7.6.0",
|
|
15
|
-
"simple-git": "^3.20.0"
|
|
16
|
-
},
|
|
17
5
|
"license": "MIT",
|
|
18
6
|
"homepage": "https://github.com/code-pushup/cli/tree/main/packages/utils#readme",
|
|
19
7
|
"bugs": {
|
|
20
|
-
"url": "https://github.com/code-pushup/cli/issues"
|
|
8
|
+
"url": "https://github.com/code-pushup/cli/issues?q=is%3Aissue%20state%3Aopen%20type%3ABug%20label%3A\"🧩%20utils\""
|
|
21
9
|
},
|
|
22
10
|
"repository": {
|
|
23
11
|
"type": "git",
|
|
24
12
|
"url": "git+https://github.com/code-pushup/cli.git",
|
|
25
13
|
"directory": "packages/utils"
|
|
26
14
|
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"CLI",
|
|
17
|
+
"Code PushUp",
|
|
18
|
+
"developer tools",
|
|
19
|
+
"helpers",
|
|
20
|
+
"utils"
|
|
21
|
+
],
|
|
27
22
|
"publishConfig": {
|
|
28
23
|
"access": "public"
|
|
29
24
|
},
|
|
30
25
|
"type": "module",
|
|
31
26
|
"main": "./index.js",
|
|
32
|
-
"types": "./src/index.d.ts"
|
|
33
|
-
|
|
27
|
+
"types": "./src/index.d.ts",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@code-pushup/models": "0.53.1",
|
|
30
|
+
"@isaacs/cliui": "^8.0.2",
|
|
31
|
+
"@poppinss/cliui": "^6.4.0",
|
|
32
|
+
"ansis": "^3.3.0",
|
|
33
|
+
"build-md": "^0.4.2",
|
|
34
|
+
"bundle-require": "^4.0.1",
|
|
35
|
+
"esbuild": "^0.19.2",
|
|
36
|
+
"multi-progress-bars": "^5.0.3",
|
|
37
|
+
"semver": "^7.6.0",
|
|
38
|
+
"simple-git": "^3.20.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -16,4 +16,5 @@ export declare function metaDescription(audit: Pick<AuditReport, 'docsUrl' | 'de
|
|
|
16
16
|
export declare function linkToLocalSourceForIde(source: SourceFileLocation, options?: Pick<MdReportOptions, 'outputDir'>): InlineText;
|
|
17
17
|
export declare function formatSourceLine(position: SourceFileLocation['position']): string;
|
|
18
18
|
export declare function formatGitHubLink(file: string, position: SourceFileLocation['position']): string;
|
|
19
|
+
export declare function formatGitLabLink(file: string, position: SourceFileLocation['position']): string;
|
|
19
20
|
export declare function formatFileLink(file: string, position: SourceFileLocation['position'], outputDir: string): string;
|
|
@@ -21,4 +21,5 @@ export type SortableAuditReport = AuditReport & {
|
|
|
21
21
|
};
|
|
22
22
|
export type DiffOutcome = 'positive' | 'negative' | 'mixed' | 'unchanged';
|
|
23
23
|
export type MdReportOptions = Pick<PersistConfig, 'outputDir'>;
|
|
24
|
-
export
|
|
24
|
+
export declare const SUPPORTED_ENVIRONMENTS: readonly ["vscode", "github", "gitlab", "other"];
|
|
25
|
+
export type EnvironmentType = (typeof SUPPORTED_ENVIRONMENTS)[number];
|