Using constructors and instance methods would allow this functionality to be:
configured via constructors
passed around as instances
mocked out for testing
So:
class Pub {
Pub({String sdkPath});
get(...);
//...
PubGlobal get global => new PubGlobal(pub: this);
}
class PubGlobal {
PubGlobal({Pub pub});
// The rest pretty much stays as is.
}
// Replaces [Dart].
class Vm {
Vm({String sdkPath});
run(...);
//...
}
// Replaces [Dart2js].
class Compiler {
Compiler({String sdkPath});
compile(...);
//...
}
class Analyzer {
Analyzer.sdk({String sdkPath});
/// Uses pub by default, or sdk if it matches constraint and saves downloading.
Analyzer({VersionConstraint constraint});
analyze(...);
//...
}
// Calls `dartfmt`.
class Formatter {
Formatter.sdk({String sdkPath});
/// Uses pub by default, or sdk if it matches constraint and saves downloading.
Formatter({VersionConstraint constraint});
//...
}
Then for a little extra convenience, we could either expose them at the top-level:
final Pub pub = new Pub();
final Vm vm = new Vm();
final Compiler compiler = new Compiler();
final Analyzer analyzer = new Analyzer();
final Formatter formatter = new Formatter();
or as members of a reified SDK (which can also be configured, passed around, mocked, etc.):
final Sdk sdk = new Sdk();
class Sdk {
final String path;
Directory get dir => new Directory(path);
/// Defaults the path using the current [getSdkDir] logic.
Sdk({this.path});
Vm get vm => new Vm(sdkPath: path) ;
Compiler get compiler => new Compiler(sdkPath: path);
Analyzer get analyzer => new Analyzer.sdk(sdkPath: path);
Formatter get formatter => new Formatter.sdk(sdkPath: path);
Pub get pub => new Pub(sdkPath: path);
}
or both:
final Pub pub = sdk.pub;
final Vm vm = sdk.vm;
final Compiler compiler = sdk.compiler;
final Analyzer analyzer = new Analyzer();
final Formatter formatter = new Formatter();
Using constructors and instance methods would allow this functionality to be:
So:
Then for a little extra convenience, we could either expose them at the top-level:
or as members of a reified SDK (which can also be configured, passed around, mocked, etc.):
or both:
Example usage:
This would be a big breaking change, but well worth it IMO.