Skip to content

Commit 44e727d

Browse files
refactor: remove Q library from Powershell SDK in favor of native promises (#944)
* Removed Q library in favor of native promises from pwsh subfolder * Changed function name inside a block comment to prevent it from being parsed in a test
1 parent ff62c9b commit 44e727d

File tree

8 files changed

+13
-411
lines changed

8 files changed

+13
-411
lines changed

powershell/Tests/L0/_suite.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/// <reference path="../../definitions/mocha.d.ts"/>
22
/// <reference path="../../definitions/node.d.ts"/>
3-
/// <reference path="../../definitions/Q.d.ts"/>
43

5-
import Q = require('q');
64
import assert = require('assert');
75
import psRunner = require('../lib/psRunner');
86
import path = require('path');

powershell/Tests/lib/psRunner.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/// <reference path="../../definitions/node.d.ts"/>
2-
/// <reference path="../../definitions/Q.d.ts"/>
32

4-
import Q = require('q');
53
import events = require('events');
64
import fs = require('fs');
75
import path = require('path');
@@ -21,7 +19,7 @@ class PSEngineRunner extends events.EventEmitter {
2119

2220
private _childProcess: child.ChildProcess;
2321
private _errors: string[];
24-
private _runDeferred: Q.Deferred<void>;
22+
private _runDeferred: Promise<void>;
2523
public stderr: string;
2624
public stdout: string;
2725

@@ -39,7 +37,7 @@ class PSEngineRunner extends events.EventEmitter {
3937
.then(() => {
4038
done();
4139
})
42-
.fail((err) => {
40+
.catch((err) => {
4341
done(err);
4442
});
4543
}
@@ -50,7 +48,6 @@ class PSEngineRunner extends events.EventEmitter {
5048
}
5149

5250
this.emit('starting');
53-
var defer = Q.defer<void>();
5451
var powershell = shell.which('powershell.exe').stdout;
5552
this._childProcess = child.spawn(
5653
powershell, // command
@@ -74,9 +71,9 @@ class PSEngineRunner extends events.EventEmitter {
7471
// Check for special ouput indicating end of test.
7572
if (('' + data).indexOf('_END_OF_TEST_ce10a77a_') >= 0) {
7673
if (this._errors.length > 0) {
77-
this._runDeferred.reject(this._errors.join('\n'));
74+
this._runDeferred = Promise.reject(this._errors.join('\n'));
7875
} else {
79-
this._runDeferred.resolve(null);
76+
this._runDeferred = Promise.resolve();
8077
}
8178
} else if (data != '\n') {
8279
if (('' + data).match(/##vso\[task.logissue .*type=error/)) {
@@ -98,12 +95,12 @@ class PSEngineRunner extends events.EventEmitter {
9895
});
9996
}
10097

101-
private runPromise(psPath: string): Q.Promise<void> {
98+
private runPromise(psPath: string): Promise<void> {
10299
this.emit('running test');
103100
this._errors = [];
104-
this._runDeferred = Q.defer<void>();
101+
this._runDeferred = Promise.resolve();
105102
this._childProcess.stdin.write(psPath + '\n')
106-
return <Q.Promise<void>>this._runDeferred.promise;
103+
return this._runDeferred;
107104
}
108105
}
109106

powershell/VstsTaskSdk/LocalizationFunctions.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ function Get-LocString {
6060

6161
<#
6262
.SYNOPSIS
63-
Imports resource strings for use with Get-VstsLocString.
63+
Imports resource strings for use with GetVstsLocString.
6464
6565
.DESCRIPTION
66-
Imports resource strings for use with Get-VstsLocString. The imported strings are stored in an internal resource string dictionary. Optionally, if a separate resource file for the current culture exists, then the localized strings from that file then imported (overlaid) into the same internal resource string dictionary.
66+
Imports resource strings for use with GetVstsLocString. The imported strings are stored in an internal resource string dictionary. Optionally, if a separate resource file for the current culture exists, then the localized strings from that file then imported (overlaid) into the same internal resource string dictionary.
6767
6868
Resource strings from the SDK are prefixed with "PSLIB_". This prefix should be avoided for custom resource strings.
6969

powershell/VstsTaskSdk/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"loc.messages.PSLIB_EnumeratingSubdirectoriesFailedForPath0": "Enumerating subdirectories failed for path: '{0}'",
77
"loc.messages.PSLIB_FileNotFound0": "File not found: '{0}'",
88
"loc.messages.PSLIB_Input0": "'{0}' input",
9-
"loc.messages.PSLIB_InvalidPattern0": "Path cannot end with a directory separator character: '{0}'",
9+
"loc.messages.PSLIB_InvalidPattern0": "Invalid pattern: '{0}'",
1010
"loc.messages.PSLIB_LeafPathNotFound0": "Leaf path not found: '{0}'",
1111
"loc.messages.PSLIB_PathLengthNotReturnedFor0": "Path normalization/expansion failed. The path length was not returned by the Kernel32 subsystem for: '{0}'",
1212
"loc.messages.PSLIB_PathNotFound0": "Path not found: '{0}'",
@@ -15,4 +15,4 @@
1515
"loc.messages.PSLIB_StringFormatFailed": "String format failed.",
1616
"loc.messages.PSLIB_StringResourceKeyNotFound0": "String resource key not found: '{0}'",
1717
"loc.messages.PSLIB_TaskVariable0": "'{0}' task variable"
18-
}
18+
}

powershell/definitions/Q.d.ts

Lines changed: 0 additions & 386 deletions
This file was deleted.

powershell/make.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ target.test = function() {
6666
target.build();
6767

6868
util.mkdir('-p', testPath);
69-
util.run(`tsc --outDir "${testPath}" --module commonjs --rootDir Tests Tests/lib/psRunner.ts`);
70-
util.run(`tsc --outDir "${testPath}" --rootDir Tests Tests/L0/_suite.ts`);
69+
util.run(`tsc --outDir "${testPath}" --module commonjs --target es6 --rootDir Tests Tests/lib/psRunner.ts`);
70+
util.run(`tsc --outDir "${testPath}" --module commonjs --target es6 --rootDir Tests Tests/L0/_suite.ts`);
7171
util.cp('-r', path.join('Tests', '*'), testPath);
7272
util.run('mocha "' + path.join(testPath, 'L0', '_suite.js') + '"');
7373
}

powershell/package-lock.json

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

powershell/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"devDependencies": {
2626
"adm-zip": "^0.5.9",
2727
"mocha": "5.2.0",
28-
"q": "1.4.1",
2928
"shelljs": "^0.8.5",
3029
"sync-request": "3.0.1",
3130
"typescript": "1.8.7"

0 commit comments

Comments
 (0)