diff options
Diffstat (limited to 'build/lib/extensions.js')
-rw-r--r-- | build/lib/extensions.js | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/build/lib/extensions.js b/build/lib/extensions.js index 99ebc6dee2b..50fc4dd945b 100644 --- a/build/lib/extensions.js +++ b/build/lib/extensions.js @@ -4,13 +4,15 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); -exports.buildExtensionMedia = exports.webpackExtensions = exports.translatePackageJSON = exports.scanBuiltinExtensions = exports.packageMarketplaceExtensionsStream = exports.packageLocalExtensionsStream = exports.fromMarketplace = void 0; +exports.buildExtensionMedia = exports.webpackExtensions = exports.translatePackageJSON = exports.scanBuiltinExtensions = exports.packageMarketplaceExtensionsStream = exports.packageLocalExtensionsStream = exports.fromGithub = exports.fromMarketplace = void 0; const es = require("event-stream"); const fs = require("fs"); const cp = require("child_process"); const glob = require("glob"); const gulp = require("gulp"); const path = require("path"); +const through2 = require("through2"); +const got_1 = require("got"); const File = require("vinyl"); const stats_1 = require("./stats"); const util2 = require("./util"); @@ -169,16 +171,17 @@ function fromLocalNormal(extensionPath) { .catch(err => result.emit('error', err)); return result.pipe((0, stats_1.createStatsStream)(path.basename(extensionPath))); } +const userAgent = 'VSCode Build'; const baseHeaders = { 'X-Market-Client-Id': 'VSCode Build', - 'User-Agent': 'VSCode Build', + 'User-Agent': userAgent, 'X-Market-User-Id': '291C1CD0-051A-4123-9B4B-30D60EF52EE2', }; -function fromMarketplace(extensionName, version, metadata) { +function fromMarketplace(serviceUrl, { name: extensionName, version, metadata }) { const remote = require('gulp-remote-retry-src'); const json = require('gulp-json-editor'); const [publisher, name] = extensionName.split('.'); - const url = `https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${publisher}/vsextensions/${name}/${version}/vspackage`; + const url = `${serviceUrl}/publishers/${publisher}/vsextensions/${name}/${version}/vspackage`; fancyLog('Downloading extension:', ansiColors.yellow(`${extensionName}@${version}`), '...'); const options = { base: url, @@ -198,6 +201,44 @@ function fromMarketplace(extensionName, version, metadata) { .pipe(packageJsonFilter.restore); } exports.fromMarketplace = fromMarketplace; +const ghApiHeaders = { + Accept: 'application/vnd.github.v3+json', + 'User-Agent': userAgent, +}; +if (process.env.GITHUB_TOKEN) { + ghApiHeaders.Authorization = 'Basic ' + Buffer.from(process.env.GITHUB_TOKEN).toString('base64'); +} +const ghDownloadHeaders = { + ...ghApiHeaders, + Accept: 'application/octet-stream', +}; +function fromGithub({ name, version, repo, metadata }) { + const remote = require('gulp-remote-retry-src'); + const json = require('gulp-json-editor'); + fancyLog('Downloading extension from GH:', ansiColors.yellow(`${name}@${version}`), '...'); + const packageJsonFilter = filter('package.json', { restore: true }); + return remote([`/repos${new URL(repo).pathname}/releases/tags/v${version}`], { + base: 'https://api.github.com', + requestOptions: { headers: ghApiHeaders } + }).pipe(through2.obj(function (file, _enc, callback) { + const asset = JSON.parse(file.contents.toString()).assets.find((a) => a.name.endsWith('.vsix')); + if (!asset) { + return callback(new Error(`Could not find vsix in release of ${repo} @ ${version}`)); + } + const res = got_1.default.stream(asset.url, { headers: ghDownloadHeaders, followRedirect: true }); + file.contents = res.pipe(through2()); + callback(null, file); + })) + .pipe(buffer()) + .pipe(vzip.src()) + .pipe(filter('extension/**')) + .pipe(rename(p => p.dirname = p.dirname.replace(/^extension\/?/, ''))) + .pipe(packageJsonFilter) + .pipe(buffer()) + .pipe(json({ __metadata: metadata })) + .pipe(packageJsonFilter.restore); +} +exports.fromGithub = fromGithub; const excludedExtensions = [ 'vscode-api-tests', 'vscode-colorize-tests', @@ -272,14 +313,14 @@ function packageLocalExtensionsStream(forWeb) { .pipe(util2.setExecutableBit(['**/*.sh']))); } exports.packageLocalExtensionsStream = packageLocalExtensionsStream; -function packageMarketplaceExtensionsStream(forWeb) { +function packageMarketplaceExtensionsStream(forWeb, galleryServiceUrl) { const marketplaceExtensionsDescriptions = [ ...builtInExtensions.filter(({ name }) => (forWeb ? !marketplaceWebExtensionsExclude.has(name) : true)), ...(forWeb ? webBuiltInExtensions : []) ]; const marketplaceExtensionsStream = minifyExtensionResources(es.merge(...marketplaceExtensionsDescriptions .map(extension => { - const input = fromMarketplace(extension.name, extension.version, extension.metadata) + const input = (galleryServiceUrl ? fromMarketplace(galleryServiceUrl, extension) : fromGithub(extension)) .pipe(rename(p => p.dirname = `extensions/${extension.name}/${p.dirname}`)); return updateExtensionPackageJSON(input, (data) => { delete data.scripts; |