Skip to content

Commit ab68b95

Browse files
authored
Merge branch 'master' into dependabot/npm_and_yarn/vscode-languageclient-8.1.0
2 parents c5f0d7b + 89d6ebd commit ab68b95

File tree

3 files changed

+2
-191
lines changed

3 files changed

+2
-191
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@
564564
"@types/node": "^20.1.0",
565565
"@types/vscode": "^1.79.1",
566566
"@types/which": "^3.0.0",
567-
"@types/yauzl": "^2.9.1",
568567
"@typescript-eslint/eslint-plugin": "^5.59.5",
569568
"@typescript-eslint/parser": "^5.57.1",
570569
"@vscode/test-electron": "^2.3.3",
@@ -585,7 +584,6 @@
585584
"dependencies": {
586585
"ts-pattern": "^4.2.2",
587586
"vscode-languageclient": "^8.1.0",
588-
"which": "^3.0.1",
589-
"yauzl": "^2.10.0"
587+
"which": "^3.0.1"
590588
}
591589
}

src/utils.ts

Lines changed: 1 addition & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import * as child_process from 'child_process';
22
import * as fs from 'fs';
3-
import * as http from 'http';
43
import * as https from 'https';
54
import * as os from 'os';
6-
import { extname } from 'path';
7-
import { promisify } from 'util';
8-
import { OutputChannel, ProgressLocation, window, workspace, WorkspaceFolder } from 'vscode';
5+
import { OutputChannel, workspace, WorkspaceFolder } from 'vscode';
96
import { Logger } from 'vscode-languageclient';
107
import * as which from 'which';
11-
import * as yazul from 'yauzl';
12-
import { createGunzip } from 'zlib';
138

