DEV Community

Cover image for Use an output inventory to investigate a repeat build
KhaledSalem
KhaledSalem

Posted on

Use an output inventory to investigate a repeat build

A production build returning exit code zero is necessary, but it does not tell you which artifacts changed. This lab adds a small read-only inventory helper. It does not claim to prove runtime correctness.

Create inventory.mjs outside the output directory:

import { readdir, readFile } from 'node:fs/promises';
import { resolve, relative, join } from 'node:path';
import { createHash } from 'node:crypto';

const root = resolve(process.argv[2] ?? 'dist');
async function walk(dir) {
  const entries = await readdir(dir, { withFileTypes: true });
  const rows = [];
  for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
    const path = join(dir, entry.name);
    if (entry.isDirectory()) rows.push(...await walk(path));
    else if (entry.isFile()) {
      const bytes = await readFile(path);
      rows.push({
        file: relative(root, path).split('\\').join('/'),
        bytes: bytes.length,
        sha256: createHash('sha256').update(bytes).digest('hex'),
      });
    }
  }
  return rows;
}
console.log(JSON.stringify(await walk(root), null, 2));
Enter fullscreen mode Exit fullscreen mode

This helper includes regular files and skips symbolic links. Use the actual output directory if it is not dist. It fails if the directory cannot be read rather than treating a missing build as an empty success.

Compare two states

pnpm exec ionify build
node inventory.mjs dist > before.json
# Change one visible string in an imported component.
pnpm exec ionify build
node inventory.mjs dist > after.json
Enter fullscreen mode Exit fullscreen mode

Keep the JSON files outside dist. Compare filenames, byte counts and hashes with your normal diff tool. Content-hashed names can turn a change into an addition and removal, so do not compare only matching filenames.

Serve the production output and check the edited label. Repeat without another source change and inspect any unexpected artifact differences. Timestamps, source maps or environment-dependent content can require explanation; a changed hash alone does not identify the cause.

This is a diagnostic tool, not an Ionify feature or a security audit. It helps turn “the build felt strange” into a precise observation that a maintainer can investigate.

Top comments (0)