Skip to content

Commit 8b3f34d

Browse files
DmitriiBobreshevismayilov-ismayilKonstantin TyukalovKonstantinTyukalov
authored
[Deasync remove] - Remove deasync from task-lib (#1002)
* Removed unsupported lib, added async methods (#932) * Removed unsupported lib, added async methods * Update 3rd party library change to async * Format style in ThirdPartyNotice * [Deasync remove] - Remove deasync from task-lib - Remove deasync from node build process * [Deasync remove] - Remove deasync from task-lib - Remove deasync from node build process * [Deasync remove] - Remove deasync from task-lib - Remove deasync from node build process - Fixed unit tests - Updated json * Added publish script for PowerShell SDK (#975) * simple yampl to create pipeline * Add additional steps into pipeline to publish nuget feed * Upgrade net framework version * Revert csproj changes * Specify msbuild version for old netframework support * Add arch argument to msbuild installation * Bump package version * Use nuspec version directly * Fix downloadFileAsync * rm committed minimatch dll * Move publish steps to job + temp disable it * Move version to package back. Fix encoding * Add publish script * Update tags * update company metadata * Update to publish to powershell gallery --------- Co-authored-by: Konstantin Tyukalov <[email protected]> Co-authored-by: Konstantin Tyukalov <[email protected]> * [Deasync remove] - Remove deasync from task-lib - Code review changes --------- Co-authored-by: İsmayıl İsmayılov <[email protected]> Co-authored-by: Konstantin Tyukalov <[email protected]> Co-authored-by: Konstantin Tyukalov <[email protected]>
1 parent 6bbd1e8 commit 8b3f34d

16 files changed

+462
-620
lines changed

ci/powershell/publish-job.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
jobs:
2+
- job: Publish
3+
displayName: Publish SDK to PowerShell gallery
4+
pool:
5+
vmImage: windows-2022
6+
steps:
7+
- powershell: |
8+
Install-Module -Name Microsoft.PowerShell.PSResourceGet -Verbose
9+
displayName: Install new publish cmdlets
10+
11+
- powershell: |
12+
$publishOptions = @{
13+
Path = './VstsTaskSdk'
14+
ApiKey = $env:API_KEY
15+
Repository = 'PSGallery'
16+
Verbose = $true
17+
}
18+
Publish-PSResource @publishOptions
19+
20+
displayName: Publish to gallery
21+
workingDirectory: powershell/_build
22+
env:
23+
API_KEY: $(PSGalleryApiKey)

node/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ Backported from ver.`3.4.0`:
4848
## 4.4.0
4949

5050
- Add `getBoolFeatureFlag` [#936](https://github.com/microsoft/azure-pipelines-task-lib/pull/936)
51+
52+
## 4.6.0
53+
54+
- Replaced deprecated "sync-request" lib and Added new Async methods - [#932](https://github.com/microsoft/azure-pipelines-task-lib/pull/932)
55+
56+
## 5.0.0-preview.0
57+
58+
- [Mockery replacement] - Replaced mockery with similar adapter - [#968](https://github.com/microsoft/azure-pipelines-task-lib/pull/968)

node/ThirdPartyNotice.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This Azure Pipelines extension (azure-pipelines-task-lib) is based on or incorpo
3636
30. semver (git+https://github.com/npm/node-semver.git)
3737
31. shelljs (git://github.com/arturadib/shelljs.git)
3838
32. string_decoder (git://github.com/rvagg/string_decoder.git)
39-
33. sync-request (git+https://github.com/ForbesLindesay/sync-request.git)
39+
33. nodejs-file-downloader (git://github.com/ibrod83/nodejs-file-downloader.git)
4040
34. then-request (git+https://github.com/then/then-request.git)
4141
35. typedarray (git://github.com/substack/typedarray.git)
4242
36. typescript (git+https://github.com/Microsoft/TypeScript.git)
@@ -889,7 +889,8 @@ IN THE SOFTWARE.
889889
=========================================
890890
END OF string_decoder NOTICES, INFORMATION, AND LICENSE
891891

892-
%% sync-request NOTICES, INFORMATION, AND LICENSE BEGIN HERE
892+
893+
%% nodejs-file-downloader NOTICES, INFORMATION, AND LICENSE BEGIN HERE
893894
=========================================
894895
Copyright (c) 2014 Forbes Lindesay
895896

@@ -911,7 +912,8 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
911912
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
912913
THE SOFTWARE.
913914
=========================================
914-
END OF sync-request NOTICES, INFORMATION, AND LICENSE
915+
END OF nodejs-file-downloader NOTICES, INFORMATION, AND LICENSE
916+
915917

916918
%% then-request NOTICES, INFORMATION, AND LICENSE BEGIN HERE
917919
=========================================

node/buildutils.js

+67-62
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ var fs = require('fs');
44
var os = require('os');
55
var path = require('path');
66
var process = require('process');
7-
var syncRequest = require('sync-request');
7+
var admZip = require('adm-zip');
8+
const Downloader = require("nodejs-file-downloader");
89

910
var downloadPath = path.join(__dirname, '_download');
1011
var testPath = path.join(__dirname, '_test');
1112

12-
exports.run = function(cl) {
13+
var run = function (cl) {
1314
console.log('> ' + cl);
1415
var rc = exec(cl).code;
1516
if (rc !== 0) {
1617
echo('Exec failed with rc ' + rc);
1718
exit(rc);
1819
}
1920
}
20-
var run = exports.run;
21+
exports.run = run;
2122

22-
exports.getExternals = function () {
23+
const getExternalsAsync = async () => {
2324
if (process.env['TF_BUILD']) {
2425
// skip adding node 5.10.1 to the PATH. the CI definition tests against node 5 and 6.
2526
return;
@@ -38,16 +39,19 @@ exports.getExternals = function () {
3839
var nodeVersion = 'v16.13.0';
3940
switch (platform) {
4041
case 'darwin':
41-
var nodeArchivePath = downloadArchive(nodeUrl + '/' + nodeVersion + '/node-' + nodeVersion + '-darwin-x64.tar.gz');
42+
var nodeArchivePath = await downloadArchiveAsync(nodeUrl + '/' + nodeVersion + '/node-' + nodeVersion + '-darwin-x64.tar.gz');
4243
addPath(path.join(nodeArchivePath, 'node-' + nodeVersion + '-darwin-x64', 'bin'));
4344
break;
4445
case 'linux':
45-
var nodeArchivePath = downloadArchive(nodeUrl + '/' + nodeVersion + '/node-' + nodeVersion + '-linux-x64.tar.gz');
46+
var nodeArchivePath = await downloadArchiveAsync(nodeUrl + '/' + nodeVersion + '/node-' + nodeVersion + '-linux-x64.tar.gz');
4647
addPath(path.join(nodeArchivePath, 'node-' + nodeVersion + '-linux-x64', 'bin'));
4748
break;
4849
case 'win32':
49-
var nodeExePath = downloadFile(nodeUrl + '/' + nodeVersion + '/win-x64/node.exe');
50-
var nodeLibPath = downloadFile(nodeUrl + '/' + nodeVersion + '/win-x64/node.lib');
50+
var [nodeExePath, nodeLibPath] = await Promise.all([
51+
downloadFileAsync(nodeUrl + '/' + nodeVersion + '/win-x64/node.exe'),
52+
downloadFileAsync(nodeUrl + '/' + nodeVersion + '/win-x64/node.lib')
53+
]);
54+
5155
var nodeDirectory = path.join(testPath, 'node');
5256
mkdir('-p', nodeDirectory);
5357
cp(nodeExePath, path.join(nodeDirectory, 'node.exe'));
@@ -57,83 +61,84 @@ exports.getExternals = function () {
5761
}
5862
}
5963

60-
var downloadFile = function (url) {
64+
exports.getExternalsAsync = getExternalsAsync
65+
66+
67+
var downloadFileAsync = async function (url, fileName) {
6168
// validate parameters
6269
if (!url) {
6370
throw new Error('Parameter "url" must be set.');
6471
}
6572

66-
// short-circuit if already downloaded
73+
// skip if already downloaded
6774
var scrubbedUrl = url.replace(/[/\:?]/g, '_');
68-
var targetPath = path.join(downloadPath, 'file', scrubbedUrl);
75+
if (fileName === undefined) {
76+
fileName = scrubbedUrl;
77+
}
78+
var targetPath = path.join(downloadPath, 'file', fileName);
6979
var marker = targetPath + '.completed';
70-
if (!test('-f', marker)) {
71-
console.log('Downloading file: ' + url);
80+
if (test('-f', marker)) {
81+
console.log('File already exists: ' + targetPath);
82+
return targetPath;
83+
}
7284

73-
// delete any previous partial attempt
74-
if (test('-f', targetPath)) {
75-
rm('-f', targetPath);
76-
}
85+
console.log('Downloading file: ' + url);
86+
// delete any previous partial attempt
87+
if (test('-f', targetPath)) {
88+
rm('-f', targetPath);
89+
}
7790

78-
// download the file
79-
mkdir('-p', path.join(downloadPath, 'file'));
80-
var result = syncRequest('GET', url);
81-
fs.writeFileSync(targetPath, result.getBody());
91+
// download the file
92+
mkdir('-p', path.join(downloadPath, 'file'));
8293

83-
// write the completed marker
84-
fs.writeFileSync(marker, '');
85-
}
94+
const downloader = new Downloader({
95+
url: url,
96+
directory: path.join(downloadPath, 'file'),
97+
fileName: fileName
98+
});
8699

87-
return targetPath;
88-
}
100+
const { filePath } = await downloader.download(); // Downloader.download() resolves with some useful properties.
101+
fs.writeFileSync(marker, '');
102+
return filePath;
103+
};
89104

90-
var downloadArchive = function (url) {
91-
// validate platform
92-
var platform = os.platform();
93-
if (platform != 'darwin' && platform != 'linux') {
94-
throw new Error('Unexpected platform: ' + platform);
95-
}
96105

97-
// validate parameters
106+
var downloadArchiveAsync = async function (url, fileName) {
98107
if (!url) {
99108
throw new Error('Parameter "url" must be set.');
100109
}
101110

102-
if (!url.match(/\.tar\.gz$/)) {
103-
throw new Error('Expected .tar.gz');
111+
// skip if already downloaded and extracted
112+
var scrubbedUrl = url.replace(/[\/\\:?]/g, '_');
113+
if (fileName !== undefined) {
114+
scrubbedUrl = fileName;
104115
}
105-
106-
// short-circuit if already downloaded and extracted
107-
var scrubbedUrl = url.replace(/[/\:?]/g, '_');
108116
var targetPath = path.join(downloadPath, 'archive', scrubbedUrl);
109117
var marker = targetPath + '.completed';
110-
if (!test('-f', marker)) {
111-
// download the archive
112-
var archivePath = downloadFile(url);
113-
console.log('Extracting archive: ' + url);
114-
115-
// delete any previously attempted extraction directory
116-
if (test('-d', targetPath)) {
117-
rm('-rf', targetPath);
118-
}
119-
120-
// extract
121-
mkdir('-p', targetPath);
122-
var cwd = process.cwd();
123-
process.chdir(targetPath);
124-
try {
125-
run('tar -xzf "' + archivePath + '"');
126-
}
127-
finally {
128-
process.chdir(cwd);
129-
}
130-
131-
// write the completed marker
132-
fs.writeFileSync(marker, '');
118+
if (test('-f', marker)) {
119+
return targetPath;
120+
}
121+
122+
// download the archive
123+
var archivePath = await downloadFileAsync(url, scrubbedUrl);
124+
console.log('Extracting archive: ' + url);
125+
126+
// delete any previously attempted extraction directory
127+
if (test('-d', targetPath)) {
128+
rm('-rf', targetPath);
133129
}
134130

131+
// extract
132+
mkdir('-p', targetPath);
133+
var zip = new admZip(archivePath);
134+
zip.extractAllTo(targetPath);
135+
136+
// write the completed marker
137+
fs.writeFileSync(marker, '');
138+
135139
return targetPath;
136-
}
140+
};
141+
137142

138143
var addPath = function (directory) {
139144
var separator;

node/make.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ target.build = function() {
3838
rm(path.join(buildPath, 'index.*'));
3939
}
4040

41-
target.test = function() {
41+
target.test = async function() {
4242
target.build();
4343

44-
buildutils.getExternals();
44+
await buildutils.getExternalsAsync();
4545
run('tsc -p ./test');
4646
cp('-Rf', rp('test/scripts'), testPath);
4747
cp('-Rf', rp('test/fakeTasks'), testPath);
@@ -65,3 +65,13 @@ target.loc = function() {
6565
var enContents = JSON.stringify(strings, null, 2);
6666
fs.writeFileSync(path.join(strPath, 'resources.resjson'), enContents)
6767
}
68+
69+
process.on('uncaughtException', err => {
70+
console.error(`Uncaught exception: ${err.message}`);
71+
console.debug(err.stack);
72+
});
73+
74+
process.on('unhandledRejection', err => {
75+
console.error(`Unhandled rejection: ${err.message}`);
76+
console.debug(err.stack);
77+
});

0 commit comments

Comments
 (0)