@code-pushup/js-packages-plugin 0.49.0 → 0.51.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.
Files changed (37) hide show
  1. package/README.md +2 -2
  2. package/bin.js +169 -147
  3. package/index.js +310 -142
  4. package/package.json +5 -31
  5. package/src/lib/config.d.ts +5 -5
  6. package/src/lib/constants.d.ts +2 -2
  7. package/src/lib/js-packages-plugin.d.ts +2 -2
  8. package/src/lib/package-managers/derive-package-manager.d.ts +3 -0
  9. package/src/lib/package-managers/derive-yarn.d.ts +1 -0
  10. package/src/lib/package-managers/index.d.ts +1 -1
  11. package/src/lib/package-managers/npm/audit-result.d.ts +2 -2
  12. package/src/lib/package-managers/npm/npm.d.ts +1 -1
  13. package/src/lib/package-managers/npm/outdated-result.d.ts +1 -1
  14. package/src/lib/package-managers/npm/types.d.ts +3 -3
  15. package/src/lib/package-managers/package-managers.d.ts +2 -2
  16. package/src/lib/package-managers/pnpm/audit-result.d.ts +1 -1
  17. package/src/lib/package-managers/pnpm/outdated-result.d.ts +1 -1
  18. package/src/lib/package-managers/pnpm/pnpm.d.ts +1 -1
  19. package/src/lib/package-managers/pnpm/types.d.ts +2 -2
  20. package/src/lib/package-managers/pnpm/utils.d.ts +1 -0
  21. package/src/lib/package-managers/types.d.ts +3 -3
  22. package/src/lib/package-managers/yarn-classic/audit-result.d.ts +1 -1
  23. package/src/lib/package-managers/yarn-classic/constants.d.ts +2 -2
  24. package/src/lib/package-managers/yarn-classic/outdated-result.d.ts +1 -1
  25. package/src/lib/package-managers/yarn-classic/types.d.ts +1 -1
  26. package/src/lib/package-managers/yarn-classic/yarn-classic.d.ts +1 -1
  27. package/src/lib/package-managers/yarn-modern/audit-result.d.ts +1 -1
  28. package/src/lib/package-managers/yarn-modern/outdated-result.d.ts +1 -1
  29. package/src/lib/package-managers/yarn-modern/types.d.ts +2 -2
  30. package/src/lib/package-managers/yarn-modern/yarn-modern.d.ts +1 -1
  31. package/src/lib/runner/audit/constants.d.ts +1 -1
  32. package/src/lib/runner/audit/transform.d.ts +2 -2
  33. package/src/lib/runner/audit/utils.d.ts +1 -1
  34. package/src/lib/runner/index.d.ts +1 -1
  35. package/src/lib/runner/outdated/transform.d.ts +3 -3
  36. package/src/lib/runner/utils.d.ts +2 -2
  37. package/src/lib/utils.d.ts +10 -0
package/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  // packages/plugin-js-packages/src/lib/js-packages-plugin.ts
2
- import { dirname as dirname2, join as join3 } from "node:path";
2
+ import { dirname as dirname2, join as join4 } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
 
5
5
  // packages/plugin-js-packages/package.json
6
6
  var name = "@code-pushup/js-packages-plugin";
7
- var version = "0.49.0";
7
+ var version = "0.51.0";
8
8
 
9
9
  // packages/plugin-js-packages/src/lib/config.ts
10
- import { z as z16 } from "zod";
10
+ import { z as z17 } from "zod";
11
11
 
12
12
  // packages/models/src/lib/implementation/schemas.ts
13
13
  import { MATERIAL_ICONS } from "vscode-material-icons";
@@ -166,9 +166,27 @@ function hasNonZeroWeightedRef(refs) {
166
166
  return refs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
167
167
  }
168
168
 
169
- // packages/models/src/lib/audit.ts
169
+ // packages/models/src/lib/source.ts
170
170
  import { z as z2 } from "zod";
