@@ -28,41 +28,21 @@ const PLATFORM_MAPPING = {
2828} ;
2929
3030const arch = ARCH_MAPPING [ process . arch ] ;
31-
3231const platform = PLATFORM_MAPPING [ process . platform ] ;
3332
3433// TODO: import pkg from "../package.json" assert { type: "json" };
3534const readPackageJson = async ( ) => {
36- const packageJsonPath = path . join ( "." , "package.json" ) ;
37- const contents = await fs . promises . readFile ( packageJsonPath ) ;
35+ const contents = await fs . promises . readFile ( "package.json" ) ;
3836 return JSON . parse ( contents ) ;
3937} ;
4038
41- const parsePackageJson = ( packageJson ) => {
42- if ( ! arch ) {
43- throw Error (
44- "Installation is not supported for this architecture: " + process . arch
45- ) ;
46- }
47-
48- if ( ! platform ) {
49- throw Error (
50- "Installation is not supported for this platform: " + process . platform
51- ) ;
52- }
53-
54- // Build the download url from package.json
39+ // Build the download url from package.json
40+ const getDownloadUrl = ( packageJson ) => {
5541 const pkgName = packageJson . name ;
5642 const version = packageJson . version ;
5743 const repo = packageJson . repository ;
5844 const url = `https://github.com/${ repo } /releases/download/v${ version } /${ pkgName } _${ platform } _${ arch } .tar.gz` ;
59-
60- let binPath = path . join ( "bin" , "supabase" ) ;
61- if ( platform == "windows" ) {
62- binPath += ".exe" ;
63- }
64-
65- return { binPath, url } ;
45+ return url ;
6646} ;
6747
6848const fetchAndParseCheckSumFile = async ( packageJson , agent ) => {
@@ -98,6 +78,7 @@ const errGlobal = `Installing Supabase CLI as a global module is not supported.
9878Please use one of the supported package managers: https://github.com/supabase/cli#install-the-cli
9979` ;
10080const errChecksum = "Checksum mismatch. Downloaded data might be corrupted." ;
81+ const errUnsupported = `Installation is not supported for ${ process . platform } ${ process . arch } ` ;
10182
10283/**
10384 * Reads the configuration from application's package.json,
@@ -113,9 +94,17 @@ async function main() {
11394 if ( process . env . npm_config_global || yarnGlobal ) {
11495 throw errGlobal ;
11596 }
97+ if ( ! arch || ! platform ) {
98+ throw errUnsupported ;
99+ }
116100
117101 const pkg = await readPackageJson ( ) ;
118- const { binPath, url } = parsePackageJson ( pkg ) ;
102+ if ( platform === "windows" ) {
103+ // Update bin path in package.json
104+ pkg . bin [ pkg . name ] += ".exe" ;
105+ }
106+
107+ const binPath = pkg . bin [ pkg . name ] ;
119108 const binDir = path . dirname ( binPath ) ;
120109 await fs . promises . mkdir ( binDir , { recursive : true } ) ;
121110
@@ -124,6 +113,7 @@ async function main() {
124113 const binName = path . basename ( binPath ) ;
125114 const untar = tar . x ( { cwd : binDir } , [ binName ] ) ;
126115
116+ const url = getDownloadUrl ( pkg ) ;
127117 console . info ( "Downloading" , url ) ;
128118 const proxyUrl =
129119 process . env . npm_config_https_proxy ||
0 commit comments