Skip to content

Commit b61584b

Browse files
Update 7zip in utility-common package (#457)
* Update 7zip in utility-common package * Update downloading 7zip from urls
1 parent 2b53b8b commit b61584b

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

common-npm-packages/utility-common/compressutility.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
var path = require('path');
3+
var path = require('path');
44
import * as tl from "azure-pipelines-task-lib/task";
55
import * as trm from 'azure-pipelines-task-lib/toolrunner';
66

@@ -11,7 +11,15 @@ var xpTarLocation: string;
1111
var xpZipLocation: string;
1212
// 7zip
1313
var xpSevenZipLocation: string;
14-
var winSevenZipLocation: string = path.join(__dirname, 'tools/7zip/7z.exe');
14+
var winSevenZipLocation: string = getWinSevenZipLocation();
15+
16+
function getWinSevenZipLocation(): string {
17+
if (tl.getPipelineFeature("Use7zV2409InUtilityCommonPackage")) {
18+
return path.join(__dirname, 'tools/7zip24/7z.exe');
19+
} else {
20+
return path.join(__dirname, 'tools/7zip5/7z.exe');
21+
}
22+
}
1523

1624
// Creates compressed archive of all files(recusively) inside sourceFolder directory (excluding the sourceFolder directly itself)
1725
export function createArchive(sourceFolder: string, archiveType: string, archiveFile: string) {
@@ -86,7 +94,7 @@ function zipArchive(archive: string, files: string[]) {
8694
zip.arg(files[i]);
8795
}
8896
} else {
89-
zip.arg(".");
97+
zip.arg(".");
9098
}
9199

92100
return handleExecResult(zip.execSync(getOptions()), archive);
@@ -109,7 +117,7 @@ function tarArchive(archive: string, compression: string, files: string[]) {
109117
}
110118
tar.arg('-f');
111119
tar.arg(archive);
112-
if(files.length > 0) {
120+
if(files.length > 0) {
113121
for (var i = 0; i < files.length; i++) {
114122
tar.arg(files[i]);
115123
}
Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
var path = require('path');
2-
var fs = require('fs');
3-
var util = require('../build-scripts/util');
4-
var { downloadArchive } = require('../build-scripts/downloadArchive');
5-
6-
var buildPath = './_build'
7-
var toolPath = './tools'
8-
var zipUrl = 'https://vstsagenttools.blob.core.windows.net/tools/7zip/5/7zip.zip'
9-
10-
const targetPath = downloadArchive(zipUrl, path.join('../_download', toolPath));
11-
if (!fs.existsSync(toolPath)) {
12-
util.mkdir('-p', toolPath);
13-
}
1+
const { existsSync } = require('node:fs');
2+
const { join } = require('node:path');
3+
4+
const util = require('../build-scripts/util');
5+
const { downloadArchive } = require('../build-scripts/downloadArchive');
6+
7+
const buildPath = './_build';
8+
const toolPath = './tools';
9+
10+
const zipUrls = {
11+
'7zip5': 'https://vstsagenttools.blob.core.windows.net/tools/7zip/5/7zip.zip',
12+
'7zip24': 'https://vstsagenttools.blob.core.windows.net/tools/7zip/24.09/7zip.zip'
13+
};
1414

15-
util.cp('-rf', path.join(targetPath, '*'), toolPath);
15+
for (const [version, url] of Object.entries(zipUrls)) {
16+
const targetPath = join(toolPath, version);
17+
const sourcePath = downloadArchive(url, join('../_download', targetPath));
18+
19+
if (!existsSync(targetPath)) {
20+
util.mkdir('-p', targetPath);
21+
}
22+
23+
util.cp('-rf', join(sourcePath, '*'), targetPath);
24+
}
1625

1726
util.rm('-rf', buildPath)
18-
util.run(path.join(__dirname, 'node_modules/.bin/tsc') + ' --outDir ' + buildPath);
27+
util.run(join(__dirname, 'node_modules/.bin/tsc') + ' --outDir ' + buildPath);
1928

20-
util.cp(path.join(__dirname, 'package.json'), buildPath);
21-
util.cp(path.join(__dirname, 'package-lock.json'), buildPath);
22-
util.cp(path.join(__dirname, 'module.json'), buildPath);
29+
util.cp(join(__dirname, 'package.json'), buildPath);
30+
util.cp(join(__dirname, 'package-lock.json'), buildPath);
31+
util.cp(join(__dirname, 'module.json'), buildPath);
2332
util.cp('-r', 'tools', buildPath);
2433
util.cp('-r', 'Strings', buildPath);
2534
util.cp('-r', 'node_modules', buildPath);

0 commit comments

Comments
 (0)