Skip to content

Commit dbe8be2

Browse files
authored
Reenable the common front-end in dart2js by creating a .packages file (#1829)
1 parent 5f329bc commit dbe8be2

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

lib/src/barback/dart2js_transformer.dart

+19-4
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ class Dart2JSTransformer extends Transformer implements LazyTransformer {
134134

135135
var entrypoint = _environment.graph.packages[id.package].path(id.path);
136136

137-
// We define the packageRoot in terms of the entrypoint directory, and not
138-
// the rootPackage, to ensure that the generated source-maps are valid.
137+
// We define the .packages file in terms of the entrypoint directory, and
138+
// not the rootPackage, to ensure that the generated source-maps are valid.
139139
// Source-maps contain relative URLs to package sources and these relative
140140
// URLs should be self-contained within the paths served by pub-serve.
141141
// See #1511 for details.
142142
var buildDir = _environment.getSourceDirectoryContaining(id.path);
143-
var packageRoot = _environment.rootPackage.path(buildDir, "packages");
143+
var packageConfig = _environment.rootPackage.path(buildDir, ".packages");
144144

145145
// TODO(rnystrom): Should have more sophisticated error-handling here. Need
146146
// to report compile errors to the user in an easily visible way. Need to
@@ -154,7 +154,7 @@ class Dart2JSTransformer extends Transformer implements LazyTransformer {
154154
defaultsTo: _settings.mode == BarbackMode.RELEASE),
155155
verbose: _configBool('verbose'),
156156
environment: _configEnvironment,
157-
packageRoot: packageRoot,
157+
packageConfig: packageConfig,
158158
analyzeAll: _configBool('analyzeAll'),
159159
preserveUris: _configBool('preserveUris'),
160160
suppressWarnings: _configBool('suppressWarnings'),
@@ -223,6 +223,7 @@ class _BarbackCompilerProvider implements dart.CompilerProvider {
223223
final AssetEnvironment _environment;
224224
final Transform _transform;
225225
String _libraryRootPath;
226+
String _packagesFileContents;
226227

227228
/// The map of previously loaded files.
228229
///
@@ -279,6 +280,18 @@ class _BarbackCompilerProvider implements dart.CompilerProvider {
279280
.getSourceDirectoryContaining(_transform.primaryInput.id.path);
280281
_libraryRootPath =
281282
_environment.rootPackage.path(buildDir, "packages", r"$sdk");
283+
284+
// We also define the entries within the .packages file in terms of the
285+
// entrypoint directory, and not the rootPackage, to ensure that the
286+
// generated source-maps are valid.
287+
// Source-maps contain relative URLs to package sources and these relative
288+
// URLs should be self-contained within the paths served by pub-serve.
289+
// See #1511 for details.
290+
var sb = new StringBuffer();
291+
for (var package in _environment.graph.packages.keys) {
292+
sb.write('$package:packages/$package/\n');
293+
}
294+
_packagesFileContents = '$sb';
282295
}
283296

284297
/// A [CompilerInputProvider] for dart2js.
@@ -400,6 +413,8 @@ class _BarbackCompilerProvider implements dart.CompilerProvider {
400413
if (id != null) {
401414
if (id.extension == '.dill') {
402415
return collectBytes(_transform.readInput(id));
416+
} else if (id.path.endsWith('/.packages')) {
417+
return _packagesFileContents;
403418
} else {
404419
return _transform.readInputAsString(id);
405420
}

lib/src/dart.dart

+9-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'dart:isolate';
1010
import 'package:analyzer/analyzer.dart';
1111
import 'package:barback/barback.dart';
1212
import 'package:compiler_unsupported/compiler.dart' as compiler;
13-
import 'package:compiler_unsupported/src/filenames.dart' show appendSlash;
1413
import 'package:path/path.dart' as p;
1514

1615
import 'exceptions.dart';
@@ -51,16 +50,16 @@ abstract class CompilerProvider {
5150
/// Uses [provider] to communcate between dart2js and the caller. Returns a
5251
/// future that completes when compilation is done.
5352
///
54-
/// By default, the package root is assumed to be adjacent to [entrypoint], but
55-
/// if [packageRoot] is passed that will be used instead.
53+
/// By default, the .packages file is assumed to be adjacent to [entrypoint],
54+
/// but if [packageConfig] is passed that will be used instead.
5655
Future compile(String entrypoint, CompilerProvider provider,
5756
{Iterable<String> commandLineOptions,
5857
bool checked: false,
5958
bool csp: false,
6059
bool minify: true,
6160
bool verbose: false,
6261
Map<String, String> environment,
63-
String packageRoot,
62+
String packageConfig,
6463
bool analyzeAll: false,
6564
bool preserveUris: false,
6665
bool suppressWarnings: false,
@@ -89,7 +88,6 @@ Future compile(String entrypoint, CompilerProvider provider,
8988
if (platformBinaries != null) {
9089
options.add('--platform-binaries=$platformBinaries');
9190
}
92-
options.add('--use-old-frontend');
9391

9492
var sourceUrl = p.toUri(entrypoint);
9593
options.add("--out=$sourceUrl.js");
@@ -102,21 +100,22 @@ Future compile(String entrypoint, CompilerProvider provider,
102100
if (environment == null) environment = {};
103101
if (commandLineOptions != null) options.addAll(commandLineOptions);
104102

105-
if (packageRoot == null) {
106-
packageRoot = p.join(p.dirname(entrypoint), 'packages');
103+
if (packageConfig == null) {
104+
packageConfig = p.join(p.dirname(entrypoint), '.packages');
107105
} else {
108-
packageRoot = p.normalize(p.absolute(packageRoot));
106+
packageConfig = p.normalize(p.absolute(packageConfig));
109107
}
110108

111109
await compiler.compile(
112110
p.toUri(entrypoint),
113111
provider.libraryRoot,
114-
p.toUri(appendSlash(packageRoot)),
112+
null,
115113
provider.provideInput,
116114
provider.handleDiagnostic,
117115
options,
118116
provider.provideOutput,
119-
environment);
117+
environment,
118+
p.toUri(packageConfig));
120119
}
121120

122121
/// Returns whether [dart] looks like an entrypoint file.

0 commit comments

Comments
 (0)