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
+3 -3
View File
@@ -22,7 +22,7 @@ import HakEnv from './hakEnv';
export default async function clean(hakEnv: HakEnv, moduleInfo: DependencyInfo): Promise<void> {
await new Promise<void>((resolve, reject) => {
rimraf(moduleInfo.moduleDotHakDir, (err: Error) => {
rimraf(moduleInfo.moduleDotHakDir, (err?: Error | null) => {
if (err) {
reject(err);
} else {
@@ -32,7 +32,7 @@ export default async function clean(hakEnv: HakEnv, moduleInfo: DependencyInfo):
});
await new Promise<void>((resolve, reject) => {
rimraf(path.join(hakEnv.dotHakDir, 'links', moduleInfo.name), (err: Error) => {
rimraf(path.join(hakEnv.dotHakDir, 'links', moduleInfo.name), (err?: Error | null) => {
if (err) {
reject(err);
} else {
@@ -42,7 +42,7 @@ export default async function clean(hakEnv: HakEnv, moduleInfo: DependencyInfo):
});
await new Promise<void>((resolve, reject) => {
rimraf(path.join(hakEnv.projectRoot, 'node_modules', moduleInfo.name), (err: Error) => {
rimraf(path.join(hakEnv.projectRoot, 'node_modules', moduleInfo.name), (err?: Error | null) => {
if (err) {
reject(err);
} else {
+19
View File
@@ -0,0 +1,19 @@
/*
Copyright 2022 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
declare module "find-npm-prefix" {
export default function findPrefix(dir: string): Promise<string>;
}
+7 -17
View File
@@ -37,20 +37,17 @@ async function getRuntimeVersion(projectRoot: string): Promise<string> {
export default class HakEnv {
public readonly target: Target;
public runtime: string;
public runtimeVersion: string;
public runtime?: string;
public runtimeVersion?: string;
public dotHakDir: string;
public constructor(public readonly projectRoot: string, targetId: TargetId | null) {
if (targetId) {
this.target = TARGETS[targetId];
} else {
this.target = getHost();
}
const target = targetId ? TARGETS[targetId] : getHost();
if (!this.target) {
if (!target) {
throw new Error(`Unknown target ${targetId}!`);
}
this.target = target;
this.dotHakDir = path.join(this.projectRoot, '.hak');
}
@@ -60,10 +57,7 @@ export default class HakEnv {
}
public getRuntimeAbi(): string {
return nodePreGypVersioning.get_runtime_abi(
this.runtime,
this.runtimeVersion,
);
return nodePreGypVersioning.get_runtime_abi(this.runtime!, this.runtimeVersion!);
}
// {node_abi}-{platform}-{arch}
@@ -95,7 +89,7 @@ export default class HakEnv {
return isHostId(this.target.id);
}
public makeGypEnv(): Record<string, string> {
public makeGypEnv(): Record<string, string | undefined> {
return Object.assign({}, process.env, {
npm_config_arch: this.target.arch,
npm_config_target_arch: this.target.arch,
@@ -107,10 +101,6 @@ export default class HakEnv {
});
}
public getNodeModuleBin(name: string): string {
return path.join(this.projectRoot, 'node_modules', '.bin', name);
}
public wantsStaticSqlCipherUnix(): boolean {
return this.isMac() || process.env.SQLCIPHER_STATIC == '1';
}
+1 -1
View File
@@ -38,7 +38,7 @@ const MODULECOMMANDS = [
// Shortcuts for multiple commands at once (useful for building universal binaries
// because you can run the fetch/fetchDeps/build for each arch and then copy/link once)
const METACOMMANDS = {
const METACOMMANDS: Record<string, string[]> = {
'fetchandbuild': ['check', 'fetch', 'fetchDeps', 'build'],
'copyandlink': ['copy', 'link'],
};
+20
View File
@@ -0,0 +1,20 @@
/*
Copyright 2022 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
declare module "node-pre-gyp/lib/util/versioning" {
// eslint-disable-next-line @typescript-eslint/naming-convention
export function get_runtime_abi(runtime: string, version: string): string;
}
-18
View File
@@ -1,18 +0,0 @@
{
"compilerOptions": {
"moduleResolution": "node",
"esModuleInterop": true,
"target": "es2017",
"module": "commonjs",
"sourceMap": false,
"lib": [
"es2019",
]
},
"include": [
"./**/*.ts"
],
"ts-node": {
"transpileOnly": true
}
}