@code-pushup/utils 0.52.0 → 0.53.0
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
|
@@ -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
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "Low-level utilities (helper functions, etc.) used by Code PushUp CLI",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@code-pushup/models": "0.
|
|
6
|
+
"@code-pushup/models": "0.53.0",
|
|
7
7
|
"@isaacs/cliui": "^8.0.2",
|
|
8
8
|
"@poppinss/cliui": "^6.4.0",
|
|
9
9
|
"ansis": "^3.3.0",
|
|
@@ -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];
|