Skip to content
Snippets Groups Projects
Commit a3146387 authored by cbracken@google.com's avatar cbracken@google.com Committed by Natalie Weizenbaum
Browse files

Read package:browser .js files from barback rather than from packages directory.

The previous code assumes that the packages/ directory exists. This will no
longer be the case if the package-spec DEP is implemented. Also resolves a
breaking edge-case: if a pubspec.lock exists but the packages directory has
been deleted, pub build will terminate with a file not found.

BUG=
R=rnystrom@google.com

Review URL: https://codereview.chromium.org//1000193004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@44468 260f80e4-7a28-3924-810f-c04153c831b5
parent e1439253
No related branches found
No related tags found
No related merge requests found
......@@ -93,7 +93,8 @@ class BuildCommand extends BarbackCommand {
.map((asset) => asset.id);
return Future.wait(assets.map(_writeAsset)).then((_) {
builtFiles += _copyBrowserJsFiles(dart2JSEntrypoints);
return _copyBrowserJsFiles(dart2JSEntrypoints, assets);
}).then((_) {
log.message('Built $builtFiles ${pluralize('file', builtFiles)} '
'to "$outputDirectory".');
......@@ -190,13 +191,11 @@ class BuildCommand extends BarbackCommand {
/// If this package depends directly on the `browser` package, this ensures
/// that the JavaScript bootstrap files are copied into `packages/browser/`
/// directories next to each entrypoint in [entrypoints].
///
/// Returns the number of files it copied.
int _copyBrowserJsFiles(Iterable<AssetId> entrypoints) {
Future _copyBrowserJsFiles(Iterable<AssetId> entrypoints, AssetSet assets) {
// Must depend on the browser package.
if (!entrypoint.root.immediateDependencies.any(
(dep) => dep.name == 'browser' && dep.source == 'hosted')) {
return 0;
return new Future.value();
}
// Get all of the subdirectories that contain Dart entrypoints.
......@@ -209,29 +208,17 @@ class BuildCommand extends BarbackCommand {
.where((dir) => path.split(dir).length > 1)
.toSet();
for (var dir in entrypointDirs) {
var jsAssets = assets.where((asset) =>
asset.id.package == 'browser' && asset.id.extension == '.js');
return Future.wait(entrypointDirs.expand((dir) {
// TODO(nweiz): we should put browser JS files next to any HTML file
// rather than any entrypoint. An HTML file could import an entrypoint
// that's not adjacent.
_addBrowserJs(dir, "dart");
_addBrowserJs(dir, "interop");
}
return entrypointDirs.length * 2;
}
// TODO(nweiz): do something more principled when issue 6101 is fixed.
/// Ensures that the [name].js file is copied into [directory] in [target],
/// under `packages/browser/`.
void _addBrowserJs(String directory, String name) {
var jsPath = entrypoint.root.path(
outputDirectory, directory, 'packages', 'browser', '$name.js');
ensureDir(path.dirname(jsPath));
// TODO(rnystrom): This won't work if we get rid of symlinks and the top
// level "packages" directory. Will need to copy from the browser
// directory.
copyFile(path.join(entrypoint.packagesDir, 'browser', '$name.js'), jsPath);
return jsAssets.map((asset) {
var jsPath = path.join(dir, _idToPath(asset.id));
return _writeOutputFile(asset, jsPath);
});
}));
}
/// Converts [entry] to a JSON object for use with JSON-formatted output.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment