@@ -3,14 +3,19 @@ import * as fs from "node:fs";
3
3
import { pipeline } from "node:stream" ;
4
4
import { resolve } from "node:path" ;
5
5
import { fileURLToPath } from "node:url" ;
6
- import { format , promisify } from "node:util" ;
6
+ import { promisify } from "node:util" ;
7
+ const streamPipeline = promisify ( pipeline ) ;
7
8
8
9
const CLI_ROOT = resolve ( fileURLToPath ( import . meta. url ) , "../.." ) ;
9
10
const PACKAGES_PGLT_ROOT = resolve ( CLI_ROOT , ".." ) ;
10
11
const PGLT_ROOT = resolve ( PACKAGES_PGLT_ROOT , "../.." ) ;
11
12
const MANIFEST_PATH = resolve ( CLI_ROOT , "package.json" ) ;
12
-
13
- const streamPipeline = promisify ( pipeline ) ;
13
+ const SUPPORTED_PLATFORMS = [
14
+ "pc-windows-msvc" ,
15
+ "apple-darwin" ,
16
+ "unknown-linux-gnu" ,
17
+ ] ;
18
+ const SUPPORTED_ARCHITECTURES = [ "x86_64" , "aarch64" ] ;
14
19
15
20
async function downloadSchema ( releaseTag , githubToken ) {
16
21
const assetUrl = `https://github.com/supabase-community/postgres_lsp/releases/download/${ releaseTag } /schema.json` ;
@@ -34,7 +39,7 @@ async function downloadSchema(releaseTag, githubToken) {
34
39
console . log ( `Downloaded schema for ${ releaseTag } ` ) ;
35
40
}
36
41
37
- async function downloadAsset ( platform , arch , os , releaseTag , githubToken ) {
42
+ async function downloadBinary ( platform , arch , os , releaseTag , githubToken ) {
38
43
const buildName = getBuildName ( platform , arch ) ;
39
44
40
45
const assetUrl = `https://github.com/supabase-community/postgres_lsp/releases/download/${ releaseTag } /${ buildName } ` ;
@@ -59,31 +64,15 @@ async function downloadAsset(platform, arch, os, releaseTag, githubToken) {
59
64
console . log ( `Downloaded asset for ${ buildName } (v${ releaseTag } )` ) ;
60
65
}
61
66
62
- const rootManifest = JSON . parse (
63
- fs . readFileSync ( MANIFEST_PATH ) . toString ( "utf-8" )
64
- ) ;
65
-
66
- function getBinaryExt ( os ) {
67
- return os === "windows" ? ".exe" : "" ;
68
- }
67
+ async function overwriteManifestVersions ( releaseTag ) {
68
+ const manifestClone = structuredClone ( rootManifest ) ;
69
69
70
- function getBinarySource ( platform , arch , os ) {
71
- const ext = getBinaryExt ( os ) ;
72
- return resolve ( PGLT_ROOT , `${ getBuildName ( platform , arch ) } ${ ext } ` ) ;
73
- }
74
-
75
- function getBuildName ( platform , arch ) {
76
- return `pglt_${ arch } -${ platform } ` ;
77
- }
78
-
79
- function getPackageName ( platform , arch ) {
80
- // trim the "unknown" from linux
81
- const name = platform . split ( "-" ) . slice ( - 2 ) . join ( "-" ) ;
82
- return `@pglt/cli-${ arch } -${ name } ` ;
83
- }
70
+ manifestClone . version = releaseTag ;
71
+ for ( const key in manifestClone . optionalDependencies ) {
72
+ manifestClone . optionalDependencies [ key ] = releaseTag ;
73
+ }
84
74
85
- function getOs ( platform ) {
86
- return platform . split ( "-" ) . find ( ( _ , idx ) => idx === 1 ) ;
75
+ fs . writeFileSync ( MANIFEST_PATH , JSON . stringify ( manifestClone , null , 2 ) ) ;
87
76
}
88
77
89
78
function copyBinaryToNativePackage ( platform , arch , os ) {
@@ -158,6 +147,33 @@ function copySchemaToNativePackage(platform, arch) {
158
147
fs . chmodSync ( schemaTarget , 0o666 ) ;
159
148
}
160
149
150
+ const rootManifest = JSON . parse (
151
+ fs . readFileSync ( MANIFEST_PATH ) . toString ( "utf-8" )
152
+ ) ;
153
+
154
+ function getBinaryExt ( os ) {
155
+ return os === "windows" ? ".exe" : "" ;
156
+ }
157
+
158
+ function getBinarySource ( platform , arch , os ) {
159
+ const ext = getBinaryExt ( os ) ;
160
+ return resolve ( PGLT_ROOT , `${ getBuildName ( platform , arch ) } ${ ext } ` ) ;
161
+ }
162
+
163
+ function getBuildName ( platform , arch ) {
164
+ return `pglt_${ arch } -${ platform } ` ;
165
+ }
166
+
167
+ function getPackageName ( platform , arch ) {
168
+ // trim the "unknown" from linux and the "pc" from windows
169
+ const name = platform . split ( "-" ) . slice ( - 2 ) . join ( "-" ) ;
170
+ return `@pglt/cli-${ arch } -${ name } ` ;
171
+ }
172
+
173
+ function getOs ( platform ) {
174
+ return platform . split ( "-" ) . find ( ( _ , idx ) => idx === 1 ) ;
175
+ }
176
+
161
177
( async function main ( ) {
162
178
const githubToken = process . env . GITHUB_TOKEN ;
163
179
const releaseTag = process . env . RELEASE_TAG ;
@@ -166,15 +182,13 @@ function copySchemaToNativePackage(platform, arch) {
166
182
assert ( releaseTag , "RELEASE_TAG not defined!" ) ;
167
183
168
184
await downloadSchema ( releaseTag , githubToken ) ;
185
+ overwriteManifestVersions ( releaseTag ) ;
169
186
170
- const PLATFORMS = [ "pc-windows-msvc" , "apple-darwin" , "unknown-linux-gnu" ] ;
171
- const ARCHITECTURES = [ "x86_64" , "aarch64" ] ;
172
-
173
- for ( const platform of PLATFORMS ) {
187
+ for ( const platform of SUPPORTED_PLATFORMS ) {
174
188
const os = getOs ( platform ) ;
175
189
176
- for ( const arch of ARCHITECTURES ) {
177
- await downloadAsset ( platform , arch , os , releaseTag , githubToken ) ;
190
+ for ( const arch of SUPPORTED_ARCHITECTURES ) {
191
+ await downloadBinary ( platform , arch , os , releaseTag , githubToken ) ;
178
192
copyBinaryToNativePackage ( platform , arch , os ) ;
179
193
copySchemaToNativePackage ( platform , arch ) ;
180
194
}
0 commit comments