diff --git a/src/js/lib/project-manager/src/build.ts b/src/js/lib/project-manager/src/build.ts index 5797085f23..02cd4e23ee 100644 --- a/src/js/lib/project-manager/src/build.ts +++ b/src/js/lib/project-manager/src/build.ts @@ -1,14 +1,19 @@ /// Build script that downloads and extracts the project manager from CI. /// The project manager will be available at `paths.dist.bin` after running this script. +// @ts-ignore import { http } from 'follow-redirects' import * as os from 'os' import * as fss from 'fs' import * as path from 'path' +// @ts-ignore import * as tar from 'tar' +// @ts-ignore import * as unzipper from 'unzipper' import * as url from 'url' +// @ts-ignore import * as paths from './../../../../../build/paths' +import { IncomingMessage } from 'http' const fs = fss.promises const distPath = paths.dist.bin @@ -66,7 +71,7 @@ function make_project_manager_binary_executable() { } } -function decompress_project_manager(source_file_path, target_folder) { +function decompress_project_manager(source_file_path: fss.PathLike, target_folder: string) { let decompressor if (source_file_path.toString().endsWith('.zip')) { decompressor = unzipper.Extract({ path: target_folder }) @@ -109,11 +114,15 @@ class DownloadProgressIndicator { } // TODO: Consider adding to common library for re-use in other parts of the build system. -async function download_project_manager( - file_url: string, - overwrite: boolean -): Promise { - const file_name = url.parse(file_url).pathname.split('/').pop() +async function download_project_manager(file_url: string, overwrite: boolean): Promise { + const parse_result = url.parse(file_url).pathname + if (parse_result === undefined || parse_result === null) { + throw `File URL does not contain valid path name: ` + file_url + } + const file_name = parse_result.split('/').pop() + if (file_name === undefined || file_name === null) { + throw `File URL does not contain path separator: ` + file_url + } const file_path = path.resolve(distPath, file_name) if (fss.existsSync(file_path) && !overwrite) { @@ -134,8 +143,8 @@ async function download_project_manager( const target_file = fss.createWriteStream(file_path) const progress_indicator = new DownloadProgressIndicator() - http.get(options, (res) => { - res.on('data', (data) => { + http.get(options, (res: IncomingMessage) => { + res.on('data', (data: string) => { target_file.write(data) progress_indicator.add_progress_bytes(data.length) }).on('end', () => {