Add --path option and detect new install layouts

This commit is contained in:
Claude
2026-06-01 15:32:47 +00:00
parent ec131886ee
commit 2f1be7abca
2 changed files with 37 additions and 9 deletions
+4
View File
@@ -24,6 +24,9 @@ node . start
# Restore original (if needed) # Restore original (if needed)
node . restore node . restore
# Specify a custom install path (e.g. Program Files)
node . patch --path "C:\Program Files\HTTP Toolkit"
``` ```
## How it works ## How it works
@@ -38,6 +41,7 @@ node . restore
- Creates a backup at `app.asar.bak` before patching - Creates a backup at `app.asar.bak` before patching
- You can set a custom proxy with the `PROXY` environment variable - You can set a custom proxy with the `PROXY` environment variable
- Use `--path` to point at a non-default install location; auto-detection also covers `Program Files` and the newer `Programs\httptoolkit\HTTP Toolkit` layout on Windows
- Works offline after first run (caches UI files locally) - Works offline after first run (caches UI files locally)
## License ## License
+33 -9
View File
@@ -14,6 +14,10 @@ const argv = await yargs(process.argv.slice(2))
.command('patch', 'Patch HTTP Toolkit using the specified script') .command('patch', 'Patch HTTP Toolkit using the specified script')
.command('restore', 'Restore HTTP Toolkit files to their original state') .command('restore', 'Restore HTTP Toolkit files to their original state')
.command('start', 'Start HTTP Toolkit') .command('start', 'Start HTTP Toolkit')
.option('path', {
type: 'string',
describe: 'Path to the HTTP Toolkit installation (the install dir or its resources folder)'
})
.demandCommand(1, 'You need at least one command before moving on') .demandCommand(1, 'You need at least one command before moving on')
.alias('h', 'help') .alias('h', 'help')
.parse() .parse()
@@ -26,17 +30,37 @@ const pm = userAgent ? userAgent.split('/')[0] : 'npm'
const installCmd = pm === 'npm' ? 'install' : 'add' const installCmd = pm === 'npm' ? 'install' : 'add'
// Try to find where HTTP Toolkit is installed // Try to find where HTTP Toolkit is installed
const appPath = const getAppPath = () => {
isWin ? path.join(process.env.LOCALAPPDATA ?? '', 'Programs', 'httptoolkit', 'resources') if (argv.path) {
: isMac ? '/Applications/HTTP Toolkit.app/Contents/Resources' return /resources$/i.test(argv.path) ? argv.path : path.join(argv.path, isMac ? 'Contents/Resources' : 'resources')
: fs.existsSync('/opt/HTTP Toolkit/resources') ? '/opt/HTTP Toolkit/resources' }
: '/opt/httptoolkit/resources' const localAppData = process.env.LOCALAPPDATA ?? ''
const candidates = isWin
? [
path.join(localAppData, 'Programs', 'httptoolkit', 'HTTP Toolkit', 'resources'), // current default
path.join(localAppData, 'Programs', 'httptoolkit', 'resources'), // older default
path.join(process.env.PROGRAMFILES ?? '', 'HTTP Toolkit', 'resources'),
path.join(process.env['PROGRAMFILES(X86)'] ?? '', 'HTTP Toolkit', 'resources')
]
: isMac
? ['/Applications/HTTP Toolkit.app/Contents/Resources']
: [
'/opt/HTTP Toolkit/resources',
'/opt/httptoolkit/resources',
'/usr/lib/httptoolkit'
]
for (const p of candidates) {
if (p && fs.existsSync(path.join(p, 'app.asar'))) return p
}
return candidates[0]
}
const appPath = getAppPath()
const exePath = const exePath =
isWin ? path.join(process.env.LOCALAPPDATA ?? '', 'Programs', 'httptoolkit', 'HTTP Toolkit.exe') isWin ? path.join(path.dirname(appPath), 'HTTP Toolkit.exe')
: isMac ? '/Applications/HTTP Toolkit.app/Contents/MacOS/HTTP Toolkit' : isMac ? path.join(path.dirname(appPath), 'MacOS', 'HTTP Toolkit')
: fs.existsSync('/opt/HTTP Toolkit/httptoolkit') ? '/opt/HTTP Toolkit/httptoolkit' : path.join(path.dirname(appPath), 'httptoolkit')
: '/opt/httptoolkit/httptoolkit'
const isSudo = !isWin && (process.getuid || (() => process.env.SUDO_UID ? 0 : null))() === 0 const isSudo = !isWin && (process.getuid || (() => process.env.SUDO_UID ? 0 : null))() === 0