Skip to content

Commit 3f5def1

Browse files
authored
Add logging to node download (microsoft#184070)
Add logging to node download. For microsoft#182951
1 parent ce729a5 commit 3f5def1

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

build/gulpfile.reh.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const { compileBuildTask } = require('./gulpfile.compile');
2929
const { compileExtensionsBuildTask, compileExtensionMediaBuildTask } = require('./gulpfile.extensions');
3030
const { vscodeWebEntryPoints, vscodeWebResourceIncludes, createVSCodeWebFileContentMapper } = require('./gulpfile.vscode.web');
3131
const cp = require('child_process');
32+
const log = require('fancy-log');
3233

3334
const REPO_ROOT = path.dirname(__dirname);
3435
const commit = getVersion(REPO_ROOT);
@@ -163,25 +164,27 @@ function nodejs(platform, arch) {
163164

164165
if (platform === 'win32') {
165166
if (product.nodejsRepository) {
167+
log(`Downloading node.js ${nodeVersion} ${platform} ${arch} from ${product.nodejsRepository}...`);
166168
return assetFromGithub(product.nodejsRepository, nodeVersion, name => name === `win-${arch}-node.exe`)
167169
.pipe(rename('node.exe'));
168170
}
169-
170-
return remote(`/dist/v${nodeVersion}/win-${arch}/node.exe`, { base: 'https://nodejs.org' })
171+
log(`Downloading node.js ${nodeVersion} ${platform} ${arch} from https://nodejs.org`);
172+
return remote(`/dist/v${nodeVersion}/win-${arch}/node.exe`, { base: 'https://nodejs.org', verbose: true })
171173
.pipe(rename('node.exe'));
172174
}
173175

174176
if (arch === 'alpine' || platform === 'alpine') {
175177
const imageName = arch === 'arm64' ? 'arm64v8/node' : 'node';
178+
log(`Downloading node.js ${nodeVersion} ${platform} ${arch} from docker image ${imageName}`);
176179
const contents = cp.execSync(`docker run --rm ${imageName}:${nodeVersion}-alpine /bin/sh -c 'cat \`which node\`'`, { maxBuffer: 100 * 1024 * 1024, encoding: 'buffer' });
177180
return es.readArray([new File({ path: 'node', contents, stat: { mode: parseInt('755', 8) } })]);
178181
}
179182

180183
if (arch === 'armhf') {
181184
arch = 'armv7l';
182185
}
183-
184-
return remote(`/dist/v${nodeVersion}/node-v${nodeVersion}-${platform}-${arch}.tar.gz`, { base: 'https://nodejs.org' })
186+
log(`Downloading node.js ${nodeVersion} ${platform} ${arch} from https://nodejs.org`);
187+
return remote(`/dist/v${nodeVersion}/node-v${nodeVersion}-${platform}-${arch}.tar.gz`, { base: 'https://nodejs.org', verbose: true })
185188
.pipe(flatmap(stream => stream.pipe(gunzip()).pipe(untar())))
186189
.pipe(filter('**/node'))
187190
.pipe(util.setExecutableBit('**'))

build/lib/gulpRemoteSource.js

Lines changed: 16 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/gulpRemoteSource.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import * as es from 'event-stream';
77
import fetch, { RequestInit } from 'node-fetch';
88
import * as VinylFile from 'vinyl';
99
import * as through2 from 'through2';
10+
import * as log from 'fancy-log';
11+
import * as ansiColors from 'ansi-colors';
1012

1113
export interface IOptions {
1214
base?: string;
1315
buffer?: boolean;
1416
fetchOptions?: RequestInit;
17+
verbose?: boolean;
1518
}
1619

1720
export function remote(urls: string[] | string, options: IOptions): es.ThroughStream {
@@ -41,9 +44,17 @@ export function remote(urls: string[] | string, options: IOptions): es.ThroughSt
4144
}));
4245
}
4346

44-
async function fetchWithRetry(url: string, options: IOptions, retries = 3, retryDelay = 1000): Promise<VinylFile> {
47+
async function fetchWithRetry(url: string, options: IOptions, retries = 3, retryDelay = 250): Promise<VinylFile> {
4548
try {
49+
let startTime = 0;
50+
if (options.verbose) {
51+
log(`Start fetching ${ansiColors.magenta(url)}${retries !== 3 ? `(${3 - retries} retry}` : ''}`);
52+
startTime = new Date().getTime();
53+
}
4654
const response = await fetch(url, options.fetchOptions);
55+
if (options.verbose) {
56+
log(`Fetch completed: Status ${response.status}. Took ${ansiColors.magenta(`${new Date().getTime() - startTime} ms`)}`);
57+
}
4758
if (response.ok && (response.status >= 200 && response.status < 300)) {
4859
// request must be piped out once created, or we'll get this error: "You cannot pipe after data has been emitted from the response."
4960
const contents = options.buffer ? await response.buffer() : response.body.pipe(through2());
@@ -54,12 +65,15 @@ async function fetchWithRetry(url: string, options: IOptions, retries = 3, retry
5465
contents
5566
});
5667
}
57-
throw new Error(`Request ${url} failed with status code: ${response.status}`);
68+
throw new Error(`Request ${ansiColors.magenta(url)} failed with status code: ${response.status}`);
5869
} catch (e) {
5970
if (retries > 0) {
6071
await new Promise(c => setTimeout(c, retryDelay));
6172
return fetchWithRetry(url, options, retries - 1, retryDelay * 3);
6273
}
74+
if (options.verbose) {
75+
log(`Fetching ${ansiColors.cyan(url)} failed: ${e}`);
76+
}
6377
throw e;
6478
}
6579
}

0 commit comments

Comments
 (0)