Skip to content

Commit eaa79fd

Browse files
committed
fix: update types
1 parent 60afd22 commit eaa79fd

20 files changed

+816
-745
lines changed

packages/models/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,7 @@ export {
136136
export { uploadConfigSchema, type UploadConfig } from './lib/upload-config.js';
137137
export {
138138
artifactGenerationCommandSchema,
139-
pluginArtifactOptionsSchema,
139+
type Command,
140+
type CommandObject,
141+
type PluginArtifactOptions,
140142
} from './lib/configuration.js';

packages/models/src/lib/configuration.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
import { z } from 'zod';
22

3+
export const commandSchema = z
4+
.string({ description: 'Generate artifact files' })
5+
.min(1);
6+
export type Command = z.infer<typeof commandSchema>;
7+
8+
export const commandObjectSchema = z.object({
9+
command: z.string({ description: 'Generate artifact files' }).min(1),
10+
args: z.array(z.string()).optional(),
11+
});
12+
export type CommandObject = z.infer<typeof commandObjectSchema>;
313
/**
414
* Generic schema for a tool command configuration, reusable across plugins.
515
*/
616
export const artifactGenerationCommandSchema = z.union([
7-
z.string({ description: 'Generate artifact files' }).min(1),
8-
z.object({
9-
command: z.string({ description: 'Generate artifact files' }).min(1),
10-
args: z.array(z.string()).optional(),
11-
}),
17+
commandSchema,
18+
commandObjectSchema,
1219
]);
1320

21+
export type ArtifactGenerationCommand = z.infer<
22+
typeof artifactGenerationCommandSchema
23+
>;
24+
1425
export const pluginArtifactOptionsSchema = z.object({
1526
generateArtifactsCommand: artifactGenerationCommandSchema.optional(),
1627
artifactsPaths: z.union([z.string(), z.array(z.string()).min(1)]),

packages/plugin-bundle-stats/code-pushup.large-angular.config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import bundleStatsPlugin, { type GroupingRule } from './src';
2-
import { BlacklistEntry } from './src/lib/runner/types';
1+
import bundleStatsPlugin, {
2+
type BlacklistEntry,
3+
type GroupingRule,
4+
} from './src/index.js';
35

46
const sharedHint =
57
'Remove or conditionally load. Supported natively in modern browsers or replace with modern Angular architecture. See: https://blog.angular.io/zone-less-angular-explained-5fa951ce6f6e';
@@ -250,7 +252,7 @@ const config = {
250252
plugins: [
251253
await bundleStatsPlugin({
252254
bundler: 'esbuild',
253-
artefactsPath:
255+
artifactsPaths:
254256
'./packages/plugin-bundle-stats/mocks/fixtures/stats/angular-large.stats.json',
255257
selection: {
256258
excludeOutputs: ['**/*.map', '**/*.d.ts'], // Only exclude source maps as they're not part of runtime bundle
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { bundleStatsPlugin } from './lib/bundle-stats-plugin';
22

3-
export type { BundleStatsOptions, PluginOptions } from './lib/types.js';
3+
export type {
4+
BundleStatsAuditOptions as BundleStatsOptions,
5+
PluginOptions,
6+
} from './lib/types.js';
47
export type {
58
GroupingRule,
69
PatternList,
7-
BundleStatsConfig,
10+
BundleStatsConfig as BundleStatsConfig,
811
} from './lib/runner/types.js';
12+
export type { BlacklistEntry } from './lib/runner/audits/scoring.js';
913

1014
export default bundleStatsPlugin;
1115
export { DEFAULT_GROUPING, DEFAULT_PRUNING } from './lib/constants.js';

packages/plugin-bundle-stats/src/lib/bundle-stats-plugin.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,38 @@ import { createRequire } from 'node:module';
22
import type { Audit, PluginConfig } from '@code-pushup/models';
33
import { BUNDLE_STATS_PLUGIN_SLUG } from './constants.js';
44
import { normalizeBundleStatsOptions } from './normalize.js';
5-
import { bundleStatsRunner } from './runner/bundle-stats-runner.js';
6-
import { type BundleStatsConfig } from './runner/types.js';
5+
import {
6+
bundleStatsRunner,
7+
mergeAuditConfigs,
8+
} from './runner/bundle-stats-runner.js';
79
import type { PluginOptions } from './types.js';
810

911
const PKG = createRequire(import.meta.url)('../../package.json');
1012

1113
export async function bundleStatsPlugin(
1214
options: PluginOptions,
1315
): Promise<PluginConfig> {
14-
const { groups = [], audits, ...restOptions } = options;
16+
const {
17+
groups = [],
18+
bundler,
19+
artifactsPaths,
20+
generateArtifactsCommand,
21+
audits,
22+
...pluginOptions
23+
} = options;
1524

16-
const auditConfigs: BundleStatsConfig[] = audits.map(
17-
normalizeBundleStatsOptions,
25+
const bundleStatsConfigs = mergeAuditConfigs(
26+
audits.map(normalizeBundleStatsOptions),
27+
pluginOptions,
28+
);
29+
30+
const auditConfigs: Audit[] = bundleStatsConfigs.map(
31+
({ slug, title, description, ..._ }) =>
32+
({
33+
slug,
34+
title,
35+
description,
36+
}) satisfies Audit,
1837
);
1938

2039
return {
@@ -25,18 +44,13 @@ export async function bundleStatsPlugin(
2544
icon: 'folder-rules',
2645
description: 'Official Code PushUp Bundle Stats plugin.',
2746
docsUrl: 'https://npm.im/@code-pushup/bundle-stats-plugin',
28-
audits: auditConfigs.map(
29-
({ slug, description, title, ..._ }) =>
30-
({
31-
slug,
32-
title,
33-
description,
34-
}) satisfies Audit,
35-
),
36-
groups: groups ?? [],
47+
audits: auditConfigs,
48+
groups,
3749
runner: await bundleStatsRunner({
38-
...restOptions,
39-
audits: auditConfigs,
50+
bundler,
51+
artifactsPaths,
52+
generateArtifactsCommand,
53+
bundleStatsConfigs,
4054
}),
4155
};
4256
}

packages/plugin-bundle-stats/src/lib/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PruningOptions } from './runner/audits/details/tree.js';
1+
import type { PruningConfig } from './runner/audits/details/tree.js';
22
import type { GroupingRule } from './runner/types.js';
33

44
/**
@@ -356,7 +356,7 @@ export const DEFAULT_GROUPING: GroupingRule[] = [
356356
* Default pruning options for bundle stats analysis.
357357
* These settings control how the bundle tree is simplified and organized.
358358
*/
359-
export const DEFAULT_PRUNING: PruningOptions = {
359+
export const DEFAULT_PRUNING: PruningConfig = {
360360
maxChildren: 10,
361361
startDepth: 0,
362362
maxDepth: 4,

0 commit comments

Comments
 (0)