@@ -2,6 +2,7 @@ import 'dart:io' as io;
22
33import 'package:file/file.dart' ;
44import 'package:file/local.dart' ;
5+ import 'package:file/memory.dart' ;
56import 'package:script_runner/src/config.dart' ;
67// ignore: no_leading_underscores_for_library_prefixes
78import 'package:script_runner/src/utils.dart' as _utils;
@@ -30,7 +31,7 @@ class RunnableScript {
3031
3132 /// The environment variables to run the script in.
3233 /// This map is appended to the one given in the config.
33- final Map <String , String >? env;
34+ final Map <String , String > env;
3435
3536 /// Other scripts in the config which are runnable by this script.
3637 /// The script loader pre-loads these as temporary aliases to allow combined scripts to be run.
@@ -57,7 +58,7 @@ class RunnableScript {
5758 required this .args,
5859 this .description,
5960 this .workingDir,
60- this .env,
61+ this .env = const {} ,
6162 FileSystem ? fileSystem,
6263 this .displayCmd = false ,
6364 this .appendNewline = false ,
@@ -94,23 +95,25 @@ class RunnableScript {
9495 description: description,
9596 displayCmd: displayCmd,
9697 appendNewline: appendNewline,
98+ env: map['env' ] as Map <String , String >? ?? {},
9799 );
98100 } catch (e) {
99101 throw StateError ('Failed to parse script, arguments: $map , $fileSystem . Error: $e ' );
100102 }
101103 }
102104
103105 /// Runs the current script with the given extra arguments.
104- Future <int > run (List <String > extraArgs) async {
106+ Future <int > run ([ List <String > extraArgs = const []] ) async {
105107 final effectiveArgs = args + extraArgs;
106108 final config = await ScriptRunnerConfig .get (_fileSystem);
107109
108110 final scrContents = _getScriptContents (config, extraArgs: extraArgs);
109111 final scrPath = _getScriptPath ();
112+ final scrFile = _fileSystem.file (scrPath);
110113
111- await _fileSystem. file (scrPath) .writeAsString (scrContents);
114+ await scrFile .writeAsString (scrContents);
112115
113- if (config.shell.os != OS .windows) {
116+ if (config.shell.os != OS .windows && _fileSystem is ! MemoryFileSystem ) {
114117 final result = await io.Process .run ("chmod" , ["u+x" , scrPath]);
115118 if (result.exitCode != 0 ) throw Exception (result.stderr);
116119 }
@@ -148,7 +151,7 @@ class RunnableScript {
148151 final result = await io.Process .start (
149152 config.shell.shell,
150153 [config.shell.shellExecFlag, scrPath],
151- environment: {...? config.env, ...? env},
154+ environment: {...? config.env, ...env},
152155 workingDirectory: workingDir ?? config.workingDir,
153156 mode: io.ProcessStartMode .inheritStdio,
154157 includeParentEnvironment: true ,
0 commit comments