@code-pushup/utils 0.8.0 → 0.8.2

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
@@ -4,7 +4,7 @@ import { spawn } from "child_process";
4
4
  // packages/utils/src/lib/report.ts
5
5
  import { join as join2 } from "path";
6
6
 
7
- // packages/models/src/lib/category-config.ts
7
+ // packages/models/src/lib/audit.ts
8
8
  import { z as z2 } from "zod";
9
9
 
10
10
  // packages/models/src/lib/implementation/schemas.ts
@@ -144,13 +144,107 @@ function hasWeightedRefsInCategories(categoryRefs) {
144
144
  return categoryRefs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
145
145
  }
146
146
 
147
+ // packages/models/src/lib/audit.ts
148
+ var auditSchema = z2.object({
149
+ slug: slugSchema("ID (unique within plugin)")
150
+ }).merge(
151
+ metaSchema({
152
+ titleDescription: "Descriptive name",
153
+ descriptionDescription: "Description (markdown)",
154
+ docsUrlDescription: "Link to documentation (rationale)",
155
+ description: "List of scorable metrics for the given plugin"
156
+ })
157
+ );
158
+ var pluginAuditsSchema = z2.array(auditSchema, {
159
+ description: "List of audits maintained in a plugin"
160
+ }).refine(
161
+ (auditMetadata) => !getDuplicateSlugsInAudits(auditMetadata),
162
+ (auditMetadata) => ({
163
+ message: duplicateSlugsInAuditsErrorMsg(auditMetadata)
164
+ })
165
+ );
166
+ function duplicateSlugsInAuditsErrorMsg(audits) {
167
+ const duplicateRefs = getDuplicateSlugsInAudits(audits);
168
+ return `In plugin audits the slugs are not unique: ${errorItems(
169
+ duplicateRefs
170
+ )}`;
171
+ }
172
+ function getDuplicateSlugsInAudits(audits) {
173
+ return hasDuplicateStrings(audits.map(({ slug }) => slug));
174
+ }
175
+
176
+ // packages/models/src/lib/audit-issue.ts
177
+ import { z as z3 } from "zod";
178
+ var sourceFileLocationSchema = z3.object(
179
+ {
180
+ file: filePathSchema("Relative path to source file in Git repo"),
181
+ position: z3.object(
182
+ {
183
+ startLine: positiveIntSchema("Start line"),
184
+ startColumn: positiveIntSchema("Start column").optional(),
185
+ endLine: positiveIntSchema("End line").optional(),
186
+ endColumn: positiveIntSchema("End column").optional()
187
+ },
188
+ { description: "Location in file" }
189
+ ).optional()
190
+ },
191
+ { description: "Source file location" }
192
+ );
193
+ var issueSeveritySchema = z3.enum(["info", "warning", "error"], {
194
+ description: "Severity level"
195
+ });
196
+ var issueSchema = z3.object(
197
+ {
198
+ message: z3.string({ description: "Descriptive error message" }).max(512),
199
+ severity: issueSeveritySchema,
200
+ source: sourceFileLocationSchema.optional()
201
+ },
202
+ { description: "Issue information" }
203
+ );
204
+
205
+ // packages/models/src/lib/audit-output.ts
206
+ import { z as z4 } from "zod";
207
+ var auditOutputSchema = z4.object(
208
+ {
209
+ slug: slugSchema("Reference to audit"),
210
+ displayValue: z4.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional(),
211
+ value: positiveIntSchema("Raw numeric value"),
212
+ score: z4.number({
213
+ description: "Value between 0 and 1"
214
+ }).min(0).max(1),
215
+ details: z4.object(
216
+ {
217
+ issues: z4.array(issueSchema, { description: "List of findings" })
218
+ },
219
+ { description: "Detailed information" }
220
+ ).optional()
221
+ },
222
+ { description: "Audit information" }
223
+ );
224
+ var auditOutputsSchema = z4.array(auditOutputSchema, {
225
+ description: "List of JSON formatted audit output emitted by the runner process of a plugin"
226
+ }).refine(
227
+ (audits) => !getDuplicateSlugsInAudits2(audits),
228
+ (audits) => ({ message: duplicateSlugsInAuditsErrorMsg2(audits) })
229
+ );
230
+ function duplicateSlugsInAuditsErrorMsg2(audits) {
231
+ const duplicateRefs = getDuplicateSlugsInAudits2(audits);
232
+ return `In plugin audits the slugs are not unique: ${errorItems(
233
+ duplicateRefs
234
+ )}`;
235
+ }
236
+ function getDuplicateSlugsInAudits2(audits) {
237
+ return hasDuplicateStrings(audits.map(({ slug }) => slug));
238
+ }
239
+
147
240
  // packages/models/src/lib/category-config.ts
