Skip to content

Commit

Permalink
fix: ensure binaries are executable
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Oct 22, 2024
1 parent 58e9cc5 commit 76eae0d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
5 changes: 3 additions & 2 deletions bin/todoctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import os from 'node:os'
import fs from 'node:fs'

let filename = fileURLToPath(import.meta.url)
let dirname = path.dirname(filename)

let platform = os.platform()
let arch = os.arch()

let binaries = {
export let dirname = path.dirname(filename)

export let binaries = {
'win32:x64': 'windows/x64/todoctor.exe',
'darwin:arm64': 'macos/arm64/todoctor',
'linux:arm64': 'linux/arm64/todoctor',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
"start": "pnpm run /^start:/",
"start:preview": "vite",
"build": "pnpm run /^build:/",
"build:lib": "cargo build --release && node ./scripts/build",
"build:lib": "cargo build --release && node ./scripts/build.js",
"build:preview": "vite build",
"postinstall": "node ./scripts/postinstall.js",
"release": "pnpm release:check && pnpm release:version",
"release:check": "pnpm test && pnpm run build",
"release:version": "changelogen --output changelog.md --release --push",
Expand Down
20 changes: 6 additions & 14 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import fs from 'node:fs'
import os from 'node:os'
Expand All @@ -16,6 +17,9 @@ let archMap = {
x64: 'x64',
}

let filename = fileURLToPath(import.meta.url)
let dirname = path.dirname(filename)

let platformName = platformMap[platform]
let archName = archMap[arch]

Expand All @@ -26,20 +30,8 @@ if (!platformName || !archName) {

let binaryName = platform === 'win32' ? 'todoctor.exe' : 'todoctor'

let sourcePath = path.join(
import.meta.dirname,
'..',
'target',
'release',
binaryName,
)
let destDir = path.join(
import.meta.dirname,
'..',
'bin',
platformName,
archName,
)
let sourcePath = path.join(dirname, '..', 'target', 'release', binaryName)
let destDir = path.join(dirname, platformName, archName)
let destPath = path.join(destDir, binaryName)

if (!fs.existsSync(destDir)) {
Expand Down
8 changes: 8 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import path from 'node:path'
import fs from 'node:fs'

import { dirname as binDirectory, binaries } from '../bin/todoctor'

Object.values(binaries).forEach(binaryPath => {
fs.chmodSync(path.join(binDirectory, binaryPath), 0o755)
})

0 comments on commit 76eae0d

Please sign in to comment.