1
1
import assert from "node:assert" ;
2
2
import * as fs from "node:fs" ;
3
+ import { pipeline } from "node:stream" ;
3
4
import { resolve } from "node:path" ;
4
5
import { fileURLToPath } from "node:url" ;
5
- import { format } from "node:util" ;
6
+ import { format , promisify } from "node:util" ;
6
7
7
8
const CLI_ROOT = resolve ( fileURLToPath ( import . meta. url ) , "../.." ) ;
8
9
const PACKAGES_PGLT_ROOT = resolve ( CLI_ROOT , ".." ) ;
9
10
const PGLT_ROOT = resolve ( PACKAGES_PGLT_ROOT , "../.." ) ;
10
11
const MANIFEST_PATH = resolve ( CLI_ROOT , "package.json" ) ;
11
12
13
+ const streamPipeline = promisify ( pipeline ) ;
14
+
12
15
async function downloadSchema ( releaseTag , githubToken ) {
13
16
const assetUrl = `https://github.com/supabase-community/postgres_lsp/releases/download/${ releaseTag } /schema.json` ;
14
17
@@ -26,11 +29,7 @@ async function downloadSchema(releaseTag, githubToken) {
26
29
// download to root.
27
30
const fileStream = fs . createWriteStream ( resolve ( PGLT_ROOT , "schema.json" ) ) ;
28
31
29
- await new Promise ( ( res , rej ) => {
30
- response . body . pipeTo ( fileStream ) ;
31
- fileStream . on ( "error" , rej ) ;
32
- fileStream . on ( "finish" , res ) ;
33
- } ) ;
32
+ await streamPipeline ( response . body , fileStream ) ;
34
33
35
34
console . log ( `Downloaded schema for ${ releaseTag } ` ) ;
36
35
}
@@ -53,11 +52,7 @@ async function downloadAsset(platform, os, arch, releaseTag, githubToken) {
53
52
// just download to root.
54
53
const fileStream = fs . createWriteStream ( getBinarySource ( os , platform , arch ) ) ;
55
54
56
- await new Promise ( ( res , rej ) => {
57
- response . body . pipeTo ( fileStream ) ;
58
- fileStream . on ( "error" , rej ) ;
59
- fileStream . on ( "finish" , res ) ;
60
- } ) ;
55
+ await streamPipeline ( response . body , fileStream ) ;
61
56
62
57
console . log ( `Downloaded asset for ${ buildName } (v${ releaseTag } )` ) ;
63
58
}
0 commit comments