@@ -4,51 +4,43 @@ import 'dart:io';
4
4
import 'package:analyzer/dart/analysis/utilities.dart' ;
5
5
import 'package:args/command_runner.dart' ;
6
6
import 'package:dart_dev/dart_dev.dart' ;
7
- import 'package:dart_dev/src/dart_dev_tool.dart' ;
8
- import 'package:dart_dev/src/utils/format_tool_builder.dart' ;
9
- import 'package:dart_dev/src/utils/get_dart_version_comment.dart' ;
10
- import 'package:dart_dev/src/utils/parse_flag_from_args.dart' ;
11
7
import 'package:io/ansi.dart' ;
12
8
import 'package:io/io.dart' show ExitCode;
13
9
import 'package:logging/logging.dart' ;
14
10
import 'package:path/path.dart' as p;
15
11
16
- import '../utils.dart' ;
17
12
import 'dart_dev_runner.dart' ;
18
13
import 'tools/over_react_format_tool.dart' ;
19
14
import 'utils/assert_dir_is_dart_package.dart' ;
15
+ import 'utils/cached_pubspec.dart' ;
16
+ import 'utils/dart_dev_paths.dart' ;
20
17
import 'utils/dart_tool_cache.dart' ;
21
18
import 'utils/ensure_process_exit.dart' ;
19
+ import 'utils/format_tool_builder.dart' ;
20
+ import 'utils/get_dart_version_comment.dart' ;
22
21
import 'utils/logging.dart' ;
22
+ import 'utils/parse_flag_from_args.dart' ;
23
23
24
24
typedef _ConfigGetter = Map <String , DevTool > Function ();
25
25
26
- final _runScriptPath = p. join (cacheDirPath, 'run.dart' );
26
+ final paths = DartDevPaths ( );
27
27
28
- final _runScript = File (_runScriptPath);
29
-
30
- final _configPath = p.join ('tool' , 'dart_dev' , 'config.dart' );
31
-
32
- final _oldDevDartPath = p.join ('tool' , 'dev.dart' );
33
-
34
- final _relativeDevDartPath = p.relative (
35
- p.absolute (_configPath),
36
- from: p.absolute (p.dirname (_runScriptPath)),
37
- );
28
+ final _runScript = File (paths.runScript);
38
29
39
30
Future <void > run (List <String > args) async {
40
31
attachLoggerToStdio (args);
41
- final configExists = File (_configPath).existsSync ();
42
- final oldDevDartExists = File (_oldDevDartPath).existsSync ();
32
+
33
+ final configExists = File (paths.config).existsSync ();
34
+ final oldDevDartExists = File (paths.legacyConfig).existsSync ();
43
35
44
36
if (! configExists) {
45
- log.fine ('No custom `$_configPath ` file found; '
37
+ log.fine ('No custom `${ paths . config } ` file found; '
46
38
'using default config.' );
47
39
}
48
40
if (oldDevDartExists) {
49
41
log.warning (yellow.wrap (
50
- 'dart_dev v3 now expects configuration to be at `$_configPath `,\n '
51
- 'but `$_oldDevDartPath ` still exists. View the guide to see how to upgrade:\n '
42
+ 'dart_dev v3 now expects configuration to be at `${ paths . config } `,\n '
43
+ 'but `${ paths . legacyConfig } ` still exists. View the guide to see how to upgrade:\n '
52
44
'https://github.com/Workiva/dart_dev/blob/master/doc/v3-upgrade-guide.md' ));
53
45
}
54
46
@@ -60,7 +52,7 @@ Future<void> run(List<String> args) async {
60
52
61
53
generateRunScript ();
62
54
final process = await Process .start (
63
- Platform .executable, [_runScriptPath , ...args],
55
+ Platform .executable, [paths.runScript , ...args],
64
56
mode: ProcessStartMode .inheritStdio);
65
57
ensureProcessExit (process);
66
58
exitCode = await process.exitCode;
@@ -70,7 +62,7 @@ Future<void> handleFastFormat(List<String> args) async {
70
62
assertDirIsDartPackage ();
71
63
72
64
DevTool formatTool;
73
- final configFile = File (_configPath );
65
+ final configFile = File (paths.config );
74
66
if (configFile.existsSync ()) {
75
67
final toolBuilder = FormatToolBuilder ();
76
68
parseString (content: configFile.readAsStringSync ())
@@ -119,11 +111,11 @@ bool get shouldWriteRunScript =>
119
111
const _isDartDevNullSafe = false ;
120
112
121
113
String buildDartDevRunScriptContents () {
122
- final hasCustomToolDevDart = File (_configPath ).existsSync ();
114
+ final hasCustomToolDevDart = File (paths.config ).existsSync ();
123
115
// If the config has a dart version comment (e.g., if it opts out of null safety),
124
116
// copy it over to the entrypoint so the program is run in that language version.
125
117
var dartVersionComment = hasCustomToolDevDart
126
- ? getDartVersionComment (File (_configPath ).readAsStringSync ())
118
+ ? getDartVersionComment (File (paths.config ).readAsStringSync ())
127
119
: null ;
128
120
// If dart_dev itself is not null-safe, opt the entrypoint out of null-safety
129
121
// so the entrypoint doesn't fail to run in packages that have opted into null-safety.
@@ -137,7 +129,7 @@ import 'dart:io';
137
129
138
130
import 'package:dart_dev/src/core_config.dart';
139
131
import 'package:dart_dev/src/executable.dart' as executable;
140
- ${hasCustomToolDevDart ? "import '$_relativeDevDartPath ' as custom_dev;" : "" }
132
+ ${hasCustomToolDevDart ? "import '${ paths . configFromRunScriptForDart } ' as custom_dev;" : "" }
141
133
142
134
void main(List<String> args) async {
143
135
await executable.runWithConfig(args,
@@ -162,7 +154,7 @@ Future<void> runWithConfig(
162
154
config = configGetter ();
163
155
} catch (error) {
164
156
stderr
165
- ..writeln ('Invalid "$_configPath " in ${p .absolute (p .current )}' )
157
+ ..writeln ('Invalid "${ paths . config } " in ${p .absolute (p .current )}' )
166
158
..writeln ()
167
159
..writeln ('It should provide a `Map<String, DevTool> config;` getter,'
168
160
' but it either does not exist or threw unexpectedly:' )
0 commit comments