From 0fe39687ea4ef7b2243b8d8601f806a837c386b7 Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Wed, 8 Jul 2026 15:58:09 +0200 Subject: [PATCH 1/7] remove v2 path from rc --- pear.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/pear.js b/pear.js index 2b5cb75..08af1db 100755 --- a/pear.js +++ b/pear.js @@ -3,12 +3,18 @@ const process = require('process') const os = require('os') const path = require('path') const fs = require('fs') -const { isWindows, isLinux } = require('which-runtime') +const { isWindows, isLinux, isMac } = require('which-runtime') const goodbye = require('graceful-goodbye') const byteSize = require('tiny-byte-size') const isTTY = process.stdout.isTTY +try { + migrateFromV2() +} catch (err) { + console.log(err) +} + const PEAR_KEY = 'pear://smw4thqaqed9iq6bae7a9cxd4fesruixgkafe38jny33ahs33igy' const key = PEAR_KEY @@ -111,3 +117,41 @@ function libatomicCheck() { return false } } + +function migrateFromV2() { + if (isWindows) return + if (!fs.existsSync(getRcPath())) return + const rcPath = getRcPath() + const oldPath = isMac + ? path.join(os.homedir(), 'Library', 'Application Support', 'pear', 'bin') + : path.join(os.homedir(), '.config', 'pear', 'bin') + const oldComment = '# Added by Pear Runtime, configures system with Pear CLI' + const rc = fs.readFileSync(rcPath, 'utf8') + const cleaned = rc + .split('\n') + .filter( + (line) => + line.trimEnd() !== `export PATH="${oldPath}":$PATH` && + line.trimEnd() !== oldComment + ) + .join('\n') + if (cleaned !== rc) fs.writeFileSync(rcPath, cleaned) +} + +function getRcPath() { + const home = os.homedir() + + const candidates = [ + '.zshrc', + '.zprofile', + '.bashrc', + '.bash_profile', + '.profile', + '.kshrc', + '.tcshrc', + '.cshrc' + ] + + const existing = candidates.find((f) => fs.existsSync(path.join(home, f))) + return path.join(home, existing ?? candidates[0]) +} From d7bcfe361b81479038cb8f9e5a5711fae3596fb9 Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Wed, 8 Jul 2026 16:05:44 +0200 Subject: [PATCH 2/7] error handling --- pear.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pear.js b/pear.js index 08af1db..4ea9ae1 100755 --- a/pear.js +++ b/pear.js @@ -38,6 +38,10 @@ if (fs.existsSync(BIN)) { .on('exit', function (code) { resolve(code) }) + .on('error', function (err) { + console.error('Failed to run Pear:', err.message) + resolve(1) + }) }) goodbye(async () => { child.kill() @@ -82,7 +86,8 @@ Please install it first using the appropriate package manager for your system. install.on('error', (err) => { if (isTTY) clear() - throw err + console.error('Installation failed:', err.message) + process.exit(1) }) install From fe682e370b419d34536abd3f664fc50326e4292d Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Wed, 8 Jul 2026 16:46:27 +0200 Subject: [PATCH 3/7] remove from every rc file --- pear.js | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/pear.js b/pear.js index 4ea9ae1..14cc0aa 100755 --- a/pear.js +++ b/pear.js @@ -9,12 +9,6 @@ const byteSize = require('tiny-byte-size') const isTTY = process.stdout.isTTY -try { - migrateFromV2() -} catch (err) { - console.log(err) -} - const PEAR_KEY = 'pear://smw4thqaqed9iq6bae7a9cxd4fesruixgkafe38jny33ahs33igy' const key = PEAR_KEY @@ -64,6 +58,13 @@ Please install it first using the appropriate package manager for your system. `) process.exit(1) } + + try { + migrateFromV2() + } catch (err) { + console.log(err) + } + const Install = require('pear-install') console.log('Installing Pear (Please stand by, this might take a bit...)') @@ -125,25 +126,25 @@ function libatomicCheck() { function migrateFromV2() { if (isWindows) return - if (!fs.existsSync(getRcPath())) return - const rcPath = getRcPath() const oldPath = isMac ? path.join(os.homedir(), 'Library', 'Application Support', 'pear', 'bin') : path.join(os.homedir(), '.config', 'pear', 'bin') const oldComment = '# Added by Pear Runtime, configures system with Pear CLI' - const rc = fs.readFileSync(rcPath, 'utf8') - const cleaned = rc - .split('\n') - .filter( - (line) => - line.trimEnd() !== `export PATH="${oldPath}":$PATH` && - line.trimEnd() !== oldComment - ) - .join('\n') - if (cleaned !== rc) fs.writeFileSync(rcPath, cleaned) + for (const rcPath of getRcPaths()) { + const rc = fs.readFileSync(rcPath, 'utf8') + const cleaned = rc + .split('\n') + .filter( + (line) => + line.trimEnd() !== `export PATH="${oldPath}":$PATH` && + line.trimEnd() !== oldComment + ) + .join('\n') + if (cleaned !== rc) fs.writeFileSync(rcPath, cleaned) + } } -function getRcPath() { +function getRcPaths() { const home = os.homedir() const candidates = [ @@ -157,6 +158,7 @@ function getRcPath() { '.cshrc' ] - const existing = candidates.find((f) => fs.existsSync(path.join(home, f))) - return path.join(home, existing ?? candidates[0]) + return candidates + .map((f) => path.join(home, f)) + .filter((p) => fs.existsSync(p)) } From 05291de28e69f5a0893ec8b3285e7b077482936e Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Wed, 8 Jul 2026 18:27:27 +0200 Subject: [PATCH 4/7] remove path export with and without quotes --- pear.js | 1 + 1 file changed, 1 insertion(+) diff --git a/pear.js b/pear.js index 14cc0aa..20e3ec9 100755 --- a/pear.js +++ b/pear.js @@ -137,6 +137,7 @@ function migrateFromV2() { .filter( (line) => line.trimEnd() !== `export PATH="${oldPath}":$PATH` && + line.trimEnd() !== `export PATH="${oldPath}:$PATH"` && line.trimEnd() !== oldComment ) .join('\n') From 7e113d51f86e2d463a43f5e0a7d16c19e2932472 Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Wed, 8 Jul 2026 18:51:07 +0200 Subject: [PATCH 5/7] use console.error in case of migration error --- pear.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pear.js b/pear.js index 20e3ec9..a525ae4 100755 --- a/pear.js +++ b/pear.js @@ -62,7 +62,7 @@ Please install it first using the appropriate package manager for your system. try { migrateFromV2() } catch (err) { - console.log(err) + console.error(err) } const Install = require('pear-install') From 9c4b0eb9b9825e7072fafdc3c881161069ff5928 Mon Sep 17 00:00:00 2001 From: rafapaezbas Date: Wed, 8 Jul 2026 19:21:15 +0200 Subject: [PATCH 6/7] added message after installation --- pear.js | 1 + 1 file changed, 1 insertion(+) diff --git a/pear.js b/pear.js index a525ae4..cdac674 100755 --- a/pear.js +++ b/pear.js @@ -79,6 +79,7 @@ Please install it first using the appropriate package manager for your system. if (result.success) { console.log('Pear installed!') + console.log('Please open a new terminal (or restart your current one) for the updated PATH to take effect.') } else { console.error('Installation failed:', result) process.exit(1) From febd4f1018553f25e5da2668f931fcc0185ce139 Mon Sep 17 00:00:00 2001 From: Andrei Regiani Date: Wed, 8 Jul 2026 14:30:20 -0300 Subject: [PATCH 7/7] npm run format --- pear.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pear.js b/pear.js index cdac674..498fc65 100755 --- a/pear.js +++ b/pear.js @@ -79,7 +79,9 @@ Please install it first using the appropriate package manager for your system. if (result.success) { console.log('Pear installed!') - console.log('Please open a new terminal (or restart your current one) for the updated PATH to take effect.') + console.log( + 'Please open a new terminal (or restart your current one) for the updated PATH to take effect.' + ) } else { console.error('Installation failed:', result) process.exit(1)