@@ -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 }
0 commit comments