OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Common methods used by transfomers for dealing with asset IDs. | 5 /// Common methods used by transfomers for dealing with asset IDs. |
6 library code_transformers.assets; | 6 library code_transformers.assets; |
7 | 7 |
8 import 'dart:math' show min, max; | 8 import 'dart:math' show min, max; |
9 | 9 |
10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 var assetsIndex = segments.indexOf('assets'); | 57 var assetsIndex = segments.indexOf('assets'); |
58 var index = (packagesIndex >= 0 && assetsIndex >= 0) | 58 var index = (packagesIndex >= 0 && assetsIndex >= 0) |
59 ? min(packagesIndex, assetsIndex) | 59 ? min(packagesIndex, assetsIndex) |
60 : max(packagesIndex, assetsIndex); | 60 : max(packagesIndex, assetsIndex); |
61 if (index > -1) { | 61 if (index > -1) { |
62 if (entryFolder) { | 62 if (entryFolder) { |
63 // URLs of the form "packages/foo/bar" seen under entry folders (like | 63 // URLs of the form "packages/foo/bar" seen under entry folders (like |
64 // web/, test/, example/, etc) are resolved as an asset in another | 64 // web/, test/, example/, etc) are resolved as an asset in another |
65 // package. 'packages' can be used anywhere, there is no need to walk up | 65 // package. 'packages' can be used anywhere, there is no need to walk up |
66 // where the entrypoint file was. | 66 // where the entrypoint file was. |
| 67 // TODO(sigmund): this needs to change: Only resolve when index == 1 && |
| 68 // topFolder == segment[0], otherwise give a warning (dartbug.com/17596). |
67 return _extractOtherPackageId(index, segments, logger, span); | 69 return _extractOtherPackageId(index, segments, logger, span); |
68 } else if (index == 1 && segments[0] == '..') { | 70 } else if (index == 1 && segments[0] == '..') { |
69 // Relative URLs of the form "../../packages/foo/bar" in an asset under | 71 // Relative URLs of the form "../../packages/foo/bar" in an asset under |
70 // lib/ or asset/ are also resolved as an asset in another package, but we | 72 // lib/ or asset/ are also resolved as an asset in another package, but we |
71 // check that the relative path goes all the way out where the packages | 73 // check that the relative path goes all the way out where the packages |
72 // folder lives (otherwise the app would not work in Dartium). Since | 74 // folder lives (otherwise the app would not work in Dartium). Since |
73 // [targetPath] has been normalized, "packages" or "assets" should be at | 75 // [targetPath] has been normalized, "packages" or "assets" should be at |
74 // index 1. | 76 // index 1. |
75 return _extractOtherPackageId(1, segments, logger, span); | 77 return _extractOtherPackageId(1, segments, logger, span); |
76 } else { | 78 } else { |
(...skipping 21 matching lines...) Expand all Loading... |
98 if (prefix != 'packages' && prefix != 'assets') return null; | 100 if (prefix != 'packages' && prefix != 'assets') return null; |
99 var folder = prefix == 'packages' ? 'lib' : 'asset'; | 101 var folder = prefix == 'packages' ? 'lib' : 'asset'; |
100 if (segments.length < index + 3) { | 102 if (segments.length < index + 3) { |
101 logger.warning("incomplete $prefix/ path. It should have at least 3 " | 103 logger.warning("incomplete $prefix/ path. It should have at least 3 " |
102 "segments $prefix/name/path-from-name's-$folder-dir", span: span); | 104 "segments $prefix/name/path-from-name's-$folder-dir", span: span); |
103 return null; | 105 return null; |
104 } | 106 } |
105 return new AssetId(segments[index + 1], | 107 return new AssetId(segments[index + 1], |
106 path.url.join(folder, path.url.joinAll(segments.sublist(index + 2)))); | 108 path.url.join(folder, path.url.joinAll(segments.sublist(index + 2)))); |
107 } | 109 } |
OLD | NEW |