1- import { constants , chmodSync , createWriteStream } from 'node:fs'
1+ import { constants , chmodSync , createWriteStream , existsSync , mkdirSync } from 'node:fs'
22import https from 'node:https'
33import { arch , exit , platform } from 'node:process'
4- import { getExecutablePath } from './utils'
4+ import { DEFAULT_CACHE_FOLDER , DEFAULT_EXECUTABLE_PATH , USER_EXECUTABLE_PATH } from './utils'
55
66const PLATFORMS = {
77 darwin : {
@@ -20,10 +20,13 @@ const PLATFORMS = {
2020 */
2121export const download = async ( ) : Promise < void > => {
2222 const platformPath = PLATFORMS ?. [ platform ] ?. [ arch ]
23- const executablePath = getExecutablePath ( )
23+
24+ if ( ! existsSync ( DEFAULT_CACHE_FOLDER ) ) {
25+ mkdirSync ( DEFAULT_CACHE_FOLDER , { recursive : true } )
26+ }
2427
2528 const get = ( url : string , resolve : ( value ?: unknown ) => void , reject : ( reason : any ) => void ) => {
26- const file = createWriteStream ( executablePath )
29+ const file = createWriteStream ( DEFAULT_EXECUTABLE_PATH )
2730
2831 https . get ( url , res => {
2932 if (
@@ -49,13 +52,18 @@ export const download = async (): Promise<void> => {
4952 }
5053
5154 if ( platformPath ) {
55+ if ( USER_EXECUTABLE_PATH ) {
56+ console . info ( '$LIGHTPANDA_EXECUTABLE_PATH found, skipping binary download…' )
57+ exit ( 0 )
58+ }
59+
5260 try {
5361 console . info ( '⏳ Downloading latest version of Lightpanda browser…' )
5462
5563 await downloadBinary (
5664 `https://github.com/lightpanda-io/browser/releases/download/nightly/lightpanda-${ platformPath } ` ,
5765 )
58- chmodSync ( executablePath , constants . S_IRWXU )
66+ chmodSync ( DEFAULT_EXECUTABLE_PATH , constants . S_IRWXU )
5967
6068 console . info ( '✅ Done!' )
6169 exit ( 0 )
0 commit comments