summaryrefslogtreecommitdiff
path: root/modules/ext/wpm.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/ext/wpm.js')
-rw-r--r--modules/ext/wpm.js56
1 files changed, 45 insertions, 11 deletions
diff --git a/modules/ext/wpm.js b/modules/ext/wpm.js
index 68ac9cb..e9b9b50 100644
--- a/modules/ext/wpm.js
+++ b/modules/ext/wpm.js
@@ -21,6 +21,35 @@ class WpmModule {
saveInstalled() {
localStorage.setItem('webx11_wpm_installed', JSON.stringify(this.installed));
}
+ // ── Catalog normalisation ───────────────────────────────────────────────
+ // packages.json is hand-edited JSON and its field names have drifted: `kanban`
+ // shipped with `description` while the other 31 entries use `desc`
+ // (RPT-20261109-123907-5a6273ab), and an entry can be missing `category` /
+ // `commands` entirely. Reading pkg.desc.toLowerCase() straight out of the index
+ // threw a TypeError out of `wpm search` for EVERY keyword (the bad entry is only
+ // reached mid-loop), so all catalog reads go through _pkg()/_packageMap().
+ // `desc` wins when both keys exist; values are coerced so .toLowerCase() is safe.
+ _pkg(name, raw) {
+ const src = (raw && typeof raw === 'object') ? raw : {};
+ const str = (v) => (v === undefined || v === null) ? '' : String(v);
+ let commands = src.commands;
+ if (typeof commands === 'string') commands = [commands];
+ if (!Array.isArray(commands)) commands = [];
+ return Object.assign({}, src, {
+ name: str(src.name) || str(name),
+ version: str(src.version) || '?',
+ desc: str(src.desc) || str(src.description),
+ category: str(src.category),
+ url: str(src.url),
+ commands: commands,
+ });
+ }
+ _packageMap(idx) {
+ const pkgs = (idx && idx.packages && typeof idx.packages === 'object') ? idx.packages : {};
+ const out = {};
+ Object.keys(pkgs).forEach(k => { out[k] = this._pkg(k, pkgs[k]); });
+ return out;
+ }
registerCommands() {
this.commands['wpm'] = (args) => this.handle(args);
}
@@ -52,8 +81,9 @@ class WpmModule {
if (!name) return this.terminal.print('Usage: wpm install <package>', 'warning');
const idx = await this.loadIndex();
if (!idx) return;
- const pkg = idx.packages[name];
- if (!pkg) return this.terminal.print(`Package "${name}" not found. Try: wpm search <keyword>`, 'error');
+ const raw = idx.packages && idx.packages[name];
+ if (!raw) return this.terminal.print(`Package "${name}" not found. Try: wpm search <keyword>`, 'error');
+ const pkg = this._pkg(name, raw);
if (this.installed[name]) return this.terminal.print(`Package "${name}" already installed. Use wpm update to reinstall.`, 'warning');
this.terminal.print(`Installing ${pkg.name} v${pkg.version}...`, 'info');
this.terminal.print(` ${pkg.desc}`, 'info');
@@ -106,8 +136,9 @@ class WpmModule {
});
}
this.terminal.print('\n=== Available Packages ===', 'info');
- Object.keys(idx.packages).sort().forEach(name => {
- const pkg = idx.packages[name];
+ const pkgs = this._packageMap(idx);
+ Object.keys(pkgs).sort().forEach(name => {
+ const pkg = pkgs[name];
const installed = this.installed[name] ? ' ✅' : '';
this.terminal.print(` ${name} - ${pkg.desc}${installed}`);
});
@@ -116,10 +147,10 @@ class WpmModule {
if (!keyword) return this.terminal.print('Usage: wpm search <keyword>', 'warning');
const idx = await this.loadIndex();
if (!idx) return;
- const kw = keyword.toLowerCase();
+ const kw = String(keyword).toLowerCase();
const results = [];
- Object.entries(idx.packages).forEach(([name, pkg]) => {
- if (name.includes(kw) || pkg.desc.toLowerCase().includes(kw) || pkg.category.toLowerCase().includes(kw)) {
+ Object.entries(this._packageMap(idx)).forEach(([name, pkg]) => {
+ if (name.toLowerCase().includes(kw) || pkg.desc.toLowerCase().includes(kw) || pkg.category.toLowerCase().includes(kw)) {
results.push({ name, ...pkg });
}
});
@@ -137,8 +168,9 @@ class WpmModule {
if (!this.index) return;
this.terminal.print('Index refreshed.', 'success');
const outdated = [];
+ const pkgs = this._packageMap(this.index);
Object.keys(this.installed).forEach(name => {
- const pkg = this.index.packages[name];
+ const pkg = pkgs[name];
if (pkg && pkg.version !== this.installed[name].version) {
outdated.push(name);
}
@@ -151,7 +183,8 @@ class WpmModule {
if (!name) return this.terminal.print('Usage: wpm remove <package>', 'warning');
if (!this.installed[name]) return this.terminal.print(`Package "${name}" is not installed via wpm`, 'warning');
const idx = await this.loadIndex();
- const className = idx && idx.packages[name] ? idx.packages[name].name.replace(/\s+/g, '') + 'Module' : null;
+ const raw = idx && idx.packages ? idx.packages[name] : null;
+ const className = raw ? this._pkg(name, raw).name.replace(/\s+/g, '') + 'Module' : null;
if (className && this.terminal.moduleManager.unregisterModule(className)) {
this.terminal.print(`Module ${className} unregistered`, 'info');
}
@@ -163,8 +196,9 @@ class WpmModule {
if (!name) return this.terminal.print('Usage: wpm info <package>', 'warning');
const idx = await this.loadIndex();
if (!idx) return;
- const pkg = idx.packages[name];
- if (!pkg) return this.terminal.print(`Package "${name}" not found`, 'error');
+ const raw = idx.packages && idx.packages[name];
+ if (!raw) return this.terminal.print(`Package "${name}" not found`, 'error');
+ const pkg = this._pkg(name, raw);
this.terminal.print(`=== ${pkg.name} v${pkg.version} ===`, 'info');
this.terminal.print(`Description: ${pkg.desc}`);
this.terminal.print(`Category: ${pkg.category}`);