@code-pushup/utils 0.51.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
@@ -1275,6 +1275,9 @@ function findLineNumberInText(content, pattern) {
1275
1275
  function filePathToCliArg(path) {
1276
1276
  return `"${path}"`;
1277
1277
  }
1278
+ function projectToFilename(project) {
1279
+ return project.replace(/[/\\\s]+/g, "-").replace(/@/g, "");
1280
+ }
1278
1281
 
1279
1282
  // packages/utils/src/lib/filter.ts
1280
1283
  function filterItemRefsBy(items, refFilterFn) {
@@ -1921,25 +1924,30 @@ import {
1921
1924
  } from "build-md";
1922
1925
  import { posix as pathPosix } from "node:path";
1923
1926
 
1924
- // packages/utils/src/lib/reports/ide-environment.ts
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
+ };
1925
1942
  function getEnvironmentType() {
1926
- if (isVSCode()) {
1927
- return "vscode";
1928
- }
1929
- if (isGitHub()) {
1930
- return "github";
1931
- }
1932
- return "other";
1933
- }
1934
- function isVSCode() {
1935
- return process.env["TERM_PROGRAM"] === "vscode";
1936
- }
1937
- function isGitHub() {
1938
- return process.env["GITHUB_ACTIONS"] === "true";
1943
+ return SUPPORTED_ENVIRONMENTS.find((env) => environmentChecks[env]()) ?? "other";
1939
1944
  }
1940
1945
  function getGitHubBaseUrl() {
1941
1946
  return `${process.env["GITHUB_SERVER_URL"]}/${process.env["GITHUB_REPOSITORY"]}/blob/${process.env["GITHUB_SHA"]}`;
1942
1947
  }
1948
+ function getGitLabBaseUrl() {
1949
+ return `${process.env["CI_SERVER_URL"]}/${process.env["CI_PROJECT_PATH"]}/-/blob/${process.env["CI_COMMIT_SHA"]}`;
1950
+ }
1943
1951
 
1944
1952
  // packages/utils/src/lib/reports/formatting.ts
1945
1953
  function tableSection(tableData, options) {
@@ -2005,6 +2013,15 @@ function formatGitHubLink(file, position) {
2005
2013
  const lineRange = end && start !== end ? `${start}-${end}` : start;
2006
2014
  return `${baseUrl}/${file}#${lineRange}`;
2007
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
+ }
2008
2025
  function formatFileLink(file, position, outputDir) {
2009
2026
  const relativePath = pathPosix.relative(outputDir, file);
2010
2027
  const env = getEnvironmentType();
@@ -2013,6 +2030,8 @@ function formatFileLink(file, position, outputDir) {
2013
2030
  return position ? `${relativePath}#L${position.startLine}` : relativePath;
2014
2031
  case "github":
2015
2032
  return formatGitHubLink(file, position);
2033
+ case "gitlab":
2034
+ return formatGitLabLink(file, position);
2016
2035
  default:
2017
2036
  return relativePath;
2018
2037
  }
@@ -2658,11 +2677,11 @@ import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
2658
2677
  function log(msg = "") {
2659
2678
  ui().logger.log(msg);
2660
2679
  }
2661
- function logStdoutSummary(report) {
2680
+ function logStdoutSummary(report, verbose = false) {
2662
2681
  const printCategories = report.categories.length > 0;
2663
2682
  log(reportToHeaderSection(report));
2664
2683
  log();
2665
- logPlugins(report);
2684
+ logPlugins(report.plugins, verbose);
2666
2685
  if (printCategories) {
2667
2686
  logCategories(report);
2668
2687
  }
@@ -2673,36 +2692,49 @@ function reportToHeaderSection(report) {
2673
2692
  const { packageName, version } = report;
2674
2693
  return `${bold4(REPORT_HEADLINE_TEXT)} - ${packageName}@${version}`;
2675
2694
  }
2676
- function logPlugins(report) {
2677
- const { plugins } = report;
2695
+ function logPlugins(plugins, verbose) {
2678
2696
  plugins.forEach((plugin) => {
2679
2697
  const { title, audits } = plugin;
2698
+ const filteredAudits = verbose ? audits : audits.filter(({ score }) => score !== 1);
2699
+ const diff = audits.length - filteredAudits.length;
2700
+ logAudits(title, filteredAudits);
2701
+ if (diff > 0) {
2702
+ const notice = filteredAudits.length === 0 ? `... All ${diff} audits have perfect scores ...` : `... ${diff} audits with perfect scores omitted for brevity ...`;
2703
+ logRow(1, notice);
2704
+ }
2680
2705
  log();
2681
- log(bold4.magentaBright(`${title} audits`));
2682
- log();
2683
- audits.forEach((audit) => {
2684
- ui().row([
2685
- {
2686
- text: applyScoreColor({ score: audit.score, text: "\u25CF" }),
2687
- width: 2,
2688
- padding: [0, 1, 0, 0]
2689
- },
2690
- {
2691
- text: audit.title,
2692
- // eslint-disable-next-line no-magic-numbers
2693
- padding: [0, 3, 0, 0]
2694
- },
2695
- {
2696
- text: cyanBright(audit.displayValue || `${audit.value}`),
2697
- // eslint-disable-next-line no-magic-numbers
2698
- width: 20,
2699
- padding: [0, 0, 0, 0]
2700
- }
2701
- ]);
2702
- });
2703
- log();
2704
2706
  });
2705
2707
  }
2708
+ function logAudits(pluginTitle, audits) {
2709
+ log();
2710
+ log(bold4.magentaBright(`${pluginTitle} audits`));
2711
+ log();
2712
+ audits.forEach(({ score, title, displayValue, value }) => {
2713
+ logRow(score, title, displayValue || `${value}`);
2714
+ });
2715
+ }
2716
+ function logRow(score, title, value) {
2717
+ ui().row([
2718
+ {
2719
+ text: applyScoreColor({ score, text: "\u25CF" }),
2720
+ width: 2,
2721
+ padding: [0, 1, 0, 0]
2722
+ },
2723
+ {
2724
+ text: title,
2725
+ // eslint-disable-next-line no-magic-numbers
2726
+ padding: [0, 3, 0, 0]
2727
+ },
2728
+ ...value ? [
2729
+ {
2730
+ text: cyanBright(value),
2731
+ // eslint-disable-next-line no-magic-numbers
2732
+ width: 20,
2733
+ padding: [0, 0, 0, 0]
2734
+ }
2735
+ ] : []
2736
+ ]);
2737
+ }
2706
2738
  function logCategories({ categories, plugins }) {
2707
2739
  const hAlign = (idx) => idx === 0 ? "left" : "right";
2708
2740
  const rows = categories.map(({ title, score, refs, isBinary }) => [
@@ -2911,6 +2943,7 @@ export {
2911
2943
  pluginWorkDir,
2912
2944
  pluralize,
2913
2945
  pluralizeToken,
2946
+ projectToFilename,
2914
2947
  readJsonFile,
2915
2948
  readTextFile,
2916
2949
  removeDirectoryIfExists,
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.51.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.51.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",
@@ -24,6 +24,9 @@
24
24
  "url": "git+https://github.com/code-pushup/cli.git",
25
25
  "directory": "packages/utils"
26
26
  },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
27
30
  "type": "module",
28
31
  "main": "./index.js",
29
32
  "types": "./src/index.d.ts"
package/src/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { exists } from '@code-pushup/models';
2
2
  export { comparePairs, matchArrayItemsByKey, type Diff } from './lib/diff';
3
3
  export { stringifyError } from './lib/errors';
4
4
  export { ProcessError, executeProcess, type ProcessConfig, type ProcessObserver, type ProcessResult, } from './lib/execute-process';
5
- export { crawlFileSystem, directoryExists, ensureDirectoryExists, fileExists, filePathToCliArg, findLineNumberInText, importModule, logMultipleFileResults, pluginWorkDir, readJsonFile, readTextFile, removeDirectoryIfExists, type CrawlFileSystemOptions, type FileResult, type MultipleFileResults, } from './lib/file-system';
5
+ export { crawlFileSystem, directoryExists, ensureDirectoryExists, fileExists, filePathToCliArg, findLineNumberInText, importModule, logMultipleFileResults, pluginWorkDir, projectToFilename, readJsonFile, readTextFile, removeDirectoryIfExists, type CrawlFileSystemOptions, type FileResult, type MultipleFileResults, } from './lib/file-system';
6
6
  export { filterItemRefsBy } from './lib/filter';
7
7
  export { formatBytes, formatDuration, pluralize, pluralizeToken, slugify, truncateDescription, truncateIssueMessage, truncateText, truncateTitle, } from './lib/formatting';
8
8
  export { formatGitPath, getGitRoot, guardAgainstLocalChanges, safeCheckout, toGitPath, } from './lib/git/git';
@@ -18,3 +18,4 @@ export type CrawlFileSystemOptions<T> = {
18
18
  export declare function crawlFileSystem<T = string>(options: CrawlFileSystemOptions<T>): Promise<T[]>;
19
19
  export declare function findLineNumberInText(content: string, pattern: string): number | null;
20
20
  export declare function filePathToCliArg(path: string): string;
21
+ export declare function projectToFilename(project: string): string;
@@ -0,0 +1,4 @@
1
+ import { type EnvironmentType } from './types';
2
+ export declare function getEnvironmentType(): EnvironmentType;
3
+ export declare function getGitHubBaseUrl(): string;
4
+ export declare function getGitLabBaseUrl(): string;
@@ -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;
@@ -1,4 +1,5 @@
1
1
  import type { ScoredReport } from './types';
2
- export declare function logStdoutSummary(report: ScoredReport): void;
2
+ export declare function logStdoutSummary(report: ScoredReport, verbose?: boolean): void;
3
+ export declare function logPlugins(plugins: ScoredReport['plugins'], verbose: boolean): void;
3
4
  export declare function logCategories({ categories, plugins }: ScoredReport): void;
4
5
  export declare function binaryIconPrefix(score: number, isBinary: boolean | undefined): 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 type IdeEnvironment = 'vscode' | 'github' | 'other';
24
+ export declare const SUPPORTED_ENVIRONMENTS: readonly ["vscode", "github", "gitlab", "other"];
25
+ export type EnvironmentType = (typeof SUPPORTED_ENVIRONMENTS)[number];
@@ -1,3 +0,0 @@
1
- import type { IdeEnvironment } from './types';
2
- export declare function getEnvironmentType(): IdeEnvironment;
3
- export declare function getGitHubBaseUrl(): string;