This document describes the current architecture of the Barrel Roll VS Code extension.
Barrel Roll is organized around focused services and thin integration layers:
- command registration and UX flow in
src/extension.ts - barrel generation orchestration in
src/core/barrel/barrel-file.generator.ts - export parsing in
src/core/parser/export.parser.ts - file system access in
src/core/io/file-system.service.ts - deterministic output construction in
src/core/barrel/barrel-content.builder.ts - update sanitization in
src/core/barrel/content-sanitizer.ts - parse-result caching in
src/core/barrel/export-cache.ts
The design emphasizes separation of concerns, deterministic output, and testability.
src/
extension.ts # VS Code activation and command wiring
core/
barrel/
barrel-file.generator.ts # Main orchestrator
barrel-content.builder.ts
content-sanitizer.ts
export-cache.ts
export-patterns.ts
io/
file-system.service.ts
parser/
export.parser.ts
logging/
output-channel.logger.ts
test/
unit/** # Unit tests
integration/** # Integration tests
testHarness.ts # Node test setup
runTest.ts # VS Code integration entry point
types/
utils/
Two commands are contributed in package.json and registered in src/extension.ts:
barrel-roll.generateBarrelbarrel-roll.generateBarrelRecursive
Both commands share the same generator instance. A lightweight in-memory queue serializes execution to avoid concurrent writes when commands are triggered rapidly.
- A VS Code command is triggered.
src/extension.tsresolves the target folder URI.BarrelFileGeneratorreads TypeScript files and subdirectories.ExportCachereturns cached parse results for unchanged files.ExportParserextracts and normalizes export symbols.BarrelContentBuilderproduces deterministic barrel lines.- If
index.tsexists,BarrelContentSanitizerpreserves direct declarations and removes stale/duplicate export lines. FileSystemServicewrites finalindex.tscontent.
- Activates extension services.
- Registers commands and progress notifications.
- Configures output-channel logging.
- Handles friendly user-facing error messages.
- Main orchestrator for recursive and non-recursive generation.
- Applies generation options and mode behavior.
- Coordinates file discovery, parsing, content building, and writing.
- Supports merge behavior for existing barrels via sanitizer.
- Caches parsed exports by file path +
mtime. - Avoids repeat parsing during recursive operations.
- Uses bounded cache size with eviction.
- Handles directory scanning and file reads/writes.
- Filters ignored directories and non-source files.
- Excludes test files and declaration files from barrel export discovery.
- Includes file-size safeguards to avoid pathological reads.
- Extracts export declarations into normalized internal shapes.
- Distinguishes value exports from type-only exports.
- Supports default export detection.
- Produces sorted, stable export output.
- Ensures consistent formatting for type/value/default exports.
- Preserves direct definitions already present in
index.ts. - Sanitizes conflicting or stale re-export lines during updates.
- Test execution uses Node's built-in test runner via
scripts/run-tests.cjs. - Unit tests:
src/test/unit/** - Integration tests:
src/test/integration/** - VS Code integration entrypoint:
src/test/runTest.ts - Shared test helpers:
src/test/testTypes.ts
- Compile bundle: webpack (
webpack.config.cjs) ->dist/extension.js - VSIX packaging:
@vscode/vsce - Publish allowlist controlled by
.vscodeignore
- Deterministic output ordering to reduce diff noise.
- Safe updates that preserve direct declarations in existing barrels.
- Serialized command execution to avoid write races.
- Lightweight parsing/caching balance for speed in larger trees.
- Minimal publish surface in VSIX artifacts.
- Add export grammar support in
src/core/parser/export.parser.ts. - Adjust formatting/output policy in
src/core/barrel/barrel-content.builder.ts. - Extend sanitization policy in
src/core/barrel/content-sanitizer.ts. - Add generation modes/options in
src/types/andsrc/core/barrel/barrel-file.generator.ts.