Skip to content

Commit ab98bc2

Browse files
committed
fix: executable path write
1 parent cc2462f commit ab98bc2

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

packages/browser/src/download.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { constants, chmodSync, createWriteStream } from 'node:fs'
1+
import { constants, chmodSync, createWriteStream, existsSync, mkdirSync } from 'node:fs'
22
import https from 'node:https'
33
import { 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

66
const PLATFORMS = {
77
darwin: {
@@ -20,10 +20,13 @@ const PLATFORMS = {
2020
*/
2121
export 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)

packages/browser/src/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import os from 'node:os'
22

3-
const BINARY_NAME = 'lightpanda'
3+
export const DEFAULT_CACHE_FOLDER = `${os.homedir()}/.cache/lightpanda-node`
4+
export const BINARY_NAME = 'lightpanda'
5+
6+
export const USER_EXECUTABLE_PATH = process.env.LIGHTPANDA_EXECUTABLE_PATH
7+
export const DEFAULT_EXECUTABLE_PATH = `${DEFAULT_CACHE_FOLDER}/${BINARY_NAME}`
48

59
/**
610
* Validate a URL structure
@@ -40,7 +44,5 @@ export const validatePort = (port: number): void => {
4044
* Get executable path
4145
*/
4246
export const getExecutablePath = () => {
43-
return (
44-
process.env.LIGHTPANDA_EXECUTABLE_PATH ?? `${os.homedir()}/.cache/lightpanda-node${BINARY_NAME}`
45-
)
47+
return USER_EXECUTABLE_PATH ?? DEFAULT_EXECUTABLE_PATH
4648
}

0 commit comments

Comments
 (0)