UNPKG

8.07 kBJavaScriptView Raw
1"use strict";
2/*---------------------------------------------------------------------------------------------
3 * Copyright (c) Microsoft Corporation. All rights reserved.
4 * Licensed under the MIT License. See License.txt in the project root for license information.
5 *--------------------------------------------------------------------------------------------*/
6var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7 return new (P || (P = Promise))(function (resolve, reject) {
8 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
11 step((generator = generator.apply(thisArg, _arguments || [])).next());
12 });
13};
14var __generator = (this && this.__generator) || function (thisArg, body) {
15 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
16 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
17 function verb(n) { return function (v) { return step([n, v]); }; }
18 function step(op) {
19 if (f) throw new TypeError("Generator is already executing.");
20 while (_) try {
21 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
22 if (y = 0, t) op = [op[0] & 2, t.value];
23 switch (op[0]) {
24 case 0: case 1: t = op; break;
25 case 4: _.label++; return { value: op[1], done: false };
26 case 5: _.label++; y = op[1]; op = [0]; continue;
27 case 7: op = _.ops.pop(); _.trys.pop(); continue;
28 default:
29 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
30 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
31 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
32 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
33 if (t[2]) _.ops.pop();
34 _.trys.pop(); continue;
35 }
36 op = body.call(thisArg, _);
37 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
38 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
39 }
40};
41Object.defineProperty(exports, "__esModule", { value: true });
42var path = require("path");
43var url_1 = require("url");
44var request = require("./request");
45switch (process.platform) {
46 case 'darwin':
47 exports.downloadPlatform = 'darwin';
48 break;
49 case 'win32':
50 exports.downloadPlatform = 'win32-archive';
51 break;
52 default:
53 exports.downloadPlatform = 'linux-x64';
54}
55function getVSCodeDownloadUrl(version) {
56 if (version === 'insiders') {
57 return "https://update.code.visualstudio.com/latest/" + exports.downloadPlatform + "/insider";
58 }
59 return "https://update.code.visualstudio.com/" + version + "/" + exports.downloadPlatform + "/stable";
60}
61exports.getVSCodeDownloadUrl = getVSCodeDownloadUrl;
62var HttpsProxyAgent = require('https-proxy-agent');
63var HttpProxyAgent = require('http-proxy-agent');
64var PROXY_AGENT = undefined;
65var HTTPS_PROXY_AGENT = undefined;
66if (process.env.npm_config_proxy) {
67 PROXY_AGENT = new HttpProxyAgent(process.env.npm_config_proxy);
68 HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_proxy);
69}
70if (process.env.npm_config_https_proxy) {
71 HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_https_proxy);
72}
73function urlToOptions(url) {
74 var options = url_1.parse(url);
75 if (PROXY_AGENT && options.protocol.startsWith('http:')) {
76 options.agent = PROXY_AGENT;
77 }
78 if (HTTPS_PROXY_AGENT && options.protocol.startsWith('https:')) {
79 options.agent = HTTPS_PROXY_AGENT;
80 }
81 return options;
82}
83exports.urlToOptions = urlToOptions;
84function downloadDirToExecutablePath(dir) {
85 if (process.platform === 'win32') {
86 return path.resolve(dir, 'Code.exe');
87 }
88 else if (process.platform === 'darwin') {
89 return path.resolve(dir, 'Visual Studio Code.app/Contents/MacOS/Electron');
90 }
91 else {
92 return path.resolve(dir, 'VSCode-linux-x64/code');
93 }
94}
95exports.downloadDirToExecutablePath = downloadDirToExecutablePath;
96function insidersDownloadDirToExecutablePath(dir) {
97 if (process.platform === 'win32') {
98 return path.resolve(dir, 'Code - Insiders.exe');
99 }
100 else if (process.platform === 'darwin') {
101 return path.resolve(dir, 'Visual Studio Code - Insiders.app/Contents/MacOS/Electron');
102 }
103 else {
104 return path.resolve(dir, 'VSCode-linux-x64/code-insiders');
105 }
106}
107exports.insidersDownloadDirToExecutablePath = insidersDownloadDirToExecutablePath;
108function insidersDownloadDirMetadata(dir) {
109 var productJsonPath;
110 if (process.platform === 'win32') {
111 productJsonPath = path.resolve(dir, 'resources/app/product.json');
112 }
113 else if (process.platform === 'darwin') {
114 productJsonPath = path.resolve(dir, 'Visual Studio Code - Insiders.app/Contents/Resources/app/product.json');
115 }
116 else {
117 productJsonPath = path.resolve(dir, 'VSCode-linux-x64/resources/app/product.json');
118 }
119 var productJson = require(productJsonPath);
120 return {
121 version: productJson.commit,
122 date: productJson.date
123 };
124}
125exports.insidersDownloadDirMetadata = insidersDownloadDirMetadata;
126function getLatestInsidersMetadata(platform) {
127 return __awaiter(this, void 0, void 0, function () {
128 var remoteUrl;
129 return __generator(this, function (_a) {
130 switch (_a.label) {
131 case 0:
132 remoteUrl = "https://update.code.visualstudio.com/api/update/" + platform + "/insider/latest";
133 return [4 /*yield*/, request.getJSON(remoteUrl)];
134 case 1: return [2 /*return*/, _a.sent()];
135 }
136 });
137 });
138}
139exports.getLatestInsidersMetadata = getLatestInsidersMetadata;
140/**
141 * Resolve the VS Code cli path from executable path returned from `downloadAndUnzipVSCode`.
142 * You can use this path to spawn processes for extension management. For example:
143 *
144 * ```ts
145 * const cp = require('child_process');
146 * const { downloadAndUnzipVSCode, resolveCliPathFromExecutablePath } = require('vscode-test')
147 * const vscodeExecutablePath = await downloadAndUnzipVSCode('1.36.0');
148 * const cliPath = resolveCliPathFromExecutablePath(vscodeExecutablePath);
149 *
150 * cp.spawnSync(cliPath, ['--install-extension', '<EXTENSION-ID-OR-PATH-TO-VSIX>'], {
151 * encoding: 'utf-8',
152 * stdio: 'inherit'
153 * });
154 * ```
155 *
156 * @param vscodeExecutablePath The `vscodeExecutablePath` from `downloadAndUnzipVSCode`.
157 */
158function resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath) {
159 if (process.platform === 'win32') {
160 if (vscodeExecutablePath.endsWith('Code - Insiders.exe')) {
161 return path.resolve(vscodeExecutablePath, '../bin/code-insiders.cmd');
162 }
163 else {
164 return path.resolve(vscodeExecutablePath, '../bin/code.cmd');
165 }
166 }
167 else if (process.platform === 'darwin') {
168 return path.resolve(vscodeExecutablePath, '../../../Contents/Resources/app/bin/code');
169 }
170 else {
171 if (vscodeExecutablePath.endsWith('code-insiders')) {
172 return path.resolve(vscodeExecutablePath, '../bin/code-insiders');
173 }
174 else {
175 return path.resolve(vscodeExecutablePath, '../bin/code');
176 }
177 }
178}
179exports.resolveCliPathFromVSCodeExecutablePath = resolveCliPathFromVSCodeExecutablePath;