@@ -8,14 +8,14 @@ import fse from 'fs-extra';
8
8
import * as fsp from 'fs/promises' ;
9
9
import { JSDOM } from 'jsdom' ;
10
10
import Initer from 'lethal-build' ;
11
- import fetch from 'node-fetch ' ;
11
+ import needle from 'needle ' ;
12
12
import * as path from 'path' ;
13
13
import 'promise-snake' ;
14
14
15
15
export const {
16
16
comp,
17
17
dir,
18
- } = Initer ( import . meta . url + '/../..' ) ;
18
+ } = Initer ( __dirname + '/../..' ) ;
19
19
20
20
export async function pipeStream ( from : NodeJS . ReadableStream , to : NodeJS . WritableStream ) {
21
21
await new Promise ( res => from . pipe ( to ) . once ( 'close' , res ) ) ;
@@ -32,9 +32,9 @@ export function outFilename(file: string) {
32
32
return path . relative ( dir , file ) ;
33
33
}
34
34
35
- export async function curl ( url : string ) {
36
- const rep = await fetch ( url , { protocol : 'http :' } ) ;
37
- if ( ! rep . ok ) throw new Error ( `Failed to fetch ${ url } ` ) ;
35
+ export async function curl ( url : string ) : Promise < NodeJS . ReadableStream > {
36
+ const rep = await needle ( 'get' , url , { protocol : 'https :' } ) ;
37
+ if ( rep . errored ) throw new Error ( `Failed to fetch ${ url } ` ) ;
38
38
console . log ( `Fetched ${ url } ` ) ;
39
39
return rep ;
40
40
}
@@ -51,7 +51,7 @@ export interface DownloadCfg {
51
51
export async function download ( url : string , file : string , { force = false , tryGet = false } : DownloadCfg = { } ) {
52
52
if ( ! force && await fse . exists ( file ) ) return console . log ( `Already find ${ outFilename ( file ) } ` ) ;
53
53
try {
54
- await writeFile ( ( await curl ( url ) ) . body , file ) ;
54
+ await writeFile ( await curl ( url ) , file ) ;
55
55
}
56
56
catch ( err ) {
57
57
if ( ! tryGet ) throw err ;
0 commit comments