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:path/path.dart'; | 11 import 'package:path/path.dart'; |
12 | 12 |
13 import '../compiler.dart' show defaultRuntimeFiles; | 13 import '../compiler.dart' show defaultRuntimeFiles; |
14 import '../options.dart'; | 14 import '../options.dart'; |
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)] | 29 ? _ALIASED_RUNTIME_FILES[basename(file.path)] |
30 : null; | 30 : null; |
31 | 31 |
32 Directory _getRuntimeDir(CompilerOptions options) => new Directory( | 32 Directory _getRuntimeDir(CompilerOptions options) => new Directory( |
(...skipping 15 matching lines...) Expand all Loading... |
48 return files | 48 return files |
49 ..sort((File a, File b) { | 49 ..sort((File a, File b) { |
50 int pa = getPriorityIndex(a), pb = getPriorityIndex(b); | 50 int pa = getPriorityIndex(a), pb = getPriorityIndex(b); |
51 return pa != pb ? (pa - pb) : a.path.compareTo(b.path); | 51 return pa != pb ? (pa - pb) : a.path.compareTo(b.path); |
52 }); | 52 }); |
53 } | 53 } |
54 | 54 |
55 /// TODO(ochafik): Split / reuse [AbstractCompiler.getModuleName]. | 55 /// TODO(ochafik): Split / reuse [AbstractCompiler.getModuleName]. |
56 String getMainModuleName(CompilerOptions options) => | 56 String getMainModuleName(CompilerOptions options) => |
57 basename(withoutExtension(options.inputs.single)); | 57 basename(withoutExtension(options.inputs.single)); |
OLD | NEW |