Socket
Socket
Sign inDemoInstall

@vscode/test-electron

Package Overview
Dependencies
Maintainers
19
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vscode/test-electron - npm Package Compare versions

Comparing version 2.0.3 to 2.1.0

out/progress.d.ts

4

CHANGELOG.md
# Changelog
### 2.1.0 | 2021-01-14
- Add a progress `reporter` option on the `TestOptions`, which can be used to see more detail or silence download progress.
### 2.0.3 | 2021-01-11

@@ -4,0 +8,0 @@

4

out/download.d.ts

@@ -0,1 +1,2 @@

import { ProgressReporter } from './progress';
/**

@@ -18,2 +19,3 @@ * Adapted from https://github.com/microsoft/TypeScript/issues/29729

readonly architecture: DownloadArchitecture;
readonly reporter?: ProgressReporter;
}

@@ -40,3 +42,3 @@ export declare const defaultCachePath: string;

*/
export declare function downloadAndUnzipVSCode(version?: DownloadVersion, platform?: DownloadPlatform): Promise<string>;
export declare function downloadAndUnzipVSCode(version?: DownloadVersion, platform?: DownloadPlatform, reporter?: ProgressReporter): Promise<string>;
export {};

@@ -8,12 +8,13 @@ "use strict";

exports.downloadAndUnzipVSCode = exports.download = exports.defaultCachePath = void 0;
const cp = require("child_process");
const fs = require("fs");
const os_1 = require("os");
const path = require("path");
const cp = require("child_process");
const stream_1 = require("stream");
const unzipper_1 = require("unzipper");
const util_1 = require("util");
const del = require("./del");
const progress_1 = require("./progress");
const request = require("./request");
const del = require("./del");
const util_1 = require("./util");
const unzipper_1 = require("unzipper");
const stream_1 = require("stream");
const os_1 = require("os");
const util_2 = require("util");
const util_2 = require("./util");
const extensionRoot = process.cwd();

@@ -40,8 +41,8 @@ const vscodeStableReleasesAPI = `https://update.code.visualstudio.com/api/releases/stable`;

