Skip to content

Commit

Permalink
Revert "refactor: remove Q library from Powershell SDK in favor of na…
Browse files Browse the repository at this point in the history
…tive promises (#944)"

This reverts commit 44e727d.
  • Loading branch information
KonstantinTyukalov committed Oct 9, 2023
1 parent 7625c87 commit a703a0a
Show file tree
Hide file tree
Showing 8 changed files with 411 additions and 13 deletions.
2 changes: 2 additions & 0 deletions powershell/Tests/L0/_suite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// <reference path="../../definitions/mocha.d.ts"/>
/// <reference path="../../definitions/node.d.ts"/>
/// <reference path="../../definitions/Q.d.ts"/>

import Q = require('q');
import assert = require('assert');
import psRunner = require('../lib/psRunner');
import path = require('path');
Expand Down
17 changes: 10 additions & 7 deletions powershell/Tests/lib/psRunner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// <reference path="../../definitions/node.d.ts"/>
/// <reference path="../../definitions/Q.d.ts"/>

import Q = require('q');
import events = require('events');
import fs = require('fs');
import path = require('path');
Expand All @@ -19,7 +21,7 @@ class PSEngineRunner extends events.EventEmitter {

private _childProcess: child.ChildProcess;
private _errors: string[];
private _runDeferred: Promise<void>;
private _runDeferred: Q.Deferred<void>;
public stderr: string;
public stdout: string;

Expand All @@ -37,7 +39,7 @@ class PSEngineRunner extends events.EventEmitter {
.then(() => {
done();
})
.catch((err) => {
.fail((err) => {
done(err);
});
}
Expand All @@ -48,6 +50,7 @@ class PSEngineRunner extends events.EventEmitter {
}

this.emit('starting');
var defer = Q.defer<void>();
var powershell = shell.which('powershell.exe').stdout;
this._childProcess = child.spawn(
powershell, // command
Expand All @@ -71,9 +74,9 @@ class PSEngineRunner extends events.EventEmitter {
// Check for special ouput indicating end of test.
if (('' + data).indexOf('_END_OF_TEST_ce10a77a_') >= 0) {
if (this._errors.length > 0) {
this._runDeferred = Promise.reject(this._errors.join('\n'));
this._runDeferred.reject(this._errors.join('\n'));
} else {
this._runDeferred = Promise.resolve();
this._runDeferred.resolve(null);
}
} else if (data != '\n') {
if (('' + data).match(/##vso\[task.logissue .*type=error/)) {
Expand All @@ -95,12 +98,12 @@ class PSEngineRunner extends events.EventEmitter {
});
}

private runPromise(psPath: string): Promise<void> {
private runPromise(psPath: string): Q.Promise<void> {
this.emit('running test');
this._errors = [];
this._runDeferred = Promise.resolve();
this._runDeferred = Q.defer<void>();
this._childProcess.stdin.write(psPath + '\n')
return this._runDeferred;
return <Q.Promise<void>>this._runDeferred.promise;
}
}

Expand Down
4 changes: 2 additions & 2 deletions powershell/VstsTaskSdk/LocalizationFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ function Get-LocString {

<#
.SYNOPSIS
Imports resource strings for use with GetVstsLocString.
Imports resource strings for use with Get-VstsLocString.
.DESCRIPTION
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.
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.
Resource strings from the SDK are prefixed with "PSLIB_". This prefix should be avoided for custom resource strings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"loc.messages.PSLIB_EnumeratingSubdirectoriesFailedForPath0": "Enumerating subdirectories failed for path: '{0}'",
"loc.messages.PSLIB_FileNotFound0": "File not found: '{0}'",
"loc.messages.PSLIB_Input0": "'{0}' input",
"loc.messages.PSLIB_InvalidPattern0": "Invalid pattern: '{0}'",
"loc.messages.PSLIB_InvalidPattern0": "Path cannot end with a directory separator character: '{0}'",
"loc.messages.PSLIB_LeafPathNotFound0": "Leaf path not found: '{0}'",
"loc.messages.PSLIB_PathLengthNotReturnedFor0": "Path normalization/expansion failed. The path length was not returned by the Kernel32 subsystem for: '{0}'",
"loc.messages.PSLIB_PathNotFound0": "Path not found: '{0}'",
Expand All @@ -15,4 +15,4 @@
"loc.messages.PSLIB_StringFormatFailed": "String format failed.",
"loc.messages.PSLIB_StringResourceKeyNotFound0": "String resource key not found: '{0}'",
"loc.messages.PSLIB_TaskVariable0": "'{0}' task variable"
}
}
386 changes: 386 additions & 0 deletions powershell/definitions/Q.d.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions powershell/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ target.test = function() {
target.build();

util.mkdir('-p', testPath);
util.run(`tsc --outDir "${testPath}" --module commonjs --target es6 --rootDir Tests Tests/lib/psRunner.ts`);
util.run(`tsc --outDir "${testPath}" --module commonjs --target es6 --rootDir Tests Tests/L0/_suite.ts`);
util.run(`tsc --outDir "${testPath}" --module commonjs --rootDir Tests Tests/lib/psRunner.ts`);
util.run(`tsc --outDir "${testPath}" --rootDir Tests Tests/L0/_suite.ts`);
util.cp('-r', path.join('Tests', '*'), testPath);
util.run('mocha "' + path.join(testPath, 'L0', '_suite.js') + '"');
}
Expand Down
6 changes: 6 additions & 0 deletions powershell/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions powershell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"adm-zip": "^0.5.9",
"deasync": "^0.1.28",
"mocha": "5.2.0",
"q": "1.4.1",
"shelljs": "^0.8.5",
"typescript": "1.8.7",
"nodejs-file-downloader": "^4.11.1"
Expand Down

0 comments on commit a703a0a

Please sign in to comment.