Skip to content

Commit

Permalink
Add support for serving a custom DevTools build (#2748)
Browse files Browse the repository at this point in the history
The Dart SDK will use a pinned version pre-built version of DevTools.
This means that DDS requires a way to provide a path to the pinned build
to devtools_server in order to correctly serve the application.
  • Loading branch information
bkonyi committed Feb 26, 2021
1 parent 6e5983f commit 7686580
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
13 changes: 9 additions & 4 deletions packages/devtools_server/lib/src/external_handlers.dart
Expand Up @@ -27,18 +27,23 @@ import 'server_api.dart';
/// DevTools project.
Future<shelf.Handler> defaultHandler(
ClientManager clients, {
String customDevToolsPath,
bool debugMode = false,
}) async {
final resourceUri = await Isolate.resolvePackageUri(
Uri(scheme: 'package', path: 'devtools/devtools.dart'));
String buildDir = customDevToolsPath;
if (buildDir == null) {
final resourceUri = await Isolate.resolvePackageUri(
Uri(scheme: 'package', path: 'devtools/devtools.dart'));

final packageDir = path.dirname(path.dirname(resourceUri.toFilePath()));
final packageDir = path.dirname(path.dirname(resourceUri.toFilePath()));
buildDir = path.join(packageDir, 'build');
}

// Default static handler for all non-package requests.
Handler buildDirHandler;
if (!debugMode) {
buildDirHandler = createStaticHandler(
path.join(packageDir, 'build'),
buildDir,
defaultDocument: 'index.html',
);
}
Expand Down
14 changes: 12 additions & 2 deletions packages/devtools_server/lib/src/server.dart
Expand Up @@ -145,7 +145,12 @@ Future<void> _serveDevToolsWithArgs(
///
/// `handler` is the [shelf.Handler] that the server will use for all requests.
/// If null, [defaultHandler] will be used. Defaults to null.
// Note: this method is used by the Flutter CLI and by package:dwds.
///
/// `customDevToolsPath` is a path to a directory containing a pre-built
/// DevTools application. If not provided, the pre-built DevTools application
/// shipped via pub will be used.
///
// Note: this method is used by the Dart CLI, Flutter CLI, and by package:dwds.
Future<HttpServer> serveDevTools({
bool enableStdinCommands = true,
bool machineMode = false,
Expand All @@ -156,6 +161,7 @@ Future<HttpServer> serveDevTools({
bool headlessMode = false,
bool verboseMode = false,
String hostname,
String customDevToolsPath,
int port = 0,
int numPortsToTry = defaultTryPorts,
shelf.Handler handler,
Expand All @@ -180,7 +186,11 @@ Future<HttpServer> serveDevTools({

clients = ClientManager(enableNotifications);

handler ??= await defaultHandler(clients, debugMode: debugMode);
handler ??= await defaultHandler(
clients,
customDevToolsPath: customDevToolsPath,
debugMode: debugMode,
);

HttpServer server;
SocketException ex;
Expand Down

0 comments on commit 7686580

Please sign in to comment.