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.
Files changed (2) hide show
  1. package/dist/server.js +24 -8
  2. 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
- // GUI-launched processes may not inherit the shell PATH where npm is installed.
69
- const npmEnv = {
70
- ...process.env,
71
- PATH: [dirname(process.execPath), process.env.PATH].filter(Boolean).join(process.platform === 'win32' ? ';' : ':'),
72
- };
73
- await execFileAsync('npm', ['install', '-g', 'windsor-bot@latest'], { env: npmEnv });
74
- const { stdout } = await execFileAsync('npm', ['root', '-g'], { env: npmEnv });
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')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "windsor-bot",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Self-hosted Discord bot automation for household list and todo printing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",