@@ -2,10 +2,13 @@ import 'dart:io';
22import 'package:mason/mason.dart' ;
33import 'package:path/path.dart' as path;
44import 'package:yaml/yaml.dart' ;
5+ import 'package:yaml_edit/yaml_edit.dart' ;
56
67/// A void callback function (e.g. `void Function()` ).
78typedef VoidCallback = void Function ();
89
10+ void _noop () {}
11+
912/// Opts out of dart workspaces until we can generate per package lockfiles.
1013/// https://github.com/dart-lang/pub/issues/4594
1114VoidCallback disableWorkspaceResolution (
@@ -18,7 +21,7 @@ VoidCallback disableWorkspaceResolution(
1821 } on Exception catch (e) {
1922 context.logger.err ('$e ' );
2023 exit (1 );
21- return () {} ;
24+ return _noop ;
2225 }
2326}
2427
@@ -35,12 +38,15 @@ void Function() overrideResolutionInPubspecOverrides(String projectDirectory) {
3538 final contents = pubspecOverridesFile.readAsStringSync ();
3639 final pubspecOverrides = loadYaml (contents) as YamlMap ? ;
3740
38- if (pubspecOverrides? ['resolution' ] == 'null' ) return () {};
39- pubspecOverridesFile.writeAsStringSync (
40- '''
41- resolution: null
42- $contents ''' ,
43- );
41+ if (pubspecOverrides == null ) {
42+ pubspecOverridesFile.writeAsStringSync ('resolution: null' );
43+ return () => pubspecOverridesFile.writeAsStringSync (contents);
44+ }
45+
46+ if (pubspecOverrides['resolution' ] == 'null' ) return _noop;
47+
48+ final editor = YamlEditor (contents)..update (['resolution' ], null );
49+ pubspecOverridesFile.writeAsStringSync (editor.toString ());
4450
4551 return () => pubspecOverridesFile.writeAsStringSync (contents);
4652}
0 commit comments