@@ -134,13 +134,13 @@ class Dart2JSTransformer extends Transformer implements LazyTransformer {
134
134
135
135
var entrypoint = _environment.graph.packages[id.package].path (id.path);
136
136
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.
139
139
// Source-maps contain relative URLs to package sources and these relative
140
140
// URLs should be self-contained within the paths served by pub-serve.
141
141
// See #1511 for details.
142
142
var buildDir = _environment.getSourceDirectoryContaining (id.path);
143
- var packageRoot = _environment.rootPackage.path (buildDir, "packages" );
143
+ var packageConfig = _environment.rootPackage.path (buildDir, ". packages" );
144
144
145
145
// TODO(rnystrom): Should have more sophisticated error-handling here. Need
146
146
// to report compile errors to the user in an easily visible way. Need to
@@ -154,7 +154,7 @@ class Dart2JSTransformer extends Transformer implements LazyTransformer {
154
154
defaultsTo: _settings.mode == BarbackMode .RELEASE ),
155
155
verbose: _configBool ('verbose' ),
156
156
environment: _configEnvironment,
157
- packageRoot : packageRoot ,
157
+ packageConfig : packageConfig ,
158
158
analyzeAll: _configBool ('analyzeAll' ),
159
159
preserveUris: _configBool ('preserveUris' ),
160
160
suppressWarnings: _configBool ('suppressWarnings' ),
@@ -223,6 +223,7 @@ class _BarbackCompilerProvider implements dart.CompilerProvider {
223
223
final AssetEnvironment _environment;
224
224
final Transform _transform;
225
225
String _libraryRootPath;
226
+ String _packagesFileContents;
226
227
227
228
/// The map of previously loaded files.
228
229
///
@@ -279,6 +280,18 @@ class _BarbackCompilerProvider implements dart.CompilerProvider {
279
280
.getSourceDirectoryContaining (_transform.primaryInput.id.path);
280
281
_libraryRootPath =
281
282
_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 ' ;
282
295
}
283
296
284
297
/// A [CompilerInputProvider] for dart2js.
@@ -400,6 +413,8 @@ class _BarbackCompilerProvider implements dart.CompilerProvider {
400
413
if (id != null ) {
401
414
if (id.extension == '.dill' ) {
402
415
return collectBytes (_transform.readInput (id));
416
+ } else if (id.path.endsWith ('/.packages' )) {
417
+ return _packagesFileContents;
403
418
} else {
404
419
return _transform.readInputAsString (id);
405
420
}
0 commit comments