windsor-bot 0.2.8 → 0.2.9

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 +19 -2
  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 { access, constants, readFile, stat } from 'fs/promises';
4
+ import { access, constants, readFile, readdir, stat } from 'fs/promises';
5
5
  import { promisify } from 'util';
6
6
  import { spawn } from 'child_process';
7
7
  import { dirname, join } from 'path';
@@ -67,6 +67,7 @@ async function readPackageVersion() {
67
67
  async function updateGlobalBot() {
68
68
  const configuredCandidates = [
69
69
  process.env['npm_execpath'],
70
+ process.env['NVM_BIN'] ? join(process.env['NVM_BIN'], 'npm') : undefined,
70
71
  join(dirname(process.execPath), '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js'),
71
72
  join(dirname(process.execPath), 'npm'),
72
73
  '/usr/local/lib/node_modules/npm/bin/npm-cli.js',
@@ -80,11 +81,27 @@ async function updateGlobalBot() {
80
81
  .filter((candidate) => Boolean(candidate))
81
82
  .map(candidate => candidate.trim())
82
83
  .filter((candidate, index, candidates) => candidates.indexOf(candidate) === index);
84
+ const nvmDir = process.env['NVM_DIR'] ?? (process.env['HOME'] ? join(process.env['HOME'], '.nvm') : undefined);
85
+ const nvmCandidates = [];
86
+ if (nvmDir) {
87
+ try {
88
+ const nodeVersions = await readdir(join(nvmDir, 'versions', 'node'), { withFileTypes: true });
89
+ for (const version of nodeVersions) {
90
+ if (version.isDirectory())
91
+ nvmCandidates.push(join(nvmDir, 'versions', 'node', version.name, 'bin', 'npm'));
92
+ }
93
+ logEvent('info', `Found ${nvmCandidates.length} nvm npm candidate(s) under ${nvmDir}`);
94
+ }
95
+ catch (error) {
96
+ const code = error instanceof Error && 'code' in error ? String(error.code) : 'unknown';
97
+ logEvent('info', `Unable to inspect nvm npm locations under ${nvmDir} (${code})`);
98
+ }
99
+ }
83
100
  const pathCandidates = (process.env['PATH'] ?? '')
84
101
  .split(':')
85
102
  .filter(Boolean)
86
103
  .map(directory => join(directory, 'npm'));
87
- const npmCandidates = [...configuredCandidates, ...pathCandidates]
104
+ const npmCandidates = [...configuredCandidates, ...nvmCandidates, ...pathCandidates]
88
105
  .filter((candidate, index, candidates) => candidates.indexOf(candidate) === index);
89
106
  logEvent('info', `Update requested; checking ${npmCandidates.length} npm candidate(s) (node=${process.execPath}, cwd=${process.cwd()})`);
90
107
  let npmCommand;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "windsor-bot",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Self-hosted Discord bot automation for household list and todo printing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",