Browse Source

The `DartSdk.install()` method now returns the path to the install directory

tags/v2.2.0
Cédric Belin 4 months ago
parent
commit
922672863c
4 changed files with 16 additions and 14 deletions
  1. +1
    -1
      lib/index.d.ts
  2. +9
    -3
      src/setup_dart/DartSdk.hx
  3. +1
    -0
      test.hxml
  4. +5
    -10
      test/setup_dart/DartSdkTest.hx

+ 1
- 1
lib/index.d.ts View File

@@ -6,7 +6,7 @@ export declare class DartSdk {
readonly releaseUrl: string;
version: string;
download(): Promise<string>;
install(): Promise<void>;
install(): Promise<string>;
}

export interface DartSdkOptions {


+ 9
- 3
src/setup_dart/DartSdk.hx View File

@@ -58,8 +58,11 @@ class DartSdk {
.then(file -> ToolCache.extractZip(file))
.then(path -> Path.join([path, "dart-sdk"]));

/** Installs this Dart SDK, after downloading it if required. **/
public function install(): Promise<Any> {
/**
Installs this Dart SDK, after downloading it if required.
Returns the path to the install directory.
**/
public function install(): Promise<String> {
final toolName = "dart-sdk";
var sdkDir = version != "latest" ? ToolCache.find(toolName, version, architecture) : "";

@@ -71,7 +74,10 @@ class DartSdk {
.then(_ -> ToolCache.cacheDir(sdkDir, toolName, version, architecture));
}

return promise.then(sdkDir -> Core.addPath(Path.join([sdkDir, "bin"])));
return promise.then(sdkDir -> {
Core.addPath(Path.join([sdkDir, "bin"]));
sdkDir;
});
}

/** Initializes the class. **/


+ 1
- 0
test.hxml View File

@@ -4,6 +4,7 @@
--js var/tests.js
--library hxnodejs
--library mcover
--library thenshim
--library utest
--macro mcover.MCover.coverage([''], ['src'])
--main TestAll

+ 5
- 10
test/setup_dart/DartSdkTest.hx View File

@@ -8,6 +8,7 @@ import utest.Async;
import utest.Test;

using StringTools;
using thenshim.PromiseTools;

/** Tests the features of the `DartSdk` class. **/
class DartSdkTest extends Test {
@@ -48,12 +49,9 @@ class DartSdkTest extends Test {
final executable = Sys.systemName() == "Windows" ? "dart.exe" : "dart";
Assert.isTrue(FileSystem.exists('$sdkDir/bin/$executable'));
Assert.equals("2.7.0", File.getContent('$sdkDir/version').rtrim());
async.done();
})
.catchError(e -> {
Assert.fail(Std.string(e));
async.done();
});
.catchError(e -> Assert.fail(Std.string(e)))
.finally(() -> async.done());
}

/** Tests the `install()` method. **/
@@ -65,11 +63,8 @@ class DartSdkTest extends Test {
.then(_ -> {
final path = Path.normalize('/dart-sdk/${dartSdk.version}/${dartSdk.architecture}/bin');
Assert.isTrue(Sys.getEnv("PATH").contains(path));
async.done();
})
.catchError(e -> {
Assert.fail(Std.string(e));
async.done();
});
.catchError(e -> Assert.fail(Std.string(e)))
.finally(() -> async.done());
}
}

Loading…
Cancel
Save