server - introduce support for nodejsRepository (#179105)

* server - introduce support for `nodejsRepository`

* fix path

* add auth

* proper download

* extract to utility function

* reuse

* fix compile
This commit is contained in:
Benjamin Pasero
2023-04-05 14:36:25 +02:00
committed by GitHub
parent 19f5801470
commit 34d69db22c
6 changed files with 98 additions and 55 deletions

View File

@@ -9,8 +9,6 @@ import * as cp from 'child_process';
import * as glob from 'glob';
import * as gulp from 'gulp';
import * as path from 'path';
import * as through2 from 'through2';
import got from 'got';
import { Stream } from 'stream';
import * as File from 'vinyl';
import { createStatsStream } from './stats';
@@ -26,6 +24,7 @@ import webpack = require('webpack');
import { getProductionDependencies } from './dependencies';
import { getExtensionStream } from './builtInExtensions';
import { getVersion } from './getVersion';
import { assetFromGithub } from './github';
const root = path.dirname(path.dirname(__dirname));
const commit = getVersion(root);
@@ -238,39 +237,15 @@ export function fromMarketplace(serviceUrl: string, { name: extensionName, versi
.pipe(packageJsonFilter.restore);
}
const ghApiHeaders: Record<string, string> = {
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',
};
export function fromGithub({ name, version, repo, metadata }: IBuiltInExtension): Stream {
const remote = require('gulp-remote-retry-src');
const json = require('gulp-json-editor') as typeof import('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: any) => a.name.endsWith('.vsix'));
if (!asset) {
return callback(new Error(`Could not find vsix in release of ${repo} @ ${version}`));
}
const res = got.stream(asset.url, { headers: ghDownloadHeaders, followRedirect: true });
file.contents = res.pipe(through2());
callback(null, file);
}))
return assetFromGithub(new URL(repo).pathname, version, name => name.endsWith('.vsix'))
.pipe(buffer())
.pipe(vzip.src())
.pipe(filter('extension/**'))