| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Development server that compiles Dart to JS on the fly. | 5 /// Development server that compiles Dart to JS on the fly. |
| 6 library dev_compiler.src.server; | 6 library dev_compiler.src.server; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 | 11 |
| 12 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; | 12 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; |
| 13 import 'package:analyzer/file_system/memory_file_system.dart'; | 13 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart' | 14 import 'package:analyzer/src/generated/engine.dart' |
| 15 show AnalysisContext, ChangeSet; | 15 show AnalysisContext, ChangeSet; |
| 16 import 'package:analyzer/src/generated/error.dart'; | 16 import 'package:analyzer/src/generated/error.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:logging/logging.dart' show Level, Logger, LogRecord; | 18 import 'package:logging/logging.dart' show Level, Logger, LogRecord; |
| 19 import 'package:path/path.dart' as path; | 19 import 'package:path/path.dart' as path; |
| 20 import 'package:shelf/shelf.dart' as shelf; | 20 import 'package:shelf/shelf.dart' as shelf; |
| 21 import 'package:shelf/shelf_io.dart' as shelf; | 21 import 'package:shelf/shelf_io.dart' as shelf; |
| 22 import 'package:shelf_static/shelf_static.dart' as shelf_static; | 22 import 'package:shelf_static/shelf_static.dart' as shelf_static; |
| 23 | 23 |
| 24 import '../codegen/code_generator.dart' show CodeGenerator; | 24 import '../codegen/code_generator.dart' show CodeGenerator; |
| 25 import '../codegen/html_codegen.dart' show generateEntryHtml; | 25 import '../codegen/html_codegen.dart' show generateEntryHtml; |
| 26 import '../codegen/js_codegen.dart'; | 26 import '../codegen/js_codegen.dart'; |
| 27 import '../analysis_context.dart'; | 27 import '../analysis_context.dart'; |
| 28 import '../compiler.dart' show AbstractCompiler; | 28 import '../compiler.dart' show AbstractCompiler, createErrorReporter; |
| 29 import '../info.dart' | 29 import '../info.dart' |
| 30 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; | 30 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; |
| 31 import '../options.dart'; | 31 import '../options.dart'; |
| 32 import '../report.dart'; | 32 import '../report.dart'; |
| 33 import '../utils.dart'; | 33 import '../utils.dart'; |
| 34 | 34 |
| 35 import 'dependency_graph.dart'; | 35 import 'dependency_graph.dart'; |
| 36 | 36 |
| 37 /// Encapsulates the logic when the compiler is run as a development server. | 37 /// Encapsulates the logic when the compiler is run as a development server. |
| 38 class ServerCompiler extends AbstractCompiler { | 38 class ServerCompiler extends AbstractCompiler { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 222 |
| 223 // TODO(sigmund): allow running without a dir, but keep output in memory? | 223 // TODO(sigmund): allow running without a dir, but keep output in memory? |
| 224 var outDir = options.codegenOptions.outputDir; | 224 var outDir = options.codegenOptions.outputDir; |
| 225 if (outDir == null) { | 225 if (outDir == null) { |
| 226 print('error: devc in server mode also requires specifying and ' | 226 print('error: devc in server mode also requires specifying and ' |
| 227 'output location for generated code.'); | 227 'output location for generated code.'); |
| 228 exit(1); | 228 exit(1); |
| 229 } | 229 } |
| 230 var port = options.port; | 230 var port = options.port; |
| 231 var host = options.host; | 231 var host = options.host; |
| 232 var compiler = new ServerCompiler(context, options); | 232 var reporter = createErrorReporter(context, options); |
| 233 var compiler = new ServerCompiler(context, options, reporter: reporter); |
| 233 return new DevServer._(compiler, outDir, host, port, entryPath); | 234 return new DevServer._(compiler, outDir, host, port, entryPath); |
| 234 } | 235 } |
| 235 | 236 |
| 236 DevServer._(ServerCompiler compiler, this.outDir, this.host, this.port, | 237 DevServer._(ServerCompiler compiler, this.outDir, this.host, this.port, |
| 237 String entryPath) | 238 String entryPath) |
| 238 : this.compiler = compiler, | 239 : this.compiler = compiler, |
| 239 // TODO(jmesserly): this logic is duplicated in a few places | 240 // TODO(jmesserly): this logic is duplicated in a few places |
| 240 this._entryPath = compiler.options.sourceOptions.useImplicitHtml | 241 this._entryPath = compiler.options.sourceOptions.useImplicitHtml |
| 241 ? SourceResolverOptions.implicitHtmlFile | 242 ? SourceResolverOptions.implicitHtmlFile |
| 242 : entryPath; | 243 : entryPath; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 302 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 302 var src = resolver.resolveAbsolute(uri, actualUri); | 303 var src = resolver.resolveAbsolute(uri, actualUri); |
| 303 return src.exists() ? src : null; | 304 return src.exists() ? src : null; |
| 304 } | 305 } |
| 305 | 306 |
| 306 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); | 307 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); |
| 307 } | 308 } |
| 308 | 309 |
| 309 final _log = new Logger('dev_compiler.src.server'); | 310 final _log = new Logger('dev_compiler.src.server'); |
| 310 final _earlyErrorResult = new CheckerResults(const [], true); | 311 final _earlyErrorResult = new CheckerResults(const [], true); |
| OLD | NEW |