Improve use of Typescript (#474)

* Switch out needle with node-fetch

* Iterate

* Update asar package and switch to canonical name

* Use ts-node for scripts

* Iterate

* Update yarn.lock

* Use node:stream.promises

* Remove logfile

* Fix types

* Fix types
This commit is contained in:
Michael Telatynski
2022-12-05 11:50:49 +00:00
committed by GitHub
parent b52787a49e
commit 56370de568
13 changed files with 162 additions and 107 deletions

View File

@@ -18,12 +18,20 @@ import path from 'path';
import childProcess from 'child_process';
import fs from 'fs';
import fsProm from 'fs/promises';
import needle from 'needle';
import tar from 'tar';
import fetch from 'node-fetch';
import { promises as stream } from "stream";
import HakEnv from '../../scripts/hak/hakEnv';
import { DependencyInfo } from '../../scripts/hak/dep';
async function download(url: string, filename: string): Promise<void> {
const resp = await fetch(url);
if (!resp.ok) throw new Error(`unexpected response ${resp.statusText}`);
if (!resp.body) throw new Error(`unexpected response has no body ${resp.statusText}`);
await stream.pipeline(resp.body, fs.createWriteStream(filename));
}
export default async function(hakEnv: HakEnv, moduleInfo: DependencyInfo): Promise<void> {
if (hakEnv.wantsStaticSqlCipher()) {
await getSqlCipher(hakEnv, moduleInfo);
@@ -57,11 +65,7 @@ async function getSqlCipher(hakEnv: HakEnv, moduleInfo: DependencyInfo): Promise
haveSqlcipherTar = false;
}
if (!haveSqlcipherTar) {
const bob = needle('get', `https://github.com/sqlcipher/sqlcipher/archive/v${version}.tar.gz`, {
follow: 10,
output: sqlCipherTarball,
});
await bob;
await download(`https://github.com/sqlcipher/sqlcipher/archive/v${version}.tar.gz`, sqlCipherTarball);
}
// Extract the tarball to per-target directories, then we avoid cross-contaiminating archs
@@ -118,10 +122,7 @@ async function getOpenSsl(hakEnv: HakEnv, moduleInfo: DependencyInfo): Promise<v
haveOpenSslTar = false;
}
if (!haveOpenSslTar) {
await needle('get', `https://www.openssl.org/source/openssl-${version}.tar.gz`, {
follow: 10,
output: openSslTarball,
});
await download(`https://www.openssl.org/source/openssl-${version}.tar.gz`, openSslTarball);
}
console.log("extracting " + openSslTarball + " in " + moduleInfo.moduleTargetDotHakDir);