PackageCompiler class

Compiles a multi-module ball Program into a full Dart package, producing one .dart file per non-std module.

Output layout

Module names are converted back to file paths using the inverse of PackageEncoder.filePathToModuleName:

Ball module Output file path
lib.src.models lib/src/models.dart
bin.main bin/main.dart

Entry module

The module referenced by Program.entryModule is compiled with a main() entry function. All other user-defined modules are compiled without one.

pubspec.yaml and package manifest files

PackageEncoder embeds pubspec.yaml, pubspec.lock, and other root-level config files as assets in the __assets__ module. writeToDirectory extracts them verbatim — no reconstruction needed.

Usage — in memory

final compiler = PackageCompiler(program);
final files = compiler.compileToMap();
// files: { 'lib/src/models.dart': '// Generated ...\nclass User { ... }', ... }

Usage — write to disk

final compiler = PackageCompiler(program);
compiler.writeToDirectory(Directory('/path/to/output'));

Constructors

PackageCompiler(Program program)

Properties

hashCode → int
The hash code for this object.
no setterinherited
program → Program
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

compileToMap() → Map<String, String>
Compile all user-defined modules and return a map from relative file path to Dart source code.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
writeToDirectory(Directory outputDir) → List<String>
Compile all modules and write the output files under outputDir.

Operators

operator ==(Object other) → bool
The equality operator.
inherited