pear-install 1.0.9 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +1 -0
- package/index.js +44 -24
- package/package.json +2 -2
package/bin.js
CHANGED
package/index.js
CHANGED
|
@@ -72,19 +72,9 @@ class Install extends ReadyResource {
|
|
|
72
72
|
|
|
73
73
|
await this.drive.ready()
|
|
74
74
|
this.doneFinding = this.drive.findingPeers()
|
|
75
|
-
|
|
75
|
+
this.swarm.join(this.drive.discoveryKey, { server: false, client: true })
|
|
76
76
|
this.swarm.on('connection', (c) => this.corestore.replicate(c))
|
|
77
77
|
|
|
78
|
-
let serving = false
|
|
79
|
-
this.swarm.dht.on('nat-update', () => {
|
|
80
|
-
if (!this.swarm.dht.randomized && !serving) {
|
|
81
|
-
serving = true
|
|
82
|
-
this.swarm
|
|
83
|
-
.join(this.drive.discoveryKey, { server: true, client: false })
|
|
84
|
-
.flushed()
|
|
85
|
-
.then(() => topic.destroy())
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
78
|
const deferred = Promise.withResolvers()
|
|
89
79
|
const countdown = setTimeout(() => {
|
|
90
80
|
deferred.reject(ERR_NETWORK_TIMEOUT('Network Timeout ' + timeout / 1000 + 's'))
|
|
@@ -107,11 +97,9 @@ class Install extends ReadyResource {
|
|
|
107
97
|
const ext = isWindows ? '.exe' : ''
|
|
108
98
|
const dest = to
|
|
109
99
|
? path.join(to, binName + ext)
|
|
110
|
-
:
|
|
111
|
-
? path.join(
|
|
112
|
-
:
|
|
113
|
-
? path.join(localAppData, 'Programs', appName, binName + ext)
|
|
114
|
-
: path.join(home, '.local', 'bin', binName)
|
|
100
|
+
: isWindows
|
|
101
|
+
? path.join(localAppData, 'Programs', appName, binName + ext)
|
|
102
|
+
: path.join(home, '.local', 'bin', binName)
|
|
115
103
|
this.targets.push({ filename: binName, ext, dest, isBin: true })
|
|
116
104
|
}
|
|
117
105
|
}
|
|
@@ -230,24 +218,19 @@ class Install extends ReadyResource {
|
|
|
230
218
|
} catch (err) {
|
|
231
219
|
if (err.code === 'EACCES' || err.code === 'EPERM') {
|
|
232
220
|
const dir = path.dirname(dest)
|
|
233
|
-
|
|
234
|
-
? `sudo chgrp admin ${dir} && sudo chmod g+w ${dir}`
|
|
235
|
-
: `sudo chown -R "$(id -un):$(id -gn)" ${dir}`
|
|
236
|
-
throw ERR_PERMISSION_REQUIRED(`Permission denied: ${dest}\n Fix: ${fix}`)
|
|
221
|
+
throw ERR_PERMISSION_REQUIRED(`Permission denied: ${dest}\n`)
|
|
237
222
|
}
|
|
238
223
|
throw err
|
|
239
224
|
}
|
|
240
225
|
fs.chmodSync(dest, 0o755)
|
|
226
|
+
if (!isWindows) this._addToPath(path.join(os.homedir(), '.local', 'bin'))
|
|
241
227
|
} else {
|
|
242
228
|
try {
|
|
243
229
|
await fs.promises.rename(from, dest)
|
|
244
230
|
} catch (err) {
|
|
245
231
|
if (err.code === 'EACCES' || err.code === 'EPERM') {
|
|
246
232
|
const dir = path.dirname(dest)
|
|
247
|
-
|
|
248
|
-
? `sudo chgrp admin ${dir} && sudo chmod g+w ${dir}`
|
|
249
|
-
: `sudo chown -R "$(id -un):$(id -gn)" ${dir}`
|
|
250
|
-
throw ERR_PERMISSION_REQUIRED(`Permission denied: ${dest}\n Fix: ${fix}`)
|
|
233
|
+
throw ERR_PERMISSION_REQUIRED(`Permission denied: ${dest}\n`)
|
|
251
234
|
}
|
|
252
235
|
throw err
|
|
253
236
|
}
|
|
@@ -374,6 +357,43 @@ class Install extends ReadyResource {
|
|
|
374
357
|
this.base = null
|
|
375
358
|
}
|
|
376
359
|
}
|
|
360
|
+
|
|
361
|
+
_addToPath(newPath) {
|
|
362
|
+
const { configFile, shell } = this._detectShellConfig()
|
|
363
|
+
|
|
364
|
+
const isFish = shell === 'fish'
|
|
365
|
+
const exportLine = isFish ? `\nfish_add_path ${newPath}` : `\nexport PATH="$PATH:${newPath}"`
|
|
366
|
+
|
|
367
|
+
const content = fs.existsSync(configFile) ? fs.readFileSync(configFile, 'utf8') : ''
|
|
368
|
+
if (process.env.PATH.split(':').includes(newPath) || content.includes(exportLine)) {
|
|
369
|
+
return
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
fs.appendFileSync(configFile, exportLine + '\n', 'utf8')
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
_detectShellConfig() {
|
|
376
|
+
const home = os.homedir()
|
|
377
|
+
const shell = path.basename(process.env.SHELL)
|
|
378
|
+
|
|
379
|
+
const configCandidates = {
|
|
380
|
+
zsh: ['.zshrc', '.zprofile'],
|
|
381
|
+
bash: isMac
|
|
382
|
+
? ['.bash_profile', '.bashrc', '.profile']
|
|
383
|
+
: ['.bashrc', '.bash_profile', '.profile'],
|
|
384
|
+
fish: ['.config/fish/config.fish'],
|
|
385
|
+
ksh: ['.kshrc', '.profile'],
|
|
386
|
+
tcsh: ['.tcshrc', '.cshrc'],
|
|
387
|
+
csh: ['.cshrc', '.tcshrc'],
|
|
388
|
+
sh: ['.profile']
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const candidates = configCandidates[shell] ?? ['.profile']
|
|
392
|
+
const existing = candidates.find((f) => fs.existsSync(path.join(home, f)))
|
|
393
|
+
const configFile = path.join(home, existing ?? candidates[0])
|
|
394
|
+
|
|
395
|
+
return { configFile, shell }
|
|
396
|
+
}
|
|
377
397
|
}
|
|
378
398
|
|
|
379
399
|
module.exports = Install
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-install",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"description": "Install Pear and Pear Applications",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"localdrive": "^2.2.1",
|
|
73
73
|
"paparam": "^1.10.1",
|
|
74
74
|
"pear-errors": "^1.0.1",
|
|
75
|
-
"pear-link": "^
|
|
75
|
+
"pear-link": "^5.0.0",
|
|
76
76
|
"pear-opstream": "^1.0.1",
|
|
77
77
|
"pear-opwait": "^1.0.0",
|
|
78
78
|
"streamx": "^2.23.0",
|