<commit_before>// Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library pub.pub_package_provider;

import 'dart:async';

import 'package:barback/barback.dart';
import 'package:path/path.dart' as path;

import 'entrypoint.dart';

/// An implementation of barback's [PackageProvider] interface so that barback
/// can assets within pub packages.
class PubPackageProvider implements PackageProvider {
  /// Maps the names of all of the packages in [_entrypoint]'s transitive
  /// dependency graph to the local path of the directory for that package.
  final Map<String, String> _packageDirs;

  /// Creates a new provider for [entrypoint].
  static Future<PubPackageProvider> create(Entrypoint entrypoint) {
    var packageDirs = <String, String>{};

    packageDirs[entrypoint.root.name] = entrypoint.root.dir;

    // Cache package directories up front so we can have synchronous access
    // to them.
    var futures = [];
    entrypoint.loadLockFile().packages.forEach((name, package) {
      var source = entrypoint.cache.sources[package.source];
      futures.add(source.getDirectory(package).then((packageDir) {
        packageDirs[name] = packageDir;
      }));
    });

    return Future.wait(futures).then((_) {
      return new PubPackageProvider._(packageDirs);
    });
  }

  PubPackageProvider._(this._packageDirs);

  Iterable<String> get packages => _packageDirs.keys;

  /// Gets the root directory of [package].
  String getPackageDir(String package) => _packageDirs[package];

  // TODO(rnystrom): Actually support transformers.
  Iterable<Iterable<Transformer>> getTransformers(String package) => [];

  Future<Asset> getAsset(AssetId id) {
    var file = path.join(_packageDirs[id.package], id.path);
    return new Future.value(new Asset.fromPath(id, file));
  }
}
<commit_msg>Add the ability to dynamically modify transforms to barback.<commit_after>// Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library pub.pub_package_provider;

import 'dart:async';

import 'package:barback/barback.dart';
import 'package:path/path.dart' as path;

import 'entrypoint.dart';

/// An implementation of barback's [PackageProvider] interface so that barback
/// can assets within pub packages.
class PubPackageProvider implements PackageProvider {
  /// Maps the names of all of the packages in [_entrypoint]'s transitive
  /// dependency graph to the local path of the directory for that package.
  final Map<String, String> _packageDirs;

  /// Creates a new provider for [entrypoint].
  static Future<PubPackageProvider> create(Entrypoint entrypoint) {
    var packageDirs = <String, String>{};

    packageDirs[entrypoint.root.name] = entrypoint.root.dir;

    // Cache package directories up front so we can have synchronous access
    // to them.
    var futures = [];
    entrypoint.loadLockFile().packages.forEach((name, package) {
      var source = entrypoint.cache.sources[package.source];
      futures.add(source.getDirectory(package).then((packageDir) {
        packageDirs[name] = packageDir;
      }));
    });

    return Future.wait(futures).then((_) {
      return new PubPackageProvider._(packageDirs);
    });
  }

  PubPackageProvider._(this._packageDirs);

  Iterable<String> get packages => _packageDirs.keys;

  /// Gets the root directory of [package].
  String getPackageDir(String package) => _packageDirs[package];

  Future<Asset> getAsset(AssetId id) {
    var file = path.join(_packageDirs[id.package], id.path);
    return new Future.value(new Asset.fromPath(id, file));
  }
}

{'fraction_non_alphanumeric': 0.10952504541915391, 'fraction_numerical': 0.002076304178562159, 'mean_word_length': 3.9158163265306123, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4019991', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1081, 'n_words': 345}