Skip to content

@ogygia/barrels

Build report

At the end of each build leg barrels() prints what it moved and which barrels it went around most. debug prints every rewrite, a component that can't be parsed is named, and the devtools say why a barrel an island still imports was left.

On this page

You want to know the pass did something, and where it didn’t. barrels() says so in three places: a report at the end of each build, a line per rewrite when you ask for it, and the devtools’ findings.

Report

At the end of each build leg (Kit builds the client, then the server), barrels() prints a report: how many files it rewrote out of how many it read, how many barrel imports and names moved, how many barrels it went around, and the time from the first transform to the last. Then the barrels it went around most, by names moved, with how many files imported through each.

report sets how much of it prints:

  • true (the default): the eight biggest barrels, and a count of the rest;
  • 'all': every barrel;
  • false: nothing.

Dev prints no report.

When nothing needed rewriting, it says that in one line (barrels_report_none). The report itself is barrels_report. Paths are relative to the workspace root.

barrels: 41 of 212 files rewritten — 96 barrel imports → leaves (143 names), 3 barrels bypassed, 1.84 s first to last transform
  118 names  src/lib/components/index.ts  ← 37 importers
   21 names  src/lib/icons/index.ts  ← 9 importers
    4 names  packages/ui/src/index.ts  ← 2 importers

debug

debug: true prints each rewrite as it happens, in dev and in the build: the file, the names, the barrel they came through and the files they go to now (barrels_rewrite).

import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { barrels } from '@ogygia/barrels';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    ogygia(),
    barrels({ report: 'all', debug: true }),
    sveltekit()
  ]
});

Skipped components

A .svelte file the Svelte parser can’t read keeps every import it has, so its island ships each barrel whole. barrels() warns once per file with barrels_component_skipped, naming the parser’s error and where, and every report lists the skipped components. The Svelte compiler reports the syntax error itself; fix it and the imports are rewritten.

Why a barrel stayed

The devtools raise island-barrel when an island still imports a barrel whole. With barrels() listed, the finding also quotes why the pass left that barrel, and the fix for each reason:

ReasonWhyFix
impureIt runs code of its own besides its re-exports.Move that code into a module of its own, or list the barrel in force.
keptkeep lists it.Take it out of keep.
outside the projectIt’s a package, and packages doesn’t list it.List it in packages.
opaqueIt re-exports from a module that can’t be read.Import those names from their own files.
ownThe names are defined in the barrel itself.Move them into files of their own.
ambiguousTwo export * lines give the same name.Export the name from one place only.
pinnedAn import of it marks a region, and a region import stays as written.Import the region from its own file.
namespaceIt’s imported whole (import * as).Import the names the island uses.
unparsableA component that imports it couldn’t be parsed.Fix the component the build log names.

Without barrels(), the finding suggests adding it. See Page findings and the profiler’s Findings.