Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
fix: harden macOS --install mount and cleanup flow
Mihai - Alexandru Chindrișcb09d3adf6cd
diff --git a/bin/builders/BaseBuilder.ts b/bin/builders/BaseBuilder.tsindex ecae1567..e780b210 100644--- a/bin/builders/BaseBuilder.ts+++ b/bin/builders/BaseBuilder.ts@@ -1,3 +1,4 @@+import os from 'os';import path from 'path';import fsExtra from 'fs-extra';import chalk from 'chalk';@@ -312,14 +313,32 @@ export default abstract class BaseBuilder {appName: string,): Promise<void> {const { execa } = await import('execa');- const volumePath = `/Volumes/${appName}`;- const appSource = path.join(volumePath, `${appName}.app`);- const appDest = `/Applications/${appName}.app`;+ const mountRoot = path.join(os.tmpdir(), 'pake-install-');+ const mountPoint = await fsExtra.mkdtemp(mountRoot);+ let attached = false;try {logger.info(`- Installing ${appName} to /Applications...`);- await execa('hdiutil', ['attach', dmgPath]);+ await execa('hdiutil', [+ 'attach',+ dmgPath,+ '-nobrowse',+ '-readonly',+ '-mountpoint',+ mountPoint,+ ]);+ attached = true;++ const entries = await fsExtra.readdir(mountPoint);+ const appBundleName = entries.find((entry) => entry.endsWith('.app'));++ if (!appBundleName) {+ throw new Error('No .app bundle found inside mounted DMG');+ }++ const appSource = path.join(mountPoint, appBundleName);+ const appDest = path.join('/Applications', appBundleName);// Remove existing installation if presentif (await fsExtra.pathExists(appDest)) {@@ -327,18 +346,27 @@ export default abstract class BaseBuilder {}await fsExtra.copy(appSource, appDest);- await execa('hdiutil', ['detach', volumePath]);++ await execa('hdiutil', ['detach', mountPoint]);+ attached = false;await fsExtra.remove(dmgPath);- logger.success(`✔ ${appName} installed to /Applications`);+ logger.success(+ `✔ ${appBundleName.replace(/\.app$/, '')} installed to /Applications`,+ );logger.success(`✔ Installer DMG removed`);} catch (error) {- // Attempt cleanup on failure- try {- await execa('hdiutil', ['detach', volumePath]).catch(() => {});- } catch {}logger.error(`✕ Failed to install ${appName}: ${error}`);logger.info(` The DMG is still available at: ${dmgPath}`);+ } finally {+ if (attached) {+ await execa('hdiutil', ['detach', mountPoint]).catch(async () => {+ await execa('hdiutil', ['detach', mountPoint, '-force']).catch(+ () => undefined,+ );+ });+ }+ await fsExtra.remove(mountPoint).catch(() => undefined);}}diff --git a/dist/cli.js b/dist/cli.jsindex b101cb9f..05777df3 100644--- a/dist/cli.js+++ b/dist/cli.js@@ -4,9 +4,9 @@ import updateNotifier from 'update-notifier';import path from 'path';import fsExtra from 'fs-extra';import { fileURLToPath } from 'url';+import os from 'os';import chalk from 'chalk';import prompts from 'prompts';-import os from 'os';import { execa, execaSync } from 'execa';import crypto from 'crypto';import ora from 'ora';@@ -969,31 +969,50 @@ class BaseBuilder {}async installDmgToApplications(dmgPath, appName) {const { execa } = await import('execa');- const volumePath = `/Volumes/${appName}`;- const appSource = path.join(volumePath, `${appName}.app`);- const appDest = `/Applications/${appName}.app`;+ const mountRoot = path.join(os.tmpdir(), 'pake-install-');+ const mountPoint = await fsExtra.mkdtemp(mountRoot);+ let attached = false;try {logger.info(`- Installing ${appName} to /Applications...`);- await execa('hdiutil', ['attach', dmgPath]);+ await execa('hdiutil', [+ 'attach',+ dmgPath,+ '-nobrowse',+ '-readonly',+ '-mountpoint',+ mountPoint,+ ]);+ attached = true;+ const entries = await fsExtra.readdir(mountPoint);+ const appBundleName = entries.find((entry) => entry.endsWith('.app'));+ if (!appBundleName) {+ throw new Error('No .app bundle found inside mounted DMG');+ }+ const appSource = path.join(mountPoint, appBundleName);+ const appDest = path.join('/Applications', appBundleName);// Remove existing installation if presentif (await fsExtra.pathExists(appDest)) {await fsExtra.remove(appDest);}await fsExtra.copy(appSource, appDest);- await execa('hdiutil', ['detach', volumePath]);+ await execa('hdiutil', ['detach', mountPoint]);+ attached = false;await fsExtra.remove(dmgPath);- logger.success(`✔ ${appName} installed to /Applications`);+ logger.success(`✔ ${appBundleName.replace(/\.app$/, '')} installed to /Applications`);logger.success(`✔ Installer DMG removed`);}catch (error) {- // Attempt cleanup on failure- try {- await execa('hdiutil', ['detach', volumePath]).catch(() => { });- }- catch { }logger.error(`✕ Failed to install ${appName}: ${error}`);logger.info(` The DMG is still available at: ${dmgPath}`);}+ finally {+ if (attached) {+ await execa('hdiutil', ['detach', mountPoint]).catch(async () => {+ await execa('hdiutil', ['detach', mountPoint, '-force']).catch(() => undefined);+ });+ }+ await fsExtra.remove(mountPoint).catch(() => undefined);+ }}getFileType(target) {return target;