Use fetch() to download node
Summary: This is more reliable and follows redirect which we need for GitHub downloads. Reviewed By: antonk52 Differential Revision: D50263976 fbshipit-source-id: d001b6eb460510b0b673ea66651e7c39cac3092f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0cb5331c31
commit
c80be9960a
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
const dotenv = require('dotenv').config();
|
const dotenv = require('dotenv').config();
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import https from 'https';
|
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import tar from 'tar';
|
import tar from 'tar';
|
||||||
import {
|
import {
|
||||||
@@ -36,6 +35,7 @@ import {spawn} from 'promisify-child-process';
|
|||||||
import {homedir} from 'os';
|
import {homedir} from 'os';
|
||||||
import {need as pkgFetch} from 'pkg-fetch';
|
import {need as pkgFetch} from 'pkg-fetch';
|
||||||
import {exec} from 'child_process';
|
import {exec} from 'child_process';
|
||||||
|
import fetch from '@adobe/node-fetch-retry';
|
||||||
|
|
||||||
// This needs to be tested individually. As of 2022Q2, node17 is not supported.
|
// This needs to be tested individually. As of 2022Q2, node17 is not supported.
|
||||||
const SUPPORTED_NODE_PLATFORM = 'node16';
|
const SUPPORTED_NODE_PLATFORM = 'node16';
|
||||||
@@ -489,16 +489,19 @@ async function download(url: string, dest: string): Promise<void> {
|
|||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
// Then, download the file and save it to the destination path.
|
// Then, download the file and save it to the destination path.
|
||||||
const file: fs.WriteStream = fs.createWriteStream(dest);
|
const file: fs.WriteStream = fs.createWriteStream(dest);
|
||||||
https
|
fetch(url)
|
||||||
.get(url, (response) => {
|
.then((response) => {
|
||||||
response.pipe(file);
|
response.body.pipe(file);
|
||||||
|
response.body.on('error', (err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
file.on('finish', () => {
|
file.on('finish', () => {
|
||||||
file.close();
|
file.close();
|
||||||
console.log(`✅ Download successful ${url}.`);
|
console.log(`✅ Download successful ${url} to ${dest}.`);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.on('error', (error: Error) => {
|
.catch((error: Error) => {
|
||||||
console.log(`❌ Download failed ${url}. Error: ${error}`);
|
console.log(`❌ Download failed ${url}. Error: ${error}`);
|
||||||
fs.unlink(dest);
|
fs.unlink(dest);
|
||||||
reject(error);
|
reject(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user