Skip to content

Convert Pub, Dart, Dart2js, Analyzer static methods to constructors and instance methods #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
seaneagan opened this issue Apr 23, 2015 · 1 comment

Comments

@seaneagan
Copy link
Contributor

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();

Example usage:

pub.get(...);
pub.global.run(...);
vm.run(...);
compiler.compile(...);
analyzer.analyze(...);
sdk.analyzer.analyze(...);
formatter.format(...);
sdk.formatter.format(...);

This would be a big breaking change, but well worth it IMO.

@seaneagan seaneagan added this to the 0.8.0 - rename? milestone Apr 23, 2015
@devoncarew
Copy link
Contributor

Resolution: yes! but let's try and be conscious of reducing the number of breaking changes.

jcollins-g pushed a commit to jcollins-g/grinder.dart that referenced this issue Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants