windsor-bot 0.1.16 → 0.1.17
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/dist/server.js +24 -8
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createServer } from 'http';
|
|
2
2
|
import { execFile } from 'child_process';
|
|
3
3
|
import { build } from 'esbuild';
|
|
4
|
-
import { readFile, stat } from 'fs/promises';
|
|
4
|
+
import { access, readFile, stat } from 'fs/promises';
|
|
5
5
|
import { promisify } from 'util';
|
|
6
6
|
import { spawn } from 'child_process';
|
|
7
7
|
import { dirname, join } from 'path';
|
|
@@ -65,13 +65,29 @@ async function readPackageVersion() {
|
|
|
65
65
|
return packageJson.version;
|
|
66
66
|
}
|
|
67
67
|
async function updateGlobalBot() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
const npmCliCandidates = [
|
|
69
|
+
process.env['npm_execpath'],
|
|
70
|
+
join(dirname(process.execPath), '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js'),
|
|
71
|
+
'/usr/local/lib/node_modules/npm/bin/npm-cli.js',
|
|
72
|
+
'/opt/homebrew/lib/node_modules/npm/bin/npm-cli.js',
|
|
73
|
+
].filter((candidate) => Boolean(candidate));
|
|
74
|
+
let npmCliPath;
|
|
75
|
+
for (const candidate of npmCliCandidates) {
|
|
76
|
+
try {
|
|
77
|
+
await access(candidate);
|
|
78
|
+
npmCliPath = candidate;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Try the next known npm installation location.
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!npmCliPath)
|
|
86
|
+
throw new Error('Unable to locate npm');
|
|
87
|
+
const npmCli = npmCliPath;
|
|
88
|
+
const runNpm = (args) => execFileAsync(process.execPath, [npmCli, ...args]);
|
|
89
|
+
await runNpm(['install', '-g', 'windsor-bot@latest']);
|
|
90
|
+
const { stdout } = await runNpm(['root', '-g']);
|
|
75
91
|
const packageJsonPath = join(stdout.trim(), 'windsor-bot', 'package.json');
|
|
76
92
|
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'));
|
|
77
93
|
if (typeof packageJson.version !== 'string')
|