Reenable the common front-end in dart2js by creating a .packages file (#1829)
diff --git a/lib/src/barback/dart2js_transformer.dart b/lib/src/barback/dart2js_transformer.dart
index e9678ff..e020deb 100644
--- a/lib/src/barback/dart2js_transformer.dart
+++ b/lib/src/barback/dart2js_transformer.dart
@@ -134,13 +134,13 @@
var entrypoint = _environment.graph.packages[id.package].path(id.path);
- // We define the packageRoot in terms of the entrypoint directory, and not
- // the rootPackage, to ensure that the generated source-maps are valid.
+ // We define the .packages file in terms of the entrypoint directory, and
+ // not the rootPackage, to ensure that the generated source-maps are valid.
// Source-maps contain relative URLs to package sources and these relative
// URLs should be self-contained within the paths served by pub-serve.
// See #1511 for details.
var buildDir = _environment.getSourceDirectoryContaining(id.path);
- var packageRoot = _environment.rootPackage.path(buildDir, "packages");
+ var packageConfig = _environment.rootPackage.path(buildDir, ".packages");
// TODO(rnystrom): Should have more sophisticated error-handling here. Need
// to report compile errors to the user in an easily visible way. Need to
@@ -154,7 +154,7 @@
defaultsTo: _settings.mode == BarbackMode.RELEASE),
verbose: _configBool('verbose'),
environment: _configEnvironment,
- packageRoot: packageRoot,
+ packageConfig: packageConfig,
analyzeAll: _configBool('analyzeAll'),
preserveUris: _configBool('preserveUris'),
suppressWarnings: _configBool('suppressWarnings'),
@@ -223,6 +223,7 @@
final AssetEnvironment _environment;
final Transform _transform;
String _libraryRootPath;
+ String _packagesFileContents;
/// The map of previously loaded files.
///
@@ -279,6 +280,18 @@
.getSourceDirectoryContaining(_transform.primaryInput.id.path);
_libraryRootPath =
_environment.rootPackage.path(buildDir, "packages", r"$sdk");
+
+ // We also define the entries within the .packages file in terms of the
+ // entrypoint directory, and not the rootPackage, to ensure that the
+ // generated source-maps are valid.
+ // Source-maps contain relative URLs to package sources and these relative
+ // URLs should be self-contained within the paths served by pub-serve.
+ // See #1511 for details.
+ var sb = new StringBuffer();
+ for (var package in _environment.graph.packages.keys) {
+ sb.write('$package:packages/$package/\n');
+ }
+ _packagesFileContents = '$sb';
}
/// A [CompilerInputProvider] for dart2js.
@@ -400,6 +413,8 @@
if (id != null) {
if (id.extension == '.dill') {
return collectBytes(_transform.readInput(id));
+ } else if (id.path.endsWith('/.packages')) {
+ return _packagesFileContents;
} else {
return _transform.readInputAsString(id);
}
diff --git a/lib/src/dart.dart b/lib/src/dart.dart
index f673858..4bb3117 100644
--- a/lib/src/dart.dart
+++ b/lib/src/dart.dart
@@ -10,7 +10,6 @@
import 'package:analyzer/analyzer.dart';
import 'package:barback/barback.dart';
import 'package:compiler_unsupported/compiler.dart' as compiler;
-import 'package:compiler_unsupported/src/filenames.dart' show appendSlash;
import 'package:path/path.dart' as p;
import 'exceptions.dart';
@@ -51,8 +50,8 @@
/// Uses [provider] to communcate between dart2js and the caller. Returns a
/// future that completes when compilation is done.
///
-/// By default, the package root is assumed to be adjacent to [entrypoint], but
-/// if [packageRoot] is passed that will be used instead.
+/// By default, the .packages file is assumed to be adjacent to [entrypoint],
+/// but if [packageConfig] is passed that will be used instead.
Future compile(String entrypoint, CompilerProvider provider,
{Iterable<String> commandLineOptions,
bool checked: false,
@@ -60,7 +59,7 @@
bool minify: true,
bool verbose: false,
Map<String, String> environment,
- String packageRoot,
+ String packageConfig,
bool analyzeAll: false,
bool preserveUris: false,
bool suppressWarnings: false,
@@ -89,7 +88,6 @@
if (platformBinaries != null) {
options.add('--platform-binaries=$platformBinaries');
}
- options.add('--use-old-frontend');
var sourceUrl = p.toUri(entrypoint);
options.add("--out=$sourceUrl.js");
@@ -102,21 +100,22 @@
if (environment == null) environment = {};
if (commandLineOptions != null) options.addAll(commandLineOptions);
- if (packageRoot == null) {
- packageRoot = p.join(p.dirname(entrypoint), 'packages');
+ if (packageConfig == null) {
+ packageConfig = p.join(p.dirname(entrypoint), '.packages');
} else {
- packageRoot = p.normalize(p.absolute(packageRoot));
+ packageConfig = p.normalize(p.absolute(packageConfig));
}
await compiler.compile(
p.toUri(entrypoint),
provider.libraryRoot,
- p.toUri(appendSlash(packageRoot)),
+ null,
provider.provideInput,
provider.handleDiagnostic,
options,
provider.provideOutput,
- environment);
+ environment,
+ p.toUri(packageConfig));
}
/// Returns whether [dart] looks like an entrypoint file.