async function downloadVSCodeArchive(options) {
var _a, _b;
if (!fs.existsSync(options.cachePath)) {
fs.mkdirSync(options.cachePath);
}
const downloadUrl = util_1.getVSCodeDownloadUrl(options.version, options.platform, options.architecture);
const text = `Downloading VS Code ${options.version} from ${downloadUrl}`;
process.stdout.write(text);
const downloadUrl = util_2.getVSCodeDownloadUrl(options.version, options.platform, options.architecture);
(_a = options.reporter) === null || _a === void 0 ? void 0 : _a.report({ stage: progress_1.ProgressReportStage.ResolvingCDNLocation, url: downloadUrl });
const res = await request.getStream(downloadUrl);

@@ -51,36 +52,21 @@ if (res.statusCode !== 302) {

}
const archiveUrl = res.headers.location;
if (!archiveUrl) {
const url = res.headers.location;
if (!url) {
throw 'Failed to get VS Code archive location';
}
const download = await request.getStream(archiveUrl);
printProgress(text, download);
return { stream: download, format: archiveUrl.endsWith('.zip') ? 'zip' : 'tgz' };
}
function printProgress(baseText, res) {
if (!process.stdout.isTTY) {
return;
}
const total = Number(res.headers['content-length']);
let received = 0;
let timeout;
const reset = '\x1b[G\x1b[0K';
res.on('data', chunk => {
if (!timeout) {
timeout = setTimeout(() => {
process.stdout.write(`${reset}${baseText}: ${received}/${total} (${(received / total * 100).toFixed()}%)`);
timeout = undefined;
}, 100);
}
received += chunk.length;
res.destroy();
const download = await request.getStream(url);
const totalBytes = Number(download.headers['content-length']);
(_b = options.reporter) === null || _b === void 0 ? void 0 : _b.report({ stage: progress_1.ProgressReportStage.Downloading, url, bytesSoFar: 0, totalBytes });
let bytesSoFar = 0;
download.on('data', chunk => {
var _a;
bytesSoFar += chunk.length;
(_a = options.reporter) === null || _a === void 0 ? void 0 : _a.report({ stage: progress_1.ProgressReportStage.Downloading, url, bytesSoFar, totalBytes });
});
res.on('end', () => {
if (timeout) {
clearTimeout(timeout);
}
console.log(`${reset}${baseText}: complete`);
download.on('end', () => {
var _a;
(_a = options.reporter) === null || _a === void 0 ? void 0 : _a.report({ stage: progress_1.ProgressReportStage.Downloading, url, bytesSoFar: totalBytes, totalBytes });
});
res.on('error', err => {
throw err;
});
return { stream: download, format: url.endsWith('.zip') ? 'zip' : 'tgz' };
}

@@ -108,3 +94,3 @@ /**

try {
await util_2.promisify(stream_1.pipeline)(stream, fs.createWriteStream(stagingFile));
await util_1.promisify(stream_1.pipeline)(stream, fs.createWriteStream(stagingFile));
await spawnDecompressorChild('unzip', ['-q', stagingFile, '-d', extractDir]);

@@ -141,7 +127,8 @@ }

async function download(options) {
var _a, _b, _c;
var _a, _b, _c, _d;
let version = options === null || options === void 0 ? void 0 : options.version;
const platform = (_a = options === null || options === void 0 ? void 0 : options.platform) !== null && _a !== void 0 ? _a : util_1.systemDefaultPlatform;
const architecture = (_b = options === null || options === void 0 ? void 0 : options.architecture) !== null && _b !== void 0 ? _b : util_1.systemDefaultArchitecture;
const platform = (_a = options === null || options === void 0 ? void 0 : options.platform) !== null && _a !== void 0 ? _a : util_2.systemDefaultPlatform;
const architecture = (_b = options === null || options === void 0 ? void 0 : options.architecture) !== null && _b !== void 0 ? _b : util_2.systemDefaultArchitecture;
const cachePath = (_c = options === null || options === void 0 ? void 0 : options.cachePath) !== null && _c !== void 0 ? _c : exports.defaultCachePath;
const reporter = (_d = options === null || options === void 0 ? void 0 : options.reporter) !== null && _d !== void 0 ? _d : new progress_1.ConsoleReporter(process.stdout.isTTY);
if (version) {

@@ -165,21 +152,27 @@ if (version === 'stable') {

}
reporter.report({ stage: progress_1.ProgressReportStage.ResolvedVersion, version });
const downloadedPath = path.resolve(cachePath, `vscode-${platform}-${version}`);
if (fs.existsSync(downloadedPath)) {
if (version === 'insiders') {
const { version: currentHash, date: currentDate } = util_1.insidersDownloadDirMetadata(downloadedPath);
const { version: latestHash, timestamp: latestTimestamp } = await util_1.getLatestInsidersMetadata(util_1.systemDefaultPlatform);
reporter.report({ stage: progress_1.ProgressReportStage.FetchingInsidersMetadata });
const { version: currentHash, date: currentDate } = util_2.insidersDownloadDirMetadata(downloadedPath);
const { version: latestHash, timestamp: latestTimestamp } = await util_2.getLatestInsidersMetadata(util_2.systemDefaultPlatform);
if (currentHash === latestHash) {
console.log(`Found insiders matching latest Insiders release. Skipping download.`);
return Promise.resolve(util_1.insidersDownloadDirToExecutablePath(downloadedPath));
reporter.report({ stage: progress_1.ProgressReportStage.FoundMatchingInstall, downloadedPath });
return Promise.resolve(util_2.insidersDownloadDirToExecutablePath(downloadedPath));
}
else {
try {
console.log(`Remove outdated Insiders at ${downloadedPath} and re-downloading.`);
console.log(`Old: ${currentHash} | ${currentDate}`);
console.log(`New: ${latestHash} | ${new Date(latestTimestamp).toISOString()}`);
reporter.report({
stage: progress_1.ProgressReportStage.ReplacingOldInsiders,
downloadedPath,
oldDate: currentDate,
oldHash: currentHash,
newDate: new Date(latestTimestamp),
newHash: latestHash,
});
await del.rmdir(downloadedPath);
console.log(`Removed ${downloadedPath}`);
}
catch (err) {
console.error(err);
reporter.error(err);
throw Error(`Failed to remove outdated Insiders at ${downloadedPath}.`);

@@ -190,20 +183,20 @@ }

else {
console.log(`Found ${downloadedPath}. Skipping download.`);
return Promise.resolve(util_1.downloadDirToExecutablePath(downloadedPath));
reporter.report({ stage: progress_1.ProgressReportStage.FoundMatchingInstall, downloadedPath });
return Promise.resolve(util_2.downloadDirToExecutablePath(downloadedPath));
}
}
try {
const { stream, format } = await downloadVSCodeArchive({ version, architecture, platform, cachePath });
const { stream, format } = await downloadVSCodeArchive({ version, architecture, platform, cachePath, reporter });
await unzipVSCode(downloadedPath, stream, format);
console.log(`Downloaded VS Code ${version} into ${downloadedPath}`);
reporter.report({ stage: progress_1.ProgressReportStage.NewInstallComplete, downloadedPath });
}
catch (err) {
console.error(err);
reporter.error(err);
throw Error(`Failed to download and unzip VS Code ${version}`);
}
if (version === 'insiders') {
return Promise.resolve(util_1.insidersDownloadDirToExecutablePath(downloadedPath));
return Promise.resolve(util_2.insidersDownloadDirToExecutablePath(downloadedPath));
}
else {
return util_1.downloadDirToExecutablePath(downloadedPath);
return util_2.downloadDirToExecutablePath(downloadedPath);
}

@@ -226,5 +219,5 @@ }

*/
async function downloadAndUnzipVSCode(version, platform = util_1.systemDefaultPlatform) {
return await download({ version, platform });
async function downloadAndUnzipVSCode(version, platform = util_2.systemDefaultPlatform, reporter) {
return await download({ version, platform, reporter });
}
exports.downloadAndUnzipVSCode = downloadAndUnzipVSCode;
export { download, downloadAndUnzipVSCode } from './download';
export { runTests } from './runTest';
export { resolveCliPathFromVSCodeExecutablePath, resolveCliArgsFromVSCodeExecutablePath } from './util';
export * from './progress';

@@ -6,2 +6,12 @@ "use strict";

*--------------------------------------------------------------------------------------------*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -17,1 +27,2 @@ exports.resolveCliArgsFromVSCodeExecutablePath = exports.resolveCliPathFromVSCodeExecutablePath = exports.runTests = exports.downloadAndUnzipVSCode = exports.download = void 0;

Object.defineProperty(exports, "resolveCliArgsFromVSCodeExecutablePath", { enumerable: true, get: function () { return util_1.resolveCliArgsFromVSCodeExecutablePath; } });
__exportStar(require("./progress"), exports);
import { DownloadVersion, DownloadPlatform } from './download';
import { ProgressReporter } from './progress';
export interface TestOptions {

@@ -74,2 +75,8 @@ /**

launchArgs?: string[];
/**
* Progress reporter to use while VS Code is downloaded. Defaults to a
* console reporter. A {@link SilentReporter} is also available, and you
* may implement your own.
*/
reporter?: ProgressReporter;
}

@@ -76,0 +83,0 @@ /**

@@ -18,3 +18,3 @@ "use strict";

if (!options.vscodeExecutablePath) {
options.vscodeExecutablePath = await download_1.downloadAndUnzipVSCode(options.version, options.platform);
options.vscodeExecutablePath = await download_1.downloadAndUnzipVSCode(options.version, options.platform, options.reporter);
}

@@ -21,0 +21,0 @@ let args = [

@@ -13,3 +13,3 @@ /// <reference types="node" />

version: any;
date: any;
date: Date;
};

@@ -16,0 +16,0 @@ export interface IUpdateMetadata {

@@ -108,3 +108,3 @@ "use strict";

version: productJson.commit,
date: productJson.date
date: new Date(productJson.date)
};

@@ -111,0 +111,0 @@ }

{
"name": "@vscode/test-electron",
"version": "2.0.3",
"version": "2.1.0",
"scripts": {

@@ -5,0 +5,0 @@ "compile": "tsc -p ./",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc