@chenmk/superflow 0.5.4 → 0.5.5
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.
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const { spawnSync } = require('child_process');
|
|
5
|
-
const { existsSync } = require('fs');
|
|
5
|
+
const { existsSync, readFileSync, writeFileSync } = require('fs');
|
|
6
6
|
const { join } = require('path');
|
|
7
7
|
|
|
8
8
|
const NODE_MIN = 20;
|
|
@@ -20,6 +20,19 @@ function major(version) {
|
|
|
20
20
|
return match ? Number(match[1]) : 0;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function removeNpmNvmConflict(home) {
|
|
24
|
+
const npmrc = join(home, '.npmrc');
|
|
25
|
+
if (!existsSync(npmrc)) return;
|
|
26
|
+
const source = readFileSync(npmrc, 'utf8');
|
|
27
|
+
const lines = source.split(/\r?\n/);
|
|
28
|
+
const kept = lines.filter((line) => !/^\s*(prefix|globalconfig)\s*=/i.test(line));
|
|
29
|
+
if (kept.length === lines.length) return;
|
|
30
|
+
const backup = `${npmrc}.superflow-backup`;
|
|
31
|
+
writeFileSync(backup, source, { mode: 0o600 });
|
|
32
|
+
writeFileSync(npmrc, kept.join('\n'), { mode: 0o600 });
|
|
33
|
+
console.log(`[Superflow] Backed up incompatible npm settings: ${backup}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
function main() {
|
|
24
37
|
console.log('[Superflow] Starting one-command installation...');
|
|
25
38
|
if (major(process.version) >= NODE_MIN) {
|
|
@@ -37,6 +50,7 @@ function main() {
|
|
|
37
50
|
}
|
|
38
51
|
const home = process.env.HOME;
|
|
39
52
|
if (!home) throw new Error('HOME is required to install Node.js.');
|
|
53
|
+
removeNpmNvmConflict(home);
|
|
40
54
|
const nvm = process.env.NVM_DIR || join(home, '.nvm');
|
|
41
55
|
const script = [
|
|
42
56
|
'set -e',
|
|
@@ -46,7 +60,7 @@ function main() {
|
|
|
46
60
|
'fi',
|
|
47
61
|
'. "$NVM_DIR/nvm.sh"',
|
|
48
62
|
`nvm use --delete-prefix 20 --silent || true`,
|
|
49
|
-
`nvm install `,
|
|
63
|
+
`nvm install 20`,
|
|
50
64
|
`nvm use --delete-prefix ${NODE_MIN}`,
|
|
51
65
|
`nvm alias default ${NODE_MIN}`,
|
|
52
66
|
`npm install -g "${MAIN}" --registry https://registry.npmjs.org`,
|