1 | import got from 'got';
|
2 | import gunzipMaybe from 'gunzip-maybe';
|
3 | import stream from 'stream';
|
4 | import * as tsm from 'ts-morph';
|
5 | import { promisify } from 'util';
|
6 | import { log } from '../utils/log';
|
7 | import { extractPackageTarball } from './extract-package-tarball';
|
8 |
|
9 | const pipeline = promisify(stream.pipeline);
|
10 |
|
11 | export async function tryDownloadPackage({
|
12 | tarball,
|
13 | }: {
|
14 | tarball: string;
|
15 | }): Promise<tsm.FileSystemHost | undefined> {
|
16 | try {
|
17 | const fileSystem = new tsm.InMemoryFileSystemHost();
|
18 |
|
19 | await pipeline(
|
20 | got.stream(tarball),
|
21 | gunzipMaybe(),
|
22 | extractPackageTarball({ fileSystem })
|
23 | );
|
24 |
|
25 | return fileSystem;
|
26 | } catch (err) {
|
27 | log('tryDownloadPackage: download failed: %O', { tarball, err });
|
28 | return undefined;
|
29 | }
|
30 | }
|