| 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 /// JS runtime files utilities used by dartdevrun. | 5 /// JS runtime files utilities used by dartdevrun. |
| 6 library dev_compiler.src.runner.runtime_utils; | 6 library dev_compiler.src.runner.runtime_utils; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| 11 import 'package:dev_compiler/src/compiler.dart' show defaultRuntimeFiles; | 11 import 'package:dev_compiler/src/compiler.dart' show defaultRuntimeFiles; |
| 12 import 'package:dev_compiler/src/options.dart'; | 12 import 'package:dev_compiler/src/options.dart'; |
| 13 import 'package:path/path.dart'; | 13 import 'package:path/path.dart'; |
| 14 | 14 |
| 15 import 'file_utils.dart'; | 15 import 'file_utils.dart'; |
| 16 | 16 |
| 17 /// In node.js / io.js, these modules need to be aliased globally | 17 /// In node.js / io.js, these modules need to be aliased globally |
| 18 /// (e.g. `var foo = require('./path/to/foo.js')`). | 18 /// (e.g. `var foo = require('./path/to/foo.js')`). |
| 19 /// TODO(ochafik): Investigate alternative module / alias patterns. | 19 /// TODO(ochafik): Investigate alternative module / alias patterns. |
| 20 const _ALIASED_RUNTIME_FILES = const { | 20 const _ALIASED_RUNTIME_FILES = const { |
| 21 'dart_library.js': 'dart_library', | 21 'dart_library.js': 'dart_library', |
| 22 'dart_utils.js': 'dart_utils', | 22 'dart_utils.js': 'dart_utils', |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 /// If [path] is a runtime file with an alias, returns that alias, otherwise | 25 /// If [path] is a runtime file with an alias, returns that alias, otherwise |
| 26 /// returns null. | 26 /// returns null. |
| 27 String getRuntimeFileAlias(CompilerOptions options, File file) => | 27 String getRuntimeFileAlias(CompilerOptions options, File file) => |
| 28 file.absolute.path.startsWith(_getRuntimeDir(options).absolute.path) | 28 file.absolute.path.startsWith(_getRuntimeDir(options).absolute.path) |
| 29 ? _ALIASED_RUNTIME_FILES[basename(file.path)] : null; | 29 ? _ALIASED_RUNTIME_FILES[basename(file.path)] |
| 30 : null; |
| 30 | 31 |
| 31 Directory _getRuntimeDir(CompilerOptions options) => new Directory( | 32 Directory _getRuntimeDir(CompilerOptions options) => new Directory( |
| 32 join(options.codegenOptions.outputDir, 'dev_compiler', 'runtime')); | 33 join(options.codegenOptions.outputDir, 'dev_compiler', 'runtime')); |
| 33 | 34 |
| 34 Future<List<File>> listOutputFiles(CompilerOptions options) async { | 35 Future<List<File>> listOutputFiles(CompilerOptions options) async { |
| 35 List<File> files = | 36 List<File> files = |
| 36 await listJsFiles(new Directory(options.codegenOptions.outputDir)); | 37 await listJsFiles(new Directory(options.codegenOptions.outputDir)); |
| 37 | 38 |
| 38 var runtimePath = _getRuntimeDir(options).absolute.path; | 39 var runtimePath = _getRuntimeDir(options).absolute.path; |
| 39 isRuntimeFile(File file) => file.path.startsWith(runtimePath); | 40 isRuntimeFile(File file) => file.path.startsWith(runtimePath); |
| 40 | 41 |
| 41 final maxIndex = defaultRuntimeFiles.length; | 42 final maxIndex = defaultRuntimeFiles.length; |
| 42 getPriorityIndex(File file) { | 43 getPriorityIndex(File file) { |
| 43 if (!isRuntimeFile(file)) return maxIndex; | 44 if (!isRuntimeFile(file)) return maxIndex; |
| 44 int i = defaultRuntimeFiles.indexOf(basename(file.path)); | 45 int i = defaultRuntimeFiles.indexOf(basename(file.path)); |
| 45 return i < 0 ? maxIndex : i; | 46 return i < 0 ? maxIndex : i; |
| 46 } | 47 } |
| 47 return files..sort((File a, File b) { | 48 return files |
| 48 int pa = getPriorityIndex(a), | 49 ..sort((File a, File b) { |
| 49 pb = getPriorityIndex(b); | 50 int pa = getPriorityIndex(a), pb = getPriorityIndex(b); |
| 50 return pa != pb ? (pa - pb) : a.path.compareTo(b.path); | 51 return pa != pb ? (pa - pb) : a.path.compareTo(b.path); |
| 51 }); | 52 }); |
| 52 } | 53 } |
| 53 | 54 |
| 54 /// TODO(ochafik): Split / reuse [AbstractCompiler.getModuleName]. | 55 /// TODO(ochafik): Split / reuse [AbstractCompiler.getModuleName]. |
| 55 String getMainModuleName(CompilerOptions options) => | 56 String getMainModuleName(CompilerOptions options) => |
| 56 basename(withoutExtension(options.inputs.single)); | 57 basename(withoutExtension(options.inputs.single)); |
| OLD | NEW |