149
// Used for environment variables later on
1510
export interface IEnvVars {
@@ -125,18 +120,6 @@ export function comparePVP(l: string, r: string): number {
125120
*/
126121
const userAgentHeader = { 'User-Agent': 'vscode-haskell' };
127122

128-
/** downloadFile may get called twice on the same src and destination:
129-
* When this happens, we should only download the file once but return two
130-
* promises that wait on the same download. This map keeps track of which
131-
* files are currently being downloaded and we short circuit any calls to
132-
* downloadFile which have a hit in this map by returning the promise stored
133-
* here.
134-
* Note that we have to use a double nested map since array/pointer/object
135-
* equality is by reference, not value in Map. And we are using a tuple of
136-
* [src, dest] as the key.
137-
*/
138-
const inFlightDownloads = new Map<string, Map<string, Thenable<boolean>>>();
139-
140123
export async function httpsGetSilently(options: https.RequestOptions): Promise<string> {
141124
const opts: https.RequestOptions = {
142125
...options,
@@ -176,144 +159,6 @@ export async function httpsGetSilently(options: https.RequestOptions): Promise<s
176159
});
177160
}
178161

179-
async function ignoreFileNotExists(err: NodeJS.ErrnoException): Promise<void> {
180-
if (err.code === 'ENOENT') {
181-
return;
182-
}
183-
throw err;
184-
}
185-
186-
export async function downloadFile(titleMsg: string, src: string, dest: string): Promise<boolean> {
187-
// Check to see if we're already in the process of downloading the same thing
188-
const inFlightDownload = inFlightDownloads.get(src)?.get(dest);
189-
if (inFlightDownload) {
190-
return inFlightDownload;
191-
}
192-
193-
// If it already is downloaded just use that
194-
if (fs.existsSync(dest)) {
195-
return false;
196-
}
197-
198-
// Download it to a .tmp location first, then rename it!
199-
// This way if the download fails halfway through or something then we know
200-
// to delete it and try again
201-
const downloadDest = dest + '.download';
202-
if (fs.existsSync(downloadDest)) {
203-
fs.unlinkSync(downloadDest);
204-
}
205-
206-
const downloadTask = window
207-
.withProgress(
208-
{
209-
location: ProgressLocation.Notification,
210-
title: titleMsg,
211-
cancellable: false,
212-
},
213-
async (progress) => {
214-
const p = new Promise<void>((resolve, reject) => {
215-
const srcUrl = new URL(src);
216-
const opts: https.RequestOptions = {
217-
host: srcUrl.host,
218-
path: srcUrl.pathname,
219-
protocol: srcUrl.protocol,
220-
port: srcUrl.port,
221-
headers: userAgentHeader,
222-
};
223-
getWithRedirects(opts, (res) => {
224-
const totalSize = parseInt(res.headers['content-length'] || '1', 10);
225-
const fileStream = fs.createWriteStream(downloadDest, { mode: 0o744 });
226-
let curSize = 0;
227-
228-
// Decompress it if it's a gzip or zip
229-
const needsGunzip =
230-
res.headers['content-type'] === 'application/gzip' || extname(srcUrl.pathname ?? '') === '.gz';
231-
const needsUnzip =
232-
res.headers['content-type'] === 'application/zip' || extname(srcUrl.pathname ?? '') === '.zip';
233-
if (needsGunzip) {
234-
const gunzip = createGunzip();
235-
gunzip.on('error', reject);
236-
res.pipe(gunzip).pipe(fileStream);
237-
} else if (needsUnzip) {
238-
const zipDest = downloadDest + '.zip';
239-
const zipFs = fs.createWriteStream(zipDest);
240-
zipFs.on('error', reject);
241-
zipFs.on('close', () => {
242-
yazul.open(zipDest, (err, zipfile) => {
243-
if (err) {
244-
throw err;
245-
}
246-
if (!zipfile) {
247-
throw Error("Couldn't decompress zip");
248-
}
249-
250-
// We only expect *one* file inside each zip
251-
zipfile.on('entry', (entry: yazul.Entry) => {
252-
zipfile.openReadStream(entry, (err2, readStream) => {
253-
if (err2) {
254-
throw err2;
255-
}
256-
readStream?.pipe(fileStream);
257-
});
258-
});
259-
});
260-
});
261-
res.pipe(zipFs);
262-
} else {
263-
res.pipe(fileStream);
264-
}
265-
266-
function toMB(bytes: number) {
267-
return bytes / (1024 * 1024);
268-
}
269-
270-
res.on('data', (chunk: Buffer) => {
271-
curSize += chunk.byteLength;
272-
const msg = `${toMB(curSize).toFixed(1)}MB / ${toMB(totalSize).toFixed(1)}MB`;
273-
progress.report({ message: msg, increment: (chunk.length / totalSize) * 100 });
274-
});
275-
res.on('error', reject);
276-
fileStream.on('close', resolve);
277-
}).on('error', reject);
278-
});
279-
try {
280-
await p;
281-
// Finally rename it to the actual dest
282-
fs.renameSync(downloadDest, dest);
283-
} finally {
284-
// And remember to remove it from the list of current downloads
285-
inFlightDownloads.get(src)?.delete(dest);
286-
}
287-
}
288-
)
289-
.then(() => true);
290-
291-
try {
292-
if (inFlightDownloads.has(src)) {
293-
inFlightDownloads.get(src)?.set(dest, downloadTask);
294-
} else {
295-
inFlightDownloads.set(src, new Map([[dest, downloadTask]]));
296-
}
297-
return await downloadTask;
298-
} catch (e: any) {
299-
await promisify(fs.unlink)(downloadDest).catch(ignoreFileNotExists);
300-
throw new Error(`Failed to download ${src}:\n${e.message}`);
301-
}
302-
}
303-
304-
function getWithRedirects(opts: https.RequestOptions, f: (res: http.IncomingMessage) => void): http.ClientRequest {
305-
return https.get(opts, (res) => {
306-
if (res.statusCode === 301 || res.statusCode === 302) {
307-
if (!res.headers.location) {
308-
console.error('301/302 without a location header');
309-
return;
310-
}
311-
https.get(res.headers.location, f);
312-
} else {
313-
f(res);
314-
}
315-
});
316-
}
317162

318163
/*
319164
* Checks if the executable is on the PATH

yarn.lock

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,6 @@
248248
dependencies:
249249
"@types/yargs-parser" "*"
250250

251-
"@types/yauzl@^2.9.1":
252-
version "2.10.0"
253-
resolved "https://registry.yarnpkg.com/@types/yauzl/-/yauzl-2.10.0.tgz#b3248295276cf8c6f153ebe6a9aba0c988cb2599"
254-
integrity sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==
255-
dependencies:
256-
"@types/node" "*"
257-
258251
"@typescript-eslint/eslint-plugin@^5.59.5":
259252
version "5.60.1"
260253
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.60.1.tgz#81382d6ecb92b8dda70e91f9035611cb2fecd1c3"
@@ -648,11 +641,6 @@ browserslist@^4.14.5:
648641
node-releases "^2.0.12"
649642
update-browserslist-db "^1.0.11"
650643

651-
buffer-crc32@~0.2.3:
652-
version "0.2.13"
653-
resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"
654-
integrity sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==
655-
656644
buffer-from@^1.0.0:
657645
version "1.1.2"
658646
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
@@ -1012,13 +1000,6 @@ fastq@^1.6.0:
10121000
dependencies:
10131001
reusify "^1.0.4"
10141002

1015-
fd-slicer@~1.1.0:
1016-
version "1.1.0"
1017-
resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.1.0.tgz#25c7c89cb1f9077f8891bbe61d8f390eae256f1e"
1018-
integrity sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==
1019-
dependencies:
1020-
pend "~1.2.0"
1021-
10221003
file-entry-cache@^6.0.1:
10231004
version "6.0.1"
10241005
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027"
@@ -1712,11 +1693,6 @@ path-type@^4.0.0:
17121693
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
17131694
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
17141695

1715-
pend@~1.2.0:
1716-
version "1.2.0"
1717-
resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50"
1718-
integrity sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==
1719-
17201696
picocolors@^1.0.0:
17211697
version "1.0.0"
17221698
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
@@ -2297,14 +2273,6 @@ yargs@16.2.0:
22972273
y18n "^5.0.5"
22982274
yargs-parser "^20.2.2"
22992275

2300-
yauzl@^2.10.0:
2301-
version "2.10.0"
2302-
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"
2303-
integrity sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==
2304-
dependencies:
2305-
buffer-crc32 "~0.2.3"
2306-
fd-slicer "~1.1.0"
2307-
23082276
yocto-queue@^0.1.0:
23092277
version "0.1.0"
23102278
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"

0 commit comments

Comments
 (0)