| Index: sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart b/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
|
| index 621e85a1bb7df2446bc9f1be9c67079eeabdc9b1..714fd70b645e836d95d09e0591473df0c196844d 100644
|
| --- a/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
|
| +++ b/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
|
| @@ -39,7 +39,10 @@ void main(_, SendPort replyTo) {
|
| _respond(wrappedMessage, (message) {
|
| var library = Uri.parse(message['library']);
|
| var configuration = JSON.decode(message['configuration']);
|
| - return initialize(library, configuration).
|
| + if (configuration == null) configuration = {};
|
| + var mode = new BarbackMode.fromString(message['mode']);
|
| + var settings = new BarbackSettings(configuration, mode);
|
| + return initialize(library, settings).
|
| map(_serializeTransformerOrGroup).toList();
|
| });
|
| });
|
| @@ -48,9 +51,8 @@ void main(_, SendPort replyTo) {
|
| /// Loads all the transformers and groups defined in [uri].
|
| ///
|
| /// Loads the library, finds any Transformer or TransformerGroup subclasses in
|
| -/// it, instantiates them (with [configuration] if it's non-null), and returns
|
| -/// them.
|
| -Iterable initialize(Uri uri, Map configuration) {
|
| +/// it, instantiates them with [settings], and returns them.
|
| +Iterable initialize(Uri uri, BarbackSettings settings) {
|
| var mirrors = currentMirrorSystem();
|
| var transformerClass = reflectClass(Transformer);
|
| var groupClass = reflectClass(TransformerGroup);
|
| @@ -67,19 +69,12 @@ Iterable initialize(Uri uri, Map configuration) {
|
|
|
| var constructor = getConstructor(classMirror, 'asPlugin');
|
| if (constructor == null) return null;
|
| - if (constructor.parameters.isEmpty) {
|
| - if (configuration != null) return null;
|
| - return classMirror.newInstance(const Symbol('asPlugin'), []).reflectee;
|
| - }
|
| - if (constructor.parameters.length != 1) return null;
|
| + if (constructor.parameters.length > 1) return null;
|
|
|
| - // If the constructor expects configuration and none was passed, it defaults
|
| - // to an empty map.
|
| - if (configuration == null) configuration = {};
|
| + var parameters = [];
|
| + if (constructor.parameters.isNotEmpty) parameters.add(settings);
|
|
|
| - // TODO(nweiz): if the constructor accepts named parameters, automatically
|
| - // destructure the configuration map.
|
| - return classMirror.newInstance(const Symbol('asPlugin'), [configuration])
|
| + return classMirror.newInstance(const Symbol('asPlugin'), parameters)
|
| .reflectee;
|
| }).where((classMirror) => classMirror != null);
|
| }
|
| @@ -444,7 +439,8 @@ Stream callbackStream(Stream callback()) {
|
| /// [id].
|
| ///
|
| /// [server] is used to serve any Dart files needed to load the transformers.
|
| -Future<Set> loadTransformers(BarbackServer server, TransformerId id) {
|
| +Future<Set> loadTransformers(BarbackServer server, BarbackMode mode,
|
| + TransformerId id) {
|
| return id.getAssetId(server.barback).then((assetId) {
|
| var path = assetId.path.replaceFirst('lib/', '');
|
| // TODO(nweiz): load from a "package:" URI when issue 12474 is fixed.
|
| @@ -460,6 +456,7 @@ Future<Set> loadTransformers(BarbackServer server, TransformerId id) {
|
| .then((sendPort) {
|
| return _call(sendPort, {
|
| 'library': uri,
|
| + 'mode': mode.name,
|
| // TODO(nweiz): support non-JSON-encodable configuration maps.
|
| 'configuration': JSON.encode(id.configuration)
|
| }).then((transformers) {
|
| @@ -552,7 +549,7 @@ Map _serializeTransform(Transform transform) {
|
|
|
| if (message['type'] == 'addOutput') {
|
| transform.addOutput(_deserializeAsset(message['output']));
|
| - return;
|
| + return null;
|
| }
|
|
|
| assert(message['type'] == 'log');
|
|
|