Skip to content

Commit

Permalink
Support running pub when it's not on the environment path (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Apr 3, 2018
1 parent bb44773 commit ccf432b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ install:
- ps: wget https://storage.googleapis.com/dart-archive/channels/dev/release/latest/sdk/dartsdk-windows-x64-release.zip -OutFile dart-sdk.zip
- cmd: echo "Unzipping dart-sdk..."
- cmd: 7z x dart-sdk.zip -o"C:\tools" -y > nul
- set PATH=%PATH%;C:\tools\dart-sdk\bin
- set PATH=%PATH%;%APPDATA%\Pub\Cache\bin
- cd webdev
- pub get && exit 0
- C:\tools\dart-sdk\bin\pub.bat get && exit 0

build: off

test_script:
- pub run test -j 1
- C:\tools\dart-sdk\bin\pub.bat run test -j 1

cache:
- C:\Users\appveyor\AppData\Roaming\Pub\Cache
4 changes: 4 additions & 0 deletions webdev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.3+1

- Support running `pub` when it's not in the environment path.

## 0.1.3

- Now runs on Windows.
Expand Down
4 changes: 2 additions & 2 deletions webdev/lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PackageExceptionDetails {
}

Future _runPubDeps() async {
var result = Process.runSync('pub', ['deps'], runInShell: true);
var result = Process.runSync(pubPath, ['deps']);

if (result.exitCode == 65 || result.exitCode == 66) {
throw new PackageException._(
Expand All @@ -47,7 +47,7 @@ Future _runPubDeps() async {

if (result.exitCode != 0) {
throw new ProcessException(
'pub',
pubPath,
['deps'],
'***OUT***\n${result.stdout}\n***ERR***\n${result.stderr}\n***',
exitCode);
Expand Down
17 changes: 17 additions & 0 deletions webdev/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';

final supportedBuildRunnerVersionRange = new VersionRange(
min: new Version(0, 8, 0),
includeMin: true,
max: new Version(0, 9, 0),
includeMax: false);

/// The path to the root directory of the SDK.
final String _sdkDir = (() {
// The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is
// "/path/to/sdk".
var aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable));
assert(FileSystemEntity.isFileSync(p.join(aboveExecutable, 'version')));
return aboveExecutable;
})();

final String dartPath =
p.join(_sdkDir, 'bin', Platform.isWindows ? 'dart.exe' : 'dart');
final String pubPath =
p.join(_sdkDir, 'bin', Platform.isWindows ? 'pub.bat' : 'pub');
2 changes: 1 addition & 1 deletion webdev/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: webdev
version: 0.1.3
version: 0.1.3+1
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/webdev
description: >-
Expand Down
21 changes: 4 additions & 17 deletions webdev/test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,14 @@ import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;
import 'package:test_process/test_process.dart';
import 'package:webdev/src/util.dart';

final _webdevBin = p.absolute(p.join('bin', 'webdev.dart'));

/// The path to the root directory of the SDK.
final String _sdkDir = (() {
// The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is
// "/path/to/sdk".
var aboveExecutable = p.dirname(p.dirname(Platform.resolvedExecutable));
assert(FileSystemEntity.isFileSync(p.join(aboveExecutable, 'version')));
return aboveExecutable;
})();

final String _dartPath = p.join(_sdkDir, 'bin', 'dart');
final String _pubPath = p.join(_sdkDir, 'bin', 'pub');

Future<TestProcess> _runWebDev(List<String> args, {String workingDirectory}) {
var fullArgs = [_webdevBin]..addAll(args);

return TestProcess.start(_dartPath, fullArgs,
return TestProcess.start(dartPath, fullArgs,
workingDirectory: workingDirectory);
}

Expand Down Expand Up @@ -218,10 +207,8 @@ dependencies:

test('should succeed with valid configuration', () async {
var exampleDirectory = p.absolute(p.join(p.current, '..', 'example'));
var process = await TestProcess.start(_pubPath, ['get'],
workingDirectory: exampleDirectory,
environment: _getPubEnvironment(),
runInShell: true);
var process = await TestProcess.start(pubPath, ['get'],
workingDirectory: exampleDirectory, environment: _getPubEnvironment());

await process.shouldExit(0);

Expand Down

0 comments on commit ccf432b

Please sign in to comment.