Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build/gulpfile.reh.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const rename = require('gulp-rename');
const replace = require('gulp-replace');
const filter = require('gulp-filter');
const { getProductionDependencies } = require('./lib/dependencies');
const { assetFromGithub } = require('./lib/github');
const vfs = require('vinyl-fs');
const packageJson = require('../package.json');
const flatmap = require('gulp-flatmap');
Expand Down Expand Up @@ -162,6 +163,11 @@ function nodejs(platform, arch) {
}

if (platform === 'win32') {
if (product.nodejsRepository) {
return assetFromGithub(product.nodejsRepository, nodeVersion, name => name === `win-${arch}-node.exe`)
.pipe(rename('node.exe'));
}

return remote(`/dist/v${nodeVersion}/win-${arch}/node.exe`, { base: 'https://nodejs.org' })
.pipe(rename('node.exe'));
}
Expand Down
30 changes: 3 additions & 27 deletions build/lib/extensions.js

Large diffs are not rendered by default.

29 changes: 2 additions & 27 deletions build/lib/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -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/**'))
Expand Down
43 changes: 43 additions & 0 deletions build/lib/github.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions build/lib/github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Stream } from 'stream';
import got from 'got';
import * as remote from 'gulp-remote-retry-src';
import * as through2 from 'through2';

const ghApiHeaders: Record<string, string> = {
Accept: 'application/vnd.github.v3+json',
'User-Agent': 'VSCode Build',
};
if (process.env.GITHUB_TOKEN) {
ghApiHeaders.Authorization = 'Basic ' + Buffer.from(process.env.GITHUB_TOKEN).toString('base64');
}
const ghDownloadHeaders = {
...ghApiHeaders,
Accept: 'application/octet-stream',
};

/**
* @param repo for example `Microsoft/vscode`
* @param version for example `16.17.1` - must be a valid releases tag
* @param assetName for example (name) => name === `win-x64-node.exe` - must be an asset that exists
* @returns a stream with the asset as file
*/
export function assetFromGithub(repo: string, version: string, assetFilter: (name: string) => boolean): Stream {
return remote(`/repos/${repo.replace(/^\/|\/$/g, '')}/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: { name: string }) => assetFilter(a.name));
if (!asset) {
return callback(new Error(`Could not find asset in release of ${repo} @ ${version}`));
}

const res = got.stream(asset.url, { headers: ghDownloadHeaders, followRedirect: true });
file.contents = res.pipe(through2());
callback(null, file);
}));
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "code-oss-dev",
"version": "1.78.0",
"distro": "41a18d6ff0c57bb1e805906a181778fe4747cf86",
"distro": "8e1c873581aa258fc90ddfa322f0d76e49f1c822",
"author": {
"name": "Microsoft Corporation"
},
Expand Down