Skip to content

Commit 56c6e68

Browse files
Port code changes from commit bbc5570 - update dependencies and modernize URL parsing
Co-authored-by: tarunramsinghani <2929463+tarunramsinghani@users.noreply.github.com>
1 parent 92cdc5a commit 56c6e68

File tree

7 files changed

+101
-96
lines changed

7 files changed

+101
-96
lines changed

app/exec/build/tasks/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path = require("path");
55
import shell = require("shelljs");
66
import tasksBase = require("./default");
77
import trace = require("../../../lib/trace");
8-
import uuid = require("uuid");
8+
import { v1 as uuidv1 } from "uuid";
99

1010
export interface TaskCreateResult {
1111
taskPath: string;
@@ -81,7 +81,7 @@ export class TaskCreate extends tasksBase.BuildTaskBase<TaskCreateResult> {
8181

8282
trace.debug("creating definition");
8383
let def: any = {};
84-
def.id = uuid.v1();
84+
def.id = uuidv1();
8585
trace.debug("id: " + def.id);
8686
def.name = taskName;
8787
trace.debug("name: " + def.name);

app/exec/extension/_lib/merger.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { forwardSlashesPath, toZipItemName } from "./utils";
1414
import _ = require("lodash");
1515
import fs = require("fs");
16-
import glob = require("glob");
16+
import { glob } from "glob";
1717
import jju = require("jju");
1818
import jsonInPlace = require("json-in-place");
1919
import loc = require("./loc");
@@ -56,18 +56,7 @@ export class Merger {
5656
const globs = this.settings.manifestGlobs.map(p => (path.isAbsolute(p) ? p : path.join(this.settings.root, p)));
5757

5858
trace.debug("merger.gatherManifestsFromGlob");
59-
const promises = globs.map(
60-
pattern =>
61-
new Promise<string[]>((resolve, reject) => {
62-
glob(pattern, (err, matches) => {
63-
if (err) {
64-
reject(err);
65-
} else {
66-
resolve(matches);
67-
}
68-
});
69-
}),
70-
);
59+
const promises = globs.map(pattern => glob(pattern));
7160

7261
return Promise.all(promises)
7362
.then(results => _.uniq(_.flatten<string>(results)))
@@ -104,7 +93,7 @@ export class Merger {
10493

10594
// build environment object from --env parameter
10695
const env = {};
107-
(this.settings.env || []).forEach(kvp => {
96+
(this.settings.env || []).forEach(kvp => {
10897
const [key, ...value] = kvp.split('=');
10998
env[key] = value.join('=');
11099
});
@@ -119,7 +108,7 @@ export class Merger {
119108
throw new Error(`The export function from manifest-js file ${fullJsFile} must return the manifest object`)
120109
}
121110
return manifestData;
122-
}
111+
}
123112

124113
/**
125114
* Finds all manifests and merges them into two JS Objects: vsoManifest and vsixManifest
@@ -413,9 +402,9 @@ export class Merger {
413402
private async validateBuildTaskContributions(contributions: any[]): Promise<void> {
414403
try {
415404
// Filter contributions to only build tasks
416-
const buildTaskContributions = contributions.filter(contrib =>
417-
contrib.type === "ms.vss-distributed-task.task" &&
418-
contrib.properties &&
405+
const buildTaskContributions = contributions.filter(contrib =>
406+
contrib.type === "ms.vss-distributed-task.task" &&
407+
contrib.properties &&
419408
contrib.properties.name
420409
);
421410

app/lib/connection.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
import { BasicCredentialHandler } from "azure-devops-node-api/handlers/basiccreds";
22

3-
import url = require("url");
43
import apim = require("azure-devops-node-api/WebApi");
54
import apibasem = require("azure-devops-node-api/interfaces/common/VsoBaseInterfaces");
65
import trace = require("./trace");
76

87
export class TfsConnection {
9-
private parsedUrl: url.Url;
8+
private parsedUrl: URL;
109

1110
private accountUrl: string;
1211
private collectionUrl: string;
1312

1413
constructor(private serviceUrl: string) {
15-
this.parsedUrl = url.parse(this.serviceUrl);
14+
// Parse URL, but handle failures gracefully to mimic url.parse() behavior
15+
try {
16+
this.parsedUrl = new URL(this.serviceUrl);
17+
} catch (error) {
18+
// Mimic url.parse() behavior for invalid URLs
19+
// url.parse() would return an object with null/empty values instead of throwing
20+
this.parsedUrl = {
21+
protocol: this.serviceUrl && this.serviceUrl.includes('://') ? this.serviceUrl.split('://')[0] + ':' : '',
22+
host: null,
23+
hostname: null,
24+
pathname: this.serviceUrl && !this.serviceUrl.includes('://') ? this.serviceUrl : '',
25+
search: '',
26+
hash: ''
27+
} as any;
28+
}
1629

17-
var splitPath: string[] = this.parsedUrl.path.split("/").slice(1);
30+
var splitPath: string[] = this.parsedUrl.pathname.split("/").slice(1);
1831
this.accountUrl = this.parsedUrl.protocol + "//" + this.parsedUrl.host;
1932

2033
if (splitPath.length === 2 && splitPath[0] === "tfs") {

package.json

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@
1919
"prepublishOnly": "npm run build",
2020
"build:tests": "tsc -p tsconfig.tests.json",
2121
"postbuild:tests": "ncp tests/build-samples _tests/build-samples && ncp tests/extension-samples _tests/extension-samples",
22-
"test": "npm run build:tests && mocha \"_tests/tests/**/*.js\"",
23-
"test:ci": "npm run build:tests && mocha \"_tests/tests/**/*.js\" --reporter xunit --reporter-options output=test-results.xml",
24-
"test:commandline": "npm run build:tests && mocha \"_tests/tests/commandline.js\"",
25-
"test:server-integration": "npm run build:tests && mocha \"_tests/tests/server-integration-*.js\"",
26-
"test:focused-login": "npm run build:tests && mocha \"_tests/tests/focused-login-test.js\"",
27-
"test:server-integration-login": "npm run build:tests && mocha \"_tests/tests/server-integration-login.js\"",
28-
"test:server-integration-workitem": "npm run build:tests && mocha \"_tests/tests/server-integration-workitem.js\"",
29-
"test:build-local": "npm run build:tests && mocha \"_tests/tests/build-local-tests.js\"",
30-
"test:build-server-integration": "npm run build:tests && mocha \"_tests/tests/build-server-integration-tests.js\"",
31-
"test:build-consolidated": "npm run test:build-local && npm run test:build-server-integration",
32-
"test:extension-local": "npm run build:tests && mocha \"_tests/tests/extension-local-tests.js\"",
33-
"test:extension-server-integration": "npm run build:tests && mocha \"_tests/tests/extension-server-integration-tests.js\"",
34-
"test:extension-consolidated": "npm run test:extension-local && npm run test:extension-server-integration"
22+
"test": "npm run build:tests && mocha \"_tests/tests/**/*.js\"",
23+
"test:ci": "npm run build:tests && mocha \"_tests/tests/**/*.js\" --reporter xunit --reporter-options output=test-results.xml",
24+
"test:commandline": "npm run build:tests && mocha \"_tests/tests/commandline.js\"",
25+
"test:server-integration": "npm run build:tests && mocha \"_tests/tests/server-integration-*.js\"",
26+
"test:focused-login": "npm run build:tests && mocha \"_tests/tests/focused-login-test.js\"",
27+
"test:server-integration-login": "npm run build:tests && mocha \"_tests/tests/server-integration-login.js\"",
28+
"test:server-integration-workitem": "npm run build:tests && mocha \"_tests/tests/server-integration-workitem.js\"",
29+
"test:build-local": "npm run build:tests && mocha \"_tests/tests/build-local-tests.js\"",
30+
"test:build-server-integration": "npm run build:tests && mocha \"_tests/tests/build-server-integration-tests.js\"",
31+
"test:build-consolidated": "npm run test:build-local && npm run test:build-server-integration",
32+
"test:extension-local": "npm run build:tests && mocha \"_tests/tests/extension-local-tests.js\"",
33+
"test:extension-server-integration": "npm run build:tests && mocha \"_tests/tests/extension-server-integration-tests.js\"",
34+
"test:extension-consolidated": "npm run test:extension-local && npm run test:extension-server-integration"
3535
},
3636
"dependencies": {
3737
"app-root-path": "1.0.0",
38-
"archiver": "2.0.3",
38+
"archiver": "^7.0.1",
3939
"azure-devops-node-api": "^14.0.0",
4040
"clipboardy": "^4.0.0",
4141
"colors": "~1.3.0",
42-
"glob": "7.1.2",
42+
"glob": "^11.0.3",
4343
"jju": "^1.4.0",
4444
"json-in-place": "^1.0.1",
4545
"jszip": "^3.10.1",
@@ -50,32 +50,30 @@
5050
"os-homedir": "^1.0.1",
5151
"prompt": "^1.3.0",
5252
"read": "^1.0.6",
53-
"shelljs": "^0.8.5",
53+
"shelljs": "^0.10.0",
5454
"tmp": "^0.2.4",
5555
"tracer": "0.7.4",
5656
"util.promisify": "^1.0.0",
57-
"uuid": "^3.0.1",
57+
"uuid": "^13.0.0",
5858
"validator": "^13.7.0",
5959
"winreg": "0.0.12",
6060
"xml2js": "^0.5.0"
6161
},
6262
"devDependencies": {
6363
"@types/clipboardy": "~1.1.0",
64-
"@types/glob": "^5.0.29",
6564
"@types/jju": "^1.4.1",
6665
"@types/jszip": "~3.1.2",
6766
"@types/lodash": "~4.14.110",
6867
"@types/mkdirp": "^1.0.2",
6968
"@types/mocha": "^10.0.0",
7069
"@types/node": "8.10.66",
7170
"@types/shelljs": "^0.8.11",
72-
"@types/uuid": "^2.0.29",
7371
"@types/validator": "^4.5.27",
7472
"@types/winreg": "^1.2.29",
7573
"@types/xml2js": "0.0.27",
76-
"mocha": "^10.2.0",
74+
"mocha": "^11.7.3",
7775
"ncp": "^2.0.0",
78-
"rimraf": "^2.6.1",
76+
"rimraf": "^6.0.1",
7977
"typescript": "^4.9.5"
8078
},
8179
"engines": {

0 commit comments

Comments
 (0)