241
+ import { z as z5 } from "zod";
148
242
  var categoryRefSchema = weightedRefSchema(
149
243
  "Weighted references to audits and/or groups for the category",
150
244
  "Slug of an audit or group (depending on `type`)"
151
245
  ).merge(
152
- z2.object({
153
- type: z2.enum(["audit", "group"], {
246
+ z5.object({
247
+ type: z5.enum(["audit", "group"], {
154
248
  description: "Discriminant for reference kind, affects where `slug` is looked up"
155
249
  }),
156
250
  plugin: slugSchema(
@@ -171,8 +265,8 @@ var categoryConfigSchema = scorableSchema(
171
265
  description: "Meta info for category"
172
266
  })
173
267
  ).merge(
174
- z2.object({
175
- isBinary: z2.boolean({
268
+ z5.object({
269
+ isBinary: z5.boolean({
176
270
  description: 'Is this a binary category (i.e. only a perfect score considered a "pass")?'
177
271
  }).optional()
178
272
  })
@@ -188,7 +282,7 @@ function getDuplicateRefsInCategoryMetrics(metrics) {
188
282
  metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
189
283
  );
190
284
  }
191
- var categoriesSchema = z2.array(categoryConfigSchema, {
285
+ var categoriesSchema = z5.array(categoryConfigSchema, {
192
286
  description: "Categorization of individual audits"
193
287
  }).min(1).refine(
194
288
  (categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
@@ -210,68 +304,38 @@ function getDuplicateSlugCategories(categories) {
210
304
  import { z as z11 } from "zod";
211
305
 
212
306
  // packages/models/src/lib/persist-config.ts
213
- import { z as z3 } from "zod";
214
- var formatSchema = z3.enum(["json", "md"]);
215
- var persistConfigSchema = z3.object({
307
+ import { z as z6 } from "zod";
308
+ var formatSchema = z6.enum(["json", "md"]);
309
+ var persistConfigSchema = z6.object({
216
310
  outputDir: filePathSchema("Artifacts folder").optional(),
217
311
  filename: fileNameSchema(
218
312
  "Artifacts file name (without extension)"
219
313
  ).optional(),
220
- format: z3.array(formatSchema).optional()
314
+ format: z6.array(formatSchema).optional()
221
315
  });
222
316
 
223
317
  // packages/models/src/lib/plugin-config.ts
224
318
  import { z as z9 } from "zod";
225
319
 
226
- // packages/models/src/lib/plugin-config-audits.ts
227
- import { z as z4 } from "zod";
228
- var auditSchema = z4.object({
229
- slug: slugSchema("ID (unique within plugin)")
230
- }).merge(
231
- metaSchema({
232
- titleDescription: "Descriptive name",
233
- descriptionDescription: "Description (markdown)",
234
- docsUrlDescription: "Link to documentation (rationale)",
235
- description: "List of scorable metrics for the given plugin"
236
- })
237
- );
238
- var pluginAuditsSchema = z4.array(auditSchema, {
239
- description: "List of audits maintained in a plugin"
240
- }).refine(
241
- (auditMetadata) => !getDuplicateSlugsInAudits(auditMetadata),
242
- (auditMetadata) => ({
243
- message: duplicateSlugsInAuditsErrorMsg(auditMetadata)
244
- })
245
- );
246
- function duplicateSlugsInAuditsErrorMsg(audits) {
247
- const duplicateRefs = getDuplicateSlugsInAudits(audits);
248
- return `In plugin audits the slugs are not unique: ${errorItems(
249
- duplicateRefs
250
- )}`;
251
- }
252
- function getDuplicateSlugsInAudits(audits) {
253
- return hasDuplicateStrings(audits.map(({ slug }) => slug));
254
- }
255
-
256
- // packages/models/src/lib/plugin-config-groups.ts
257
- import { z as z5 } from "zod";
258
- var auditGroupRefSchema = weightedRefSchema(
259
- "Weighted references to audits",
260
- "Reference slug to an audit within this plugin (e.g. 'max-lines')"
320
+ // packages/models/src/lib/group.ts
321
+ import { z as z7 } from "zod";
322
+ var groupRefSchema = weightedRefSchema(
323
+ "Weighted reference to a group",
324
+ "Reference slug to a group within this plugin (e.g. 'max-lines')"
261
325
  );
262
- var auditGroupMetaSchema = metaSchema({
326
+ var groupMetaSchema = metaSchema({
263
327
  titleDescription: "Descriptive name for the group",
264
328
  descriptionDescription: "Description of the group (markdown)",
265
329
  docsUrlDescription: "Group documentation site",
266
330
  description: "Group metadata"
267
331
  });
268
- var auditGroupSchema = scorableSchema(
269
- 'An audit group aggregates a set of audits into a single score which can be referenced from a category. E.g. the group slug "performance" groups audits and can be referenced in a category',
270
- auditGroupRefSchema,
332
+ var groupSchema = scorableSchema(
333
+ 'A group aggregates a set of audits into a single score which can be referenced from a category. E.g. the group slug "performance" groups audits and can be referenced in a category',
334
+ groupRefSchema,
271
335
  getDuplicateRefsInGroups,
272
336
  duplicateRefsInGroupsErrorMsg
273
- ).merge(auditGroupMetaSchema);
274
- var auditGroupsSchema = z5.array(auditGroupSchema, {
337
+ ).merge(groupMetaSchema);
338
+ var groupsSchema = z7.array(groupSchema, {
275
339
  description: "List of groups"
276
340
  }).optional().refine(
277
341
  (groups) => !getDuplicateSlugsInGroups(groups),
@@ -279,16 +343,14 @@ var auditGroupsSchema = z5.array(auditGroupSchema, {
279
343
  message: duplicateSlugsInGroupsErrorMsg(groups)
280
344
  })
281
345
  );
282
- function duplicateRefsInGroupsErrorMsg(groupAudits) {
283
- const duplicateRefs = getDuplicateRefsInGroups(groupAudits);
284
- return `In plugin groups the audit refs are not unique: ${errorItems(
346
+ function duplicateRefsInGroupsErrorMsg(groups) {
347
+ const duplicateRefs = getDuplicateRefsInGroups(groups);
348
+ return `In plugin groups the following references are not unique: ${errorItems(
285
349
  duplicateRefs
286
350
  )}`;
287
351
  }
288
- function getDuplicateRefsInGroups(groupAudits) {
289
- return hasDuplicateStrings(
290
- groupAudits.map(({ slug: ref }) => ref).filter(exists)
291
- );
352
+ function getDuplicateRefsInGroups(groups) {
353
+ return hasDuplicateStrings(groups.map(({ slug: ref }) => ref).filter(exists));
292
354
  }
293
355
  function duplicateSlugsInGroupsErrorMsg(groups) {
294
356
  const duplicateRefs = getDuplicateSlugsInGroups(groups);
@@ -298,76 +360,8 @@ function getDuplicateSlugsInGroups(groups) {
298
360
  return Array.isArray(groups) ? hasDuplicateStrings(groups.map(({ slug }) => slug)) : false;
299
361
  }
300
362
 
301
- // packages/models/src/lib/plugin-config-runner.ts
363
+ // packages/models/src/lib/runner-config.ts
302
364
  import { z as z8 } from "zod";
303
-
304
- // packages/models/src/lib/plugin-process-output.ts
305
- import { z as z7 } from "zod";
306
-
307
- // packages/models/src/lib/plugin-process-output-audit-issue.ts
308
- import { z as z6 } from "zod";
309
- var sourceFileLocationSchema = z6.object(
310
- {
311
- file: filePathSchema("Relative path to source file in Git repo"),
312
- position: z6.object(
313
- {
314
- startLine: positiveIntSchema("Start line"),
315
- startColumn: positiveIntSchema("Start column").optional(),
316
- endLine: positiveIntSchema("End line").optional(),
317
- endColumn: positiveIntSchema("End column").optional()
318
- },
319
- { description: "Location in file" }
320
- ).optional()
321
- },
322
- { description: "Source file location" }
323
- );
324
- var issueSeveritySchema = z6.enum(["info", "warning", "error"], {
325
- description: "Severity level"
326
- });
327
- var issueSchema = z6.object(
328
- {
329
- message: z6.string({ description: "Descriptive error message" }).max(512),
330
- severity: issueSeveritySchema,
331
- source: sourceFileLocationSchema.optional()
332
- },
333
- { description: "Issue information" }
334
- );
335
-
336
- // packages/models/src/lib/plugin-process-output.ts
337
- var auditOutputSchema = z7.object(
338
- {
339
- slug: slugSchema("Reference to audit"),
340
- displayValue: z7.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional(),
341
- value: positiveIntSchema("Raw numeric value"),
342
- score: z7.number({
343
- description: "Value between 0 and 1"
344
- }).min(0).max(1),
345
- details: z7.object(
346
- {
347
- issues: z7.array(issueSchema, { description: "List of findings" })
348
- },
349
- { description: "Detailed information" }
350
- ).optional()
351
- },
352
- { description: "Audit information" }
353
- );
354
- var auditOutputsSchema = z7.array(auditOutputSchema, {
355
- description: "List of JSON formatted audit output emitted by the runner process of a plugin"
356
- }).refine(
357
- (audits) => !getDuplicateSlugsInAudits2(audits),
358
- (audits) => ({ message: duplicateSlugsInAuditsErrorMsg2(audits) })
359
- );
360
- function duplicateSlugsInAuditsErrorMsg2(audits) {
361
- const duplicateRefs = getDuplicateSlugsInAudits2(audits);
362
- return `In plugin audits the slugs are not unique: ${errorItems(
363
- duplicateRefs
364
- )}`;
365
- }
366
- function getDuplicateSlugsInAudits2(audits) {
367
- return hasDuplicateStrings(audits.map(({ slug }) => slug));
368
- }
369
-
370
- // packages/models/src/lib/plugin-config-runner.ts
371
365
  var outputTransformSchema = z8.function().args(z8.unknown()).returns(z8.union([auditOutputsSchema, z8.promise(auditOutputsSchema)]));
372
366
  var runnerConfigSchema = z8.object(
373
367
  {
@@ -404,7 +398,7 @@ var pluginMetaSchema = packageVersionSchema({
404
398
  var pluginDataSchema = z9.object({
405
399
  runner: z9.union([runnerConfigSchema, runnerFunctionSchema]),
406
400
  audits: pluginAuditsSchema,
407
- groups: auditGroupsSchema
401
+ groups: groupsSchema
408
402
  });
409
403
  var pluginConfigSchema = pluginMetaSchema.merge(pluginDataSchema).refine(
410
404
  (pluginCfg) => !getMissingRefsFromGroups(pluginCfg),
@@ -517,7 +511,7 @@ var pluginReportSchema = pluginMetaSchema.merge(
517
511
  ).merge(
518
512
  z12.object({
519
513
  audits: z12.array(auditReportSchema),
520
- groups: z12.array(auditGroupSchema).optional()
514
+ groups: z12.array(groupSchema).optional()
521
515
  })
522
516
  );
523
517
  var reportSchema = packageVersionSchema({
@@ -789,25 +783,28 @@ function calcDuration(start, stop) {
789
783
  return Math.floor(stop - start);
790
784
  }
791
785
  function countCategoryAudits(refs, plugins) {
792
- const groupLookup = plugins.reduce((lookup, plugin) => {
793
- if (!plugin.groups.length) {
794
- return lookup;
795
- }
796
- return {
797
- ...lookup,
798
- [plugin.slug]: {
799
- ...plugin.groups.reduce(
800
- (groupLookup2, group) => {
801
- return {
802
- ...groupLookup2,
803
- [group.slug]: group
804
- };
805
- },
806
- {}
807
- )
786
+ const groupLookup = plugins.reduce(
787
+ (lookup, plugin) => {
788
+ if (!plugin.groups.length) {
789
+ return lookup;
808
790
  }
809
- };
810
- }, {});
791
+ return {
792
+ ...lookup,
793
+ [plugin.slug]: {
794
+ ...plugin.groups.reduce(
795
+ (groupLookup2, group) => {
796
+ return {
797
+ ...groupLookup2,
798
+ [group.slug]: group
799
+ };
800
+ },
801
+ {}
802
+ )
803
+ }
804
+ };
805
+ },
806
+ {}
807
+ );
811
808
  return refs.reduce((acc, ref) => {
812
809
  if (ref.type === "group") {
813
810
  const groupRefs = groupLookup[ref.plugin]?.[ref.slug]?.refs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "bundle-require": "^4.0.1",
@@ -1,5 +1,5 @@
1
1
  import { CategoryRef, IssueSeverity as CliIssueSeverity, Format, Issue, PersistConfig, Report } from '@code-pushup/models';
2
- import { EnrichedAuditReport, EnrichedScoredAuditGroupWithAudits, ScoredReport, WeighedAuditReport } from './scoring';
2
+ import { EnrichedAuditReport, EnrichedScoredGroupWithAudits, ScoredReport, WeighedAuditReport } from './scoring';
3
3
  export declare const FOOTER_PREFIX = "Made with \u2764 by";
4
4
  export declare const CODE_PUSHUP_DOMAIN = "code-pushup.dev";
5
5
  export declare const README_LINK = "https://github.com/flowup/quality-metrics-cli#readme";
@@ -17,7 +17,7 @@ export declare function calcDuration(start: number, stop?: number): number;
17
17
  export declare function countWeightedRefs(refs: CategoryRef[]): number;
18
18
  export declare function countCategoryAudits(refs: CategoryRef[], plugins: ScoredReport['plugins']): number;
19
19
  export declare function getAuditByRef({ slug, weight, plugin }: CategoryRef, plugins: ScoredReport['plugins']): WeighedAuditReport;
20
- export declare function getGroupWithAudits(refSlug: string, refPlugin: string, plugins: ScoredReport['plugins']): EnrichedScoredAuditGroupWithAudits;
20
+ export declare function getGroupWithAudits(refSlug: string, refPlugin: string, plugins: ScoredReport['plugins']): EnrichedScoredGroupWithAudits;
21
21
  export declare function sortCategoryAudits(a: WeighedAuditReport, b: WeighedAuditReport): number;
22
22
  export declare function sortAudits(a: EnrichedAuditReport, b: EnrichedAuditReport): number;
23
23
  export declare function compareIssueSeverity(severity1: CliIssueSeverity, severity2: CliIssueSeverity): number;
@@ -1,24 +1,24 @@
1
- import { AuditGroup, AuditReport, CategoryConfig, PluginReport, Report } from '@code-pushup/models';
1
+ import { AuditReport, CategoryConfig, Group, PluginReport, Report } from '@code-pushup/models';
2
2
  export type EnrichedAuditReport = AuditReport & {
3
3
  plugin: string;
4
4
  };
5
5
  export type WeighedAuditReport = EnrichedAuditReport & {
6
6
  weight: number;
7
7
  };
8
- export type EnrichedScoredAuditGroupWithAudits = EnrichedScoredAuditGroup & {
8
+ export type EnrichedScoredGroupWithAudits = EnrichedScoredGroup & {
9
9
  audits: AuditReport[];
10
10
  };
11
11
  type ScoredCategoryConfig = CategoryConfig & {
12
12
  score: number;
13
13
  };
14
- export type EnrichedScoredAuditGroup = AuditGroup & {
14
+ export type EnrichedScoredGroup = Group & {
15
15
  plugin: string;
16
16
  score: number;
17
17
  };
18
18
  export type ScoredReport = Omit<Report, 'plugins' | 'categories'> & {
19
19
  plugins: (Omit<PluginReport, 'audits' | 'groups'> & {
20
20
  audits: EnrichedAuditReport[];
21
- groups: EnrichedScoredAuditGroup[];
21
+ groups: EnrichedScoredGroup[];
22
22
  })[];
23
23
  categories: ScoredCategoryConfig[];
24
24
  };