From 651c9c1af8a85c6c6cb53882263abcd595d1544f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 28 Nov 2026 13:02:37 +0100 Subject: [PATCH 1/4] ci: report sizes for affected plugins --- .github/workflows/size.yml | 9 + scripts/__tests__/size-report-package.test.ts | 110 +++++++++++- scripts/size-report-plugin-plan.mjs | 162 ++++++++++++++++++ scripts/size-report-plugins.mjs | 71 ++++++++ scripts/size-report.d.mts | 6 + scripts/size-report.mjs | 6 +- 6 files changed, 361 insertions(+), 3 deletions(-) create mode 100644 scripts/size-report-plugin-plan.mjs create mode 100644 scripts/size-report-plugins.mjs diff --git a/.github/workflows/size.yml b/.github/workflows/size.yml index 6a90047017..5448ff184f 100644 --- a/.github/workflows/size.yml +++ b/.github/workflows/size.yml @@ -35,6 +35,13 @@ jobs: - name: Setup toolchain uses: ./.github/actions/setup-node-pnpm + - name: Select affected plugins + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + node scripts/size-report-plugin-plan.mjs "$BASE_SHA" "$HEAD_SHA" /tmp/agent-device-plugin-size-plan + - name: Preserve report scripts run: | mkdir -p /tmp/agent-device-size-report @@ -65,6 +72,7 @@ jobs: fi node /tmp/agent-device-size-report/size-report.mjs \ --startup-runs 7 \ + --plugins /tmp/agent-device-plugin-size-plan/base.json \ --json /tmp/agent-device-size-base.json # Save immediately: the job-end dist belongs to the PR head, not the base. @@ -83,6 +91,7 @@ jobs: pnpm size \ --compare /tmp/agent-device-size-base.json \ --startup-runs 7 \ + --plugins /tmp/agent-device-plugin-size-plan/head.json \ --json .tmp/size-report.json \ --markdown .tmp/size-report.md cp /tmp/agent-device-size-base.json .tmp/size-report-base.json diff --git a/scripts/__tests__/size-report-package.test.ts b/scripts/__tests__/size-report-package.test.ts index 96b49bc6c1..b9ede3de30 100644 --- a/scripts/__tests__/size-report-package.test.ts +++ b/scripts/__tests__/size-report-package.test.ts @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { execFile } from 'node:child_process'; -import { mkdir, readFile, realpath, writeFile } from 'node:fs/promises'; -import { join } from 'node:path'; +import { mkdir, readFile, realpath, rm, writeFile } from 'node:fs/promises'; +import { dirname, join } from 'node:path'; import { promisify } from 'node:util'; import { test } from 'vitest'; import { mkdtempForTest } from '@agent-device/test-kit'; @@ -625,12 +625,118 @@ test('Markdown emphasizes total install size and startup without duplicate break assert.match(markdown, /\| Package \(download\) \| 90 B \| 100 B \| \+10 B \|/); assert.match(markdown, /\| CLI --help \| 25.0 ms \| 20.0 ms \| -5.0 ms \|/); assert.doesNotMatch(markdown, /JS raw|JS gzip|npm bundled|components|Top.*chunks|packed files/); + assert.doesNotMatch(markdown, /Affected plugins/); assert.match( formatMarkdown(current, null), /\| Installed \(including dependencies\) \| - \| 350 B \| - \|/, ); }); +test('Markdown compares measured plugins and labels added and removed packages', () => { + const core = { + npmPack: { tarballBytes: 100, unpackedBytes: 300 }, + cleanInstalled: { totalBytes: 350 }, + }; + const plugin = { + name: '@agent-device/one', + installedBytes: 60, + unpackedBytes: 30, + tarballBytes: 10, + }; + const markdown = formatMarkdown( + { + ...core, + plugins: [ + { ...plugin, installedBytes: 65 }, + { ...plugin, name: '@agent-device/new' }, + ], + }, + { ...core, plugins: [plugin, { ...plugin, name: '@agent-device/old' }] }, + ); + assert.match( + markdown, + /\| `@agent-device\/one` \| 60 B → 65 B \(\+5 B\) \| 30 B → 30 B \(0 B\) \| 10 B → 10 B \(0 B\) \|/, + ); + assert.match(markdown, /\| `@agent-device\/new` \| 60 B \(new\)/); + assert.match(markdown, /\| `@agent-device\/old` \| 60 B → removed/); +}); + +test('plugin plan follows changed build inputs on both compared revisions', async () => { + const cwd = await mkdtempForTest('size-plugin-plan-'); + const git = async (...args: string[]) => + (await execFileAsync('git', args, { cwd })).stdout.trim(); + const write = async (file: string, text: string) => { + await mkdir(dirname(join(cwd, file)), { recursive: true }); + await writeFile(join(cwd, file), text); + }; + const commit = async (subject: string) => { + await git('add', '-A'); + await git( + '-c', + 'user.name=Fixture', + '-c', + 'user.email=fixture@example.test', + 'commit', + '-qm', + subject, + ); + return await git('rev-parse', 'HEAD'); + }; + const plan = async (base: string, head: string) => { + const output = join(cwd, '.git', 'plan'); + await execFileAsync( + process.execPath, + [join(import.meta.dirname, '../size-report-plugin-plan.mjs'), base, head, output], + { cwd }, + ); + const readSide = async (side: string) => + (JSON.parse(await readFile(join(output, `${side}.json`), 'utf8')) as { name: string }[]).map( + ({ name }) => name, + ); + return { base: await readSide('base'), head: await readSide('head') }; + }; + const one = '@agent-device/one'; + const two = '@agent-device/two'; + const dep = '@agent-device/build-piece'; + await git('init', '-q'); + await write( + 'packages/one/package.json', + JSON.stringify({ name: one, 'agent-device': {}, devDependencies: { [dep]: 'workspace:*' } }), + ); + await write('packages/two/package.json', JSON.stringify({ name: two, agentDevicePlugin: {} })); + await write('packages/build-piece/package.json', JSON.stringify({ name: dep, private: true })); + await write('pnpm-lock.yaml', 'importers:\n packages/one: {}\n packages/two: {}\n'); + const base = await commit('base'); + + await write('src/cli.ts', 'export {};'); + await write('packages/one/src/only.test.ts', 'export {};'); + const unrelated = await commit('unrelated CLI and plugin test'); + assert.deepEqual(await plan(base, unrelated), { base: [], head: [] }); + + await write('packages/build-piece/src/index.ts', 'export {};'); + const dependency = await commit('plugin dependency'); + assert.deepEqual(await plan(unrelated, dependency), { base: [one], head: [one] }); + + await write( + 'pnpm-lock.yaml', + 'importers:\n packages/one: {}\n packages/two:\n dependencies:\n external-lib: {specifier: "^1.0.0", version: 1.0.0}\n', + ); + const lock = await commit('one package changes its external dependency'); + assert.deepEqual(await plan(dependency, lock), { base: [two], head: [two] }); + + await write('bundler/two/build.mjs', 'export {};'); + const bundler = await commit('one plugin changes its build'); + assert.deepEqual(await plan(lock, bundler), { base: [two], head: [two] }); + + await write('tsconfig.lib.json', '{}'); + const shared = await commit('shared TypeScript configuration'); + assert.deepEqual(await plan(bundler, shared), { base: [one, two], head: [one, two] }); + + await rm(join(cwd, 'packages/one'), { recursive: true }); + const removed = await commit('remove plugin'); + assert.deepEqual(await plan(shared, removed), { base: [one], head: [] }); +}); + test('base measurement uses the measured revision package asset policy', async () => { const workflow = await readFile( join(import.meta.dirname, '../../.github/workflows/size.yml'), diff --git a/scripts/size-report-plugin-plan.mjs b/scripts/size-report-plugin-plan.mjs new file mode 100644 index 0000000000..f8bc337359 --- /dev/null +++ b/scripts/size-report-plugin-plan.mjs @@ -0,0 +1,162 @@ +import { execFileSync } from 'node:child_process'; +import fs from 'node:fs'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; +import { isDeepStrictEqual } from 'node:util'; +import { parse } from 'yaml'; + +const MANIFEST = /^packages\/[^/]+\/package\.json$/; +const TEST_PATH = /(?:^|\/)(?:__tests__|test|tests)\/|\.(?:test|spec|fixtures)\.[cm]?[jt]sx?$/; +const SHARED_BUILD_INPUT = + /^(?:package\.json|pnpm-workspace\.yaml|\.npmrc|LICENSE|tsconfig[^/]*\.json|scripts\/lib\/bundled-license-notices\.ts)$/; +const ROOT_PLUGIN_INPUT = /^src\/sdk\//; +const BUILD_TOOLS = ['tsdown', 'typescript', '@typescript/native-preview', 'rollup-plugin-license']; + +function git(...args) { + return execFileSync('git', args, { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 }); +} + +function workspaceAt(ref) { + const files = git('ls-tree', '-r', '--name-only', '-z', ref, '--', 'packages').split('\0'); + return files + .filter((file) => MANIFEST.test(file)) + .map((file) => ({ + directory: path.posix.dirname(file), + manifest: JSON.parse(git('show', `${ref}:${file}`)), + })); +} + +function isPublishedPlugin({ manifest }) { + return ( + manifest.private !== true && Boolean(manifest.agentDevicePlugin ?? manifest['agent-device']) + ); +} + +function workspaceClosure(plugin, byName) { + const seen = new Set(); + const pending = [plugin]; + while (pending.length > 0) { + const pkg = pending.pop(); + if (seen.has(pkg.directory)) continue; + seen.add(pkg.directory); + const { dependencies, optionalDependencies, peerDependencies, devDependencies } = pkg.manifest; + for (const [name, source] of Object.entries({ + ...dependencies, + ...optionalDependencies, + ...peerDependencies, + ...devDependencies, + })) { + if (!source.startsWith('workspace:') || name === '@agent-device/test-kit') continue; + const dependency = byName.get(name); + if (dependency) pending.push(dependency); + } + } + return seen; +} + +function changedLockInputs(base, head) { + const { + importers: before = {}, + packages: beforePackages = {}, + snapshots: beforeSnapshots = {}, + ...baseSettings + } = base; + const { + importers: after = {}, + packages: afterPackages = {}, + snapshots: afterSnapshots = {}, + ...headSettings + } = head; + const rootToolsChanged = BUILD_TOOLS.some( + (name) => + !isDeepStrictEqual(before['.']?.devDependencies?.[name], after['.']?.devDependencies?.[name]), + ); + // A lock entry can keep its identity while its transitive resolutions or integrity change. + const shared = + !isDeepStrictEqual(baseSettings, headSettings) || + rootToolsChanged || + changedExistingEntries(beforePackages, afterPackages) || + changedExistingEntries(beforeSnapshots, afterSnapshots); + const directories = new Set( + [...new Set([...Object.keys(before), ...Object.keys(after)])].filter( + (directory) => directory !== '.' && !isDeepStrictEqual(before[directory], after[directory]), + ), + ); + return { shared, directories }; +} + +function changedExistingEntries(before, after) { + return Object.keys(before).some( + (key) => Object.hasOwn(after, key) && !isDeepStrictEqual(before[key], after[key]), + ); +} + +function buildOwner(file) { + if (file === 'scripts/lib/jpeg-decoder-only.ts') return 'maestro'; + return /^(?:build|bundler)\/([^/]+)(?:\/|$)/.exec(file)?.[1]; +} + +function affectedPlugins(workspace, files, lock, knownBuildOwners) { + const byName = new Map(workspace.map((pkg) => [pkg.manifest.name, pkg])); + const shared = + lock.shared || + files.some((file) => { + if (SHARED_BUILD_INPUT.test(file) || ROOT_PLUGIN_INPUT.test(file)) return true; + const owner = buildOwner(file); + return owner !== undefined && !knownBuildOwners.has(owner); + }); + return workspace.filter(isPublishedPlugin).filter((pkg) => { + if (shared) return true; + const closure = workspaceClosure(pkg, byName); + if ([...closure].some((directory) => lock.directories.has(directory))) return true; + const owner = pkg.manifest.name.split('/').at(-1); + const sourcePrefixes = [...closure].map((directory) => `${directory}/`); + return files.some( + (file) => + buildOwner(file) === owner || sourcePrefixes.some((prefix) => file.startsWith(prefix)), + ); + }); +} + +function plan(base, head, files, lock) { + const knownBuildOwners = new Set( + [...base, ...head].filter(isPublishedPlugin).map((pkg) => pkg.manifest.name.split('/').at(-1)), + ); + // The same Maestro build inputs can feed the core on branches where it is built in. + knownBuildOwners.add('maestro'); + const productionFiles = files.filter((file) => !TEST_PATH.test(file)); + const changed = new Set( + [ + ...affectedPlugins(base, productionFiles, lock, knownBuildOwners), + ...affectedPlugins(head, productionFiles, lock, knownBuildOwners), + ].map((pkg) => pkg.manifest.name), + ); + const side = (workspace) => + workspace + .filter(isPublishedPlugin) + .filter((pkg) => changed.has(pkg.manifest.name)) + .map(({ directory, manifest }) => ({ directory, name: manifest.name })); + return { base: side(base), head: side(head) }; +} + +if (process.argv[1] && pathToFileURL(path.resolve(process.argv[1])).href === import.meta.url) { + const [base, head, output] = process.argv.slice(2); + if (!base || !head || !output) { + throw new Error('Usage: node scripts/size-report-plugin-plan.mjs '); + } + const files = git('diff', '--name-only', '--no-renames', '-z', base, head, '--').split('\0'); + const lock = files.includes('pnpm-lock.yaml') + ? changedLockInputs( + parse(git('show', `${base}:pnpm-lock.yaml`)), + parse(git('show', `${head}:pnpm-lock.yaml`)), + ) + : { shared: false, directories: new Set() }; + const plugins = plan(workspaceAt(base), workspaceAt(head), files, lock); + fs.mkdirSync(output, { recursive: true }); + for (const [side, entries] of Object.entries(plugins)) { + fs.writeFileSync(path.join(output, `${side}.json`), JSON.stringify(entries)); + process.stdout.write( + `Plugin sizes (${side}): ${entries.map((entry) => entry.name).join(', ') || 'none'}\n`, + ); + } +} diff --git a/scripts/size-report-plugins.mjs b/scripts/size-report-plugins.mjs new file mode 100644 index 0000000000..c655c7d8b5 --- /dev/null +++ b/scripts/size-report-plugins.mjs @@ -0,0 +1,71 @@ +import { execFileSync } from 'node:child_process'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import { formatBytes, formatDiff } from './size-report-format.mjs'; +import { measureCleanInstalledPackage, measureDirectory } from './size-report-install.mjs'; + +export function measurePluginSizes(root, planPath) { + const plugins = JSON.parse(fs.readFileSync(planPath, 'utf8')); + return plugins.map((plugin) => measurePlugin(root, plugin)); +} + +function measurePlugin(root, { name, directory }) { + const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-plugin-size-')); + try { + const tarball = path.join(scratch, 'plugin.tgz'); + execFileSync('pnpm', ['pack', '--out', tarball], { + cwd: path.join(root, directory), + stdio: ['ignore', 'ignore', 'inherit'], + }); + execFileSync('tar', ['-xzf', tarball, '-C', scratch]); + const packageDir = path.join(scratch, 'package'); + const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')); + if (manifest.name !== name) throw new Error(`Expected to pack ${name}, got ${manifest.name}.`); + const unpackedBytes = measureDirectory(packageDir).packageBytes; + const hasDependencies = + Object.keys({ + ...manifest.dependencies, + ...manifest.optionalDependencies, + ...manifest.peerDependencies, + }).length > 0; + return { + name, + unpackedBytes, + tarballBytes: fs.statSync(tarball).size, + installedBytes: + hasDependencies || manifest.bin + ? measureCleanInstalledPackage(tarball, name).totalBytes + : unpackedBytes, + }; + } finally { + fs.rmSync(scratch, { recursive: true, force: true }); + } +} + +export function formatPluginSizes(plugins = [], basePlugins = []) { + const current = new Map(plugins.map((plugin) => [plugin.name, plugin])); + const base = new Map(basePlugins.map((plugin) => [plugin.name, plugin])); + const names = [...new Set([...current.keys(), ...base.keys()])].sort(); + if (names.length === 0) return ''; + const rows = names.map((name) => { + const before = base.get(name); + const after = current.get(name); + const metrics = ['installedBytes', 'unpackedBytes', 'tarballBytes']; + const cells = metrics.map((metric) => formatPluginMetric(before?.[metric], after?.[metric])); + return `| \`${name}\` | ${cells.join(' | ')} |`; + }); + return `### Affected plugins + +| Plugin | Installed (including dependencies) | Unpacked | Download | +|---|---:|---:|---:| +${rows.join('\n')} + +`; +} + +function formatPluginMetric(base, current) { + if (current === undefined) return `${formatBytes(base)} → removed`; + if (base === undefined) return `${formatBytes(current)} (new)`; + return `${formatBytes(base)} → ${formatBytes(current)} (${formatDiff(base, current)})`; +} diff --git a/scripts/size-report.d.mts b/scripts/size-report.d.mts index 8fc1d1d0ac..7315a028ac 100644 --- a/scripts/size-report.d.mts +++ b/scripts/size-report.d.mts @@ -3,6 +3,12 @@ export type SizeReport = Readonly<{ npmPack: Readonly<{ tarballBytes: number; unpackedBytes: number }>; cleanInstalled: Readonly<{ totalBytes: number }>; + plugins?: readonly Readonly<{ + name: string; + unpackedBytes: number; + tarballBytes: number; + installedBytes: number; + }>[]; startup?: Readonly<{ runs: number; benchmarks: readonly Readonly<{ name: string; medianMs: number }>[]; diff --git a/scripts/size-report.mjs b/scripts/size-report.mjs index 2104885707..fcc0b15842 100644 --- a/scripts/size-report.mjs +++ b/scripts/size-report.mjs @@ -9,6 +9,7 @@ import { formatBytes, formatDiff, formatMaybeBytes } from './size-report-format. import { collectNpmPack } from './size-report-package.mjs'; import { measureCleanInstalledPackage } from './size-report-install.mjs'; import { preparePublishAssets } from './prepare-publish-assets.mjs'; +import { formatPluginSizes, measurePluginSizes } from './size-report-plugins.mjs'; const COMMENT_MARKER = ''; const GITHUB_REQUEST_ATTEMPTS = 4; @@ -23,6 +24,7 @@ const VALUE_ARGS = new Map([ ['--post-comment', 'postComment'], ['--pr', 'pr'], ['--startup-runs', 'startupRuns'], + ['--plugins', 'plugins'], ]); const STARTUP_BENCHMARKS = [ @@ -46,6 +48,7 @@ async function run() { const report = collectReport(cwd, { startupRuns: parseNonNegativeInteger(args.startupRuns ?? '0', '--startup-runs'), }); + if (args.plugins) report.plugins = measurePluginSizes(cwd, args.plugins); const baseReport = args.compare ? JSON.parse(fs.readFileSync(args.compare, 'utf8')) : null; if (args.json) { @@ -96,6 +99,7 @@ Options: --markdown Write the markdown report. --compare Compare against a previously written JSON report. --startup-runs Measure startup medians for side-effect-free CLI commands. + --plugins Measure the plugin packages selected in this JSON plan. --post-comment Post or update the markdown report on the current PR. --pr Pull request number for --post-comment. `); @@ -223,7 +227,7 @@ function formatMarkdown(report, baseReport) { |---|---:|---:|---:| ${rows.join('\n')} -${formatStartupBenchmarks(report.startup, baseReport?.startup)}`; +${formatStartupBenchmarks(report.startup, baseReport?.startup)}${formatPluginSizes(report.plugins, baseReport?.plugins)}`; } function metricRow(label, base, current) { From 1ee1f281fd6965a8cfdede2c940b7e712cac3780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 28 Nov 2026 13:08:13 +0100 Subject: [PATCH 2/4] fix(ci): measure clean plugin installs consistently --- scripts/__tests__/size-report-package.test.ts | 147 +++++++++--------- scripts/size-report-plugin-plan.d.mts | 13 ++ scripts/size-report-plugin-plan.mjs | 19 ++- scripts/size-report-plugins.mjs | 13 +- scripts/size-report.mjs | 4 +- 5 files changed, 101 insertions(+), 95 deletions(-) create mode 100644 scripts/size-report-plugin-plan.d.mts diff --git a/scripts/__tests__/size-report-package.test.ts b/scripts/__tests__/size-report-package.test.ts index b9ede3de30..367a8fb79f 100644 --- a/scripts/__tests__/size-report-package.test.ts +++ b/scripts/__tests__/size-report-package.test.ts @@ -1,11 +1,12 @@ import assert from 'node:assert/strict'; import { execFile } from 'node:child_process'; -import { mkdir, readFile, realpath, rm, writeFile } from 'node:fs/promises'; -import { dirname, join } from 'node:path'; +import { mkdir, readFile, realpath, writeFile } from 'node:fs/promises'; +import { join } from 'node:path'; import { promisify } from 'node:util'; import { test } from 'vitest'; import { mkdtempForTest } from '@agent-device/test-kit'; import { formatMarkdown } from '../size-report.mjs'; +import { planPluginSizes } from '../size-report-plugin-plan.mjs'; import { assertBundledLicenseNotices, assertPublishPackageContents, @@ -659,82 +660,78 @@ test('Markdown compares measured plugins and labels added and removed packages', ); assert.match(markdown, /\| `@agent-device\/new` \| 60 B \(new\)/); assert.match(markdown, /\| `@agent-device\/old` \| 60 B → removed/); + assert.doesNotMatch(formatMarkdown(core, { ...core, plugins: [plugin] }), /Affected plugins/); + assert.match( + formatMarkdown({ ...core, plugins: [] }, { ...core, plugins: [plugin] }), + /\| `@agent-device\/one` \| 60 B → removed/, + ); }); -test('plugin plan follows changed build inputs on both compared revisions', async () => { - const cwd = await mkdtempForTest('size-plugin-plan-'); - const git = async (...args: string[]) => - (await execFileAsync('git', args, { cwd })).stdout.trim(); - const write = async (file: string, text: string) => { - await mkdir(dirname(join(cwd, file)), { recursive: true }); - await writeFile(join(cwd, file), text); - }; - const commit = async (subject: string) => { - await git('add', '-A'); - await git( - '-c', - 'user.name=Fixture', - '-c', - 'user.email=fixture@example.test', - 'commit', - '-qm', - subject, - ); - return await git('rev-parse', 'HEAD'); - }; - const plan = async (base: string, head: string) => { - const output = join(cwd, '.git', 'plan'); - await execFileAsync( - process.execPath, - [join(import.meta.dirname, '../size-report-plugin-plan.mjs'), base, head, output], - { cwd }, - ); - const readSide = async (side: string) => - (JSON.parse(await readFile(join(output, `${side}.json`), 'utf8')) as { name: string }[]).map( - ({ name }) => name, - ); - return { base: await readSide('base'), head: await readSide('head') }; +const one = { + directory: 'packages/one', + manifest: { + name: '@agent-device/one', + 'agent-device': {}, + devDependencies: { '@agent-device/build-piece': 'workspace:*' }, + }, +}; +const two = { + directory: 'packages/two', + manifest: { name: '@agent-device/two', agentDevicePlugin: {} }, +}; +const buildPiece = { + directory: 'packages/build-piece', + manifest: { name: '@agent-device/build-piece', private: true }, +}; +const workspace = [one, two, buildPiece]; +const oneEntry = { directory: one.directory, name: one.manifest.name }; +const twoEntry = { directory: two.directory, name: two.manifest.name }; + +test('plugin plan follows changed build inputs without selecting unrelated plugins', () => { + assert.deepEqual( + planPluginSizes(workspace, workspace, ['src/cli.ts', 'packages/one/src/only.test.ts']), + { base: [], head: [] }, + ); + assert.deepEqual(planPluginSizes(workspace, workspace, ['packages/build-piece/src/index.ts']), { + base: [oneEntry], + head: [oneEntry], + }); + assert.deepEqual(planPluginSizes(workspace, workspace, ['bundler/two/build.mjs']), { + base: [twoEntry], + head: [twoEntry], + }); + assert.deepEqual(planPluginSizes(workspace, workspace, ['tsconfig.lib.json']), { + base: [oneEntry, twoEntry], + head: [oneEntry, twoEntry], + }); +}); + +test('plugin plan follows a changed lockfile importer', () => { + const base = { importers: { 'packages/one': {}, 'packages/two': {} } }; + const head = { + importers: { + ...base.importers, + 'packages/two': { + dependencies: { 'external-lib': { specifier: '^1.0.0', version: '1.0.0' } }, + }, + }, }; - const one = '@agent-device/one'; - const two = '@agent-device/two'; - const dep = '@agent-device/build-piece'; - await git('init', '-q'); - await write( - 'packages/one/package.json', - JSON.stringify({ name: one, 'agent-device': {}, devDependencies: { [dep]: 'workspace:*' } }), - ); - await write('packages/two/package.json', JSON.stringify({ name: two, agentDevicePlugin: {} })); - await write('packages/build-piece/package.json', JSON.stringify({ name: dep, private: true })); - await write('pnpm-lock.yaml', 'importers:\n packages/one: {}\n packages/two: {}\n'); - const base = await commit('base'); - - await write('src/cli.ts', 'export {};'); - await write('packages/one/src/only.test.ts', 'export {};'); - const unrelated = await commit('unrelated CLI and plugin test'); - assert.deepEqual(await plan(base, unrelated), { base: [], head: [] }); - - await write('packages/build-piece/src/index.ts', 'export {};'); - const dependency = await commit('plugin dependency'); - assert.deepEqual(await plan(unrelated, dependency), { base: [one], head: [one] }); - - await write( - 'pnpm-lock.yaml', - 'importers:\n packages/one: {}\n packages/two:\n dependencies:\n external-lib: {specifier: "^1.0.0", version: 1.0.0}\n', - ); - const lock = await commit('one package changes its external dependency'); - assert.deepEqual(await plan(dependency, lock), { base: [two], head: [two] }); - - await write('bundler/two/build.mjs', 'export {};'); - const bundler = await commit('one plugin changes its build'); - assert.deepEqual(await plan(lock, bundler), { base: [two], head: [two] }); - - await write('tsconfig.lib.json', '{}'); - const shared = await commit('shared TypeScript configuration'); - assert.deepEqual(await plan(bundler, shared), { base: [one, two], head: [one, two] }); - - await rm(join(cwd, 'packages/one'), { recursive: true }); - const removed = await commit('remove plugin'); - assert.deepEqual(await plan(shared, removed), { base: [one], head: [] }); + assert.deepEqual(planPluginSizes(workspace, workspace, ['pnpm-lock.yaml'], { base, head }), { + base: [twoEntry], + head: [twoEntry], + }); +}); + +test('plugin plans measure added and removed plugins only where they exist', () => { + const other = [two, buildPiece]; + assert.deepEqual(planPluginSizes(other, workspace, ['packages/one/package.json']), { + base: [], + head: [oneEntry], + }); + assert.deepEqual(planPluginSizes(workspace, other, ['packages/one/package.json']), { + base: [oneEntry], + head: [], + }); }); test('base measurement uses the measured revision package asset policy', async () => { diff --git a/scripts/size-report-plugin-plan.d.mts b/scripts/size-report-plugin-plan.d.mts new file mode 100644 index 0000000000..7809d92c7f --- /dev/null +++ b/scripts/size-report-plugin-plan.d.mts @@ -0,0 +1,13 @@ +type WorkspacePackage = Readonly<{ + directory: string; + manifest: Readonly<{ name: string } & Record>; +}>; + +type PluginPlanEntry = Readonly<{ directory: string; name: string }>; + +export function planPluginSizes( + base: readonly WorkspacePackage[], + head: readonly WorkspacePackage[], + files: readonly string[], + lockfiles?: { base: Record; head: Record }, +): { base: PluginPlanEntry[]; head: PluginPlanEntry[] }; diff --git a/scripts/size-report-plugin-plan.mjs b/scripts/size-report-plugin-plan.mjs index f8bc337359..b0decbee90 100644 --- a/scripts/size-report-plugin-plan.mjs +++ b/scripts/size-report-plugin-plan.mjs @@ -118,7 +118,10 @@ function affectedPlugins(workspace, files, lock, knownBuildOwners) { }); } -function plan(base, head, files, lock) { +export function planPluginSizes(base, head, files, lockfiles) { + const lock = lockfiles + ? changedLockInputs(lockfiles.base, lockfiles.head) + : { shared: false, directories: new Set() }; const knownBuildOwners = new Set( [...base, ...head].filter(isPublishedPlugin).map((pkg) => pkg.manifest.name.split('/').at(-1)), ); @@ -145,13 +148,13 @@ if (process.argv[1] && pathToFileURL(path.resolve(process.argv[1])).href === imp throw new Error('Usage: node scripts/size-report-plugin-plan.mjs '); } const files = git('diff', '--name-only', '--no-renames', '-z', base, head, '--').split('\0'); - const lock = files.includes('pnpm-lock.yaml') - ? changedLockInputs( - parse(git('show', `${base}:pnpm-lock.yaml`)), - parse(git('show', `${head}:pnpm-lock.yaml`)), - ) - : { shared: false, directories: new Set() }; - const plugins = plan(workspaceAt(base), workspaceAt(head), files, lock); + const lockfiles = files.includes('pnpm-lock.yaml') + ? { + base: parse(git('show', `${base}:pnpm-lock.yaml`)), + head: parse(git('show', `${head}:pnpm-lock.yaml`)), + } + : undefined; + const plugins = planPluginSizes(workspaceAt(base), workspaceAt(head), files, lockfiles); fs.mkdirSync(output, { recursive: true }); for (const [side, entries] of Object.entries(plugins)) { fs.writeFileSync(path.join(output, `${side}.json`), JSON.stringify(entries)); diff --git a/scripts/size-report-plugins.mjs b/scripts/size-report-plugins.mjs index c655c7d8b5..9a0e59a443 100644 --- a/scripts/size-report-plugins.mjs +++ b/scripts/size-report-plugins.mjs @@ -23,27 +23,18 @@ function measurePlugin(root, { name, directory }) { const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')); if (manifest.name !== name) throw new Error(`Expected to pack ${name}, got ${manifest.name}.`); const unpackedBytes = measureDirectory(packageDir).packageBytes; - const hasDependencies = - Object.keys({ - ...manifest.dependencies, - ...manifest.optionalDependencies, - ...manifest.peerDependencies, - }).length > 0; return { name, unpackedBytes, tarballBytes: fs.statSync(tarball).size, - installedBytes: - hasDependencies || manifest.bin - ? measureCleanInstalledPackage(tarball, name).totalBytes - : unpackedBytes, + installedBytes: measureCleanInstalledPackage(tarball, name).totalBytes, }; } finally { fs.rmSync(scratch, { recursive: true, force: true }); } } -export function formatPluginSizes(plugins = [], basePlugins = []) { +export function formatPluginSizes(plugins, basePlugins = []) { const current = new Map(plugins.map((plugin) => [plugin.name, plugin])); const base = new Map(basePlugins.map((plugin) => [plugin.name, plugin])); const names = [...new Set([...current.keys(), ...base.keys()])].sort(); diff --git a/scripts/size-report.mjs b/scripts/size-report.mjs index fcc0b15842..473b894f60 100644 --- a/scripts/size-report.mjs +++ b/scripts/size-report.mjs @@ -207,6 +207,8 @@ function walk(root) { } function formatMarkdown(report, baseReport) { + const pluginSizes = + report.plugins === undefined ? '' : formatPluginSizes(report.plugins, baseReport?.plugins); const rows = [ metricRow( 'Installed (including dependencies)', @@ -227,7 +229,7 @@ function formatMarkdown(report, baseReport) { |---|---:|---:|---:| ${rows.join('\n')} -${formatStartupBenchmarks(report.startup, baseReport?.startup)}${formatPluginSizes(report.plugins, baseReport?.plugins)}`; +${formatStartupBenchmarks(report.startup, baseReport?.startup)}${pluginSizes}`; } function metricRow(label, base, current) { From 993e616bdca06a14f738134027bacc8822c2090b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 28 Nov 2026 13:20:59 +0100 Subject: [PATCH 3/4] fix(ci): scope plugin size selection to the PR diff --- scripts/__tests__/size-report-package.test.ts | 53 +++++++++++++++++++ scripts/size-report-install.d.mts | 1 + scripts/size-report-install.mjs | 4 +- scripts/size-report-plugin-plan.d.mts | 1 + scripts/size-report-plugin-plan.mjs | 36 +++++++++---- scripts/size-report-plugins.mjs | 28 ++++++++-- 6 files changed, 106 insertions(+), 17 deletions(-) diff --git a/scripts/__tests__/size-report-package.test.ts b/scripts/__tests__/size-report-package.test.ts index 367a8fb79f..cfd7142465 100644 --- a/scripts/__tests__/size-report-package.test.ts +++ b/scripts/__tests__/size-report-package.test.ts @@ -734,6 +734,59 @@ test('plugin plans measure added and removed plugins only where they exist', () }); }); +test('plugin selection ignores upstream-only changes in a diverged checkout', async () => { + const cwd = await mkdtempForTest('size-plugin-merge-base-'); + const git = async (...args: string[]) => + ( + await execFileAsync( + 'git', + [ + '-c', + 'user.name=Fixture', + '-c', + 'user.email=fixture@example.com', + '-c', + 'commit.gpgsign=false', + '-c', + 'core.hooksPath=/dev/null', + ...args, + ], + { cwd }, + ) + ).stdout.trim(); + await git('init', '-q'); + for (const { directory, manifest } of workspace) { + await mkdir(join(cwd, directory), { recursive: true }); + await writeFile(join(cwd, directory, 'package.json'), JSON.stringify(manifest)); + } + const lock = join(cwd, 'pnpm-lock.yaml'); + await writeFile(lock, 'settings: {excludeLinksFromLockfile: false}\n'); + await git('add', '.'); + await git('commit', '-qm', 'fork point'); + const fork = await git('rev-parse', 'HEAD'); + await git('mv', two.directory, 'packages/moved-two'); + await writeFile(lock, 'settings: {excludeLinksFromLockfile: true}\n'); + await git('commit', '-qam', 'upstream only'); + const base = await git('rev-parse', 'HEAD'); + await git('checkout', '-q', '--detach', fork); + await writeFile( + lock, + 'settings: {excludeLinksFromLockfile: false}\nimporters: {packages/two: {}}\n', + ); + await git('commit', '-qam', 'PR change'); + + const output = join(cwd, 'plan'); + await execFileAsync( + process.execPath, + [join(import.meta.dirname, '../size-report-plugin-plan.mjs'), base, 'HEAD', output], + { cwd }, + ); + assert.deepEqual(JSON.parse(await readFile(join(output, 'base.json'), 'utf8')), [ + { ...twoEntry, directory: 'packages/moved-two' }, + ]); + assert.deepEqual(JSON.parse(await readFile(join(output, 'head.json'), 'utf8')), [twoEntry]); +}); + test('base measurement uses the measured revision package asset policy', async () => { const workflow = await readFile( join(import.meta.dirname, '../../.github/workflows/size.yml'), diff --git a/scripts/size-report-install.d.mts b/scripts/size-report-install.d.mts index 0e7aa19f56..41a39a0b7f 100644 --- a/scripts/size-report-install.d.mts +++ b/scripts/size-report-install.d.mts @@ -5,6 +5,7 @@ export type DirectoryMeasurement = { packageBytes: number; files: number }; export function measureCleanInstalledPackage( tarballPath: string, packageName: string, + timeout?: number, ): DirectoryMeasurement & { totalBytes: number }; export function assertInstalledSnapshotBridge(packageDir: string): void; diff --git a/scripts/size-report-install.mjs b/scripts/size-report-install.mjs index 9b56ff2ae6..b73f51b1de 100644 --- a/scripts/size-report-install.mjs +++ b/scripts/size-report-install.mjs @@ -4,7 +4,7 @@ import os from 'node:os'; import path from 'node:path'; import { assertSnapshotBridgeAssets, SNAPSHOT_BRIDGE_ASSET_PATHS } from './size-report-package.mjs'; -export function measureCleanInstalledPackage(tarballPath, packageName) { +export function measureCleanInstalledPackage(tarballPath, packageName, timeout = 5 * 60_000) { const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-size-install-')); const consumerDir = path.join(workDir, 'consumer'); const npmCache = path.join(workDir, 'npm-cache'); @@ -27,7 +27,7 @@ export function measureCleanInstalledPackage(tarballPath, packageName) { cwd: consumerDir, env: { ...process.env, npm_config_cache: npmCache }, stdio: ['ignore', 'ignore', 'inherit'], - timeout: 5 * 60 * 1000, + timeout, }, ); const packageDir = path.join(consumerDir, 'node_modules', packageName); diff --git a/scripts/size-report-plugin-plan.d.mts b/scripts/size-report-plugin-plan.d.mts index 7809d92c7f..ebebe39b03 100644 --- a/scripts/size-report-plugin-plan.d.mts +++ b/scripts/size-report-plugin-plan.d.mts @@ -10,4 +10,5 @@ export function planPluginSizes( head: readonly WorkspacePackage[], files: readonly string[], lockfiles?: { base: Record; head: Record }, + comparisonBase?: readonly WorkspacePackage[], ): { base: PluginPlanEntry[]; head: PluginPlanEntry[] }; diff --git a/scripts/size-report-plugin-plan.mjs b/scripts/size-report-plugin-plan.mjs index b0decbee90..ae72f244b9 100644 --- a/scripts/size-report-plugin-plan.mjs +++ b/scripts/size-report-plugin-plan.mjs @@ -118,7 +118,7 @@ function affectedPlugins(workspace, files, lock, knownBuildOwners) { }); } -export function planPluginSizes(base, head, files, lockfiles) { +function affectedPluginNames(base, head, files, lockfiles) { const lock = lockfiles ? changedLockInputs(lockfiles.base, lockfiles.head) : { shared: false, directories: new Set() }; @@ -128,18 +128,24 @@ export function planPluginSizes(base, head, files, lockfiles) { // The same Maestro build inputs can feed the core on branches where it is built in. knownBuildOwners.add('maestro'); const productionFiles = files.filter((file) => !TEST_PATH.test(file)); - const changed = new Set( + return new Set( [ ...affectedPlugins(base, productionFiles, lock, knownBuildOwners), ...affectedPlugins(head, productionFiles, lock, knownBuildOwners), ].map((pkg) => pkg.manifest.name), ); - const side = (workspace) => - workspace - .filter(isPublishedPlugin) - .filter((pkg) => changed.has(pkg.manifest.name)) - .map(({ directory, manifest }) => ({ directory, name: manifest.name })); - return { base: side(base), head: side(head) }; +} + +function measurementEntries(workspace, names) { + return workspace + .filter(isPublishedPlugin) + .filter((pkg) => names.has(pkg.manifest.name)) + .map(({ directory, manifest }) => ({ directory, name: manifest.name })); +} + +export function planPluginSizes(base, head, files, lockfiles, comparisonBase = base) { + const names = affectedPluginNames(base, head, files, lockfiles); + return { base: measurementEntries(comparisonBase, names), head: measurementEntries(head, names) }; } if (process.argv[1] && pathToFileURL(path.resolve(process.argv[1])).href === import.meta.url) { @@ -147,14 +153,22 @@ if (process.argv[1] && pathToFileURL(path.resolve(process.argv[1])).href === imp if (!base || !head || !output) { throw new Error('Usage: node scripts/size-report-plugin-plan.mjs '); } - const files = git('diff', '--name-only', '--no-renames', '-z', base, head, '--').split('\0'); + const fork = git('merge-base', base, head).trim(); + const files = git('diff', '--name-only', '--no-renames', '-z', fork, head, '--').split('\0'); const lockfiles = files.includes('pnpm-lock.yaml') ? { - base: parse(git('show', `${base}:pnpm-lock.yaml`)), + base: parse(git('show', `${fork}:pnpm-lock.yaml`)), head: parse(git('show', `${head}:pnpm-lock.yaml`)), } : undefined; - const plugins = planPluginSizes(workspaceAt(base), workspaceAt(head), files, lockfiles); + const forkWorkspace = workspaceAt(fork); + const plugins = planPluginSizes( + forkWorkspace, + workspaceAt(head), + files, + lockfiles, + base === fork ? forkWorkspace : workspaceAt(base), + ); fs.mkdirSync(output, { recursive: true }); for (const [side, entries] of Object.entries(plugins)) { fs.writeFileSync(path.join(output, `${side}.json`), JSON.stringify(entries)); diff --git a/scripts/size-report-plugins.mjs b/scripts/size-report-plugins.mjs index 9a0e59a443..ad28506bdc 100644 --- a/scripts/size-report-plugins.mjs +++ b/scripts/size-report-plugins.mjs @@ -5,20 +5,39 @@ import path from 'node:path'; import { formatBytes, formatDiff } from './size-report-format.mjs'; import { measureCleanInstalledPackage, measureDirectory } from './size-report-install.mjs'; +// Base and head each share this allowance across their selected plugins. +const PLUGIN_MEASUREMENT_BUDGET_MS = 90_000; + export function measurePluginSizes(root, planPath) { const plugins = JSON.parse(fs.readFileSync(planPath, 'utf8')); - return plugins.map((plugin) => measurePlugin(root, plugin)); + const deadline = performance.now() + PLUGIN_MEASUREMENT_BUDGET_MS; + return plugins.map((plugin) => { + try { + return measurePlugin(root, plugin, deadline); + } catch (error) { + throw new Error(`Could not measure plugin ${plugin.name}: ${error.message}`, { + cause: error, + }); + } + }); +} + +function remainingTime(deadline) { + const timeout = Math.ceil(deadline - performance.now()); + if (timeout <= 0) throw new Error('Plugin measurement budget exhausted.'); + return timeout; } -function measurePlugin(root, { name, directory }) { +function measurePlugin(root, { name, directory }, deadline) { const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-plugin-size-')); try { const tarball = path.join(scratch, 'plugin.tgz'); execFileSync('pnpm', ['pack', '--out', tarball], { cwd: path.join(root, directory), stdio: ['ignore', 'ignore', 'inherit'], + timeout: remainingTime(deadline), }); - execFileSync('tar', ['-xzf', tarball, '-C', scratch]); + execFileSync('tar', ['-xzf', tarball, '-C', scratch], { timeout: remainingTime(deadline) }); const packageDir = path.join(scratch, 'package'); const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')); if (manifest.name !== name) throw new Error(`Expected to pack ${name}, got ${manifest.name}.`); @@ -27,7 +46,8 @@ function measurePlugin(root, { name, directory }) { name, unpackedBytes, tarballBytes: fs.statSync(tarball).size, - installedBytes: measureCleanInstalledPackage(tarball, name).totalBytes, + installedBytes: measureCleanInstalledPackage(tarball, name, remainingTime(deadline)) + .totalBytes, }; } finally { fs.rmSync(scratch, { recursive: true, force: true }); From ad33aa2451f45140096e19053bc706bcba3644a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 28 Nov 2026 13:38:01 +0100 Subject: [PATCH 4/4] fix(ci): report v2 plugins and incomplete size measurements --- scripts/__tests__/size-report-package.test.ts | 62 ++++++++++++++++++- scripts/size-report-plugin-plan.mjs | 8 ++- scripts/size-report-plugins.mjs | 17 +++-- scripts/size-report.d.mts | 15 +++-- 4 files changed, 88 insertions(+), 14 deletions(-) diff --git a/scripts/__tests__/size-report-package.test.ts b/scripts/__tests__/size-report-package.test.ts index cfd7142465..31f167b911 100644 --- a/scripts/__tests__/size-report-package.test.ts +++ b/scripts/__tests__/size-report-package.test.ts @@ -667,11 +667,52 @@ test('Markdown compares measured plugins and labels added and removed packages', ); }); +test('exhausted plugin budget keeps the core report and identifies unmeasured sizes', async () => { + const cwd = await mkdtempForTest('size-plugin-budget-'); + const plan = join(cwd, 'plan.json'); + await writeFile(plan, JSON.stringify([{ name: '@agent-device/one', directory: 'packages/one' }])); + const modulePath = join(import.meta.dirname, '../size-report-plugins.mjs'); + const { stdout, stderr } = await execFileAsync( + process.execPath, + [ + '--input-type=module', + '-e', + `const { measurePluginSizes } = await import(process.argv[1]); + let time = 0; + performance.now = () => (time += 120_000); + console.log(JSON.stringify(measurePluginSizes(process.cwd(), process.argv[2])));`, + modulePath, + plan, + ], + { cwd }, + ); + assert.match(stderr, /@agent-device\/one: Plugin measurement budget exhausted/); + const unmeasured = JSON.parse(stdout); + const core = { + npmPack: { tarballBytes: 100, unpackedBytes: 300 }, + cleanInstalled: { totalBytes: 350 }, + }; + const before = { + ...core, + plugins: [ + { name: '@agent-device/one', installedBytes: 60, unpackedBytes: 30, tarballBytes: 10 }, + ], + }; + const after = { ...core, plugins: unmeasured }; + const markdown = formatMarkdown(after, before); + assert.match(markdown, /\| Package \(download\) \| 100 B \| 100 B \| 0 B \|/); + assert.match( + markdown, + /\| `@agent-device\/one` \| 60 B → unavailable \| 30 B → unavailable \| 10 B → unavailable \|/, + ); + assert.match(formatMarkdown(before, after), /\| `@agent-device\/one` \| unavailable → 60 B \|/); +}); + const one = { directory: 'packages/one', manifest: { name: '@agent-device/one', - 'agent-device': {}, + exports: { './agent-device': './dist/agent-device.mjs' }, devDependencies: { '@agent-device/build-piece': 'workspace:*' }, }, }; @@ -706,6 +747,25 @@ test('plugin plan follows changed build inputs without selecting unrelated plugi }); }); +test('plugin plan selects published v2-only providers by their export', async () => { + const providers = await Promise.all( + ['tizen', 'webos'].map(async (provider) => { + const directory = `packages/provider-${provider}`; + const manifest = JSON.parse( + await readFile(join(import.meta.dirname, '../..', directory, 'package.json'), 'utf8'), + ); + return { directory, manifest }; + }), + ); + for (const { directory, manifest } of providers) { + const entry = { directory, name: manifest.name }; + assert.deepEqual(planPluginSizes(providers, providers, [`${directory}/src/index.ts`]), { + base: [entry], + head: [entry], + }); + } +}); + test('plugin plan follows a changed lockfile importer', () => { const base = { importers: { 'packages/one': {}, 'packages/two': {} } }; const head = { diff --git a/scripts/size-report-plugin-plan.mjs b/scripts/size-report-plugin-plan.mjs index ae72f244b9..b1cdc876a9 100644 --- a/scripts/size-report-plugin-plan.mjs +++ b/scripts/size-report-plugin-plan.mjs @@ -27,9 +27,11 @@ function workspaceAt(ref) { } function isPublishedPlugin({ manifest }) { - return ( - manifest.private !== true && Boolean(manifest.agentDevicePlugin ?? manifest['agent-device']) - ); + if (manifest.private === true) return false; + const exports = manifest.exports; + const hasPluginExport = + exports !== null && typeof exports === 'object' && Object.hasOwn(exports, './agent-device'); + return hasPluginExport || manifest.agentDevicePlugin !== undefined; } function workspaceClosure(plugin, byName) { diff --git a/scripts/size-report-plugins.mjs b/scripts/size-report-plugins.mjs index ad28506bdc..7639b452a0 100644 --- a/scripts/size-report-plugins.mjs +++ b/scripts/size-report-plugins.mjs @@ -15,9 +15,8 @@ export function measurePluginSizes(root, planPath) { try { return measurePlugin(root, plugin, deadline); } catch (error) { - throw new Error(`Could not measure plugin ${plugin.name}: ${error.message}`, { - cause: error, - }); + process.stderr.write(`Could not measure plugin ${plugin.name}: ${error.message}\n`); + return { name: plugin.name, unavailable: true }; } }); } @@ -63,7 +62,9 @@ export function formatPluginSizes(plugins, basePlugins = []) { const before = base.get(name); const after = current.get(name); const metrics = ['installedBytes', 'unpackedBytes', 'tarballBytes']; - const cells = metrics.map((metric) => formatPluginMetric(before?.[metric], after?.[metric])); + const cells = metrics.map((metric) => + formatPluginMetric(pluginMetric(before, metric), pluginMetric(after, metric)), + ); return `| \`${name}\` | ${cells.join(' | ')} |`; }); return `### Affected plugins @@ -75,7 +76,15 @@ ${rows.join('\n')} `; } +function pluginMetric(plugin, metric) { + return plugin?.unavailable ? 'unavailable' : plugin?.[metric]; +} + function formatPluginMetric(base, current) { + if (base === 'unavailable' || current === 'unavailable') { + const display = (value) => (typeof value === 'number' ? formatBytes(value) : (value ?? '-')); + return `${display(base)} → ${display(current)}`; + } if (current === undefined) return `${formatBytes(base)} → removed`; if (base === undefined) return `${formatBytes(current)} (new)`; return `${formatBytes(base)} → ${formatBytes(current)} (${formatDiff(base, current)})`; diff --git a/scripts/size-report.d.mts b/scripts/size-report.d.mts index 7315a028ac..ff54599d46 100644 --- a/scripts/size-report.d.mts +++ b/scripts/size-report.d.mts @@ -3,12 +3,15 @@ export type SizeReport = Readonly<{ npmPack: Readonly<{ tarballBytes: number; unpackedBytes: number }>; cleanInstalled: Readonly<{ totalBytes: number }>; - plugins?: readonly Readonly<{ - name: string; - unpackedBytes: number; - tarballBytes: number; - installedBytes: number; - }>[]; + plugins?: readonly ( + | Readonly<{ + name: string; + unpackedBytes: number; + tarballBytes: number; + installedBytes: number; + }> + | Readonly<{ name: string; unavailable: true }> + )[]; startup?: Readonly<{ runs: number; benchmarks: readonly Readonly<{ name: string; medianMs: number }>[];