diff --git a/lib/src/executable.dart b/lib/src/executable.dart index c863cd3e..c8bcc118 100644 --- a/lib/src/executable.dart +++ b/lib/src/executable.dart @@ -33,7 +33,7 @@ void main(List args) { if (options['version'] as bool) { _loadVersion().then((version) { print(version); - exit(0); + exitCode = 0; }); return; } @@ -42,7 +42,8 @@ void main(List args) { print("Compile Sass to CSS.\n"); print("Usage: dart-sass \n"); print(argParser.usage); - exit(64); + exitCode = 64; + return; } var color = options['color'] as bool; @@ -60,7 +61,7 @@ void main(List args) { // Exit code 65 indicates invalid data per // http://www.freebsd.org/cgi/man.cgi?query=sysexits. - exit(65); + exitCode = 65; } catch (error, stackTrace) { if (color) stderr.write('\u001b[31m\u001b[1m'); stderr.write('Unexpected exception:'); @@ -71,6 +72,7 @@ void main(List args) { stderr.writeln(); stderr.write(new Trace.from(stackTrace).terse.toString()); stderr.flush(); + exitCode = 255; } } diff --git a/lib/src/io/interface.dart b/lib/src/io/interface.dart index 33676aef..cd735d44 100644 --- a/lib/src/io/interface.dart +++ b/lib/src/io/interface.dart @@ -26,5 +26,5 @@ String readFile(String path) => null; /// Returns whether a file at [path] exists. bool fileExists(String path) => null; -/// Exits the process with the given [exitCode]. -void exit(int exitCode) {} +/// Gets and sets the exit code that the process will use when it exits. +int exitCode; diff --git a/lib/src/io/node.dart b/lib/src/io/node.dart index 5993b31a..fa2f9740 100644 --- a/lib/src/io/node.dart +++ b/lib/src/io/node.dart @@ -44,5 +44,8 @@ external _Stderr get _stderr; final stderr = new Stderr(_stderr); -@JS("process.exit") -external int exit(int exitCode); +@JS("process.exitCode") +external int get exitCode; + +@JS("process.exitCode") +external set exitCode(int code); diff --git a/lib/src/io/vm.dart b/lib/src/io/vm.dart index a49a7167..9f7d610d 100644 --- a/lib/src/io/vm.dart +++ b/lib/src/io/vm.dart @@ -4,10 +4,10 @@ import 'dart:io' as io; +export 'dart:io' show exitCode; + io.Stdout get stderr => io.stderr; String readFile(String path) => new io.File(path).readAsStringSync(); bool fileExists(String path) => new io.File(path).existsSync(); - -void exit(int exitCode) => io.exit(exitCode);