Skip to content

Commit

Permalink
refactor: remove Q library from Powershell SDK in favor of native pro…
Browse files Browse the repository at this point in the history
…mises (microsoft#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
  • Loading branch information
aleksandrlevochkin committed Aug 14, 2023
1 parent ff62c9b commit 44e727d
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 411 deletions.
2 changes: 0 additions & 2 deletions powershell/Tests/L0/_suite.ts
@@ -1,8 +1,6 @@
/// <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: 7 additions & 10 deletions powershell/Tests/lib/psRunner.ts
@@ -1,7 +1,5 @@
/// <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 @@ -21,7 +19,7 @@ class PSEngineRunner extends events.EventEmitter {

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

Expand All @@ -39,7 +37,7 @@ class PSEngineRunner extends events.EventEmitter {
.then(() => {
done();
})
.fail((err) => {
.catch((err) => {
done(err);
});
}
Expand All @@ -50,7 +48,6 @@ 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 @@ -74,9 +71,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.reject(this._errors.join('\n'));
this._runDeferred = Promise.reject(this._errors.join('\n'));
} else {
this._runDeferred.resolve(null);
this._runDeferred = Promise.resolve();
}
} else if (data != '\n') {
if (('' + data).match(/##vso\[task.logissue .*type=error/)) {
Expand All @@ -98,12 +95,12 @@ class PSEngineRunner extends events.EventEmitter {
});
}

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

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

<#
.SYNOPSIS
Imports resource strings for use with Get-VstsLocString.
Imports resource strings for use with GetVstsLocString.
.DESCRIPTION
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.
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.
Resource strings from the SDK are prefixed with "PSLIB_". This prefix should be avoided for custom resource strings.
Expand Down
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": "Path cannot end with a directory separator character: '{0}'",
"loc.messages.PSLIB_InvalidPattern0": "Invalid pattern: '{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: 0 additions & 386 deletions powershell/definitions/Q.d.ts

This file was deleted.

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

util.mkdir('-p', testPath);
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.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.cp('-r', path.join('Tests', '*'), testPath);
util.run('mocha "' + path.join(testPath, 'L0', '_suite.js') + '"');
}
Expand Down
6 changes: 0 additions & 6 deletions powershell/package-lock.json

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

1 change: 0 additions & 1 deletion powershell/package.json
Expand Up @@ -25,7 +25,6 @@
"devDependencies": {
"adm-zip": "^0.5.9",
"mocha": "5.2.0",
"q": "1.4.1",
"shelljs": "^0.8.5",
"sync-request": "3.0.1",
"typescript": "1.8.7"
Expand Down

0 comments on commit 44e727d

Please sign in to comment.