Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Unified Diff: sdk/lib/_internal/pub/lib/src/command/run.dart

Issue 330183003: Support paths outside of "bin" for pub run. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Test that root directory is served. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/lib/src/progress.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/command/run.dart
diff --git a/sdk/lib/_internal/pub/lib/src/command/run.dart b/sdk/lib/_internal/pub/lib/src/command/run.dart
index a315ae59f20014d975f31f0b24a0c35b0d4ba881..73b62be8b425e433c0ab2575ae089b1623b2aa3a 100644
--- a/sdk/lib/_internal/pub/lib/src/command/run.dart
+++ b/sdk/lib/_internal/pub/lib/src/command/run.dart
@@ -8,6 +8,7 @@ import 'dart:async';
import 'dart:io';
import 'package:barback/barback.dart';
+import 'package:path/path.dart' as path;
import 'package:stack_trace/stack_trace.dart';
import '../barback/asset_environment.dart';
@@ -38,6 +39,8 @@ class RunCommand extends PubCommand {
}
var environment;
+ var scriptPath;
+ var args;
return AssetEnvironment.create(entrypoint, BarbackMode.RELEASE,
WatcherType.NONE, useDart2JS: false)
.then((_environment) {
@@ -49,14 +52,27 @@ class RunCommand extends PubCommand {
log.error(log.red("Build error:\n$error"));
});
- return environment.serveDirectory("bin");
- }).then((server) {
var script = commandOptions.rest[0];
- var args = commandOptions.rest.skip(1).toList();
-
- // TODO(rnystrom): Support scripts in other directories.
- var scriptPath = "bin/$script.dart";
-
+ args = commandOptions.rest.skip(1).toList();
+
+ // If the command has a path separator, then it's a path relative to the
+ // root of the package. Otherwise, it's implicitly understood to be in
+ // "bin".
+ var rootDir;
+ var parts = path.split(script);
+ if (parts.length > 1) {
+ scriptPath = "$script.dart";
+ rootDir = parts.first;
+ } else {
+ scriptPath = "bin/$script.dart";
+ rootDir = "bin";
+ }
+
+ // Serve the entire root-most directory containing the entrypoint. That
+ // ensures that, for example, things like `import '../../utils.dart';`
+ // will work from within some deeply nested script.
+ return environment.serveDirectory(rootDir);
+ }).then((server) {
// Try to make sure the entrypoint script exists (or is generated) before
// we spawn the process to run it.
return environment.barback.getAssetById(
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/lib/src/progress.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698