171
- var auditSchema = z2.object({
171
+ var sourceFileLocationSchema = z2.object(
172
+ {
173
+ file: filePathSchema.describe("Relative path to source file in Git repo"),
174
+ position: z2.object(
175
+ {
176
+ startLine: positiveIntSchema.describe("Start line"),
177
+ startColumn: positiveIntSchema.describe("Start column").optional(),
178
+ endLine: positiveIntSchema.describe("End line").optional(),
179
+ endColumn: positiveIntSchema.describe("End column").optional()
180
+ },
181
+ { description: "Location in file" }
182
+ ).optional()
183
+ },
184
+ { description: "Source file location" }
185
+ );
186
+
187
+ // packages/models/src/lib/audit.ts
188
+ import { z as z3 } from "zod";
189
+ var auditSchema = z3.object({
172
190
  slug: slugSchema.describe("ID (unique within plugin)")
173
191
  }).merge(
174
192
  metaSchema({
@@ -178,7 +196,7 @@ var auditSchema = z2.object({
178
196
  description: "List of scorable metrics for the given plugin"
179
197
  })
180
198
  );
181
- var pluginAuditsSchema = z2.array(auditSchema, {
199
+ var pluginAuditsSchema = z3.array(auditSchema, {
182
200
  description: "List of audits maintained in a plugin"
183
201
  }).min(1).refine(
184
202
  (auditMetadata) => !getDuplicateSlugsInAudits(auditMetadata),
@@ -197,31 +215,16 @@ function getDuplicateSlugsInAudits(audits) {
197
215
  }
198
216
 
199
217
  // packages/models/src/lib/audit-output.ts
200
- import { z as z5 } from "zod";
218
+ import { z as z6 } from "zod";
201
219
 
202
220
  // packages/models/src/lib/issue.ts
203
- import { z as z3 } from "zod";
204
- var sourceFileLocationSchema = z3.object(
205
- {
206
- file: filePathSchema.describe("Relative path to source file in Git repo"),
207
- position: z3.object(
208
- {
209
- startLine: positiveIntSchema.describe("Start line"),
210
- startColumn: positiveIntSchema.describe("Start column").optional(),
211
- endLine: positiveIntSchema.describe("End line").optional(),
212
- endColumn: positiveIntSchema.describe("End column").optional()
213
- },
214
- { description: "Location in file" }
215
- ).optional()
216
- },
217
- { description: "Source file location" }
218
- );
219
- var issueSeveritySchema = z3.enum(["info", "warning", "error"], {
221
+ import { z as z4 } from "zod";
222
+ var issueSeveritySchema = z4.enum(["info", "warning", "error"], {
220
223
  description: "Severity level"
221
224
  });
222
- var issueSchema = z3.object(
225
+ var issueSchema = z4.object(
223
226
  {
224
- message: z3.string({ description: "Descriptive error message" }).max(MAX_ISSUE_MESSAGE_LENGTH),
227
+ message: z4.string({ description: "Descriptive error message" }).max(MAX_ISSUE_MESSAGE_LENGTH),
225
228
  severity: issueSeveritySchema,
226
229
  source: sourceFileLocationSchema.optional()
227
230
  },
@@ -229,60 +232,60 @@ var issueSchema = z3.object(
229
232
  );
230
233
 
231
234
  // packages/models/src/lib/table.ts
232
- import { z as z4 } from "zod";
233
- var tableAlignmentSchema = z4.enum(["left", "center", "right"], {
235
+ import { z as z5 } from "zod";
236
+ var tableAlignmentSchema = z5.enum(["left", "center", "right"], {
234
237
  description: "Cell alignment"
235
238
  });
236
- var tableColumnObjectSchema = z4.object({
237
- key: z4.string(),
238
- label: z4.string().optional(),
239
+ var tableColumnObjectSchema = z5.object({
240
+ key: z5.string(),
241
+ label: z5.string().optional(),
239
242
  align: tableAlignmentSchema.optional()
240
243
  });
241
- var tableRowObjectSchema = z4.record(tableCellValueSchema, {
244
+ var tableRowObjectSchema = z5.record(tableCellValueSchema, {
242
245
  description: "Object row"
243
246
  });
244
- var tableRowPrimitiveSchema = z4.array(tableCellValueSchema, {
247
+ var tableRowPrimitiveSchema = z5.array(tableCellValueSchema, {
245
248
  description: "Primitive row"
246
249
  });
247
- var tableSharedSchema = z4.object({
248
- title: z4.string().optional().describe("Display title for table")
250
+ var tableSharedSchema = z5.object({
251
+ title: z5.string().optional().describe("Display title for table")
249
252
  });
250
253
  var tablePrimitiveSchema = tableSharedSchema.merge(
251
- z4.object(
254
+ z5.object(
252
255
  {
253
- columns: z4.array(tableAlignmentSchema).optional(),
254
- rows: z4.array(tableRowPrimitiveSchema)
256
+ columns: z5.array(tableAlignmentSchema).optional(),
257
+ rows: z5.array(tableRowPrimitiveSchema)
255
258
  },
256
259
  { description: "Table with primitive rows and optional alignment columns" }
257
260
  )
258
261
  );
259
262
  var tableObjectSchema = tableSharedSchema.merge(
260
- z4.object(
263
+ z5.object(
261
264
  {
262
- columns: z4.union([
263
- z4.array(tableAlignmentSchema),
264
- z4.array(tableColumnObjectSchema)
265
+ columns: z5.union([
266
+ z5.array(tableAlignmentSchema),
267
+ z5.array(tableColumnObjectSchema)
265
268
  ]).optional(),
266
- rows: z4.array(tableRowObjectSchema)
269
+ rows: z5.array(tableRowObjectSchema)
267
270
  },
268
271
  {
269
272
  description: "Table with object rows and optional alignment or object columns"
270
273
  }
271
274
  )
272
275
  );
273
- var tableSchema = (description = "Table information") => z4.union([tablePrimitiveSchema, tableObjectSchema], { description });
276
+ var tableSchema = (description = "Table information") => z5.union([tablePrimitiveSchema, tableObjectSchema], { description });
274
277
 
275
278
  // packages/models/src/lib/audit-output.ts
276
279
  var auditValueSchema = nonnegativeNumberSchema.describe("Raw numeric value");
277
- var auditDisplayValueSchema = z5.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
278
- var auditDetailsSchema = z5.object(
280
+ var auditDisplayValueSchema = z6.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
281
+ var auditDetailsSchema = z6.object(
279
282
  {
280
- issues: z5.array(issueSchema, { description: "List of findings" }).optional(),
283
+ issues: z6.array(issueSchema, { description: "List of findings" }).optional(),
281
284
  table: tableSchema("Table of related findings").optional()
282
285
  },
283
286
  { description: "Detailed information" }
284
287
  );
285
- var auditOutputSchema = z5.object(
288
+ var auditOutputSchema = z6.object(
286
289
  {
287
290
  slug: slugSchema.describe("Reference to audit"),
288
291
  displayValue: auditDisplayValueSchema,
@@ -292,7 +295,7 @@ var auditOutputSchema = z5.object(
292
295
  },
293
296
  { description: "Audit information" }
294
297
  );
295
- var auditOutputsSchema = z5.array(auditOutputSchema, {
298
+ var auditOutputsSchema = z6.array(auditOutputSchema, {
296
299
  description: "List of JSON formatted audit output emitted by the runner process of a plugin"
297
300
  }).refine(
298
301
  (audits) => !getDuplicateSlugsInAudits2(audits),
@@ -309,13 +312,13 @@ function getDuplicateSlugsInAudits2(audits) {
309
312
  }
310
313
 
311
314
  // packages/models/src/lib/category-config.ts
312
- import { z as z6 } from "zod";
315
+ import { z as z7 } from "zod";
313
316
  var categoryRefSchema = weightedRefSchema(
314
317
  "Weighted references to audits and/or groups for the category",
315
318
  "Slug of an audit or group (depending on `type`)"
316
319
  ).merge(
317
- z6.object({
318
- type: z6.enum(["audit", "group"], {
320
+ z7.object({
321
+ type: z7.enum(["audit", "group"], {
319
322
  description: "Discriminant for reference kind, affects where `slug` is looked up"
320
323
  }),
321
324
  plugin: slugSchema.describe(
@@ -336,8 +339,8 @@ var categoryConfigSchema = scorableSchema(
336
339
  description: "Meta info for category"
337
340
  })
338
341
  ).merge(
339
- z6.object({
340
- isBinary: z6.boolean({
342
+ z7.object({
343
+ isBinary: z7.boolean({
341
344
  description: 'Is this a binary category (i.e. only a perfect score considered a "pass")?'
342
345
  }).optional()
343
346
  })
@@ -353,7 +356,7 @@ function getDuplicateRefsInCategoryMetrics(metrics) {
353
356
  metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
354
357
  );
355
358
  }
356
- var categoriesSchema = z6.array(categoryConfigSchema, {
359
+ var categoriesSchema = z7.array(categoryConfigSchema, {
357
360
  description: "Categorization of individual audits"
358
361
  }).refine(
359
362
  (categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
@@ -372,18 +375,18 @@ function getDuplicateSlugCategories(categories) {
372
375
  }
373
376
 
374
377
  // packages/models/src/lib/commit.ts
375
- import { z as z7 } from "zod";
376
- var commitSchema = z7.object(
378
+ import { z as z8 } from "zod";
379
+ var commitSchema = z8.object(
377
380
  {
378
- hash: z7.string({ description: "Commit SHA (full)" }).regex(
381
+ hash: z8.string({ description: "Commit SHA (full)" }).regex(
379
382
  /^[\da-f]{40}$/,
380
383
  "Commit SHA should be a 40-character hexadecimal string"
381
384
  ),
382
- message: z7.string({ description: "Commit message" }),
383
- date: z7.coerce.date({
385
+ message: z8.string({ description: "Commit message" }),
386
+ date: z8.coerce.date({
384
387
  description: "Date and time when commit was authored"
385
388
  }),
386
- author: z7.string({
389
+ author: z8.string({
387
390
  description: "Commit author name"
388
391
  }).trim()
389
392
  },
@@ -391,22 +394,22 @@ var commitSchema = z7.object(
391
394
  );
392
395
 
393
396
  // packages/models/src/lib/core-config.ts
394
- import { z as z13 } from "zod";
397
+ import { z as z14 } from "zod";
395
398
 
396
399
  // packages/models/src/lib/persist-config.ts
397
- import { z as z8 } from "zod";
398
- var formatSchema = z8.enum(["json", "md"]);
399
- var persistConfigSchema = z8.object({
400
+ import { z as z9 } from "zod";
401
+ var formatSchema = z9.enum(["json", "md"]);
402
+ var persistConfigSchema = z9.object({
400
403
  outputDir: filePathSchema.describe("Artifacts folder").optional(),
401
404
  filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
402
- format: z8.array(formatSchema).optional()
405
+ format: z9.array(formatSchema).optional()
403
406
  });
404
407
 
405
408
  // packages/models/src/lib/plugin-config.ts
406
- import { z as z11 } from "zod";
409
+ import { z as z12 } from "zod";
407
410
 
408
411
  // packages/models/src/lib/group.ts
409
- import { z as z9 } from "zod";
412
+ import { z as z10 } from "zod";
410
413
  var groupRefSchema = weightedRefSchema(
411
414
  "Weighted reference to a group",
412
415
  "Reference slug to a group within this plugin (e.g. 'max-lines')"
@@ -423,7 +426,7 @@ var groupSchema = scorableSchema(
423
426
  getDuplicateRefsInGroups,
424
427
  duplicateRefsInGroupsErrorMsg
425
428
  ).merge(groupMetaSchema);
426
- var groupsSchema = z9.array(groupSchema, {
429
+ var groupsSchema = z10.array(groupSchema, {
427
430
  description: "List of groups"
428
431
  }).optional().refine(
429
432
  (groups) => !getDuplicateSlugsInGroups(groups),
@@ -451,14 +454,14 @@ function getDuplicateSlugsInGroups(groups) {
451
454
  }
452
455
 
453
456
  // packages/models/src/lib/runner-config.ts
454
- import { z as z10 } from "zod";
455
- var outputTransformSchema = z10.function().args(z10.unknown()).returns(z10.union([auditOutputsSchema, z10.promise(auditOutputsSchema)]));
456
- var runnerConfigSchema = z10.object(
457
+ import { z as z11 } from "zod";
458
+ var outputTransformSchema = z11.function().args(z11.unknown()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
459
+ var runnerConfigSchema = z11.object(
457
460
  {
458
- command: z10.string({
461
+ command: z11.string({
459
462
  description: "Shell command to execute"
460
463
  }),
461
- args: z10.array(z10.string({ description: "Command arguments" })).optional(),
464
+ args: z11.array(z11.string({ description: "Command arguments" })).optional(),
462
465
  outputFile: filePathSchema.describe("Output path"),
463
466
  outputTransform: outputTransformSchema.optional()
464
467
  },
@@ -466,8 +469,8 @@ var runnerConfigSchema = z10.object(
466
469
  description: "How to execute runner"
467
470
  }
468
471
  );
469
- var onProgressSchema = z10.function().args(z10.unknown()).returns(z10.void());
470
- var runnerFunctionSchema = z10.function().args(onProgressSchema.optional()).returns(z10.union([auditOutputsSchema, z10.promise(auditOutputsSchema)]));
472
+ var onProgressSchema = z11.function().args(z11.unknown()).returns(z11.void());
473
+ var runnerFunctionSchema = z11.function().args(onProgressSchema.optional()).returns(z11.union([auditOutputsSchema, z11.promise(auditOutputsSchema)]));
471
474
 
472
475
  // packages/models/src/lib/plugin-config.ts
473
476
  var pluginMetaSchema = packageVersionSchema().merge(
@@ -478,13 +481,13 @@ var pluginMetaSchema = packageVersionSchema().merge(
478
481
  description: "Plugin metadata"
479
482
  })
480
483
  ).merge(
481
- z11.object({
484
+ z12.object({
482
485
  slug: slugSchema.describe("Unique plugin slug within core config"),
483
486
  icon: materialIconSchema
484
487
  })
485
488
  );
486
- var pluginDataSchema = z11.object({
487
- runner: z11.union([runnerConfigSchema, runnerFunctionSchema]),
489
+ var pluginDataSchema = z12.object({
490
+ runner: z12.union([runnerConfigSchema, runnerFunctionSchema]),
488
491
  audits: pluginAuditsSchema,
489
492
  groups: groupsSchema
490
493
  });
@@ -510,22 +513,22 @@ function getMissingRefsFromGroups(pluginCfg) {
510
513
  }
511
514
 
512
515
  // packages/models/src/lib/upload-config.ts
513
- import { z as z12 } from "zod";
514
- var uploadConfigSchema = z12.object({
516
+ import { z as z13 } from "zod";
517
+ var uploadConfigSchema = z13.object({
515
518
  server: urlSchema.describe("URL of deployed portal API"),
516
- apiKey: z12.string({
519
+ apiKey: z13.string({
517
520
  description: "API key with write access to portal (use `process.env` for security)"
518
521
  }),
519
522
  organization: slugSchema.describe(
520
523
  "Organization slug from Code PushUp portal"
521
524
  ),
522
525
  project: slugSchema.describe("Project slug from Code PushUp portal"),
523
- timeout: z12.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
526
+ timeout: z13.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
524
527
  });
525
528
 
526
529
  // packages/models/src/lib/core-config.ts
527
- var unrefinedCoreConfigSchema = z13.object({
528
- plugins: z13.array(pluginConfigSchema, {
530
+ var unrefinedCoreConfigSchema = z14.object({
531
+ plugins: z14.array(pluginConfigSchema, {
529
532
  description: "List of plugins to be used (official, community-provided, or custom)"
530
533
  }).min(1),
531
534
  /** portal configuration for persisting results */
@@ -548,7 +551,7 @@ function refineCoreConfig(schema) {
548
551
  }
549
552
 
550
553
  // packages/models/src/lib/report.ts
551
- import { z as z14 } from "zod";
554
+ import { z as z15 } from "zod";
552
555
  var auditReportSchema = auditSchema.merge(auditOutputSchema);
553
556
  var pluginReportSchema = pluginMetaSchema.merge(
554
557
  executionMetaSchema({
@@ -556,9 +559,9 @@ var pluginReportSchema = pluginMetaSchema.merge(
556
559
  descriptionDuration: "Duration of the plugin run in ms"
557
560
  })
558
561
  ).merge(
559
- z14.object({
560
- audits: z14.array(auditReportSchema).min(1),
561
- groups: z14.array(groupSchema).optional()
562
+ z15.object({
563
+ audits: z15.array(auditReportSchema).min(1),
564
+ groups: z15.array(groupSchema).optional()
562
565
  })
563
566
  ).refine(
564
567
  (pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
@@ -592,10 +595,10 @@ var reportSchema = packageVersionSchema({
592
595
  descriptionDuration: "Duration of the collect run in ms"
593
596
  })
594
597
  ).merge(
595
- z14.object(
598
+ z15.object(
596
599
  {
597
- categories: z14.array(categoryConfigSchema),
598
- plugins: z14.array(pluginReportSchema).min(1),
600
+ categories: z15.array(categoryConfigSchema),
601
+ plugins: z15.array(pluginReportSchema).min(1),
599
602
  commit: commitSchema.describe("Git commit for which report was collected").nullable()
600
603
  },
601
604
  { description: "Collect output data" }
@@ -611,40 +614,40 @@ var reportSchema = packageVersionSchema({
611
614
  );
612
615
 
613
616
  // packages/models/src/lib/reports-diff.ts
614
- import { z as z15 } from "zod";
617
+ import { z as z16 } from "zod";
615
618
  function makeComparisonSchema(schema) {
616
619
  const sharedDescription = schema.description || "Result";
617
- return z15.object({
620
+ return z16.object({
618
621
  before: schema.describe(`${sharedDescription} (source commit)`),
619
622
  after: schema.describe(`${sharedDescription} (target commit)`)
620
623
  });
621
624
  }
622
625
  function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
623
- return z15.object(
626
+ return z16.object(
624
627
  {
625
- changed: z15.array(diffSchema),
626
- unchanged: z15.array(resultSchema),
627
- added: z15.array(resultSchema),
628
- removed: z15.array(resultSchema)
628
+ changed: z16.array(diffSchema),
629
+ unchanged: z16.array(resultSchema),
630
+ added: z16.array(resultSchema),
631
+ removed: z16.array(resultSchema)
629
632
  },
630
633
  { description }
631
634
  );
632
635
  }
633
- var scorableMetaSchema = z15.object({
636
+ var scorableMetaSchema = z16.object({
634
637
  slug: slugSchema,
635
638
  title: titleSchema,
636
639
  docsUrl: docsUrlSchema
637
640
  });
638
641
  var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
639
- z15.object({
642
+ z16.object({
640
643
  plugin: pluginMetaSchema.pick({ slug: true, title: true, docsUrl: true }).describe("Plugin which defines it")
641
644
  })
642
645
  );
643
646
  var scorableDiffSchema = scorableMetaSchema.merge(
644
- z15.object({
647
+ z16.object({
645
648
  scores: makeComparisonSchema(scoreSchema).merge(
646
- z15.object({
647
- diff: z15.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
649
+ z16.object({
650
+ diff: z16.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
648
651
  })
649
652
  ).describe("Score comparison")
650
653
  })
@@ -655,10 +658,10 @@ var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
655
658
  var categoryDiffSchema = scorableDiffSchema;
656
659
  var groupDiffSchema = scorableWithPluginDiffSchema;
657
660
  var auditDiffSchema = scorableWithPluginDiffSchema.merge(
658
- z15.object({
661
+ z16.object({
659
662
  values: makeComparisonSchema(auditValueSchema).merge(
660
- z15.object({
661
- diff: z15.number().int().describe("Value change (`values.after - values.before`)")
663
+ z16.object({
664
+ diff: z16.number().int().describe("Value change (`values.after - values.before`)")
662
665
  })
663
666
  ).describe("Audit `value` comparison"),
664
667
  displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
@@ -667,16 +670,18 @@ var auditDiffSchema = scorableWithPluginDiffSchema.merge(
667
670
  })
668
671
  );
669
672
  var categoryResultSchema = scorableMetaSchema.merge(
670
- z15.object({ score: scoreSchema })
673
+ z16.object({ score: scoreSchema })
671
674
  );
672
675
  var groupResultSchema = scorableWithPluginMetaSchema.merge(
673
- z15.object({ score: scoreSchema })
676
+ z16.object({ score: scoreSchema })
674
677
  );
675
678
  var auditResultSchema = scorableWithPluginMetaSchema.merge(
676
679
  auditOutputSchema.pick({ score: true, value: true, displayValue: true })
677
680
  );
678
- var reportsDiffSchema = z15.object({
681
+ var reportsDiffSchema = z16.object({
679
682
  commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
683
+ portalUrl: urlSchema.optional().describe("Link to comparison page in Code PushUp portal"),
684
+ label: z16.string().optional().describe("Label (e.g. project name)"),
680
685
  categories: makeArraysComparisonSchema(
681
686
  categoryDiffSchema,
682
687
  categoryResultSchema,
@@ -730,17 +735,17 @@ var dependencyDocs = {
730
735
 
731
736
  // packages/plugin-js-packages/src/lib/config.ts
732
737
  var dependencyGroups = ["prod", "dev", "optional"];
733
- var dependencyGroupSchema = z16.enum(dependencyGroups);
734
- var packageCommandSchema = z16.enum(["audit", "outdated"]);
735
- var packageManagerIdSchema = z16.enum([
738
+ var dependencyGroupSchema = z17.enum(dependencyGroups);
739
+ var packageCommandSchema = z17.enum(["audit", "outdated"]);
740
+ var packageManagerIdSchema = z17.enum([
736
741
  "npm",
737
742
  "yarn-classic",
738
743
  "yarn-modern",
739
744
  "pnpm"
740
745
  ]);
741
- var packageJsonPathSchema = z16.union([
742
- z16.array(z16.string()).min(1),
743
- z16.object({ autoSearch: z16.literal(true) })
746
+ var packageJsonPathSchema = z17.union([
747
+ z17.array(z17.string()).min(1),
748
+ z17.object({ autoSearch: z17.literal(true) })
744
749
  ]).describe(
745
750
  "File paths to package.json. Looks only at root package.json by default"
746
751
  ).default(["package.json"]);
@@ -751,7 +756,7 @@ var packageAuditLevels = [
751
756
  "low",
752
757
  "info"
753
758
  ];
754
- var packageAuditLevelSchema = z16.enum(packageAuditLevels);
759
+ var packageAuditLevelSchema = z17.enum(packageAuditLevels);
755
760
  function fillAuditLevelMapping(mapping) {
756
761
  return {
757
762
  critical: mapping.critical ?? defaultAuditLevelMapping.critical,
@@ -761,20 +766,23 @@ function fillAuditLevelMapping(mapping) {
761
766
  info: mapping.info ?? defaultAuditLevelMapping.info
762
767
  };
763
768
  }
764
- var jsPackagesPluginConfigSchema = z16.object({
765
- checks: z16.array(packageCommandSchema, {
769
+ var jsPackagesPluginConfigSchema = z17.object({
770
+ checks: z17.array(packageCommandSchema, {
766
771
  description: "Package manager commands to be run. Defaults to both audit and outdated."
767
772
  }).min(1).default(["audit", "outdated"]),
768
- packageManager: packageManagerIdSchema.describe(
769
- "Package manager to be used."
770
- ),
771
- dependencyGroups: z16.array(dependencyGroupSchema).min(1).default(["prod", "dev"]),
772
- auditLevelMapping: z16.record(packageAuditLevelSchema, issueSeveritySchema, {
773
+ packageManager: packageManagerIdSchema.describe("Package manager to be used.").optional(),
774
+ dependencyGroups: z17.array(dependencyGroupSchema).min(1).default(["prod", "dev"]),
775
+ auditLevelMapping: z17.record(packageAuditLevelSchema, issueSeveritySchema, {
773
776
  description: "Mapping of audit levels to issue severity. Custom mapping or overrides may be entered manually, otherwise has a default preset."
774
777
  }).default(defaultAuditLevelMapping).transform(fillAuditLevelMapping),
775
778
  packageJsonPaths: packageJsonPathSchema
776
779
  });
777
780
 
781
+ // packages/utils/src/lib/execute-process.ts
782
+ import {
783
+ spawn
784
+ } from "node:child_process";
785
+
778
786
  // packages/utils/src/lib/reports/utils.ts
779
787
  import ansis from "ansis";
780
788
  import { md } from "build-md";
@@ -782,6 +790,60 @@ import { md } from "build-md";
782
790
  // packages/utils/src/lib/reports/constants.ts
783
791
  var TERMINAL_WIDTH = 80;
784
792
 
793
+ // packages/utils/src/lib/reports/utils.ts
794
+ function calcDuration(start, stop) {
795
+ return Math.round((stop ?? performance.now()) - start);
796
+ }
797
+
798
+ // packages/utils/src/lib/execute-process.ts
799
+ var ProcessError = class extends Error {
800
+ code;
801
+ stderr;
802
+ stdout;
803
+ constructor(result) {
804
+ super(result.stderr);
805
+ this.code = result.code;
806
+ this.stderr = result.stderr;
807
+ this.stdout = result.stdout;
808
+ }
809
+ };
810
+ function executeProcess(cfg) {
811
+ const { command, args, observer, ignoreExitCode = false, ...options } = cfg;
812
+ const { onStdout, onStderr, onError, onComplete } = observer ?? {};
813
+ const date = (/* @__PURE__ */ new Date()).toISOString();
814
+ const start = performance.now();
815
+ return new Promise((resolve, reject) => {
816
+ const spawnedProcess = spawn(command, args ?? [], {
817
+ shell: true,
818
+ ...options
819
+ });
820
+ let stdout = "";
821
+ let stderr = "";
822
+ spawnedProcess.stdout.on("data", (data) => {
823
+ stdout += String(data);
824
+ onStdout?.(String(data), spawnedProcess);
825
+ });
826
+ spawnedProcess.stderr.on("data", (data) => {
827
+ stderr += String(data);
828
+ onStderr?.(String(data), spawnedProcess);
829
+ });
830
+ spawnedProcess.on("error", (err) => {
831
+ stderr += err.toString();
832
+ });
833
+ spawnedProcess.on("close", (code2) => {
834
+ const timings = { date, duration: calcDuration(start) };
835
+ if (code2 === 0 || ignoreExitCode) {
836
+ onComplete?.();
837
+ resolve({ code: code2, stdout, stderr, ...timings });
838
+ } else {
839
+ const errorMsg = new ProcessError({ code: code2, stdout, stderr, ...timings });
840
+ onError?.(errorMsg);
841
+ reject(errorMsg);
842
+ }
843
+ });
844
+ });
845
+ }
846
+
785
847
  // packages/utils/src/lib/file-system.ts
786
848
  import { bold, gray } from "ansis";
787
849
  import { bundleRequire } from "bundle-require";
@@ -816,6 +878,14 @@ function logListItem(args) {
816
878
  }
817
879
 
818
880
  // packages/utils/src/lib/file-system.ts
881
+ async function fileExists(path) {
882
+ try {
883
+ const stats = await stat(path);
884
+ return stats.isFile();
885
+ } catch {
886
+ return false;
887
+ }
888
+ }
819
889
  async function ensureDirectoryExists(baseDir) {
820
890
  try {
821
891
  await mkdir(baseDir, { recursive: true });
@@ -870,17 +940,23 @@ import { MultiProgressBars } from "multi-progress-bars";
870
940
  import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md";
871
941
 
872
942
  // packages/utils/src/lib/reports/formatting.ts
873
- import { MarkdownDocument, md as md2 } from "build-md";
943
+ import {
944
+ MarkdownDocument,
945
+ md as md2
946
+ } from "build-md";
874
947
 
875
948
  // packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
876
949
  import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
877
950
 
878
951
  // packages/utils/src/lib/reports/generate-md-reports-diff.ts
879
952
  import {
880
- MarkdownDocument as MarkdownDocument4,
881
- md as md5
953
+ MarkdownDocument as MarkdownDocument5,
954
+ md as md6
882
955
  } from "build-md";
883
956
 
957
+ // packages/utils/src/lib/reports/generate-md-reports-diff-utils.ts
958
+ import { MarkdownDocument as MarkdownDocument4, md as md5 } from "build-md";
959
+
884
960
  // packages/utils/src/lib/reports/log-stdout-summary.ts
885
961
  import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
886
962
 
@@ -1038,9 +1114,14 @@ function getVulnerabilitiesTotal(summary) {
1038
1114
  return Object.values(summary).reduce((acc, value) => acc + value, 0);
1039
1115
  }
1040
1116
 
1117
+ // packages/plugin-js-packages/src/lib/package-managers/pnpm/utils.ts
1118
+ var filterOutWarnings = (output) => output.split("\n").filter((line) => !line.trim().startsWith("WARN")).join("\n");
1119
+
1041
1120
  // packages/plugin-js-packages/src/lib/package-managers/pnpm/audit-result.ts
1042
1121
  function pnpmToAuditResult(output) {
1043
- const pnpmResult = JSON.parse(output);
1122
+ const pnpmResult = JSON.parse(
1123
+ filterOutWarnings(output)
1124
+ );
1044
1125
  const vulnerabilities = Object.values(pnpmResult.advisories).map(
1045
1126
  ({
1046
1127
  module_name: name2,
@@ -1083,7 +1164,9 @@ function pnpmToDirectDependency(path) {
1083
1164
 
1084
1165
  // packages/plugin-js-packages/src/lib/package-managers/pnpm/outdated-result.ts
1085
1166
  function pnpmToOutdatedResult(output) {
1086
- const pnpmOutdated = JSON.parse(output);
1167
+ const pnpmOutdated = JSON.parse(
1168
+ filterOutWarnings(output)
1169
+ );
1087
1170
  return objectToEntries(pnpmOutdated).map(
1088
1171
  ([name2, { current, latest, dependencyType: type }]) => ({
1089
1172
  name: name2,
@@ -1369,7 +1452,7 @@ import { writeFile } from "node:fs/promises";
1369
1452
  import { dirname } from "node:path";
1370
1453
 
1371
1454
  // packages/plugin-js-packages/src/lib/runner/audit/transform.ts
1372
- import { md as md6 } from "build-md";
1455
+ import { md as md7 } from "build-md";
1373
1456
 
1374
1457
  // packages/plugin-js-packages/src/lib/runner/constants.ts
1375
1458
  import { join as join2 } from "node:path";
@@ -1382,7 +1465,7 @@ var PLUGIN_CONFIG_PATH = join2(
1382
1465
  );
1383
1466
 
1384
1467
  // packages/plugin-js-packages/src/lib/runner/outdated/transform.ts
1385
- import { md as md7 } from "build-md";
1468
+ import { md as md8 } from "build-md";
1386
1469
  import { clean, diff, neq } from "semver";
1387
1470
 
1388
1471
  // packages/plugin-js-packages/src/lib/runner/outdated/constants.ts
@@ -1408,28 +1491,113 @@ async function createRunnerConfig(scriptPath, config) {
1408
1491
  };
1409
1492
  }
1410
1493
 
1494
+ // packages/plugin-js-packages/src/lib/package-managers/derive-package-manager.ts
1495
+ import { readFile as readFile2 } from "node:fs/promises";
1496
+ import { join as join3 } from "node:path";
1497
+
1498
+ // packages/plugin-js-packages/src/lib/package-managers/derive-yarn.ts
1499
+ async function deriveYarnVersion() {
1500
+ const { stdout } = await executeProcess({
1501
+ command: "yarn",
1502
+ args: ["-v"]
1503
+ });
1504
+ const yarnVersion = Number.parseInt(stdout.toString().trim().at(0) ?? "", 10);
1505
+ if (yarnVersion >= 2) {
1506
+ return "yarn-modern";
1507
+ } else if (yarnVersion === 1) {
1508
+ return "yarn-classic";
1509
+ }
1510
+ return false;
1511
+ }
1512
+
1513
+ // packages/plugin-js-packages/src/lib/package-managers/derive-package-manager.ts
1514
+ async function derivePackageManagerInPackageJson(currentDir = process.cwd()) {
1515
+ if (await fileExists(join3(currentDir, "package.json"))) {
1516
+ const content = JSON.parse(
1517
+ (await readFile2(join3("package.json"))).toString()
1518
+ );
1519
+ const { packageManager: packageManagerData = "" } = content;
1520
+ const [manager = "", version2 = ""] = packageManagerData.split("@");
1521
+ if (manager === "npm") {
1522
+ return manager;
1523
+ }
1524
+ if (manager === "pnpm") {
1525
+ return manager;
1526
+ }
1527
+ if (manager === "yarn") {
1528
+ const majorVersion = Number(version2.split(".")[0]);
1529
+ return majorVersion > 1 ? "yarn-modern" : "yarn-classic";
1530
+ }
1531
+ }
1532
+ return false;
1533
+ }
1534
+ async function derivePackageManager(currentDir = process.cwd()) {
1535
+ const pkgManagerFromPackageJson = await derivePackageManagerInPackageJson(
1536
+ currentDir
1537
+ );
1538
+ if (pkgManagerFromPackageJson) {
1539
+ return pkgManagerFromPackageJson;
1540
+ }
1541
+ if (await fileExists(join3(currentDir, "package-lock.json"))) {
1542
+ return "npm";
1543
+ } else if (await fileExists(join3(currentDir, "pnpm-lock.yaml"))) {
1544
+ return "pnpm";
1545
+ } else if (await fileExists(join3(currentDir, "yarn.lock"))) {
1546
+ const yarnVersion = await deriveYarnVersion();
1547
+ if (yarnVersion) {
1548
+ return yarnVersion;
1549
+ }
1550
+ }
1551
+ throw new Error(
1552
+ "Could not detect package manager. Please provide it in the js-packages plugin config."
1553
+ );
1554
+ }
1555
+
1556
+ // packages/plugin-js-packages/src/lib/utils.ts
1557
+ async function normalizeConfig(config) {
1558
+ const jsPackagesPluginConfig = jsPackagesPluginConfigSchema.parse(
1559
+ config ?? {}
1560
+ );
1561
+ const {
1562
+ packageManager,
1563
+ dependencyGroups: dependencyGroupsCfg = [],
1564
+ checks: checksCfg = [],
1565
+ ...jsPackagesPluginConfigRest
1566
+ } = jsPackagesPluginConfig;
1567
+ const checks = [...new Set(checksCfg)];
1568
+ const depGroups = [...new Set(dependencyGroupsCfg)];
1569
+ const pm = packageManagers[packageManager ?? await derivePackageManager()];
1570
+ return {
1571
+ ...jsPackagesPluginConfigRest,
1572
+ packageManager: pm,
1573
+ checks,
1574
+ depGroups
1575
+ };
1576
+ }
1577
+
1411
1578
  // packages/plugin-js-packages/src/lib/js-packages-plugin.ts
1412
1579
  async function jsPackagesPlugin(config) {
1413
- const jsPackagesPluginConfig = jsPackagesPluginConfigSchema.parse(config);
1414
- const checks = [...new Set(jsPackagesPluginConfig.checks)];
1415
- const depGroups = [...new Set(jsPackagesPluginConfig.dependencyGroups)];
1416
- const id = jsPackagesPluginConfig.packageManager;
1417
- const pm = packageManagers[id];
1418
- const runnerScriptPath = join3(
1580
+ const { packageManager, checks, depGroups, ...jsPackagesPluginConfigRest } = await normalizeConfig(config);
1581
+ const runnerScriptPath = join4(
1419
1582
  fileURLToPath(dirname2(import.meta.url)),
1420
1583
  "bin.js"
1421
1584
  );
1422
1585
  return {
1423
1586
  slug: "js-packages",
1424
1587
  title: "JS Packages",
1425
- icon: pm.icon,
1588
+ icon: packageManager.icon,
1426
1589
  description: "This plugin runs audit to uncover vulnerabilities and lists outdated dependencies. It supports npm, yarn classic, yarn modern, and pnpm package managers.",
1427
- docsUrl: pm.docs.homepage,
1590
+ docsUrl: packageManager.docs.homepage,
1428
1591
  packageName: name,
1429
1592
  version,
1430
- audits: createAudits(id, checks, depGroups),
1431
- groups: createGroups(id, checks, depGroups),
1432
- runner: await createRunnerConfig(runnerScriptPath, jsPackagesPluginConfig)
1593
+ audits: createAudits(packageManager.slug, checks, depGroups),
1594
+ groups: createGroups(packageManager.slug, checks, depGroups),
1595
+ runner: await createRunnerConfig(runnerScriptPath, {
1596
+ ...jsPackagesPluginConfigRest,
1597
+ checks,
1598
+ packageManager: packageManager.slug,
1599
+ dependencyGroups: depGroups
1600
+ })
1433
1601
  };
1434
1602
  }
1435
1603
  function createGroups(id, checks, depGroups) {