chahuadev-dev-launcher / runtime /platform-darwin.js
chahuadev's picture
fix: remove ineffective sandbox on home/support iframes (allow-scripts+allow-same-origin defeats sandbox per spec)
b92316a verified
'use strict'
/**
* platform-darwin.js — macOS-specific runtime adapter
* Loaded exclusively when process.platform === 'darwin'
*/
const path = require('path')
const os = require('os')
const PLATFORM = 'darwin'
// ── Writable path candidates for app userData ─────────────────────────────────
function getWritableCandidates(appDirName) {
const candidates = []
candidates.push(path.join(os.homedir(), 'Library', 'Application Support', 'Chahuadev', appDirName))
candidates.push(path.join(os.tmpdir(), appDirName))
return candidates
}
// ── Command name normalization ────────────────────────────────────────────────
// macOS: no .cmd suffix — npm/npx/pnpm/yarn are native shell scripts.
function normalizeExecName(cmd) {
return String(cmd || '').trim()
}
// ── Shell wrapping ────────────────────────────────────────────────────────────
// macOS commands run directly via node-pty — no cmd.exe-style wrapping needed.
function shouldUseShell(cmd) { // eslint-disable-line no-unused-vars
return false
}
// Not called on macOS (shouldUseShell always false), but satisfies interface.
function buildShellSpawn(cmd, args) {
return { file: cmd, args: args || [] }
}
// ── node-pty spawn extra options ──────────────────────────────────────────────
// useConpty is Windows-only. macOS uses standard POSIX PTY.
function getPtySpawnOptions() {
return {}
}
// ── Node.js runtime path ──────────────────────────────────────────────────────
function resolveNodeRuntime() {
return 'node'
}
// ── Linux/macOS build command ─────────────────────────────────────────────────
function _quoteBash(s) {
return `'${String(s || '').replace(/'/g, `'"'"'`)}'`
}
function rewriteLinuxBuildCommand(cwd) {
const script = [
'set -euo pipefail',
`cd ${_quoteBash(cwd)}`,
'npm install',
'if npm run | grep -q "build:linux"; then npm run build:linux; else npx electron-builder --linux AppImage --x64 --publish never; fi'
].join('; ')
return {
cmd: 'bash',
args: ['-lc', script],
rewriteInfo: {
applied: true,
kind: 'launcher-linux-build-inline-bash',
targetProjectPath: cwd
}
}
}
// ── Protected OS path bases ───────────────────────────────────────────────────
// Base list covers standard macOS paths.
// We also scan /Volumes at runtime to protect externally mounted volumes
// (Time Machine disks, network shares, disk images, external drives, etc.)
function _readMacVolumes() {
try {
const fs = require('fs')
// /Volumes contains all mounted filesystems; the boot volume is a symlink → '/'
// Filter out symlinks to avoid double-protecting the root partition.
return fs.readdirSync('/Volumes').reduce((acc, name) => {
const full = `/Volumes/${name}`
try {
const stat = fs.lstatSync(full)
if (!stat.isSymbolicLink()) acc.push(full)
} catch { /* ignore vanished entries */ }
return acc
}, [])
} catch {
return []
}
}
function getProtectedPathBases() {
const homeDir = os.homedir()
return [
'/System', '/Library', '/Applications',
'/private', '/usr', '/bin', '/sbin',
'/var', '/etc', '/opt',
path.join(homeDir, 'Library'),
..._readMacVolumes()
]
}
module.exports = {
PLATFORM,
getWritableCandidates,
normalizeExecName,
shouldUseShell,
buildShellSpawn,
getPtySpawnOptions,
resolveNodeRuntime,
rewriteLinuxBuildCommand,
getProtectedPathBases
}